1 /* YACC parser for Ada expressions, for GDB.
2 Copyright (C) 1986-2023 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* Parse an Ada expression from text in a string,
20 and return the result as a struct expression pointer.
21 That structure contains arithmetic operations in reverse polish,
22 with constants represented by operations that are followed by special data.
23 See expression.h for the details of the format.
24 What is important here is that it can be built up sequentially
25 during the process of parsing; the lower levels of the tree always
26 come first in the result.
28 malloc's and realloc's in this file are transformed to
29 xmalloc and xrealloc respectively by the same sed command in the
30 makefile that remaps any other malloc/realloc inserted by the parser
31 generator. Doing this with #defines and trying to control the interaction
32 with include files (<malloc.h> and <stdlib.h> for example) just became
33 too messy, particularly when such includes can be inserted at random
34 times by the parser generator. */
40 #include "expression.h"
42 #include "parser-defs.h"
49 #define parse_type(ps) builtin_type (ps->gdbarch ())
51 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
53 #define GDB_YY_REMAP_PREFIX ada_
58 struct minimal_symbol *msym;
59 const struct block *block;
63 /* The state of the parser, used internally when we are parsing the
66 static struct parser_state *pstate = NULL;
68 /* The original expression string. */
69 static const char *original_expr;
71 /* We don't have a good way to manage non-POD data in Yacc, so store
72 values here. The storage here is only valid for the duration of
74 static std::vector<std::unique_ptr<gdb_mpz>> int_storage;
78 static int yylex (void);
80 static void yyerror (const char *);
82 static void write_int (struct parser_state *, LONGEST, struct type *);
84 static void write_object_renaming (struct parser_state *,
85 const struct block *, const char *, int,
88 static struct type* write_var_or_type (struct parser_state *,
89 const struct block *, struct stoken);
90 static struct type *write_var_or_type_completion (struct parser_state *,
94 static void write_name_assoc (struct parser_state *, struct stoken);
96 static const struct block *block_lookup (const struct block *, const char *);
98 static void write_ambiguous_var (struct parser_state *,
99 const struct block *, const char *, int);
101 static struct type *type_for_char (struct parser_state *, ULONGEST);
103 static struct type *type_system_address (struct parser_state *);
105 static std::string find_completion_bounds (struct parser_state *);
107 using namespace expr;
109 /* Handle Ada type resolution for OP. DEPROCEDURE_P and CONTEXT_TYPE
110 are passed to the resolve method, if called. */
112 resolve (operation_up &&op, bool deprocedure_p, struct type *context_type)
114 operation_up result = std::move (op);
115 ada_resolvable *res = dynamic_cast<ada_resolvable *> (result.get ());
117 return res->replace (std::move (result),
118 pstate->expout.get (),
120 pstate->parse_completion,
121 pstate->block_tracker,
126 /* Like parser_state::pop, but handles Ada type resolution.
127 DEPROCEDURE_P and CONTEXT_TYPE are passed to the resolve method, if
130 ada_pop (bool deprocedure_p = true, struct type *context_type = nullptr)
132 /* Of course it's ok to call parser_state::pop here... */
133 return resolve (pstate->pop (), deprocedure_p, context_type);
136 /* Like parser_state::wrap, but use ada_pop to pop the value. */
141 operation_up arg = ada_pop ();
142 pstate->push_new<T> (std::move (arg));
145 /* Create and push an address-of operation, as appropriate for Ada.
146 If TYPE is not NULL, the resulting operation will be wrapped in a
149 ada_addrof (struct type *type = nullptr)
151 operation_up arg = ada_pop (false);
152 operation_up addr = make_operation<unop_addr_operation> (std::move (arg));
154 = make_operation<ada_wrapped_operation> (std::move (addr));
156 wrapped = make_operation<unop_cast_operation> (std::move (wrapped), type);
157 pstate->push (std::move (wrapped));
160 /* Handle operator overloading. Either returns a function all
161 operation wrapping the arguments, or it returns null, leaving the
162 caller to construct the appropriate operation. If RHS is null, a
163 unary operator is assumed. */
165 maybe_overload (enum exp_opcode op, operation_up &lhs, operation_up &rhs)
167 struct value *args[2];
170 args[0] = lhs->evaluate (nullptr, pstate->expout.get (),
171 EVAL_AVOID_SIDE_EFFECTS);
176 args[1] = rhs->evaluate (nullptr, pstate->expout.get (),
177 EVAL_AVOID_SIDE_EFFECTS);
181 block_symbol fn = ada_find_operator_symbol (op, pstate->parse_completion,
183 if (fn.symbol == nullptr)
186 if (symbol_read_needs_frame (fn.symbol))
187 pstate->block_tracker->update (fn.block, INNERMOST_BLOCK_FOR_SYMBOLS);
188 operation_up callee = make_operation<ada_var_value_operation> (fn);
190 std::vector<operation_up> argvec;
191 argvec.push_back (std::move (lhs));
193 argvec.push_back (std::move (rhs));
194 return make_operation<ada_funcall_operation> (std::move (callee),
198 /* Like parser_state::wrap, but use ada_pop to pop the value, and
199 handle unary overloading. */
202 ada_wrap_overload (enum exp_opcode op)
204 operation_up arg = ada_pop ();
207 operation_up call = maybe_overload (op, arg, empty);
209 call = make_operation<T> (std::move (arg));
210 pstate->push (std::move (call));
213 /* A variant of parser_state::wrap2 that uses ada_pop to pop both
214 operands, and then pushes a new Ada-wrapped operation of the
218 ada_un_wrap2 (enum exp_opcode op)
220 operation_up rhs = ada_pop ();
221 operation_up lhs = ada_pop ();
223 operation_up wrapped = maybe_overload (op, lhs, rhs);
224 if (wrapped == nullptr)
226 wrapped = make_operation<T> (std::move (lhs), std::move (rhs));
227 wrapped = make_operation<ada_wrapped_operation> (std::move (wrapped));
229 pstate->push (std::move (wrapped));
232 /* A variant of parser_state::wrap2 that uses ada_pop to pop both
233 operands. Unlike ada_un_wrap2, ada_wrapped_operation is not
237 ada_wrap2 (enum exp_opcode op)
239 operation_up rhs = ada_pop ();
240 operation_up lhs = ada_pop ();
241 operation_up call = maybe_overload (op, lhs, rhs);
243 call = make_operation<T> (std::move (lhs), std::move (rhs));
244 pstate->push (std::move (call));
247 /* A variant of parser_state::wrap2 that uses ada_pop to pop both
248 operands. OP is also passed to the constructor of the new binary
252 ada_wrap_op (enum exp_opcode op)
254 operation_up rhs = ada_pop ();
255 operation_up lhs = ada_pop ();
256 operation_up call = maybe_overload (op, lhs, rhs);
258 call = make_operation<T> (op, std::move (lhs), std::move (rhs));
259 pstate->push (std::move (call));
262 /* Pop three operands using ada_pop, then construct a new ternary
263 operation of type T and push it. */
268 operation_up rhs = ada_pop ();
269 operation_up mid = ada_pop ();
270 operation_up lhs = ada_pop ();
271 pstate->push_new<T> (std::move (lhs), std::move (mid), std::move (rhs));
274 /* Pop NARGS operands, then a callee operand, and use these to
275 construct and push a new Ada function call operation. */
277 ada_funcall (int nargs)
279 /* We use the ordinary pop here, because we're going to do
280 resolution in a separate step, in order to handle array
282 std::vector<operation_up> args = pstate->pop_vector (nargs);
283 /* Call parser_state::pop here, because we don't want to
284 function-convert the callee slot of a call we're already
286 operation_up callee = pstate->pop ();
288 ada_var_value_operation *vvo
289 = dynamic_cast<ada_var_value_operation *> (callee.get ());
291 struct type *callee_t = nullptr;
293 || vvo->get_symbol ()->domain () != UNDEF_DOMAIN)
295 struct value *callee_v = callee->evaluate (nullptr,
296 pstate->expout.get (),
297 EVAL_AVOID_SIDE_EFFECTS);
298 callee_t = ada_check_typedef (callee_v->type ());
299 array_arity = ada_array_arity (callee_t);
302 for (int i = 0; i < nargs; ++i)
304 struct type *subtype = nullptr;
306 subtype = ada_index_type (callee_t, i + 1, "array type");
307 args[i] = resolve (std::move (args[i]), true, subtype);
310 std::unique_ptr<ada_funcall_operation> funcall
311 (new ada_funcall_operation (std::move (callee), std::move (args)));
312 funcall->resolve (pstate->expout.get (), true, pstate->parse_completion,
313 pstate->block_tracker, nullptr);
314 pstate->push (std::move (funcall));
317 /* The components being constructed during this parse. */
318 static std::vector<ada_component_up> components;
320 /* Create a new ada_component_up of the indicated type and arguments,
321 and push it on the global 'components' vector. */
322 template<typename T, typename... Arg>
324 push_component (Arg... args)
326 components.emplace_back (new T (std::forward<Arg> (args)...));
329 /* Examine the final element of the 'components' vector, and return it
330 as a pointer to an ada_choices_component. The caller is
331 responsible for ensuring that the final element is in fact an
332 ada_choices_component. */
333 static ada_choices_component *
336 ada_component *last = components.back ().get ();
337 return gdb::checked_static_cast<ada_choices_component *> (last);
340 /* Pop the most recent component from the global stack, and return
342 static ada_component_up
345 ada_component_up result = std::move (components.back ());
346 components.pop_back ();
350 /* Pop the N most recent components from the global stack, and return
352 static std::vector<ada_component_up>
353 pop_components (int n)
355 std::vector<ada_component_up> result (n);
356 for (int i = 1; i <= n; ++i)
357 result[n - i] = pop_component ();
361 /* The associations being constructed during this parse. */
362 static std::vector<ada_association_up> associations;
364 /* Create a new ada_association_up of the indicated type and
365 arguments, and push it on the global 'associations' vector. */
366 template<typename T, typename... Arg>
368 push_association (Arg... args)
370 associations.emplace_back (new T (std::forward<Arg> (args)...));
373 /* Pop the most recent association from the global stack, and return
375 static ada_association_up
378 ada_association_up result = std::move (associations.back ());
379 associations.pop_back ();
383 /* Pop the N most recent associations from the global stack, and
384 return them in a vector. */
385 static std::vector<ada_association_up>
386 pop_associations (int n)
388 std::vector<ada_association_up> result (n);
389 for (int i = 1; i <= n; ++i)
390 result[n - i] = pop_association ();
394 /* Expression completer for attributes. */
395 struct ada_tick_completer : public expr_completion_base
397 explicit ada_tick_completer (std::string &&name)
398 : m_name (std::move (name))
402 bool complete (struct expression *exp,
403 completion_tracker &tracker) override;
410 /* Make a new ada_tick_completer and wrap it in a unique pointer. */
411 static std::unique_ptr<expr_completion_base>
412 make_tick_completer (struct stoken tok)
414 return (std::unique_ptr<expr_completion_base>
415 (new ada_tick_completer (std::string (tok.ptr, tok.length))));
437 const struct block *bval;
438 struct internalvar *ivar;
441 %type <lval> positional_list component_groups component_associations
442 %type <lval> aggregate_component_list
443 %type <tval> var_or_type type_prefix opt_type_prefix
445 %token <typed_val> INT NULL_PTR
446 %token <typed_char> CHARLIT
447 %token <typed_val_float> FLOAT
448 %token TRUEKEYWORD FALSEKEYWORD
450 %token <sval> STRING NAME DOT_ID TICK_COMPLETE DOT_COMPLETE NAME_COMPLETE
452 %type <lval> arglist tick_arglist
454 /* Special type cases, put in to allow the parser to distinguish different
456 %token <sval> DOLLAR_VARIABLE
459 %left _AND_ OR XOR THEN ELSE
460 %left '=' NOTEQUAL '<' '>' LEQ GEQ IN DOTDOT
464 %left '*' '/' MOD REM
465 %right STARSTAR ABS NOT
467 /* Artificial token to give NAME => ... and NAME | priority over reducing
468 NAME to <primary> and to give <primary>' priority over reducing <primary>
474 %right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
475 %right TICK_MAX TICK_MIN TICK_MODULUS
476 %right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
477 %right TICK_COMPLETE TICK_ENUM_REP TICK_ENUM_VAL
478 /* The following are right-associative only so that reductions at this
479 precedence have lower precedence than '.' and '('. The syntax still
480 forces a.b.c, e.g., to be LEFT-associated. */
481 %right '.' '(' '[' DOT_ID DOT_COMPLETE
491 /* Expressions, including the sequencing operator. */
494 { ada_wrap2<comma_operation> (BINOP_COMMA); }
495 | primary ASSIGN exp /* Extension for convenience */
497 operation_up rhs = pstate->pop ();
498 operation_up lhs = ada_pop ();
500 = lhs->evaluate (nullptr, pstate->expout.get (),
501 EVAL_AVOID_SIDE_EFFECTS);
502 rhs = resolve (std::move (rhs), true,
504 pstate->push_new<ada_assign_operation>
505 (std::move (lhs), std::move (rhs));
509 /* Expressions, not including the sequencing operator. */
511 primary : primary DOT_ID
513 if (strcmp ($2.ptr, "all") == 0)
514 ada_wrap<ada_unop_ind_operation> ();
517 operation_up arg = ada_pop ();
518 pstate->push_new<ada_structop_operation>
519 (std::move (arg), copy_name ($2));
524 primary : primary DOT_COMPLETE
526 /* This is done even for ".all", because
527 that might be a prefix. */
528 operation_up arg = ada_pop ();
529 ada_structop_operation *str_op
530 = (new ada_structop_operation
531 (std::move (arg), copy_name ($2)));
532 str_op->set_prefix (find_completion_bounds (pstate));
533 pstate->push (operation_up (str_op));
534 pstate->mark_struct_expression (str_op);
538 primary : primary '(' arglist ')'
539 { ada_funcall ($3); }
540 | var_or_type '(' arglist ')'
545 error (_("Invalid conversion"));
546 operation_up arg = ada_pop ();
547 pstate->push_new<unop_cast_operation>
548 (std::move (arg), $1);
555 primary : var_or_type '\'' '(' exp ')'
558 error (_("Type required for qualification"));
559 operation_up arg = ada_pop (true,
561 pstate->push_new<ada_qual_operation>
562 (std::move (arg), $1);
567 primary '(' simple_exp DOTDOT simple_exp ')'
568 { ada_wrap3<ada_ternop_slice_operation> (); }
569 | var_or_type '(' simple_exp DOTDOT simple_exp ')'
571 ada_wrap3<ada_ternop_slice_operation> ();
573 error (_("Cannot slice a type"));
577 primary : '(' exp1 ')' { }
580 /* The following rule causes a conflict with the type conversion
582 To get around it, we give '(' higher priority and add bridge rules for
583 var_or_type (exp, exp, ...)
584 var_or_type (exp .. exp)
585 We also have the action for var_or_type(exp) generate a function call
586 when the first symbol does not denote a type. */
588 primary : var_or_type %prec VAR
590 pstate->push_new<type_operation> ($1);
594 primary : DOLLAR_VARIABLE /* Various GDB extensions */
595 { pstate->push_dollar ($1); }
600 pstate->push_new<ada_aggregate_operation>
608 simple_exp : '-' simple_exp %prec UNARY
609 { ada_wrap_overload<ada_neg_operation> (UNOP_NEG); }
612 simple_exp : '+' simple_exp %prec UNARY
614 operation_up arg = ada_pop ();
617 /* If an overloaded operator was found, use
618 it. Otherwise, unary + has no effect and
619 the argument can be pushed instead. */
620 operation_up call = maybe_overload (UNOP_PLUS, arg,
623 arg = std::move (call);
624 pstate->push (std::move (arg));
628 simple_exp : NOT simple_exp %prec UNARY
630 ada_wrap_overload<unary_logical_not_operation>
635 simple_exp : ABS simple_exp %prec UNARY
636 { ada_wrap_overload<ada_abs_operation> (UNOP_ABS); }
639 arglist : { $$ = 0; }
648 | arglist ',' NAME ARROW exp
652 primary : '{' var_or_type '}' primary %prec '.'
656 error (_("Type required within braces in coercion"));
657 operation_up arg = ada_pop ();
658 pstate->push_new<unop_memval_operation>
659 (std::move (arg), $2);
663 /* Binary operators in order of decreasing precedence. */
665 simple_exp : simple_exp STARSTAR simple_exp
666 { ada_wrap2<ada_binop_exp_operation> (BINOP_EXP); }
669 simple_exp : simple_exp '*' simple_exp
670 { ada_wrap2<ada_binop_mul_operation> (BINOP_MUL); }
673 simple_exp : simple_exp '/' simple_exp
674 { ada_wrap2<ada_binop_div_operation> (BINOP_DIV); }
677 simple_exp : simple_exp REM simple_exp /* May need to be fixed to give correct Ada REM */
678 { ada_wrap2<ada_binop_rem_operation> (BINOP_REM); }
681 simple_exp : simple_exp MOD simple_exp
682 { ada_wrap2<ada_binop_mod_operation> (BINOP_MOD); }
685 simple_exp : simple_exp '@' simple_exp /* GDB extension */
686 { ada_wrap2<repeat_operation> (BINOP_REPEAT); }
689 simple_exp : simple_exp '+' simple_exp
690 { ada_wrap_op<ada_binop_addsub_operation> (BINOP_ADD); }
693 simple_exp : simple_exp '&' simple_exp
694 { ada_wrap2<ada_concat_operation> (BINOP_CONCAT); }
697 simple_exp : simple_exp '-' simple_exp
698 { ada_wrap_op<ada_binop_addsub_operation> (BINOP_SUB); }
701 relation : simple_exp
704 relation : simple_exp '=' simple_exp
705 { ada_wrap_op<ada_binop_equal_operation> (BINOP_EQUAL); }
708 relation : simple_exp NOTEQUAL simple_exp
709 { ada_wrap_op<ada_binop_equal_operation> (BINOP_NOTEQUAL); }
712 relation : simple_exp LEQ simple_exp
713 { ada_un_wrap2<leq_operation> (BINOP_LEQ); }
716 relation : simple_exp IN simple_exp DOTDOT simple_exp
717 { ada_wrap3<ada_ternop_range_operation> (); }
718 | simple_exp IN primary TICK_RANGE tick_arglist
720 operation_up rhs = ada_pop ();
721 operation_up lhs = ada_pop ();
722 pstate->push_new<ada_binop_in_bounds_operation>
723 (std::move (lhs), std::move (rhs), $5);
725 | simple_exp IN var_or_type %prec TICK_ACCESS
728 error (_("Right operand of 'in' must be type"));
729 operation_up arg = ada_pop ();
730 pstate->push_new<ada_unop_range_operation>
731 (std::move (arg), $3);
733 | simple_exp NOT IN simple_exp DOTDOT simple_exp
734 { ada_wrap3<ada_ternop_range_operation> ();
735 ada_wrap<unary_logical_not_operation> (); }
736 | simple_exp NOT IN primary TICK_RANGE tick_arglist
738 operation_up rhs = ada_pop ();
739 operation_up lhs = ada_pop ();
740 pstate->push_new<ada_binop_in_bounds_operation>
741 (std::move (lhs), std::move (rhs), $6);
742 ada_wrap<unary_logical_not_operation> ();
744 | simple_exp NOT IN var_or_type %prec TICK_ACCESS
747 error (_("Right operand of 'in' must be type"));
748 operation_up arg = ada_pop ();
749 pstate->push_new<ada_unop_range_operation>
750 (std::move (arg), $4);
751 ada_wrap<unary_logical_not_operation> ();
755 relation : simple_exp GEQ simple_exp
756 { ada_un_wrap2<geq_operation> (BINOP_GEQ); }
759 relation : simple_exp '<' simple_exp
760 { ada_un_wrap2<less_operation> (BINOP_LESS); }
763 relation : simple_exp '>' simple_exp
764 { ada_un_wrap2<gtr_operation> (BINOP_GTR); }
776 relation _AND_ relation
777 { ada_wrap2<ada_bitwise_and_operation>
778 (BINOP_BITWISE_AND); }
779 | and_exp _AND_ relation
780 { ada_wrap2<ada_bitwise_and_operation>
781 (BINOP_BITWISE_AND); }
785 relation _AND_ THEN relation
786 { ada_wrap2<logical_and_operation>
787 (BINOP_LOGICAL_AND); }
788 | and_then_exp _AND_ THEN relation
789 { ada_wrap2<logical_and_operation>
790 (BINOP_LOGICAL_AND); }
795 { ada_wrap2<ada_bitwise_ior_operation>
796 (BINOP_BITWISE_IOR); }
798 { ada_wrap2<ada_bitwise_ior_operation>
799 (BINOP_BITWISE_IOR); }
803 relation OR ELSE relation
804 { ada_wrap2<logical_or_operation> (BINOP_LOGICAL_OR); }
805 | or_else_exp OR ELSE relation
806 { ada_wrap2<logical_or_operation> (BINOP_LOGICAL_OR); }
809 xor_exp : relation XOR relation
810 { ada_wrap2<ada_bitwise_xor_operation>
811 (BINOP_BITWISE_XOR); }
812 | xor_exp XOR relation
813 { ada_wrap2<ada_bitwise_xor_operation>
814 (BINOP_BITWISE_XOR); }
817 /* Primaries can denote types (OP_TYPE). In cases such as
818 primary TICK_ADDRESS, where a type would be invalid, it will be
819 caught when evaluate_subexp in ada-lang.c tries to evaluate the
820 primary, expecting a value. Precedence rules resolve the ambiguity
821 in NAME TICK_ACCESS in favor of shifting to form a var_or_type. A
822 construct such as aType'access'access will again cause an error when
823 aType'access evaluates to a type that evaluate_subexp attempts to
825 primary : primary TICK_ACCESS
827 | primary TICK_ADDRESS
828 { ada_addrof (type_system_address (pstate)); }
829 | primary TICK_COMPLETE
831 pstate->mark_completion (make_tick_completer ($2));
833 | primary TICK_FIRST tick_arglist
835 operation_up arg = ada_pop ();
836 pstate->push_new<ada_unop_atr_operation>
837 (std::move (arg), OP_ATR_FIRST, $3);
839 | primary TICK_LAST tick_arglist
841 operation_up arg = ada_pop ();
842 pstate->push_new<ada_unop_atr_operation>
843 (std::move (arg), OP_ATR_LAST, $3);
845 | primary TICK_LENGTH tick_arglist
847 operation_up arg = ada_pop ();
848 pstate->push_new<ada_unop_atr_operation>
849 (std::move (arg), OP_ATR_LENGTH, $3);
852 { ada_wrap<ada_atr_size_operation> (); }
854 { ada_wrap<ada_atr_tag_operation> (); }
855 | opt_type_prefix TICK_MIN '(' exp ',' exp ')'
856 { ada_wrap2<ada_binop_min_operation> (BINOP_MIN); }
857 | opt_type_prefix TICK_MAX '(' exp ',' exp ')'
858 { ada_wrap2<ada_binop_max_operation> (BINOP_MAX); }
859 | opt_type_prefix TICK_POS '(' exp ')'
860 { ada_wrap<ada_pos_operation> (); }
861 | type_prefix TICK_VAL '(' exp ')'
863 operation_up arg = ada_pop ();
864 pstate->push_new<ada_atr_val_operation>
865 ($1, std::move (arg));
867 | type_prefix TICK_ENUM_REP '(' exp ')'
869 operation_up arg = ada_pop (true, $1);
870 pstate->push_new<ada_atr_enum_rep_operation>
871 ($1, std::move (arg));
873 | type_prefix TICK_ENUM_VAL '(' exp ')'
875 operation_up arg = ada_pop (true, $1);
876 pstate->push_new<ada_atr_enum_val_operation>
877 ($1, std::move (arg));
879 | type_prefix TICK_MODULUS
881 struct type *type_arg = check_typedef ($1);
882 if (!ada_is_modular_type (type_arg))
883 error (_("'modulus must be applied to modular type"));
884 write_int (pstate, ada_modulus (type_arg),
885 type_arg->target_type ());
889 tick_arglist : %prec '('
892 { $$ = $2.val->as_integer<LONGEST> (); }
899 error (_("Prefix must be type"));
908 { $$ = parse_type (pstate)->builtin_void; }
914 pstate->push_new<long_const_operation> ($1.type, *$1.val);
915 ada_wrap<ada_wrapped_operation> ();
921 pstate->push_new<ada_char_operation> ($1.type, $1.val);
928 std::copy (std::begin ($1.val), std::end ($1.val),
930 pstate->push_new<float_const_operation>
932 ada_wrap<ada_wrapped_operation> ();
938 struct type *null_ptr_type
939 = lookup_pointer_type (parse_type (pstate)->builtin_int0);
940 write_int (pstate, 0, null_ptr_type);
946 pstate->push_new<ada_string_operation>
951 primary : TRUEKEYWORD
953 write_int (pstate, 1,
954 parse_type (pstate)->builtin_bool);
958 write_int (pstate, 0,
959 parse_type (pstate)->builtin_bool);
964 { error (_("NEW not implemented.")); }
967 var_or_type: NAME %prec VAR
968 { $$ = write_var_or_type (pstate, NULL, $1); }
969 | NAME_COMPLETE %prec VAR
971 $$ = write_var_or_type_completion (pstate,
975 | block NAME %prec VAR
976 { $$ = write_var_or_type (pstate, $1, $2); }
977 | block NAME_COMPLETE %prec VAR
979 $$ = write_var_or_type_completion (pstate,
985 $$ = write_var_or_type (pstate, NULL, $1);
989 $$ = lookup_pointer_type ($$);
991 | block NAME TICK_ACCESS
993 $$ = write_var_or_type (pstate, $1, $2);
997 $$ = lookup_pointer_type ($$);
1002 block : NAME COLONCOLON
1003 { $$ = block_lookup (NULL, $1.ptr); }
1004 | block NAME COLONCOLON
1005 { $$ = block_lookup ($1, $2.ptr); }
1009 '(' aggregate_component_list ')'
1011 std::vector<ada_component_up> components
1012 = pop_components ($2);
1014 push_component<ada_aggregate_component>
1015 (std::move (components));
1019 aggregate_component_list :
1020 component_groups { $$ = $1; }
1021 | positional_list exp
1023 push_component<ada_positional_component>
1027 | positional_list component_groups
1034 push_component<ada_positional_component>
1038 | positional_list exp ','
1040 push_component<ada_positional_component>
1048 | component_group { $$ = 1; }
1049 | component_group ',' component_groups
1053 others : OTHERS ARROW exp
1055 push_component<ada_others_component> (ada_pop ());
1060 component_associations
1062 ada_choices_component *choices = choice_component ();
1063 choices->set_associations (pop_associations ($1));
1067 /* We use this somewhat obscure definition in order to handle NAME => and
1068 NAME | differently from exp => and exp |. ARROW and '|' have a precedence
1069 above that of the reduction of NAME to var_or_type. By delaying
1070 decisions until after the => or '|', we convert the ambiguity to a
1071 resolved shift/reduce conflict. */
1072 component_associations :
1075 push_component<ada_choices_component> (ada_pop ());
1076 write_name_assoc (pstate, $1);
1079 | simple_exp ARROW exp
1081 push_component<ada_choices_component> (ada_pop ());
1082 push_association<ada_name_association> (ada_pop ());
1085 | simple_exp DOTDOT simple_exp ARROW exp
1087 push_component<ada_choices_component> (ada_pop ());
1088 operation_up rhs = ada_pop ();
1089 operation_up lhs = ada_pop ();
1090 push_association<ada_discrete_range_association>
1091 (std::move (lhs), std::move (rhs));
1094 | NAME '|' component_associations
1096 write_name_assoc (pstate, $1);
1099 | simple_exp '|' component_associations
1101 push_association<ada_name_association> (ada_pop ());
1104 | simple_exp DOTDOT simple_exp '|' component_associations
1107 operation_up rhs = ada_pop ();
1108 operation_up lhs = ada_pop ();
1109 push_association<ada_discrete_range_association>
1110 (std::move (lhs), std::move (rhs));
1115 /* Some extensions borrowed from C, for the benefit of those who find they
1116 can't get used to Ada notation in GDB. */
1118 primary : '*' primary %prec '.'
1119 { ada_wrap<ada_unop_ind_operation> (); }
1120 | '&' primary %prec '.'
1122 | primary '[' exp ']'
1124 ada_wrap2<subscript_operation> (BINOP_SUBSCRIPT);
1125 ada_wrap<ada_wrapped_operation> ();
1131 /* yylex defined in ada-lex.c: Reads one token, getting characters */
1132 /* through lexptr. */
1134 /* Remap normal flex interface names (yylex) as well as gratuitiously */
1135 /* global symbol names, so we can have multiple flex-generated parsers */
1138 /* (See note above on previous definitions for YACC.) */
1140 #define yy_create_buffer ada_yy_create_buffer
1141 #define yy_delete_buffer ada_yy_delete_buffer
1142 #define yy_init_buffer ada_yy_init_buffer
1143 #define yy_load_buffer_state ada_yy_load_buffer_state
1144 #define yy_switch_to_buffer ada_yy_switch_to_buffer
1145 #define yyrestart ada_yyrestart
1146 #define yytext ada_yytext
1148 static struct obstack temp_parse_space;
1150 /* The following kludge was found necessary to prevent conflicts between */
1151 /* defs.h and non-standard stdlib.h files. */
1152 #define qsort __qsort__dummy
1153 #include "ada-lex.c"
1156 ada_parse (struct parser_state *par_state)
1158 /* Setting up the parser state. */
1159 scoped_restore pstate_restore = make_scoped_restore (&pstate);
1160 gdb_assert (par_state != NULL);
1162 original_expr = par_state->lexptr;
1164 scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
1167 lexer_init (yyin); /* (Re-)initialize lexer. */
1168 obstack_free (&temp_parse_space, NULL);
1169 obstack_init (&temp_parse_space);
1170 components.clear ();
1171 associations.clear ();
1172 int_storage.clear ();
1174 int result = yyparse ();
1177 struct type *context_type = nullptr;
1178 if (par_state->void_context_p)
1179 context_type = parse_type (par_state)->builtin_void;
1180 pstate->set_operation (ada_pop (true, context_type));
1186 yyerror (const char *msg)
1188 error (_("Error in expression, near `%s'."), pstate->lexptr);
1191 /* Emit expression to access an instance of SYM, in block BLOCK (if
1195 write_var_from_sym (struct parser_state *par_state, block_symbol sym)
1197 if (symbol_read_needs_frame (sym.symbol))
1198 par_state->block_tracker->update (sym.block, INNERMOST_BLOCK_FOR_SYMBOLS);
1200 par_state->push_new<ada_var_value_operation> (sym);
1203 /* Write integer or boolean constant ARG of type TYPE. */
1206 write_int (struct parser_state *par_state, LONGEST arg, struct type *type)
1208 pstate->push_new<long_const_operation> (type, arg);
1209 ada_wrap<ada_wrapped_operation> ();
1212 /* Emit expression corresponding to the renamed object named
1213 designated by RENAMED_ENTITY[0 .. RENAMED_ENTITY_LEN-1] in the
1214 context of ORIG_LEFT_CONTEXT, to which is applied the operations
1215 encoded by RENAMING_EXPR. MAX_DEPTH is the maximum number of
1216 cascaded renamings to allow. If ORIG_LEFT_CONTEXT is null, it
1217 defaults to the currently selected block. ORIG_SYMBOL is the
1218 symbol that originally encoded the renaming. It is needed only
1219 because its prefix also qualifies any index variables used to index
1220 or slice an array. It should not be necessary once we go to the
1221 new encoding entirely (FIXME pnh 7/20/2007). */
1224 write_object_renaming (struct parser_state *par_state,
1225 const struct block *orig_left_context,
1226 const char *renamed_entity, int renamed_entity_len,
1227 const char *renaming_expr, int max_depth)
1230 enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
1231 struct block_symbol sym_info;
1234 error (_("Could not find renamed symbol"));
1236 if (orig_left_context == NULL)
1237 orig_left_context = get_selected_block (NULL);
1239 name = obstack_strndup (&temp_parse_space, renamed_entity,
1240 renamed_entity_len);
1241 ada_lookup_encoded_symbol (name, orig_left_context, VAR_DOMAIN, &sym_info);
1242 if (sym_info.symbol == NULL)
1243 error (_("Could not find renamed variable: %s"), ada_decode (name).c_str ());
1244 else if (sym_info.symbol->aclass () == LOC_TYPEDEF)
1245 /* We have a renaming of an old-style renaming symbol. Don't
1246 trust the block information. */
1247 sym_info.block = orig_left_context;
1250 const char *inner_renamed_entity;
1251 int inner_renamed_entity_len;
1252 const char *inner_renaming_expr;
1254 switch (ada_parse_renaming (sym_info.symbol, &inner_renamed_entity,
1255 &inner_renamed_entity_len,
1256 &inner_renaming_expr))
1258 case ADA_NOT_RENAMING:
1259 write_var_from_sym (par_state, sym_info);
1261 case ADA_OBJECT_RENAMING:
1262 write_object_renaming (par_state, sym_info.block,
1263 inner_renamed_entity, inner_renamed_entity_len,
1264 inner_renaming_expr, max_depth - 1);
1271 slice_state = SIMPLE_INDEX;
1272 while (*renaming_expr == 'X')
1276 switch (*renaming_expr) {
1279 ada_wrap<ada_unop_ind_operation> ();
1282 slice_state = LOWER_BOUND;
1286 if (isdigit (*renaming_expr))
1289 long val = strtol (renaming_expr, &next, 10);
1290 if (next == renaming_expr)
1292 renaming_expr = next;
1293 write_int (par_state, val, parse_type (par_state)->builtin_int);
1299 struct block_symbol index_sym_info;
1301 end = strchr (renaming_expr, 'X');
1303 end = renaming_expr + strlen (renaming_expr);
1305 index_name = obstack_strndup (&temp_parse_space, renaming_expr,
1306 end - renaming_expr);
1307 renaming_expr = end;
1309 ada_lookup_encoded_symbol (index_name, orig_left_context,
1310 VAR_DOMAIN, &index_sym_info);
1311 if (index_sym_info.symbol == NULL)
1312 error (_("Could not find %s"), index_name);
1313 else if (index_sym_info.symbol->aclass () == LOC_TYPEDEF)
1314 /* Index is an old-style renaming symbol. */
1315 index_sym_info.block = orig_left_context;
1316 write_var_from_sym (par_state, index_sym_info);
1318 if (slice_state == SIMPLE_INDEX)
1320 else if (slice_state == LOWER_BOUND)
1321 slice_state = UPPER_BOUND;
1322 else if (slice_state == UPPER_BOUND)
1324 ada_wrap3<ada_ternop_slice_operation> ();
1325 slice_state = SIMPLE_INDEX;
1335 if (slice_state != SIMPLE_INDEX)
1337 end = strchr (renaming_expr, 'X');
1339 end = renaming_expr + strlen (renaming_expr);
1341 operation_up arg = ada_pop ();
1342 pstate->push_new<ada_structop_operation>
1343 (std::move (arg), std::string (renaming_expr,
1344 end - renaming_expr));
1345 renaming_expr = end;
1353 if (slice_state == SIMPLE_INDEX)
1357 error (_("Internal error in encoding of renaming declaration"));
1360 static const struct block*
1361 block_lookup (const struct block *context, const char *raw_name)
1364 struct symtab *symtab;
1365 const struct block *result = NULL;
1367 std::string name_storage;
1368 if (raw_name[0] == '\'')
1375 name_storage = ada_encode (raw_name);
1376 name = name_storage.c_str ();
1379 std::vector<struct block_symbol> syms
1380 = ada_lookup_symbol_list (name, context, VAR_DOMAIN);
1383 && (syms.empty () || syms[0].symbol->aclass () != LOC_BLOCK))
1384 symtab = lookup_symtab (name);
1389 result = symtab->compunit ()->blockvector ()->static_block ();
1390 else if (syms.empty () || syms[0].symbol->aclass () != LOC_BLOCK)
1392 if (context == NULL)
1393 error (_("No file or function \"%s\"."), raw_name);
1395 error (_("No function \"%s\" in specified context."), raw_name);
1399 if (syms.size () > 1)
1400 warning (_("Function name \"%s\" ambiguous here"), raw_name);
1401 result = syms[0].symbol->value_block ();
1407 static struct symbol*
1408 select_possible_type_sym (const std::vector<struct block_symbol> &syms)
1411 int preferred_index;
1412 struct type *preferred_type;
1414 preferred_index = -1; preferred_type = NULL;
1415 for (i = 0; i < syms.size (); i += 1)
1416 switch (syms[i].symbol->aclass ())
1419 if (ada_prefer_type (syms[i].symbol->type (), preferred_type))
1421 preferred_index = i;
1422 preferred_type = syms[i].symbol->type ();
1428 case LOC_REGPARM_ADDR:
1435 if (preferred_type == NULL)
1437 return syms[preferred_index].symbol;
1441 find_primitive_type (struct parser_state *par_state, const char *name)
1444 type = language_lookup_primitive_type (par_state->language (),
1445 par_state->gdbarch (),
1447 if (type == NULL && strcmp ("system__address", name) == 0)
1448 type = type_system_address (par_state);
1452 /* Check to see if we have a regular definition of this
1453 type that just didn't happen to have been read yet. */
1455 char *expanded_name =
1456 (char *) alloca (strlen (name) + sizeof ("standard__"));
1457 strcpy (expanded_name, "standard__");
1458 strcat (expanded_name, name);
1459 sym = ada_lookup_symbol (expanded_name, NULL, VAR_DOMAIN).symbol;
1460 if (sym != NULL && sym->aclass () == LOC_TYPEDEF)
1461 type = sym->type ();
1468 chop_selector (const char *name, int end)
1471 for (i = end - 1; i > 0; i -= 1)
1472 if (name[i] == '.' || (name[i] == '_' && name[i+1] == '_'))
1477 /* If NAME is a string beginning with a separator (either '__', or
1478 '.'), chop this separator and return the result; else, return
1482 chop_separator (const char *name)
1487 if (name[0] == '_' && name[1] == '_')
1493 /* Given that SELS is a string of the form (<sep><identifier>)*, where
1494 <sep> is '__' or '.', write the indicated sequence of
1495 STRUCTOP_STRUCT expression operators. Returns a pointer to the
1496 last operation that was pushed. */
1497 static ada_structop_operation *
1498 write_selectors (struct parser_state *par_state, const char *sels)
1500 ada_structop_operation *result = nullptr;
1501 while (*sels != '\0')
1503 const char *p = chop_separator (sels);
1505 while (*sels != '\0' && *sels != '.'
1506 && (sels[0] != '_' || sels[1] != '_'))
1508 operation_up arg = ada_pop ();
1509 result = new ada_structop_operation (std::move (arg),
1510 std::string (p, sels - p));
1511 pstate->push (operation_up (result));
1516 /* Write a variable access (OP_VAR_VALUE) to ambiguous encoded name
1517 NAME[0..LEN-1], in block context BLOCK, to be resolved later. Writes
1518 a temporary symbol that is valid until the next call to ada_parse.
1521 write_ambiguous_var (struct parser_state *par_state,
1522 const struct block *block, const char *name, int len)
1524 struct symbol *sym = new (&temp_parse_space) symbol ();
1526 sym->set_domain (UNDEF_DOMAIN);
1527 sym->set_linkage_name (obstack_strndup (&temp_parse_space, name, len));
1528 sym->set_language (language_ada, nullptr);
1530 block_symbol bsym { sym, block };
1531 par_state->push_new<ada_var_value_operation> (bsym);
1534 /* A convenient wrapper around ada_get_field_index that takes
1535 a non NUL-terminated FIELD_NAME0 and a FIELD_NAME_LEN instead
1536 of a NUL-terminated field name. */
1539 ada_nget_field_index (const struct type *type, const char *field_name0,
1540 int field_name_len, int maybe_missing)
1542 char *field_name = (char *) alloca ((field_name_len + 1) * sizeof (char));
1544 strncpy (field_name, field_name0, field_name_len);
1545 field_name[field_name_len] = '\0';
1546 return ada_get_field_index (type, field_name, maybe_missing);
1549 /* If encoded_field_name is the name of a field inside symbol SYM,
1550 then return the type of that field. Otherwise, return NULL.
1552 This function is actually recursive, so if ENCODED_FIELD_NAME
1553 doesn't match one of the fields of our symbol, then try to see
1554 if ENCODED_FIELD_NAME could not be a succession of field names
1555 (in other words, the user entered an expression of the form
1556 TYPE_NAME.FIELD1.FIELD2.FIELD3), in which case we evaluate
1557 each field name sequentially to obtain the desired field type.
1558 In case of failure, we return NULL. */
1560 static struct type *
1561 get_symbol_field_type (struct symbol *sym, const char *encoded_field_name)
1563 const char *field_name = encoded_field_name;
1564 const char *subfield_name;
1565 struct type *type = sym->type ();
1568 if (type == NULL || field_name == NULL)
1570 type = check_typedef (type);
1572 while (field_name[0] != '\0')
1574 field_name = chop_separator (field_name);
1576 fieldno = ada_get_field_index (type, field_name, 1);
1578 return type->field (fieldno).type ();
1580 subfield_name = field_name;
1581 while (*subfield_name != '\0' && *subfield_name != '.'
1582 && (subfield_name[0] != '_' || subfield_name[1] != '_'))
1585 if (subfield_name[0] == '\0')
1588 fieldno = ada_nget_field_index (type, field_name,
1589 subfield_name - field_name, 1);
1593 type = type->field (fieldno).type ();
1594 field_name = subfield_name;
1600 /* Look up NAME0 (an unencoded identifier or dotted name) in BLOCK (or
1601 expression_block_context if NULL). If it denotes a type, return
1602 that type. Otherwise, write expression code to evaluate it as an
1603 object and return NULL. In this second case, NAME0 will, in general,
1604 have the form <name>(.<selector_name>)*, where <name> is an object
1605 or renaming encoded in the debugging data. Calls error if no
1606 prefix <name> matches a name in the debugging data (i.e., matches
1607 either a complete name or, as a wild-card match, the final
1611 write_var_or_type (struct parser_state *par_state,
1612 const struct block *block, struct stoken name0)
1619 block = par_state->expression_context_block;
1621 std::string name_storage = ada_encode (name0.ptr);
1622 name_len = name_storage.size ();
1623 encoded_name = obstack_strndup (&temp_parse_space, name_storage.c_str (),
1625 for (depth = 0; depth < MAX_RENAMING_CHAIN_LENGTH; depth += 1)
1629 tail_index = name_len;
1630 while (tail_index > 0)
1632 struct symbol *type_sym;
1633 struct symbol *renaming_sym;
1634 const char* renaming;
1636 const char* renaming_expr;
1637 int terminator = encoded_name[tail_index];
1639 encoded_name[tail_index] = '\0';
1640 /* In order to avoid double-encoding, we want to only pass
1641 the decoded form to lookup functions. */
1642 std::string decoded_name = ada_decode (encoded_name);
1643 encoded_name[tail_index] = terminator;
1645 std::vector<struct block_symbol> syms
1646 = ada_lookup_symbol_list (decoded_name.c_str (), block, VAR_DOMAIN);
1648 type_sym = select_possible_type_sym (syms);
1650 if (type_sym != NULL)
1651 renaming_sym = type_sym;
1652 else if (syms.size () == 1)
1653 renaming_sym = syms[0].symbol;
1655 renaming_sym = NULL;
1657 switch (ada_parse_renaming (renaming_sym, &renaming,
1658 &renaming_len, &renaming_expr))
1660 case ADA_NOT_RENAMING:
1662 case ADA_PACKAGE_RENAMING:
1663 case ADA_EXCEPTION_RENAMING:
1664 case ADA_SUBPROGRAM_RENAMING:
1666 int alloc_len = renaming_len + name_len - tail_index + 1;
1668 = (char *) obstack_alloc (&temp_parse_space, alloc_len);
1669 strncpy (new_name, renaming, renaming_len);
1670 strcpy (new_name + renaming_len, encoded_name + tail_index);
1671 encoded_name = new_name;
1672 name_len = renaming_len + name_len - tail_index;
1673 goto TryAfterRenaming;
1675 case ADA_OBJECT_RENAMING:
1676 write_object_renaming (par_state, block, renaming, renaming_len,
1677 renaming_expr, MAX_RENAMING_CHAIN_LENGTH);
1678 write_selectors (par_state, encoded_name + tail_index);
1681 internal_error (_("impossible value from ada_parse_renaming"));
1684 if (type_sym != NULL)
1686 struct type *field_type;
1688 if (tail_index == name_len)
1689 return type_sym->type ();
1691 /* We have some extraneous characters after the type name.
1692 If this is an expression "TYPE_NAME.FIELD0.[...].FIELDN",
1693 then try to get the type of FIELDN. */
1695 = get_symbol_field_type (type_sym, encoded_name + tail_index);
1696 if (field_type != NULL)
1699 error (_("Invalid attempt to select from type: \"%s\"."),
1702 else if (tail_index == name_len && syms.empty ())
1704 struct type *type = find_primitive_type (par_state,
1711 if (syms.size () == 1)
1713 write_var_from_sym (par_state, syms[0]);
1714 write_selectors (par_state, encoded_name + tail_index);
1717 else if (syms.empty ())
1719 struct objfile *objfile = nullptr;
1720 if (block != nullptr)
1721 objfile = block->objfile ();
1723 struct bound_minimal_symbol msym
1724 = ada_lookup_simple_minsym (decoded_name.c_str (), objfile);
1725 if (msym.minsym != NULL)
1727 par_state->push_new<ada_var_msym_value_operation> (msym);
1728 /* Maybe cause error here rather than later? FIXME? */
1729 write_selectors (par_state, encoded_name + tail_index);
1733 if (tail_index == name_len
1734 && strncmp (encoded_name, "standard__",
1735 sizeof ("standard__") - 1) == 0)
1736 error (_("No definition of \"%s\" found."), name0.ptr);
1738 tail_index = chop_selector (encoded_name, tail_index);
1742 write_ambiguous_var (par_state, block, encoded_name,
1744 write_selectors (par_state, encoded_name + tail_index);
1749 if (!have_full_symbols () && !have_partial_symbols () && block == NULL)
1750 error (_("No symbol table is loaded. Use the \"file\" command."));
1751 if (block == par_state->expression_context_block)
1752 error (_("No definition of \"%s\" in current context."), name0.ptr);
1754 error (_("No definition of \"%s\" in specified context."), name0.ptr);
1759 error (_("Could not find renamed symbol \"%s\""), name0.ptr);
1763 /* Because ada_completer_word_break_characters does not contain '.' --
1764 and it cannot easily be added, this breaks other completions -- we
1765 have to recreate the completion word-splitting here, so that we can
1766 provide a prefix that is then used when completing field names.
1767 Without this, an attempt like "complete print abc.d" will give a
1768 result like "print def" rather than "print abc.def". */
1771 find_completion_bounds (struct parser_state *par_state)
1773 const char *end = pstate->lexptr;
1774 /* First the end of the prefix. Here we stop at the token start or
1776 for (; end > original_expr && end[-1] != '.' && !isspace (end[-1]); --end)
1780 /* Now find the start of the prefix. */
1781 const char *ptr = end;
1782 /* Here we allow '.'. */
1784 ptr > original_expr && (ptr[-1] == '.'
1786 || (ptr[-1] >= 'a' && ptr[-1] <= 'z')
1787 || (ptr[-1] >= 'A' && ptr[-1] <= 'Z')
1788 || (ptr[-1] & 0xff) >= 0x80);
1793 /* ... except, skip leading spaces. */
1794 ptr = skip_spaces (ptr);
1796 return std::string (ptr, end);
1799 /* A wrapper for write_var_or_type that is used specifically when
1800 completion is requested for the last of a sequence of
1803 static struct type *
1804 write_var_or_type_completion (struct parser_state *par_state,
1805 const struct block *block, struct stoken name0)
1807 int tail_index = chop_selector (name0.ptr, name0.length);
1808 /* If there's no separator, just defer to ordinary symbol
1810 if (tail_index == -1)
1811 return write_var_or_type (par_state, block, name0);
1813 std::string copy (name0.ptr, tail_index);
1814 struct type *type = write_var_or_type (par_state, block,
1816 (int) copy.length () });
1817 /* For completion purposes, it's enough that we return a type
1819 if (type != nullptr)
1822 ada_structop_operation *op = write_selectors (par_state,
1823 name0.ptr + tail_index);
1824 op->set_prefix (find_completion_bounds (par_state));
1825 par_state->mark_struct_expression (op);
1829 /* Write a left side of a component association (e.g., NAME in NAME =>
1830 exp). If NAME has the form of a selected component, write it as an
1831 ordinary expression. If it is a simple variable that unambiguously
1832 corresponds to exactly one symbol that does not denote a type or an
1833 object renaming, also write it normally as an OP_VAR_VALUE.
1834 Otherwise, write it as an OP_NAME.
1836 Unfortunately, we don't know at this point whether NAME is supposed
1837 to denote a record component name or the value of an array index.
1838 Therefore, it is not appropriate to disambiguate an ambiguous name
1839 as we normally would, nor to replace a renaming with its referent.
1840 As a result, in the (one hopes) rare case that one writes an
1841 aggregate such as (R => 42) where R renames an object or is an
1842 ambiguous name, one must write instead ((R) => 42). */
1845 write_name_assoc (struct parser_state *par_state, struct stoken name)
1847 if (strchr (name.ptr, '.') == NULL)
1849 std::vector<struct block_symbol> syms
1850 = ada_lookup_symbol_list (name.ptr,
1851 par_state->expression_context_block,
1854 if (syms.size () != 1 || syms[0].symbol->aclass () == LOC_TYPEDEF)
1855 pstate->push_new<ada_string_operation> (copy_name (name));
1857 write_var_from_sym (par_state, syms[0]);
1860 if (write_var_or_type (par_state, NULL, name) != NULL)
1861 error (_("Invalid use of type."));
1863 push_association<ada_name_association> (ada_pop ());
1866 static struct type *
1867 type_for_char (struct parser_state *par_state, ULONGEST value)
1870 return language_string_char_type (par_state->language (),
1871 par_state->gdbarch ());
1872 else if (value <= 0xffff)
1873 return language_lookup_primitive_type (par_state->language (),
1874 par_state->gdbarch (),
1876 return language_lookup_primitive_type (par_state->language (),
1877 par_state->gdbarch (),
1878 "wide_wide_character");
1881 static struct type *
1882 type_system_address (struct parser_state *par_state)
1885 = language_lookup_primitive_type (par_state->language (),
1886 par_state->gdbarch (),
1888 return type != NULL ? type : parse_type (par_state)->builtin_data_ptr;
1891 void _initialize_ada_exp ();
1893 _initialize_ada_exp ()
1895 obstack_init (&temp_parse_space);