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