xref: /dflybsd-src/contrib/gdb-7/gdb/c-exp.y (revision c50c785cb49e9377ca78104c5540c7b33f768771)
15796c8dcSSimon Schubert /* YACC parser for C expressions, for GDB.
25796c8dcSSimon Schubert    Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3*c50c785cSJohn Marino    1998, 1999, 2000, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
45796c8dcSSimon Schubert    Free Software Foundation, Inc.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    This file is part of GDB.
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
95796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
105796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
115796c8dcSSimon Schubert    (at your option) any later version.
125796c8dcSSimon Schubert 
135796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
145796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
155796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165796c8dcSSimon Schubert    GNU General Public License for more details.
175796c8dcSSimon Schubert 
185796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
195796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
205796c8dcSSimon Schubert 
215796c8dcSSimon Schubert /* Parse a C expression from text in a string,
225796c8dcSSimon Schubert    and return the result as a  struct expression  pointer.
235796c8dcSSimon Schubert    That structure contains arithmetic operations in reverse polish,
245796c8dcSSimon Schubert    with constants represented by operations that are followed by special data.
255796c8dcSSimon Schubert    See expression.h for the details of the format.
265796c8dcSSimon Schubert    What is important here is that it can be built up sequentially
275796c8dcSSimon Schubert    during the process of parsing; the lower levels of the tree always
285796c8dcSSimon Schubert    come first in the result.
295796c8dcSSimon Schubert 
305796c8dcSSimon Schubert    Note that malloc's and realloc's in this file are transformed to
315796c8dcSSimon Schubert    xmalloc and xrealloc respectively by the same sed command in the
325796c8dcSSimon Schubert    makefile that remaps any other malloc/realloc inserted by the parser
335796c8dcSSimon Schubert    generator.  Doing this with #defines and trying to control the interaction
345796c8dcSSimon Schubert    with include files (<malloc.h> and <stdlib.h> for example) just became
355796c8dcSSimon Schubert    too messy, particularly when such includes can be inserted at random
365796c8dcSSimon Schubert    times by the parser generator.  */
375796c8dcSSimon Schubert 
385796c8dcSSimon Schubert %{
395796c8dcSSimon Schubert 
405796c8dcSSimon Schubert #include "defs.h"
415796c8dcSSimon Schubert #include "gdb_string.h"
425796c8dcSSimon Schubert #include <ctype.h>
435796c8dcSSimon Schubert #include "expression.h"
445796c8dcSSimon Schubert #include "value.h"
455796c8dcSSimon Schubert #include "parser-defs.h"
465796c8dcSSimon Schubert #include "language.h"
475796c8dcSSimon Schubert #include "c-lang.h"
485796c8dcSSimon Schubert #include "bfd.h" /* Required by objfiles.h.  */
495796c8dcSSimon Schubert #include "symfile.h" /* Required by objfiles.h.  */
505796c8dcSSimon Schubert #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
515796c8dcSSimon Schubert #include "charset.h"
525796c8dcSSimon Schubert #include "block.h"
535796c8dcSSimon Schubert #include "cp-support.h"
545796c8dcSSimon Schubert #include "dfp.h"
555796c8dcSSimon Schubert #include "gdb_assert.h"
565796c8dcSSimon Schubert #include "macroscope.h"
575796c8dcSSimon Schubert 
585796c8dcSSimon Schubert #define parse_type builtin_type (parse_gdbarch)
595796c8dcSSimon Schubert 
605796c8dcSSimon Schubert /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
615796c8dcSSimon Schubert    as well as gratuitiously global symbol names, so we can have multiple
625796c8dcSSimon Schubert    yacc generated parsers in gdb.  Note that these are only the variables
635796c8dcSSimon Schubert    produced by yacc.  If other parser generators (bison, byacc, etc) produce
645796c8dcSSimon Schubert    additional global names that conflict at link time, then those parser
655796c8dcSSimon Schubert    generators need to be fixed instead of adding those names to this list. */
665796c8dcSSimon Schubert 
675796c8dcSSimon Schubert #define	yymaxdepth c_maxdepth
685796c8dcSSimon Schubert #define	yyparse	c_parse_internal
695796c8dcSSimon Schubert #define	yylex	c_lex
705796c8dcSSimon Schubert #define	yyerror	c_error
715796c8dcSSimon Schubert #define	yylval	c_lval
725796c8dcSSimon Schubert #define	yychar	c_char
735796c8dcSSimon Schubert #define	yydebug	c_debug
745796c8dcSSimon Schubert #define	yypact	c_pact
755796c8dcSSimon Schubert #define	yyr1	c_r1
765796c8dcSSimon Schubert #define	yyr2	c_r2
775796c8dcSSimon Schubert #define	yydef	c_def
785796c8dcSSimon Schubert #define	yychk	c_chk
795796c8dcSSimon Schubert #define	yypgo	c_pgo
805796c8dcSSimon Schubert #define	yyact	c_act
815796c8dcSSimon Schubert #define	yyexca	c_exca
825796c8dcSSimon Schubert #define yyerrflag c_errflag
835796c8dcSSimon Schubert #define yynerrs	c_nerrs
845796c8dcSSimon Schubert #define	yyps	c_ps
855796c8dcSSimon Schubert #define	yypv	c_pv
865796c8dcSSimon Schubert #define	yys	c_s
875796c8dcSSimon Schubert #define	yy_yys	c_yys
885796c8dcSSimon Schubert #define	yystate	c_state
895796c8dcSSimon Schubert #define	yytmp	c_tmp
905796c8dcSSimon Schubert #define	yyv	c_v
915796c8dcSSimon Schubert #define	yy_yyv	c_yyv
925796c8dcSSimon Schubert #define	yyval	c_val
935796c8dcSSimon Schubert #define	yylloc	c_lloc
945796c8dcSSimon Schubert #define yyreds	c_reds		/* With YYDEBUG defined */
955796c8dcSSimon Schubert #define yytoks	c_toks		/* With YYDEBUG defined */
965796c8dcSSimon Schubert #define yyname	c_name		/* With YYDEBUG defined */
975796c8dcSSimon Schubert #define yyrule	c_rule		/* With YYDEBUG defined */
985796c8dcSSimon Schubert #define yylhs	c_yylhs
995796c8dcSSimon Schubert #define yylen	c_yylen
1005796c8dcSSimon Schubert #define yydefred c_yydefred
1015796c8dcSSimon Schubert #define yydgoto	c_yydgoto
1025796c8dcSSimon Schubert #define yysindex c_yysindex
1035796c8dcSSimon Schubert #define yyrindex c_yyrindex
1045796c8dcSSimon Schubert #define yygindex c_yygindex
1055796c8dcSSimon Schubert #define yytable	 c_yytable
1065796c8dcSSimon Schubert #define yycheck	 c_yycheck
1075796c8dcSSimon Schubert 
1085796c8dcSSimon Schubert #ifndef YYDEBUG
1095796c8dcSSimon Schubert #define	YYDEBUG 1		/* Default to yydebug support */
1105796c8dcSSimon Schubert #endif
1115796c8dcSSimon Schubert 
1125796c8dcSSimon Schubert #define YYFPRINTF parser_fprintf
1135796c8dcSSimon Schubert 
1145796c8dcSSimon Schubert int yyparse (void);
1155796c8dcSSimon Schubert 
1165796c8dcSSimon Schubert static int yylex (void);
1175796c8dcSSimon Schubert 
1185796c8dcSSimon Schubert void yyerror (char *);
1195796c8dcSSimon Schubert 
1205796c8dcSSimon Schubert %}
1215796c8dcSSimon Schubert 
1225796c8dcSSimon Schubert /* Although the yacc "value" of an expression is not used,
1235796c8dcSSimon Schubert    since the result is stored in the structure being created,
1245796c8dcSSimon Schubert    other node types do have values.  */
1255796c8dcSSimon Schubert 
1265796c8dcSSimon Schubert %union
1275796c8dcSSimon Schubert   {
1285796c8dcSSimon Schubert     LONGEST lval;
1295796c8dcSSimon Schubert     struct {
1305796c8dcSSimon Schubert       LONGEST val;
1315796c8dcSSimon Schubert       struct type *type;
1325796c8dcSSimon Schubert     } typed_val_int;
1335796c8dcSSimon Schubert     struct {
1345796c8dcSSimon Schubert       DOUBLEST dval;
1355796c8dcSSimon Schubert       struct type *type;
1365796c8dcSSimon Schubert     } typed_val_float;
1375796c8dcSSimon Schubert     struct {
1385796c8dcSSimon Schubert       gdb_byte val[16];
1395796c8dcSSimon Schubert       struct type *type;
1405796c8dcSSimon Schubert     } typed_val_decfloat;
1415796c8dcSSimon Schubert     struct symbol *sym;
1425796c8dcSSimon Schubert     struct type *tval;
1435796c8dcSSimon Schubert     struct stoken sval;
1445796c8dcSSimon Schubert     struct typed_stoken tsval;
1455796c8dcSSimon Schubert     struct ttype tsym;
1465796c8dcSSimon Schubert     struct symtoken ssym;
1475796c8dcSSimon Schubert     int voidval;
1485796c8dcSSimon Schubert     struct block *bval;
1495796c8dcSSimon Schubert     enum exp_opcode opcode;
1505796c8dcSSimon Schubert     struct internalvar *ivar;
1515796c8dcSSimon Schubert 
1525796c8dcSSimon Schubert     struct stoken_vector svec;
1535796c8dcSSimon Schubert     struct type **tvec;
1545796c8dcSSimon Schubert     int *ivec;
1555796c8dcSSimon Schubert   }
1565796c8dcSSimon Schubert 
1575796c8dcSSimon Schubert %{
1585796c8dcSSimon Schubert /* YYSTYPE gets defined by %union */
1595796c8dcSSimon Schubert static int parse_number (char *, int, int, YYSTYPE *);
160cf7f2e2dSJohn Marino static struct stoken operator_stoken (const char *);
1615796c8dcSSimon Schubert %}
1625796c8dcSSimon Schubert 
1635796c8dcSSimon Schubert %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
1645796c8dcSSimon Schubert %type <lval> rcurly
165cf7f2e2dSJohn Marino %type <tval> type typebase
1665796c8dcSSimon Schubert %type <tvec> nonempty_typelist
1675796c8dcSSimon Schubert /* %type <bval> block */
1685796c8dcSSimon Schubert 
1695796c8dcSSimon Schubert /* Fancy type parsing.  */
1705796c8dcSSimon Schubert %type <voidval> func_mod direct_abs_decl abs_decl
1715796c8dcSSimon Schubert %type <tval> ptype
1725796c8dcSSimon Schubert %type <lval> array_mod
1735796c8dcSSimon Schubert 
1745796c8dcSSimon Schubert %token <typed_val_int> INT
1755796c8dcSSimon Schubert %token <typed_val_float> FLOAT
1765796c8dcSSimon Schubert %token <typed_val_decfloat> DECFLOAT
1775796c8dcSSimon Schubert 
1785796c8dcSSimon Schubert /* Both NAME and TYPENAME tokens represent symbols in the input,
1795796c8dcSSimon Schubert    and both convey their data as strings.
1805796c8dcSSimon Schubert    But a TYPENAME is a string that happens to be defined as a typedef
1815796c8dcSSimon Schubert    or builtin type name (such as int or char)
1825796c8dcSSimon Schubert    and a NAME is any other symbol.
1835796c8dcSSimon Schubert    Contexts where this distinction is not important can use the
1845796c8dcSSimon Schubert    nonterminal "name", which matches either NAME or TYPENAME.  */
1855796c8dcSSimon Schubert 
1865796c8dcSSimon Schubert %token <tsval> STRING
1875796c8dcSSimon Schubert %token <tsval> CHAR
1885796c8dcSSimon Schubert %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
189cf7f2e2dSJohn Marino %token <ssym> UNKNOWN_CPP_NAME
1905796c8dcSSimon Schubert %token <voidval> COMPLETE
1915796c8dcSSimon Schubert %token <tsym> TYPENAME
1925796c8dcSSimon Schubert %type <sval> name
1935796c8dcSSimon Schubert %type <svec> string_exp
1945796c8dcSSimon Schubert %type <ssym> name_not_typename
1955796c8dcSSimon Schubert %type <tsym> typename
1965796c8dcSSimon Schubert 
1975796c8dcSSimon Schubert /* A NAME_OR_INT is a symbol which is not known in the symbol table,
1985796c8dcSSimon Schubert    but which would parse as a valid number in the current input radix.
1995796c8dcSSimon Schubert    E.g. "c" when input_radix==16.  Depending on the parse, it will be
2005796c8dcSSimon Schubert    turned into a name or into a number.  */
2015796c8dcSSimon Schubert 
2025796c8dcSSimon Schubert %token <ssym> NAME_OR_INT
2035796c8dcSSimon Schubert 
204cf7f2e2dSJohn Marino %token OPERATOR
2055796c8dcSSimon Schubert %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
2065796c8dcSSimon Schubert %token TEMPLATE
2075796c8dcSSimon Schubert %token ERROR
208cf7f2e2dSJohn Marino %token NEW DELETE
209cf7f2e2dSJohn Marino %type <sval> operator
210cf7f2e2dSJohn Marino %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
2115796c8dcSSimon Schubert 
2125796c8dcSSimon Schubert /* Special type cases, put in to allow the parser to distinguish different
2135796c8dcSSimon Schubert    legal basetypes.  */
2145796c8dcSSimon Schubert %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
2155796c8dcSSimon Schubert 
216cf7f2e2dSJohn Marino %token <sval> VARIABLE
2175796c8dcSSimon Schubert 
2185796c8dcSSimon Schubert %token <opcode> ASSIGN_MODIFY
2195796c8dcSSimon Schubert 
2205796c8dcSSimon Schubert /* C++ */
2215796c8dcSSimon Schubert %token TRUEKEYWORD
2225796c8dcSSimon Schubert %token FALSEKEYWORD
2235796c8dcSSimon Schubert 
2245796c8dcSSimon Schubert 
2255796c8dcSSimon Schubert %left ','
2265796c8dcSSimon Schubert %left ABOVE_COMMA
2275796c8dcSSimon Schubert %right '=' ASSIGN_MODIFY
2285796c8dcSSimon Schubert %right '?'
2295796c8dcSSimon Schubert %left OROR
2305796c8dcSSimon Schubert %left ANDAND
2315796c8dcSSimon Schubert %left '|'
2325796c8dcSSimon Schubert %left '^'
2335796c8dcSSimon Schubert %left '&'
2345796c8dcSSimon Schubert %left EQUAL NOTEQUAL
2355796c8dcSSimon Schubert %left '<' '>' LEQ GEQ
2365796c8dcSSimon Schubert %left LSH RSH
2375796c8dcSSimon Schubert %left '@'
2385796c8dcSSimon Schubert %left '+' '-'
2395796c8dcSSimon Schubert %left '*' '/' '%'
2405796c8dcSSimon Schubert %right UNARY INCREMENT DECREMENT
2415796c8dcSSimon Schubert %right ARROW ARROW_STAR '.' DOT_STAR '[' '('
2425796c8dcSSimon Schubert %token <ssym> BLOCKNAME
2435796c8dcSSimon Schubert %token <bval> FILENAME
2445796c8dcSSimon Schubert %type <bval> block
2455796c8dcSSimon Schubert %left COLONCOLON
2465796c8dcSSimon Schubert 
2475796c8dcSSimon Schubert 
2485796c8dcSSimon Schubert %%
2495796c8dcSSimon Schubert 
2505796c8dcSSimon Schubert start   :	exp1
2515796c8dcSSimon Schubert 	|	type_exp
2525796c8dcSSimon Schubert 	;
2535796c8dcSSimon Schubert 
2545796c8dcSSimon Schubert type_exp:	type
2555796c8dcSSimon Schubert 			{ write_exp_elt_opcode(OP_TYPE);
2565796c8dcSSimon Schubert 			  write_exp_elt_type($1);
2575796c8dcSSimon Schubert 			  write_exp_elt_opcode(OP_TYPE);}
2585796c8dcSSimon Schubert 	;
2595796c8dcSSimon Schubert 
2605796c8dcSSimon Schubert /* Expressions, including the comma operator.  */
2615796c8dcSSimon Schubert exp1	:	exp
2625796c8dcSSimon Schubert 	|	exp1 ',' exp
2635796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_COMMA); }
2645796c8dcSSimon Schubert 	;
2655796c8dcSSimon Schubert 
2665796c8dcSSimon Schubert /* Expressions, not including the comma operator.  */
2675796c8dcSSimon Schubert exp	:	'*' exp    %prec UNARY
2685796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_IND); }
2695796c8dcSSimon Schubert 	;
2705796c8dcSSimon Schubert 
2715796c8dcSSimon Schubert exp	:	'&' exp    %prec UNARY
2725796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_ADDR); }
2735796c8dcSSimon Schubert 	;
2745796c8dcSSimon Schubert 
2755796c8dcSSimon Schubert exp	:	'-' exp    %prec UNARY
2765796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_NEG); }
2775796c8dcSSimon Schubert 	;
2785796c8dcSSimon Schubert 
2795796c8dcSSimon Schubert exp	:	'+' exp    %prec UNARY
2805796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_PLUS); }
2815796c8dcSSimon Schubert 	;
2825796c8dcSSimon Schubert 
2835796c8dcSSimon Schubert exp	:	'!' exp    %prec UNARY
2845796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
2855796c8dcSSimon Schubert 	;
2865796c8dcSSimon Schubert 
2875796c8dcSSimon Schubert exp	:	'~' exp    %prec UNARY
2885796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_COMPLEMENT); }
2895796c8dcSSimon Schubert 	;
2905796c8dcSSimon Schubert 
2915796c8dcSSimon Schubert exp	:	INCREMENT exp    %prec UNARY
2925796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_PREINCREMENT); }
2935796c8dcSSimon Schubert 	;
2945796c8dcSSimon Schubert 
2955796c8dcSSimon Schubert exp	:	DECREMENT exp    %prec UNARY
2965796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_PREDECREMENT); }
2975796c8dcSSimon Schubert 	;
2985796c8dcSSimon Schubert 
2995796c8dcSSimon Schubert exp	:	exp INCREMENT    %prec UNARY
3005796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_POSTINCREMENT); }
3015796c8dcSSimon Schubert 	;
3025796c8dcSSimon Schubert 
3035796c8dcSSimon Schubert exp	:	exp DECREMENT    %prec UNARY
3045796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_POSTDECREMENT); }
3055796c8dcSSimon Schubert 	;
3065796c8dcSSimon Schubert 
3075796c8dcSSimon Schubert exp	:	SIZEOF exp       %prec UNARY
3085796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_SIZEOF); }
3095796c8dcSSimon Schubert 	;
3105796c8dcSSimon Schubert 
3115796c8dcSSimon Schubert exp	:	exp ARROW name
3125796c8dcSSimon Schubert 			{ write_exp_elt_opcode (STRUCTOP_PTR);
3135796c8dcSSimon Schubert 			  write_exp_string ($3);
3145796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR); }
3155796c8dcSSimon Schubert 	;
3165796c8dcSSimon Schubert 
3175796c8dcSSimon Schubert exp	:	exp ARROW name COMPLETE
3185796c8dcSSimon Schubert 			{ mark_struct_expression ();
3195796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR);
3205796c8dcSSimon Schubert 			  write_exp_string ($3);
3215796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR); }
3225796c8dcSSimon Schubert 	;
3235796c8dcSSimon Schubert 
3245796c8dcSSimon Schubert exp	:	exp ARROW COMPLETE
3255796c8dcSSimon Schubert 			{ struct stoken s;
3265796c8dcSSimon Schubert 			  mark_struct_expression ();
3275796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR);
3285796c8dcSSimon Schubert 			  s.ptr = "";
3295796c8dcSSimon Schubert 			  s.length = 0;
3305796c8dcSSimon Schubert 			  write_exp_string (s);
3315796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_PTR); }
3325796c8dcSSimon Schubert 	;
3335796c8dcSSimon Schubert 
3345796c8dcSSimon Schubert exp	:	exp ARROW qualified_name
3355796c8dcSSimon Schubert 			{ /* exp->type::name becomes exp->*(&type::name) */
3365796c8dcSSimon Schubert 			  /* Note: this doesn't work if name is a
3375796c8dcSSimon Schubert 			     static member!  FIXME */
3385796c8dcSSimon Schubert 			  write_exp_elt_opcode (UNOP_ADDR);
3395796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_MPTR); }
3405796c8dcSSimon Schubert 	;
3415796c8dcSSimon Schubert 
3425796c8dcSSimon Schubert exp	:	exp ARROW_STAR exp
3435796c8dcSSimon Schubert 			{ write_exp_elt_opcode (STRUCTOP_MPTR); }
3445796c8dcSSimon Schubert 	;
3455796c8dcSSimon Schubert 
3465796c8dcSSimon Schubert exp	:	exp '.' name
3475796c8dcSSimon Schubert 			{ write_exp_elt_opcode (STRUCTOP_STRUCT);
3485796c8dcSSimon Schubert 			  write_exp_string ($3);
3495796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
3505796c8dcSSimon Schubert 	;
3515796c8dcSSimon Schubert 
3525796c8dcSSimon Schubert exp	:	exp '.' name COMPLETE
3535796c8dcSSimon Schubert 			{ mark_struct_expression ();
3545796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT);
3555796c8dcSSimon Schubert 			  write_exp_string ($3);
3565796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
3575796c8dcSSimon Schubert 	;
3585796c8dcSSimon Schubert 
3595796c8dcSSimon Schubert exp	:	exp '.' COMPLETE
3605796c8dcSSimon Schubert 			{ struct stoken s;
3615796c8dcSSimon Schubert 			  mark_struct_expression ();
3625796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT);
3635796c8dcSSimon Schubert 			  s.ptr = "";
3645796c8dcSSimon Schubert 			  s.length = 0;
3655796c8dcSSimon Schubert 			  write_exp_string (s);
3665796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
3675796c8dcSSimon Schubert 	;
3685796c8dcSSimon Schubert 
3695796c8dcSSimon Schubert exp	:	exp '.' qualified_name
3705796c8dcSSimon Schubert 			{ /* exp.type::name becomes exp.*(&type::name) */
3715796c8dcSSimon Schubert 			  /* Note: this doesn't work if name is a
3725796c8dcSSimon Schubert 			     static member!  FIXME */
3735796c8dcSSimon Schubert 			  write_exp_elt_opcode (UNOP_ADDR);
3745796c8dcSSimon Schubert 			  write_exp_elt_opcode (STRUCTOP_MEMBER); }
3755796c8dcSSimon Schubert 	;
3765796c8dcSSimon Schubert 
3775796c8dcSSimon Schubert exp	:	exp DOT_STAR exp
3785796c8dcSSimon Schubert 			{ write_exp_elt_opcode (STRUCTOP_MEMBER); }
3795796c8dcSSimon Schubert 	;
3805796c8dcSSimon Schubert 
3815796c8dcSSimon Schubert exp	:	exp '[' exp1 ']'
3825796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
3835796c8dcSSimon Schubert 	;
3845796c8dcSSimon Schubert 
3855796c8dcSSimon Schubert exp	:	exp '('
3865796c8dcSSimon Schubert 			/* This is to save the value of arglist_len
3875796c8dcSSimon Schubert 			   being accumulated by an outer function call.  */
3885796c8dcSSimon Schubert 			{ start_arglist (); }
3895796c8dcSSimon Schubert 		arglist ')'	%prec ARROW
3905796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_FUNCALL);
3915796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST) end_arglist ());
3925796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_FUNCALL); }
3935796c8dcSSimon Schubert 	;
3945796c8dcSSimon Schubert 
395cf7f2e2dSJohn Marino exp	:	UNKNOWN_CPP_NAME '('
396cf7f2e2dSJohn Marino 			{
397cf7f2e2dSJohn Marino 			  /* This could potentially be a an argument defined
398cf7f2e2dSJohn Marino 			     lookup function (Koenig).  */
399cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (OP_ADL_FUNC);
400cf7f2e2dSJohn Marino 			  write_exp_elt_block (expression_context_block);
401cf7f2e2dSJohn Marino 			  write_exp_elt_sym (NULL); /* Placeholder.  */
402cf7f2e2dSJohn Marino 			  write_exp_string ($1.stoken);
403cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (OP_ADL_FUNC);
404cf7f2e2dSJohn Marino 
405cf7f2e2dSJohn Marino 			/* This is to save the value of arglist_len
406cf7f2e2dSJohn Marino 			   being accumulated by an outer function call.  */
407cf7f2e2dSJohn Marino 
408cf7f2e2dSJohn Marino 			  start_arglist ();
409cf7f2e2dSJohn Marino 			}
410cf7f2e2dSJohn Marino 		arglist ')'	%prec ARROW
411cf7f2e2dSJohn Marino 			{
412cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (OP_FUNCALL);
413cf7f2e2dSJohn Marino 			  write_exp_elt_longcst ((LONGEST) end_arglist ());
414cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (OP_FUNCALL);
415cf7f2e2dSJohn Marino 			}
416cf7f2e2dSJohn Marino 	;
417cf7f2e2dSJohn Marino 
4185796c8dcSSimon Schubert lcurly	:	'{'
4195796c8dcSSimon Schubert 			{ start_arglist (); }
4205796c8dcSSimon Schubert 	;
4215796c8dcSSimon Schubert 
4225796c8dcSSimon Schubert arglist	:
4235796c8dcSSimon Schubert 	;
4245796c8dcSSimon Schubert 
4255796c8dcSSimon Schubert arglist	:	exp
4265796c8dcSSimon Schubert 			{ arglist_len = 1; }
4275796c8dcSSimon Schubert 	;
4285796c8dcSSimon Schubert 
4295796c8dcSSimon Schubert arglist	:	arglist ',' exp   %prec ABOVE_COMMA
4305796c8dcSSimon Schubert 			{ arglist_len++; }
4315796c8dcSSimon Schubert 	;
4325796c8dcSSimon Schubert 
433cf7f2e2dSJohn Marino exp     :       exp '(' nonempty_typelist ')' const_or_volatile
434cf7f2e2dSJohn Marino 			{ int i;
435cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (TYPE_INSTANCE);
436cf7f2e2dSJohn Marino 			  write_exp_elt_longcst ((LONGEST) $<ivec>3[0]);
437cf7f2e2dSJohn Marino 			  for (i = 0; i < $<ivec>3[0]; ++i)
438cf7f2e2dSJohn Marino 			    write_exp_elt_type ($<tvec>3[i + 1]);
439cf7f2e2dSJohn Marino 			  write_exp_elt_longcst((LONGEST) $<ivec>3[0]);
440cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (TYPE_INSTANCE);
441cf7f2e2dSJohn Marino 			  free ($3);
442cf7f2e2dSJohn Marino 			}
443cf7f2e2dSJohn Marino 	;
444cf7f2e2dSJohn Marino 
4455796c8dcSSimon Schubert rcurly	:	'}'
4465796c8dcSSimon Schubert 			{ $$ = end_arglist () - 1; }
4475796c8dcSSimon Schubert 	;
4485796c8dcSSimon Schubert exp	:	lcurly arglist rcurly	%prec ARROW
4495796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_ARRAY);
4505796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST) 0);
4515796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST) $3);
4525796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_ARRAY); }
4535796c8dcSSimon Schubert 	;
4545796c8dcSSimon Schubert 
4555796c8dcSSimon Schubert exp	:	lcurly type rcurly exp  %prec UNARY
4565796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_MEMVAL);
4575796c8dcSSimon Schubert 			  write_exp_elt_type ($2);
4585796c8dcSSimon Schubert 			  write_exp_elt_opcode (UNOP_MEMVAL); }
4595796c8dcSSimon Schubert 	;
4605796c8dcSSimon Schubert 
4615796c8dcSSimon Schubert exp	:	'(' type ')' exp  %prec UNARY
4625796c8dcSSimon Schubert 			{ write_exp_elt_opcode (UNOP_CAST);
4635796c8dcSSimon Schubert 			  write_exp_elt_type ($2);
4645796c8dcSSimon Schubert 			  write_exp_elt_opcode (UNOP_CAST); }
4655796c8dcSSimon Schubert 	;
4665796c8dcSSimon Schubert 
4675796c8dcSSimon Schubert exp	:	'(' exp1 ')'
4685796c8dcSSimon Schubert 			{ }
4695796c8dcSSimon Schubert 	;
4705796c8dcSSimon Schubert 
4715796c8dcSSimon Schubert /* Binary operators in order of decreasing precedence.  */
4725796c8dcSSimon Schubert 
4735796c8dcSSimon Schubert exp	:	exp '@' exp
4745796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_REPEAT); }
4755796c8dcSSimon Schubert 	;
4765796c8dcSSimon Schubert 
4775796c8dcSSimon Schubert exp	:	exp '*' exp
4785796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_MUL); }
4795796c8dcSSimon Schubert 	;
4805796c8dcSSimon Schubert 
4815796c8dcSSimon Schubert exp	:	exp '/' exp
4825796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_DIV); }
4835796c8dcSSimon Schubert 	;
4845796c8dcSSimon Schubert 
4855796c8dcSSimon Schubert exp	:	exp '%' exp
4865796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_REM); }
4875796c8dcSSimon Schubert 	;
4885796c8dcSSimon Schubert 
4895796c8dcSSimon Schubert exp	:	exp '+' exp
4905796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_ADD); }
4915796c8dcSSimon Schubert 	;
4925796c8dcSSimon Schubert 
4935796c8dcSSimon Schubert exp	:	exp '-' exp
4945796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_SUB); }
4955796c8dcSSimon Schubert 	;
4965796c8dcSSimon Schubert 
4975796c8dcSSimon Schubert exp	:	exp LSH exp
4985796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LSH); }
4995796c8dcSSimon Schubert 	;
5005796c8dcSSimon Schubert 
5015796c8dcSSimon Schubert exp	:	exp RSH exp
5025796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_RSH); }
5035796c8dcSSimon Schubert 	;
5045796c8dcSSimon Schubert 
5055796c8dcSSimon Schubert exp	:	exp EQUAL exp
5065796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_EQUAL); }
5075796c8dcSSimon Schubert 	;
5085796c8dcSSimon Schubert 
5095796c8dcSSimon Schubert exp	:	exp NOTEQUAL exp
5105796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
5115796c8dcSSimon Schubert 	;
5125796c8dcSSimon Schubert 
5135796c8dcSSimon Schubert exp	:	exp LEQ exp
5145796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LEQ); }
5155796c8dcSSimon Schubert 	;
5165796c8dcSSimon Schubert 
5175796c8dcSSimon Schubert exp	:	exp GEQ exp
5185796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_GEQ); }
5195796c8dcSSimon Schubert 	;
5205796c8dcSSimon Schubert 
5215796c8dcSSimon Schubert exp	:	exp '<' exp
5225796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LESS); }
5235796c8dcSSimon Schubert 	;
5245796c8dcSSimon Schubert 
5255796c8dcSSimon Schubert exp	:	exp '>' exp
5265796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_GTR); }
5275796c8dcSSimon Schubert 	;
5285796c8dcSSimon Schubert 
5295796c8dcSSimon Schubert exp	:	exp '&' exp
5305796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
5315796c8dcSSimon Schubert 	;
5325796c8dcSSimon Schubert 
5335796c8dcSSimon Schubert exp	:	exp '^' exp
5345796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
5355796c8dcSSimon Schubert 	;
5365796c8dcSSimon Schubert 
5375796c8dcSSimon Schubert exp	:	exp '|' exp
5385796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
5395796c8dcSSimon Schubert 	;
5405796c8dcSSimon Schubert 
5415796c8dcSSimon Schubert exp	:	exp ANDAND exp
5425796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
5435796c8dcSSimon Schubert 	;
5445796c8dcSSimon Schubert 
5455796c8dcSSimon Schubert exp	:	exp OROR exp
5465796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
5475796c8dcSSimon Schubert 	;
5485796c8dcSSimon Schubert 
5495796c8dcSSimon Schubert exp	:	exp '?' exp ':' exp	%prec '?'
5505796c8dcSSimon Schubert 			{ write_exp_elt_opcode (TERNOP_COND); }
5515796c8dcSSimon Schubert 	;
5525796c8dcSSimon Schubert 
5535796c8dcSSimon Schubert exp	:	exp '=' exp
5545796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_ASSIGN); }
5555796c8dcSSimon Schubert 	;
5565796c8dcSSimon Schubert 
5575796c8dcSSimon Schubert exp	:	exp ASSIGN_MODIFY exp
5585796c8dcSSimon Schubert 			{ write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
5595796c8dcSSimon Schubert 			  write_exp_elt_opcode ($2);
5605796c8dcSSimon Schubert 			  write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
5615796c8dcSSimon Schubert 	;
5625796c8dcSSimon Schubert 
5635796c8dcSSimon Schubert exp	:	INT
5645796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_LONG);
5655796c8dcSSimon Schubert 			  write_exp_elt_type ($1.type);
5665796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST)($1.val));
5675796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_LONG); }
5685796c8dcSSimon Schubert 	;
5695796c8dcSSimon Schubert 
5705796c8dcSSimon Schubert exp	:	CHAR
5715796c8dcSSimon Schubert 			{
5725796c8dcSSimon Schubert 			  struct stoken_vector vec;
5735796c8dcSSimon Schubert 			  vec.len = 1;
5745796c8dcSSimon Schubert 			  vec.tokens = &$1;
5755796c8dcSSimon Schubert 			  write_exp_string_vector ($1.type, &vec);
5765796c8dcSSimon Schubert 			}
5775796c8dcSSimon Schubert 	;
5785796c8dcSSimon Schubert 
5795796c8dcSSimon Schubert exp	:	NAME_OR_INT
5805796c8dcSSimon Schubert 			{ YYSTYPE val;
5815796c8dcSSimon Schubert 			  parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
5825796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_LONG);
5835796c8dcSSimon Schubert 			  write_exp_elt_type (val.typed_val_int.type);
5845796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
5855796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_LONG);
5865796c8dcSSimon Schubert 			}
5875796c8dcSSimon Schubert 	;
5885796c8dcSSimon Schubert 
5895796c8dcSSimon Schubert 
5905796c8dcSSimon Schubert exp	:	FLOAT
5915796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_DOUBLE);
5925796c8dcSSimon Schubert 			  write_exp_elt_type ($1.type);
5935796c8dcSSimon Schubert 			  write_exp_elt_dblcst ($1.dval);
5945796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_DOUBLE); }
5955796c8dcSSimon Schubert 	;
5965796c8dcSSimon Schubert 
5975796c8dcSSimon Schubert exp	:	DECFLOAT
5985796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_DECFLOAT);
5995796c8dcSSimon Schubert 			  write_exp_elt_type ($1.type);
6005796c8dcSSimon Schubert 			  write_exp_elt_decfloatcst ($1.val);
6015796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_DECFLOAT); }
6025796c8dcSSimon Schubert 	;
6035796c8dcSSimon Schubert 
6045796c8dcSSimon Schubert exp	:	variable
6055796c8dcSSimon Schubert 	;
6065796c8dcSSimon Schubert 
6075796c8dcSSimon Schubert exp	:	VARIABLE
608cf7f2e2dSJohn Marino 			{
609cf7f2e2dSJohn Marino 			  write_dollar_variable ($1);
610cf7f2e2dSJohn Marino 			}
6115796c8dcSSimon Schubert 	;
6125796c8dcSSimon Schubert 
6135796c8dcSSimon Schubert exp	:	SIZEOF '(' type ')'	%prec UNARY
6145796c8dcSSimon Schubert 			{ write_exp_elt_opcode (OP_LONG);
615*c50c785cSJohn Marino 			  write_exp_elt_type (lookup_signed_typename
616*c50c785cSJohn Marino 					      (parse_language, parse_gdbarch,
617*c50c785cSJohn Marino 					       "int"));
6185796c8dcSSimon Schubert 			  CHECK_TYPEDEF ($3);
6195796c8dcSSimon Schubert 			  write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
6205796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_LONG); }
6215796c8dcSSimon Schubert 	;
6225796c8dcSSimon Schubert 
623cf7f2e2dSJohn Marino exp	:	REINTERPRET_CAST '<' type '>' '(' exp ')' %prec UNARY
624cf7f2e2dSJohn Marino 			{ write_exp_elt_opcode (UNOP_REINTERPRET_CAST);
625cf7f2e2dSJohn Marino 			  write_exp_elt_type ($3);
626cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
627cf7f2e2dSJohn Marino 	;
628cf7f2e2dSJohn Marino 
629cf7f2e2dSJohn Marino exp	:	STATIC_CAST '<' type '>' '(' exp ')' %prec UNARY
630cf7f2e2dSJohn Marino 			{ write_exp_elt_opcode (UNOP_CAST);
631cf7f2e2dSJohn Marino 			  write_exp_elt_type ($3);
632cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (UNOP_CAST); }
633cf7f2e2dSJohn Marino 	;
634cf7f2e2dSJohn Marino 
635cf7f2e2dSJohn Marino exp	:	DYNAMIC_CAST '<' type '>' '(' exp ')' %prec UNARY
636cf7f2e2dSJohn Marino 			{ write_exp_elt_opcode (UNOP_DYNAMIC_CAST);
637cf7f2e2dSJohn Marino 			  write_exp_elt_type ($3);
638cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
639cf7f2e2dSJohn Marino 	;
640cf7f2e2dSJohn Marino 
641cf7f2e2dSJohn Marino exp	:	CONST_CAST '<' type '>' '(' exp ')' %prec UNARY
642cf7f2e2dSJohn Marino 			{ /* We could do more error checking here, but
643cf7f2e2dSJohn Marino 			     it doesn't seem worthwhile.  */
644cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (UNOP_CAST);
645cf7f2e2dSJohn Marino 			  write_exp_elt_type ($3);
646cf7f2e2dSJohn Marino 			  write_exp_elt_opcode (UNOP_CAST); }
647cf7f2e2dSJohn Marino 	;
648cf7f2e2dSJohn Marino 
6495796c8dcSSimon Schubert string_exp:
6505796c8dcSSimon Schubert 		STRING
6515796c8dcSSimon Schubert 			{
6525796c8dcSSimon Schubert 			  /* We copy the string here, and not in the
6535796c8dcSSimon Schubert 			     lexer, to guarantee that we do not leak a
6545796c8dcSSimon Schubert 			     string.  Note that we follow the
6555796c8dcSSimon Schubert 			     NUL-termination convention of the
6565796c8dcSSimon Schubert 			     lexer.  */
6575796c8dcSSimon Schubert 			  struct typed_stoken *vec = XNEW (struct typed_stoken);
6585796c8dcSSimon Schubert 			  $$.len = 1;
6595796c8dcSSimon Schubert 			  $$.tokens = vec;
6605796c8dcSSimon Schubert 
6615796c8dcSSimon Schubert 			  vec->type = $1.type;
6625796c8dcSSimon Schubert 			  vec->length = $1.length;
6635796c8dcSSimon Schubert 			  vec->ptr = malloc ($1.length + 1);
6645796c8dcSSimon Schubert 			  memcpy (vec->ptr, $1.ptr, $1.length + 1);
6655796c8dcSSimon Schubert 			}
6665796c8dcSSimon Schubert 
6675796c8dcSSimon Schubert 	|	string_exp STRING
6685796c8dcSSimon Schubert 			{
6695796c8dcSSimon Schubert 			  /* Note that we NUL-terminate here, but just
6705796c8dcSSimon Schubert 			     for convenience.  */
6715796c8dcSSimon Schubert 			  char *p;
6725796c8dcSSimon Schubert 			  ++$$.len;
6735796c8dcSSimon Schubert 			  $$.tokens = realloc ($$.tokens,
6745796c8dcSSimon Schubert 					       $$.len * sizeof (struct typed_stoken));
6755796c8dcSSimon Schubert 
6765796c8dcSSimon Schubert 			  p = malloc ($2.length + 1);
6775796c8dcSSimon Schubert 			  memcpy (p, $2.ptr, $2.length + 1);
6785796c8dcSSimon Schubert 
6795796c8dcSSimon Schubert 			  $$.tokens[$$.len - 1].type = $2.type;
6805796c8dcSSimon Schubert 			  $$.tokens[$$.len - 1].length = $2.length;
6815796c8dcSSimon Schubert 			  $$.tokens[$$.len - 1].ptr = p;
6825796c8dcSSimon Schubert 			}
6835796c8dcSSimon Schubert 		;
6845796c8dcSSimon Schubert 
6855796c8dcSSimon Schubert exp	:	string_exp
6865796c8dcSSimon Schubert 			{
6875796c8dcSSimon Schubert 			  int i;
6885796c8dcSSimon Schubert 			  enum c_string_type type = C_STRING;
6895796c8dcSSimon Schubert 
6905796c8dcSSimon Schubert 			  for (i = 0; i < $1.len; ++i)
6915796c8dcSSimon Schubert 			    {
6925796c8dcSSimon Schubert 			      switch ($1.tokens[i].type)
6935796c8dcSSimon Schubert 				{
6945796c8dcSSimon Schubert 				case C_STRING:
6955796c8dcSSimon Schubert 				  break;
6965796c8dcSSimon Schubert 				case C_WIDE_STRING:
6975796c8dcSSimon Schubert 				case C_STRING_16:
6985796c8dcSSimon Schubert 				case C_STRING_32:
6995796c8dcSSimon Schubert 				  if (type != C_STRING
7005796c8dcSSimon Schubert 				      && type != $1.tokens[i].type)
701*c50c785cSJohn Marino 				    error (_("Undefined string concatenation."));
7025796c8dcSSimon Schubert 				  type = $1.tokens[i].type;
7035796c8dcSSimon Schubert 				  break;
7045796c8dcSSimon Schubert 				default:
7055796c8dcSSimon Schubert 				  /* internal error */
7065796c8dcSSimon Schubert 				  internal_error (__FILE__, __LINE__,
7075796c8dcSSimon Schubert 						  "unrecognized type in string concatenation");
7085796c8dcSSimon Schubert 				}
7095796c8dcSSimon Schubert 			    }
7105796c8dcSSimon Schubert 
7115796c8dcSSimon Schubert 			  write_exp_string_vector (type, &$1);
7125796c8dcSSimon Schubert 			  for (i = 0; i < $1.len; ++i)
7135796c8dcSSimon Schubert 			    free ($1.tokens[i].ptr);
7145796c8dcSSimon Schubert 			  free ($1.tokens);
7155796c8dcSSimon Schubert 			}
7165796c8dcSSimon Schubert 	;
7175796c8dcSSimon Schubert 
7185796c8dcSSimon Schubert /* C++.  */
7195796c8dcSSimon Schubert exp     :       TRUEKEYWORD
7205796c8dcSSimon Schubert                         { write_exp_elt_opcode (OP_LONG);
7215796c8dcSSimon Schubert                           write_exp_elt_type (parse_type->builtin_bool);
7225796c8dcSSimon Schubert                           write_exp_elt_longcst ((LONGEST) 1);
7235796c8dcSSimon Schubert                           write_exp_elt_opcode (OP_LONG); }
7245796c8dcSSimon Schubert 	;
7255796c8dcSSimon Schubert 
7265796c8dcSSimon Schubert exp     :       FALSEKEYWORD
7275796c8dcSSimon Schubert                         { write_exp_elt_opcode (OP_LONG);
7285796c8dcSSimon Schubert                           write_exp_elt_type (parse_type->builtin_bool);
7295796c8dcSSimon Schubert                           write_exp_elt_longcst ((LONGEST) 0);
7305796c8dcSSimon Schubert                           write_exp_elt_opcode (OP_LONG); }
7315796c8dcSSimon Schubert 	;
7325796c8dcSSimon Schubert 
7335796c8dcSSimon Schubert /* end of C++.  */
7345796c8dcSSimon Schubert 
7355796c8dcSSimon Schubert block	:	BLOCKNAME
7365796c8dcSSimon Schubert 			{
7375796c8dcSSimon Schubert 			  if ($1.sym)
7385796c8dcSSimon Schubert 			    $$ = SYMBOL_BLOCK_VALUE ($1.sym);
7395796c8dcSSimon Schubert 			  else
740*c50c785cSJohn Marino 			    error (_("No file or function \"%s\"."),
7415796c8dcSSimon Schubert 				   copy_name ($1.stoken));
7425796c8dcSSimon Schubert 			}
7435796c8dcSSimon Schubert 	|	FILENAME
7445796c8dcSSimon Schubert 			{
7455796c8dcSSimon Schubert 			  $$ = $1;
7465796c8dcSSimon Schubert 			}
7475796c8dcSSimon Schubert 	;
7485796c8dcSSimon Schubert 
7495796c8dcSSimon Schubert block	:	block COLONCOLON name
7505796c8dcSSimon Schubert 			{ struct symbol *tem
7515796c8dcSSimon Schubert 			    = lookup_symbol (copy_name ($3), $1,
7525796c8dcSSimon Schubert 					     VAR_DOMAIN, (int *) NULL);
7535796c8dcSSimon Schubert 			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
754*c50c785cSJohn Marino 			    error (_("No function \"%s\" in specified context."),
7555796c8dcSSimon Schubert 				   copy_name ($3));
7565796c8dcSSimon Schubert 			  $$ = SYMBOL_BLOCK_VALUE (tem); }
7575796c8dcSSimon Schubert 	;
7585796c8dcSSimon Schubert 
7595796c8dcSSimon Schubert variable:	block COLONCOLON name
7605796c8dcSSimon Schubert 			{ struct symbol *sym;
7615796c8dcSSimon Schubert 			  sym = lookup_symbol (copy_name ($3), $1,
7625796c8dcSSimon Schubert 					       VAR_DOMAIN, (int *) NULL);
7635796c8dcSSimon Schubert 			  if (sym == 0)
764*c50c785cSJohn Marino 			    error (_("No symbol \"%s\" in specified context."),
7655796c8dcSSimon Schubert 				   copy_name ($3));
7665796c8dcSSimon Schubert 
7675796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_VAR_VALUE);
7685796c8dcSSimon Schubert 			  /* block_found is set by lookup_symbol.  */
7695796c8dcSSimon Schubert 			  write_exp_elt_block (block_found);
7705796c8dcSSimon Schubert 			  write_exp_elt_sym (sym);
7715796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_VAR_VALUE); }
7725796c8dcSSimon Schubert 	;
7735796c8dcSSimon Schubert 
774cf7f2e2dSJohn Marino qualified_name:	TYPENAME COLONCOLON name
7755796c8dcSSimon Schubert 			{
776cf7f2e2dSJohn Marino 			  struct type *type = $1.type;
777cf7f2e2dSJohn Marino 			  CHECK_TYPEDEF (type);
7785796c8dcSSimon Schubert 			  if (TYPE_CODE (type) != TYPE_CODE_STRUCT
7795796c8dcSSimon Schubert 			      && TYPE_CODE (type) != TYPE_CODE_UNION
7805796c8dcSSimon Schubert 			      && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
781*c50c785cSJohn Marino 			    error (_("`%s' is not defined as an aggregate type."),
7825796c8dcSSimon Schubert 				   TYPE_NAME (type));
7835796c8dcSSimon Schubert 
7845796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_SCOPE);
7855796c8dcSSimon Schubert 			  write_exp_elt_type (type);
7865796c8dcSSimon Schubert 			  write_exp_string ($3);
7875796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_SCOPE);
7885796c8dcSSimon Schubert 			}
789cf7f2e2dSJohn Marino 	|	TYPENAME COLONCOLON '~' name
7905796c8dcSSimon Schubert 			{
791cf7f2e2dSJohn Marino 			  struct type *type = $1.type;
7925796c8dcSSimon Schubert 			  struct stoken tmp_token;
793cf7f2e2dSJohn Marino 			  CHECK_TYPEDEF (type);
7945796c8dcSSimon Schubert 			  if (TYPE_CODE (type) != TYPE_CODE_STRUCT
7955796c8dcSSimon Schubert 			      && TYPE_CODE (type) != TYPE_CODE_UNION
7965796c8dcSSimon Schubert 			      && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
797*c50c785cSJohn Marino 			    error (_("`%s' is not defined as an aggregate type."),
7985796c8dcSSimon Schubert 				   TYPE_NAME (type));
7995796c8dcSSimon Schubert 
8005796c8dcSSimon Schubert 			  tmp_token.ptr = (char*) alloca ($4.length + 2);
8015796c8dcSSimon Schubert 			  tmp_token.length = $4.length + 1;
8025796c8dcSSimon Schubert 			  tmp_token.ptr[0] = '~';
8035796c8dcSSimon Schubert 			  memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
8045796c8dcSSimon Schubert 			  tmp_token.ptr[tmp_token.length] = 0;
8055796c8dcSSimon Schubert 
8065796c8dcSSimon Schubert 			  /* Check for valid destructor name.  */
8075796c8dcSSimon Schubert 			  destructor_name_p (tmp_token.ptr, type);
8085796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_SCOPE);
8095796c8dcSSimon Schubert 			  write_exp_elt_type (type);
8105796c8dcSSimon Schubert 			  write_exp_string (tmp_token);
8115796c8dcSSimon Schubert 			  write_exp_elt_opcode (OP_SCOPE);
8125796c8dcSSimon Schubert 			}
813cf7f2e2dSJohn Marino 	|	TYPENAME COLONCOLON name COLONCOLON name
814cf7f2e2dSJohn Marino 			{
815cf7f2e2dSJohn Marino 			  char *copy = copy_name ($3);
816cf7f2e2dSJohn Marino 			  error (_("No type \"%s\" within class "
817cf7f2e2dSJohn Marino 				   "or namespace \"%s\"."),
818cf7f2e2dSJohn Marino 				 copy, TYPE_NAME ($1.type));
819cf7f2e2dSJohn Marino 			}
8205796c8dcSSimon Schubert 	;
8215796c8dcSSimon Schubert 
8225796c8dcSSimon Schubert variable:	qualified_name
823cf7f2e2dSJohn Marino 	|	COLONCOLON name_not_typename
8245796c8dcSSimon Schubert 			{
825cf7f2e2dSJohn Marino 			  char *name = copy_name ($2.stoken);
8265796c8dcSSimon Schubert 			  struct symbol *sym;
8275796c8dcSSimon Schubert 			  struct minimal_symbol *msymbol;
8285796c8dcSSimon Schubert 
8295796c8dcSSimon Schubert 			  sym =
8305796c8dcSSimon Schubert 			    lookup_symbol (name, (const struct block *) NULL,
8315796c8dcSSimon Schubert 					   VAR_DOMAIN, (int *) NULL);
8325796c8dcSSimon Schubert 			  if (sym)
8335796c8dcSSimon Schubert 			    {
8345796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_VAR_VALUE);
8355796c8dcSSimon Schubert 			      write_exp_elt_block (NULL);
8365796c8dcSSimon Schubert 			      write_exp_elt_sym (sym);
8375796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_VAR_VALUE);
8385796c8dcSSimon Schubert 			      break;
8395796c8dcSSimon Schubert 			    }
8405796c8dcSSimon Schubert 
8415796c8dcSSimon Schubert 			  msymbol = lookup_minimal_symbol (name, NULL, NULL);
8425796c8dcSSimon Schubert 			  if (msymbol != NULL)
8435796c8dcSSimon Schubert 			    write_exp_msymbol (msymbol);
8445796c8dcSSimon Schubert 			  else if (!have_full_symbols () && !have_partial_symbols ())
845*c50c785cSJohn Marino 			    error (_("No symbol table is loaded.  Use the \"file\" command."));
8465796c8dcSSimon Schubert 			  else
847*c50c785cSJohn Marino 			    error (_("No symbol \"%s\" in current context."), name);
8485796c8dcSSimon Schubert 			}
8495796c8dcSSimon Schubert 	;
8505796c8dcSSimon Schubert 
8515796c8dcSSimon Schubert variable:	name_not_typename
8525796c8dcSSimon Schubert 			{ struct symbol *sym = $1.sym;
8535796c8dcSSimon Schubert 
8545796c8dcSSimon Schubert 			  if (sym)
8555796c8dcSSimon Schubert 			    {
8565796c8dcSSimon Schubert 			      if (symbol_read_needs_frame (sym))
8575796c8dcSSimon Schubert 				{
858cf7f2e2dSJohn Marino 				  if (innermost_block == 0
859cf7f2e2dSJohn Marino 				      || contained_in (block_found,
8605796c8dcSSimon Schubert 						       innermost_block))
8615796c8dcSSimon Schubert 				    innermost_block = block_found;
8625796c8dcSSimon Schubert 				}
8635796c8dcSSimon Schubert 
8645796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_VAR_VALUE);
8655796c8dcSSimon Schubert 			      /* We want to use the selected frame, not
8665796c8dcSSimon Schubert 				 another more inner frame which happens to
8675796c8dcSSimon Schubert 				 be in the same block.  */
8685796c8dcSSimon Schubert 			      write_exp_elt_block (NULL);
8695796c8dcSSimon Schubert 			      write_exp_elt_sym (sym);
8705796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_VAR_VALUE);
8715796c8dcSSimon Schubert 			    }
8725796c8dcSSimon Schubert 			  else if ($1.is_a_field_of_this)
8735796c8dcSSimon Schubert 			    {
8745796c8dcSSimon Schubert 			      /* C++: it hangs off of `this'.  Must
8755796c8dcSSimon Schubert 			         not inadvertently convert from a method call
8765796c8dcSSimon Schubert 				 to data ref.  */
877cf7f2e2dSJohn Marino 			      if (innermost_block == 0
878cf7f2e2dSJohn Marino 				  || contained_in (block_found,
879cf7f2e2dSJohn Marino 						   innermost_block))
8805796c8dcSSimon Schubert 				innermost_block = block_found;
8815796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_THIS);
8825796c8dcSSimon Schubert 			      write_exp_elt_opcode (OP_THIS);
8835796c8dcSSimon Schubert 			      write_exp_elt_opcode (STRUCTOP_PTR);
8845796c8dcSSimon Schubert 			      write_exp_string ($1.stoken);
8855796c8dcSSimon Schubert 			      write_exp_elt_opcode (STRUCTOP_PTR);
8865796c8dcSSimon Schubert 			    }
8875796c8dcSSimon Schubert 			  else
8885796c8dcSSimon Schubert 			    {
8895796c8dcSSimon Schubert 			      struct minimal_symbol *msymbol;
8905796c8dcSSimon Schubert 			      char *arg = copy_name ($1.stoken);
8915796c8dcSSimon Schubert 
8925796c8dcSSimon Schubert 			      msymbol =
8935796c8dcSSimon Schubert 				lookup_minimal_symbol (arg, NULL, NULL);
8945796c8dcSSimon Schubert 			      if (msymbol != NULL)
8955796c8dcSSimon Schubert 				write_exp_msymbol (msymbol);
8965796c8dcSSimon Schubert 			      else if (!have_full_symbols () && !have_partial_symbols ())
897*c50c785cSJohn Marino 				error (_("No symbol table is loaded.  Use the \"file\" command."));
8985796c8dcSSimon Schubert 			      else
899*c50c785cSJohn Marino 				error (_("No symbol \"%s\" in current context."),
9005796c8dcSSimon Schubert 				       copy_name ($1.stoken));
9015796c8dcSSimon Schubert 			    }
9025796c8dcSSimon Schubert 			}
9035796c8dcSSimon Schubert 	;
9045796c8dcSSimon Schubert 
9055796c8dcSSimon Schubert space_identifier : '@' NAME
9065796c8dcSSimon Schubert 		{ push_type_address_space (copy_name ($2.stoken));
9075796c8dcSSimon Schubert 		  push_type (tp_space_identifier);
9085796c8dcSSimon Schubert 		}
9095796c8dcSSimon Schubert 	;
9105796c8dcSSimon Schubert 
9115796c8dcSSimon Schubert const_or_volatile: const_or_volatile_noopt
9125796c8dcSSimon Schubert 	|
9135796c8dcSSimon Schubert 	;
9145796c8dcSSimon Schubert 
9155796c8dcSSimon Schubert cv_with_space_id : const_or_volatile space_identifier const_or_volatile
9165796c8dcSSimon Schubert 	;
9175796c8dcSSimon Schubert 
9185796c8dcSSimon Schubert const_or_volatile_or_space_identifier_noopt: cv_with_space_id
9195796c8dcSSimon Schubert 	| const_or_volatile_noopt
9205796c8dcSSimon Schubert 	;
9215796c8dcSSimon Schubert 
9225796c8dcSSimon Schubert const_or_volatile_or_space_identifier:
9235796c8dcSSimon Schubert 		const_or_volatile_or_space_identifier_noopt
9245796c8dcSSimon Schubert 	|
9255796c8dcSSimon Schubert 	;
9265796c8dcSSimon Schubert 
9275796c8dcSSimon Schubert abs_decl:	'*'
9285796c8dcSSimon Schubert 			{ push_type (tp_pointer); $$ = 0; }
9295796c8dcSSimon Schubert 	|	'*' abs_decl
9305796c8dcSSimon Schubert 			{ push_type (tp_pointer); $$ = $2; }
9315796c8dcSSimon Schubert 	|	'&'
9325796c8dcSSimon Schubert 			{ push_type (tp_reference); $$ = 0; }
9335796c8dcSSimon Schubert 	|	'&' abs_decl
9345796c8dcSSimon Schubert 			{ push_type (tp_reference); $$ = $2; }
9355796c8dcSSimon Schubert 	|	direct_abs_decl
9365796c8dcSSimon Schubert 	;
9375796c8dcSSimon Schubert 
9385796c8dcSSimon Schubert direct_abs_decl: '(' abs_decl ')'
9395796c8dcSSimon Schubert 			{ $$ = $2; }
9405796c8dcSSimon Schubert 	|	direct_abs_decl array_mod
9415796c8dcSSimon Schubert 			{
9425796c8dcSSimon Schubert 			  push_type_int ($2);
9435796c8dcSSimon Schubert 			  push_type (tp_array);
9445796c8dcSSimon Schubert 			}
9455796c8dcSSimon Schubert 	|	array_mod
9465796c8dcSSimon Schubert 			{
9475796c8dcSSimon Schubert 			  push_type_int ($1);
9485796c8dcSSimon Schubert 			  push_type (tp_array);
9495796c8dcSSimon Schubert 			  $$ = 0;
9505796c8dcSSimon Schubert 			}
9515796c8dcSSimon Schubert 
9525796c8dcSSimon Schubert 	| 	direct_abs_decl func_mod
9535796c8dcSSimon Schubert 			{ push_type (tp_function); }
9545796c8dcSSimon Schubert 	|	func_mod
9555796c8dcSSimon Schubert 			{ push_type (tp_function); }
9565796c8dcSSimon Schubert 	;
9575796c8dcSSimon Schubert 
9585796c8dcSSimon Schubert array_mod:	'[' ']'
9595796c8dcSSimon Schubert 			{ $$ = -1; }
9605796c8dcSSimon Schubert 	|	'[' INT ']'
9615796c8dcSSimon Schubert 			{ $$ = $2.val; }
9625796c8dcSSimon Schubert 	;
9635796c8dcSSimon Schubert 
9645796c8dcSSimon Schubert func_mod:	'(' ')'
9655796c8dcSSimon Schubert 			{ $$ = 0; }
9665796c8dcSSimon Schubert 	|	'(' nonempty_typelist ')'
9675796c8dcSSimon Schubert 			{ free ($2); $$ = 0; }
9685796c8dcSSimon Schubert 	;
9695796c8dcSSimon Schubert 
9705796c8dcSSimon Schubert /* We used to try to recognize pointer to member types here, but
9715796c8dcSSimon Schubert    that didn't work (shift/reduce conflicts meant that these rules never
9725796c8dcSSimon Schubert    got executed).  The problem is that
9735796c8dcSSimon Schubert      int (foo::bar::baz::bizzle)
9745796c8dcSSimon Schubert    is a function type but
9755796c8dcSSimon Schubert      int (foo::bar::baz::bizzle::*)
9765796c8dcSSimon Schubert    is a pointer to member type.  Stroustrup loses again!  */
9775796c8dcSSimon Schubert 
9785796c8dcSSimon Schubert type	:	ptype
9795796c8dcSSimon Schubert 	;
9805796c8dcSSimon Schubert 
9815796c8dcSSimon Schubert typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
9825796c8dcSSimon Schubert 	:	TYPENAME
9835796c8dcSSimon Schubert 			{ $$ = $1.type; }
9845796c8dcSSimon Schubert 	|	INT_KEYWORD
985*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
986*c50c785cSJohn Marino 						       parse_gdbarch,
987*c50c785cSJohn Marino 						       "int"); }
9885796c8dcSSimon Schubert 	|	LONG
989*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
990*c50c785cSJohn Marino 						       parse_gdbarch,
991*c50c785cSJohn Marino 						       "long"); }
9925796c8dcSSimon Schubert 	|	SHORT
993*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
994*c50c785cSJohn Marino 						       parse_gdbarch,
995*c50c785cSJohn Marino 						       "short"); }
9965796c8dcSSimon Schubert 	|	LONG INT_KEYWORD
997*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
998*c50c785cSJohn Marino 						       parse_gdbarch,
999*c50c785cSJohn Marino 						       "long"); }
10005796c8dcSSimon Schubert 	|	LONG SIGNED_KEYWORD INT_KEYWORD
1001*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1002*c50c785cSJohn Marino 						       parse_gdbarch,
1003*c50c785cSJohn Marino 						       "long"); }
10045796c8dcSSimon Schubert 	|	LONG SIGNED_KEYWORD
1005*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1006*c50c785cSJohn Marino 						       parse_gdbarch,
1007*c50c785cSJohn Marino 						       "long"); }
10085796c8dcSSimon Schubert 	|	SIGNED_KEYWORD LONG INT_KEYWORD
1009*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1010*c50c785cSJohn Marino 						       parse_gdbarch,
1011*c50c785cSJohn Marino 						       "long"); }
10125796c8dcSSimon Schubert 	|	UNSIGNED LONG INT_KEYWORD
1013*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1014*c50c785cSJohn Marino 							 parse_gdbarch,
1015*c50c785cSJohn Marino 							 "long"); }
10165796c8dcSSimon Schubert 	|	LONG UNSIGNED INT_KEYWORD
1017*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1018*c50c785cSJohn Marino 							 parse_gdbarch,
1019*c50c785cSJohn Marino 							 "long"); }
10205796c8dcSSimon Schubert 	|	LONG UNSIGNED
1021*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1022*c50c785cSJohn Marino 							 parse_gdbarch,
1023*c50c785cSJohn Marino 							 "long"); }
10245796c8dcSSimon Schubert 	|	LONG LONG
1025*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1026*c50c785cSJohn Marino 						       parse_gdbarch,
1027*c50c785cSJohn Marino 						       "long long"); }
10285796c8dcSSimon Schubert 	|	LONG LONG INT_KEYWORD
1029*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1030*c50c785cSJohn Marino 						       parse_gdbarch,
1031*c50c785cSJohn Marino 						       "long long"); }
10325796c8dcSSimon Schubert 	|	LONG LONG SIGNED_KEYWORD INT_KEYWORD
1033*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1034*c50c785cSJohn Marino 						       parse_gdbarch,
1035*c50c785cSJohn Marino 						       "long long"); }
10365796c8dcSSimon Schubert 	|	LONG LONG SIGNED_KEYWORD
1037*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1038*c50c785cSJohn Marino 						       parse_gdbarch,
1039*c50c785cSJohn Marino 						       "long long"); }
10405796c8dcSSimon Schubert 	|	SIGNED_KEYWORD LONG LONG
1041*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1042*c50c785cSJohn Marino 						       parse_gdbarch,
1043*c50c785cSJohn Marino 						       "long long"); }
10445796c8dcSSimon Schubert 	|	SIGNED_KEYWORD LONG LONG INT_KEYWORD
1045*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1046*c50c785cSJohn Marino 						       parse_gdbarch,
1047*c50c785cSJohn Marino 						       "long long"); }
10485796c8dcSSimon Schubert 	|	UNSIGNED LONG LONG
1049*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1050*c50c785cSJohn Marino 							 parse_gdbarch,
1051*c50c785cSJohn Marino 							 "long long"); }
10525796c8dcSSimon Schubert 	|	UNSIGNED LONG LONG INT_KEYWORD
1053*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1054*c50c785cSJohn Marino 							 parse_gdbarch,
1055*c50c785cSJohn Marino 							 "long long"); }
10565796c8dcSSimon Schubert 	|	LONG LONG UNSIGNED
1057*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1058*c50c785cSJohn Marino 							 parse_gdbarch,
1059*c50c785cSJohn Marino 							 "long long"); }
10605796c8dcSSimon Schubert 	|	LONG LONG UNSIGNED INT_KEYWORD
1061*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1062*c50c785cSJohn Marino 							 parse_gdbarch,
1063*c50c785cSJohn Marino 							 "long long"); }
10645796c8dcSSimon Schubert 	|	SHORT INT_KEYWORD
1065*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1066*c50c785cSJohn Marino 						       parse_gdbarch,
1067*c50c785cSJohn Marino 						       "short"); }
10685796c8dcSSimon Schubert 	|	SHORT SIGNED_KEYWORD INT_KEYWORD
1069*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1070*c50c785cSJohn Marino 						       parse_gdbarch,
1071*c50c785cSJohn Marino 						       "short"); }
10725796c8dcSSimon Schubert 	|	SHORT SIGNED_KEYWORD
1073*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1074*c50c785cSJohn Marino 						       parse_gdbarch,
1075*c50c785cSJohn Marino 						       "short"); }
10765796c8dcSSimon Schubert 	|	UNSIGNED SHORT INT_KEYWORD
1077*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1078*c50c785cSJohn Marino 							 parse_gdbarch,
1079*c50c785cSJohn Marino 							 "short"); }
10805796c8dcSSimon Schubert 	|	SHORT UNSIGNED
1081*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1082*c50c785cSJohn Marino 							 parse_gdbarch,
1083*c50c785cSJohn Marino 							 "short"); }
10845796c8dcSSimon Schubert 	|	SHORT UNSIGNED INT_KEYWORD
1085*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1086*c50c785cSJohn Marino 							 parse_gdbarch,
1087*c50c785cSJohn Marino 							 "short"); }
10885796c8dcSSimon Schubert 	|	DOUBLE_KEYWORD
1089*c50c785cSJohn Marino 			{ $$ = lookup_typename (parse_language, parse_gdbarch,
1090*c50c785cSJohn Marino 						"double", (struct block *) NULL,
1091*c50c785cSJohn Marino 						0); }
10925796c8dcSSimon Schubert 	|	LONG DOUBLE_KEYWORD
1093*c50c785cSJohn Marino 			{ $$ = lookup_typename (parse_language, parse_gdbarch,
1094*c50c785cSJohn Marino 						"long double",
1095*c50c785cSJohn Marino 						(struct block *) NULL, 0); }
10965796c8dcSSimon Schubert 	|	STRUCT name
10975796c8dcSSimon Schubert 			{ $$ = lookup_struct (copy_name ($2),
10985796c8dcSSimon Schubert 					      expression_context_block); }
10995796c8dcSSimon Schubert 	|	CLASS name
11005796c8dcSSimon Schubert 			{ $$ = lookup_struct (copy_name ($2),
11015796c8dcSSimon Schubert 					      expression_context_block); }
11025796c8dcSSimon Schubert 	|	UNION name
11035796c8dcSSimon Schubert 			{ $$ = lookup_union (copy_name ($2),
11045796c8dcSSimon Schubert 					     expression_context_block); }
11055796c8dcSSimon Schubert 	|	ENUM name
11065796c8dcSSimon Schubert 			{ $$ = lookup_enum (copy_name ($2),
11075796c8dcSSimon Schubert 					    expression_context_block); }
11085796c8dcSSimon Schubert 	|	UNSIGNED typename
11095796c8dcSSimon Schubert 			{ $$ = lookup_unsigned_typename (parse_language,
11105796c8dcSSimon Schubert 							 parse_gdbarch,
11115796c8dcSSimon Schubert 							 TYPE_NAME($2.type)); }
11125796c8dcSSimon Schubert 	|	UNSIGNED
1113*c50c785cSJohn Marino 			{ $$ = lookup_unsigned_typename (parse_language,
1114*c50c785cSJohn Marino 							 parse_gdbarch,
1115*c50c785cSJohn Marino 							 "int"); }
11165796c8dcSSimon Schubert 	|	SIGNED_KEYWORD typename
11175796c8dcSSimon Schubert 			{ $$ = lookup_signed_typename (parse_language,
11185796c8dcSSimon Schubert 						       parse_gdbarch,
11195796c8dcSSimon Schubert 						       TYPE_NAME($2.type)); }
11205796c8dcSSimon Schubert 	|	SIGNED_KEYWORD
1121*c50c785cSJohn Marino 			{ $$ = lookup_signed_typename (parse_language,
1122*c50c785cSJohn Marino 						       parse_gdbarch,
1123*c50c785cSJohn Marino 						       "int"); }
11245796c8dcSSimon Schubert                 /* It appears that this rule for templates is never
11255796c8dcSSimon Schubert                    reduced; template recognition happens by lookahead
11265796c8dcSSimon Schubert                    in the token processing code in yylex. */
11275796c8dcSSimon Schubert 	|	TEMPLATE name '<' type '>'
11285796c8dcSSimon Schubert 			{ $$ = lookup_template_type(copy_name($2), $4,
11295796c8dcSSimon Schubert 						    expression_context_block);
11305796c8dcSSimon Schubert 			}
11315796c8dcSSimon Schubert 	| const_or_volatile_or_space_identifier_noopt typebase
11325796c8dcSSimon Schubert 			{ $$ = follow_types ($2); }
11335796c8dcSSimon Schubert 	| typebase const_or_volatile_or_space_identifier_noopt
11345796c8dcSSimon Schubert 			{ $$ = follow_types ($1); }
11355796c8dcSSimon Schubert 	;
11365796c8dcSSimon Schubert 
11375796c8dcSSimon Schubert typename:	TYPENAME
11385796c8dcSSimon Schubert 	|	INT_KEYWORD
11395796c8dcSSimon Schubert 		{
11405796c8dcSSimon Schubert 		  $$.stoken.ptr = "int";
11415796c8dcSSimon Schubert 		  $$.stoken.length = 3;
1142*c50c785cSJohn Marino 		  $$.type = lookup_signed_typename (parse_language,
1143*c50c785cSJohn Marino 						    parse_gdbarch,
1144*c50c785cSJohn Marino 						    "int");
11455796c8dcSSimon Schubert 		}
11465796c8dcSSimon Schubert 	|	LONG
11475796c8dcSSimon Schubert 		{
11485796c8dcSSimon Schubert 		  $$.stoken.ptr = "long";
11495796c8dcSSimon Schubert 		  $$.stoken.length = 4;
1150*c50c785cSJohn Marino 		  $$.type = lookup_signed_typename (parse_language,
1151*c50c785cSJohn Marino 						    parse_gdbarch,
1152*c50c785cSJohn Marino 						    "long");
11535796c8dcSSimon Schubert 		}
11545796c8dcSSimon Schubert 	|	SHORT
11555796c8dcSSimon Schubert 		{
11565796c8dcSSimon Schubert 		  $$.stoken.ptr = "short";
11575796c8dcSSimon Schubert 		  $$.stoken.length = 5;
1158*c50c785cSJohn Marino 		  $$.type = lookup_signed_typename (parse_language,
1159*c50c785cSJohn Marino 						    parse_gdbarch,
1160*c50c785cSJohn Marino 						    "short");
11615796c8dcSSimon Schubert 		}
11625796c8dcSSimon Schubert 	;
11635796c8dcSSimon Schubert 
11645796c8dcSSimon Schubert nonempty_typelist
11655796c8dcSSimon Schubert 	:	type
11665796c8dcSSimon Schubert 		{ $$ = (struct type **) malloc (sizeof (struct type *) * 2);
11675796c8dcSSimon Schubert 		  $<ivec>$[0] = 1;	/* Number of types in vector */
11685796c8dcSSimon Schubert 		  $$[1] = $1;
11695796c8dcSSimon Schubert 		}
11705796c8dcSSimon Schubert 	|	nonempty_typelist ',' type
11715796c8dcSSimon Schubert 		{ int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
11725796c8dcSSimon Schubert 		  $$ = (struct type **) realloc ((char *) $1, len);
11735796c8dcSSimon Schubert 		  $$[$<ivec>$[0]] = $3;
11745796c8dcSSimon Schubert 		}
11755796c8dcSSimon Schubert 	;
11765796c8dcSSimon Schubert 
11775796c8dcSSimon Schubert ptype	:	typebase
11785796c8dcSSimon Schubert 	|	ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
11795796c8dcSSimon Schubert 		{ $$ = follow_types ($1); }
11805796c8dcSSimon Schubert 	;
11815796c8dcSSimon Schubert 
11825796c8dcSSimon Schubert const_and_volatile: 	CONST_KEYWORD VOLATILE_KEYWORD
11835796c8dcSSimon Schubert 	| 		VOLATILE_KEYWORD CONST_KEYWORD
11845796c8dcSSimon Schubert 	;
11855796c8dcSSimon Schubert 
11865796c8dcSSimon Schubert const_or_volatile_noopt:  	const_and_volatile
11875796c8dcSSimon Schubert 			{ push_type (tp_const);
11885796c8dcSSimon Schubert 			  push_type (tp_volatile);
11895796c8dcSSimon Schubert 			}
11905796c8dcSSimon Schubert 	| 		CONST_KEYWORD
11915796c8dcSSimon Schubert 			{ push_type (tp_const); }
11925796c8dcSSimon Schubert 	| 		VOLATILE_KEYWORD
11935796c8dcSSimon Schubert 			{ push_type (tp_volatile); }
11945796c8dcSSimon Schubert 	;
11955796c8dcSSimon Schubert 
1196cf7f2e2dSJohn Marino operator:	OPERATOR NEW
1197cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (" new"); }
1198cf7f2e2dSJohn Marino 	|	OPERATOR DELETE
1199cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (" delete"); }
1200cf7f2e2dSJohn Marino 	|	OPERATOR NEW '[' ']'
1201cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (" new[]"); }
1202cf7f2e2dSJohn Marino 	|	OPERATOR DELETE '[' ']'
1203cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (" delete[]"); }
1204cf7f2e2dSJohn Marino 	|	OPERATOR '+'
1205cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("+"); }
1206cf7f2e2dSJohn Marino 	|	OPERATOR '-'
1207cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("-"); }
1208cf7f2e2dSJohn Marino 	|	OPERATOR '*'
1209cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("*"); }
1210cf7f2e2dSJohn Marino 	|	OPERATOR '/'
1211cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("/"); }
1212cf7f2e2dSJohn Marino 	|	OPERATOR '%'
1213cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("%"); }
1214cf7f2e2dSJohn Marino 	|	OPERATOR '^'
1215cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("^"); }
1216cf7f2e2dSJohn Marino 	|	OPERATOR '&'
1217cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("&"); }
1218cf7f2e2dSJohn Marino 	|	OPERATOR '|'
1219cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("|"); }
1220cf7f2e2dSJohn Marino 	|	OPERATOR '~'
1221cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("~"); }
1222cf7f2e2dSJohn Marino 	|	OPERATOR '!'
1223cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("!"); }
1224cf7f2e2dSJohn Marino 	|	OPERATOR '='
1225cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("="); }
1226cf7f2e2dSJohn Marino 	|	OPERATOR '<'
1227cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("<"); }
1228cf7f2e2dSJohn Marino 	|	OPERATOR '>'
1229cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (">"); }
1230cf7f2e2dSJohn Marino 	|	OPERATOR ASSIGN_MODIFY
1231cf7f2e2dSJohn Marino 			{ const char *op = "unknown";
1232cf7f2e2dSJohn Marino 			  switch ($2)
1233cf7f2e2dSJohn Marino 			    {
1234cf7f2e2dSJohn Marino 			    case BINOP_RSH:
1235cf7f2e2dSJohn Marino 			      op = ">>=";
1236cf7f2e2dSJohn Marino 			      break;
1237cf7f2e2dSJohn Marino 			    case BINOP_LSH:
1238cf7f2e2dSJohn Marino 			      op = "<<=";
1239cf7f2e2dSJohn Marino 			      break;
1240cf7f2e2dSJohn Marino 			    case BINOP_ADD:
1241cf7f2e2dSJohn Marino 			      op = "+=";
1242cf7f2e2dSJohn Marino 			      break;
1243cf7f2e2dSJohn Marino 			    case BINOP_SUB:
1244cf7f2e2dSJohn Marino 			      op = "-=";
1245cf7f2e2dSJohn Marino 			      break;
1246cf7f2e2dSJohn Marino 			    case BINOP_MUL:
1247cf7f2e2dSJohn Marino 			      op = "*=";
1248cf7f2e2dSJohn Marino 			      break;
1249cf7f2e2dSJohn Marino 			    case BINOP_DIV:
1250cf7f2e2dSJohn Marino 			      op = "/=";
1251cf7f2e2dSJohn Marino 			      break;
1252cf7f2e2dSJohn Marino 			    case BINOP_REM:
1253cf7f2e2dSJohn Marino 			      op = "%=";
1254cf7f2e2dSJohn Marino 			      break;
1255cf7f2e2dSJohn Marino 			    case BINOP_BITWISE_IOR:
1256cf7f2e2dSJohn Marino 			      op = "|=";
1257cf7f2e2dSJohn Marino 			      break;
1258cf7f2e2dSJohn Marino 			    case BINOP_BITWISE_AND:
1259cf7f2e2dSJohn Marino 			      op = "&=";
1260cf7f2e2dSJohn Marino 			      break;
1261cf7f2e2dSJohn Marino 			    case BINOP_BITWISE_XOR:
1262cf7f2e2dSJohn Marino 			      op = "^=";
1263cf7f2e2dSJohn Marino 			      break;
1264cf7f2e2dSJohn Marino 			    default:
1265cf7f2e2dSJohn Marino 			      break;
1266cf7f2e2dSJohn Marino 			    }
1267cf7f2e2dSJohn Marino 
1268cf7f2e2dSJohn Marino 			  $$ = operator_stoken (op);
1269cf7f2e2dSJohn Marino 			}
1270cf7f2e2dSJohn Marino 	|	OPERATOR LSH
1271cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("<<"); }
1272cf7f2e2dSJohn Marino 	|	OPERATOR RSH
1273cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (">>"); }
1274cf7f2e2dSJohn Marino 	|	OPERATOR EQUAL
1275cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("=="); }
1276cf7f2e2dSJohn Marino 	|	OPERATOR NOTEQUAL
1277cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("!="); }
1278cf7f2e2dSJohn Marino 	|	OPERATOR LEQ
1279cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("<="); }
1280cf7f2e2dSJohn Marino 	|	OPERATOR GEQ
1281cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (">="); }
1282cf7f2e2dSJohn Marino 	|	OPERATOR ANDAND
1283cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("&&"); }
1284cf7f2e2dSJohn Marino 	|	OPERATOR OROR
1285cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("||"); }
1286cf7f2e2dSJohn Marino 	|	OPERATOR INCREMENT
1287cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("++"); }
1288cf7f2e2dSJohn Marino 	|	OPERATOR DECREMENT
1289cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("--"); }
1290cf7f2e2dSJohn Marino 	|	OPERATOR ','
1291cf7f2e2dSJohn Marino 			{ $$ = operator_stoken (","); }
1292cf7f2e2dSJohn Marino 	|	OPERATOR ARROW_STAR
1293cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("->*"); }
1294cf7f2e2dSJohn Marino 	|	OPERATOR ARROW
1295cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("->"); }
1296cf7f2e2dSJohn Marino 	|	OPERATOR '(' ')'
1297cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("()"); }
1298cf7f2e2dSJohn Marino 	|	OPERATOR '[' ']'
1299cf7f2e2dSJohn Marino 			{ $$ = operator_stoken ("[]"); }
1300cf7f2e2dSJohn Marino 	|	OPERATOR ptype
1301cf7f2e2dSJohn Marino 			{ char *name;
1302cf7f2e2dSJohn Marino 			  long length;
1303cf7f2e2dSJohn Marino 			  struct ui_file *buf = mem_fileopen ();
1304cf7f2e2dSJohn Marino 
1305cf7f2e2dSJohn Marino 			  c_print_type ($2, NULL, buf, -1, 0);
1306cf7f2e2dSJohn Marino 			  name = ui_file_xstrdup (buf, &length);
1307cf7f2e2dSJohn Marino 			  ui_file_delete (buf);
1308cf7f2e2dSJohn Marino 			  $$ = operator_stoken (name);
1309cf7f2e2dSJohn Marino 			  free (name);
1310cf7f2e2dSJohn Marino 			}
1311cf7f2e2dSJohn Marino 	;
1312cf7f2e2dSJohn Marino 
1313cf7f2e2dSJohn Marino 
1314cf7f2e2dSJohn Marino 
13155796c8dcSSimon Schubert name	:	NAME { $$ = $1.stoken; }
13165796c8dcSSimon Schubert 	|	BLOCKNAME { $$ = $1.stoken; }
13175796c8dcSSimon Schubert 	|	TYPENAME { $$ = $1.stoken; }
13185796c8dcSSimon Schubert 	|	NAME_OR_INT  { $$ = $1.stoken; }
1319cf7f2e2dSJohn Marino 	|	UNKNOWN_CPP_NAME  { $$ = $1.stoken; }
1320cf7f2e2dSJohn Marino 	|	operator { $$ = $1; }
13215796c8dcSSimon Schubert 	;
13225796c8dcSSimon Schubert 
13235796c8dcSSimon Schubert name_not_typename :	NAME
13245796c8dcSSimon Schubert 	|	BLOCKNAME
13255796c8dcSSimon Schubert /* These would be useful if name_not_typename was useful, but it is just
13265796c8dcSSimon Schubert    a fake for "variable", so these cause reduce/reduce conflicts because
13275796c8dcSSimon Schubert    the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
13285796c8dcSSimon Schubert    =exp) or just an exp.  If name_not_typename was ever used in an lvalue
13295796c8dcSSimon Schubert    context where only a name could occur, this might be useful.
13305796c8dcSSimon Schubert   	|	NAME_OR_INT
13315796c8dcSSimon Schubert  */
1332cf7f2e2dSJohn Marino 	|	operator
1333cf7f2e2dSJohn Marino 			{
1334cf7f2e2dSJohn Marino 			  $$.stoken = $1;
1335cf7f2e2dSJohn Marino 			  $$.sym = lookup_symbol ($1.ptr,
1336cf7f2e2dSJohn Marino 						  expression_context_block,
1337cf7f2e2dSJohn Marino 						  VAR_DOMAIN,
1338cf7f2e2dSJohn Marino 						  &$$.is_a_field_of_this);
1339cf7f2e2dSJohn Marino 			}
1340cf7f2e2dSJohn Marino 	|	UNKNOWN_CPP_NAME
13415796c8dcSSimon Schubert 	;
13425796c8dcSSimon Schubert 
13435796c8dcSSimon Schubert %%
13445796c8dcSSimon Schubert 
1345cf7f2e2dSJohn Marino /* Returns a stoken of the operator name given by OP (which does not
1346cf7f2e2dSJohn Marino    include the string "operator").  */
1347cf7f2e2dSJohn Marino static struct stoken
1348cf7f2e2dSJohn Marino operator_stoken (const char *op)
1349cf7f2e2dSJohn Marino {
1350cf7f2e2dSJohn Marino   static const char *operator_string = "operator";
1351cf7f2e2dSJohn Marino   struct stoken st = { NULL, 0 };
1352cf7f2e2dSJohn Marino   st.length = strlen (operator_string) + strlen (op);
1353cf7f2e2dSJohn Marino   st.ptr = malloc (st.length + 1);
1354cf7f2e2dSJohn Marino   strcpy (st.ptr, operator_string);
1355cf7f2e2dSJohn Marino   strcat (st.ptr, op);
1356cf7f2e2dSJohn Marino 
1357cf7f2e2dSJohn Marino   /* The toplevel (c_parse) will free the memory allocated here.  */
1358cf7f2e2dSJohn Marino   make_cleanup (free, st.ptr);
1359cf7f2e2dSJohn Marino   return st;
1360cf7f2e2dSJohn Marino };
1361cf7f2e2dSJohn Marino 
13625796c8dcSSimon Schubert /* Take care of parsing a number (anything that starts with a digit).
13635796c8dcSSimon Schubert    Set yylval and return the token type; update lexptr.
13645796c8dcSSimon Schubert    LEN is the number of characters in it.  */
13655796c8dcSSimon Schubert 
13665796c8dcSSimon Schubert /*** Needs some error checking for the float case ***/
13675796c8dcSSimon Schubert 
13685796c8dcSSimon Schubert static int
13695796c8dcSSimon Schubert parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
13705796c8dcSSimon Schubert {
13715796c8dcSSimon Schubert   /* FIXME: Shouldn't these be unsigned?  We don't deal with negative values
13725796c8dcSSimon Schubert      here, and we do kind of silly things like cast to unsigned.  */
13735796c8dcSSimon Schubert   LONGEST n = 0;
13745796c8dcSSimon Schubert   LONGEST prevn = 0;
13755796c8dcSSimon Schubert   ULONGEST un;
13765796c8dcSSimon Schubert 
13775796c8dcSSimon Schubert   int i = 0;
13785796c8dcSSimon Schubert   int c;
13795796c8dcSSimon Schubert   int base = input_radix;
13805796c8dcSSimon Schubert   int unsigned_p = 0;
13815796c8dcSSimon Schubert 
13825796c8dcSSimon Schubert   /* Number of "L" suffixes encountered.  */
13835796c8dcSSimon Schubert   int long_p = 0;
13845796c8dcSSimon Schubert 
13855796c8dcSSimon Schubert   /* We have found a "L" or "U" suffix.  */
13865796c8dcSSimon Schubert   int found_suffix = 0;
13875796c8dcSSimon Schubert 
13885796c8dcSSimon Schubert   ULONGEST high_bit;
13895796c8dcSSimon Schubert   struct type *signed_type;
13905796c8dcSSimon Schubert   struct type *unsigned_type;
13915796c8dcSSimon Schubert 
13925796c8dcSSimon Schubert   if (parsed_float)
13935796c8dcSSimon Schubert     {
1394*c50c785cSJohn Marino       const char *suffix;
1395*c50c785cSJohn Marino       int suffix_len;
13965796c8dcSSimon Schubert 
13975796c8dcSSimon Schubert       /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
13985796c8dcSSimon Schubert          point.  Return DECFLOAT.  */
13995796c8dcSSimon Schubert 
14005796c8dcSSimon Schubert       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
14015796c8dcSSimon Schubert 	{
14025796c8dcSSimon Schubert 	  p[len - 2] = '\0';
14035796c8dcSSimon Schubert 	  putithere->typed_val_decfloat.type
14045796c8dcSSimon Schubert 	    = parse_type->builtin_decfloat;
14055796c8dcSSimon Schubert 	  decimal_from_string (putithere->typed_val_decfloat.val, 4,
14065796c8dcSSimon Schubert 			       gdbarch_byte_order (parse_gdbarch), p);
14075796c8dcSSimon Schubert 	  p[len - 2] = 'd';
14085796c8dcSSimon Schubert 	  return DECFLOAT;
14095796c8dcSSimon Schubert 	}
14105796c8dcSSimon Schubert 
14115796c8dcSSimon Schubert       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
14125796c8dcSSimon Schubert 	{
14135796c8dcSSimon Schubert 	  p[len - 2] = '\0';
14145796c8dcSSimon Schubert 	  putithere->typed_val_decfloat.type
14155796c8dcSSimon Schubert 	    = parse_type->builtin_decdouble;
14165796c8dcSSimon Schubert 	  decimal_from_string (putithere->typed_val_decfloat.val, 8,
14175796c8dcSSimon Schubert 			       gdbarch_byte_order (parse_gdbarch), p);
14185796c8dcSSimon Schubert 	  p[len - 2] = 'd';
14195796c8dcSSimon Schubert 	  return DECFLOAT;
14205796c8dcSSimon Schubert 	}
14215796c8dcSSimon Schubert 
14225796c8dcSSimon Schubert       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
14235796c8dcSSimon Schubert 	{
14245796c8dcSSimon Schubert 	  p[len - 2] = '\0';
14255796c8dcSSimon Schubert 	  putithere->typed_val_decfloat.type
14265796c8dcSSimon Schubert 	    = parse_type->builtin_declong;
14275796c8dcSSimon Schubert 	  decimal_from_string (putithere->typed_val_decfloat.val, 16,
14285796c8dcSSimon Schubert 			       gdbarch_byte_order (parse_gdbarch), p);
14295796c8dcSSimon Schubert 	  p[len - 2] = 'd';
14305796c8dcSSimon Schubert 	  return DECFLOAT;
14315796c8dcSSimon Schubert 	}
14325796c8dcSSimon Schubert 
1433*c50c785cSJohn Marino       if (! parse_c_float (parse_gdbarch, p, len,
1434*c50c785cSJohn Marino 			   &putithere->typed_val_float.dval,
1435*c50c785cSJohn Marino 			   &putithere->typed_val_float.type))
1436cf7f2e2dSJohn Marino 	return ERROR;
14375796c8dcSSimon Schubert       return FLOAT;
14385796c8dcSSimon Schubert     }
14395796c8dcSSimon Schubert 
14405796c8dcSSimon Schubert   /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
14415796c8dcSSimon Schubert   if (p[0] == '0')
14425796c8dcSSimon Schubert     switch (p[1])
14435796c8dcSSimon Schubert       {
14445796c8dcSSimon Schubert       case 'x':
14455796c8dcSSimon Schubert       case 'X':
14465796c8dcSSimon Schubert 	if (len >= 3)
14475796c8dcSSimon Schubert 	  {
14485796c8dcSSimon Schubert 	    p += 2;
14495796c8dcSSimon Schubert 	    base = 16;
14505796c8dcSSimon Schubert 	    len -= 2;
14515796c8dcSSimon Schubert 	  }
14525796c8dcSSimon Schubert 	break;
14535796c8dcSSimon Schubert 
1454cf7f2e2dSJohn Marino       case 'b':
1455cf7f2e2dSJohn Marino       case 'B':
1456cf7f2e2dSJohn Marino 	if (len >= 3)
1457cf7f2e2dSJohn Marino 	  {
1458cf7f2e2dSJohn Marino 	    p += 2;
1459cf7f2e2dSJohn Marino 	    base = 2;
1460cf7f2e2dSJohn Marino 	    len -= 2;
1461cf7f2e2dSJohn Marino 	  }
1462cf7f2e2dSJohn Marino 	break;
1463cf7f2e2dSJohn Marino 
14645796c8dcSSimon Schubert       case 't':
14655796c8dcSSimon Schubert       case 'T':
14665796c8dcSSimon Schubert       case 'd':
14675796c8dcSSimon Schubert       case 'D':
14685796c8dcSSimon Schubert 	if (len >= 3)
14695796c8dcSSimon Schubert 	  {
14705796c8dcSSimon Schubert 	    p += 2;
14715796c8dcSSimon Schubert 	    base = 10;
14725796c8dcSSimon Schubert 	    len -= 2;
14735796c8dcSSimon Schubert 	  }
14745796c8dcSSimon Schubert 	break;
14755796c8dcSSimon Schubert 
14765796c8dcSSimon Schubert       default:
14775796c8dcSSimon Schubert 	base = 8;
14785796c8dcSSimon Schubert 	break;
14795796c8dcSSimon Schubert       }
14805796c8dcSSimon Schubert 
14815796c8dcSSimon Schubert   while (len-- > 0)
14825796c8dcSSimon Schubert     {
14835796c8dcSSimon Schubert       c = *p++;
14845796c8dcSSimon Schubert       if (c >= 'A' && c <= 'Z')
14855796c8dcSSimon Schubert 	c += 'a' - 'A';
14865796c8dcSSimon Schubert       if (c != 'l' && c != 'u')
14875796c8dcSSimon Schubert 	n *= base;
14885796c8dcSSimon Schubert       if (c >= '0' && c <= '9')
14895796c8dcSSimon Schubert 	{
14905796c8dcSSimon Schubert 	  if (found_suffix)
14915796c8dcSSimon Schubert 	    return ERROR;
14925796c8dcSSimon Schubert 	  n += i = c - '0';
14935796c8dcSSimon Schubert 	}
14945796c8dcSSimon Schubert       else
14955796c8dcSSimon Schubert 	{
14965796c8dcSSimon Schubert 	  if (base > 10 && c >= 'a' && c <= 'f')
14975796c8dcSSimon Schubert 	    {
14985796c8dcSSimon Schubert 	      if (found_suffix)
14995796c8dcSSimon Schubert 		return ERROR;
15005796c8dcSSimon Schubert 	      n += i = c - 'a' + 10;
15015796c8dcSSimon Schubert 	    }
15025796c8dcSSimon Schubert 	  else if (c == 'l')
15035796c8dcSSimon Schubert 	    {
15045796c8dcSSimon Schubert 	      ++long_p;
15055796c8dcSSimon Schubert 	      found_suffix = 1;
15065796c8dcSSimon Schubert 	    }
15075796c8dcSSimon Schubert 	  else if (c == 'u')
15085796c8dcSSimon Schubert 	    {
15095796c8dcSSimon Schubert 	      unsigned_p = 1;
15105796c8dcSSimon Schubert 	      found_suffix = 1;
15115796c8dcSSimon Schubert 	    }
15125796c8dcSSimon Schubert 	  else
15135796c8dcSSimon Schubert 	    return ERROR;	/* Char not a digit */
15145796c8dcSSimon Schubert 	}
15155796c8dcSSimon Schubert       if (i >= base)
15165796c8dcSSimon Schubert 	return ERROR;		/* Invalid digit in this base */
15175796c8dcSSimon Schubert 
15185796c8dcSSimon Schubert       /* Portably test for overflow (only works for nonzero values, so make
15195796c8dcSSimon Schubert 	 a second check for zero).  FIXME: Can't we just make n and prevn
15205796c8dcSSimon Schubert 	 unsigned and avoid this?  */
15215796c8dcSSimon Schubert       if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
15225796c8dcSSimon Schubert 	unsigned_p = 1;		/* Try something unsigned */
15235796c8dcSSimon Schubert 
15245796c8dcSSimon Schubert       /* Portably test for unsigned overflow.
15255796c8dcSSimon Schubert 	 FIXME: This check is wrong; for example it doesn't find overflow
15265796c8dcSSimon Schubert 	 on 0x123456789 when LONGEST is 32 bits.  */
15275796c8dcSSimon Schubert       if (c != 'l' && c != 'u' && n != 0)
15285796c8dcSSimon Schubert 	{
15295796c8dcSSimon Schubert 	  if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1530*c50c785cSJohn Marino 	    error (_("Numeric constant too large."));
15315796c8dcSSimon Schubert 	}
15325796c8dcSSimon Schubert       prevn = n;
15335796c8dcSSimon Schubert     }
15345796c8dcSSimon Schubert 
15355796c8dcSSimon Schubert   /* An integer constant is an int, a long, or a long long.  An L
15365796c8dcSSimon Schubert      suffix forces it to be long; an LL suffix forces it to be long
15375796c8dcSSimon Schubert      long.  If not forced to a larger size, it gets the first type of
15385796c8dcSSimon Schubert      the above that it fits in.  To figure out whether it fits, we
15395796c8dcSSimon Schubert      shift it right and see whether anything remains.  Note that we
15405796c8dcSSimon Schubert      can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
15415796c8dcSSimon Schubert      operation, because many compilers will warn about such a shift
15425796c8dcSSimon Schubert      (which always produces a zero result).  Sometimes gdbarch_int_bit
15435796c8dcSSimon Schubert      or gdbarch_long_bit will be that big, sometimes not.  To deal with
15445796c8dcSSimon Schubert      the case where it is we just always shift the value more than
15455796c8dcSSimon Schubert      once, with fewer bits each time.  */
15465796c8dcSSimon Schubert 
15475796c8dcSSimon Schubert   un = (ULONGEST)n >> 2;
15485796c8dcSSimon Schubert   if (long_p == 0
15495796c8dcSSimon Schubert       && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
15505796c8dcSSimon Schubert     {
15515796c8dcSSimon Schubert       high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
15525796c8dcSSimon Schubert 
15535796c8dcSSimon Schubert       /* A large decimal (not hex or octal) constant (between INT_MAX
15545796c8dcSSimon Schubert 	 and UINT_MAX) is a long or unsigned long, according to ANSI,
15555796c8dcSSimon Schubert 	 never an unsigned int, but this code treats it as unsigned
15565796c8dcSSimon Schubert 	 int.  This probably should be fixed.  GCC gives a warning on
15575796c8dcSSimon Schubert 	 such constants.  */
15585796c8dcSSimon Schubert 
15595796c8dcSSimon Schubert       unsigned_type = parse_type->builtin_unsigned_int;
15605796c8dcSSimon Schubert       signed_type = parse_type->builtin_int;
15615796c8dcSSimon Schubert     }
15625796c8dcSSimon Schubert   else if (long_p <= 1
15635796c8dcSSimon Schubert 	   && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
15645796c8dcSSimon Schubert     {
15655796c8dcSSimon Schubert       high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
15665796c8dcSSimon Schubert       unsigned_type = parse_type->builtin_unsigned_long;
15675796c8dcSSimon Schubert       signed_type = parse_type->builtin_long;
15685796c8dcSSimon Schubert     }
15695796c8dcSSimon Schubert   else
15705796c8dcSSimon Schubert     {
15715796c8dcSSimon Schubert       int shift;
15725796c8dcSSimon Schubert       if (sizeof (ULONGEST) * HOST_CHAR_BIT
15735796c8dcSSimon Schubert 	  < gdbarch_long_long_bit (parse_gdbarch))
15745796c8dcSSimon Schubert 	/* A long long does not fit in a LONGEST.  */
15755796c8dcSSimon Schubert 	shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
15765796c8dcSSimon Schubert       else
15775796c8dcSSimon Schubert 	shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
15785796c8dcSSimon Schubert       high_bit = (ULONGEST) 1 << shift;
15795796c8dcSSimon Schubert       unsigned_type = parse_type->builtin_unsigned_long_long;
15805796c8dcSSimon Schubert       signed_type = parse_type->builtin_long_long;
15815796c8dcSSimon Schubert     }
15825796c8dcSSimon Schubert 
15835796c8dcSSimon Schubert    putithere->typed_val_int.val = n;
15845796c8dcSSimon Schubert 
15855796c8dcSSimon Schubert    /* If the high bit of the worked out type is set then this number
15865796c8dcSSimon Schubert       has to be unsigned. */
15875796c8dcSSimon Schubert 
15885796c8dcSSimon Schubert    if (unsigned_p || (n & high_bit))
15895796c8dcSSimon Schubert      {
15905796c8dcSSimon Schubert        putithere->typed_val_int.type = unsigned_type;
15915796c8dcSSimon Schubert      }
15925796c8dcSSimon Schubert    else
15935796c8dcSSimon Schubert      {
15945796c8dcSSimon Schubert        putithere->typed_val_int.type = signed_type;
15955796c8dcSSimon Schubert      }
15965796c8dcSSimon Schubert 
15975796c8dcSSimon Schubert    return INT;
15985796c8dcSSimon Schubert }
15995796c8dcSSimon Schubert 
16005796c8dcSSimon Schubert /* Temporary obstack used for holding strings.  */
16015796c8dcSSimon Schubert static struct obstack tempbuf;
16025796c8dcSSimon Schubert static int tempbuf_init;
16035796c8dcSSimon Schubert 
16045796c8dcSSimon Schubert /* Parse a C escape sequence.  The initial backslash of the sequence
16055796c8dcSSimon Schubert    is at (*PTR)[-1].  *PTR will be updated to point to just after the
16065796c8dcSSimon Schubert    last character of the sequence.  If OUTPUT is not NULL, the
16075796c8dcSSimon Schubert    translated form of the escape sequence will be written there.  If
16085796c8dcSSimon Schubert    OUTPUT is NULL, no output is written and the call will only affect
16095796c8dcSSimon Schubert    *PTR.  If an escape sequence is expressed in target bytes, then the
16105796c8dcSSimon Schubert    entire sequence will simply be copied to OUTPUT.  Return 1 if any
16115796c8dcSSimon Schubert    character was emitted, 0 otherwise.  */
16125796c8dcSSimon Schubert 
16135796c8dcSSimon Schubert int
16145796c8dcSSimon Schubert c_parse_escape (char **ptr, struct obstack *output)
16155796c8dcSSimon Schubert {
16165796c8dcSSimon Schubert   char *tokptr = *ptr;
16175796c8dcSSimon Schubert   int result = 1;
16185796c8dcSSimon Schubert 
16195796c8dcSSimon Schubert   /* Some escape sequences undergo character set conversion.  Those we
16205796c8dcSSimon Schubert      translate here.  */
16215796c8dcSSimon Schubert   switch (*tokptr)
16225796c8dcSSimon Schubert     {
16235796c8dcSSimon Schubert       /* Hex escapes do not undergo character set conversion, so keep
16245796c8dcSSimon Schubert 	 the escape sequence for later.  */
16255796c8dcSSimon Schubert     case 'x':
16265796c8dcSSimon Schubert       if (output)
16275796c8dcSSimon Schubert 	obstack_grow_str (output, "\\x");
16285796c8dcSSimon Schubert       ++tokptr;
16295796c8dcSSimon Schubert       if (!isxdigit (*tokptr))
16305796c8dcSSimon Schubert 	error (_("\\x escape without a following hex digit"));
16315796c8dcSSimon Schubert       while (isxdigit (*tokptr))
16325796c8dcSSimon Schubert 	{
16335796c8dcSSimon Schubert 	  if (output)
16345796c8dcSSimon Schubert 	    obstack_1grow (output, *tokptr);
16355796c8dcSSimon Schubert 	  ++tokptr;
16365796c8dcSSimon Schubert 	}
16375796c8dcSSimon Schubert       break;
16385796c8dcSSimon Schubert 
16395796c8dcSSimon Schubert       /* Octal escapes do not undergo character set conversion, so
16405796c8dcSSimon Schubert 	 keep the escape sequence for later.  */
16415796c8dcSSimon Schubert     case '0':
16425796c8dcSSimon Schubert     case '1':
16435796c8dcSSimon Schubert     case '2':
16445796c8dcSSimon Schubert     case '3':
16455796c8dcSSimon Schubert     case '4':
16465796c8dcSSimon Schubert     case '5':
16475796c8dcSSimon Schubert     case '6':
16485796c8dcSSimon Schubert     case '7':
16495796c8dcSSimon Schubert       {
16505796c8dcSSimon Schubert 	int i;
16515796c8dcSSimon Schubert 	if (output)
16525796c8dcSSimon Schubert 	  obstack_grow_str (output, "\\");
16535796c8dcSSimon Schubert 	for (i = 0;
16545796c8dcSSimon Schubert 	     i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
16555796c8dcSSimon Schubert 	     ++i)
16565796c8dcSSimon Schubert 	  {
16575796c8dcSSimon Schubert 	    if (output)
16585796c8dcSSimon Schubert 	      obstack_1grow (output, *tokptr);
16595796c8dcSSimon Schubert 	    ++tokptr;
16605796c8dcSSimon Schubert 	  }
16615796c8dcSSimon Schubert       }
16625796c8dcSSimon Schubert       break;
16635796c8dcSSimon Schubert 
16645796c8dcSSimon Schubert       /* We handle UCNs later.  We could handle them here, but that
16655796c8dcSSimon Schubert 	 would mean a spurious error in the case where the UCN could
16665796c8dcSSimon Schubert 	 be converted to the target charset but not the host
16675796c8dcSSimon Schubert 	 charset.  */
16685796c8dcSSimon Schubert     case 'u':
16695796c8dcSSimon Schubert     case 'U':
16705796c8dcSSimon Schubert       {
16715796c8dcSSimon Schubert 	char c = *tokptr;
16725796c8dcSSimon Schubert 	int i, len = c == 'U' ? 8 : 4;
16735796c8dcSSimon Schubert 	if (output)
16745796c8dcSSimon Schubert 	  {
16755796c8dcSSimon Schubert 	    obstack_1grow (output, '\\');
16765796c8dcSSimon Schubert 	    obstack_1grow (output, *tokptr);
16775796c8dcSSimon Schubert 	  }
16785796c8dcSSimon Schubert 	++tokptr;
16795796c8dcSSimon Schubert 	if (!isxdigit (*tokptr))
16805796c8dcSSimon Schubert 	  error (_("\\%c escape without a following hex digit"), c);
16815796c8dcSSimon Schubert 	for (i = 0; i < len && isxdigit (*tokptr); ++i)
16825796c8dcSSimon Schubert 	  {
16835796c8dcSSimon Schubert 	    if (output)
16845796c8dcSSimon Schubert 	      obstack_1grow (output, *tokptr);
16855796c8dcSSimon Schubert 	    ++tokptr;
16865796c8dcSSimon Schubert 	  }
16875796c8dcSSimon Schubert       }
16885796c8dcSSimon Schubert       break;
16895796c8dcSSimon Schubert 
16905796c8dcSSimon Schubert       /* We must pass backslash through so that it does not
16915796c8dcSSimon Schubert 	 cause quoting during the second expansion.  */
16925796c8dcSSimon Schubert     case '\\':
16935796c8dcSSimon Schubert       if (output)
16945796c8dcSSimon Schubert 	obstack_grow_str (output, "\\\\");
16955796c8dcSSimon Schubert       ++tokptr;
16965796c8dcSSimon Schubert       break;
16975796c8dcSSimon Schubert 
16985796c8dcSSimon Schubert       /* Escapes which undergo conversion.  */
16995796c8dcSSimon Schubert     case 'a':
17005796c8dcSSimon Schubert       if (output)
17015796c8dcSSimon Schubert 	obstack_1grow (output, '\a');
17025796c8dcSSimon Schubert       ++tokptr;
17035796c8dcSSimon Schubert       break;
17045796c8dcSSimon Schubert     case 'b':
17055796c8dcSSimon Schubert       if (output)
17065796c8dcSSimon Schubert 	obstack_1grow (output, '\b');
17075796c8dcSSimon Schubert       ++tokptr;
17085796c8dcSSimon Schubert       break;
17095796c8dcSSimon Schubert     case 'f':
17105796c8dcSSimon Schubert       if (output)
17115796c8dcSSimon Schubert 	obstack_1grow (output, '\f');
17125796c8dcSSimon Schubert       ++tokptr;
17135796c8dcSSimon Schubert       break;
17145796c8dcSSimon Schubert     case 'n':
17155796c8dcSSimon Schubert       if (output)
17165796c8dcSSimon Schubert 	obstack_1grow (output, '\n');
17175796c8dcSSimon Schubert       ++tokptr;
17185796c8dcSSimon Schubert       break;
17195796c8dcSSimon Schubert     case 'r':
17205796c8dcSSimon Schubert       if (output)
17215796c8dcSSimon Schubert 	obstack_1grow (output, '\r');
17225796c8dcSSimon Schubert       ++tokptr;
17235796c8dcSSimon Schubert       break;
17245796c8dcSSimon Schubert     case 't':
17255796c8dcSSimon Schubert       if (output)
17265796c8dcSSimon Schubert 	obstack_1grow (output, '\t');
17275796c8dcSSimon Schubert       ++tokptr;
17285796c8dcSSimon Schubert       break;
17295796c8dcSSimon Schubert     case 'v':
17305796c8dcSSimon Schubert       if (output)
17315796c8dcSSimon Schubert 	obstack_1grow (output, '\v');
17325796c8dcSSimon Schubert       ++tokptr;
17335796c8dcSSimon Schubert       break;
17345796c8dcSSimon Schubert 
17355796c8dcSSimon Schubert       /* GCC extension.  */
17365796c8dcSSimon Schubert     case 'e':
17375796c8dcSSimon Schubert       if (output)
17385796c8dcSSimon Schubert 	obstack_1grow (output, HOST_ESCAPE_CHAR);
17395796c8dcSSimon Schubert       ++tokptr;
17405796c8dcSSimon Schubert       break;
17415796c8dcSSimon Schubert 
17425796c8dcSSimon Schubert       /* Backslash-newline expands to nothing at all.  */
17435796c8dcSSimon Schubert     case '\n':
17445796c8dcSSimon Schubert       ++tokptr;
17455796c8dcSSimon Schubert       result = 0;
17465796c8dcSSimon Schubert       break;
17475796c8dcSSimon Schubert 
17485796c8dcSSimon Schubert       /* A few escapes just expand to the character itself.  */
17495796c8dcSSimon Schubert     case '\'':
17505796c8dcSSimon Schubert     case '\"':
17515796c8dcSSimon Schubert     case '?':
17525796c8dcSSimon Schubert       /* GCC extensions.  */
17535796c8dcSSimon Schubert     case '(':
17545796c8dcSSimon Schubert     case '{':
17555796c8dcSSimon Schubert     case '[':
17565796c8dcSSimon Schubert     case '%':
17575796c8dcSSimon Schubert       /* Unrecognized escapes turn into the character itself.  */
17585796c8dcSSimon Schubert     default:
17595796c8dcSSimon Schubert       if (output)
17605796c8dcSSimon Schubert 	obstack_1grow (output, *tokptr);
17615796c8dcSSimon Schubert       ++tokptr;
17625796c8dcSSimon Schubert       break;
17635796c8dcSSimon Schubert     }
17645796c8dcSSimon Schubert   *ptr = tokptr;
17655796c8dcSSimon Schubert   return result;
17665796c8dcSSimon Schubert }
17675796c8dcSSimon Schubert 
17685796c8dcSSimon Schubert /* Parse a string or character literal from TOKPTR.  The string or
17695796c8dcSSimon Schubert    character may be wide or unicode.  *OUTPTR is set to just after the
17705796c8dcSSimon Schubert    end of the literal in the input string.  The resulting token is
17715796c8dcSSimon Schubert    stored in VALUE.  This returns a token value, either STRING or
17725796c8dcSSimon Schubert    CHAR, depending on what was parsed.  *HOST_CHARS is set to the
17735796c8dcSSimon Schubert    number of host characters in the literal.  */
17745796c8dcSSimon Schubert static int
17755796c8dcSSimon Schubert parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
17765796c8dcSSimon Schubert 		      int *host_chars)
17775796c8dcSSimon Schubert {
1778cf7f2e2dSJohn Marino   int quote;
17795796c8dcSSimon Schubert   enum c_string_type type;
17805796c8dcSSimon Schubert 
17815796c8dcSSimon Schubert   /* Build the gdb internal form of the input string in tempbuf.  Note
17825796c8dcSSimon Schubert      that the buffer is null byte terminated *only* for the
17835796c8dcSSimon Schubert      convenience of debugging gdb itself and printing the buffer
17845796c8dcSSimon Schubert      contents when the buffer contains no embedded nulls.  Gdb does
17855796c8dcSSimon Schubert      not depend upon the buffer being null byte terminated, it uses
17865796c8dcSSimon Schubert      the length string instead.  This allows gdb to handle C strings
17875796c8dcSSimon Schubert      (as well as strings in other languages) with embedded null
17885796c8dcSSimon Schubert      bytes */
17895796c8dcSSimon Schubert 
17905796c8dcSSimon Schubert   if (!tempbuf_init)
17915796c8dcSSimon Schubert     tempbuf_init = 1;
17925796c8dcSSimon Schubert   else
17935796c8dcSSimon Schubert     obstack_free (&tempbuf, NULL);
17945796c8dcSSimon Schubert   obstack_init (&tempbuf);
17955796c8dcSSimon Schubert 
17965796c8dcSSimon Schubert   /* Record the string type.  */
17975796c8dcSSimon Schubert   if (*tokptr == 'L')
17985796c8dcSSimon Schubert     {
17995796c8dcSSimon Schubert       type = C_WIDE_STRING;
18005796c8dcSSimon Schubert       ++tokptr;
18015796c8dcSSimon Schubert     }
18025796c8dcSSimon Schubert   else if (*tokptr == 'u')
18035796c8dcSSimon Schubert     {
18045796c8dcSSimon Schubert       type = C_STRING_16;
18055796c8dcSSimon Schubert       ++tokptr;
18065796c8dcSSimon Schubert     }
18075796c8dcSSimon Schubert   else if (*tokptr == 'U')
18085796c8dcSSimon Schubert     {
18095796c8dcSSimon Schubert       type = C_STRING_32;
18105796c8dcSSimon Schubert       ++tokptr;
18115796c8dcSSimon Schubert     }
18125796c8dcSSimon Schubert   else
18135796c8dcSSimon Schubert     type = C_STRING;
18145796c8dcSSimon Schubert 
18155796c8dcSSimon Schubert   /* Skip the quote.  */
18165796c8dcSSimon Schubert   quote = *tokptr;
18175796c8dcSSimon Schubert   if (quote == '\'')
18185796c8dcSSimon Schubert     type |= C_CHAR;
18195796c8dcSSimon Schubert   ++tokptr;
18205796c8dcSSimon Schubert 
18215796c8dcSSimon Schubert   *host_chars = 0;
18225796c8dcSSimon Schubert 
18235796c8dcSSimon Schubert   while (*tokptr)
18245796c8dcSSimon Schubert     {
18255796c8dcSSimon Schubert       char c = *tokptr;
18265796c8dcSSimon Schubert       if (c == '\\')
18275796c8dcSSimon Schubert 	{
18285796c8dcSSimon Schubert 	  ++tokptr;
18295796c8dcSSimon Schubert 	  *host_chars += c_parse_escape (&tokptr, &tempbuf);
18305796c8dcSSimon Schubert 	}
18315796c8dcSSimon Schubert       else if (c == quote)
18325796c8dcSSimon Schubert 	break;
18335796c8dcSSimon Schubert       else
18345796c8dcSSimon Schubert 	{
18355796c8dcSSimon Schubert 	  obstack_1grow (&tempbuf, c);
18365796c8dcSSimon Schubert 	  ++tokptr;
18375796c8dcSSimon Schubert 	  /* FIXME: this does the wrong thing with multi-byte host
18385796c8dcSSimon Schubert 	     characters.  We could use mbrlen here, but that would
18395796c8dcSSimon Schubert 	     make "set host-charset" a bit less useful.  */
18405796c8dcSSimon Schubert 	  ++*host_chars;
18415796c8dcSSimon Schubert 	}
18425796c8dcSSimon Schubert     }
18435796c8dcSSimon Schubert 
18445796c8dcSSimon Schubert   if (*tokptr != quote)
18455796c8dcSSimon Schubert     {
18465796c8dcSSimon Schubert       if (quote == '"')
1847*c50c785cSJohn Marino 	error (_("Unterminated string in expression."));
18485796c8dcSSimon Schubert       else
1849*c50c785cSJohn Marino 	error (_("Unmatched single quote."));
18505796c8dcSSimon Schubert     }
18515796c8dcSSimon Schubert   ++tokptr;
18525796c8dcSSimon Schubert 
18535796c8dcSSimon Schubert   value->type = type;
18545796c8dcSSimon Schubert   value->ptr = obstack_base (&tempbuf);
18555796c8dcSSimon Schubert   value->length = obstack_object_size (&tempbuf);
18565796c8dcSSimon Schubert 
18575796c8dcSSimon Schubert   *outptr = tokptr;
18585796c8dcSSimon Schubert 
18595796c8dcSSimon Schubert   return quote == '"' ? STRING : CHAR;
18605796c8dcSSimon Schubert }
18615796c8dcSSimon Schubert 
18625796c8dcSSimon Schubert struct token
18635796c8dcSSimon Schubert {
18645796c8dcSSimon Schubert   char *operator;
18655796c8dcSSimon Schubert   int token;
18665796c8dcSSimon Schubert   enum exp_opcode opcode;
18675796c8dcSSimon Schubert   int cxx_only;
18685796c8dcSSimon Schubert };
18695796c8dcSSimon Schubert 
18705796c8dcSSimon Schubert static const struct token tokentab3[] =
18715796c8dcSSimon Schubert   {
18725796c8dcSSimon Schubert     {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
18735796c8dcSSimon Schubert     {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
18745796c8dcSSimon Schubert     {"->*", ARROW_STAR, BINOP_END, 1}
18755796c8dcSSimon Schubert   };
18765796c8dcSSimon Schubert 
18775796c8dcSSimon Schubert static const struct token tokentab2[] =
18785796c8dcSSimon Schubert   {
18795796c8dcSSimon Schubert     {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
18805796c8dcSSimon Schubert     {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
18815796c8dcSSimon Schubert     {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
18825796c8dcSSimon Schubert     {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
18835796c8dcSSimon Schubert     {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
18845796c8dcSSimon Schubert     {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
18855796c8dcSSimon Schubert     {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
18865796c8dcSSimon Schubert     {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
18875796c8dcSSimon Schubert     {"++", INCREMENT, BINOP_END, 0},
18885796c8dcSSimon Schubert     {"--", DECREMENT, BINOP_END, 0},
18895796c8dcSSimon Schubert     {"->", ARROW, BINOP_END, 0},
18905796c8dcSSimon Schubert     {"&&", ANDAND, BINOP_END, 0},
18915796c8dcSSimon Schubert     {"||", OROR, BINOP_END, 0},
18925796c8dcSSimon Schubert     /* "::" is *not* only C++: gdb overrides its meaning in several
18935796c8dcSSimon Schubert        different ways, e.g., 'filename'::func, function::variable.  */
18945796c8dcSSimon Schubert     {"::", COLONCOLON, BINOP_END, 0},
18955796c8dcSSimon Schubert     {"<<", LSH, BINOP_END, 0},
18965796c8dcSSimon Schubert     {">>", RSH, BINOP_END, 0},
18975796c8dcSSimon Schubert     {"==", EQUAL, BINOP_END, 0},
18985796c8dcSSimon Schubert     {"!=", NOTEQUAL, BINOP_END, 0},
18995796c8dcSSimon Schubert     {"<=", LEQ, BINOP_END, 0},
19005796c8dcSSimon Schubert     {">=", GEQ, BINOP_END, 0},
19015796c8dcSSimon Schubert     {".*", DOT_STAR, BINOP_END, 1}
19025796c8dcSSimon Schubert   };
19035796c8dcSSimon Schubert 
19045796c8dcSSimon Schubert /* Identifier-like tokens.  */
19055796c8dcSSimon Schubert static const struct token ident_tokens[] =
19065796c8dcSSimon Schubert   {
19075796c8dcSSimon Schubert     {"unsigned", UNSIGNED, OP_NULL, 0},
19085796c8dcSSimon Schubert     {"template", TEMPLATE, OP_NULL, 1},
19095796c8dcSSimon Schubert     {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
19105796c8dcSSimon Schubert     {"struct", STRUCT, OP_NULL, 0},
19115796c8dcSSimon Schubert     {"signed", SIGNED_KEYWORD, OP_NULL, 0},
19125796c8dcSSimon Schubert     {"sizeof", SIZEOF, OP_NULL, 0},
19135796c8dcSSimon Schubert     {"double", DOUBLE_KEYWORD, OP_NULL, 0},
19145796c8dcSSimon Schubert     {"false", FALSEKEYWORD, OP_NULL, 1},
19155796c8dcSSimon Schubert     {"class", CLASS, OP_NULL, 1},
19165796c8dcSSimon Schubert     {"union", UNION, OP_NULL, 0},
19175796c8dcSSimon Schubert     {"short", SHORT, OP_NULL, 0},
19185796c8dcSSimon Schubert     {"const", CONST_KEYWORD, OP_NULL, 0},
19195796c8dcSSimon Schubert     {"enum", ENUM, OP_NULL, 0},
19205796c8dcSSimon Schubert     {"long", LONG, OP_NULL, 0},
19215796c8dcSSimon Schubert     {"true", TRUEKEYWORD, OP_NULL, 1},
19225796c8dcSSimon Schubert     {"int", INT_KEYWORD, OP_NULL, 0},
1923cf7f2e2dSJohn Marino     {"new", NEW, OP_NULL, 1},
1924cf7f2e2dSJohn Marino     {"delete", DELETE, OP_NULL, 1},
1925cf7f2e2dSJohn Marino     {"operator", OPERATOR, OP_NULL, 1},
19265796c8dcSSimon Schubert 
19275796c8dcSSimon Schubert     {"and", ANDAND, BINOP_END, 1},
19285796c8dcSSimon Schubert     {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, 1},
19295796c8dcSSimon Schubert     {"bitand", '&', OP_NULL, 1},
19305796c8dcSSimon Schubert     {"bitor", '|', OP_NULL, 1},
19315796c8dcSSimon Schubert     {"compl", '~', OP_NULL, 1},
19325796c8dcSSimon Schubert     {"not", '!', OP_NULL, 1},
19335796c8dcSSimon Schubert     {"not_eq", NOTEQUAL, BINOP_END, 1},
19345796c8dcSSimon Schubert     {"or", OROR, BINOP_END, 1},
19355796c8dcSSimon Schubert     {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 1},
19365796c8dcSSimon Schubert     {"xor", '^', OP_NULL, 1},
1937cf7f2e2dSJohn Marino     {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 1},
1938cf7f2e2dSJohn Marino 
1939cf7f2e2dSJohn Marino     {"const_cast", CONST_CAST, OP_NULL, 1 },
1940cf7f2e2dSJohn Marino     {"dynamic_cast", DYNAMIC_CAST, OP_NULL, 1 },
1941cf7f2e2dSJohn Marino     {"static_cast", STATIC_CAST, OP_NULL, 1 },
1942cf7f2e2dSJohn Marino     {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, 1 }
19435796c8dcSSimon Schubert   };
19445796c8dcSSimon Schubert 
19455796c8dcSSimon Schubert /* When we find that lexptr (the global var defined in parse.c) is
19465796c8dcSSimon Schubert    pointing at a macro invocation, we expand the invocation, and call
19475796c8dcSSimon Schubert    scan_macro_expansion to save the old lexptr here and point lexptr
19485796c8dcSSimon Schubert    into the expanded text.  When we reach the end of that, we call
19495796c8dcSSimon Schubert    end_macro_expansion to pop back to the value we saved here.  The
19505796c8dcSSimon Schubert    macro expansion code promises to return only fully-expanded text,
19515796c8dcSSimon Schubert    so we don't need to "push" more than one level.
19525796c8dcSSimon Schubert 
19535796c8dcSSimon Schubert    This is disgusting, of course.  It would be cleaner to do all macro
19545796c8dcSSimon Schubert    expansion beforehand, and then hand that to lexptr.  But we don't
19555796c8dcSSimon Schubert    really know where the expression ends.  Remember, in a command like
19565796c8dcSSimon Schubert 
19575796c8dcSSimon Schubert      (gdb) break *ADDRESS if CONDITION
19585796c8dcSSimon Schubert 
19595796c8dcSSimon Schubert    we evaluate ADDRESS in the scope of the current frame, but we
19605796c8dcSSimon Schubert    evaluate CONDITION in the scope of the breakpoint's location.  So
19615796c8dcSSimon Schubert    it's simply wrong to try to macro-expand the whole thing at once.  */
19625796c8dcSSimon Schubert static char *macro_original_text;
19635796c8dcSSimon Schubert 
19645796c8dcSSimon Schubert /* We save all intermediate macro expansions on this obstack for the
19655796c8dcSSimon Schubert    duration of a single parse.  The expansion text may sometimes have
19665796c8dcSSimon Schubert    to live past the end of the expansion, due to yacc lookahead.
19675796c8dcSSimon Schubert    Rather than try to be clever about saving the data for a single
19685796c8dcSSimon Schubert    token, we simply keep it all and delete it after parsing has
19695796c8dcSSimon Schubert    completed.  */
19705796c8dcSSimon Schubert static struct obstack expansion_obstack;
19715796c8dcSSimon Schubert 
19725796c8dcSSimon Schubert static void
19735796c8dcSSimon Schubert scan_macro_expansion (char *expansion)
19745796c8dcSSimon Schubert {
19755796c8dcSSimon Schubert   char *copy;
19765796c8dcSSimon Schubert 
19775796c8dcSSimon Schubert   /* We'd better not be trying to push the stack twice.  */
19785796c8dcSSimon Schubert   gdb_assert (! macro_original_text);
19795796c8dcSSimon Schubert 
19805796c8dcSSimon Schubert   /* Copy to the obstack, and then free the intermediate
19815796c8dcSSimon Schubert      expansion.  */
19825796c8dcSSimon Schubert   copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
19835796c8dcSSimon Schubert   xfree (expansion);
19845796c8dcSSimon Schubert 
19855796c8dcSSimon Schubert   /* Save the old lexptr value, so we can return to it when we're done
19865796c8dcSSimon Schubert      parsing the expanded text.  */
19875796c8dcSSimon Schubert   macro_original_text = lexptr;
19885796c8dcSSimon Schubert   lexptr = copy;
19895796c8dcSSimon Schubert }
19905796c8dcSSimon Schubert 
19915796c8dcSSimon Schubert 
19925796c8dcSSimon Schubert static int
19935796c8dcSSimon Schubert scanning_macro_expansion (void)
19945796c8dcSSimon Schubert {
19955796c8dcSSimon Schubert   return macro_original_text != 0;
19965796c8dcSSimon Schubert }
19975796c8dcSSimon Schubert 
19985796c8dcSSimon Schubert 
19995796c8dcSSimon Schubert static void
20005796c8dcSSimon Schubert finished_macro_expansion (void)
20015796c8dcSSimon Schubert {
20025796c8dcSSimon Schubert   /* There'd better be something to pop back to.  */
20035796c8dcSSimon Schubert   gdb_assert (macro_original_text);
20045796c8dcSSimon Schubert 
20055796c8dcSSimon Schubert   /* Pop back to the original text.  */
20065796c8dcSSimon Schubert   lexptr = macro_original_text;
20075796c8dcSSimon Schubert   macro_original_text = 0;
20085796c8dcSSimon Schubert }
20095796c8dcSSimon Schubert 
20105796c8dcSSimon Schubert 
20115796c8dcSSimon Schubert static void
20125796c8dcSSimon Schubert scan_macro_cleanup (void *dummy)
20135796c8dcSSimon Schubert {
20145796c8dcSSimon Schubert   if (macro_original_text)
20155796c8dcSSimon Schubert     finished_macro_expansion ();
20165796c8dcSSimon Schubert 
20175796c8dcSSimon Schubert   obstack_free (&expansion_obstack, NULL);
20185796c8dcSSimon Schubert }
20195796c8dcSSimon Schubert 
2020cf7f2e2dSJohn Marino /* Return true iff the token represents a C++ cast operator.  */
2021cf7f2e2dSJohn Marino 
2022cf7f2e2dSJohn Marino static int
2023cf7f2e2dSJohn Marino is_cast_operator (const char *token, int len)
2024cf7f2e2dSJohn Marino {
2025cf7f2e2dSJohn Marino   return (! strncmp (token, "dynamic_cast", len)
2026cf7f2e2dSJohn Marino 	  || ! strncmp (token, "static_cast", len)
2027cf7f2e2dSJohn Marino 	  || ! strncmp (token, "reinterpret_cast", len)
2028cf7f2e2dSJohn Marino 	  || ! strncmp (token, "const_cast", len));
2029cf7f2e2dSJohn Marino }
20305796c8dcSSimon Schubert 
20315796c8dcSSimon Schubert /* The scope used for macro expansion.  */
20325796c8dcSSimon Schubert static struct macro_scope *expression_macro_scope;
20335796c8dcSSimon Schubert 
20345796c8dcSSimon Schubert /* This is set if a NAME token appeared at the very end of the input
20355796c8dcSSimon Schubert    string, with no whitespace separating the name from the EOF.  This
20365796c8dcSSimon Schubert    is used only when parsing to do field name completion.  */
20375796c8dcSSimon Schubert static int saw_name_at_eof;
20385796c8dcSSimon Schubert 
20395796c8dcSSimon Schubert /* This is set if the previously-returned token was a structure
20405796c8dcSSimon Schubert    operator -- either '.' or ARROW.  This is used only when parsing to
20415796c8dcSSimon Schubert    do field name completion.  */
20425796c8dcSSimon Schubert static int last_was_structop;
20435796c8dcSSimon Schubert 
20445796c8dcSSimon Schubert /* Read one token, getting characters through lexptr.  */
20455796c8dcSSimon Schubert 
20465796c8dcSSimon Schubert static int
2047cf7f2e2dSJohn Marino lex_one_token (void)
20485796c8dcSSimon Schubert {
20495796c8dcSSimon Schubert   int c;
20505796c8dcSSimon Schubert   int namelen;
20515796c8dcSSimon Schubert   unsigned int i;
20525796c8dcSSimon Schubert   char *tokstart;
20535796c8dcSSimon Schubert   int saw_structop = last_was_structop;
20545796c8dcSSimon Schubert   char *copy;
20555796c8dcSSimon Schubert 
20565796c8dcSSimon Schubert   last_was_structop = 0;
20575796c8dcSSimon Schubert 
20585796c8dcSSimon Schubert  retry:
20595796c8dcSSimon Schubert 
20605796c8dcSSimon Schubert   /* Check if this is a macro invocation that we need to expand.  */
20615796c8dcSSimon Schubert   if (! scanning_macro_expansion ())
20625796c8dcSSimon Schubert     {
20635796c8dcSSimon Schubert       char *expanded = macro_expand_next (&lexptr,
20645796c8dcSSimon Schubert                                           standard_macro_lookup,
20655796c8dcSSimon Schubert                                           expression_macro_scope);
20665796c8dcSSimon Schubert 
20675796c8dcSSimon Schubert       if (expanded)
20685796c8dcSSimon Schubert         scan_macro_expansion (expanded);
20695796c8dcSSimon Schubert     }
20705796c8dcSSimon Schubert 
20715796c8dcSSimon Schubert   prev_lexptr = lexptr;
20725796c8dcSSimon Schubert 
20735796c8dcSSimon Schubert   tokstart = lexptr;
20745796c8dcSSimon Schubert   /* See if it is a special token of length 3.  */
20755796c8dcSSimon Schubert   for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
20765796c8dcSSimon Schubert     if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
20775796c8dcSSimon Schubert       {
20785796c8dcSSimon Schubert 	if (tokentab3[i].cxx_only
20795796c8dcSSimon Schubert 	    && parse_language->la_language != language_cplus)
20805796c8dcSSimon Schubert 	  break;
20815796c8dcSSimon Schubert 
20825796c8dcSSimon Schubert 	lexptr += 3;
20835796c8dcSSimon Schubert 	yylval.opcode = tokentab3[i].opcode;
20845796c8dcSSimon Schubert 	return tokentab3[i].token;
20855796c8dcSSimon Schubert       }
20865796c8dcSSimon Schubert 
20875796c8dcSSimon Schubert   /* See if it is a special token of length 2.  */
20885796c8dcSSimon Schubert   for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
20895796c8dcSSimon Schubert     if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
20905796c8dcSSimon Schubert       {
20915796c8dcSSimon Schubert 	if (tokentab2[i].cxx_only
20925796c8dcSSimon Schubert 	    && parse_language->la_language != language_cplus)
20935796c8dcSSimon Schubert 	  break;
20945796c8dcSSimon Schubert 
20955796c8dcSSimon Schubert 	lexptr += 2;
20965796c8dcSSimon Schubert 	yylval.opcode = tokentab2[i].opcode;
20975796c8dcSSimon Schubert 	if (in_parse_field && tokentab2[i].token == ARROW)
20985796c8dcSSimon Schubert 	  last_was_structop = 1;
20995796c8dcSSimon Schubert 	return tokentab2[i].token;
21005796c8dcSSimon Schubert       }
21015796c8dcSSimon Schubert 
21025796c8dcSSimon Schubert   switch (c = *tokstart)
21035796c8dcSSimon Schubert     {
21045796c8dcSSimon Schubert     case 0:
21055796c8dcSSimon Schubert       /* If we were just scanning the result of a macro expansion,
21065796c8dcSSimon Schubert          then we need to resume scanning the original text.
21075796c8dcSSimon Schubert 	 If we're parsing for field name completion, and the previous
21085796c8dcSSimon Schubert 	 token allows such completion, return a COMPLETE token.
21095796c8dcSSimon Schubert          Otherwise, we were already scanning the original text, and
21105796c8dcSSimon Schubert          we're really done.  */
21115796c8dcSSimon Schubert       if (scanning_macro_expansion ())
21125796c8dcSSimon Schubert         {
21135796c8dcSSimon Schubert           finished_macro_expansion ();
21145796c8dcSSimon Schubert           goto retry;
21155796c8dcSSimon Schubert         }
21165796c8dcSSimon Schubert       else if (saw_name_at_eof)
21175796c8dcSSimon Schubert 	{
21185796c8dcSSimon Schubert 	  saw_name_at_eof = 0;
21195796c8dcSSimon Schubert 	  return COMPLETE;
21205796c8dcSSimon Schubert 	}
21215796c8dcSSimon Schubert       else if (saw_structop)
21225796c8dcSSimon Schubert 	return COMPLETE;
21235796c8dcSSimon Schubert       else
21245796c8dcSSimon Schubert         return 0;
21255796c8dcSSimon Schubert 
21265796c8dcSSimon Schubert     case ' ':
21275796c8dcSSimon Schubert     case '\t':
21285796c8dcSSimon Schubert     case '\n':
21295796c8dcSSimon Schubert       lexptr++;
21305796c8dcSSimon Schubert       goto retry;
21315796c8dcSSimon Schubert 
21325796c8dcSSimon Schubert     case '[':
21335796c8dcSSimon Schubert     case '(':
21345796c8dcSSimon Schubert       paren_depth++;
21355796c8dcSSimon Schubert       lexptr++;
21365796c8dcSSimon Schubert       return c;
21375796c8dcSSimon Schubert 
21385796c8dcSSimon Schubert     case ']':
21395796c8dcSSimon Schubert     case ')':
21405796c8dcSSimon Schubert       if (paren_depth == 0)
21415796c8dcSSimon Schubert 	return 0;
21425796c8dcSSimon Schubert       paren_depth--;
21435796c8dcSSimon Schubert       lexptr++;
21445796c8dcSSimon Schubert       return c;
21455796c8dcSSimon Schubert 
21465796c8dcSSimon Schubert     case ',':
21475796c8dcSSimon Schubert       if (comma_terminates
21485796c8dcSSimon Schubert           && paren_depth == 0
21495796c8dcSSimon Schubert           && ! scanning_macro_expansion ())
21505796c8dcSSimon Schubert 	return 0;
21515796c8dcSSimon Schubert       lexptr++;
21525796c8dcSSimon Schubert       return c;
21535796c8dcSSimon Schubert 
21545796c8dcSSimon Schubert     case '.':
21555796c8dcSSimon Schubert       /* Might be a floating point number.  */
21565796c8dcSSimon Schubert       if (lexptr[1] < '0' || lexptr[1] > '9')
21575796c8dcSSimon Schubert 	{
21585796c8dcSSimon Schubert 	  if (in_parse_field)
21595796c8dcSSimon Schubert 	    last_was_structop = 1;
21605796c8dcSSimon Schubert 	  goto symbol;		/* Nope, must be a symbol. */
21615796c8dcSSimon Schubert 	}
21625796c8dcSSimon Schubert       /* FALL THRU into number case.  */
21635796c8dcSSimon Schubert 
21645796c8dcSSimon Schubert     case '0':
21655796c8dcSSimon Schubert     case '1':
21665796c8dcSSimon Schubert     case '2':
21675796c8dcSSimon Schubert     case '3':
21685796c8dcSSimon Schubert     case '4':
21695796c8dcSSimon Schubert     case '5':
21705796c8dcSSimon Schubert     case '6':
21715796c8dcSSimon Schubert     case '7':
21725796c8dcSSimon Schubert     case '8':
21735796c8dcSSimon Schubert     case '9':
21745796c8dcSSimon Schubert       {
21755796c8dcSSimon Schubert 	/* It's a number.  */
21765796c8dcSSimon Schubert 	int got_dot = 0, got_e = 0, toktype;
21775796c8dcSSimon Schubert 	char *p = tokstart;
21785796c8dcSSimon Schubert 	int hex = input_radix > 10;
21795796c8dcSSimon Schubert 
21805796c8dcSSimon Schubert 	if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
21815796c8dcSSimon Schubert 	  {
21825796c8dcSSimon Schubert 	    p += 2;
21835796c8dcSSimon Schubert 	    hex = 1;
21845796c8dcSSimon Schubert 	  }
21855796c8dcSSimon Schubert 	else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
21865796c8dcSSimon Schubert 	  {
21875796c8dcSSimon Schubert 	    p += 2;
21885796c8dcSSimon Schubert 	    hex = 0;
21895796c8dcSSimon Schubert 	  }
21905796c8dcSSimon Schubert 
21915796c8dcSSimon Schubert 	for (;; ++p)
21925796c8dcSSimon Schubert 	  {
21935796c8dcSSimon Schubert 	    /* This test includes !hex because 'e' is a valid hex digit
21945796c8dcSSimon Schubert 	       and thus does not indicate a floating point number when
21955796c8dcSSimon Schubert 	       the radix is hex.  */
21965796c8dcSSimon Schubert 	    if (!hex && !got_e && (*p == 'e' || *p == 'E'))
21975796c8dcSSimon Schubert 	      got_dot = got_e = 1;
21985796c8dcSSimon Schubert 	    /* This test does not include !hex, because a '.' always indicates
21995796c8dcSSimon Schubert 	       a decimal floating point number regardless of the radix.  */
22005796c8dcSSimon Schubert 	    else if (!got_dot && *p == '.')
22015796c8dcSSimon Schubert 	      got_dot = 1;
22025796c8dcSSimon Schubert 	    else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
22035796c8dcSSimon Schubert 		     && (*p == '-' || *p == '+'))
22045796c8dcSSimon Schubert 	      /* This is the sign of the exponent, not the end of the
22055796c8dcSSimon Schubert 		 number.  */
22065796c8dcSSimon Schubert 	      continue;
22075796c8dcSSimon Schubert 	    /* We will take any letters or digits.  parse_number will
22085796c8dcSSimon Schubert 	       complain if past the radix, or if L or U are not final.  */
22095796c8dcSSimon Schubert 	    else if ((*p < '0' || *p > '9')
22105796c8dcSSimon Schubert 		     && ((*p < 'a' || *p > 'z')
22115796c8dcSSimon Schubert 				  && (*p < 'A' || *p > 'Z')))
22125796c8dcSSimon Schubert 	      break;
22135796c8dcSSimon Schubert 	  }
22145796c8dcSSimon Schubert 	toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
22155796c8dcSSimon Schubert         if (toktype == ERROR)
22165796c8dcSSimon Schubert 	  {
22175796c8dcSSimon Schubert 	    char *err_copy = (char *) alloca (p - tokstart + 1);
22185796c8dcSSimon Schubert 
22195796c8dcSSimon Schubert 	    memcpy (err_copy, tokstart, p - tokstart);
22205796c8dcSSimon Schubert 	    err_copy[p - tokstart] = 0;
2221*c50c785cSJohn Marino 	    error (_("Invalid number \"%s\"."), err_copy);
22225796c8dcSSimon Schubert 	  }
22235796c8dcSSimon Schubert 	lexptr = p;
22245796c8dcSSimon Schubert 	return toktype;
22255796c8dcSSimon Schubert       }
22265796c8dcSSimon Schubert 
22275796c8dcSSimon Schubert     case '+':
22285796c8dcSSimon Schubert     case '-':
22295796c8dcSSimon Schubert     case '*':
22305796c8dcSSimon Schubert     case '/':
22315796c8dcSSimon Schubert     case '%':
22325796c8dcSSimon Schubert     case '|':
22335796c8dcSSimon Schubert     case '&':
22345796c8dcSSimon Schubert     case '^':
22355796c8dcSSimon Schubert     case '~':
22365796c8dcSSimon Schubert     case '!':
22375796c8dcSSimon Schubert     case '@':
22385796c8dcSSimon Schubert     case '<':
22395796c8dcSSimon Schubert     case '>':
22405796c8dcSSimon Schubert     case '?':
22415796c8dcSSimon Schubert     case ':':
22425796c8dcSSimon Schubert     case '=':
22435796c8dcSSimon Schubert     case '{':
22445796c8dcSSimon Schubert     case '}':
22455796c8dcSSimon Schubert     symbol:
22465796c8dcSSimon Schubert       lexptr++;
22475796c8dcSSimon Schubert       return c;
22485796c8dcSSimon Schubert 
22495796c8dcSSimon Schubert     case 'L':
22505796c8dcSSimon Schubert     case 'u':
22515796c8dcSSimon Schubert     case 'U':
22525796c8dcSSimon Schubert       if (tokstart[1] != '"' && tokstart[1] != '\'')
22535796c8dcSSimon Schubert 	break;
22545796c8dcSSimon Schubert       /* Fall through.  */
22555796c8dcSSimon Schubert     case '\'':
22565796c8dcSSimon Schubert     case '"':
22575796c8dcSSimon Schubert       {
22585796c8dcSSimon Schubert 	int host_len;
22595796c8dcSSimon Schubert 	int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
22605796c8dcSSimon Schubert 					   &host_len);
22615796c8dcSSimon Schubert 	if (result == CHAR)
22625796c8dcSSimon Schubert 	  {
22635796c8dcSSimon Schubert 	    if (host_len == 0)
2264*c50c785cSJohn Marino 	      error (_("Empty character constant."));
22655796c8dcSSimon Schubert 	    else if (host_len > 2 && c == '\'')
22665796c8dcSSimon Schubert 	      {
22675796c8dcSSimon Schubert 		++tokstart;
22685796c8dcSSimon Schubert 		namelen = lexptr - tokstart - 1;
22695796c8dcSSimon Schubert 		goto tryname;
22705796c8dcSSimon Schubert 	      }
22715796c8dcSSimon Schubert 	    else if (host_len > 1)
2272*c50c785cSJohn Marino 	      error (_("Invalid character constant."));
22735796c8dcSSimon Schubert 	  }
22745796c8dcSSimon Schubert 	return result;
22755796c8dcSSimon Schubert       }
22765796c8dcSSimon Schubert     }
22775796c8dcSSimon Schubert 
22785796c8dcSSimon Schubert   if (!(c == '_' || c == '$'
22795796c8dcSSimon Schubert 	|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
22805796c8dcSSimon Schubert     /* We must have come across a bad character (e.g. ';').  */
2281*c50c785cSJohn Marino     error (_("Invalid character '%c' in expression."), c);
22825796c8dcSSimon Schubert 
22835796c8dcSSimon Schubert   /* It's a name.  See how long it is.  */
22845796c8dcSSimon Schubert   namelen = 0;
22855796c8dcSSimon Schubert   for (c = tokstart[namelen];
22865796c8dcSSimon Schubert        (c == '_' || c == '$' || (c >= '0' && c <= '9')
22875796c8dcSSimon Schubert 	|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
22885796c8dcSSimon Schubert     {
22895796c8dcSSimon Schubert       /* Template parameter lists are part of the name.
22905796c8dcSSimon Schubert 	 FIXME: This mishandles `print $a<4&&$a>3'.  */
22915796c8dcSSimon Schubert 
22925796c8dcSSimon Schubert       if (c == '<')
22935796c8dcSSimon Schubert 	{
2294cf7f2e2dSJohn Marino 	  if (! is_cast_operator (tokstart, namelen))
2295cf7f2e2dSJohn Marino 	    {
22965796c8dcSSimon Schubert 	      /* Scan ahead to get rest of the template specification.  Note
22975796c8dcSSimon Schubert 		 that we look ahead only when the '<' adjoins non-whitespace
22985796c8dcSSimon Schubert 		 characters; for comparison expressions, e.g. "a < b > c",
22995796c8dcSSimon Schubert 		 there must be spaces before the '<', etc. */
23005796c8dcSSimon Schubert 
23015796c8dcSSimon Schubert 	      char * p = find_template_name_end (tokstart + namelen);
23025796c8dcSSimon Schubert 	      if (p)
23035796c8dcSSimon Schubert 		namelen = p - tokstart;
2304cf7f2e2dSJohn Marino 	    }
23055796c8dcSSimon Schubert 	  break;
23065796c8dcSSimon Schubert 	}
23075796c8dcSSimon Schubert       c = tokstart[++namelen];
23085796c8dcSSimon Schubert     }
23095796c8dcSSimon Schubert 
23105796c8dcSSimon Schubert   /* The token "if" terminates the expression and is NOT removed from
23115796c8dcSSimon Schubert      the input stream.  It doesn't count if it appears in the
23125796c8dcSSimon Schubert      expansion of a macro.  */
23135796c8dcSSimon Schubert   if (namelen == 2
23145796c8dcSSimon Schubert       && tokstart[0] == 'i'
23155796c8dcSSimon Schubert       && tokstart[1] == 'f'
23165796c8dcSSimon Schubert       && ! scanning_macro_expansion ())
23175796c8dcSSimon Schubert     {
23185796c8dcSSimon Schubert       return 0;
23195796c8dcSSimon Schubert     }
23205796c8dcSSimon Schubert 
2321cf7f2e2dSJohn Marino   /* For the same reason (breakpoint conditions), "thread N"
2322cf7f2e2dSJohn Marino      terminates the expression.  "thread" could be an identifier, but
2323cf7f2e2dSJohn Marino      an identifier is never followed by a number without intervening
2324cf7f2e2dSJohn Marino      punctuation.  "task" is similar.  Handle abbreviations of these,
2325cf7f2e2dSJohn Marino      similarly to breakpoint.c:find_condition_and_thread.  */
2326cf7f2e2dSJohn Marino   if (namelen >= 1
2327cf7f2e2dSJohn Marino       && (strncmp (tokstart, "thread", namelen) == 0
2328cf7f2e2dSJohn Marino 	  || strncmp (tokstart, "task", namelen) == 0)
2329cf7f2e2dSJohn Marino       && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
2330cf7f2e2dSJohn Marino       && ! scanning_macro_expansion ())
2331cf7f2e2dSJohn Marino     {
2332cf7f2e2dSJohn Marino       char *p = tokstart + namelen + 1;
2333cf7f2e2dSJohn Marino       while (*p == ' ' || *p == '\t')
2334cf7f2e2dSJohn Marino 	p++;
2335cf7f2e2dSJohn Marino       if (*p >= '0' && *p <= '9')
2336cf7f2e2dSJohn Marino 	return 0;
2337cf7f2e2dSJohn Marino     }
2338cf7f2e2dSJohn Marino 
23395796c8dcSSimon Schubert   lexptr += namelen;
23405796c8dcSSimon Schubert 
23415796c8dcSSimon Schubert   tryname:
23425796c8dcSSimon Schubert 
23435796c8dcSSimon Schubert   yylval.sval.ptr = tokstart;
23445796c8dcSSimon Schubert   yylval.sval.length = namelen;
23455796c8dcSSimon Schubert 
23465796c8dcSSimon Schubert   /* Catch specific keywords.  */
23475796c8dcSSimon Schubert   copy = copy_name (yylval.sval);
23485796c8dcSSimon Schubert   for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
23495796c8dcSSimon Schubert     if (strcmp (copy, ident_tokens[i].operator) == 0)
23505796c8dcSSimon Schubert       {
23515796c8dcSSimon Schubert 	if (ident_tokens[i].cxx_only
23525796c8dcSSimon Schubert 	    && parse_language->la_language != language_cplus)
23535796c8dcSSimon Schubert 	  break;
23545796c8dcSSimon Schubert 
23555796c8dcSSimon Schubert 	/* It is ok to always set this, even though we don't always
23565796c8dcSSimon Schubert 	   strictly need to.  */
23575796c8dcSSimon Schubert 	yylval.opcode = ident_tokens[i].opcode;
23585796c8dcSSimon Schubert 	return ident_tokens[i].token;
23595796c8dcSSimon Schubert       }
23605796c8dcSSimon Schubert 
23615796c8dcSSimon Schubert   if (*tokstart == '$')
23625796c8dcSSimon Schubert     return VARIABLE;
2363cf7f2e2dSJohn Marino 
2364cf7f2e2dSJohn Marino   if (in_parse_field && *lexptr == '\0')
2365cf7f2e2dSJohn Marino     saw_name_at_eof = 1;
2366cf7f2e2dSJohn Marino   return NAME;
23675796c8dcSSimon Schubert }
23685796c8dcSSimon Schubert 
2369cf7f2e2dSJohn Marino /* An object of this type is pushed on a FIFO by the "outer" lexer.  */
2370cf7f2e2dSJohn Marino typedef struct
2371cf7f2e2dSJohn Marino {
2372cf7f2e2dSJohn Marino   int token;
2373cf7f2e2dSJohn Marino   YYSTYPE value;
2374cf7f2e2dSJohn Marino } token_and_value;
2375cf7f2e2dSJohn Marino 
2376cf7f2e2dSJohn Marino DEF_VEC_O (token_and_value);
2377cf7f2e2dSJohn Marino 
2378cf7f2e2dSJohn Marino /* A FIFO of tokens that have been read but not yet returned to the
2379cf7f2e2dSJohn Marino    parser.  */
2380cf7f2e2dSJohn Marino static VEC (token_and_value) *token_fifo;
2381cf7f2e2dSJohn Marino 
2382cf7f2e2dSJohn Marino /* Non-zero if the lexer should return tokens from the FIFO.  */
2383cf7f2e2dSJohn Marino static int popping;
2384cf7f2e2dSJohn Marino 
2385cf7f2e2dSJohn Marino /* Temporary storage for c_lex; this holds symbol names as they are
2386cf7f2e2dSJohn Marino    built up.  */
2387cf7f2e2dSJohn Marino static struct obstack name_obstack;
2388cf7f2e2dSJohn Marino 
2389cf7f2e2dSJohn Marino /* Classify a NAME token.  The contents of the token are in `yylval'.
2390cf7f2e2dSJohn Marino    Updates yylval and returns the new token type.  BLOCK is the block
2391cf7f2e2dSJohn Marino    in which lookups start; this can be NULL to mean the global
2392cf7f2e2dSJohn Marino    scope.  */
2393cf7f2e2dSJohn Marino static int
2394cf7f2e2dSJohn Marino classify_name (struct block *block)
23955796c8dcSSimon Schubert {
23965796c8dcSSimon Schubert   struct symbol *sym;
2397cf7f2e2dSJohn Marino   char *copy;
23985796c8dcSSimon Schubert   int is_a_field_of_this = 0;
23995796c8dcSSimon Schubert 
2400cf7f2e2dSJohn Marino   copy = copy_name (yylval.sval);
2401cf7f2e2dSJohn Marino 
2402cf7f2e2dSJohn Marino   sym = lookup_symbol (copy, block, VAR_DOMAIN,
24035796c8dcSSimon Schubert 		       parse_language->la_language == language_cplus
24045796c8dcSSimon Schubert 		       ? &is_a_field_of_this : (int *) NULL);
2405cf7f2e2dSJohn Marino 
24065796c8dcSSimon Schubert   if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
24075796c8dcSSimon Schubert     {
24085796c8dcSSimon Schubert       yylval.ssym.sym = sym;
24095796c8dcSSimon Schubert       yylval.ssym.is_a_field_of_this = is_a_field_of_this;
24105796c8dcSSimon Schubert       return BLOCKNAME;
24115796c8dcSSimon Schubert     }
24125796c8dcSSimon Schubert   else if (!sym)
2413cf7f2e2dSJohn Marino     {
2414cf7f2e2dSJohn Marino       /* See if it's a file name. */
24155796c8dcSSimon Schubert       struct symtab *symtab;
24165796c8dcSSimon Schubert 
24175796c8dcSSimon Schubert       symtab = lookup_symtab (copy);
24185796c8dcSSimon Schubert       if (symtab)
24195796c8dcSSimon Schubert 	{
24205796c8dcSSimon Schubert 	  yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
24215796c8dcSSimon Schubert 	  return FILENAME;
24225796c8dcSSimon Schubert 	}
24235796c8dcSSimon Schubert     }
24245796c8dcSSimon Schubert 
24255796c8dcSSimon Schubert   if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
24265796c8dcSSimon Schubert     {
24275796c8dcSSimon Schubert       yylval.tsym.type = SYMBOL_TYPE (sym);
24285796c8dcSSimon Schubert       return TYPENAME;
24295796c8dcSSimon Schubert     }
2430cf7f2e2dSJohn Marino 
24315796c8dcSSimon Schubert   yylval.tsym.type
24325796c8dcSSimon Schubert     = language_lookup_primitive_type_by_name (parse_language,
24335796c8dcSSimon Schubert 					      parse_gdbarch, copy);
24345796c8dcSSimon Schubert   if (yylval.tsym.type != NULL)
24355796c8dcSSimon Schubert     return TYPENAME;
24365796c8dcSSimon Schubert 
2437cf7f2e2dSJohn Marino   /* Input names that aren't symbols but ARE valid hex numbers, when
2438cf7f2e2dSJohn Marino      the input radix permits them, can be names or numbers depending
2439cf7f2e2dSJohn Marino      on the parse.  Note we support radixes > 16 here.  */
2440cf7f2e2dSJohn Marino   if (!sym
2441cf7f2e2dSJohn Marino       && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
2442cf7f2e2dSJohn Marino 	  || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
24435796c8dcSSimon Schubert     {
24445796c8dcSSimon Schubert       YYSTYPE newlval;	/* Its value is ignored.  */
2445cf7f2e2dSJohn Marino       int hextype = parse_number (copy, yylval.sval.length, 0, &newlval);
24465796c8dcSSimon Schubert       if (hextype == INT)
24475796c8dcSSimon Schubert 	{
24485796c8dcSSimon Schubert 	  yylval.ssym.sym = sym;
24495796c8dcSSimon Schubert 	  yylval.ssym.is_a_field_of_this = is_a_field_of_this;
24505796c8dcSSimon Schubert 	  return NAME_OR_INT;
24515796c8dcSSimon Schubert 	}
24525796c8dcSSimon Schubert     }
24535796c8dcSSimon Schubert 
24545796c8dcSSimon Schubert   /* Any other kind of symbol */
24555796c8dcSSimon Schubert   yylval.ssym.sym = sym;
24565796c8dcSSimon Schubert   yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2457cf7f2e2dSJohn Marino 
2458cf7f2e2dSJohn Marino   if (sym == NULL
2459cf7f2e2dSJohn Marino       && parse_language->la_language == language_cplus
2460*c50c785cSJohn Marino       && !is_a_field_of_this
2461cf7f2e2dSJohn Marino       && !lookup_minimal_symbol (copy, NULL, NULL))
2462cf7f2e2dSJohn Marino     return UNKNOWN_CPP_NAME;
2463cf7f2e2dSJohn Marino 
24645796c8dcSSimon Schubert   return NAME;
24655796c8dcSSimon Schubert }
2466cf7f2e2dSJohn Marino 
2467cf7f2e2dSJohn Marino /* Like classify_name, but used by the inner loop of the lexer, when a
2468cf7f2e2dSJohn Marino    name might have already been seen.  FIRST_NAME is true if the token
2469cf7f2e2dSJohn Marino    in `yylval' is the first component of a name, false otherwise.  If
2470cf7f2e2dSJohn Marino    this function returns NAME, it might not have updated `yylval'.
2471cf7f2e2dSJohn Marino    This is ok because the caller only cares about TYPENAME.  */
2472cf7f2e2dSJohn Marino static int
2473cf7f2e2dSJohn Marino classify_inner_name (struct block *block, int first_name)
2474cf7f2e2dSJohn Marino {
2475cf7f2e2dSJohn Marino   struct type *type, *new_type;
2476cf7f2e2dSJohn Marino   char *copy;
2477cf7f2e2dSJohn Marino 
2478cf7f2e2dSJohn Marino   if (first_name)
2479cf7f2e2dSJohn Marino     return classify_name (block);
2480cf7f2e2dSJohn Marino 
2481cf7f2e2dSJohn Marino   type = check_typedef (yylval.tsym.type);
2482cf7f2e2dSJohn Marino   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2483cf7f2e2dSJohn Marino       && TYPE_CODE (type) != TYPE_CODE_UNION
2484cf7f2e2dSJohn Marino       && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2485cf7f2e2dSJohn Marino     /* We know the caller won't expect us to update yylval.  */
2486cf7f2e2dSJohn Marino     return NAME;
2487cf7f2e2dSJohn Marino 
2488cf7f2e2dSJohn Marino   copy = copy_name (yylval.tsym.stoken);
2489cf7f2e2dSJohn Marino   new_type = cp_lookup_nested_type (type, copy, block);
2490cf7f2e2dSJohn Marino 
2491cf7f2e2dSJohn Marino   if (new_type == NULL)
2492cf7f2e2dSJohn Marino     /* We know the caller won't expect us to update yylval.  */
2493cf7f2e2dSJohn Marino     return NAME;
2494cf7f2e2dSJohn Marino 
2495cf7f2e2dSJohn Marino   yylval.tsym.type = new_type;
2496cf7f2e2dSJohn Marino   return TYPENAME;
2497cf7f2e2dSJohn Marino }
2498cf7f2e2dSJohn Marino 
2499cf7f2e2dSJohn Marino /* The outer level of a two-level lexer.  This calls the inner lexer
2500cf7f2e2dSJohn Marino    to return tokens.  It then either returns these tokens, or
2501cf7f2e2dSJohn Marino    aggregates them into a larger token.  This lets us work around a
2502cf7f2e2dSJohn Marino    problem in our parsing approach, where the parser could not
2503cf7f2e2dSJohn Marino    distinguish between qualified names and qualified types at the
2504cf7f2e2dSJohn Marino    right point.
2505cf7f2e2dSJohn Marino 
2506cf7f2e2dSJohn Marino    This approach is still not ideal, because it mishandles template
2507cf7f2e2dSJohn Marino    types.  See the comment in lex_one_token for an example.  However,
2508cf7f2e2dSJohn Marino    this is still an improvement over the earlier approach, and will
2509cf7f2e2dSJohn Marino    suffice until we move to better parsing technology.  */
2510cf7f2e2dSJohn Marino static int
2511cf7f2e2dSJohn Marino yylex (void)
2512cf7f2e2dSJohn Marino {
2513cf7f2e2dSJohn Marino   token_and_value current;
2514cf7f2e2dSJohn Marino   int first_was_coloncolon, last_was_coloncolon, first_iter;
2515cf7f2e2dSJohn Marino 
2516cf7f2e2dSJohn Marino   if (popping && !VEC_empty (token_and_value, token_fifo))
2517cf7f2e2dSJohn Marino     {
2518cf7f2e2dSJohn Marino       token_and_value tv = *VEC_index (token_and_value, token_fifo, 0);
2519cf7f2e2dSJohn Marino       VEC_ordered_remove (token_and_value, token_fifo, 0);
2520cf7f2e2dSJohn Marino       yylval = tv.value;
2521cf7f2e2dSJohn Marino       return tv.token;
2522cf7f2e2dSJohn Marino     }
2523cf7f2e2dSJohn Marino   popping = 0;
2524cf7f2e2dSJohn Marino 
2525cf7f2e2dSJohn Marino   current.token = lex_one_token ();
2526cf7f2e2dSJohn Marino   if (current.token == NAME)
2527cf7f2e2dSJohn Marino     current.token = classify_name (expression_context_block);
2528cf7f2e2dSJohn Marino   if (parse_language->la_language != language_cplus
2529cf7f2e2dSJohn Marino       || (current.token != TYPENAME && current.token != COLONCOLON))
2530cf7f2e2dSJohn Marino     return current.token;
2531cf7f2e2dSJohn Marino 
2532cf7f2e2dSJohn Marino   first_was_coloncolon = current.token == COLONCOLON;
2533cf7f2e2dSJohn Marino   last_was_coloncolon = first_was_coloncolon;
2534cf7f2e2dSJohn Marino   obstack_free (&name_obstack, obstack_base (&name_obstack));
2535cf7f2e2dSJohn Marino   if (!last_was_coloncolon)
2536cf7f2e2dSJohn Marino     obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
2537cf7f2e2dSJohn Marino   current.value = yylval;
2538cf7f2e2dSJohn Marino   first_iter = 1;
2539cf7f2e2dSJohn Marino   while (1)
2540cf7f2e2dSJohn Marino     {
2541cf7f2e2dSJohn Marino       token_and_value next;
2542cf7f2e2dSJohn Marino 
2543cf7f2e2dSJohn Marino       next.token = lex_one_token ();
2544cf7f2e2dSJohn Marino       next.value = yylval;
2545cf7f2e2dSJohn Marino 
2546cf7f2e2dSJohn Marino       if (next.token == NAME && last_was_coloncolon)
2547cf7f2e2dSJohn Marino 	{
2548cf7f2e2dSJohn Marino 	  int classification;
2549cf7f2e2dSJohn Marino 
2550cf7f2e2dSJohn Marino 	  classification = classify_inner_name (first_was_coloncolon
2551cf7f2e2dSJohn Marino 						? NULL
2552cf7f2e2dSJohn Marino 						: expression_context_block,
2553cf7f2e2dSJohn Marino 						first_iter);
2554cf7f2e2dSJohn Marino 	  /* We keep going until we either run out of names, or until
2555cf7f2e2dSJohn Marino 	     we have a qualified name which is not a type.  */
2556cf7f2e2dSJohn Marino 	  if (classification != TYPENAME)
2557cf7f2e2dSJohn Marino 	    {
2558cf7f2e2dSJohn Marino 	      /* Push the final component and leave the loop.  */
2559cf7f2e2dSJohn Marino 	      VEC_safe_push (token_and_value, token_fifo, &next);
2560cf7f2e2dSJohn Marino 	      break;
2561cf7f2e2dSJohn Marino 	    }
2562cf7f2e2dSJohn Marino 
2563cf7f2e2dSJohn Marino 	  /* Update the partial name we are constructing.  */
2564cf7f2e2dSJohn Marino 	  if (!first_iter)
2565cf7f2e2dSJohn Marino 	    {
2566cf7f2e2dSJohn Marino 	      /* We don't want to put a leading "::" into the name.  */
2567cf7f2e2dSJohn Marino 	      obstack_grow_str (&name_obstack, "::");
2568cf7f2e2dSJohn Marino 	    }
2569cf7f2e2dSJohn Marino 	  obstack_grow (&name_obstack, next.value.sval.ptr,
2570cf7f2e2dSJohn Marino 			next.value.sval.length);
2571cf7f2e2dSJohn Marino 
2572cf7f2e2dSJohn Marino 	  yylval.sval.ptr = obstack_base (&name_obstack);
2573cf7f2e2dSJohn Marino 	  yylval.sval.length = obstack_object_size (&name_obstack);
2574cf7f2e2dSJohn Marino 	  current.value = yylval;
2575cf7f2e2dSJohn Marino 	  current.token = classification;
2576cf7f2e2dSJohn Marino 
2577cf7f2e2dSJohn Marino 	  last_was_coloncolon = 0;
2578cf7f2e2dSJohn Marino 	}
2579cf7f2e2dSJohn Marino       else if (next.token == COLONCOLON && !last_was_coloncolon)
2580cf7f2e2dSJohn Marino 	last_was_coloncolon = 1;
2581cf7f2e2dSJohn Marino       else
2582cf7f2e2dSJohn Marino 	{
2583cf7f2e2dSJohn Marino 	  /* We've reached the end of the name.  */
2584cf7f2e2dSJohn Marino 	  VEC_safe_push (token_and_value, token_fifo, &next);
2585cf7f2e2dSJohn Marino 	  break;
2586cf7f2e2dSJohn Marino 	}
2587cf7f2e2dSJohn Marino 
2588cf7f2e2dSJohn Marino       first_iter = 0;
2589cf7f2e2dSJohn Marino     }
2590cf7f2e2dSJohn Marino 
2591cf7f2e2dSJohn Marino   popping = 1;
2592cf7f2e2dSJohn Marino 
2593cf7f2e2dSJohn Marino   /* If we ended with a "::", insert it too.  */
2594cf7f2e2dSJohn Marino   if (last_was_coloncolon)
2595cf7f2e2dSJohn Marino     {
2596cf7f2e2dSJohn Marino       token_and_value cc;
2597cf7f2e2dSJohn Marino       memset (&cc, 0, sizeof (token_and_value));
2598cf7f2e2dSJohn Marino       if (first_was_coloncolon && first_iter)
2599cf7f2e2dSJohn Marino 	{
2600cf7f2e2dSJohn Marino 	  yylval = cc.value;
2601cf7f2e2dSJohn Marino 	  return COLONCOLON;
2602cf7f2e2dSJohn Marino 	}
2603cf7f2e2dSJohn Marino       cc.token = COLONCOLON;
2604cf7f2e2dSJohn Marino       VEC_safe_insert (token_and_value, token_fifo, 0, &cc);
2605cf7f2e2dSJohn Marino     }
2606cf7f2e2dSJohn Marino 
2607cf7f2e2dSJohn Marino   yylval = current.value;
2608cf7f2e2dSJohn Marino   yylval.sval.ptr = obstack_copy0 (&expansion_obstack,
2609cf7f2e2dSJohn Marino 				   yylval.sval.ptr,
2610cf7f2e2dSJohn Marino 				   yylval.sval.length);
2611cf7f2e2dSJohn Marino   return current.token;
26125796c8dcSSimon Schubert }
26135796c8dcSSimon Schubert 
26145796c8dcSSimon Schubert int
26155796c8dcSSimon Schubert c_parse (void)
26165796c8dcSSimon Schubert {
26175796c8dcSSimon Schubert   int result;
26185796c8dcSSimon Schubert   struct cleanup *back_to = make_cleanup (free_current_contents,
26195796c8dcSSimon Schubert 					  &expression_macro_scope);
26205796c8dcSSimon Schubert 
26215796c8dcSSimon Schubert   /* Set up the scope for macro expansion.  */
26225796c8dcSSimon Schubert   expression_macro_scope = NULL;
26235796c8dcSSimon Schubert 
26245796c8dcSSimon Schubert   if (expression_context_block)
26255796c8dcSSimon Schubert     expression_macro_scope
26265796c8dcSSimon Schubert       = sal_macro_scope (find_pc_line (expression_context_pc, 0));
26275796c8dcSSimon Schubert   else
26285796c8dcSSimon Schubert     expression_macro_scope = default_macro_scope ();
26295796c8dcSSimon Schubert   if (! expression_macro_scope)
26305796c8dcSSimon Schubert     expression_macro_scope = user_macro_scope ();
26315796c8dcSSimon Schubert 
26325796c8dcSSimon Schubert   /* Initialize macro expansion code.  */
26335796c8dcSSimon Schubert   obstack_init (&expansion_obstack);
26345796c8dcSSimon Schubert   gdb_assert (! macro_original_text);
26355796c8dcSSimon Schubert   make_cleanup (scan_macro_cleanup, 0);
26365796c8dcSSimon Schubert 
2637cf7f2e2dSJohn Marino   make_cleanup_restore_integer (&yydebug);
2638cf7f2e2dSJohn Marino   yydebug = parser_debug;
2639cf7f2e2dSJohn Marino 
26405796c8dcSSimon Schubert   /* Initialize some state used by the lexer.  */
26415796c8dcSSimon Schubert   last_was_structop = 0;
26425796c8dcSSimon Schubert   saw_name_at_eof = 0;
26435796c8dcSSimon Schubert 
2644cf7f2e2dSJohn Marino   VEC_free (token_and_value, token_fifo);
2645cf7f2e2dSJohn Marino   popping = 0;
2646cf7f2e2dSJohn Marino   obstack_init (&name_obstack);
2647cf7f2e2dSJohn Marino   make_cleanup_obstack_free (&name_obstack);
2648cf7f2e2dSJohn Marino 
26495796c8dcSSimon Schubert   result = yyparse ();
26505796c8dcSSimon Schubert   do_cleanups (back_to);
26515796c8dcSSimon Schubert   return result;
26525796c8dcSSimon Schubert }
26535796c8dcSSimon Schubert 
26545796c8dcSSimon Schubert 
26555796c8dcSSimon Schubert void
26565796c8dcSSimon Schubert yyerror (char *msg)
26575796c8dcSSimon Schubert {
26585796c8dcSSimon Schubert   if (prev_lexptr)
26595796c8dcSSimon Schubert     lexptr = prev_lexptr;
26605796c8dcSSimon Schubert 
2661*c50c785cSJohn Marino   error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
26625796c8dcSSimon Schubert }
2663