xref: /dflybsd-src/contrib/gdb-7/gdb/c-exp.y (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* YACC parser for C expressions, for GDB.
2*ef5ccd6cSJohn Marino    Copyright (C) 1986-2013 Free Software Foundation, Inc.
35796c8dcSSimon Schubert 
45796c8dcSSimon Schubert    This file is part of GDB.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
75796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
85796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
95796c8dcSSimon Schubert    (at your option) any later version.
105796c8dcSSimon Schubert 
115796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
125796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
135796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
145796c8dcSSimon Schubert    GNU General Public License for more details.
155796c8dcSSimon Schubert 
165796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
175796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
185796c8dcSSimon Schubert 
195796c8dcSSimon Schubert /* Parse a C expression from text in a string,
205796c8dcSSimon Schubert    and return the result as a  struct expression  pointer.
215796c8dcSSimon Schubert    That structure contains arithmetic operations in reverse polish,
225796c8dcSSimon Schubert    with constants represented by operations that are followed by special data.
235796c8dcSSimon Schubert    See expression.h for the details of the format.
245796c8dcSSimon Schubert    What is important here is that it can be built up sequentially
255796c8dcSSimon Schubert    during the process of parsing; the lower levels of the tree always
265796c8dcSSimon Schubert    come first in the result.
275796c8dcSSimon Schubert 
285796c8dcSSimon Schubert    Note that malloc's and realloc's in this file are transformed to
295796c8dcSSimon Schubert    xmalloc and xrealloc respectively by the same sed command in the
305796c8dcSSimon Schubert    makefile that remaps any other malloc/realloc inserted by the parser
315796c8dcSSimon Schubert    generator.  Doing this with #defines and trying to control the interaction
325796c8dcSSimon Schubert    with include files (<malloc.h> and <stdlib.h> for example) just became
335796c8dcSSimon Schubert    too messy, particularly when such includes can be inserted at random
345796c8dcSSimon Schubert    times by the parser generator.  */
355796c8dcSSimon Schubert 
365796c8dcSSimon Schubert %{
375796c8dcSSimon Schubert 
385796c8dcSSimon Schubert #include "defs.h"
395796c8dcSSimon Schubert #include "gdb_string.h"
405796c8dcSSimon Schubert #include <ctype.h>
415796c8dcSSimon Schubert #include "expression.h"
425796c8dcSSimon Schubert #include "value.h"
435796c8dcSSimon Schubert #include "parser-defs.h"
445796c8dcSSimon Schubert #include "language.h"
455796c8dcSSimon Schubert #include "c-lang.h"
465796c8dcSSimon Schubert #include "bfd.h" /* Required by objfiles.h.  */
475796c8dcSSimon Schubert #include "symfile.h" /* Required by objfiles.h.  */
485796c8dcSSimon Schubert #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
495796c8dcSSimon Schubert #include "charset.h"
505796c8dcSSimon Schubert #include "block.h"
515796c8dcSSimon Schubert #include "cp-support.h"
525796c8dcSSimon Schubert #include "dfp.h"
535796c8dcSSimon Schubert #include "gdb_assert.h"
545796c8dcSSimon Schubert #include "macroscope.h"
55*ef5ccd6cSJohn Marino #include "objc-lang.h"
56*ef5ccd6cSJohn Marino #include "typeprint.h"
57*ef5ccd6cSJohn Marino #include "cp-abi.h"
585796c8dcSSimon Schubert 
595796c8dcSSimon Schubert #define parse_type builtin_type (parse_gdbarch)
605796c8dcSSimon Schubert 
615796c8dcSSimon Schubert /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
625796c8dcSSimon Schubert    as well as gratuitiously global symbol names, so we can have multiple
635796c8dcSSimon Schubert    yacc generated parsers in gdb.  Note that these are only the variables
645796c8dcSSimon Schubert    produced by yacc.  If other parser generators (bison, byacc, etc) produce
655796c8dcSSimon Schubert    additional global names that conflict at link time, then those parser
665796c8dcSSimon Schubert    generators need to be fixed instead of adding those names to this list. */
675796c8dcSSimon Schubert 
685796c8dcSSimon Schubert #define	yymaxdepth c_maxdepth
695796c8dcSSimon Schubert #define	yyparse	c_parse_internal
705796c8dcSSimon Schubert #define	yylex	c_lex
715796c8dcSSimon Schubert #define	yyerror	c_error
725796c8dcSSimon Schubert #define	yylval	c_lval
735796c8dcSSimon Schubert #define	yychar	c_char
745796c8dcSSimon Schubert #define	yydebug	c_debug
755796c8dcSSimon Schubert #define	yypact	c_pact
765796c8dcSSimon Schubert #define	yyr1	c_r1
775796c8dcSSimon Schubert #define	yyr2	c_r2
785796c8dcSSimon Schubert #define	yydef	c_def
795796c8dcSSimon Schubert #define	yychk	c_chk
805796c8dcSSimon Schubert #define	yypgo	c_pgo
815796c8dcSSimon Schubert #define	yyact	c_act
825796c8dcSSimon Schubert #define	yyexca	c_exca
835796c8dcSSimon Schubert #define yyerrflag c_errflag
845796c8dcSSimon Schubert #define yynerrs	c_nerrs
855796c8dcSSimon Schubert #define	yyps	c_ps
865796c8dcSSimon Schubert #define	yypv	c_pv
875796c8dcSSimon Schubert #define	yys	c_s
885796c8dcSSimon Schubert #define	yy_yys	c_yys
895796c8dcSSimon Schubert #define	yystate	c_state
905796c8dcSSimon Schubert #define	yytmp	c_tmp
915796c8dcSSimon Schubert #define	yyv	c_v
925796c8dcSSimon Schubert #define	yy_yyv	c_yyv
935796c8dcSSimon Schubert #define	yyval	c_val
945796c8dcSSimon Schubert #define	yylloc	c_lloc
955796c8dcSSimon Schubert #define yyreds	c_reds		/* With YYDEBUG defined */
965796c8dcSSimon Schubert #define yytoks	c_toks		/* With YYDEBUG defined */
975796c8dcSSimon Schubert #define yyname	c_name		/* With YYDEBUG defined */
985796c8dcSSimon Schubert #define yyrule	c_rule		/* With YYDEBUG defined */
995796c8dcSSimon Schubert #define yylhs	c_yylhs
1005796c8dcSSimon Schubert #define yylen	c_yylen
1015796c8dcSSimon Schubert #define yydefred c_yydefred
1025796c8dcSSimon Schubert #define yydgoto	c_yydgoto
1035796c8dcSSimon Schubert #define yysindex c_yysindex
1045796c8dcSSimon Schubert #define yyrindex c_yyrindex
1055796c8dcSSimon Schubert #define yygindex c_yygindex
1065796c8dcSSimon Schubert #define yytable	 c_yytable
1075796c8dcSSimon Schubert #define yycheck	 c_yycheck
108*ef5ccd6cSJohn Marino #define yyss	c_yyss
109*ef5ccd6cSJohn Marino #define yysslim	c_yysslim
110*ef5ccd6cSJohn Marino #define yyssp	c_yyssp
111*ef5ccd6cSJohn Marino #define yystacksize c_yystacksize
112*ef5ccd6cSJohn Marino #define yyvs	c_yyvs
113*ef5ccd6cSJohn Marino #define yyvsp	c_yyvsp
1145796c8dcSSimon Schubert 
1155796c8dcSSimon Schubert #ifndef YYDEBUG
1165796c8dcSSimon Schubert #define	YYDEBUG 1		/* Default to yydebug support */
1175796c8dcSSimon Schubert #endif
1185796c8dcSSimon Schubert 
1195796c8dcSSimon Schubert #define YYFPRINTF parser_fprintf
1205796c8dcSSimon Schubert 
1215796c8dcSSimon Schubert int yyparse (void);
1225796c8dcSSimon Schubert 
1235796c8dcSSimon Schubert static int yylex (void);
1245796c8dcSSimon Schubert 
1255796c8dcSSimon Schubert void yyerror (char *);
1265796c8dcSSimon Schubert 
1275796c8dcSSimon Schubert %}
1285796c8dcSSimon Schubert 
1295796c8dcSSimon Schubert /* Although the yacc "value" of an expression is not used,
1305796c8dcSSimon Schubert    since the result is stored in the structure being created,
1315796c8dcSSimon Schubert    other node types do have values.  */
1325796c8dcSSimon Schubert 
1335796c8dcSSimon Schubert %union
1345796c8dcSSimon Schubert   {
1355796c8dcSSimon Schubert     LONGEST lval;
1365796c8dcSSimon Schubert     struct {
1375796c8dcSSimon Schubert       LONGEST val;
1385796c8dcSSimon Schubert       struct type *type;
1395796c8dcSSimon Schubert     } typed_val_int;
1405796c8dcSSimon Schubert     struct {
1415796c8dcSSimon Schubert       DOUBLEST dval;
1425796c8dcSSimon Schubert       struct type *type;
1435796c8dcSSimon Schubert     } typed_val_float;
1445796c8dcSSimon Schubert     struct {
1455796c8dcSSimon Schubert       gdb_byte val[16];
1465796c8dcSSimon Schubert       struct type *type;
1475796c8dcSSimon Schubert     } typed_val_decfloat;
1485796c8dcSSimon Schubert     struct symbol *sym;
1495796c8dcSSimon Schubert     struct type *tval;
1505796c8dcSSimon Schubert     struct stoken sval;
1515796c8dcSSimon Schubert     struct typed_stoken tsval;
1525796c8dcSSimon Schubert     struct ttype tsym;
1535796c8dcSSimon Schubert     struct symtoken ssym;
1545796c8dcSSimon Schubert     int voidval;
1555796c8dcSSimon Schubert     struct block *bval;
1565796c8dcSSimon Schubert     enum exp_opcode opcode;
1575796c8dcSSimon Schubert     struct internalvar *ivar;
1585796c8dcSSimon Schubert 
1595796c8dcSSimon Schubert     struct stoken_vector svec;
160*ef5ccd6cSJohn Marino     VEC (type_ptr) *tvec;
1615796c8dcSSimon Schubert     int *ivec;
162*ef5ccd6cSJohn Marino 
163*ef5ccd6cSJohn Marino     struct type_stack *type_stack;
164*ef5ccd6cSJohn Marino 
165*ef5ccd6cSJohn Marino     struct objc_class_str class;
1665796c8dcSSimon Schubert   }
1675796c8dcSSimon Schubert 
1685796c8dcSSimon Schubert %{
1695796c8dcSSimon Schubert /* YYSTYPE gets defined by %union */
1705796c8dcSSimon Schubert static int parse_number (char *, int, int, YYSTYPE *);
171cf7f2e2dSJohn Marino static struct stoken operator_stoken (const char *);
172*ef5ccd6cSJohn Marino static void check_parameter_typelist (VEC (type_ptr) *);
1735796c8dcSSimon Schubert %}
1745796c8dcSSimon Schubert 
1755796c8dcSSimon Schubert %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
1765796c8dcSSimon Schubert %type <lval> rcurly
177cf7f2e2dSJohn Marino %type <tval> type typebase
178*ef5ccd6cSJohn Marino %type <tvec> nonempty_typelist func_mod parameter_typelist
1795796c8dcSSimon Schubert /* %type <bval> block */
1805796c8dcSSimon Schubert 
1815796c8dcSSimon Schubert /* Fancy type parsing.  */
1825796c8dcSSimon Schubert %type <tval> ptype
1835796c8dcSSimon Schubert %type <lval> array_mod
184*ef5ccd6cSJohn Marino %type <tval> conversion_type_id
185*ef5ccd6cSJohn Marino 
186*ef5ccd6cSJohn Marino %type <type_stack> ptr_operator_ts abs_decl direct_abs_decl
1875796c8dcSSimon Schubert 
1885796c8dcSSimon Schubert %token <typed_val_int> INT
1895796c8dcSSimon Schubert %token <typed_val_float> FLOAT
1905796c8dcSSimon Schubert %token <typed_val_decfloat> DECFLOAT
1915796c8dcSSimon Schubert 
1925796c8dcSSimon Schubert /* Both NAME and TYPENAME tokens represent symbols in the input,
1935796c8dcSSimon Schubert    and both convey their data as strings.
1945796c8dcSSimon Schubert    But a TYPENAME is a string that happens to be defined as a typedef
1955796c8dcSSimon Schubert    or builtin type name (such as int or char)
1965796c8dcSSimon Schubert    and a NAME is any other symbol.
1975796c8dcSSimon Schubert    Contexts where this distinction is not important can use the
1985796c8dcSSimon Schubert    nonterminal "name", which matches either NAME or TYPENAME.  */
1995796c8dcSSimon Schubert 
2005796c8dcSSimon Schubert %token <tsval> STRING
201*ef5ccd6cSJohn Marino %token <sval> NSSTRING		/* ObjC Foundation "NSString" literal */
202*ef5ccd6cSJohn Marino %token SELECTOR			/* ObjC "@selector" pseudo-operator   */
2035796c8dcSSimon Schubert %token <tsval> CHAR
2045796c8dcSSimon Schubert %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
205cf7f2e2dSJohn Marino %token <ssym> UNKNOWN_CPP_NAME
2065796c8dcSSimon Schubert %token <voidval> COMPLETE
2075796c8dcSSimon Schubert %token <tsym> TYPENAME
208*ef5ccd6cSJohn Marino %token <class> CLASSNAME	/* ObjC Class name */
2095796c8dcSSimon Schubert %type <sval> name
2105796c8dcSSimon Schubert %type <svec> string_exp
2115796c8dcSSimon Schubert %type <ssym> name_not_typename
2125796c8dcSSimon Schubert %type <tsym> typename
2135796c8dcSSimon Schubert 
214*ef5ccd6cSJohn Marino  /* This is like a '[' token, but is only generated when parsing
215*ef5ccd6cSJohn Marino     Objective C.  This lets us reuse the same parser without
216*ef5ccd6cSJohn Marino     erroneously parsing ObjC-specific expressions in C.  */
217*ef5ccd6cSJohn Marino %token OBJC_LBRAC
218*ef5ccd6cSJohn Marino 
2195796c8dcSSimon Schubert /* A NAME_OR_INT is a symbol which is not known in the symbol table,
2205796c8dcSSimon Schubert    but which would parse as a valid number in the current input radix.
2215796c8dcSSimon Schubert    E.g. "c" when input_radix==16.  Depending on the parse, it will be
2225796c8dcSSimon Schubert    turned into a name or into a number.  */
2235796c8dcSSimon Schubert 
2245796c8dcSSimon Schubert %token <ssym> NAME_OR_INT
2255796c8dcSSimon Schubert 
226cf7f2e2dSJohn Marino %token OPERATOR
2275796c8dcSSimon Schubert %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
2285796c8dcSSimon Schubert %token TEMPLATE
2295796c8dcSSimon Schubert %token ERROR
230cf7f2e2dSJohn Marino %token NEW DELETE
231cf7f2e2dSJohn Marino %type <sval> operator
232cf7f2e2dSJohn Marino %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
233a45ae5f8SJohn Marino %token ENTRY
234*ef5ccd6cSJohn Marino %token TYPEOF
235*ef5ccd6cSJohn Marino %token DECLTYPE
2365796c8dcSSimon Schubert 
2375796c8dcSSimon Schubert /* Special type cases, put in to allow the parser to distinguish different
2385796c8dcSSimon Schubert    legal basetypes.  */
2395796c8dcSSimon Schubert %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
2405796c8dcSSimon Schubert 
241cf7f2e2dSJohn Marino %token <sval> VARIABLE
2425796c8dcSSimon Schubert 
2435796c8dcSSimon Schubert %token <opcode> ASSIGN_MODIFY
2445796c8dcSSimon Schubert 
2455796c8dcSSimon Schubert /* C++ */
2465796c8dcSSimon Schubert %token TRUEKEYWORD
2475796c8dcSSimon Schubert %token FALSEKEYWORD
2485796c8dcSSimon Schubert 
2495796c8dcSSimon Schubert 
2505796c8dcSSimon Schubert %left ','
2515796c8dcSSimon Schubert %left ABOVE_COMMA
2525796c8dcSSimon Schubert %right '=' ASSIGN_MODIFY
2535796c8dcSSimon Schubert %right '?'
2545796c8dcSSimon Schubert %left OROR
2555796c8dcSSimon Schubert %left ANDAND
2565796c8dcSSimon Schubert %left '|'
2575796c8dcSSimon Schubert %left '^'
2585796c8dcSSimon Schubert %left '&'
2595796c8dcSSimon Schubert %left EQUAL NOTEQUAL
2605796c8dcSSimon Schubert %left '<' '>' LEQ GEQ
2615796c8dcSSimon Schubert %left LSH RSH
2625796c8dcSSimon Schubert %left '@'
2635796c8dcSSimon Schubert %left '+' '-'
2645796c8dcSSimon Schubert %left '*' '/' '%'
2655796c8dcSSimon Schubert %right UNARY INCREMENT DECREMENT
266*ef5ccd6cSJohn Marino %right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '('
2675796c8dcSSimon Schubert %token <ssym> BLOCKNAME
2685796c8dcSSimon Schubert %token <bval> FILENAME
2695796c8dcSSimon Schubert %type <bval> block
2705796c8dcSSimon Schubert %left COLONCOLON
2715796c8dcSSimon Schubert 
272*ef5ccd6cSJohn Marino %token DOTDOTDOT
273*ef5ccd6cSJohn Marino 
2745796c8dcSSimon Schubert 
2755796c8dcSSimon Schubert %%
2765796c8dcSSimon Schubert 
2775796c8dcSSimon Schubert start   :	exp1
2785796c8dcSSimon Schubert 	|	type_exp
2795796c8dcSSimon Schubert 	;
2805796c8dcSSimon Schubert 
2815796c8dcSSimon Schubert type_exp:	type
2825796c8dcSSimon Schubert 			{ write_exp_elt_opcode(OP_TYPE);
2835796c8dcSSimon Schubert 			  write_exp_elt_type($1);
2845796c8dcSSimon Schubert 			  write_exp_elt_opcode(OP_TYPE);}
285*ef5ccd6cSJohn Marino 	|	TYPEOF '(' exp ')'
286*ef5ccd6cSJohn Marino 			{
287*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_TYPEOF);
288*ef5ccd6cSJohn Marino 			}
289*ef5ccd6cSJohn Marino 	|	TYPEOF '(' type ')'
290*ef5ccd6cSJohn Marino 			{
291*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_TYPE);
292*ef5ccd6cSJohn Marino 			  write_exp_elt_type ($3);
293*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_TYPE);
294*ef5ccd6cSJohn Marino 			}
295*ef5ccd6cSJohn Marino 	|	DECLTYPE '(' exp ')'
296*ef5ccd6cSJohn Marino 			{
297*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_DECLTYPE);
298*ef5ccd6cSJohn Marino 			}
2995796c8dcSSimon Schubert 	;
3005796c8dcSSimon Schubert 
3015796c8dcSSimon Schubert /* Expressions, including the comma operator.  */
3025796c8dcSSimon Schubert exp1	:	exp
3035796c8dcSSimon Schubert 	|	exp1 ',' exp
3045796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_COMMA); }
3055796c8dcSSimon Schubert 	;
3065796c8dcSSimon Schubert 
3075796c8dcSSimon Schubert /* Expressions, not including the comma operator.  */
3085796c8dcSSimon Schubert exp	:	'*' exp    %prec UNARY
3095796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_IND); }
3105796c8dcSSimon Schubert 	;
3115796c8dcSSimon Schubert 
3125796c8dcSSimon Schubert exp	:	'&' exp    %prec UNARY
3135796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_ADDR); }
3145796c8dcSSimon Schubert 	;
3155796c8dcSSimon Schubert 
3165796c8dcSSimon Schubert exp	:	'-' exp    %prec UNARY
3175796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_NEG); }
3185796c8dcSSimon Schubert 	;
3195796c8dcSSimon Schubert 
3205796c8dcSSimon Schubert exp	:	'+' exp    %prec UNARY
3215796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_PLUS); }
3225796c8dcSSimon Schubert 	;
3235796c8dcSSimon Schubert 
3245796c8dcSSimon Schubert exp	:	'!' exp    %prec UNARY
3255796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
3265796c8dcSSimon Schubert 	;
3275796c8dcSSimon Schubert 
3285796c8dcSSimon Schubert exp	:	'~' exp    %prec UNARY
3295796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_COMPLEMENT); }
3305796c8dcSSimon Schubert 	;
3315796c8dcSSimon Schubert 
3325796c8dcSSimon Schubert exp	:	INCREMENT exp    %prec UNARY
3335796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_PREINCREMENT); }
3345796c8dcSSimon Schubert 	;
3355796c8dcSSimon Schubert 
3365796c8dcSSimon Schubert exp	:	DECREMENT exp    %prec UNARY
3375796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_PREDECREMENT); }
3385796c8dcSSimon Schubert 	;
3395796c8dcSSimon Schubert 
3405796c8dcSSimon Schubert exp	:	exp INCREMENT    %prec UNARY
3415796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_POSTINCREMENT); }
3425796c8dcSSimon Schubert 	;
3435796c8dcSSimon Schubert 
3445796c8dcSSimon Schubert exp	:	exp DECREMENT    %prec UNARY
3455796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_POSTDECREMENT); }
3465796c8dcSSimon Schubert 	;
3475796c8dcSSimon Schubert 
3485796c8dcSSimon Schubert exp	:	SIZEOF exp       %prec UNARY
3495796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_SIZEOF); }
3505796c8dcSSimon Schubert 	;
3515796c8dcSSimon Schubert 
3525796c8dcSSimon Schubert exp	:	exp ARROW name
3535796c8dcSSimon Schubert 			{ write_exp_elt_opcode (STRUCTOP_PTR);
3545796c8dcSSimon Schubert 			  write_exp_string ($3);
3555796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR); }
3565796c8dcSSimon Schubert 	;
3575796c8dcSSimon Schubert 
3585796c8dcSSimon Schubert exp	:	exp ARROW name COMPLETE
3595796c8dcSSimon Schubert 			{ mark_struct_expression ();
3605796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR);
3615796c8dcSSimon Schubert 			  write_exp_string ($3);
3625796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR); }
3635796c8dcSSimon Schubert 	;
3645796c8dcSSimon Schubert 
3655796c8dcSSimon Schubert exp	:	exp ARROW COMPLETE
3665796c8dcSSimon Schubert 			{ struct stoken s;
3675796c8dcSSimon Schubert 			  mark_struct_expression ();
3685796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR);
3695796c8dcSSimon Schubert 			  s.ptr = "";
3705796c8dcSSimon Schubert 			  s.length = 0;
3715796c8dcSSimon Schubert 			  write_exp_string (s);
3725796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR); }
3735796c8dcSSimon Schubert 	;
3745796c8dcSSimon Schubert 
3755796c8dcSSimon Schubert exp	:	exp ARROW qualified_name
3765796c8dcSSimon Schubert 			{ /* exp->type::name becomes exp->*(&type::name) */
3775796c8dcSSimon Schubert 			  /* Note: this doesn't work if name is a
3785796c8dcSSimon Schubert 			     static member!  FIXME */
3795796c8dcSSimon Schubert 			  write_exp_elt_opcode (UNOP_ADDR);
3805796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_MPTR); }
3815796c8dcSSimon Schubert 	;
3825796c8dcSSimon Schubert 
3835796c8dcSSimon Schubert exp	:	exp ARROW_STAR exp
3845796c8dcSSimon Schubert 			{ write_exp_elt_opcode (STRUCTOP_MPTR); }
3855796c8dcSSimon Schubert 	;
3865796c8dcSSimon Schubert 
3875796c8dcSSimon Schubert exp	:	exp '.' name
3885796c8dcSSimon Schubert 			{ write_exp_elt_opcode (STRUCTOP_STRUCT);
3895796c8dcSSimon Schubert 			  write_exp_string ($3);
3905796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
3915796c8dcSSimon Schubert 	;
3925796c8dcSSimon Schubert 
3935796c8dcSSimon Schubert exp	:	exp '.' name COMPLETE
3945796c8dcSSimon Schubert 			{ mark_struct_expression ();
3955796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT);
3965796c8dcSSimon Schubert 			  write_exp_string ($3);
3975796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
3985796c8dcSSimon Schubert 	;
3995796c8dcSSimon Schubert 
4005796c8dcSSimon Schubert exp	:	exp '.' COMPLETE
4015796c8dcSSimon Schubert 			{ struct stoken s;
4025796c8dcSSimon Schubert 			  mark_struct_expression ();
4035796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT);
4045796c8dcSSimon Schubert 			  s.ptr = "";
4055796c8dcSSimon Schubert 			  s.length = 0;
4065796c8dcSSimon Schubert 			  write_exp_string (s);
4075796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
4085796c8dcSSimon Schubert 	;
4095796c8dcSSimon Schubert 
4105796c8dcSSimon Schubert exp	:	exp '.' qualified_name
4115796c8dcSSimon Schubert 			{ /* exp.type::name becomes exp.*(&type::name) */
4125796c8dcSSimon Schubert 			  /* Note: this doesn't work if name is a
4135796c8dcSSimon Schubert 			     static member!  FIXME */
4145796c8dcSSimon Schubert 			  write_exp_elt_opcode (UNOP_ADDR);
4155796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_MEMBER); }
4165796c8dcSSimon Schubert 	;
4175796c8dcSSimon Schubert 
4185796c8dcSSimon Schubert exp	:	exp DOT_STAR exp
4195796c8dcSSimon Schubert 			{ write_exp_elt_opcode (STRUCTOP_MEMBER); }
4205796c8dcSSimon Schubert 	;
4215796c8dcSSimon Schubert 
4225796c8dcSSimon Schubert exp	:	exp '[' exp1 ']'
4235796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
4245796c8dcSSimon Schubert 	;
4255796c8dcSSimon Schubert 
426*ef5ccd6cSJohn Marino exp	:	exp OBJC_LBRAC exp1 ']'
427*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
428*ef5ccd6cSJohn Marino 	;
429*ef5ccd6cSJohn Marino 
430*ef5ccd6cSJohn Marino /*
431*ef5ccd6cSJohn Marino  * The rules below parse ObjC message calls of the form:
432*ef5ccd6cSJohn Marino  *	'[' target selector {':' argument}* ']'
433*ef5ccd6cSJohn Marino  */
434*ef5ccd6cSJohn Marino 
435*ef5ccd6cSJohn Marino exp	: 	OBJC_LBRAC TYPENAME
436*ef5ccd6cSJohn Marino 			{
437*ef5ccd6cSJohn Marino 			  CORE_ADDR class;
438*ef5ccd6cSJohn Marino 
439*ef5ccd6cSJohn Marino 			  class = lookup_objc_class (parse_gdbarch,
440*ef5ccd6cSJohn Marino 						     copy_name ($2.stoken));
441*ef5ccd6cSJohn Marino 			  if (class == 0)
442*ef5ccd6cSJohn Marino 			    error (_("%s is not an ObjC Class"),
443*ef5ccd6cSJohn Marino 				   copy_name ($2.stoken));
444*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_LONG);
445*ef5ccd6cSJohn Marino 			  write_exp_elt_type (parse_type->builtin_int);
446*ef5ccd6cSJohn Marino 			  write_exp_elt_longcst ((LONGEST) class);
447*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_LONG);
448*ef5ccd6cSJohn Marino 			  start_msglist();
449*ef5ccd6cSJohn Marino 			}
450*ef5ccd6cSJohn Marino 		msglist ']'
451*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (OP_OBJC_MSGCALL);
452*ef5ccd6cSJohn Marino 			  end_msglist();
453*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_OBJC_MSGCALL);
454*ef5ccd6cSJohn Marino 			}
455*ef5ccd6cSJohn Marino 	;
456*ef5ccd6cSJohn Marino 
457*ef5ccd6cSJohn Marino exp	:	OBJC_LBRAC CLASSNAME
458*ef5ccd6cSJohn Marino 			{
459*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_LONG);
460*ef5ccd6cSJohn Marino 			  write_exp_elt_type (parse_type->builtin_int);
461*ef5ccd6cSJohn Marino 			  write_exp_elt_longcst ((LONGEST) $2.class);
462*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_LONG);
463*ef5ccd6cSJohn Marino 			  start_msglist();
464*ef5ccd6cSJohn Marino 			}
465*ef5ccd6cSJohn Marino 		msglist ']'
466*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (OP_OBJC_MSGCALL);
467*ef5ccd6cSJohn Marino 			  end_msglist();
468*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_OBJC_MSGCALL);
469*ef5ccd6cSJohn Marino 			}
470*ef5ccd6cSJohn Marino 	;
471*ef5ccd6cSJohn Marino 
472*ef5ccd6cSJohn Marino exp	:	OBJC_LBRAC exp
473*ef5ccd6cSJohn Marino 			{ start_msglist(); }
474*ef5ccd6cSJohn Marino 		msglist ']'
475*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (OP_OBJC_MSGCALL);
476*ef5ccd6cSJohn Marino 			  end_msglist();
477*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_OBJC_MSGCALL);
478*ef5ccd6cSJohn Marino 			}
479*ef5ccd6cSJohn Marino 	;
480*ef5ccd6cSJohn Marino 
481*ef5ccd6cSJohn Marino msglist :	name
482*ef5ccd6cSJohn Marino 			{ add_msglist(&$1, 0); }
483*ef5ccd6cSJohn Marino 	|	msgarglist
484*ef5ccd6cSJohn Marino 	;
485*ef5ccd6cSJohn Marino 
486*ef5ccd6cSJohn Marino msgarglist :	msgarg
487*ef5ccd6cSJohn Marino 	|	msgarglist msgarg
488*ef5ccd6cSJohn Marino 	;
489*ef5ccd6cSJohn Marino 
490*ef5ccd6cSJohn Marino msgarg	:	name ':' exp
491*ef5ccd6cSJohn Marino 			{ add_msglist(&$1, 1); }
492*ef5ccd6cSJohn Marino 	|	':' exp	/* Unnamed arg.  */
493*ef5ccd6cSJohn Marino 			{ add_msglist(0, 1);   }
494*ef5ccd6cSJohn Marino 	|	',' exp	/* Variable number of args.  */
495*ef5ccd6cSJohn Marino 			{ add_msglist(0, 0);   }
496*ef5ccd6cSJohn Marino 	;
497*ef5ccd6cSJohn Marino 
4985796c8dcSSimon Schubert exp	:	exp '('
4995796c8dcSSimon Schubert 			/* This is to save the value of arglist_len
5005796c8dcSSimon Schubert 			   being accumulated by an outer function call.  */
5015796c8dcSSimon Schubert 			{ start_arglist (); }
5025796c8dcSSimon Schubert 		arglist ')'	%prec ARROW
5035796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_FUNCALL);
5045796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST) end_arglist ());
5055796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_FUNCALL); }
5065796c8dcSSimon Schubert 	;
5075796c8dcSSimon Schubert 
508cf7f2e2dSJohn Marino exp	:	UNKNOWN_CPP_NAME '('
509cf7f2e2dSJohn Marino 			{
510cf7f2e2dSJohn Marino 			  /* This could potentially be a an argument defined
511cf7f2e2dSJohn Marino 			     lookup function (Koenig).  */
512cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (OP_ADL_FUNC);
513cf7f2e2dSJohn Marino 			  write_exp_elt_block (expression_context_block);
514cf7f2e2dSJohn Marino 			  write_exp_elt_sym (NULL); /* Placeholder.  */
515cf7f2e2dSJohn Marino 			  write_exp_string ($1.stoken);
516cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (OP_ADL_FUNC);
517cf7f2e2dSJohn Marino 
518cf7f2e2dSJohn Marino 			/* This is to save the value of arglist_len
519cf7f2e2dSJohn Marino 			   being accumulated by an outer function call.  */
520cf7f2e2dSJohn Marino 
521cf7f2e2dSJohn Marino 			  start_arglist ();
522cf7f2e2dSJohn Marino 			}
523cf7f2e2dSJohn Marino 		arglist ')'	%prec ARROW
524cf7f2e2dSJohn Marino 			{
525cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (OP_FUNCALL);
526cf7f2e2dSJohn Marino 			  write_exp_elt_longcst ((LONGEST) end_arglist ());
527cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (OP_FUNCALL);
528cf7f2e2dSJohn Marino 			}
529cf7f2e2dSJohn Marino 	;
530cf7f2e2dSJohn Marino 
5315796c8dcSSimon Schubert lcurly	:	'{'
5325796c8dcSSimon Schubert 			{ start_arglist (); }
5335796c8dcSSimon Schubert 	;
5345796c8dcSSimon Schubert 
5355796c8dcSSimon Schubert arglist	:
5365796c8dcSSimon Schubert 	;
5375796c8dcSSimon Schubert 
5385796c8dcSSimon Schubert arglist	:	exp
5395796c8dcSSimon Schubert 			{ arglist_len = 1; }
5405796c8dcSSimon Schubert 	;
5415796c8dcSSimon Schubert 
5425796c8dcSSimon Schubert arglist	:	arglist ',' exp   %prec ABOVE_COMMA
5435796c8dcSSimon Schubert 			{ arglist_len++; }
5445796c8dcSSimon Schubert 	;
5455796c8dcSSimon Schubert 
546*ef5ccd6cSJohn Marino exp     :       exp '(' parameter_typelist ')' const_or_volatile
547cf7f2e2dSJohn Marino 			{ int i;
548*ef5ccd6cSJohn Marino 			  VEC (type_ptr) *type_list = $3;
549*ef5ccd6cSJohn Marino 			  struct type *type_elt;
550*ef5ccd6cSJohn Marino 			  LONGEST len = VEC_length (type_ptr, type_list);
551*ef5ccd6cSJohn Marino 
552cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (TYPE_INSTANCE);
553*ef5ccd6cSJohn Marino 			  write_exp_elt_longcst (len);
554*ef5ccd6cSJohn Marino 			  for (i = 0;
555*ef5ccd6cSJohn Marino 			       VEC_iterate (type_ptr, type_list, i, type_elt);
556*ef5ccd6cSJohn Marino 			       ++i)
557*ef5ccd6cSJohn Marino 			    write_exp_elt_type (type_elt);
558*ef5ccd6cSJohn Marino 			  write_exp_elt_longcst(len);
559cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (TYPE_INSTANCE);
560*ef5ccd6cSJohn Marino 			  VEC_free (type_ptr, type_list);
561cf7f2e2dSJohn Marino 			}
562cf7f2e2dSJohn Marino 	;
563cf7f2e2dSJohn Marino 
5645796c8dcSSimon Schubert rcurly	:	'}'
5655796c8dcSSimon Schubert 			{ $$ = end_arglist () - 1; }
5665796c8dcSSimon Schubert 	;
5675796c8dcSSimon Schubert exp	:	lcurly arglist rcurly	%prec ARROW
5685796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_ARRAY);
5695796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST) 0);
5705796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST) $3);
5715796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_ARRAY); }
5725796c8dcSSimon Schubert 	;
5735796c8dcSSimon Schubert 
574*ef5ccd6cSJohn Marino exp	:	lcurly type_exp rcurly exp  %prec UNARY
575*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (UNOP_MEMVAL_TYPE); }
5765796c8dcSSimon Schubert 	;
5775796c8dcSSimon Schubert 
578*ef5ccd6cSJohn Marino exp	:	'(' type_exp ')' exp  %prec UNARY
579*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (UNOP_CAST_TYPE); }
5805796c8dcSSimon Schubert 	;
5815796c8dcSSimon Schubert 
5825796c8dcSSimon Schubert exp	:	'(' exp1 ')'
5835796c8dcSSimon Schubert 			{ }
5845796c8dcSSimon Schubert 	;
5855796c8dcSSimon Schubert 
5865796c8dcSSimon Schubert /* Binary operators in order of decreasing precedence.  */
5875796c8dcSSimon Schubert 
5885796c8dcSSimon Schubert exp	:	exp '@' exp
5895796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_REPEAT); }
5905796c8dcSSimon Schubert 	;
5915796c8dcSSimon Schubert 
5925796c8dcSSimon Schubert exp	:	exp '*' exp
5935796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_MUL); }
5945796c8dcSSimon Schubert 	;
5955796c8dcSSimon Schubert 
5965796c8dcSSimon Schubert exp	:	exp '/' exp
5975796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_DIV); }
5985796c8dcSSimon Schubert 	;
5995796c8dcSSimon Schubert 
6005796c8dcSSimon Schubert exp	:	exp '%' exp
6015796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_REM); }
6025796c8dcSSimon Schubert 	;
6035796c8dcSSimon Schubert 
6045796c8dcSSimon Schubert exp	:	exp '+' exp
6055796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_ADD); }
6065796c8dcSSimon Schubert 	;
6075796c8dcSSimon Schubert 
6085796c8dcSSimon Schubert exp	:	exp '-' exp
6095796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_SUB); }
6105796c8dcSSimon Schubert 	;
6115796c8dcSSimon Schubert 
6125796c8dcSSimon Schubert exp	:	exp LSH exp
6135796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LSH); }
6145796c8dcSSimon Schubert 	;
6155796c8dcSSimon Schubert 
6165796c8dcSSimon Schubert exp	:	exp RSH exp
6175796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_RSH); }
6185796c8dcSSimon Schubert 	;
6195796c8dcSSimon Schubert 
6205796c8dcSSimon Schubert exp	:	exp EQUAL exp
6215796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_EQUAL); }
6225796c8dcSSimon Schubert 	;
6235796c8dcSSimon Schubert 
6245796c8dcSSimon Schubert exp	:	exp NOTEQUAL exp
6255796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
6265796c8dcSSimon Schubert 	;
6275796c8dcSSimon Schubert 
6285796c8dcSSimon Schubert exp	:	exp LEQ exp
6295796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LEQ); }
6305796c8dcSSimon Schubert 	;
6315796c8dcSSimon Schubert 
6325796c8dcSSimon Schubert exp	:	exp GEQ exp
6335796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_GEQ); }
6345796c8dcSSimon Schubert 	;
6355796c8dcSSimon Schubert 
6365796c8dcSSimon Schubert exp	:	exp '<' exp
6375796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LESS); }
6385796c8dcSSimon Schubert 	;
6395796c8dcSSimon Schubert 
6405796c8dcSSimon Schubert exp	:	exp '>' exp
6415796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_GTR); }
6425796c8dcSSimon Schubert 	;
6435796c8dcSSimon Schubert 
6445796c8dcSSimon Schubert exp	:	exp '&' exp
6455796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
6465796c8dcSSimon Schubert 	;
6475796c8dcSSimon Schubert 
6485796c8dcSSimon Schubert exp	:	exp '^' exp
6495796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
6505796c8dcSSimon Schubert 	;
6515796c8dcSSimon Schubert 
6525796c8dcSSimon Schubert exp	:	exp '|' exp
6535796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
6545796c8dcSSimon Schubert 	;
6555796c8dcSSimon Schubert 
6565796c8dcSSimon Schubert exp	:	exp ANDAND exp
6575796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
6585796c8dcSSimon Schubert 	;
6595796c8dcSSimon Schubert 
6605796c8dcSSimon Schubert exp	:	exp OROR exp
6615796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
6625796c8dcSSimon Schubert 	;
6635796c8dcSSimon Schubert 
6645796c8dcSSimon Schubert exp	:	exp '?' exp ':' exp	%prec '?'
6655796c8dcSSimon Schubert 			{ write_exp_elt_opcode (TERNOP_COND); }
6665796c8dcSSimon Schubert 	;
6675796c8dcSSimon Schubert 
6685796c8dcSSimon Schubert exp	:	exp '=' exp
6695796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_ASSIGN); }
6705796c8dcSSimon Schubert 	;
6715796c8dcSSimon Schubert 
6725796c8dcSSimon Schubert exp	:	exp ASSIGN_MODIFY exp
6735796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
6745796c8dcSSimon Schubert 			  write_exp_elt_opcode ($2);
6755796c8dcSSimon Schubert 			  write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
6765796c8dcSSimon Schubert 	;
6775796c8dcSSimon Schubert 
6785796c8dcSSimon Schubert exp	:	INT
6795796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_LONG);
6805796c8dcSSimon Schubert 			  write_exp_elt_type ($1.type);
6815796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST)($1.val));
6825796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_LONG); }
6835796c8dcSSimon Schubert 	;
6845796c8dcSSimon Schubert 
6855796c8dcSSimon Schubert exp	:	CHAR
6865796c8dcSSimon Schubert 			{
6875796c8dcSSimon Schubert 			  struct stoken_vector vec;
6885796c8dcSSimon Schubert 			  vec.len = 1;
6895796c8dcSSimon Schubert 			  vec.tokens = &$1;
6905796c8dcSSimon Schubert 			  write_exp_string_vector ($1.type, &vec);
6915796c8dcSSimon Schubert 			}
6925796c8dcSSimon Schubert 	;
6935796c8dcSSimon Schubert 
6945796c8dcSSimon Schubert exp	:	NAME_OR_INT
6955796c8dcSSimon Schubert 			{ YYSTYPE val;
6965796c8dcSSimon Schubert 			  parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
6975796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_LONG);
6985796c8dcSSimon Schubert 			  write_exp_elt_type (val.typed_val_int.type);
6995796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
7005796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_LONG);
7015796c8dcSSimon Schubert 			}
7025796c8dcSSimon Schubert 	;
7035796c8dcSSimon Schubert 
7045796c8dcSSimon Schubert 
7055796c8dcSSimon Schubert exp	:	FLOAT
7065796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_DOUBLE);
7075796c8dcSSimon Schubert 			  write_exp_elt_type ($1.type);
7085796c8dcSSimon Schubert 			  write_exp_elt_dblcst ($1.dval);
7095796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_DOUBLE); }
7105796c8dcSSimon Schubert 	;
7115796c8dcSSimon Schubert 
7125796c8dcSSimon Schubert exp	:	DECFLOAT
7135796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_DECFLOAT);
7145796c8dcSSimon Schubert 			  write_exp_elt_type ($1.type);
7155796c8dcSSimon Schubert 			  write_exp_elt_decfloatcst ($1.val);
7165796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_DECFLOAT); }
7175796c8dcSSimon Schubert 	;
7185796c8dcSSimon Schubert 
7195796c8dcSSimon Schubert exp	:	variable
7205796c8dcSSimon Schubert 	;
7215796c8dcSSimon Schubert 
7225796c8dcSSimon Schubert exp	:	VARIABLE
723cf7f2e2dSJohn Marino 			{
724cf7f2e2dSJohn Marino 			  write_dollar_variable ($1);
725cf7f2e2dSJohn Marino 			}
7265796c8dcSSimon Schubert 	;
7275796c8dcSSimon Schubert 
728*ef5ccd6cSJohn Marino exp	:	SELECTOR '(' name ')'
729*ef5ccd6cSJohn Marino 			{
730*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_OBJC_SELECTOR);
731*ef5ccd6cSJohn Marino 			  write_exp_string ($3);
732*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_OBJC_SELECTOR); }
733*ef5ccd6cSJohn Marino 	;
734*ef5ccd6cSJohn Marino 
7355796c8dcSSimon Schubert exp	:	SIZEOF '(' type ')'	%prec UNARY
7365796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_LONG);
737c50c785cSJohn Marino 			  write_exp_elt_type (lookup_signed_typename
738c50c785cSJohn Marino 					      (parse_language, parse_gdbarch,
739c50c785cSJohn Marino 					       "int"));
7405796c8dcSSimon Schubert 			  CHECK_TYPEDEF ($3);
7415796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
7425796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_LONG); }
7435796c8dcSSimon Schubert 	;
7445796c8dcSSimon Schubert 
745*ef5ccd6cSJohn Marino exp	:	REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
746*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
747cf7f2e2dSJohn Marino 	;
748cf7f2e2dSJohn Marino 
749*ef5ccd6cSJohn Marino exp	:	STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
750*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (UNOP_CAST_TYPE); }
751cf7f2e2dSJohn Marino 	;
752cf7f2e2dSJohn Marino 
753*ef5ccd6cSJohn Marino exp	:	DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
754*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
755cf7f2e2dSJohn Marino 	;
756cf7f2e2dSJohn Marino 
757*ef5ccd6cSJohn Marino exp	:	CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
758cf7f2e2dSJohn Marino 			{ /* We could do more error checking here, but
759cf7f2e2dSJohn Marino 			     it doesn't seem worthwhile.  */
760*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (UNOP_CAST_TYPE); }
761cf7f2e2dSJohn Marino 	;
762cf7f2e2dSJohn Marino 
7635796c8dcSSimon Schubert string_exp:
7645796c8dcSSimon Schubert 		STRING
7655796c8dcSSimon Schubert 			{
7665796c8dcSSimon Schubert 			  /* We copy the string here, and not in the
7675796c8dcSSimon Schubert 			     lexer, to guarantee that we do not leak a
7685796c8dcSSimon Schubert 			     string.  Note that we follow the
7695796c8dcSSimon Schubert 			     NUL-termination convention of the
7705796c8dcSSimon Schubert 			     lexer.  */
7715796c8dcSSimon Schubert 			  struct typed_stoken *vec = XNEW (struct typed_stoken);
7725796c8dcSSimon Schubert 			  $$.len = 1;
7735796c8dcSSimon Schubert 			  $$.tokens = vec;
7745796c8dcSSimon Schubert 
7755796c8dcSSimon Schubert 			  vec->type = $1.type;
7765796c8dcSSimon Schubert 			  vec->length = $1.length;
7775796c8dcSSimon Schubert 			  vec->ptr = malloc ($1.length + 1);
7785796c8dcSSimon Schubert 			  memcpy (vec->ptr, $1.ptr, $1.length + 1);
7795796c8dcSSimon Schubert 			}
7805796c8dcSSimon Schubert 
7815796c8dcSSimon Schubert 	|	string_exp STRING
7825796c8dcSSimon Schubert 			{
7835796c8dcSSimon Schubert 			  /* Note that we NUL-terminate here, but just
7845796c8dcSSimon Schubert 			     for convenience.  */
7855796c8dcSSimon Schubert 			  char *p;
7865796c8dcSSimon Schubert 			  ++$$.len;
7875796c8dcSSimon Schubert 			  $$.tokens = realloc ($$.tokens,
7885796c8dcSSimon Schubert 					       $$.len * sizeof (struct typed_stoken));
7895796c8dcSSimon Schubert 
7905796c8dcSSimon Schubert 			  p = malloc ($2.length + 1);
7915796c8dcSSimon Schubert 			  memcpy (p, $2.ptr, $2.length + 1);
7925796c8dcSSimon Schubert 
7935796c8dcSSimon Schubert 			  $$.tokens[$$.len - 1].type = $2.type;
7945796c8dcSSimon Schubert 			  $$.tokens[$$.len - 1].length = $2.length;
7955796c8dcSSimon Schubert 			  $$.tokens[$$.len - 1].ptr = p;
7965796c8dcSSimon Schubert 			}
7975796c8dcSSimon Schubert 		;
7985796c8dcSSimon Schubert 
7995796c8dcSSimon Schubert exp	:	string_exp
8005796c8dcSSimon Schubert 			{
8015796c8dcSSimon Schubert 			  int i;
8025796c8dcSSimon Schubert 			  enum c_string_type type = C_STRING;
8035796c8dcSSimon Schubert 
8045796c8dcSSimon Schubert 			  for (i = 0; i < $1.len; ++i)
8055796c8dcSSimon Schubert 			    {
8065796c8dcSSimon Schubert 			      switch ($1.tokens[i].type)
8075796c8dcSSimon Schubert 				{
8085796c8dcSSimon Schubert 				case C_STRING:
8095796c8dcSSimon Schubert 				  break;
8105796c8dcSSimon Schubert 				case C_WIDE_STRING:
8115796c8dcSSimon Schubert 				case C_STRING_16:
8125796c8dcSSimon Schubert 				case C_STRING_32:
8135796c8dcSSimon Schubert 				  if (type != C_STRING
8145796c8dcSSimon Schubert 				      && type != $1.tokens[i].type)
815c50c785cSJohn Marino 				    error (_("Undefined string concatenation."));
8165796c8dcSSimon Schubert 				  type = $1.tokens[i].type;
8175796c8dcSSimon Schubert 				  break;
8185796c8dcSSimon Schubert 				default:
8195796c8dcSSimon Schubert 				  /* internal error */
8205796c8dcSSimon Schubert 				  internal_error (__FILE__, __LINE__,
8215796c8dcSSimon Schubert 						  "unrecognized type in string concatenation");
8225796c8dcSSimon Schubert 				}
8235796c8dcSSimon Schubert 			    }
8245796c8dcSSimon Schubert 
8255796c8dcSSimon Schubert 			  write_exp_string_vector (type, &$1);
8265796c8dcSSimon Schubert 			  for (i = 0; i < $1.len; ++i)
8275796c8dcSSimon Schubert 			    free ($1.tokens[i].ptr);
8285796c8dcSSimon Schubert 			  free ($1.tokens);
8295796c8dcSSimon Schubert 			}
8305796c8dcSSimon Schubert 	;
8315796c8dcSSimon Schubert 
832*ef5ccd6cSJohn Marino exp     :	NSSTRING	/* ObjC NextStep NSString constant
833*ef5ccd6cSJohn Marino 				 * of the form '@' '"' string '"'.
834*ef5ccd6cSJohn Marino 				 */
835*ef5ccd6cSJohn Marino 			{ write_exp_elt_opcode (OP_OBJC_NSSTRING);
836*ef5ccd6cSJohn Marino 			  write_exp_string ($1);
837*ef5ccd6cSJohn Marino 			  write_exp_elt_opcode (OP_OBJC_NSSTRING); }
838*ef5ccd6cSJohn Marino 	;
839*ef5ccd6cSJohn Marino 
8405796c8dcSSimon Schubert /* C++.  */
8415796c8dcSSimon Schubert exp     :       TRUEKEYWORD
8425796c8dcSSimon Schubert                         { write_exp_elt_opcode (OP_LONG);
8435796c8dcSSimon Schubert                           write_exp_elt_type (parse_type->builtin_bool);
8445796c8dcSSimon Schubert                           write_exp_elt_longcst ((LONGEST) 1);
8455796c8dcSSimon Schubert                           write_exp_elt_opcode (OP_LONG); }
8465796c8dcSSimon Schubert 	;
8475796c8dcSSimon Schubert 
8485796c8dcSSimon Schubert exp     :       FALSEKEYWORD
8495796c8dcSSimon Schubert                         { write_exp_elt_opcode (OP_LONG);
8505796c8dcSSimon Schubert                           write_exp_elt_type (parse_type->builtin_bool);
8515796c8dcSSimon Schubert                           write_exp_elt_longcst ((LONGEST) 0);
8525796c8dcSSimon Schubert                           write_exp_elt_opcode (OP_LONG); }
8535796c8dcSSimon Schubert 	;
8545796c8dcSSimon Schubert 
8555796c8dcSSimon Schubert /* end of C++.  */
8565796c8dcSSimon Schubert 
8575796c8dcSSimon Schubert block	:	BLOCKNAME
8585796c8dcSSimon Schubert 			{
8595796c8dcSSimon Schubert 			  if ($1.sym)
8605796c8dcSSimon Schubert 			    $$ = SYMBOL_BLOCK_VALUE ($1.sym);
8615796c8dcSSimon Schubert 			  else
862c50c785cSJohn Marino 			    error (_("No file or function \"%s\"."),
8635796c8dcSSimon Schubert 				   copy_name ($1.stoken));
8645796c8dcSSimon Schubert 			}
8655796c8dcSSimon Schubert 	|	FILENAME
8665796c8dcSSimon Schubert 			{
8675796c8dcSSimon Schubert 			  $$ = $1;
8685796c8dcSSimon Schubert 			}
8695796c8dcSSimon Schubert 	;
8705796c8dcSSimon Schubert 
8715796c8dcSSimon Schubert block	:	block COLONCOLON name
8725796c8dcSSimon Schubert 			{ struct symbol *tem
8735796c8dcSSimon Schubert 			    = lookup_symbol (copy_name ($3), $1,
874*ef5ccd6cSJohn Marino 					     VAR_DOMAIN, NULL);
8755796c8dcSSimon Schubert 			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
876c50c785cSJohn Marino 			    error (_("No function \"%s\" in specified context."),
8775796c8dcSSimon Schubert 				   copy_name ($3));
8785796c8dcSSimon Schubert 			  $$ = SYMBOL_BLOCK_VALUE (tem); }
8795796c8dcSSimon Schubert 	;
8805796c8dcSSimon Schubert 
881a45ae5f8SJohn Marino variable:	name_not_typename ENTRY
882a45ae5f8SJohn Marino 			{ struct symbol *sym = $1.sym;
883a45ae5f8SJohn Marino 
884a45ae5f8SJohn Marino 			  if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
885a45ae5f8SJohn Marino 			      || !symbol_read_needs_frame (sym))
886a45ae5f8SJohn Marino 			    error (_("@entry can be used only for function "
887a45ae5f8SJohn Marino 				     "parameters, not for \"%s\""),
888a45ae5f8SJohn Marino 				   copy_name ($1.stoken));
889a45ae5f8SJohn Marino 
890a45ae5f8SJohn Marino 			  write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
891a45ae5f8SJohn Marino 			  write_exp_elt_sym (sym);
892a45ae5f8SJohn Marino 			  write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
893a45ae5f8SJohn Marino 			}
894a45ae5f8SJohn Marino 	;
895a45ae5f8SJohn Marino 
8965796c8dcSSimon Schubert variable:	block COLONCOLON name
8975796c8dcSSimon Schubert 			{ struct symbol *sym;
8985796c8dcSSimon Schubert 			  sym = lookup_symbol (copy_name ($3), $1,
899*ef5ccd6cSJohn Marino 					       VAR_DOMAIN, NULL);
9005796c8dcSSimon Schubert 			  if (sym == 0)
901c50c785cSJohn Marino 			    error (_("No symbol \"%s\" in specified context."),
9025796c8dcSSimon Schubert 				   copy_name ($3));
903*ef5ccd6cSJohn Marino 			  if (symbol_read_needs_frame (sym))
904*ef5ccd6cSJohn Marino 			    {
905*ef5ccd6cSJohn Marino 			      if (innermost_block == 0
906*ef5ccd6cSJohn Marino 				  || contained_in (block_found,
907*ef5ccd6cSJohn Marino 						   innermost_block))
908*ef5ccd6cSJohn Marino 				innermost_block = block_found;
909*ef5ccd6cSJohn Marino 			    }
9105796c8dcSSimon Schubert 
9115796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_VAR_VALUE);
9125796c8dcSSimon Schubert 			  /* block_found is set by lookup_symbol.  */
9135796c8dcSSimon Schubert 			  write_exp_elt_block (block_found);
9145796c8dcSSimon Schubert 			  write_exp_elt_sym (sym);
9155796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_VAR_VALUE); }
9165796c8dcSSimon Schubert 	;
9175796c8dcSSimon Schubert 
918cf7f2e2dSJohn Marino qualified_name:	TYPENAME COLONCOLON name
9195796c8dcSSimon Schubert 			{
920cf7f2e2dSJohn Marino 			  struct type *type = $1.type;
921cf7f2e2dSJohn Marino 			  CHECK_TYPEDEF (type);
9225796c8dcSSimon Schubert 			  if (TYPE_CODE (type) != TYPE_CODE_STRUCT
9235796c8dcSSimon Schubert 			      && TYPE_CODE (type) != TYPE_CODE_UNION
9245796c8dcSSimon Schubert 			      && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
925c50c785cSJohn Marino 			    error (_("`%s' is not defined as an aggregate type."),
926*ef5ccd6cSJohn Marino 				   TYPE_SAFE_NAME (type));
9275796c8dcSSimon Schubert 
9285796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_SCOPE);
9295796c8dcSSimon Schubert 			  write_exp_elt_type (type);
9305796c8dcSSimon Schubert 			  write_exp_string ($3);
9315796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_SCOPE);
9325796c8dcSSimon Schubert 			}
933cf7f2e2dSJohn Marino 	|	TYPENAME COLONCOLON '~' name
9345796c8dcSSimon Schubert 			{
935cf7f2e2dSJohn Marino 			  struct type *type = $1.type;
9365796c8dcSSimon Schubert 			  struct stoken tmp_token;
937cf7f2e2dSJohn Marino 			  CHECK_TYPEDEF (type);
9385796c8dcSSimon Schubert 			  if (TYPE_CODE (type) != TYPE_CODE_STRUCT
9395796c8dcSSimon Schubert 			      && TYPE_CODE (type) != TYPE_CODE_UNION
9405796c8dcSSimon Schubert 			      && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
941c50c785cSJohn Marino 			    error (_("`%s' is not defined as an aggregate type."),
942*ef5ccd6cSJohn Marino 				   TYPE_SAFE_NAME (type));
9435796c8dcSSimon Schubert 
9445796c8dcSSimon Schubert 			  tmp_token.ptr = (char*) alloca ($4.length + 2);
9455796c8dcSSimon Schubert 			  tmp_token.length = $4.length + 1;
9465796c8dcSSimon Schubert 			  tmp_token.ptr[0] = '~';
9475796c8dcSSimon Schubert 			  memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
9485796c8dcSSimon Schubert 			  tmp_token.ptr[tmp_token.length] = 0;
9495796c8dcSSimon Schubert 
9505796c8dcSSimon Schubert 			  /* Check for valid destructor name.  */
951a45ae5f8SJohn Marino 			  destructor_name_p (tmp_token.ptr, $1.type);
9525796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_SCOPE);
9535796c8dcSSimon Schubert 			  write_exp_elt_type (type);
9545796c8dcSSimon Schubert 			  write_exp_string (tmp_token);
9555796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_SCOPE);
9565796c8dcSSimon Schubert 			}
957cf7f2e2dSJohn Marino 	|	TYPENAME COLONCOLON name COLONCOLON name
958cf7f2e2dSJohn Marino 			{
959cf7f2e2dSJohn Marino 			  char *copy = copy_name ($3);
960cf7f2e2dSJohn Marino 			  error (_("No type \"%s\" within class "
961cf7f2e2dSJohn Marino 				   "or namespace \"%s\"."),
962*ef5ccd6cSJohn Marino 				 copy, TYPE_SAFE_NAME ($1.type));
963cf7f2e2dSJohn Marino 			}
9645796c8dcSSimon Schubert 	;
9655796c8dcSSimon Schubert 
9665796c8dcSSimon Schubert variable:	qualified_name
967cf7f2e2dSJohn Marino 	|	COLONCOLON name_not_typename
9685796c8dcSSimon Schubert 			{
969cf7f2e2dSJohn Marino 			  char *name = copy_name ($2.stoken);
9705796c8dcSSimon Schubert 			  struct symbol *sym;
9715796c8dcSSimon Schubert 			  struct minimal_symbol *msymbol;
9725796c8dcSSimon Schubert 
9735796c8dcSSimon Schubert 			  sym =
9745796c8dcSSimon Schubert 			    lookup_symbol (name, (const struct block *) NULL,
975*ef5ccd6cSJohn Marino 					   VAR_DOMAIN, NULL);
9765796c8dcSSimon Schubert 			  if (sym)
9775796c8dcSSimon Schubert 			    {
9785796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_VAR_VALUE);
9795796c8dcSSimon Schubert 			      write_exp_elt_block (NULL);
9805796c8dcSSimon Schubert 			      write_exp_elt_sym (sym);
9815796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_VAR_VALUE);
9825796c8dcSSimon Schubert 			      break;
9835796c8dcSSimon Schubert 			    }
9845796c8dcSSimon Schubert 
9855796c8dcSSimon Schubert 			  msymbol = lookup_minimal_symbol (name, NULL, NULL);
9865796c8dcSSimon Schubert 			  if (msymbol != NULL)
9875796c8dcSSimon Schubert 			    write_exp_msymbol (msymbol);
9885796c8dcSSimon Schubert 			  else if (!have_full_symbols () && !have_partial_symbols ())
989c50c785cSJohn Marino 			    error (_("No symbol table is loaded.  Use the \"file\" command."));
9905796c8dcSSimon Schubert 			  else
991c50c785cSJohn Marino 			    error (_("No symbol \"%s\" in current context."), name);
9925796c8dcSSimon Schubert 			}
9935796c8dcSSimon Schubert 	;
9945796c8dcSSimon Schubert 
9955796c8dcSSimon Schubert variable:	name_not_typename
9965796c8dcSSimon Schubert 			{ struct symbol *sym = $1.sym;
9975796c8dcSSimon Schubert 
9985796c8dcSSimon Schubert 			  if (sym)
9995796c8dcSSimon Schubert 			    {
10005796c8dcSSimon Schubert 			      if (symbol_read_needs_frame (sym))
10015796c8dcSSimon Schubert 				{
1002cf7f2e2dSJohn Marino 				  if (innermost_block == 0
1003cf7f2e2dSJohn Marino 				      || contained_in (block_found,
10045796c8dcSSimon Schubert 						       innermost_block))
10055796c8dcSSimon Schubert 				    innermost_block = block_found;
10065796c8dcSSimon Schubert 				}
10075796c8dcSSimon Schubert 
10085796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_VAR_VALUE);
10095796c8dcSSimon Schubert 			      /* We want to use the selected frame, not
10105796c8dcSSimon Schubert 				 another more inner frame which happens to
10115796c8dcSSimon Schubert 				 be in the same block.  */
10125796c8dcSSimon Schubert 			      write_exp_elt_block (NULL);
10135796c8dcSSimon Schubert 			      write_exp_elt_sym (sym);
10145796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_VAR_VALUE);
10155796c8dcSSimon Schubert 			    }
10165796c8dcSSimon Schubert 			  else if ($1.is_a_field_of_this)
10175796c8dcSSimon Schubert 			    {
10185796c8dcSSimon Schubert 			      /* C++: it hangs off of `this'.  Must
10195796c8dcSSimon Schubert 			         not inadvertently convert from a method call
10205796c8dcSSimon Schubert 				 to data ref.  */
1021cf7f2e2dSJohn Marino 			      if (innermost_block == 0
1022cf7f2e2dSJohn Marino 				  || contained_in (block_found,
1023cf7f2e2dSJohn Marino 						   innermost_block))
10245796c8dcSSimon Schubert 				innermost_block = block_found;
10255796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_THIS);
10265796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_THIS);
10275796c8dcSSimon Schubert 			      write_exp_elt_opcode (STRUCTOP_PTR);
10285796c8dcSSimon Schubert 			      write_exp_string ($1.stoken);
10295796c8dcSSimon Schubert 			      write_exp_elt_opcode (STRUCTOP_PTR);
10305796c8dcSSimon Schubert 			    }
10315796c8dcSSimon Schubert 			  else
10325796c8dcSSimon Schubert 			    {
10335796c8dcSSimon Schubert 			      struct minimal_symbol *msymbol;
10345796c8dcSSimon Schubert 			      char *arg = copy_name ($1.stoken);
10355796c8dcSSimon Schubert 
10365796c8dcSSimon Schubert 			      msymbol =
10375796c8dcSSimon Schubert 				lookup_minimal_symbol (arg, NULL, NULL);
10385796c8dcSSimon Schubert 			      if (msymbol != NULL)
10395796c8dcSSimon Schubert 				write_exp_msymbol (msymbol);
10405796c8dcSSimon Schubert 			      else if (!have_full_symbols () && !have_partial_symbols ())
1041c50c785cSJohn Marino 				error (_("No symbol table is loaded.  Use the \"file\" command."));
10425796c8dcSSimon Schubert 			      else
1043c50c785cSJohn Marino 				error (_("No symbol \"%s\" in current context."),
10445796c8dcSSimon Schubert 				       copy_name ($1.stoken));
10455796c8dcSSimon Schubert 			    }
10465796c8dcSSimon Schubert 			}
10475796c8dcSSimon Schubert 	;
10485796c8dcSSimon Schubert 
10495796c8dcSSimon Schubert space_identifier : '@' NAME
1050*ef5ccd6cSJohn Marino 		{ insert_type_address_space (copy_name ($2.stoken)); }
10515796c8dcSSimon Schubert 	;
10525796c8dcSSimon Schubert 
10535796c8dcSSimon Schubert const_or_volatile: const_or_volatile_noopt
10545796c8dcSSimon Schubert 	|
10555796c8dcSSimon Schubert 	;
10565796c8dcSSimon Schubert 
10575796c8dcSSimon Schubert cv_with_space_id : const_or_volatile space_identifier const_or_volatile
10585796c8dcSSimon Schubert 	;
10595796c8dcSSimon Schubert 
10605796c8dcSSimon Schubert const_or_volatile_or_space_identifier_noopt: cv_with_space_id
10615796c8dcSSimon Schubert 	| const_or_volatile_noopt
10625796c8dcSSimon Schubert 	;
10635796c8dcSSimon Schubert 
10645796c8dcSSimon Schubert const_or_volatile_or_space_identifier:
10655796c8dcSSimon Schubert 		const_or_volatile_or_space_identifier_noopt
10665796c8dcSSimon Schubert 	|
10675796c8dcSSimon Schubert 	;
10685796c8dcSSimon Schubert 
1069*ef5ccd6cSJohn Marino ptr_operator:
1070*ef5ccd6cSJohn Marino 		ptr_operator '*'
1071*ef5ccd6cSJohn Marino 			{ insert_type (tp_pointer); }
1072*ef5ccd6cSJohn Marino 		const_or_volatile_or_space_identifier
1073*ef5ccd6cSJohn Marino 	|	'*'
1074*ef5ccd6cSJohn Marino 			{ insert_type (tp_pointer); }
1075*ef5ccd6cSJohn Marino 		const_or_volatile_or_space_identifier
10765796c8dcSSimon Schubert 	|	'&'
1077*ef5ccd6cSJohn Marino 			{ insert_type (tp_reference); }
1078*ef5ccd6cSJohn Marino 	|	'&' ptr_operator
1079*ef5ccd6cSJohn Marino 			{ insert_type (tp_reference); }
1080*ef5ccd6cSJohn Marino 	;
1081*ef5ccd6cSJohn Marino 
1082*ef5ccd6cSJohn Marino ptr_operator_ts: ptr_operator
1083*ef5ccd6cSJohn Marino 			{
1084*ef5ccd6cSJohn Marino 			  $$ = get_type_stack ();
1085*ef5ccd6cSJohn Marino 			  /* This cleanup is eventually run by
1086*ef5ccd6cSJohn Marino 			     c_parse.  */
1087*ef5ccd6cSJohn Marino 			  make_cleanup (type_stack_cleanup, $$);
1088*ef5ccd6cSJohn Marino 			}
1089*ef5ccd6cSJohn Marino 	;
1090*ef5ccd6cSJohn Marino 
1091*ef5ccd6cSJohn Marino abs_decl:	ptr_operator_ts direct_abs_decl
1092*ef5ccd6cSJohn Marino 			{ $$ = append_type_stack ($2, $1); }
1093*ef5ccd6cSJohn Marino 	|	ptr_operator_ts
10945796c8dcSSimon Schubert 	|	direct_abs_decl
10955796c8dcSSimon Schubert 	;
10965796c8dcSSimon Schubert 
10975796c8dcSSimon Schubert direct_abs_decl: '(' abs_decl ')'
10985796c8dcSSimon Schubert 			{ $$ = $2; }
10995796c8dcSSimon Schubert 	|	direct_abs_decl array_mod
11005796c8dcSSimon Schubert 			{
1101*ef5ccd6cSJohn Marino 			  push_type_stack ($1);
11025796c8dcSSimon Schubert 			  push_type_int ($2);
11035796c8dcSSimon Schubert 			  push_type (tp_array);
1104*ef5ccd6cSJohn Marino 			  $$ = get_type_stack ();
11055796c8dcSSimon Schubert 			}
11065796c8dcSSimon Schubert 	|	array_mod
11075796c8dcSSimon Schubert 			{
11085796c8dcSSimon Schubert 			  push_type_int ($1);
11095796c8dcSSimon Schubert 			  push_type (tp_array);
1110*ef5ccd6cSJohn Marino 			  $$ = get_type_stack ();
11115796c8dcSSimon Schubert 			}
11125796c8dcSSimon Schubert 
11135796c8dcSSimon Schubert 	| 	direct_abs_decl func_mod
1114*ef5ccd6cSJohn Marino 			{
1115*ef5ccd6cSJohn Marino 			  push_type_stack ($1);
1116*ef5ccd6cSJohn Marino 			  push_typelist ($2);
1117*ef5ccd6cSJohn Marino 			  $$ = get_type_stack ();
1118*ef5ccd6cSJohn Marino 			}
11195796c8dcSSimon Schubert 	|	func_mod
1120*ef5ccd6cSJohn Marino 			{
1121*ef5ccd6cSJohn Marino 			  push_typelist ($1);
1122*ef5ccd6cSJohn Marino 			  $$ = get_type_stack ();
1123*ef5ccd6cSJohn Marino 			}
11245796c8dcSSimon Schubert 	;
11255796c8dcSSimon Schubert 
11265796c8dcSSimon Schubert array_mod:	'[' ']'
11275796c8dcSSimon Schubert 			{ $$ = -1; }
1128*ef5ccd6cSJohn Marino 	|	OBJC_LBRAC ']'
1129*ef5ccd6cSJohn Marino 			{ $$ = -1; }
11305796c8dcSSimon Schubert 	|	'[' INT ']'
11315796c8dcSSimon Schubert 			{ $$ = $2.val; }
1132*ef5ccd6cSJohn Marino 	|	OBJC_LBRAC INT ']'
1133*ef5ccd6cSJohn Marino 			{ $$ = $2.val; }
11345796c8dcSSimon Schubert 	;
11355796c8dcSSimon Schubert 
11365796c8dcSSimon Schubert func_mod:	'(' ')'
1137*ef5ccd6cSJohn Marino 			{ $$ = NULL; }
1138*ef5ccd6cSJohn Marino 	|	'(' parameter_typelist ')'
1139*ef5ccd6cSJohn Marino 			{ $$ = $2; }
11405796c8dcSSimon Schubert 	;
11415796c8dcSSimon Schubert 
11425796c8dcSSimon Schubert /* We used to try to recognize pointer to member types here, but
11435796c8dcSSimon Schubert    that didn't work (shift/reduce conflicts meant that these rules never
11445796c8dcSSimon Schubert    got executed).  The problem is that
11455796c8dcSSimon Schubert      int (foo::bar::baz::bizzle)
11465796c8dcSSimon Schubert    is a function type but
11475796c8dcSSimon Schubert      int (foo::bar::baz::bizzle::*)
11485796c8dcSSimon Schubert    is a pointer to member type.  Stroustrup loses again!  */
11495796c8dcSSimon Schubert 
11505796c8dcSSimon Schubert type	:	ptype
11515796c8dcSSimon Schubert 	;
11525796c8dcSSimon Schubert 
11535796c8dcSSimon Schubert typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
11545796c8dcSSimon Schubert 	:	TYPENAME
11555796c8dcSSimon Schubert 			{ $$ = $1.type; }
11565796c8dcSSimon Schubert 	|	INT_KEYWORD
1157c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1158c50c785cSJohn Marino 						       parse_gdbarch,
1159c50c785cSJohn Marino 						       "int"); }
11605796c8dcSSimon Schubert 	|	LONG
1161c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1162c50c785cSJohn Marino 						       parse_gdbarch,
1163c50c785cSJohn Marino 						       "long"); }
11645796c8dcSSimon Schubert 	|	SHORT
1165c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1166c50c785cSJohn Marino 						       parse_gdbarch,
1167c50c785cSJohn Marino 						       "short"); }
11685796c8dcSSimon Schubert 	|	LONG INT_KEYWORD
1169c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1170c50c785cSJohn Marino 						       parse_gdbarch,
1171c50c785cSJohn Marino 						       "long"); }
11725796c8dcSSimon Schubert 	|	LONG SIGNED_KEYWORD INT_KEYWORD
1173c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1174c50c785cSJohn Marino 						       parse_gdbarch,
1175c50c785cSJohn Marino 						       "long"); }
11765796c8dcSSimon Schubert 	|	LONG SIGNED_KEYWORD
1177c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1178c50c785cSJohn Marino 						       parse_gdbarch,
1179c50c785cSJohn Marino 						       "long"); }
11805796c8dcSSimon Schubert 	|	SIGNED_KEYWORD LONG INT_KEYWORD
1181c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1182c50c785cSJohn Marino 						       parse_gdbarch,
1183c50c785cSJohn Marino 						       "long"); }
11845796c8dcSSimon Schubert 	|	UNSIGNED LONG INT_KEYWORD
1185c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1186c50c785cSJohn Marino 							 parse_gdbarch,
1187c50c785cSJohn Marino 							 "long"); }
11885796c8dcSSimon Schubert 	|	LONG UNSIGNED INT_KEYWORD
1189c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1190c50c785cSJohn Marino 							 parse_gdbarch,
1191c50c785cSJohn Marino 							 "long"); }
11925796c8dcSSimon Schubert 	|	LONG UNSIGNED
1193c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1194c50c785cSJohn Marino 							 parse_gdbarch,
1195c50c785cSJohn Marino 							 "long"); }
11965796c8dcSSimon Schubert 	|	LONG LONG
1197c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1198c50c785cSJohn Marino 						       parse_gdbarch,
1199c50c785cSJohn Marino 						       "long long"); }
12005796c8dcSSimon Schubert 	|	LONG LONG INT_KEYWORD
1201c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1202c50c785cSJohn Marino 						       parse_gdbarch,
1203c50c785cSJohn Marino 						       "long long"); }
12045796c8dcSSimon Schubert 	|	LONG LONG SIGNED_KEYWORD INT_KEYWORD
1205c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1206c50c785cSJohn Marino 						       parse_gdbarch,
1207c50c785cSJohn Marino 						       "long long"); }
12085796c8dcSSimon Schubert 	|	LONG LONG SIGNED_KEYWORD
1209c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1210c50c785cSJohn Marino 						       parse_gdbarch,
1211c50c785cSJohn Marino 						       "long long"); }
12125796c8dcSSimon Schubert 	|	SIGNED_KEYWORD LONG LONG
1213c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1214c50c785cSJohn Marino 						       parse_gdbarch,
1215c50c785cSJohn Marino 						       "long long"); }
12165796c8dcSSimon Schubert 	|	SIGNED_KEYWORD LONG LONG INT_KEYWORD
1217c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1218c50c785cSJohn Marino 						       parse_gdbarch,
1219c50c785cSJohn Marino 						       "long long"); }
12205796c8dcSSimon Schubert 	|	UNSIGNED LONG LONG
1221c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1222c50c785cSJohn Marino 							 parse_gdbarch,
1223c50c785cSJohn Marino 							 "long long"); }
12245796c8dcSSimon Schubert 	|	UNSIGNED LONG LONG INT_KEYWORD
1225c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1226c50c785cSJohn Marino 							 parse_gdbarch,
1227c50c785cSJohn Marino 							 "long long"); }
12285796c8dcSSimon Schubert 	|	LONG LONG UNSIGNED
1229c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1230c50c785cSJohn Marino 							 parse_gdbarch,
1231c50c785cSJohn Marino 							 "long long"); }
12325796c8dcSSimon Schubert 	|	LONG LONG UNSIGNED INT_KEYWORD
1233c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1234c50c785cSJohn Marino 							 parse_gdbarch,
1235c50c785cSJohn Marino 							 "long long"); }
12365796c8dcSSimon Schubert 	|	SHORT INT_KEYWORD
1237c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1238c50c785cSJohn Marino 						       parse_gdbarch,
1239c50c785cSJohn Marino 						       "short"); }
12405796c8dcSSimon Schubert 	|	SHORT SIGNED_KEYWORD INT_KEYWORD
1241c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1242c50c785cSJohn Marino 						       parse_gdbarch,
1243c50c785cSJohn Marino 						       "short"); }
12445796c8dcSSimon Schubert 	|	SHORT SIGNED_KEYWORD
1245c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1246c50c785cSJohn Marino 						       parse_gdbarch,
1247c50c785cSJohn Marino 						       "short"); }
12485796c8dcSSimon Schubert 	|	UNSIGNED SHORT INT_KEYWORD
1249c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1250c50c785cSJohn Marino 							 parse_gdbarch,
1251c50c785cSJohn Marino 							 "short"); }
12525796c8dcSSimon Schubert 	|	SHORT UNSIGNED
1253c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1254c50c785cSJohn Marino 							 parse_gdbarch,
1255c50c785cSJohn Marino 							 "short"); }
12565796c8dcSSimon Schubert 	|	SHORT UNSIGNED INT_KEYWORD
1257c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1258c50c785cSJohn Marino 							 parse_gdbarch,
1259c50c785cSJohn Marino 							 "short"); }
12605796c8dcSSimon Schubert 	|	DOUBLE_KEYWORD
1261c50c785cSJohn Marino 			{ $$ = lookup_typename (parse_language, parse_gdbarch,
1262c50c785cSJohn Marino 						"double", (struct block *) NULL,
1263c50c785cSJohn Marino 						0); }
12645796c8dcSSimon Schubert 	|	LONG DOUBLE_KEYWORD
1265c50c785cSJohn Marino 			{ $$ = lookup_typename (parse_language, parse_gdbarch,
1266c50c785cSJohn Marino 						"long double",
1267c50c785cSJohn Marino 						(struct block *) NULL, 0); }
12685796c8dcSSimon Schubert 	|	STRUCT name
12695796c8dcSSimon Schubert 			{ $$ = lookup_struct (copy_name ($2),
12705796c8dcSSimon Schubert 					      expression_context_block); }
1271*ef5ccd6cSJohn Marino 	|	STRUCT COMPLETE
1272*ef5ccd6cSJohn Marino 			{
1273*ef5ccd6cSJohn Marino 			  mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
1274*ef5ccd6cSJohn Marino 			  $$ = NULL;
1275*ef5ccd6cSJohn Marino 			}
1276*ef5ccd6cSJohn Marino 	|	STRUCT name COMPLETE
1277*ef5ccd6cSJohn Marino 			{
1278*ef5ccd6cSJohn Marino 			  mark_completion_tag (TYPE_CODE_STRUCT, $2.ptr,
1279*ef5ccd6cSJohn Marino 					       $2.length);
1280*ef5ccd6cSJohn Marino 			  $$ = NULL;
1281*ef5ccd6cSJohn Marino 			}
12825796c8dcSSimon Schubert 	|	CLASS name
12835796c8dcSSimon Schubert 			{ $$ = lookup_struct (copy_name ($2),
12845796c8dcSSimon Schubert 					      expression_context_block); }
1285*ef5ccd6cSJohn Marino 	|	CLASS COMPLETE
1286*ef5ccd6cSJohn Marino 			{
1287*ef5ccd6cSJohn Marino 			  mark_completion_tag (TYPE_CODE_CLASS, "", 0);
1288*ef5ccd6cSJohn Marino 			  $$ = NULL;
1289*ef5ccd6cSJohn Marino 			}
1290*ef5ccd6cSJohn Marino 	|	CLASS name COMPLETE
1291*ef5ccd6cSJohn Marino 			{
1292*ef5ccd6cSJohn Marino 			  mark_completion_tag (TYPE_CODE_CLASS, $2.ptr,
1293*ef5ccd6cSJohn Marino 					       $2.length);
1294*ef5ccd6cSJohn Marino 			  $$ = NULL;
1295*ef5ccd6cSJohn Marino 			}
12965796c8dcSSimon Schubert 	|	UNION name
12975796c8dcSSimon Schubert 			{ $$ = lookup_union (copy_name ($2),
12985796c8dcSSimon Schubert 					     expression_context_block); }
1299*ef5ccd6cSJohn Marino 	|	UNION COMPLETE
1300*ef5ccd6cSJohn Marino 			{
1301*ef5ccd6cSJohn Marino 			  mark_completion_tag (TYPE_CODE_UNION, "", 0);
1302*ef5ccd6cSJohn Marino 			  $$ = NULL;
1303*ef5ccd6cSJohn Marino 			}
1304*ef5ccd6cSJohn Marino 	|	UNION name COMPLETE
1305*ef5ccd6cSJohn Marino 			{
1306*ef5ccd6cSJohn Marino 			  mark_completion_tag (TYPE_CODE_UNION, $2.ptr,
1307*ef5ccd6cSJohn Marino 					       $2.length);
1308*ef5ccd6cSJohn Marino 			  $$ = NULL;
1309*ef5ccd6cSJohn Marino 			}
13105796c8dcSSimon Schubert 	|	ENUM name
13115796c8dcSSimon Schubert 			{ $$ = lookup_enum (copy_name ($2),
13125796c8dcSSimon Schubert 					    expression_context_block); }
1313*ef5ccd6cSJohn Marino 	|	ENUM COMPLETE
1314*ef5ccd6cSJohn Marino 			{
1315*ef5ccd6cSJohn Marino 			  mark_completion_tag (TYPE_CODE_ENUM, "", 0);
1316*ef5ccd6cSJohn Marino 			  $$ = NULL;
1317*ef5ccd6cSJohn Marino 			}
1318*ef5ccd6cSJohn Marino 	|	ENUM name COMPLETE
1319*ef5ccd6cSJohn Marino 			{
1320*ef5ccd6cSJohn Marino 			  mark_completion_tag (TYPE_CODE_ENUM, $2.ptr,
1321*ef5ccd6cSJohn Marino 					       $2.length);
1322*ef5ccd6cSJohn Marino 			  $$ = NULL;
1323*ef5ccd6cSJohn Marino 			}
13245796c8dcSSimon Schubert 	|	UNSIGNED typename
13255796c8dcSSimon Schubert 			{ $$ = lookup_unsigned_typename (parse_language,
13265796c8dcSSimon Schubert 							 parse_gdbarch,
13275796c8dcSSimon Schubert 							 TYPE_NAME($2.type)); }
13285796c8dcSSimon Schubert 	|	UNSIGNED
1329c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1330c50c785cSJohn Marino 							 parse_gdbarch,
1331c50c785cSJohn Marino 							 "int"); }
13325796c8dcSSimon Schubert 	|	SIGNED_KEYWORD typename
13335796c8dcSSimon Schubert 			{ $$ = lookup_signed_typename (parse_language,
13345796c8dcSSimon Schubert 						       parse_gdbarch,
13355796c8dcSSimon Schubert 						       TYPE_NAME($2.type)); }
13365796c8dcSSimon Schubert 	|	SIGNED_KEYWORD
1337c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1338c50c785cSJohn Marino 						       parse_gdbarch,
1339c50c785cSJohn Marino 						       "int"); }
13405796c8dcSSimon Schubert                 /* It appears that this rule for templates is never
13415796c8dcSSimon Schubert                    reduced; template recognition happens by lookahead
13425796c8dcSSimon Schubert                    in the token processing code in yylex. */
13435796c8dcSSimon Schubert 	|	TEMPLATE name '<' type '>'
13445796c8dcSSimon Schubert 			{ $$ = lookup_template_type(copy_name($2), $4,
13455796c8dcSSimon Schubert 						    expression_context_block);
13465796c8dcSSimon Schubert 			}
13475796c8dcSSimon Schubert 	| const_or_volatile_or_space_identifier_noopt typebase
13485796c8dcSSimon Schubert 			{ $$ = follow_types ($2); }
13495796c8dcSSimon Schubert 	| typebase const_or_volatile_or_space_identifier_noopt
13505796c8dcSSimon Schubert 			{ $$ = follow_types ($1); }
13515796c8dcSSimon Schubert 	;
13525796c8dcSSimon Schubert 
13535796c8dcSSimon Schubert typename:	TYPENAME
13545796c8dcSSimon Schubert 	|	INT_KEYWORD
13555796c8dcSSimon Schubert 		{
13565796c8dcSSimon Schubert 		  $$.stoken.ptr = "int";
13575796c8dcSSimon Schubert 		  $$.stoken.length = 3;
1358c50c785cSJohn Marino 		  $$.type = lookup_signed_typename (parse_language,
1359c50c785cSJohn Marino 						    parse_gdbarch,
1360c50c785cSJohn Marino 						    "int");
13615796c8dcSSimon Schubert 		}
13625796c8dcSSimon Schubert 	|	LONG
13635796c8dcSSimon Schubert 		{
13645796c8dcSSimon Schubert 		  $$.stoken.ptr = "long";
13655796c8dcSSimon Schubert 		  $$.stoken.length = 4;
1366c50c785cSJohn Marino 		  $$.type = lookup_signed_typename (parse_language,
1367c50c785cSJohn Marino 						    parse_gdbarch,
1368c50c785cSJohn Marino 						    "long");
13695796c8dcSSimon Schubert 		}
13705796c8dcSSimon Schubert 	|	SHORT
13715796c8dcSSimon Schubert 		{
13725796c8dcSSimon Schubert 		  $$.stoken.ptr = "short";
13735796c8dcSSimon Schubert 		  $$.stoken.length = 5;
1374c50c785cSJohn Marino 		  $$.type = lookup_signed_typename (parse_language,
1375c50c785cSJohn Marino 						    parse_gdbarch,
1376c50c785cSJohn Marino 						    "short");
13775796c8dcSSimon Schubert 		}
13785796c8dcSSimon Schubert 	;
13795796c8dcSSimon Schubert 
1380*ef5ccd6cSJohn Marino parameter_typelist:
1381*ef5ccd6cSJohn Marino 		nonempty_typelist
1382*ef5ccd6cSJohn Marino 			{ check_parameter_typelist ($1); }
1383*ef5ccd6cSJohn Marino 	|	nonempty_typelist ',' DOTDOTDOT
1384*ef5ccd6cSJohn Marino 			{
1385*ef5ccd6cSJohn Marino 			  VEC_safe_push (type_ptr, $1, NULL);
1386*ef5ccd6cSJohn Marino 			  check_parameter_typelist ($1);
1387*ef5ccd6cSJohn Marino 			  $$ = $1;
1388*ef5ccd6cSJohn Marino 			}
1389*ef5ccd6cSJohn Marino 	;
1390*ef5ccd6cSJohn Marino 
13915796c8dcSSimon Schubert nonempty_typelist
13925796c8dcSSimon Schubert 	:	type
1393*ef5ccd6cSJohn Marino 		{
1394*ef5ccd6cSJohn Marino 		  VEC (type_ptr) *typelist = NULL;
1395*ef5ccd6cSJohn Marino 		  VEC_safe_push (type_ptr, typelist, $1);
1396*ef5ccd6cSJohn Marino 		  $$ = typelist;
13975796c8dcSSimon Schubert 		}
13985796c8dcSSimon Schubert 	|	nonempty_typelist ',' type
1399*ef5ccd6cSJohn Marino 		{
1400*ef5ccd6cSJohn Marino 		  VEC_safe_push (type_ptr, $1, $3);
1401*ef5ccd6cSJohn Marino 		  $$ = $1;
14025796c8dcSSimon Schubert 		}
14035796c8dcSSimon Schubert 	;
14045796c8dcSSimon Schubert 
14055796c8dcSSimon Schubert ptype	:	typebase
1406*ef5ccd6cSJohn Marino 	|	ptype abs_decl
1407*ef5ccd6cSJohn Marino 		{
1408*ef5ccd6cSJohn Marino 		  push_type_stack ($2);
1409*ef5ccd6cSJohn Marino 		  $$ = follow_types ($1);
1410*ef5ccd6cSJohn Marino 		}
1411*ef5ccd6cSJohn Marino 	;
1412*ef5ccd6cSJohn Marino 
1413*ef5ccd6cSJohn Marino conversion_type_id: typebase conversion_declarator
14145796c8dcSSimon Schubert 		{ $$ = follow_types ($1); }
14155796c8dcSSimon Schubert 	;
14165796c8dcSSimon Schubert 
1417*ef5ccd6cSJohn Marino conversion_declarator:  /* Nothing.  */
1418*ef5ccd6cSJohn Marino 	| ptr_operator conversion_declarator
1419*ef5ccd6cSJohn Marino 	;
1420*ef5ccd6cSJohn Marino 
14215796c8dcSSimon Schubert const_and_volatile: 	CONST_KEYWORD VOLATILE_KEYWORD
14225796c8dcSSimon Schubert 	| 		VOLATILE_KEYWORD CONST_KEYWORD
14235796c8dcSSimon Schubert 	;
14245796c8dcSSimon Schubert 
14255796c8dcSSimon Schubert const_or_volatile_noopt:  	const_and_volatile
1426*ef5ccd6cSJohn Marino 			{ insert_type (tp_const);
1427*ef5ccd6cSJohn Marino 			  insert_type (tp_volatile);
14285796c8dcSSimon Schubert 			}
14295796c8dcSSimon Schubert 	| 		CONST_KEYWORD
1430*ef5ccd6cSJohn Marino 			{ insert_type (tp_const); }
14315796c8dcSSimon Schubert 	| 		VOLATILE_KEYWORD
1432*ef5ccd6cSJohn Marino 			{ insert_type (tp_volatile); }
14335796c8dcSSimon Schubert 	;
14345796c8dcSSimon Schubert 
1435cf7f2e2dSJohn Marino operator:	OPERATOR NEW
1436cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (" new"); }
1437cf7f2e2dSJohn Marino 	|	OPERATOR DELETE
1438cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (" delete"); }
1439cf7f2e2dSJohn Marino 	|	OPERATOR NEW '[' ']'
1440cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (" new[]"); }
1441cf7f2e2dSJohn Marino 	|	OPERATOR DELETE '[' ']'
1442cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (" delete[]"); }
1443*ef5ccd6cSJohn Marino 	|	OPERATOR NEW OBJC_LBRAC ']'
1444*ef5ccd6cSJohn Marino 			{ $$ = operator_stoken (" new[]"); }
1445*ef5ccd6cSJohn Marino 	|	OPERATOR DELETE OBJC_LBRAC ']'
1446*ef5ccd6cSJohn Marino 			{ $$ = operator_stoken (" delete[]"); }
1447cf7f2e2dSJohn Marino 	|	OPERATOR '+'
1448cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("+"); }
1449cf7f2e2dSJohn Marino 	|	OPERATOR '-'
1450cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("-"); }
1451cf7f2e2dSJohn Marino 	|	OPERATOR '*'
1452cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("*"); }
1453cf7f2e2dSJohn Marino 	|	OPERATOR '/'
1454cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("/"); }
1455cf7f2e2dSJohn Marino 	|	OPERATOR '%'
1456cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("%"); }
1457cf7f2e2dSJohn Marino 	|	OPERATOR '^'
1458cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("^"); }
1459cf7f2e2dSJohn Marino 	|	OPERATOR '&'
1460cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("&"); }
1461cf7f2e2dSJohn Marino 	|	OPERATOR '|'
1462cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("|"); }
1463cf7f2e2dSJohn Marino 	|	OPERATOR '~'
1464cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("~"); }
1465cf7f2e2dSJohn Marino 	|	OPERATOR '!'
1466cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("!"); }
1467cf7f2e2dSJohn Marino 	|	OPERATOR '='
1468cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("="); }
1469cf7f2e2dSJohn Marino 	|	OPERATOR '<'
1470cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("<"); }
1471cf7f2e2dSJohn Marino 	|	OPERATOR '>'
1472cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (">"); }
1473cf7f2e2dSJohn Marino 	|	OPERATOR ASSIGN_MODIFY
1474cf7f2e2dSJohn Marino 			{ const char *op = "unknown";
1475cf7f2e2dSJohn Marino 			  switch ($2)
1476cf7f2e2dSJohn Marino 			    {
1477cf7f2e2dSJohn Marino 			    case BINOP_RSH:
1478cf7f2e2dSJohn Marino 			      op = ">>=";
1479cf7f2e2dSJohn Marino 			      break;
1480cf7f2e2dSJohn Marino 			    case BINOP_LSH:
1481cf7f2e2dSJohn Marino 			      op = "<<=";
1482cf7f2e2dSJohn Marino 			      break;
1483cf7f2e2dSJohn Marino 			    case BINOP_ADD:
1484cf7f2e2dSJohn Marino 			      op = "+=";
1485cf7f2e2dSJohn Marino 			      break;
1486cf7f2e2dSJohn Marino 			    case BINOP_SUB:
1487cf7f2e2dSJohn Marino 			      op = "-=";
1488cf7f2e2dSJohn Marino 			      break;
1489cf7f2e2dSJohn Marino 			    case BINOP_MUL:
1490cf7f2e2dSJohn Marino 			      op = "*=";
1491cf7f2e2dSJohn Marino 			      break;
1492cf7f2e2dSJohn Marino 			    case BINOP_DIV:
1493cf7f2e2dSJohn Marino 			      op = "/=";
1494cf7f2e2dSJohn Marino 			      break;
1495cf7f2e2dSJohn Marino 			    case BINOP_REM:
1496cf7f2e2dSJohn Marino 			      op = "%=";
1497cf7f2e2dSJohn Marino 			      break;
1498cf7f2e2dSJohn Marino 			    case BINOP_BITWISE_IOR:
1499cf7f2e2dSJohn Marino 			      op = "|=";
1500cf7f2e2dSJohn Marino 			      break;
1501cf7f2e2dSJohn Marino 			    case BINOP_BITWISE_AND:
1502cf7f2e2dSJohn Marino 			      op = "&=";
1503cf7f2e2dSJohn Marino 			      break;
1504cf7f2e2dSJohn Marino 			    case BINOP_BITWISE_XOR:
1505cf7f2e2dSJohn Marino 			      op = "^=";
1506cf7f2e2dSJohn Marino 			      break;
1507cf7f2e2dSJohn Marino 			    default:
1508cf7f2e2dSJohn Marino 			      break;
1509cf7f2e2dSJohn Marino 			    }
1510cf7f2e2dSJohn Marino 
1511cf7f2e2dSJohn Marino 			  $$ = operator_stoken (op);
1512cf7f2e2dSJohn Marino 			}
1513cf7f2e2dSJohn Marino 	|	OPERATOR LSH
1514cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("<<"); }
1515cf7f2e2dSJohn Marino 	|	OPERATOR RSH
1516cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (">>"); }
1517cf7f2e2dSJohn Marino 	|	OPERATOR EQUAL
1518cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("=="); }
1519cf7f2e2dSJohn Marino 	|	OPERATOR NOTEQUAL
1520cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("!="); }
1521cf7f2e2dSJohn Marino 	|	OPERATOR LEQ
1522cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("<="); }
1523cf7f2e2dSJohn Marino 	|	OPERATOR GEQ
1524cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (">="); }
1525cf7f2e2dSJohn Marino 	|	OPERATOR ANDAND
1526cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("&&"); }
1527cf7f2e2dSJohn Marino 	|	OPERATOR OROR
1528cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("||"); }
1529cf7f2e2dSJohn Marino 	|	OPERATOR INCREMENT
1530cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("++"); }
1531cf7f2e2dSJohn Marino 	|	OPERATOR DECREMENT
1532cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("--"); }
1533cf7f2e2dSJohn Marino 	|	OPERATOR ','
1534cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (","); }
1535cf7f2e2dSJohn Marino 	|	OPERATOR ARROW_STAR
1536cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("->*"); }
1537cf7f2e2dSJohn Marino 	|	OPERATOR ARROW
1538cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("->"); }
1539cf7f2e2dSJohn Marino 	|	OPERATOR '(' ')'
1540cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("()"); }
1541cf7f2e2dSJohn Marino 	|	OPERATOR '[' ']'
1542cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("[]"); }
1543*ef5ccd6cSJohn Marino 	|	OPERATOR OBJC_LBRAC ']'
1544*ef5ccd6cSJohn Marino 			{ $$ = operator_stoken ("[]"); }
1545*ef5ccd6cSJohn Marino 	|	OPERATOR conversion_type_id
1546cf7f2e2dSJohn Marino 			{ char *name;
1547cf7f2e2dSJohn Marino 			  long length;
1548cf7f2e2dSJohn Marino 			  struct ui_file *buf = mem_fileopen ();
1549cf7f2e2dSJohn Marino 
1550*ef5ccd6cSJohn Marino 			  c_print_type ($2, NULL, buf, -1, 0,
1551*ef5ccd6cSJohn Marino 					&type_print_raw_options);
1552cf7f2e2dSJohn Marino 			  name = ui_file_xstrdup (buf, &length);
1553cf7f2e2dSJohn Marino 			  ui_file_delete (buf);
1554cf7f2e2dSJohn Marino 			  $$ = operator_stoken (name);
1555cf7f2e2dSJohn Marino 			  free (name);
1556cf7f2e2dSJohn Marino 			}
1557cf7f2e2dSJohn Marino 	;
1558cf7f2e2dSJohn Marino 
1559cf7f2e2dSJohn Marino 
1560cf7f2e2dSJohn Marino 
15615796c8dcSSimon Schubert name	:	NAME { $$ = $1.stoken; }
15625796c8dcSSimon Schubert 	|	BLOCKNAME { $$ = $1.stoken; }
15635796c8dcSSimon Schubert 	|	TYPENAME { $$ = $1.stoken; }
15645796c8dcSSimon Schubert 	|	NAME_OR_INT  { $$ = $1.stoken; }
1565cf7f2e2dSJohn Marino 	|	UNKNOWN_CPP_NAME  { $$ = $1.stoken; }
1566cf7f2e2dSJohn Marino 	|	operator { $$ = $1; }
15675796c8dcSSimon Schubert 	;
15685796c8dcSSimon Schubert 
15695796c8dcSSimon Schubert name_not_typename :	NAME
15705796c8dcSSimon Schubert 	|	BLOCKNAME
15715796c8dcSSimon Schubert /* These would be useful if name_not_typename was useful, but it is just
15725796c8dcSSimon Schubert    a fake for "variable", so these cause reduce/reduce conflicts because
15735796c8dcSSimon Schubert    the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
15745796c8dcSSimon Schubert    =exp) or just an exp.  If name_not_typename was ever used in an lvalue
15755796c8dcSSimon Schubert    context where only a name could occur, this might be useful.
15765796c8dcSSimon Schubert   	|	NAME_OR_INT
15775796c8dcSSimon Schubert  */
1578cf7f2e2dSJohn Marino 	|	operator
1579cf7f2e2dSJohn Marino 			{
1580*ef5ccd6cSJohn Marino 			  struct field_of_this_result is_a_field_of_this;
1581*ef5ccd6cSJohn Marino 
1582cf7f2e2dSJohn Marino 			  $$.stoken = $1;
1583cf7f2e2dSJohn Marino 			  $$.sym = lookup_symbol ($1.ptr,
1584cf7f2e2dSJohn Marino 						  expression_context_block,
1585cf7f2e2dSJohn Marino 						  VAR_DOMAIN,
1586*ef5ccd6cSJohn Marino 						  &is_a_field_of_this);
1587*ef5ccd6cSJohn Marino 			  $$.is_a_field_of_this
1588*ef5ccd6cSJohn Marino 			    = is_a_field_of_this.type != NULL;
1589cf7f2e2dSJohn Marino 			}
1590cf7f2e2dSJohn Marino 	|	UNKNOWN_CPP_NAME
15915796c8dcSSimon Schubert 	;
15925796c8dcSSimon Schubert 
15935796c8dcSSimon Schubert %%
15945796c8dcSSimon Schubert 
1595cf7f2e2dSJohn Marino /* Returns a stoken of the operator name given by OP (which does not
1596cf7f2e2dSJohn Marino    include the string "operator").  */
1597cf7f2e2dSJohn Marino static struct stoken
1598cf7f2e2dSJohn Marino operator_stoken (const char *op)
1599cf7f2e2dSJohn Marino {
1600cf7f2e2dSJohn Marino   static const char *operator_string = "operator";
1601cf7f2e2dSJohn Marino   struct stoken st = { NULL, 0 };
1602cf7f2e2dSJohn Marino   st.length = strlen (operator_string) + strlen (op);
1603cf7f2e2dSJohn Marino   st.ptr = malloc (st.length + 1);
1604cf7f2e2dSJohn Marino   strcpy (st.ptr, operator_string);
1605cf7f2e2dSJohn Marino   strcat (st.ptr, op);
1606cf7f2e2dSJohn Marino 
1607cf7f2e2dSJohn Marino   /* The toplevel (c_parse) will free the memory allocated here.  */
1608cf7f2e2dSJohn Marino   make_cleanup (free, st.ptr);
1609cf7f2e2dSJohn Marino   return st;
1610cf7f2e2dSJohn Marino };
1611cf7f2e2dSJohn Marino 
1612*ef5ccd6cSJohn Marino /* Validate a parameter typelist.  */
1613*ef5ccd6cSJohn Marino 
1614*ef5ccd6cSJohn Marino static void
check_parameter_typelist(VEC (type_ptr)* params)1615*ef5ccd6cSJohn Marino check_parameter_typelist (VEC (type_ptr) *params)
1616*ef5ccd6cSJohn Marino {
1617*ef5ccd6cSJohn Marino   struct type *type;
1618*ef5ccd6cSJohn Marino   int ix;
1619*ef5ccd6cSJohn Marino 
1620*ef5ccd6cSJohn Marino   for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix)
1621*ef5ccd6cSJohn Marino     {
1622*ef5ccd6cSJohn Marino       if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
1623*ef5ccd6cSJohn Marino 	{
1624*ef5ccd6cSJohn Marino 	  if (ix == 0)
1625*ef5ccd6cSJohn Marino 	    {
1626*ef5ccd6cSJohn Marino 	      if (VEC_length (type_ptr, params) == 1)
1627*ef5ccd6cSJohn Marino 		{
1628*ef5ccd6cSJohn Marino 		  /* Ok.  */
1629*ef5ccd6cSJohn Marino 		  break;
1630*ef5ccd6cSJohn Marino 		}
1631*ef5ccd6cSJohn Marino 	      VEC_free (type_ptr, params);
1632*ef5ccd6cSJohn Marino 	      error (_("parameter types following 'void'"));
1633*ef5ccd6cSJohn Marino 	    }
1634*ef5ccd6cSJohn Marino 	  else
1635*ef5ccd6cSJohn Marino 	    {
1636*ef5ccd6cSJohn Marino 	      VEC_free (type_ptr, params);
1637*ef5ccd6cSJohn Marino 	      error (_("'void' invalid as parameter type"));
1638*ef5ccd6cSJohn Marino 	    }
1639*ef5ccd6cSJohn Marino 	}
1640*ef5ccd6cSJohn Marino     }
1641*ef5ccd6cSJohn Marino }
1642*ef5ccd6cSJohn Marino 
16435796c8dcSSimon Schubert /* Take care of parsing a number (anything that starts with a digit).
16445796c8dcSSimon Schubert    Set yylval and return the token type; update lexptr.
16455796c8dcSSimon Schubert    LEN is the number of characters in it.  */
16465796c8dcSSimon Schubert 
16475796c8dcSSimon Schubert /*** Needs some error checking for the float case ***/
16485796c8dcSSimon Schubert 
16495796c8dcSSimon Schubert static int
parse_number(char * p,int len,int parsed_float,YYSTYPE * putithere)16505796c8dcSSimon Schubert parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
16515796c8dcSSimon Schubert {
16525796c8dcSSimon Schubert   /* FIXME: Shouldn't these be unsigned?  We don't deal with negative values
16535796c8dcSSimon Schubert      here, and we do kind of silly things like cast to unsigned.  */
16545796c8dcSSimon Schubert   LONGEST n = 0;
16555796c8dcSSimon Schubert   LONGEST prevn = 0;
16565796c8dcSSimon Schubert   ULONGEST un;
16575796c8dcSSimon Schubert 
16585796c8dcSSimon Schubert   int i = 0;
16595796c8dcSSimon Schubert   int c;
16605796c8dcSSimon Schubert   int base = input_radix;
16615796c8dcSSimon Schubert   int unsigned_p = 0;
16625796c8dcSSimon Schubert 
16635796c8dcSSimon Schubert   /* Number of "L" suffixes encountered.  */
16645796c8dcSSimon Schubert   int long_p = 0;
16655796c8dcSSimon Schubert 
16665796c8dcSSimon Schubert   /* We have found a "L" or "U" suffix.  */
16675796c8dcSSimon Schubert   int found_suffix = 0;
16685796c8dcSSimon Schubert 
16695796c8dcSSimon Schubert   ULONGEST high_bit;
16705796c8dcSSimon Schubert   struct type *signed_type;
16715796c8dcSSimon Schubert   struct type *unsigned_type;
16725796c8dcSSimon Schubert 
16735796c8dcSSimon Schubert   if (parsed_float)
16745796c8dcSSimon Schubert     {
16755796c8dcSSimon Schubert       /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
16765796c8dcSSimon Schubert          point.  Return DECFLOAT.  */
16775796c8dcSSimon Schubert 
16785796c8dcSSimon Schubert       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
16795796c8dcSSimon Schubert 	{
16805796c8dcSSimon Schubert 	  p[len - 2] = '\0';
16815796c8dcSSimon Schubert 	  putithere->typed_val_decfloat.type
16825796c8dcSSimon Schubert 	    = parse_type->builtin_decfloat;
16835796c8dcSSimon Schubert 	  decimal_from_string (putithere->typed_val_decfloat.val, 4,
16845796c8dcSSimon Schubert 			       gdbarch_byte_order (parse_gdbarch), p);
16855796c8dcSSimon Schubert 	  p[len - 2] = 'd';
16865796c8dcSSimon Schubert 	  return DECFLOAT;
16875796c8dcSSimon Schubert 	}
16885796c8dcSSimon Schubert 
16895796c8dcSSimon Schubert       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
16905796c8dcSSimon Schubert 	{
16915796c8dcSSimon Schubert 	  p[len - 2] = '\0';
16925796c8dcSSimon Schubert 	  putithere->typed_val_decfloat.type
16935796c8dcSSimon Schubert 	    = parse_type->builtin_decdouble;
16945796c8dcSSimon Schubert 	  decimal_from_string (putithere->typed_val_decfloat.val, 8,
16955796c8dcSSimon Schubert 			       gdbarch_byte_order (parse_gdbarch), p);
16965796c8dcSSimon Schubert 	  p[len - 2] = 'd';
16975796c8dcSSimon Schubert 	  return DECFLOAT;
16985796c8dcSSimon Schubert 	}
16995796c8dcSSimon Schubert 
17005796c8dcSSimon Schubert       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
17015796c8dcSSimon Schubert 	{
17025796c8dcSSimon Schubert 	  p[len - 2] = '\0';
17035796c8dcSSimon Schubert 	  putithere->typed_val_decfloat.type
17045796c8dcSSimon Schubert 	    = parse_type->builtin_declong;
17055796c8dcSSimon Schubert 	  decimal_from_string (putithere->typed_val_decfloat.val, 16,
17065796c8dcSSimon Schubert 			       gdbarch_byte_order (parse_gdbarch), p);
17075796c8dcSSimon Schubert 	  p[len - 2] = 'd';
17085796c8dcSSimon Schubert 	  return DECFLOAT;
17095796c8dcSSimon Schubert 	}
17105796c8dcSSimon Schubert 
1711c50c785cSJohn Marino       if (! parse_c_float (parse_gdbarch, p, len,
1712c50c785cSJohn Marino 			   &putithere->typed_val_float.dval,
1713c50c785cSJohn Marino 			   &putithere->typed_val_float.type))
1714cf7f2e2dSJohn Marino 	return ERROR;
17155796c8dcSSimon Schubert       return FLOAT;
17165796c8dcSSimon Schubert     }
17175796c8dcSSimon Schubert 
17185796c8dcSSimon Schubert   /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
17195796c8dcSSimon Schubert   if (p[0] == '0')
17205796c8dcSSimon Schubert     switch (p[1])
17215796c8dcSSimon Schubert       {
17225796c8dcSSimon Schubert       case 'x':
17235796c8dcSSimon Schubert       case 'X':
17245796c8dcSSimon Schubert 	if (len >= 3)
17255796c8dcSSimon Schubert 	  {
17265796c8dcSSimon Schubert 	    p += 2;
17275796c8dcSSimon Schubert 	    base = 16;
17285796c8dcSSimon Schubert 	    len -= 2;
17295796c8dcSSimon Schubert 	  }
17305796c8dcSSimon Schubert 	break;
17315796c8dcSSimon Schubert 
1732cf7f2e2dSJohn Marino       case 'b':
1733cf7f2e2dSJohn Marino       case 'B':
1734cf7f2e2dSJohn Marino 	if (len >= 3)
1735cf7f2e2dSJohn Marino 	  {
1736cf7f2e2dSJohn Marino 	    p += 2;
1737cf7f2e2dSJohn Marino 	    base = 2;
1738cf7f2e2dSJohn Marino 	    len -= 2;
1739cf7f2e2dSJohn Marino 	  }
1740cf7f2e2dSJohn Marino 	break;
1741cf7f2e2dSJohn Marino 
17425796c8dcSSimon Schubert       case 't':
17435796c8dcSSimon Schubert       case 'T':
17445796c8dcSSimon Schubert       case 'd':
17455796c8dcSSimon Schubert       case 'D':
17465796c8dcSSimon Schubert 	if (len >= 3)
17475796c8dcSSimon Schubert 	  {
17485796c8dcSSimon Schubert 	    p += 2;
17495796c8dcSSimon Schubert 	    base = 10;
17505796c8dcSSimon Schubert 	    len -= 2;
17515796c8dcSSimon Schubert 	  }
17525796c8dcSSimon Schubert 	break;
17535796c8dcSSimon Schubert 
17545796c8dcSSimon Schubert       default:
17555796c8dcSSimon Schubert 	base = 8;
17565796c8dcSSimon Schubert 	break;
17575796c8dcSSimon Schubert       }
17585796c8dcSSimon Schubert 
17595796c8dcSSimon Schubert   while (len-- > 0)
17605796c8dcSSimon Schubert     {
17615796c8dcSSimon Schubert       c = *p++;
17625796c8dcSSimon Schubert       if (c >= 'A' && c <= 'Z')
17635796c8dcSSimon Schubert 	c += 'a' - 'A';
17645796c8dcSSimon Schubert       if (c != 'l' && c != 'u')
17655796c8dcSSimon Schubert 	n *= base;
17665796c8dcSSimon Schubert       if (c >= '0' && c <= '9')
17675796c8dcSSimon Schubert 	{
17685796c8dcSSimon Schubert 	  if (found_suffix)
17695796c8dcSSimon Schubert 	    return ERROR;
17705796c8dcSSimon Schubert 	  n += i = c - '0';
17715796c8dcSSimon Schubert 	}
17725796c8dcSSimon Schubert       else
17735796c8dcSSimon Schubert 	{
17745796c8dcSSimon Schubert 	  if (base > 10 && c >= 'a' && c <= 'f')
17755796c8dcSSimon Schubert 	    {
17765796c8dcSSimon Schubert 	      if (found_suffix)
17775796c8dcSSimon Schubert 		return ERROR;
17785796c8dcSSimon Schubert 	      n += i = c - 'a' + 10;
17795796c8dcSSimon Schubert 	    }
17805796c8dcSSimon Schubert 	  else if (c == 'l')
17815796c8dcSSimon Schubert 	    {
17825796c8dcSSimon Schubert 	      ++long_p;
17835796c8dcSSimon Schubert 	      found_suffix = 1;
17845796c8dcSSimon Schubert 	    }
17855796c8dcSSimon Schubert 	  else if (c == 'u')
17865796c8dcSSimon Schubert 	    {
17875796c8dcSSimon Schubert 	      unsigned_p = 1;
17885796c8dcSSimon Schubert 	      found_suffix = 1;
17895796c8dcSSimon Schubert 	    }
17905796c8dcSSimon Schubert 	  else
17915796c8dcSSimon Schubert 	    return ERROR;	/* Char not a digit */
17925796c8dcSSimon Schubert 	}
17935796c8dcSSimon Schubert       if (i >= base)
17945796c8dcSSimon Schubert 	return ERROR;		/* Invalid digit in this base */
17955796c8dcSSimon Schubert 
17965796c8dcSSimon Schubert       /* Portably test for overflow (only works for nonzero values, so make
17975796c8dcSSimon Schubert 	 a second check for zero).  FIXME: Can't we just make n and prevn
17985796c8dcSSimon Schubert 	 unsigned and avoid this?  */
17995796c8dcSSimon Schubert       if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
18005796c8dcSSimon Schubert 	unsigned_p = 1;		/* Try something unsigned */
18015796c8dcSSimon Schubert 
18025796c8dcSSimon Schubert       /* Portably test for unsigned overflow.
18035796c8dcSSimon Schubert 	 FIXME: This check is wrong; for example it doesn't find overflow
18045796c8dcSSimon Schubert 	 on 0x123456789 when LONGEST is 32 bits.  */
18055796c8dcSSimon Schubert       if (c != 'l' && c != 'u' && n != 0)
18065796c8dcSSimon Schubert 	{
18075796c8dcSSimon Schubert 	  if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1808c50c785cSJohn Marino 	    error (_("Numeric constant too large."));
18095796c8dcSSimon Schubert 	}
18105796c8dcSSimon Schubert       prevn = n;
18115796c8dcSSimon Schubert     }
18125796c8dcSSimon Schubert 
18135796c8dcSSimon Schubert   /* An integer constant is an int, a long, or a long long.  An L
18145796c8dcSSimon Schubert      suffix forces it to be long; an LL suffix forces it to be long
18155796c8dcSSimon Schubert      long.  If not forced to a larger size, it gets the first type of
18165796c8dcSSimon Schubert      the above that it fits in.  To figure out whether it fits, we
18175796c8dcSSimon Schubert      shift it right and see whether anything remains.  Note that we
18185796c8dcSSimon Schubert      can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
18195796c8dcSSimon Schubert      operation, because many compilers will warn about such a shift
18205796c8dcSSimon Schubert      (which always produces a zero result).  Sometimes gdbarch_int_bit
18215796c8dcSSimon Schubert      or gdbarch_long_bit will be that big, sometimes not.  To deal with
18225796c8dcSSimon Schubert      the case where it is we just always shift the value more than
18235796c8dcSSimon Schubert      once, with fewer bits each time.  */
18245796c8dcSSimon Schubert 
18255796c8dcSSimon Schubert   un = (ULONGEST)n >> 2;
18265796c8dcSSimon Schubert   if (long_p == 0
18275796c8dcSSimon Schubert       && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
18285796c8dcSSimon Schubert     {
18295796c8dcSSimon Schubert       high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
18305796c8dcSSimon Schubert 
18315796c8dcSSimon Schubert       /* A large decimal (not hex or octal) constant (between INT_MAX
18325796c8dcSSimon Schubert 	 and UINT_MAX) is a long or unsigned long, according to ANSI,
18335796c8dcSSimon Schubert 	 never an unsigned int, but this code treats it as unsigned
18345796c8dcSSimon Schubert 	 int.  This probably should be fixed.  GCC gives a warning on
18355796c8dcSSimon Schubert 	 such constants.  */
18365796c8dcSSimon Schubert 
18375796c8dcSSimon Schubert       unsigned_type = parse_type->builtin_unsigned_int;
18385796c8dcSSimon Schubert       signed_type = parse_type->builtin_int;
18395796c8dcSSimon Schubert     }
18405796c8dcSSimon Schubert   else if (long_p <= 1
18415796c8dcSSimon Schubert 	   && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
18425796c8dcSSimon Schubert     {
18435796c8dcSSimon Schubert       high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
18445796c8dcSSimon Schubert       unsigned_type = parse_type->builtin_unsigned_long;
18455796c8dcSSimon Schubert       signed_type = parse_type->builtin_long;
18465796c8dcSSimon Schubert     }
18475796c8dcSSimon Schubert   else
18485796c8dcSSimon Schubert     {
18495796c8dcSSimon Schubert       int shift;
18505796c8dcSSimon Schubert       if (sizeof (ULONGEST) * HOST_CHAR_BIT
18515796c8dcSSimon Schubert 	  < gdbarch_long_long_bit (parse_gdbarch))
18525796c8dcSSimon Schubert 	/* A long long does not fit in a LONGEST.  */
18535796c8dcSSimon Schubert 	shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
18545796c8dcSSimon Schubert       else
18555796c8dcSSimon Schubert 	shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
18565796c8dcSSimon Schubert       high_bit = (ULONGEST) 1 << shift;
18575796c8dcSSimon Schubert       unsigned_type = parse_type->builtin_unsigned_long_long;
18585796c8dcSSimon Schubert       signed_type = parse_type->builtin_long_long;
18595796c8dcSSimon Schubert     }
18605796c8dcSSimon Schubert 
18615796c8dcSSimon Schubert    putithere->typed_val_int.val = n;
18625796c8dcSSimon Schubert 
18635796c8dcSSimon Schubert    /* If the high bit of the worked out type is set then this number
18645796c8dcSSimon Schubert       has to be unsigned. */
18655796c8dcSSimon Schubert 
18665796c8dcSSimon Schubert    if (unsigned_p || (n & high_bit))
18675796c8dcSSimon Schubert      {
18685796c8dcSSimon Schubert        putithere->typed_val_int.type = unsigned_type;
18695796c8dcSSimon Schubert      }
18705796c8dcSSimon Schubert    else
18715796c8dcSSimon Schubert      {
18725796c8dcSSimon Schubert        putithere->typed_val_int.type = signed_type;
18735796c8dcSSimon Schubert      }
18745796c8dcSSimon Schubert 
18755796c8dcSSimon Schubert    return INT;
18765796c8dcSSimon Schubert }
18775796c8dcSSimon Schubert 
18785796c8dcSSimon Schubert /* Temporary obstack used for holding strings.  */
18795796c8dcSSimon Schubert static struct obstack tempbuf;
18805796c8dcSSimon Schubert static int tempbuf_init;
18815796c8dcSSimon Schubert 
18825796c8dcSSimon Schubert /* Parse a C escape sequence.  The initial backslash of the sequence
18835796c8dcSSimon Schubert    is at (*PTR)[-1].  *PTR will be updated to point to just after the
18845796c8dcSSimon Schubert    last character of the sequence.  If OUTPUT is not NULL, the
18855796c8dcSSimon Schubert    translated form of the escape sequence will be written there.  If
18865796c8dcSSimon Schubert    OUTPUT is NULL, no output is written and the call will only affect
18875796c8dcSSimon Schubert    *PTR.  If an escape sequence is expressed in target bytes, then the
18885796c8dcSSimon Schubert    entire sequence will simply be copied to OUTPUT.  Return 1 if any
18895796c8dcSSimon Schubert    character was emitted, 0 otherwise.  */
18905796c8dcSSimon Schubert 
18915796c8dcSSimon Schubert int
c_parse_escape(char ** ptr,struct obstack * output)18925796c8dcSSimon Schubert c_parse_escape (char **ptr, struct obstack *output)
18935796c8dcSSimon Schubert {
18945796c8dcSSimon Schubert   char *tokptr = *ptr;
18955796c8dcSSimon Schubert   int result = 1;
18965796c8dcSSimon Schubert 
18975796c8dcSSimon Schubert   /* Some escape sequences undergo character set conversion.  Those we
18985796c8dcSSimon Schubert      translate here.  */
18995796c8dcSSimon Schubert   switch (*tokptr)
19005796c8dcSSimon Schubert     {
19015796c8dcSSimon Schubert       /* Hex escapes do not undergo character set conversion, so keep
19025796c8dcSSimon Schubert 	 the escape sequence for later.  */
19035796c8dcSSimon Schubert     case 'x':
19045796c8dcSSimon Schubert       if (output)
19055796c8dcSSimon Schubert 	obstack_grow_str (output, "\\x");
19065796c8dcSSimon Schubert       ++tokptr;
19075796c8dcSSimon Schubert       if (!isxdigit (*tokptr))
19085796c8dcSSimon Schubert 	error (_("\\x escape without a following hex digit"));
19095796c8dcSSimon Schubert       while (isxdigit (*tokptr))
19105796c8dcSSimon Schubert 	{
19115796c8dcSSimon Schubert 	  if (output)
19125796c8dcSSimon Schubert 	    obstack_1grow (output, *tokptr);
19135796c8dcSSimon Schubert 	  ++tokptr;
19145796c8dcSSimon Schubert 	}
19155796c8dcSSimon Schubert       break;
19165796c8dcSSimon Schubert 
19175796c8dcSSimon Schubert       /* Octal escapes do not undergo character set conversion, so
19185796c8dcSSimon Schubert 	 keep the escape sequence for later.  */
19195796c8dcSSimon Schubert     case '0':
19205796c8dcSSimon Schubert     case '1':
19215796c8dcSSimon Schubert     case '2':
19225796c8dcSSimon Schubert     case '3':
19235796c8dcSSimon Schubert     case '4':
19245796c8dcSSimon Schubert     case '5':
19255796c8dcSSimon Schubert     case '6':
19265796c8dcSSimon Schubert     case '7':
19275796c8dcSSimon Schubert       {
19285796c8dcSSimon Schubert 	int i;
19295796c8dcSSimon Schubert 	if (output)
19305796c8dcSSimon Schubert 	  obstack_grow_str (output, "\\");
19315796c8dcSSimon Schubert 	for (i = 0;
19325796c8dcSSimon Schubert 	     i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
19335796c8dcSSimon Schubert 	     ++i)
19345796c8dcSSimon Schubert 	  {
19355796c8dcSSimon Schubert 	    if (output)
19365796c8dcSSimon Schubert 	      obstack_1grow (output, *tokptr);
19375796c8dcSSimon Schubert 	    ++tokptr;
19385796c8dcSSimon Schubert 	  }
19395796c8dcSSimon Schubert       }
19405796c8dcSSimon Schubert       break;
19415796c8dcSSimon Schubert 
19425796c8dcSSimon Schubert       /* We handle UCNs later.  We could handle them here, but that
19435796c8dcSSimon Schubert 	 would mean a spurious error in the case where the UCN could
19445796c8dcSSimon Schubert 	 be converted to the target charset but not the host
19455796c8dcSSimon Schubert 	 charset.  */
19465796c8dcSSimon Schubert     case 'u':
19475796c8dcSSimon Schubert     case 'U':
19485796c8dcSSimon Schubert       {
19495796c8dcSSimon Schubert 	char c = *tokptr;
19505796c8dcSSimon Schubert 	int i, len = c == 'U' ? 8 : 4;
19515796c8dcSSimon Schubert 	if (output)
19525796c8dcSSimon Schubert 	  {
19535796c8dcSSimon Schubert 	    obstack_1grow (output, '\\');
19545796c8dcSSimon Schubert 	    obstack_1grow (output, *tokptr);
19555796c8dcSSimon Schubert 	  }
19565796c8dcSSimon Schubert 	++tokptr;
19575796c8dcSSimon Schubert 	if (!isxdigit (*tokptr))
19585796c8dcSSimon Schubert 	  error (_("\\%c escape without a following hex digit"), c);
19595796c8dcSSimon Schubert 	for (i = 0; i < len && isxdigit (*tokptr); ++i)
19605796c8dcSSimon Schubert 	  {
19615796c8dcSSimon Schubert 	    if (output)
19625796c8dcSSimon Schubert 	      obstack_1grow (output, *tokptr);
19635796c8dcSSimon Schubert 	    ++tokptr;
19645796c8dcSSimon Schubert 	  }
19655796c8dcSSimon Schubert       }
19665796c8dcSSimon Schubert       break;
19675796c8dcSSimon Schubert 
19685796c8dcSSimon Schubert       /* We must pass backslash through so that it does not
19695796c8dcSSimon Schubert 	 cause quoting during the second expansion.  */
19705796c8dcSSimon Schubert     case '\\':
19715796c8dcSSimon Schubert       if (output)
19725796c8dcSSimon Schubert 	obstack_grow_str (output, "\\\\");
19735796c8dcSSimon Schubert       ++tokptr;
19745796c8dcSSimon Schubert       break;
19755796c8dcSSimon Schubert 
19765796c8dcSSimon Schubert       /* Escapes which undergo conversion.  */
19775796c8dcSSimon Schubert     case 'a':
19785796c8dcSSimon Schubert       if (output)
19795796c8dcSSimon Schubert 	obstack_1grow (output, '\a');
19805796c8dcSSimon Schubert       ++tokptr;
19815796c8dcSSimon Schubert       break;
19825796c8dcSSimon Schubert     case 'b':
19835796c8dcSSimon Schubert       if (output)
19845796c8dcSSimon Schubert 	obstack_1grow (output, '\b');
19855796c8dcSSimon Schubert       ++tokptr;
19865796c8dcSSimon Schubert       break;
19875796c8dcSSimon Schubert     case 'f':
19885796c8dcSSimon Schubert       if (output)
19895796c8dcSSimon Schubert 	obstack_1grow (output, '\f');
19905796c8dcSSimon Schubert       ++tokptr;
19915796c8dcSSimon Schubert       break;
19925796c8dcSSimon Schubert     case 'n':
19935796c8dcSSimon Schubert       if (output)
19945796c8dcSSimon Schubert 	obstack_1grow (output, '\n');
19955796c8dcSSimon Schubert       ++tokptr;
19965796c8dcSSimon Schubert       break;
19975796c8dcSSimon Schubert     case 'r':
19985796c8dcSSimon Schubert       if (output)
19995796c8dcSSimon Schubert 	obstack_1grow (output, '\r');
20005796c8dcSSimon Schubert       ++tokptr;
20015796c8dcSSimon Schubert       break;
20025796c8dcSSimon Schubert     case 't':
20035796c8dcSSimon Schubert       if (output)
20045796c8dcSSimon Schubert 	obstack_1grow (output, '\t');
20055796c8dcSSimon Schubert       ++tokptr;
20065796c8dcSSimon Schubert       break;
20075796c8dcSSimon Schubert     case 'v':
20085796c8dcSSimon Schubert       if (output)
20095796c8dcSSimon Schubert 	obstack_1grow (output, '\v');
20105796c8dcSSimon Schubert       ++tokptr;
20115796c8dcSSimon Schubert       break;
20125796c8dcSSimon Schubert 
20135796c8dcSSimon Schubert       /* GCC extension.  */
20145796c8dcSSimon Schubert     case 'e':
20155796c8dcSSimon Schubert       if (output)
20165796c8dcSSimon Schubert 	obstack_1grow (output, HOST_ESCAPE_CHAR);
20175796c8dcSSimon Schubert       ++tokptr;
20185796c8dcSSimon Schubert       break;
20195796c8dcSSimon Schubert 
20205796c8dcSSimon Schubert       /* Backslash-newline expands to nothing at all.  */
20215796c8dcSSimon Schubert     case '\n':
20225796c8dcSSimon Schubert       ++tokptr;
20235796c8dcSSimon Schubert       result = 0;
20245796c8dcSSimon Schubert       break;
20255796c8dcSSimon Schubert 
20265796c8dcSSimon Schubert       /* A few escapes just expand to the character itself.  */
20275796c8dcSSimon Schubert     case '\'':
20285796c8dcSSimon Schubert     case '\"':
20295796c8dcSSimon Schubert     case '?':
20305796c8dcSSimon Schubert       /* GCC extensions.  */
20315796c8dcSSimon Schubert     case '(':
20325796c8dcSSimon Schubert     case '{':
20335796c8dcSSimon Schubert     case '[':
20345796c8dcSSimon Schubert     case '%':
20355796c8dcSSimon Schubert       /* Unrecognized escapes turn into the character itself.  */
20365796c8dcSSimon Schubert     default:
20375796c8dcSSimon Schubert       if (output)
20385796c8dcSSimon Schubert 	obstack_1grow (output, *tokptr);
20395796c8dcSSimon Schubert       ++tokptr;
20405796c8dcSSimon Schubert       break;
20415796c8dcSSimon Schubert     }
20425796c8dcSSimon Schubert   *ptr = tokptr;
20435796c8dcSSimon Schubert   return result;
20445796c8dcSSimon Schubert }
20455796c8dcSSimon Schubert 
20465796c8dcSSimon Schubert /* Parse a string or character literal from TOKPTR.  The string or
20475796c8dcSSimon Schubert    character may be wide or unicode.  *OUTPTR is set to just after the
20485796c8dcSSimon Schubert    end of the literal in the input string.  The resulting token is
20495796c8dcSSimon Schubert    stored in VALUE.  This returns a token value, either STRING or
20505796c8dcSSimon Schubert    CHAR, depending on what was parsed.  *HOST_CHARS is set to the
20515796c8dcSSimon Schubert    number of host characters in the literal.  */
20525796c8dcSSimon Schubert static int
parse_string_or_char(char * tokptr,char ** outptr,struct typed_stoken * value,int * host_chars)20535796c8dcSSimon Schubert parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
20545796c8dcSSimon Schubert 		      int *host_chars)
20555796c8dcSSimon Schubert {
2056cf7f2e2dSJohn Marino   int quote;
20575796c8dcSSimon Schubert   enum c_string_type type;
2058*ef5ccd6cSJohn Marino   int is_objc = 0;
20595796c8dcSSimon Schubert 
20605796c8dcSSimon Schubert   /* Build the gdb internal form of the input string in tempbuf.  Note
20615796c8dcSSimon Schubert      that the buffer is null byte terminated *only* for the
20625796c8dcSSimon Schubert      convenience of debugging gdb itself and printing the buffer
20635796c8dcSSimon Schubert      contents when the buffer contains no embedded nulls.  Gdb does
20645796c8dcSSimon Schubert      not depend upon the buffer being null byte terminated, it uses
20655796c8dcSSimon Schubert      the length string instead.  This allows gdb to handle C strings
20665796c8dcSSimon Schubert      (as well as strings in other languages) with embedded null
20675796c8dcSSimon Schubert      bytes */
20685796c8dcSSimon Schubert 
20695796c8dcSSimon Schubert   if (!tempbuf_init)
20705796c8dcSSimon Schubert     tempbuf_init = 1;
20715796c8dcSSimon Schubert   else
20725796c8dcSSimon Schubert     obstack_free (&tempbuf, NULL);
20735796c8dcSSimon Schubert   obstack_init (&tempbuf);
20745796c8dcSSimon Schubert 
20755796c8dcSSimon Schubert   /* Record the string type.  */
20765796c8dcSSimon Schubert   if (*tokptr == 'L')
20775796c8dcSSimon Schubert     {
20785796c8dcSSimon Schubert       type = C_WIDE_STRING;
20795796c8dcSSimon Schubert       ++tokptr;
20805796c8dcSSimon Schubert     }
20815796c8dcSSimon Schubert   else if (*tokptr == 'u')
20825796c8dcSSimon Schubert     {
20835796c8dcSSimon Schubert       type = C_STRING_16;
20845796c8dcSSimon Schubert       ++tokptr;
20855796c8dcSSimon Schubert     }
20865796c8dcSSimon Schubert   else if (*tokptr == 'U')
20875796c8dcSSimon Schubert     {
20885796c8dcSSimon Schubert       type = C_STRING_32;
20895796c8dcSSimon Schubert       ++tokptr;
20905796c8dcSSimon Schubert     }
2091*ef5ccd6cSJohn Marino   else if (*tokptr == '@')
2092*ef5ccd6cSJohn Marino     {
2093*ef5ccd6cSJohn Marino       /* An Objective C string.  */
2094*ef5ccd6cSJohn Marino       is_objc = 1;
2095*ef5ccd6cSJohn Marino       type = C_STRING;
2096*ef5ccd6cSJohn Marino       ++tokptr;
2097*ef5ccd6cSJohn Marino     }
20985796c8dcSSimon Schubert   else
20995796c8dcSSimon Schubert     type = C_STRING;
21005796c8dcSSimon Schubert 
21015796c8dcSSimon Schubert   /* Skip the quote.  */
21025796c8dcSSimon Schubert   quote = *tokptr;
21035796c8dcSSimon Schubert   if (quote == '\'')
21045796c8dcSSimon Schubert     type |= C_CHAR;
21055796c8dcSSimon Schubert   ++tokptr;
21065796c8dcSSimon Schubert 
21075796c8dcSSimon Schubert   *host_chars = 0;
21085796c8dcSSimon Schubert 
21095796c8dcSSimon Schubert   while (*tokptr)
21105796c8dcSSimon Schubert     {
21115796c8dcSSimon Schubert       char c = *tokptr;
21125796c8dcSSimon Schubert       if (c == '\\')
21135796c8dcSSimon Schubert 	{
21145796c8dcSSimon Schubert 	  ++tokptr;
21155796c8dcSSimon Schubert 	  *host_chars += c_parse_escape (&tokptr, &tempbuf);
21165796c8dcSSimon Schubert 	}
21175796c8dcSSimon Schubert       else if (c == quote)
21185796c8dcSSimon Schubert 	break;
21195796c8dcSSimon Schubert       else
21205796c8dcSSimon Schubert 	{
21215796c8dcSSimon Schubert 	  obstack_1grow (&tempbuf, c);
21225796c8dcSSimon Schubert 	  ++tokptr;
21235796c8dcSSimon Schubert 	  /* FIXME: this does the wrong thing with multi-byte host
21245796c8dcSSimon Schubert 	     characters.  We could use mbrlen here, but that would
21255796c8dcSSimon Schubert 	     make "set host-charset" a bit less useful.  */
21265796c8dcSSimon Schubert 	  ++*host_chars;
21275796c8dcSSimon Schubert 	}
21285796c8dcSSimon Schubert     }
21295796c8dcSSimon Schubert 
21305796c8dcSSimon Schubert   if (*tokptr != quote)
21315796c8dcSSimon Schubert     {
21325796c8dcSSimon Schubert       if (quote == '"')
2133c50c785cSJohn Marino 	error (_("Unterminated string in expression."));
21345796c8dcSSimon Schubert       else
2135c50c785cSJohn Marino 	error (_("Unmatched single quote."));
21365796c8dcSSimon Schubert     }
21375796c8dcSSimon Schubert   ++tokptr;
21385796c8dcSSimon Schubert 
21395796c8dcSSimon Schubert   value->type = type;
21405796c8dcSSimon Schubert   value->ptr = obstack_base (&tempbuf);
21415796c8dcSSimon Schubert   value->length = obstack_object_size (&tempbuf);
21425796c8dcSSimon Schubert 
21435796c8dcSSimon Schubert   *outptr = tokptr;
21445796c8dcSSimon Schubert 
2145*ef5ccd6cSJohn Marino   return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR;
21465796c8dcSSimon Schubert }
21475796c8dcSSimon Schubert 
2148*ef5ccd6cSJohn Marino /* This is used to associate some attributes with a token.  */
2149*ef5ccd6cSJohn Marino 
2150*ef5ccd6cSJohn Marino enum token_flags
2151*ef5ccd6cSJohn Marino {
2152*ef5ccd6cSJohn Marino   /* If this bit is set, the token is C++-only.  */
2153*ef5ccd6cSJohn Marino 
2154*ef5ccd6cSJohn Marino   FLAG_CXX = 1,
2155*ef5ccd6cSJohn Marino 
2156*ef5ccd6cSJohn Marino   /* If this bit is set, the token is conditional: if there is a
2157*ef5ccd6cSJohn Marino      symbol of the same name, then the token is a symbol; otherwise,
2158*ef5ccd6cSJohn Marino      the token is a keyword.  */
2159*ef5ccd6cSJohn Marino 
2160*ef5ccd6cSJohn Marino   FLAG_SHADOW = 2
2161*ef5ccd6cSJohn Marino };
2162*ef5ccd6cSJohn Marino 
21635796c8dcSSimon Schubert struct token
21645796c8dcSSimon Schubert {
21655796c8dcSSimon Schubert   char *operator;
21665796c8dcSSimon Schubert   int token;
21675796c8dcSSimon Schubert   enum exp_opcode opcode;
2168*ef5ccd6cSJohn Marino   enum token_flags flags;
21695796c8dcSSimon Schubert };
21705796c8dcSSimon Schubert 
21715796c8dcSSimon Schubert static const struct token tokentab3[] =
21725796c8dcSSimon Schubert   {
21735796c8dcSSimon Schubert     {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
21745796c8dcSSimon Schubert     {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
2175*ef5ccd6cSJohn Marino     {"->*", ARROW_STAR, BINOP_END, FLAG_CXX},
2176*ef5ccd6cSJohn Marino     {"...", DOTDOTDOT, BINOP_END, 0}
21775796c8dcSSimon Schubert   };
21785796c8dcSSimon Schubert 
21795796c8dcSSimon Schubert static const struct token tokentab2[] =
21805796c8dcSSimon Schubert   {
21815796c8dcSSimon Schubert     {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
21825796c8dcSSimon Schubert     {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
21835796c8dcSSimon Schubert     {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
21845796c8dcSSimon Schubert     {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
21855796c8dcSSimon Schubert     {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
21865796c8dcSSimon Schubert     {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
21875796c8dcSSimon Schubert     {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
21885796c8dcSSimon Schubert     {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
21895796c8dcSSimon Schubert     {"++", INCREMENT, BINOP_END, 0},
21905796c8dcSSimon Schubert     {"--", DECREMENT, BINOP_END, 0},
21915796c8dcSSimon Schubert     {"->", ARROW, BINOP_END, 0},
21925796c8dcSSimon Schubert     {"&&", ANDAND, BINOP_END, 0},
21935796c8dcSSimon Schubert     {"||", OROR, BINOP_END, 0},
21945796c8dcSSimon Schubert     /* "::" is *not* only C++: gdb overrides its meaning in several
21955796c8dcSSimon Schubert        different ways, e.g., 'filename'::func, function::variable.  */
21965796c8dcSSimon Schubert     {"::", COLONCOLON, BINOP_END, 0},
21975796c8dcSSimon Schubert     {"<<", LSH, BINOP_END, 0},
21985796c8dcSSimon Schubert     {">>", RSH, BINOP_END, 0},
21995796c8dcSSimon Schubert     {"==", EQUAL, BINOP_END, 0},
22005796c8dcSSimon Schubert     {"!=", NOTEQUAL, BINOP_END, 0},
22015796c8dcSSimon Schubert     {"<=", LEQ, BINOP_END, 0},
22025796c8dcSSimon Schubert     {">=", GEQ, BINOP_END, 0},
2203*ef5ccd6cSJohn Marino     {".*", DOT_STAR, BINOP_END, FLAG_CXX}
22045796c8dcSSimon Schubert   };
22055796c8dcSSimon Schubert 
22065796c8dcSSimon Schubert /* Identifier-like tokens.  */
22075796c8dcSSimon Schubert static const struct token ident_tokens[] =
22085796c8dcSSimon Schubert   {
22095796c8dcSSimon Schubert     {"unsigned", UNSIGNED, OP_NULL, 0},
2210*ef5ccd6cSJohn Marino     {"template", TEMPLATE, OP_NULL, FLAG_CXX},
22115796c8dcSSimon Schubert     {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
22125796c8dcSSimon Schubert     {"struct", STRUCT, OP_NULL, 0},
22135796c8dcSSimon Schubert     {"signed", SIGNED_KEYWORD, OP_NULL, 0},
22145796c8dcSSimon Schubert     {"sizeof", SIZEOF, OP_NULL, 0},
22155796c8dcSSimon Schubert     {"double", DOUBLE_KEYWORD, OP_NULL, 0},
2216*ef5ccd6cSJohn Marino     {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
2217*ef5ccd6cSJohn Marino     {"class", CLASS, OP_NULL, FLAG_CXX},
22185796c8dcSSimon Schubert     {"union", UNION, OP_NULL, 0},
22195796c8dcSSimon Schubert     {"short", SHORT, OP_NULL, 0},
22205796c8dcSSimon Schubert     {"const", CONST_KEYWORD, OP_NULL, 0},
22215796c8dcSSimon Schubert     {"enum", ENUM, OP_NULL, 0},
22225796c8dcSSimon Schubert     {"long", LONG, OP_NULL, 0},
2223*ef5ccd6cSJohn Marino     {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
22245796c8dcSSimon Schubert     {"int", INT_KEYWORD, OP_NULL, 0},
2225*ef5ccd6cSJohn Marino     {"new", NEW, OP_NULL, FLAG_CXX},
2226*ef5ccd6cSJohn Marino     {"delete", DELETE, OP_NULL, FLAG_CXX},
2227*ef5ccd6cSJohn Marino     {"operator", OPERATOR, OP_NULL, FLAG_CXX},
22285796c8dcSSimon Schubert 
2229*ef5ccd6cSJohn Marino     {"and", ANDAND, BINOP_END, FLAG_CXX},
2230*ef5ccd6cSJohn Marino     {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
2231*ef5ccd6cSJohn Marino     {"bitand", '&', OP_NULL, FLAG_CXX},
2232*ef5ccd6cSJohn Marino     {"bitor", '|', OP_NULL, FLAG_CXX},
2233*ef5ccd6cSJohn Marino     {"compl", '~', OP_NULL, FLAG_CXX},
2234*ef5ccd6cSJohn Marino     {"not", '!', OP_NULL, FLAG_CXX},
2235*ef5ccd6cSJohn Marino     {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX},
2236*ef5ccd6cSJohn Marino     {"or", OROR, BINOP_END, FLAG_CXX},
2237*ef5ccd6cSJohn Marino     {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX},
2238*ef5ccd6cSJohn Marino     {"xor", '^', OP_NULL, FLAG_CXX},
2239*ef5ccd6cSJohn Marino     {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX},
2240cf7f2e2dSJohn Marino 
2241*ef5ccd6cSJohn Marino     {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX },
2242*ef5ccd6cSJohn Marino     {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX },
2243*ef5ccd6cSJohn Marino     {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX },
2244*ef5ccd6cSJohn Marino     {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX },
2245*ef5ccd6cSJohn Marino 
2246*ef5ccd6cSJohn Marino     {"__typeof__", TYPEOF, OP_TYPEOF, 0 },
2247*ef5ccd6cSJohn Marino     {"__typeof", TYPEOF, OP_TYPEOF, 0 },
2248*ef5ccd6cSJohn Marino     {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW },
2249*ef5ccd6cSJohn Marino     {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX },
2250*ef5ccd6cSJohn Marino     {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW }
22515796c8dcSSimon Schubert   };
22525796c8dcSSimon Schubert 
22535796c8dcSSimon Schubert /* When we find that lexptr (the global var defined in parse.c) is
22545796c8dcSSimon Schubert    pointing at a macro invocation, we expand the invocation, and call
22555796c8dcSSimon Schubert    scan_macro_expansion to save the old lexptr here and point lexptr
22565796c8dcSSimon Schubert    into the expanded text.  When we reach the end of that, we call
22575796c8dcSSimon Schubert    end_macro_expansion to pop back to the value we saved here.  The
22585796c8dcSSimon Schubert    macro expansion code promises to return only fully-expanded text,
22595796c8dcSSimon Schubert    so we don't need to "push" more than one level.
22605796c8dcSSimon Schubert 
22615796c8dcSSimon Schubert    This is disgusting, of course.  It would be cleaner to do all macro
22625796c8dcSSimon Schubert    expansion beforehand, and then hand that to lexptr.  But we don't
22635796c8dcSSimon Schubert    really know where the expression ends.  Remember, in a command like
22645796c8dcSSimon Schubert 
22655796c8dcSSimon Schubert      (gdb) break *ADDRESS if CONDITION
22665796c8dcSSimon Schubert 
22675796c8dcSSimon Schubert    we evaluate ADDRESS in the scope of the current frame, but we
22685796c8dcSSimon Schubert    evaluate CONDITION in the scope of the breakpoint's location.  So
22695796c8dcSSimon Schubert    it's simply wrong to try to macro-expand the whole thing at once.  */
22705796c8dcSSimon Schubert static char *macro_original_text;
22715796c8dcSSimon Schubert 
22725796c8dcSSimon Schubert /* We save all intermediate macro expansions on this obstack for the
22735796c8dcSSimon Schubert    duration of a single parse.  The expansion text may sometimes have
22745796c8dcSSimon Schubert    to live past the end of the expansion, due to yacc lookahead.
22755796c8dcSSimon Schubert    Rather than try to be clever about saving the data for a single
22765796c8dcSSimon Schubert    token, we simply keep it all and delete it after parsing has
22775796c8dcSSimon Schubert    completed.  */
22785796c8dcSSimon Schubert static struct obstack expansion_obstack;
22795796c8dcSSimon Schubert 
22805796c8dcSSimon Schubert static void
scan_macro_expansion(char * expansion)22815796c8dcSSimon Schubert scan_macro_expansion (char *expansion)
22825796c8dcSSimon Schubert {
22835796c8dcSSimon Schubert   char *copy;
22845796c8dcSSimon Schubert 
22855796c8dcSSimon Schubert   /* We'd better not be trying to push the stack twice.  */
22865796c8dcSSimon Schubert   gdb_assert (! macro_original_text);
22875796c8dcSSimon Schubert 
22885796c8dcSSimon Schubert   /* Copy to the obstack, and then free the intermediate
22895796c8dcSSimon Schubert      expansion.  */
22905796c8dcSSimon Schubert   copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
22915796c8dcSSimon Schubert   xfree (expansion);
22925796c8dcSSimon Schubert 
22935796c8dcSSimon Schubert   /* Save the old lexptr value, so we can return to it when we're done
22945796c8dcSSimon Schubert      parsing the expanded text.  */
22955796c8dcSSimon Schubert   macro_original_text = lexptr;
22965796c8dcSSimon Schubert   lexptr = copy;
22975796c8dcSSimon Schubert }
22985796c8dcSSimon Schubert 
22995796c8dcSSimon Schubert 
23005796c8dcSSimon Schubert static int
scanning_macro_expansion(void)23015796c8dcSSimon Schubert scanning_macro_expansion (void)
23025796c8dcSSimon Schubert {
23035796c8dcSSimon Schubert   return macro_original_text != 0;
23045796c8dcSSimon Schubert }
23055796c8dcSSimon Schubert 
23065796c8dcSSimon Schubert 
23075796c8dcSSimon Schubert static void
finished_macro_expansion(void)23085796c8dcSSimon Schubert finished_macro_expansion (void)
23095796c8dcSSimon Schubert {
23105796c8dcSSimon Schubert   /* There'd better be something to pop back to.  */
23115796c8dcSSimon Schubert   gdb_assert (macro_original_text);
23125796c8dcSSimon Schubert 
23135796c8dcSSimon Schubert   /* Pop back to the original text.  */
23145796c8dcSSimon Schubert   lexptr = macro_original_text;
23155796c8dcSSimon Schubert   macro_original_text = 0;
23165796c8dcSSimon Schubert }
23175796c8dcSSimon Schubert 
23185796c8dcSSimon Schubert 
23195796c8dcSSimon Schubert static void
scan_macro_cleanup(void * dummy)23205796c8dcSSimon Schubert scan_macro_cleanup (void *dummy)
23215796c8dcSSimon Schubert {
23225796c8dcSSimon Schubert   if (macro_original_text)
23235796c8dcSSimon Schubert     finished_macro_expansion ();
23245796c8dcSSimon Schubert 
23255796c8dcSSimon Schubert   obstack_free (&expansion_obstack, NULL);
23265796c8dcSSimon Schubert }
23275796c8dcSSimon Schubert 
2328cf7f2e2dSJohn Marino /* Return true iff the token represents a C++ cast operator.  */
2329cf7f2e2dSJohn Marino 
2330cf7f2e2dSJohn Marino static int
is_cast_operator(const char * token,int len)2331cf7f2e2dSJohn Marino is_cast_operator (const char *token, int len)
2332cf7f2e2dSJohn Marino {
2333cf7f2e2dSJohn Marino   return (! strncmp (token, "dynamic_cast", len)
2334cf7f2e2dSJohn Marino 	  || ! strncmp (token, "static_cast", len)
2335cf7f2e2dSJohn Marino 	  || ! strncmp (token, "reinterpret_cast", len)
2336cf7f2e2dSJohn Marino 	  || ! strncmp (token, "const_cast", len));
2337cf7f2e2dSJohn Marino }
23385796c8dcSSimon Schubert 
23395796c8dcSSimon Schubert /* The scope used for macro expansion.  */
23405796c8dcSSimon Schubert static struct macro_scope *expression_macro_scope;
23415796c8dcSSimon Schubert 
23425796c8dcSSimon Schubert /* This is set if a NAME token appeared at the very end of the input
23435796c8dcSSimon Schubert    string, with no whitespace separating the name from the EOF.  This
23445796c8dcSSimon Schubert    is used only when parsing to do field name completion.  */
23455796c8dcSSimon Schubert static int saw_name_at_eof;
23465796c8dcSSimon Schubert 
23475796c8dcSSimon Schubert /* This is set if the previously-returned token was a structure
23485796c8dcSSimon Schubert    operator -- either '.' or ARROW.  This is used only when parsing to
23495796c8dcSSimon Schubert    do field name completion.  */
23505796c8dcSSimon Schubert static int last_was_structop;
23515796c8dcSSimon Schubert 
23525796c8dcSSimon Schubert /* Read one token, getting characters through lexptr.  */
23535796c8dcSSimon Schubert 
23545796c8dcSSimon Schubert static int
lex_one_token(void)2355cf7f2e2dSJohn Marino lex_one_token (void)
23565796c8dcSSimon Schubert {
23575796c8dcSSimon Schubert   int c;
23585796c8dcSSimon Schubert   int namelen;
23595796c8dcSSimon Schubert   unsigned int i;
23605796c8dcSSimon Schubert   char *tokstart;
23615796c8dcSSimon Schubert   int saw_structop = last_was_structop;
23625796c8dcSSimon Schubert   char *copy;
23635796c8dcSSimon Schubert 
23645796c8dcSSimon Schubert   last_was_structop = 0;
23655796c8dcSSimon Schubert 
23665796c8dcSSimon Schubert  retry:
23675796c8dcSSimon Schubert 
23685796c8dcSSimon Schubert   /* Check if this is a macro invocation that we need to expand.  */
23695796c8dcSSimon Schubert   if (! scanning_macro_expansion ())
23705796c8dcSSimon Schubert     {
23715796c8dcSSimon Schubert       char *expanded = macro_expand_next (&lexptr,
23725796c8dcSSimon Schubert                                           standard_macro_lookup,
23735796c8dcSSimon Schubert                                           expression_macro_scope);
23745796c8dcSSimon Schubert 
23755796c8dcSSimon Schubert       if (expanded)
23765796c8dcSSimon Schubert         scan_macro_expansion (expanded);
23775796c8dcSSimon Schubert     }
23785796c8dcSSimon Schubert 
23795796c8dcSSimon Schubert   prev_lexptr = lexptr;
23805796c8dcSSimon Schubert 
23815796c8dcSSimon Schubert   tokstart = lexptr;
23825796c8dcSSimon Schubert   /* See if it is a special token of length 3.  */
23835796c8dcSSimon Schubert   for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
23845796c8dcSSimon Schubert     if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
23855796c8dcSSimon Schubert       {
2386*ef5ccd6cSJohn Marino 	if ((tokentab3[i].flags & FLAG_CXX) != 0
23875796c8dcSSimon Schubert 	    && parse_language->la_language != language_cplus)
23885796c8dcSSimon Schubert 	  break;
23895796c8dcSSimon Schubert 
23905796c8dcSSimon Schubert 	lexptr += 3;
23915796c8dcSSimon Schubert 	yylval.opcode = tokentab3[i].opcode;
23925796c8dcSSimon Schubert 	return tokentab3[i].token;
23935796c8dcSSimon Schubert       }
23945796c8dcSSimon Schubert 
23955796c8dcSSimon Schubert   /* See if it is a special token of length 2.  */
23965796c8dcSSimon Schubert   for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
23975796c8dcSSimon Schubert     if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
23985796c8dcSSimon Schubert       {
2399*ef5ccd6cSJohn Marino 	if ((tokentab2[i].flags & FLAG_CXX) != 0
24005796c8dcSSimon Schubert 	    && parse_language->la_language != language_cplus)
24015796c8dcSSimon Schubert 	  break;
24025796c8dcSSimon Schubert 
24035796c8dcSSimon Schubert 	lexptr += 2;
24045796c8dcSSimon Schubert 	yylval.opcode = tokentab2[i].opcode;
2405*ef5ccd6cSJohn Marino 	if (parse_completion && tokentab2[i].token == ARROW)
24065796c8dcSSimon Schubert 	  last_was_structop = 1;
24075796c8dcSSimon Schubert 	return tokentab2[i].token;
24085796c8dcSSimon Schubert       }
24095796c8dcSSimon Schubert 
24105796c8dcSSimon Schubert   switch (c = *tokstart)
24115796c8dcSSimon Schubert     {
24125796c8dcSSimon Schubert     case 0:
24135796c8dcSSimon Schubert       /* If we were just scanning the result of a macro expansion,
24145796c8dcSSimon Schubert          then we need to resume scanning the original text.
24155796c8dcSSimon Schubert 	 If we're parsing for field name completion, and the previous
24165796c8dcSSimon Schubert 	 token allows such completion, return a COMPLETE token.
24175796c8dcSSimon Schubert          Otherwise, we were already scanning the original text, and
24185796c8dcSSimon Schubert          we're really done.  */
24195796c8dcSSimon Schubert       if (scanning_macro_expansion ())
24205796c8dcSSimon Schubert         {
24215796c8dcSSimon Schubert           finished_macro_expansion ();
24225796c8dcSSimon Schubert           goto retry;
24235796c8dcSSimon Schubert         }
24245796c8dcSSimon Schubert       else if (saw_name_at_eof)
24255796c8dcSSimon Schubert 	{
24265796c8dcSSimon Schubert 	  saw_name_at_eof = 0;
24275796c8dcSSimon Schubert 	  return COMPLETE;
24285796c8dcSSimon Schubert 	}
24295796c8dcSSimon Schubert       else if (saw_structop)
24305796c8dcSSimon Schubert 	return COMPLETE;
24315796c8dcSSimon Schubert       else
24325796c8dcSSimon Schubert         return 0;
24335796c8dcSSimon Schubert 
24345796c8dcSSimon Schubert     case ' ':
24355796c8dcSSimon Schubert     case '\t':
24365796c8dcSSimon Schubert     case '\n':
24375796c8dcSSimon Schubert       lexptr++;
24385796c8dcSSimon Schubert       goto retry;
24395796c8dcSSimon Schubert 
24405796c8dcSSimon Schubert     case '[':
24415796c8dcSSimon Schubert     case '(':
24425796c8dcSSimon Schubert       paren_depth++;
24435796c8dcSSimon Schubert       lexptr++;
2444*ef5ccd6cSJohn Marino       if (parse_language->la_language == language_objc && c == '[')
2445*ef5ccd6cSJohn Marino 	return OBJC_LBRAC;
24465796c8dcSSimon Schubert       return c;
24475796c8dcSSimon Schubert 
24485796c8dcSSimon Schubert     case ']':
24495796c8dcSSimon Schubert     case ')':
24505796c8dcSSimon Schubert       if (paren_depth == 0)
24515796c8dcSSimon Schubert 	return 0;
24525796c8dcSSimon Schubert       paren_depth--;
24535796c8dcSSimon Schubert       lexptr++;
24545796c8dcSSimon Schubert       return c;
24555796c8dcSSimon Schubert 
24565796c8dcSSimon Schubert     case ',':
24575796c8dcSSimon Schubert       if (comma_terminates
24585796c8dcSSimon Schubert           && paren_depth == 0
24595796c8dcSSimon Schubert           && ! scanning_macro_expansion ())
24605796c8dcSSimon Schubert 	return 0;
24615796c8dcSSimon Schubert       lexptr++;
24625796c8dcSSimon Schubert       return c;
24635796c8dcSSimon Schubert 
24645796c8dcSSimon Schubert     case '.':
24655796c8dcSSimon Schubert       /* Might be a floating point number.  */
24665796c8dcSSimon Schubert       if (lexptr[1] < '0' || lexptr[1] > '9')
24675796c8dcSSimon Schubert 	{
2468*ef5ccd6cSJohn Marino 	  if (parse_completion)
24695796c8dcSSimon Schubert 	    last_was_structop = 1;
24705796c8dcSSimon Schubert 	  goto symbol;		/* Nope, must be a symbol. */
24715796c8dcSSimon Schubert 	}
24725796c8dcSSimon Schubert       /* FALL THRU into number case.  */
24735796c8dcSSimon Schubert 
24745796c8dcSSimon Schubert     case '0':
24755796c8dcSSimon Schubert     case '1':
24765796c8dcSSimon Schubert     case '2':
24775796c8dcSSimon Schubert     case '3':
24785796c8dcSSimon Schubert     case '4':
24795796c8dcSSimon Schubert     case '5':
24805796c8dcSSimon Schubert     case '6':
24815796c8dcSSimon Schubert     case '7':
24825796c8dcSSimon Schubert     case '8':
24835796c8dcSSimon Schubert     case '9':
24845796c8dcSSimon Schubert       {
24855796c8dcSSimon Schubert 	/* It's a number.  */
24865796c8dcSSimon Schubert 	int got_dot = 0, got_e = 0, toktype;
24875796c8dcSSimon Schubert 	char *p = tokstart;
24885796c8dcSSimon Schubert 	int hex = input_radix > 10;
24895796c8dcSSimon Schubert 
24905796c8dcSSimon Schubert 	if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
24915796c8dcSSimon Schubert 	  {
24925796c8dcSSimon Schubert 	    p += 2;
24935796c8dcSSimon Schubert 	    hex = 1;
24945796c8dcSSimon Schubert 	  }
24955796c8dcSSimon Schubert 	else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
24965796c8dcSSimon Schubert 	  {
24975796c8dcSSimon Schubert 	    p += 2;
24985796c8dcSSimon Schubert 	    hex = 0;
24995796c8dcSSimon Schubert 	  }
25005796c8dcSSimon Schubert 
25015796c8dcSSimon Schubert 	for (;; ++p)
25025796c8dcSSimon Schubert 	  {
25035796c8dcSSimon Schubert 	    /* This test includes !hex because 'e' is a valid hex digit
25045796c8dcSSimon Schubert 	       and thus does not indicate a floating point number when
25055796c8dcSSimon Schubert 	       the radix is hex.  */
25065796c8dcSSimon Schubert 	    if (!hex && !got_e && (*p == 'e' || *p == 'E'))
25075796c8dcSSimon Schubert 	      got_dot = got_e = 1;
25085796c8dcSSimon Schubert 	    /* This test does not include !hex, because a '.' always indicates
25095796c8dcSSimon Schubert 	       a decimal floating point number regardless of the radix.  */
25105796c8dcSSimon Schubert 	    else if (!got_dot && *p == '.')
25115796c8dcSSimon Schubert 	      got_dot = 1;
25125796c8dcSSimon Schubert 	    else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
25135796c8dcSSimon Schubert 		     && (*p == '-' || *p == '+'))
25145796c8dcSSimon Schubert 	      /* This is the sign of the exponent, not the end of the
25155796c8dcSSimon Schubert 		 number.  */
25165796c8dcSSimon Schubert 	      continue;
25175796c8dcSSimon Schubert 	    /* We will take any letters or digits.  parse_number will
25185796c8dcSSimon Schubert 	       complain if past the radix, or if L or U are not final.  */
25195796c8dcSSimon Schubert 	    else if ((*p < '0' || *p > '9')
25205796c8dcSSimon Schubert 		     && ((*p < 'a' || *p > 'z')
25215796c8dcSSimon Schubert 				  && (*p < 'A' || *p > 'Z')))
25225796c8dcSSimon Schubert 	      break;
25235796c8dcSSimon Schubert 	  }
25245796c8dcSSimon Schubert 	toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
25255796c8dcSSimon Schubert         if (toktype == ERROR)
25265796c8dcSSimon Schubert 	  {
25275796c8dcSSimon Schubert 	    char *err_copy = (char *) alloca (p - tokstart + 1);
25285796c8dcSSimon Schubert 
25295796c8dcSSimon Schubert 	    memcpy (err_copy, tokstart, p - tokstart);
25305796c8dcSSimon Schubert 	    err_copy[p - tokstart] = 0;
2531c50c785cSJohn Marino 	    error (_("Invalid number \"%s\"."), err_copy);
25325796c8dcSSimon Schubert 	  }
25335796c8dcSSimon Schubert 	lexptr = p;
25345796c8dcSSimon Schubert 	return toktype;
25355796c8dcSSimon Schubert       }
25365796c8dcSSimon Schubert 
2537a45ae5f8SJohn Marino     case '@':
2538a45ae5f8SJohn Marino       {
2539a45ae5f8SJohn Marino 	char *p = &tokstart[1];
2540a45ae5f8SJohn Marino 	size_t len = strlen ("entry");
2541a45ae5f8SJohn Marino 
2542*ef5ccd6cSJohn Marino 	if (parse_language->la_language == language_objc)
2543*ef5ccd6cSJohn Marino 	  {
2544*ef5ccd6cSJohn Marino 	    size_t len = strlen ("selector");
2545*ef5ccd6cSJohn Marino 
2546*ef5ccd6cSJohn Marino 	    if (strncmp (p, "selector", len) == 0
2547*ef5ccd6cSJohn Marino 		&& (p[len] == '\0' || isspace (p[len])))
2548*ef5ccd6cSJohn Marino 	      {
2549*ef5ccd6cSJohn Marino 		lexptr = p + len;
2550*ef5ccd6cSJohn Marino 		return SELECTOR;
2551*ef5ccd6cSJohn Marino 	      }
2552*ef5ccd6cSJohn Marino 	    else if (*p == '"')
2553*ef5ccd6cSJohn Marino 	      goto parse_string;
2554*ef5ccd6cSJohn Marino 	  }
2555*ef5ccd6cSJohn Marino 
2556a45ae5f8SJohn Marino 	while (isspace (*p))
2557a45ae5f8SJohn Marino 	  p++;
2558a45ae5f8SJohn Marino 	if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
2559a45ae5f8SJohn Marino 	    && p[len] != '_')
2560a45ae5f8SJohn Marino 	  {
2561a45ae5f8SJohn Marino 	    lexptr = &p[len];
2562a45ae5f8SJohn Marino 	    return ENTRY;
2563a45ae5f8SJohn Marino 	  }
2564a45ae5f8SJohn Marino       }
2565a45ae5f8SJohn Marino       /* FALLTHRU */
25665796c8dcSSimon Schubert     case '+':
25675796c8dcSSimon Schubert     case '-':
25685796c8dcSSimon Schubert     case '*':
25695796c8dcSSimon Schubert     case '/':
25705796c8dcSSimon Schubert     case '%':
25715796c8dcSSimon Schubert     case '|':
25725796c8dcSSimon Schubert     case '&':
25735796c8dcSSimon Schubert     case '^':
25745796c8dcSSimon Schubert     case '~':
25755796c8dcSSimon Schubert     case '!':
25765796c8dcSSimon Schubert     case '<':
25775796c8dcSSimon Schubert     case '>':
25785796c8dcSSimon Schubert     case '?':
25795796c8dcSSimon Schubert     case ':':
25805796c8dcSSimon Schubert     case '=':
25815796c8dcSSimon Schubert     case '{':
25825796c8dcSSimon Schubert     case '}':
25835796c8dcSSimon Schubert     symbol:
25845796c8dcSSimon Schubert       lexptr++;
25855796c8dcSSimon Schubert       return c;
25865796c8dcSSimon Schubert 
25875796c8dcSSimon Schubert     case 'L':
25885796c8dcSSimon Schubert     case 'u':
25895796c8dcSSimon Schubert     case 'U':
25905796c8dcSSimon Schubert       if (tokstart[1] != '"' && tokstart[1] != '\'')
25915796c8dcSSimon Schubert 	break;
25925796c8dcSSimon Schubert       /* Fall through.  */
25935796c8dcSSimon Schubert     case '\'':
25945796c8dcSSimon Schubert     case '"':
2595*ef5ccd6cSJohn Marino 
2596*ef5ccd6cSJohn Marino     parse_string:
25975796c8dcSSimon Schubert       {
25985796c8dcSSimon Schubert 	int host_len;
25995796c8dcSSimon Schubert 	int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
26005796c8dcSSimon Schubert 					   &host_len);
26015796c8dcSSimon Schubert 	if (result == CHAR)
26025796c8dcSSimon Schubert 	  {
26035796c8dcSSimon Schubert 	    if (host_len == 0)
2604c50c785cSJohn Marino 	      error (_("Empty character constant."));
26055796c8dcSSimon Schubert 	    else if (host_len > 2 && c == '\'')
26065796c8dcSSimon Schubert 	      {
26075796c8dcSSimon Schubert 		++tokstart;
26085796c8dcSSimon Schubert 		namelen = lexptr - tokstart - 1;
26095796c8dcSSimon Schubert 		goto tryname;
26105796c8dcSSimon Schubert 	      }
26115796c8dcSSimon Schubert 	    else if (host_len > 1)
2612c50c785cSJohn Marino 	      error (_("Invalid character constant."));
26135796c8dcSSimon Schubert 	  }
26145796c8dcSSimon Schubert 	return result;
26155796c8dcSSimon Schubert       }
26165796c8dcSSimon Schubert     }
26175796c8dcSSimon Schubert 
26185796c8dcSSimon Schubert   if (!(c == '_' || c == '$'
26195796c8dcSSimon Schubert 	|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
26205796c8dcSSimon Schubert     /* We must have come across a bad character (e.g. ';').  */
2621c50c785cSJohn Marino     error (_("Invalid character '%c' in expression."), c);
26225796c8dcSSimon Schubert 
26235796c8dcSSimon Schubert   /* It's a name.  See how long it is.  */
26245796c8dcSSimon Schubert   namelen = 0;
26255796c8dcSSimon Schubert   for (c = tokstart[namelen];
26265796c8dcSSimon Schubert        (c == '_' || c == '$' || (c >= '0' && c <= '9')
26275796c8dcSSimon Schubert 	|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
26285796c8dcSSimon Schubert     {
26295796c8dcSSimon Schubert       /* Template parameter lists are part of the name.
26305796c8dcSSimon Schubert 	 FIXME: This mishandles `print $a<4&&$a>3'.  */
26315796c8dcSSimon Schubert 
26325796c8dcSSimon Schubert       if (c == '<')
26335796c8dcSSimon Schubert 	{
2634cf7f2e2dSJohn Marino 	  if (! is_cast_operator (tokstart, namelen))
2635cf7f2e2dSJohn Marino 	    {
26365796c8dcSSimon Schubert 	      /* Scan ahead to get rest of the template specification.  Note
26375796c8dcSSimon Schubert 		 that we look ahead only when the '<' adjoins non-whitespace
26385796c8dcSSimon Schubert 		 characters; for comparison expressions, e.g. "a < b > c",
26395796c8dcSSimon Schubert 		 there must be spaces before the '<', etc. */
26405796c8dcSSimon Schubert 
26415796c8dcSSimon Schubert 	      char * p = find_template_name_end (tokstart + namelen);
26425796c8dcSSimon Schubert 	      if (p)
26435796c8dcSSimon Schubert 		namelen = p - tokstart;
2644cf7f2e2dSJohn Marino 	    }
26455796c8dcSSimon Schubert 	  break;
26465796c8dcSSimon Schubert 	}
26475796c8dcSSimon Schubert       c = tokstart[++namelen];
26485796c8dcSSimon Schubert     }
26495796c8dcSSimon Schubert 
26505796c8dcSSimon Schubert   /* The token "if" terminates the expression and is NOT removed from
26515796c8dcSSimon Schubert      the input stream.  It doesn't count if it appears in the
26525796c8dcSSimon Schubert      expansion of a macro.  */
26535796c8dcSSimon Schubert   if (namelen == 2
26545796c8dcSSimon Schubert       && tokstart[0] == 'i'
26555796c8dcSSimon Schubert       && tokstart[1] == 'f'
26565796c8dcSSimon Schubert       && ! scanning_macro_expansion ())
26575796c8dcSSimon Schubert     {
26585796c8dcSSimon Schubert       return 0;
26595796c8dcSSimon Schubert     }
26605796c8dcSSimon Schubert 
2661cf7f2e2dSJohn Marino   /* For the same reason (breakpoint conditions), "thread N"
2662cf7f2e2dSJohn Marino      terminates the expression.  "thread" could be an identifier, but
2663cf7f2e2dSJohn Marino      an identifier is never followed by a number without intervening
2664cf7f2e2dSJohn Marino      punctuation.  "task" is similar.  Handle abbreviations of these,
2665cf7f2e2dSJohn Marino      similarly to breakpoint.c:find_condition_and_thread.  */
2666cf7f2e2dSJohn Marino   if (namelen >= 1
2667cf7f2e2dSJohn Marino       && (strncmp (tokstart, "thread", namelen) == 0
2668cf7f2e2dSJohn Marino 	  || strncmp (tokstart, "task", namelen) == 0)
2669cf7f2e2dSJohn Marino       && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
2670cf7f2e2dSJohn Marino       && ! scanning_macro_expansion ())
2671cf7f2e2dSJohn Marino     {
2672cf7f2e2dSJohn Marino       char *p = tokstart + namelen + 1;
2673cf7f2e2dSJohn Marino       while (*p == ' ' || *p == '\t')
2674cf7f2e2dSJohn Marino 	p++;
2675cf7f2e2dSJohn Marino       if (*p >= '0' && *p <= '9')
2676cf7f2e2dSJohn Marino 	return 0;
2677cf7f2e2dSJohn Marino     }
2678cf7f2e2dSJohn Marino 
26795796c8dcSSimon Schubert   lexptr += namelen;
26805796c8dcSSimon Schubert 
26815796c8dcSSimon Schubert   tryname:
26825796c8dcSSimon Schubert 
26835796c8dcSSimon Schubert   yylval.sval.ptr = tokstart;
26845796c8dcSSimon Schubert   yylval.sval.length = namelen;
26855796c8dcSSimon Schubert 
26865796c8dcSSimon Schubert   /* Catch specific keywords.  */
26875796c8dcSSimon Schubert   copy = copy_name (yylval.sval);
26885796c8dcSSimon Schubert   for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
26895796c8dcSSimon Schubert     if (strcmp (copy, ident_tokens[i].operator) == 0)
26905796c8dcSSimon Schubert       {
2691*ef5ccd6cSJohn Marino 	if ((ident_tokens[i].flags & FLAG_CXX) != 0
26925796c8dcSSimon Schubert 	    && parse_language->la_language != language_cplus)
26935796c8dcSSimon Schubert 	  break;
26945796c8dcSSimon Schubert 
2695*ef5ccd6cSJohn Marino 	if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
2696*ef5ccd6cSJohn Marino 	  {
2697*ef5ccd6cSJohn Marino 	    struct field_of_this_result is_a_field_of_this;
2698*ef5ccd6cSJohn Marino 
2699*ef5ccd6cSJohn Marino 	    if (lookup_symbol (copy, expression_context_block,
2700*ef5ccd6cSJohn Marino 			       VAR_DOMAIN,
2701*ef5ccd6cSJohn Marino 			       (parse_language->la_language == language_cplus
2702*ef5ccd6cSJohn Marino 				? &is_a_field_of_this
2703*ef5ccd6cSJohn Marino 				: NULL))
2704*ef5ccd6cSJohn Marino 		!= NULL)
2705*ef5ccd6cSJohn Marino 	      {
2706*ef5ccd6cSJohn Marino 		/* The keyword is shadowed.  */
2707*ef5ccd6cSJohn Marino 		break;
2708*ef5ccd6cSJohn Marino 	      }
2709*ef5ccd6cSJohn Marino 	  }
2710*ef5ccd6cSJohn Marino 
27115796c8dcSSimon Schubert 	/* It is ok to always set this, even though we don't always
27125796c8dcSSimon Schubert 	   strictly need to.  */
27135796c8dcSSimon Schubert 	yylval.opcode = ident_tokens[i].opcode;
27145796c8dcSSimon Schubert 	return ident_tokens[i].token;
27155796c8dcSSimon Schubert       }
27165796c8dcSSimon Schubert 
27175796c8dcSSimon Schubert   if (*tokstart == '$')
27185796c8dcSSimon Schubert     return VARIABLE;
2719cf7f2e2dSJohn Marino 
2720*ef5ccd6cSJohn Marino   if (parse_completion && *lexptr == '\0')
2721cf7f2e2dSJohn Marino     saw_name_at_eof = 1;
2722*ef5ccd6cSJohn Marino 
2723*ef5ccd6cSJohn Marino   yylval.ssym.stoken = yylval.sval;
2724*ef5ccd6cSJohn Marino   yylval.ssym.sym = NULL;
2725*ef5ccd6cSJohn Marino   yylval.ssym.is_a_field_of_this = 0;
2726cf7f2e2dSJohn Marino   return NAME;
27275796c8dcSSimon Schubert }
27285796c8dcSSimon Schubert 
2729cf7f2e2dSJohn Marino /* An object of this type is pushed on a FIFO by the "outer" lexer.  */
2730cf7f2e2dSJohn Marino typedef struct
2731cf7f2e2dSJohn Marino {
2732cf7f2e2dSJohn Marino   int token;
2733cf7f2e2dSJohn Marino   YYSTYPE value;
2734cf7f2e2dSJohn Marino } token_and_value;
2735cf7f2e2dSJohn Marino 
2736cf7f2e2dSJohn Marino DEF_VEC_O (token_and_value);
2737cf7f2e2dSJohn Marino 
2738cf7f2e2dSJohn Marino /* A FIFO of tokens that have been read but not yet returned to the
2739cf7f2e2dSJohn Marino    parser.  */
2740cf7f2e2dSJohn Marino static VEC (token_and_value) *token_fifo;
2741cf7f2e2dSJohn Marino 
2742cf7f2e2dSJohn Marino /* Non-zero if the lexer should return tokens from the FIFO.  */
2743cf7f2e2dSJohn Marino static int popping;
2744cf7f2e2dSJohn Marino 
2745cf7f2e2dSJohn Marino /* Temporary storage for c_lex; this holds symbol names as they are
2746cf7f2e2dSJohn Marino    built up.  */
2747cf7f2e2dSJohn Marino static struct obstack name_obstack;
2748cf7f2e2dSJohn Marino 
2749cf7f2e2dSJohn Marino /* Classify a NAME token.  The contents of the token are in `yylval'.
2750cf7f2e2dSJohn Marino    Updates yylval and returns the new token type.  BLOCK is the block
2751cf7f2e2dSJohn Marino    in which lookups start; this can be NULL to mean the global
2752cf7f2e2dSJohn Marino    scope.  */
2753cf7f2e2dSJohn Marino static int
classify_name(const struct block * block)2754*ef5ccd6cSJohn Marino classify_name (const struct block *block)
27555796c8dcSSimon Schubert {
27565796c8dcSSimon Schubert   struct symbol *sym;
2757cf7f2e2dSJohn Marino   char *copy;
2758*ef5ccd6cSJohn Marino   struct field_of_this_result is_a_field_of_this;
27595796c8dcSSimon Schubert 
2760cf7f2e2dSJohn Marino   copy = copy_name (yylval.sval);
2761cf7f2e2dSJohn Marino 
2762*ef5ccd6cSJohn Marino   /* Initialize this in case we *don't* use it in this call; that way
2763*ef5ccd6cSJohn Marino      we can refer to it unconditionally below.  */
2764*ef5ccd6cSJohn Marino   memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
2765*ef5ccd6cSJohn Marino 
2766cf7f2e2dSJohn Marino   sym = lookup_symbol (copy, block, VAR_DOMAIN,
2767*ef5ccd6cSJohn Marino 		       parse_language->la_name_of_this
2768*ef5ccd6cSJohn Marino 		       ? &is_a_field_of_this : NULL);
2769cf7f2e2dSJohn Marino 
27705796c8dcSSimon Schubert   if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
27715796c8dcSSimon Schubert     {
27725796c8dcSSimon Schubert       yylval.ssym.sym = sym;
2773*ef5ccd6cSJohn Marino       yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
27745796c8dcSSimon Schubert       return BLOCKNAME;
27755796c8dcSSimon Schubert     }
27765796c8dcSSimon Schubert   else if (!sym)
2777cf7f2e2dSJohn Marino     {
2778cf7f2e2dSJohn Marino       /* See if it's a file name. */
27795796c8dcSSimon Schubert       struct symtab *symtab;
27805796c8dcSSimon Schubert 
27815796c8dcSSimon Schubert       symtab = lookup_symtab (copy);
27825796c8dcSSimon Schubert       if (symtab)
27835796c8dcSSimon Schubert 	{
27845796c8dcSSimon Schubert 	  yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
27855796c8dcSSimon Schubert 	  return FILENAME;
27865796c8dcSSimon Schubert 	}
2787*ef5ccd6cSJohn Marino 
2788*ef5ccd6cSJohn Marino       /* If we found a field of 'this', we might have erroneously
2789*ef5ccd6cSJohn Marino 	 found a constructor where we wanted a type name.  Handle this
2790*ef5ccd6cSJohn Marino 	 case by noticing that we found a constructor and then look up
2791*ef5ccd6cSJohn Marino 	 the type tag instead.  */
2792*ef5ccd6cSJohn Marino       if (is_a_field_of_this.type != NULL
2793*ef5ccd6cSJohn Marino 	  && is_a_field_of_this.fn_field != NULL
2794*ef5ccd6cSJohn Marino 	  && TYPE_FN_FIELD_CONSTRUCTOR (is_a_field_of_this.fn_field->fn_fields,
2795*ef5ccd6cSJohn Marino 					0))
2796*ef5ccd6cSJohn Marino 	{
2797*ef5ccd6cSJohn Marino 	  struct field_of_this_result inner_is_a_field_of_this;
2798*ef5ccd6cSJohn Marino 
2799*ef5ccd6cSJohn Marino 	  sym = lookup_symbol (copy, block, STRUCT_DOMAIN,
2800*ef5ccd6cSJohn Marino 			       &inner_is_a_field_of_this);
2801*ef5ccd6cSJohn Marino 	  if (sym != NULL)
2802*ef5ccd6cSJohn Marino 	    {
2803*ef5ccd6cSJohn Marino 	      yylval.tsym.type = SYMBOL_TYPE (sym);
2804*ef5ccd6cSJohn Marino 	      return TYPENAME;
2805*ef5ccd6cSJohn Marino 	    }
2806*ef5ccd6cSJohn Marino 	}
28075796c8dcSSimon Schubert     }
28085796c8dcSSimon Schubert 
28095796c8dcSSimon Schubert   if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
28105796c8dcSSimon Schubert     {
28115796c8dcSSimon Schubert       yylval.tsym.type = SYMBOL_TYPE (sym);
28125796c8dcSSimon Schubert       return TYPENAME;
28135796c8dcSSimon Schubert     }
2814cf7f2e2dSJohn Marino 
28155796c8dcSSimon Schubert   yylval.tsym.type
28165796c8dcSSimon Schubert     = language_lookup_primitive_type_by_name (parse_language,
28175796c8dcSSimon Schubert 					      parse_gdbarch, copy);
28185796c8dcSSimon Schubert   if (yylval.tsym.type != NULL)
28195796c8dcSSimon Schubert     return TYPENAME;
28205796c8dcSSimon Schubert 
2821*ef5ccd6cSJohn Marino   /* See if it's an ObjC classname.  */
2822*ef5ccd6cSJohn Marino   if (parse_language->la_language == language_objc && !sym)
2823*ef5ccd6cSJohn Marino     {
2824*ef5ccd6cSJohn Marino       CORE_ADDR Class = lookup_objc_class (parse_gdbarch, copy);
2825*ef5ccd6cSJohn Marino       if (Class)
2826*ef5ccd6cSJohn Marino 	{
2827*ef5ccd6cSJohn Marino 	  yylval.class.class = Class;
2828*ef5ccd6cSJohn Marino 	  sym = lookup_struct_typedef (copy, expression_context_block, 1);
2829*ef5ccd6cSJohn Marino 	  if (sym)
2830*ef5ccd6cSJohn Marino 	    yylval.class.type = SYMBOL_TYPE (sym);
2831*ef5ccd6cSJohn Marino 	  return CLASSNAME;
2832*ef5ccd6cSJohn Marino 	}
2833*ef5ccd6cSJohn Marino     }
2834*ef5ccd6cSJohn Marino 
2835cf7f2e2dSJohn Marino   /* Input names that aren't symbols but ARE valid hex numbers, when
2836cf7f2e2dSJohn Marino      the input radix permits them, can be names or numbers depending
2837cf7f2e2dSJohn Marino      on the parse.  Note we support radixes > 16 here.  */
2838cf7f2e2dSJohn Marino   if (!sym
2839cf7f2e2dSJohn Marino       && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
2840cf7f2e2dSJohn Marino 	  || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
28415796c8dcSSimon Schubert     {
28425796c8dcSSimon Schubert       YYSTYPE newlval;	/* Its value is ignored.  */
2843cf7f2e2dSJohn Marino       int hextype = parse_number (copy, yylval.sval.length, 0, &newlval);
28445796c8dcSSimon Schubert       if (hextype == INT)
28455796c8dcSSimon Schubert 	{
28465796c8dcSSimon Schubert 	  yylval.ssym.sym = sym;
2847*ef5ccd6cSJohn Marino 	  yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
28485796c8dcSSimon Schubert 	  return NAME_OR_INT;
28495796c8dcSSimon Schubert 	}
28505796c8dcSSimon Schubert     }
28515796c8dcSSimon Schubert 
28525796c8dcSSimon Schubert   /* Any other kind of symbol */
28535796c8dcSSimon Schubert   yylval.ssym.sym = sym;
2854*ef5ccd6cSJohn Marino   yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
2855cf7f2e2dSJohn Marino 
2856cf7f2e2dSJohn Marino   if (sym == NULL
2857cf7f2e2dSJohn Marino       && parse_language->la_language == language_cplus
2858*ef5ccd6cSJohn Marino       && is_a_field_of_this.type == NULL
2859cf7f2e2dSJohn Marino       && !lookup_minimal_symbol (copy, NULL, NULL))
2860cf7f2e2dSJohn Marino     return UNKNOWN_CPP_NAME;
2861cf7f2e2dSJohn Marino 
28625796c8dcSSimon Schubert   return NAME;
28635796c8dcSSimon Schubert }
2864cf7f2e2dSJohn Marino 
2865cf7f2e2dSJohn Marino /* Like classify_name, but used by the inner loop of the lexer, when a
2866*ef5ccd6cSJohn Marino    name might have already been seen.  CONTEXT is the context type, or
2867*ef5ccd6cSJohn Marino    NULL if this is the first component of a name.  */
2868*ef5ccd6cSJohn Marino 
2869cf7f2e2dSJohn Marino static int
classify_inner_name(const struct block * block,struct type * context)2870*ef5ccd6cSJohn Marino classify_inner_name (const struct block *block, struct type *context)
2871cf7f2e2dSJohn Marino {
2872*ef5ccd6cSJohn Marino   struct type *type;
2873cf7f2e2dSJohn Marino   char *copy;
2874cf7f2e2dSJohn Marino 
2875*ef5ccd6cSJohn Marino   if (context == NULL)
2876cf7f2e2dSJohn Marino     return classify_name (block);
2877cf7f2e2dSJohn Marino 
2878*ef5ccd6cSJohn Marino   type = check_typedef (context);
2879cf7f2e2dSJohn Marino   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2880cf7f2e2dSJohn Marino       && TYPE_CODE (type) != TYPE_CODE_UNION
2881cf7f2e2dSJohn Marino       && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2882*ef5ccd6cSJohn Marino     return ERROR;
2883cf7f2e2dSJohn Marino 
2884*ef5ccd6cSJohn Marino   copy = copy_name (yylval.ssym.stoken);
2885*ef5ccd6cSJohn Marino   yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block);
2886*ef5ccd6cSJohn Marino   if (yylval.ssym.sym == NULL)
2887*ef5ccd6cSJohn Marino     return ERROR;
2888cf7f2e2dSJohn Marino 
2889*ef5ccd6cSJohn Marino   switch (SYMBOL_CLASS (yylval.ssym.sym))
2890*ef5ccd6cSJohn Marino     {
2891*ef5ccd6cSJohn Marino     case LOC_BLOCK:
2892*ef5ccd6cSJohn Marino     case LOC_LABEL:
2893*ef5ccd6cSJohn Marino       return ERROR;
2894cf7f2e2dSJohn Marino 
2895*ef5ccd6cSJohn Marino     case LOC_TYPEDEF:
2896*ef5ccd6cSJohn Marino       yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);;
2897cf7f2e2dSJohn Marino       return TYPENAME;
2898*ef5ccd6cSJohn Marino 
2899*ef5ccd6cSJohn Marino     default:
2900*ef5ccd6cSJohn Marino       return NAME;
2901*ef5ccd6cSJohn Marino     }
2902*ef5ccd6cSJohn Marino   internal_error (__FILE__, __LINE__, _("not reached"));
2903cf7f2e2dSJohn Marino }
2904cf7f2e2dSJohn Marino 
2905cf7f2e2dSJohn Marino /* The outer level of a two-level lexer.  This calls the inner lexer
2906cf7f2e2dSJohn Marino    to return tokens.  It then either returns these tokens, or
2907cf7f2e2dSJohn Marino    aggregates them into a larger token.  This lets us work around a
2908cf7f2e2dSJohn Marino    problem in our parsing approach, where the parser could not
2909cf7f2e2dSJohn Marino    distinguish between qualified names and qualified types at the
2910cf7f2e2dSJohn Marino    right point.
2911cf7f2e2dSJohn Marino 
2912cf7f2e2dSJohn Marino    This approach is still not ideal, because it mishandles template
2913cf7f2e2dSJohn Marino    types.  See the comment in lex_one_token for an example.  However,
2914cf7f2e2dSJohn Marino    this is still an improvement over the earlier approach, and will
2915cf7f2e2dSJohn Marino    suffice until we move to better parsing technology.  */
2916cf7f2e2dSJohn Marino static int
yylex(void)2917cf7f2e2dSJohn Marino yylex (void)
2918cf7f2e2dSJohn Marino {
2919cf7f2e2dSJohn Marino   token_and_value current;
2920cf7f2e2dSJohn Marino   int first_was_coloncolon, last_was_coloncolon, first_iter;
2921*ef5ccd6cSJohn Marino   struct type *context_type = NULL;
2922cf7f2e2dSJohn Marino 
2923cf7f2e2dSJohn Marino   if (popping && !VEC_empty (token_and_value, token_fifo))
2924cf7f2e2dSJohn Marino     {
2925cf7f2e2dSJohn Marino       token_and_value tv = *VEC_index (token_and_value, token_fifo, 0);
2926cf7f2e2dSJohn Marino       VEC_ordered_remove (token_and_value, token_fifo, 0);
2927cf7f2e2dSJohn Marino       yylval = tv.value;
2928cf7f2e2dSJohn Marino       return tv.token;
2929cf7f2e2dSJohn Marino     }
2930cf7f2e2dSJohn Marino   popping = 0;
2931cf7f2e2dSJohn Marino 
2932cf7f2e2dSJohn Marino   current.token = lex_one_token ();
2933cf7f2e2dSJohn Marino   if (current.token == NAME)
2934cf7f2e2dSJohn Marino     current.token = classify_name (expression_context_block);
2935cf7f2e2dSJohn Marino   if (parse_language->la_language != language_cplus
2936cf7f2e2dSJohn Marino       || (current.token != TYPENAME && current.token != COLONCOLON))
2937cf7f2e2dSJohn Marino     return current.token;
2938cf7f2e2dSJohn Marino 
2939cf7f2e2dSJohn Marino   first_was_coloncolon = current.token == COLONCOLON;
2940cf7f2e2dSJohn Marino   last_was_coloncolon = first_was_coloncolon;
2941cf7f2e2dSJohn Marino   obstack_free (&name_obstack, obstack_base (&name_obstack));
2942cf7f2e2dSJohn Marino   if (!last_was_coloncolon)
2943*ef5ccd6cSJohn Marino     {
2944cf7f2e2dSJohn Marino       obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
2945*ef5ccd6cSJohn Marino       context_type = yylval.tsym.type;
2946*ef5ccd6cSJohn Marino     }
2947cf7f2e2dSJohn Marino   current.value = yylval;
2948cf7f2e2dSJohn Marino   first_iter = 1;
2949cf7f2e2dSJohn Marino   while (1)
2950cf7f2e2dSJohn Marino     {
2951cf7f2e2dSJohn Marino       token_and_value next;
2952cf7f2e2dSJohn Marino 
2953cf7f2e2dSJohn Marino       next.token = lex_one_token ();
2954cf7f2e2dSJohn Marino       next.value = yylval;
2955cf7f2e2dSJohn Marino 
2956cf7f2e2dSJohn Marino       if (next.token == NAME && last_was_coloncolon)
2957cf7f2e2dSJohn Marino 	{
2958cf7f2e2dSJohn Marino 	  int classification;
2959cf7f2e2dSJohn Marino 
2960cf7f2e2dSJohn Marino 	  classification = classify_inner_name (first_was_coloncolon
2961cf7f2e2dSJohn Marino 						? NULL
2962cf7f2e2dSJohn Marino 						: expression_context_block,
2963*ef5ccd6cSJohn Marino 						context_type);
2964cf7f2e2dSJohn Marino 	  /* We keep going until we either run out of names, or until
2965cf7f2e2dSJohn Marino 	     we have a qualified name which is not a type.  */
2966*ef5ccd6cSJohn Marino 	  if (classification != TYPENAME && classification != NAME)
2967cf7f2e2dSJohn Marino 	    {
2968cf7f2e2dSJohn Marino 	      /* Push the final component and leave the loop.  */
2969cf7f2e2dSJohn Marino 	      VEC_safe_push (token_and_value, token_fifo, &next);
2970cf7f2e2dSJohn Marino 	      break;
2971cf7f2e2dSJohn Marino 	    }
2972cf7f2e2dSJohn Marino 
2973cf7f2e2dSJohn Marino 	  /* Update the partial name we are constructing.  */
2974*ef5ccd6cSJohn Marino 	  if (context_type != NULL)
2975cf7f2e2dSJohn Marino 	    {
2976cf7f2e2dSJohn Marino 	      /* We don't want to put a leading "::" into the name.  */
2977cf7f2e2dSJohn Marino 	      obstack_grow_str (&name_obstack, "::");
2978cf7f2e2dSJohn Marino 	    }
2979cf7f2e2dSJohn Marino 	  obstack_grow (&name_obstack, next.value.sval.ptr,
2980cf7f2e2dSJohn Marino 			next.value.sval.length);
2981cf7f2e2dSJohn Marino 
2982cf7f2e2dSJohn Marino 	  yylval.sval.ptr = obstack_base (&name_obstack);
2983cf7f2e2dSJohn Marino 	  yylval.sval.length = obstack_object_size (&name_obstack);
2984cf7f2e2dSJohn Marino 	  current.value = yylval;
2985cf7f2e2dSJohn Marino 	  current.token = classification;
2986cf7f2e2dSJohn Marino 
2987cf7f2e2dSJohn Marino 	  last_was_coloncolon = 0;
2988*ef5ccd6cSJohn Marino 
2989*ef5ccd6cSJohn Marino 	  if (classification == NAME)
2990*ef5ccd6cSJohn Marino 	    break;
2991*ef5ccd6cSJohn Marino 
2992*ef5ccd6cSJohn Marino 	  context_type = yylval.tsym.type;
2993cf7f2e2dSJohn Marino 	}
2994cf7f2e2dSJohn Marino       else if (next.token == COLONCOLON && !last_was_coloncolon)
2995cf7f2e2dSJohn Marino 	last_was_coloncolon = 1;
2996cf7f2e2dSJohn Marino       else
2997cf7f2e2dSJohn Marino 	{
2998cf7f2e2dSJohn Marino 	  /* We've reached the end of the name.  */
2999cf7f2e2dSJohn Marino 	  VEC_safe_push (token_and_value, token_fifo, &next);
3000cf7f2e2dSJohn Marino 	  break;
3001cf7f2e2dSJohn Marino 	}
3002cf7f2e2dSJohn Marino 
3003cf7f2e2dSJohn Marino       first_iter = 0;
3004cf7f2e2dSJohn Marino     }
3005cf7f2e2dSJohn Marino 
3006cf7f2e2dSJohn Marino   popping = 1;
3007cf7f2e2dSJohn Marino 
3008cf7f2e2dSJohn Marino   /* If we ended with a "::", insert it too.  */
3009cf7f2e2dSJohn Marino   if (last_was_coloncolon)
3010cf7f2e2dSJohn Marino     {
3011cf7f2e2dSJohn Marino       token_and_value cc;
3012cf7f2e2dSJohn Marino       memset (&cc, 0, sizeof (token_and_value));
3013cf7f2e2dSJohn Marino       if (first_was_coloncolon && first_iter)
3014cf7f2e2dSJohn Marino 	{
3015cf7f2e2dSJohn Marino 	  yylval = cc.value;
3016cf7f2e2dSJohn Marino 	  return COLONCOLON;
3017cf7f2e2dSJohn Marino 	}
3018cf7f2e2dSJohn Marino       cc.token = COLONCOLON;
3019cf7f2e2dSJohn Marino       VEC_safe_insert (token_and_value, token_fifo, 0, &cc);
3020cf7f2e2dSJohn Marino     }
3021cf7f2e2dSJohn Marino 
3022cf7f2e2dSJohn Marino   yylval = current.value;
3023cf7f2e2dSJohn Marino   yylval.sval.ptr = obstack_copy0 (&expansion_obstack,
3024cf7f2e2dSJohn Marino 				   yylval.sval.ptr,
3025cf7f2e2dSJohn Marino 				   yylval.sval.length);
3026cf7f2e2dSJohn Marino   return current.token;
30275796c8dcSSimon Schubert }
30285796c8dcSSimon Schubert 
30295796c8dcSSimon Schubert int
c_parse(void)30305796c8dcSSimon Schubert c_parse (void)
30315796c8dcSSimon Schubert {
30325796c8dcSSimon Schubert   int result;
30335796c8dcSSimon Schubert   struct cleanup *back_to = make_cleanup (free_current_contents,
30345796c8dcSSimon Schubert 					  &expression_macro_scope);
30355796c8dcSSimon Schubert 
30365796c8dcSSimon Schubert   /* Set up the scope for macro expansion.  */
30375796c8dcSSimon Schubert   expression_macro_scope = NULL;
30385796c8dcSSimon Schubert 
30395796c8dcSSimon Schubert   if (expression_context_block)
30405796c8dcSSimon Schubert     expression_macro_scope
30415796c8dcSSimon Schubert       = sal_macro_scope (find_pc_line (expression_context_pc, 0));
30425796c8dcSSimon Schubert   else
30435796c8dcSSimon Schubert     expression_macro_scope = default_macro_scope ();
30445796c8dcSSimon Schubert   if (! expression_macro_scope)
30455796c8dcSSimon Schubert     expression_macro_scope = user_macro_scope ();
30465796c8dcSSimon Schubert 
30475796c8dcSSimon Schubert   /* Initialize macro expansion code.  */
30485796c8dcSSimon Schubert   obstack_init (&expansion_obstack);
30495796c8dcSSimon Schubert   gdb_assert (! macro_original_text);
30505796c8dcSSimon Schubert   make_cleanup (scan_macro_cleanup, 0);
30515796c8dcSSimon Schubert 
3052cf7f2e2dSJohn Marino   make_cleanup_restore_integer (&yydebug);
3053cf7f2e2dSJohn Marino   yydebug = parser_debug;
3054cf7f2e2dSJohn Marino 
30555796c8dcSSimon Schubert   /* Initialize some state used by the lexer.  */
30565796c8dcSSimon Schubert   last_was_structop = 0;
30575796c8dcSSimon Schubert   saw_name_at_eof = 0;
30585796c8dcSSimon Schubert 
3059cf7f2e2dSJohn Marino   VEC_free (token_and_value, token_fifo);
3060cf7f2e2dSJohn Marino   popping = 0;
3061cf7f2e2dSJohn Marino   obstack_init (&name_obstack);
3062cf7f2e2dSJohn Marino   make_cleanup_obstack_free (&name_obstack);
3063cf7f2e2dSJohn Marino 
30645796c8dcSSimon Schubert   result = yyparse ();
30655796c8dcSSimon Schubert   do_cleanups (back_to);
30665796c8dcSSimon Schubert   return result;
30675796c8dcSSimon Schubert }
30685796c8dcSSimon Schubert 
30695796c8dcSSimon Schubert 
30705796c8dcSSimon Schubert void
yyerror(char * msg)30715796c8dcSSimon Schubert yyerror (char *msg)
30725796c8dcSSimon Schubert {
30735796c8dcSSimon Schubert   if (prev_lexptr)
30745796c8dcSSimon Schubert     lexptr = prev_lexptr;
30755796c8dcSSimon Schubert 
3076c50c785cSJohn Marino   error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
30775796c8dcSSimon Schubert }
3078