1 /* YACC parser for Ada expressions, for GDB.
2 Copyright (C) 1986-2021 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"
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 */
52 #define parse_type(ps) builtin_type (ps->gdbarch ())
54 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
56 #define GDB_YY_REMAP_PREFIX ada_
61 struct minimal_symbol
*msym
;
62 const struct block
*block
;
66 /* The state of the parser, used internally when we are parsing the
69 static struct parser_state
*pstate
= NULL
;
71 /* If expression is in the context of TYPE'(...), then TYPE, else
73 static struct type
*type_qualifier
;
77 static int yylex (void);
79 static void yyerror (const char *);
81 static void write_int
(struct parser_state
*, LONGEST
, struct type
*);
83 static void write_object_renaming
(struct parser_state
*,
84 const struct block
*, const char *, int,
87 static struct type
* write_var_or_type
(struct parser_state
*,
88 const struct block
*, struct stoken
);
90 static void write_name_assoc
(struct parser_state
*, struct stoken
);
92 static const struct block
*block_lookup
(const struct block
*, const char *);
94 static LONGEST convert_char_literal
(struct type
*, LONGEST
);
96 static void write_ambiguous_var
(struct parser_state
*,
97 const struct block
*, char *, int);
99 static struct type
*type_int
(struct parser_state
*);
101 static struct type
*type_long
(struct parser_state
*);
103 static struct type
*type_long_long
(struct parser_state
*);
105 static struct type
*type_long_double
(struct parser_state
*);
107 static struct type
*type_char
(struct parser_state
*);
109 static struct type
*type_boolean
(struct parser_state
*);
111 static struct type
*type_system_address
(struct parser_state
*);
113 using namespace expr
;
115 /* Handle Ada type resolution for OP. DEPROCEDURE_P and CONTEXT_TYPE
116 are passed to the resolve method, if called. */
118 resolve
(operation_up
&&op
, bool deprocedure_p
, struct type
*context_type
)
120 operation_up result
= std
::move
(op
);
121 ada_resolvable
*res
= dynamic_cast
<ada_resolvable
*> (result.get
());
123 && res
->resolve
(pstate
->expout.get
(),
125 pstate
->parse_completion
,
126 pstate
->block_tracker
,
129 = make_operation
<ada_funcall_operation
> (std
::move
(result
),
130 std
::vector
<operation_up
> ());
135 /* Like parser_state::pop, but handles Ada type resolution.
136 DEPROCEDURE_P and CONTEXT_TYPE are passed to the resolve method, if
139 ada_pop
(bool deprocedure_p
= true
, struct type
*context_type
= nullptr
)
141 /* Of course it's ok to call parser_state::pop here... */
142 return resolve
(pstate
->pop
(), deprocedure_p
, context_type
);
145 /* Like parser_state::wrap, but use ada_pop to pop the value. */
150 operation_up arg
= ada_pop
();
151 pstate
->push_new
<T
> (std
::move
(arg
));
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
158 ada_addrof
(struct type
*type
= nullptr
)
160 operation_up arg
= ada_pop
(false
);
161 operation_up addr
= make_operation
<unop_addr_operation
> (std
::move
(arg
));
163 = make_operation
<ada_wrapped_operation
> (std
::move
(addr
));
165 wrapped
= make_operation
<unop_cast_operation
> (std
::move
(wrapped
), type
);
166 pstate
->push
(std
::move
(wrapped
));
169 /* Handle operator overloading. Either returns a function all
170 operation wrapping the arguments, or it returns null, leaving the
171 caller to construct the appropriate operation. If RHS is null, a
172 unary operator is assumed. */
174 maybe_overload
(enum exp_opcode op
, operation_up
&lhs
, operation_up
&rhs
)
176 struct value
*args
[2];
179 args
[0] = lhs
->evaluate
(nullptr
, pstate
->expout.get
(),
180 EVAL_AVOID_SIDE_EFFECTS
);
185 args
[1] = rhs
->evaluate
(nullptr
, pstate
->expout.get
(),
186 EVAL_AVOID_SIDE_EFFECTS
);
190 block_symbol fn
= ada_find_operator_symbol
(op
, pstate
->parse_completion
,
192 if
(fn.symbol
== nullptr
)
195 if
(symbol_read_needs_frame
(fn.symbol
))
196 pstate
->block_tracker
->update
(fn.block
, INNERMOST_BLOCK_FOR_SYMBOLS
);
197 operation_up callee
= make_operation
<ada_var_value_operation
> (fn
);
199 std
::vector
<operation_up
> argvec
;
200 argvec.push_back
(std
::move
(lhs
));
202 argvec.push_back
(std
::move
(rhs
));
203 return make_operation
<ada_funcall_operation
> (std
::move
(callee
),
207 /* Like parser_state::wrap, but use ada_pop to pop the value, and
208 handle unary overloading. */
211 ada_wrap_overload
(enum exp_opcode op
)
213 operation_up arg
= ada_pop
();
216 operation_up call
= maybe_overload
(op
, arg
, empty
);
218 call
= make_operation
<T
> (std
::move
(arg
));
219 pstate
->push
(std
::move
(call
));
222 /* A variant of parser_state::wrap2 that uses ada_pop to pop both
223 operands, and then pushes a new Ada-wrapped operation of the
227 ada_un_wrap2
(enum exp_opcode op
)
229 operation_up rhs
= ada_pop
();
230 operation_up lhs
= ada_pop
();
232 operation_up wrapped
= maybe_overload
(op
, lhs
, rhs
);
233 if
(wrapped
== nullptr
)
235 wrapped
= make_operation
<T
> (std
::move
(lhs
), std
::move
(rhs
));
236 wrapped
= make_operation
<ada_wrapped_operation
> (std
::move
(wrapped
));
238 pstate
->push
(std
::move
(wrapped
));
241 /* A variant of parser_state::wrap2 that uses ada_pop to pop both
242 operands. Unlike ada_un_wrap2, ada_wrapped_operation is not
246 ada_wrap2
(enum exp_opcode op
)
248 operation_up rhs
= ada_pop
();
249 operation_up lhs
= ada_pop
();
250 operation_up call
= maybe_overload
(op
, lhs
, rhs
);
252 call
= make_operation
<T
> (std
::move
(lhs
), std
::move
(rhs
));
253 pstate
->push
(std
::move
(call
));
256 /* A variant of parser_state::wrap2 that uses ada_pop to pop both
257 operands. OP is also passed to the constructor of the new binary
261 ada_wrap_op
(enum exp_opcode op
)
263 operation_up rhs
= ada_pop
();
264 operation_up lhs
= ada_pop
();
265 operation_up call
= maybe_overload
(op
, lhs
, rhs
);
267 call
= make_operation
<T
> (op
, std
::move
(lhs
), std
::move
(rhs
));
268 pstate
->push
(std
::move
(call
));
271 /* Pop three operands using ada_pop, then construct a new ternary
272 operation of type T and push it. */
277 operation_up rhs
= ada_pop
();
278 operation_up mid
= ada_pop
();
279 operation_up lhs
= ada_pop
();
280 pstate
->push_new
<T
> (std
::move
(lhs
), std
::move
(mid
), std
::move
(rhs
));
283 /* Pop NARGS operands, then a callee operand, and use these to
284 construct and push a new Ada function call operation. */
286 ada_funcall
(int nargs
)
288 /* We use the ordinary pop here, because we're going to do
289 resolution in a separate step, in order to handle array
291 std
::vector
<operation_up
> args
= pstate
->pop_vector
(nargs
);
292 /* Call parser_state::pop here, because we don't want to
293 function-convert the callee slot of a call we're already
295 operation_up callee
= pstate
->pop
();
297 ada_var_value_operation
*vvo
298 = dynamic_cast
<ada_var_value_operation
*> (callee.get
());
300 struct type
*callee_t
= nullptr
;
302 || SYMBOL_DOMAIN
(vvo
->get_symbol
()) != UNDEF_DOMAIN
)
304 struct value
*callee_v
= callee
->evaluate
(nullptr
,
305 pstate
->expout.get
(),
306 EVAL_AVOID_SIDE_EFFECTS
);
307 callee_t
= ada_check_typedef
(value_type
(callee_v
));
308 array_arity
= ada_array_arity
(callee_t
);
311 for
(int i
= 0; i
< nargs
; ++i
)
313 struct type
*subtype
= nullptr
;
315 subtype
= ada_index_type
(callee_t
, i
+ 1, "array type");
316 args
[i
] = resolve
(std
::move
(args
[i
]), true
, subtype
);
319 std
::unique_ptr
<ada_funcall_operation
> funcall
320 (new ada_funcall_operation
(std
::move
(callee
), std
::move
(args
)));
321 funcall
->resolve
(pstate
->expout.get
(), true
, pstate
->parse_completion
,
322 pstate
->block_tracker
, nullptr
);
323 pstate
->push
(std
::move
(funcall
));
326 /* The components being constructed during this parse. */
327 static std
::vector
<ada_component_up
> components
;
329 /* Create a new ada_component_up of the indicated type and arguments,
330 and push it on the global 'components' vector. */
331 template
<typename T
, typename... Arg
>
333 push_component
(Arg... args
)
335 components.emplace_back
(new T
(std
::forward
<Arg
> (args
)...
));
338 /* Examine the final element of the 'components' vector, and return it
339 as a pointer to an ada_choices_component. The caller is
340 responsible for ensuring that the final element is in fact an
341 ada_choices_component. */
342 static ada_choices_component
*
345 ada_component
*last
= components.back
().get
();
346 ada_choices_component
*result
= dynamic_cast
<ada_choices_component
*> (last
);
347 gdb_assert
(result
!= nullptr
);
351 /* Pop the most recent component from the global stack, and return
353 static ada_component_up
356 ada_component_up result
= std
::move
(components.back
());
357 components.pop_back
();
361 /* Pop the N most recent components from the global stack, and return
363 static std
::vector
<ada_component_up
>
364 pop_components
(int n
)
366 std
::vector
<ada_component_up
> result
(n
);
367 for
(int i
= 1; i
<= n
; ++i
)
368 result
[n
- i
] = pop_component
();
372 /* The associations being constructed during this parse. */
373 static std
::vector
<ada_association_up
> associations
;
375 /* Create a new ada_association_up of the indicated type and
376 arguments, and push it on the global 'associations' vector. */
377 template
<typename T
, typename... Arg
>
379 push_association
(Arg... args
)
381 associations.emplace_back
(new T
(std
::forward
<Arg
> (args
)...
));
384 /* Pop the most recent association from the global stack, and return
386 static ada_association_up
389 ada_association_up result
= std
::move
(associations.back
());
390 associations.pop_back
();
394 /* Pop the N most recent associations from the global stack, and
395 return them in a vector. */
396 static std
::vector
<ada_association_up
>
397 pop_associations
(int n
)
399 std
::vector
<ada_association_up
> result
(n
);
400 for
(int i
= 1; i
<= n
; ++i
)
401 result
[n
- i
] = pop_association
();
420 const struct block
*bval
;
421 struct internalvar
*ivar
;
424 %type
<lval
> positional_list component_groups component_associations
425 %type
<lval
> aggregate_component_list
426 %type
<tval
> var_or_type type_prefix opt_type_prefix
428 %token
<typed_val
> INT NULL_PTR CHARLIT
429 %token
<typed_val_float
> FLOAT
430 %token TRUEKEYWORD FALSEKEYWORD
432 %token
<sval
> STRING NAME DOT_ID
434 %type
<lval
> arglist tick_arglist
436 %type
<tval
> save_qualifier
440 /* Special type cases, put in to allow the parser to distinguish different
442 %token
<sval
> DOLLAR_VARIABLE
445 %left _AND_ OR XOR THEN ELSE
446 %left
'=' NOTEQUAL
'<' '>' LEQ GEQ IN DOTDOT
450 %left
'*' '/' MOD REM
451 %right STARSTAR ABS NOT
453 /* Artificial token to give NAME => ... and NAME | priority over reducing
454 NAME to <primary> and to give <primary>' priority over reducing <primary>
460 %right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
461 %right TICK_MAX TICK_MIN TICK_MODULUS
462 %right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
463 /* The following are right-associative only so that reductions at this
464 precedence have lower precedence than '.' and '('. The syntax still
465 forces a.b.c, e.g., to be LEFT-associated. */
466 %right
'.' '(' '[' DOT_ID DOT_ALL
476 /* Expressions, including the sequencing operator. */
479 { ada_wrap2
<comma_operation
> (BINOP_COMMA
); }
480 | primary ASSIGN exp
/* Extension for convenience */
482 operation_up rhs
= pstate
->pop
();
483 operation_up lhs
= ada_pop
();
485 = lhs
->evaluate
(nullptr
, pstate
->expout.get
(),
486 EVAL_AVOID_SIDE_EFFECTS
);
487 rhs
= resolve
(std
::move
(rhs
), true
,
488 value_type
(lhs_val
));
489 pstate
->push_new
<ada_assign_operation
>
490 (std
::move
(lhs
), std
::move
(rhs
));
494 /* Expressions, not including the sequencing operator. */
495 primary
: primary DOT_ALL
496 { ada_wrap
<ada_unop_ind_operation
> (); }
499 primary
: primary DOT_ID
501 operation_up arg
= ada_pop
();
502 pstate
->push_new
<ada_structop_operation
>
503 (std
::move
(arg
), copy_name
($2));
507 primary
: primary
'(' arglist
')'
508 { ada_funcall
($3); }
509 | var_or_type
'(' arglist
')'
514 error (_
("Invalid conversion"));
515 operation_up arg
= ada_pop
();
516 pstate
->push_new
<unop_cast_operation
>
517 (std
::move
(arg
), $1);
524 primary
: var_or_type
'\'' save_qualifier
{ type_qualifier
= $1; }
528 error (_
("Type required for qualification"));
529 operation_up arg
= ada_pop
(true
,
531 pstate
->push_new
<ada_qual_operation
>
532 (std
::move
(arg
), $1);
537 save_qualifier
: { $$
= type_qualifier
; }
541 primary
'(' simple_exp DOTDOT simple_exp
')'
542 { ada_wrap3
<ada_ternop_slice_operation
> (); }
543 | var_or_type
'(' simple_exp DOTDOT simple_exp
')'
545 ada_wrap3
<ada_ternop_slice_operation
> ();
547 error (_
("Cannot slice a type"));
551 primary
: '(' exp1
')' { }
554 /* The following rule causes a conflict with the type conversion
556 To get around it, we give '(' higher priority and add bridge rules for
557 var_or_type (exp, exp, ...)
558 var_or_type (exp .. exp)
559 We also have the action for var_or_type(exp) generate a function call
560 when the first symbol does not denote a type. */
562 primary
: var_or_type %prec VAR
564 pstate
->push_new
<type_operation
> ($1);
568 primary
: DOLLAR_VARIABLE
/* Various GDB extensions */
569 { pstate
->push_dollar
($1); }
574 pstate
->push_new
<ada_aggregate_operation
>
582 simple_exp
: '-' simple_exp %prec UNARY
583 { ada_wrap_overload
<ada_neg_operation
> (UNOP_NEG
); }
586 simple_exp
: '+' simple_exp %prec UNARY
588 operation_up arg
= ada_pop
();
591 /* If an overloaded operator was found, use
592 it. Otherwise, unary + has no effect and
593 the argument can be pushed instead. */
594 operation_up call
= maybe_overload
(UNOP_PLUS
, arg
,
597 arg
= std
::move
(call
);
598 pstate
->push
(std
::move
(arg
));
602 simple_exp
: NOT simple_exp %prec UNARY
604 ada_wrap_overload
<unary_logical_not_operation
>
609 simple_exp
: ABS simple_exp %prec UNARY
610 { ada_wrap_overload
<ada_abs_operation
> (UNOP_ABS
); }
613 arglist
: { $$
= 0; }
622 | arglist
',' NAME ARROW exp
626 primary
: '{' var_or_type
'}' primary %prec
'.'
630 error (_
("Type required within braces in coercion"));
631 operation_up arg
= ada_pop
();
632 pstate
->push_new
<unop_memval_operation
>
633 (std
::move
(arg
), $2);
637 /* Binary operators in order of decreasing precedence. */
639 simple_exp
: simple_exp STARSTAR simple_exp
640 { ada_wrap2
<ada_binop_exp_operation
> (BINOP_EXP
); }
643 simple_exp
: simple_exp
'*' simple_exp
644 { ada_wrap2
<ada_binop_mul_operation
> (BINOP_MUL
); }
647 simple_exp
: simple_exp
'/' simple_exp
648 { ada_wrap2
<ada_binop_div_operation
> (BINOP_DIV
); }
651 simple_exp
: simple_exp REM simple_exp
/* May need to be fixed to give correct Ada REM */
652 { ada_wrap2
<ada_binop_rem_operation
> (BINOP_REM
); }
655 simple_exp
: simple_exp MOD simple_exp
656 { ada_wrap2
<ada_binop_mod_operation
> (BINOP_MOD
); }
659 simple_exp
: simple_exp
'@' simple_exp
/* GDB extension */
660 { ada_wrap2
<repeat_operation
> (BINOP_REPEAT
); }
663 simple_exp
: simple_exp
'+' simple_exp
664 { ada_wrap_op
<ada_binop_addsub_operation
> (BINOP_ADD
); }
667 simple_exp
: simple_exp
'&' simple_exp
668 { ada_wrap2
<concat_operation
> (BINOP_CONCAT
); }
671 simple_exp
: simple_exp
'-' simple_exp
672 { ada_wrap_op
<ada_binop_addsub_operation
> (BINOP_SUB
); }
675 relation
: simple_exp
678 relation
: simple_exp
'=' simple_exp
679 { ada_wrap_op
<ada_binop_equal_operation
> (BINOP_EQUAL
); }
682 relation
: simple_exp NOTEQUAL simple_exp
683 { ada_wrap_op
<ada_binop_equal_operation
> (BINOP_NOTEQUAL
); }
686 relation
: simple_exp LEQ simple_exp
687 { ada_un_wrap2
<leq_operation
> (BINOP_LEQ
); }
690 relation
: simple_exp IN simple_exp DOTDOT simple_exp
691 { ada_wrap3
<ada_ternop_range_operation
> (); }
692 | simple_exp IN primary TICK_RANGE tick_arglist
694 operation_up rhs
= ada_pop
();
695 operation_up lhs
= ada_pop
();
696 pstate
->push_new
<ada_binop_in_bounds_operation
>
697 (std
::move
(lhs
), std
::move
(rhs
), $5);
699 | simple_exp IN var_or_type %prec TICK_ACCESS
702 error (_
("Right operand of 'in' must be type"));
703 operation_up arg
= ada_pop
();
704 pstate
->push_new
<ada_unop_range_operation
>
705 (std
::move
(arg
), $3);
707 | simple_exp NOT IN simple_exp DOTDOT simple_exp
708 { ada_wrap3
<ada_ternop_range_operation
> ();
709 ada_wrap
<unary_logical_not_operation
> (); }
710 | simple_exp NOT IN primary TICK_RANGE tick_arglist
712 operation_up rhs
= ada_pop
();
713 operation_up lhs
= ada_pop
();
714 pstate
->push_new
<ada_binop_in_bounds_operation
>
715 (std
::move
(lhs
), std
::move
(rhs
), $6);
716 ada_wrap
<unary_logical_not_operation
> ();
718 | simple_exp NOT IN var_or_type %prec TICK_ACCESS
721 error (_
("Right operand of 'in' must be type"));
722 operation_up arg
= ada_pop
();
723 pstate
->push_new
<ada_unop_range_operation
>
724 (std
::move
(arg
), $4);
725 ada_wrap
<unary_logical_not_operation
> ();
729 relation
: simple_exp GEQ simple_exp
730 { ada_un_wrap2
<geq_operation
> (BINOP_GEQ
); }
733 relation
: simple_exp
'<' simple_exp
734 { ada_un_wrap2
<less_operation
> (BINOP_LESS
); }
737 relation
: simple_exp
'>' simple_exp
738 { ada_un_wrap2
<gtr_operation
> (BINOP_GTR
); }
750 relation _AND_ relation
751 { ada_wrap2
<ada_bitwise_and_operation
>
752 (BINOP_BITWISE_AND
); }
753 | and_exp _AND_ relation
754 { ada_wrap2
<ada_bitwise_and_operation
>
755 (BINOP_BITWISE_AND
); }
759 relation _AND_ THEN relation
760 { ada_wrap2
<logical_and_operation
>
761 (BINOP_LOGICAL_AND
); }
762 | and_then_exp _AND_ THEN relation
763 { ada_wrap2
<logical_and_operation
>
764 (BINOP_LOGICAL_AND
); }
769 { ada_wrap2
<ada_bitwise_ior_operation
>
770 (BINOP_BITWISE_IOR
); }
772 { ada_wrap2
<ada_bitwise_ior_operation
>
773 (BINOP_BITWISE_IOR
); }
777 relation OR ELSE relation
778 { ada_wrap2
<logical_or_operation
> (BINOP_LOGICAL_OR
); }
779 | or_else_exp OR ELSE relation
780 { ada_wrap2
<logical_or_operation
> (BINOP_LOGICAL_OR
); }
783 xor_exp
: relation XOR relation
784 { ada_wrap2
<ada_bitwise_xor_operation
>
785 (BINOP_BITWISE_XOR
); }
786 | xor_exp XOR relation
787 { ada_wrap2
<ada_bitwise_xor_operation
>
788 (BINOP_BITWISE_XOR
); }
791 /* Primaries can denote types (OP_TYPE). In cases such as
792 primary TICK_ADDRESS, where a type would be invalid, it will be
793 caught when evaluate_subexp in ada-lang.c tries to evaluate the
794 primary, expecting a value. Precedence rules resolve the ambiguity
795 in NAME TICK_ACCESS in favor of shifting to form a var_or_type. A
796 construct such as aType'access'access will again cause an error when
797 aType'access evaluates to a type that evaluate_subexp attempts to
799 primary
: primary TICK_ACCESS
801 | primary TICK_ADDRESS
802 { ada_addrof
(type_system_address
(pstate
)); }
803 | primary TICK_FIRST tick_arglist
805 operation_up arg
= ada_pop
();
806 pstate
->push_new
<ada_unop_atr_operation
>
807 (std
::move
(arg
), OP_ATR_FIRST
, $3);
809 | primary TICK_LAST tick_arglist
811 operation_up arg
= ada_pop
();
812 pstate
->push_new
<ada_unop_atr_operation
>
813 (std
::move
(arg
), OP_ATR_LAST
, $3);
815 | primary TICK_LENGTH tick_arglist
817 operation_up arg
= ada_pop
();
818 pstate
->push_new
<ada_unop_atr_operation
>
819 (std
::move
(arg
), OP_ATR_LENGTH
, $3);
822 { ada_wrap
<ada_atr_size_operation
> (); }
824 { ada_wrap
<ada_atr_tag_operation
> (); }
825 | opt_type_prefix TICK_MIN
'(' exp
',' exp
')'
826 { ada_wrap2
<ada_binop_min_operation
> (BINOP_MIN
); }
827 | opt_type_prefix TICK_MAX
'(' exp
',' exp
')'
828 { ada_wrap2
<ada_binop_max_operation
> (BINOP_MAX
); }
829 | opt_type_prefix TICK_POS
'(' exp
')'
830 { ada_wrap
<ada_pos_operation
> (); }
831 | type_prefix TICK_VAL
'(' exp
')'
833 operation_up arg
= ada_pop
();
834 pstate
->push_new
<ada_atr_val_operation
>
835 ($1, std
::move
(arg
));
837 | type_prefix TICK_MODULUS
839 struct type
*type_arg
= check_typedef
($1);
840 if
(!ada_is_modular_type
(type_arg
))
841 error (_
("'modulus must be applied to modular type"));
842 write_int
(pstate
, ada_modulus
(type_arg
),
843 TYPE_TARGET_TYPE
(type_arg
));
847 tick_arglist
: %prec
'('
857 error (_
("Prefix must be type"));
866 { $$
= parse_type
(pstate
)->builtin_void
; }
871 { write_int
(pstate
, (LONGEST
) $1.val
, $1.type
); }
876 convert_char_literal
(type_qualifier
, $1.val
),
877 (type_qualifier
== NULL
)
878 ?
$1.type
: type_qualifier
);
885 std
::copy
(std
::begin
($1.val
), std
::end
($1.val
),
887 pstate
->push_new
<float_const_operation
>
889 ada_wrap
<ada_wrapped_operation
> ();
894 { write_int
(pstate
, 0, type_int
(pstate
)); }
899 pstate
->push_new
<ada_string_operation
>
904 primary
: TRUEKEYWORD
905 { write_int
(pstate
, 1, type_boolean
(pstate
)); }
907 { write_int
(pstate
, 0, type_boolean
(pstate
)); }
911 { error (_
("NEW not implemented.")); }
914 var_or_type: NAME %prec VAR
915 { $$
= write_var_or_type
(pstate
, NULL
, $1); }
916 | block NAME %prec VAR
917 { $$
= write_var_or_type
(pstate
, $1, $2); }
920 $$
= write_var_or_type
(pstate
, NULL
, $1);
924 $$
= lookup_pointer_type
($$
);
926 | block NAME TICK_ACCESS
928 $$
= write_var_or_type
(pstate
, $1, $2);
932 $$
= lookup_pointer_type
($$
);
937 block
: NAME COLONCOLON
938 { $$
= block_lookup
(NULL
, $1.ptr
); }
939 | block NAME COLONCOLON
940 { $$
= block_lookup
($1, $2.ptr
); }
944 '(' aggregate_component_list
')'
946 std
::vector
<ada_component_up
> components
947 = pop_components
($2);
949 push_component
<ada_aggregate_component
>
950 (std
::move
(components
));
954 aggregate_component_list
:
955 component_groups
{ $$
= $1; }
956 | positional_list exp
958 push_component
<ada_positional_component
>
962 | positional_list component_groups
969 push_component
<ada_positional_component
>
973 | positional_list exp
','
975 push_component
<ada_positional_component
>
983 | component_group
{ $$
= 1; }
984 | component_group
',' component_groups
988 others
: OTHERS ARROW exp
990 push_component
<ada_others_component
> (ada_pop
());
995 component_associations
997 ada_choices_component
*choices
= choice_component
();
998 choices
->set_associations
(pop_associations
($1));
1002 /* We use this somewhat obscure definition in order to handle NAME => and
1003 NAME | differently from exp => and exp |. ARROW and '|' have a precedence
1004 above that of the reduction of NAME to var_or_type. By delaying
1005 decisions until after the => or '|', we convert the ambiguity to a
1006 resolved shift/reduce conflict. */
1007 component_associations
:
1010 push_component
<ada_choices_component
> (ada_pop
());
1011 write_name_assoc
(pstate
, $1);
1014 | simple_exp ARROW exp
1016 push_component
<ada_choices_component
> (ada_pop
());
1017 push_association
<ada_name_association
> (ada_pop
());
1020 | simple_exp DOTDOT simple_exp ARROW exp
1022 push_component
<ada_choices_component
> (ada_pop
());
1023 operation_up rhs
= ada_pop
();
1024 operation_up lhs
= ada_pop
();
1025 push_association
<ada_discrete_range_association
>
1026 (std
::move
(lhs
), std
::move
(rhs
));
1029 | NAME
'|' component_associations
1031 write_name_assoc
(pstate
, $1);
1034 | simple_exp
'|' component_associations
1036 push_association
<ada_name_association
> (ada_pop
());
1039 | simple_exp DOTDOT simple_exp
'|' component_associations
1042 operation_up rhs
= ada_pop
();
1043 operation_up lhs
= ada_pop
();
1044 push_association
<ada_discrete_range_association
>
1045 (std
::move
(lhs
), std
::move
(rhs
));
1050 /* Some extensions borrowed from C, for the benefit of those who find they
1051 can't get used to Ada notation in GDB. */
1053 primary
: '*' primary %prec
'.'
1054 { ada_wrap
<ada_unop_ind_operation
> (); }
1055 |
'&' primary %prec
'.'
1057 | primary
'[' exp
']'
1059 ada_wrap2
<subscript_operation
> (BINOP_SUBSCRIPT
);
1060 ada_wrap
<ada_wrapped_operation
> ();
1066 /* yylex defined in ada-lex.c: Reads one token, getting characters */
1067 /* through lexptr. */
1069 /* Remap normal flex interface names (yylex) as well as gratuitiously */
1070 /* global symbol names, so we can have multiple flex-generated parsers */
1073 /* (See note above on previous definitions for YACC.) */
1075 #define yy_create_buffer ada_yy_create_buffer
1076 #define yy_delete_buffer ada_yy_delete_buffer
1077 #define yy_init_buffer ada_yy_init_buffer
1078 #define yy_load_buffer_state ada_yy_load_buffer_state
1079 #define yy_switch_to_buffer ada_yy_switch_to_buffer
1080 #define yyrestart ada_yyrestart
1081 #define yytext ada_yytext
1083 static struct obstack temp_parse_space
;
1085 /* The following kludge was found necessary to prevent conflicts between */
1086 /* defs.h and non-standard stdlib.h files. */
1087 #define qsort __qsort__dummy
1088 #include "ada-lex.c"
1091 ada_parse
(struct parser_state
*par_state
)
1093 /* Setting up the parser state. */
1094 scoped_restore pstate_restore
= make_scoped_restore
(&pstate
);
1095 gdb_assert
(par_state
!= NULL
);
1098 lexer_init
(yyin
); /* (Re-)initialize lexer. */
1099 type_qualifier
= NULL
;
1100 obstack_free
(&temp_parse_space
, NULL
);
1101 obstack_init
(&temp_parse_space
);
1102 components.clear
();
1103 associations.clear
();
1105 int result
= yyparse ();
1108 struct type
*context_type
= nullptr
;
1109 if
(par_state
->void_context_p
)
1110 context_type
= parse_type
(par_state
)->builtin_void
;
1111 pstate
->set_operation
(ada_pop
(true
, context_type
));
1117 yyerror (const char *msg
)
1119 error (_
("Error in expression, near `%s'."), pstate
->lexptr
);
1122 /* Emit expression to access an instance of SYM, in block BLOCK (if
1126 write_var_from_sym
(struct parser_state
*par_state
, block_symbol sym
)
1128 if
(symbol_read_needs_frame
(sym.symbol
))
1129 par_state
->block_tracker
->update
(sym.block
, INNERMOST_BLOCK_FOR_SYMBOLS
);
1131 par_state
->push_new
<ada_var_value_operation
> (sym
);
1134 /* Write integer or boolean constant ARG of type TYPE. */
1137 write_int
(struct parser_state
*par_state
, LONGEST arg
, struct type
*type
)
1139 pstate
->push_new
<long_const_operation
> (type
, arg
);
1140 ada_wrap
<ada_wrapped_operation
> ();
1143 /* Emit expression corresponding to the renamed object named
1144 * designated by RENAMED_ENTITY[0 .. RENAMED_ENTITY_LEN-1] in the
1145 * context of ORIG_LEFT_CONTEXT, to which is applied the operations
1146 * encoded by RENAMING_EXPR. MAX_DEPTH is the maximum number of
1147 * cascaded renamings to allow. If ORIG_LEFT_CONTEXT is null, it
1148 * defaults to the currently selected block. ORIG_SYMBOL is the
1149 * symbol that originally encoded the renaming. It is needed only
1150 * because its prefix also qualifies any index variables used to index
1151 * or slice an array. It should not be necessary once we go to the
1152 * new encoding entirely (FIXME pnh 7/20/2007). */
1155 write_object_renaming
(struct parser_state
*par_state
,
1156 const struct block
*orig_left_context
,
1157 const char *renamed_entity
, int renamed_entity_len
,
1158 const char *renaming_expr
, int max_depth
)
1161 enum { SIMPLE_INDEX
, LOWER_BOUND
, UPPER_BOUND
} slice_state
;
1162 struct block_symbol sym_info
;
1165 error (_
("Could not find renamed symbol"));
1167 if
(orig_left_context
== NULL
)
1168 orig_left_context
= get_selected_block
(NULL
);
1170 name
= obstack_strndup
(&temp_parse_space
, renamed_entity
,
1171 renamed_entity_len
);
1172 ada_lookup_encoded_symbol
(name
, orig_left_context
, VAR_DOMAIN
, &sym_info
);
1173 if
(sym_info.symbol
== NULL
)
1174 error (_
("Could not find renamed variable: %s"), ada_decode
(name
).c_str
());
1175 else if
(SYMBOL_CLASS
(sym_info.symbol
) == LOC_TYPEDEF
)
1176 /* We have a renaming of an old-style renaming symbol. Don't
1177 trust the block information. */
1178 sym_info.block
= orig_left_context
;
1181 const char *inner_renamed_entity
;
1182 int inner_renamed_entity_len
;
1183 const char *inner_renaming_expr
;
1185 switch
(ada_parse_renaming
(sym_info.symbol
, &inner_renamed_entity
,
1186 &inner_renamed_entity_len
,
1187 &inner_renaming_expr
))
1189 case ADA_NOT_RENAMING
:
1190 write_var_from_sym
(par_state
, sym_info
);
1192 case ADA_OBJECT_RENAMING
:
1193 write_object_renaming
(par_state
, sym_info.block
,
1194 inner_renamed_entity
, inner_renamed_entity_len
,
1195 inner_renaming_expr
, max_depth
- 1);
1202 slice_state
= SIMPLE_INDEX
;
1203 while
(*renaming_expr
== 'X')
1207 switch
(*renaming_expr
) {
1210 ada_wrap
<ada_unop_ind_operation
> ();
1213 slice_state
= LOWER_BOUND
;
1217 if
(isdigit
(*renaming_expr
))
1220 long val
= strtol
(renaming_expr
, &next
, 10);
1221 if
(next
== renaming_expr
)
1223 renaming_expr
= next
;
1224 write_int
(par_state
, val
, type_int
(par_state
));
1230 struct block_symbol index_sym_info
;
1232 end
= strchr
(renaming_expr
, 'X');
1234 end
= renaming_expr
+ strlen
(renaming_expr
);
1236 index_name
= obstack_strndup
(&temp_parse_space
, renaming_expr
,
1237 end
- renaming_expr
);
1238 renaming_expr
= end
;
1240 ada_lookup_encoded_symbol
(index_name
, orig_left_context
,
1241 VAR_DOMAIN
, &index_sym_info
);
1242 if
(index_sym_info.symbol
== NULL
)
1243 error (_
("Could not find %s"), index_name
);
1244 else if
(SYMBOL_CLASS
(index_sym_info.symbol
) == LOC_TYPEDEF
)
1245 /* Index is an old-style renaming symbol. */
1246 index_sym_info.block
= orig_left_context
;
1247 write_var_from_sym
(par_state
, index_sym_info
);
1249 if
(slice_state
== SIMPLE_INDEX
)
1251 else if
(slice_state
== LOWER_BOUND
)
1252 slice_state
= UPPER_BOUND
;
1253 else if
(slice_state
== UPPER_BOUND
)
1255 ada_wrap3
<ada_ternop_slice_operation
> ();
1256 slice_state
= SIMPLE_INDEX
;
1266 if
(slice_state
!= SIMPLE_INDEX
)
1268 end
= strchr
(renaming_expr
, 'X');
1270 end
= renaming_expr
+ strlen
(renaming_expr
);
1272 operation_up arg
= ada_pop
();
1273 pstate
->push_new
<ada_structop_operation
>
1274 (std
::move
(arg
), std
::string (renaming_expr
,
1275 end
- renaming_expr
));
1276 renaming_expr
= end
;
1284 if
(slice_state
== SIMPLE_INDEX
)
1288 error (_
("Internal error in encoding of renaming declaration"));
1291 static const struct block
*
1292 block_lookup
(const struct block
*context
, const char *raw_name
)
1295 struct symtab
*symtab
;
1296 const struct block
*result
= NULL
;
1298 std
::string name_storage
;
1299 if
(raw_name
[0] == '\'')
1306 name_storage
= ada_encode
(raw_name
);
1307 name
= name_storage.c_str
();
1310 std
::vector
<struct block_symbol
> syms
1311 = ada_lookup_symbol_list
(name
, context
, VAR_DOMAIN
);
1314 && (syms.empty
() || SYMBOL_CLASS
(syms
[0].symbol
) != LOC_BLOCK
))
1315 symtab
= lookup_symtab
(name
);
1320 result
= BLOCKVECTOR_BLOCK
(SYMTAB_BLOCKVECTOR
(symtab
), STATIC_BLOCK
);
1321 else if
(syms.empty
() || SYMBOL_CLASS
(syms
[0].symbol
) != LOC_BLOCK
)
1323 if
(context
== NULL
)
1324 error (_
("No file or function \"%s\"."), raw_name
);
1326 error (_
("No function \"%s\" in specified context."), raw_name
);
1330 if
(syms.size
() > 1)
1331 warning
(_
("Function name \"%s\" ambiguous here"), raw_name
);
1332 result
= SYMBOL_BLOCK_VALUE
(syms
[0].symbol
);
1338 static struct symbol
*
1339 select_possible_type_sym
(const std
::vector
<struct block_symbol
> &syms
)
1342 int preferred_index
;
1343 struct type
*preferred_type
;
1345 preferred_index
= -1; preferred_type
= NULL
;
1346 for
(i
= 0; i
< syms.size
(); i
+= 1)
1347 switch
(SYMBOL_CLASS
(syms
[i
].symbol
))
1350 if
(ada_prefer_type
(SYMBOL_TYPE
(syms
[i
].symbol
), preferred_type
))
1352 preferred_index
= i
;
1353 preferred_type
= SYMBOL_TYPE
(syms
[i
].symbol
);
1359 case LOC_REGPARM_ADDR
:
1366 if
(preferred_type
== NULL
)
1368 return syms
[preferred_index
].symbol
;
1372 find_primitive_type
(struct parser_state
*par_state
, const char *name
)
1375 type
= language_lookup_primitive_type
(par_state
->language
(),
1376 par_state
->gdbarch
(),
1378 if
(type
== NULL
&& strcmp
("system__address", name
) == 0)
1379 type
= type_system_address
(par_state
);
1383 /* Check to see if we have a regular definition of this
1384 type that just didn't happen to have been read yet. */
1386 char *expanded_name
=
1387 (char *) alloca
(strlen
(name
) + sizeof
("standard__"));
1388 strcpy
(expanded_name
, "standard__");
1389 strcat
(expanded_name
, name
);
1390 sym
= ada_lookup_symbol
(expanded_name
, NULL
, VAR_DOMAIN
).symbol
;
1391 if
(sym
!= NULL
&& SYMBOL_CLASS
(sym
) == LOC_TYPEDEF
)
1392 type
= SYMBOL_TYPE
(sym
);
1399 chop_selector
(char *name
, int end
)
1402 for
(i
= end
- 1; i
> 0; i
-= 1)
1403 if
(name
[i
] == '.' ||
(name
[i
] == '_' && name
[i
+1] == '_'))
1408 /* If NAME is a string beginning with a separator (either '__', or
1409 '.'), chop this separator and return the result; else, return
1413 chop_separator
(char *name
)
1418 if
(name
[0] == '_' && name
[1] == '_')
1424 /* Given that SELS is a string of the form (<sep><identifier>)*, where
1425 <sep> is '__' or '.', write the indicated sequence of
1426 STRUCTOP_STRUCT expression operators. */
1428 write_selectors
(struct parser_state
*par_state
, char *sels
)
1430 while
(*sels
!= '\0')
1432 char *p
= chop_separator
(sels
);
1434 while
(*sels
!= '\0' && *sels
!= '.'
1435 && (sels
[0] != '_' || sels
[1] != '_'))
1437 operation_up arg
= ada_pop
();
1438 pstate
->push_new
<ada_structop_operation
>
1439 (std
::move
(arg
), std
::string (p
, sels
- p
));
1443 /* Write a variable access (OP_VAR_VALUE) to ambiguous encoded name
1444 NAME[0..LEN-1], in block context BLOCK, to be resolved later. Writes
1445 a temporary symbol that is valid until the next call to ada_parse.
1448 write_ambiguous_var
(struct parser_state
*par_state
,
1449 const struct block
*block
, char *name
, int len
)
1451 struct symbol
*sym
= new
(&temp_parse_space
) symbol
();
1453 SYMBOL_DOMAIN
(sym
) = UNDEF_DOMAIN
;
1454 sym
->set_linkage_name
(obstack_strndup
(&temp_parse_space
, name
, len
));
1455 sym
->set_language
(language_ada
, nullptr
);
1457 block_symbol bsym
{ sym
, block
};
1458 par_state
->push_new
<ada_var_value_operation
> (bsym
);
1461 /* A convenient wrapper around ada_get_field_index that takes
1462 a non NUL-terminated FIELD_NAME0 and a FIELD_NAME_LEN instead
1463 of a NUL-terminated field name. */
1466 ada_nget_field_index
(const struct type
*type
, const char *field_name0
,
1467 int field_name_len
, int maybe_missing
)
1469 char *field_name
= (char *) alloca
((field_name_len
+ 1) * sizeof
(char));
1471 strncpy
(field_name
, field_name0
, field_name_len
);
1472 field_name
[field_name_len
] = '\0';
1473 return ada_get_field_index
(type
, field_name
, maybe_missing
);
1476 /* If encoded_field_name is the name of a field inside symbol SYM,
1477 then return the type of that field. Otherwise, return NULL.
1479 This function is actually recursive, so if ENCODED_FIELD_NAME
1480 doesn't match one of the fields of our symbol, then try to see
1481 if ENCODED_FIELD_NAME could not be a succession of field names
1482 (in other words, the user entered an expression of the form
1483 TYPE_NAME.FIELD1.FIELD2.FIELD3), in which case we evaluate
1484 each field name sequentially to obtain the desired field type.
1485 In case of failure, we return NULL. */
1487 static struct type
*
1488 get_symbol_field_type
(struct symbol
*sym
, char *encoded_field_name
)
1490 char *field_name
= encoded_field_name
;
1491 char *subfield_name
;
1492 struct type
*type
= SYMBOL_TYPE
(sym
);
1495 if
(type
== NULL || field_name
== NULL
)
1497 type
= check_typedef
(type
);
1499 while
(field_name
[0] != '\0')
1501 field_name
= chop_separator
(field_name
);
1503 fieldno
= ada_get_field_index
(type
, field_name
, 1);
1505 return type
->field
(fieldno
).type
();
1507 subfield_name
= field_name
;
1508 while
(*subfield_name
!= '\0' && *subfield_name
!= '.'
1509 && (subfield_name
[0] != '_' || subfield_name
[1] != '_'))
1512 if
(subfield_name
[0] == '\0')
1515 fieldno
= ada_nget_field_index
(type
, field_name
,
1516 subfield_name
- field_name
, 1);
1520 type
= type
->field
(fieldno
).type
();
1521 field_name
= subfield_name
;
1527 /* Look up NAME0 (an unencoded identifier or dotted name) in BLOCK (or
1528 expression_block_context if NULL). If it denotes a type, return
1529 that type. Otherwise, write expression code to evaluate it as an
1530 object and return NULL. In this second case, NAME0 will, in general,
1531 have the form <name>(.<selector_name>)*, where <name> is an object
1532 or renaming encoded in the debugging data. Calls error if no
1533 prefix <name> matches a name in the debugging data (i.e., matches
1534 either a complete name or, as a wild-card match, the final
1538 write_var_or_type
(struct parser_state
*par_state
,
1539 const struct block
*block
, struct stoken name0
)
1546 block
= par_state
->expression_context_block
;
1548 std
::string name_storage
= ada_encode
(name0.ptr
);
1549 name_len
= name_storage.size
();
1550 encoded_name
= obstack_strndup
(&temp_parse_space
, name_storage.c_str
(),
1552 for
(depth
= 0; depth
< MAX_RENAMING_CHAIN_LENGTH
; depth
+= 1)
1556 tail_index
= name_len
;
1557 while
(tail_index
> 0)
1559 struct symbol
*type_sym
;
1560 struct symbol
*renaming_sym
;
1561 const char* renaming
;
1563 const char* renaming_expr
;
1564 int terminator
= encoded_name
[tail_index
];
1566 encoded_name
[tail_index
] = '\0';
1567 std
::vector
<struct block_symbol
> syms
1568 = ada_lookup_symbol_list
(encoded_name
, block
, VAR_DOMAIN
);
1569 encoded_name
[tail_index
] = terminator
;
1571 type_sym
= select_possible_type_sym
(syms
);
1573 if
(type_sym
!= NULL
)
1574 renaming_sym
= type_sym
;
1575 else if
(syms.size
() == 1)
1576 renaming_sym
= syms
[0].symbol
;
1578 renaming_sym
= NULL
;
1580 switch
(ada_parse_renaming
(renaming_sym
, &renaming
,
1581 &renaming_len
, &renaming_expr
))
1583 case ADA_NOT_RENAMING
:
1585 case ADA_PACKAGE_RENAMING
:
1586 case ADA_EXCEPTION_RENAMING
:
1587 case ADA_SUBPROGRAM_RENAMING
:
1589 int alloc_len
= renaming_len
+ name_len
- tail_index
+ 1;
1591 = (char *) obstack_alloc
(&temp_parse_space
, alloc_len
);
1592 strncpy
(new_name
, renaming
, renaming_len
);
1593 strcpy
(new_name
+ renaming_len
, encoded_name
+ tail_index
);
1594 encoded_name
= new_name
;
1595 name_len
= renaming_len
+ name_len
- tail_index
;
1596 goto TryAfterRenaming
;
1598 case ADA_OBJECT_RENAMING
:
1599 write_object_renaming
(par_state
, block
, renaming
, renaming_len
,
1600 renaming_expr
, MAX_RENAMING_CHAIN_LENGTH
);
1601 write_selectors
(par_state
, encoded_name
+ tail_index
);
1604 internal_error
(__FILE__
, __LINE__
,
1605 _
("impossible value from ada_parse_renaming"));
1608 if
(type_sym
!= NULL
)
1610 struct type
*field_type
;
1612 if
(tail_index
== name_len
)
1613 return SYMBOL_TYPE
(type_sym
);
1615 /* We have some extraneous characters after the type name.
1616 If this is an expression "TYPE_NAME.FIELD0.[...].FIELDN",
1617 then try to get the type of FIELDN. */
1619 = get_symbol_field_type
(type_sym
, encoded_name
+ tail_index
);
1620 if
(field_type
!= NULL
)
1623 error (_
("Invalid attempt to select from type: \"%s\"."),
1626 else if
(tail_index
== name_len
&& syms.empty
())
1628 struct type
*type
= find_primitive_type
(par_state
,
1635 if
(syms.size
() == 1)
1637 write_var_from_sym
(par_state
, syms
[0]);
1638 write_selectors
(par_state
, encoded_name
+ tail_index
);
1641 else if
(syms.empty
())
1643 struct bound_minimal_symbol msym
1644 = ada_lookup_simple_minsym
(encoded_name
);
1645 if
(msym.minsym
!= NULL
)
1647 par_state
->push_new
<ada_var_msym_value_operation
> (msym
);
1648 /* Maybe cause error here rather than later? FIXME? */
1649 write_selectors
(par_state
, encoded_name
+ tail_index
);
1653 if
(tail_index
== name_len
1654 && strncmp
(encoded_name
, "standard__",
1655 sizeof
("standard__") - 1) == 0)
1656 error (_
("No definition of \"%s\" found."), name0.ptr
);
1658 tail_index
= chop_selector
(encoded_name
, tail_index
);
1662 write_ambiguous_var
(par_state
, block
, encoded_name
,
1664 write_selectors
(par_state
, encoded_name
+ tail_index
);
1669 if
(!have_full_symbols
() && !have_partial_symbols
() && block
== NULL
)
1670 error (_
("No symbol table is loaded. Use the \"file\" command."));
1671 if
(block
== par_state
->expression_context_block
)
1672 error (_
("No definition of \"%s\" in current context."), name0.ptr
);
1674 error (_
("No definition of \"%s\" in specified context."), name0.ptr
);
1679 error (_
("Could not find renamed symbol \"%s\""), name0.ptr
);
1683 /* Write a left side of a component association (e.g., NAME in NAME =>
1684 exp). If NAME has the form of a selected component, write it as an
1685 ordinary expression. If it is a simple variable that unambiguously
1686 corresponds to exactly one symbol that does not denote a type or an
1687 object renaming, also write it normally as an OP_VAR_VALUE.
1688 Otherwise, write it as an OP_NAME.
1690 Unfortunately, we don't know at this point whether NAME is supposed
1691 to denote a record component name or the value of an array index.
1692 Therefore, it is not appropriate to disambiguate an ambiguous name
1693 as we normally would, nor to replace a renaming with its referent.
1694 As a result, in the (one hopes) rare case that one writes an
1695 aggregate such as (R => 42) where R renames an object or is an
1696 ambiguous name, one must write instead ((R) => 42). */
1699 write_name_assoc
(struct parser_state
*par_state
, struct stoken name
)
1701 if
(strchr
(name.ptr
, '.') == NULL
)
1703 std
::vector
<struct block_symbol
> syms
1704 = ada_lookup_symbol_list
(name.ptr
,
1705 par_state
->expression_context_block
,
1708 if
(syms.size
() != 1 || SYMBOL_CLASS
(syms
[0].symbol
) == LOC_TYPEDEF
)
1709 pstate
->push_new
<ada_string_operation
> (copy_name
(name
));
1711 write_var_from_sym
(par_state
, syms
[0]);
1714 if
(write_var_or_type
(par_state
, NULL
, name
) != NULL
)
1715 error (_
("Invalid use of type."));
1717 push_association
<ada_name_association
> (ada_pop
());
1720 /* Convert the character literal whose ASCII value would be VAL to the
1721 appropriate value of type TYPE, if there is a translation.
1722 Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
1723 the literal 'A' (VAL == 65), returns 0. */
1726 convert_char_literal
(struct type
*type
, LONGEST val
)
1733 type
= check_typedef
(type
);
1734 if
(type
->code
() != TYPE_CODE_ENUM
)
1737 if
((val
>= 'a' && val
<= 'z') ||
(val
>= '0' && val
<= '9'))
1738 xsnprintf
(name
, sizeof
(name
), "Q%c", (int) val
);
1740 xsnprintf
(name
, sizeof
(name
), "QU%02x", (int) val
);
1741 size_t len
= strlen
(name
);
1742 for
(f
= 0; f
< type
->num_fields
(); f
+= 1)
1744 /* Check the suffix because an enum constant in a package will
1745 have a name like "pkg__QUxx". This is safe enough because we
1746 already have the correct type, and because mangling means
1747 there can't be clashes. */
1748 const char *ename
= TYPE_FIELD_NAME
(type
, f
);
1749 size_t elen
= strlen
(ename
);
1751 if
(elen
>= len
&& strcmp
(name
, ename
+ elen
- len
) == 0)
1752 return TYPE_FIELD_ENUMVAL
(type
, f
);
1757 static struct type
*
1758 type_int
(struct parser_state
*par_state
)
1760 return parse_type
(par_state
)->builtin_int
;
1763 static struct type
*
1764 type_long
(struct parser_state
*par_state
)
1766 return parse_type
(par_state
)->builtin_long
;
1769 static struct type
*
1770 type_long_long
(struct parser_state
*par_state
)
1772 return parse_type
(par_state
)->builtin_long_long
;
1775 static struct type
*
1776 type_long_double
(struct parser_state
*par_state
)
1778 return parse_type
(par_state
)->builtin_long_double
;
1781 static struct type
*
1782 type_char
(struct parser_state
*par_state
)
1784 return language_string_char_type
(par_state
->language
(),
1785 par_state
->gdbarch
());
1788 static struct type
*
1789 type_boolean
(struct parser_state
*par_state
)
1791 return parse_type
(par_state
)->builtin_bool
;
1794 static struct type
*
1795 type_system_address
(struct parser_state
*par_state
)
1798 = language_lookup_primitive_type
(par_state
->language
(),
1799 par_state
->gdbarch
(),
1801 return type
!= NULL ? type
: parse_type
(par_state
)->builtin_data_ptr
;
1804 void _initialize_ada_exp
();
1806 _initialize_ada_exp
()
1808 obstack_init
(&temp_parse_space
);