[gdb] Fix stepping over fork with follow-fork-mode child and gcc-8
[deliverable/binutils-gdb.git] / gdb / c-exp.y
CommitLineData
c906108c 1/* YACC parser for C expressions, for GDB.
b811d2c2 2 Copyright (C) 1986-2020 Free Software Foundation, Inc.
c906108c 3
5b1ba0e5 4 This file is part of GDB.
c906108c 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.
c906108c 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.
c906108c 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/>. */
c906108c
SS
18
19/* Parse a C 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 Note that 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. */
4d29c0a8 35
c906108c
SS
36%{
37
38#include "defs.h"
c906108c
SS
39#include <ctype.h>
40#include "expression.h"
41#include "value.h"
42#include "parser-defs.h"
43#include "language.h"
44#include "c-lang.h"
b1b60145 45#include "c-support.h"
c906108c
SS
46#include "bfd.h" /* Required by objfiles.h. */
47#include "symfile.h" /* Required by objfiles.h. */
48#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
234b45d4 49#include "charset.h"
fe898f56 50#include "block.h"
79c2c32d 51#include "cp-support.h"
7c8adf68 52#include "macroscope.h"
f2e8016f 53#include "objc-lang.h"
79d43c61 54#include "typeprint.h"
6592e36f 55#include "cp-abi.h"
dac43e32 56#include "type-stack.h"
fa649bb7 57#include "target-float.h"
c906108c 58
fa9f5be6 59#define parse_type(ps) builtin_type (ps->gdbarch ())
3e79cecf 60
b3f11165
PA
61/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
62 etc). */
63#define GDB_YY_REMAP_PREFIX c_
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
02e12e38
TT
71/* Data that must be held for the duration of a parse. */
72
73struct c_parse_state
74{
75 /* These are used to hold type lists and type stacks that are
76 allocated during the parse. */
77 std::vector<std::unique_ptr<std::vector<struct type *>>> type_lists;
78 std::vector<std::unique_ptr<struct type_stack>> type_stacks;
c65bac38
TT
79
80 /* Storage for some strings allocated during the parse. */
81 std::vector<gdb::unique_xmalloc_ptr<char>> strings;
9d30e1fd
TT
82
83 /* When we find that lexptr (the global var defined in parse.c) is
84 pointing at a macro invocation, we expand the invocation, and call
85 scan_macro_expansion to save the old lexptr here and point lexptr
86 into the expanded text. When we reach the end of that, we call
87 end_macro_expansion to pop back to the value we saved here. The
88 macro expansion code promises to return only fully-expanded text,
89 so we don't need to "push" more than one level.
90
91 This is disgusting, of course. It would be cleaner to do all macro
92 expansion beforehand, and then hand that to lexptr. But we don't
93 really know where the expression ends. Remember, in a command like
94
95 (gdb) break *ADDRESS if CONDITION
96
97 we evaluate ADDRESS in the scope of the current frame, but we
98 evaluate CONDITION in the scope of the breakpoint's location. So
99 it's simply wrong to try to macro-expand the whole thing at once. */
100 const char *macro_original_text = nullptr;
101
102 /* We save all intermediate macro expansions on this obstack for the
103 duration of a single parse. The expansion text may sometimes have
104 to live past the end of the expansion, due to yacc lookahead.
105 Rather than try to be clever about saving the data for a single
106 token, we simply keep it all and delete it after parsing has
107 completed. */
108 auto_obstack expansion_obstack;
dac43e32
TT
109
110 /* The type stack. */
111 struct type_stack type_stack;
02e12e38
TT
112};
113
114/* This is set and cleared in c_parse. */
115
116static struct c_parse_state *cpstate;
117
a14ed312 118int yyparse (void);
c906108c 119
a14ed312 120static int yylex (void);
c906108c 121
69d340c6 122static void yyerror (const char *);
c906108c 123
3d567982
TT
124static int type_aggregate_p (struct type *);
125
c906108c
SS
126%}
127
128/* Although the yacc "value" of an expression is not used,
129 since the result is stored in the structure being created,
130 other node types do have values. */
131
132%union
133 {
134 LONGEST lval;
135 struct {
136 LONGEST val;
137 struct type *type;
138 } typed_val_int;
27bc4d80
TJB
139 struct {
140 gdb_byte val[16];
141 struct type *type;
edd079d9 142 } typed_val_float;
c906108c
SS
143 struct type *tval;
144 struct stoken sval;
6c7a06a3 145 struct typed_stoken tsval;
c906108c
SS
146 struct ttype tsym;
147 struct symtoken ssym;
148 int voidval;
3977b71f 149 const struct block *bval;
c906108c 150 enum exp_opcode opcode;
c906108c 151
6c7a06a3 152 struct stoken_vector svec;
02e12e38 153 std::vector<struct type *> *tvec;
fcde5961
TT
154
155 struct type_stack *type_stack;
f2e8016f 156
fe978cb0 157 struct objc_class_str theclass;
c906108c
SS
158 }
159
160%{
161/* YYSTYPE gets defined by %union */
410a0ff2
SDJ
162static int parse_number (struct parser_state *par_state,
163 const char *, int, int, YYSTYPE *);
66c53f2b 164static struct stoken operator_stoken (const char *);
6f0ffe50 165static struct stoken typename_stoken (const char *);
02e12e38 166static void check_parameter_typelist (std::vector<struct type *> *);
410a0ff2
SDJ
167static void write_destructor_name (struct parser_state *par_state,
168 struct stoken);
9507860e 169
12c5175d 170#ifdef YYBISON
9507860e
TT
171static void c_print_token (FILE *file, int type, YYSTYPE value);
172#define YYPRINT(FILE, TYPE, VALUE) c_print_token (FILE, TYPE, VALUE)
12c5175d 173#endif
c906108c
SS
174%}
175
858be34c 176%type <voidval> exp exp1 type_exp start variable qualified_name lcurly function_method
c906108c 177%type <lval> rcurly
3638a098 178%type <tval> type typebase scalar_type
a6fb9c08 179%type <tvec> nonempty_typelist func_mod parameter_typelist
c906108c
SS
180/* %type <bval> block */
181
182/* Fancy type parsing. */
c906108c
SS
183%type <tval> ptype
184%type <lval> array_mod
95c391b6 185%type <tval> conversion_type_id
c906108c 186
fcde5961
TT
187%type <type_stack> ptr_operator_ts abs_decl direct_abs_decl
188
fa649bb7
TT
189%token <typed_val_int> INT COMPLEX_INT
190%token <typed_val_float> FLOAT COMPLEX_FLOAT
c906108c
SS
191
192/* Both NAME and TYPENAME tokens represent symbols in the input,
193 and both convey their data as strings.
194 But a TYPENAME is a string that happens to be defined as a typedef
195 or builtin type name (such as int or char)
196 and a NAME is any other symbol.
197 Contexts where this distinction is not important can use the
198 nonterminal "name", which matches either NAME or TYPENAME. */
199
6c7a06a3 200%token <tsval> STRING
f2e8016f
TT
201%token <sval> NSSTRING /* ObjC Foundation "NSString" literal */
202%token SELECTOR /* ObjC "@selector" pseudo-operator */
6c7a06a3 203%token <tsval> CHAR
c906108c 204%token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
7322dca9 205%token <ssym> UNKNOWN_CPP_NAME
65d12d83 206%token <voidval> COMPLETE
c906108c 207%token <tsym> TYPENAME
fe978cb0 208%token <theclass> CLASSNAME /* ObjC Class name */
0f5d3f63 209%type <sval> name field_name
6c7a06a3 210%type <svec> string_exp
c906108c 211%type <ssym> name_not_typename
fe978cb0 212%type <tsym> type_name
c906108c 213
f2e8016f
TT
214 /* This is like a '[' token, but is only generated when parsing
215 Objective C. This lets us reuse the same parser without
216 erroneously parsing ObjC-specific expressions in C. */
217%token OBJC_LBRAC
218
c906108c
SS
219/* A NAME_OR_INT is a symbol which is not known in the symbol table,
220 but which would parse as a valid number in the current input radix.
221 E.g. "c" when input_radix==16. Depending on the parse, it will be
222 turned into a name or into a number. */
223
4d29c0a8 224%token <ssym> NAME_OR_INT
c906108c 225
66c53f2b 226%token OPERATOR
007e1530 227%token STRUCT CLASS UNION ENUM SIZEOF ALIGNOF UNSIGNED COLONCOLON
c906108c
SS
228%token TEMPLATE
229%token ERROR
66c53f2b 230%token NEW DELETE
fe978cb0 231%type <sval> oper
4e8f195d 232%token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
941b2081 233%token ENTRY
608b4967
TT
234%token TYPEOF
235%token DECLTYPE
6e72ca20 236%token TYPEID
c906108c
SS
237
238/* Special type cases, put in to allow the parser to distinguish different
239 legal basetypes. */
240%token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
3293bbaf 241%token RESTRICT ATOMIC
3638a098 242%token FLOAT_KEYWORD COMPLEX
c906108c 243
cfeadda5 244%token <sval> DOLLAR_VARIABLE
c906108c
SS
245
246%token <opcode> ASSIGN_MODIFY
247
248/* C++ */
c906108c
SS
249%token TRUEKEYWORD
250%token FALSEKEYWORD
251
252
253%left ','
254%left ABOVE_COMMA
255%right '=' ASSIGN_MODIFY
256%right '?'
257%left OROR
258%left ANDAND
259%left '|'
260%left '^'
261%left '&'
262%left EQUAL NOTEQUAL
263%left '<' '>' LEQ GEQ
264%left LSH RSH
265%left '@'
266%left '+' '-'
267%left '*' '/' '%'
268%right UNARY INCREMENT DECREMENT
f2e8016f 269%right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '('
4d29c0a8 270%token <ssym> BLOCKNAME
c906108c
SS
271%token <bval> FILENAME
272%type <bval> block
273%left COLONCOLON
274
a6fb9c08
TT
275%token DOTDOTDOT
276
c906108c
SS
277\f
278%%
279
280start : exp1
281 | type_exp
282 ;
283
284type_exp: type
410a0ff2
SDJ
285 { write_exp_elt_opcode(pstate, OP_TYPE);
286 write_exp_elt_type(pstate, $1);
287 write_exp_elt_opcode(pstate, OP_TYPE);}
608b4967
TT
288 | TYPEOF '(' exp ')'
289 {
410a0ff2 290 write_exp_elt_opcode (pstate, OP_TYPEOF);
608b4967
TT
291 }
292 | TYPEOF '(' type ')'
293 {
410a0ff2
SDJ
294 write_exp_elt_opcode (pstate, OP_TYPE);
295 write_exp_elt_type (pstate, $3);
296 write_exp_elt_opcode (pstate, OP_TYPE);
608b4967
TT
297 }
298 | DECLTYPE '(' exp ')'
299 {
410a0ff2 300 write_exp_elt_opcode (pstate, OP_DECLTYPE);
608b4967 301 }
c906108c
SS
302 ;
303
304/* Expressions, including the comma operator. */
305exp1 : exp
306 | exp1 ',' exp
410a0ff2 307 { write_exp_elt_opcode (pstate, BINOP_COMMA); }
c906108c
SS
308 ;
309
310/* Expressions, not including the comma operator. */
311exp : '*' exp %prec UNARY
410a0ff2 312 { write_exp_elt_opcode (pstate, UNOP_IND); }
ef944135 313 ;
c906108c
SS
314
315exp : '&' exp %prec UNARY
410a0ff2 316 { write_exp_elt_opcode (pstate, UNOP_ADDR); }
ef944135 317 ;
c906108c
SS
318
319exp : '-' exp %prec UNARY
410a0ff2 320 { write_exp_elt_opcode (pstate, UNOP_NEG); }
c906108c
SS
321 ;
322
36e9969c 323exp : '+' exp %prec UNARY
410a0ff2 324 { write_exp_elt_opcode (pstate, UNOP_PLUS); }
36e9969c
NS
325 ;
326
c906108c 327exp : '!' exp %prec UNARY
410a0ff2 328 { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
c906108c
SS
329 ;
330
331exp : '~' exp %prec UNARY
410a0ff2 332 { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
c906108c
SS
333 ;
334
335exp : INCREMENT exp %prec UNARY
410a0ff2 336 { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); }
c906108c
SS
337 ;
338
339exp : DECREMENT exp %prec UNARY
410a0ff2 340 { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); }
c906108c
SS
341 ;
342
343exp : exp INCREMENT %prec UNARY
410a0ff2 344 { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
c906108c
SS
345 ;
346
347exp : exp DECREMENT %prec UNARY
410a0ff2 348 { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
c906108c
SS
349 ;
350
6e72ca20 351exp : TYPEID '(' exp ')' %prec UNARY
410a0ff2 352 { write_exp_elt_opcode (pstate, OP_TYPEID); }
6e72ca20
TT
353 ;
354
355exp : TYPEID '(' type_exp ')' %prec UNARY
410a0ff2 356 { write_exp_elt_opcode (pstate, OP_TYPEID); }
6e72ca20
TT
357 ;
358
c906108c 359exp : SIZEOF exp %prec UNARY
410a0ff2 360 { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
c906108c
SS
361 ;
362
007e1530
TT
363exp : ALIGNOF '(' type_exp ')' %prec UNARY
364 { write_exp_elt_opcode (pstate, UNOP_ALIGNOF); }
365 ;
366
0f5d3f63 367exp : exp ARROW field_name
410a0ff2
SDJ
368 { write_exp_elt_opcode (pstate, STRUCTOP_PTR);
369 write_exp_string (pstate, $3);
370 write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
c906108c
SS
371 ;
372
0f5d3f63 373exp : exp ARROW field_name COMPLETE
2a612529 374 { pstate->mark_struct_expression ();
410a0ff2
SDJ
375 write_exp_elt_opcode (pstate, STRUCTOP_PTR);
376 write_exp_string (pstate, $3);
377 write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
65d12d83
TT
378 ;
379
380exp : exp ARROW COMPLETE
381 { struct stoken s;
2a612529 382 pstate->mark_struct_expression ();
410a0ff2 383 write_exp_elt_opcode (pstate, STRUCTOP_PTR);
65d12d83
TT
384 s.ptr = "";
385 s.length = 0;
410a0ff2
SDJ
386 write_exp_string (pstate, s);
387 write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
65d12d83
TT
388 ;
389
24955f63 390exp : exp ARROW '~' name
410a0ff2
SDJ
391 { write_exp_elt_opcode (pstate, STRUCTOP_PTR);
392 write_destructor_name (pstate, $4);
393 write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
24955f63
TT
394 ;
395
396exp : exp ARROW '~' name COMPLETE
2a612529 397 { pstate->mark_struct_expression ();
410a0ff2
SDJ
398 write_exp_elt_opcode (pstate, STRUCTOP_PTR);
399 write_destructor_name (pstate, $4);
400 write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
24955f63
TT
401 ;
402
c906108c
SS
403exp : exp ARROW qualified_name
404 { /* exp->type::name becomes exp->*(&type::name) */
405 /* Note: this doesn't work if name is a
406 static member! FIXME */
410a0ff2
SDJ
407 write_exp_elt_opcode (pstate, UNOP_ADDR);
408 write_exp_elt_opcode (pstate, STRUCTOP_MPTR); }
c906108c
SS
409 ;
410
c1af96a0 411exp : exp ARROW_STAR exp
410a0ff2 412 { write_exp_elt_opcode (pstate, STRUCTOP_MPTR); }
c906108c
SS
413 ;
414
0f5d3f63 415exp : exp '.' field_name
410a0ff2
SDJ
416 { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
417 write_exp_string (pstate, $3);
418 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
c906108c
SS
419 ;
420
0f5d3f63 421exp : exp '.' field_name COMPLETE
2a612529 422 { pstate->mark_struct_expression ();
410a0ff2
SDJ
423 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
424 write_exp_string (pstate, $3);
425 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
65d12d83
TT
426 ;
427
428exp : exp '.' COMPLETE
429 { struct stoken s;
2a612529 430 pstate->mark_struct_expression ();
410a0ff2 431 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
65d12d83
TT
432 s.ptr = "";
433 s.length = 0;
410a0ff2
SDJ
434 write_exp_string (pstate, s);
435 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
65d12d83
TT
436 ;
437
24955f63 438exp : exp '.' '~' name
410a0ff2
SDJ
439 { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
440 write_destructor_name (pstate, $4);
441 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
24955f63
TT
442 ;
443
444exp : exp '.' '~' name COMPLETE
2a612529 445 { pstate->mark_struct_expression ();
410a0ff2
SDJ
446 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
447 write_destructor_name (pstate, $4);
448 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
24955f63
TT
449 ;
450
c906108c
SS
451exp : exp '.' qualified_name
452 { /* exp.type::name becomes exp.*(&type::name) */
453 /* Note: this doesn't work if name is a
454 static member! FIXME */
410a0ff2
SDJ
455 write_exp_elt_opcode (pstate, UNOP_ADDR);
456 write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
c906108c
SS
457 ;
458
c1af96a0 459exp : exp DOT_STAR exp
410a0ff2 460 { write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
c906108c
SS
461 ;
462
463exp : exp '[' exp1 ']'
410a0ff2 464 { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
c906108c
SS
465 ;
466
f2e8016f 467exp : exp OBJC_LBRAC exp1 ']'
410a0ff2 468 { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
f2e8016f
TT
469 ;
470
471/*
472 * The rules below parse ObjC message calls of the form:
473 * '[' target selector {':' argument}* ']'
474 */
475
476exp : OBJC_LBRAC TYPENAME
477 {
fe978cb0 478 CORE_ADDR theclass;
f2e8016f 479
61f4b350 480 std::string copy = copy_name ($2.stoken);
fa9f5be6 481 theclass = lookup_objc_class (pstate->gdbarch (),
61f4b350 482 copy.c_str ());
fe978cb0 483 if (theclass == 0)
f2e8016f 484 error (_("%s is not an ObjC Class"),
61f4b350 485 copy.c_str ());
410a0ff2
SDJ
486 write_exp_elt_opcode (pstate, OP_LONG);
487 write_exp_elt_type (pstate,
61f4b350 488 parse_type (pstate)->builtin_int);
fe978cb0 489 write_exp_elt_longcst (pstate, (LONGEST) theclass);
410a0ff2 490 write_exp_elt_opcode (pstate, OP_LONG);
f2e8016f
TT
491 start_msglist();
492 }
493 msglist ']'
410a0ff2
SDJ
494 { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
495 end_msglist (pstate);
496 write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
f2e8016f
TT
497 }
498 ;
499
500exp : OBJC_LBRAC CLASSNAME
501 {
410a0ff2
SDJ
502 write_exp_elt_opcode (pstate, OP_LONG);
503 write_exp_elt_type (pstate,
504 parse_type (pstate)->builtin_int);
fe978cb0 505 write_exp_elt_longcst (pstate, (LONGEST) $2.theclass);
410a0ff2 506 write_exp_elt_opcode (pstate, OP_LONG);
f2e8016f
TT
507 start_msglist();
508 }
509 msglist ']'
410a0ff2
SDJ
510 { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
511 end_msglist (pstate);
512 write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
f2e8016f
TT
513 }
514 ;
515
516exp : OBJC_LBRAC exp
517 { start_msglist(); }
518 msglist ']'
410a0ff2
SDJ
519 { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
520 end_msglist (pstate);
521 write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
f2e8016f
TT
522 }
523 ;
524
525msglist : name
526 { add_msglist(&$1, 0); }
527 | msgarglist
528 ;
529
530msgarglist : msgarg
531 | msgarglist msgarg
532 ;
533
534msgarg : name ':' exp
535 { add_msglist(&$1, 1); }
536 | ':' exp /* Unnamed arg. */
537 { add_msglist(0, 1); }
538 | ',' exp /* Variable number of args. */
539 { add_msglist(0, 0); }
540 ;
541
4d29c0a8 542exp : exp '('
c906108c
SS
543 /* This is to save the value of arglist_len
544 being accumulated by an outer function call. */
43476f0b 545 { pstate->start_arglist (); }
c906108c 546 arglist ')' %prec ARROW
410a0ff2
SDJ
547 { write_exp_elt_opcode (pstate, OP_FUNCALL);
548 write_exp_elt_longcst (pstate,
43476f0b 549 pstate->end_arglist ());
410a0ff2 550 write_exp_elt_opcode (pstate, OP_FUNCALL); }
c906108c
SS
551 ;
552
858be34c
PA
553/* This is here to disambiguate with the production for
554 "func()::static_var" further below, which uses
555 function_method_void. */
556exp : exp '(' ')' %prec ARROW
43476f0b 557 { pstate->start_arglist ();
858be34c
PA
558 write_exp_elt_opcode (pstate, OP_FUNCALL);
559 write_exp_elt_longcst (pstate,
43476f0b 560 pstate->end_arglist ());
858be34c
PA
561 write_exp_elt_opcode (pstate, OP_FUNCALL); }
562 ;
563
564
941b2081 565exp : UNKNOWN_CPP_NAME '('
7322dca9
SW
566 {
567 /* This could potentially be a an argument defined
568 lookup function (Koenig). */
410a0ff2 569 write_exp_elt_opcode (pstate, OP_ADL_FUNC);
1e58a4a4
TT
570 write_exp_elt_block
571 (pstate, pstate->expression_context_block);
410a0ff2
SDJ
572 write_exp_elt_sym (pstate,
573 NULL); /* Placeholder. */
574 write_exp_string (pstate, $1.stoken);
575 write_exp_elt_opcode (pstate, OP_ADL_FUNC);
7322dca9
SW
576
577 /* This is to save the value of arglist_len
578 being accumulated by an outer function call. */
579
43476f0b 580 pstate->start_arglist ();
7322dca9
SW
581 }
582 arglist ')' %prec ARROW
583 {
410a0ff2
SDJ
584 write_exp_elt_opcode (pstate, OP_FUNCALL);
585 write_exp_elt_longcst (pstate,
43476f0b 586 pstate->end_arglist ());
410a0ff2 587 write_exp_elt_opcode (pstate, OP_FUNCALL);
7322dca9
SW
588 }
589 ;
590
c906108c 591lcurly : '{'
43476f0b 592 { pstate->start_arglist (); }
c906108c
SS
593 ;
594
595arglist :
596 ;
597
598arglist : exp
43476f0b 599 { pstate->arglist_len = 1; }
c906108c
SS
600 ;
601
602arglist : arglist ',' exp %prec ABOVE_COMMA
43476f0b 603 { pstate->arglist_len++; }
c906108c
SS
604 ;
605
858be34c 606function_method: exp '(' parameter_typelist ')' const_or_volatile
02e12e38
TT
607 {
608 std::vector<struct type *> *type_list = $3;
609 LONGEST len = type_list->size ();
71918a86 610
410a0ff2 611 write_exp_elt_opcode (pstate, TYPE_INSTANCE);
3693fdb3
PA
612 /* Save the const/volatile qualifiers as
613 recorded by the const_or_volatile
614 production's actions. */
dac43e32
TT
615 write_exp_elt_longcst
616 (pstate,
617 (cpstate->type_stack
618 .follow_type_instance_flags ()));
410a0ff2 619 write_exp_elt_longcst (pstate, len);
02e12e38 620 for (type *type_elt : *type_list)
410a0ff2
SDJ
621 write_exp_elt_type (pstate, type_elt);
622 write_exp_elt_longcst(pstate, len);
623 write_exp_elt_opcode (pstate, TYPE_INSTANCE);
072bba3b
KS
624 }
625 ;
626
858be34c
PA
627function_method_void: exp '(' ')' const_or_volatile
628 { write_exp_elt_opcode (pstate, TYPE_INSTANCE);
3693fdb3 629 /* See above. */
dac43e32
TT
630 write_exp_elt_longcst
631 (pstate,
632 cpstate->type_stack.follow_type_instance_flags ());
858be34c
PA
633 write_exp_elt_longcst (pstate, 0);
634 write_exp_elt_longcst (pstate, 0);
635 write_exp_elt_opcode (pstate, TYPE_INSTANCE);
636 }
637 ;
638
639exp : function_method
640 ;
641
642/* Normally we must interpret "func()" as a function call, instead of
643 a type. The user needs to write func(void) to disambiguate.
644 However, in the "func()::static_var" case, there's no
645 ambiguity. */
646function_method_void_or_typelist: function_method
647 | function_method_void
648 ;
649
650exp : function_method_void_or_typelist COLONCOLON name
651 {
652 write_exp_elt_opcode (pstate, OP_FUNC_STATIC_VAR);
653 write_exp_string (pstate, $3);
654 write_exp_elt_opcode (pstate, OP_FUNC_STATIC_VAR);
655 }
656 ;
657
c906108c 658rcurly : '}'
43476f0b 659 { $$ = pstate->end_arglist () - 1; }
c906108c
SS
660 ;
661exp : lcurly arglist rcurly %prec ARROW
410a0ff2
SDJ
662 { write_exp_elt_opcode (pstate, OP_ARRAY);
663 write_exp_elt_longcst (pstate, (LONGEST) 0);
664 write_exp_elt_longcst (pstate, (LONGEST) $3);
665 write_exp_elt_opcode (pstate, OP_ARRAY); }
c906108c
SS
666 ;
667
9eaf6705 668exp : lcurly type_exp rcurly exp %prec UNARY
410a0ff2 669 { write_exp_elt_opcode (pstate, UNOP_MEMVAL_TYPE); }
c906108c
SS
670 ;
671
9eaf6705 672exp : '(' type_exp ')' exp %prec UNARY
410a0ff2 673 { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); }
c906108c
SS
674 ;
675
676exp : '(' exp1 ')'
677 { }
678 ;
679
680/* Binary operators in order of decreasing precedence. */
681
682exp : exp '@' exp
410a0ff2 683 { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
c906108c
SS
684 ;
685
686exp : exp '*' exp
410a0ff2 687 { write_exp_elt_opcode (pstate, BINOP_MUL); }
c906108c
SS
688 ;
689
690exp : exp '/' exp
410a0ff2 691 { write_exp_elt_opcode (pstate, BINOP_DIV); }
c906108c
SS
692 ;
693
694exp : exp '%' exp
410a0ff2 695 { write_exp_elt_opcode (pstate, BINOP_REM); }
c906108c
SS
696 ;
697
698exp : exp '+' exp
410a0ff2 699 { write_exp_elt_opcode (pstate, BINOP_ADD); }
c906108c
SS
700 ;
701
702exp : exp '-' exp
410a0ff2 703 { write_exp_elt_opcode (pstate, BINOP_SUB); }
c906108c
SS
704 ;
705
706exp : exp LSH exp
410a0ff2 707 { write_exp_elt_opcode (pstate, BINOP_LSH); }
c906108c
SS
708 ;
709
710exp : exp RSH exp
410a0ff2 711 { write_exp_elt_opcode (pstate, BINOP_RSH); }
c906108c
SS
712 ;
713
714exp : exp EQUAL exp
410a0ff2 715 { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
c906108c
SS
716 ;
717
718exp : exp NOTEQUAL exp
410a0ff2 719 { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
c906108c
SS
720 ;
721
722exp : exp LEQ exp
410a0ff2 723 { write_exp_elt_opcode (pstate, BINOP_LEQ); }
c906108c
SS
724 ;
725
726exp : exp GEQ exp
410a0ff2 727 { write_exp_elt_opcode (pstate, BINOP_GEQ); }
c906108c
SS
728 ;
729
730exp : exp '<' exp
410a0ff2 731 { write_exp_elt_opcode (pstate, BINOP_LESS); }
c906108c
SS
732 ;
733
734exp : exp '>' exp
410a0ff2 735 { write_exp_elt_opcode (pstate, BINOP_GTR); }
c906108c
SS
736 ;
737
738exp : exp '&' exp
410a0ff2 739 { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
c906108c
SS
740 ;
741
742exp : exp '^' exp
410a0ff2 743 { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
c906108c
SS
744 ;
745
746exp : exp '|' exp
410a0ff2 747 { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
c906108c
SS
748 ;
749
750exp : exp ANDAND exp
410a0ff2 751 { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
c906108c
SS
752 ;
753
754exp : exp OROR exp
410a0ff2 755 { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
c906108c
SS
756 ;
757
758exp : exp '?' exp ':' exp %prec '?'
410a0ff2 759 { write_exp_elt_opcode (pstate, TERNOP_COND); }
c906108c 760 ;
4d29c0a8 761
c906108c 762exp : exp '=' exp
410a0ff2 763 { write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
c906108c
SS
764 ;
765
766exp : exp ASSIGN_MODIFY exp
410a0ff2
SDJ
767 { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY);
768 write_exp_elt_opcode (pstate, $2);
769 write_exp_elt_opcode (pstate,
770 BINOP_ASSIGN_MODIFY); }
c906108c
SS
771 ;
772
773exp : INT
410a0ff2
SDJ
774 { write_exp_elt_opcode (pstate, OP_LONG);
775 write_exp_elt_type (pstate, $1.type);
776 write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
777 write_exp_elt_opcode (pstate, OP_LONG); }
c906108c
SS
778 ;
779
fa649bb7
TT
780exp : COMPLEX_INT
781 {
782 write_exp_elt_opcode (pstate, OP_LONG);
783 write_exp_elt_type (pstate, TYPE_TARGET_TYPE ($1.type));
784 write_exp_elt_longcst (pstate, 0);
785 write_exp_elt_opcode (pstate, OP_LONG);
786 write_exp_elt_opcode (pstate, OP_LONG);
787 write_exp_elt_type (pstate, TYPE_TARGET_TYPE ($1.type));
788 write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
789 write_exp_elt_opcode (pstate, OP_LONG);
790 write_exp_elt_opcode (pstate, OP_COMPLEX);
791 write_exp_elt_type (pstate, $1.type);
792 write_exp_elt_opcode (pstate, OP_COMPLEX);
793 }
794 ;
795
6c7a06a3
TT
796exp : CHAR
797 {
798 struct stoken_vector vec;
799 vec.len = 1;
800 vec.tokens = &$1;
410a0ff2 801 write_exp_string_vector (pstate, $1.type, &vec);
6c7a06a3
TT
802 }
803 ;
804
c906108c
SS
805exp : NAME_OR_INT
806 { YYSTYPE val;
410a0ff2
SDJ
807 parse_number (pstate, $1.stoken.ptr,
808 $1.stoken.length, 0, &val);
809 write_exp_elt_opcode (pstate, OP_LONG);
810 write_exp_elt_type (pstate, val.typed_val_int.type);
811 write_exp_elt_longcst (pstate,
812 (LONGEST) val.typed_val_int.val);
813 write_exp_elt_opcode (pstate, OP_LONG);
c906108c
SS
814 }
815 ;
816
817
818exp : FLOAT
edd079d9 819 { write_exp_elt_opcode (pstate, OP_FLOAT);
410a0ff2 820 write_exp_elt_type (pstate, $1.type);
edd079d9
UW
821 write_exp_elt_floatcst (pstate, $1.val);
822 write_exp_elt_opcode (pstate, OP_FLOAT); }
27bc4d80
TJB
823 ;
824
fa649bb7
TT
825exp : COMPLEX_FLOAT
826 {
827 struct type *underlying
828 = TYPE_TARGET_TYPE ($1.type);
829
830 write_exp_elt_opcode (pstate, OP_FLOAT);
831 write_exp_elt_type (pstate, underlying);
832 gdb_byte val[16];
833 target_float_from_host_double (val, underlying, 0);
834 write_exp_elt_floatcst (pstate, val);
835 write_exp_elt_opcode (pstate, OP_FLOAT);
836 write_exp_elt_opcode (pstate, OP_FLOAT);
837 write_exp_elt_type (pstate, underlying);
838 write_exp_elt_floatcst (pstate, $1.val);
839 write_exp_elt_opcode (pstate, OP_FLOAT);
840 write_exp_elt_opcode (pstate, OP_COMPLEX);
841 write_exp_elt_type (pstate, $1.type);
842 write_exp_elt_opcode (pstate, OP_COMPLEX);
843 }
844 ;
845
c906108c
SS
846exp : variable
847 ;
848
cfeadda5 849exp : DOLLAR_VARIABLE
48e32051 850 {
410a0ff2 851 write_dollar_variable (pstate, $1);
48e32051 852 }
c906108c
SS
853 ;
854
f2e8016f
TT
855exp : SELECTOR '(' name ')'
856 {
410a0ff2
SDJ
857 write_exp_elt_opcode (pstate, OP_OBJC_SELECTOR);
858 write_exp_string (pstate, $3);
859 write_exp_elt_opcode (pstate, OP_OBJC_SELECTOR); }
f2e8016f
TT
860 ;
861
c906108c 862exp : SIZEOF '(' type ')' %prec UNARY
245a5f0b
KS
863 { struct type *type = $3;
864 write_exp_elt_opcode (pstate, OP_LONG);
410a0ff2 865 write_exp_elt_type (pstate, lookup_signed_typename
73923d7e 866 (pstate->language (),
f4b8a18d 867 "int"));
f168693b 868 type = check_typedef (type);
245a5f0b
KS
869
870 /* $5.3.3/2 of the C++ Standard (n3290 draft)
871 says of sizeof: "When applied to a reference
872 or a reference type, the result is the size of
873 the referenced type." */
53cc15f5 874 if (TYPE_IS_REFERENCE (type))
245a5f0b 875 type = check_typedef (TYPE_TARGET_TYPE (type));
410a0ff2 876 write_exp_elt_longcst (pstate,
245a5f0b 877 (LONGEST) TYPE_LENGTH (type));
410a0ff2 878 write_exp_elt_opcode (pstate, OP_LONG); }
c906108c
SS
879 ;
880
9eaf6705 881exp : REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
410a0ff2
SDJ
882 { write_exp_elt_opcode (pstate,
883 UNOP_REINTERPRET_CAST); }
4e8f195d
TT
884 ;
885
9eaf6705 886exp : STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
410a0ff2 887 { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); }
4e8f195d
TT
888 ;
889
9eaf6705 890exp : DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
410a0ff2 891 { write_exp_elt_opcode (pstate, UNOP_DYNAMIC_CAST); }
4e8f195d
TT
892 ;
893
9eaf6705 894exp : CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
4e8f195d
TT
895 { /* We could do more error checking here, but
896 it doesn't seem worthwhile. */
410a0ff2 897 write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); }
4e8f195d
TT
898 ;
899
c209f847
TT
900string_exp:
901 STRING
902 {
903 /* We copy the string here, and not in the
904 lexer, to guarantee that we do not leak a
905 string. Note that we follow the
906 NUL-termination convention of the
907 lexer. */
6c7a06a3
TT
908 struct typed_stoken *vec = XNEW (struct typed_stoken);
909 $$.len = 1;
910 $$.tokens = vec;
911
912 vec->type = $1.type;
913 vec->length = $1.length;
224c3ddb 914 vec->ptr = (char *) malloc ($1.length + 1);
6c7a06a3 915 memcpy (vec->ptr, $1.ptr, $1.length + 1);
c209f847
TT
916 }
917
918 | string_exp STRING
919 {
920 /* Note that we NUL-terminate here, but just
921 for convenience. */
6c7a06a3
TT
922 char *p;
923 ++$$.len;
224c3ddb
SM
924 $$.tokens = XRESIZEVEC (struct typed_stoken,
925 $$.tokens, $$.len);
6c7a06a3 926
224c3ddb 927 p = (char *) malloc ($2.length + 1);
6c7a06a3
TT
928 memcpy (p, $2.ptr, $2.length + 1);
929
930 $$.tokens[$$.len - 1].type = $2.type;
931 $$.tokens[$$.len - 1].length = $2.length;
932 $$.tokens[$$.len - 1].ptr = p;
c209f847
TT
933 }
934 ;
935
936exp : string_exp
6c7a06a3
TT
937 {
938 int i;
0c801b96 939 c_string_type type = C_STRING;
6c7a06a3
TT
940
941 for (i = 0; i < $1.len; ++i)
c906108c 942 {
6c7a06a3
TT
943 switch ($1.tokens[i].type)
944 {
945 case C_STRING:
946 break;
947 case C_WIDE_STRING:
948 case C_STRING_16:
949 case C_STRING_32:
950 if (type != C_STRING
951 && type != $1.tokens[i].type)
001083c6 952 error (_("Undefined string concatenation."));
0c801b96 953 type = (enum c_string_type_values) $1.tokens[i].type;
6c7a06a3
TT
954 break;
955 default:
956 /* internal error */
957 internal_error (__FILE__, __LINE__,
958 "unrecognized type in string concatenation");
959 }
c906108c 960 }
6c7a06a3 961
410a0ff2 962 write_exp_string_vector (pstate, type, &$1);
6c7a06a3
TT
963 for (i = 0; i < $1.len; ++i)
964 free ($1.tokens[i].ptr);
965 free ($1.tokens);
c209f847 966 }
c906108c
SS
967 ;
968
f2e8016f
TT
969exp : NSSTRING /* ObjC NextStep NSString constant
970 * of the form '@' '"' string '"'.
971 */
410a0ff2
SDJ
972 { write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING);
973 write_exp_string (pstate, $1);
974 write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING); }
f2e8016f
TT
975 ;
976
c906108c 977/* C++. */
4d29c0a8 978exp : TRUEKEYWORD
410a0ff2
SDJ
979 { write_exp_elt_opcode (pstate, OP_LONG);
980 write_exp_elt_type (pstate,
981 parse_type (pstate)->builtin_bool);
982 write_exp_elt_longcst (pstate, (LONGEST) 1);
983 write_exp_elt_opcode (pstate, OP_LONG); }
c906108c
SS
984 ;
985
4d29c0a8 986exp : FALSEKEYWORD
410a0ff2
SDJ
987 { write_exp_elt_opcode (pstate, OP_LONG);
988 write_exp_elt_type (pstate,
989 parse_type (pstate)->builtin_bool);
990 write_exp_elt_longcst (pstate, (LONGEST) 0);
991 write_exp_elt_opcode (pstate, OP_LONG); }
c906108c
SS
992 ;
993
994/* end of C++. */
995
996block : BLOCKNAME
997 {
d12307c1
PMR
998 if ($1.sym.symbol)
999 $$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol);
c906108c 1000 else
001083c6 1001 error (_("No file or function \"%s\"."),
61f4b350 1002 copy_name ($1.stoken).c_str ());
c906108c
SS
1003 }
1004 | FILENAME
1005 {
1006 $$ = $1;
1007 }
1008 ;
1009
1010block : block COLONCOLON name
61f4b350
TT
1011 {
1012 std::string copy = copy_name ($3);
1013 struct symbol *tem
1014 = lookup_symbol (copy.c_str (), $1,
d12307c1
PMR
1015 VAR_DOMAIN, NULL).symbol;
1016
c906108c 1017 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
001083c6 1018 error (_("No function \"%s\" in specified context."),
61f4b350 1019 copy.c_str ());
c906108c
SS
1020 $$ = SYMBOL_BLOCK_VALUE (tem); }
1021 ;
1022
941b2081 1023variable: name_not_typename ENTRY
d12307c1 1024 { struct symbol *sym = $1.sym.symbol;
36b11add
JK
1025
1026 if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
1027 || !symbol_read_needs_frame (sym))
1028 error (_("@entry can be used only for function "
1029 "parameters, not for \"%s\""),
61f4b350 1030 copy_name ($1.stoken).c_str ());
36b11add 1031
410a0ff2
SDJ
1032 write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
1033 write_exp_elt_sym (pstate, sym);
1034 write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
36b11add
JK
1035 }
1036 ;
1037
c906108c 1038variable: block COLONCOLON name
61f4b350
TT
1039 {
1040 std::string copy = copy_name ($3);
1041 struct block_symbol sym
1042 = lookup_symbol (copy.c_str (), $1,
d12307c1
PMR
1043 VAR_DOMAIN, NULL);
1044
1045 if (sym.symbol == 0)
001083c6 1046 error (_("No symbol \"%s\" in specified context."),
61f4b350 1047 copy.c_str ());
d12307c1 1048 if (symbol_read_needs_frame (sym.symbol))
699bd4cf 1049 pstate->block_tracker->update (sym);
c906108c 1050
410a0ff2 1051 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
d12307c1
PMR
1052 write_exp_elt_block (pstate, sym.block);
1053 write_exp_elt_sym (pstate, sym.symbol);
410a0ff2 1054 write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
c906108c
SS
1055 ;
1056
48e32051 1057qualified_name: TYPENAME COLONCOLON name
c906108c 1058 {
48e32051 1059 struct type *type = $1.type;
f168693b 1060 type = check_typedef (type);
3d567982 1061 if (!type_aggregate_p (type))
001083c6 1062 error (_("`%s' is not defined as an aggregate type."),
7fc75ca7 1063 TYPE_SAFE_NAME (type));
c906108c 1064
410a0ff2
SDJ
1065 write_exp_elt_opcode (pstate, OP_SCOPE);
1066 write_exp_elt_type (pstate, type);
1067 write_exp_string (pstate, $3);
1068 write_exp_elt_opcode (pstate, OP_SCOPE);
c906108c 1069 }
48e32051 1070 | TYPENAME COLONCOLON '~' name
c906108c 1071 {
48e32051 1072 struct type *type = $1.type;
c906108c 1073 struct stoken tmp_token;
d7561cbb
KS
1074 char *buf;
1075
f168693b 1076 type = check_typedef (type);
3d567982 1077 if (!type_aggregate_p (type))
001083c6 1078 error (_("`%s' is not defined as an aggregate type."),
7fc75ca7 1079 TYPE_SAFE_NAME (type));
224c3ddb 1080 buf = (char *) alloca ($4.length + 2);
d7561cbb 1081 tmp_token.ptr = buf;
c906108c 1082 tmp_token.length = $4.length + 1;
d7561cbb
KS
1083 buf[0] = '~';
1084 memcpy (buf+1, $4.ptr, $4.length);
1085 buf[tmp_token.length] = 0;
c906108c
SS
1086
1087 /* Check for valid destructor name. */
d8228535 1088 destructor_name_p (tmp_token.ptr, $1.type);
410a0ff2
SDJ
1089 write_exp_elt_opcode (pstate, OP_SCOPE);
1090 write_exp_elt_type (pstate, type);
1091 write_exp_string (pstate, tmp_token);
1092 write_exp_elt_opcode (pstate, OP_SCOPE);
c906108c 1093 }
48e32051
TT
1094 | TYPENAME COLONCOLON name COLONCOLON name
1095 {
61f4b350 1096 std::string copy = copy_name ($3);
48e32051
TT
1097 error (_("No type \"%s\" within class "
1098 "or namespace \"%s\"."),
61f4b350 1099 copy.c_str (), TYPE_SAFE_NAME ($1.type));
48e32051 1100 }
c906108c
SS
1101 ;
1102
1103variable: qualified_name
48e32051 1104 | COLONCOLON name_not_typename
c906108c 1105 {
61f4b350 1106 std::string name = copy_name ($2.stoken);
c906108c 1107 struct symbol *sym;
7c7b6655 1108 struct bound_minimal_symbol msymbol;
c906108c 1109
d12307c1 1110 sym
61f4b350
TT
1111 = lookup_symbol (name.c_str (),
1112 (const struct block *) NULL,
d12307c1 1113 VAR_DOMAIN, NULL).symbol;
c906108c
SS
1114 if (sym)
1115 {
410a0ff2
SDJ
1116 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
1117 write_exp_elt_block (pstate, NULL);
1118 write_exp_elt_sym (pstate, sym);
1119 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
c906108c
SS
1120 break;
1121 }
1122
61f4b350 1123 msymbol = lookup_bound_minimal_symbol (name.c_str ());
7c7b6655 1124 if (msymbol.minsym != NULL)
410a0ff2 1125 write_exp_msymbol (pstate, msymbol);
c841afd5 1126 else if (!have_full_symbols () && !have_partial_symbols ())
001083c6 1127 error (_("No symbol table is loaded. Use the \"file\" command."));
c906108c 1128 else
61f4b350
TT
1129 error (_("No symbol \"%s\" in current context."),
1130 name.c_str ());
c906108c
SS
1131 }
1132 ;
1133
1134variable: name_not_typename
d12307c1 1135 { struct block_symbol sym = $1.sym;
c906108c 1136
d12307c1 1137 if (sym.symbol)
c906108c 1138 {
d12307c1 1139 if (symbol_read_needs_frame (sym.symbol))
699bd4cf 1140 pstate->block_tracker->update (sym);
c906108c 1141
ca31ab1d
PA
1142 /* If we found a function, see if it's
1143 an ifunc resolver that has the same
1144 address as the ifunc symbol itself.
1145 If so, prefer the ifunc symbol. */
1146
1147 bound_minimal_symbol resolver
1148 = find_gnu_ifunc (sym.symbol);
1149 if (resolver.minsym != NULL)
1150 write_exp_msymbol (pstate, resolver);
1151 else
1152 {
1153 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
1154 write_exp_elt_block (pstate, sym.block);
1155 write_exp_elt_sym (pstate, sym.symbol);
1156 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
1157 }
c906108c
SS
1158 }
1159 else if ($1.is_a_field_of_this)
1160 {
1161 /* C++: it hangs off of `this'. Must
1162 not inadvertently convert from a method call
1163 to data ref. */
699bd4cf 1164 pstate->block_tracker->update (sym);
410a0ff2
SDJ
1165 write_exp_elt_opcode (pstate, OP_THIS);
1166 write_exp_elt_opcode (pstate, OP_THIS);
1167 write_exp_elt_opcode (pstate, STRUCTOP_PTR);
1168 write_exp_string (pstate, $1.stoken);
1169 write_exp_elt_opcode (pstate, STRUCTOP_PTR);
c906108c
SS
1170 }
1171 else
1172 {
61f4b350 1173 std::string arg = copy_name ($1.stoken);
c906108c 1174
bf223d3e 1175 bound_minimal_symbol msymbol
61f4b350 1176 = lookup_bound_minimal_symbol (arg.c_str ());
bf223d3e
PA
1177 if (msymbol.minsym == NULL)
1178 {
1179 if (!have_full_symbols () && !have_partial_symbols ())
1180 error (_("No symbol table is loaded. Use the \"file\" command."));
1181 else
1182 error (_("No symbol \"%s\" in current context."),
61f4b350 1183 arg.c_str ());
bf223d3e
PA
1184 }
1185
1186 /* This minsym might be an alias for
1187 another function. See if we can find
1188 the debug symbol for the target, and
1189 if so, use it instead, since it has
1190 return type / prototype info. This
1191 is important for example for "p
1192 *__errno_location()". */
1193 symbol *alias_target
f50776aa
PA
1194 = ((msymbol.minsym->type != mst_text_gnu_ifunc
1195 && msymbol.minsym->type != mst_data_gnu_ifunc)
a376e11d
PA
1196 ? find_function_alias_target (msymbol)
1197 : NULL);
bf223d3e
PA
1198 if (alias_target != NULL)
1199 {
1200 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
1201 write_exp_elt_block
1202 (pstate, SYMBOL_BLOCK_VALUE (alias_target));
1203 write_exp_elt_sym (pstate, alias_target);
1204 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
1205 }
c906108c 1206 else
bf223d3e 1207 write_exp_msymbol (pstate, msymbol);
c906108c
SS
1208 }
1209 }
1210 ;
1211
47663de5
MS
1212const_or_volatile: const_or_volatile_noopt
1213 |
c906108c 1214 ;
47663de5 1215
3293bbaf
TT
1216single_qualifier:
1217 CONST_KEYWORD
1218 { cpstate->type_stack.insert (tp_const); }
1219 | VOLATILE_KEYWORD
1220 { cpstate->type_stack.insert (tp_volatile); }
1221 | ATOMIC
1222 { cpstate->type_stack.insert (tp_atomic); }
1223 | RESTRICT
1224 { cpstate->type_stack.insert (tp_restrict); }
1225 | '@' NAME
1226 {
1227 cpstate->type_stack.insert (pstate,
1228 copy_name ($2.stoken).c_str ());
1229 }
56e2d25a 1230 ;
47663de5 1231
3293bbaf
TT
1232qualifier_seq_noopt:
1233 single_qualifier
1234 | qualifier_seq single_qualifier
56e2d25a 1235 ;
47663de5 1236
3293bbaf
TT
1237qualifier_seq:
1238 qualifier_seq_noopt
47663de5 1239 |
56e2d25a 1240 ;
47663de5 1241
95c391b6
TT
1242ptr_operator:
1243 ptr_operator '*'
dac43e32 1244 { cpstate->type_stack.insert (tp_pointer); }
3293bbaf 1245 qualifier_seq
4d29c0a8 1246 | '*'
dac43e32 1247 { cpstate->type_stack.insert (tp_pointer); }
3293bbaf 1248 qualifier_seq
c906108c 1249 | '&'
dac43e32 1250 { cpstate->type_stack.insert (tp_reference); }
95c391b6 1251 | '&' ptr_operator
dac43e32 1252 { cpstate->type_stack.insert (tp_reference); }
53cc15f5 1253 | ANDAND
dac43e32 1254 { cpstate->type_stack.insert (tp_rvalue_reference); }
53cc15f5 1255 | ANDAND ptr_operator
dac43e32 1256 { cpstate->type_stack.insert (tp_rvalue_reference); }
95c391b6
TT
1257 ;
1258
fcde5961
TT
1259ptr_operator_ts: ptr_operator
1260 {
dac43e32 1261 $$ = cpstate->type_stack.create ();
02e12e38 1262 cpstate->type_stacks.emplace_back ($$);
fcde5961
TT
1263 }
1264 ;
1265
1266abs_decl: ptr_operator_ts direct_abs_decl
dac43e32 1267 { $$ = $2->append ($1); }
4d29c0a8 1268 | ptr_operator_ts
c906108c
SS
1269 | direct_abs_decl
1270 ;
1271
1272direct_abs_decl: '(' abs_decl ')'
fcde5961 1273 { $$ = $2; }
c906108c
SS
1274 | direct_abs_decl array_mod
1275 {
dac43e32
TT
1276 cpstate->type_stack.push ($1);
1277 cpstate->type_stack.push ($2);
1278 cpstate->type_stack.push (tp_array);
1279 $$ = cpstate->type_stack.create ();
ab759ca8 1280 cpstate->type_stacks.emplace_back ($$);
c906108c
SS
1281 }
1282 | array_mod
1283 {
dac43e32
TT
1284 cpstate->type_stack.push ($1);
1285 cpstate->type_stack.push (tp_array);
1286 $$ = cpstate->type_stack.create ();
ab759ca8 1287 cpstate->type_stacks.emplace_back ($$);
c906108c
SS
1288 }
1289
1290 | direct_abs_decl func_mod
fcde5961 1291 {
dac43e32
TT
1292 cpstate->type_stack.push ($1);
1293 cpstate->type_stack.push ($2);
1294 $$ = cpstate->type_stack.create ();
ab759ca8 1295 cpstate->type_stacks.emplace_back ($$);
fcde5961 1296 }
c906108c 1297 | func_mod
fcde5961 1298 {
dac43e32
TT
1299 cpstate->type_stack.push ($1);
1300 $$ = cpstate->type_stack.create ();
ab759ca8 1301 cpstate->type_stacks.emplace_back ($$);
fcde5961 1302 }
c906108c
SS
1303 ;
1304
1305array_mod: '[' ']'
1306 { $$ = -1; }
f2e8016f
TT
1307 | OBJC_LBRAC ']'
1308 { $$ = -1; }
c906108c
SS
1309 | '[' INT ']'
1310 { $$ = $2.val; }
f2e8016f
TT
1311 | OBJC_LBRAC INT ']'
1312 { $$ = $2.val; }
c906108c
SS
1313 ;
1314
1315func_mod: '(' ')'
02e12e38
TT
1316 {
1317 $$ = new std::vector<struct type *>;
1318 cpstate->type_lists.emplace_back ($$);
1319 }
a6fb9c08 1320 | '(' parameter_typelist ')'
71918a86 1321 { $$ = $2; }
c906108c
SS
1322 ;
1323
a22229c4 1324/* We used to try to recognize pointer to member types here, but
c906108c
SS
1325 that didn't work (shift/reduce conflicts meant that these rules never
1326 got executed). The problem is that
1327 int (foo::bar::baz::bizzle)
1328 is a function type but
1329 int (foo::bar::baz::bizzle::*)
1330 is a pointer to member type. Stroustrup loses again! */
1331
1332type : ptype
c906108c
SS
1333 ;
1334
3638a098
TT
1335/* A helper production that recognizes scalar types that can validly
1336 be used with _Complex. */
b6c95c0c 1337
3638a098
TT
1338scalar_type:
1339 INT_KEYWORD
73923d7e 1340 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1341 "int"); }
c906108c 1342 | LONG
73923d7e 1343 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1344 "long"); }
c906108c 1345 | SHORT
73923d7e 1346 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1347 "short"); }
c906108c 1348 | LONG INT_KEYWORD
73923d7e 1349 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1350 "long"); }
b2c4da81 1351 | LONG SIGNED_KEYWORD INT_KEYWORD
73923d7e 1352 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1353 "long"); }
b2c4da81 1354 | LONG SIGNED_KEYWORD
73923d7e 1355 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1356 "long"); }
b2c4da81 1357 | SIGNED_KEYWORD LONG INT_KEYWORD
73923d7e 1358 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1359 "long"); }
c906108c 1360 | UNSIGNED LONG INT_KEYWORD
73923d7e 1361 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1362 "long"); }
b2c4da81 1363 | LONG UNSIGNED INT_KEYWORD
73923d7e 1364 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1365 "long"); }
b2c4da81 1366 | LONG UNSIGNED
73923d7e 1367 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1368 "long"); }
c906108c 1369 | LONG LONG
73923d7e 1370 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1371 "long long"); }
c906108c 1372 | LONG LONG INT_KEYWORD
73923d7e 1373 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1374 "long long"); }
b2c4da81 1375 | LONG LONG SIGNED_KEYWORD INT_KEYWORD
73923d7e 1376 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1377 "long long"); }
b2c4da81 1378 | LONG LONG SIGNED_KEYWORD
73923d7e 1379 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1380 "long long"); }
b2c4da81 1381 | SIGNED_KEYWORD LONG LONG
73923d7e 1382 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1383 "long long"); }
55baeb84 1384 | SIGNED_KEYWORD LONG LONG INT_KEYWORD
73923d7e 1385 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1386 "long long"); }
c906108c 1387 | UNSIGNED LONG LONG
73923d7e 1388 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1389 "long long"); }
c906108c 1390 | UNSIGNED LONG LONG INT_KEYWORD
73923d7e 1391 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1392 "long long"); }
b2c4da81 1393 | LONG LONG UNSIGNED
73923d7e 1394 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1395 "long long"); }
b2c4da81 1396 | LONG LONG UNSIGNED INT_KEYWORD
73923d7e 1397 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1398 "long long"); }
c906108c 1399 | SHORT INT_KEYWORD
73923d7e 1400 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1401 "short"); }
b2c4da81 1402 | SHORT SIGNED_KEYWORD INT_KEYWORD
73923d7e 1403 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1404 "short"); }
b2c4da81 1405 | SHORT SIGNED_KEYWORD
73923d7e 1406 { $$ = lookup_signed_typename (pstate->language (),
f4b8a18d 1407 "short"); }
c906108c 1408 | UNSIGNED SHORT INT_KEYWORD
73923d7e 1409 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1410 "short"); }
4d29c0a8 1411 | SHORT UNSIGNED
73923d7e 1412 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1413 "short"); }
b2c4da81 1414 | SHORT UNSIGNED INT_KEYWORD
73923d7e 1415 { $$ = lookup_unsigned_typename (pstate->language (),
f4b8a18d 1416 "short"); }
c906108c 1417 | DOUBLE_KEYWORD
73923d7e 1418 { $$ = lookup_typename (pstate->language (),
410a0ff2 1419 "double",
582942f4 1420 NULL,
f4b8a18d 1421 0); }
3638a098
TT
1422 | FLOAT_KEYWORD
1423 { $$ = lookup_typename (pstate->language (),
1424 "float",
1425 NULL,
1426 0); }
c906108c 1427 | LONG DOUBLE_KEYWORD
73923d7e 1428 { $$ = lookup_typename (pstate->language (),
f4b8a18d 1429 "long double",
582942f4 1430 NULL,
410a0ff2 1431 0); }
3638a098
TT
1432 | UNSIGNED type_name
1433 { $$ = lookup_unsigned_typename (pstate->language (),
1434 TYPE_NAME($2.type)); }
1435 | UNSIGNED
1436 { $$ = lookup_unsigned_typename (pstate->language (),
1437 "int"); }
1438 | SIGNED_KEYWORD type_name
1439 { $$ = lookup_signed_typename (pstate->language (),
1440 TYPE_NAME($2.type)); }
1441 | SIGNED_KEYWORD
1442 { $$ = lookup_signed_typename (pstate->language (),
1443 "int"); }
1444 ;
1445
1446/* Implements (approximately): (type-qualifier)* type-specifier.
1447
1448 When type-specifier is only ever a single word, like 'float' then these
1449 arrive as pre-built TYPENAME tokens thanks to the classify_name
1450 function. However, when a type-specifier can contain multiple words,
1451 for example 'double' can appear as just 'double' or 'long double', and
1452 similarly 'long' can appear as just 'long' or in 'long double', then
1453 these type-specifiers are parsed into their own tokens in the function
1454 lex_one_token and the ident_tokens array. These separate tokens are all
1455 recognised here. */
1456typebase
1457 : TYPENAME
1458 { $$ = $1.type; }
1459 | scalar_type
1460 { $$ = $1; }
1461 | COMPLEX scalar_type
1462 {
1463 $$ = init_complex_type (nullptr, $2);
1464 }
c906108c 1465 | STRUCT name
1e58a4a4 1466 { $$
61f4b350 1467 = lookup_struct (copy_name ($2).c_str (),
1e58a4a4
TT
1468 pstate->expression_context_block);
1469 }
2f68a895
TT
1470 | STRUCT COMPLETE
1471 {
2a612529
TT
1472 pstate->mark_completion_tag (TYPE_CODE_STRUCT,
1473 "", 0);
2f68a895
TT
1474 $$ = NULL;
1475 }
1476 | STRUCT name COMPLETE
1477 {
2a612529
TT
1478 pstate->mark_completion_tag (TYPE_CODE_STRUCT,
1479 $2.ptr, $2.length);
2f68a895
TT
1480 $$ = NULL;
1481 }
c906108c 1482 | CLASS name
1e58a4a4 1483 { $$ = lookup_struct
61f4b350
TT
1484 (copy_name ($2).c_str (),
1485 pstate->expression_context_block);
1e58a4a4 1486 }
2f68a895
TT
1487 | CLASS COMPLETE
1488 {
2a612529
TT
1489 pstate->mark_completion_tag (TYPE_CODE_STRUCT,
1490 "", 0);
2f68a895
TT
1491 $$ = NULL;
1492 }
1493 | CLASS name COMPLETE
1494 {
2a612529
TT
1495 pstate->mark_completion_tag (TYPE_CODE_STRUCT,
1496 $2.ptr, $2.length);
2f68a895
TT
1497 $$ = NULL;
1498 }
c906108c 1499 | UNION name
1e58a4a4 1500 { $$
61f4b350 1501 = lookup_union (copy_name ($2).c_str (),
1e58a4a4
TT
1502 pstate->expression_context_block);
1503 }
2f68a895
TT
1504 | UNION COMPLETE
1505 {
2a612529
TT
1506 pstate->mark_completion_tag (TYPE_CODE_UNION,
1507 "", 0);
2f68a895
TT
1508 $$ = NULL;
1509 }
1510 | UNION name COMPLETE
1511 {
2a612529
TT
1512 pstate->mark_completion_tag (TYPE_CODE_UNION,
1513 $2.ptr, $2.length);
2f68a895
TT
1514 $$ = NULL;
1515 }
c906108c 1516 | ENUM name
61f4b350 1517 { $$ = lookup_enum (copy_name ($2).c_str (),
1e58a4a4
TT
1518 pstate->expression_context_block);
1519 }
2f68a895
TT
1520 | ENUM COMPLETE
1521 {
2a612529 1522 pstate->mark_completion_tag (TYPE_CODE_ENUM, "", 0);
2f68a895
TT
1523 $$ = NULL;
1524 }
1525 | ENUM name COMPLETE
1526 {
2a612529
TT
1527 pstate->mark_completion_tag (TYPE_CODE_ENUM, $2.ptr,
1528 $2.length);
2f68a895
TT
1529 $$ = NULL;
1530 }
c906108c
SS
1531 /* It appears that this rule for templates is never
1532 reduced; template recognition happens by lookahead
4d29c0a8 1533 in the token processing code in yylex. */
c906108c 1534 | TEMPLATE name '<' type '>'
1e58a4a4 1535 { $$ = lookup_template_type
61f4b350 1536 (copy_name($2).c_str (), $4,
1e58a4a4 1537 pstate->expression_context_block);
c906108c 1538 }
3293bbaf 1539 | qualifier_seq_noopt typebase
dac43e32 1540 { $$ = cpstate->type_stack.follow_types ($2); }
3293bbaf 1541 | typebase qualifier_seq_noopt
dac43e32 1542 { $$ = cpstate->type_stack.follow_types ($1); }
c906108c
SS
1543 ;
1544
fe978cb0 1545type_name: TYPENAME
c906108c
SS
1546 | INT_KEYWORD
1547 {
1548 $$.stoken.ptr = "int";
1549 $$.stoken.length = 3;
73923d7e 1550 $$.type = lookup_signed_typename (pstate->language (),
f4b8a18d 1551 "int");
c906108c
SS
1552 }
1553 | LONG
1554 {
1555 $$.stoken.ptr = "long";
1556 $$.stoken.length = 4;
73923d7e 1557 $$.type = lookup_signed_typename (pstate->language (),
f4b8a18d 1558 "long");
c906108c
SS
1559 }
1560 | SHORT
1561 {
1562 $$.stoken.ptr = "short";
1563 $$.stoken.length = 5;
73923d7e 1564 $$.type = lookup_signed_typename (pstate->language (),
f4b8a18d 1565 "short");
c906108c
SS
1566 }
1567 ;
1568
a6fb9c08
TT
1569parameter_typelist:
1570 nonempty_typelist
e314d629 1571 { check_parameter_typelist ($1); }
a6fb9c08
TT
1572 | nonempty_typelist ',' DOTDOTDOT
1573 {
02e12e38 1574 $1->push_back (NULL);
e314d629 1575 check_parameter_typelist ($1);
a6fb9c08
TT
1576 $$ = $1;
1577 }
1578 ;
1579
c906108c
SS
1580nonempty_typelist
1581 : type
71918a86 1582 {
02e12e38
TT
1583 std::vector<struct type *> *typelist
1584 = new std::vector<struct type *>;
1585 cpstate->type_lists.emplace_back (typelist);
1586
1587 typelist->push_back ($1);
71918a86 1588 $$ = typelist;
c906108c
SS
1589 }
1590 | nonempty_typelist ',' type
71918a86 1591 {
02e12e38 1592 $1->push_back ($3);
71918a86 1593 $$ = $1;
c906108c
SS
1594 }
1595 ;
1596
47663de5 1597ptype : typebase
95c391b6 1598 | ptype abs_decl
fcde5961 1599 {
dac43e32
TT
1600 cpstate->type_stack.push ($2);
1601 $$ = cpstate->type_stack.follow_types ($1);
fcde5961 1602 }
47663de5
MS
1603 ;
1604
95c391b6 1605conversion_type_id: typebase conversion_declarator
dac43e32 1606 { $$ = cpstate->type_stack.follow_types ($1); }
95c391b6
TT
1607 ;
1608
1609conversion_declarator: /* Nothing. */
1610 | ptr_operator conversion_declarator
1611 ;
1612
47663de5
MS
1613const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
1614 | VOLATILE_KEYWORD CONST_KEYWORD
1615 ;
1616
4d29c0a8 1617const_or_volatile_noopt: const_and_volatile
dac43e32
TT
1618 { cpstate->type_stack.insert (tp_const);
1619 cpstate->type_stack.insert (tp_volatile);
47663de5
MS
1620 }
1621 | CONST_KEYWORD
dac43e32 1622 { cpstate->type_stack.insert (tp_const); }
47663de5 1623 | VOLATILE_KEYWORD
dac43e32 1624 { cpstate->type_stack.insert (tp_volatile); }
47663de5
MS
1625 ;
1626
fe978cb0 1627oper: OPERATOR NEW
66c53f2b
KS
1628 { $$ = operator_stoken (" new"); }
1629 | OPERATOR DELETE
4cd18215 1630 { $$ = operator_stoken (" delete"); }
66c53f2b
KS
1631 | OPERATOR NEW '[' ']'
1632 { $$ = operator_stoken (" new[]"); }
1633 | OPERATOR DELETE '[' ']'
4cd18215 1634 { $$ = operator_stoken (" delete[]"); }
f2e8016f
TT
1635 | OPERATOR NEW OBJC_LBRAC ']'
1636 { $$ = operator_stoken (" new[]"); }
1637 | OPERATOR DELETE OBJC_LBRAC ']'
1638 { $$ = operator_stoken (" delete[]"); }
66c53f2b
KS
1639 | OPERATOR '+'
1640 { $$ = operator_stoken ("+"); }
1641 | OPERATOR '-'
1642 { $$ = operator_stoken ("-"); }
1643 | OPERATOR '*'
1644 { $$ = operator_stoken ("*"); }
1645 | OPERATOR '/'
1646 { $$ = operator_stoken ("/"); }
1647 | OPERATOR '%'
1648 { $$ = operator_stoken ("%"); }
1649 | OPERATOR '^'
1650 { $$ = operator_stoken ("^"); }
1651 | OPERATOR '&'
1652 { $$ = operator_stoken ("&"); }
1653 | OPERATOR '|'
1654 { $$ = operator_stoken ("|"); }
1655 | OPERATOR '~'
1656 { $$ = operator_stoken ("~"); }
1657 | OPERATOR '!'
1658 { $$ = operator_stoken ("!"); }
1659 | OPERATOR '='
1660 { $$ = operator_stoken ("="); }
1661 | OPERATOR '<'
1662 { $$ = operator_stoken ("<"); }
1663 | OPERATOR '>'
1664 { $$ = operator_stoken (">"); }
1665 | OPERATOR ASSIGN_MODIFY
c8ba13ad 1666 { const char *op = " unknown";
66c53f2b
KS
1667 switch ($2)
1668 {
1669 case BINOP_RSH:
1670 op = ">>=";
1671 break;
1672 case BINOP_LSH:
1673 op = "<<=";
1674 break;
1675 case BINOP_ADD:
1676 op = "+=";
1677 break;
1678 case BINOP_SUB:
1679 op = "-=";
1680 break;
1681 case BINOP_MUL:
1682 op = "*=";
1683 break;
1684 case BINOP_DIV:
1685 op = "/=";
1686 break;
1687 case BINOP_REM:
1688 op = "%=";
1689 break;
1690 case BINOP_BITWISE_IOR:
1691 op = "|=";
1692 break;
1693 case BINOP_BITWISE_AND:
1694 op = "&=";
1695 break;
1696 case BINOP_BITWISE_XOR:
1697 op = "^=";
1698 break;
1699 default:
1700 break;
1701 }
1702
1703 $$ = operator_stoken (op);
1704 }
1705 | OPERATOR LSH
1706 { $$ = operator_stoken ("<<"); }
1707 | OPERATOR RSH
1708 { $$ = operator_stoken (">>"); }
1709 | OPERATOR EQUAL
1710 { $$ = operator_stoken ("=="); }
1711 | OPERATOR NOTEQUAL
1712 { $$ = operator_stoken ("!="); }
1713 | OPERATOR LEQ
1714 { $$ = operator_stoken ("<="); }
1715 | OPERATOR GEQ
1716 { $$ = operator_stoken (">="); }
1717 | OPERATOR ANDAND
1718 { $$ = operator_stoken ("&&"); }
1719 | OPERATOR OROR
1720 { $$ = operator_stoken ("||"); }
1721 | OPERATOR INCREMENT
1722 { $$ = operator_stoken ("++"); }
1723 | OPERATOR DECREMENT
1724 { $$ = operator_stoken ("--"); }
1725 | OPERATOR ','
1726 { $$ = operator_stoken (","); }
1727 | OPERATOR ARROW_STAR
1728 { $$ = operator_stoken ("->*"); }
1729 | OPERATOR ARROW
1730 { $$ = operator_stoken ("->"); }
1731 | OPERATOR '(' ')'
1732 { $$ = operator_stoken ("()"); }
1733 | OPERATOR '[' ']'
1734 { $$ = operator_stoken ("[]"); }
f2e8016f
TT
1735 | OPERATOR OBJC_LBRAC ']'
1736 { $$ = operator_stoken ("[]"); }
95c391b6 1737 | OPERATOR conversion_type_id
d7e74731 1738 { string_file buf;
66c53f2b 1739
d7e74731 1740 c_print_type ($2, NULL, &buf, -1, 0,
79d43c61 1741 &type_print_raw_options);
c8ba13ad
KS
1742
1743 /* This also needs canonicalization. */
1744 std::string canon
1745 = cp_canonicalize_string (buf.c_str ());
1746 if (canon.empty ())
1747 canon = std::move (buf.string ());
1748 $$ = operator_stoken ((" " + canon).c_str ());
66c53f2b
KS
1749 }
1750 ;
1751
6f0ffe50
AB
1752/* This rule exists in order to allow some tokens that would not normally
1753 match the 'name' rule to appear as fields within a struct. The example
1754 that initially motivated this was the RISC-V target which models the
1755 floating point registers as a union with fields called 'float' and
3638a098 1756 'double'. */
0f5d3f63
AB
1757field_name
1758 : name
6f0ffe50 1759 | DOUBLE_KEYWORD { $$ = typename_stoken ("double"); }
3638a098 1760 | FLOAT_KEYWORD { $$ = typename_stoken ("float"); }
6f0ffe50
AB
1761 | INT_KEYWORD { $$ = typename_stoken ("int"); }
1762 | LONG { $$ = typename_stoken ("long"); }
1763 | SHORT { $$ = typename_stoken ("short"); }
1764 | SIGNED_KEYWORD { $$ = typename_stoken ("signed"); }
1765 | UNSIGNED { $$ = typename_stoken ("unsigned"); }
0f5d3f63 1766 ;
66c53f2b 1767
c906108c
SS
1768name : NAME { $$ = $1.stoken; }
1769 | BLOCKNAME { $$ = $1.stoken; }
1770 | TYPENAME { $$ = $1.stoken; }
1771 | NAME_OR_INT { $$ = $1.stoken; }
7322dca9 1772 | UNKNOWN_CPP_NAME { $$ = $1.stoken; }
fe978cb0 1773 | oper { $$ = $1; }
c906108c
SS
1774 ;
1775
1776name_not_typename : NAME
1777 | BLOCKNAME
1778/* These would be useful if name_not_typename was useful, but it is just
1779 a fake for "variable", so these cause reduce/reduce conflicts because
1780 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1781 =exp) or just an exp. If name_not_typename was ever used in an lvalue
1782 context where only a name could occur, this might be useful.
1783 | NAME_OR_INT
1784 */
fe978cb0 1785 | oper
6e31430b 1786 {
1993b719
TT
1787 struct field_of_this_result is_a_field_of_this;
1788
6e31430b 1789 $$.stoken = $1;
1e58a4a4
TT
1790 $$.sym
1791 = lookup_symbol ($1.ptr,
1792 pstate->expression_context_block,
1793 VAR_DOMAIN,
1794 &is_a_field_of_this);
1993b719
TT
1795 $$.is_a_field_of_this
1796 = is_a_field_of_this.type != NULL;
6e31430b 1797 }
7322dca9 1798 | UNKNOWN_CPP_NAME
c906108c
SS
1799 ;
1800
1801%%
1802
24955f63
TT
1803/* Like write_exp_string, but prepends a '~'. */
1804
1805static void
410a0ff2 1806write_destructor_name (struct parser_state *par_state, struct stoken token)
24955f63 1807{
224c3ddb 1808 char *copy = (char *) alloca (token.length + 1);
24955f63
TT
1809
1810 copy[0] = '~';
1811 memcpy (&copy[1], token.ptr, token.length);
1812
1813 token.ptr = copy;
1814 ++token.length;
1815
410a0ff2 1816 write_exp_string (par_state, token);
24955f63
TT
1817}
1818
66c53f2b 1819/* Returns a stoken of the operator name given by OP (which does not
4d29c0a8
DE
1820 include the string "operator"). */
1821
66c53f2b
KS
1822static struct stoken
1823operator_stoken (const char *op)
1824{
66c53f2b 1825 struct stoken st = { NULL, 0 };
d7561cbb
KS
1826 char *buf;
1827
8090b426 1828 st.length = CP_OPERATOR_LEN + strlen (op);
224c3ddb 1829 buf = (char *) malloc (st.length + 1);
8090b426 1830 strcpy (buf, CP_OPERATOR_STR);
d7561cbb
KS
1831 strcat (buf, op);
1832 st.ptr = buf;
66c53f2b
KS
1833
1834 /* The toplevel (c_parse) will free the memory allocated here. */
c65bac38 1835 cpstate->strings.emplace_back (buf);
66c53f2b
KS
1836 return st;
1837};
1838
6f0ffe50
AB
1839/* Returns a stoken of the type named TYPE. */
1840
1841static struct stoken
1842typename_stoken (const char *type)
1843{
1844 struct stoken st = { type, 0 };
1845 st.length = strlen (type);
1846 return st;
1847};
1848
3d567982
TT
1849/* Return true if the type is aggregate-like. */
1850
1851static int
1852type_aggregate_p (struct type *type)
1853{
1854 return (TYPE_CODE (type) == TYPE_CODE_STRUCT
1855 || TYPE_CODE (type) == TYPE_CODE_UNION
1856 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE
1857 || (TYPE_CODE (type) == TYPE_CODE_ENUM
1858 && TYPE_DECLARED_CLASS (type)));
1859}
1860
e314d629
TT
1861/* Validate a parameter typelist. */
1862
1863static void
02e12e38 1864check_parameter_typelist (std::vector<struct type *> *params)
e314d629
TT
1865{
1866 struct type *type;
1867 int ix;
1868
02e12e38 1869 for (ix = 0; ix < params->size (); ++ix)
e314d629 1870 {
02e12e38 1871 type = (*params)[ix];
e314d629
TT
1872 if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
1873 {
1874 if (ix == 0)
1875 {
02e12e38 1876 if (params->size () == 1)
e314d629
TT
1877 {
1878 /* Ok. */
1879 break;
1880 }
e314d629
TT
1881 error (_("parameter types following 'void'"));
1882 }
1883 else
02e12e38 1884 error (_("'void' invalid as parameter type"));
e314d629
TT
1885 }
1886 }
1887}
1888
c906108c
SS
1889/* Take care of parsing a number (anything that starts with a digit).
1890 Set yylval and return the token type; update lexptr.
1891 LEN is the number of characters in it. */
1892
1893/*** Needs some error checking for the float case ***/
1894
1895static int
410a0ff2
SDJ
1896parse_number (struct parser_state *par_state,
1897 const char *buf, int len, int parsed_float, YYSTYPE *putithere)
c906108c 1898{
20562150
TT
1899 ULONGEST n = 0;
1900 ULONGEST prevn = 0;
c906108c
SS
1901 ULONGEST un;
1902
710122da
DC
1903 int i = 0;
1904 int c;
1905 int base = input_radix;
c906108c
SS
1906 int unsigned_p = 0;
1907
1908 /* Number of "L" suffixes encountered. */
1909 int long_p = 0;
1910
fa649bb7
TT
1911 /* Imaginary number. */
1912 bool imaginary_p = false;
1913
1914 /* We have found a "L" or "U" (or "i") suffix. */
c906108c
SS
1915 int found_suffix = 0;
1916
1917 ULONGEST high_bit;
1918 struct type *signed_type;
1919 struct type *unsigned_type;
d7561cbb
KS
1920 char *p;
1921
224c3ddb 1922 p = (char *) alloca (len);
d7561cbb 1923 memcpy (p, buf, len);
c906108c
SS
1924
1925 if (parsed_float)
1926 {
fa649bb7
TT
1927 if (len >= 1 && p[len - 1] == 'i')
1928 {
1929 imaginary_p = true;
1930 --len;
1931 }
1932
edd079d9 1933 /* Handle suffixes for decimal floating-point: "df", "dd" or "dl". */
fe9441f6 1934 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
27bc4d80 1935 {
edd079d9 1936 putithere->typed_val_float.type
410a0ff2 1937 = parse_type (par_state)->builtin_decfloat;
edd079d9 1938 len -= 2;
27bc4d80 1939 }
edd079d9 1940 else if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
27bc4d80 1941 {
edd079d9 1942 putithere->typed_val_float.type
410a0ff2 1943 = parse_type (par_state)->builtin_decdouble;
edd079d9 1944 len -= 2;
27bc4d80 1945 }
edd079d9 1946 else if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
27bc4d80 1947 {
edd079d9 1948 putithere->typed_val_float.type
410a0ff2 1949 = parse_type (par_state)->builtin_declong;
edd079d9
UW
1950 len -= 2;
1951 }
1952 /* Handle suffixes: 'f' for float, 'l' for long double. */
b1b60145 1953 else if (len >= 1 && TOLOWER (p[len - 1]) == 'f')
edd079d9
UW
1954 {
1955 putithere->typed_val_float.type
1956 = parse_type (par_state)->builtin_float;
1957 len -= 1;
1958 }
b1b60145 1959 else if (len >= 1 && TOLOWER (p[len - 1]) == 'l')
edd079d9
UW
1960 {
1961 putithere->typed_val_float.type
1962 = parse_type (par_state)->builtin_long_double;
1963 len -= 1;
1964 }
1965 /* Default type for floating-point literals is double. */
1966 else
1967 {
1968 putithere->typed_val_float.type
1969 = parse_type (par_state)->builtin_double;
27bc4d80
TJB
1970 }
1971
edd079d9
UW
1972 if (!parse_float (p, len,
1973 putithere->typed_val_float.type,
1974 putithere->typed_val_float.val))
1975 return ERROR;
fa649bb7
TT
1976
1977 if (imaginary_p)
1978 putithere->typed_val_float.type
1979 = init_complex_type (nullptr, putithere->typed_val_float.type);
1980
1981 return imaginary_p ? COMPLEX_FLOAT : FLOAT;
c906108c
SS
1982 }
1983
1984 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
ebf13736 1985 if (p[0] == '0' && len > 1)
c906108c
SS
1986 switch (p[1])
1987 {
1988 case 'x':
1989 case 'X':
1990 if (len >= 3)
1991 {
1992 p += 2;
1993 base = 16;
1994 len -= 2;
1995 }
1996 break;
1997
b5cfddf5
JK
1998 case 'b':
1999 case 'B':
2000 if (len >= 3)
2001 {
2002 p += 2;
2003 base = 2;
2004 len -= 2;
2005 }
2006 break;
2007
c906108c
SS
2008 case 't':
2009 case 'T':
2010 case 'd':
2011 case 'D':
2012 if (len >= 3)
2013 {
2014 p += 2;
2015 base = 10;
2016 len -= 2;
2017 }
2018 break;
2019
2020 default:
2021 base = 8;
2022 break;
2023 }
2024
2025 while (len-- > 0)
2026 {
2027 c = *p++;
2028 if (c >= 'A' && c <= 'Z')
2029 c += 'a' - 'A';
fa649bb7 2030 if (c != 'l' && c != 'u' && c != 'i')
c906108c
SS
2031 n *= base;
2032 if (c >= '0' && c <= '9')
2033 {
2034 if (found_suffix)
2035 return ERROR;
2036 n += i = c - '0';
2037 }
2038 else
2039 {
2040 if (base > 10 && c >= 'a' && c <= 'f')
2041 {
2042 if (found_suffix)
2043 return ERROR;
2044 n += i = c - 'a' + 10;
2045 }
2046 else if (c == 'l')
2047 {
2048 ++long_p;
2049 found_suffix = 1;
2050 }
2051 else if (c == 'u')
2052 {
2053 unsigned_p = 1;
2054 found_suffix = 1;
2055 }
fa649bb7
TT
2056 else if (c == 'i')
2057 {
2058 imaginary_p = true;
2059 found_suffix = 1;
2060 }
c906108c
SS
2061 else
2062 return ERROR; /* Char not a digit */
2063 }
2064 if (i >= base)
2065 return ERROR; /* Invalid digit in this base */
2066
2067 /* Portably test for overflow (only works for nonzero values, so make
2068 a second check for zero). FIXME: Can't we just make n and prevn
2069 unsigned and avoid this? */
fa649bb7 2070 if (c != 'l' && c != 'u' && c != 'i' && (prevn >= n) && n != 0)
c906108c
SS
2071 unsigned_p = 1; /* Try something unsigned */
2072
2073 /* Portably test for unsigned overflow.
2074 FIXME: This check is wrong; for example it doesn't find overflow
2075 on 0x123456789 when LONGEST is 32 bits. */
fa649bb7 2076 if (c != 'l' && c != 'u' && c != 'i' && n != 0)
c906108c 2077 {
20562150 2078 if (unsigned_p && prevn >= n)
001083c6 2079 error (_("Numeric constant too large."));
c906108c
SS
2080 }
2081 prevn = n;
2082 }
2083
2084 /* An integer constant is an int, a long, or a long long. An L
2085 suffix forces it to be long; an LL suffix forces it to be long
2086 long. If not forced to a larger size, it gets the first type of
2087 the above that it fits in. To figure out whether it fits, we
2088 shift it right and see whether anything remains. Note that we
2089 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
2090 operation, because many compilers will warn about such a shift
9a76efb6
UW
2091 (which always produces a zero result). Sometimes gdbarch_int_bit
2092 or gdbarch_long_bit will be that big, sometimes not. To deal with
c906108c
SS
2093 the case where it is we just always shift the value more than
2094 once, with fewer bits each time. */
2095
20562150 2096 un = n >> 2;
c906108c 2097 if (long_p == 0
fa9f5be6 2098 && (un >> (gdbarch_int_bit (par_state->gdbarch ()) - 2)) == 0)
c906108c 2099 {
410a0ff2 2100 high_bit
fa9f5be6 2101 = ((ULONGEST)1) << (gdbarch_int_bit (par_state->gdbarch ()) - 1);
c906108c
SS
2102
2103 /* A large decimal (not hex or octal) constant (between INT_MAX
2104 and UINT_MAX) is a long or unsigned long, according to ANSI,
2105 never an unsigned int, but this code treats it as unsigned
2106 int. This probably should be fixed. GCC gives a warning on
2107 such constants. */
2108
410a0ff2
SDJ
2109 unsigned_type = parse_type (par_state)->builtin_unsigned_int;
2110 signed_type = parse_type (par_state)->builtin_int;
c906108c
SS
2111 }
2112 else if (long_p <= 1
fa9f5be6 2113 && (un >> (gdbarch_long_bit (par_state->gdbarch ()) - 2)) == 0)
c906108c 2114 {
410a0ff2 2115 high_bit
fa9f5be6 2116 = ((ULONGEST)1) << (gdbarch_long_bit (par_state->gdbarch ()) - 1);
410a0ff2
SDJ
2117 unsigned_type = parse_type (par_state)->builtin_unsigned_long;
2118 signed_type = parse_type (par_state)->builtin_long;
c906108c
SS
2119 }
2120 else
2121 {
2122 int shift;
4d29c0a8 2123 if (sizeof (ULONGEST) * HOST_CHAR_BIT
fa9f5be6 2124 < gdbarch_long_long_bit (par_state->gdbarch ()))
c906108c
SS
2125 /* A long long does not fit in a LONGEST. */
2126 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
2127 else
fa9f5be6 2128 shift = (gdbarch_long_long_bit (par_state->gdbarch ()) - 1);
c906108c 2129 high_bit = (ULONGEST) 1 << shift;
410a0ff2
SDJ
2130 unsigned_type = parse_type (par_state)->builtin_unsigned_long_long;
2131 signed_type = parse_type (par_state)->builtin_long_long;
c906108c
SS
2132 }
2133
2134 putithere->typed_val_int.val = n;
2135
2136 /* If the high bit of the worked out type is set then this number
2137 has to be unsigned. */
2138
4d29c0a8 2139 if (unsigned_p || (n & high_bit))
c906108c
SS
2140 {
2141 putithere->typed_val_int.type = unsigned_type;
2142 }
4d29c0a8 2143 else
c906108c
SS
2144 {
2145 putithere->typed_val_int.type = signed_type;
2146 }
2147
fa649bb7
TT
2148 if (imaginary_p)
2149 putithere->typed_val_int.type
2150 = init_complex_type (nullptr, putithere->typed_val_int.type);
2151
2152 return imaginary_p ? COMPLEX_INT : INT;
c906108c
SS
2153}
2154
6c7a06a3
TT
2155/* Temporary obstack used for holding strings. */
2156static struct obstack tempbuf;
2157static int tempbuf_init;
2158
2159/* Parse a C escape sequence. The initial backslash of the sequence
2160 is at (*PTR)[-1]. *PTR will be updated to point to just after the
2161 last character of the sequence. If OUTPUT is not NULL, the
2162 translated form of the escape sequence will be written there. If
2163 OUTPUT is NULL, no output is written and the call will only affect
2164 *PTR. If an escape sequence is expressed in target bytes, then the
2165 entire sequence will simply be copied to OUTPUT. Return 1 if any
2166 character was emitted, 0 otherwise. */
2167
2168int
d7561cbb 2169c_parse_escape (const char **ptr, struct obstack *output)
6c7a06a3 2170{
d7561cbb 2171 const char *tokptr = *ptr;
6c7a06a3
TT
2172 int result = 1;
2173
2174 /* Some escape sequences undergo character set conversion. Those we
2175 translate here. */
2176 switch (*tokptr)
2177 {
2178 /* Hex escapes do not undergo character set conversion, so keep
2179 the escape sequence for later. */
2180 case 'x':
2181 if (output)
2182 obstack_grow_str (output, "\\x");
2183 ++tokptr;
b1b60145 2184 if (!ISXDIGIT (*tokptr))
6c7a06a3 2185 error (_("\\x escape without a following hex digit"));
b1b60145 2186 while (ISXDIGIT (*tokptr))
6c7a06a3
TT
2187 {
2188 if (output)
2189 obstack_1grow (output, *tokptr);
2190 ++tokptr;
2191 }
2192 break;
2193
2194 /* Octal escapes do not undergo character set conversion, so
2195 keep the escape sequence for later. */
2196 case '0':
2197 case '1':
2198 case '2':
2199 case '3':
2200 case '4':
2201 case '5':
2202 case '6':
2203 case '7':
30b66ecc
TT
2204 {
2205 int i;
2206 if (output)
2207 obstack_grow_str (output, "\\");
2208 for (i = 0;
b1b60145 2209 i < 3 && ISDIGIT (*tokptr) && *tokptr != '8' && *tokptr != '9';
30b66ecc
TT
2210 ++i)
2211 {
2212 if (output)
2213 obstack_1grow (output, *tokptr);
2214 ++tokptr;
2215 }
2216 }
6c7a06a3
TT
2217 break;
2218
2219 /* We handle UCNs later. We could handle them here, but that
2220 would mean a spurious error in the case where the UCN could
2221 be converted to the target charset but not the host
2222 charset. */
2223 case 'u':
2224 case 'U':
2225 {
2226 char c = *tokptr;
2227 int i, len = c == 'U' ? 8 : 4;
2228 if (output)
2229 {
2230 obstack_1grow (output, '\\');
2231 obstack_1grow (output, *tokptr);
2232 }
2233 ++tokptr;
b1b60145 2234 if (!ISXDIGIT (*tokptr))
6c7a06a3 2235 error (_("\\%c escape without a following hex digit"), c);
b1b60145 2236 for (i = 0; i < len && ISXDIGIT (*tokptr); ++i)
6c7a06a3
TT
2237 {
2238 if (output)
2239 obstack_1grow (output, *tokptr);
2240 ++tokptr;
2241 }
2242 }
2243 break;
2244
2245 /* We must pass backslash through so that it does not
2246 cause quoting during the second expansion. */
2247 case '\\':
2248 if (output)
2249 obstack_grow_str (output, "\\\\");
2250 ++tokptr;
2251 break;
2252
2253 /* Escapes which undergo conversion. */
2254 case 'a':
2255 if (output)
2256 obstack_1grow (output, '\a');
2257 ++tokptr;
2258 break;
2259 case 'b':
2260 if (output)
2261 obstack_1grow (output, '\b');
2262 ++tokptr;
2263 break;
2264 case 'f':
2265 if (output)
2266 obstack_1grow (output, '\f');
2267 ++tokptr;
2268 break;
2269 case 'n':
2270 if (output)
2271 obstack_1grow (output, '\n');
2272 ++tokptr;
2273 break;
2274 case 'r':
2275 if (output)
2276 obstack_1grow (output, '\r');
2277 ++tokptr;
2278 break;
2279 case 't':
2280 if (output)
2281 obstack_1grow (output, '\t');
2282 ++tokptr;
2283 break;
2284 case 'v':
2285 if (output)
2286 obstack_1grow (output, '\v');
2287 ++tokptr;
2288 break;
2289
2290 /* GCC extension. */
2291 case 'e':
2292 if (output)
2293 obstack_1grow (output, HOST_ESCAPE_CHAR);
2294 ++tokptr;
2295 break;
2296
2297 /* Backslash-newline expands to nothing at all. */
2298 case '\n':
2299 ++tokptr;
2300 result = 0;
2301 break;
2302
2303 /* A few escapes just expand to the character itself. */
2304 case '\'':
2305 case '\"':
2306 case '?':
2307 /* GCC extensions. */
2308 case '(':
2309 case '{':
2310 case '[':
2311 case '%':
2312 /* Unrecognized escapes turn into the character itself. */
2313 default:
2314 if (output)
2315 obstack_1grow (output, *tokptr);
2316 ++tokptr;
2317 break;
2318 }
2319 *ptr = tokptr;
2320 return result;
2321}
2322
2323/* Parse a string or character literal from TOKPTR. The string or
2324 character may be wide or unicode. *OUTPTR is set to just after the
2325 end of the literal in the input string. The resulting token is
2326 stored in VALUE. This returns a token value, either STRING or
2327 CHAR, depending on what was parsed. *HOST_CHARS is set to the
2328 number of host characters in the literal. */
4d29c0a8 2329
6c7a06a3 2330static int
d7561cbb
KS
2331parse_string_or_char (const char *tokptr, const char **outptr,
2332 struct typed_stoken *value, int *host_chars)
6c7a06a3 2333{
8c5630cb 2334 int quote;
0c801b96 2335 c_string_type type;
f2e8016f 2336 int is_objc = 0;
6c7a06a3
TT
2337
2338 /* Build the gdb internal form of the input string in tempbuf. Note
2339 that the buffer is null byte terminated *only* for the
2340 convenience of debugging gdb itself and printing the buffer
2341 contents when the buffer contains no embedded nulls. Gdb does
2342 not depend upon the buffer being null byte terminated, it uses
2343 the length string instead. This allows gdb to handle C strings
2344 (as well as strings in other languages) with embedded null
2345 bytes */
2346
2347 if (!tempbuf_init)
2348 tempbuf_init = 1;
2349 else
2350 obstack_free (&tempbuf, NULL);
2351 obstack_init (&tempbuf);
2352
2353 /* Record the string type. */
2354 if (*tokptr == 'L')
2355 {
2356 type = C_WIDE_STRING;
2357 ++tokptr;
2358 }
2359 else if (*tokptr == 'u')
2360 {
2361 type = C_STRING_16;
2362 ++tokptr;
2363 }
2364 else if (*tokptr == 'U')
2365 {
2366 type = C_STRING_32;
2367 ++tokptr;
2368 }
f2e8016f
TT
2369 else if (*tokptr == '@')
2370 {
2371 /* An Objective C string. */
2372 is_objc = 1;
2373 type = C_STRING;
2374 ++tokptr;
2375 }
6c7a06a3
TT
2376 else
2377 type = C_STRING;
2378
2379 /* Skip the quote. */
2380 quote = *tokptr;
2381 if (quote == '\'')
2382 type |= C_CHAR;
2383 ++tokptr;
2384
2385 *host_chars = 0;
2386
2387 while (*tokptr)
2388 {
2389 char c = *tokptr;
2390 if (c == '\\')
2391 {
2392 ++tokptr;
2393 *host_chars += c_parse_escape (&tokptr, &tempbuf);
2394 }
2395 else if (c == quote)
2396 break;
2397 else
2398 {
2399 obstack_1grow (&tempbuf, c);
2400 ++tokptr;
2401 /* FIXME: this does the wrong thing with multi-byte host
2402 characters. We could use mbrlen here, but that would
2403 make "set host-charset" a bit less useful. */
2404 ++*host_chars;
2405 }
2406 }
2407
2408 if (*tokptr != quote)
2409 {
2410 if (quote == '"')
001083c6 2411 error (_("Unterminated string in expression."));
6c7a06a3 2412 else
001083c6 2413 error (_("Unmatched single quote."));
6c7a06a3
TT
2414 }
2415 ++tokptr;
2416
2417 value->type = type;
79f33898 2418 value->ptr = (char *) obstack_base (&tempbuf);
6c7a06a3
TT
2419 value->length = obstack_object_size (&tempbuf);
2420
2421 *outptr = tokptr;
2422
f2e8016f 2423 return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR;
6c7a06a3
TT
2424}
2425
274b54d7
TT
2426/* This is used to associate some attributes with a token. */
2427
8d297bbf 2428enum token_flag
274b54d7
TT
2429{
2430 /* If this bit is set, the token is C++-only. */
2431
2432 FLAG_CXX = 1,
2433
3293bbaf
TT
2434 /* If this bit is set, the token is C-only. */
2435
2436 FLAG_C = 2,
2437
274b54d7
TT
2438 /* If this bit is set, the token is conditional: if there is a
2439 symbol of the same name, then the token is a symbol; otherwise,
2440 the token is a keyword. */
2441
3293bbaf 2442 FLAG_SHADOW = 4
274b54d7 2443};
8d297bbf 2444DEF_ENUM_FLAGS_TYPE (enum token_flag, token_flags);
274b54d7 2445
c906108c
SS
2446struct token
2447{
a121b7c1 2448 const char *oper;
c906108c
SS
2449 int token;
2450 enum exp_opcode opcode;
8d297bbf 2451 token_flags flags;
c906108c
SS
2452};
2453
2454static const struct token tokentab3[] =
2455 {
ba163c7e 2456 {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
c1af96a0 2457 {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
274b54d7 2458 {"->*", ARROW_STAR, BINOP_END, FLAG_CXX},
a6fb9c08 2459 {"...", DOTDOTDOT, BINOP_END, 0}
c906108c
SS
2460 };
2461
2462static const struct token tokentab2[] =
2463 {
ba163c7e
TT
2464 {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
2465 {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
2466 {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
2467 {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
2468 {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
2469 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
2470 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
2471 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
2472 {"++", INCREMENT, BINOP_END, 0},
2473 {"--", DECREMENT, BINOP_END, 0},
2474 {"->", ARROW, BINOP_END, 0},
2475 {"&&", ANDAND, BINOP_END, 0},
2476 {"||", OROR, BINOP_END, 0},
ec7f2efe
KS
2477 /* "::" is *not* only C++: gdb overrides its meaning in several
2478 different ways, e.g., 'filename'::func, function::variable. */
ba163c7e
TT
2479 {"::", COLONCOLON, BINOP_END, 0},
2480 {"<<", LSH, BINOP_END, 0},
2481 {">>", RSH, BINOP_END, 0},
2482 {"==", EQUAL, BINOP_END, 0},
2483 {"!=", NOTEQUAL, BINOP_END, 0},
2484 {"<=", LEQ, BINOP_END, 0},
c1af96a0 2485 {">=", GEQ, BINOP_END, 0},
274b54d7 2486 {".*", DOT_STAR, BINOP_END, FLAG_CXX}
ba163c7e
TT
2487 };
2488
b6c95c0c
AB
2489/* Identifier-like tokens. Only type-specifiers than can appear in
2490 multi-word type names (for example 'double' can appear in 'long
2491 double') need to be listed here. type-specifiers that are only ever
3638a098 2492 single word (like 'char') are handled by the classify_name function. */
ba163c7e
TT
2493static const struct token ident_tokens[] =
2494 {
2495 {"unsigned", UNSIGNED, OP_NULL, 0},
274b54d7 2496 {"template", TEMPLATE, OP_NULL, FLAG_CXX},
ba163c7e
TT
2497 {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
2498 {"struct", STRUCT, OP_NULL, 0},
2499 {"signed", SIGNED_KEYWORD, OP_NULL, 0},
2500 {"sizeof", SIZEOF, OP_NULL, 0},
007e1530
TT
2501 {"_Alignof", ALIGNOF, OP_NULL, 0},
2502 {"alignof", ALIGNOF, OP_NULL, FLAG_CXX},
ba163c7e 2503 {"double", DOUBLE_KEYWORD, OP_NULL, 0},
3638a098 2504 {"float", FLOAT_KEYWORD, OP_NULL, 0},
274b54d7
TT
2505 {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
2506 {"class", CLASS, OP_NULL, FLAG_CXX},
ba163c7e
TT
2507 {"union", UNION, OP_NULL, 0},
2508 {"short", SHORT, OP_NULL, 0},
2509 {"const", CONST_KEYWORD, OP_NULL, 0},
3293bbaf
TT
2510 {"restrict", RESTRICT, OP_NULL, FLAG_C | FLAG_SHADOW},
2511 {"__restrict__", RESTRICT, OP_NULL, 0},
2512 {"__restrict", RESTRICT, OP_NULL, 0},
2513 {"_Atomic", ATOMIC, OP_NULL, 0},
ba163c7e
TT
2514 {"enum", ENUM, OP_NULL, 0},
2515 {"long", LONG, OP_NULL, 0},
3638a098
TT
2516 {"_Complex", COMPLEX, OP_NULL, 0},
2517 {"__complex__", COMPLEX, OP_NULL, 0},
2518
274b54d7 2519 {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
ba163c7e 2520 {"int", INT_KEYWORD, OP_NULL, 0},
274b54d7
TT
2521 {"new", NEW, OP_NULL, FLAG_CXX},
2522 {"delete", DELETE, OP_NULL, FLAG_CXX},
2523 {"operator", OPERATOR, OP_NULL, FLAG_CXX},
2524
2525 {"and", ANDAND, BINOP_END, FLAG_CXX},
2526 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
2527 {"bitand", '&', OP_NULL, FLAG_CXX},
2528 {"bitor", '|', OP_NULL, FLAG_CXX},
2529 {"compl", '~', OP_NULL, FLAG_CXX},
2530 {"not", '!', OP_NULL, FLAG_CXX},
2531 {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX},
2532 {"or", OROR, BINOP_END, FLAG_CXX},
2533 {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX},
2534 {"xor", '^', OP_NULL, FLAG_CXX},
2535 {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX},
2536
2537 {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX },
2538 {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX },
2539 {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX },
608b4967
TT
2540 {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX },
2541
2542 {"__typeof__", TYPEOF, OP_TYPEOF, 0 },
2543 {"__typeof", TYPEOF, OP_TYPEOF, 0 },
2544 {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW },
2545 {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX },
6e72ca20
TT
2546 {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW },
2547
2548 {"typeid", TYPEID, OP_TYPEID, FLAG_CXX}
c906108c
SS
2549 };
2550
7c8adf68
TT
2551
2552static void
2553scan_macro_expansion (char *expansion)
2554{
021887d8 2555 const char *copy;
7c8adf68
TT
2556
2557 /* We'd better not be trying to push the stack twice. */
9d30e1fd 2558 gdb_assert (! cpstate->macro_original_text);
7c8adf68
TT
2559
2560 /* Copy to the obstack, and then free the intermediate
2561 expansion. */
021887d8 2562 copy = obstack_strdup (&cpstate->expansion_obstack, expansion);
7c8adf68
TT
2563 xfree (expansion);
2564
2565 /* Save the old lexptr value, so we can return to it when we're done
2566 parsing the expanded text. */
5776fca3
TT
2567 cpstate->macro_original_text = pstate->lexptr;
2568 pstate->lexptr = copy;
7c8adf68
TT
2569}
2570
7c8adf68
TT
2571static int
2572scanning_macro_expansion (void)
2573{
9d30e1fd 2574 return cpstate->macro_original_text != 0;
7c8adf68
TT
2575}
2576
4d29c0a8 2577static void
7c8adf68
TT
2578finished_macro_expansion (void)
2579{
2580 /* There'd better be something to pop back to. */
9d30e1fd 2581 gdb_assert (cpstate->macro_original_text);
7c8adf68
TT
2582
2583 /* Pop back to the original text. */
5776fca3 2584 pstate->lexptr = cpstate->macro_original_text;
9d30e1fd 2585 cpstate->macro_original_text = 0;
7c8adf68
TT
2586}
2587
4e8f195d
TT
2588/* Return true iff the token represents a C++ cast operator. */
2589
2590static int
2591is_cast_operator (const char *token, int len)
2592{
2593 return (! strncmp (token, "dynamic_cast", len)
2594 || ! strncmp (token, "static_cast", len)
2595 || ! strncmp (token, "reinterpret_cast", len)
2596 || ! strncmp (token, "const_cast", len));
2597}
7c8adf68
TT
2598
2599/* The scope used for macro expansion. */
2600static struct macro_scope *expression_macro_scope;
2601
65d12d83
TT
2602/* This is set if a NAME token appeared at the very end of the input
2603 string, with no whitespace separating the name from the EOF. This
2604 is used only when parsing to do field name completion. */
2605static int saw_name_at_eof;
2606
2607/* This is set if the previously-returned token was a structure
59498c30
LS
2608 operator -- either '.' or ARROW. */
2609static bool last_was_structop;
65d12d83 2610
28aaf3fd
TT
2611/* Depth of parentheses. */
2612static int paren_depth;
2613
c906108c
SS
2614/* Read one token, getting characters through lexptr. */
2615
2616static int
59498c30 2617lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
c906108c
SS
2618{
2619 int c;
2620 int namelen;
2621 unsigned int i;
d7561cbb 2622 const char *tokstart;
59498c30 2623 bool saw_structop = last_was_structop;
65d12d83 2624
59498c30
LS
2625 last_was_structop = false;
2626 *is_quoted_name = false;
65d12d83 2627
c906108c
SS
2628 retry:
2629
84f0252a
JB
2630 /* Check if this is a macro invocation that we need to expand. */
2631 if (! scanning_macro_expansion ())
2632 {
5776fca3 2633 char *expanded = macro_expand_next (&pstate->lexptr,
7c8adf68
TT
2634 standard_macro_lookup,
2635 expression_macro_scope);
84f0252a
JB
2636
2637 if (expanded)
2638 scan_macro_expansion (expanded);
2639 }
2640
5776fca3 2641 pstate->prev_lexptr = pstate->lexptr;
c906108c 2642
5776fca3 2643 tokstart = pstate->lexptr;
c906108c
SS
2644 /* See if it is a special token of length 3. */
2645 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
fe978cb0 2646 if (strncmp (tokstart, tokentab3[i].oper, 3) == 0)
c906108c 2647 {
274b54d7 2648 if ((tokentab3[i].flags & FLAG_CXX) != 0
73923d7e 2649 && par_state->language ()->la_language != language_cplus)
ec7f2efe 2650 break;
3293bbaf 2651 gdb_assert ((tokentab3[i].flags & FLAG_C) == 0);
ec7f2efe 2652
5776fca3 2653 pstate->lexptr += 3;
c906108c
SS
2654 yylval.opcode = tokentab3[i].opcode;
2655 return tokentab3[i].token;
2656 }
2657
2658 /* See if it is a special token of length 2. */
2659 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
fe978cb0 2660 if (strncmp (tokstart, tokentab2[i].oper, 2) == 0)
c906108c 2661 {
274b54d7 2662 if ((tokentab2[i].flags & FLAG_CXX) != 0
73923d7e 2663 && par_state->language ()->la_language != language_cplus)
ec7f2efe 2664 break;
f7d4f0b1 2665 gdb_assert ((tokentab2[i].flags & FLAG_C) == 0);
ec7f2efe 2666
5776fca3 2667 pstate->lexptr += 2;
c906108c 2668 yylval.opcode = tokentab2[i].opcode;
59498c30 2669 if (tokentab2[i].token == ARROW)
65d12d83 2670 last_was_structop = 1;
c906108c
SS
2671 return tokentab2[i].token;
2672 }
2673
2674 switch (c = *tokstart)
2675 {
2676 case 0:
84f0252a
JB
2677 /* If we were just scanning the result of a macro expansion,
2678 then we need to resume scanning the original text.
65d12d83
TT
2679 If we're parsing for field name completion, and the previous
2680 token allows such completion, return a COMPLETE token.
84f0252a
JB
2681 Otherwise, we were already scanning the original text, and
2682 we're really done. */
2683 if (scanning_macro_expansion ())
2684 {
2685 finished_macro_expansion ();
2686 goto retry;
2687 }
65d12d83
TT
2688 else if (saw_name_at_eof)
2689 {
2690 saw_name_at_eof = 0;
2691 return COMPLETE;
2692 }
2a612529 2693 else if (par_state->parse_completion && saw_structop)
65d12d83 2694 return COMPLETE;
84f0252a
JB
2695 else
2696 return 0;
c906108c
SS
2697
2698 case ' ':
2699 case '\t':
2700 case '\n':
5776fca3 2701 pstate->lexptr++;
c906108c
SS
2702 goto retry;
2703
379a77b5 2704 case '[':
c906108c
SS
2705 case '(':
2706 paren_depth++;
5776fca3 2707 pstate->lexptr++;
73923d7e 2708 if (par_state->language ()->la_language == language_objc
410a0ff2 2709 && c == '[')
f2e8016f 2710 return OBJC_LBRAC;
c906108c
SS
2711 return c;
2712
379a77b5 2713 case ']':
c906108c
SS
2714 case ')':
2715 if (paren_depth == 0)
2716 return 0;
2717 paren_depth--;
5776fca3 2718 pstate->lexptr++;
c906108c
SS
2719 return c;
2720
2721 case ',':
8621b685 2722 if (pstate->comma_terminates
84f0252a
JB
2723 && paren_depth == 0
2724 && ! scanning_macro_expansion ())
c906108c 2725 return 0;
5776fca3 2726 pstate->lexptr++;
c906108c
SS
2727 return c;
2728
2729 case '.':
2730 /* Might be a floating point number. */
5776fca3 2731 if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9')
65d12d83 2732 {
59498c30 2733 last_was_structop = true;
65d12d83
TT
2734 goto symbol; /* Nope, must be a symbol. */
2735 }
86a73007 2736 /* FALL THRU. */
c906108c
SS
2737
2738 case '0':
2739 case '1':
2740 case '2':
2741 case '3':
2742 case '4':
2743 case '5':
2744 case '6':
2745 case '7':
2746 case '8':
2747 case '9':
2748 {
2749 /* It's a number. */
2750 int got_dot = 0, got_e = 0, toktype;
d7561cbb 2751 const char *p = tokstart;
c906108c
SS
2752 int hex = input_radix > 10;
2753
2754 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
2755 {
2756 p += 2;
2757 hex = 1;
2758 }
2759 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
2760 {
2761 p += 2;
2762 hex = 0;
2763 }
2764
2765 for (;; ++p)
2766 {
2767 /* This test includes !hex because 'e' is a valid hex digit
2768 and thus does not indicate a floating point number when
2769 the radix is hex. */
2770 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2771 got_dot = got_e = 1;
2772 /* This test does not include !hex, because a '.' always indicates
2773 a decimal floating point number regardless of the radix. */
2774 else if (!got_dot && *p == '.')
2775 got_dot = 1;
2776 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2777 && (*p == '-' || *p == '+'))
2778 /* This is the sign of the exponent, not the end of the
2779 number. */
2780 continue;
2781 /* We will take any letters or digits. parse_number will
2782 complain if past the radix, or if L or U are not final. */
2783 else if ((*p < '0' || *p > '9')
2784 && ((*p < 'a' || *p > 'z')
2785 && (*p < 'A' || *p > 'Z')))
2786 break;
2787 }
410a0ff2
SDJ
2788 toktype = parse_number (par_state, tokstart, p - tokstart,
2789 got_dot|got_e, &yylval);
c906108c
SS
2790 if (toktype == ERROR)
2791 {
2792 char *err_copy = (char *) alloca (p - tokstart + 1);
2793
2794 memcpy (err_copy, tokstart, p - tokstart);
2795 err_copy[p - tokstart] = 0;
001083c6 2796 error (_("Invalid number \"%s\"."), err_copy);
c906108c 2797 }
5776fca3 2798 pstate->lexptr = p;
c906108c
SS
2799 return toktype;
2800 }
2801
941b2081
JK
2802 case '@':
2803 {
d7561cbb 2804 const char *p = &tokstart[1];
941b2081 2805
73923d7e 2806 if (par_state->language ()->la_language == language_objc)
f2e8016f
TT
2807 {
2808 size_t len = strlen ("selector");
2809
2810 if (strncmp (p, "selector", len) == 0
b1b60145 2811 && (p[len] == '\0' || ISSPACE (p[len])))
f2e8016f 2812 {
5776fca3 2813 pstate->lexptr = p + len;
f2e8016f
TT
2814 return SELECTOR;
2815 }
2816 else if (*p == '"')
2817 goto parse_string;
2818 }
2819
b1b60145 2820 while (ISSPACE (*p))
941b2081 2821 p++;
b926417a 2822 size_t len = strlen ("entry");
b1b60145 2823 if (strncmp (p, "entry", len) == 0 && !c_ident_is_alnum (p[len])
941b2081
JK
2824 && p[len] != '_')
2825 {
5776fca3 2826 pstate->lexptr = &p[len];
941b2081
JK
2827 return ENTRY;
2828 }
2829 }
2830 /* FALLTHRU */
c906108c
SS
2831 case '+':
2832 case '-':
2833 case '*':
2834 case '/':
2835 case '%':
2836 case '|':
2837 case '&':
2838 case '^':
2839 case '~':
2840 case '!':
c906108c
SS
2841 case '<':
2842 case '>':
c906108c
SS
2843 case '?':
2844 case ':':
2845 case '=':
2846 case '{':
2847 case '}':
2848 symbol:
5776fca3 2849 pstate->lexptr++;
c906108c
SS
2850 return c;
2851
6c7a06a3
TT
2852 case 'L':
2853 case 'u':
2854 case 'U':
2855 if (tokstart[1] != '"' && tokstart[1] != '\'')
2856 break;
2857 /* Fall through. */
2858 case '\'':
c906108c 2859 case '"':
f2e8016f
TT
2860
2861 parse_string:
6c7a06a3
TT
2862 {
2863 int host_len;
5776fca3
TT
2864 int result = parse_string_or_char (tokstart, &pstate->lexptr,
2865 &yylval.tsval, &host_len);
6c7a06a3 2866 if (result == CHAR)
c906108c 2867 {
6c7a06a3 2868 if (host_len == 0)
001083c6 2869 error (_("Empty character constant."));
6c7a06a3 2870 else if (host_len > 2 && c == '\'')
c906108c 2871 {
6c7a06a3 2872 ++tokstart;
5776fca3 2873 namelen = pstate->lexptr - tokstart - 1;
59498c30 2874 *is_quoted_name = true;
805e1f19 2875
6c7a06a3 2876 goto tryname;
c906108c 2877 }
6c7a06a3 2878 else if (host_len > 1)
001083c6 2879 error (_("Invalid character constant."));
c906108c 2880 }
6c7a06a3
TT
2881 return result;
2882 }
c906108c
SS
2883 }
2884
b1b60145 2885 if (!(c == '_' || c == '$' || c_ident_is_alpha (c)))
c906108c 2886 /* We must have come across a bad character (e.g. ';'). */
001083c6 2887 error (_("Invalid character '%c' in expression."), c);
c906108c
SS
2888
2889 /* It's a name. See how long it is. */
2890 namelen = 0;
2891 for (c = tokstart[namelen];
b1b60145 2892 (c == '_' || c == '$' || c_ident_is_alnum (c) || c == '<');)
c906108c
SS
2893 {
2894 /* Template parameter lists are part of the name.
2895 FIXME: This mishandles `print $a<4&&$a>3'. */
2896
2897 if (c == '<')
4e8f195d
TT
2898 {
2899 if (! is_cast_operator (tokstart, namelen))
2900 {
2901 /* Scan ahead to get rest of the template specification. Note
2902 that we look ahead only when the '<' adjoins non-whitespace
2903 characters; for comparison expressions, e.g. "a < b > c",
2904 there must be spaces before the '<', etc. */
d7561cbb
KS
2905 const char *p = find_template_name_end (tokstart + namelen);
2906
4e8f195d
TT
2907 if (p)
2908 namelen = p - tokstart;
2909 }
2910 break;
c906108c
SS
2911 }
2912 c = tokstart[++namelen];
2913 }
2914
84f0252a
JB
2915 /* The token "if" terminates the expression and is NOT removed from
2916 the input stream. It doesn't count if it appears in the
2917 expansion of a macro. */
2918 if (namelen == 2
2919 && tokstart[0] == 'i'
2920 && tokstart[1] == 'f'
2921 && ! scanning_macro_expansion ())
c906108c
SS
2922 {
2923 return 0;
2924 }
2925
b6199126
DJ
2926 /* For the same reason (breakpoint conditions), "thread N"
2927 terminates the expression. "thread" could be an identifier, but
2928 an identifier is never followed by a number without intervening
2929 punctuation. "task" is similar. Handle abbreviations of these,
2930 similarly to breakpoint.c:find_condition_and_thread. */
2931 if (namelen >= 1
2932 && (strncmp (tokstart, "thread", namelen) == 0
2933 || strncmp (tokstart, "task", namelen) == 0)
2934 && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
2935 && ! scanning_macro_expansion ())
2936 {
d7561cbb
KS
2937 const char *p = tokstart + namelen + 1;
2938
b6199126
DJ
2939 while (*p == ' ' || *p == '\t')
2940 p++;
2941 if (*p >= '0' && *p <= '9')
2942 return 0;
2943 }
2944
5776fca3 2945 pstate->lexptr += namelen;
c906108c
SS
2946
2947 tryname:
2948
c906108c
SS
2949 yylval.sval.ptr = tokstart;
2950 yylval.sval.length = namelen;
2951
ba163c7e 2952 /* Catch specific keywords. */
61f4b350 2953 std::string copy = copy_name (yylval.sval);
ba163c7e 2954 for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
61f4b350 2955 if (copy == ident_tokens[i].oper)
ba163c7e 2956 {
274b54d7 2957 if ((ident_tokens[i].flags & FLAG_CXX) != 0
73923d7e 2958 && par_state->language ()->la_language != language_cplus)
ba163c7e 2959 break;
3293bbaf
TT
2960 if ((ident_tokens[i].flags & FLAG_C) != 0
2961 && par_state->language ()->la_language != language_c
2962 && par_state->language ()->la_language != language_objc)
2963 break;
ba163c7e 2964
274b54d7
TT
2965 if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
2966 {
1993b719 2967 struct field_of_this_result is_a_field_of_this;
274b54d7 2968
61f4b350 2969 if (lookup_symbol (copy.c_str (),
1e58a4a4 2970 pstate->expression_context_block,
274b54d7 2971 VAR_DOMAIN,
73923d7e 2972 (par_state->language ()->la_language
410a0ff2 2973 == language_cplus ? &is_a_field_of_this
d12307c1 2974 : NULL)).symbol
274b54d7
TT
2975 != NULL)
2976 {
2977 /* The keyword is shadowed. */
2978 break;
2979 }
2980 }
2981
ba163c7e
TT
2982 /* It is ok to always set this, even though we don't always
2983 strictly need to. */
2984 yylval.opcode = ident_tokens[i].opcode;
2985 return ident_tokens[i].token;
2986 }
2987
c906108c 2988 if (*tokstart == '$')
cfeadda5 2989 return DOLLAR_VARIABLE;
48e32051 2990
2a612529 2991 if (pstate->parse_completion && *pstate->lexptr == '\0')
48e32051 2992 saw_name_at_eof = 1;
e234dfaf
TT
2993
2994 yylval.ssym.stoken = yylval.sval;
d12307c1
PMR
2995 yylval.ssym.sym.symbol = NULL;
2996 yylval.ssym.sym.block = NULL;
e234dfaf 2997 yylval.ssym.is_a_field_of_this = 0;
48e32051
TT
2998 return NAME;
2999}
3000
3001/* An object of this type is pushed on a FIFO by the "outer" lexer. */
5fe3f3e4 3002struct token_and_value
48e32051
TT
3003{
3004 int token;
e707a91d 3005 YYSTYPE value;
5fe3f3e4 3006};
48e32051
TT
3007
3008/* A FIFO of tokens that have been read but not yet returned to the
3009 parser. */
5fe3f3e4 3010static std::vector<token_and_value> token_fifo;
48e32051
TT
3011
3012/* Non-zero if the lexer should return tokens from the FIFO. */
3013static int popping;
3014
3015/* Temporary storage for c_lex; this holds symbol names as they are
3016 built up. */
8268c778 3017auto_obstack name_obstack;
48e32051
TT
3018
3019/* Classify a NAME token. The contents of the token are in `yylval'.
3020 Updates yylval and returns the new token type. BLOCK is the block
805e1f19
TT
3021 in which lookups start; this can be NULL to mean the global scope.
3022 IS_QUOTED_NAME is non-zero if the name token was originally quoted
59498c30
LS
3023 in single quotes. IS_AFTER_STRUCTOP is true if this name follows
3024 a structure operator -- either '.' or ARROW */
4d29c0a8 3025
48e32051 3026static int
410a0ff2 3027classify_name (struct parser_state *par_state, const struct block *block,
59498c30 3028 bool is_quoted_name, bool is_after_structop)
48e32051 3029{
d12307c1 3030 struct block_symbol bsym;
1993b719 3031 struct field_of_this_result is_a_field_of_this;
48e32051 3032
61f4b350 3033 std::string copy = copy_name (yylval.sval);
48e32051 3034
1993b719
TT
3035 /* Initialize this in case we *don't* use it in this call; that way
3036 we can refer to it unconditionally below. */
3037 memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
3038
61f4b350 3039 bsym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN,
73923d7e 3040 par_state->language ()->la_name_of_this
d12307c1 3041 ? &is_a_field_of_this : NULL);
48e32051 3042
d12307c1 3043 if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK)
c906108c 3044 {
d12307c1 3045 yylval.ssym.sym = bsym;
1993b719 3046 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
48e32051 3047 return BLOCKNAME;
c906108c 3048 }
d12307c1 3049 else if (!bsym.symbol)
48e32051 3050 {
6592e36f
TT
3051 /* If we found a field of 'this', we might have erroneously
3052 found a constructor where we wanted a type name. Handle this
3053 case by noticing that we found a constructor and then look up
3054 the type tag instead. */
3055 if (is_a_field_of_this.type != NULL
3056 && is_a_field_of_this.fn_field != NULL
3057 && TYPE_FN_FIELD_CONSTRUCTOR (is_a_field_of_this.fn_field->fn_fields,
3058 0))
3059 {
3060 struct field_of_this_result inner_is_a_field_of_this;
3061
61f4b350 3062 bsym = lookup_symbol (copy.c_str (), block, STRUCT_DOMAIN,
d12307c1
PMR
3063 &inner_is_a_field_of_this);
3064 if (bsym.symbol != NULL)
6592e36f 3065 {
d12307c1 3066 yylval.tsym.type = SYMBOL_TYPE (bsym.symbol);
6592e36f
TT
3067 return TYPENAME;
3068 }
3069 }
805e1f19 3070
59498c30
LS
3071 /* If we found a field on the "this" object, or we are looking
3072 up a field on a struct, then we want to prefer it over a
805e1f19
TT
3073 filename. However, if the name was quoted, then it is better
3074 to check for a filename or a block, since this is the only
3075 way the user has of requiring the extension to be used. */
59498c30
LS
3076 if ((is_a_field_of_this.type == NULL && !is_after_structop)
3077 || is_quoted_name)
805e1f19
TT
3078 {
3079 /* See if it's a file name. */
3080 struct symtab *symtab;
3081
61f4b350 3082 symtab = lookup_symtab (copy.c_str ());
805e1f19
TT
3083 if (symtab)
3084 {
439247b6 3085 yylval.bval = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab),
805e1f19
TT
3086 STATIC_BLOCK);
3087 return FILENAME;
3088 }
3089 }
48e32051 3090 }
c906108c 3091
d12307c1 3092 if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_TYPEDEF)
48e32051 3093 {
d12307c1 3094 yylval.tsym.type = SYMBOL_TYPE (bsym.symbol);
47663de5 3095 return TYPENAME;
48e32051 3096 }
c906108c 3097
f2e8016f 3098 /* See if it's an ObjC classname. */
73923d7e 3099 if (par_state->language ()->la_language == language_objc && !bsym.symbol)
f2e8016f 3100 {
61f4b350
TT
3101 CORE_ADDR Class = lookup_objc_class (par_state->gdbarch (),
3102 copy.c_str ());
f2e8016f
TT
3103 if (Class)
3104 {
d12307c1
PMR
3105 struct symbol *sym;
3106
fe978cb0 3107 yylval.theclass.theclass = Class;
61f4b350 3108 sym = lookup_struct_typedef (copy.c_str (),
1e58a4a4 3109 par_state->expression_context_block, 1);
826f0041 3110 if (sym)
fe978cb0 3111 yylval.theclass.type = SYMBOL_TYPE (sym);
f2e8016f
TT
3112 return CLASSNAME;
3113 }
3114 }
3115
48e32051
TT
3116 /* Input names that aren't symbols but ARE valid hex numbers, when
3117 the input radix permits them, can be names or numbers depending
3118 on the parse. Note we support radixes > 16 here. */
d12307c1 3119 if (!bsym.symbol
48e32051
TT
3120 && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
3121 || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
3122 {
3123 YYSTYPE newlval; /* Its value is ignored. */
61f4b350 3124 int hextype = parse_number (par_state, copy.c_str (), yylval.sval.length,
410a0ff2 3125 0, &newlval);
d12307c1 3126
48e32051
TT
3127 if (hextype == INT)
3128 {
d12307c1 3129 yylval.ssym.sym = bsym;
1993b719 3130 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
48e32051
TT
3131 return NAME_OR_INT;
3132 }
3133 }
3134
3135 /* Any other kind of symbol */
d12307c1 3136 yylval.ssym.sym = bsym;
1993b719 3137 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
7322dca9 3138
d12307c1 3139 if (bsym.symbol == NULL
73923d7e 3140 && par_state->language ()->la_language == language_cplus
1993b719 3141 && is_a_field_of_this.type == NULL
61f4b350 3142 && lookup_minimal_symbol (copy.c_str (), NULL, NULL).minsym == NULL)
7322dca9
SW
3143 return UNKNOWN_CPP_NAME;
3144
48e32051
TT
3145 return NAME;
3146}
c906108c 3147
48e32051 3148/* Like classify_name, but used by the inner loop of the lexer, when a
e234dfaf
TT
3149 name might have already been seen. CONTEXT is the context type, or
3150 NULL if this is the first component of a name. */
50af5481 3151
48e32051 3152static int
410a0ff2
SDJ
3153classify_inner_name (struct parser_state *par_state,
3154 const struct block *block, struct type *context)
48e32051 3155{
df54f8eb 3156 struct type *type;
48e32051 3157
e234dfaf 3158 if (context == NULL)
59498c30 3159 return classify_name (par_state, block, false, false);
48e32051 3160
e234dfaf 3161 type = check_typedef (context);
3d567982 3162 if (!type_aggregate_p (type))
50af5481 3163 return ERROR;
48e32051 3164
61f4b350 3165 std::string copy = copy_name (yylval.ssym.stoken);
4dcabcc2 3166 /* N.B. We assume the symbol can only be in VAR_DOMAIN. */
61f4b350
TT
3167 yylval.ssym.sym = cp_lookup_nested_symbol (type, copy.c_str (), block,
3168 VAR_DOMAIN);
f7e3ecae
KS
3169
3170 /* If no symbol was found, search for a matching base class named
3171 COPY. This will allow users to enter qualified names of class members
3172 relative to the `this' pointer. */
d12307c1 3173 if (yylval.ssym.sym.symbol == NULL)
f7e3ecae 3174 {
61f4b350
TT
3175 struct type *base_type = cp_find_type_baseclass_by_name (type,
3176 copy.c_str ());
f7e3ecae
KS
3177
3178 if (base_type != NULL)
3179 {
3180 yylval.tsym.type = base_type;
3181 return TYPENAME;
3182 }
3183
3184 return ERROR;
3185 }
50af5481 3186
d12307c1 3187 switch (SYMBOL_CLASS (yylval.ssym.sym.symbol))
50af5481
JK
3188 {
3189 case LOC_BLOCK:
3190 case LOC_LABEL:
f7e3ecae
KS
3191 /* cp_lookup_nested_symbol might have accidentally found a constructor
3192 named COPY when we really wanted a base class of the same name.
3193 Double-check this case by looking for a base class. */
3194 {
61f4b350
TT
3195 struct type *base_type
3196 = cp_find_type_baseclass_by_name (type, copy.c_str ());
f7e3ecae
KS
3197
3198 if (base_type != NULL)
3199 {
3200 yylval.tsym.type = base_type;
3201 return TYPENAME;
3202 }
3203 }
50af5481 3204 return ERROR;
48e32051 3205
50af5481 3206 case LOC_TYPEDEF:
d12307c1 3207 yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym.symbol);
50af5481 3208 return TYPENAME;
48e32051 3209
50af5481 3210 default:
50af5481
JK
3211 return NAME;
3212 }
3213 internal_error (__FILE__, __LINE__, _("not reached"));
48e32051
TT
3214}
3215
3216/* The outer level of a two-level lexer. This calls the inner lexer
3217 to return tokens. It then either returns these tokens, or
3218 aggregates them into a larger token. This lets us work around a
3219 problem in our parsing approach, where the parser could not
3220 distinguish between qualified names and qualified types at the
3221 right point.
4d29c0a8 3222
48e32051
TT
3223 This approach is still not ideal, because it mishandles template
3224 types. See the comment in lex_one_token for an example. However,
3225 this is still an improvement over the earlier approach, and will
3226 suffice until we move to better parsing technology. */
4d29c0a8 3227
48e32051
TT
3228static int
3229yylex (void)
3230{
3231 token_and_value current;
b2f83c08 3232 int first_was_coloncolon, last_was_coloncolon;
e234dfaf 3233 struct type *context_type = NULL;
b2f83c08
TT
3234 int last_to_examine, next_to_examine, checkpoint;
3235 const struct block *search_block;
59498c30 3236 bool is_quoted_name, last_lex_was_structop;
48e32051 3237
5fe3f3e4 3238 if (popping && !token_fifo.empty ())
b2f83c08 3239 goto do_pop;
48e32051
TT
3240 popping = 0;
3241
59498c30
LS
3242 last_lex_was_structop = last_was_structop;
3243
b2f83c08
TT
3244 /* Read the first token and decide what to do. Most of the
3245 subsequent code is C++-only; but also depends on seeing a "::" or
3246 name-like token. */
410a0ff2 3247 current.token = lex_one_token (pstate, &is_quoted_name);
48e32051 3248 if (current.token == NAME)
1e58a4a4 3249 current.token = classify_name (pstate, pstate->expression_context_block,
59498c30 3250 is_quoted_name, last_lex_was_structop);
73923d7e 3251 if (pstate->language ()->la_language != language_cplus
b2f83c08
TT
3252 || (current.token != TYPENAME && current.token != COLONCOLON
3253 && current.token != FILENAME))
48e32051
TT
3254 return current.token;
3255
b2f83c08
TT
3256 /* Read any sequence of alternating "::" and name-like tokens into
3257 the token FIFO. */
3258 current.value = yylval;
5fe3f3e4 3259 token_fifo.push_back (current);
b2f83c08
TT
3260 last_was_coloncolon = current.token == COLONCOLON;
3261 while (1)
3262 {
59498c30 3263 bool ignore;
805e1f19
TT
3264
3265 /* We ignore quoted names other than the very first one.
3266 Subsequent ones do not have any special meaning. */
410a0ff2 3267 current.token = lex_one_token (pstate, &ignore);
b2f83c08 3268 current.value = yylval;
5fe3f3e4 3269 token_fifo.push_back (current);
b2f83c08
TT
3270
3271 if ((last_was_coloncolon && current.token != NAME)
3272 || (!last_was_coloncolon && current.token != COLONCOLON))
3273 break;
3274 last_was_coloncolon = !last_was_coloncolon;
3275 }
3276 popping = 1;
3277
3278 /* We always read one extra token, so compute the number of tokens
3279 to examine accordingly. */
5fe3f3e4 3280 last_to_examine = token_fifo.size () - 2;
b2f83c08
TT
3281 next_to_examine = 0;
3282
5fe3f3e4 3283 current = token_fifo[next_to_examine];
b2f83c08
TT
3284 ++next_to_examine;
3285
8268c778 3286 name_obstack.clear ();
b2f83c08
TT
3287 checkpoint = 0;
3288 if (current.token == FILENAME)
3289 search_block = current.value.bval;
3290 else if (current.token == COLONCOLON)
3291 search_block = NULL;
3292 else
e234dfaf 3293 {
b2f83c08 3294 gdb_assert (current.token == TYPENAME);
1e58a4a4 3295 search_block = pstate->expression_context_block;
b2f83c08
TT
3296 obstack_grow (&name_obstack, current.value.sval.ptr,
3297 current.value.sval.length);
3298 context_type = current.value.tsym.type;
3299 checkpoint = 1;
e234dfaf 3300 }
b2f83c08
TT
3301
3302 first_was_coloncolon = current.token == COLONCOLON;
3303 last_was_coloncolon = first_was_coloncolon;
3304
3305 while (next_to_examine <= last_to_examine)
48e32051 3306 {
5fe3f3e4 3307 token_and_value next;
48e32051 3308
5fe3f3e4 3309 next = token_fifo[next_to_examine];
b2f83c08 3310 ++next_to_examine;
48e32051 3311
5fe3f3e4 3312 if (next.token == NAME && last_was_coloncolon)
48e32051
TT
3313 {
3314 int classification;
3315
5fe3f3e4 3316 yylval = next.value;
410a0ff2
SDJ
3317 classification = classify_inner_name (pstate, search_block,
3318 context_type);
48e32051
TT
3319 /* We keep going until we either run out of names, or until
3320 we have a qualified name which is not a type. */
50af5481 3321 if (classification != TYPENAME && classification != NAME)
b2f83c08
TT
3322 break;
3323
3324 /* Accept up to this token. */
3325 checkpoint = next_to_examine;
48e32051
TT
3326
3327 /* Update the partial name we are constructing. */
e234dfaf 3328 if (context_type != NULL)
48e32051
TT
3329 {
3330 /* We don't want to put a leading "::" into the name. */
3331 obstack_grow_str (&name_obstack, "::");
3332 }
5fe3f3e4
TT
3333 obstack_grow (&name_obstack, next.value.sval.ptr,
3334 next.value.sval.length);
48e32051 3335
79f33898 3336 yylval.sval.ptr = (const char *) obstack_base (&name_obstack);
48e32051
TT
3337 yylval.sval.length = obstack_object_size (&name_obstack);
3338 current.value = yylval;
3339 current.token = classification;
3340
3341 last_was_coloncolon = 0;
4d29c0a8 3342
e234dfaf
TT
3343 if (classification == NAME)
3344 break;
3345
3346 context_type = yylval.tsym.type;
48e32051 3347 }
5fe3f3e4 3348 else if (next.token == COLONCOLON && !last_was_coloncolon)
48e32051
TT
3349 last_was_coloncolon = 1;
3350 else
3351 {
3352 /* We've reached the end of the name. */
48e32051
TT
3353 break;
3354 }
48e32051
TT
3355 }
3356
b2f83c08
TT
3357 /* If we have a replacement token, install it as the first token in
3358 the FIFO, and delete the other constituent tokens. */
3359 if (checkpoint > 0)
48e32051 3360 {
224c3ddb 3361 current.value.sval.ptr
0cf9feb9
TT
3362 = obstack_strndup (&cpstate->expansion_obstack,
3363 current.value.sval.ptr,
3364 current.value.sval.length);
b2f83c08 3365
5fe3f3e4 3366 token_fifo[0] = current;
b2f83c08 3367 if (checkpoint > 1)
5fe3f3e4
TT
3368 token_fifo.erase (token_fifo.begin () + 1,
3369 token_fifo.begin () + checkpoint);
48e32051
TT
3370 }
3371
b2f83c08 3372 do_pop:
5fe3f3e4
TT
3373 current = token_fifo[0];
3374 token_fifo.erase (token_fifo.begin ());
48e32051 3375 yylval = current.value;
48e32051 3376 return current.token;
c906108c
SS
3377}
3378
65d12d83 3379int
410a0ff2 3380c_parse (struct parser_state *par_state)
65d12d83 3381{
410a0ff2 3382 /* Setting up the parser state. */
eae49211 3383 scoped_restore pstate_restore = make_scoped_restore (&pstate);
410a0ff2
SDJ
3384 gdb_assert (par_state != NULL);
3385 pstate = par_state;
3386
02e12e38
TT
3387 c_parse_state cstate;
3388 scoped_restore cstate_restore = make_scoped_restore (&cpstate, &cstate);
3389
f6c2623e 3390 gdb::unique_xmalloc_ptr<struct macro_scope> macro_scope;
7c8adf68 3391
1e58a4a4
TT
3392 if (par_state->expression_context_block)
3393 macro_scope
3394 = sal_macro_scope (find_pc_line (par_state->expression_context_pc, 0));
7c8adf68 3395 else
f6c2623e
TT
3396 macro_scope = default_macro_scope ();
3397 if (! macro_scope)
3398 macro_scope = user_macro_scope ();
3399
3400 scoped_restore restore_macro_scope
3401 = make_scoped_restore (&expression_macro_scope, macro_scope.get ());
7c8adf68 3402
156d9eab
TT
3403 scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
3404 parser_debug);
92981e24 3405
7c8adf68 3406 /* Initialize some state used by the lexer. */
59498c30 3407 last_was_structop = false;
65d12d83 3408 saw_name_at_eof = 0;
28aaf3fd 3409 paren_depth = 0;
7c8adf68 3410
5fe3f3e4 3411 token_fifo.clear ();
48e32051 3412 popping = 0;
8268c778 3413 name_obstack.clear ();
48e32051 3414
9d30e1fd 3415 return yyparse ();
65d12d83
TT
3416}
3417
12c5175d
MK
3418#ifdef YYBISON
3419
9507860e
TT
3420/* This is called via the YYPRINT macro when parser debugging is
3421 enabled. It prints a token's value. */
3422
3423static void
3424c_print_token (FILE *file, int type, YYSTYPE value)
3425{
3426 switch (type)
3427 {
3428 case INT:
66be918f
PA
3429 parser_fprintf (file, "typed_val_int<%s, %s>",
3430 TYPE_SAFE_NAME (value.typed_val_int.type),
3431 pulongest (value.typed_val_int.val));
9507860e
TT
3432 break;
3433
3434 case CHAR:
3435 case STRING:
3436 {
224c3ddb 3437 char *copy = (char *) alloca (value.tsval.length + 1);
9507860e
TT
3438
3439 memcpy (copy, value.tsval.ptr, value.tsval.length);
3440 copy[value.tsval.length] = '\0';
3441
66be918f 3442 parser_fprintf (file, "tsval<type=%d, %s>", value.tsval.type, copy);
9507860e
TT
3443 }
3444 break;
3445
3446 case NSSTRING:
cfeadda5 3447 case DOLLAR_VARIABLE:
61f4b350 3448 parser_fprintf (file, "sval<%s>", copy_name (value.sval).c_str ());
9507860e
TT
3449 break;
3450
3451 case TYPENAME:
66be918f
PA
3452 parser_fprintf (file, "tsym<type=%s, name=%s>",
3453 TYPE_SAFE_NAME (value.tsym.type),
61f4b350 3454 copy_name (value.tsym.stoken).c_str ());
9507860e
TT
3455 break;
3456
3457 case NAME:
3458 case UNKNOWN_CPP_NAME:
3459 case NAME_OR_INT:
3460 case BLOCKNAME:
66be918f 3461 parser_fprintf (file, "ssym<name=%s, sym=%s, field_of_this=%d>",
61f4b350 3462 copy_name (value.ssym.stoken).c_str (),
66be918f 3463 (value.ssym.sym.symbol == NULL
987012b8 3464 ? "(null)" : value.ssym.sym.symbol->print_name ()),
66be918f 3465 value.ssym.is_a_field_of_this);
9507860e
TT
3466 break;
3467
3468 case FILENAME:
66be918f 3469 parser_fprintf (file, "bval<%s>", host_address_to_string (value.bval));
9507860e
TT
3470 break;
3471 }
3472}
7c8adf68 3473
12c5175d
MK
3474#endif
3475
69d340c6 3476static void
a121b7c1 3477yyerror (const char *msg)
c906108c 3478{
5776fca3
TT
3479 if (pstate->prev_lexptr)
3480 pstate->lexptr = pstate->prev_lexptr;
665132f9 3481
5776fca3 3482 error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
c906108c 3483}
This page took 1.623988 seconds and 4 git commands to generate.