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