Use bound_minimal_symbol in var_msym_value_operation
[deliverable/binutils-gdb.git] / gdb / ada-exp.y
1 /* YACC parser for Ada expressions, for GDB.
2 Copyright (C) 1986-2021 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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/>. */
18
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.
27
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. */
35
36 %{
37
38 #include "defs.h"
39 #include <ctype.h>
40 #include "expression.h"
41 #include "value.h"
42 #include "parser-defs.h"
43 #include "language.h"
44 #include "ada-lang.h"
45 #include "bfd.h" /* Required by objfiles.h. */
46 #include "symfile.h" /* Required by objfiles.h. */
47 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
48 #include "frame.h"
49 #include "block.h"
50 #include "ada-exp.h"
51
52 #define parse_type(ps) builtin_type (ps->gdbarch ())
53
54 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
55 etc). */
56 #define GDB_YY_REMAP_PREFIX ada_
57 #include "yy-remap.h"
58
59 struct name_info {
60 struct symbol *sym;
61 struct minimal_symbol *msym;
62 const struct block *block;
63 struct stoken stoken;
64 };
65
66 /* The state of the parser, used internally when we are parsing the
67 expression. */
68
69 static struct parser_state *pstate = NULL;
70
71 /* If expression is in the context of TYPE'(...), then TYPE, else
72 * NULL. */
73 static struct type *type_qualifier;
74
75 int yyparse (void);
76
77 static int yylex (void);
78
79 static void yyerror (const char *);
80
81 static void write_int (struct parser_state *, LONGEST, struct type *);
82
83 static void write_object_renaming (struct parser_state *,
84 const struct block *, const char *, int,
85 const char *, int);
86
87 static struct type* write_var_or_type (struct parser_state *,
88 const struct block *, struct stoken);
89
90 static void write_name_assoc (struct parser_state *, struct stoken);
91
92 static const struct block *block_lookup (const struct block *, const char *);
93
94 static LONGEST convert_char_literal (struct type *, LONGEST);
95
96 static void write_ambiguous_var (struct parser_state *,
97 const struct block *, char *, int);
98
99 static struct type *type_int (struct parser_state *);
100
101 static struct type *type_long (struct parser_state *);
102
103 static struct type *type_long_long (struct parser_state *);
104
105 static struct type *type_long_double (struct parser_state *);
106
107 static struct type *type_char (struct parser_state *);
108
109 static struct type *type_boolean (struct parser_state *);
110
111 static struct type *type_system_address (struct parser_state *);
112
113 using namespace expr;
114
115 /* Handle Ada type resolution for OP. DEPROCEDURE_P and CONTEXT_TYPE
116 are passed to the resolve method, if called. */
117 static operation_up
118 resolve (operation_up &&op, bool deprocedure_p, struct type *context_type)
119 {
120 operation_up result = std::move (op);
121 ada_resolvable *res = dynamic_cast<ada_resolvable *> (result.get ());
122 if (res != nullptr
123 && res->resolve (pstate->expout.get (),
124 deprocedure_p,
125 pstate->parse_completion,
126 pstate->block_tracker,
127 context_type))
128 result
129 = make_operation<ada_funcall_operation> (std::move (result),
130 std::vector<operation_up> ());
131
132 return result;
133 }
134
135 /* Like parser_state::pop, but handles Ada type resolution.
136 DEPROCEDURE_P and CONTEXT_TYPE are passed to the resolve method, if
137 called. */
138 static operation_up
139 ada_pop (bool deprocedure_p = true, struct type *context_type = nullptr)
140 {
141 /* Of course it's ok to call parser_state::pop here... */
142 return resolve (pstate->pop (), deprocedure_p, context_type);
143 }
144
145 /* Like parser_state::wrap, but use ada_pop to pop the value. */
146 template<typename T>
147 void
148 ada_wrap ()
149 {
150 operation_up arg = ada_pop ();
151 pstate->push_new<T> (std::move (arg));
152 }
153
154 /* Create and push an address-of operation, as appropriate for Ada.
155 If TYPE is not NULL, the resulting operation will be wrapped in a
156 cast to TYPE. */
157 static void
158 ada_addrof (struct type *type = nullptr)
159 {
160 operation_up arg = ada_pop (false);
161 operation_up addr = make_operation<unop_addr_operation> (std::move (arg));
162 operation_up wrapped
163 = make_operation<ada_wrapped_operation> (std::move (addr));
164 if (type != nullptr)
165 wrapped = make_operation<unop_cast_operation> (std::move (wrapped), type);
166 pstate->push (std::move (wrapped));
167 }
168
169 /* A variant of parser_state::wrap2 that uses ada_pop to pop both
170 operands, and then pushes a new Ada-wrapped operation of the
171 template type T. */
172 template<typename T>
173 void
174 ada_un_wrap2 ()
175 {
176 operation_up rhs = ada_pop ();
177 operation_up lhs = ada_pop ();
178 operation_up wrapped = make_operation<T> (std::move (lhs), std::move (rhs));
179 pstate->push_new<ada_wrapped_operation> (std::move (wrapped));
180 }
181
182 /* A variant of parser_state::wrap2 that uses ada_pop to pop both
183 operands. Unlike ada_un_wrap2, ada_wrapped_operation is not
184 used. */
185 template<typename T>
186 void
187 ada_wrap2 ()
188 {
189 operation_up rhs = ada_pop ();
190 operation_up lhs = ada_pop ();
191 pstate->push_new<T> (std::move (lhs), std::move (rhs));
192 }
193
194 /* A variant of parser_state::wrap2 that uses ada_pop to pop both
195 operands. OP is also passed to the constructor of the new binary
196 operation. */
197 template<typename T>
198 void
199 ada_wrap_op (enum exp_opcode op)
200 {
201 operation_up rhs = ada_pop ();
202 operation_up lhs = ada_pop ();
203 pstate->push_new<T> (op, std::move (lhs), std::move (rhs));
204 }
205
206 /* Pop three operands using ada_pop, then construct a new ternary
207 operation of type T and push it. */
208 template<typename T>
209 void
210 ada_wrap3 ()
211 {
212 operation_up rhs = ada_pop ();
213 operation_up mid = ada_pop ();
214 operation_up lhs = ada_pop ();
215 pstate->push_new<T> (std::move (lhs), std::move (mid), std::move (rhs));
216 }
217
218 /* Pop NARGS operands, then a callee operand, and use these to
219 construct and push a new Ada function call operation. */
220 static void
221 ada_funcall (int nargs)
222 {
223 /* We use the ordinary pop here, because we're going to do
224 resolution in a separate step, in order to handle array
225 indices. */
226 std::vector<operation_up> args = pstate->pop_vector (nargs);
227 /* Call parser_state::pop here, because we don't want to
228 function-convert the callee slot of a call we're already
229 constructing. */
230 operation_up callee = pstate->pop ();
231
232 ada_var_value_operation *vvo
233 = dynamic_cast<ada_var_value_operation *> (callee.get ());
234 int array_arity = 0;
235 struct type *callee_t = nullptr;
236 if (vvo == nullptr
237 || SYMBOL_DOMAIN (vvo->get_symbol ()) != UNDEF_DOMAIN)
238 {
239 struct value *callee_v = callee->evaluate (nullptr,
240 pstate->expout.get (),
241 EVAL_AVOID_SIDE_EFFECTS);
242 callee_t = ada_check_typedef (value_type (callee_v));
243 array_arity = ada_array_arity (callee_t);
244 }
245
246 for (int i = 0; i < nargs; ++i)
247 {
248 struct type *subtype = nullptr;
249 if (i < array_arity)
250 subtype = ada_index_type (callee_t, i + 1, "array type");
251 args[i] = resolve (std::move (args[i]), true, subtype);
252 }
253
254 std::unique_ptr<ada_funcall_operation> funcall
255 (new ada_funcall_operation (std::move (callee), std::move (args)));
256 funcall->resolve (pstate->expout.get (), true, pstate->parse_completion,
257 pstate->block_tracker, nullptr);
258 pstate->push (std::move (funcall));
259 }
260
261 /* The components being constructed during this parse. */
262 static std::vector<ada_component_up> components;
263
264 /* Create a new ada_component_up of the indicated type and arguments,
265 and push it on the global 'components' vector. */
266 template<typename T, typename... Arg>
267 void
268 push_component (Arg... args)
269 {
270 components.emplace_back (new T (std::forward<Arg> (args)...));
271 }
272
273 /* Examine the final element of the 'components' vector, and return it
274 as a pointer to an ada_choices_component. The caller is
275 responsible for ensuring that the final element is in fact an
276 ada_choices_component. */
277 static ada_choices_component *
278 choice_component ()
279 {
280 ada_component *last = components.back ().get ();
281 ada_choices_component *result = dynamic_cast<ada_choices_component *> (last);
282 gdb_assert (result != nullptr);
283 return result;
284 }
285
286 /* Pop the most recent component from the global stack, and return
287 it. */
288 static ada_component_up
289 pop_component ()
290 {
291 ada_component_up result = std::move (components.back ());
292 components.pop_back ();
293 return result;
294 }
295
296 /* Pop the N most recent components from the global stack, and return
297 them in a vector. */
298 static std::vector<ada_component_up>
299 pop_components (int n)
300 {
301 std::vector<ada_component_up> result (n);
302 for (int i = 1; i <= n; ++i)
303 result[n - i] = pop_component ();
304 return result;
305 }
306
307 /* The associations being constructed during this parse. */
308 static std::vector<ada_association_up> associations;
309
310 /* Create a new ada_association_up of the indicated type and
311 arguments, and push it on the global 'associations' vector. */
312 template<typename T, typename... Arg>
313 void
314 push_association (Arg... args)
315 {
316 associations.emplace_back (new T (std::forward<Arg> (args)...));
317 }
318
319 /* Pop the most recent association from the global stack, and return
320 it. */
321 static ada_association_up
322 pop_association ()
323 {
324 ada_association_up result = std::move (associations.back ());
325 associations.pop_back ();
326 return result;
327 }
328
329 /* Pop the N most recent associations from the global stack, and
330 return them in a vector. */
331 static std::vector<ada_association_up>
332 pop_associations (int n)
333 {
334 std::vector<ada_association_up> result (n);
335 for (int i = 1; i <= n; ++i)
336 result[n - i] = pop_association ();
337 return result;
338 }
339
340 %}
341
342 %union
343 {
344 LONGEST lval;
345 struct {
346 LONGEST val;
347 struct type *type;
348 } typed_val;
349 struct {
350 gdb_byte val[16];
351 struct type *type;
352 } typed_val_float;
353 struct type *tval;
354 struct stoken sval;
355 const struct block *bval;
356 struct internalvar *ivar;
357 }
358
359 %type <lval> positional_list component_groups component_associations
360 %type <lval> aggregate_component_list
361 %type <tval> var_or_type type_prefix opt_type_prefix
362
363 %token <typed_val> INT NULL_PTR CHARLIT
364 %token <typed_val_float> FLOAT
365 %token TRUEKEYWORD FALSEKEYWORD
366 %token COLONCOLON
367 %token <sval> STRING NAME DOT_ID
368 %type <bval> block
369 %type <lval> arglist tick_arglist
370
371 %type <tval> save_qualifier
372
373 %token DOT_ALL
374
375 /* Special type cases, put in to allow the parser to distinguish different
376 legal basetypes. */
377 %token <sval> DOLLAR_VARIABLE
378
379 %nonassoc ASSIGN
380 %left _AND_ OR XOR THEN ELSE
381 %left '=' NOTEQUAL '<' '>' LEQ GEQ IN DOTDOT
382 %left '@'
383 %left '+' '-' '&'
384 %left UNARY
385 %left '*' '/' MOD REM
386 %right STARSTAR ABS NOT
387
388 /* Artificial token to give NAME => ... and NAME | priority over reducing
389 NAME to <primary> and to give <primary>' priority over reducing <primary>
390 to <simple_exp>. */
391 %nonassoc VAR
392
393 %nonassoc ARROW '|'
394
395 %right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
396 %right TICK_MAX TICK_MIN TICK_MODULUS
397 %right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
398 /* The following are right-associative only so that reductions at this
399 precedence have lower precedence than '.' and '('. The syntax still
400 forces a.b.c, e.g., to be LEFT-associated. */
401 %right '.' '(' '[' DOT_ID DOT_ALL
402
403 %token NEW OTHERS
404
405 \f
406 %%
407
408 start : exp1
409 ;
410
411 /* Expressions, including the sequencing operator. */
412 exp1 : exp
413 | exp1 ';' exp
414 { ada_wrap2<comma_operation> (); }
415 | primary ASSIGN exp /* Extension for convenience */
416 { ada_wrap2<ada_assign_operation> (); }
417 ;
418
419 /* Expressions, not including the sequencing operator. */
420 primary : primary DOT_ALL
421 { ada_wrap<ada_unop_ind_operation> (); }
422 ;
423
424 primary : primary DOT_ID
425 {
426 operation_up arg = ada_pop ();
427 pstate->push_new<ada_structop_operation>
428 (std::move (arg), copy_name ($2));
429 }
430 ;
431
432 primary : primary '(' arglist ')'
433 { ada_funcall ($3); }
434 | var_or_type '(' arglist ')'
435 {
436 if ($1 != NULL)
437 {
438 if ($3 != 1)
439 error (_("Invalid conversion"));
440 operation_up arg = ada_pop ();
441 pstate->push_new<unop_cast_operation>
442 (std::move (arg), $1);
443 }
444 else
445 ada_funcall ($3);
446 }
447 ;
448
449 primary : var_or_type '\'' save_qualifier { type_qualifier = $1; }
450 '(' exp ')'
451 {
452 if ($1 == NULL)
453 error (_("Type required for qualification"));
454 operation_up arg = ada_pop (true,
455 check_typedef ($1));
456 pstate->push_new<ada_qual_operation>
457 (std::move (arg), $1);
458 type_qualifier = $3;
459 }
460 ;
461
462 save_qualifier : { $$ = type_qualifier; }
463 ;
464
465 primary :
466 primary '(' simple_exp DOTDOT simple_exp ')'
467 { ada_wrap3<ada_ternop_slice_operation> (); }
468 | var_or_type '(' simple_exp DOTDOT simple_exp ')'
469 { if ($1 == NULL)
470 ada_wrap3<ada_ternop_slice_operation> ();
471 else
472 error (_("Cannot slice a type"));
473 }
474 ;
475
476 primary : '(' exp1 ')' { }
477 ;
478
479 /* The following rule causes a conflict with the type conversion
480 var_or_type (exp)
481 To get around it, we give '(' higher priority and add bridge rules for
482 var_or_type (exp, exp, ...)
483 var_or_type (exp .. exp)
484 We also have the action for var_or_type(exp) generate a function call
485 when the first symbol does not denote a type. */
486
487 primary : var_or_type %prec VAR
488 { if ($1 != NULL)
489 pstate->push_new<type_operation> ($1);
490 }
491 ;
492
493 primary : DOLLAR_VARIABLE /* Various GDB extensions */
494 { pstate->push_dollar ($1); }
495 ;
496
497 primary : aggregate
498 {
499 pstate->push_new<ada_aggregate_operation>
500 (pop_component ());
501 }
502 ;
503
504 simple_exp : primary
505 ;
506
507 simple_exp : '-' simple_exp %prec UNARY
508 { ada_wrap<ada_neg_operation> (); }
509 ;
510
511 simple_exp : '+' simple_exp %prec UNARY
512 {
513 /* No need to do anything. */
514 }
515 ;
516
517 simple_exp : NOT simple_exp %prec UNARY
518 { ada_wrap<unary_logical_not_operation> (); }
519 ;
520
521 simple_exp : ABS simple_exp %prec UNARY
522 { ada_wrap<ada_abs_operation> (); }
523 ;
524
525 arglist : { $$ = 0; }
526 ;
527
528 arglist : exp
529 { $$ = 1; }
530 | NAME ARROW exp
531 { $$ = 1; }
532 | arglist ',' exp
533 { $$ = $1 + 1; }
534 | arglist ',' NAME ARROW exp
535 { $$ = $1 + 1; }
536 ;
537
538 primary : '{' var_or_type '}' primary %prec '.'
539 /* GDB extension */
540 {
541 if ($2 == NULL)
542 error (_("Type required within braces in coercion"));
543 operation_up arg = ada_pop ();
544 pstate->push_new<unop_memval_operation>
545 (std::move (arg), $2);
546 }
547 ;
548
549 /* Binary operators in order of decreasing precedence. */
550
551 simple_exp : simple_exp STARSTAR simple_exp
552 { ada_wrap2<ada_binop_exp_operation> (); }
553 ;
554
555 simple_exp : simple_exp '*' simple_exp
556 { ada_wrap2<ada_binop_mul_operation> (); }
557 ;
558
559 simple_exp : simple_exp '/' simple_exp
560 { ada_wrap2<ada_binop_div_operation> (); }
561 ;
562
563 simple_exp : simple_exp REM simple_exp /* May need to be fixed to give correct Ada REM */
564 { ada_wrap2<ada_binop_rem_operation> (); }
565 ;
566
567 simple_exp : simple_exp MOD simple_exp
568 { ada_wrap2<ada_binop_mod_operation> (); }
569 ;
570
571 simple_exp : simple_exp '@' simple_exp /* GDB extension */
572 { ada_wrap2<repeat_operation> (); }
573 ;
574
575 simple_exp : simple_exp '+' simple_exp
576 { ada_wrap_op<ada_binop_addsub_operation> (BINOP_ADD); }
577 ;
578
579 simple_exp : simple_exp '&' simple_exp
580 { ada_wrap2<concat_operation> (); }
581 ;
582
583 simple_exp : simple_exp '-' simple_exp
584 { ada_wrap_op<ada_binop_addsub_operation> (BINOP_SUB); }
585 ;
586
587 relation : simple_exp
588 ;
589
590 relation : simple_exp '=' simple_exp
591 { ada_wrap_op<ada_binop_equal_operation> (BINOP_EQUAL); }
592 ;
593
594 relation : simple_exp NOTEQUAL simple_exp
595 { ada_wrap_op<ada_binop_equal_operation> (BINOP_NOTEQUAL); }
596 ;
597
598 relation : simple_exp LEQ simple_exp
599 { ada_un_wrap2<leq_operation> (); }
600 ;
601
602 relation : simple_exp IN simple_exp DOTDOT simple_exp
603 { ada_wrap3<ada_ternop_range_operation> (); }
604 | simple_exp IN primary TICK_RANGE tick_arglist
605 {
606 operation_up rhs = ada_pop ();
607 operation_up lhs = ada_pop ();
608 pstate->push_new<ada_binop_in_bounds_operation>
609 (std::move (lhs), std::move (rhs), $5);
610 }
611 | simple_exp IN var_or_type %prec TICK_ACCESS
612 {
613 if ($3 == NULL)
614 error (_("Right operand of 'in' must be type"));
615 operation_up arg = ada_pop ();
616 pstate->push_new<ada_unop_range_operation>
617 (std::move (arg), $3);
618 }
619 | simple_exp NOT IN simple_exp DOTDOT simple_exp
620 { ada_wrap3<ada_ternop_range_operation> ();
621 ada_wrap<unary_logical_not_operation> (); }
622 | simple_exp NOT IN primary TICK_RANGE tick_arglist
623 {
624 operation_up rhs = ada_pop ();
625 operation_up lhs = ada_pop ();
626 pstate->push_new<ada_binop_in_bounds_operation>
627 (std::move (lhs), std::move (rhs), $6);
628 ada_wrap<unary_logical_not_operation> ();
629 }
630 | simple_exp NOT IN var_or_type %prec TICK_ACCESS
631 {
632 if ($4 == NULL)
633 error (_("Right operand of 'in' must be type"));
634 operation_up arg = ada_pop ();
635 pstate->push_new<ada_unop_range_operation>
636 (std::move (arg), $4);
637 ada_wrap<unary_logical_not_operation> ();
638 }
639 ;
640
641 relation : simple_exp GEQ simple_exp
642 { ada_un_wrap2<geq_operation> (); }
643 ;
644
645 relation : simple_exp '<' simple_exp
646 { ada_un_wrap2<less_operation> (); }
647 ;
648
649 relation : simple_exp '>' simple_exp
650 { ada_un_wrap2<gtr_operation> (); }
651 ;
652
653 exp : relation
654 | and_exp
655 | and_then_exp
656 | or_exp
657 | or_else_exp
658 | xor_exp
659 ;
660
661 and_exp :
662 relation _AND_ relation
663 { ada_wrap2<ada_bitwise_and_operation> (); }
664 | and_exp _AND_ relation
665 { ada_wrap2<ada_bitwise_and_operation> (); }
666 ;
667
668 and_then_exp :
669 relation _AND_ THEN relation
670 { ada_wrap2<logical_and_operation> (); }
671 | and_then_exp _AND_ THEN relation
672 { ada_wrap2<logical_and_operation> (); }
673 ;
674
675 or_exp :
676 relation OR relation
677 { ada_wrap2<ada_bitwise_ior_operation> (); }
678 | or_exp OR relation
679 { ada_wrap2<ada_bitwise_ior_operation> (); }
680 ;
681
682 or_else_exp :
683 relation OR ELSE relation
684 { ada_wrap2<logical_or_operation> (); }
685 | or_else_exp OR ELSE relation
686 { ada_wrap2<logical_or_operation> (); }
687 ;
688
689 xor_exp : relation XOR relation
690 { ada_wrap2<ada_bitwise_xor_operation> (); }
691 | xor_exp XOR relation
692 { ada_wrap2<ada_bitwise_xor_operation> (); }
693 ;
694
695 /* Primaries can denote types (OP_TYPE). In cases such as
696 primary TICK_ADDRESS, where a type would be invalid, it will be
697 caught when evaluate_subexp in ada-lang.c tries to evaluate the
698 primary, expecting a value. Precedence rules resolve the ambiguity
699 in NAME TICK_ACCESS in favor of shifting to form a var_or_type. A
700 construct such as aType'access'access will again cause an error when
701 aType'access evaluates to a type that evaluate_subexp attempts to
702 evaluate. */
703 primary : primary TICK_ACCESS
704 { ada_addrof (); }
705 | primary TICK_ADDRESS
706 { ada_addrof (type_system_address (pstate)); }
707 | primary TICK_FIRST tick_arglist
708 {
709 operation_up arg = ada_pop ();
710 pstate->push_new<ada_unop_atr_operation>
711 (std::move (arg), OP_ATR_FIRST, $3);
712 }
713 | primary TICK_LAST tick_arglist
714 {
715 operation_up arg = ada_pop ();
716 pstate->push_new<ada_unop_atr_operation>
717 (std::move (arg), OP_ATR_LAST, $3);
718 }
719 | primary TICK_LENGTH tick_arglist
720 {
721 operation_up arg = ada_pop ();
722 pstate->push_new<ada_unop_atr_operation>
723 (std::move (arg), OP_ATR_LENGTH, $3);
724 }
725 | primary TICK_SIZE
726 { ada_wrap<ada_atr_size_operation> (); }
727 | primary TICK_TAG
728 { ada_wrap<ada_atr_tag_operation> (); }
729 | opt_type_prefix TICK_MIN '(' exp ',' exp ')'
730 { ada_wrap2<ada_binop_min_operation> (); }
731 | opt_type_prefix TICK_MAX '(' exp ',' exp ')'
732 { ada_wrap2<ada_binop_max_operation> (); }
733 | opt_type_prefix TICK_POS '(' exp ')'
734 { ada_wrap<ada_pos_operation> (); }
735 | type_prefix TICK_VAL '(' exp ')'
736 {
737 operation_up arg = ada_pop ();
738 pstate->push_new<ada_atr_val_operation>
739 ($1, std::move (arg));
740 }
741 | type_prefix TICK_MODULUS
742 {
743 struct type *type_arg = check_typedef ($1);
744 if (!ada_is_modular_type (type_arg))
745 error (_("'modulus must be applied to modular type"));
746 write_int (pstate, ada_modulus (type_arg),
747 TYPE_TARGET_TYPE (type_arg));
748 }
749 ;
750
751 tick_arglist : %prec '('
752 { $$ = 1; }
753 | '(' INT ')'
754 { $$ = $2.val; }
755 ;
756
757 type_prefix :
758 var_or_type
759 {
760 if ($1 == NULL)
761 error (_("Prefix must be type"));
762 $$ = $1;
763 }
764 ;
765
766 opt_type_prefix :
767 type_prefix
768 { $$ = $1; }
769 | /* EMPTY */
770 { $$ = parse_type (pstate)->builtin_void; }
771 ;
772
773
774 primary : INT
775 { write_int (pstate, (LONGEST) $1.val, $1.type); }
776 ;
777
778 primary : CHARLIT
779 { write_int (pstate,
780 convert_char_literal (type_qualifier, $1.val),
781 (type_qualifier == NULL)
782 ? $1.type : type_qualifier);
783 }
784 ;
785
786 primary : FLOAT
787 {
788 float_data data;
789 std::copy (std::begin ($1.val), std::end ($1.val),
790 std::begin (data));
791 pstate->push_new<float_const_operation>
792 ($1.type, data);
793 ada_wrap<ada_wrapped_operation> ();
794 }
795 ;
796
797 primary : NULL_PTR
798 { write_int (pstate, 0, type_int (pstate)); }
799 ;
800
801 primary : STRING
802 {
803 pstate->push_new<ada_string_operation>
804 (copy_name ($1));
805 }
806 ;
807
808 primary : TRUEKEYWORD
809 { write_int (pstate, 1, type_boolean (pstate)); }
810 | FALSEKEYWORD
811 { write_int (pstate, 0, type_boolean (pstate)); }
812 ;
813
814 primary : NEW NAME
815 { error (_("NEW not implemented.")); }
816 ;
817
818 var_or_type: NAME %prec VAR
819 { $$ = write_var_or_type (pstate, NULL, $1); }
820 | block NAME %prec VAR
821 { $$ = write_var_or_type (pstate, $1, $2); }
822 | NAME TICK_ACCESS
823 {
824 $$ = write_var_or_type (pstate, NULL, $1);
825 if ($$ == NULL)
826 ada_addrof ();
827 else
828 $$ = lookup_pointer_type ($$);
829 }
830 | block NAME TICK_ACCESS
831 {
832 $$ = write_var_or_type (pstate, $1, $2);
833 if ($$ == NULL)
834 ada_addrof ();
835 else
836 $$ = lookup_pointer_type ($$);
837 }
838 ;
839
840 /* GDB extension */
841 block : NAME COLONCOLON
842 { $$ = block_lookup (NULL, $1.ptr); }
843 | block NAME COLONCOLON
844 { $$ = block_lookup ($1, $2.ptr); }
845 ;
846
847 aggregate :
848 '(' aggregate_component_list ')'
849 {
850 std::vector<ada_component_up> components
851 = pop_components ($2);
852
853 push_component<ada_aggregate_component>
854 (std::move (components));
855 }
856 ;
857
858 aggregate_component_list :
859 component_groups { $$ = $1; }
860 | positional_list exp
861 {
862 push_component<ada_positional_component>
863 ($1, ada_pop ());
864 $$ = $1 + 1;
865 }
866 | positional_list component_groups
867 { $$ = $1 + $2; }
868 ;
869
870 positional_list :
871 exp ','
872 {
873 push_component<ada_positional_component>
874 (0, ada_pop ());
875 $$ = 1;
876 }
877 | positional_list exp ','
878 {
879 push_component<ada_positional_component>
880 ($1, ada_pop ());
881 $$ = $1 + 1;
882 }
883 ;
884
885 component_groups:
886 others { $$ = 1; }
887 | component_group { $$ = 1; }
888 | component_group ',' component_groups
889 { $$ = $3 + 1; }
890 ;
891
892 others : OTHERS ARROW exp
893 {
894 push_component<ada_others_component> (ada_pop ());
895 }
896 ;
897
898 component_group :
899 component_associations
900 {
901 ada_choices_component *choices = choice_component ();
902 choices->set_associations (pop_associations ($1));
903 }
904 ;
905
906 /* We use this somewhat obscure definition in order to handle NAME => and
907 NAME | differently from exp => and exp |. ARROW and '|' have a precedence
908 above that of the reduction of NAME to var_or_type. By delaying
909 decisions until after the => or '|', we convert the ambiguity to a
910 resolved shift/reduce conflict. */
911 component_associations :
912 NAME ARROW exp
913 {
914 push_component<ada_choices_component> (ada_pop ());
915 write_name_assoc (pstate, $1);
916 $$ = 1;
917 }
918 | simple_exp ARROW exp
919 {
920 push_component<ada_choices_component> (ada_pop ());
921 push_association<ada_name_association> (ada_pop ());
922 $$ = 1;
923 }
924 | simple_exp DOTDOT simple_exp ARROW exp
925 {
926 push_component<ada_choices_component> (ada_pop ());
927 operation_up rhs = ada_pop ();
928 operation_up lhs = ada_pop ();
929 push_association<ada_discrete_range_association>
930 (std::move (lhs), std::move (rhs));
931 $$ = 1;
932 }
933 | NAME '|' component_associations
934 {
935 write_name_assoc (pstate, $1);
936 $$ = $3 + 1;
937 }
938 | simple_exp '|' component_associations
939 {
940 push_association<ada_name_association> (ada_pop ());
941 $$ = $3 + 1;
942 }
943 | simple_exp DOTDOT simple_exp '|' component_associations
944
945 {
946 operation_up rhs = ada_pop ();
947 operation_up lhs = ada_pop ();
948 push_association<ada_discrete_range_association>
949 (std::move (lhs), std::move (rhs));
950 $$ = $5 + 1;
951 }
952 ;
953
954 /* Some extensions borrowed from C, for the benefit of those who find they
955 can't get used to Ada notation in GDB. */
956
957 primary : '*' primary %prec '.'
958 { ada_wrap<ada_unop_ind_operation> (); }
959 | '&' primary %prec '.'
960 { ada_addrof (); }
961 | primary '[' exp ']'
962 {
963 ada_wrap2<subscript_operation> ();
964 ada_wrap<ada_wrapped_operation> ();
965 }
966 ;
967
968 %%
969
970 /* yylex defined in ada-lex.c: Reads one token, getting characters */
971 /* through lexptr. */
972
973 /* Remap normal flex interface names (yylex) as well as gratuitiously */
974 /* global symbol names, so we can have multiple flex-generated parsers */
975 /* in gdb. */
976
977 /* (See note above on previous definitions for YACC.) */
978
979 #define yy_create_buffer ada_yy_create_buffer
980 #define yy_delete_buffer ada_yy_delete_buffer
981 #define yy_init_buffer ada_yy_init_buffer
982 #define yy_load_buffer_state ada_yy_load_buffer_state
983 #define yy_switch_to_buffer ada_yy_switch_to_buffer
984 #define yyrestart ada_yyrestart
985 #define yytext ada_yytext
986
987 static struct obstack temp_parse_space;
988
989 /* The following kludge was found necessary to prevent conflicts between */
990 /* defs.h and non-standard stdlib.h files. */
991 #define qsort __qsort__dummy
992 #include "ada-lex.c"
993
994 int
995 ada_parse (struct parser_state *par_state)
996 {
997 /* Setting up the parser state. */
998 scoped_restore pstate_restore = make_scoped_restore (&pstate);
999 gdb_assert (par_state != NULL);
1000 pstate = par_state;
1001
1002 lexer_init (yyin); /* (Re-)initialize lexer. */
1003 type_qualifier = NULL;
1004 obstack_free (&temp_parse_space, NULL);
1005 obstack_init (&temp_parse_space);
1006 components.clear ();
1007 associations.clear ();
1008
1009 int result = yyparse ();
1010 if (!result)
1011 {
1012 struct type *context_type = nullptr;
1013 if (par_state->void_context_p)
1014 context_type = parse_type (par_state)->builtin_void;
1015 pstate->set_operation (ada_pop (true, context_type));
1016 }
1017 return result;
1018 }
1019
1020 static void
1021 yyerror (const char *msg)
1022 {
1023 error (_("Error in expression, near `%s'."), pstate->lexptr);
1024 }
1025
1026 /* Emit expression to access an instance of SYM, in block BLOCK (if
1027 non-NULL). */
1028
1029 static void
1030 write_var_from_sym (struct parser_state *par_state,
1031 const struct block *block,
1032 struct symbol *sym)
1033 {
1034 if (symbol_read_needs_frame (sym))
1035 par_state->block_tracker->update (block, INNERMOST_BLOCK_FOR_SYMBOLS);
1036
1037 par_state->push_new<ada_var_value_operation> (sym, block);
1038 }
1039
1040 /* Write integer or boolean constant ARG of type TYPE. */
1041
1042 static void
1043 write_int (struct parser_state *par_state, LONGEST arg, struct type *type)
1044 {
1045 pstate->push_new<long_const_operation> (type, arg);
1046 ada_wrap<ada_wrapped_operation> ();
1047 }
1048
1049 /* Emit expression corresponding to the renamed object named
1050 * designated by RENAMED_ENTITY[0 .. RENAMED_ENTITY_LEN-1] in the
1051 * context of ORIG_LEFT_CONTEXT, to which is applied the operations
1052 * encoded by RENAMING_EXPR. MAX_DEPTH is the maximum number of
1053 * cascaded renamings to allow. If ORIG_LEFT_CONTEXT is null, it
1054 * defaults to the currently selected block. ORIG_SYMBOL is the
1055 * symbol that originally encoded the renaming. It is needed only
1056 * because its prefix also qualifies any index variables used to index
1057 * or slice an array. It should not be necessary once we go to the
1058 * new encoding entirely (FIXME pnh 7/20/2007). */
1059
1060 static void
1061 write_object_renaming (struct parser_state *par_state,
1062 const struct block *orig_left_context,
1063 const char *renamed_entity, int renamed_entity_len,
1064 const char *renaming_expr, int max_depth)
1065 {
1066 char *name;
1067 enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
1068 struct block_symbol sym_info;
1069
1070 if (max_depth <= 0)
1071 error (_("Could not find renamed symbol"));
1072
1073 if (orig_left_context == NULL)
1074 orig_left_context = get_selected_block (NULL);
1075
1076 name = obstack_strndup (&temp_parse_space, renamed_entity,
1077 renamed_entity_len);
1078 ada_lookup_encoded_symbol (name, orig_left_context, VAR_DOMAIN, &sym_info);
1079 if (sym_info.symbol == NULL)
1080 error (_("Could not find renamed variable: %s"), ada_decode (name).c_str ());
1081 else if (SYMBOL_CLASS (sym_info.symbol) == LOC_TYPEDEF)
1082 /* We have a renaming of an old-style renaming symbol. Don't
1083 trust the block information. */
1084 sym_info.block = orig_left_context;
1085
1086 {
1087 const char *inner_renamed_entity;
1088 int inner_renamed_entity_len;
1089 const char *inner_renaming_expr;
1090
1091 switch (ada_parse_renaming (sym_info.symbol, &inner_renamed_entity,
1092 &inner_renamed_entity_len,
1093 &inner_renaming_expr))
1094 {
1095 case ADA_NOT_RENAMING:
1096 write_var_from_sym (par_state, sym_info.block, sym_info.symbol);
1097 break;
1098 case ADA_OBJECT_RENAMING:
1099 write_object_renaming (par_state, sym_info.block,
1100 inner_renamed_entity, inner_renamed_entity_len,
1101 inner_renaming_expr, max_depth - 1);
1102 break;
1103 default:
1104 goto BadEncoding;
1105 }
1106 }
1107
1108 slice_state = SIMPLE_INDEX;
1109 while (*renaming_expr == 'X')
1110 {
1111 renaming_expr += 1;
1112
1113 switch (*renaming_expr) {
1114 case 'A':
1115 renaming_expr += 1;
1116 ada_wrap<ada_unop_ind_operation> ();
1117 break;
1118 case 'L':
1119 slice_state = LOWER_BOUND;
1120 /* FALLTHROUGH */
1121 case 'S':
1122 renaming_expr += 1;
1123 if (isdigit (*renaming_expr))
1124 {
1125 char *next;
1126 long val = strtol (renaming_expr, &next, 10);
1127 if (next == renaming_expr)
1128 goto BadEncoding;
1129 renaming_expr = next;
1130 write_int (par_state, val, type_int (par_state));
1131 }
1132 else
1133 {
1134 const char *end;
1135 char *index_name;
1136 struct block_symbol index_sym_info;
1137
1138 end = strchr (renaming_expr, 'X');
1139 if (end == NULL)
1140 end = renaming_expr + strlen (renaming_expr);
1141
1142 index_name = obstack_strndup (&temp_parse_space, renaming_expr,
1143 end - renaming_expr);
1144 renaming_expr = end;
1145
1146 ada_lookup_encoded_symbol (index_name, orig_left_context,
1147 VAR_DOMAIN, &index_sym_info);
1148 if (index_sym_info.symbol == NULL)
1149 error (_("Could not find %s"), index_name);
1150 else if (SYMBOL_CLASS (index_sym_info.symbol) == LOC_TYPEDEF)
1151 /* Index is an old-style renaming symbol. */
1152 index_sym_info.block = orig_left_context;
1153 write_var_from_sym (par_state, index_sym_info.block,
1154 index_sym_info.symbol);
1155 }
1156 if (slice_state == SIMPLE_INDEX)
1157 ada_funcall (1);
1158 else if (slice_state == LOWER_BOUND)
1159 slice_state = UPPER_BOUND;
1160 else if (slice_state == UPPER_BOUND)
1161 {
1162 ada_wrap3<ada_ternop_slice_operation> ();
1163 slice_state = SIMPLE_INDEX;
1164 }
1165 break;
1166
1167 case 'R':
1168 {
1169 const char *end;
1170
1171 renaming_expr += 1;
1172
1173 if (slice_state != SIMPLE_INDEX)
1174 goto BadEncoding;
1175 end = strchr (renaming_expr, 'X');
1176 if (end == NULL)
1177 end = renaming_expr + strlen (renaming_expr);
1178
1179 operation_up arg = ada_pop ();
1180 pstate->push_new<ada_structop_operation>
1181 (std::move (arg), std::string (renaming_expr,
1182 end - renaming_expr));
1183 renaming_expr = end;
1184 break;
1185 }
1186
1187 default:
1188 goto BadEncoding;
1189 }
1190 }
1191 if (slice_state == SIMPLE_INDEX)
1192 return;
1193
1194 BadEncoding:
1195 error (_("Internal error in encoding of renaming declaration"));
1196 }
1197
1198 static const struct block*
1199 block_lookup (const struct block *context, const char *raw_name)
1200 {
1201 const char *name;
1202 struct symtab *symtab;
1203 const struct block *result = NULL;
1204
1205 std::string name_storage;
1206 if (raw_name[0] == '\'')
1207 {
1208 raw_name += 1;
1209 name = raw_name;
1210 }
1211 else
1212 {
1213 name_storage = ada_encode (raw_name);
1214 name = name_storage.c_str ();
1215 }
1216
1217 std::vector<struct block_symbol> syms
1218 = ada_lookup_symbol_list (name, context, VAR_DOMAIN);
1219
1220 if (context == NULL
1221 && (syms.empty () || SYMBOL_CLASS (syms[0].symbol) != LOC_BLOCK))
1222 symtab = lookup_symtab (name);
1223 else
1224 symtab = NULL;
1225
1226 if (symtab != NULL)
1227 result = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), STATIC_BLOCK);
1228 else if (syms.empty () || SYMBOL_CLASS (syms[0].symbol) != LOC_BLOCK)
1229 {
1230 if (context == NULL)
1231 error (_("No file or function \"%s\"."), raw_name);
1232 else
1233 error (_("No function \"%s\" in specified context."), raw_name);
1234 }
1235 else
1236 {
1237 if (syms.size () > 1)
1238 warning (_("Function name \"%s\" ambiguous here"), raw_name);
1239 result = SYMBOL_BLOCK_VALUE (syms[0].symbol);
1240 }
1241
1242 return result;
1243 }
1244
1245 static struct symbol*
1246 select_possible_type_sym (const std::vector<struct block_symbol> &syms)
1247 {
1248 int i;
1249 int preferred_index;
1250 struct type *preferred_type;
1251
1252 preferred_index = -1; preferred_type = NULL;
1253 for (i = 0; i < syms.size (); i += 1)
1254 switch (SYMBOL_CLASS (syms[i].symbol))
1255 {
1256 case LOC_TYPEDEF:
1257 if (ada_prefer_type (SYMBOL_TYPE (syms[i].symbol), preferred_type))
1258 {
1259 preferred_index = i;
1260 preferred_type = SYMBOL_TYPE (syms[i].symbol);
1261 }
1262 break;
1263 case LOC_REGISTER:
1264 case LOC_ARG:
1265 case LOC_REF_ARG:
1266 case LOC_REGPARM_ADDR:
1267 case LOC_LOCAL:
1268 case LOC_COMPUTED:
1269 return NULL;
1270 default:
1271 break;
1272 }
1273 if (preferred_type == NULL)
1274 return NULL;
1275 return syms[preferred_index].symbol;
1276 }
1277
1278 static struct type*
1279 find_primitive_type (struct parser_state *par_state, const char *name)
1280 {
1281 struct type *type;
1282 type = language_lookup_primitive_type (par_state->language (),
1283 par_state->gdbarch (),
1284 name);
1285 if (type == NULL && strcmp ("system__address", name) == 0)
1286 type = type_system_address (par_state);
1287
1288 if (type != NULL)
1289 {
1290 /* Check to see if we have a regular definition of this
1291 type that just didn't happen to have been read yet. */
1292 struct symbol *sym;
1293 char *expanded_name =
1294 (char *) alloca (strlen (name) + sizeof ("standard__"));
1295 strcpy (expanded_name, "standard__");
1296 strcat (expanded_name, name);
1297 sym = ada_lookup_symbol (expanded_name, NULL, VAR_DOMAIN).symbol;
1298 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1299 type = SYMBOL_TYPE (sym);
1300 }
1301
1302 return type;
1303 }
1304
1305 static int
1306 chop_selector (char *name, int end)
1307 {
1308 int i;
1309 for (i = end - 1; i > 0; i -= 1)
1310 if (name[i] == '.' || (name[i] == '_' && name[i+1] == '_'))
1311 return i;
1312 return -1;
1313 }
1314
1315 /* If NAME is a string beginning with a separator (either '__', or
1316 '.'), chop this separator and return the result; else, return
1317 NAME. */
1318
1319 static char *
1320 chop_separator (char *name)
1321 {
1322 if (*name == '.')
1323 return name + 1;
1324
1325 if (name[0] == '_' && name[1] == '_')
1326 return name + 2;
1327
1328 return name;
1329 }
1330
1331 /* Given that SELS is a string of the form (<sep><identifier>)*, where
1332 <sep> is '__' or '.', write the indicated sequence of
1333 STRUCTOP_STRUCT expression operators. */
1334 static void
1335 write_selectors (struct parser_state *par_state, char *sels)
1336 {
1337 while (*sels != '\0')
1338 {
1339 char *p = chop_separator (sels);
1340 sels = p;
1341 while (*sels != '\0' && *sels != '.'
1342 && (sels[0] != '_' || sels[1] != '_'))
1343 sels += 1;
1344 operation_up arg = ada_pop ();
1345 pstate->push_new<ada_structop_operation>
1346 (std::move (arg), std::string (p, sels - p));
1347 }
1348 }
1349
1350 /* Write a variable access (OP_VAR_VALUE) to ambiguous encoded name
1351 NAME[0..LEN-1], in block context BLOCK, to be resolved later. Writes
1352 a temporary symbol that is valid until the next call to ada_parse.
1353 */
1354 static void
1355 write_ambiguous_var (struct parser_state *par_state,
1356 const struct block *block, char *name, int len)
1357 {
1358 struct symbol *sym = new (&temp_parse_space) symbol ();
1359
1360 SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
1361 sym->set_linkage_name (obstack_strndup (&temp_parse_space, name, len));
1362 sym->set_language (language_ada, nullptr);
1363
1364 par_state->push_new<ada_var_value_operation> (sym, block);
1365 }
1366
1367 /* A convenient wrapper around ada_get_field_index that takes
1368 a non NUL-terminated FIELD_NAME0 and a FIELD_NAME_LEN instead
1369 of a NUL-terminated field name. */
1370
1371 static int
1372 ada_nget_field_index (const struct type *type, const char *field_name0,
1373 int field_name_len, int maybe_missing)
1374 {
1375 char *field_name = (char *) alloca ((field_name_len + 1) * sizeof (char));
1376
1377 strncpy (field_name, field_name0, field_name_len);
1378 field_name[field_name_len] = '\0';
1379 return ada_get_field_index (type, field_name, maybe_missing);
1380 }
1381
1382 /* If encoded_field_name is the name of a field inside symbol SYM,
1383 then return the type of that field. Otherwise, return NULL.
1384
1385 This function is actually recursive, so if ENCODED_FIELD_NAME
1386 doesn't match one of the fields of our symbol, then try to see
1387 if ENCODED_FIELD_NAME could not be a succession of field names
1388 (in other words, the user entered an expression of the form
1389 TYPE_NAME.FIELD1.FIELD2.FIELD3), in which case we evaluate
1390 each field name sequentially to obtain the desired field type.
1391 In case of failure, we return NULL. */
1392
1393 static struct type *
1394 get_symbol_field_type (struct symbol *sym, char *encoded_field_name)
1395 {
1396 char *field_name = encoded_field_name;
1397 char *subfield_name;
1398 struct type *type = SYMBOL_TYPE (sym);
1399 int fieldno;
1400
1401 if (type == NULL || field_name == NULL)
1402 return NULL;
1403 type = check_typedef (type);
1404
1405 while (field_name[0] != '\0')
1406 {
1407 field_name = chop_separator (field_name);
1408
1409 fieldno = ada_get_field_index (type, field_name, 1);
1410 if (fieldno >= 0)
1411 return type->field (fieldno).type ();
1412
1413 subfield_name = field_name;
1414 while (*subfield_name != '\0' && *subfield_name != '.'
1415 && (subfield_name[0] != '_' || subfield_name[1] != '_'))
1416 subfield_name += 1;
1417
1418 if (subfield_name[0] == '\0')
1419 return NULL;
1420
1421 fieldno = ada_nget_field_index (type, field_name,
1422 subfield_name - field_name, 1);
1423 if (fieldno < 0)
1424 return NULL;
1425
1426 type = type->field (fieldno).type ();
1427 field_name = subfield_name;
1428 }
1429
1430 return NULL;
1431 }
1432
1433 /* Look up NAME0 (an unencoded identifier or dotted name) in BLOCK (or
1434 expression_block_context if NULL). If it denotes a type, return
1435 that type. Otherwise, write expression code to evaluate it as an
1436 object and return NULL. In this second case, NAME0 will, in general,
1437 have the form <name>(.<selector_name>)*, where <name> is an object
1438 or renaming encoded in the debugging data. Calls error if no
1439 prefix <name> matches a name in the debugging data (i.e., matches
1440 either a complete name or, as a wild-card match, the final
1441 identifier). */
1442
1443 static struct type*
1444 write_var_or_type (struct parser_state *par_state,
1445 const struct block *block, struct stoken name0)
1446 {
1447 int depth;
1448 char *encoded_name;
1449 int name_len;
1450
1451 if (block == NULL)
1452 block = par_state->expression_context_block;
1453
1454 std::string name_storage = ada_encode (name0.ptr);
1455 name_len = name_storage.size ();
1456 encoded_name = obstack_strndup (&temp_parse_space, name_storage.c_str (),
1457 name_len);
1458 for (depth = 0; depth < MAX_RENAMING_CHAIN_LENGTH; depth += 1)
1459 {
1460 int tail_index;
1461
1462 tail_index = name_len;
1463 while (tail_index > 0)
1464 {
1465 struct symbol *type_sym;
1466 struct symbol *renaming_sym;
1467 const char* renaming;
1468 int renaming_len;
1469 const char* renaming_expr;
1470 int terminator = encoded_name[tail_index];
1471
1472 encoded_name[tail_index] = '\0';
1473 std::vector<struct block_symbol> syms
1474 = ada_lookup_symbol_list (encoded_name, block, VAR_DOMAIN);
1475 encoded_name[tail_index] = terminator;
1476
1477 type_sym = select_possible_type_sym (syms);
1478
1479 if (type_sym != NULL)
1480 renaming_sym = type_sym;
1481 else if (syms.size () == 1)
1482 renaming_sym = syms[0].symbol;
1483 else
1484 renaming_sym = NULL;
1485
1486 switch (ada_parse_renaming (renaming_sym, &renaming,
1487 &renaming_len, &renaming_expr))
1488 {
1489 case ADA_NOT_RENAMING:
1490 break;
1491 case ADA_PACKAGE_RENAMING:
1492 case ADA_EXCEPTION_RENAMING:
1493 case ADA_SUBPROGRAM_RENAMING:
1494 {
1495 int alloc_len = renaming_len + name_len - tail_index + 1;
1496 char *new_name
1497 = (char *) obstack_alloc (&temp_parse_space, alloc_len);
1498 strncpy (new_name, renaming, renaming_len);
1499 strcpy (new_name + renaming_len, encoded_name + tail_index);
1500 encoded_name = new_name;
1501 name_len = renaming_len + name_len - tail_index;
1502 goto TryAfterRenaming;
1503 }
1504 case ADA_OBJECT_RENAMING:
1505 write_object_renaming (par_state, block, renaming, renaming_len,
1506 renaming_expr, MAX_RENAMING_CHAIN_LENGTH);
1507 write_selectors (par_state, encoded_name + tail_index);
1508 return NULL;
1509 default:
1510 internal_error (__FILE__, __LINE__,
1511 _("impossible value from ada_parse_renaming"));
1512 }
1513
1514 if (type_sym != NULL)
1515 {
1516 struct type *field_type;
1517
1518 if (tail_index == name_len)
1519 return SYMBOL_TYPE (type_sym);
1520
1521 /* We have some extraneous characters after the type name.
1522 If this is an expression "TYPE_NAME.FIELD0.[...].FIELDN",
1523 then try to get the type of FIELDN. */
1524 field_type
1525 = get_symbol_field_type (type_sym, encoded_name + tail_index);
1526 if (field_type != NULL)
1527 return field_type;
1528 else
1529 error (_("Invalid attempt to select from type: \"%s\"."),
1530 name0.ptr);
1531 }
1532 else if (tail_index == name_len && syms.empty ())
1533 {
1534 struct type *type = find_primitive_type (par_state,
1535 encoded_name);
1536
1537 if (type != NULL)
1538 return type;
1539 }
1540
1541 if (syms.size () == 1)
1542 {
1543 write_var_from_sym (par_state, syms[0].block, syms[0].symbol);
1544 write_selectors (par_state, encoded_name + tail_index);
1545 return NULL;
1546 }
1547 else if (syms.empty ())
1548 {
1549 struct bound_minimal_symbol msym
1550 = ada_lookup_simple_minsym (encoded_name);
1551 if (msym.minsym != NULL)
1552 {
1553 par_state->push_new<ada_var_msym_value_operation> (msym);
1554 /* Maybe cause error here rather than later? FIXME? */
1555 write_selectors (par_state, encoded_name + tail_index);
1556 return NULL;
1557 }
1558
1559 if (tail_index == name_len
1560 && strncmp (encoded_name, "standard__",
1561 sizeof ("standard__") - 1) == 0)
1562 error (_("No definition of \"%s\" found."), name0.ptr);
1563
1564 tail_index = chop_selector (encoded_name, tail_index);
1565 }
1566 else
1567 {
1568 write_ambiguous_var (par_state, block, encoded_name,
1569 tail_index);
1570 write_selectors (par_state, encoded_name + tail_index);
1571 return NULL;
1572 }
1573 }
1574
1575 if (!have_full_symbols () && !have_partial_symbols () && block == NULL)
1576 error (_("No symbol table is loaded. Use the \"file\" command."));
1577 if (block == par_state->expression_context_block)
1578 error (_("No definition of \"%s\" in current context."), name0.ptr);
1579 else
1580 error (_("No definition of \"%s\" in specified context."), name0.ptr);
1581
1582 TryAfterRenaming: ;
1583 }
1584
1585 error (_("Could not find renamed symbol \"%s\""), name0.ptr);
1586
1587 }
1588
1589 /* Write a left side of a component association (e.g., NAME in NAME =>
1590 exp). If NAME has the form of a selected component, write it as an
1591 ordinary expression. If it is a simple variable that unambiguously
1592 corresponds to exactly one symbol that does not denote a type or an
1593 object renaming, also write it normally as an OP_VAR_VALUE.
1594 Otherwise, write it as an OP_NAME.
1595
1596 Unfortunately, we don't know at this point whether NAME is supposed
1597 to denote a record component name or the value of an array index.
1598 Therefore, it is not appropriate to disambiguate an ambiguous name
1599 as we normally would, nor to replace a renaming with its referent.
1600 As a result, in the (one hopes) rare case that one writes an
1601 aggregate such as (R => 42) where R renames an object or is an
1602 ambiguous name, one must write instead ((R) => 42). */
1603
1604 static void
1605 write_name_assoc (struct parser_state *par_state, struct stoken name)
1606 {
1607 if (strchr (name.ptr, '.') == NULL)
1608 {
1609 std::vector<struct block_symbol> syms
1610 = ada_lookup_symbol_list (name.ptr,
1611 par_state->expression_context_block,
1612 VAR_DOMAIN);
1613
1614 if (syms.size () != 1 || SYMBOL_CLASS (syms[0].symbol) == LOC_TYPEDEF)
1615 pstate->push_new<ada_string_operation> (copy_name (name));
1616 else
1617 write_var_from_sym (par_state, syms[0].block, syms[0].symbol);
1618 }
1619 else
1620 if (write_var_or_type (par_state, NULL, name) != NULL)
1621 error (_("Invalid use of type."));
1622
1623 push_association<ada_name_association> (ada_pop ());
1624 }
1625
1626 /* Convert the character literal whose ASCII value would be VAL to the
1627 appropriate value of type TYPE, if there is a translation.
1628 Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
1629 the literal 'A' (VAL == 65), returns 0. */
1630
1631 static LONGEST
1632 convert_char_literal (struct type *type, LONGEST val)
1633 {
1634 char name[7];
1635 int f;
1636
1637 if (type == NULL)
1638 return val;
1639 type = check_typedef (type);
1640 if (type->code () != TYPE_CODE_ENUM)
1641 return val;
1642
1643 if ((val >= 'a' && val <= 'z') || (val >= '0' && val <= '9'))
1644 xsnprintf (name, sizeof (name), "Q%c", (int) val);
1645 else
1646 xsnprintf (name, sizeof (name), "QU%02x", (int) val);
1647 size_t len = strlen (name);
1648 for (f = 0; f < type->num_fields (); f += 1)
1649 {
1650 /* Check the suffix because an enum constant in a package will
1651 have a name like "pkg__QUxx". This is safe enough because we
1652 already have the correct type, and because mangling means
1653 there can't be clashes. */
1654 const char *ename = TYPE_FIELD_NAME (type, f);
1655 size_t elen = strlen (ename);
1656
1657 if (elen >= len && strcmp (name, ename + elen - len) == 0)
1658 return TYPE_FIELD_ENUMVAL (type, f);
1659 }
1660 return val;
1661 }
1662
1663 static struct type *
1664 type_int (struct parser_state *par_state)
1665 {
1666 return parse_type (par_state)->builtin_int;
1667 }
1668
1669 static struct type *
1670 type_long (struct parser_state *par_state)
1671 {
1672 return parse_type (par_state)->builtin_long;
1673 }
1674
1675 static struct type *
1676 type_long_long (struct parser_state *par_state)
1677 {
1678 return parse_type (par_state)->builtin_long_long;
1679 }
1680
1681 static struct type *
1682 type_long_double (struct parser_state *par_state)
1683 {
1684 return parse_type (par_state)->builtin_long_double;
1685 }
1686
1687 static struct type *
1688 type_char (struct parser_state *par_state)
1689 {
1690 return language_string_char_type (par_state->language (),
1691 par_state->gdbarch ());
1692 }
1693
1694 static struct type *
1695 type_boolean (struct parser_state *par_state)
1696 {
1697 return parse_type (par_state)->builtin_bool;
1698 }
1699
1700 static struct type *
1701 type_system_address (struct parser_state *par_state)
1702 {
1703 struct type *type
1704 = language_lookup_primitive_type (par_state->language (),
1705 par_state->gdbarch (),
1706 "system__address");
1707 return type != NULL ? type : parse_type (par_state)->builtin_data_ptr;
1708 }
1709
1710 void _initialize_ada_exp ();
1711 void
1712 _initialize_ada_exp ()
1713 {
1714 obstack_init (&temp_parse_space);
1715 }
This page took 0.068334 seconds and 4 git commands to generate.