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