119370Spst/* YACC parser for C expressions, for GDB. 298944Sobrien Copyright 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3130803Smarcel 1998, 1999, 2000, 2003, 2004 419370Spst Free Software Foundation, Inc. 519370Spst 619370SpstThis file is part of GDB. 719370Spst 819370SpstThis program is free software; you can redistribute it and/or modify 919370Spstit under the terms of the GNU General Public License as published by 1019370Spstthe Free Software Foundation; either version 2 of the License, or 1119370Spst(at your option) any later version. 1219370Spst 1319370SpstThis program is distributed in the hope that it will be useful, 1419370Spstbut WITHOUT ANY WARRANTY; without even the implied warranty of 1519370SpstMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1619370SpstGNU General Public License for more details. 1719370Spst 1819370SpstYou should have received a copy of the GNU General Public License 1919370Spstalong with this program; if not, write to the Free Software 2019370SpstFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 2119370Spst 2219370Spst/* Parse a C expression from text in a string, 2319370Spst and return the result as a struct expression pointer. 2419370Spst That structure contains arithmetic operations in reverse polish, 2519370Spst with constants represented by operations that are followed by special data. 2619370Spst See expression.h for the details of the format. 2719370Spst What is important here is that it can be built up sequentially 2819370Spst during the process of parsing; the lower levels of the tree always 2919370Spst come first in the result. 3019370Spst 3119370Spst Note that malloc's and realloc's in this file are transformed to 3219370Spst xmalloc and xrealloc respectively by the same sed command in the 3319370Spst makefile that remaps any other malloc/realloc inserted by the parser 3419370Spst generator. Doing this with #defines and trying to control the interaction 3519370Spst with include files (<malloc.h> and <stdlib.h> for example) just became 3619370Spst too messy, particularly when such includes can be inserted at random 3719370Spst times by the parser generator. */ 3819370Spst 3919370Spst%{ 4019370Spst 4119370Spst#include "defs.h" 4219370Spst#include "gdb_string.h" 4319370Spst#include <ctype.h> 4419370Spst#include "expression.h" 4519370Spst#include "value.h" 4619370Spst#include "parser-defs.h" 4719370Spst#include "language.h" 4819370Spst#include "c-lang.h" 4919370Spst#include "bfd.h" /* Required by objfiles.h. */ 5019370Spst#include "symfile.h" /* Required by objfiles.h. */ 5119370Spst#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ 52130803Smarcel#include "charset.h" 53130803Smarcel#include "block.h" 54130803Smarcel#include "cp-support.h" 5519370Spst 5646283Sdfr/* Flag indicating we're dealing with HP-compiled objects */ 5746283Sdfrextern int hp_som_som_object_present; 5846283Sdfr 5919370Spst/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), 6019370Spst as well as gratuitiously global symbol names, so we can have multiple 6119370Spst yacc generated parsers in gdb. Note that these are only the variables 6219370Spst produced by yacc. If other parser generators (bison, byacc, etc) produce 6319370Spst additional global names that conflict at link time, then those parser 6419370Spst generators need to be fixed instead of adding those names to this list. */ 6519370Spst 6619370Spst#define yymaxdepth c_maxdepth 6719370Spst#define yyparse c_parse 6819370Spst#define yylex c_lex 6919370Spst#define yyerror c_error 7019370Spst#define yylval c_lval 7119370Spst#define yychar c_char 7219370Spst#define yydebug c_debug 7319370Spst#define yypact c_pact 7419370Spst#define yyr1 c_r1 7519370Spst#define yyr2 c_r2 7619370Spst#define yydef c_def 7719370Spst#define yychk c_chk 7819370Spst#define yypgo c_pgo 7919370Spst#define yyact c_act 8019370Spst#define yyexca c_exca 8119370Spst#define yyerrflag c_errflag 8219370Spst#define yynerrs c_nerrs 8319370Spst#define yyps c_ps 8419370Spst#define yypv c_pv 8519370Spst#define yys c_s 8619370Spst#define yy_yys c_yys 8719370Spst#define yystate c_state 8819370Spst#define yytmp c_tmp 8919370Spst#define yyv c_v 9019370Spst#define yy_yyv c_yyv 9119370Spst#define yyval c_val 9219370Spst#define yylloc c_lloc 9319370Spst#define yyreds c_reds /* With YYDEBUG defined */ 9419370Spst#define yytoks c_toks /* With YYDEBUG defined */ 95130803Smarcel#define yyname c_name /* With YYDEBUG defined */ 96130803Smarcel#define yyrule c_rule /* With YYDEBUG defined */ 9719370Spst#define yylhs c_yylhs 9819370Spst#define yylen c_yylen 9919370Spst#define yydefred c_yydefred 10019370Spst#define yydgoto c_yydgoto 10119370Spst#define yysindex c_yysindex 10219370Spst#define yyrindex c_yyrindex 10319370Spst#define yygindex c_yygindex 10419370Spst#define yytable c_yytable 10519370Spst#define yycheck c_yycheck 10619370Spst 10719370Spst#ifndef YYDEBUG 108130803Smarcel#define YYDEBUG 1 /* Default to yydebug support */ 10919370Spst#endif 11019370Spst 111130803Smarcel#define YYFPRINTF parser_fprintf 112130803Smarcel 11398944Sobrienint yyparse (void); 11419370Spst 11598944Sobrienstatic int yylex (void); 11619370Spst 11798944Sobrienvoid yyerror (char *); 11819370Spst 11919370Spst%} 12019370Spst 12119370Spst/* Although the yacc "value" of an expression is not used, 12219370Spst since the result is stored in the structure being created, 12319370Spst other node types do have values. */ 12419370Spst 12519370Spst%union 12619370Spst { 12719370Spst LONGEST lval; 12819370Spst struct { 12919370Spst LONGEST val; 13019370Spst struct type *type; 13119370Spst } typed_val_int; 13219370Spst struct { 13319370Spst DOUBLEST dval; 13419370Spst struct type *type; 13519370Spst } typed_val_float; 13619370Spst struct symbol *sym; 13719370Spst struct type *tval; 13819370Spst struct stoken sval; 13919370Spst struct ttype tsym; 14019370Spst struct symtoken ssym; 14119370Spst int voidval; 14219370Spst struct block *bval; 14319370Spst enum exp_opcode opcode; 14419370Spst struct internalvar *ivar; 14519370Spst 14619370Spst struct type **tvec; 14719370Spst int *ivec; 14819370Spst } 14919370Spst 15019370Spst%{ 15119370Spst/* YYSTYPE gets defined by %union */ 15298944Sobrienstatic int parse_number (char *, int, int, YYSTYPE *); 15319370Spst%} 15419370Spst 15519370Spst%type <voidval> exp exp1 type_exp start variable qualified_name lcurly 15619370Spst%type <lval> rcurly 157130803Smarcel%type <tval> type typebase qualified_type 15819370Spst%type <tvec> nonempty_typelist 15919370Spst/* %type <bval> block */ 16019370Spst 16119370Spst/* Fancy type parsing. */ 16219370Spst%type <voidval> func_mod direct_abs_decl abs_decl 16319370Spst%type <tval> ptype 16419370Spst%type <lval> array_mod 16519370Spst 16619370Spst%token <typed_val_int> INT 16719370Spst%token <typed_val_float> FLOAT 16819370Spst 16919370Spst/* Both NAME and TYPENAME tokens represent symbols in the input, 17019370Spst and both convey their data as strings. 17119370Spst But a TYPENAME is a string that happens to be defined as a typedef 17219370Spst or builtin type name (such as int or char) 17319370Spst and a NAME is any other symbol. 17419370Spst Contexts where this distinction is not important can use the 17519370Spst nonterminal "name", which matches either NAME or TYPENAME. */ 17619370Spst 17719370Spst%token <sval> STRING 17819370Spst%token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */ 17919370Spst%token <tsym> TYPENAME 18019370Spst%type <sval> name 18119370Spst%type <ssym> name_not_typename 18219370Spst%type <tsym> typename 18319370Spst 18419370Spst/* A NAME_OR_INT is a symbol which is not known in the symbol table, 18519370Spst but which would parse as a valid number in the current input radix. 18619370Spst E.g. "c" when input_radix==16. Depending on the parse, it will be 18719370Spst turned into a name or into a number. */ 18819370Spst 18919370Spst%token <ssym> NAME_OR_INT 19019370Spst 19119370Spst%token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON 19219370Spst%token TEMPLATE 19319370Spst%token ERROR 19419370Spst 19519370Spst/* Special type cases, put in to allow the parser to distinguish different 19619370Spst legal basetypes. */ 19719370Spst%token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD 19819370Spst 19919370Spst%token <voidval> VARIABLE 20019370Spst 20119370Spst%token <opcode> ASSIGN_MODIFY 20219370Spst 20319370Spst/* C++ */ 20446283Sdfr%token TRUEKEYWORD 20546283Sdfr%token FALSEKEYWORD 20619370Spst 20746283Sdfr 20819370Spst%left ',' 20919370Spst%left ABOVE_COMMA 21019370Spst%right '=' ASSIGN_MODIFY 21119370Spst%right '?' 21219370Spst%left OROR 21319370Spst%left ANDAND 21419370Spst%left '|' 21519370Spst%left '^' 21619370Spst%left '&' 21719370Spst%left EQUAL NOTEQUAL 21819370Spst%left '<' '>' LEQ GEQ 21919370Spst%left LSH RSH 22019370Spst%left '@' 22119370Spst%left '+' '-' 22219370Spst%left '*' '/' '%' 22319370Spst%right UNARY INCREMENT DECREMENT 22419370Spst%right ARROW '.' '[' '(' 22519370Spst%token <ssym> BLOCKNAME 22646283Sdfr%token <bval> FILENAME 22719370Spst%type <bval> block 22819370Spst%left COLONCOLON 22919370Spst 23019370Spst 23119370Spst%% 23219370Spst 23319370Spststart : exp1 23419370Spst | type_exp 23519370Spst ; 23619370Spst 23719370Spsttype_exp: type 23819370Spst { write_exp_elt_opcode(OP_TYPE); 23919370Spst write_exp_elt_type($1); 24019370Spst write_exp_elt_opcode(OP_TYPE);} 24119370Spst ; 24219370Spst 24319370Spst/* Expressions, including the comma operator. */ 24419370Spstexp1 : exp 24519370Spst | exp1 ',' exp 24619370Spst { write_exp_elt_opcode (BINOP_COMMA); } 24719370Spst ; 24819370Spst 24919370Spst/* Expressions, not including the comma operator. */ 25019370Spstexp : '*' exp %prec UNARY 25119370Spst { write_exp_elt_opcode (UNOP_IND); } 252130803Smarcel ; 25319370Spst 25419370Spstexp : '&' exp %prec UNARY 25519370Spst { write_exp_elt_opcode (UNOP_ADDR); } 256130803Smarcel ; 25719370Spst 25819370Spstexp : '-' exp %prec UNARY 25919370Spst { write_exp_elt_opcode (UNOP_NEG); } 26019370Spst ; 26119370Spst 26219370Spstexp : '!' exp %prec UNARY 26319370Spst { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } 26419370Spst ; 26519370Spst 26619370Spstexp : '~' exp %prec UNARY 26719370Spst { write_exp_elt_opcode (UNOP_COMPLEMENT); } 26819370Spst ; 26919370Spst 27019370Spstexp : INCREMENT exp %prec UNARY 27119370Spst { write_exp_elt_opcode (UNOP_PREINCREMENT); } 27219370Spst ; 27319370Spst 27419370Spstexp : DECREMENT exp %prec UNARY 27519370Spst { write_exp_elt_opcode (UNOP_PREDECREMENT); } 27619370Spst ; 27719370Spst 27819370Spstexp : exp INCREMENT %prec UNARY 27919370Spst { write_exp_elt_opcode (UNOP_POSTINCREMENT); } 28019370Spst ; 28119370Spst 28219370Spstexp : exp DECREMENT %prec UNARY 28319370Spst { write_exp_elt_opcode (UNOP_POSTDECREMENT); } 28419370Spst ; 28519370Spst 28619370Spstexp : SIZEOF exp %prec UNARY 28719370Spst { write_exp_elt_opcode (UNOP_SIZEOF); } 28819370Spst ; 28919370Spst 29019370Spstexp : exp ARROW name 29119370Spst { write_exp_elt_opcode (STRUCTOP_PTR); 29219370Spst write_exp_string ($3); 29319370Spst write_exp_elt_opcode (STRUCTOP_PTR); } 29419370Spst ; 29519370Spst 29619370Spstexp : exp ARROW qualified_name 29719370Spst { /* exp->type::name becomes exp->*(&type::name) */ 29819370Spst /* Note: this doesn't work if name is a 29919370Spst static member! FIXME */ 30019370Spst write_exp_elt_opcode (UNOP_ADDR); 30119370Spst write_exp_elt_opcode (STRUCTOP_MPTR); } 30219370Spst ; 30346283Sdfr 30419370Spstexp : exp ARROW '*' exp 30519370Spst { write_exp_elt_opcode (STRUCTOP_MPTR); } 30619370Spst ; 30719370Spst 30819370Spstexp : exp '.' name 30919370Spst { write_exp_elt_opcode (STRUCTOP_STRUCT); 31019370Spst write_exp_string ($3); 31119370Spst write_exp_elt_opcode (STRUCTOP_STRUCT); } 31219370Spst ; 31319370Spst 31419370Spstexp : exp '.' qualified_name 31519370Spst { /* exp.type::name becomes exp.*(&type::name) */ 31619370Spst /* Note: this doesn't work if name is a 31719370Spst static member! FIXME */ 31819370Spst write_exp_elt_opcode (UNOP_ADDR); 31919370Spst write_exp_elt_opcode (STRUCTOP_MEMBER); } 32019370Spst ; 32119370Spst 32219370Spstexp : exp '.' '*' exp 32319370Spst { write_exp_elt_opcode (STRUCTOP_MEMBER); } 32419370Spst ; 32519370Spst 32619370Spstexp : exp '[' exp1 ']' 32719370Spst { write_exp_elt_opcode (BINOP_SUBSCRIPT); } 32819370Spst ; 32919370Spst 33019370Spstexp : exp '(' 33119370Spst /* This is to save the value of arglist_len 33219370Spst being accumulated by an outer function call. */ 33319370Spst { start_arglist (); } 33419370Spst arglist ')' %prec ARROW 33519370Spst { write_exp_elt_opcode (OP_FUNCALL); 33619370Spst write_exp_elt_longcst ((LONGEST) end_arglist ()); 33719370Spst write_exp_elt_opcode (OP_FUNCALL); } 33819370Spst ; 33919370Spst 34019370Spstlcurly : '{' 34119370Spst { start_arglist (); } 34219370Spst ; 34319370Spst 34419370Spstarglist : 34519370Spst ; 34619370Spst 34719370Spstarglist : exp 34819370Spst { arglist_len = 1; } 34919370Spst ; 35019370Spst 35119370Spstarglist : arglist ',' exp %prec ABOVE_COMMA 35219370Spst { arglist_len++; } 35319370Spst ; 35419370Spst 35519370Spstrcurly : '}' 35619370Spst { $$ = end_arglist () - 1; } 35719370Spst ; 35819370Spstexp : lcurly arglist rcurly %prec ARROW 35919370Spst { write_exp_elt_opcode (OP_ARRAY); 36019370Spst write_exp_elt_longcst ((LONGEST) 0); 36119370Spst write_exp_elt_longcst ((LONGEST) $3); 36219370Spst write_exp_elt_opcode (OP_ARRAY); } 36319370Spst ; 36419370Spst 36519370Spstexp : lcurly type rcurly exp %prec UNARY 36619370Spst { write_exp_elt_opcode (UNOP_MEMVAL); 36719370Spst write_exp_elt_type ($2); 36819370Spst write_exp_elt_opcode (UNOP_MEMVAL); } 36919370Spst ; 37019370Spst 37119370Spstexp : '(' type ')' exp %prec UNARY 37219370Spst { write_exp_elt_opcode (UNOP_CAST); 37319370Spst write_exp_elt_type ($2); 37419370Spst write_exp_elt_opcode (UNOP_CAST); } 37519370Spst ; 37619370Spst 37719370Spstexp : '(' exp1 ')' 37819370Spst { } 37919370Spst ; 38019370Spst 38119370Spst/* Binary operators in order of decreasing precedence. */ 38219370Spst 38319370Spstexp : exp '@' exp 38419370Spst { write_exp_elt_opcode (BINOP_REPEAT); } 38519370Spst ; 38619370Spst 38719370Spstexp : exp '*' exp 38819370Spst { write_exp_elt_opcode (BINOP_MUL); } 38919370Spst ; 39019370Spst 39119370Spstexp : exp '/' exp 39219370Spst { write_exp_elt_opcode (BINOP_DIV); } 39319370Spst ; 39419370Spst 39519370Spstexp : exp '%' exp 39619370Spst { write_exp_elt_opcode (BINOP_REM); } 39719370Spst ; 39819370Spst 39919370Spstexp : exp '+' exp 40019370Spst { write_exp_elt_opcode (BINOP_ADD); } 40119370Spst ; 40219370Spst 40319370Spstexp : exp '-' exp 40419370Spst { write_exp_elt_opcode (BINOP_SUB); } 40519370Spst ; 40619370Spst 40719370Spstexp : exp LSH exp 40819370Spst { write_exp_elt_opcode (BINOP_LSH); } 40919370Spst ; 41019370Spst 41119370Spstexp : exp RSH exp 41219370Spst { write_exp_elt_opcode (BINOP_RSH); } 41319370Spst ; 41419370Spst 41519370Spstexp : exp EQUAL exp 41619370Spst { write_exp_elt_opcode (BINOP_EQUAL); } 41719370Spst ; 41819370Spst 41919370Spstexp : exp NOTEQUAL exp 42019370Spst { write_exp_elt_opcode (BINOP_NOTEQUAL); } 42119370Spst ; 42219370Spst 42319370Spstexp : exp LEQ exp 42419370Spst { write_exp_elt_opcode (BINOP_LEQ); } 42519370Spst ; 42619370Spst 42719370Spstexp : exp GEQ exp 42819370Spst { write_exp_elt_opcode (BINOP_GEQ); } 42919370Spst ; 43019370Spst 43119370Spstexp : exp '<' exp 43219370Spst { write_exp_elt_opcode (BINOP_LESS); } 43319370Spst ; 43419370Spst 43519370Spstexp : exp '>' exp 43619370Spst { write_exp_elt_opcode (BINOP_GTR); } 43719370Spst ; 43819370Spst 43919370Spstexp : exp '&' exp 44019370Spst { write_exp_elt_opcode (BINOP_BITWISE_AND); } 44119370Spst ; 44219370Spst 44319370Spstexp : exp '^' exp 44419370Spst { write_exp_elt_opcode (BINOP_BITWISE_XOR); } 44519370Spst ; 44619370Spst 44719370Spstexp : exp '|' exp 44819370Spst { write_exp_elt_opcode (BINOP_BITWISE_IOR); } 44919370Spst ; 45019370Spst 45119370Spstexp : exp ANDAND exp 45219370Spst { write_exp_elt_opcode (BINOP_LOGICAL_AND); } 45319370Spst ; 45419370Spst 45519370Spstexp : exp OROR exp 45619370Spst { write_exp_elt_opcode (BINOP_LOGICAL_OR); } 45719370Spst ; 45819370Spst 45919370Spstexp : exp '?' exp ':' exp %prec '?' 46019370Spst { write_exp_elt_opcode (TERNOP_COND); } 46119370Spst ; 46219370Spst 46319370Spstexp : exp '=' exp 46419370Spst { write_exp_elt_opcode (BINOP_ASSIGN); } 46519370Spst ; 46619370Spst 46719370Spstexp : exp ASSIGN_MODIFY exp 46819370Spst { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); 46919370Spst write_exp_elt_opcode ($2); 47019370Spst write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } 47119370Spst ; 47219370Spst 47319370Spstexp : INT 47419370Spst { write_exp_elt_opcode (OP_LONG); 47519370Spst write_exp_elt_type ($1.type); 47619370Spst write_exp_elt_longcst ((LONGEST)($1.val)); 47719370Spst write_exp_elt_opcode (OP_LONG); } 47819370Spst ; 47919370Spst 48019370Spstexp : NAME_OR_INT 48119370Spst { YYSTYPE val; 48219370Spst parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val); 48319370Spst write_exp_elt_opcode (OP_LONG); 48419370Spst write_exp_elt_type (val.typed_val_int.type); 48519370Spst write_exp_elt_longcst ((LONGEST)val.typed_val_int.val); 48619370Spst write_exp_elt_opcode (OP_LONG); 48719370Spst } 48819370Spst ; 48919370Spst 49019370Spst 49119370Spstexp : FLOAT 49219370Spst { write_exp_elt_opcode (OP_DOUBLE); 49319370Spst write_exp_elt_type ($1.type); 49419370Spst write_exp_elt_dblcst ($1.dval); 49519370Spst write_exp_elt_opcode (OP_DOUBLE); } 49619370Spst ; 49719370Spst 49819370Spstexp : variable 49919370Spst ; 50019370Spst 50119370Spstexp : VARIABLE 50219370Spst /* Already written by write_dollar_variable. */ 50319370Spst ; 50419370Spst 50519370Spstexp : SIZEOF '(' type ')' %prec UNARY 50619370Spst { write_exp_elt_opcode (OP_LONG); 50719370Spst write_exp_elt_type (builtin_type_int); 50819370Spst CHECK_TYPEDEF ($3); 50919370Spst write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); 51019370Spst write_exp_elt_opcode (OP_LONG); } 51119370Spst ; 51219370Spst 51319370Spstexp : STRING 51419370Spst { /* C strings are converted into array constants with 51519370Spst an explicit null byte added at the end. Thus 51619370Spst the array upper bound is the string length. 51719370Spst There is no such thing in C as a completely empty 51819370Spst string. */ 51919370Spst char *sp = $1.ptr; int count = $1.length; 52019370Spst while (count-- > 0) 52119370Spst { 52219370Spst write_exp_elt_opcode (OP_LONG); 52319370Spst write_exp_elt_type (builtin_type_char); 52419370Spst write_exp_elt_longcst ((LONGEST)(*sp++)); 52519370Spst write_exp_elt_opcode (OP_LONG); 52619370Spst } 52719370Spst write_exp_elt_opcode (OP_LONG); 52819370Spst write_exp_elt_type (builtin_type_char); 52919370Spst write_exp_elt_longcst ((LONGEST)'\0'); 53019370Spst write_exp_elt_opcode (OP_LONG); 53119370Spst write_exp_elt_opcode (OP_ARRAY); 53219370Spst write_exp_elt_longcst ((LONGEST) 0); 53319370Spst write_exp_elt_longcst ((LONGEST) ($1.length)); 53419370Spst write_exp_elt_opcode (OP_ARRAY); } 53519370Spst ; 53619370Spst 53719370Spst/* C++. */ 53846283Sdfrexp : TRUEKEYWORD 53946283Sdfr { write_exp_elt_opcode (OP_LONG); 54046283Sdfr write_exp_elt_type (builtin_type_bool); 54146283Sdfr write_exp_elt_longcst ((LONGEST) 1); 54246283Sdfr write_exp_elt_opcode (OP_LONG); } 54346283Sdfr ; 54446283Sdfr 54546283Sdfrexp : FALSEKEYWORD 54646283Sdfr { write_exp_elt_opcode (OP_LONG); 54746283Sdfr write_exp_elt_type (builtin_type_bool); 54846283Sdfr write_exp_elt_longcst ((LONGEST) 0); 54946283Sdfr write_exp_elt_opcode (OP_LONG); } 55046283Sdfr ; 55146283Sdfr 55219370Spst/* end of C++. */ 55319370Spst 55419370Spstblock : BLOCKNAME 55519370Spst { 55646283Sdfr if ($1.sym) 55746283Sdfr $$ = SYMBOL_BLOCK_VALUE ($1.sym); 55819370Spst else 55946283Sdfr error ("No file or function \"%s\".", 56046283Sdfr copy_name ($1.stoken)); 56119370Spst } 56246283Sdfr | FILENAME 56346283Sdfr { 56446283Sdfr $$ = $1; 56546283Sdfr } 56619370Spst ; 56719370Spst 56819370Spstblock : block COLONCOLON name 56919370Spst { struct symbol *tem 57019370Spst = lookup_symbol (copy_name ($3), $1, 571130803Smarcel VAR_DOMAIN, (int *) NULL, 57219370Spst (struct symtab **) NULL); 57319370Spst if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK) 57419370Spst error ("No function \"%s\" in specified context.", 57519370Spst copy_name ($3)); 57619370Spst $$ = SYMBOL_BLOCK_VALUE (tem); } 57719370Spst ; 57819370Spst 57919370Spstvariable: block COLONCOLON name 58019370Spst { struct symbol *sym; 58119370Spst sym = lookup_symbol (copy_name ($3), $1, 582130803Smarcel VAR_DOMAIN, (int *) NULL, 58319370Spst (struct symtab **) NULL); 58419370Spst if (sym == 0) 58519370Spst error ("No symbol \"%s\" in specified context.", 58619370Spst copy_name ($3)); 58719370Spst 58819370Spst write_exp_elt_opcode (OP_VAR_VALUE); 58919370Spst /* block_found is set by lookup_symbol. */ 59019370Spst write_exp_elt_block (block_found); 59119370Spst write_exp_elt_sym (sym); 59219370Spst write_exp_elt_opcode (OP_VAR_VALUE); } 59319370Spst ; 59419370Spst 59519370Spstqualified_name: typebase COLONCOLON name 59619370Spst { 59719370Spst struct type *type = $1; 59819370Spst if (TYPE_CODE (type) != TYPE_CODE_STRUCT 599130803Smarcel && TYPE_CODE (type) != TYPE_CODE_UNION 600130803Smarcel && TYPE_CODE (type) != TYPE_CODE_NAMESPACE) 60119370Spst error ("`%s' is not defined as an aggregate type.", 60219370Spst TYPE_NAME (type)); 60319370Spst 60419370Spst write_exp_elt_opcode (OP_SCOPE); 60519370Spst write_exp_elt_type (type); 60619370Spst write_exp_string ($3); 60719370Spst write_exp_elt_opcode (OP_SCOPE); 60819370Spst } 60919370Spst | typebase COLONCOLON '~' name 61019370Spst { 61119370Spst struct type *type = $1; 61219370Spst struct stoken tmp_token; 61319370Spst if (TYPE_CODE (type) != TYPE_CODE_STRUCT 614130803Smarcel && TYPE_CODE (type) != TYPE_CODE_UNION 615130803Smarcel && TYPE_CODE (type) != TYPE_CODE_NAMESPACE) 61619370Spst error ("`%s' is not defined as an aggregate type.", 61719370Spst TYPE_NAME (type)); 61819370Spst 61919370Spst tmp_token.ptr = (char*) alloca ($4.length + 2); 62019370Spst tmp_token.length = $4.length + 1; 62119370Spst tmp_token.ptr[0] = '~'; 62219370Spst memcpy (tmp_token.ptr+1, $4.ptr, $4.length); 62319370Spst tmp_token.ptr[tmp_token.length] = 0; 62446283Sdfr 62546283Sdfr /* Check for valid destructor name. */ 62646283Sdfr destructor_name_p (tmp_token.ptr, type); 62719370Spst write_exp_elt_opcode (OP_SCOPE); 62819370Spst write_exp_elt_type (type); 62919370Spst write_exp_string (tmp_token); 63019370Spst write_exp_elt_opcode (OP_SCOPE); 63119370Spst } 63219370Spst ; 63319370Spst 63419370Spstvariable: qualified_name 63519370Spst | COLONCOLON name 63619370Spst { 63719370Spst char *name = copy_name ($2); 63819370Spst struct symbol *sym; 63919370Spst struct minimal_symbol *msymbol; 64019370Spst 64119370Spst sym = 64219370Spst lookup_symbol (name, (const struct block *) NULL, 643130803Smarcel VAR_DOMAIN, (int *) NULL, 64419370Spst (struct symtab **) NULL); 64519370Spst if (sym) 64619370Spst { 64719370Spst write_exp_elt_opcode (OP_VAR_VALUE); 64819370Spst write_exp_elt_block (NULL); 64919370Spst write_exp_elt_sym (sym); 65019370Spst write_exp_elt_opcode (OP_VAR_VALUE); 65119370Spst break; 65219370Spst } 65319370Spst 65419370Spst msymbol = lookup_minimal_symbol (name, NULL, NULL); 65519370Spst if (msymbol != NULL) 65619370Spst { 65719370Spst write_exp_msymbol (msymbol, 65819370Spst lookup_function_type (builtin_type_int), 65919370Spst builtin_type_int); 66019370Spst } 66119370Spst else 66219370Spst if (!have_full_symbols () && !have_partial_symbols ()) 66319370Spst error ("No symbol table is loaded. Use the \"file\" command."); 66419370Spst else 66519370Spst error ("No symbol \"%s\" in current context.", name); 66619370Spst } 66719370Spst ; 66819370Spst 66919370Spstvariable: name_not_typename 67019370Spst { struct symbol *sym = $1.sym; 67119370Spst 67219370Spst if (sym) 67319370Spst { 67419370Spst if (symbol_read_needs_frame (sym)) 67519370Spst { 67619370Spst if (innermost_block == 0 || 67719370Spst contained_in (block_found, 67819370Spst innermost_block)) 67919370Spst innermost_block = block_found; 68019370Spst } 68119370Spst 68219370Spst write_exp_elt_opcode (OP_VAR_VALUE); 68319370Spst /* We want to use the selected frame, not 68419370Spst another more inner frame which happens to 68519370Spst be in the same block. */ 68619370Spst write_exp_elt_block (NULL); 68719370Spst write_exp_elt_sym (sym); 68819370Spst write_exp_elt_opcode (OP_VAR_VALUE); 68919370Spst } 69019370Spst else if ($1.is_a_field_of_this) 69119370Spst { 69219370Spst /* C++: it hangs off of `this'. Must 69319370Spst not inadvertently convert from a method call 69419370Spst to data ref. */ 69519370Spst if (innermost_block == 0 || 69619370Spst contained_in (block_found, innermost_block)) 69719370Spst innermost_block = block_found; 69819370Spst write_exp_elt_opcode (OP_THIS); 69919370Spst write_exp_elt_opcode (OP_THIS); 70019370Spst write_exp_elt_opcode (STRUCTOP_PTR); 70119370Spst write_exp_string ($1.stoken); 70219370Spst write_exp_elt_opcode (STRUCTOP_PTR); 70319370Spst } 70419370Spst else 70519370Spst { 70619370Spst struct minimal_symbol *msymbol; 707130803Smarcel char *arg = copy_name ($1.stoken); 70819370Spst 70919370Spst msymbol = 71019370Spst lookup_minimal_symbol (arg, NULL, NULL); 71119370Spst if (msymbol != NULL) 71219370Spst { 71319370Spst write_exp_msymbol (msymbol, 71419370Spst lookup_function_type (builtin_type_int), 71519370Spst builtin_type_int); 71619370Spst } 71719370Spst else if (!have_full_symbols () && !have_partial_symbols ()) 71819370Spst error ("No symbol table is loaded. Use the \"file\" command."); 71919370Spst else 72019370Spst error ("No symbol \"%s\" in current context.", 72119370Spst copy_name ($1.stoken)); 72219370Spst } 72319370Spst } 72419370Spst ; 72519370Spst 72698944Sobrienspace_identifier : '@' NAME 72798944Sobrien { push_type_address_space (copy_name ($2.stoken)); 72898944Sobrien push_type (tp_space_identifier); 72998944Sobrien } 73098944Sobrien ; 73119370Spst 73298944Sobrienconst_or_volatile: const_or_volatile_noopt 73398944Sobrien | 73419370Spst ; 73519370Spst 73698944Sobriencv_with_space_id : const_or_volatile space_identifier const_or_volatile 73798944Sobrien ; 73898944Sobrien 73998944Sobrienconst_or_volatile_or_space_identifier_noopt: cv_with_space_id 74098944Sobrien | const_or_volatile_noopt 74198944Sobrien ; 74298944Sobrien 74398944Sobrienconst_or_volatile_or_space_identifier: 74498944Sobrien const_or_volatile_or_space_identifier_noopt 74598944Sobrien | 74698944Sobrien ; 74798944Sobrien 74819370Spstabs_decl: '*' 74919370Spst { push_type (tp_pointer); $$ = 0; } 75019370Spst | '*' abs_decl 75119370Spst { push_type (tp_pointer); $$ = $2; } 75219370Spst | '&' 75319370Spst { push_type (tp_reference); $$ = 0; } 75419370Spst | '&' abs_decl 75519370Spst { push_type (tp_reference); $$ = $2; } 75619370Spst | direct_abs_decl 75719370Spst ; 75819370Spst 75919370Spstdirect_abs_decl: '(' abs_decl ')' 76019370Spst { $$ = $2; } 76119370Spst | direct_abs_decl array_mod 76219370Spst { 76319370Spst push_type_int ($2); 76419370Spst push_type (tp_array); 76519370Spst } 76619370Spst | array_mod 76719370Spst { 76819370Spst push_type_int ($1); 76919370Spst push_type (tp_array); 77019370Spst $$ = 0; 77119370Spst } 77219370Spst 77319370Spst | direct_abs_decl func_mod 77419370Spst { push_type (tp_function); } 77519370Spst | func_mod 77619370Spst { push_type (tp_function); } 77719370Spst ; 77819370Spst 77919370Spstarray_mod: '[' ']' 78019370Spst { $$ = -1; } 78119370Spst | '[' INT ']' 78219370Spst { $$ = $2.val; } 78319370Spst ; 78419370Spst 78519370Spstfunc_mod: '(' ')' 78619370Spst { $$ = 0; } 78719370Spst | '(' nonempty_typelist ')' 788130803Smarcel { free ($2); $$ = 0; } 78919370Spst ; 79019370Spst 79119370Spst/* We used to try to recognize more pointer to member types here, but 79219370Spst that didn't work (shift/reduce conflicts meant that these rules never 79319370Spst got executed). The problem is that 79419370Spst int (foo::bar::baz::bizzle) 79519370Spst is a function type but 79619370Spst int (foo::bar::baz::bizzle::*) 79719370Spst is a pointer to member type. Stroustrup loses again! */ 79819370Spst 79919370Spsttype : ptype 80019370Spst | typebase COLONCOLON '*' 80119370Spst { $$ = lookup_member_type (builtin_type_int, $1); } 80219370Spst ; 80319370Spst 80419370Spsttypebase /* Implements (approximately): (type-qualifier)* type-specifier */ 80519370Spst : TYPENAME 80619370Spst { $$ = $1.type; } 80719370Spst | INT_KEYWORD 80819370Spst { $$ = builtin_type_int; } 80919370Spst | LONG 81019370Spst { $$ = builtin_type_long; } 81119370Spst | SHORT 81219370Spst { $$ = builtin_type_short; } 81319370Spst | LONG INT_KEYWORD 81419370Spst { $$ = builtin_type_long; } 815130803Smarcel | LONG SIGNED_KEYWORD INT_KEYWORD 816130803Smarcel { $$ = builtin_type_long; } 817130803Smarcel | LONG SIGNED_KEYWORD 818130803Smarcel { $$ = builtin_type_long; } 819130803Smarcel | SIGNED_KEYWORD LONG INT_KEYWORD 820130803Smarcel { $$ = builtin_type_long; } 82119370Spst | UNSIGNED LONG INT_KEYWORD 82219370Spst { $$ = builtin_type_unsigned_long; } 823130803Smarcel | LONG UNSIGNED INT_KEYWORD 824130803Smarcel { $$ = builtin_type_unsigned_long; } 825130803Smarcel | LONG UNSIGNED 826130803Smarcel { $$ = builtin_type_unsigned_long; } 82719370Spst | LONG LONG 82819370Spst { $$ = builtin_type_long_long; } 82919370Spst | LONG LONG INT_KEYWORD 83019370Spst { $$ = builtin_type_long_long; } 831130803Smarcel | LONG LONG SIGNED_KEYWORD INT_KEYWORD 832130803Smarcel { $$ = builtin_type_long_long; } 833130803Smarcel | LONG LONG SIGNED_KEYWORD 834130803Smarcel { $$ = builtin_type_long_long; } 835130803Smarcel | SIGNED_KEYWORD LONG LONG 836130803Smarcel { $$ = builtin_type_long_long; } 837130803Smarcel | SIGNED_KEYWORD LONG LONG INT_KEYWORD 838130803Smarcel { $$ = builtin_type_long_long; } 83919370Spst | UNSIGNED LONG LONG 84019370Spst { $$ = builtin_type_unsigned_long_long; } 84119370Spst | UNSIGNED LONG LONG INT_KEYWORD 84219370Spst { $$ = builtin_type_unsigned_long_long; } 843130803Smarcel | LONG LONG UNSIGNED 844130803Smarcel { $$ = builtin_type_unsigned_long_long; } 845130803Smarcel | LONG LONG UNSIGNED INT_KEYWORD 846130803Smarcel { $$ = builtin_type_unsigned_long_long; } 84719370Spst | SHORT INT_KEYWORD 84819370Spst { $$ = builtin_type_short; } 849130803Smarcel | SHORT SIGNED_KEYWORD INT_KEYWORD 850130803Smarcel { $$ = builtin_type_short; } 851130803Smarcel | SHORT SIGNED_KEYWORD 852130803Smarcel { $$ = builtin_type_short; } 85319370Spst | UNSIGNED SHORT INT_KEYWORD 85419370Spst { $$ = builtin_type_unsigned_short; } 855130803Smarcel | SHORT UNSIGNED 856130803Smarcel { $$ = builtin_type_unsigned_short; } 857130803Smarcel | SHORT UNSIGNED INT_KEYWORD 858130803Smarcel { $$ = builtin_type_unsigned_short; } 85919370Spst | DOUBLE_KEYWORD 86019370Spst { $$ = builtin_type_double; } 86119370Spst | LONG DOUBLE_KEYWORD 86219370Spst { $$ = builtin_type_long_double; } 86319370Spst | STRUCT name 86419370Spst { $$ = lookup_struct (copy_name ($2), 86519370Spst expression_context_block); } 86619370Spst | CLASS name 86719370Spst { $$ = lookup_struct (copy_name ($2), 86819370Spst expression_context_block); } 86919370Spst | UNION name 87019370Spst { $$ = lookup_union (copy_name ($2), 87119370Spst expression_context_block); } 87219370Spst | ENUM name 87319370Spst { $$ = lookup_enum (copy_name ($2), 87419370Spst expression_context_block); } 87519370Spst | UNSIGNED typename 87619370Spst { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); } 87719370Spst | UNSIGNED 87819370Spst { $$ = builtin_type_unsigned_int; } 87919370Spst | SIGNED_KEYWORD typename 88019370Spst { $$ = lookup_signed_typename (TYPE_NAME($2.type)); } 88119370Spst | SIGNED_KEYWORD 88219370Spst { $$ = builtin_type_int; } 88346283Sdfr /* It appears that this rule for templates is never 88446283Sdfr reduced; template recognition happens by lookahead 88546283Sdfr in the token processing code in yylex. */ 88619370Spst | TEMPLATE name '<' type '>' 88719370Spst { $$ = lookup_template_type(copy_name($2), $4, 88819370Spst expression_context_block); 88919370Spst } 89098944Sobrien | const_or_volatile_or_space_identifier_noopt typebase 89198944Sobrien { $$ = follow_types ($2); } 89298944Sobrien | typebase const_or_volatile_or_space_identifier_noopt 89398944Sobrien { $$ = follow_types ($1); } 894130803Smarcel | qualified_type 89519370Spst ; 89619370Spst 897130803Smarcel/* FIXME: carlton/2003-09-25: This next bit leads to lots of 898130803Smarcel reduce-reduce conflicts, because the parser doesn't know whether or 899130803Smarcel not to use qualified_name or qualified_type: the rules are 900130803Smarcel identical. If the parser is parsing 'A::B::x', then, when it sees 901130803Smarcel the second '::', it knows that the expression to the left of it has 902130803Smarcel to be a type, so it uses qualified_type. But if it is parsing just 903130803Smarcel 'A::B', then it doesn't have any way of knowing which rule to use, 904130803Smarcel so there's a reduce-reduce conflict; it picks qualified_name, since 905130803Smarcel that occurs earlier in this file than qualified_type. 906130803Smarcel 907130803Smarcel There's no good way to fix this with the grammar as it stands; as 908130803Smarcel far as I can tell, some of the problems arise from ambiguities that 909130803Smarcel GDB introduces ('start' can be either an expression or a type), but 910130803Smarcel some of it is inherent to the nature of C++ (you want to treat the 911130803Smarcel input "(FOO)" fairly differently depending on whether FOO is an 912130803Smarcel expression or a type, and if FOO is a complex expression, this can 913130803Smarcel be hard to determine at the right time). Fortunately, it works 914130803Smarcel pretty well in most cases. For example, if you do 'ptype A::B', 915130803Smarcel where A::B is a nested type, then the parser will mistakenly 916130803Smarcel misidentify it as an expression; but evaluate_subexp will get 917130803Smarcel called with 'noside' set to EVAL_AVOID_SIDE_EFFECTS, and everything 918130803Smarcel will work out anyways. But there are situations where the parser 919130803Smarcel will get confused: the most common one that I've run into is when 920130803Smarcel you want to do 921130803Smarcel 922130803Smarcel print *((A::B *) x)" 923130803Smarcel 924130803Smarcel where the parser doesn't realize that A::B has to be a type until 925130803Smarcel it hits the first right paren, at which point it's too late. (The 926130803Smarcel workaround is to type "print *(('A::B' *) x)" instead.) (And 927130803Smarcel another solution is to fix our symbol-handling code so that the 928130803Smarcel user never wants to type something like that in the first place, 929130803Smarcel because we get all the types right without the user's help!) 930130803Smarcel 931130803Smarcel Perhaps we could fix this by making the lexer smarter. Some of 932130803Smarcel this functionality used to be in the lexer, but in a way that 933130803Smarcel worked even less well than the current solution: that attempt 934130803Smarcel involved having the parser sometimes handle '::' and having the 935130803Smarcel lexer sometimes handle it, and without a clear division of 936130803Smarcel responsibility, it quickly degenerated into a big mess. Probably 937130803Smarcel the eventual correct solution will give more of a role to the lexer 938130803Smarcel (ideally via code that is shared between the lexer and 939130803Smarcel decode_line_1), but I'm not holding my breath waiting for somebody 940130803Smarcel to get around to cleaning this up... */ 941130803Smarcel 942130803Smarcelqualified_type: typebase COLONCOLON name 943130803Smarcel { 944130803Smarcel struct type *type = $1; 945130803Smarcel struct type *new_type; 946130803Smarcel char *ncopy = alloca ($3.length + 1); 947130803Smarcel 948130803Smarcel memcpy (ncopy, $3.ptr, $3.length); 949130803Smarcel ncopy[$3.length] = '\0'; 950130803Smarcel 951130803Smarcel if (TYPE_CODE (type) != TYPE_CODE_STRUCT 952130803Smarcel && TYPE_CODE (type) != TYPE_CODE_UNION 953130803Smarcel && TYPE_CODE (type) != TYPE_CODE_NAMESPACE) 954130803Smarcel error ("`%s' is not defined as an aggregate type.", 955130803Smarcel TYPE_NAME (type)); 956130803Smarcel 957130803Smarcel new_type = cp_lookup_nested_type (type, ncopy, 958130803Smarcel expression_context_block); 959130803Smarcel if (new_type == NULL) 960130803Smarcel error ("No type \"%s\" within class or namespace \"%s\".", 961130803Smarcel ncopy, TYPE_NAME (type)); 962130803Smarcel 963130803Smarcel $$ = new_type; 964130803Smarcel } 965130803Smarcel ; 966130803Smarcel 96719370Spsttypename: TYPENAME 96819370Spst | INT_KEYWORD 96919370Spst { 97019370Spst $$.stoken.ptr = "int"; 97119370Spst $$.stoken.length = 3; 97219370Spst $$.type = builtin_type_int; 97319370Spst } 97419370Spst | LONG 97519370Spst { 97619370Spst $$.stoken.ptr = "long"; 97719370Spst $$.stoken.length = 4; 97819370Spst $$.type = builtin_type_long; 97919370Spst } 98019370Spst | SHORT 98119370Spst { 98219370Spst $$.stoken.ptr = "short"; 98319370Spst $$.stoken.length = 5; 98419370Spst $$.type = builtin_type_short; 98519370Spst } 98619370Spst ; 98719370Spst 98819370Spstnonempty_typelist 98919370Spst : type 99019370Spst { $$ = (struct type **) malloc (sizeof (struct type *) * 2); 99119370Spst $<ivec>$[0] = 1; /* Number of types in vector */ 99219370Spst $$[1] = $1; 99319370Spst } 99419370Spst | nonempty_typelist ',' type 99519370Spst { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1); 99619370Spst $$ = (struct type **) realloc ((char *) $1, len); 99719370Spst $$[$<ivec>$[0]] = $3; 99819370Spst } 99919370Spst ; 100019370Spst 100198944Sobrienptype : typebase 100298944Sobrien | ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier 100398944Sobrien { $$ = follow_types ($1); } 100498944Sobrien ; 100598944Sobrien 100698944Sobrienconst_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD 100798944Sobrien | VOLATILE_KEYWORD CONST_KEYWORD 100898944Sobrien ; 100998944Sobrien 101098944Sobrienconst_or_volatile_noopt: const_and_volatile 101198944Sobrien { push_type (tp_const); 101298944Sobrien push_type (tp_volatile); 101398944Sobrien } 101498944Sobrien | CONST_KEYWORD 101598944Sobrien { push_type (tp_const); } 101698944Sobrien | VOLATILE_KEYWORD 101798944Sobrien { push_type (tp_volatile); } 101898944Sobrien ; 101998944Sobrien 102019370Spstname : NAME { $$ = $1.stoken; } 102119370Spst | BLOCKNAME { $$ = $1.stoken; } 102219370Spst | TYPENAME { $$ = $1.stoken; } 102319370Spst | NAME_OR_INT { $$ = $1.stoken; } 102419370Spst ; 102519370Spst 102619370Spstname_not_typename : NAME 102719370Spst | BLOCKNAME 102819370Spst/* These would be useful if name_not_typename was useful, but it is just 102919370Spst a fake for "variable", so these cause reduce/reduce conflicts because 103019370Spst the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable, 103119370Spst =exp) or just an exp. If name_not_typename was ever used in an lvalue 103219370Spst context where only a name could occur, this might be useful. 103319370Spst | NAME_OR_INT 103419370Spst */ 103519370Spst ; 103619370Spst 103719370Spst%% 103819370Spst 103919370Spst/* Take care of parsing a number (anything that starts with a digit). 104019370Spst Set yylval and return the token type; update lexptr. 104119370Spst LEN is the number of characters in it. */ 104219370Spst 104319370Spst/*** Needs some error checking for the float case ***/ 104419370Spst 104519370Spststatic int 104619370Spstparse_number (p, len, parsed_float, putithere) 1047130803Smarcel char *p; 1048130803Smarcel int len; 104919370Spst int parsed_float; 105019370Spst YYSTYPE *putithere; 105119370Spst{ 105219370Spst /* FIXME: Shouldn't these be unsigned? We don't deal with negative values 105319370Spst here, and we do kind of silly things like cast to unsigned. */ 1054130803Smarcel LONGEST n = 0; 1055130803Smarcel LONGEST prevn = 0; 105646283Sdfr ULONGEST un; 105719370Spst 1058130803Smarcel int i = 0; 1059130803Smarcel int c; 1060130803Smarcel int base = input_radix; 106119370Spst int unsigned_p = 0; 106219370Spst 106319370Spst /* Number of "L" suffixes encountered. */ 106419370Spst int long_p = 0; 106519370Spst 106619370Spst /* We have found a "L" or "U" suffix. */ 106719370Spst int found_suffix = 0; 106819370Spst 106946283Sdfr ULONGEST high_bit; 107019370Spst struct type *signed_type; 107119370Spst struct type *unsigned_type; 107219370Spst 107319370Spst if (parsed_float) 107419370Spst { 107546283Sdfr /* It's a float since it contains a point or an exponent. */ 107619370Spst char c; 107746283Sdfr int num = 0; /* number of tokens scanned by scanf */ 107846283Sdfr char saved_char = p[len]; 107919370Spst 108046283Sdfr p[len] = 0; /* null-terminate the token */ 108119370Spst if (sizeof (putithere->typed_val_float.dval) <= sizeof (float)) 108246283Sdfr num = sscanf (p, "%g%c", (float *) &putithere->typed_val_float.dval,&c); 108319370Spst else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double)) 108446283Sdfr num = sscanf (p, "%lg%c", (double *) &putithere->typed_val_float.dval,&c); 108519370Spst else 108619370Spst { 108746283Sdfr#ifdef SCANF_HAS_LONG_DOUBLE 108846283Sdfr num = sscanf (p, "%Lg%c", &putithere->typed_val_float.dval,&c); 108919370Spst#else 109019370Spst /* Scan it into a double, then assign it to the long double. 109119370Spst This at least wins with values representable in the range 109219370Spst of doubles. */ 109319370Spst double temp; 109446283Sdfr num = sscanf (p, "%lg%c", &temp,&c); 109519370Spst putithere->typed_val_float.dval = temp; 109619370Spst#endif 109719370Spst } 109846283Sdfr p[len] = saved_char; /* restore the input stream */ 109946283Sdfr if (num != 1) /* check scanf found ONLY a float ... */ 110046283Sdfr return ERROR; 110119370Spst /* See if it has `f' or `l' suffix (float or long double). */ 110219370Spst 110319370Spst c = tolower (p[len - 1]); 110419370Spst 110519370Spst if (c == 'f') 110619370Spst putithere->typed_val_float.type = builtin_type_float; 110719370Spst else if (c == 'l') 110819370Spst putithere->typed_val_float.type = builtin_type_long_double; 110919370Spst else if (isdigit (c) || c == '.') 111019370Spst putithere->typed_val_float.type = builtin_type_double; 111119370Spst else 111219370Spst return ERROR; 111319370Spst 111419370Spst return FLOAT; 111519370Spst } 111619370Spst 111719370Spst /* Handle base-switching prefixes 0x, 0t, 0d, 0 */ 111819370Spst if (p[0] == '0') 111919370Spst switch (p[1]) 112019370Spst { 112119370Spst case 'x': 112219370Spst case 'X': 112319370Spst if (len >= 3) 112419370Spst { 112519370Spst p += 2; 112619370Spst base = 16; 112719370Spst len -= 2; 112819370Spst } 112919370Spst break; 113019370Spst 113119370Spst case 't': 113219370Spst case 'T': 113319370Spst case 'd': 113419370Spst case 'D': 113519370Spst if (len >= 3) 113619370Spst { 113719370Spst p += 2; 113819370Spst base = 10; 113919370Spst len -= 2; 114019370Spst } 114119370Spst break; 114219370Spst 114319370Spst default: 114419370Spst base = 8; 114519370Spst break; 114619370Spst } 114719370Spst 114819370Spst while (len-- > 0) 114919370Spst { 115019370Spst c = *p++; 115119370Spst if (c >= 'A' && c <= 'Z') 115219370Spst c += 'a' - 'A'; 115319370Spst if (c != 'l' && c != 'u') 115419370Spst n *= base; 115519370Spst if (c >= '0' && c <= '9') 115619370Spst { 115719370Spst if (found_suffix) 115819370Spst return ERROR; 115919370Spst n += i = c - '0'; 116019370Spst } 116119370Spst else 116219370Spst { 116319370Spst if (base > 10 && c >= 'a' && c <= 'f') 116419370Spst { 116519370Spst if (found_suffix) 116619370Spst return ERROR; 116719370Spst n += i = c - 'a' + 10; 116819370Spst } 116919370Spst else if (c == 'l') 117019370Spst { 117119370Spst ++long_p; 117219370Spst found_suffix = 1; 117319370Spst } 117419370Spst else if (c == 'u') 117519370Spst { 117619370Spst unsigned_p = 1; 117719370Spst found_suffix = 1; 117819370Spst } 117919370Spst else 118019370Spst return ERROR; /* Char not a digit */ 118119370Spst } 118219370Spst if (i >= base) 118319370Spst return ERROR; /* Invalid digit in this base */ 118419370Spst 118519370Spst /* Portably test for overflow (only works for nonzero values, so make 118619370Spst a second check for zero). FIXME: Can't we just make n and prevn 118719370Spst unsigned and avoid this? */ 118819370Spst if (c != 'l' && c != 'u' && (prevn >= n) && n != 0) 118919370Spst unsigned_p = 1; /* Try something unsigned */ 119019370Spst 119119370Spst /* Portably test for unsigned overflow. 119219370Spst FIXME: This check is wrong; for example it doesn't find overflow 119319370Spst on 0x123456789 when LONGEST is 32 bits. */ 119419370Spst if (c != 'l' && c != 'u' && n != 0) 119519370Spst { 119646283Sdfr if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n)) 119719370Spst error ("Numeric constant too large."); 119819370Spst } 119919370Spst prevn = n; 120019370Spst } 120119370Spst 120219370Spst /* An integer constant is an int, a long, or a long long. An L 120319370Spst suffix forces it to be long; an LL suffix forces it to be long 120419370Spst long. If not forced to a larger size, it gets the first type of 120519370Spst the above that it fits in. To figure out whether it fits, we 120619370Spst shift it right and see whether anything remains. Note that we 120719370Spst can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one 120819370Spst operation, because many compilers will warn about such a shift 120919370Spst (which always produces a zero result). Sometimes TARGET_INT_BIT 121019370Spst or TARGET_LONG_BIT will be that big, sometimes not. To deal with 121119370Spst the case where it is we just always shift the value more than 121219370Spst once, with fewer bits each time. */ 121319370Spst 121446283Sdfr un = (ULONGEST)n >> 2; 121519370Spst if (long_p == 0 121619370Spst && (un >> (TARGET_INT_BIT - 2)) == 0) 121719370Spst { 121846283Sdfr high_bit = ((ULONGEST)1) << (TARGET_INT_BIT-1); 121919370Spst 122019370Spst /* A large decimal (not hex or octal) constant (between INT_MAX 122119370Spst and UINT_MAX) is a long or unsigned long, according to ANSI, 122219370Spst never an unsigned int, but this code treats it as unsigned 122319370Spst int. This probably should be fixed. GCC gives a warning on 122419370Spst such constants. */ 122519370Spst 122619370Spst unsigned_type = builtin_type_unsigned_int; 122719370Spst signed_type = builtin_type_int; 122819370Spst } 122919370Spst else if (long_p <= 1 123019370Spst && (un >> (TARGET_LONG_BIT - 2)) == 0) 123119370Spst { 123246283Sdfr high_bit = ((ULONGEST)1) << (TARGET_LONG_BIT-1); 123319370Spst unsigned_type = builtin_type_unsigned_long; 123419370Spst signed_type = builtin_type_long; 123519370Spst } 123619370Spst else 123719370Spst { 123846283Sdfr int shift; 123946283Sdfr if (sizeof (ULONGEST) * HOST_CHAR_BIT < TARGET_LONG_LONG_BIT) 124019370Spst /* A long long does not fit in a LONGEST. */ 124146283Sdfr shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1); 124246283Sdfr else 124346283Sdfr shift = (TARGET_LONG_LONG_BIT - 1); 124446283Sdfr high_bit = (ULONGEST) 1 << shift; 124519370Spst unsigned_type = builtin_type_unsigned_long_long; 124619370Spst signed_type = builtin_type_long_long; 124719370Spst } 124819370Spst 124919370Spst putithere->typed_val_int.val = n; 125019370Spst 125119370Spst /* If the high bit of the worked out type is set then this number 125219370Spst has to be unsigned. */ 125319370Spst 125419370Spst if (unsigned_p || (n & high_bit)) 125519370Spst { 125619370Spst putithere->typed_val_int.type = unsigned_type; 125719370Spst } 125819370Spst else 125919370Spst { 126019370Spst putithere->typed_val_int.type = signed_type; 126119370Spst } 126219370Spst 126319370Spst return INT; 126419370Spst} 126519370Spst 126619370Spststruct token 126719370Spst{ 126819370Spst char *operator; 126919370Spst int token; 127019370Spst enum exp_opcode opcode; 127119370Spst}; 127219370Spst 127319370Spststatic const struct token tokentab3[] = 127419370Spst { 127519370Spst {">>=", ASSIGN_MODIFY, BINOP_RSH}, 127619370Spst {"<<=", ASSIGN_MODIFY, BINOP_LSH} 127719370Spst }; 127819370Spst 127919370Spststatic const struct token tokentab2[] = 128019370Spst { 128119370Spst {"+=", ASSIGN_MODIFY, BINOP_ADD}, 128219370Spst {"-=", ASSIGN_MODIFY, BINOP_SUB}, 128319370Spst {"*=", ASSIGN_MODIFY, BINOP_MUL}, 128419370Spst {"/=", ASSIGN_MODIFY, BINOP_DIV}, 128519370Spst {"%=", ASSIGN_MODIFY, BINOP_REM}, 128619370Spst {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR}, 128719370Spst {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND}, 128819370Spst {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR}, 128919370Spst {"++", INCREMENT, BINOP_END}, 129019370Spst {"--", DECREMENT, BINOP_END}, 129119370Spst {"->", ARROW, BINOP_END}, 129219370Spst {"&&", ANDAND, BINOP_END}, 129319370Spst {"||", OROR, BINOP_END}, 129419370Spst {"::", COLONCOLON, BINOP_END}, 129519370Spst {"<<", LSH, BINOP_END}, 129619370Spst {">>", RSH, BINOP_END}, 129719370Spst {"==", EQUAL, BINOP_END}, 129819370Spst {"!=", NOTEQUAL, BINOP_END}, 129919370Spst {"<=", LEQ, BINOP_END}, 130019370Spst {">=", GEQ, BINOP_END} 130119370Spst }; 130219370Spst 130319370Spst/* Read one token, getting characters through lexptr. */ 130419370Spst 130519370Spststatic int 130619370Spstyylex () 130719370Spst{ 130819370Spst int c; 130919370Spst int namelen; 131019370Spst unsigned int i; 131119370Spst char *tokstart; 131219370Spst char *tokptr; 131319370Spst int tempbufindex; 131419370Spst static char *tempbuf; 131519370Spst static int tempbufsize; 131646283Sdfr struct symbol * sym_class = NULL; 131746283Sdfr char * token_string = NULL; 131846283Sdfr int class_prefix = 0; 131946283Sdfr int unquoted_expr; 132046283Sdfr 132119370Spst retry: 132219370Spst 1323130803Smarcel /* Check if this is a macro invocation that we need to expand. */ 1324130803Smarcel if (! scanning_macro_expansion ()) 1325130803Smarcel { 1326130803Smarcel char *expanded = macro_expand_next (&lexptr, 1327130803Smarcel expression_macro_lookup_func, 1328130803Smarcel expression_macro_lookup_baton); 1329130803Smarcel 1330130803Smarcel if (expanded) 1331130803Smarcel scan_macro_expansion (expanded); 1332130803Smarcel } 1333130803Smarcel 1334130803Smarcel prev_lexptr = lexptr; 133546283Sdfr unquoted_expr = 1; 133646283Sdfr 133719370Spst tokstart = lexptr; 133819370Spst /* See if it is a special token of length 3. */ 133919370Spst for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++) 1340130803Smarcel if (strncmp (tokstart, tokentab3[i].operator, 3) == 0) 134119370Spst { 134219370Spst lexptr += 3; 134319370Spst yylval.opcode = tokentab3[i].opcode; 134419370Spst return tokentab3[i].token; 134519370Spst } 134619370Spst 134719370Spst /* See if it is a special token of length 2. */ 134819370Spst for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++) 1349130803Smarcel if (strncmp (tokstart, tokentab2[i].operator, 2) == 0) 135019370Spst { 135119370Spst lexptr += 2; 135219370Spst yylval.opcode = tokentab2[i].opcode; 135319370Spst return tokentab2[i].token; 135419370Spst } 135519370Spst 135619370Spst switch (c = *tokstart) 135719370Spst { 135819370Spst case 0: 1359130803Smarcel /* If we were just scanning the result of a macro expansion, 1360130803Smarcel then we need to resume scanning the original text. 1361130803Smarcel Otherwise, we were already scanning the original text, and 1362130803Smarcel we're really done. */ 1363130803Smarcel if (scanning_macro_expansion ()) 1364130803Smarcel { 1365130803Smarcel finished_macro_expansion (); 1366130803Smarcel goto retry; 1367130803Smarcel } 1368130803Smarcel else 1369130803Smarcel return 0; 137019370Spst 137119370Spst case ' ': 137219370Spst case '\t': 137319370Spst case '\n': 137419370Spst lexptr++; 137519370Spst goto retry; 137619370Spst 137719370Spst case '\'': 137819370Spst /* We either have a character constant ('0' or '\177' for example) 137919370Spst or we have a quoted symbol reference ('foo(int,int)' in C++ 138019370Spst for example). */ 138119370Spst lexptr++; 138219370Spst c = *lexptr++; 138319370Spst if (c == '\\') 138419370Spst c = parse_escape (&lexptr); 138519370Spst else if (c == '\'') 138619370Spst error ("Empty character constant."); 1387130803Smarcel else if (! host_char_to_target (c, &c)) 1388130803Smarcel { 1389130803Smarcel int toklen = lexptr - tokstart + 1; 1390130803Smarcel char *tok = alloca (toklen + 1); 1391130803Smarcel memcpy (tok, tokstart, toklen); 1392130803Smarcel tok[toklen] = '\0'; 1393130803Smarcel error ("There is no character corresponding to %s in the target " 1394130803Smarcel "character set `%s'.", tok, target_charset ()); 1395130803Smarcel } 139619370Spst 139719370Spst yylval.typed_val_int.val = c; 139819370Spst yylval.typed_val_int.type = builtin_type_char; 139919370Spst 140019370Spst c = *lexptr++; 140119370Spst if (c != '\'') 140219370Spst { 140319370Spst namelen = skip_quoted (tokstart) - tokstart; 140419370Spst if (namelen > 2) 140519370Spst { 140619370Spst lexptr = tokstart + namelen; 140746283Sdfr unquoted_expr = 0; 140819370Spst if (lexptr[-1] != '\'') 140919370Spst error ("Unmatched single quote."); 141019370Spst namelen -= 2; 141119370Spst tokstart++; 141219370Spst goto tryname; 141319370Spst } 141419370Spst error ("Invalid character constant."); 141519370Spst } 141619370Spst return INT; 141719370Spst 141819370Spst case '(': 141919370Spst paren_depth++; 142019370Spst lexptr++; 142119370Spst return c; 142219370Spst 142319370Spst case ')': 142419370Spst if (paren_depth == 0) 142519370Spst return 0; 142619370Spst paren_depth--; 142719370Spst lexptr++; 142819370Spst return c; 142919370Spst 143019370Spst case ',': 1431130803Smarcel if (comma_terminates 1432130803Smarcel && paren_depth == 0 1433130803Smarcel && ! scanning_macro_expansion ()) 143419370Spst return 0; 143519370Spst lexptr++; 143619370Spst return c; 143719370Spst 143819370Spst case '.': 143919370Spst /* Might be a floating point number. */ 144019370Spst if (lexptr[1] < '0' || lexptr[1] > '9') 144119370Spst goto symbol; /* Nope, must be a symbol. */ 144219370Spst /* FALL THRU into number case. */ 144319370Spst 144419370Spst case '0': 144519370Spst case '1': 144619370Spst case '2': 144719370Spst case '3': 144819370Spst case '4': 144919370Spst case '5': 145019370Spst case '6': 145119370Spst case '7': 145219370Spst case '8': 145319370Spst case '9': 145419370Spst { 145519370Spst /* It's a number. */ 145619370Spst int got_dot = 0, got_e = 0, toktype; 1457130803Smarcel char *p = tokstart; 145819370Spst int hex = input_radix > 10; 145919370Spst 146019370Spst if (c == '0' && (p[1] == 'x' || p[1] == 'X')) 146119370Spst { 146219370Spst p += 2; 146319370Spst hex = 1; 146419370Spst } 146519370Spst else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D')) 146619370Spst { 146719370Spst p += 2; 146819370Spst hex = 0; 146919370Spst } 147019370Spst 147119370Spst for (;; ++p) 147219370Spst { 147319370Spst /* This test includes !hex because 'e' is a valid hex digit 147419370Spst and thus does not indicate a floating point number when 147519370Spst the radix is hex. */ 147619370Spst if (!hex && !got_e && (*p == 'e' || *p == 'E')) 147719370Spst got_dot = got_e = 1; 147819370Spst /* This test does not include !hex, because a '.' always indicates 147919370Spst a decimal floating point number regardless of the radix. */ 148019370Spst else if (!got_dot && *p == '.') 148119370Spst got_dot = 1; 148219370Spst else if (got_e && (p[-1] == 'e' || p[-1] == 'E') 148319370Spst && (*p == '-' || *p == '+')) 148419370Spst /* This is the sign of the exponent, not the end of the 148519370Spst number. */ 148619370Spst continue; 148719370Spst /* We will take any letters or digits. parse_number will 148819370Spst complain if past the radix, or if L or U are not final. */ 148919370Spst else if ((*p < '0' || *p > '9') 149019370Spst && ((*p < 'a' || *p > 'z') 149119370Spst && (*p < 'A' || *p > 'Z'))) 149219370Spst break; 149319370Spst } 149419370Spst toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval); 149519370Spst if (toktype == ERROR) 149619370Spst { 149719370Spst char *err_copy = (char *) alloca (p - tokstart + 1); 149819370Spst 149919370Spst memcpy (err_copy, tokstart, p - tokstart); 150019370Spst err_copy[p - tokstart] = 0; 150119370Spst error ("Invalid number \"%s\".", err_copy); 150219370Spst } 150319370Spst lexptr = p; 150419370Spst return toktype; 150519370Spst } 150619370Spst 150719370Spst case '+': 150819370Spst case '-': 150919370Spst case '*': 151019370Spst case '/': 151119370Spst case '%': 151219370Spst case '|': 151319370Spst case '&': 151419370Spst case '^': 151519370Spst case '~': 151619370Spst case '!': 151719370Spst case '@': 151819370Spst case '<': 151919370Spst case '>': 152019370Spst case '[': 152119370Spst case ']': 152219370Spst case '?': 152319370Spst case ':': 152419370Spst case '=': 152519370Spst case '{': 152619370Spst case '}': 152719370Spst symbol: 152819370Spst lexptr++; 152919370Spst return c; 153019370Spst 153119370Spst case '"': 153219370Spst 153319370Spst /* Build the gdb internal form of the input string in tempbuf, 153419370Spst translating any standard C escape forms seen. Note that the 153519370Spst buffer is null byte terminated *only* for the convenience of 153619370Spst debugging gdb itself and printing the buffer contents when 153719370Spst the buffer contains no embedded nulls. Gdb does not depend 153819370Spst upon the buffer being null byte terminated, it uses the length 153919370Spst string instead. This allows gdb to handle C strings (as well 154019370Spst as strings in other languages) with embedded null bytes */ 154119370Spst 154219370Spst tokptr = ++tokstart; 154319370Spst tempbufindex = 0; 154419370Spst 154519370Spst do { 1546130803Smarcel char *char_start_pos = tokptr; 1547130803Smarcel 154819370Spst /* Grow the static temp buffer if necessary, including allocating 154919370Spst the first one on demand. */ 155019370Spst if (tempbufindex + 1 >= tempbufsize) 155119370Spst { 155219370Spst tempbuf = (char *) realloc (tempbuf, tempbufsize += 64); 155319370Spst } 155419370Spst switch (*tokptr) 155519370Spst { 155619370Spst case '\0': 155719370Spst case '"': 155819370Spst /* Do nothing, loop will terminate. */ 155919370Spst break; 156019370Spst case '\\': 156119370Spst tokptr++; 156219370Spst c = parse_escape (&tokptr); 156319370Spst if (c == -1) 156419370Spst { 156519370Spst continue; 156619370Spst } 156719370Spst tempbuf[tempbufindex++] = c; 156819370Spst break; 156919370Spst default: 1570130803Smarcel c = *tokptr++; 1571130803Smarcel if (! host_char_to_target (c, &c)) 1572130803Smarcel { 1573130803Smarcel int len = tokptr - char_start_pos; 1574130803Smarcel char *copy = alloca (len + 1); 1575130803Smarcel memcpy (copy, char_start_pos, len); 1576130803Smarcel copy[len] = '\0'; 1577130803Smarcel 1578130803Smarcel error ("There is no character corresponding to `%s' " 1579130803Smarcel "in the target character set `%s'.", 1580130803Smarcel copy, target_charset ()); 1581130803Smarcel } 1582130803Smarcel tempbuf[tempbufindex++] = c; 158319370Spst break; 158419370Spst } 158519370Spst } while ((*tokptr != '"') && (*tokptr != '\0')); 158619370Spst if (*tokptr++ != '"') 158719370Spst { 158819370Spst error ("Unterminated string in expression."); 158919370Spst } 159019370Spst tempbuf[tempbufindex] = '\0'; /* See note above */ 159119370Spst yylval.sval.ptr = tempbuf; 159219370Spst yylval.sval.length = tempbufindex; 159319370Spst lexptr = tokptr; 159419370Spst return (STRING); 159519370Spst } 159619370Spst 159719370Spst if (!(c == '_' || c == '$' 159819370Spst || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) 159919370Spst /* We must have come across a bad character (e.g. ';'). */ 160019370Spst error ("Invalid character '%c' in expression.", c); 160119370Spst 160219370Spst /* It's a name. See how long it is. */ 160319370Spst namelen = 0; 160419370Spst for (c = tokstart[namelen]; 160519370Spst (c == '_' || c == '$' || (c >= '0' && c <= '9') 160619370Spst || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');) 160719370Spst { 160846283Sdfr /* Template parameter lists are part of the name. 160946283Sdfr FIXME: This mishandles `print $a<4&&$a>3'. */ 161019370Spst 161146283Sdfr if (c == '<') 161246283Sdfr { 161346283Sdfr /* Scan ahead to get rest of the template specification. Note 161446283Sdfr that we look ahead only when the '<' adjoins non-whitespace 161546283Sdfr characters; for comparison expressions, e.g. "a < b > c", 161646283Sdfr there must be spaces before the '<', etc. */ 161746283Sdfr 161846283Sdfr char * p = find_template_name_end (tokstart + namelen); 161946283Sdfr if (p) 162046283Sdfr namelen = p - tokstart; 162146283Sdfr break; 162246283Sdfr } 162346283Sdfr c = tokstart[++namelen]; 162446283Sdfr } 162546283Sdfr 1626130803Smarcel /* The token "if" terminates the expression and is NOT removed from 1627130803Smarcel the input stream. It doesn't count if it appears in the 1628130803Smarcel expansion of a macro. */ 1629130803Smarcel if (namelen == 2 1630130803Smarcel && tokstart[0] == 'i' 1631130803Smarcel && tokstart[1] == 'f' 1632130803Smarcel && ! scanning_macro_expansion ()) 163319370Spst { 163419370Spst return 0; 163519370Spst } 163619370Spst 163719370Spst lexptr += namelen; 163819370Spst 163919370Spst tryname: 164019370Spst 164119370Spst /* Catch specific keywords. Should be done with a data structure. */ 164219370Spst switch (namelen) 164319370Spst { 164419370Spst case 8: 1645130803Smarcel if (strncmp (tokstart, "unsigned", 8) == 0) 164619370Spst return UNSIGNED; 164719370Spst if (current_language->la_language == language_cplus 1648130803Smarcel && strncmp (tokstart, "template", 8) == 0) 164919370Spst return TEMPLATE; 1650130803Smarcel if (strncmp (tokstart, "volatile", 8) == 0) 165119370Spst return VOLATILE_KEYWORD; 165219370Spst break; 165319370Spst case 6: 1654130803Smarcel if (strncmp (tokstart, "struct", 6) == 0) 165519370Spst return STRUCT; 1656130803Smarcel if (strncmp (tokstart, "signed", 6) == 0) 165719370Spst return SIGNED_KEYWORD; 1658130803Smarcel if (strncmp (tokstart, "sizeof", 6) == 0) 165919370Spst return SIZEOF; 1660130803Smarcel if (strncmp (tokstart, "double", 6) == 0) 166119370Spst return DOUBLE_KEYWORD; 166219370Spst break; 166319370Spst case 5: 166446283Sdfr if (current_language->la_language == language_cplus) 166546283Sdfr { 1666130803Smarcel if (strncmp (tokstart, "false", 5) == 0) 166746283Sdfr return FALSEKEYWORD; 1668130803Smarcel if (strncmp (tokstart, "class", 5) == 0) 166946283Sdfr return CLASS; 167046283Sdfr } 1671130803Smarcel if (strncmp (tokstart, "union", 5) == 0) 167219370Spst return UNION; 1673130803Smarcel if (strncmp (tokstart, "short", 5) == 0) 167419370Spst return SHORT; 1675130803Smarcel if (strncmp (tokstart, "const", 5) == 0) 167619370Spst return CONST_KEYWORD; 167719370Spst break; 167819370Spst case 4: 1679130803Smarcel if (strncmp (tokstart, "enum", 4) == 0) 168019370Spst return ENUM; 1681130803Smarcel if (strncmp (tokstart, "long", 4) == 0) 168219370Spst return LONG; 168346283Sdfr if (current_language->la_language == language_cplus) 168446283Sdfr { 1685130803Smarcel if (strncmp (tokstart, "true", 4) == 0) 168646283Sdfr return TRUEKEYWORD; 168746283Sdfr } 168819370Spst break; 168919370Spst case 3: 1690130803Smarcel if (strncmp (tokstart, "int", 3) == 0) 169119370Spst return INT_KEYWORD; 169219370Spst break; 169319370Spst default: 169419370Spst break; 169519370Spst } 169619370Spst 169719370Spst yylval.sval.ptr = tokstart; 169819370Spst yylval.sval.length = namelen; 169919370Spst 170019370Spst if (*tokstart == '$') 170119370Spst { 170219370Spst write_dollar_variable (yylval.sval); 170319370Spst return VARIABLE; 170419370Spst } 170546283Sdfr 170646283Sdfr /* Look ahead and see if we can consume more of the input 170746283Sdfr string to get a reasonable class/namespace spec or a 170846283Sdfr fully-qualified name. This is a kludge to get around the 170946283Sdfr HP aCC compiler's generation of symbol names with embedded 1710130803Smarcel colons for namespace and nested classes. */ 1711130803Smarcel 1712130803Smarcel /* NOTE: carlton/2003-09-24: I don't entirely understand the 1713130803Smarcel HP-specific code, either here or in linespec. Having said that, 1714130803Smarcel I suspect that we're actually moving towards their model: we want 1715130803Smarcel symbols whose names are fully qualified, which matches the 1716130803Smarcel description above. */ 171746283Sdfr if (unquoted_expr) 171846283Sdfr { 171946283Sdfr /* Only do it if not inside single quotes */ 172046283Sdfr sym_class = parse_nested_classes_for_hpacc (yylval.sval.ptr, yylval.sval.length, 172146283Sdfr &token_string, &class_prefix, &lexptr); 172246283Sdfr if (sym_class) 172346283Sdfr { 172446283Sdfr /* Replace the current token with the bigger one we found */ 172546283Sdfr yylval.sval.ptr = token_string; 172646283Sdfr yylval.sval.length = strlen (token_string); 172746283Sdfr } 172846283Sdfr } 172946283Sdfr 173019370Spst /* Use token-type BLOCKNAME for symbols that happen to be defined as 173119370Spst functions or symtabs. If this is not so, then ... 173219370Spst Use token-type TYPENAME for symbols that happen to be defined 173319370Spst currently as names of types; NAME for other symbols. 173419370Spst The caller is not constrained to care about the distinction. */ 173519370Spst { 173619370Spst char *tmp = copy_name (yylval.sval); 173719370Spst struct symbol *sym; 173819370Spst int is_a_field_of_this = 0; 173919370Spst int hextype; 174019370Spst 174119370Spst sym = lookup_symbol (tmp, expression_context_block, 1742130803Smarcel VAR_DOMAIN, 174319370Spst current_language->la_language == language_cplus 174419370Spst ? &is_a_field_of_this : (int *) NULL, 174519370Spst (struct symtab **) NULL); 174619370Spst /* Call lookup_symtab, not lookup_partial_symtab, in case there are 174719370Spst no psymtabs (coff, xcoff, or some future change to blow away the 174819370Spst psymtabs once once symbols are read). */ 174946283Sdfr if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) 175019370Spst { 175119370Spst yylval.ssym.sym = sym; 175219370Spst yylval.ssym.is_a_field_of_this = is_a_field_of_this; 175319370Spst return BLOCKNAME; 175419370Spst } 175546283Sdfr else if (!sym) 175646283Sdfr { /* See if it's a file name. */ 175746283Sdfr struct symtab *symtab; 175846283Sdfr 175946283Sdfr symtab = lookup_symtab (tmp); 176046283Sdfr 176146283Sdfr if (symtab) 176246283Sdfr { 176346283Sdfr yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK); 176446283Sdfr return FILENAME; 176546283Sdfr } 176646283Sdfr } 176746283Sdfr 176819370Spst if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF) 176919370Spst { 1770130803Smarcel /* NOTE: carlton/2003-09-25: There used to be code here to 1771130803Smarcel handle nested types. It didn't work very well. See the 1772130803Smarcel comment before qualified_type for more info. */ 177319370Spst yylval.tsym.type = SYMBOL_TYPE (sym); 177419370Spst return TYPENAME; 177519370Spst } 177619370Spst if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0) 177798944Sobrien return TYPENAME; 177819370Spst 177919370Spst /* Input names that aren't symbols but ARE valid hex numbers, 178019370Spst when the input radix permits them, can be names or numbers 178119370Spst depending on the parse. Note we support radixes > 16 here. */ 178219370Spst if (!sym && 178319370Spst ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) || 178419370Spst (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10))) 178519370Spst { 178619370Spst YYSTYPE newlval; /* Its value is ignored. */ 178719370Spst hextype = parse_number (tokstart, namelen, 0, &newlval); 178819370Spst if (hextype == INT) 178919370Spst { 179019370Spst yylval.ssym.sym = sym; 179119370Spst yylval.ssym.is_a_field_of_this = is_a_field_of_this; 179219370Spst return NAME_OR_INT; 179319370Spst } 179419370Spst } 179519370Spst 179619370Spst /* Any other kind of symbol */ 179719370Spst yylval.ssym.sym = sym; 179819370Spst yylval.ssym.is_a_field_of_this = is_a_field_of_this; 179919370Spst return NAME; 180019370Spst } 180119370Spst} 180219370Spst 180319370Spstvoid 180419370Spstyyerror (msg) 180519370Spst char *msg; 180619370Spst{ 1807130803Smarcel if (prev_lexptr) 1808130803Smarcel lexptr = prev_lexptr; 1809130803Smarcel 181019370Spst error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr); 181119370Spst} 1812