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