gdb/fortran: Add support for the ABS intrinsic function
[deliverable/binutils-gdb.git] / gdb / f-exp.y
CommitLineData
0c9c3474 1
c906108c 2/* YACC parser for Fortran expressions, for GDB.
42a4f53d 3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
4fcf66da 4
c906108c
SS
5 Contributed by Motorola. Adapted from the C parser by Farooq Butt
6 (fmbutt@engage.sps.mot.com).
7
5b1ba0e5 8 This file is part of GDB.
c906108c 9
5b1ba0e5
NS
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
c906108c 14
5b1ba0e5
NS
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
c906108c 19
5b1ba0e5
NS
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
22
23/* This was blantantly ripped off the C expression parser, please
24 be aware of that as you look at its basic structure -FMB */
25
26/* Parse a F77 expression from text in a string,
27 and return the result as a struct expression pointer.
28 That structure contains arithmetic operations in reverse polish,
29 with constants represented by operations that are followed by special data.
30 See expression.h for the details of the format.
31 What is important here is that it can be built up sequentially
32 during the process of parsing; the lower levels of the tree always
33 come first in the result.
34
35 Note that malloc's and realloc's in this file are transformed to
36 xmalloc and xrealloc respectively by the same sed command in the
37 makefile that remaps any other malloc/realloc inserted by the parser
38 generator. Doing this with #defines and trying to control the interaction
39 with include files (<malloc.h> and <stdlib.h> for example) just became
40 too messy, particularly when such includes can be inserted at random
41 times by the parser generator. */
42
43%{
44
45#include "defs.h"
c906108c
SS
46#include "expression.h"
47#include "value.h"
48#include "parser-defs.h"
49#include "language.h"
50#include "f-lang.h"
51#include "bfd.h" /* Required by objfiles.h. */
52#include "symfile.h" /* Required by objfiles.h. */
53#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
fe898f56 54#include "block.h"
0f6e1ba6 55#include <ctype.h>
325fac50 56#include <algorithm>
c906108c 57
410a0ff2
SDJ
58#define parse_type(ps) builtin_type (parse_gdbarch (ps))
59#define parse_f_type(ps) builtin_f_type (parse_gdbarch (ps))
3e79cecf 60
b3f11165
PA
61/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
62 etc). */
63#define GDB_YY_REMAP_PREFIX f_
64#include "yy-remap.h"
f461f5cf 65
410a0ff2
SDJ
66/* The state of the parser, used internally when we are parsing the
67 expression. */
68
69static struct parser_state *pstate = NULL;
70
a14ed312 71int yyparse (void);
c906108c 72
a14ed312 73static int yylex (void);
c906108c 74
69d340c6 75static void yyerror (const char *);
c906108c 76
a14ed312 77static void growbuf_by_size (int);
c906108c 78
a14ed312 79static int match_string_literal (void);
c906108c 80
4d00f5d8
AB
81static void push_kind_type (LONGEST val, struct type *type);
82
83static struct type *convert_to_kind_type (struct type *basetype, int kind);
84
c906108c
SS
85%}
86
87/* Although the yacc "value" of an expression is not used,
88 since the result is stored in the structure being created,
89 other node types do have values. */
90
91%union
92 {
93 LONGEST lval;
94 struct {
95 LONGEST val;
96 struct type *type;
97 } typed_val;
edd079d9
UW
98 struct {
99 gdb_byte val[16];
100 struct type *type;
101 } typed_val_float;
c906108c
SS
102 struct symbol *sym;
103 struct type *tval;
104 struct stoken sval;
105 struct ttype tsym;
106 struct symtoken ssym;
107 int voidval;
108 struct block *bval;
109 enum exp_opcode opcode;
110 struct internalvar *ivar;
111
112 struct type **tvec;
113 int *ivec;
114 }
115
116%{
117/* YYSTYPE gets defined by %union */
410a0ff2
SDJ
118static int parse_number (struct parser_state *, const char *, int,
119 int, YYSTYPE *);
c906108c
SS
120%}
121
122%type <voidval> exp type_exp start variable
123%type <tval> type typebase
124%type <tvec> nonempty_typelist
125/* %type <bval> block */
126
127/* Fancy type parsing. */
128%type <voidval> func_mod direct_abs_decl abs_decl
129%type <tval> ptype
130
131%token <typed_val> INT
edd079d9 132%token <typed_val_float> FLOAT
c906108c
SS
133
134/* Both NAME and TYPENAME tokens represent symbols in the input,
135 and both convey their data as strings.
136 But a TYPENAME is a string that happens to be defined as a typedef
137 or builtin type name (such as int or char)
138 and a NAME is any other symbol.
139 Contexts where this distinction is not important can use the
140 nonterminal "name", which matches either NAME or TYPENAME. */
141
142%token <sval> STRING_LITERAL
143%token <lval> BOOLEAN_LITERAL
144%token <ssym> NAME
145%token <tsym> TYPENAME
2a5e440c 146%type <sval> name
c906108c 147%type <ssym> name_not_typename
c906108c
SS
148
149/* A NAME_OR_INT is a symbol which is not known in the symbol table,
150 but which would parse as a valid number in the current input radix.
151 E.g. "c" when input_radix==16. Depending on the parse, it will be
152 turned into a name or into a number. */
153
154%token <ssym> NAME_OR_INT
155
4d00f5d8 156%token SIZEOF KIND
c906108c
SS
157%token ERROR
158
159/* Special type cases, put in to allow the parser to distinguish different
160 legal basetypes. */
161%token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD
ce4b0682 162%token LOGICAL_S8_KEYWORD
c906108c
SS
163%token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
164%token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD
165%token BOOL_AND BOOL_OR BOOL_NOT
166%token <lval> CHARACTER
167
cfeadda5 168%token <voidval> DOLLAR_VARIABLE
c906108c
SS
169
170%token <opcode> ASSIGN_MODIFY
0841c79a 171%token <opcode> UNOP_INTRINSIC
c906108c
SS
172
173%left ','
174%left ABOVE_COMMA
175%right '=' ASSIGN_MODIFY
176%right '?'
177%left BOOL_OR
178%right BOOL_NOT
179%left BOOL_AND
180%left '|'
181%left '^'
182%left '&'
183%left EQUAL NOTEQUAL
184%left LESSTHAN GREATERTHAN LEQ GEQ
185%left LSH RSH
186%left '@'
187%left '+' '-'
2a5e440c 188%left '*' '/'
bd49c137 189%right STARSTAR
2a5e440c 190%right '%'
c906108c
SS
191%right UNARY
192%right '('
193
194\f
195%%
196
197start : exp
198 | type_exp
199 ;
200
201type_exp: type
410a0ff2
SDJ
202 { write_exp_elt_opcode (pstate, OP_TYPE);
203 write_exp_elt_type (pstate, $1);
204 write_exp_elt_opcode (pstate, OP_TYPE); }
c906108c
SS
205 ;
206
207exp : '(' exp ')'
208 { }
209 ;
210
211/* Expressions, not including the comma operator. */
212exp : '*' exp %prec UNARY
410a0ff2 213 { write_exp_elt_opcode (pstate, UNOP_IND); }
ef944135 214 ;
c906108c
SS
215
216exp : '&' exp %prec UNARY
410a0ff2 217 { write_exp_elt_opcode (pstate, UNOP_ADDR); }
ef944135 218 ;
c906108c
SS
219
220exp : '-' exp %prec UNARY
410a0ff2 221 { write_exp_elt_opcode (pstate, UNOP_NEG); }
c906108c
SS
222 ;
223
224exp : BOOL_NOT exp %prec UNARY
410a0ff2 225 { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
c906108c
SS
226 ;
227
228exp : '~' exp %prec UNARY
410a0ff2 229 { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
c906108c
SS
230 ;
231
232exp : SIZEOF exp %prec UNARY
410a0ff2 233 { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
c906108c
SS
234 ;
235
4d00f5d8
AB
236exp : KIND '(' exp ')' %prec UNARY
237 { write_exp_elt_opcode (pstate, UNOP_KIND); }
238 ;
239
c906108c
SS
240/* No more explicit array operators, we treat everything in F77 as
241 a function call. The disambiguation as to whether we are
242 doing a subscript operation or a function call is done
243 later in eval.c. */
244
245exp : exp '('
246 { start_arglist (); }
247 arglist ')'
410a0ff2
SDJ
248 { write_exp_elt_opcode (pstate,
249 OP_F77_UNDETERMINED_ARGLIST);
250 write_exp_elt_longcst (pstate,
251 (LONGEST) end_arglist ());
252 write_exp_elt_opcode (pstate,
253 OP_F77_UNDETERMINED_ARGLIST); }
c906108c
SS
254 ;
255
0841c79a
AB
256exp : UNOP_INTRINSIC '(' exp ')'
257 { write_exp_elt_opcode (pstate, $1); }
258 ;
259
c906108c
SS
260arglist :
261 ;
262
263arglist : exp
264 { arglist_len = 1; }
265 ;
266
0b4e1325
WZ
267arglist : subrange
268 { arglist_len = 1; }
ef944135 269 ;
c906108c
SS
270
271arglist : arglist ',' exp %prec ABOVE_COMMA
272 { arglist_len++; }
273 ;
274
0b4e1325
WZ
275/* There are four sorts of subrange types in F90. */
276
277subrange: exp ':' exp %prec ABOVE_COMMA
01739a3b 278 { write_exp_elt_opcode (pstate, OP_RANGE);
410a0ff2 279 write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
01739a3b 280 write_exp_elt_opcode (pstate, OP_RANGE); }
0b4e1325
WZ
281 ;
282
283subrange: exp ':' %prec ABOVE_COMMA
01739a3b 284 { write_exp_elt_opcode (pstate, OP_RANGE);
410a0ff2 285 write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
01739a3b 286 write_exp_elt_opcode (pstate, OP_RANGE); }
c906108c
SS
287 ;
288
0b4e1325 289subrange: ':' exp %prec ABOVE_COMMA
01739a3b 290 { write_exp_elt_opcode (pstate, OP_RANGE);
410a0ff2 291 write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
01739a3b 292 write_exp_elt_opcode (pstate, OP_RANGE); }
0b4e1325
WZ
293 ;
294
295subrange: ':' %prec ABOVE_COMMA
01739a3b 296 { write_exp_elt_opcode (pstate, OP_RANGE);
410a0ff2 297 write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
01739a3b 298 write_exp_elt_opcode (pstate, OP_RANGE); }
0b4e1325 299 ;
c906108c
SS
300
301complexnum: exp ',' exp
302 { }
303 ;
304
305exp : '(' complexnum ')'
410a0ff2
SDJ
306 { write_exp_elt_opcode (pstate, OP_COMPLEX);
307 write_exp_elt_type (pstate,
308 parse_f_type (pstate)
309 ->builtin_complex_s16);
310 write_exp_elt_opcode (pstate, OP_COMPLEX); }
c906108c
SS
311 ;
312
313exp : '(' type ')' exp %prec UNARY
410a0ff2
SDJ
314 { write_exp_elt_opcode (pstate, UNOP_CAST);
315 write_exp_elt_type (pstate, $2);
316 write_exp_elt_opcode (pstate, UNOP_CAST); }
c906108c
SS
317 ;
318
2a5e440c 319exp : exp '%' name
410a0ff2
SDJ
320 { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
321 write_exp_string (pstate, $3);
322 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
2a5e440c
WZ
323 ;
324
c906108c
SS
325/* Binary operators in order of decreasing precedence. */
326
327exp : exp '@' exp
410a0ff2 328 { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
c906108c
SS
329 ;
330
bd49c137 331exp : exp STARSTAR exp
410a0ff2 332 { write_exp_elt_opcode (pstate, BINOP_EXP); }
bd49c137
WZ
333 ;
334
c906108c 335exp : exp '*' exp
410a0ff2 336 { write_exp_elt_opcode (pstate, BINOP_MUL); }
c906108c
SS
337 ;
338
339exp : exp '/' exp
410a0ff2 340 { write_exp_elt_opcode (pstate, BINOP_DIV); }
c906108c
SS
341 ;
342
c906108c 343exp : exp '+' exp
410a0ff2 344 { write_exp_elt_opcode (pstate, BINOP_ADD); }
c906108c
SS
345 ;
346
347exp : exp '-' exp
410a0ff2 348 { write_exp_elt_opcode (pstate, BINOP_SUB); }
c906108c
SS
349 ;
350
351exp : exp LSH exp
410a0ff2 352 { write_exp_elt_opcode (pstate, BINOP_LSH); }
c906108c
SS
353 ;
354
355exp : exp RSH exp
410a0ff2 356 { write_exp_elt_opcode (pstate, BINOP_RSH); }
c906108c
SS
357 ;
358
359exp : exp EQUAL exp
410a0ff2 360 { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
c906108c
SS
361 ;
362
363exp : exp NOTEQUAL exp
410a0ff2 364 { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
c906108c
SS
365 ;
366
367exp : exp LEQ exp
410a0ff2 368 { write_exp_elt_opcode (pstate, BINOP_LEQ); }
c906108c
SS
369 ;
370
371exp : exp GEQ exp
410a0ff2 372 { write_exp_elt_opcode (pstate, BINOP_GEQ); }
c906108c
SS
373 ;
374
375exp : exp LESSTHAN exp
410a0ff2 376 { write_exp_elt_opcode (pstate, BINOP_LESS); }
c906108c
SS
377 ;
378
379exp : exp GREATERTHAN exp
410a0ff2 380 { write_exp_elt_opcode (pstate, BINOP_GTR); }
c906108c
SS
381 ;
382
383exp : exp '&' exp
410a0ff2 384 { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
c906108c
SS
385 ;
386
387exp : exp '^' exp
410a0ff2 388 { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
c906108c
SS
389 ;
390
391exp : exp '|' exp
410a0ff2 392 { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
c906108c
SS
393 ;
394
395exp : exp BOOL_AND exp
410a0ff2 396 { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
c906108c
SS
397 ;
398
399
400exp : exp BOOL_OR exp
410a0ff2 401 { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
c906108c
SS
402 ;
403
404exp : exp '=' exp
410a0ff2 405 { write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
c906108c
SS
406 ;
407
408exp : exp ASSIGN_MODIFY exp
410a0ff2
SDJ
409 { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY);
410 write_exp_elt_opcode (pstate, $2);
411 write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); }
c906108c
SS
412 ;
413
414exp : INT
410a0ff2
SDJ
415 { write_exp_elt_opcode (pstate, OP_LONG);
416 write_exp_elt_type (pstate, $1.type);
417 write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
418 write_exp_elt_opcode (pstate, OP_LONG); }
c906108c
SS
419 ;
420
421exp : NAME_OR_INT
422 { YYSTYPE val;
410a0ff2
SDJ
423 parse_number (pstate, $1.stoken.ptr,
424 $1.stoken.length, 0, &val);
425 write_exp_elt_opcode (pstate, OP_LONG);
426 write_exp_elt_type (pstate, val.typed_val.type);
427 write_exp_elt_longcst (pstate,
428 (LONGEST)val.typed_val.val);
429 write_exp_elt_opcode (pstate, OP_LONG); }
c906108c
SS
430 ;
431
432exp : FLOAT
edd079d9
UW
433 { write_exp_elt_opcode (pstate, OP_FLOAT);
434 write_exp_elt_type (pstate, $1.type);
435 write_exp_elt_floatcst (pstate, $1.val);
436 write_exp_elt_opcode (pstate, OP_FLOAT); }
c906108c
SS
437 ;
438
439exp : variable
440 ;
441
cfeadda5 442exp : DOLLAR_VARIABLE
c906108c
SS
443 ;
444
445exp : SIZEOF '(' type ')' %prec UNARY
410a0ff2
SDJ
446 { write_exp_elt_opcode (pstate, OP_LONG);
447 write_exp_elt_type (pstate,
448 parse_f_type (pstate)
449 ->builtin_integer);
f168693b 450 $3 = check_typedef ($3);
410a0ff2
SDJ
451 write_exp_elt_longcst (pstate,
452 (LONGEST) TYPE_LENGTH ($3));
453 write_exp_elt_opcode (pstate, OP_LONG); }
c906108c
SS
454 ;
455
456exp : BOOLEAN_LITERAL
410a0ff2
SDJ
457 { write_exp_elt_opcode (pstate, OP_BOOL);
458 write_exp_elt_longcst (pstate, (LONGEST) $1);
459 write_exp_elt_opcode (pstate, OP_BOOL);
c906108c
SS
460 }
461 ;
462
463exp : STRING_LITERAL
464 {
410a0ff2
SDJ
465 write_exp_elt_opcode (pstate, OP_STRING);
466 write_exp_string (pstate, $1);
467 write_exp_elt_opcode (pstate, OP_STRING);
c906108c
SS
468 }
469 ;
470
471variable: name_not_typename
d12307c1 472 { struct block_symbol sym = $1.sym;
c906108c 473
d12307c1 474 if (sym.symbol)
c906108c 475 {
d12307c1 476 if (symbol_read_needs_frame (sym.symbol))
aee1fcdf 477 innermost_block.update (sym);
410a0ff2 478 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
63e43d3a 479 write_exp_elt_block (pstate, sym.block);
d12307c1 480 write_exp_elt_sym (pstate, sym.symbol);
410a0ff2 481 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
c906108c
SS
482 break;
483 }
484 else
485 {
7c7b6655 486 struct bound_minimal_symbol msymbol;
710122da 487 char *arg = copy_name ($1.stoken);
c906108c
SS
488
489 msymbol =
7c7b6655
TT
490 lookup_bound_minimal_symbol (arg);
491 if (msymbol.minsym != NULL)
410a0ff2 492 write_exp_msymbol (pstate, msymbol);
c906108c 493 else if (!have_full_symbols () && !have_partial_symbols ())
001083c6 494 error (_("No symbol table is loaded. Use the \"file\" command."));
c906108c 495 else
001083c6 496 error (_("No symbol \"%s\" in current context."),
c906108c
SS
497 copy_name ($1.stoken));
498 }
499 }
500 ;
501
502
503type : ptype
504 ;
505
506ptype : typebase
507 | typebase abs_decl
508 {
509 /* This is where the interesting stuff happens. */
510 int done = 0;
511 int array_size;
512 struct type *follow_type = $1;
513 struct type *range_type;
514
515 while (!done)
516 switch (pop_type ())
517 {
518 case tp_end:
519 done = 1;
520 break;
521 case tp_pointer:
522 follow_type = lookup_pointer_type (follow_type);
523 break;
524 case tp_reference:
3b224330 525 follow_type = lookup_lvalue_reference_type (follow_type);
c906108c
SS
526 break;
527 case tp_array:
528 array_size = pop_type_int ();
529 if (array_size != -1)
530 {
531 range_type =
0c9c3474
SA
532 create_static_range_type ((struct type *) NULL,
533 parse_f_type (pstate)
534 ->builtin_integer,
535 0, array_size - 1);
c906108c
SS
536 follow_type =
537 create_array_type ((struct type *) NULL,
538 follow_type, range_type);
539 }
540 else
541 follow_type = lookup_pointer_type (follow_type);
542 break;
543 case tp_function:
544 follow_type = lookup_function_type (follow_type);
545 break;
4d00f5d8
AB
546 case tp_kind:
547 {
548 int kind_val = pop_type_int ();
549 follow_type
550 = convert_to_kind_type (follow_type, kind_val);
551 }
552 break;
c906108c
SS
553 }
554 $$ = follow_type;
555 }
556 ;
557
558abs_decl: '*'
559 { push_type (tp_pointer); $$ = 0; }
560 | '*' abs_decl
561 { push_type (tp_pointer); $$ = $2; }
562 | '&'
563 { push_type (tp_reference); $$ = 0; }
564 | '&' abs_decl
565 { push_type (tp_reference); $$ = $2; }
566 | direct_abs_decl
567 ;
568
569direct_abs_decl: '(' abs_decl ')'
570 { $$ = $2; }
4d00f5d8
AB
571 | '(' KIND '=' INT ')'
572 { push_kind_type ($4.val, $4.type); }
c906108c
SS
573 | direct_abs_decl func_mod
574 { push_type (tp_function); }
575 | func_mod
576 { push_type (tp_function); }
577 ;
578
579func_mod: '(' ')'
580 { $$ = 0; }
581 | '(' nonempty_typelist ')'
8dbb1c65 582 { free ($2); $$ = 0; }
c906108c
SS
583 ;
584
585typebase /* Implements (approximately): (type-qualifier)* type-specifier */
586 : TYPENAME
587 { $$ = $1.type; }
588 | INT_KEYWORD
410a0ff2 589 { $$ = parse_f_type (pstate)->builtin_integer; }
c906108c 590 | INT_S2_KEYWORD
410a0ff2 591 { $$ = parse_f_type (pstate)->builtin_integer_s2; }
c906108c 592 | CHARACTER
410a0ff2 593 { $$ = parse_f_type (pstate)->builtin_character; }
ce4b0682 594 | LOGICAL_S8_KEYWORD
410a0ff2 595 { $$ = parse_f_type (pstate)->builtin_logical_s8; }
c906108c 596 | LOGICAL_KEYWORD
410a0ff2 597 { $$ = parse_f_type (pstate)->builtin_logical; }
c906108c 598 | LOGICAL_S2_KEYWORD
410a0ff2 599 { $$ = parse_f_type (pstate)->builtin_logical_s2; }
c906108c 600 | LOGICAL_S1_KEYWORD
410a0ff2 601 { $$ = parse_f_type (pstate)->builtin_logical_s1; }
c906108c 602 | REAL_KEYWORD
410a0ff2 603 { $$ = parse_f_type (pstate)->builtin_real; }
c906108c 604 | REAL_S8_KEYWORD
410a0ff2 605 { $$ = parse_f_type (pstate)->builtin_real_s8; }
c906108c 606 | REAL_S16_KEYWORD
410a0ff2 607 { $$ = parse_f_type (pstate)->builtin_real_s16; }
c906108c 608 | COMPLEX_S8_KEYWORD
410a0ff2 609 { $$ = parse_f_type (pstate)->builtin_complex_s8; }
c906108c 610 | COMPLEX_S16_KEYWORD
410a0ff2 611 { $$ = parse_f_type (pstate)->builtin_complex_s16; }
c906108c 612 | COMPLEX_S32_KEYWORD
410a0ff2 613 { $$ = parse_f_type (pstate)->builtin_complex_s32; }
c906108c
SS
614 ;
615
c906108c
SS
616nonempty_typelist
617 : type
618 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
619 $<ivec>$[0] = 1; /* Number of types in vector */
620 $$[1] = $1;
621 }
622 | nonempty_typelist ',' type
623 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
624 $$ = (struct type **) realloc ((char *) $1, len);
625 $$[$<ivec>$[0]] = $3;
626 }
627 ;
628
2a5e440c
WZ
629name : NAME
630 { $$ = $1.stoken; }
631 ;
632
c906108c
SS
633name_not_typename : NAME
634/* These would be useful if name_not_typename was useful, but it is just
635 a fake for "variable", so these cause reduce/reduce conflicts because
636 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
637 =exp) or just an exp. If name_not_typename was ever used in an lvalue
638 context where only a name could occur, this might be useful.
639 | NAME_OR_INT
640 */
641 ;
642
643%%
644
645/* Take care of parsing a number (anything that starts with a digit).
646 Set yylval and return the token type; update lexptr.
647 LEN is the number of characters in it. */
648
649/*** Needs some error checking for the float case ***/
650
651static int
410a0ff2
SDJ
652parse_number (struct parser_state *par_state,
653 const char *p, int len, int parsed_float, YYSTYPE *putithere)
c906108c 654{
710122da
DC
655 LONGEST n = 0;
656 LONGEST prevn = 0;
657 int c;
658 int base = input_radix;
c906108c
SS
659 int unsigned_p = 0;
660 int long_p = 0;
661 ULONGEST high_bit;
662 struct type *signed_type;
663 struct type *unsigned_type;
664
665 if (parsed_float)
666 {
667 /* It's a float since it contains a point or an exponent. */
edd079d9
UW
668 /* [dD] is not understood as an exponent by parse_float,
669 change it to 'e'. */
c906108c
SS
670 char *tmp, *tmp2;
671
4fcf66da 672 tmp = xstrdup (p);
c906108c
SS
673 for (tmp2 = tmp; *tmp2; ++tmp2)
674 if (*tmp2 == 'd' || *tmp2 == 'D')
675 *tmp2 = 'e';
edd079d9
UW
676
677 /* FIXME: Should this use different types? */
678 putithere->typed_val_float.type = parse_f_type (pstate)->builtin_real_s8;
679 bool parsed = parse_float (tmp, len,
680 putithere->typed_val_float.type,
681 putithere->typed_val_float.val);
c906108c 682 free (tmp);
edd079d9 683 return parsed? FLOAT : ERROR;
c906108c
SS
684 }
685
686 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
687 if (p[0] == '0')
688 switch (p[1])
689 {
690 case 'x':
691 case 'X':
692 if (len >= 3)
693 {
694 p += 2;
695 base = 16;
696 len -= 2;
697 }
698 break;
699
700 case 't':
701 case 'T':
702 case 'd':
703 case 'D':
704 if (len >= 3)
705 {
706 p += 2;
707 base = 10;
708 len -= 2;
709 }
710 break;
711
712 default:
713 base = 8;
714 break;
715 }
716
717 while (len-- > 0)
718 {
719 c = *p++;
0f6e1ba6
AC
720 if (isupper (c))
721 c = tolower (c);
722 if (len == 0 && c == 'l')
723 long_p = 1;
724 else if (len == 0 && c == 'u')
725 unsigned_p = 1;
c906108c
SS
726 else
727 {
0f6e1ba6
AC
728 int i;
729 if (c >= '0' && c <= '9')
730 i = c - '0';
731 else if (c >= 'a' && c <= 'f')
732 i = c - 'a' + 10;
c906108c
SS
733 else
734 return ERROR; /* Char not a digit */
0f6e1ba6
AC
735 if (i >= base)
736 return ERROR; /* Invalid digit in this base */
737 n *= base;
738 n += i;
c906108c 739 }
c906108c
SS
740 /* Portably test for overflow (only works for nonzero values, so make
741 a second check for zero). */
742 if ((prevn >= n) && n != 0)
743 unsigned_p=1; /* Try something unsigned */
744 /* If range checking enabled, portably test for unsigned overflow. */
745 if (RANGE_CHECK && n != 0)
746 {
747 if ((unsigned_p && (unsigned)prevn >= (unsigned)n))
001083c6 748 range_error (_("Overflow on numeric constant."));
c906108c
SS
749 }
750 prevn = n;
751 }
752
753 /* If the number is too big to be an int, or it's got an l suffix
754 then it's a long. Work out if this has to be a long by
7a9dd1b2 755 shifting right and seeing if anything remains, and the
c906108c
SS
756 target int size is different to the target long size.
757
758 In the expression below, we could have tested
3e79cecf 759 (n >> gdbarch_int_bit (parse_gdbarch))
c906108c
SS
760 to see if it was zero,
761 but too many compilers warn about that, when ints and longs
762 are the same size. So we shift it twice, with fewer bits
763 each time, for the same result. */
764
410a0ff2
SDJ
765 if ((gdbarch_int_bit (parse_gdbarch (par_state))
766 != gdbarch_long_bit (parse_gdbarch (par_state))
9a76efb6 767 && ((n >> 2)
410a0ff2
SDJ
768 >> (gdbarch_int_bit (parse_gdbarch (par_state))-2))) /* Avoid
769 shift warning */
c906108c
SS
770 || long_p)
771 {
410a0ff2
SDJ
772 high_bit = ((ULONGEST)1)
773 << (gdbarch_long_bit (parse_gdbarch (par_state))-1);
774 unsigned_type = parse_type (par_state)->builtin_unsigned_long;
775 signed_type = parse_type (par_state)->builtin_long;
c906108c
SS
776 }
777 else
778 {
410a0ff2
SDJ
779 high_bit =
780 ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
781 unsigned_type = parse_type (par_state)->builtin_unsigned_int;
782 signed_type = parse_type (par_state)->builtin_int;
c906108c
SS
783 }
784
785 putithere->typed_val.val = n;
786
787 /* If the high bit of the worked out type is set then this number
0963b4bd 788 has to be unsigned. */
c906108c
SS
789
790 if (unsigned_p || (n & high_bit))
791 putithere->typed_val.type = unsigned_type;
792 else
793 putithere->typed_val.type = signed_type;
794
795 return INT;
796}
797
4d00f5d8
AB
798/* Called to setup the type stack when we encounter a '(kind=N)' type
799 modifier, performs some bounds checking on 'N' and then pushes this to
800 the type stack followed by the 'tp_kind' marker. */
801static void
802push_kind_type (LONGEST val, struct type *type)
803{
804 int ival;
805
806 if (TYPE_UNSIGNED (type))
807 {
808 ULONGEST uval = static_cast <ULONGEST> (val);
809 if (uval > INT_MAX)
810 error (_("kind value out of range"));
811 ival = static_cast <int> (uval);
812 }
813 else
814 {
815 if (val > INT_MAX || val < 0)
816 error (_("kind value out of range"));
817 ival = static_cast <int> (val);
818 }
819
820 push_type_int (ival);
821 push_type (tp_kind);
822}
823
824/* Called when a type has a '(kind=N)' modifier after it, for example
825 'character(kind=1)'. The BASETYPE is the type described by 'character'
826 in our example, and KIND is the integer '1'. This function returns a
827 new type that represents the basetype of a specific kind. */
828static struct type *
829convert_to_kind_type (struct type *basetype, int kind)
830{
831 if (basetype == parse_f_type (pstate)->builtin_character)
832 {
833 /* Character of kind 1 is a special case, this is the same as the
834 base character type. */
835 if (kind == 1)
836 return parse_f_type (pstate)->builtin_character;
837 }
3be47f7a
AB
838 else if (basetype == parse_f_type (pstate)->builtin_complex_s8)
839 {
840 if (kind == 4)
841 return parse_f_type (pstate)->builtin_complex_s8;
842 else if (kind == 8)
843 return parse_f_type (pstate)->builtin_complex_s16;
844 else if (kind == 16)
845 return parse_f_type (pstate)->builtin_complex_s32;
846 }
847 else if (basetype == parse_f_type (pstate)->builtin_real)
848 {
849 if (kind == 4)
850 return parse_f_type (pstate)->builtin_real;
851 else if (kind == 8)
852 return parse_f_type (pstate)->builtin_real_s8;
853 else if (kind == 16)
854 return parse_f_type (pstate)->builtin_real_s16;
855 }
856 else if (basetype == parse_f_type (pstate)->builtin_logical)
857 {
858 if (kind == 1)
859 return parse_f_type (pstate)->builtin_logical_s1;
860 else if (kind == 2)
861 return parse_f_type (pstate)->builtin_logical_s2;
862 else if (kind == 4)
863 return parse_f_type (pstate)->builtin_logical;
864 else if (kind == 8)
865 return parse_f_type (pstate)->builtin_logical_s8;
866 }
867 else if (basetype == parse_f_type (pstate)->builtin_integer)
868 {
869 if (kind == 2)
870 return parse_f_type (pstate)->builtin_integer_s2;
871 else if (kind == 4)
872 return parse_f_type (pstate)->builtin_integer;
067630bd
AB
873 else if (kind == 8)
874 return parse_f_type (pstate)->builtin_integer_s8;
3be47f7a 875 }
4d00f5d8
AB
876
877 error (_("unsupported kind %d for type %s"),
878 kind, TYPE_SAFE_NAME (basetype));
879
880 /* Should never get here. */
881 return nullptr;
882}
883
c906108c
SS
884struct token
885{
c8f91604 886 /* The string to match against. */
a121b7c1 887 const char *oper;
c8f91604
AB
888
889 /* The lexer token to return. */
c906108c 890 int token;
c8f91604
AB
891
892 /* The expression opcode to embed within the token. */
c906108c 893 enum exp_opcode opcode;
c8f91604
AB
894
895 /* When this is true the string in OPER is matched exactly including
896 case, when this is false OPER is matched case insensitively. */
897 bool case_sensitive;
c906108c
SS
898};
899
900static const struct token dot_ops[] =
901{
c8f91604
AB
902 { ".and.", BOOL_AND, BINOP_END, false },
903 { ".or.", BOOL_OR, BINOP_END, false },
904 { ".not.", BOOL_NOT, BINOP_END, false },
905 { ".eq.", EQUAL, BINOP_END, false },
906 { ".eqv.", EQUAL, BINOP_END, false },
907 { ".neqv.", NOTEQUAL, BINOP_END, false },
908 { ".ne.", NOTEQUAL, BINOP_END, false },
909 { ".le.", LEQ, BINOP_END, false },
910 { ".ge.", GEQ, BINOP_END, false },
911 { ".gt.", GREATERTHAN, BINOP_END, false },
912 { ".lt.", LESSTHAN, BINOP_END, false },
c906108c
SS
913};
914
dd9f2c76
AB
915/* Holds the Fortran representation of a boolean, and the integer value we
916 substitute in when one of the matching strings is parsed. */
917struct f77_boolean_val
c906108c 918{
dd9f2c76 919 /* The string representing a Fortran boolean. */
a121b7c1 920 const char *name;
dd9f2c76
AB
921
922 /* The integer value to replace it with. */
c906108c 923 int value;
dd9f2c76 924};
c906108c 925
dd9f2c76
AB
926/* The set of Fortran booleans. These are matched case insensitively. */
927static const struct f77_boolean_val boolean_values[] =
c906108c
SS
928{
929 { ".true.", 1 },
dd9f2c76 930 { ".false.", 0 }
c906108c
SS
931};
932
c8f91604 933static const struct token f77_keywords[] =
c906108c 934{
c8f91604
AB
935 /* Historically these have always been lowercase only in GDB. */
936 { "complex_16", COMPLEX_S16_KEYWORD, BINOP_END, true },
937 { "complex_32", COMPLEX_S32_KEYWORD, BINOP_END, true },
938 { "character", CHARACTER, BINOP_END, true },
939 { "integer_2", INT_S2_KEYWORD, BINOP_END, true },
940 { "logical_1", LOGICAL_S1_KEYWORD, BINOP_END, true },
941 { "logical_2", LOGICAL_S2_KEYWORD, BINOP_END, true },
942 { "logical_8", LOGICAL_S8_KEYWORD, BINOP_END, true },
943 { "complex_8", COMPLEX_S8_KEYWORD, BINOP_END, true },
944 { "integer", INT_KEYWORD, BINOP_END, true },
945 { "logical", LOGICAL_KEYWORD, BINOP_END, true },
946 { "real_16", REAL_S16_KEYWORD, BINOP_END, true },
947 { "complex", COMPLEX_S8_KEYWORD, BINOP_END, true },
948 { "sizeof", SIZEOF, BINOP_END, true },
949 { "real_8", REAL_S8_KEYWORD, BINOP_END, true },
950 { "real", REAL_KEYWORD, BINOP_END, true },
4d00f5d8
AB
951 /* The following correspond to actual functions in Fortran and are case
952 insensitive. */
0841c79a
AB
953 { "kind", KIND, BINOP_END, false },
954 { "abs", UNOP_INTRINSIC, UNOP_ABS, false }
c8f91604 955};
c906108c
SS
956
957/* Implementation of a dynamically expandable buffer for processing input
958 characters acquired through lexptr and building a value to return in
0963b4bd 959 yylval. Ripped off from ch-exp.y */
c906108c
SS
960
961static char *tempbuf; /* Current buffer contents */
962static int tempbufsize; /* Size of allocated buffer */
963static int tempbufindex; /* Current index into buffer */
964
965#define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */
966
967#define CHECKBUF(size) \
968 do { \
969 if (tempbufindex + (size) >= tempbufsize) \
970 { \
971 growbuf_by_size (size); \
972 } \
973 } while (0);
974
975
0963b4bd
MS
976/* Grow the static temp buffer if necessary, including allocating the
977 first one on demand. */
c906108c
SS
978
979static void
d04550a6 980growbuf_by_size (int count)
c906108c
SS
981{
982 int growby;
983
325fac50 984 growby = std::max (count, GROWBY_MIN_SIZE);
c906108c
SS
985 tempbufsize += growby;
986 if (tempbuf == NULL)
987 tempbuf = (char *) malloc (tempbufsize);
988 else
989 tempbuf = (char *) realloc (tempbuf, tempbufsize);
990}
991
992/* Blatantly ripped off from ch-exp.y. This routine recognizes F77
0963b4bd 993 string-literals.
c906108c
SS
994
995 Recognize a string literal. A string literal is a nonzero sequence
996 of characters enclosed in matching single quotes, except that
997 a single character inside single quotes is a character literal, which
998 we reject as a string literal. To embed the terminator character inside
999 a string, it is simply doubled (I.E. 'this''is''one''string') */
1000
1001static int
eeae04df 1002match_string_literal (void)
c906108c 1003{
d7561cbb 1004 const char *tokptr = lexptr;
c906108c
SS
1005
1006 for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
1007 {
1008 CHECKBUF (1);
1009 if (*tokptr == *lexptr)
1010 {
1011 if (*(tokptr + 1) == *lexptr)
1012 tokptr++;
1013 else
1014 break;
1015 }
1016 tempbuf[tempbufindex++] = *tokptr;
1017 }
1018 if (*tokptr == '\0' /* no terminator */
1019 || tempbufindex == 0) /* no string */
1020 return 0;
1021 else
1022 {
1023 tempbuf[tempbufindex] = '\0';
1024 yylval.sval.ptr = tempbuf;
1025 yylval.sval.length = tempbufindex;
1026 lexptr = ++tokptr;
1027 return STRING_LITERAL;
1028 }
1029}
1030
1031/* Read one token, getting characters through lexptr. */
1032
1033static int
eeae04df 1034yylex (void)
c906108c
SS
1035{
1036 int c;
1037 int namelen;
b926417a 1038 unsigned int token;
d7561cbb 1039 const char *tokstart;
c906108c
SS
1040
1041 retry:
065432a8
PM
1042
1043 prev_lexptr = lexptr;
1044
c906108c 1045 tokstart = lexptr;
dd9f2c76
AB
1046
1047 /* First of all, let us make sure we are not dealing with the
c906108c 1048 special tokens .true. and .false. which evaluate to 1 and 0. */
dd9f2c76 1049
c906108c 1050 if (*lexptr == '.')
dd9f2c76
AB
1051 {
1052 for (int i = 0; i < ARRAY_SIZE (boolean_values); i++)
c906108c 1053 {
dd9f2c76
AB
1054 if (strncasecmp (tokstart, boolean_values[i].name,
1055 strlen (boolean_values[i].name)) == 0)
c906108c 1056 {
dd9f2c76
AB
1057 lexptr += strlen (boolean_values[i].name);
1058 yylval.lval = boolean_values[i].value;
c906108c
SS
1059 return BOOLEAN_LITERAL;
1060 }
1061 }
1062 }
c8f91604 1063
bd49c137 1064 /* See if it is a special .foo. operator. */
c8f91604
AB
1065 for (int i = 0; i < ARRAY_SIZE (dot_ops); i++)
1066 if (strncasecmp (tokstart, dot_ops[i].oper,
1067 strlen (dot_ops[i].oper)) == 0)
c906108c 1068 {
c8f91604 1069 gdb_assert (!dot_ops[i].case_sensitive);
fe978cb0 1070 lexptr += strlen (dot_ops[i].oper);
c906108c
SS
1071 yylval.opcode = dot_ops[i].opcode;
1072 return dot_ops[i].token;
1073 }
c8f91604 1074
bd49c137
WZ
1075 /* See if it is an exponentiation operator. */
1076
1077 if (strncmp (tokstart, "**", 2) == 0)
1078 {
1079 lexptr += 2;
1080 yylval.opcode = BINOP_EXP;
1081 return STARSTAR;
1082 }
1083
c906108c
SS
1084 switch (c = *tokstart)
1085 {
1086 case 0:
1087 return 0;
1088
1089 case ' ':
1090 case '\t':
1091 case '\n':
1092 lexptr++;
1093 goto retry;
1094
1095 case '\'':
1096 token = match_string_literal ();
1097 if (token != 0)
1098 return (token);
1099 break;
1100
1101 case '(':
1102 paren_depth++;
1103 lexptr++;
1104 return c;
1105
1106 case ')':
1107 if (paren_depth == 0)
1108 return 0;
1109 paren_depth--;
1110 lexptr++;
1111 return c;
1112
1113 case ',':
1114 if (comma_terminates && paren_depth == 0)
1115 return 0;
1116 lexptr++;
1117 return c;
1118
1119 case '.':
1120 /* Might be a floating point number. */
1121 if (lexptr[1] < '0' || lexptr[1] > '9')
0963b4bd 1122 goto symbol; /* Nope, must be a symbol. */
86a73007 1123 /* FALL THRU. */
c906108c
SS
1124
1125 case '0':
1126 case '1':
1127 case '2':
1128 case '3':
1129 case '4':
1130 case '5':
1131 case '6':
1132 case '7':
1133 case '8':
1134 case '9':
1135 {
1136 /* It's a number. */
1137 int got_dot = 0, got_e = 0, got_d = 0, toktype;
d7561cbb 1138 const char *p = tokstart;
c906108c
SS
1139 int hex = input_radix > 10;
1140
1141 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1142 {
1143 p += 2;
1144 hex = 1;
1145 }
0963b4bd
MS
1146 else if (c == '0' && (p[1]=='t' || p[1]=='T'
1147 || p[1]=='d' || p[1]=='D'))
c906108c
SS
1148 {
1149 p += 2;
1150 hex = 0;
1151 }
1152
1153 for (;; ++p)
1154 {
1155 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1156 got_dot = got_e = 1;
1157 else if (!hex && !got_d && (*p == 'd' || *p == 'D'))
1158 got_dot = got_d = 1;
1159 else if (!hex && !got_dot && *p == '.')
1160 got_dot = 1;
1161 else if (((got_e && (p[-1] == 'e' || p[-1] == 'E'))
1162 || (got_d && (p[-1] == 'd' || p[-1] == 'D')))
1163 && (*p == '-' || *p == '+'))
1164 /* This is the sign of the exponent, not the end of the
1165 number. */
1166 continue;
1167 /* We will take any letters or digits. parse_number will
1168 complain if past the radix, or if L or U are not final. */
1169 else if ((*p < '0' || *p > '9')
1170 && ((*p < 'a' || *p > 'z')
1171 && (*p < 'A' || *p > 'Z')))
1172 break;
1173 }
410a0ff2
SDJ
1174 toktype = parse_number (pstate, tokstart, p - tokstart,
1175 got_dot|got_e|got_d,
c906108c
SS
1176 &yylval);
1177 if (toktype == ERROR)
1178 {
1179 char *err_copy = (char *) alloca (p - tokstart + 1);
1180
1181 memcpy (err_copy, tokstart, p - tokstart);
1182 err_copy[p - tokstart] = 0;
001083c6 1183 error (_("Invalid number \"%s\"."), err_copy);
c906108c
SS
1184 }
1185 lexptr = p;
1186 return toktype;
1187 }
1188
1189 case '+':
1190 case '-':
1191 case '*':
1192 case '/':
1193 case '%':
1194 case '|':
1195 case '&':
1196 case '^':
1197 case '~':
1198 case '!':
1199 case '@':
1200 case '<':
1201 case '>':
1202 case '[':
1203 case ']':
1204 case '?':
1205 case ':':
1206 case '=':
1207 case '{':
1208 case '}':
1209 symbol:
1210 lexptr++;
1211 return c;
1212 }
1213
f55ee35c 1214 if (!(c == '_' || c == '$' || c ==':'
c906108c
SS
1215 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1216 /* We must have come across a bad character (e.g. ';'). */
001083c6 1217 error (_("Invalid character '%c' in expression."), c);
c906108c
SS
1218
1219 namelen = 0;
1220 for (c = tokstart[namelen];
f55ee35c 1221 (c == '_' || c == '$' || c == ':' || (c >= '0' && c <= '9')
c906108c
SS
1222 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1223 c = tokstart[++namelen]);
1224
1225 /* The token "if" terminates the expression and is NOT
1226 removed from the input stream. */
1227
1228 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1229 return 0;
1230
1231 lexptr += namelen;
1232
1233 /* Catch specific keywords. */
c8f91604
AB
1234
1235 for (int i = 0; i < ARRAY_SIZE (f77_keywords); i++)
fe978cb0 1236 if (strlen (f77_keywords[i].oper) == namelen
c8f91604
AB
1237 && ((!f77_keywords[i].case_sensitive
1238 && strncasecmp (tokstart, f77_keywords[i].oper, namelen) == 0)
1239 || (f77_keywords[i].case_sensitive
1240 && strncmp (tokstart, f77_keywords[i].oper, namelen) == 0)))
c906108c 1241 {
c906108c
SS
1242 yylval.opcode = f77_keywords[i].opcode;
1243 return f77_keywords[i].token;
1244 }
c8f91604 1245
c906108c
SS
1246 yylval.sval.ptr = tokstart;
1247 yylval.sval.length = namelen;
1248
1249 if (*tokstart == '$')
1250 {
410a0ff2 1251 write_dollar_variable (pstate, yylval.sval);
cfeadda5 1252 return DOLLAR_VARIABLE;
c906108c
SS
1253 }
1254
1255 /* Use token-type TYPENAME for symbols that happen to be defined
1256 currently as names of types; NAME for other symbols.
1257 The caller is not constrained to care about the distinction. */
1258 {
1259 char *tmp = copy_name (yylval.sval);
d12307c1 1260 struct block_symbol result;
1993b719 1261 struct field_of_this_result is_a_field_of_this;
530e8392
KB
1262 enum domain_enum_tag lookup_domains[] =
1263 {
1264 STRUCT_DOMAIN,
1265 VAR_DOMAIN,
1266 MODULE_DOMAIN
1267 };
c906108c 1268 int hextype;
7f9b20bb 1269
b926417a 1270 for (int i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
c906108c 1271 {
7f9b20bb
KB
1272 /* Initialize this in case we *don't* use it in this call; that
1273 way we can refer to it unconditionally below. */
1274 memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
1275
d12307c1
PMR
1276 result = lookup_symbol (tmp, expression_context_block,
1277 lookup_domains[i],
1278 parse_language (pstate)->la_language
1279 == language_cplus
1280 ? &is_a_field_of_this : NULL);
1281 if (result.symbol && SYMBOL_CLASS (result.symbol) == LOC_TYPEDEF)
7f9b20bb 1282 {
d12307c1 1283 yylval.tsym.type = SYMBOL_TYPE (result.symbol);
7f9b20bb
KB
1284 return TYPENAME;
1285 }
1286
d12307c1 1287 if (result.symbol)
7f9b20bb 1288 break;
c906108c 1289 }
7f9b20bb 1290
54a5b07d 1291 yylval.tsym.type
46b0da17
DE
1292 = language_lookup_primitive_type (parse_language (pstate),
1293 parse_gdbarch (pstate), tmp);
54a5b07d 1294 if (yylval.tsym.type != NULL)
c906108c
SS
1295 return TYPENAME;
1296
1297 /* Input names that aren't symbols but ARE valid hex numbers,
1298 when the input radix permits them, can be names or numbers
1299 depending on the parse. Note we support radixes > 16 here. */
d12307c1 1300 if (!result.symbol
c906108c
SS
1301 && ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10)
1302 || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1303 {
1304 YYSTYPE newlval; /* Its value is ignored. */
410a0ff2 1305 hextype = parse_number (pstate, tokstart, namelen, 0, &newlval);
c906108c
SS
1306 if (hextype == INT)
1307 {
d12307c1 1308 yylval.ssym.sym = result;
1993b719 1309 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
c906108c
SS
1310 return NAME_OR_INT;
1311 }
1312 }
1313
1314 /* Any other kind of symbol */
d12307c1 1315 yylval.ssym.sym = result;
1993b719 1316 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
c906108c
SS
1317 return NAME;
1318 }
1319}
1320
410a0ff2
SDJ
1321int
1322f_parse (struct parser_state *par_state)
1323{
410a0ff2 1324 /* Setting up the parser state. */
eae49211 1325 scoped_restore pstate_restore = make_scoped_restore (&pstate);
e454224f
AB
1326 scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
1327 parser_debug);
410a0ff2
SDJ
1328 gdb_assert (par_state != NULL);
1329 pstate = par_state;
1330
eae49211 1331 return yyparse ();
410a0ff2
SDJ
1332}
1333
69d340c6 1334static void
a121b7c1 1335yyerror (const char *msg)
c906108c 1336{
065432a8
PM
1337 if (prev_lexptr)
1338 lexptr = prev_lexptr;
1339
69d340c6 1340 error (_("A %s in expression, near `%s'."), msg, lexptr);
c906108c 1341}
This page took 1.726452 seconds and 4 git commands to generate.