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