1 /* YACC parser for Ada expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994, 1997, 2000
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Parse an Ada expression from text in a string,
22 and return the result as a struct expression pointer.
23 That structure contains arithmetic operations in reverse polish,
24 with constants represented by operations that are followed by special data.
25 See expression.h for the details of the format.
26 What is important here is that it can be built up sequentially
27 during the process of parsing; the lower levels of the tree always
28 come first in the result.
30 malloc's and realloc's in this file are transformed to
31 xmalloc and xrealloc respectively by the same sed command in the
32 makefile that remaps any other malloc/realloc inserted by the parser
33 generator. Doing this with #defines and trying to control the interaction
34 with include files (<malloc.h> and <stdlib.h> for example) just became
35 too messy, particularly when such includes can be inserted at random
36 times by the parser generator. */
43 #include "expression.h"
45 #include "parser-defs.h"
48 #include "bfd.h" /* Required by objfiles.h. */
49 #include "symfile.h" /* Required by objfiles.h. */
50 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
53 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
54 as well as gratuitiously global symbol names, so we can have multiple
55 yacc generated parsers in gdb. These are only the variables
56 produced by yacc. If other parser generators (bison, byacc, etc) produce
57 additional global names that conflict at link time, then those parser
58 generators need to be fixed instead of adding those names to this list. */
60 /* NOTE: This is clumsy, especially since BISON and FLEX provide --prefix
61 options. I presume we are maintaining it to accommodate systems
62 without BISON? (PNH) */
64 #define yymaxdepth ada_maxdepth
65 #define yyparse _ada_parse /* ada_parse calls this after initialization */
67 #define yyerror ada_error
68 #define yylval ada_lval
69 #define yychar ada_char
70 #define yydebug ada_debug
71 #define yypact ada_pact
78 #define yyexca ada_exca
79 #define yyerrflag ada_errflag
80 #define yynerrs ada_nerrs
84 #define yy_yys ada_yys
85 #define yystate ada_state
88 #define yy_yyv ada_yyv
90 #define yylloc ada_lloc
91 #define yyreds ada_reds /* With YYDEBUG defined */
92 #define yytoks ada_toks /* With YYDEBUG defined */
93 #define yyname ada_name /* With YYDEBUG defined */
94 #define yyrule ada_rule /* With YYDEBUG defined */
97 #define YYDEBUG 1 /* Default to yydebug support */
100 #define YYFPRINTF parser_fprintf
104 struct minimal_symbol* msym;
106 struct stoken stoken;
109 /* If expression is in the context of TYPE'(...), then TYPE, else
111 static struct type* type_qualifier;
115 static int yylex (void);
117 void yyerror (char *);
119 static struct stoken string_to_operator (struct stoken);
121 static void write_attribute_call0 (enum ada_attribute);
123 static void write_attribute_call1 (enum ada_attribute, LONGEST);
125 static void write_attribute_calln (enum ada_attribute, int);
127 static void write_object_renaming (struct block*, struct symbol*);
129 static void write_var_from_name (struct block*, struct name_info);
132 convert_char_literal (struct type*, LONGEST);
148 struct name_info ssym;
151 struct internalvar *ivar;
155 %type <voidval> exp exp1 simple_exp start variable
158 %token <typed_val> INT NULL_PTR CHARLIT
159 %token <typed_val_float> FLOAT
160 %token <tval> TYPENAME
161 %token <bval> BLOCKNAME
163 /* Both NAME and TYPENAME tokens represent symbols in the input,
164 and both convey their data as strings.
165 But a TYPENAME is a string that happens to be defined as a typedef
166 or builtin type name (such as int or char)
167 and a NAME is any other symbol.
168 Contexts where this distinction is not important can use the
169 nonterminal "name", which matches either NAME or TYPENAME. */
172 %token <ssym> NAME DOT_ID OBJECT_RENAMING
174 %type <lval> arglist tick_arglist
176 %type <tval> save_qualifier
180 /* Special type cases, put in to allow the parser to distinguish different
182 %token <lval> LAST REGNAME
184 %token <ivar> INTERNAL_VARIABLE
187 %left _AND_ OR XOR THEN ELSE
188 %left '=' NOTEQUAL '<' '>' LEQ GEQ IN DOTDOT
192 %left '*' '/' MOD REM
193 %right STARSTAR ABS NOT
194 /* The following are right-associative only so that reductions at this
195 precedence have lower precedence than '.' and '('. The syntax still
196 forces a.b.c, e.g., to be LEFT-associated. */
197 %right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
198 %right TICK_MAX TICK_MIN TICK_MODULUS
199 %right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
200 %right '.' '(' '[' DOT_ID DOT_ALL
208 | type { write_exp_elt_opcode (OP_TYPE);
209 write_exp_elt_type ($1);
210 write_exp_elt_opcode (OP_TYPE); }
213 /* Expressions, including the sequencing operator. */
216 { write_exp_elt_opcode (BINOP_COMMA); }
219 /* Expressions, not including the sequencing operator. */
220 simple_exp : simple_exp DOT_ALL
221 { write_exp_elt_opcode (UNOP_IND); }
224 simple_exp : simple_exp DOT_ID
225 { write_exp_elt_opcode (STRUCTOP_STRUCT);
226 write_exp_string ($2.stoken);
227 write_exp_elt_opcode (STRUCTOP_STRUCT);
231 simple_exp : simple_exp '(' arglist ')'
233 write_exp_elt_opcode (OP_FUNCALL);
234 write_exp_elt_longcst ($3);
235 write_exp_elt_opcode (OP_FUNCALL);
239 simple_exp : type '(' exp ')'
241 write_exp_elt_opcode (UNOP_CAST);
242 write_exp_elt_type ($1);
243 write_exp_elt_opcode (UNOP_CAST);
247 simple_exp : type '\'' save_qualifier { type_qualifier = $1; } '(' exp ')'
249 /* write_exp_elt_opcode (UNOP_QUAL); */
250 /* FIXME: UNOP_QUAL should be defined in expression.h */
251 write_exp_elt_type ($1);
252 /* write_exp_elt_opcode (UNOP_QUAL); */
253 /* FIXME: UNOP_QUAL should be defined in expression.h */
258 save_qualifier : { $$ = type_qualifier; }
262 simple_exp '(' exp DOTDOT exp ')'
263 { write_exp_elt_opcode (TERNOP_SLICE); }
266 simple_exp : '(' exp1 ')' { }
269 simple_exp : variable
272 simple_exp: REGNAME /* GDB extension */
273 { write_exp_elt_opcode (OP_REGISTER);
274 write_exp_elt_longcst ((LONGEST) $1);
275 write_exp_elt_opcode (OP_REGISTER);
279 simple_exp: INTERNAL_VARIABLE /* GDB extension */
280 { write_exp_elt_opcode (OP_INTERNALVAR);
281 write_exp_elt_intern ($1);
282 write_exp_elt_opcode (OP_INTERNALVAR);
291 { write_exp_elt_opcode (OP_LAST);
292 write_exp_elt_longcst ((LONGEST) $1);
293 write_exp_elt_opcode (OP_LAST);
297 exp : exp ASSIGN exp /* Extension for convenience */
298 { write_exp_elt_opcode (BINOP_ASSIGN); }
301 exp : '-' exp %prec UNARY
302 { write_exp_elt_opcode (UNOP_NEG); }
305 exp : '+' exp %prec UNARY
306 { write_exp_elt_opcode (UNOP_PLUS); }
309 exp : NOT exp %prec UNARY
310 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
313 exp : ABS exp %prec UNARY
314 { write_exp_elt_opcode (UNOP_ABS); }
317 arglist : { $$ = 0; }
326 | arglist ',' any_name ARROW exp
330 exp : '{' type '}' exp %prec '.'
332 { write_exp_elt_opcode (UNOP_MEMVAL);
333 write_exp_elt_type ($2);
334 write_exp_elt_opcode (UNOP_MEMVAL);
338 /* Binary operators in order of decreasing precedence. */
340 exp : exp STARSTAR exp
341 { write_exp_elt_opcode (BINOP_EXP); }
345 { write_exp_elt_opcode (BINOP_MUL); }
349 { write_exp_elt_opcode (BINOP_DIV); }
352 exp : exp REM exp /* May need to be fixed to give correct Ada REM */
353 { write_exp_elt_opcode (BINOP_REM); }
357 { write_exp_elt_opcode (BINOP_MOD); }
360 exp : exp '@' exp /* GDB extension */
361 { write_exp_elt_opcode (BINOP_REPEAT); }
365 { write_exp_elt_opcode (BINOP_ADD); }
369 { write_exp_elt_opcode (BINOP_CONCAT); }
373 { write_exp_elt_opcode (BINOP_SUB); }
377 { write_exp_elt_opcode (BINOP_EQUAL); }
380 exp : exp NOTEQUAL exp
381 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
385 { write_exp_elt_opcode (BINOP_LEQ); }
388 exp : exp IN exp DOTDOT exp
389 { /*write_exp_elt_opcode (TERNOP_MBR); */ }
390 /* FIXME: TERNOP_MBR should be defined in
392 | exp IN exp TICK_RANGE tick_arglist
393 { /*write_exp_elt_opcode (BINOP_MBR); */
394 /* FIXME: BINOP_MBR should be defined in expression.h */
395 write_exp_elt_longcst ((LONGEST) $5);
396 /*write_exp_elt_opcode (BINOP_MBR); */
398 | exp IN TYPENAME %prec TICK_ACCESS
399 { /*write_exp_elt_opcode (UNOP_MBR); */
400 /* FIXME: UNOP_QUAL should be defined in expression.h */
401 write_exp_elt_type ($3);
402 /* write_exp_elt_opcode (UNOP_MBR); */
403 /* FIXME: UNOP_MBR should be defined in expression.h */
405 | exp NOT IN exp DOTDOT exp
406 { /*write_exp_elt_opcode (TERNOP_MBR); */
407 /* FIXME: TERNOP_MBR should be defined in expression.h */
408 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
410 | exp NOT IN exp TICK_RANGE tick_arglist
411 { /* write_exp_elt_opcode (BINOP_MBR); */
412 /* FIXME: BINOP_MBR should be defined in expression.h */
413 write_exp_elt_longcst ((LONGEST) $6);
414 /*write_exp_elt_opcode (BINOP_MBR);*/
415 /* FIXME: BINOP_MBR should be defined in expression.h */
416 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
418 | exp NOT IN TYPENAME %prec TICK_ACCESS
419 { /*write_exp_elt_opcode (UNOP_MBR);*/
420 /* FIXME: UNOP_MBR should be defined in expression.h */
421 write_exp_elt_type ($4);
422 /* write_exp_elt_opcode (UNOP_MBR);*/
423 /* FIXME: UNOP_MBR should be defined in expression.h */
424 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
429 { write_exp_elt_opcode (BINOP_GEQ); }
433 { write_exp_elt_opcode (BINOP_LESS); }
437 { write_exp_elt_opcode (BINOP_GTR); }
440 exp : exp _AND_ exp /* Fix for Ada elementwise AND. */
441 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
444 exp : exp _AND_ THEN exp %prec _AND_
445 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
448 exp : exp OR exp /* Fix for Ada elementwise OR */
449 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
452 exp : exp OR ELSE exp
453 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
456 exp : exp XOR exp /* Fix for Ada elementwise XOR */
457 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
460 simple_exp : simple_exp TICK_ACCESS
461 { write_exp_elt_opcode (UNOP_ADDR); }
462 | simple_exp TICK_ADDRESS
463 { write_exp_elt_opcode (UNOP_ADDR);
464 write_exp_elt_opcode (UNOP_CAST);
465 write_exp_elt_type (builtin_type_ada_system_address);
466 write_exp_elt_opcode (UNOP_CAST);
468 | simple_exp TICK_FIRST tick_arglist
469 { write_attribute_call1 (ATR_FIRST, $3); }
470 | simple_exp TICK_LAST tick_arglist
471 { write_attribute_call1 (ATR_LAST, $3); }
472 | simple_exp TICK_LENGTH tick_arglist
473 { write_attribute_call1 (ATR_LENGTH, $3); }
474 | simple_exp TICK_SIZE
475 { write_attribute_call0 (ATR_SIZE); }
476 | simple_exp TICK_TAG
477 { write_attribute_call0 (ATR_TAG); }
478 | opt_type_prefix TICK_MIN '(' exp ',' exp ')'
479 { write_attribute_calln (ATR_MIN, 2); }
480 | opt_type_prefix TICK_MAX '(' exp ',' exp ')'
481 { write_attribute_calln (ATR_MAX, 2); }
482 | opt_type_prefix TICK_POS '(' exp ')'
483 { write_attribute_calln (ATR_POS, 1); }
484 | type_prefix TICK_FIRST tick_arglist
485 { write_attribute_call1 (ATR_FIRST, $3); }
486 | type_prefix TICK_LAST tick_arglist
487 { write_attribute_call1 (ATR_LAST, $3); }
488 | type_prefix TICK_LENGTH tick_arglist
489 { write_attribute_call1 (ATR_LENGTH, $3); }
490 | type_prefix TICK_VAL '(' exp ')'
491 { write_attribute_calln (ATR_VAL, 1); }
492 | type_prefix TICK_MODULUS
493 { write_attribute_call0 (ATR_MODULUS); }
496 tick_arglist : %prec '('
504 { write_exp_elt_opcode (OP_TYPE);
505 write_exp_elt_type ($1);
506 write_exp_elt_opcode (OP_TYPE); }
512 { write_exp_elt_opcode (OP_TYPE);
513 write_exp_elt_type (builtin_type_void);
514 write_exp_elt_opcode (OP_TYPE); }
519 { write_exp_elt_opcode (OP_LONG);
520 write_exp_elt_type ($1.type);
521 write_exp_elt_longcst ((LONGEST)($1.val));
522 write_exp_elt_opcode (OP_LONG);
527 { write_exp_elt_opcode (OP_LONG);
528 if (type_qualifier == NULL)
529 write_exp_elt_type ($1.type);
531 write_exp_elt_type (type_qualifier);
532 write_exp_elt_longcst
533 (convert_char_literal (type_qualifier, $1.val));
534 write_exp_elt_opcode (OP_LONG);
539 { write_exp_elt_opcode (OP_DOUBLE);
540 write_exp_elt_type ($1.type);
541 write_exp_elt_dblcst ($1.dval);
542 write_exp_elt_opcode (OP_DOUBLE);
547 { write_exp_elt_opcode (OP_LONG);
548 write_exp_elt_type (builtin_type_int);
549 write_exp_elt_longcst ((LONGEST)(0));
550 write_exp_elt_opcode (OP_LONG);
555 { /* Ada strings are converted into array constants
556 a lower bound of 1. Thus, the array upper bound
557 is the string length. */
558 char *sp = $1.ptr; int count;
560 { /* One dummy character for the type */
561 write_exp_elt_opcode (OP_LONG);
562 write_exp_elt_type (builtin_type_ada_char);
563 write_exp_elt_longcst ((LONGEST)(0));
564 write_exp_elt_opcode (OP_LONG);
566 for (count = $1.length; count > 0; count -= 1)
568 write_exp_elt_opcode (OP_LONG);
569 write_exp_elt_type (builtin_type_ada_char);
570 write_exp_elt_longcst ((LONGEST)(*sp));
572 write_exp_elt_opcode (OP_LONG);
574 write_exp_elt_opcode (OP_ARRAY);
575 write_exp_elt_longcst ((LONGEST) 1);
576 write_exp_elt_longcst ((LONGEST) ($1.length));
577 write_exp_elt_opcode (OP_ARRAY);
582 { error ("NEW not implemented."); }
585 variable: NAME { write_var_from_name (NULL, $1); }
586 | block NAME /* GDB extension */
587 { write_var_from_name ($1, $2); }
588 | OBJECT_RENAMING { write_object_renaming (NULL, $1.sym); }
589 | block OBJECT_RENAMING
590 { write_object_renaming ($1, $2.sym); }
595 | OBJECT_RENAMING { }
598 block : BLOCKNAME /* GDB extension */
600 | block BLOCKNAME /* GDB extension */
605 type : TYPENAME { $$ = $1; }
606 | block TYPENAME { $$ = $2; }
607 | TYPENAME TICK_ACCESS
608 { $$ = lookup_pointer_type ($1); }
609 | block TYPENAME TICK_ACCESS
610 { $$ = lookup_pointer_type ($2); }
613 /* Some extensions borrowed from C, for the benefit of those who find they
614 can't get used to Ada notation in GDB. */
616 exp : '*' exp %prec '.'
617 { write_exp_elt_opcode (UNOP_IND); }
619 { write_exp_elt_opcode (UNOP_ADDR); }
621 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
626 /* yylex defined in ada-lex.c: Reads one token, getting characters */
627 /* through lexptr. */
629 /* Remap normal flex interface names (yylex) as well as gratuitiously */
630 /* global symbol names, so we can have multiple flex-generated parsers */
633 /* (See note above on previous definitions for YACC.) */
635 #define yy_create_buffer ada_yy_create_buffer
636 #define yy_delete_buffer ada_yy_delete_buffer
637 #define yy_init_buffer ada_yy_init_buffer
638 #define yy_load_buffer_state ada_yy_load_buffer_state
639 #define yy_switch_to_buffer ada_yy_switch_to_buffer
640 #define yyrestart ada_yyrestart
641 #define yytext ada_yytext
642 #define yywrap ada_yywrap
644 /* The following kludge was found necessary to prevent conflicts between */
645 /* defs.h and non-standard stdlib.h files. */
646 #define qsort __qsort__dummy
652 lexer_init (yyin); /* (Re-)initialize lexer. */
653 left_block_context = NULL;
654 type_qualifier = NULL;
656 return _ada_parse ();
663 error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
666 /* The operator name corresponding to operator symbol STRING (adds
667 quotes and maps to lower-case). Destroys the previous contents of
668 the array pointed to by STRING.ptr. Error if STRING does not match
669 a valid Ada operator. Assumes that STRING.ptr points to a
670 null-terminated string and that, if STRING is a valid operator
671 symbol, the array pointed to by STRING.ptr contains at least
672 STRING.length+3 characters. */
675 string_to_operator (string)
676 struct stoken string;
680 for (i = 0; ada_opname_table[i].mangled != NULL; i += 1)
682 if (string.length == strlen (ada_opname_table[i].demangled)-2
683 && strncasecmp (string.ptr, ada_opname_table[i].demangled+1,
686 strncpy (string.ptr, ada_opname_table[i].demangled,
692 error ("Invalid operator symbol `%s'", string.ptr);
695 /* Emit expression to access an instance of SYM, in block BLOCK (if
696 * non-NULL), and with :: qualification ORIG_LEFT_CONTEXT. */
698 write_var_from_sym (orig_left_context, block, sym)
699 struct block* orig_left_context;
703 if (orig_left_context == NULL && symbol_read_needs_frame (sym))
705 if (innermost_block == 0 ||
706 contained_in (block, innermost_block))
707 innermost_block = block;
710 write_exp_elt_opcode (OP_VAR_VALUE);
711 /* We want to use the selected frame, not another more inner frame
712 which happens to be in the same block */
713 write_exp_elt_block (NULL);
714 write_exp_elt_sym (sym);
715 write_exp_elt_opcode (OP_VAR_VALUE);
718 /* Emit expression to access an instance of NAME. */
720 write_var_from_name (orig_left_context, name)
721 struct block* orig_left_context;
722 struct name_info name;
724 if (name.msym != NULL)
726 write_exp_msymbol (name.msym,
727 lookup_function_type (builtin_type_int),
730 else if (name.sym == NULL)
732 /* Multiple matches: record name and starting block for later
733 resolution by ada_resolve. */
734 /* write_exp_elt_opcode (OP_UNRESOLVED_VALUE); */
735 /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
736 write_exp_elt_block (name.block);
737 /* write_exp_elt_name (name.stoken.ptr); */
738 /* FIXME: write_exp_elt_name should be defined in defs.h, located in parse.c */
739 /* write_exp_elt_opcode (OP_UNRESOLVED_VALUE); */
740 /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
743 write_var_from_sym (orig_left_context, name.block, name.sym);
746 /* Write a call on parameterless attribute ATR. */
749 write_attribute_call0 (atr)
750 enum ada_attribute atr;
752 /* write_exp_elt_opcode (OP_ATTRIBUTE); */
753 /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
754 write_exp_elt_longcst ((LONGEST) 0);
755 write_exp_elt_longcst ((LONGEST) atr);
756 /* write_exp_elt_opcode (OP_ATTRIBUTE); */
757 /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
760 /* Write a call on an attribute ATR with one constant integer
764 write_attribute_call1 (atr, arg)
765 enum ada_attribute atr;
768 write_exp_elt_opcode (OP_LONG);
769 write_exp_elt_type (builtin_type_int);
770 write_exp_elt_longcst (arg);
771 write_exp_elt_opcode (OP_LONG);
772 /*write_exp_elt_opcode (OP_ATTRIBUTE);*/
773 /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
774 write_exp_elt_longcst ((LONGEST) 1);
775 write_exp_elt_longcst ((LONGEST) atr);
776 /*write_exp_elt_opcode (OP_ATTRIBUTE);*/
777 /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
780 /* Write a call on an attribute ATR with N parameters, whose code must have
781 * been generated previously. */
784 write_attribute_calln (atr, n)
785 enum ada_attribute atr;
788 /*write_exp_elt_opcode (OP_ATTRIBUTE);*/
789 /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
790 write_exp_elt_longcst ((LONGEST) n);
791 write_exp_elt_longcst ((LONGEST) atr);
792 /* write_exp_elt_opcode (OP_ATTRIBUTE);*/
793 /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
796 /* Emit expression corresponding to the renamed object designated by
797 * the type RENAMING, which must be the referent of an object renaming
798 * type, in the context of ORIG_LEFT_CONTEXT (?). */
800 write_object_renaming (orig_left_context, renaming)
801 struct block* orig_left_context;
802 struct symbol* renaming;
804 const char* qualification = SYMBOL_NAME (renaming);
805 const char* simple_tail;
806 const char* expr = TYPE_FIELD_NAME (SYMBOL_TYPE (renaming), 0);
810 enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
812 /* if orig_left_context is null, then use the currently selected
813 block, otherwise we might fail our symbol lookup below */
814 if (orig_left_context == NULL)
815 orig_left_context = get_selected_block (NULL);
817 for (simple_tail = qualification + strlen (qualification);
818 simple_tail != qualification; simple_tail -= 1)
820 if (*simple_tail == '.')
825 else if (STREQN (simple_tail, "__", 2))
832 suffix = strstr (expr, "___XE");
836 name = (char*) malloc (suffix - expr + 1);
837 /* add_name_string_cleanup (name); */
838 /* FIXME: add_name_string_cleanup should be defined in
839 parser-defs.h, implemented in parse.c */
840 strncpy (name, expr, suffix-expr);
841 name[suffix-expr] = '\000';
842 sym = lookup_symbol (name, orig_left_context, VAR_NAMESPACE, 0, NULL);
844 error ("Could not find renamed variable: %s", ada_demangle (name));
846 /* FIXME: ada_demangle should be defined in defs.h, implemented in ada-lang.c */
847 write_var_from_sym (orig_left_context, block_found, sym);
850 slice_state = SIMPLE_INDEX;
851 while (*suffix == 'X')
857 slice_state = LOWER_BOUND;
860 if (isdigit (*suffix))
863 long val = strtol (suffix, &next, 10);
867 write_exp_elt_opcode (OP_LONG);
868 write_exp_elt_type (builtin_type_ada_int);
869 write_exp_elt_longcst ((LONGEST) val);
870 write_exp_elt_opcode (OP_LONG);
877 struct symbol* index_sym;
879 end = strchr (suffix, 'X');
881 end = suffix + strlen (suffix);
883 index_len = simple_tail - qualification + 2 + (suffix - end) + 1;
884 index_name = (char*) malloc (index_len);
885 memset (index_name, '\000', index_len);
886 /* add_name_string_cleanup (index_name);*/
887 /* FIXME: add_name_string_cleanup should be defined in
888 parser-defs.h, implemented in parse.c */
889 strncpy (index_name, qualification, simple_tail - qualification);
890 index_name[simple_tail - qualification] = '\000';
891 strncat (index_name, suffix, suffix-end);
895 lookup_symbol (index_name, NULL, VAR_NAMESPACE, 0, NULL);
896 if (index_sym == NULL)
897 error ("Could not find %s", index_name);
898 write_var_from_sym (NULL, block_found, sym);
900 if (slice_state == SIMPLE_INDEX)
902 write_exp_elt_opcode (OP_FUNCALL);
903 write_exp_elt_longcst ((LONGEST) 1);
904 write_exp_elt_opcode (OP_FUNCALL);
906 else if (slice_state == LOWER_BOUND)
907 slice_state = UPPER_BOUND;
908 else if (slice_state == UPPER_BOUND)
910 write_exp_elt_opcode (TERNOP_SLICE);
911 slice_state = SIMPLE_INDEX;
917 struct stoken field_name;
921 if (slice_state != SIMPLE_INDEX)
923 end = strchr (suffix, 'X');
925 end = suffix + strlen (suffix);
926 field_name.length = end - suffix;
927 field_name.ptr = (char*) malloc (end - suffix + 1);
928 strncpy (field_name.ptr, suffix, end - suffix);
929 field_name.ptr[end - suffix] = '\000';
931 write_exp_elt_opcode (STRUCTOP_STRUCT);
932 write_exp_string (field_name);
933 write_exp_elt_opcode (STRUCTOP_STRUCT);
941 if (slice_state == SIMPLE_INDEX)
945 error ("Internal error in encoding of renaming declaration: %s",
946 SYMBOL_NAME (renaming));
949 /* Convert the character literal whose ASCII value would be VAL to the
950 appropriate value of type TYPE, if there is a translation.
951 Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
952 the literal 'A' (VAL == 65), returns 0. */
954 convert_char_literal (struct type* type, LONGEST val)
959 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM)
961 sprintf (name, "QU%02x", (int) val);
962 for (f = 0; f < TYPE_NFIELDS (type); f += 1)
964 if (STREQ (name, TYPE_FIELD_NAME (type, f)))
965 return TYPE_FIELD_BITPOS (type, f);