1 /* YACC parser for Ada expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994, 1997, 2000, 2003,
3 2004 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Parse an Ada expression from text in a string,
23 and return the result as a struct expression pointer.
24 That structure contains arithmetic operations in reverse polish,
25 with constants represented by operations that are followed by special data.
26 See expression.h for the details of the format.
27 What is important here is that it can be built up sequentially
28 during the process of parsing; the lower levels of the tree always
29 come first in the result.
31 malloc's and realloc's in this file are transformed to
32 xmalloc and xrealloc respectively by the same sed command in the
33 makefile that remaps any other malloc/realloc inserted by the parser
34 generator. Doing this with #defines and trying to control the interaction
35 with include files (<malloc.h> and <stdlib.h> for example) just became
36 too messy, particularly when such includes can be inserted at random
37 times by the parser generator. */
42 #include "gdb_string.h"
44 #include "expression.h"
46 #include "parser-defs.h"
49 #include "bfd.h" /* Required by objfiles.h. */
50 #include "symfile.h" /* Required by objfiles.h. */
51 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
55 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
56 as well as gratuitiously global symbol names, so we can have multiple
57 yacc generated parsers in gdb. These are only the variables
58 produced by yacc. If other parser generators (bison, byacc, etc) produce
59 additional global names that conflict at link time, then those parser
60 generators need to be fixed instead of adding those names to this list. */
62 /* NOTE: This is clumsy, especially since BISON and FLEX provide --prefix
63 options. I presume we are maintaining it to accommodate systems
64 without BISON? (PNH) */
66 #define yymaxdepth ada_maxdepth
67 #define yyparse _ada_parse /* ada_parse calls this after initialization */
69 #define yyerror ada_error
70 #define yylval ada_lval
71 #define yychar ada_char
72 #define yydebug ada_debug
73 #define yypact ada_pact
80 #define yyexca ada_exca
81 #define yyerrflag ada_errflag
82 #define yynerrs ada_nerrs
86 #define yy_yys ada_yys
87 #define yystate ada_state
90 #define yy_yyv ada_yyv
92 #define yylloc ada_lloc
93 #define yyreds ada_reds /* With YYDEBUG defined */
94 #define yytoks ada_toks /* With YYDEBUG defined */
95 #define yyname ada_name /* With YYDEBUG defined */
96 #define yyrule ada_rule /* With YYDEBUG defined */
99 #define YYDEBUG 1 /* Default to yydebug support */
102 #define YYFPRINTF parser_fprintf
106 struct minimal_symbol *msym;
108 struct stoken stoken;
111 static struct stoken empty_stoken = { "", 0 };
113 /* If expression is in the context of TYPE'(...), then TYPE, else
115 static struct type *type_qualifier;
119 static int yylex (void);
121 void yyerror (char *);
123 static struct stoken string_to_operator (struct stoken);
125 static void write_int (LONGEST, struct type *);
127 static void write_object_renaming (struct block *, struct symbol *, int);
129 static struct type* write_var_or_type (struct block *, struct stoken);
131 static void write_name_assoc (struct stoken);
133 static void write_exp_op_with_string (enum exp_opcode, struct stoken);
135 static struct block *block_lookup (struct block *, char *);
137 static LONGEST convert_char_literal (struct type *, LONGEST);
139 static void write_ambiguous_var (struct block *, char *, int);
141 static struct type *type_int (void);
143 static struct type *type_long (void);
145 static struct type *type_long_long (void);
147 static struct type *type_float (void);
149 static struct type *type_double (void);
151 static struct type *type_long_double (void);
153 static struct type *type_char (void);
155 static struct type *type_system_address (void);
173 struct internalvar *ivar;
176 %type <lval> positional_list component_groups component_associations
177 %type <lval> aggregate_component_list
178 %type <tval> var_or_type
180 %token <typed_val> INT NULL_PTR CHARLIT
181 %token <typed_val_float> FLOAT
183 %token <sval> STRING NAME DOT_ID
185 %type <lval> arglist tick_arglist
187 %type <tval> save_qualifier
191 /* Special type cases, put in to allow the parser to distinguish different
193 %token <sval> SPECIAL_VARIABLE
196 %left _AND_ OR XOR THEN ELSE
197 %left '=' NOTEQUAL '<' '>' LEQ GEQ IN DOTDOT
201 %left '*' '/' MOD REM
202 %right STARSTAR ABS NOT
204 /* Artificial token to give NAME => ... and NAME | priority over reducing
205 NAME to <primary> and to give <primary>' priority over reducing <primary>
211 %right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
212 %right TICK_MAX TICK_MIN TICK_MODULUS
213 %right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
214 /* The following are right-associative only so that reductions at this
215 precedence have lower precedence than '.' and '('. The syntax still
216 forces a.b.c, e.g., to be LEFT-associated. */
217 %right '.' '(' '[' DOT_ID DOT_ALL
227 /* Expressions, including the sequencing operator. */
230 { write_exp_elt_opcode (BINOP_COMMA); }
231 | primary ASSIGN exp /* Extension for convenience */
232 { write_exp_elt_opcode (BINOP_ASSIGN); }
235 /* Expressions, not including the sequencing operator. */
236 primary : primary DOT_ALL
237 { write_exp_elt_opcode (UNOP_IND); }
240 primary : primary DOT_ID
241 { write_exp_op_with_string (STRUCTOP_STRUCT, $2); }
244 primary : primary '(' arglist ')'
246 write_exp_elt_opcode (OP_FUNCALL);
247 write_exp_elt_longcst ($3);
248 write_exp_elt_opcode (OP_FUNCALL);
250 | var_or_type '(' arglist ')'
255 error (_("Invalid conversion"));
256 write_exp_elt_opcode (UNOP_CAST);
257 write_exp_elt_type ($1);
258 write_exp_elt_opcode (UNOP_CAST);
262 write_exp_elt_opcode (OP_FUNCALL);
263 write_exp_elt_longcst ($3);
264 write_exp_elt_opcode (OP_FUNCALL);
269 primary : var_or_type '\'' save_qualifier { type_qualifier = $1; }
273 error (_("Type required for qualification"));
274 write_exp_elt_opcode (UNOP_QUAL);
275 write_exp_elt_type ($1);
276 write_exp_elt_opcode (UNOP_QUAL);
281 save_qualifier : { $$ = type_qualifier; }
285 primary '(' simple_exp DOTDOT simple_exp ')'
286 { write_exp_elt_opcode (TERNOP_SLICE); }
287 | var_or_type '(' simple_exp DOTDOT simple_exp ')'
289 write_exp_elt_opcode (TERNOP_SLICE);
291 error (_("Cannot slice a type"));
295 primary : '(' exp1 ')' { }
298 /* The following rule causes a conflict with the type conversion
300 To get around it, we give '(' higher priority and add bridge rules for
301 var_or_type (exp, exp, ...)
302 var_or_type (exp .. exp)
303 We also have the action for var_or_type(exp) generate a function call
304 when the first symbol does not denote a type. */
306 primary : var_or_type %prec VAR
309 write_exp_elt_opcode (OP_TYPE);
310 write_exp_elt_type ($1);
311 write_exp_elt_opcode (OP_TYPE);
316 primary : SPECIAL_VARIABLE /* Various GDB extensions */
317 { write_dollar_variable ($1); }
326 simple_exp : '-' simple_exp %prec UNARY
327 { write_exp_elt_opcode (UNOP_NEG); }
330 simple_exp : '+' simple_exp %prec UNARY
331 { write_exp_elt_opcode (UNOP_PLUS); }
334 simple_exp : NOT simple_exp %prec UNARY
335 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
338 simple_exp : ABS simple_exp %prec UNARY
339 { write_exp_elt_opcode (UNOP_ABS); }
342 arglist : { $$ = 0; }
351 | arglist ',' NAME ARROW exp
355 simple_exp : '{' var_or_type '}' simple_exp %prec '.'
359 error (_("Type required within braces in coercion"));
360 write_exp_elt_opcode (UNOP_MEMVAL);
361 write_exp_elt_type ($2);
362 write_exp_elt_opcode (UNOP_MEMVAL);
366 /* Binary operators in order of decreasing precedence. */
368 simple_exp : simple_exp STARSTAR simple_exp
369 { write_exp_elt_opcode (BINOP_EXP); }
372 simple_exp : simple_exp '*' simple_exp
373 { write_exp_elt_opcode (BINOP_MUL); }
376 simple_exp : simple_exp '/' simple_exp
377 { write_exp_elt_opcode (BINOP_DIV); }
380 simple_exp : simple_exp REM simple_exp /* May need to be fixed to give correct Ada REM */
381 { write_exp_elt_opcode (BINOP_REM); }
384 simple_exp : simple_exp MOD simple_exp
385 { write_exp_elt_opcode (BINOP_MOD); }
388 simple_exp : simple_exp '@' simple_exp /* GDB extension */
389 { write_exp_elt_opcode (BINOP_REPEAT); }
392 simple_exp : simple_exp '+' simple_exp
393 { write_exp_elt_opcode (BINOP_ADD); }
396 simple_exp : simple_exp '&' simple_exp
397 { write_exp_elt_opcode (BINOP_CONCAT); }
400 simple_exp : simple_exp '-' simple_exp
401 { write_exp_elt_opcode (BINOP_SUB); }
404 relation : simple_exp
407 relation : simple_exp '=' simple_exp
408 { write_exp_elt_opcode (BINOP_EQUAL); }
411 relation : simple_exp NOTEQUAL simple_exp
412 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
415 relation : simple_exp LEQ simple_exp
416 { write_exp_elt_opcode (BINOP_LEQ); }
419 relation : simple_exp IN simple_exp DOTDOT simple_exp
420 { write_exp_elt_opcode (TERNOP_IN_RANGE); }
421 | simple_exp IN primary TICK_RANGE tick_arglist
422 { write_exp_elt_opcode (BINOP_IN_BOUNDS);
423 write_exp_elt_longcst ((LONGEST) $5);
424 write_exp_elt_opcode (BINOP_IN_BOUNDS);
426 | simple_exp IN var_or_type %prec TICK_ACCESS
429 error (_("Right operand of 'in' must be type"));
430 write_exp_elt_opcode (UNOP_IN_RANGE);
431 write_exp_elt_type ($3);
432 write_exp_elt_opcode (UNOP_IN_RANGE);
434 | simple_exp NOT IN simple_exp DOTDOT simple_exp
435 { write_exp_elt_opcode (TERNOP_IN_RANGE);
436 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
438 | simple_exp NOT IN primary TICK_RANGE tick_arglist
439 { write_exp_elt_opcode (BINOP_IN_BOUNDS);
440 write_exp_elt_longcst ((LONGEST) $6);
441 write_exp_elt_opcode (BINOP_IN_BOUNDS);
442 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
444 | simple_exp NOT IN var_or_type %prec TICK_ACCESS
447 error (_("Right operand of 'in' must be type"));
448 write_exp_elt_opcode (UNOP_IN_RANGE);
449 write_exp_elt_type ($4);
450 write_exp_elt_opcode (UNOP_IN_RANGE);
451 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
455 relation : simple_exp GEQ simple_exp
456 { write_exp_elt_opcode (BINOP_GEQ); }
459 relation : simple_exp '<' simple_exp
460 { write_exp_elt_opcode (BINOP_LESS); }
463 relation : simple_exp '>' simple_exp
464 { write_exp_elt_opcode (BINOP_GTR); }
476 relation _AND_ relation
477 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
478 | and_exp _AND_ relation
479 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
483 relation _AND_ THEN relation
484 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
485 | and_then_exp _AND_ THEN relation
486 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
491 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
493 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
497 relation OR ELSE relation
498 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
499 | or_else_exp OR ELSE relation
500 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
503 xor_exp : relation XOR relation
504 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
505 | xor_exp XOR relation
506 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
509 /* Primaries can denote types (OP_TYPE). In cases such as
510 primary TICK_ADDRESS, where a type would be invalid, it will be
511 caught when evaluate_subexp in ada-lang.c tries to evaluate the
512 primary, expecting a value. Precedence rules resolve the ambiguity
513 in NAME TICK_ACCESS in favor of shifting to form a var_or_type. A
514 construct such as aType'access'access will again cause an error when
515 aType'access evaluates to a type that evaluate_subexp attempts to
517 primary : primary TICK_ACCESS
518 { write_exp_elt_opcode (UNOP_ADDR); }
519 | primary TICK_ADDRESS
520 { write_exp_elt_opcode (UNOP_ADDR);
521 write_exp_elt_opcode (UNOP_CAST);
522 write_exp_elt_type (type_system_address ());
523 write_exp_elt_opcode (UNOP_CAST);
525 | primary TICK_FIRST tick_arglist
526 { write_int ($3, type_int ());
527 write_exp_elt_opcode (OP_ATR_FIRST); }
528 | primary TICK_LAST tick_arglist
529 { write_int ($3, type_int ());
530 write_exp_elt_opcode (OP_ATR_LAST); }
531 | primary TICK_LENGTH tick_arglist
532 { write_int ($3, type_int ());
533 write_exp_elt_opcode (OP_ATR_LENGTH); }
535 { write_exp_elt_opcode (OP_ATR_SIZE); }
537 { write_exp_elt_opcode (OP_ATR_TAG); }
538 | opt_type_prefix TICK_MIN '(' exp ',' exp ')'
539 { write_exp_elt_opcode (OP_ATR_MIN); }
540 | opt_type_prefix TICK_MAX '(' exp ',' exp ')'
541 { write_exp_elt_opcode (OP_ATR_MAX); }
542 | opt_type_prefix TICK_POS '(' exp ')'
543 { write_exp_elt_opcode (OP_ATR_POS); }
544 | type_prefix TICK_VAL '(' exp ')'
545 { write_exp_elt_opcode (OP_ATR_VAL); }
546 | type_prefix TICK_MODULUS
547 { write_exp_elt_opcode (OP_ATR_MODULUS); }
550 tick_arglist : %prec '('
560 error (_("Prefix must be type"));
561 write_exp_elt_opcode (OP_TYPE);
562 write_exp_elt_type ($1);
563 write_exp_elt_opcode (OP_TYPE); }
569 { write_exp_elt_opcode (OP_TYPE);
570 write_exp_elt_type (builtin_type_void);
571 write_exp_elt_opcode (OP_TYPE); }
576 { write_int ((LONGEST) $1.val, $1.type); }
580 { write_int (convert_char_literal (type_qualifier, $1.val),
581 (type_qualifier == NULL)
582 ? $1.type : type_qualifier);
587 { write_exp_elt_opcode (OP_DOUBLE);
588 write_exp_elt_type ($1.type);
589 write_exp_elt_dblcst ($1.dval);
590 write_exp_elt_opcode (OP_DOUBLE);
595 { write_int (0, type_int ()); }
600 write_exp_op_with_string (OP_STRING, $1);
605 { error (_("NEW not implemented.")); }
608 var_or_type: NAME %prec VAR
609 { $$ = write_var_or_type (NULL, $1); }
610 | block NAME %prec VAR
611 { $$ = write_var_or_type ($1, $2); }
614 $$ = write_var_or_type (NULL, $1);
616 write_exp_elt_opcode (UNOP_ADDR);
618 $$ = lookup_pointer_type ($$);
620 | block NAME TICK_ACCESS
622 $$ = write_var_or_type ($1, $2);
624 write_exp_elt_opcode (UNOP_ADDR);
626 $$ = lookup_pointer_type ($$);
631 block : NAME COLONCOLON
632 { $$ = block_lookup (NULL, $1.ptr); }
633 | block NAME COLONCOLON
634 { $$ = block_lookup ($1, $2.ptr); }
638 '(' aggregate_component_list ')'
640 write_exp_elt_opcode (OP_AGGREGATE);
641 write_exp_elt_longcst ($2);
642 write_exp_elt_opcode (OP_AGGREGATE);
646 aggregate_component_list :
647 component_groups { $$ = $1; }
648 | positional_list exp
649 { write_exp_elt_opcode (OP_POSITIONAL);
650 write_exp_elt_longcst ($1);
651 write_exp_elt_opcode (OP_POSITIONAL);
654 | positional_list component_groups
660 { write_exp_elt_opcode (OP_POSITIONAL);
661 write_exp_elt_longcst (0);
662 write_exp_elt_opcode (OP_POSITIONAL);
665 | positional_list exp ','
666 { write_exp_elt_opcode (OP_POSITIONAL);
667 write_exp_elt_longcst ($1);
668 write_exp_elt_opcode (OP_POSITIONAL);
675 | component_group { $$ = 1; }
676 | component_group ',' component_groups
680 others : OTHERS ARROW exp
681 { write_exp_elt_opcode (OP_OTHERS); }
685 component_associations
687 write_exp_elt_opcode (OP_CHOICES);
688 write_exp_elt_longcst ($1);
689 write_exp_elt_opcode (OP_CHOICES);
693 /* We use this somewhat obscure definition in order to handle NAME => and
694 NAME | differently from exp => and exp |. ARROW and '|' have a precedence
695 above that of the reduction of NAME to var_or_type. By delaying
696 decisions until after the => or '|', we convert the ambiguity to a
697 resolved shift/reduce conflict. */
698 component_associations :
700 { write_name_assoc ($1); }
702 | simple_exp ARROW exp
704 | simple_exp DOTDOT simple_exp ARROW
705 { write_exp_elt_opcode (OP_DISCRETE_RANGE);
706 write_exp_op_with_string (OP_NAME, empty_stoken);
710 { write_name_assoc ($1); }
711 component_associations { $$ = $4 + 1; }
713 component_associations { $$ = $3 + 1; }
714 | simple_exp DOTDOT simple_exp '|'
715 { write_exp_elt_opcode (OP_DISCRETE_RANGE); }
716 component_associations { $$ = $6 + 1; }
719 /* Some extensions borrowed from C, for the benefit of those who find they
720 can't get used to Ada notation in GDB. */
722 primary : '*' primary %prec '.'
723 { write_exp_elt_opcode (UNOP_IND); }
724 | '&' primary %prec '.'
725 { write_exp_elt_opcode (UNOP_ADDR); }
726 | primary '[' exp ']'
727 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
732 /* yylex defined in ada-lex.c: Reads one token, getting characters */
733 /* through lexptr. */
735 /* Remap normal flex interface names (yylex) as well as gratuitiously */
736 /* global symbol names, so we can have multiple flex-generated parsers */
739 /* (See note above on previous definitions for YACC.) */
741 #define yy_create_buffer ada_yy_create_buffer
742 #define yy_delete_buffer ada_yy_delete_buffer
743 #define yy_init_buffer ada_yy_init_buffer
744 #define yy_load_buffer_state ada_yy_load_buffer_state
745 #define yy_switch_to_buffer ada_yy_switch_to_buffer
746 #define yyrestart ada_yyrestart
747 #define yytext ada_yytext
748 #define yywrap ada_yywrap
750 static struct obstack temp_parse_space;
752 /* The following kludge was found necessary to prevent conflicts between */
753 /* defs.h and non-standard stdlib.h files. */
754 #define qsort __qsort__dummy
760 lexer_init (yyin); /* (Re-)initialize lexer. */
761 type_qualifier = NULL;
762 obstack_free (&temp_parse_space, NULL);
763 obstack_init (&temp_parse_space);
765 return _ada_parse ();
771 error (_("Error in expression, near `%s'."), lexptr);
774 /* The operator name corresponding to operator symbol STRING (adds
775 quotes and maps to lower-case). Destroys the previous contents of
776 the array pointed to by STRING.ptr. Error if STRING does not match
777 a valid Ada operator. Assumes that STRING.ptr points to a
778 null-terminated string and that, if STRING is a valid operator
779 symbol, the array pointed to by STRING.ptr contains at least
780 STRING.length+3 characters. */
783 string_to_operator (struct stoken string)
787 for (i = 0; ada_opname_table[i].encoded != NULL; i += 1)
789 if (string.length == strlen (ada_opname_table[i].decoded)-2
790 && strncasecmp (string.ptr, ada_opname_table[i].decoded+1,
793 strncpy (string.ptr, ada_opname_table[i].decoded,
799 error (_("Invalid operator symbol `%s'"), string.ptr);
802 /* Emit expression to access an instance of SYM, in block BLOCK (if
803 * non-NULL), and with :: qualification ORIG_LEFT_CONTEXT. */
805 write_var_from_sym (struct block *orig_left_context,
809 if (orig_left_context == NULL && symbol_read_needs_frame (sym))
811 if (innermost_block == 0
812 || contained_in (block, innermost_block))
813 innermost_block = block;
816 write_exp_elt_opcode (OP_VAR_VALUE);
817 write_exp_elt_block (block);
818 write_exp_elt_sym (sym);
819 write_exp_elt_opcode (OP_VAR_VALUE);
822 /* Write integer constant ARG of type TYPE. */
825 write_int (LONGEST arg, struct type *type)
827 write_exp_elt_opcode (OP_LONG);
828 write_exp_elt_type (type);
829 write_exp_elt_longcst (arg);
830 write_exp_elt_opcode (OP_LONG);
833 /* Write an OPCODE, string, OPCODE sequence to the current expression. */
835 write_exp_op_with_string (enum exp_opcode opcode, struct stoken token)
837 write_exp_elt_opcode (opcode);
838 write_exp_string (token);
839 write_exp_elt_opcode (opcode);
842 /* Emit expression corresponding to the renamed object designated by
843 * the type RENAMING, which must be the referent of an object renaming
844 * type, in the context of ORIG_LEFT_CONTEXT. MAX_DEPTH is the maximum
845 * number of cascaded renamings to allow. */
847 write_object_renaming (struct block *orig_left_context,
848 struct symbol *renaming, int max_depth)
850 const char *qualification = SYMBOL_LINKAGE_NAME (renaming);
851 const char *simple_tail;
852 const char *expr = TYPE_FIELD_NAME (SYMBOL_TYPE (renaming), 0);
856 enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
859 error (_("Could not find renamed symbol"));
861 /* if orig_left_context is null, then use the currently selected
862 block; otherwise we might fail our symbol lookup below. */
863 if (orig_left_context == NULL)
864 orig_left_context = get_selected_block (NULL);
866 for (simple_tail = qualification + strlen (qualification);
867 simple_tail != qualification; simple_tail -= 1)
869 if (*simple_tail == '.')
874 else if (strncmp (simple_tail, "__", 2) == 0)
881 suffix = strstr (expr, "___XE");
885 name = (char *) obstack_alloc (&temp_parse_space, suffix - expr + 1);
886 strncpy (name, expr, suffix-expr);
887 name[suffix-expr] = '\000';
888 sym = lookup_symbol (name, orig_left_context, VAR_DOMAIN, 0, NULL);
890 error (_("Could not find renamed variable: %s"), ada_decode (name));
891 if (ada_is_object_renaming (sym))
892 write_object_renaming (orig_left_context, sym, max_depth-1);
894 write_var_from_sym (orig_left_context, block_found, sym);
897 slice_state = SIMPLE_INDEX;
898 while (*suffix == 'X')
905 write_exp_elt_opcode (UNOP_IND);
908 slice_state = LOWER_BOUND;
911 if (isdigit (*suffix))
914 long val = strtol (suffix, &next, 10);
918 write_exp_elt_opcode (OP_LONG);
919 write_exp_elt_type (type_int ());
920 write_exp_elt_longcst ((LONGEST) val);
921 write_exp_elt_opcode (OP_LONG);
928 struct symbol *index_sym;
930 end = strchr (suffix, 'X');
932 end = suffix + strlen (suffix);
934 index_len = simple_tail - qualification + 2 + (suffix - end) + 1;
936 = (char *) obstack_alloc (&temp_parse_space, index_len);
937 memset (index_name, '\000', index_len);
938 strncpy (index_name, qualification, simple_tail - qualification);
939 index_name[simple_tail - qualification] = '\000';
940 strncat (index_name, suffix, suffix-end);
944 lookup_symbol (index_name, NULL, VAR_DOMAIN, 0, NULL);
945 if (index_sym == NULL)
946 error (_("Could not find %s"), index_name);
947 write_var_from_sym (NULL, block_found, sym);
949 if (slice_state == SIMPLE_INDEX)
951 write_exp_elt_opcode (OP_FUNCALL);
952 write_exp_elt_longcst ((LONGEST) 1);
953 write_exp_elt_opcode (OP_FUNCALL);
955 else if (slice_state == LOWER_BOUND)
956 slice_state = UPPER_BOUND;
957 else if (slice_state == UPPER_BOUND)
959 write_exp_elt_opcode (TERNOP_SLICE);
960 slice_state = SIMPLE_INDEX;
966 struct stoken field_name;
970 if (slice_state != SIMPLE_INDEX)
972 end = strchr (suffix, 'X');
974 end = suffix + strlen (suffix);
975 field_name.length = end - suffix;
976 field_name.ptr = xmalloc (end - suffix + 1);
977 strncpy (field_name.ptr, suffix, end - suffix);
978 field_name.ptr[end - suffix] = '\000';
980 write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
988 if (slice_state == SIMPLE_INDEX)
992 error (_("Internal error in encoding of renaming declaration: %s"),
993 SYMBOL_LINKAGE_NAME (renaming));
997 block_lookup (struct block *context, char *raw_name)
1000 struct ada_symbol_info *syms;
1002 struct symtab *symtab;
1004 if (raw_name[0] == '\'')
1010 name = ada_encode (raw_name);
1012 nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms);
1013 if (context == NULL &&
1014 (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK))
1015 symtab = lookup_symtab (name);
1020 return BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
1021 else if (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK)
1023 if (context == NULL)
1024 error (_("No file or function \"%s\"."), raw_name);
1026 error (_("No function \"%s\" in specified context."), raw_name);
1031 warning (_("Function name \"%s\" ambiguous here"), raw_name);
1032 return SYMBOL_BLOCK_VALUE (syms[0].sym);
1036 static struct symbol*
1037 select_possible_type_sym (struct ada_symbol_info *syms, int nsyms)
1040 int preferred_index;
1041 struct type *preferred_type;
1043 preferred_index = -1; preferred_type = NULL;
1044 for (i = 0; i < nsyms; i += 1)
1045 switch (SYMBOL_CLASS (syms[i].sym))
1048 if (ada_prefer_type (SYMBOL_TYPE (syms[i].sym), preferred_type))
1050 preferred_index = i;
1051 preferred_type = SYMBOL_TYPE (syms[i].sym);
1058 case LOC_REGPARM_ADDR:
1062 case LOC_BASEREG_ARG:
1064 case LOC_COMPUTED_ARG:
1069 if (preferred_type == NULL)
1071 return syms[preferred_index].sym;
1075 find_primitive_type (char *name)
1078 type = language_lookup_primitive_type_by_name (current_language,
1081 if (type == NULL && strcmp ("system__address", name) == 0)
1082 type = type_system_address ();
1086 /* Check to see if we have a regular definition of this
1087 type that just didn't happen to have been read yet. */
1090 char *expanded_name =
1091 (char *) alloca (strlen (name) + sizeof ("standard__"));
1092 strcpy (expanded_name, "standard__");
1093 strcat (expanded_name, name);
1094 sym = ada_lookup_symbol (expanded_name, NULL, VAR_DOMAIN, NULL, NULL);
1095 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1096 type = SYMBOL_TYPE (sym);
1103 chop_selector (char *name, int end)
1106 for (i = end - 1; i > 0; i -= 1)
1107 if (name[i] == '.' || (name[i] == '_' && name[i+1] == '_'))
1112 /* Given that SELS is a string of the form (<sep><identifier>)*, where
1113 <sep> is '__' or '.', write the indicated sequence of
1114 STRUCTOP_STRUCT expression operators. */
1116 write_selectors (char *sels)
1118 while (*sels != '\0')
1120 struct stoken field_name;
1122 while (*sels == '_' || *sels == '.')
1125 while (*sels != '\0' && *sels != '.'
1126 && (sels[0] != '_' || sels[1] != '_'))
1128 field_name.length = sels - p;
1130 write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
1134 /* Write a variable access (OP_VAR_VALUE) to ambiguous encoded name
1135 NAME[0..LEN-1], in block context BLOCK, to be resolved later. Writes
1136 a temporary symbol that is valid until the next call to ada_parse.
1139 write_ambiguous_var (struct block *block, char *name, int len)
1141 struct symbol *sym =
1142 obstack_alloc (&temp_parse_space, sizeof (struct symbol));
1143 memset (sym, 0, sizeof (struct symbol));
1144 SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
1145 SYMBOL_LINKAGE_NAME (sym) = obsavestring (name, len, &temp_parse_space);
1146 SYMBOL_LANGUAGE (sym) = language_ada;
1148 write_exp_elt_opcode (OP_VAR_VALUE);
1149 write_exp_elt_block (block);
1150 write_exp_elt_sym (sym);
1151 write_exp_elt_opcode (OP_VAR_VALUE);
1155 /* Look up NAME0 (an unencoded identifier or dotted name) in BLOCK (or
1156 expression_block_context if NULL). If it denotes a type, return
1157 that type. Otherwise, write expression code to evaluate it as an
1158 object and return NULL. In this second case, NAME0 will, in general,
1159 have the form <name>(.<selector_name>)*, where <name> is an object
1160 or renaming encoded in the debugging data. Calls error if no
1161 prefix <name> matches a name in the debugging data (i.e., matches
1162 either a complete name or, as a wild-card match, the final
1166 write_var_or_type (struct block *block, struct stoken name0)
1173 block = expression_context_block;
1175 encoded_name = ada_encode (name0.ptr);
1176 name_len = strlen (encoded_name);
1177 encoded_name = obsavestring (encoded_name, name_len, &temp_parse_space);
1178 for (depth = 0; depth < MAX_RENAMING_CHAIN_LENGTH; depth += 1)
1182 tail_index = name_len;
1183 while (tail_index > 0)
1186 struct ada_symbol_info *syms;
1187 struct symbol *type_sym;
1188 int terminator = encoded_name[tail_index];
1190 encoded_name[tail_index] = '\0';
1191 nsyms = ada_lookup_symbol_list (encoded_name, block,
1193 encoded_name[tail_index] = terminator;
1195 /* A single symbol may rename a package or object. */
1197 if (nsyms == 1 && !ada_is_object_renaming (syms[0].sym))
1199 struct symbol *renaming_sym =
1200 ada_find_renaming_symbol (SYMBOL_LINKAGE_NAME (syms[0].sym),
1203 if (renaming_sym != NULL)
1204 syms[0].sym = renaming_sym;
1207 type_sym = select_possible_type_sym (syms, nsyms);
1208 if (type_sym != NULL)
1210 struct type *type = SYMBOL_TYPE (type_sym);
1212 if (TYPE_CODE (type) == TYPE_CODE_VOID)
1213 error (_("`%s' matches only void type name(s)"), name0.ptr);
1214 else if (ada_is_object_renaming (type_sym))
1216 write_object_renaming (block, type_sym,
1217 MAX_RENAMING_CHAIN_LENGTH);
1218 write_selectors (encoded_name + tail_index);
1221 else if (ada_renaming_type (SYMBOL_TYPE (type_sym)) != NULL)
1224 char *renaming = ada_simple_renamed_entity (type_sym);
1225 int renaming_len = strlen (renaming);
1228 = obstack_alloc (&temp_parse_space,
1229 renaming_len + name_len - tail_index
1231 strcpy (new_name, renaming);
1233 strcpy (new_name + renaming_len, encoded_name + tail_index);
1234 encoded_name = new_name;
1235 name_len = renaming_len + name_len - tail_index;
1236 goto TryAfterRenaming;
1238 else if (tail_index == name_len)
1241 error (_("Invalid attempt to select from type: \"%s\"."), name0.ptr);
1243 else if (tail_index == name_len && nsyms == 0)
1245 struct type *type = find_primitive_type (encoded_name);
1253 write_var_from_sym (block, syms[0].block, syms[0].sym);
1254 write_selectors (encoded_name + tail_index);
1257 else if (nsyms == 0)
1260 struct minimal_symbol *msym
1261 = ada_lookup_simple_minsym (encoded_name);
1264 write_exp_msymbol (msym, lookup_function_type (type_int ()),
1266 /* Maybe cause error here rather than later? FIXME? */
1267 write_selectors (encoded_name + tail_index);
1271 if (tail_index == name_len
1272 && strncmp (encoded_name, "standard__",
1273 sizeof ("standard__") - 1) == 0)
1274 error (_("No definition of \"%s\" found."), name0.ptr);
1276 tail_index = chop_selector (encoded_name, tail_index);
1280 write_ambiguous_var (block, encoded_name, tail_index);
1281 write_selectors (encoded_name + tail_index);
1286 if (!have_full_symbols () && !have_partial_symbols () && block == NULL)
1287 error (_("No symbol table is loaded. Use the \"file\" command."));
1288 if (block == expression_context_block)
1289 error (_("No definition of \"%s\" in current context."), name0.ptr);
1291 error (_("No definition of \"%s\" in specified context."), name0.ptr);
1296 error (_("Could not find renamed symbol \"%s\""), name0.ptr);
1300 /* Write a left side of a component association (e.g., NAME in NAME =>
1301 exp). If NAME has the form of a selected component, write it as an
1302 ordinary expression. If it is a simple variable that unambiguously
1303 corresponds to exactly one symbol that does not denote a type or an
1304 object renaming, also write it normally as an OP_VAR_VALUE.
1305 Otherwise, write it as an OP_NAME.
1307 Unfortunately, we don't know at this point whether NAME is supposed
1308 to denote a record component name or the value of an array index.
1309 Therefore, it is not appropriate to disambiguate an ambiguous name
1310 as we normally would, nor to replace a renaming with its referent.
1311 As a result, in the (one hopes) rare case that one writes an
1312 aggregate such as (R => 42) where R renames an object or is an
1313 ambiguous name, one must write instead ((R) => 42). */
1316 write_name_assoc (struct stoken name)
1318 if (strchr (name.ptr, '.') == NULL)
1320 struct ada_symbol_info *syms;
1321 int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
1323 if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF)
1324 write_exp_op_with_string (OP_NAME, name);
1326 write_var_from_sym (NULL, syms[0].block, syms[0].sym);
1329 if (write_var_or_type (NULL, name) != NULL)
1330 error (_("Invalid use of type."));
1333 /* Convert the character literal whose ASCII value would be VAL to the
1334 appropriate value of type TYPE, if there is a translation.
1335 Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
1336 the literal 'A' (VAL == 65), returns 0. */
1339 convert_char_literal (struct type *type, LONGEST val)
1344 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM)
1346 sprintf (name, "QU%02x", (int) val);
1347 for (f = 0; f < TYPE_NFIELDS (type); f += 1)
1349 if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0)
1350 return TYPE_FIELD_BITPOS (type, f);
1355 static struct type *
1358 return builtin_type (current_gdbarch)->builtin_int;
1361 static struct type *
1364 return builtin_type (current_gdbarch)->builtin_long;
1367 static struct type *
1368 type_long_long (void)
1370 return builtin_type (current_gdbarch)->builtin_long_long;
1373 static struct type *
1376 return builtin_type (current_gdbarch)->builtin_float;
1379 static struct type *
1382 return builtin_type (current_gdbarch)->builtin_double;
1385 static struct type *
1386 type_long_double (void)
1388 return builtin_type (current_gdbarch)->builtin_long_double;
1391 static struct type *
1394 return language_string_char_type (current_language, current_gdbarch);
1397 static struct type *
1398 type_system_address (void)
1401 = language_lookup_primitive_type_by_name (current_language,
1404 return type != NULL ? type : lookup_pointer_type (builtin_type_void);
1408 _initialize_ada_exp (void)
1410 obstack_init (&temp_parse_space);
1413 /* FIXME: hilfingr/2004-10-05: Hack to remove warning. The function
1414 string_to_operator is supposed to be used for cases where one
1415 calls an operator function with prefix notation, as in
1416 "+" (a, b), but at some point, this code seems to have gone
1419 struct stoken (*dummy_string_to_ada_operator) (struct stoken)
1420 = string_to_operator;