gdb/c-exp.y - gdb

  1. /* YACC parser for C expressions, for GDB.
  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. /* Parse a C expression from text in a string,
  15.    and return the result as a  struct expression  pointer.
  16.    That structure contains arithmetic operations in reverse polish,
  17.    with constants represented by operations that are followed by special data.
  18.    See expression.h for the details of the format.
  19.    What is important here is that it can be built up sequentially
  20.    during the process of parsing; the lower levels of the tree always
  21.    come first in the result.

  22.    Note that malloc's and realloc's in this file are transformed to
  23.    xmalloc and xrealloc respectively by the same sed command in the
  24.    makefile that remaps any other malloc/realloc inserted by the parser
  25.    generator.  Doing this with #defines and trying to control the interaction
  26.    with include files (<malloc.h> and <stdlib.h> for example) just became
  27.    too messy, particularly when such includes can be inserted at random
  28.    times by the parser generator.  */

  29. %{

  30. #include "defs.h"
  31. #include <ctype.h>
  32. #include "expression.h"
  33. #include "value.h"
  34. #include "parser-defs.h"
  35. #include "language.h"
  36. #include "c-lang.h"
  37. #include "bfd.h" /* Required by objfiles.h.  */
  38. #include "symfile.h" /* Required by objfiles.h.  */
  39. #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
  40. #include "charset.h"
  41. #include "block.h"
  42. #include "cp-support.h"
  43. #include "dfp.h"
  44. #include "macroscope.h"
  45. #include "objc-lang.h"
  46. #include "typeprint.h"
  47. #include "cp-abi.h"

  48. #define parse_type(ps) builtin_type (parse_gdbarch (ps))

  49. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  50.    as well as gratuitiously global symbol names, so we can have multiple
  51.    yacc generated parsers in gdb.  Note that these are only the variables
  52.    produced by yacc.  If other parser generators (bison, byacc, etc) produce
  53.    additional global names that conflict at link time, then those parser
  54.    generators need to be fixed instead of adding those names to this list. */

  55. #define        yymaxdepth c_maxdepth
  56. #define        yyparse        c_parse_internal
  57. #define        yylex        c_lex
  58. #define        yyerror        c_error
  59. #define        yylval        c_lval
  60. #define        yychar        c_char
  61. #define        yydebug        c_debug
  62. #define        yypact        c_pact
  63. #define        yyr1        c_r1
  64. #define        yyr2        c_r2
  65. #define        yydef        c_def
  66. #define        yychk        c_chk
  67. #define        yypgo        c_pgo
  68. #define        yyact        c_act
  69. #define        yyexca        c_exca
  70. #define yyerrflag c_errflag
  71. #define yynerrs        c_nerrs
  72. #define        yyps        c_ps
  73. #define        yypv        c_pv
  74. #define        yys        c_s
  75. #define        yy_yys        c_yys
  76. #define        yystate        c_state
  77. #define        yytmp        c_tmp
  78. #define        yyv        c_v
  79. #define        yy_yyv        c_yyv
  80. #define        yyval        c_val
  81. #define        yylloc        c_lloc
  82. #define yyreds        c_reds                /* With YYDEBUG defined */
  83. #define yytoks        c_toks                /* With YYDEBUG defined */
  84. #define yyname        c_name                /* With YYDEBUG defined */
  85. #define yyrule        c_rule                /* With YYDEBUG defined */
  86. #define yylhs        c_yylhs
  87. #define yylen        c_yylen
  88. #define yydefred c_yydefred
  89. #define yydgoto        c_yydgoto
  90. #define yysindex c_yysindex
  91. #define yyrindex c_yyrindex
  92. #define yygindex c_yygindex
  93. #define yytable         c_yytable
  94. #define yycheck         c_yycheck
  95. #define yyss        c_yyss
  96. #define yysslim        c_yysslim
  97. #define yyssp        c_yyssp
  98. #define yystacksize c_yystacksize
  99. #define yyvs        c_yyvs
  100. #define yyvsp        c_yyvsp

  101. #ifndef YYDEBUG
  102. #define        YYDEBUG 1                /* Default to yydebug support */
  103. #endif

  104. #define YYFPRINTF parser_fprintf

  105. /* The state of the parser, used internally when we are parsing the
  106.    expression.  */

  107. static struct parser_state *pstate = NULL;

  108. int yyparse (void);

  109. static int yylex (void);

  110. void yyerror (char *);

  111. static int type_aggregate_p (struct type *);

  112. %}

  113. /* Although the yacc "value" of an expression is not used,
  114.    since the result is stored in the structure being created,
  115.    other node types do have values.  */

  116. %union
  117.   {
  118.     LONGEST lval;
  119.     struct {
  120.       LONGEST val;
  121.       struct type *type;
  122.     } typed_val_int;
  123.     struct {
  124.       DOUBLEST dval;
  125.       struct type *type;
  126.     } typed_val_float;
  127.     struct {
  128.       gdb_byte val[16];
  129.       struct type *type;
  130.     } typed_val_decfloat;
  131.     struct type *tval;
  132.     struct stoken sval;
  133.     struct typed_stoken tsval;
  134.     struct ttype tsym;
  135.     struct symtoken ssym;
  136.     int voidval;
  137.     const struct block *bval;
  138.     enum exp_opcode opcode;

  139.     struct stoken_vector svec;
  140.     VEC (type_ptr) *tvec;

  141.     struct type_stack *type_stack;

  142.     struct objc_class_str class;
  143.   }

  144. %{
  145. /* YYSTYPE gets defined by %union */
  146. static int parse_number (struct parser_state *par_state,
  147.                          const char *, int, int, YYSTYPE *);
  148. static struct stoken operator_stoken (const char *);
  149. static void check_parameter_typelist (VEC (type_ptr) *);
  150. static void write_destructor_name (struct parser_state *par_state,
  151.                                    struct stoken);

  152. #ifdef YYBISON
  153. static void c_print_token (FILE *file, int type, YYSTYPE value);
  154. #define YYPRINT(FILE, TYPE, VALUE) c_print_token (FILE, TYPE, VALUE)
  155. #endif
  156. %}

  157. %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
  158. %type <lval> rcurly
  159. %type <tval> type typebase
  160. %type <tvec> nonempty_typelist func_mod parameter_typelist
  161. /* %type <bval> block */

  162. /* Fancy type parsing.  */
  163. %type <tval> ptype
  164. %type <lval> array_mod
  165. %type <tval> conversion_type_id

  166. %type <type_stack> ptr_operator_ts abs_decl direct_abs_decl

  167. %token <typed_val_int> INT
  168. %token <typed_val_float> FLOAT
  169. %token <typed_val_decfloat> DECFLOAT

  170. /* Both NAME and TYPENAME tokens represent symbols in the input,
  171.    and both convey their data as strings.
  172.    But a TYPENAME is a string that happens to be defined as a typedef
  173.    or builtin type name (such as int or char)
  174.    and a NAME is any other symbol.
  175.    Contexts where this distinction is not important can use the
  176.    nonterminal "name", which matches either NAME or TYPENAME.  */

  177. %token <tsval> STRING
  178. %token <sval> NSSTRING                /* ObjC Foundation "NSString" literal */
  179. %token SELECTOR                        /* ObjC "@selector" pseudo-operator   */
  180. %token <tsval> CHAR
  181. %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
  182. %token <ssym> UNKNOWN_CPP_NAME
  183. %token <voidval> COMPLETE
  184. %token <tsym> TYPENAME
  185. %token <class> CLASSNAME        /* ObjC Class name */
  186. %type <sval> name
  187. %type <svec> string_exp
  188. %type <ssym> name_not_typename
  189. %type <tsym> typename

  190. /* This is like a '[' token, but is only generated when parsing
  191.     Objective C.  This lets us reuse the same parser without
  192.     erroneously parsing ObjC-specific expressions in C.  */
  193. %token OBJC_LBRAC

  194. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  195.    but which would parse as a valid number in the current input radix.
  196.    E.g. "c" when input_radix==16.  Depending on the parse, it will be
  197.    turned into a name or into a number.  */

  198. %token <ssym> NAME_OR_INT

  199. %token OPERATOR
  200. %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
  201. %token TEMPLATE
  202. %token ERROR
  203. %token NEW DELETE
  204. %type <sval> operator
  205. %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
  206. %token ENTRY
  207. %token TYPEOF
  208. %token DECLTYPE
  209. %token TYPEID

  210. /* Special type cases, put in to allow the parser to distinguish different
  211.    legal basetypes.  */
  212. %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD

  213. %token <sval> VARIABLE

  214. %token <opcode> ASSIGN_MODIFY

  215. /* C++ */
  216. %token TRUEKEYWORD
  217. %token FALSEKEYWORD


  218. %left ','
  219. %left ABOVE_COMMA
  220. %right '=' ASSIGN_MODIFY
  221. %right '?'
  222. %left OROR
  223. %left ANDAND
  224. %left '|'
  225. %left '^'
  226. %left '&'
  227. %left EQUAL NOTEQUAL
  228. %left '<' '>' LEQ GEQ
  229. %left LSH RSH
  230. %left '@'
  231. %left '+' '-'
  232. %left '*' '/' '%'
  233. %right UNARY INCREMENT DECREMENT
  234. %right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '('
  235. %token <ssym> BLOCKNAME
  236. %token <bval> FILENAME
  237. %type <bval> block
  238. %left COLONCOLON

  239. %token DOTDOTDOT


  240. %%

  241. start   :        exp1
  242.         |        type_exp
  243.         ;

  244. type_exp:        type
  245.                         { write_exp_elt_opcode(pstate, OP_TYPE);
  246.                           write_exp_elt_type(pstate, $1);
  247.                           write_exp_elt_opcode(pstate, OP_TYPE);}
  248.         |        TYPEOF '(' exp ')'
  249.                         {
  250.                           write_exp_elt_opcode (pstate, OP_TYPEOF);
  251.                         }
  252.         |        TYPEOF '(' type ')'
  253.                         {
  254.                           write_exp_elt_opcode (pstate, OP_TYPE);
  255.                           write_exp_elt_type (pstate, $3);
  256.                           write_exp_elt_opcode (pstate, OP_TYPE);
  257.                         }
  258.         |        DECLTYPE '(' exp ')'
  259.                         {
  260.                           write_exp_elt_opcode (pstate, OP_DECLTYPE);
  261.                         }
  262.         ;

  263. /* Expressions, including the comma operator.  */
  264. exp1        :        exp
  265.         |        exp1 ',' exp
  266.                         { write_exp_elt_opcode (pstate, BINOP_COMMA); }
  267.         ;

  268. /* Expressions, not including the comma operator.  */
  269. exp        :        '*' exp    %prec UNARY
  270.                         { write_exp_elt_opcode (pstate, UNOP_IND); }
  271.         ;

  272. exp        :        '&' exp    %prec UNARY
  273.                         { write_exp_elt_opcode (pstate, UNOP_ADDR); }
  274.         ;

  275. exp        :        '-' exp    %prec UNARY
  276.                         { write_exp_elt_opcode (pstate, UNOP_NEG); }
  277.         ;

  278. exp        :        '+' exp    %prec UNARY
  279.                         { write_exp_elt_opcode (pstate, UNOP_PLUS); }
  280.         ;

  281. exp        :        '!' exp    %prec UNARY
  282.                         { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
  283.         ;

  284. exp        :        '~' exp    %prec UNARY
  285.                         { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
  286.         ;

  287. exp        :        INCREMENT exp    %prec UNARY
  288.                         { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); }
  289.         ;

  290. exp        :        DECREMENT exp    %prec UNARY
  291.                         { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); }
  292.         ;

  293. exp        :        exp INCREMENT    %prec UNARY
  294.                         { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
  295.         ;

  296. exp        :        exp DECREMENT    %prec UNARY
  297.                         { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
  298.         ;

  299. exp        :        TYPEID '(' exp ')' %prec UNARY
  300.                         { write_exp_elt_opcode (pstate, OP_TYPEID); }
  301.         ;

  302. exp        :        TYPEID '(' type_exp ')' %prec UNARY
  303.                         { write_exp_elt_opcode (pstate, OP_TYPEID); }
  304.         ;

  305. exp        :        SIZEOF exp       %prec UNARY
  306.                         { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
  307.         ;

  308. exp        :        exp ARROW name
  309.                         { write_exp_elt_opcode (pstate, STRUCTOP_PTR);
  310.                           write_exp_string (pstate, $3);
  311.                           write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
  312.         ;

  313. exp        :        exp ARROW name COMPLETE
  314.                         { mark_struct_expression (pstate);
  315.                           write_exp_elt_opcode (pstate, STRUCTOP_PTR);
  316.                           write_exp_string (pstate, $3);
  317.                           write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
  318.         ;

  319. exp        :        exp ARROW COMPLETE
  320.                         { struct stoken s;
  321.                           mark_struct_expression (pstate);
  322.                           write_exp_elt_opcode (pstate, STRUCTOP_PTR);
  323.                           s.ptr = "";
  324.                           s.length = 0;
  325.                           write_exp_string (pstate, s);
  326.                           write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
  327.         ;

  328. exp        :        exp ARROW '~' name
  329.                         { write_exp_elt_opcode (pstate, STRUCTOP_PTR);
  330.                           write_destructor_name (pstate, $4);
  331.                           write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
  332.         ;

  333. exp        :        exp ARROW '~' name COMPLETE
  334.                         { mark_struct_expression (pstate);
  335.                           write_exp_elt_opcode (pstate, STRUCTOP_PTR);
  336.                           write_destructor_name (pstate, $4);
  337.                           write_exp_elt_opcode (pstate, STRUCTOP_PTR); }
  338.         ;

  339. exp        :        exp ARROW qualified_name
  340.                         { /* exp->type::name becomes exp->*(&type::name) */
  341.                           /* Note: this doesn't work if name is a
  342.                              static member!  FIXME */
  343.                           write_exp_elt_opcode (pstate, UNOP_ADDR);
  344.                           write_exp_elt_opcode (pstate, STRUCTOP_MPTR); }
  345.         ;

  346. exp        :        exp ARROW_STAR exp
  347.                         { write_exp_elt_opcode (pstate, STRUCTOP_MPTR); }
  348.         ;

  349. exp        :        exp '.' name
  350.                         { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
  351.                           write_exp_string (pstate, $3);
  352.                           write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
  353.         ;

  354. exp        :        exp '.' name COMPLETE
  355.                         { mark_struct_expression (pstate);
  356.                           write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
  357.                           write_exp_string (pstate, $3);
  358.                           write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
  359.         ;

  360. exp        :        exp '.' COMPLETE
  361.                         { struct stoken s;
  362.                           mark_struct_expression (pstate);
  363.                           write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
  364.                           s.ptr = "";
  365.                           s.length = 0;
  366.                           write_exp_string (pstate, s);
  367.                           write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
  368.         ;

  369. exp        :        exp '.' '~' name
  370.                         { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
  371.                           write_destructor_name (pstate, $4);
  372.                           write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
  373.         ;

  374. exp        :        exp '.' '~' name COMPLETE
  375.                         { mark_struct_expression (pstate);
  376.                           write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
  377.                           write_destructor_name (pstate, $4);
  378.                           write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
  379.         ;

  380. exp        :        exp '.' qualified_name
  381.                         { /* exp.type::name becomes exp.*(&type::name) */
  382.                           /* Note: this doesn't work if name is a
  383.                              static member!  FIXME */
  384.                           write_exp_elt_opcode (pstate, UNOP_ADDR);
  385.                           write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
  386.         ;

  387. exp        :        exp DOT_STAR exp
  388.                         { write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); }
  389.         ;

  390. exp        :        exp '[' exp1 ']'
  391.                         { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
  392.         ;

  393. exp        :        exp OBJC_LBRAC exp1 ']'
  394.                         { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
  395.         ;

  396. /*
  397. * The rules below parse ObjC message calls of the form:
  398. *        '[' target selector {':' argument}* ']'
  399. */

  400. exp        :         OBJC_LBRAC TYPENAME
  401.                         {
  402.                           CORE_ADDR class;

  403.                           class = lookup_objc_class (parse_gdbarch (pstate),
  404.                                                      copy_name ($2.stoken));
  405.                           if (class == 0)
  406.                             error (_("%s is not an ObjC Class"),
  407.                                    copy_name ($2.stoken));
  408.                           write_exp_elt_opcode (pstate, OP_LONG);
  409.                           write_exp_elt_type (pstate,
  410.                                             parse_type (pstate)->builtin_int);
  411.                           write_exp_elt_longcst (pstate, (LONGEST) class);
  412.                           write_exp_elt_opcode (pstate, OP_LONG);
  413.                           start_msglist();
  414.                         }
  415.                 msglist ']'
  416.                         { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
  417.                           end_msglist (pstate);
  418.                           write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
  419.                         }
  420.         ;

  421. exp        :        OBJC_LBRAC CLASSNAME
  422.                         {
  423.                           write_exp_elt_opcode (pstate, OP_LONG);
  424.                           write_exp_elt_type (pstate,
  425.                                             parse_type (pstate)->builtin_int);
  426.                           write_exp_elt_longcst (pstate, (LONGEST) $2.class);
  427.                           write_exp_elt_opcode (pstate, OP_LONG);
  428.                           start_msglist();
  429.                         }
  430.                 msglist ']'
  431.                         { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
  432.                           end_msglist (pstate);
  433.                           write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
  434.                         }
  435.         ;

  436. exp        :        OBJC_LBRAC exp
  437.                         { start_msglist(); }
  438.                 msglist ']'
  439.                         { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
  440.                           end_msglist (pstate);
  441.                           write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL);
  442.                         }
  443.         ;

  444. msglist :        name
  445.                         { add_msglist(&$1, 0); }
  446.         |        msgarglist
  447.         ;

  448. msgarglist :        msgarg
  449.         |        msgarglist msgarg
  450.         ;

  451. msgarg        :        name ':' exp
  452.                         { add_msglist(&$1, 1); }
  453.         |        ':' exp        /* Unnamed arg.  */
  454.                         { add_msglist(0, 1);   }
  455.         |        ',' exp        /* Variable number of args.  */
  456.                         { add_msglist(0, 0);   }
  457.         ;

  458. exp        :        exp '('
  459.                         /* This is to save the value of arglist_len
  460.                            being accumulated by an outer function call.  */
  461.                         { start_arglist (); }
  462.                 arglist ')'        %prec ARROW
  463.                         { write_exp_elt_opcode (pstate, OP_FUNCALL);
  464.                           write_exp_elt_longcst (pstate,
  465.                                                  (LONGEST) end_arglist ());
  466.                           write_exp_elt_opcode (pstate, OP_FUNCALL); }
  467.         ;

  468. exp        :        UNKNOWN_CPP_NAME '('
  469.                         {
  470.                           /* This could potentially be a an argument defined
  471.                              lookup function (Koenig).  */
  472.                           write_exp_elt_opcode (pstate, OP_ADL_FUNC);
  473.                           write_exp_elt_block (pstate,
  474.                                                expression_context_block);
  475.                           write_exp_elt_sym (pstate,
  476.                                              NULL); /* Placeholder.  */
  477.                           write_exp_string (pstate, $1.stoken);
  478.                           write_exp_elt_opcode (pstate, OP_ADL_FUNC);

  479.                         /* This is to save the value of arglist_len
  480.                            being accumulated by an outer function call.  */

  481.                           start_arglist ();
  482.                         }
  483.                 arglist ')'        %prec ARROW
  484.                         {
  485.                           write_exp_elt_opcode (pstate, OP_FUNCALL);
  486.                           write_exp_elt_longcst (pstate,
  487.                                                  (LONGEST) end_arglist ());
  488.                           write_exp_elt_opcode (pstate, OP_FUNCALL);
  489.                         }
  490.         ;

  491. lcurly        :        '{'
  492.                         { start_arglist (); }
  493.         ;

  494. arglist        :
  495.         ;

  496. arglist        :        exp
  497.                         { arglist_len = 1; }
  498.         ;

  499. arglist        :        arglist ',' exp   %prec ABOVE_COMMA
  500.                         { arglist_len++; }
  501.         ;

  502. exp     :       exp '(' parameter_typelist ')' const_or_volatile
  503.                         { int i;
  504.                           VEC (type_ptr) *type_list = $3;
  505.                           struct type *type_elt;
  506.                           LONGEST len = VEC_length (type_ptr, type_list);

  507.                           write_exp_elt_opcode (pstate, TYPE_INSTANCE);
  508.                           write_exp_elt_longcst (pstate, len);
  509.                           for (i = 0;
  510.                                VEC_iterate (type_ptr, type_list, i, type_elt);
  511.                                ++i)
  512.                             write_exp_elt_type (pstate, type_elt);
  513.                           write_exp_elt_longcst(pstate, len);
  514.                           write_exp_elt_opcode (pstate, TYPE_INSTANCE);
  515.                           VEC_free (type_ptr, type_list);
  516.                         }
  517.         ;

  518. rcurly        :        '}'
  519.                         { $$ = end_arglist () - 1; }
  520.         ;
  521. exp        :        lcurly arglist rcurly        %prec ARROW
  522.                         { write_exp_elt_opcode (pstate, OP_ARRAY);
  523.                           write_exp_elt_longcst (pstate, (LONGEST) 0);
  524.                           write_exp_elt_longcst (pstate, (LONGEST) $3);
  525.                           write_exp_elt_opcode (pstate, OP_ARRAY); }
  526.         ;

  527. exp        :        lcurly type_exp rcurly exp  %prec UNARY
  528.                         { write_exp_elt_opcode (pstate, UNOP_MEMVAL_TYPE); }
  529.         ;

  530. exp        :        '(' type_exp ')' exp  %prec UNARY
  531.                         { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); }
  532.         ;

  533. exp        :        '(' exp1 ')'
  534.                         { }
  535.         ;

  536. /* Binary operators in order of decreasing precedence.  */

  537. exp        :        exp '@' exp
  538.                         { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
  539.         ;

  540. exp        :        exp '*' exp
  541.                         { write_exp_elt_opcode (pstate, BINOP_MUL); }
  542.         ;

  543. exp        :        exp '/' exp
  544.                         { write_exp_elt_opcode (pstate, BINOP_DIV); }
  545.         ;

  546. exp        :        exp '%' exp
  547.                         { write_exp_elt_opcode (pstate, BINOP_REM); }
  548.         ;

  549. exp        :        exp '+' exp
  550.                         { write_exp_elt_opcode (pstate, BINOP_ADD); }
  551.         ;

  552. exp        :        exp '-' exp
  553.                         { write_exp_elt_opcode (pstate, BINOP_SUB); }
  554.         ;

  555. exp        :        exp LSH exp
  556.                         { write_exp_elt_opcode (pstate, BINOP_LSH); }
  557.         ;

  558. exp        :        exp RSH exp
  559.                         { write_exp_elt_opcode (pstate, BINOP_RSH); }
  560.         ;

  561. exp        :        exp EQUAL exp
  562.                         { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
  563.         ;

  564. exp        :        exp NOTEQUAL exp
  565.                         { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
  566.         ;

  567. exp        :        exp LEQ exp
  568.                         { write_exp_elt_opcode (pstate, BINOP_LEQ); }
  569.         ;

  570. exp        :        exp GEQ exp
  571.                         { write_exp_elt_opcode (pstate, BINOP_GEQ); }
  572.         ;

  573. exp        :        exp '<' exp
  574.                         { write_exp_elt_opcode (pstate, BINOP_LESS); }
  575.         ;

  576. exp        :        exp '>' exp
  577.                         { write_exp_elt_opcode (pstate, BINOP_GTR); }
  578.         ;

  579. exp        :        exp '&' exp
  580.                         { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
  581.         ;

  582. exp        :        exp '^' exp
  583.                         { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
  584.         ;

  585. exp        :        exp '|' exp
  586.                         { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
  587.         ;

  588. exp        :        exp ANDAND exp
  589.                         { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
  590.         ;

  591. exp        :        exp OROR exp
  592.                         { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
  593.         ;

  594. exp        :        exp '?' exp ':' exp        %prec '?'
  595.                         { write_exp_elt_opcode (pstate, TERNOP_COND); }
  596.         ;

  597. exp        :        exp '=' exp
  598.                         { write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
  599.         ;

  600. exp        :        exp ASSIGN_MODIFY exp
  601.                         { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY);
  602.                           write_exp_elt_opcode (pstate, $2);
  603.                           write_exp_elt_opcode (pstate,
  604.                                                 BINOP_ASSIGN_MODIFY); }
  605.         ;

  606. exp        :        INT
  607.                         { write_exp_elt_opcode (pstate, OP_LONG);
  608.                           write_exp_elt_type (pstate, $1.type);
  609.                           write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
  610.                           write_exp_elt_opcode (pstate, OP_LONG); }
  611.         ;

  612. exp        :        CHAR
  613.                         {
  614.                           struct stoken_vector vec;
  615.                           vec.len = 1;
  616.                           vec.tokens = &$1;
  617.                           write_exp_string_vector (pstate, $1.type, &vec);
  618.                         }
  619.         ;

  620. exp        :        NAME_OR_INT
  621.                         { YYSTYPE val;
  622.                           parse_number (pstate, $1.stoken.ptr,
  623.                                         $1.stoken.length, 0, &val);
  624.                           write_exp_elt_opcode (pstate, OP_LONG);
  625.                           write_exp_elt_type (pstate, val.typed_val_int.type);
  626.                           write_exp_elt_longcst (pstate,
  627.                                             (LONGEST) val.typed_val_int.val);
  628.                           write_exp_elt_opcode (pstate, OP_LONG);
  629.                         }
  630.         ;


  631. exp        :        FLOAT
  632.                         { write_exp_elt_opcode (pstate, OP_DOUBLE);
  633.                           write_exp_elt_type (pstate, $1.type);
  634.                           write_exp_elt_dblcst (pstate, $1.dval);
  635.                           write_exp_elt_opcode (pstate, OP_DOUBLE); }
  636.         ;

  637. exp        :        DECFLOAT
  638.                         { write_exp_elt_opcode (pstate, OP_DECFLOAT);
  639.                           write_exp_elt_type (pstate, $1.type);
  640.                           write_exp_elt_decfloatcst (pstate, $1.val);
  641.                           write_exp_elt_opcode (pstate, OP_DECFLOAT); }
  642.         ;

  643. exp        :        variable
  644.         ;

  645. exp        :        VARIABLE
  646.                         {
  647.                           write_dollar_variable (pstate, $1);
  648.                         }
  649.         ;

  650. exp        :        SELECTOR '(' name ')'
  651.                         {
  652.                           write_exp_elt_opcode (pstate, OP_OBJC_SELECTOR);
  653.                           write_exp_string (pstate, $3);
  654.                           write_exp_elt_opcode (pstate, OP_OBJC_SELECTOR); }
  655.         ;

  656. exp        :        SIZEOF '(' type ')'        %prec UNARY
  657.                         { struct type *type = $3;
  658.                           write_exp_elt_opcode (pstate, OP_LONG);
  659.                           write_exp_elt_type (pstate, lookup_signed_typename
  660.                                               (parse_language (pstate),
  661.                                                parse_gdbarch (pstate),
  662.                                                "int"));
  663.                           CHECK_TYPEDEF (type);

  664.                             /* $5.3.3/2 of the C++ Standard (n3290 draft)
  665.                                says of sizeof:  "When applied to a reference
  666.                                or a reference type, the result is the size of
  667.                                the referenced type."  */
  668.                           if (TYPE_CODE (type) == TYPE_CODE_REF)
  669.                             type = check_typedef (TYPE_TARGET_TYPE (type));
  670.                           write_exp_elt_longcst (pstate,
  671.                                                  (LONGEST) TYPE_LENGTH (type));
  672.                           write_exp_elt_opcode (pstate, OP_LONG); }
  673.         ;

  674. exp        :        REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
  675.                         { write_exp_elt_opcode (pstate,
  676.                                                 UNOP_REINTERPRET_CAST); }
  677.         ;

  678. exp        :        STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
  679.                         { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); }
  680.         ;

  681. exp        :        DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
  682.                         { write_exp_elt_opcode (pstate, UNOP_DYNAMIC_CAST); }
  683.         ;

  684. exp        :        CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
  685.                         { /* We could do more error checking here, but
  686.                              it doesn't seem worthwhile.  */
  687.                           write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); }
  688.         ;

  689. string_exp:
  690.                 STRING
  691.                         {
  692.                           /* We copy the string here, and not in the
  693.                              lexer, to guarantee that we do not leak a
  694.                              string.  Note that we follow the
  695.                              NUL-termination convention of the
  696.                              lexer.  */
  697.                           struct typed_stoken *vec = XNEW (struct typed_stoken);
  698.                           $$.len = 1;
  699.                           $$.tokens = vec;

  700.                           vec->type = $1.type;
  701.                           vec->length = $1.length;
  702.                           vec->ptr = malloc ($1.length + 1);
  703.                           memcpy (vec->ptr, $1.ptr, $1.length + 1);
  704.                         }

  705.         |        string_exp STRING
  706.                         {
  707.                           /* Note that we NUL-terminate here, but just
  708.                              for convenience.  */
  709.                           char *p;
  710.                           ++$$.len;
  711.                           $$.tokens = realloc ($$.tokens,
  712.                                                $$.len * sizeof (struct typed_stoken));

  713.                           p = malloc ($2.length + 1);
  714.                           memcpy (p, $2.ptr, $2.length + 1);

  715.                           $$.tokens[$$.len - 1].type = $2.type;
  716.                           $$.tokens[$$.len - 1].length = $2.length;
  717.                           $$.tokens[$$.len - 1].ptr = p;
  718.                         }
  719.                 ;

  720. exp        :        string_exp
  721.                         {
  722.                           int i;
  723.                           enum c_string_type type = C_STRING;

  724.                           for (i = 0; i < $1.len; ++i)
  725.                             {
  726.                               switch ($1.tokens[i].type)
  727.                                 {
  728.                                 case C_STRING:
  729.                                   break;
  730.                                 case C_WIDE_STRING:
  731.                                 case C_STRING_16:
  732.                                 case C_STRING_32:
  733.                                   if (type != C_STRING
  734.                                       && type != $1.tokens[i].type)
  735.                                     error (_("Undefined string concatenation."));
  736.                                   type = $1.tokens[i].type;
  737.                                   break;
  738.                                 default:
  739.                                   /* internal error */
  740.                                   internal_error (__FILE__, __LINE__,
  741.                                                   "unrecognized type in string concatenation");
  742.                                 }
  743.                             }

  744.                           write_exp_string_vector (pstate, type, &$1);
  745.                           for (i = 0; i < $1.len; ++i)
  746.                             free ($1.tokens[i].ptr);
  747.                           free ($1.tokens);
  748.                         }
  749.         ;

  750. exp     :        NSSTRING        /* ObjC NextStep NSString constant
  751.                                  * of the form '@' '"' string '"'.
  752.                                  */
  753.                         { write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING);
  754.                           write_exp_string (pstate, $1);
  755.                           write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING); }
  756.         ;

  757. /* C++.  */
  758. exp     :       TRUEKEYWORD
  759.                         { write_exp_elt_opcode (pstate, OP_LONG);
  760.                           write_exp_elt_type (pstate,
  761.                                           parse_type (pstate)->builtin_bool);
  762.                           write_exp_elt_longcst (pstate, (LONGEST) 1);
  763.                           write_exp_elt_opcode (pstate, OP_LONG); }
  764.         ;

  765. exp     :       FALSEKEYWORD
  766.                         { write_exp_elt_opcode (pstate, OP_LONG);
  767.                           write_exp_elt_type (pstate,
  768.                                           parse_type (pstate)->builtin_bool);
  769.                           write_exp_elt_longcst (pstate, (LONGEST) 0);
  770.                           write_exp_elt_opcode (pstate, OP_LONG); }
  771.         ;

  772. /* end of C++.  */

  773. block        :        BLOCKNAME
  774.                         {
  775.                           if ($1.sym)
  776.                             $$ = SYMBOL_BLOCK_VALUE ($1.sym);
  777.                           else
  778.                             error (_("No file or function \"%s\"."),
  779.                                    copy_name ($1.stoken));
  780.                         }
  781.         |        FILENAME
  782.                         {
  783.                           $$ = $1;
  784.                         }
  785.         ;

  786. block        :        block COLONCOLON name
  787.                         { struct symbol *tem
  788.                             = lookup_symbol (copy_name ($3), $1,
  789.                                              VAR_DOMAIN, NULL);
  790.                           if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  791.                             error (_("No function \"%s\" in specified context."),
  792.                                    copy_name ($3));
  793.                           $$ = SYMBOL_BLOCK_VALUE (tem); }
  794.         ;

  795. variable:        name_not_typename ENTRY
  796.                         { struct symbol *sym = $1.sym;

  797.                           if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
  798.                               || !symbol_read_needs_frame (sym))
  799.                             error (_("@entry can be used only for function "
  800.                                      "parameters, not for \"%s\""),
  801.                                    copy_name ($1.stoken));

  802.                           write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
  803.                           write_exp_elt_sym (pstate, sym);
  804.                           write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
  805.                         }
  806.         ;

  807. variable:        block COLONCOLON name
  808.                         { struct symbol *sym;
  809.                           sym = lookup_symbol (copy_name ($3), $1,
  810.                                                VAR_DOMAIN, NULL);
  811.                           if (sym == 0)
  812.                             error (_("No symbol \"%s\" in specified context."),
  813.                                    copy_name ($3));
  814.                           if (symbol_read_needs_frame (sym))
  815.                             {
  816.                               if (innermost_block == 0
  817.                                   || contained_in (block_found,
  818.                                                    innermost_block))
  819.                                 innermost_block = block_found;
  820.                             }

  821.                           write_exp_elt_opcode (pstate, OP_VAR_VALUE);
  822.                           /* block_found is set by lookup_symbol.  */
  823.                           write_exp_elt_block (pstate, block_found);
  824.                           write_exp_elt_sym (pstate, sym);
  825.                           write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
  826.         ;

  827. qualified_name:        TYPENAME COLONCOLON name
  828.                         {
  829.                           struct type *type = $1.type;
  830.                           CHECK_TYPEDEF (type);
  831.                           if (!type_aggregate_p (type))
  832.                             error (_("`%s' is not defined as an aggregate type."),
  833.                                    TYPE_SAFE_NAME (type));

  834.                           write_exp_elt_opcode (pstate, OP_SCOPE);
  835.                           write_exp_elt_type (pstate, type);
  836.                           write_exp_string (pstate, $3);
  837.                           write_exp_elt_opcode (pstate, OP_SCOPE);
  838.                         }
  839.         |        TYPENAME COLONCOLON '~' name
  840.                         {
  841.                           struct type *type = $1.type;
  842.                           struct stoken tmp_token;
  843.                           char *buf;

  844.                           CHECK_TYPEDEF (type);
  845.                           if (!type_aggregate_p (type))
  846.                             error (_("`%s' is not defined as an aggregate type."),
  847.                                    TYPE_SAFE_NAME (type));
  848.                           buf = alloca ($4.length + 2);
  849.                           tmp_token.ptr = buf;
  850.                           tmp_token.length = $4.length + 1;
  851.                           buf[0] = '~';
  852.                           memcpy (buf+1, $4.ptr, $4.length);
  853.                           buf[tmp_token.length] = 0;

  854.                           /* Check for valid destructor name.  */
  855.                           destructor_name_p (tmp_token.ptr, $1.type);
  856.                           write_exp_elt_opcode (pstate, OP_SCOPE);
  857.                           write_exp_elt_type (pstate, type);
  858.                           write_exp_string (pstate, tmp_token);
  859.                           write_exp_elt_opcode (pstate, OP_SCOPE);
  860.                         }
  861.         |        TYPENAME COLONCOLON name COLONCOLON name
  862.                         {
  863.                           char *copy = copy_name ($3);
  864.                           error (_("No type \"%s\" within class "
  865.                                    "or namespace \"%s\"."),
  866.                                  copy, TYPE_SAFE_NAME ($1.type));
  867.                         }
  868.         ;

  869. variable:        qualified_name
  870.         |        COLONCOLON name_not_typename
  871.                         {
  872.                           char *name = copy_name ($2.stoken);
  873.                           struct symbol *sym;
  874.                           struct bound_minimal_symbol msymbol;

  875.                           sym =
  876.                             lookup_symbol (name, (const struct block *) NULL,
  877.                                            VAR_DOMAIN, NULL);
  878.                           if (sym)
  879.                             {
  880.                               write_exp_elt_opcode (pstate, OP_VAR_VALUE);
  881.                               write_exp_elt_block (pstate, NULL);
  882.                               write_exp_elt_sym (pstate, sym);
  883.                               write_exp_elt_opcode (pstate, OP_VAR_VALUE);
  884.                               break;
  885.                             }

  886.                           msymbol = lookup_bound_minimal_symbol (name);
  887.                           if (msymbol.minsym != NULL)
  888.                             write_exp_msymbol (pstate, msymbol);
  889.                           else if (!have_full_symbols () && !have_partial_symbols ())
  890.                             error (_("No symbol table is loaded.  Use the \"file\" command."));
  891.                           else
  892.                             error (_("No symbol \"%s\" in current context."), name);
  893.                         }
  894.         ;

  895. variable:        name_not_typename
  896.                         { struct symbol *sym = $1.sym;

  897.                           if (sym)
  898.                             {
  899.                               if (symbol_read_needs_frame (sym))
  900.                                 {
  901.                                   if (innermost_block == 0
  902.                                       || contained_in (block_found,
  903.                                                        innermost_block))
  904.                                     innermost_block = block_found;
  905.                                 }

  906.                               write_exp_elt_opcode (pstate, OP_VAR_VALUE);
  907.                               /* We want to use the selected frame, not
  908.                                  another more inner frame which happens to
  909.                                  be in the same block.  */
  910.                               write_exp_elt_block (pstate, NULL);
  911.                               write_exp_elt_sym (pstate, sym);
  912.                               write_exp_elt_opcode (pstate, OP_VAR_VALUE);
  913.                             }
  914.                           else if ($1.is_a_field_of_this)
  915.                             {
  916.                               /* C++: it hangs off of `this'.  Must
  917.                                  not inadvertently convert from a method call
  918.                                  to data ref.  */
  919.                               if (innermost_block == 0
  920.                                   || contained_in (block_found,
  921.                                                    innermost_block))
  922.                                 innermost_block = block_found;
  923.                               write_exp_elt_opcode (pstate, OP_THIS);
  924.                               write_exp_elt_opcode (pstate, OP_THIS);
  925.                               write_exp_elt_opcode (pstate, STRUCTOP_PTR);
  926.                               write_exp_string (pstate, $1.stoken);
  927.                               write_exp_elt_opcode (pstate, STRUCTOP_PTR);
  928.                             }
  929.                           else
  930.                             {
  931.                               struct bound_minimal_symbol msymbol;
  932.                               char *arg = copy_name ($1.stoken);

  933.                               msymbol =
  934.                                 lookup_bound_minimal_symbol (arg);
  935.                               if (msymbol.minsym != NULL)
  936.                                 write_exp_msymbol (pstate, msymbol);
  937.                               else if (!have_full_symbols () && !have_partial_symbols ())
  938.                                 error (_("No symbol table is loaded.  Use the \"file\" command."));
  939.                               else
  940.                                 error (_("No symbol \"%s\" in current context."),
  941.                                        copy_name ($1.stoken));
  942.                             }
  943.                         }
  944.         ;

  945. space_identifier : '@' NAME
  946.                 { insert_type_address_space (pstate, copy_name ($2.stoken)); }
  947.         ;

  948. const_or_volatile: const_or_volatile_noopt
  949.         |
  950.         ;

  951. cv_with_space_id : const_or_volatile space_identifier const_or_volatile
  952.         ;

  953. const_or_volatile_or_space_identifier_noopt: cv_with_space_id
  954.         | const_or_volatile_noopt
  955.         ;

  956. const_or_volatile_or_space_identifier:
  957.                 const_or_volatile_or_space_identifier_noopt
  958.         |
  959.         ;

  960. ptr_operator:
  961.                 ptr_operator '*'
  962.                         { insert_type (tp_pointer); }
  963.                 const_or_volatile_or_space_identifier
  964.         |        '*'
  965.                         { insert_type (tp_pointer); }
  966.                 const_or_volatile_or_space_identifier
  967.         |        '&'
  968.                         { insert_type (tp_reference); }
  969.         |        '&' ptr_operator
  970.                         { insert_type (tp_reference); }
  971.         ;

  972. ptr_operator_ts: ptr_operator
  973.                         {
  974.                           $$ = get_type_stack ();
  975.                           /* This cleanup is eventually run by
  976.                              c_parse.  */
  977.                           make_cleanup (type_stack_cleanup, $$);
  978.                         }
  979.         ;

  980. abs_decl:        ptr_operator_ts direct_abs_decl
  981.                         { $$ = append_type_stack ($2, $1); }
  982.         |        ptr_operator_ts
  983.         |        direct_abs_decl
  984.         ;

  985. direct_abs_decl: '(' abs_decl ')'
  986.                         { $$ = $2; }
  987.         |        direct_abs_decl array_mod
  988.                         {
  989.                           push_type_stack ($1);
  990.                           push_type_int ($2);
  991.                           push_type (tp_array);
  992.                           $$ = get_type_stack ();
  993.                         }
  994.         |        array_mod
  995.                         {
  996.                           push_type_int ($1);
  997.                           push_type (tp_array);
  998.                           $$ = get_type_stack ();
  999.                         }

  1000.         |         direct_abs_decl func_mod
  1001.                         {
  1002.                           push_type_stack ($1);
  1003.                           push_typelist ($2);
  1004.                           $$ = get_type_stack ();
  1005.                         }
  1006.         |        func_mod
  1007.                         {
  1008.                           push_typelist ($1);
  1009.                           $$ = get_type_stack ();
  1010.                         }
  1011.         ;

  1012. array_mod:        '[' ']'
  1013.                         { $$ = -1; }
  1014.         |        OBJC_LBRAC ']'
  1015.                         { $$ = -1; }
  1016.         |        '[' INT ']'
  1017.                         { $$ = $2.val; }
  1018.         |        OBJC_LBRAC INT ']'
  1019.                         { $$ = $2.val; }
  1020.         ;

  1021. func_mod:        '(' ')'
  1022.                         { $$ = NULL; }
  1023.         |        '(' parameter_typelist ')'
  1024.                         { $$ = $2; }
  1025.         ;

  1026. /* We used to try to recognize pointer to member types here, but
  1027.    that didn't work (shift/reduce conflicts meant that these rules never
  1028.    got executed).  The problem is that
  1029.      int (foo::bar::baz::bizzle)
  1030.    is a function type but
  1031.      int (foo::bar::baz::bizzle::*)
  1032.    is a pointer to member type.  Stroustrup loses again!  */

  1033. type        :        ptype
  1034.         ;

  1035. typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
  1036.         :        TYPENAME
  1037.                         { $$ = $1.type; }
  1038.         |        INT_KEYWORD
  1039.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1040.                                                        parse_gdbarch (pstate),
  1041.                                                        "int"); }
  1042.         |        LONG
  1043.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1044.                                                        parse_gdbarch (pstate),
  1045.                                                        "long"); }
  1046.         |        SHORT
  1047.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1048.                                                        parse_gdbarch (pstate),
  1049.                                                        "short"); }
  1050.         |        LONG INT_KEYWORD
  1051.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1052.                                                        parse_gdbarch (pstate),
  1053.                                                        "long"); }
  1054.         |        LONG SIGNED_KEYWORD INT_KEYWORD
  1055.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1056.                                                        parse_gdbarch (pstate),
  1057.                                                        "long"); }
  1058.         |        LONG SIGNED_KEYWORD
  1059.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1060.                                                        parse_gdbarch (pstate),
  1061.                                                        "long"); }
  1062.         |        SIGNED_KEYWORD LONG INT_KEYWORD
  1063.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1064.                                                        parse_gdbarch (pstate),
  1065.                                                        "long"); }
  1066.         |        UNSIGNED LONG INT_KEYWORD
  1067.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1068.                                                          parse_gdbarch (pstate),
  1069.                                                          "long"); }
  1070.         |        LONG UNSIGNED INT_KEYWORD
  1071.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1072.                                                          parse_gdbarch (pstate),
  1073.                                                          "long"); }
  1074.         |        LONG UNSIGNED
  1075.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1076.                                                          parse_gdbarch (pstate),
  1077.                                                          "long"); }
  1078.         |        LONG LONG
  1079.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1080.                                                        parse_gdbarch (pstate),
  1081.                                                        "long long"); }
  1082.         |        LONG LONG INT_KEYWORD
  1083.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1084.                                                        parse_gdbarch (pstate),
  1085.                                                        "long long"); }
  1086.         |        LONG LONG SIGNED_KEYWORD INT_KEYWORD
  1087.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1088.                                                        parse_gdbarch (pstate),
  1089.                                                        "long long"); }
  1090.         |        LONG LONG SIGNED_KEYWORD
  1091.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1092.                                                        parse_gdbarch (pstate),
  1093.                                                        "long long"); }
  1094.         |        SIGNED_KEYWORD LONG LONG
  1095.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1096.                                                        parse_gdbarch (pstate),
  1097.                                                        "long long"); }
  1098.         |        SIGNED_KEYWORD LONG LONG INT_KEYWORD
  1099.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1100.                                                        parse_gdbarch (pstate),
  1101.                                                        "long long"); }
  1102.         |        UNSIGNED LONG LONG
  1103.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1104.                                                          parse_gdbarch (pstate),
  1105.                                                          "long long"); }
  1106.         |        UNSIGNED LONG LONG INT_KEYWORD
  1107.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1108.                                                          parse_gdbarch (pstate),
  1109.                                                          "long long"); }
  1110.         |        LONG LONG UNSIGNED
  1111.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1112.                                                          parse_gdbarch (pstate),
  1113.                                                          "long long"); }
  1114.         |        LONG LONG UNSIGNED INT_KEYWORD
  1115.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1116.                                                          parse_gdbarch (pstate),
  1117.                                                          "long long"); }
  1118.         |        SHORT INT_KEYWORD
  1119.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1120.                                                        parse_gdbarch (pstate),
  1121.                                                        "short"); }
  1122.         |        SHORT SIGNED_KEYWORD INT_KEYWORD
  1123.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1124.                                                        parse_gdbarch (pstate),
  1125.                                                        "short"); }
  1126.         |        SHORT SIGNED_KEYWORD
  1127.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1128.                                                        parse_gdbarch (pstate),
  1129.                                                        "short"); }
  1130.         |        UNSIGNED SHORT INT_KEYWORD
  1131.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1132.                                                          parse_gdbarch (pstate),
  1133.                                                          "short"); }
  1134.         |        SHORT UNSIGNED
  1135.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1136.                                                          parse_gdbarch (pstate),
  1137.                                                          "short"); }
  1138.         |        SHORT UNSIGNED INT_KEYWORD
  1139.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1140.                                                          parse_gdbarch (pstate),
  1141.                                                          "short"); }
  1142.         |        DOUBLE_KEYWORD
  1143.                         { $$ = lookup_typename (parse_language (pstate),
  1144.                                                 parse_gdbarch (pstate),
  1145.                                                 "double",
  1146.                                                 (struct block *) NULL,
  1147.                                                 0); }
  1148.         |        LONG DOUBLE_KEYWORD
  1149.                         { $$ = lookup_typename (parse_language (pstate),
  1150.                                                 parse_gdbarch (pstate),
  1151.                                                 "long double",
  1152.                                                 (struct block *) NULL,
  1153.                                                 0); }
  1154.         |        STRUCT name
  1155.                         { $$ = lookup_struct (copy_name ($2),
  1156.                                               expression_context_block); }
  1157.         |        STRUCT COMPLETE
  1158.                         {
  1159.                           mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
  1160.                           $$ = NULL;
  1161.                         }
  1162.         |        STRUCT name COMPLETE
  1163.                         {
  1164.                           mark_completion_tag (TYPE_CODE_STRUCT, $2.ptr,
  1165.                                                $2.length);
  1166.                           $$ = NULL;
  1167.                         }
  1168.         |        CLASS name
  1169.                         { $$ = lookup_struct (copy_name ($2),
  1170.                                               expression_context_block); }
  1171.         |        CLASS COMPLETE
  1172.                         {
  1173.                           mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
  1174.                           $$ = NULL;
  1175.                         }
  1176.         |        CLASS name COMPLETE
  1177.                         {
  1178.                           mark_completion_tag (TYPE_CODE_STRUCT, $2.ptr,
  1179.                                                $2.length);
  1180.                           $$ = NULL;
  1181.                         }
  1182.         |        UNION name
  1183.                         { $$ = lookup_union (copy_name ($2),
  1184.                                              expression_context_block); }
  1185.         |        UNION COMPLETE
  1186.                         {
  1187.                           mark_completion_tag (TYPE_CODE_UNION, "", 0);
  1188.                           $$ = NULL;
  1189.                         }
  1190.         |        UNION name COMPLETE
  1191.                         {
  1192.                           mark_completion_tag (TYPE_CODE_UNION, $2.ptr,
  1193.                                                $2.length);
  1194.                           $$ = NULL;
  1195.                         }
  1196.         |        ENUM name
  1197.                         { $$ = lookup_enum (copy_name ($2),
  1198.                                             expression_context_block); }
  1199.         |        ENUM COMPLETE
  1200.                         {
  1201.                           mark_completion_tag (TYPE_CODE_ENUM, "", 0);
  1202.                           $$ = NULL;
  1203.                         }
  1204.         |        ENUM name COMPLETE
  1205.                         {
  1206.                           mark_completion_tag (TYPE_CODE_ENUM, $2.ptr,
  1207.                                                $2.length);
  1208.                           $$ = NULL;
  1209.                         }
  1210.         |        UNSIGNED typename
  1211.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1212.                                                          parse_gdbarch (pstate),
  1213.                                                          TYPE_NAME($2.type)); }
  1214.         |        UNSIGNED
  1215.                         { $$ = lookup_unsigned_typename (parse_language (pstate),
  1216.                                                          parse_gdbarch (pstate),
  1217.                                                          "int"); }
  1218.         |        SIGNED_KEYWORD typename
  1219.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1220.                                                        parse_gdbarch (pstate),
  1221.                                                        TYPE_NAME($2.type)); }
  1222.         |        SIGNED_KEYWORD
  1223.                         { $$ = lookup_signed_typename (parse_language (pstate),
  1224.                                                        parse_gdbarch (pstate),
  1225.                                                        "int"); }
  1226.                 /* It appears that this rule for templates is never
  1227.                    reduced; template recognition happens by lookahead
  1228.                    in the token processing code in yylex. */
  1229.         |        TEMPLATE name '<' type '>'
  1230.                         { $$ = lookup_template_type(copy_name($2), $4,
  1231.                                                     expression_context_block);
  1232.                         }
  1233.         | const_or_volatile_or_space_identifier_noopt typebase
  1234.                         { $$ = follow_types ($2); }
  1235.         | typebase const_or_volatile_or_space_identifier_noopt
  1236.                         { $$ = follow_types ($1); }
  1237.         ;

  1238. typename:        TYPENAME
  1239.         |        INT_KEYWORD
  1240.                 {
  1241.                   $$.stoken.ptr = "int";
  1242.                   $$.stoken.length = 3;
  1243.                   $$.type = lookup_signed_typename (parse_language (pstate),
  1244.                                                     parse_gdbarch (pstate),
  1245.                                                     "int");
  1246.                 }
  1247.         |        LONG
  1248.                 {
  1249.                   $$.stoken.ptr = "long";
  1250.                   $$.stoken.length = 4;
  1251.                   $$.type = lookup_signed_typename (parse_language (pstate),
  1252.                                                     parse_gdbarch (pstate),
  1253.                                                     "long");
  1254.                 }
  1255.         |        SHORT
  1256.                 {
  1257.                   $$.stoken.ptr = "short";
  1258.                   $$.stoken.length = 5;
  1259.                   $$.type = lookup_signed_typename (parse_language (pstate),
  1260.                                                     parse_gdbarch (pstate),
  1261.                                                     "short");
  1262.                 }
  1263.         ;

  1264. parameter_typelist:
  1265.                 nonempty_typelist
  1266.                         { check_parameter_typelist ($1); }
  1267.         |        nonempty_typelist ',' DOTDOTDOT
  1268.                         {
  1269.                           VEC_safe_push (type_ptr, $1, NULL);
  1270.                           check_parameter_typelist ($1);
  1271.                           $$ = $1;
  1272.                         }
  1273.         ;

  1274. nonempty_typelist
  1275.         :        type
  1276.                 {
  1277.                   VEC (type_ptr) *typelist = NULL;
  1278.                   VEC_safe_push (type_ptr, typelist, $1);
  1279.                   $$ = typelist;
  1280.                 }
  1281.         |        nonempty_typelist ',' type
  1282.                 {
  1283.                   VEC_safe_push (type_ptr, $1, $3);
  1284.                   $$ = $1;
  1285.                 }
  1286.         ;

  1287. ptype        :        typebase
  1288.         |        ptype abs_decl
  1289.                 {
  1290.                   push_type_stack ($2);
  1291.                   $$ = follow_types ($1);
  1292.                 }
  1293.         ;

  1294. conversion_type_id: typebase conversion_declarator
  1295.                 { $$ = follow_types ($1); }
  1296.         ;

  1297. conversion_declarator:  /* Nothing.  */
  1298.         | ptr_operator conversion_declarator
  1299.         ;

  1300. const_and_volatile:         CONST_KEYWORD VOLATILE_KEYWORD
  1301.         |                 VOLATILE_KEYWORD CONST_KEYWORD
  1302.         ;

  1303. const_or_volatile_noopt:          const_and_volatile
  1304.                         { insert_type (tp_const);
  1305.                           insert_type (tp_volatile);
  1306.                         }
  1307.         |                 CONST_KEYWORD
  1308.                         { insert_type (tp_const); }
  1309.         |                 VOLATILE_KEYWORD
  1310.                         { insert_type (tp_volatile); }
  1311.         ;

  1312. operator:        OPERATOR NEW
  1313.                         { $$ = operator_stoken (" new"); }
  1314.         |        OPERATOR DELETE
  1315.                         { $$ = operator_stoken (" delete"); }
  1316.         |        OPERATOR NEW '[' ']'
  1317.                         { $$ = operator_stoken (" new[]"); }
  1318.         |        OPERATOR DELETE '[' ']'
  1319.                         { $$ = operator_stoken (" delete[]"); }
  1320.         |        OPERATOR NEW OBJC_LBRAC ']'
  1321.                         { $$ = operator_stoken (" new[]"); }
  1322.         |        OPERATOR DELETE OBJC_LBRAC ']'
  1323.                         { $$ = operator_stoken (" delete[]"); }
  1324.         |        OPERATOR '+'
  1325.                         { $$ = operator_stoken ("+"); }
  1326.         |        OPERATOR '-'
  1327.                         { $$ = operator_stoken ("-"); }
  1328.         |        OPERATOR '*'
  1329.                         { $$ = operator_stoken ("*"); }
  1330.         |        OPERATOR '/'
  1331.                         { $$ = operator_stoken ("/"); }
  1332.         |        OPERATOR '%'
  1333.                         { $$ = operator_stoken ("%"); }
  1334.         |        OPERATOR '^'
  1335.                         { $$ = operator_stoken ("^"); }
  1336.         |        OPERATOR '&'
  1337.                         { $$ = operator_stoken ("&"); }
  1338.         |        OPERATOR '|'
  1339.                         { $$ = operator_stoken ("|"); }
  1340.         |        OPERATOR '~'
  1341.                         { $$ = operator_stoken ("~"); }
  1342.         |        OPERATOR '!'
  1343.                         { $$ = operator_stoken ("!"); }
  1344.         |        OPERATOR '='
  1345.                         { $$ = operator_stoken ("="); }
  1346.         |        OPERATOR '<'
  1347.                         { $$ = operator_stoken ("<"); }
  1348.         |        OPERATOR '>'
  1349.                         { $$ = operator_stoken (">"); }
  1350.         |        OPERATOR ASSIGN_MODIFY
  1351.                         { const char *op = "unknown";
  1352.                           switch ($2)
  1353.                             {
  1354.                             case BINOP_RSH:
  1355.                               op = ">>=";
  1356.                               break;
  1357.                             case BINOP_LSH:
  1358.                               op = "<<=";
  1359.                               break;
  1360.                             case BINOP_ADD:
  1361.                               op = "+=";
  1362.                               break;
  1363.                             case BINOP_SUB:
  1364.                               op = "-=";
  1365.                               break;
  1366.                             case BINOP_MUL:
  1367.                               op = "*=";
  1368.                               break;
  1369.                             case BINOP_DIV:
  1370.                               op = "/=";
  1371.                               break;
  1372.                             case BINOP_REM:
  1373.                               op = "%=";
  1374.                               break;
  1375.                             case BINOP_BITWISE_IOR:
  1376.                               op = "|=";
  1377.                               break;
  1378.                             case BINOP_BITWISE_AND:
  1379.                               op = "&=";
  1380.                               break;
  1381.                             case BINOP_BITWISE_XOR:
  1382.                               op = "^=";
  1383.                               break;
  1384.                             default:
  1385.                               break;
  1386.                             }

  1387.                           $$ = operator_stoken (op);
  1388.                         }
  1389.         |        OPERATOR LSH
  1390.                         { $$ = operator_stoken ("<<"); }
  1391.         |        OPERATOR RSH
  1392.                         { $$ = operator_stoken (">>"); }
  1393.         |        OPERATOR EQUAL
  1394.                         { $$ = operator_stoken ("=="); }
  1395.         |        OPERATOR NOTEQUAL
  1396.                         { $$ = operator_stoken ("!="); }
  1397.         |        OPERATOR LEQ
  1398.                         { $$ = operator_stoken ("<="); }
  1399.         |        OPERATOR GEQ
  1400.                         { $$ = operator_stoken (">="); }
  1401.         |        OPERATOR ANDAND
  1402.                         { $$ = operator_stoken ("&&"); }
  1403.         |        OPERATOR OROR
  1404.                         { $$ = operator_stoken ("||"); }
  1405.         |        OPERATOR INCREMENT
  1406.                         { $$ = operator_stoken ("++"); }
  1407.         |        OPERATOR DECREMENT
  1408.                         { $$ = operator_stoken ("--"); }
  1409.         |        OPERATOR ','
  1410.                         { $$ = operator_stoken (","); }
  1411.         |        OPERATOR ARROW_STAR
  1412.                         { $$ = operator_stoken ("->*"); }
  1413.         |        OPERATOR ARROW
  1414.                         { $$ = operator_stoken ("->"); }
  1415.         |        OPERATOR '(' ')'
  1416.                         { $$ = operator_stoken ("()"); }
  1417.         |        OPERATOR '[' ']'
  1418.                         { $$ = operator_stoken ("[]"); }
  1419.         |        OPERATOR OBJC_LBRAC ']'
  1420.                         { $$ = operator_stoken ("[]"); }
  1421.         |        OPERATOR conversion_type_id
  1422.                         { char *name;
  1423.                           long length;
  1424.                           struct ui_file *buf = mem_fileopen ();

  1425.                           c_print_type ($2, NULL, buf, -1, 0,
  1426.                                         &type_print_raw_options);
  1427.                           name = ui_file_xstrdup (buf, &length);
  1428.                           ui_file_delete (buf);
  1429.                           $$ = operator_stoken (name);
  1430.                           free (name);
  1431.                         }
  1432.         ;



  1433. name        :        NAME { $$ = $1.stoken; }
  1434.         |        BLOCKNAME { $$ = $1.stoken; }
  1435.         |        TYPENAME { $$ = $1.stoken; }
  1436.         |        NAME_OR_INT  { $$ = $1.stoken; }
  1437.         |        UNKNOWN_CPP_NAME  { $$ = $1.stoken; }
  1438.         |        operator { $$ = $1; }
  1439.         ;

  1440. name_not_typename :        NAME
  1441.         |        BLOCKNAME
  1442. /* These would be useful if name_not_typename was useful, but it is just
  1443.    a fake for "variable", so these cause reduce/reduce conflicts because
  1444.    the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
  1445.    =exp) or just an exp.  If name_not_typename was ever used in an lvalue
  1446.    context where only a name could occur, this might be useful.
  1447.           |        NAME_OR_INT
  1448. */
  1449.         |        operator
  1450.                         {
  1451.                           struct field_of_this_result is_a_field_of_this;

  1452.                           $$.stoken = $1;
  1453.                           $$.sym = lookup_symbol ($1.ptr,
  1454.                                                   expression_context_block,
  1455.                                                   VAR_DOMAIN,
  1456.                                                   &is_a_field_of_this);
  1457.                           $$.is_a_field_of_this
  1458.                             = is_a_field_of_this.type != NULL;
  1459.                         }
  1460.         |        UNKNOWN_CPP_NAME
  1461.         ;

  1462. %%

  1463. /* Like write_exp_string, but prepends a '~'.  */

  1464. static void
  1465. write_destructor_name (struct parser_state *par_state, struct stoken token)
  1466. {
  1467.   char *copy = alloca (token.length + 1);

  1468.   copy[0] = '~';
  1469.   memcpy (&copy[1], token.ptr, token.length);

  1470.   token.ptr = copy;
  1471.   ++token.length;

  1472.   write_exp_string (par_state, token);
  1473. }

  1474. /* Returns a stoken of the operator name given by OP (which does not
  1475.    include the string "operator").  */

  1476. static struct stoken
  1477. operator_stoken (const char *op)
  1478. {
  1479.   static const char *operator_string = "operator";
  1480.   struct stoken st = { NULL, 0 };
  1481.   char *buf;

  1482.   st.length = strlen (operator_string) + strlen (op);
  1483.   buf = malloc (st.length + 1);
  1484.   strcpy (buf, operator_string);
  1485.   strcat (buf, op);
  1486.   st.ptr = buf;

  1487.   /* The toplevel (c_parse) will free the memory allocated here.  */
  1488.   make_cleanup (free, buf);
  1489.   return st;
  1490. };

  1491. /* Return true if the type is aggregate-like.  */

  1492. static int
  1493. type_aggregate_p (struct type *type)
  1494. {
  1495.   return (TYPE_CODE (type) == TYPE_CODE_STRUCT
  1496.           || TYPE_CODE (type) == TYPE_CODE_UNION
  1497.           || TYPE_CODE (type) == TYPE_CODE_NAMESPACE
  1498.           || (TYPE_CODE (type) == TYPE_CODE_ENUM
  1499.               && TYPE_DECLARED_CLASS (type)));
  1500. }

  1501. /* Validate a parameter typelist.  */

  1502. static void
  1503. check_parameter_typelist (VEC (type_ptr) *params)
  1504. {
  1505.   struct type *type;
  1506.   int ix;

  1507.   for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix)
  1508.     {
  1509.       if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
  1510.         {
  1511.           if (ix == 0)
  1512.             {
  1513.               if (VEC_length (type_ptr, params) == 1)
  1514.                 {
  1515.                   /* Ok.  */
  1516.                   break;
  1517.                 }
  1518.               VEC_free (type_ptr, params);
  1519.               error (_("parameter types following 'void'"));
  1520.             }
  1521.           else
  1522.             {
  1523.               VEC_free (type_ptr, params);
  1524.               error (_("'void' invalid as parameter type"));
  1525.             }
  1526.         }
  1527.     }
  1528. }

  1529. /* Take care of parsing a number (anything that starts with a digit).
  1530.    Set yylval and return the token type; update lexptr.
  1531.    LEN is the number of characters in it.  */

  1532. /*** Needs some error checking for the float case ***/

  1533. static int
  1534. parse_number (struct parser_state *par_state,
  1535.               const char *buf, int len, int parsed_float, YYSTYPE *putithere)
  1536. {
  1537.   /* FIXME: Shouldn't these be unsigned?  We don't deal with negative values
  1538.      here, and we do kind of silly things like cast to unsigned.  */
  1539.   LONGEST n = 0;
  1540.   LONGEST prevn = 0;
  1541.   ULONGEST un;

  1542.   int i = 0;
  1543.   int c;
  1544.   int base = input_radix;
  1545.   int unsigned_p = 0;

  1546.   /* Number of "L" suffixes encountered.  */
  1547.   int long_p = 0;

  1548.   /* We have found a "L" or "U" suffix.  */
  1549.   int found_suffix = 0;

  1550.   ULONGEST high_bit;
  1551.   struct type *signed_type;
  1552.   struct type *unsigned_type;
  1553.   char *p;

  1554.   p = alloca (len);
  1555.   memcpy (p, buf, len);

  1556.   if (parsed_float)
  1557.     {
  1558.       /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
  1559.          point.  Return DECFLOAT.  */

  1560.       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
  1561.         {
  1562.           p[len - 2] = '\0';
  1563.           putithere->typed_val_decfloat.type
  1564.             = parse_type (par_state)->builtin_decfloat;
  1565.           decimal_from_string (putithere->typed_val_decfloat.val, 4,
  1566.                                gdbarch_byte_order (parse_gdbarch (par_state)),
  1567.                                p);
  1568.           p[len - 2] = 'd';
  1569.           return DECFLOAT;
  1570.         }

  1571.       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
  1572.         {
  1573.           p[len - 2] = '\0';
  1574.           putithere->typed_val_decfloat.type
  1575.             = parse_type (par_state)->builtin_decdouble;
  1576.           decimal_from_string (putithere->typed_val_decfloat.val, 8,
  1577.                                gdbarch_byte_order (parse_gdbarch (par_state)),
  1578.                                p);
  1579.           p[len - 2] = 'd';
  1580.           return DECFLOAT;
  1581.         }

  1582.       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
  1583.         {
  1584.           p[len - 2] = '\0';
  1585.           putithere->typed_val_decfloat.type
  1586.             = parse_type (par_state)->builtin_declong;
  1587.           decimal_from_string (putithere->typed_val_decfloat.val, 16,
  1588.                                gdbarch_byte_order (parse_gdbarch (par_state)),
  1589.                                p);
  1590.           p[len - 2] = 'd';
  1591.           return DECFLOAT;
  1592.         }

  1593.       if (! parse_c_float (parse_gdbarch (par_state), p, len,
  1594.                            &putithere->typed_val_float.dval,
  1595.                            &putithere->typed_val_float.type))
  1596.         return ERROR;
  1597.       return FLOAT;
  1598.     }

  1599.   /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  1600.   if (p[0] == '0' && len > 1)
  1601.     switch (p[1])
  1602.       {
  1603.       case 'x':
  1604.       case 'X':
  1605.         if (len >= 3)
  1606.           {
  1607.             p += 2;
  1608.             base = 16;
  1609.             len -= 2;
  1610.           }
  1611.         break;

  1612.       case 'b':
  1613.       case 'B':
  1614.         if (len >= 3)
  1615.           {
  1616.             p += 2;
  1617.             base = 2;
  1618.             len -= 2;
  1619.           }
  1620.         break;

  1621.       case 't':
  1622.       case 'T':
  1623.       case 'd':
  1624.       case 'D':
  1625.         if (len >= 3)
  1626.           {
  1627.             p += 2;
  1628.             base = 10;
  1629.             len -= 2;
  1630.           }
  1631.         break;

  1632.       default:
  1633.         base = 8;
  1634.         break;
  1635.       }

  1636.   while (len-- > 0)
  1637.     {
  1638.       c = *p++;
  1639.       if (c >= 'A' && c <= 'Z')
  1640.         c += 'a' - 'A';
  1641.       if (c != 'l' && c != 'u')
  1642.         n *= base;
  1643.       if (c >= '0' && c <= '9')
  1644.         {
  1645.           if (found_suffix)
  1646.             return ERROR;
  1647.           n += i = c - '0';
  1648.         }
  1649.       else
  1650.         {
  1651.           if (base > 10 && c >= 'a' && c <= 'f')
  1652.             {
  1653.               if (found_suffix)
  1654.                 return ERROR;
  1655.               n += i = c - 'a' + 10;
  1656.             }
  1657.           else if (c == 'l')
  1658.             {
  1659.               ++long_p;
  1660.               found_suffix = 1;
  1661.             }
  1662.           else if (c == 'u')
  1663.             {
  1664.               unsigned_p = 1;
  1665.               found_suffix = 1;
  1666.             }
  1667.           else
  1668.             return ERROR;        /* Char not a digit */
  1669.         }
  1670.       if (i >= base)
  1671.         return ERROR;                /* Invalid digit in this base */

  1672.       /* Portably test for overflow (only works for nonzero values, so make
  1673.          a second check for zero).  FIXME: Can't we just make n and prevn
  1674.          unsigned and avoid this?  */
  1675.       if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
  1676.         unsigned_p = 1;                /* Try something unsigned */

  1677.       /* Portably test for unsigned overflow.
  1678.          FIXME: This check is wrong; for example it doesn't find overflow
  1679.          on 0x123456789 when LONGEST is 32 bits.  */
  1680.       if (c != 'l' && c != 'u' && n != 0)
  1681.         {
  1682.           if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
  1683.             error (_("Numeric constant too large."));
  1684.         }
  1685.       prevn = n;
  1686.     }

  1687.   /* An integer constant is an int, a long, or a long long.  An L
  1688.      suffix forces it to be long; an LL suffix forces it to be long
  1689.      long.  If not forced to a larger size, it gets the first type of
  1690.      the above that it fits in.  To figure out whether it fits, we
  1691.      shift it right and see whether anything remains.  Note that we
  1692.      can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  1693.      operation, because many compilers will warn about such a shift
  1694.      (which always produces a zero result).  Sometimes gdbarch_int_bit
  1695.      or gdbarch_long_bit will be that big, sometimes not.  To deal with
  1696.      the case where it is we just always shift the value more than
  1697.      once, with fewer bits each time.  */

  1698.   un = (ULONGEST)n >> 2;
  1699.   if (long_p == 0
  1700.       && (un >> (gdbarch_int_bit (parse_gdbarch (par_state)) - 2)) == 0)
  1701.     {
  1702.       high_bit
  1703.         = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);

  1704.       /* A large decimal (not hex or octal) constant (between INT_MAX
  1705.          and UINT_MAX) is a long or unsigned long, according to ANSI,
  1706.          never an unsigned int, but this code treats it as unsigned
  1707.          int.  This probably should be fixed.  GCC gives a warning on
  1708.          such constants.  */

  1709.       unsigned_type = parse_type (par_state)->builtin_unsigned_int;
  1710.       signed_type = parse_type (par_state)->builtin_int;
  1711.     }
  1712.   else if (long_p <= 1
  1713.            && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 2)) == 0)
  1714.     {
  1715.       high_bit
  1716.         = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch (par_state)) - 1);
  1717.       unsigned_type = parse_type (par_state)->builtin_unsigned_long;
  1718.       signed_type = parse_type (par_state)->builtin_long;
  1719.     }
  1720.   else
  1721.     {
  1722.       int shift;
  1723.       if (sizeof (ULONGEST) * HOST_CHAR_BIT
  1724.           < gdbarch_long_long_bit (parse_gdbarch (par_state)))
  1725.         /* A long long does not fit in a LONGEST.  */
  1726.         shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
  1727.       else
  1728.         shift = (gdbarch_long_long_bit (parse_gdbarch (par_state)) - 1);
  1729.       high_bit = (ULONGEST) 1 << shift;
  1730.       unsigned_type = parse_type (par_state)->builtin_unsigned_long_long;
  1731.       signed_type = parse_type (par_state)->builtin_long_long;
  1732.     }

  1733.    putithere->typed_val_int.val = n;

  1734.    /* If the high bit of the worked out type is set then this number
  1735.       has to be unsigned. */

  1736.    if (unsigned_p || (n & high_bit))
  1737.      {
  1738.        putithere->typed_val_int.type = unsigned_type;
  1739.      }
  1740.    else
  1741.      {
  1742.        putithere->typed_val_int.type = signed_type;
  1743.      }

  1744.    return INT;
  1745. }

  1746. /* Temporary obstack used for holding strings.  */
  1747. static struct obstack tempbuf;
  1748. static int tempbuf_init;

  1749. /* Parse a C escape sequence.  The initial backslash of the sequence
  1750.    is at (*PTR)[-1].  *PTR will be updated to point to just after the
  1751.    last character of the sequence.  If OUTPUT is not NULL, the
  1752.    translated form of the escape sequence will be written there.  If
  1753.    OUTPUT is NULL, no output is written and the call will only affect
  1754.    *PTR.  If an escape sequence is expressed in target bytes, then the
  1755.    entire sequence will simply be copied to OUTPUT.  Return 1 if any
  1756.    character was emitted, 0 otherwise.  */

  1757. int
  1758. c_parse_escape (const char **ptr, struct obstack *output)
  1759. {
  1760.   const char *tokptr = *ptr;
  1761.   int result = 1;

  1762.   /* Some escape sequences undergo character set conversion.  Those we
  1763.      translate here.  */
  1764.   switch (*tokptr)
  1765.     {
  1766.       /* Hex escapes do not undergo character set conversion, so keep
  1767.          the escape sequence for later.  */
  1768.     case 'x':
  1769.       if (output)
  1770.         obstack_grow_str (output, "\\x");
  1771.       ++tokptr;
  1772.       if (!isxdigit (*tokptr))
  1773.         error (_("\\x escape without a following hex digit"));
  1774.       while (isxdigit (*tokptr))
  1775.         {
  1776.           if (output)
  1777.             obstack_1grow (output, *tokptr);
  1778.           ++tokptr;
  1779.         }
  1780.       break;

  1781.       /* Octal escapes do not undergo character set conversion, so
  1782.          keep the escape sequence for later.  */
  1783.     case '0':
  1784.     case '1':
  1785.     case '2':
  1786.     case '3':
  1787.     case '4':
  1788.     case '5':
  1789.     case '6':
  1790.     case '7':
  1791.       {
  1792.         int i;
  1793.         if (output)
  1794.           obstack_grow_str (output, "\\");
  1795.         for (i = 0;
  1796.              i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
  1797.              ++i)
  1798.           {
  1799.             if (output)
  1800.               obstack_1grow (output, *tokptr);
  1801.             ++tokptr;
  1802.           }
  1803.       }
  1804.       break;

  1805.       /* We handle UCNs later.  We could handle them here, but that
  1806.          would mean a spurious error in the case where the UCN could
  1807.          be converted to the target charset but not the host
  1808.          charset.  */
  1809.     case 'u':
  1810.     case 'U':
  1811.       {
  1812.         char c = *tokptr;
  1813.         int i, len = c == 'U' ? 8 : 4;
  1814.         if (output)
  1815.           {
  1816.             obstack_1grow (output, '\\');
  1817.             obstack_1grow (output, *tokptr);
  1818.           }
  1819.         ++tokptr;
  1820.         if (!isxdigit (*tokptr))
  1821.           error (_("\\%c escape without a following hex digit"), c);
  1822.         for (i = 0; i < len && isxdigit (*tokptr); ++i)
  1823.           {
  1824.             if (output)
  1825.               obstack_1grow (output, *tokptr);
  1826.             ++tokptr;
  1827.           }
  1828.       }
  1829.       break;

  1830.       /* We must pass backslash through so that it does not
  1831.          cause quoting during the second expansion.  */
  1832.     case '\\':
  1833.       if (output)
  1834.         obstack_grow_str (output, "\\\\");
  1835.       ++tokptr;
  1836.       break;

  1837.       /* Escapes which undergo conversion.  */
  1838.     case 'a':
  1839.       if (output)
  1840.         obstack_1grow (output, '\a');
  1841.       ++tokptr;
  1842.       break;
  1843.     case 'b':
  1844.       if (output)
  1845.         obstack_1grow (output, '\b');
  1846.       ++tokptr;
  1847.       break;
  1848.     case 'f':
  1849.       if (output)
  1850.         obstack_1grow (output, '\f');
  1851.       ++tokptr;
  1852.       break;
  1853.     case 'n':
  1854.       if (output)
  1855.         obstack_1grow (output, '\n');
  1856.       ++tokptr;
  1857.       break;
  1858.     case 'r':
  1859.       if (output)
  1860.         obstack_1grow (output, '\r');
  1861.       ++tokptr;
  1862.       break;
  1863.     case 't':
  1864.       if (output)
  1865.         obstack_1grow (output, '\t');
  1866.       ++tokptr;
  1867.       break;
  1868.     case 'v':
  1869.       if (output)
  1870.         obstack_1grow (output, '\v');
  1871.       ++tokptr;
  1872.       break;

  1873.       /* GCC extension.  */
  1874.     case 'e':
  1875.       if (output)
  1876.         obstack_1grow (output, HOST_ESCAPE_CHAR);
  1877.       ++tokptr;
  1878.       break;

  1879.       /* Backslash-newline expands to nothing at all.  */
  1880.     case '\n':
  1881.       ++tokptr;
  1882.       result = 0;
  1883.       break;

  1884.       /* A few escapes just expand to the character itself.  */
  1885.     case '\'':
  1886.     case '\"':
  1887.     case '?':
  1888.       /* GCC extensions.  */
  1889.     case '(':
  1890.     case '{':
  1891.     case '[':
  1892.     case '%':
  1893.       /* Unrecognized escapes turn into the character itself.  */
  1894.     default:
  1895.       if (output)
  1896.         obstack_1grow (output, *tokptr);
  1897.       ++tokptr;
  1898.       break;
  1899.     }
  1900.   *ptr = tokptr;
  1901.   return result;
  1902. }

  1903. /* Parse a string or character literal from TOKPTR.  The string or
  1904.    character may be wide or unicode.  *OUTPTR is set to just after the
  1905.    end of the literal in the input string.  The resulting token is
  1906.    stored in VALUE.  This returns a token value, either STRING or
  1907.    CHAR, depending on what was parsed.  *HOST_CHARS is set to the
  1908.    number of host characters in the literal.  */

  1909. static int
  1910. parse_string_or_char (const char *tokptr, const char **outptr,
  1911.                       struct typed_stoken *value, int *host_chars)
  1912. {
  1913.   int quote;
  1914.   enum c_string_type type;
  1915.   int is_objc = 0;

  1916.   /* Build the gdb internal form of the input string in tempbuf.  Note
  1917.      that the buffer is null byte terminated *only* for the
  1918.      convenience of debugging gdb itself and printing the buffer
  1919.      contents when the buffer contains no embedded nulls.  Gdb does
  1920.      not depend upon the buffer being null byte terminated, it uses
  1921.      the length string instead.  This allows gdb to handle C strings
  1922.      (as well as strings in other languages) with embedded null
  1923.      bytes */

  1924.   if (!tempbuf_init)
  1925.     tempbuf_init = 1;
  1926.   else
  1927.     obstack_free (&tempbuf, NULL);
  1928.   obstack_init (&tempbuf);

  1929.   /* Record the string type.  */
  1930.   if (*tokptr == 'L')
  1931.     {
  1932.       type = C_WIDE_STRING;
  1933.       ++tokptr;
  1934.     }
  1935.   else if (*tokptr == 'u')
  1936.     {
  1937.       type = C_STRING_16;
  1938.       ++tokptr;
  1939.     }
  1940.   else if (*tokptr == 'U')
  1941.     {
  1942.       type = C_STRING_32;
  1943.       ++tokptr;
  1944.     }
  1945.   else if (*tokptr == '@')
  1946.     {
  1947.       /* An Objective C string.  */
  1948.       is_objc = 1;
  1949.       type = C_STRING;
  1950.       ++tokptr;
  1951.     }
  1952.   else
  1953.     type = C_STRING;

  1954.   /* Skip the quote.  */
  1955.   quote = *tokptr;
  1956.   if (quote == '\'')
  1957.     type |= C_CHAR;
  1958.   ++tokptr;

  1959.   *host_chars = 0;

  1960.   while (*tokptr)
  1961.     {
  1962.       char c = *tokptr;
  1963.       if (c == '\\')
  1964.         {
  1965.           ++tokptr;
  1966.           *host_chars += c_parse_escape (&tokptr, &tempbuf);
  1967.         }
  1968.       else if (c == quote)
  1969.         break;
  1970.       else
  1971.         {
  1972.           obstack_1grow (&tempbuf, c);
  1973.           ++tokptr;
  1974.           /* FIXME: this does the wrong thing with multi-byte host
  1975.              characters.  We could use mbrlen here, but that would
  1976.              make "set host-charset" a bit less useful.  */
  1977.           ++*host_chars;
  1978.         }
  1979.     }

  1980.   if (*tokptr != quote)
  1981.     {
  1982.       if (quote == '"')
  1983.         error (_("Unterminated string in expression."));
  1984.       else
  1985.         error (_("Unmatched single quote."));
  1986.     }
  1987.   ++tokptr;

  1988.   value->type = type;
  1989.   value->ptr = obstack_base (&tempbuf);
  1990.   value->length = obstack_object_size (&tempbuf);

  1991.   *outptr = tokptr;

  1992.   return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR;
  1993. }

  1994. /* This is used to associate some attributes with a token.  */

  1995. enum token_flags
  1996. {
  1997.   /* If this bit is set, the token is C++-only.  */

  1998.   FLAG_CXX = 1,

  1999.   /* If this bit is set, the token is conditional: if there is a
  2000.      symbol of the same name, then the token is a symbol; otherwise,
  2001.      the token is a keyword.  */

  2002.   FLAG_SHADOW = 2
  2003. };

  2004. struct token
  2005. {
  2006.   char *operator;
  2007.   int token;
  2008.   enum exp_opcode opcode;
  2009.   enum token_flags flags;
  2010. };

  2011. static const struct token tokentab3[] =
  2012.   {
  2013.     {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
  2014.     {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
  2015.     {"->*", ARROW_STAR, BINOP_END, FLAG_CXX},
  2016.     {"...", DOTDOTDOT, BINOP_END, 0}
  2017.   };

  2018. static const struct token tokentab2[] =
  2019.   {
  2020.     {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
  2021.     {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
  2022.     {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
  2023.     {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
  2024.     {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
  2025.     {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
  2026.     {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
  2027.     {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
  2028.     {"++", INCREMENT, BINOP_END, 0},
  2029.     {"--", DECREMENT, BINOP_END, 0},
  2030.     {"->", ARROW, BINOP_END, 0},
  2031.     {"&&", ANDAND, BINOP_END, 0},
  2032.     {"||", OROR, BINOP_END, 0},
  2033.     /* "::" is *not* only C++: gdb overrides its meaning in several
  2034.        different ways, e.g., 'filename'::func, function::variable.  */
  2035.     {"::", COLONCOLON, BINOP_END, 0},
  2036.     {"<<", LSH, BINOP_END, 0},
  2037.     {">>", RSH, BINOP_END, 0},
  2038.     {"==", EQUAL, BINOP_END, 0},
  2039.     {"!=", NOTEQUAL, BINOP_END, 0},
  2040.     {"<=", LEQ, BINOP_END, 0},
  2041.     {">=", GEQ, BINOP_END, 0},
  2042.     {".*", DOT_STAR, BINOP_END, FLAG_CXX}
  2043.   };

  2044. /* Identifier-like tokens.  */
  2045. static const struct token ident_tokens[] =
  2046.   {
  2047.     {"unsigned", UNSIGNED, OP_NULL, 0},
  2048.     {"template", TEMPLATE, OP_NULL, FLAG_CXX},
  2049.     {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
  2050.     {"struct", STRUCT, OP_NULL, 0},
  2051.     {"signed", SIGNED_KEYWORD, OP_NULL, 0},
  2052.     {"sizeof", SIZEOF, OP_NULL, 0},
  2053.     {"double", DOUBLE_KEYWORD, OP_NULL, 0},
  2054.     {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
  2055.     {"class", CLASS, OP_NULL, FLAG_CXX},
  2056.     {"union", UNION, OP_NULL, 0},
  2057.     {"short", SHORT, OP_NULL, 0},
  2058.     {"const", CONST_KEYWORD, OP_NULL, 0},
  2059.     {"enum", ENUM, OP_NULL, 0},
  2060.     {"long", LONG, OP_NULL, 0},
  2061.     {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
  2062.     {"int", INT_KEYWORD, OP_NULL, 0},
  2063.     {"new", NEW, OP_NULL, FLAG_CXX},
  2064.     {"delete", DELETE, OP_NULL, FLAG_CXX},
  2065.     {"operator", OPERATOR, OP_NULL, FLAG_CXX},

  2066.     {"and", ANDAND, BINOP_END, FLAG_CXX},
  2067.     {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
  2068.     {"bitand", '&', OP_NULL, FLAG_CXX},
  2069.     {"bitor", '|', OP_NULL, FLAG_CXX},
  2070.     {"compl", '~', OP_NULL, FLAG_CXX},
  2071.     {"not", '!', OP_NULL, FLAG_CXX},
  2072.     {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX},
  2073.     {"or", OROR, BINOP_END, FLAG_CXX},
  2074.     {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX},
  2075.     {"xor", '^', OP_NULL, FLAG_CXX},
  2076.     {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX},

  2077.     {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX },
  2078.     {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX },
  2079.     {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX },
  2080.     {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX },

  2081.     {"__typeof__", TYPEOF, OP_TYPEOF, 0 },
  2082.     {"__typeof", TYPEOF, OP_TYPEOF, 0 },
  2083.     {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW },
  2084.     {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX },
  2085.     {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW },

  2086.     {"typeid", TYPEID, OP_TYPEID, FLAG_CXX}
  2087.   };

  2088. /* When we find that lexptr (the global var defined in parse.c) is
  2089.    pointing at a macro invocation, we expand the invocation, and call
  2090.    scan_macro_expansion to save the old lexptr here and point lexptr
  2091.    into the expanded text.  When we reach the end of that, we call
  2092.    end_macro_expansion to pop back to the value we saved here.  The
  2093.    macro expansion code promises to return only fully-expanded text,
  2094.    so we don't need to "push" more than one level.

  2095.    This is disgusting, of course.  It would be cleaner to do all macro
  2096.    expansion beforehand, and then hand that to lexptr.  But we don't
  2097.    really know where the expression ends.  Remember, in a command like

  2098.      (gdb) break *ADDRESS if CONDITION

  2099.    we evaluate ADDRESS in the scope of the current frame, but we
  2100.    evaluate CONDITION in the scope of the breakpoint's location.  So
  2101.    it's simply wrong to try to macro-expand the whole thing at once.  */
  2102. static const char *macro_original_text;

  2103. /* We save all intermediate macro expansions on this obstack for the
  2104.    duration of a single parse.  The expansion text may sometimes have
  2105.    to live past the end of the expansion, due to yacc lookahead.
  2106.    Rather than try to be clever about saving the data for a single
  2107.    token, we simply keep it all and delete it after parsing has
  2108.    completed.  */
  2109. static struct obstack expansion_obstack;

  2110. static void
  2111. scan_macro_expansion (char *expansion)
  2112. {
  2113.   char *copy;

  2114.   /* We'd better not be trying to push the stack twice.  */
  2115.   gdb_assert (! macro_original_text);

  2116.   /* Copy to the obstack, and then free the intermediate
  2117.      expansion.  */
  2118.   copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
  2119.   xfree (expansion);

  2120.   /* Save the old lexptr value, so we can return to it when we're done
  2121.      parsing the expanded text.  */
  2122.   macro_original_text = lexptr;
  2123.   lexptr = copy;
  2124. }

  2125. static int
  2126. scanning_macro_expansion (void)
  2127. {
  2128.   return macro_original_text != 0;
  2129. }

  2130. static void
  2131. finished_macro_expansion (void)
  2132. {
  2133.   /* There'd better be something to pop back to.  */
  2134.   gdb_assert (macro_original_text);

  2135.   /* Pop back to the original text.  */
  2136.   lexptr = macro_original_text;
  2137.   macro_original_text = 0;
  2138. }

  2139. static void
  2140. scan_macro_cleanup (void *dummy)
  2141. {
  2142.   if (macro_original_text)
  2143.     finished_macro_expansion ();

  2144.   obstack_free (&expansion_obstack, NULL);
  2145. }

  2146. /* Return true iff the token represents a C++ cast operator.  */

  2147. static int
  2148. is_cast_operator (const char *token, int len)
  2149. {
  2150.   return (! strncmp (token, "dynamic_cast", len)
  2151.           || ! strncmp (token, "static_cast", len)
  2152.           || ! strncmp (token, "reinterpret_cast", len)
  2153.           || ! strncmp (token, "const_cast", len));
  2154. }

  2155. /* The scope used for macro expansion.  */
  2156. static struct macro_scope *expression_macro_scope;

  2157. /* This is set if a NAME token appeared at the very end of the input
  2158.    string, with no whitespace separating the name from the EOF.  This
  2159.    is used only when parsing to do field name completion.  */
  2160. static int saw_name_at_eof;

  2161. /* This is set if the previously-returned token was a structure
  2162.    operator -- either '.' or ARROW.  This is used only when parsing to
  2163.    do field name completion.  */
  2164. static int last_was_structop;

  2165. /* Read one token, getting characters through lexptr.  */

  2166. static int
  2167. lex_one_token (struct parser_state *par_state, int *is_quoted_name)
  2168. {
  2169.   int c;
  2170.   int namelen;
  2171.   unsigned int i;
  2172.   const char *tokstart;
  2173.   int saw_structop = last_was_structop;
  2174.   char *copy;

  2175.   last_was_structop = 0;
  2176.   *is_quoted_name = 0;

  2177. retry:

  2178.   /* Check if this is a macro invocation that we need to expand.  */
  2179.   if (! scanning_macro_expansion ())
  2180.     {
  2181.       char *expanded = macro_expand_next (&lexptr,
  2182.                                           standard_macro_lookup,
  2183.                                           expression_macro_scope);

  2184.       if (expanded)
  2185.         scan_macro_expansion (expanded);
  2186.     }

  2187.   prev_lexptr = lexptr;

  2188.   tokstart = lexptr;
  2189.   /* See if it is a special token of length 3.  */
  2190.   for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
  2191.     if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
  2192.       {
  2193.         if ((tokentab3[i].flags & FLAG_CXX) != 0
  2194.             && parse_language (par_state)->la_language != language_cplus)
  2195.           break;

  2196.         lexptr += 3;
  2197.         yylval.opcode = tokentab3[i].opcode;
  2198.         return tokentab3[i].token;
  2199.       }

  2200.   /* See if it is a special token of length 2.  */
  2201.   for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
  2202.     if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
  2203.       {
  2204.         if ((tokentab2[i].flags & FLAG_CXX) != 0
  2205.             && parse_language (par_state)->la_language != language_cplus)
  2206.           break;

  2207.         lexptr += 2;
  2208.         yylval.opcode = tokentab2[i].opcode;
  2209.         if (parse_completion && tokentab2[i].token == ARROW)
  2210.           last_was_structop = 1;
  2211.         return tokentab2[i].token;
  2212.       }

  2213.   switch (c = *tokstart)
  2214.     {
  2215.     case 0:
  2216.       /* If we were just scanning the result of a macro expansion,
  2217.          then we need to resume scanning the original text.
  2218.          If we're parsing for field name completion, and the previous
  2219.          token allows such completion, return a COMPLETE token.
  2220.          Otherwise, we were already scanning the original text, and
  2221.          we're really done.  */
  2222.       if (scanning_macro_expansion ())
  2223.         {
  2224.           finished_macro_expansion ();
  2225.           goto retry;
  2226.         }
  2227.       else if (saw_name_at_eof)
  2228.         {
  2229.           saw_name_at_eof = 0;
  2230.           return COMPLETE;
  2231.         }
  2232.       else if (saw_structop)
  2233.         return COMPLETE;
  2234.       else
  2235.         return 0;

  2236.     case ' ':
  2237.     case '\t':
  2238.     case '\n':
  2239.       lexptr++;
  2240.       goto retry;

  2241.     case '[':
  2242.     case '(':
  2243.       paren_depth++;
  2244.       lexptr++;
  2245.       if (parse_language (par_state)->la_language == language_objc
  2246.           && c == '[')
  2247.         return OBJC_LBRAC;
  2248.       return c;

  2249.     case ']':
  2250.     case ')':
  2251.       if (paren_depth == 0)
  2252.         return 0;
  2253.       paren_depth--;
  2254.       lexptr++;
  2255.       return c;

  2256.     case ',':
  2257.       if (comma_terminates
  2258.           && paren_depth == 0
  2259.           && ! scanning_macro_expansion ())
  2260.         return 0;
  2261.       lexptr++;
  2262.       return c;

  2263.     case '.':
  2264.       /* Might be a floating point number.  */
  2265.       if (lexptr[1] < '0' || lexptr[1] > '9')
  2266.         {
  2267.           if (parse_completion)
  2268.             last_was_structop = 1;
  2269.           goto symbol;                /* Nope, must be a symbol. */
  2270.         }
  2271.       /* FALL THRU into number case.  */

  2272.     case '0':
  2273.     case '1':
  2274.     case '2':
  2275.     case '3':
  2276.     case '4':
  2277.     case '5':
  2278.     case '6':
  2279.     case '7':
  2280.     case '8':
  2281.     case '9':
  2282.       {
  2283.         /* It's a number.  */
  2284.         int got_dot = 0, got_e = 0, toktype;
  2285.         const char *p = tokstart;
  2286.         int hex = input_radix > 10;

  2287.         if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
  2288.           {
  2289.             p += 2;
  2290.             hex = 1;
  2291.           }
  2292.         else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  2293.           {
  2294.             p += 2;
  2295.             hex = 0;
  2296.           }

  2297.         for (;; ++p)
  2298.           {
  2299.             /* This test includes !hex because 'e' is a valid hex digit
  2300.                and thus does not indicate a floating point number when
  2301.                the radix is hex.  */
  2302.             if (!hex && !got_e && (*p == 'e' || *p == 'E'))
  2303.               got_dot = got_e = 1;
  2304.             /* This test does not include !hex, because a '.' always indicates
  2305.                a decimal floating point number regardless of the radix.  */
  2306.             else if (!got_dot && *p == '.')
  2307.               got_dot = 1;
  2308.             else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
  2309.                      && (*p == '-' || *p == '+'))
  2310.               /* This is the sign of the exponent, not the end of the
  2311.                  number.  */
  2312.               continue;
  2313.             /* We will take any letters or digits.  parse_number will
  2314.                complain if past the radix, or if L or U are not final.  */
  2315.             else if ((*p < '0' || *p > '9')
  2316.                      && ((*p < 'a' || *p > 'z')
  2317.                                   && (*p < 'A' || *p > 'Z')))
  2318.               break;
  2319.           }
  2320.         toktype = parse_number (par_state, tokstart, p - tokstart,
  2321.                                 got_dot|got_e, &yylval);
  2322.         if (toktype == ERROR)
  2323.           {
  2324.             char *err_copy = (char *) alloca (p - tokstart + 1);

  2325.             memcpy (err_copy, tokstart, p - tokstart);
  2326.             err_copy[p - tokstart] = 0;
  2327.             error (_("Invalid number \"%s\"."), err_copy);
  2328.           }
  2329.         lexptr = p;
  2330.         return toktype;
  2331.       }

  2332.     case '@':
  2333.       {
  2334.         const char *p = &tokstart[1];
  2335.         size_t len = strlen ("entry");

  2336.         if (parse_language (par_state)->la_language == language_objc)
  2337.           {
  2338.             size_t len = strlen ("selector");

  2339.             if (strncmp (p, "selector", len) == 0
  2340.                 && (p[len] == '\0' || isspace (p[len])))
  2341.               {
  2342.                 lexptr = p + len;
  2343.                 return SELECTOR;
  2344.               }
  2345.             else if (*p == '"')
  2346.               goto parse_string;
  2347.           }

  2348.         while (isspace (*p))
  2349.           p++;
  2350.         if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
  2351.             && p[len] != '_')
  2352.           {
  2353.             lexptr = &p[len];
  2354.             return ENTRY;
  2355.           }
  2356.       }
  2357.       /* FALLTHRU */
  2358.     case '+':
  2359.     case '-':
  2360.     case '*':
  2361.     case '/':
  2362.     case '%':
  2363.     case '|':
  2364.     case '&':
  2365.     case '^':
  2366.     case '~':
  2367.     case '!':
  2368.     case '<':
  2369.     case '>':
  2370.     case '?':
  2371.     case ':':
  2372.     case '=':
  2373.     case '{':
  2374.     case '}':
  2375.     symbol:
  2376.       lexptr++;
  2377.       return c;

  2378.     case 'L':
  2379.     case 'u':
  2380.     case 'U':
  2381.       if (tokstart[1] != '"' && tokstart[1] != '\'')
  2382.         break;
  2383.       /* Fall through.  */
  2384.     case '\'':
  2385.     case '"':

  2386.     parse_string:
  2387.       {
  2388.         int host_len;
  2389.         int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
  2390.                                            &host_len);
  2391.         if (result == CHAR)
  2392.           {
  2393.             if (host_len == 0)
  2394.               error (_("Empty character constant."));
  2395.             else if (host_len > 2 && c == '\'')
  2396.               {
  2397.                 ++tokstart;
  2398.                 namelen = lexptr - tokstart - 1;
  2399.                 *is_quoted_name = 1;

  2400.                 goto tryname;
  2401.               }
  2402.             else if (host_len > 1)
  2403.               error (_("Invalid character constant."));
  2404.           }
  2405.         return result;
  2406.       }
  2407.     }

  2408.   if (!(c == '_' || c == '$'
  2409.         || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
  2410.     /* We must have come across a bad character (e.g. ';').  */
  2411.     error (_("Invalid character '%c' in expression."), c);

  2412.   /* It's a name.  See how long it is.  */
  2413.   namelen = 0;
  2414.   for (c = tokstart[namelen];
  2415.        (c == '_' || c == '$' || (c >= '0' && c <= '9')
  2416.         || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
  2417.     {
  2418.       /* Template parameter lists are part of the name.
  2419.          FIXME: This mishandles `print $a<4&&$a>3'.  */

  2420.       if (c == '<')
  2421.         {
  2422.           if (! is_cast_operator (tokstart, namelen))
  2423.             {
  2424.               /* Scan ahead to get rest of the template specification.  Note
  2425.                  that we look ahead only when the '<' adjoins non-whitespace
  2426.                  characters; for comparison expressions, e.g. "a < b > c",
  2427.                  there must be spaces before the '<', etc. */
  2428.               const char *p = find_template_name_end (tokstart + namelen);

  2429.               if (p)
  2430.                 namelen = p - tokstart;
  2431.             }
  2432.           break;
  2433.         }
  2434.       c = tokstart[++namelen];
  2435.     }

  2436.   /* The token "if" terminates the expression and is NOT removed from
  2437.      the input stream.  It doesn't count if it appears in the
  2438.      expansion of a macro.  */
  2439.   if (namelen == 2
  2440.       && tokstart[0] == 'i'
  2441.       && tokstart[1] == 'f'
  2442.       && ! scanning_macro_expansion ())
  2443.     {
  2444.       return 0;
  2445.     }

  2446.   /* For the same reason (breakpoint conditions), "thread N"
  2447.      terminates the expression.  "thread" could be an identifier, but
  2448.      an identifier is never followed by a number without intervening
  2449.      punctuation.  "task" is similar.  Handle abbreviations of these,
  2450.      similarly to breakpoint.c:find_condition_and_thread.  */
  2451.   if (namelen >= 1
  2452.       && (strncmp (tokstart, "thread", namelen) == 0
  2453.           || strncmp (tokstart, "task", namelen) == 0)
  2454.       && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
  2455.       && ! scanning_macro_expansion ())
  2456.     {
  2457.       const char *p = tokstart + namelen + 1;

  2458.       while (*p == ' ' || *p == '\t')
  2459.         p++;
  2460.       if (*p >= '0' && *p <= '9')
  2461.         return 0;
  2462.     }

  2463.   lexptr += namelen;

  2464.   tryname:

  2465.   yylval.sval.ptr = tokstart;
  2466.   yylval.sval.length = namelen;

  2467.   /* Catch specific keywords.  */
  2468.   copy = copy_name (yylval.sval);
  2469.   for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
  2470.     if (strcmp (copy, ident_tokens[i].operator) == 0)
  2471.       {
  2472.         if ((ident_tokens[i].flags & FLAG_CXX) != 0
  2473.             && parse_language (par_state)->la_language != language_cplus)
  2474.           break;

  2475.         if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
  2476.           {
  2477.             struct field_of_this_result is_a_field_of_this;

  2478.             if (lookup_symbol (copy, expression_context_block,
  2479.                                VAR_DOMAIN,
  2480.                                (parse_language (par_state)->la_language
  2481.                                 == language_cplus ? &is_a_field_of_this
  2482.                                 : NULL))
  2483.                 != NULL)
  2484.               {
  2485.                 /* The keyword is shadowed.  */
  2486.                 break;
  2487.               }
  2488.           }

  2489.         /* It is ok to always set this, even though we don't always
  2490.            strictly need to.  */
  2491.         yylval.opcode = ident_tokens[i].opcode;
  2492.         return ident_tokens[i].token;
  2493.       }

  2494.   if (*tokstart == '$')
  2495.     return VARIABLE;

  2496.   if (parse_completion && *lexptr == '\0')
  2497.     saw_name_at_eof = 1;

  2498.   yylval.ssym.stoken = yylval.sval;
  2499.   yylval.ssym.sym = NULL;
  2500.   yylval.ssym.is_a_field_of_this = 0;
  2501.   return NAME;
  2502. }

  2503. /* An object of this type is pushed on a FIFO by the "outer" lexer.  */
  2504. typedef struct
  2505. {
  2506.   int token;
  2507.   YYSTYPE value;
  2508. } token_and_value;

  2509. DEF_VEC_O (token_and_value);

  2510. /* A FIFO of tokens that have been read but not yet returned to the
  2511.    parser.  */
  2512. static VEC (token_and_value) *token_fifo;

  2513. /* Non-zero if the lexer should return tokens from the FIFO.  */
  2514. static int popping;

  2515. /* Temporary storage for c_lex; this holds symbol names as they are
  2516.    built up.  */
  2517. static struct obstack name_obstack;

  2518. /* Classify a NAME token.  The contents of the token are in `yylval'.
  2519.    Updates yylval and returns the new token type.  BLOCK is the block
  2520.    in which lookups start; this can be NULL to mean the global scope.
  2521.    IS_QUOTED_NAME is non-zero if the name token was originally quoted
  2522.    in single quotes.  */

  2523. static int
  2524. classify_name (struct parser_state *par_state, const struct block *block,
  2525.                int is_quoted_name)
  2526. {
  2527.   struct symbol *sym;
  2528.   char *copy;
  2529.   struct field_of_this_result is_a_field_of_this;

  2530.   copy = copy_name (yylval.sval);

  2531.   /* Initialize this in case we *don't* use it in this call; that way
  2532.      we can refer to it unconditionally below.  */
  2533.   memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));

  2534.   sym = lookup_symbol (copy, block, VAR_DOMAIN,
  2535.                        parse_language (par_state)->la_name_of_this
  2536.                        ? &is_a_field_of_this : NULL);

  2537.   if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
  2538.     {
  2539.       yylval.ssym.sym = sym;
  2540.       yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
  2541.       return BLOCKNAME;
  2542.     }
  2543.   else if (!sym)
  2544.     {
  2545.       /* If we found a field of 'this', we might have erroneously
  2546.          found a constructor where we wanted a type name.  Handle this
  2547.          case by noticing that we found a constructor and then look up
  2548.          the type tag instead.  */
  2549.       if (is_a_field_of_this.type != NULL
  2550.           && is_a_field_of_this.fn_field != NULL
  2551.           && TYPE_FN_FIELD_CONSTRUCTOR (is_a_field_of_this.fn_field->fn_fields,
  2552.                                         0))
  2553.         {
  2554.           struct field_of_this_result inner_is_a_field_of_this;

  2555.           sym = lookup_symbol (copy, block, STRUCT_DOMAIN,
  2556.                                &inner_is_a_field_of_this);
  2557.           if (sym != NULL)
  2558.             {
  2559.               yylval.tsym.type = SYMBOL_TYPE (sym);
  2560.               return TYPENAME;
  2561.             }
  2562.         }

  2563.       /* If we found a field, then we want to prefer it over a
  2564.          filename.  However, if the name was quoted, then it is better
  2565.          to check for a filename or a block, since this is the only
  2566.          way the user has of requiring the extension to be used.  */
  2567.       if (is_a_field_of_this.type == NULL || is_quoted_name)
  2568.         {
  2569.           /* See if it's a file name. */
  2570.           struct symtab *symtab;

  2571.           symtab = lookup_symtab (copy);
  2572.           if (symtab)
  2573.             {
  2574.               yylval.bval = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab),
  2575.                                                STATIC_BLOCK);
  2576.               return FILENAME;
  2577.             }
  2578.         }
  2579.     }

  2580.   if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  2581.     {
  2582.       yylval.tsym.type = SYMBOL_TYPE (sym);
  2583.       return TYPENAME;
  2584.     }

  2585.   /* See if it's an ObjC classname.  */
  2586.   if (parse_language (par_state)->la_language == language_objc && !sym)
  2587.     {
  2588.       CORE_ADDR Class = lookup_objc_class (parse_gdbarch (par_state), copy);
  2589.       if (Class)
  2590.         {
  2591.           yylval.class.class = Class;
  2592.           sym = lookup_struct_typedef (copy, expression_context_block, 1);
  2593.           if (sym)
  2594.             yylval.class.type = SYMBOL_TYPE (sym);
  2595.           return CLASSNAME;
  2596.         }
  2597.     }

  2598.   /* Input names that aren't symbols but ARE valid hex numbers, when
  2599.      the input radix permits them, can be names or numbers depending
  2600.      on the parse.  Note we support radixes > 16 here.  */
  2601.   if (!sym
  2602.       && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
  2603.           || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
  2604.     {
  2605.       YYSTYPE newlval;        /* Its value is ignored.  */
  2606.       int hextype = parse_number (par_state, copy, yylval.sval.length,
  2607.                                   0, &newlval);
  2608.       if (hextype == INT)
  2609.         {
  2610.           yylval.ssym.sym = sym;
  2611.           yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
  2612.           return NAME_OR_INT;
  2613.         }
  2614.     }

  2615.   /* Any other kind of symbol */
  2616.   yylval.ssym.sym = sym;
  2617.   yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;

  2618.   if (sym == NULL
  2619.       && parse_language (par_state)->la_language == language_cplus
  2620.       && is_a_field_of_this.type == NULL
  2621.       && lookup_minimal_symbol (copy, NULL, NULL).minsym == NULL)
  2622.     return UNKNOWN_CPP_NAME;

  2623.   return NAME;
  2624. }

  2625. /* Like classify_name, but used by the inner loop of the lexer, when a
  2626.    name might have already been seen.  CONTEXT is the context type, or
  2627.    NULL if this is the first component of a name.  */

  2628. static int
  2629. classify_inner_name (struct parser_state *par_state,
  2630.                      const struct block *block, struct type *context)
  2631. {
  2632.   struct type *type;
  2633.   char *copy;

  2634.   if (context == NULL)
  2635.     return classify_name (par_state, block, 0);

  2636.   type = check_typedef (context);
  2637.   if (!type_aggregate_p (type))
  2638.     return ERROR;

  2639.   copy = copy_name (yylval.ssym.stoken);
  2640.   yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block);

  2641.   /* If no symbol was found, search for a matching base class named
  2642.      COPY.  This will allow users to enter qualified names of class members
  2643.      relative to the `this' pointer.  */
  2644.   if (yylval.ssym.sym == NULL)
  2645.     {
  2646.       struct type *base_type = cp_find_type_baseclass_by_name (type, copy);

  2647.       if (base_type != NULL)
  2648.         {
  2649.           yylval.tsym.type = base_type;
  2650.           return TYPENAME;
  2651.         }

  2652.       return ERROR;
  2653.     }

  2654.   switch (SYMBOL_CLASS (yylval.ssym.sym))
  2655.     {
  2656.     case LOC_BLOCK:
  2657.     case LOC_LABEL:
  2658.       /* cp_lookup_nested_symbol might have accidentally found a constructor
  2659.          named COPY when we really wanted a base class of the same name.
  2660.          Double-check this case by looking for a base class.  */
  2661.       {
  2662.         struct type *base_type = cp_find_type_baseclass_by_name (type, copy);

  2663.         if (base_type != NULL)
  2664.           {
  2665.             yylval.tsym.type = base_type;
  2666.             return TYPENAME;
  2667.           }
  2668.       }
  2669.       return ERROR;

  2670.     case LOC_TYPEDEF:
  2671.       yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);
  2672.       return TYPENAME;

  2673.     default:
  2674.       return NAME;
  2675.     }
  2676.   internal_error (__FILE__, __LINE__, _("not reached"));
  2677. }

  2678. /* The outer level of a two-level lexer.  This calls the inner lexer
  2679.    to return tokens.  It then either returns these tokens, or
  2680.    aggregates them into a larger token.  This lets us work around a
  2681.    problem in our parsing approach, where the parser could not
  2682.    distinguish between qualified names and qualified types at the
  2683.    right point.

  2684.    This approach is still not ideal, because it mishandles template
  2685.    types.  See the comment in lex_one_token for an example.  However,
  2686.    this is still an improvement over the earlier approach, and will
  2687.    suffice until we move to better parsing technology.  */

  2688. static int
  2689. yylex (void)
  2690. {
  2691.   token_and_value current;
  2692.   int first_was_coloncolon, last_was_coloncolon;
  2693.   struct type *context_type = NULL;
  2694.   int last_to_examine, next_to_examine, checkpoint;
  2695.   const struct block *search_block;
  2696.   int is_quoted_name;

  2697.   if (popping && !VEC_empty (token_and_value, token_fifo))
  2698.     goto do_pop;
  2699.   popping = 0;

  2700.   /* Read the first token and decide what to do.  Most of the
  2701.      subsequent code is C++-only; but also depends on seeing a "::" or
  2702.      name-like token.  */
  2703.   current.token = lex_one_token (pstate, &is_quoted_name);
  2704.   if (current.token == NAME)
  2705.     current.token = classify_name (pstate, expression_context_block,
  2706.                                    is_quoted_name);
  2707.   if (parse_language (pstate)->la_language != language_cplus
  2708.       || (current.token != TYPENAME && current.token != COLONCOLON
  2709.           && current.token != FILENAME))
  2710.     return current.token;

  2711.   /* Read any sequence of alternating "::" and name-like tokens into
  2712.      the token FIFO.  */
  2713.   current.value = yylval;
  2714.   VEC_safe_push (token_and_value, token_fifo, &current);
  2715.   last_was_coloncolon = current.token == COLONCOLON;
  2716.   while (1)
  2717.     {
  2718.       int ignore;

  2719.       /* We ignore quoted names other than the very first one.
  2720.          Subsequent ones do not have any special meaning.  */
  2721.       current.token = lex_one_token (pstate, &ignore);
  2722.       current.value = yylval;
  2723.       VEC_safe_push (token_and_value, token_fifo, &current);

  2724.       if ((last_was_coloncolon && current.token != NAME)
  2725.           || (!last_was_coloncolon && current.token != COLONCOLON))
  2726.         break;
  2727.       last_was_coloncolon = !last_was_coloncolon;
  2728.     }
  2729.   popping = 1;

  2730.   /* We always read one extra token, so compute the number of tokens
  2731.      to examine accordingly.  */
  2732.   last_to_examine = VEC_length (token_and_value, token_fifo) - 2;
  2733.   next_to_examine = 0;

  2734.   current = *VEC_index (token_and_value, token_fifo, next_to_examine);
  2735.   ++next_to_examine;

  2736.   obstack_free (&name_obstack, obstack_base (&name_obstack));
  2737.   checkpoint = 0;
  2738.   if (current.token == FILENAME)
  2739.     search_block = current.value.bval;
  2740.   else if (current.token == COLONCOLON)
  2741.     search_block = NULL;
  2742.   else
  2743.     {
  2744.       gdb_assert (current.token == TYPENAME);
  2745.       search_block = expression_context_block;
  2746.       obstack_grow (&name_obstack, current.value.sval.ptr,
  2747.                     current.value.sval.length);
  2748.       context_type = current.value.tsym.type;
  2749.       checkpoint = 1;
  2750.     }

  2751.   first_was_coloncolon = current.token == COLONCOLON;
  2752.   last_was_coloncolon = first_was_coloncolon;

  2753.   while (next_to_examine <= last_to_examine)
  2754.     {
  2755.       token_and_value *next;

  2756.       next = VEC_index (token_and_value, token_fifo, next_to_examine);
  2757.       ++next_to_examine;

  2758.       if (next->token == NAME && last_was_coloncolon)
  2759.         {
  2760.           int classification;

  2761.           yylval = next->value;
  2762.           classification = classify_inner_name (pstate, search_block,
  2763.                                                 context_type);
  2764.           /* We keep going until we either run out of names, or until
  2765.              we have a qualified name which is not a type.  */
  2766.           if (classification != TYPENAME && classification != NAME)
  2767.             break;

  2768.           /* Accept up to this token.  */
  2769.           checkpoint = next_to_examine;

  2770.           /* Update the partial name we are constructing.  */
  2771.           if (context_type != NULL)
  2772.             {
  2773.               /* We don't want to put a leading "::" into the name.  */
  2774.               obstack_grow_str (&name_obstack, "::");
  2775.             }
  2776.           obstack_grow (&name_obstack, next->value.sval.ptr,
  2777.                         next->value.sval.length);

  2778.           yylval.sval.ptr = obstack_base (&name_obstack);
  2779.           yylval.sval.length = obstack_object_size (&name_obstack);
  2780.           current.value = yylval;
  2781.           current.token = classification;

  2782.           last_was_coloncolon = 0;

  2783.           if (classification == NAME)
  2784.             break;

  2785.           context_type = yylval.tsym.type;
  2786.         }
  2787.       else if (next->token == COLONCOLON && !last_was_coloncolon)
  2788.         last_was_coloncolon = 1;
  2789.       else
  2790.         {
  2791.           /* We've reached the end of the name.  */
  2792.           break;
  2793.         }
  2794.     }

  2795.   /* If we have a replacement token, install it as the first token in
  2796.      the FIFO, and delete the other constituent tokens.  */
  2797.   if (checkpoint > 0)
  2798.     {
  2799.       current.value.sval.ptr = obstack_copy0 (&expansion_obstack,
  2800.                                               current.value.sval.ptr,
  2801.                                               current.value.sval.length);

  2802.       VEC_replace (token_and_value, token_fifo, 0, &current);
  2803.       if (checkpoint > 1)
  2804.         VEC_block_remove (token_and_value, token_fifo, 1, checkpoint - 1);
  2805.     }

  2806. do_pop:
  2807.   current = *VEC_index (token_and_value, token_fifo, 0);
  2808.   VEC_ordered_remove (token_and_value, token_fifo, 0);
  2809.   yylval = current.value;
  2810.   return current.token;
  2811. }

  2812. int
  2813. c_parse (struct parser_state *par_state)
  2814. {
  2815.   int result;
  2816.   struct cleanup *back_to;

  2817.   /* Setting up the parser state.  */
  2818.   gdb_assert (par_state != NULL);
  2819.   pstate = par_state;

  2820.   back_to = make_cleanup (free_current_contents, &expression_macro_scope);
  2821.   make_cleanup_clear_parser_state (&pstate);

  2822.   /* Set up the scope for macro expansion.  */
  2823.   expression_macro_scope = NULL;

  2824.   if (expression_context_block)
  2825.     expression_macro_scope
  2826.       = sal_macro_scope (find_pc_line (expression_context_pc, 0));
  2827.   else
  2828.     expression_macro_scope = default_macro_scope ();
  2829.   if (! expression_macro_scope)
  2830.     expression_macro_scope = user_macro_scope ();

  2831.   /* Initialize macro expansion code.  */
  2832.   obstack_init (&expansion_obstack);
  2833.   gdb_assert (! macro_original_text);
  2834.   make_cleanup (scan_macro_cleanup, 0);

  2835.   make_cleanup_restore_integer (&yydebug);
  2836.   yydebug = parser_debug;

  2837.   /* Initialize some state used by the lexer.  */
  2838.   last_was_structop = 0;
  2839.   saw_name_at_eof = 0;

  2840.   VEC_free (token_and_value, token_fifo);
  2841.   popping = 0;
  2842.   obstack_init (&name_obstack);
  2843.   make_cleanup_obstack_free (&name_obstack);

  2844.   result = yyparse ();
  2845.   do_cleanups (back_to);

  2846.   return result;
  2847. }

  2848. #ifdef YYBISON

  2849. /* This is called via the YYPRINT macro when parser debugging is
  2850.    enabled.  It prints a token's value.  */

  2851. static void
  2852. c_print_token (FILE *file, int type, YYSTYPE value)
  2853. {
  2854.   switch (type)
  2855.     {
  2856.     case INT:
  2857.       fprintf (file, "typed_val_int<%s, %s>",
  2858.                TYPE_SAFE_NAME (value.typed_val_int.type),
  2859.                pulongest (value.typed_val_int.val));
  2860.       break;

  2861.     case CHAR:
  2862.     case STRING:
  2863.       {
  2864.         char *copy = alloca (value.tsval.length + 1);

  2865.         memcpy (copy, value.tsval.ptr, value.tsval.length);
  2866.         copy[value.tsval.length] = '\0';

  2867.         fprintf (file, "tsval<type=%d, %s>", value.tsval.type, copy);
  2868.       }
  2869.       break;

  2870.     case NSSTRING:
  2871.     case VARIABLE:
  2872.       fprintf (file, "sval<%s>", copy_name (value.sval));
  2873.       break;

  2874.     case TYPENAME:
  2875.       fprintf (file, "tsym<type=%s, name=%s>",
  2876.                TYPE_SAFE_NAME (value.tsym.type),
  2877.                copy_name (value.tsym.stoken));
  2878.       break;

  2879.     case NAME:
  2880.     case UNKNOWN_CPP_NAME:
  2881.     case NAME_OR_INT:
  2882.     case BLOCKNAME:
  2883.       fprintf (file, "ssym<name=%s, sym=%s, field_of_this=%d>",
  2884.                copy_name (value.ssym.stoken),
  2885.                (value.ssym.sym == NULL
  2886.                 ? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym)),
  2887.                value.ssym.is_a_field_of_this);
  2888.       break;

  2889.     case FILENAME:
  2890.       fprintf (file, "bval<%s>", host_address_to_string (value.bval));
  2891.       break;
  2892.     }
  2893. }

  2894. #endif

  2895. void
  2896. yyerror (char *msg)
  2897. {
  2898.   if (prev_lexptr)
  2899.     lexptr = prev_lexptr;

  2900.   error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
  2901. }