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