* dwarf2read.c (read_str_index): Delete arg cu. All callers updated.
[deliverable/binutils-gdb.git] / gdb / ada-exp.y
CommitLineData
14f9c5c9 1/* YACC parser for Ada expressions, for GDB.
ecd75fc8 2 Copyright (C) 1986-2014 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"
0e9f083f 39#include <string.h>
14f9c5c9
AS
40#include <ctype.h>
41#include "expression.h"
42#include "value.h"
43#include "parser-defs.h"
44#include "language.h"
45#include "ada-lang.h"
46#include "bfd.h" /* Required by objfiles.h. */
47#include "symfile.h" /* Required by objfiles.h. */
48#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
49#include "frame.h"
fe898f56 50#include "block.h"
14f9c5c9 51
3e79cecf
UW
52#define parse_type builtin_type (parse_gdbarch)
53
14f9c5c9
AS
54/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
55 as well as gratuitiously global symbol names, so we can have multiple
56 yacc generated parsers in gdb. These are only the variables
57 produced by yacc. If other parser generators (bison, byacc, etc) produce
58 additional global names that conflict at link time, then those parser
4c4b4cd2 59 generators need to be fixed instead of adding those names to this list. */
14f9c5c9 60
4c4b4cd2 61/* NOTE: This is clumsy, especially since BISON and FLEX provide --prefix
14f9c5c9
AS
62 options. I presume we are maintaining it to accommodate systems
63 without BISON? (PNH) */
64
65#define yymaxdepth ada_maxdepth
66#define yyparse _ada_parse /* ada_parse calls this after initialization */
67#define yylex ada_lex
68#define yyerror ada_error
69#define yylval ada_lval
70#define yychar ada_char
71#define yydebug ada_debug
4c4b4cd2
PH
72#define yypact ada_pact
73#define yyr1 ada_r1
74#define yyr2 ada_r2
75#define yydef ada_def
76#define yychk ada_chk
77#define yypgo ada_pgo
78#define yyact ada_act
14f9c5c9
AS
79#define yyexca ada_exca
80#define yyerrflag ada_errflag
81#define yynerrs ada_nerrs
82#define yyps ada_ps
83#define yypv ada_pv
84#define yys ada_s
85#define yy_yys ada_yys
86#define yystate ada_state
87#define yytmp ada_tmp
88#define yyv ada_v
89#define yy_yyv ada_yyv
90#define yyval ada_val
91#define yylloc ada_lloc
92#define yyreds ada_reds /* With YYDEBUG defined */
93#define yytoks ada_toks /* With YYDEBUG defined */
06891d83
JT
94#define yyname ada_name /* With YYDEBUG defined */
95#define yyrule ada_rule /* With YYDEBUG defined */
a7aa5b8a
MK
96#define yyss ada_yyss
97#define yysslim ada_yysslim
98#define yyssp ada_yyssp
99#define yystacksize ada_yystacksize
100#define yyvs ada_yyvs
101#define yyvsp ada_yyvsp
14f9c5c9
AS
102
103#ifndef YYDEBUG
f461f5cf 104#define YYDEBUG 1 /* Default to yydebug support */
14f9c5c9
AS
105#endif
106
f461f5cf
PM
107#define YYFPRINTF parser_fprintf
108
14f9c5c9 109struct name_info {
4c4b4cd2
PH
110 struct symbol *sym;
111 struct minimal_symbol *msym;
112 struct block *block;
14f9c5c9
AS
113 struct stoken stoken;
114};
115
52ce6436
PH
116static struct stoken empty_stoken = { "", 0 };
117
14f9c5c9 118/* If expression is in the context of TYPE'(...), then TYPE, else
4c4b4cd2
PH
119 * NULL. */
120static struct type *type_qualifier;
14f9c5c9
AS
121
122int yyparse (void);
123
124static int yylex (void);
125
126void yyerror (char *);
127
4c4b4cd2 128static void write_int (LONGEST, struct type *);
14f9c5c9 129
270140bd 130static void write_object_renaming (const struct block *, const char *, int,
aeb5907d 131 const char *, int);
14f9c5c9 132
270140bd 133static struct type* write_var_or_type (const struct block *, struct stoken);
52ce6436
PH
134
135static void write_name_assoc (struct stoken);
136
137static void write_exp_op_with_string (enum exp_opcode, struct stoken);
138
d7561cbb 139static struct block *block_lookup (struct block *, const char *);
14f9c5c9 140
19c1ef65 141static LONGEST convert_char_literal (struct type *, LONGEST);
72d5681a 142
270140bd 143static void write_ambiguous_var (const struct block *, char *, int);
52ce6436 144
72d5681a
PH
145static struct type *type_int (void);
146
147static struct type *type_long (void);
148
149static struct type *type_long_long (void);
150
151static struct type *type_float (void);
152
153static struct type *type_double (void);
154
155static struct type *type_long_double (void);
156
157static struct type *type_char (void);
158
690cc4eb
PH
159static struct type *type_boolean (void);
160
72d5681a 161static struct type *type_system_address (void);
52ce6436 162
4c4b4cd2 163%}
14f9c5c9
AS
164
165%union
166 {
167 LONGEST lval;
168 struct {
169 LONGEST val;
170 struct type *type;
171 } typed_val;
172 struct {
173 DOUBLEST dval;
174 struct type *type;
175 } typed_val_float;
176 struct type *tval;
177 struct stoken sval;
14f9c5c9
AS
178 struct block *bval;
179 struct internalvar *ivar;
14f9c5c9
AS
180 }
181
52ce6436
PH
182%type <lval> positional_list component_groups component_associations
183%type <lval> aggregate_component_list
184%type <tval> var_or_type
14f9c5c9
AS
185
186%token <typed_val> INT NULL_PTR CHARLIT
187%token <typed_val_float> FLOAT
690cc4eb 188%token TRUEKEYWORD FALSEKEYWORD
52ce6436
PH
189%token COLONCOLON
190%token <sval> STRING NAME DOT_ID
4c4b4cd2 191%type <bval> block
14f9c5c9
AS
192%type <lval> arglist tick_arglist
193
194%type <tval> save_qualifier
195
196%token DOT_ALL
197
198/* Special type cases, put in to allow the parser to distinguish different
199 legal basetypes. */
4c4b4cd2 200%token <sval> SPECIAL_VARIABLE
14f9c5c9
AS
201
202%nonassoc ASSIGN
203%left _AND_ OR XOR THEN ELSE
204%left '=' NOTEQUAL '<' '>' LEQ GEQ IN DOTDOT
205%left '@'
206%left '+' '-' '&'
207%left UNARY
208%left '*' '/' MOD REM
209%right STARSTAR ABS NOT
52ce6436
PH
210
211/* Artificial token to give NAME => ... and NAME | priority over reducing
212 NAME to <primary> and to give <primary>' priority over reducing <primary>
213 to <simple_exp>. */
214%nonassoc VAR
215
216%nonassoc ARROW '|'
217
14f9c5c9
AS
218%right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
219%right TICK_MAX TICK_MIN TICK_MODULUS
220%right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
52ce6436
PH
221 /* The following are right-associative only so that reductions at this
222 precedence have lower precedence than '.' and '('. The syntax still
223 forces a.b.c, e.g., to be LEFT-associated. */
14f9c5c9
AS
224%right '.' '(' '[' DOT_ID DOT_ALL
225
52ce6436 226%token NEW OTHERS
14f9c5c9
AS
227
228\f
229%%
230
231start : exp1
14f9c5c9
AS
232 ;
233
234/* Expressions, including the sequencing operator. */
235exp1 : exp
236 | exp1 ';' exp
237 { write_exp_elt_opcode (BINOP_COMMA); }
52ce6436
PH
238 | primary ASSIGN exp /* Extension for convenience */
239 { write_exp_elt_opcode (BINOP_ASSIGN); }
14f9c5c9
AS
240 ;
241
242/* Expressions, not including the sequencing operator. */
52ce6436 243primary : primary DOT_ALL
14f9c5c9
AS
244 { write_exp_elt_opcode (UNOP_IND); }
245 ;
246
52ce6436
PH
247primary : primary DOT_ID
248 { write_exp_op_with_string (STRUCTOP_STRUCT, $2); }
14f9c5c9
AS
249 ;
250
52ce6436 251primary : primary '(' arglist ')'
14f9c5c9
AS
252 {
253 write_exp_elt_opcode (OP_FUNCALL);
254 write_exp_elt_longcst ($3);
255 write_exp_elt_opcode (OP_FUNCALL);
256 }
52ce6436 257 | var_or_type '(' arglist ')'
14f9c5c9 258 {
52ce6436
PH
259 if ($1 != NULL)
260 {
261 if ($3 != 1)
e1d5a0d2 262 error (_("Invalid conversion"));
52ce6436
PH
263 write_exp_elt_opcode (UNOP_CAST);
264 write_exp_elt_type ($1);
265 write_exp_elt_opcode (UNOP_CAST);
266 }
267 else
268 {
269 write_exp_elt_opcode (OP_FUNCALL);
270 write_exp_elt_longcst ($3);
271 write_exp_elt_opcode (OP_FUNCALL);
272 }
14f9c5c9
AS
273 }
274 ;
275
52ce6436
PH
276primary : var_or_type '\'' save_qualifier { type_qualifier = $1; }
277 '(' exp ')'
14f9c5c9 278 {
52ce6436 279 if ($1 == NULL)
e1d5a0d2 280 error (_("Type required for qualification"));
4c4b4cd2 281 write_exp_elt_opcode (UNOP_QUAL);
14f9c5c9 282 write_exp_elt_type ($1);
4c4b4cd2 283 write_exp_elt_opcode (UNOP_QUAL);
14f9c5c9
AS
284 type_qualifier = $3;
285 }
286 ;
287
288save_qualifier : { $$ = type_qualifier; }
525d6a61 289 ;
14f9c5c9 290
52ce6436
PH
291primary :
292 primary '(' simple_exp DOTDOT simple_exp ')'
14f9c5c9 293 { write_exp_elt_opcode (TERNOP_SLICE); }
52ce6436
PH
294 | var_or_type '(' simple_exp DOTDOT simple_exp ')'
295 { if ($1 == NULL)
296 write_exp_elt_opcode (TERNOP_SLICE);
297 else
e1d5a0d2 298 error (_("Cannot slice a type"));
52ce6436 299 }
14f9c5c9
AS
300 ;
301
52ce6436 302primary : '(' exp1 ')' { }
14f9c5c9
AS
303 ;
304
52ce6436
PH
305/* The following rule causes a conflict with the type conversion
306 var_or_type (exp)
307 To get around it, we give '(' higher priority and add bridge rules for
308 var_or_type (exp, exp, ...)
309 var_or_type (exp .. exp)
310 We also have the action for var_or_type(exp) generate a function call
311 when the first symbol does not denote a type. */
312
313primary : var_or_type %prec VAR
314 { if ($1 != NULL)
315 {
316 write_exp_elt_opcode (OP_TYPE);
317 write_exp_elt_type ($1);
318 write_exp_elt_opcode (OP_TYPE);
319 }
320 }
14f9c5c9
AS
321 ;
322
52ce6436 323primary : SPECIAL_VARIABLE /* Various GDB extensions */
4c4b4cd2 324 { write_dollar_variable ($1); }
14f9c5c9
AS
325 ;
326
52ce6436
PH
327primary : aggregate
328 ;
14f9c5c9 329
52ce6436 330simple_exp : primary
14f9c5c9
AS
331 ;
332
52ce6436 333simple_exp : '-' simple_exp %prec UNARY
14f9c5c9
AS
334 { write_exp_elt_opcode (UNOP_NEG); }
335 ;
336
52ce6436 337simple_exp : '+' simple_exp %prec UNARY
14f9c5c9
AS
338 { write_exp_elt_opcode (UNOP_PLUS); }
339 ;
340
52ce6436 341simple_exp : NOT simple_exp %prec UNARY
14f9c5c9
AS
342 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
343 ;
344
52ce6436 345simple_exp : ABS simple_exp %prec UNARY
14f9c5c9
AS
346 { write_exp_elt_opcode (UNOP_ABS); }
347 ;
348
349arglist : { $$ = 0; }
350 ;
351
352arglist : exp
353 { $$ = 1; }
52ce6436 354 | NAME ARROW exp
14f9c5c9
AS
355 { $$ = 1; }
356 | arglist ',' exp
357 { $$ = $1 + 1; }
52ce6436 358 | arglist ',' NAME ARROW exp
14f9c5c9
AS
359 { $$ = $1 + 1; }
360 ;
361
bb28a9dc 362primary : '{' var_or_type '}' primary %prec '.'
14f9c5c9 363 /* GDB extension */
52ce6436
PH
364 {
365 if ($2 == NULL)
e1d5a0d2 366 error (_("Type required within braces in coercion"));
52ce6436 367 write_exp_elt_opcode (UNOP_MEMVAL);
14f9c5c9 368 write_exp_elt_type ($2);
4c4b4cd2 369 write_exp_elt_opcode (UNOP_MEMVAL);
14f9c5c9
AS
370 }
371 ;
372
373/* Binary operators in order of decreasing precedence. */
374
52ce6436 375simple_exp : simple_exp STARSTAR simple_exp
14f9c5c9
AS
376 { write_exp_elt_opcode (BINOP_EXP); }
377 ;
378
52ce6436 379simple_exp : simple_exp '*' simple_exp
14f9c5c9
AS
380 { write_exp_elt_opcode (BINOP_MUL); }
381 ;
382
52ce6436 383simple_exp : simple_exp '/' simple_exp
14f9c5c9
AS
384 { write_exp_elt_opcode (BINOP_DIV); }
385 ;
386
52ce6436 387simple_exp : simple_exp REM simple_exp /* May need to be fixed to give correct Ada REM */
14f9c5c9
AS
388 { write_exp_elt_opcode (BINOP_REM); }
389 ;
390
52ce6436 391simple_exp : simple_exp MOD simple_exp
14f9c5c9
AS
392 { write_exp_elt_opcode (BINOP_MOD); }
393 ;
394
52ce6436 395simple_exp : simple_exp '@' simple_exp /* GDB extension */
14f9c5c9
AS
396 { write_exp_elt_opcode (BINOP_REPEAT); }
397 ;
398
52ce6436 399simple_exp : simple_exp '+' simple_exp
14f9c5c9
AS
400 { write_exp_elt_opcode (BINOP_ADD); }
401 ;
402
52ce6436 403simple_exp : simple_exp '&' simple_exp
14f9c5c9
AS
404 { write_exp_elt_opcode (BINOP_CONCAT); }
405 ;
406
52ce6436 407simple_exp : simple_exp '-' simple_exp
14f9c5c9
AS
408 { write_exp_elt_opcode (BINOP_SUB); }
409 ;
410
52ce6436
PH
411relation : simple_exp
412 ;
413
414relation : simple_exp '=' simple_exp
14f9c5c9
AS
415 { write_exp_elt_opcode (BINOP_EQUAL); }
416 ;
417
52ce6436 418relation : simple_exp NOTEQUAL simple_exp
14f9c5c9
AS
419 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
420 ;
421
52ce6436 422relation : simple_exp LEQ simple_exp
14f9c5c9
AS
423 { write_exp_elt_opcode (BINOP_LEQ); }
424 ;
425
52ce6436 426relation : simple_exp IN simple_exp DOTDOT simple_exp
4c4b4cd2 427 { write_exp_elt_opcode (TERNOP_IN_RANGE); }
52ce6436 428 | simple_exp IN primary TICK_RANGE tick_arglist
4c4b4cd2 429 { write_exp_elt_opcode (BINOP_IN_BOUNDS);
14f9c5c9 430 write_exp_elt_longcst ((LONGEST) $5);
4c4b4cd2 431 write_exp_elt_opcode (BINOP_IN_BOUNDS);
14f9c5c9 432 }
52ce6436
PH
433 | simple_exp IN var_or_type %prec TICK_ACCESS
434 {
435 if ($3 == NULL)
e1d5a0d2 436 error (_("Right operand of 'in' must be type"));
52ce6436 437 write_exp_elt_opcode (UNOP_IN_RANGE);
14f9c5c9 438 write_exp_elt_type ($3);
4c4b4cd2 439 write_exp_elt_opcode (UNOP_IN_RANGE);
14f9c5c9 440 }
52ce6436 441 | simple_exp NOT IN simple_exp DOTDOT simple_exp
4c4b4cd2
PH
442 { write_exp_elt_opcode (TERNOP_IN_RANGE);
443 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
14f9c5c9 444 }
52ce6436 445 | simple_exp NOT IN primary TICK_RANGE tick_arglist
4c4b4cd2 446 { write_exp_elt_opcode (BINOP_IN_BOUNDS);
14f9c5c9 447 write_exp_elt_longcst ((LONGEST) $6);
4c4b4cd2
PH
448 write_exp_elt_opcode (BINOP_IN_BOUNDS);
449 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
14f9c5c9 450 }
52ce6436
PH
451 | simple_exp NOT IN var_or_type %prec TICK_ACCESS
452 {
453 if ($4 == NULL)
e1d5a0d2 454 error (_("Right operand of 'in' must be type"));
52ce6436 455 write_exp_elt_opcode (UNOP_IN_RANGE);
14f9c5c9 456 write_exp_elt_type ($4);
4c4b4cd2
PH
457 write_exp_elt_opcode (UNOP_IN_RANGE);
458 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
14f9c5c9
AS
459 }
460 ;
461
52ce6436 462relation : simple_exp GEQ simple_exp
14f9c5c9
AS
463 { write_exp_elt_opcode (BINOP_GEQ); }
464 ;
465
52ce6436 466relation : simple_exp '<' simple_exp
14f9c5c9
AS
467 { write_exp_elt_opcode (BINOP_LESS); }
468 ;
469
52ce6436 470relation : simple_exp '>' simple_exp
14f9c5c9
AS
471 { write_exp_elt_opcode (BINOP_GTR); }
472 ;
473
52ce6436
PH
474exp : relation
475 | and_exp
476 | and_then_exp
477 | or_exp
478 | or_else_exp
479 | xor_exp
480 ;
481
482and_exp :
483 relation _AND_ relation
14f9c5c9 484 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
52ce6436
PH
485 | and_exp _AND_ relation
486 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
487 ;
14f9c5c9 488
52ce6436
PH
489and_then_exp :
490 relation _AND_ THEN relation
491 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
492 | and_then_exp _AND_ THEN relation
14f9c5c9
AS
493 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
494 ;
495
52ce6436
PH
496or_exp :
497 relation OR relation
14f9c5c9 498 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
52ce6436
PH
499 | or_exp OR relation
500 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
501 ;
14f9c5c9 502
52ce6436
PH
503or_else_exp :
504 relation OR ELSE relation
505 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
506 | or_else_exp OR ELSE relation
14f9c5c9
AS
507 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
508 ;
509
52ce6436
PH
510xor_exp : relation XOR relation
511 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
512 | xor_exp XOR relation
14f9c5c9
AS
513 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
514 ;
515
52ce6436 516/* Primaries can denote types (OP_TYPE). In cases such as
f98ce7c2 517 primary TICK_ADDRESS, where a type would be invalid, it will be
52ce6436
PH
518 caught when evaluate_subexp in ada-lang.c tries to evaluate the
519 primary, expecting a value. Precedence rules resolve the ambiguity
520 in NAME TICK_ACCESS in favor of shifting to form a var_or_type. A
521 construct such as aType'access'access will again cause an error when
522 aType'access evaluates to a type that evaluate_subexp attempts to
523 evaluate. */
524primary : primary TICK_ACCESS
14f9c5c9 525 { write_exp_elt_opcode (UNOP_ADDR); }
52ce6436 526 | primary TICK_ADDRESS
14f9c5c9
AS
527 { write_exp_elt_opcode (UNOP_ADDR);
528 write_exp_elt_opcode (UNOP_CAST);
72d5681a 529 write_exp_elt_type (type_system_address ());
14f9c5c9
AS
530 write_exp_elt_opcode (UNOP_CAST);
531 }
52ce6436 532 | primary TICK_FIRST tick_arglist
72d5681a 533 { write_int ($3, type_int ());
4c4b4cd2 534 write_exp_elt_opcode (OP_ATR_FIRST); }
52ce6436 535 | primary TICK_LAST tick_arglist
72d5681a 536 { write_int ($3, type_int ());
4c4b4cd2 537 write_exp_elt_opcode (OP_ATR_LAST); }
52ce6436 538 | primary TICK_LENGTH tick_arglist
72d5681a 539 { write_int ($3, type_int ());
4c4b4cd2 540 write_exp_elt_opcode (OP_ATR_LENGTH); }
52ce6436 541 | primary TICK_SIZE
4c4b4cd2 542 { write_exp_elt_opcode (OP_ATR_SIZE); }
52ce6436 543 | primary TICK_TAG
4c4b4cd2 544 { write_exp_elt_opcode (OP_ATR_TAG); }
14f9c5c9 545 | opt_type_prefix TICK_MIN '(' exp ',' exp ')'
4c4b4cd2 546 { write_exp_elt_opcode (OP_ATR_MIN); }
14f9c5c9 547 | opt_type_prefix TICK_MAX '(' exp ',' exp ')'
4c4b4cd2 548 { write_exp_elt_opcode (OP_ATR_MAX); }
14f9c5c9 549 | opt_type_prefix TICK_POS '(' exp ')'
4c4b4cd2 550 { write_exp_elt_opcode (OP_ATR_POS); }
14f9c5c9 551 | type_prefix TICK_VAL '(' exp ')'
4c4b4cd2
PH
552 { write_exp_elt_opcode (OP_ATR_VAL); }
553 | type_prefix TICK_MODULUS
554 { write_exp_elt_opcode (OP_ATR_MODULUS); }
14f9c5c9
AS
555 ;
556
557tick_arglist : %prec '('
558 { $$ = 1; }
559 | '(' INT ')'
560 { $$ = $2.val; }
561 ;
562
563type_prefix :
52ce6436
PH
564 var_or_type
565 {
566 if ($1 == NULL)
e1d5a0d2 567 error (_("Prefix must be type"));
52ce6436 568 write_exp_elt_opcode (OP_TYPE);
14f9c5c9
AS
569 write_exp_elt_type ($1);
570 write_exp_elt_opcode (OP_TYPE); }
571 ;
572
573opt_type_prefix :
574 type_prefix
4c4b4cd2 575 | /* EMPTY */
14f9c5c9 576 { write_exp_elt_opcode (OP_TYPE);
3e79cecf 577 write_exp_elt_type (parse_type->builtin_void);
14f9c5c9
AS
578 write_exp_elt_opcode (OP_TYPE); }
579 ;
4c4b4cd2 580
14f9c5c9 581
52ce6436 582primary : INT
4c4b4cd2 583 { write_int ((LONGEST) $1.val, $1.type); }
14f9c5c9
AS
584 ;
585
52ce6436 586primary : CHARLIT
4c4b4cd2
PH
587 { write_int (convert_char_literal (type_qualifier, $1.val),
588 (type_qualifier == NULL)
589 ? $1.type : type_qualifier);
590 }
525d6a61 591 ;
4c4b4cd2 592
52ce6436 593primary : FLOAT
14f9c5c9
AS
594 { write_exp_elt_opcode (OP_DOUBLE);
595 write_exp_elt_type ($1.type);
596 write_exp_elt_dblcst ($1.dval);
4c4b4cd2 597 write_exp_elt_opcode (OP_DOUBLE);
14f9c5c9
AS
598 }
599 ;
600
52ce6436 601primary : NULL_PTR
72d5681a 602 { write_int (0, type_int ()); }
525d6a61 603 ;
14f9c5c9 604
52ce6436 605primary : STRING
4c4b4cd2 606 {
52ce6436 607 write_exp_op_with_string (OP_STRING, $1);
4c4b4cd2 608 }
14f9c5c9
AS
609 ;
610
690cc4eb
PH
611primary : TRUEKEYWORD
612 { write_int (1, type_boolean ()); }
613 | FALSEKEYWORD
614 { write_int (0, type_boolean ()); }
615 ;
616
52ce6436 617primary : NEW NAME
e1d5a0d2 618 { error (_("NEW not implemented.")); }
14f9c5c9
AS
619 ;
620
52ce6436
PH
621var_or_type: NAME %prec VAR
622 { $$ = write_var_or_type (NULL, $1); }
623 | block NAME %prec VAR
624 { $$ = write_var_or_type ($1, $2); }
625 | NAME TICK_ACCESS
626 {
627 $$ = write_var_or_type (NULL, $1);
628 if ($$ == NULL)
629 write_exp_elt_opcode (UNOP_ADDR);
630 else
631 $$ = lookup_pointer_type ($$);
632 }
633 | block NAME TICK_ACCESS
634 {
635 $$ = write_var_or_type ($1, $2);
636 if ($$ == NULL)
637 write_exp_elt_opcode (UNOP_ADDR);
638 else
639 $$ = lookup_pointer_type ($$);
640 }
14f9c5c9
AS
641 ;
642
52ce6436
PH
643/* GDB extension */
644block : NAME COLONCOLON
645 { $$ = block_lookup (NULL, $1.ptr); }
646 | block NAME COLONCOLON
647 { $$ = block_lookup ($1, $2.ptr); }
648 ;
14f9c5c9 649
52ce6436
PH
650aggregate :
651 '(' aggregate_component_list ')'
652 {
653 write_exp_elt_opcode (OP_AGGREGATE);
654 write_exp_elt_longcst ($2);
655 write_exp_elt_opcode (OP_AGGREGATE);
656 }
14f9c5c9
AS
657 ;
658
52ce6436
PH
659aggregate_component_list :
660 component_groups { $$ = $1; }
661 | positional_list exp
662 { write_exp_elt_opcode (OP_POSITIONAL);
663 write_exp_elt_longcst ($1);
664 write_exp_elt_opcode (OP_POSITIONAL);
665 $$ = $1 + 1;
666 }
667 | positional_list component_groups
668 { $$ = $1 + $2; }
669 ;
14f9c5c9 670
52ce6436
PH
671positional_list :
672 exp ','
673 { write_exp_elt_opcode (OP_POSITIONAL);
674 write_exp_elt_longcst (0);
675 write_exp_elt_opcode (OP_POSITIONAL);
676 $$ = 1;
677 }
678 | positional_list exp ','
679 { write_exp_elt_opcode (OP_POSITIONAL);
680 write_exp_elt_longcst ($1);
681 write_exp_elt_opcode (OP_POSITIONAL);
682 $$ = $1 + 1;
683 }
684 ;
685
686component_groups:
687 others { $$ = 1; }
688 | component_group { $$ = 1; }
689 | component_group ',' component_groups
690 { $$ = $3 + 1; }
691 ;
692
693others : OTHERS ARROW exp
694 { write_exp_elt_opcode (OP_OTHERS); }
695 ;
696
697component_group :
698 component_associations
699 {
700 write_exp_elt_opcode (OP_CHOICES);
701 write_exp_elt_longcst ($1);
702 write_exp_elt_opcode (OP_CHOICES);
703 }
704 ;
705
706/* We use this somewhat obscure definition in order to handle NAME => and
707 NAME | differently from exp => and exp |. ARROW and '|' have a precedence
708 above that of the reduction of NAME to var_or_type. By delaying
709 decisions until after the => or '|', we convert the ambiguity to a
710 resolved shift/reduce conflict. */
711component_associations :
712 NAME ARROW
713 { write_name_assoc ($1); }
714 exp { $$ = 1; }
715 | simple_exp ARROW exp
716 { $$ = 1; }
717 | simple_exp DOTDOT simple_exp ARROW
718 { write_exp_elt_opcode (OP_DISCRETE_RANGE);
719 write_exp_op_with_string (OP_NAME, empty_stoken);
720 }
721 exp { $$ = 1; }
722 | NAME '|'
723 { write_name_assoc ($1); }
724 component_associations { $$ = $4 + 1; }
725 | simple_exp '|'
726 component_associations { $$ = $3 + 1; }
727 | simple_exp DOTDOT simple_exp '|'
728 { write_exp_elt_opcode (OP_DISCRETE_RANGE); }
729 component_associations { $$ = $6 + 1; }
730 ;
14f9c5c9
AS
731
732/* Some extensions borrowed from C, for the benefit of those who find they
4c4b4cd2 733 can't get used to Ada notation in GDB. */
14f9c5c9 734
52ce6436 735primary : '*' primary %prec '.'
14f9c5c9 736 { write_exp_elt_opcode (UNOP_IND); }
52ce6436 737 | '&' primary %prec '.'
14f9c5c9 738 { write_exp_elt_opcode (UNOP_ADDR); }
52ce6436 739 | primary '[' exp ']'
14f9c5c9
AS
740 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
741 ;
742
743%%
744
745/* yylex defined in ada-lex.c: Reads one token, getting characters */
746/* through lexptr. */
747
748/* Remap normal flex interface names (yylex) as well as gratuitiously */
749/* global symbol names, so we can have multiple flex-generated parsers */
750/* in gdb. */
751
752/* (See note above on previous definitions for YACC.) */
753
754#define yy_create_buffer ada_yy_create_buffer
755#define yy_delete_buffer ada_yy_delete_buffer
756#define yy_init_buffer ada_yy_init_buffer
757#define yy_load_buffer_state ada_yy_load_buffer_state
758#define yy_switch_to_buffer ada_yy_switch_to_buffer
759#define yyrestart ada_yyrestart
760#define yytext ada_yytext
761#define yywrap ada_yywrap
762
4c4b4cd2
PH
763static struct obstack temp_parse_space;
764
14f9c5c9
AS
765/* The following kludge was found necessary to prevent conflicts between */
766/* defs.h and non-standard stdlib.h files. */
767#define qsort __qsort__dummy
768#include "ada-lex.c"
769
770int
4c4b4cd2 771ada_parse (void)
14f9c5c9 772{
4c4b4cd2 773 lexer_init (yyin); /* (Re-)initialize lexer. */
14f9c5c9 774 type_qualifier = NULL;
4c4b4cd2
PH
775 obstack_free (&temp_parse_space, NULL);
776 obstack_init (&temp_parse_space);
777
14f9c5c9
AS
778 return _ada_parse ();
779}
780
781void
4c4b4cd2 782yyerror (char *msg)
14f9c5c9 783{
03ee6b2e 784 error (_("Error in expression, near `%s'."), lexptr);
14f9c5c9
AS
785}
786
14f9c5c9 787/* Emit expression to access an instance of SYM, in block BLOCK (if
4c4b4cd2 788 * non-NULL), and with :: qualification ORIG_LEFT_CONTEXT. */
14f9c5c9 789static void
270140bd
TT
790write_var_from_sym (const struct block *orig_left_context,
791 const struct block *block,
4c4b4cd2 792 struct symbol *sym)
14f9c5c9
AS
793{
794 if (orig_left_context == NULL && symbol_read_needs_frame (sym))
795 {
c3e5cd34
PH
796 if (innermost_block == 0
797 || contained_in (block, innermost_block))
14f9c5c9
AS
798 innermost_block = block;
799 }
800
801 write_exp_elt_opcode (OP_VAR_VALUE);
4c4b4cd2 802 write_exp_elt_block (block);
14f9c5c9
AS
803 write_exp_elt_sym (sym);
804 write_exp_elt_opcode (OP_VAR_VALUE);
805}
806
690cc4eb 807/* Write integer or boolean constant ARG of type TYPE. */
14f9c5c9
AS
808
809static void
4c4b4cd2 810write_int (LONGEST arg, struct type *type)
14f9c5c9
AS
811{
812 write_exp_elt_opcode (OP_LONG);
4c4b4cd2 813 write_exp_elt_type (type);
14f9c5c9
AS
814 write_exp_elt_longcst (arg);
815 write_exp_elt_opcode (OP_LONG);
4c4b4cd2 816}
14f9c5c9 817
52ce6436
PH
818/* Write an OPCODE, string, OPCODE sequence to the current expression. */
819static void
820write_exp_op_with_string (enum exp_opcode opcode, struct stoken token)
821{
822 write_exp_elt_opcode (opcode);
823 write_exp_string (token);
824 write_exp_elt_opcode (opcode);
825}
826
aeb5907d
JB
827/* Emit expression corresponding to the renamed object named
828 * designated by RENAMED_ENTITY[0 .. RENAMED_ENTITY_LEN-1] in the
829 * context of ORIG_LEFT_CONTEXT, to which is applied the operations
830 * encoded by RENAMING_EXPR. MAX_DEPTH is the maximum number of
831 * cascaded renamings to allow. If ORIG_LEFT_CONTEXT is null, it
832 * defaults to the currently selected block. ORIG_SYMBOL is the
833 * symbol that originally encoded the renaming. It is needed only
834 * because its prefix also qualifies any index variables used to index
835 * or slice an array. It should not be necessary once we go to the
836 * new encoding entirely (FIXME pnh 7/20/2007). */
837
14f9c5c9 838static void
270140bd 839write_object_renaming (const struct block *orig_left_context,
aeb5907d
JB
840 const char *renamed_entity, int renamed_entity_len,
841 const char *renaming_expr, int max_depth)
14f9c5c9 842{
4c4b4cd2 843 char *name;
14f9c5c9 844 enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
4e5c77fe 845 struct ada_symbol_info sym_info;
14f9c5c9 846
4c4b4cd2 847 if (max_depth <= 0)
e1d5a0d2 848 error (_("Could not find renamed symbol"));
4c4b4cd2 849
14f9c5c9
AS
850 if (orig_left_context == NULL)
851 orig_left_context = get_selected_block (NULL);
852
10f0c4bb 853 name = obstack_copy0 (&temp_parse_space, renamed_entity, renamed_entity_len);
4e5c77fe
JB
854 ada_lookup_encoded_symbol (name, orig_left_context, VAR_DOMAIN, &sym_info);
855 if (sym_info.sym == NULL)
e1d5a0d2 856 error (_("Could not find renamed variable: %s"), ada_decode (name));
4e5c77fe 857 else if (SYMBOL_CLASS (sym_info.sym) == LOC_TYPEDEF)
aeb5907d
JB
858 /* We have a renaming of an old-style renaming symbol. Don't
859 trust the block information. */
4e5c77fe 860 sym_info.block = orig_left_context;
aeb5907d
JB
861
862 {
863 const char *inner_renamed_entity;
864 int inner_renamed_entity_len;
865 const char *inner_renaming_expr;
866
4e5c77fe 867 switch (ada_parse_renaming (sym_info.sym, &inner_renamed_entity,
aeb5907d
JB
868 &inner_renamed_entity_len,
869 &inner_renaming_expr))
870 {
871 case ADA_NOT_RENAMING:
4e5c77fe 872 write_var_from_sym (orig_left_context, sym_info.block, sym_info.sym);
aeb5907d
JB
873 break;
874 case ADA_OBJECT_RENAMING:
4e5c77fe 875 write_object_renaming (sym_info.block,
aeb5907d
JB
876 inner_renamed_entity, inner_renamed_entity_len,
877 inner_renaming_expr, max_depth - 1);
878 break;
879 default:
880 goto BadEncoding;
881 }
882 }
14f9c5c9 883
14f9c5c9 884 slice_state = SIMPLE_INDEX;
aeb5907d 885 while (*renaming_expr == 'X')
14f9c5c9 886 {
aeb5907d 887 renaming_expr += 1;
14f9c5c9 888
aeb5907d 889 switch (*renaming_expr) {
4c4b4cd2 890 case 'A':
aeb5907d 891 renaming_expr += 1;
4c4b4cd2
PH
892 write_exp_elt_opcode (UNOP_IND);
893 break;
14f9c5c9
AS
894 case 'L':
895 slice_state = LOWER_BOUND;
8ab1f94d 896 /* FALLTHROUGH */
14f9c5c9 897 case 'S':
aeb5907d
JB
898 renaming_expr += 1;
899 if (isdigit (*renaming_expr))
14f9c5c9 900 {
4c4b4cd2 901 char *next;
aeb5907d
JB
902 long val = strtol (renaming_expr, &next, 10);
903 if (next == renaming_expr)
14f9c5c9 904 goto BadEncoding;
aeb5907d 905 renaming_expr = next;
14f9c5c9 906 write_exp_elt_opcode (OP_LONG);
72d5681a 907 write_exp_elt_type (type_int ());
14f9c5c9
AS
908 write_exp_elt_longcst ((LONGEST) val);
909 write_exp_elt_opcode (OP_LONG);
4c4b4cd2 910 }
14f9c5c9
AS
911 else
912 {
4c4b4cd2
PH
913 const char *end;
914 char *index_name;
4e5c77fe 915 struct ada_symbol_info index_sym_info;
14f9c5c9 916
aeb5907d 917 end = strchr (renaming_expr, 'X');
4c4b4cd2 918 if (end == NULL)
aeb5907d
JB
919 end = renaming_expr + strlen (renaming_expr);
920
921 index_name =
10f0c4bb
TT
922 obstack_copy0 (&temp_parse_space, renaming_expr,
923 end - renaming_expr);
aeb5907d
JB
924 renaming_expr = end;
925
4e5c77fe
JB
926 ada_lookup_encoded_symbol (index_name, NULL, VAR_DOMAIN,
927 &index_sym_info);
928 if (index_sym_info.sym == NULL)
e1d5a0d2 929 error (_("Could not find %s"), index_name);
4e5c77fe 930 else if (SYMBOL_CLASS (index_sym_info.sym) == LOC_TYPEDEF)
aeb5907d 931 /* Index is an old-style renaming symbol. */
4e5c77fe
JB
932 index_sym_info.block = orig_left_context;
933 write_var_from_sym (NULL, index_sym_info.block,
934 index_sym_info.sym);
14f9c5c9
AS
935 }
936 if (slice_state == SIMPLE_INDEX)
4c4b4cd2 937 {
14f9c5c9
AS
938 write_exp_elt_opcode (OP_FUNCALL);
939 write_exp_elt_longcst ((LONGEST) 1);
940 write_exp_elt_opcode (OP_FUNCALL);
941 }
942 else if (slice_state == LOWER_BOUND)
943 slice_state = UPPER_BOUND;
944 else if (slice_state == UPPER_BOUND)
945 {
946 write_exp_elt_opcode (TERNOP_SLICE);
947 slice_state = SIMPLE_INDEX;
948 }
949 break;
950
951 case 'R':
952 {
953 struct stoken field_name;
4c4b4cd2 954 const char *end;
d7561cbb
KS
955 char *buf;
956
aeb5907d 957 renaming_expr += 1;
4c4b4cd2 958
14f9c5c9
AS
959 if (slice_state != SIMPLE_INDEX)
960 goto BadEncoding;
aeb5907d 961 end = strchr (renaming_expr, 'X');
4c4b4cd2 962 if (end == NULL)
aeb5907d
JB
963 end = renaming_expr + strlen (renaming_expr);
964 field_name.length = end - renaming_expr;
d7561cbb
KS
965 buf = malloc (end - renaming_expr + 1);
966 field_name.ptr = buf;
967 strncpy (buf, renaming_expr, end - renaming_expr);
968 buf[end - renaming_expr] = '\000';
aeb5907d 969 renaming_expr = end;
52ce6436 970 write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
14f9c5c9
AS
971 break;
972 }
4c4b4cd2 973
14f9c5c9
AS
974 default:
975 goto BadEncoding;
976 }
977 }
978 if (slice_state == SIMPLE_INDEX)
979 return;
980
981 BadEncoding:
aeb5907d 982 error (_("Internal error in encoding of renaming declaration"));
14f9c5c9
AS
983}
984
52ce6436 985static struct block*
d7561cbb 986block_lookup (struct block *context, const char *raw_name)
52ce6436 987{
d7561cbb 988 const char *name;
52ce6436
PH
989 struct ada_symbol_info *syms;
990 int nsyms;
991 struct symtab *symtab;
992
993 if (raw_name[0] == '\'')
994 {
995 raw_name += 1;
996 name = raw_name;
997 }
998 else
999 name = ada_encode (raw_name);
1000
4eeaa230 1001 nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms);
f8bf5763
PM
1002 if (context == NULL
1003 && (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK))
52ce6436
PH
1004 symtab = lookup_symtab (name);
1005 else
1006 symtab = NULL;
1007
1008 if (symtab != NULL)
1009 return BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
1010 else if (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK)
1011 {
1012 if (context == NULL)
e1d5a0d2 1013 error (_("No file or function \"%s\"."), raw_name);
52ce6436 1014 else
e1d5a0d2 1015 error (_("No function \"%s\" in specified context."), raw_name);
52ce6436
PH
1016 }
1017 else
1018 {
1019 if (nsyms > 1)
e1d5a0d2 1020 warning (_("Function name \"%s\" ambiguous here"), raw_name);
52ce6436
PH
1021 return SYMBOL_BLOCK_VALUE (syms[0].sym);
1022 }
1023}
1024
1025static struct symbol*
1026select_possible_type_sym (struct ada_symbol_info *syms, int nsyms)
1027{
1028 int i;
1029 int preferred_index;
1030 struct type *preferred_type;
1031
1032 preferred_index = -1; preferred_type = NULL;
1033 for (i = 0; i < nsyms; i += 1)
1034 switch (SYMBOL_CLASS (syms[i].sym))
1035 {
1036 case LOC_TYPEDEF:
1037 if (ada_prefer_type (SYMBOL_TYPE (syms[i].sym), preferred_type))
1038 {
1039 preferred_index = i;
1040 preferred_type = SYMBOL_TYPE (syms[i].sym);
1041 }
1042 break;
1043 case LOC_REGISTER:
1044 case LOC_ARG:
1045 case LOC_REF_ARG:
52ce6436
PH
1046 case LOC_REGPARM_ADDR:
1047 case LOC_LOCAL:
52ce6436 1048 case LOC_COMPUTED:
52ce6436
PH
1049 return NULL;
1050 default:
1051 break;
1052 }
1053 if (preferred_type == NULL)
1054 return NULL;
1055 return syms[preferred_index].sym;
1056}
1057
1058static struct type*
1059find_primitive_type (char *name)
1060{
1061 struct type *type;
3e79cecf
UW
1062 type = language_lookup_primitive_type_by_name (parse_language,
1063 parse_gdbarch,
52ce6436
PH
1064 name);
1065 if (type == NULL && strcmp ("system__address", name) == 0)
1066 type = type_system_address ();
1067
1068 if (type != NULL)
1069 {
1070 /* Check to see if we have a regular definition of this
1071 type that just didn't happen to have been read yet. */
52ce6436
PH
1072 struct symbol *sym;
1073 char *expanded_name =
1074 (char *) alloca (strlen (name) + sizeof ("standard__"));
1075 strcpy (expanded_name, "standard__");
1076 strcat (expanded_name, name);
21b556f4 1077 sym = ada_lookup_symbol (expanded_name, NULL, VAR_DOMAIN, NULL);
52ce6436
PH
1078 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1079 type = SYMBOL_TYPE (sym);
1080 }
1081
1082 return type;
1083}
1084
1085static int
1086chop_selector (char *name, int end)
1087{
1088 int i;
1089 for (i = end - 1; i > 0; i -= 1)
1090 if (name[i] == '.' || (name[i] == '_' && name[i+1] == '_'))
1091 return i;
1092 return -1;
1093}
1094
d3353bbd
JB
1095/* If NAME is a string beginning with a separator (either '__', or
1096 '.'), chop this separator and return the result; else, return
1097 NAME. */
1098
1099static char *
1100chop_separator (char *name)
1101{
1102 if (*name == '.')
1103 return name + 1;
1104
1105 if (name[0] == '_' && name[1] == '_')
1106 return name + 2;
1107
1108 return name;
1109}
1110
52ce6436
PH
1111/* Given that SELS is a string of the form (<sep><identifier>)*, where
1112 <sep> is '__' or '.', write the indicated sequence of
1113 STRUCTOP_STRUCT expression operators. */
1114static void
1115write_selectors (char *sels)
1116{
1117 while (*sels != '\0')
1118 {
1119 struct stoken field_name;
d3353bbd
JB
1120 char *p = chop_separator (sels);
1121 sels = p;
52ce6436
PH
1122 while (*sels != '\0' && *sels != '.'
1123 && (sels[0] != '_' || sels[1] != '_'))
1124 sels += 1;
1125 field_name.length = sels - p;
1126 field_name.ptr = p;
1127 write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
1128 }
1129}
1130
1131/* Write a variable access (OP_VAR_VALUE) to ambiguous encoded name
1132 NAME[0..LEN-1], in block context BLOCK, to be resolved later. Writes
1133 a temporary symbol that is valid until the next call to ada_parse.
1134 */
1135static void
270140bd 1136write_ambiguous_var (const struct block *block, char *name, int len)
52ce6436
PH
1137{
1138 struct symbol *sym =
1139 obstack_alloc (&temp_parse_space, sizeof (struct symbol));
1140 memset (sym, 0, sizeof (struct symbol));
1141 SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
10f0c4bb 1142 SYMBOL_LINKAGE_NAME (sym) = obstack_copy0 (&temp_parse_space, name, len);
52ce6436
PH
1143 SYMBOL_LANGUAGE (sym) = language_ada;
1144
1145 write_exp_elt_opcode (OP_VAR_VALUE);
1146 write_exp_elt_block (block);
1147 write_exp_elt_sym (sym);
1148 write_exp_elt_opcode (OP_VAR_VALUE);
1149}
1150
d3353bbd
JB
1151/* A convenient wrapper around ada_get_field_index that takes
1152 a non NUL-terminated FIELD_NAME0 and a FIELD_NAME_LEN instead
1153 of a NUL-terminated field name. */
1154
1155static int
1156ada_nget_field_index (const struct type *type, const char *field_name0,
1157 int field_name_len, int maybe_missing)
1158{
1159 char *field_name = alloca ((field_name_len + 1) * sizeof (char));
1160
1161 strncpy (field_name, field_name0, field_name_len);
1162 field_name[field_name_len] = '\0';
1163 return ada_get_field_index (type, field_name, maybe_missing);
1164}
1165
1166/* If encoded_field_name is the name of a field inside symbol SYM,
1167 then return the type of that field. Otherwise, return NULL.
1168
1169 This function is actually recursive, so if ENCODED_FIELD_NAME
1170 doesn't match one of the fields of our symbol, then try to see
1171 if ENCODED_FIELD_NAME could not be a succession of field names
1172 (in other words, the user entered an expression of the form
1173 TYPE_NAME.FIELD1.FIELD2.FIELD3), in which case we evaluate
1174 each field name sequentially to obtain the desired field type.
1175 In case of failure, we return NULL. */
1176
1177static struct type *
1178get_symbol_field_type (struct symbol *sym, char *encoded_field_name)
1179{
1180 char *field_name = encoded_field_name;
1181 char *subfield_name;
1182 struct type *type = SYMBOL_TYPE (sym);
1183 int fieldno;
1184
1185 if (type == NULL || field_name == NULL)
1186 return NULL;
6cdd57f4 1187 type = check_typedef (type);
d3353bbd
JB
1188
1189 while (field_name[0] != '\0')
1190 {
1191 field_name = chop_separator (field_name);
1192
1193 fieldno = ada_get_field_index (type, field_name, 1);
1194 if (fieldno >= 0)
1195 return TYPE_FIELD_TYPE (type, fieldno);
1196
1197 subfield_name = field_name;
1198 while (*subfield_name != '\0' && *subfield_name != '.'
1199 && (subfield_name[0] != '_' || subfield_name[1] != '_'))
1200 subfield_name += 1;
1201
1202 if (subfield_name[0] == '\0')
1203 return NULL;
1204
1205 fieldno = ada_nget_field_index (type, field_name,
1206 subfield_name - field_name, 1);
1207 if (fieldno < 0)
1208 return NULL;
1209
1210 type = TYPE_FIELD_TYPE (type, fieldno);
1211 field_name = subfield_name;
1212 }
1213
1214 return NULL;
1215}
52ce6436
PH
1216
1217/* Look up NAME0 (an unencoded identifier or dotted name) in BLOCK (or
1218 expression_block_context if NULL). If it denotes a type, return
1219 that type. Otherwise, write expression code to evaluate it as an
1220 object and return NULL. In this second case, NAME0 will, in general,
1221 have the form <name>(.<selector_name>)*, where <name> is an object
1222 or renaming encoded in the debugging data. Calls error if no
1223 prefix <name> matches a name in the debugging data (i.e., matches
1224 either a complete name or, as a wild-card match, the final
1225 identifier). */
1226
1227static struct type*
270140bd 1228write_var_or_type (const struct block *block, struct stoken name0)
52ce6436
PH
1229{
1230 int depth;
1231 char *encoded_name;
1232 int name_len;
1233
1234 if (block == NULL)
1235 block = expression_context_block;
1236
1237 encoded_name = ada_encode (name0.ptr);
1238 name_len = strlen (encoded_name);
10f0c4bb 1239 encoded_name = obstack_copy0 (&temp_parse_space, encoded_name, name_len);
52ce6436
PH
1240 for (depth = 0; depth < MAX_RENAMING_CHAIN_LENGTH; depth += 1)
1241 {
1242 int tail_index;
1243
1244 tail_index = name_len;
1245 while (tail_index > 0)
1246 {
1247 int nsyms;
1248 struct ada_symbol_info *syms;
1249 struct symbol *type_sym;
aeb5907d
JB
1250 struct symbol *renaming_sym;
1251 const char* renaming;
1252 int renaming_len;
1253 const char* renaming_expr;
52ce6436
PH
1254 int terminator = encoded_name[tail_index];
1255
1256 encoded_name[tail_index] = '\0';
1257 nsyms = ada_lookup_symbol_list (encoded_name, block,
4eeaa230 1258 VAR_DOMAIN, &syms);
52ce6436
PH
1259 encoded_name[tail_index] = terminator;
1260
1261 /* A single symbol may rename a package or object. */
1262
aeb5907d
JB
1263 /* This should go away when we move entirely to new version.
1264 FIXME pnh 7/20/2007. */
1265 if (nsyms == 1)
52ce6436 1266 {
e5e61bd7 1267 struct symbol *ren_sym =
739593e0 1268 ada_find_renaming_symbol (syms[0].sym, syms[0].block);
52ce6436 1269
e5e61bd7
AS
1270 if (ren_sym != NULL)
1271 syms[0].sym = ren_sym;
52ce6436
PH
1272 }
1273
1274 type_sym = select_possible_type_sym (syms, nsyms);
aeb5907d
JB
1275
1276 if (type_sym != NULL)
1277 renaming_sym = type_sym;
1278 else if (nsyms == 1)
1279 renaming_sym = syms[0].sym;
1280 else
1281 renaming_sym = NULL;
1282
1283 switch (ada_parse_renaming (renaming_sym, &renaming,
1284 &renaming_len, &renaming_expr))
1285 {
1286 case ADA_NOT_RENAMING:
1287 break;
1288 case ADA_PACKAGE_RENAMING:
1289 case ADA_EXCEPTION_RENAMING:
1290 case ADA_SUBPROGRAM_RENAMING:
1291 {
1292 char *new_name
1293 = obstack_alloc (&temp_parse_space,
1294 renaming_len + name_len - tail_index + 1);
1295 strncpy (new_name, renaming, renaming_len);
1296 strcpy (new_name + renaming_len, encoded_name + tail_index);
1297 encoded_name = new_name;
1298 name_len = renaming_len + name_len - tail_index;
1299 goto TryAfterRenaming;
1300 }
1301 case ADA_OBJECT_RENAMING:
1302 write_object_renaming (block, renaming, renaming_len,
1303 renaming_expr, MAX_RENAMING_CHAIN_LENGTH);
1304 write_selectors (encoded_name + tail_index);
1305 return NULL;
1306 default:
1307 internal_error (__FILE__, __LINE__,
1308 _("impossible value from ada_parse_renaming"));
1309 }
1310
52ce6436
PH
1311 if (type_sym != NULL)
1312 {
d3353bbd
JB
1313 struct type *field_type;
1314
1315 if (tail_index == name_len)
1316 return SYMBOL_TYPE (type_sym);
1317
1318 /* We have some extraneous characters after the type name.
1319 If this is an expression "TYPE_NAME.FIELD0.[...].FIELDN",
1320 then try to get the type of FIELDN. */
1321 field_type
1322 = get_symbol_field_type (type_sym, encoded_name + tail_index);
1323 if (field_type != NULL)
1324 return field_type;
52ce6436 1325 else
d3353bbd
JB
1326 error (_("Invalid attempt to select from type: \"%s\"."),
1327 name0.ptr);
52ce6436
PH
1328 }
1329 else if (tail_index == name_len && nsyms == 0)
1330 {
1331 struct type *type = find_primitive_type (encoded_name);
1332
1333 if (type != NULL)
1334 return type;
1335 }
1336
1337 if (nsyms == 1)
1338 {
1339 write_var_from_sym (block, syms[0].block, syms[0].sym);
1340 write_selectors (encoded_name + tail_index);
1341 return NULL;
1342 }
1343 else if (nsyms == 0)
1344 {
7c7b6655 1345 struct bound_minimal_symbol msym
52ce6436 1346 = ada_lookup_simple_minsym (encoded_name);
7c7b6655 1347 if (msym.minsym != NULL)
52ce6436 1348 {
c841afd5 1349 write_exp_msymbol (msym);
52ce6436
PH
1350 /* Maybe cause error here rather than later? FIXME? */
1351 write_selectors (encoded_name + tail_index);
1352 return NULL;
1353 }
1354
1355 if (tail_index == name_len
1356 && strncmp (encoded_name, "standard__",
1357 sizeof ("standard__") - 1) == 0)
e1d5a0d2 1358 error (_("No definition of \"%s\" found."), name0.ptr);
52ce6436
PH
1359
1360 tail_index = chop_selector (encoded_name, tail_index);
1361 }
1362 else
1363 {
1364 write_ambiguous_var (block, encoded_name, tail_index);
1365 write_selectors (encoded_name + tail_index);
1366 return NULL;
1367 }
1368 }
1369
1370 if (!have_full_symbols () && !have_partial_symbols () && block == NULL)
e1d5a0d2 1371 error (_("No symbol table is loaded. Use the \"file\" command."));
52ce6436 1372 if (block == expression_context_block)
e1d5a0d2 1373 error (_("No definition of \"%s\" in current context."), name0.ptr);
52ce6436 1374 else
e1d5a0d2 1375 error (_("No definition of \"%s\" in specified context."), name0.ptr);
52ce6436
PH
1376
1377 TryAfterRenaming: ;
1378 }
1379
e1d5a0d2 1380 error (_("Could not find renamed symbol \"%s\""), name0.ptr);
52ce6436
PH
1381
1382}
1383
1384/* Write a left side of a component association (e.g., NAME in NAME =>
1385 exp). If NAME has the form of a selected component, write it as an
1386 ordinary expression. If it is a simple variable that unambiguously
1387 corresponds to exactly one symbol that does not denote a type or an
1388 object renaming, also write it normally as an OP_VAR_VALUE.
1389 Otherwise, write it as an OP_NAME.
1390
1391 Unfortunately, we don't know at this point whether NAME is supposed
1392 to denote a record component name or the value of an array index.
1393 Therefore, it is not appropriate to disambiguate an ambiguous name
1394 as we normally would, nor to replace a renaming with its referent.
1395 As a result, in the (one hopes) rare case that one writes an
1396 aggregate such as (R => 42) where R renames an object or is an
1397 ambiguous name, one must write instead ((R) => 42). */
1398
1399static void
1400write_name_assoc (struct stoken name)
1401{
1402 if (strchr (name.ptr, '.') == NULL)
1403 {
1404 struct ada_symbol_info *syms;
1405 int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
4eeaa230 1406 VAR_DOMAIN, &syms);
52ce6436
PH
1407 if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF)
1408 write_exp_op_with_string (OP_NAME, name);
1409 else
1410 write_var_from_sym (NULL, syms[0].block, syms[0].sym);
1411 }
1412 else
1413 if (write_var_or_type (NULL, name) != NULL)
e1d5a0d2 1414 error (_("Invalid use of type."));
52ce6436
PH
1415}
1416
14f9c5c9
AS
1417/* Convert the character literal whose ASCII value would be VAL to the
1418 appropriate value of type TYPE, if there is a translation.
4c4b4cd2
PH
1419 Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
1420 the literal 'A' (VAL == 65), returns 0. */
52ce6436 1421
14f9c5c9 1422static LONGEST
4c4b4cd2 1423convert_char_literal (struct type *type, LONGEST val)
14f9c5c9
AS
1424{
1425 char name[7];
1426 int f;
1427
18920c42 1428 if (type == NULL)
14f9c5c9 1429 return val;
18920c42
JB
1430 type = check_typedef (type);
1431 if (TYPE_CODE (type) != TYPE_CODE_ENUM)
1432 return val;
1433
88c15c34 1434 xsnprintf (name, sizeof (name), "QU%02x", (int) val);
4c4b4cd2 1435 for (f = 0; f < TYPE_NFIELDS (type); f += 1)
14f9c5c9 1436 {
4c4b4cd2 1437 if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0)
14e75d8e 1438 return TYPE_FIELD_ENUMVAL (type, f);
14f9c5c9
AS
1439 }
1440 return val;
1441}
4c4b4cd2 1442
72d5681a
PH
1443static struct type *
1444type_int (void)
1445{
3e79cecf 1446 return parse_type->builtin_int;
72d5681a
PH
1447}
1448
1449static struct type *
1450type_long (void)
1451{
3e79cecf 1452 return parse_type->builtin_long;
72d5681a
PH
1453}
1454
1455static struct type *
1456type_long_long (void)
1457{
3e79cecf 1458 return parse_type->builtin_long_long;
72d5681a
PH
1459}
1460
1461static struct type *
1462type_float (void)
1463{
3e79cecf 1464 return parse_type->builtin_float;
72d5681a
PH
1465}
1466
1467static struct type *
1468type_double (void)
1469{
3e79cecf 1470 return parse_type->builtin_double;
72d5681a
PH
1471}
1472
1473static struct type *
1474type_long_double (void)
1475{
3e79cecf 1476 return parse_type->builtin_long_double;
72d5681a
PH
1477}
1478
1479static struct type *
1480type_char (void)
1481{
3e79cecf 1482 return language_string_char_type (parse_language, parse_gdbarch);
72d5681a
PH
1483}
1484
690cc4eb
PH
1485static struct type *
1486type_boolean (void)
1487{
3e79cecf 1488 return parse_type->builtin_bool;
690cc4eb
PH
1489}
1490
72d5681a
PH
1491static struct type *
1492type_system_address (void)
1493{
1494 struct type *type
3e79cecf
UW
1495 = language_lookup_primitive_type_by_name (parse_language,
1496 parse_gdbarch,
72d5681a 1497 "system__address");
3e79cecf 1498 return type != NULL ? type : parse_type->builtin_data_ptr;
72d5681a
PH
1499}
1500
2c0b251b
PA
1501/* Provide a prototype to silence -Wmissing-prototypes. */
1502extern initialize_file_ftype _initialize_ada_exp;
1503
4c4b4cd2
PH
1504void
1505_initialize_ada_exp (void)
1506{
1507 obstack_init (&temp_parse_space);
1508}
This page took 0.716491 seconds and 4 git commands to generate.