| 1 | /* YACC parser for C expressions, for GDB. |
| 2 | Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, |
| 3 | 1998, 1999, 2000, 2003, 2004, 2006, 2007, 2008 |
| 4 | Free Software Foundation, Inc. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | Boston, MA 02110-1301, USA. */ |
| 22 | |
| 23 | /* Parse a C expression from text in a string, |
| 24 | and return the result as a struct expression pointer. |
| 25 | That structure contains arithmetic operations in reverse polish, |
| 26 | with constants represented by operations that are followed by special data. |
| 27 | See expression.h for the details of the format. |
| 28 | What is important here is that it can be built up sequentially |
| 29 | during the process of parsing; the lower levels of the tree always |
| 30 | come first in the result. |
| 31 | |
| 32 | Note that malloc's and realloc's in this file are transformed to |
| 33 | xmalloc and xrealloc respectively by the same sed command in the |
| 34 | makefile that remaps any other malloc/realloc inserted by the parser |
| 35 | generator. Doing this with #defines and trying to control the interaction |
| 36 | with include files (<malloc.h> and <stdlib.h> for example) just became |
| 37 | too messy, particularly when such includes can be inserted at random |
| 38 | times by the parser generator. */ |
| 39 | |
| 40 | %{ |
| 41 | |
| 42 | #include "defs.h" |
| 43 | #include "gdb_string.h" |
| 44 | #include <ctype.h> |
| 45 | #include "expression.h" |
| 46 | #include "value.h" |
| 47 | #include "parser-defs.h" |
| 48 | #include "language.h" |
| 49 | #include "c-lang.h" |
| 50 | #include "bfd.h" /* Required by objfiles.h. */ |
| 51 | #include "symfile.h" /* Required by objfiles.h. */ |
| 52 | #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ |
| 53 | #include "charset.h" |
| 54 | #include "block.h" |
| 55 | #include "cp-support.h" |
| 56 | #include "dfp.h" |
| 57 | |
| 58 | /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), |
| 59 | as well as gratuitiously global symbol names, so we can have multiple |
| 60 | yacc generated parsers in gdb. Note that these are only the variables |
| 61 | produced by yacc. If other parser generators (bison, byacc, etc) produce |
| 62 | additional global names that conflict at link time, then those parser |
| 63 | generators need to be fixed instead of adding those names to this list. */ |
| 64 | |
| 65 | #define yymaxdepth c_maxdepth |
| 66 | #define yyparse c_parse_internal |
| 67 | #define yylex c_lex |
| 68 | #define yyerror c_error |
| 69 | #define yylval c_lval |
| 70 | #define yychar c_char |
| 71 | #define yydebug c_debug |
| 72 | #define yypact c_pact |
| 73 | #define yyr1 c_r1 |
| 74 | #define yyr2 c_r2 |
| 75 | #define yydef c_def |
| 76 | #define yychk c_chk |
| 77 | #define yypgo c_pgo |
| 78 | #define yyact c_act |
| 79 | #define yyexca c_exca |
| 80 | #define yyerrflag c_errflag |
| 81 | #define yynerrs c_nerrs |
| 82 | #define yyps c_ps |
| 83 | #define yypv c_pv |
| 84 | #define yys c_s |
| 85 | #define yy_yys c_yys |
| 86 | #define yystate c_state |
| 87 | #define yytmp c_tmp |
| 88 | #define yyv c_v |
| 89 | #define yy_yyv c_yyv |
| 90 | #define yyval c_val |
| 91 | #define yylloc c_lloc |
| 92 | #define yyreds c_reds /* With YYDEBUG defined */ |
| 93 | #define yytoks c_toks /* With YYDEBUG defined */ |
| 94 | #define yyname c_name /* With YYDEBUG defined */ |
| 95 | #define yyrule c_rule /* With YYDEBUG defined */ |
| 96 | #define yylhs c_yylhs |
| 97 | #define yylen c_yylen |
| 98 | #define yydefred c_yydefred |
| 99 | #define yydgoto c_yydgoto |
| 100 | #define yysindex c_yysindex |
| 101 | #define yyrindex c_yyrindex |
| 102 | #define yygindex c_yygindex |
| 103 | #define yytable c_yytable |
| 104 | #define yycheck c_yycheck |
| 105 | |
| 106 | #ifndef YYDEBUG |
| 107 | #define YYDEBUG 1 /* Default to yydebug support */ |
| 108 | #endif |
| 109 | |
| 110 | #define YYFPRINTF parser_fprintf |
| 111 | |
| 112 | int yyparse (void); |
| 113 | |
| 114 | static int yylex (void); |
| 115 | |
| 116 | void yyerror (char *); |
| 117 | |
| 118 | %} |
| 119 | |
| 120 | /* Although the yacc "value" of an expression is not used, |
| 121 | since the result is stored in the structure being created, |
| 122 | other node types do have values. */ |
| 123 | |
| 124 | %union |
| 125 | { |
| 126 | LONGEST lval; |
| 127 | struct { |
| 128 | LONGEST val; |
| 129 | struct type *type; |
| 130 | } typed_val_int; |
| 131 | struct { |
| 132 | DOUBLEST dval; |
| 133 | struct type *type; |
| 134 | } typed_val_float; |
| 135 | struct { |
| 136 | gdb_byte val[16]; |
| 137 | struct type *type; |
| 138 | } typed_val_decfloat; |
| 139 | struct symbol *sym; |
| 140 | struct type *tval; |
| 141 | struct stoken sval; |
| 142 | struct ttype tsym; |
| 143 | struct symtoken ssym; |
| 144 | int voidval; |
| 145 | struct block *bval; |
| 146 | enum exp_opcode opcode; |
| 147 | struct internalvar *ivar; |
| 148 | |
| 149 | struct type **tvec; |
| 150 | int *ivec; |
| 151 | } |
| 152 | |
| 153 | %{ |
| 154 | /* YYSTYPE gets defined by %union */ |
| 155 | static int parse_number (char *, int, int, YYSTYPE *); |
| 156 | %} |
| 157 | |
| 158 | %type <voidval> exp exp1 type_exp start variable qualified_name lcurly |
| 159 | %type <lval> rcurly |
| 160 | %type <tval> type typebase qualified_type |
| 161 | %type <tvec> nonempty_typelist |
| 162 | /* %type <bval> block */ |
| 163 | |
| 164 | /* Fancy type parsing. */ |
| 165 | %type <voidval> func_mod direct_abs_decl abs_decl |
| 166 | %type <tval> ptype |
| 167 | %type <lval> array_mod |
| 168 | |
| 169 | %token <typed_val_int> INT |
| 170 | %token <typed_val_float> FLOAT |
| 171 | %token <typed_val_decfloat> DECFLOAT |
| 172 | |
| 173 | /* Both NAME and TYPENAME tokens represent symbols in the input, |
| 174 | and both convey their data as strings. |
| 175 | But a TYPENAME is a string that happens to be defined as a typedef |
| 176 | or builtin type name (such as int or char) |
| 177 | and a NAME is any other symbol. |
| 178 | Contexts where this distinction is not important can use the |
| 179 | nonterminal "name", which matches either NAME or TYPENAME. */ |
| 180 | |
| 181 | %token <sval> STRING |
| 182 | %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */ |
| 183 | %token <voidval> COMPLETE |
| 184 | %token <tsym> TYPENAME |
| 185 | %type <sval> name |
| 186 | %type <ssym> name_not_typename |
| 187 | %type <tsym> typename |
| 188 | |
| 189 | /* A NAME_OR_INT is a symbol which is not known in the symbol table, |
| 190 | but which would parse as a valid number in the current input radix. |
| 191 | E.g. "c" when input_radix==16. Depending on the parse, it will be |
| 192 | turned into a name or into a number. */ |
| 193 | |
| 194 | %token <ssym> NAME_OR_INT |
| 195 | |
| 196 | %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON |
| 197 | %token TEMPLATE |
| 198 | %token ERROR |
| 199 | |
| 200 | /* Special type cases, put in to allow the parser to distinguish different |
| 201 | legal basetypes. */ |
| 202 | %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD |
| 203 | |
| 204 | %token <voidval> VARIABLE |
| 205 | |
| 206 | %token <opcode> ASSIGN_MODIFY |
| 207 | |
| 208 | /* C++ */ |
| 209 | %token TRUEKEYWORD |
| 210 | %token FALSEKEYWORD |
| 211 | |
| 212 | |
| 213 | %left ',' |
| 214 | %left ABOVE_COMMA |
| 215 | %right '=' ASSIGN_MODIFY |
| 216 | %right '?' |
| 217 | %left OROR |
| 218 | %left ANDAND |
| 219 | %left '|' |
| 220 | %left '^' |
| 221 | %left '&' |
| 222 | %left EQUAL NOTEQUAL |
| 223 | %left '<' '>' LEQ GEQ |
| 224 | %left LSH RSH |
| 225 | %left '@' |
| 226 | %left '+' '-' |
| 227 | %left '*' '/' '%' |
| 228 | %right UNARY INCREMENT DECREMENT |
| 229 | %right ARROW '.' '[' '(' |
| 230 | %token <ssym> BLOCKNAME |
| 231 | %token <bval> FILENAME |
| 232 | %type <bval> block |
| 233 | %left COLONCOLON |
| 234 | |
| 235 | \f |
| 236 | %% |
| 237 | |
| 238 | start : exp1 |
| 239 | | type_exp |
| 240 | ; |
| 241 | |
| 242 | type_exp: type |
| 243 | { write_exp_elt_opcode(OP_TYPE); |
| 244 | write_exp_elt_type($1); |
| 245 | write_exp_elt_opcode(OP_TYPE);} |
| 246 | ; |
| 247 | |
| 248 | /* Expressions, including the comma operator. */ |
| 249 | exp1 : exp |
| 250 | | exp1 ',' exp |
| 251 | { write_exp_elt_opcode (BINOP_COMMA); } |
| 252 | ; |
| 253 | |
| 254 | /* Expressions, not including the comma operator. */ |
| 255 | exp : '*' exp %prec UNARY |
| 256 | { write_exp_elt_opcode (UNOP_IND); } |
| 257 | ; |
| 258 | |
| 259 | exp : '&' exp %prec UNARY |
| 260 | { write_exp_elt_opcode (UNOP_ADDR); } |
| 261 | ; |
| 262 | |
| 263 | exp : '-' exp %prec UNARY |
| 264 | { write_exp_elt_opcode (UNOP_NEG); } |
| 265 | ; |
| 266 | |
| 267 | exp : '+' exp %prec UNARY |
| 268 | { write_exp_elt_opcode (UNOP_PLUS); } |
| 269 | ; |
| 270 | |
| 271 | exp : '!' exp %prec UNARY |
| 272 | { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } |
| 273 | ; |
| 274 | |
| 275 | exp : '~' exp %prec UNARY |
| 276 | { write_exp_elt_opcode (UNOP_COMPLEMENT); } |
| 277 | ; |
| 278 | |
| 279 | exp : INCREMENT exp %prec UNARY |
| 280 | { write_exp_elt_opcode (UNOP_PREINCREMENT); } |
| 281 | ; |
| 282 | |
| 283 | exp : DECREMENT exp %prec UNARY |
| 284 | { write_exp_elt_opcode (UNOP_PREDECREMENT); } |
| 285 | ; |
| 286 | |
| 287 | exp : exp INCREMENT %prec UNARY |
| 288 | { write_exp_elt_opcode (UNOP_POSTINCREMENT); } |
| 289 | ; |
| 290 | |
| 291 | exp : exp DECREMENT %prec UNARY |
| 292 | { write_exp_elt_opcode (UNOP_POSTDECREMENT); } |
| 293 | ; |
| 294 | |
| 295 | exp : SIZEOF exp %prec UNARY |
| 296 | { write_exp_elt_opcode (UNOP_SIZEOF); } |
| 297 | ; |
| 298 | |
| 299 | exp : exp ARROW name |
| 300 | { write_exp_elt_opcode (STRUCTOP_PTR); |
| 301 | write_exp_string ($3); |
| 302 | write_exp_elt_opcode (STRUCTOP_PTR); } |
| 303 | ; |
| 304 | |
| 305 | exp : exp ARROW name COMPLETE |
| 306 | { mark_struct_expression (); |
| 307 | write_exp_elt_opcode (STRUCTOP_PTR); |
| 308 | write_exp_string ($3); |
| 309 | write_exp_elt_opcode (STRUCTOP_PTR); } |
| 310 | ; |
| 311 | |
| 312 | exp : exp ARROW COMPLETE |
| 313 | { struct stoken s; |
| 314 | mark_struct_expression (); |
| 315 | write_exp_elt_opcode (STRUCTOP_PTR); |
| 316 | s.ptr = ""; |
| 317 | s.length = 0; |
| 318 | write_exp_string (s); |
| 319 | write_exp_elt_opcode (STRUCTOP_PTR); } |
| 320 | ; |
| 321 | |
| 322 | exp : exp ARROW qualified_name |
| 323 | { /* exp->type::name becomes exp->*(&type::name) */ |
| 324 | /* Note: this doesn't work if name is a |
| 325 | static member! FIXME */ |
| 326 | write_exp_elt_opcode (UNOP_ADDR); |
| 327 | write_exp_elt_opcode (STRUCTOP_MPTR); } |
| 328 | ; |
| 329 | |
| 330 | exp : exp ARROW '*' exp |
| 331 | { write_exp_elt_opcode (STRUCTOP_MPTR); } |
| 332 | ; |
| 333 | |
| 334 | exp : exp '.' name |
| 335 | { write_exp_elt_opcode (STRUCTOP_STRUCT); |
| 336 | write_exp_string ($3); |
| 337 | write_exp_elt_opcode (STRUCTOP_STRUCT); } |
| 338 | ; |
| 339 | |
| 340 | exp : exp '.' name COMPLETE |
| 341 | { mark_struct_expression (); |
| 342 | write_exp_elt_opcode (STRUCTOP_STRUCT); |
| 343 | write_exp_string ($3); |
| 344 | write_exp_elt_opcode (STRUCTOP_STRUCT); } |
| 345 | ; |
| 346 | |
| 347 | exp : exp '.' COMPLETE |
| 348 | { struct stoken s; |
| 349 | mark_struct_expression (); |
| 350 | write_exp_elt_opcode (STRUCTOP_STRUCT); |
| 351 | s.ptr = ""; |
| 352 | s.length = 0; |
| 353 | write_exp_string (s); |
| 354 | write_exp_elt_opcode (STRUCTOP_STRUCT); } |
| 355 | ; |
| 356 | |
| 357 | exp : exp '.' qualified_name |
| 358 | { /* exp.type::name becomes exp.*(&type::name) */ |
| 359 | /* Note: this doesn't work if name is a |
| 360 | static member! FIXME */ |
| 361 | write_exp_elt_opcode (UNOP_ADDR); |
| 362 | write_exp_elt_opcode (STRUCTOP_MEMBER); } |
| 363 | ; |
| 364 | |
| 365 | exp : exp '.' '*' exp |
| 366 | { write_exp_elt_opcode (STRUCTOP_MEMBER); } |
| 367 | ; |
| 368 | |
| 369 | exp : exp '[' exp1 ']' |
| 370 | { write_exp_elt_opcode (BINOP_SUBSCRIPT); } |
| 371 | ; |
| 372 | |
| 373 | exp : exp '(' |
| 374 | /* This is to save the value of arglist_len |
| 375 | being accumulated by an outer function call. */ |
| 376 | { start_arglist (); } |
| 377 | arglist ')' %prec ARROW |
| 378 | { write_exp_elt_opcode (OP_FUNCALL); |
| 379 | write_exp_elt_longcst ((LONGEST) end_arglist ()); |
| 380 | write_exp_elt_opcode (OP_FUNCALL); } |
| 381 | ; |
| 382 | |
| 383 | lcurly : '{' |
| 384 | { start_arglist (); } |
| 385 | ; |
| 386 | |
| 387 | arglist : |
| 388 | ; |
| 389 | |
| 390 | arglist : exp |
| 391 | { arglist_len = 1; } |
| 392 | ; |
| 393 | |
| 394 | arglist : arglist ',' exp %prec ABOVE_COMMA |
| 395 | { arglist_len++; } |
| 396 | ; |
| 397 | |
| 398 | rcurly : '}' |
| 399 | { $$ = end_arglist () - 1; } |
| 400 | ; |
| 401 | exp : lcurly arglist rcurly %prec ARROW |
| 402 | { write_exp_elt_opcode (OP_ARRAY); |
| 403 | write_exp_elt_longcst ((LONGEST) 0); |
| 404 | write_exp_elt_longcst ((LONGEST) $3); |
| 405 | write_exp_elt_opcode (OP_ARRAY); } |
| 406 | ; |
| 407 | |
| 408 | exp : lcurly type rcurly exp %prec UNARY |
| 409 | { write_exp_elt_opcode (UNOP_MEMVAL); |
| 410 | write_exp_elt_type ($2); |
| 411 | write_exp_elt_opcode (UNOP_MEMVAL); } |
| 412 | ; |
| 413 | |
| 414 | exp : '(' type ')' exp %prec UNARY |
| 415 | { write_exp_elt_opcode (UNOP_CAST); |
| 416 | write_exp_elt_type ($2); |
| 417 | write_exp_elt_opcode (UNOP_CAST); } |
| 418 | ; |
| 419 | |
| 420 | exp : '(' exp1 ')' |
| 421 | { } |
| 422 | ; |
| 423 | |
| 424 | /* Binary operators in order of decreasing precedence. */ |
| 425 | |
| 426 | exp : exp '@' exp |
| 427 | { write_exp_elt_opcode (BINOP_REPEAT); } |
| 428 | ; |
| 429 | |
| 430 | exp : exp '*' exp |
| 431 | { write_exp_elt_opcode (BINOP_MUL); } |
| 432 | ; |
| 433 | |
| 434 | exp : exp '/' exp |
| 435 | { write_exp_elt_opcode (BINOP_DIV); } |
| 436 | ; |
| 437 | |
| 438 | exp : exp '%' exp |
| 439 | { write_exp_elt_opcode (BINOP_REM); } |
| 440 | ; |
| 441 | |
| 442 | exp : exp '+' exp |
| 443 | { write_exp_elt_opcode (BINOP_ADD); } |
| 444 | ; |
| 445 | |
| 446 | exp : exp '-' exp |
| 447 | { write_exp_elt_opcode (BINOP_SUB); } |
| 448 | ; |
| 449 | |
| 450 | exp : exp LSH exp |
| 451 | { write_exp_elt_opcode (BINOP_LSH); } |
| 452 | ; |
| 453 | |
| 454 | exp : exp RSH exp |
| 455 | { write_exp_elt_opcode (BINOP_RSH); } |
| 456 | ; |
| 457 | |
| 458 | exp : exp EQUAL exp |
| 459 | { write_exp_elt_opcode (BINOP_EQUAL); } |
| 460 | ; |
| 461 | |
| 462 | exp : exp NOTEQUAL exp |
| 463 | { write_exp_elt_opcode (BINOP_NOTEQUAL); } |
| 464 | ; |
| 465 | |
| 466 | exp : exp LEQ exp |
| 467 | { write_exp_elt_opcode (BINOP_LEQ); } |
| 468 | ; |
| 469 | |
| 470 | exp : exp GEQ exp |
| 471 | { write_exp_elt_opcode (BINOP_GEQ); } |
| 472 | ; |
| 473 | |
| 474 | exp : exp '<' exp |
| 475 | { write_exp_elt_opcode (BINOP_LESS); } |
| 476 | ; |
| 477 | |
| 478 | exp : exp '>' exp |
| 479 | { write_exp_elt_opcode (BINOP_GTR); } |
| 480 | ; |
| 481 | |
| 482 | exp : exp '&' exp |
| 483 | { write_exp_elt_opcode (BINOP_BITWISE_AND); } |
| 484 | ; |
| 485 | |
| 486 | exp : exp '^' exp |
| 487 | { write_exp_elt_opcode (BINOP_BITWISE_XOR); } |
| 488 | ; |
| 489 | |
| 490 | exp : exp '|' exp |
| 491 | { write_exp_elt_opcode (BINOP_BITWISE_IOR); } |
| 492 | ; |
| 493 | |
| 494 | exp : exp ANDAND exp |
| 495 | { write_exp_elt_opcode (BINOP_LOGICAL_AND); } |
| 496 | ; |
| 497 | |
| 498 | exp : exp OROR exp |
| 499 | { write_exp_elt_opcode (BINOP_LOGICAL_OR); } |
| 500 | ; |
| 501 | |
| 502 | exp : exp '?' exp ':' exp %prec '?' |
| 503 | { write_exp_elt_opcode (TERNOP_COND); } |
| 504 | ; |
| 505 | |
| 506 | exp : exp '=' exp |
| 507 | { write_exp_elt_opcode (BINOP_ASSIGN); } |
| 508 | ; |
| 509 | |
| 510 | exp : exp ASSIGN_MODIFY exp |
| 511 | { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); |
| 512 | write_exp_elt_opcode ($2); |
| 513 | write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } |
| 514 | ; |
| 515 | |
| 516 | exp : INT |
| 517 | { write_exp_elt_opcode (OP_LONG); |
| 518 | write_exp_elt_type ($1.type); |
| 519 | write_exp_elt_longcst ((LONGEST)($1.val)); |
| 520 | write_exp_elt_opcode (OP_LONG); } |
| 521 | ; |
| 522 | |
| 523 | exp : NAME_OR_INT |
| 524 | { YYSTYPE val; |
| 525 | parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val); |
| 526 | write_exp_elt_opcode (OP_LONG); |
| 527 | write_exp_elt_type (val.typed_val_int.type); |
| 528 | write_exp_elt_longcst ((LONGEST)val.typed_val_int.val); |
| 529 | write_exp_elt_opcode (OP_LONG); |
| 530 | } |
| 531 | ; |
| 532 | |
| 533 | |
| 534 | exp : FLOAT |
| 535 | { write_exp_elt_opcode (OP_DOUBLE); |
| 536 | write_exp_elt_type ($1.type); |
| 537 | write_exp_elt_dblcst ($1.dval); |
| 538 | write_exp_elt_opcode (OP_DOUBLE); } |
| 539 | ; |
| 540 | |
| 541 | exp : DECFLOAT |
| 542 | { write_exp_elt_opcode (OP_DECFLOAT); |
| 543 | write_exp_elt_type ($1.type); |
| 544 | write_exp_elt_decfloatcst ($1.val); |
| 545 | write_exp_elt_opcode (OP_DECFLOAT); } |
| 546 | ; |
| 547 | |
| 548 | exp : variable |
| 549 | ; |
| 550 | |
| 551 | exp : VARIABLE |
| 552 | /* Already written by write_dollar_variable. */ |
| 553 | ; |
| 554 | |
| 555 | exp : SIZEOF '(' type ')' %prec UNARY |
| 556 | { write_exp_elt_opcode (OP_LONG); |
| 557 | write_exp_elt_type (builtin_type (current_gdbarch)->builtin_int); |
| 558 | CHECK_TYPEDEF ($3); |
| 559 | write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); |
| 560 | write_exp_elt_opcode (OP_LONG); } |
| 561 | ; |
| 562 | |
| 563 | exp : STRING |
| 564 | { /* C strings are converted into array constants with |
| 565 | an explicit null byte added at the end. Thus |
| 566 | the array upper bound is the string length. |
| 567 | There is no such thing in C as a completely empty |
| 568 | string. */ |
| 569 | char *sp = $1.ptr; int count = $1.length; |
| 570 | while (count-- > 0) |
| 571 | { |
| 572 | write_exp_elt_opcode (OP_LONG); |
| 573 | write_exp_elt_type (builtin_type (current_gdbarch)->builtin_char); |
| 574 | write_exp_elt_longcst ((LONGEST)(*sp++)); |
| 575 | write_exp_elt_opcode (OP_LONG); |
| 576 | } |
| 577 | write_exp_elt_opcode (OP_LONG); |
| 578 | write_exp_elt_type (builtin_type (current_gdbarch)->builtin_char); |
| 579 | write_exp_elt_longcst ((LONGEST)'\0'); |
| 580 | write_exp_elt_opcode (OP_LONG); |
| 581 | write_exp_elt_opcode (OP_ARRAY); |
| 582 | write_exp_elt_longcst ((LONGEST) 0); |
| 583 | write_exp_elt_longcst ((LONGEST) ($1.length)); |
| 584 | write_exp_elt_opcode (OP_ARRAY); } |
| 585 | ; |
| 586 | |
| 587 | /* C++. */ |
| 588 | exp : TRUEKEYWORD |
| 589 | { write_exp_elt_opcode (OP_LONG); |
| 590 | write_exp_elt_type (builtin_type (current_gdbarch)->builtin_bool); |
| 591 | write_exp_elt_longcst ((LONGEST) 1); |
| 592 | write_exp_elt_opcode (OP_LONG); } |
| 593 | ; |
| 594 | |
| 595 | exp : FALSEKEYWORD |
| 596 | { write_exp_elt_opcode (OP_LONG); |
| 597 | write_exp_elt_type (builtin_type (current_gdbarch)->builtin_bool); |
| 598 | write_exp_elt_longcst ((LONGEST) 0); |
| 599 | write_exp_elt_opcode (OP_LONG); } |
| 600 | ; |
| 601 | |
| 602 | /* end of C++. */ |
| 603 | |
| 604 | block : BLOCKNAME |
| 605 | { |
| 606 | if ($1.sym) |
| 607 | $$ = SYMBOL_BLOCK_VALUE ($1.sym); |
| 608 | else |
| 609 | error ("No file or function \"%s\".", |
| 610 | copy_name ($1.stoken)); |
| 611 | } |
| 612 | | FILENAME |
| 613 | { |
| 614 | $$ = $1; |
| 615 | } |
| 616 | ; |
| 617 | |
| 618 | block : block COLONCOLON name |
| 619 | { struct symbol *tem |
| 620 | = lookup_symbol (copy_name ($3), $1, |
| 621 | VAR_DOMAIN, (int *) NULL); |
| 622 | if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK) |
| 623 | error ("No function \"%s\" in specified context.", |
| 624 | copy_name ($3)); |
| 625 | $$ = SYMBOL_BLOCK_VALUE (tem); } |
| 626 | ; |
| 627 | |
| 628 | variable: block COLONCOLON name |
| 629 | { struct symbol *sym; |
| 630 | sym = lookup_symbol (copy_name ($3), $1, |
| 631 | VAR_DOMAIN, (int *) NULL); |
| 632 | if (sym == 0) |
| 633 | error ("No symbol \"%s\" in specified context.", |
| 634 | copy_name ($3)); |
| 635 | |
| 636 | write_exp_elt_opcode (OP_VAR_VALUE); |
| 637 | /* block_found is set by lookup_symbol. */ |
| 638 | write_exp_elt_block (block_found); |
| 639 | write_exp_elt_sym (sym); |
| 640 | write_exp_elt_opcode (OP_VAR_VALUE); } |
| 641 | ; |
| 642 | |
| 643 | qualified_name: typebase COLONCOLON name |
| 644 | { |
| 645 | struct type *type = $1; |
| 646 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT |
| 647 | && TYPE_CODE (type) != TYPE_CODE_UNION |
| 648 | && TYPE_CODE (type) != TYPE_CODE_NAMESPACE) |
| 649 | error ("`%s' is not defined as an aggregate type.", |
| 650 | TYPE_NAME (type)); |
| 651 | |
| 652 | write_exp_elt_opcode (OP_SCOPE); |
| 653 | write_exp_elt_type (type); |
| 654 | write_exp_string ($3); |
| 655 | write_exp_elt_opcode (OP_SCOPE); |
| 656 | } |
| 657 | | typebase COLONCOLON '~' name |
| 658 | { |
| 659 | struct type *type = $1; |
| 660 | struct stoken tmp_token; |
| 661 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT |
| 662 | && TYPE_CODE (type) != TYPE_CODE_UNION |
| 663 | && TYPE_CODE (type) != TYPE_CODE_NAMESPACE) |
| 664 | error ("`%s' is not defined as an aggregate type.", |
| 665 | TYPE_NAME (type)); |
| 666 | |
| 667 | tmp_token.ptr = (char*) alloca ($4.length + 2); |
| 668 | tmp_token.length = $4.length + 1; |
| 669 | tmp_token.ptr[0] = '~'; |
| 670 | memcpy (tmp_token.ptr+1, $4.ptr, $4.length); |
| 671 | tmp_token.ptr[tmp_token.length] = 0; |
| 672 | |
| 673 | /* Check for valid destructor name. */ |
| 674 | destructor_name_p (tmp_token.ptr, type); |
| 675 | write_exp_elt_opcode (OP_SCOPE); |
| 676 | write_exp_elt_type (type); |
| 677 | write_exp_string (tmp_token); |
| 678 | write_exp_elt_opcode (OP_SCOPE); |
| 679 | } |
| 680 | ; |
| 681 | |
| 682 | variable: qualified_name |
| 683 | | COLONCOLON name |
| 684 | { |
| 685 | char *name = copy_name ($2); |
| 686 | struct symbol *sym; |
| 687 | struct minimal_symbol *msymbol; |
| 688 | |
| 689 | sym = |
| 690 | lookup_symbol (name, (const struct block *) NULL, |
| 691 | VAR_DOMAIN, (int *) NULL); |
| 692 | if (sym) |
| 693 | { |
| 694 | write_exp_elt_opcode (OP_VAR_VALUE); |
| 695 | write_exp_elt_block (NULL); |
| 696 | write_exp_elt_sym (sym); |
| 697 | write_exp_elt_opcode (OP_VAR_VALUE); |
| 698 | break; |
| 699 | } |
| 700 | |
| 701 | msymbol = lookup_minimal_symbol (name, NULL, NULL); |
| 702 | if (msymbol != NULL) |
| 703 | { |
| 704 | write_exp_msymbol (msymbol, |
| 705 | lookup_function_type (builtin_type (current_gdbarch)->builtin_int), |
| 706 | builtin_type (current_gdbarch)->builtin_int); |
| 707 | } |
| 708 | else |
| 709 | if (!have_full_symbols () && !have_partial_symbols ()) |
| 710 | error ("No symbol table is loaded. Use the \"file\" command."); |
| 711 | else |
| 712 | error ("No symbol \"%s\" in current context.", name); |
| 713 | } |
| 714 | ; |
| 715 | |
| 716 | variable: name_not_typename |
| 717 | { struct symbol *sym = $1.sym; |
| 718 | |
| 719 | if (sym) |
| 720 | { |
| 721 | if (symbol_read_needs_frame (sym)) |
| 722 | { |
| 723 | if (innermost_block == 0 || |
| 724 | contained_in (block_found, |
| 725 | innermost_block)) |
| 726 | innermost_block = block_found; |
| 727 | } |
| 728 | |
| 729 | write_exp_elt_opcode (OP_VAR_VALUE); |
| 730 | /* We want to use the selected frame, not |
| 731 | another more inner frame which happens to |
| 732 | be in the same block. */ |
| 733 | write_exp_elt_block (NULL); |
| 734 | write_exp_elt_sym (sym); |
| 735 | write_exp_elt_opcode (OP_VAR_VALUE); |
| 736 | } |
| 737 | else if ($1.is_a_field_of_this) |
| 738 | { |
| 739 | /* C++: it hangs off of `this'. Must |
| 740 | not inadvertently convert from a method call |
| 741 | to data ref. */ |
| 742 | if (innermost_block == 0 || |
| 743 | contained_in (block_found, innermost_block)) |
| 744 | innermost_block = block_found; |
| 745 | write_exp_elt_opcode (OP_THIS); |
| 746 | write_exp_elt_opcode (OP_THIS); |
| 747 | write_exp_elt_opcode (STRUCTOP_PTR); |
| 748 | write_exp_string ($1.stoken); |
| 749 | write_exp_elt_opcode (STRUCTOP_PTR); |
| 750 | } |
| 751 | else |
| 752 | { |
| 753 | struct minimal_symbol *msymbol; |
| 754 | char *arg = copy_name ($1.stoken); |
| 755 | |
| 756 | msymbol = |
| 757 | lookup_minimal_symbol (arg, NULL, NULL); |
| 758 | if (msymbol != NULL) |
| 759 | { |
| 760 | write_exp_msymbol (msymbol, |
| 761 | lookup_function_type (builtin_type (current_gdbarch)->builtin_int), |
| 762 | builtin_type (current_gdbarch)->builtin_int); |
| 763 | } |
| 764 | else if (!have_full_symbols () && !have_partial_symbols ()) |
| 765 | error ("No symbol table is loaded. Use the \"file\" command."); |
| 766 | else |
| 767 | error ("No symbol \"%s\" in current context.", |
| 768 | copy_name ($1.stoken)); |
| 769 | } |
| 770 | } |
| 771 | ; |
| 772 | |
| 773 | space_identifier : '@' NAME |
| 774 | { push_type_address_space (copy_name ($2.stoken)); |
| 775 | push_type (tp_space_identifier); |
| 776 | } |
| 777 | ; |
| 778 | |
| 779 | const_or_volatile: const_or_volatile_noopt |
| 780 | | |
| 781 | ; |
| 782 | |
| 783 | cv_with_space_id : const_or_volatile space_identifier const_or_volatile |
| 784 | ; |
| 785 | |
| 786 | const_or_volatile_or_space_identifier_noopt: cv_with_space_id |
| 787 | | const_or_volatile_noopt |
| 788 | ; |
| 789 | |
| 790 | const_or_volatile_or_space_identifier: |
| 791 | const_or_volatile_or_space_identifier_noopt |
| 792 | | |
| 793 | ; |
| 794 | |
| 795 | abs_decl: '*' |
| 796 | { push_type (tp_pointer); $$ = 0; } |
| 797 | | '*' abs_decl |
| 798 | { push_type (tp_pointer); $$ = $2; } |
| 799 | | '&' |
| 800 | { push_type (tp_reference); $$ = 0; } |
| 801 | | '&' abs_decl |
| 802 | { push_type (tp_reference); $$ = $2; } |
| 803 | | direct_abs_decl |
| 804 | ; |
| 805 | |
| 806 | direct_abs_decl: '(' abs_decl ')' |
| 807 | { $$ = $2; } |
| 808 | | direct_abs_decl array_mod |
| 809 | { |
| 810 | push_type_int ($2); |
| 811 | push_type (tp_array); |
| 812 | } |
| 813 | | array_mod |
| 814 | { |
| 815 | push_type_int ($1); |
| 816 | push_type (tp_array); |
| 817 | $$ = 0; |
| 818 | } |
| 819 | |
| 820 | | direct_abs_decl func_mod |
| 821 | { push_type (tp_function); } |
| 822 | | func_mod |
| 823 | { push_type (tp_function); } |
| 824 | ; |
| 825 | |
| 826 | array_mod: '[' ']' |
| 827 | { $$ = -1; } |
| 828 | | '[' INT ']' |
| 829 | { $$ = $2.val; } |
| 830 | ; |
| 831 | |
| 832 | func_mod: '(' ')' |
| 833 | { $$ = 0; } |
| 834 | | '(' nonempty_typelist ')' |
| 835 | { free ($2); $$ = 0; } |
| 836 | ; |
| 837 | |
| 838 | /* We used to try to recognize pointer to member types here, but |
| 839 | that didn't work (shift/reduce conflicts meant that these rules never |
| 840 | got executed). The problem is that |
| 841 | int (foo::bar::baz::bizzle) |
| 842 | is a function type but |
| 843 | int (foo::bar::baz::bizzle::*) |
| 844 | is a pointer to member type. Stroustrup loses again! */ |
| 845 | |
| 846 | type : ptype |
| 847 | ; |
| 848 | |
| 849 | typebase /* Implements (approximately): (type-qualifier)* type-specifier */ |
| 850 | : TYPENAME |
| 851 | { $$ = $1.type; } |
| 852 | | INT_KEYWORD |
| 853 | { $$ = builtin_type (current_gdbarch)->builtin_int; } |
| 854 | | LONG |
| 855 | { $$ = builtin_type (current_gdbarch)->builtin_long; } |
| 856 | | SHORT |
| 857 | { $$ = builtin_type (current_gdbarch)->builtin_short; } |
| 858 | | LONG INT_KEYWORD |
| 859 | { $$ = builtin_type (current_gdbarch)->builtin_long; } |
| 860 | | LONG SIGNED_KEYWORD INT_KEYWORD |
| 861 | { $$ = builtin_type (current_gdbarch)->builtin_long; } |
| 862 | | LONG SIGNED_KEYWORD |
| 863 | { $$ = builtin_type (current_gdbarch)->builtin_long; } |
| 864 | | SIGNED_KEYWORD LONG INT_KEYWORD |
| 865 | { $$ = builtin_type (current_gdbarch)->builtin_long; } |
| 866 | | UNSIGNED LONG INT_KEYWORD |
| 867 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long; } |
| 868 | | LONG UNSIGNED INT_KEYWORD |
| 869 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long; } |
| 870 | | LONG UNSIGNED |
| 871 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long; } |
| 872 | | LONG LONG |
| 873 | { $$ = builtin_type (current_gdbarch)->builtin_long_long; } |
| 874 | | LONG LONG INT_KEYWORD |
| 875 | { $$ = builtin_type (current_gdbarch)->builtin_long_long; } |
| 876 | | LONG LONG SIGNED_KEYWORD INT_KEYWORD |
| 877 | { $$ = builtin_type (current_gdbarch)->builtin_long_long; } |
| 878 | | LONG LONG SIGNED_KEYWORD |
| 879 | { $$ = builtin_type (current_gdbarch)->builtin_long_long; } |
| 880 | | SIGNED_KEYWORD LONG LONG |
| 881 | { $$ = builtin_type (current_gdbarch)->builtin_long_long; } |
| 882 | | SIGNED_KEYWORD LONG LONG INT_KEYWORD |
| 883 | { $$ = builtin_type (current_gdbarch)->builtin_long_long; } |
| 884 | | UNSIGNED LONG LONG |
| 885 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long_long; } |
| 886 | | UNSIGNED LONG LONG INT_KEYWORD |
| 887 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long_long; } |
| 888 | | LONG LONG UNSIGNED |
| 889 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long_long; } |
| 890 | | LONG LONG UNSIGNED INT_KEYWORD |
| 891 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long_long; } |
| 892 | | SHORT INT_KEYWORD |
| 893 | { $$ = builtin_type (current_gdbarch)->builtin_short; } |
| 894 | | SHORT SIGNED_KEYWORD INT_KEYWORD |
| 895 | { $$ = builtin_type (current_gdbarch)->builtin_short; } |
| 896 | | SHORT SIGNED_KEYWORD |
| 897 | { $$ = builtin_type (current_gdbarch)->builtin_short; } |
| 898 | | UNSIGNED SHORT INT_KEYWORD |
| 899 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_short; } |
| 900 | | SHORT UNSIGNED |
| 901 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_short; } |
| 902 | | SHORT UNSIGNED INT_KEYWORD |
| 903 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_short; } |
| 904 | | DOUBLE_KEYWORD |
| 905 | { $$ = builtin_type (current_gdbarch)->builtin_double; } |
| 906 | | LONG DOUBLE_KEYWORD |
| 907 | { $$ = builtin_type (current_gdbarch)->builtin_long_double; } |
| 908 | | STRUCT name |
| 909 | { $$ = lookup_struct (copy_name ($2), |
| 910 | expression_context_block); } |
| 911 | | CLASS name |
| 912 | { $$ = lookup_struct (copy_name ($2), |
| 913 | expression_context_block); } |
| 914 | | UNION name |
| 915 | { $$ = lookup_union (copy_name ($2), |
| 916 | expression_context_block); } |
| 917 | | ENUM name |
| 918 | { $$ = lookup_enum (copy_name ($2), |
| 919 | expression_context_block); } |
| 920 | | UNSIGNED typename |
| 921 | { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); } |
| 922 | | UNSIGNED |
| 923 | { $$ = builtin_type (current_gdbarch)->builtin_unsigned_int; } |
| 924 | | SIGNED_KEYWORD typename |
| 925 | { $$ = lookup_signed_typename (TYPE_NAME($2.type)); } |
| 926 | | SIGNED_KEYWORD |
| 927 | { $$ = builtin_type (current_gdbarch)->builtin_int; } |
| 928 | /* It appears that this rule for templates is never |
| 929 | reduced; template recognition happens by lookahead |
| 930 | in the token processing code in yylex. */ |
| 931 | | TEMPLATE name '<' type '>' |
| 932 | { $$ = lookup_template_type(copy_name($2), $4, |
| 933 | expression_context_block); |
| 934 | } |
| 935 | | const_or_volatile_or_space_identifier_noopt typebase |
| 936 | { $$ = follow_types ($2); } |
| 937 | | typebase const_or_volatile_or_space_identifier_noopt |
| 938 | { $$ = follow_types ($1); } |
| 939 | | qualified_type |
| 940 | ; |
| 941 | |
| 942 | /* FIXME: carlton/2003-09-25: This next bit leads to lots of |
| 943 | reduce-reduce conflicts, because the parser doesn't know whether or |
| 944 | not to use qualified_name or qualified_type: the rules are |
| 945 | identical. If the parser is parsing 'A::B::x', then, when it sees |
| 946 | the second '::', it knows that the expression to the left of it has |
| 947 | to be a type, so it uses qualified_type. But if it is parsing just |
| 948 | 'A::B', then it doesn't have any way of knowing which rule to use, |
| 949 | so there's a reduce-reduce conflict; it picks qualified_name, since |
| 950 | that occurs earlier in this file than qualified_type. |
| 951 | |
| 952 | There's no good way to fix this with the grammar as it stands; as |
| 953 | far as I can tell, some of the problems arise from ambiguities that |
| 954 | GDB introduces ('start' can be either an expression or a type), but |
| 955 | some of it is inherent to the nature of C++ (you want to treat the |
| 956 | input "(FOO)" fairly differently depending on whether FOO is an |
| 957 | expression or a type, and if FOO is a complex expression, this can |
| 958 | be hard to determine at the right time). Fortunately, it works |
| 959 | pretty well in most cases. For example, if you do 'ptype A::B', |
| 960 | where A::B is a nested type, then the parser will mistakenly |
| 961 | misidentify it as an expression; but evaluate_subexp will get |
| 962 | called with 'noside' set to EVAL_AVOID_SIDE_EFFECTS, and everything |
| 963 | will work out anyways. But there are situations where the parser |
| 964 | will get confused: the most common one that I've run into is when |
| 965 | you want to do |
| 966 | |
| 967 | print *((A::B *) x)" |
| 968 | |
| 969 | where the parser doesn't realize that A::B has to be a type until |
| 970 | it hits the first right paren, at which point it's too late. (The |
| 971 | workaround is to type "print *(('A::B' *) x)" instead.) (And |
| 972 | another solution is to fix our symbol-handling code so that the |
| 973 | user never wants to type something like that in the first place, |
| 974 | because we get all the types right without the user's help!) |
| 975 | |
| 976 | Perhaps we could fix this by making the lexer smarter. Some of |
| 977 | this functionality used to be in the lexer, but in a way that |
| 978 | worked even less well than the current solution: that attempt |
| 979 | involved having the parser sometimes handle '::' and having the |
| 980 | lexer sometimes handle it, and without a clear division of |
| 981 | responsibility, it quickly degenerated into a big mess. Probably |
| 982 | the eventual correct solution will give more of a role to the lexer |
| 983 | (ideally via code that is shared between the lexer and |
| 984 | decode_line_1), but I'm not holding my breath waiting for somebody |
| 985 | to get around to cleaning this up... */ |
| 986 | |
| 987 | qualified_type: typebase COLONCOLON name |
| 988 | { |
| 989 | struct type *type = $1; |
| 990 | struct type *new_type; |
| 991 | char *ncopy = alloca ($3.length + 1); |
| 992 | |
| 993 | memcpy (ncopy, $3.ptr, $3.length); |
| 994 | ncopy[$3.length] = '\0'; |
| 995 | |
| 996 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT |
| 997 | && TYPE_CODE (type) != TYPE_CODE_UNION |
| 998 | && TYPE_CODE (type) != TYPE_CODE_NAMESPACE) |
| 999 | error ("`%s' is not defined as an aggregate type.", |
| 1000 | TYPE_NAME (type)); |
| 1001 | |
| 1002 | new_type = cp_lookup_nested_type (type, ncopy, |
| 1003 | expression_context_block); |
| 1004 | if (new_type == NULL) |
| 1005 | error ("No type \"%s\" within class or namespace \"%s\".", |
| 1006 | ncopy, TYPE_NAME (type)); |
| 1007 | |
| 1008 | $$ = new_type; |
| 1009 | } |
| 1010 | ; |
| 1011 | |
| 1012 | typename: TYPENAME |
| 1013 | | INT_KEYWORD |
| 1014 | { |
| 1015 | $$.stoken.ptr = "int"; |
| 1016 | $$.stoken.length = 3; |
| 1017 | $$.type = builtin_type (current_gdbarch)->builtin_int; |
| 1018 | } |
| 1019 | | LONG |
| 1020 | { |
| 1021 | $$.stoken.ptr = "long"; |
| 1022 | $$.stoken.length = 4; |
| 1023 | $$.type = builtin_type (current_gdbarch)->builtin_long; |
| 1024 | } |
| 1025 | | SHORT |
| 1026 | { |
| 1027 | $$.stoken.ptr = "short"; |
| 1028 | $$.stoken.length = 5; |
| 1029 | $$.type = builtin_type (current_gdbarch)->builtin_short; |
| 1030 | } |
| 1031 | ; |
| 1032 | |
| 1033 | nonempty_typelist |
| 1034 | : type |
| 1035 | { $$ = (struct type **) malloc (sizeof (struct type *) * 2); |
| 1036 | $<ivec>$[0] = 1; /* Number of types in vector */ |
| 1037 | $$[1] = $1; |
| 1038 | } |
| 1039 | | nonempty_typelist ',' type |
| 1040 | { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1); |
| 1041 | $$ = (struct type **) realloc ((char *) $1, len); |
| 1042 | $$[$<ivec>$[0]] = $3; |
| 1043 | } |
| 1044 | ; |
| 1045 | |
| 1046 | ptype : typebase |
| 1047 | | ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier |
| 1048 | { $$ = follow_types ($1); } |
| 1049 | ; |
| 1050 | |
| 1051 | const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD |
| 1052 | | VOLATILE_KEYWORD CONST_KEYWORD |
| 1053 | ; |
| 1054 | |
| 1055 | const_or_volatile_noopt: const_and_volatile |
| 1056 | { push_type (tp_const); |
| 1057 | push_type (tp_volatile); |
| 1058 | } |
| 1059 | | CONST_KEYWORD |
| 1060 | { push_type (tp_const); } |
| 1061 | | VOLATILE_KEYWORD |
| 1062 | { push_type (tp_volatile); } |
| 1063 | ; |
| 1064 | |
| 1065 | name : NAME { $$ = $1.stoken; } |
| 1066 | | BLOCKNAME { $$ = $1.stoken; } |
| 1067 | | TYPENAME { $$ = $1.stoken; } |
| 1068 | | NAME_OR_INT { $$ = $1.stoken; } |
| 1069 | ; |
| 1070 | |
| 1071 | name_not_typename : NAME |
| 1072 | | BLOCKNAME |
| 1073 | /* These would be useful if name_not_typename was useful, but it is just |
| 1074 | a fake for "variable", so these cause reduce/reduce conflicts because |
| 1075 | the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable, |
| 1076 | =exp) or just an exp. If name_not_typename was ever used in an lvalue |
| 1077 | context where only a name could occur, this might be useful. |
| 1078 | | NAME_OR_INT |
| 1079 | */ |
| 1080 | ; |
| 1081 | |
| 1082 | %% |
| 1083 | |
| 1084 | /* Take care of parsing a number (anything that starts with a digit). |
| 1085 | Set yylval and return the token type; update lexptr. |
| 1086 | LEN is the number of characters in it. */ |
| 1087 | |
| 1088 | /*** Needs some error checking for the float case ***/ |
| 1089 | |
| 1090 | static int |
| 1091 | parse_number (p, len, parsed_float, putithere) |
| 1092 | char *p; |
| 1093 | int len; |
| 1094 | int parsed_float; |
| 1095 | YYSTYPE *putithere; |
| 1096 | { |
| 1097 | /* FIXME: Shouldn't these be unsigned? We don't deal with negative values |
| 1098 | here, and we do kind of silly things like cast to unsigned. */ |
| 1099 | LONGEST n = 0; |
| 1100 | LONGEST prevn = 0; |
| 1101 | ULONGEST un; |
| 1102 | |
| 1103 | int i = 0; |
| 1104 | int c; |
| 1105 | int base = input_radix; |
| 1106 | int unsigned_p = 0; |
| 1107 | |
| 1108 | /* Number of "L" suffixes encountered. */ |
| 1109 | int long_p = 0; |
| 1110 | |
| 1111 | /* We have found a "L" or "U" suffix. */ |
| 1112 | int found_suffix = 0; |
| 1113 | |
| 1114 | ULONGEST high_bit; |
| 1115 | struct type *signed_type; |
| 1116 | struct type *unsigned_type; |
| 1117 | |
| 1118 | if (parsed_float) |
| 1119 | { |
| 1120 | /* It's a float since it contains a point or an exponent. */ |
| 1121 | char *s; |
| 1122 | int num; /* number of tokens scanned by scanf */ |
| 1123 | char saved_char; |
| 1124 | |
| 1125 | /* If it ends at "df", "dd" or "dl", take it as type of decimal floating |
| 1126 | point. Return DECFLOAT. */ |
| 1127 | |
| 1128 | if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f') |
| 1129 | { |
| 1130 | p[len - 2] = '\0'; |
| 1131 | putithere->typed_val_decfloat.type |
| 1132 | = builtin_type (current_gdbarch)->builtin_decfloat; |
| 1133 | decimal_from_string (putithere->typed_val_decfloat.val, 4, p); |
| 1134 | p[len - 2] = 'd'; |
| 1135 | return DECFLOAT; |
| 1136 | } |
| 1137 | |
| 1138 | if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd') |
| 1139 | { |
| 1140 | p[len - 2] = '\0'; |
| 1141 | putithere->typed_val_decfloat.type |
| 1142 | = builtin_type (current_gdbarch)->builtin_decdouble; |
| 1143 | decimal_from_string (putithere->typed_val_decfloat.val, 8, p); |
| 1144 | p[len - 2] = 'd'; |
| 1145 | return DECFLOAT; |
| 1146 | } |
| 1147 | |
| 1148 | if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l') |
| 1149 | { |
| 1150 | p[len - 2] = '\0'; |
| 1151 | putithere->typed_val_decfloat.type |
| 1152 | = builtin_type (current_gdbarch)->builtin_declong; |
| 1153 | decimal_from_string (putithere->typed_val_decfloat.val, 16, p); |
| 1154 | p[len - 2] = 'd'; |
| 1155 | return DECFLOAT; |
| 1156 | } |
| 1157 | |
| 1158 | s = malloc (len); |
| 1159 | saved_char = p[len]; |
| 1160 | p[len] = 0; /* null-terminate the token */ |
| 1161 | num = sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%s", |
| 1162 | &putithere->typed_val_float.dval, s); |
| 1163 | p[len] = saved_char; /* restore the input stream */ |
| 1164 | |
| 1165 | if (num == 1) |
| 1166 | putithere->typed_val_float.type = |
| 1167 | builtin_type (current_gdbarch)->builtin_double; |
| 1168 | |
| 1169 | if (num == 2 ) |
| 1170 | { |
| 1171 | /* See if it has any float suffix: 'f' for float, 'l' for long |
| 1172 | double. */ |
| 1173 | if (!strcasecmp (s, "f")) |
| 1174 | putithere->typed_val_float.type = |
| 1175 | builtin_type (current_gdbarch)->builtin_float; |
| 1176 | else if (!strcasecmp (s, "l")) |
| 1177 | putithere->typed_val_float.type = |
| 1178 | builtin_type (current_gdbarch)->builtin_long_double; |
| 1179 | else |
| 1180 | { |
| 1181 | free (s); |
| 1182 | return ERROR; |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | free (s); |
| 1187 | return FLOAT; |
| 1188 | } |
| 1189 | |
| 1190 | /* Handle base-switching prefixes 0x, 0t, 0d, 0 */ |
| 1191 | if (p[0] == '0') |
| 1192 | switch (p[1]) |
| 1193 | { |
| 1194 | case 'x': |
| 1195 | case 'X': |
| 1196 | if (len >= 3) |
| 1197 | { |
| 1198 | p += 2; |
| 1199 | base = 16; |
| 1200 | len -= 2; |
| 1201 | } |
| 1202 | break; |
| 1203 | |
| 1204 | case 't': |
| 1205 | case 'T': |
| 1206 | case 'd': |
| 1207 | case 'D': |
| 1208 | if (len >= 3) |
| 1209 | { |
| 1210 | p += 2; |
| 1211 | base = 10; |
| 1212 | len -= 2; |
| 1213 | } |
| 1214 | break; |
| 1215 | |
| 1216 | default: |
| 1217 | base = 8; |
| 1218 | break; |
| 1219 | } |
| 1220 | |
| 1221 | while (len-- > 0) |
| 1222 | { |
| 1223 | c = *p++; |
| 1224 | if (c >= 'A' && c <= 'Z') |
| 1225 | c += 'a' - 'A'; |
| 1226 | if (c != 'l' && c != 'u') |
| 1227 | n *= base; |
| 1228 | if (c >= '0' && c <= '9') |
| 1229 | { |
| 1230 | if (found_suffix) |
| 1231 | return ERROR; |
| 1232 | n += i = c - '0'; |
| 1233 | } |
| 1234 | else |
| 1235 | { |
| 1236 | if (base > 10 && c >= 'a' && c <= 'f') |
| 1237 | { |
| 1238 | if (found_suffix) |
| 1239 | return ERROR; |
| 1240 | n += i = c - 'a' + 10; |
| 1241 | } |
| 1242 | else if (c == 'l') |
| 1243 | { |
| 1244 | ++long_p; |
| 1245 | found_suffix = 1; |
| 1246 | } |
| 1247 | else if (c == 'u') |
| 1248 | { |
| 1249 | unsigned_p = 1; |
| 1250 | found_suffix = 1; |
| 1251 | } |
| 1252 | else |
| 1253 | return ERROR; /* Char not a digit */ |
| 1254 | } |
| 1255 | if (i >= base) |
| 1256 | return ERROR; /* Invalid digit in this base */ |
| 1257 | |
| 1258 | /* Portably test for overflow (only works for nonzero values, so make |
| 1259 | a second check for zero). FIXME: Can't we just make n and prevn |
| 1260 | unsigned and avoid this? */ |
| 1261 | if (c != 'l' && c != 'u' && (prevn >= n) && n != 0) |
| 1262 | unsigned_p = 1; /* Try something unsigned */ |
| 1263 | |
| 1264 | /* Portably test for unsigned overflow. |
| 1265 | FIXME: This check is wrong; for example it doesn't find overflow |
| 1266 | on 0x123456789 when LONGEST is 32 bits. */ |
| 1267 | if (c != 'l' && c != 'u' && n != 0) |
| 1268 | { |
| 1269 | if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n)) |
| 1270 | error ("Numeric constant too large."); |
| 1271 | } |
| 1272 | prevn = n; |
| 1273 | } |
| 1274 | |
| 1275 | /* An integer constant is an int, a long, or a long long. An L |
| 1276 | suffix forces it to be long; an LL suffix forces it to be long |
| 1277 | long. If not forced to a larger size, it gets the first type of |
| 1278 | the above that it fits in. To figure out whether it fits, we |
| 1279 | shift it right and see whether anything remains. Note that we |
| 1280 | can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one |
| 1281 | operation, because many compilers will warn about such a shift |
| 1282 | (which always produces a zero result). Sometimes gdbarch_int_bit |
| 1283 | or gdbarch_long_bit will be that big, sometimes not. To deal with |
| 1284 | the case where it is we just always shift the value more than |
| 1285 | once, with fewer bits each time. */ |
| 1286 | |
| 1287 | un = (ULONGEST)n >> 2; |
| 1288 | if (long_p == 0 |
| 1289 | && (un >> (gdbarch_int_bit (current_gdbarch) - 2)) == 0) |
| 1290 | { |
| 1291 | high_bit = ((ULONGEST)1) << (gdbarch_int_bit (current_gdbarch) - 1); |
| 1292 | |
| 1293 | /* A large decimal (not hex or octal) constant (between INT_MAX |
| 1294 | and UINT_MAX) is a long or unsigned long, according to ANSI, |
| 1295 | never an unsigned int, but this code treats it as unsigned |
| 1296 | int. This probably should be fixed. GCC gives a warning on |
| 1297 | such constants. */ |
| 1298 | |
| 1299 | unsigned_type = builtin_type (current_gdbarch)->builtin_unsigned_int; |
| 1300 | signed_type = builtin_type (current_gdbarch)->builtin_int; |
| 1301 | } |
| 1302 | else if (long_p <= 1 |
| 1303 | && (un >> (gdbarch_long_bit (current_gdbarch) - 2)) == 0) |
| 1304 | { |
| 1305 | high_bit = ((ULONGEST)1) << (gdbarch_long_bit (current_gdbarch) - 1); |
| 1306 | unsigned_type = builtin_type (current_gdbarch)->builtin_unsigned_long; |
| 1307 | signed_type = builtin_type (current_gdbarch)->builtin_long; |
| 1308 | } |
| 1309 | else |
| 1310 | { |
| 1311 | int shift; |
| 1312 | if (sizeof (ULONGEST) * HOST_CHAR_BIT |
| 1313 | < gdbarch_long_long_bit (current_gdbarch)) |
| 1314 | /* A long long does not fit in a LONGEST. */ |
| 1315 | shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1); |
| 1316 | else |
| 1317 | shift = (gdbarch_long_long_bit (current_gdbarch) - 1); |
| 1318 | high_bit = (ULONGEST) 1 << shift; |
| 1319 | unsigned_type = builtin_type (current_gdbarch)->builtin_unsigned_long_long; |
| 1320 | signed_type = builtin_type (current_gdbarch)->builtin_long_long; |
| 1321 | } |
| 1322 | |
| 1323 | putithere->typed_val_int.val = n; |
| 1324 | |
| 1325 | /* If the high bit of the worked out type is set then this number |
| 1326 | has to be unsigned. */ |
| 1327 | |
| 1328 | if (unsigned_p || (n & high_bit)) |
| 1329 | { |
| 1330 | putithere->typed_val_int.type = unsigned_type; |
| 1331 | } |
| 1332 | else |
| 1333 | { |
| 1334 | putithere->typed_val_int.type = signed_type; |
| 1335 | } |
| 1336 | |
| 1337 | return INT; |
| 1338 | } |
| 1339 | |
| 1340 | struct token |
| 1341 | { |
| 1342 | char *operator; |
| 1343 | int token; |
| 1344 | enum exp_opcode opcode; |
| 1345 | }; |
| 1346 | |
| 1347 | static const struct token tokentab3[] = |
| 1348 | { |
| 1349 | {">>=", ASSIGN_MODIFY, BINOP_RSH}, |
| 1350 | {"<<=", ASSIGN_MODIFY, BINOP_LSH} |
| 1351 | }; |
| 1352 | |
| 1353 | static const struct token tokentab2[] = |
| 1354 | { |
| 1355 | {"+=", ASSIGN_MODIFY, BINOP_ADD}, |
| 1356 | {"-=", ASSIGN_MODIFY, BINOP_SUB}, |
| 1357 | {"*=", ASSIGN_MODIFY, BINOP_MUL}, |
| 1358 | {"/=", ASSIGN_MODIFY, BINOP_DIV}, |
| 1359 | {"%=", ASSIGN_MODIFY, BINOP_REM}, |
| 1360 | {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR}, |
| 1361 | {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND}, |
| 1362 | {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR}, |
| 1363 | {"++", INCREMENT, BINOP_END}, |
| 1364 | {"--", DECREMENT, BINOP_END}, |
| 1365 | {"->", ARROW, BINOP_END}, |
| 1366 | {"&&", ANDAND, BINOP_END}, |
| 1367 | {"||", OROR, BINOP_END}, |
| 1368 | {"::", COLONCOLON, BINOP_END}, |
| 1369 | {"<<", LSH, BINOP_END}, |
| 1370 | {">>", RSH, BINOP_END}, |
| 1371 | {"==", EQUAL, BINOP_END}, |
| 1372 | {"!=", NOTEQUAL, BINOP_END}, |
| 1373 | {"<=", LEQ, BINOP_END}, |
| 1374 | {">=", GEQ, BINOP_END} |
| 1375 | }; |
| 1376 | |
| 1377 | /* This is set if a NAME token appeared at the very end of the input |
| 1378 | string, with no whitespace separating the name from the EOF. This |
| 1379 | is used only when parsing to do field name completion. */ |
| 1380 | static int saw_name_at_eof; |
| 1381 | |
| 1382 | /* This is set if the previously-returned token was a structure |
| 1383 | operator -- either '.' or ARROW. This is used only when parsing to |
| 1384 | do field name completion. */ |
| 1385 | static int last_was_structop; |
| 1386 | |
| 1387 | /* Read one token, getting characters through lexptr. */ |
| 1388 | |
| 1389 | static int |
| 1390 | yylex () |
| 1391 | { |
| 1392 | int c; |
| 1393 | int namelen; |
| 1394 | unsigned int i; |
| 1395 | char *tokstart; |
| 1396 | char *tokptr; |
| 1397 | int tempbufindex; |
| 1398 | static char *tempbuf; |
| 1399 | static int tempbufsize; |
| 1400 | char * token_string = NULL; |
| 1401 | int class_prefix = 0; |
| 1402 | int saw_structop = last_was_structop; |
| 1403 | |
| 1404 | last_was_structop = 0; |
| 1405 | |
| 1406 | retry: |
| 1407 | |
| 1408 | /* Check if this is a macro invocation that we need to expand. */ |
| 1409 | if (! scanning_macro_expansion ()) |
| 1410 | { |
| 1411 | char *expanded = macro_expand_next (&lexptr, |
| 1412 | expression_macro_lookup_func, |
| 1413 | expression_macro_lookup_baton); |
| 1414 | |
| 1415 | if (expanded) |
| 1416 | scan_macro_expansion (expanded); |
| 1417 | } |
| 1418 | |
| 1419 | prev_lexptr = lexptr; |
| 1420 | |
| 1421 | tokstart = lexptr; |
| 1422 | /* See if it is a special token of length 3. */ |
| 1423 | for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++) |
| 1424 | if (strncmp (tokstart, tokentab3[i].operator, 3) == 0) |
| 1425 | { |
| 1426 | lexptr += 3; |
| 1427 | yylval.opcode = tokentab3[i].opcode; |
| 1428 | return tokentab3[i].token; |
| 1429 | } |
| 1430 | |
| 1431 | /* See if it is a special token of length 2. */ |
| 1432 | for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++) |
| 1433 | if (strncmp (tokstart, tokentab2[i].operator, 2) == 0) |
| 1434 | { |
| 1435 | lexptr += 2; |
| 1436 | yylval.opcode = tokentab2[i].opcode; |
| 1437 | if (in_parse_field && tokentab2[i].token == ARROW) |
| 1438 | last_was_structop = 1; |
| 1439 | return tokentab2[i].token; |
| 1440 | } |
| 1441 | |
| 1442 | switch (c = *tokstart) |
| 1443 | { |
| 1444 | case 0: |
| 1445 | /* If we were just scanning the result of a macro expansion, |
| 1446 | then we need to resume scanning the original text. |
| 1447 | If we're parsing for field name completion, and the previous |
| 1448 | token allows such completion, return a COMPLETE token. |
| 1449 | Otherwise, we were already scanning the original text, and |
| 1450 | we're really done. */ |
| 1451 | if (scanning_macro_expansion ()) |
| 1452 | { |
| 1453 | finished_macro_expansion (); |
| 1454 | goto retry; |
| 1455 | } |
| 1456 | else if (saw_name_at_eof) |
| 1457 | { |
| 1458 | saw_name_at_eof = 0; |
| 1459 | return COMPLETE; |
| 1460 | } |
| 1461 | else if (saw_structop) |
| 1462 | return COMPLETE; |
| 1463 | else |
| 1464 | return 0; |
| 1465 | |
| 1466 | case ' ': |
| 1467 | case '\t': |
| 1468 | case '\n': |
| 1469 | lexptr++; |
| 1470 | goto retry; |
| 1471 | |
| 1472 | case '\'': |
| 1473 | /* We either have a character constant ('0' or '\177' for example) |
| 1474 | or we have a quoted symbol reference ('foo(int,int)' in C++ |
| 1475 | for example). */ |
| 1476 | lexptr++; |
| 1477 | c = *lexptr++; |
| 1478 | if (c == '\\') |
| 1479 | c = parse_escape (&lexptr); |
| 1480 | else if (c == '\'') |
| 1481 | error ("Empty character constant."); |
| 1482 | else if (! host_char_to_target (c, &c)) |
| 1483 | { |
| 1484 | int toklen = lexptr - tokstart + 1; |
| 1485 | char *tok = alloca (toklen + 1); |
| 1486 | memcpy (tok, tokstart, toklen); |
| 1487 | tok[toklen] = '\0'; |
| 1488 | error ("There is no character corresponding to %s in the target " |
| 1489 | "character set `%s'.", tok, target_charset ()); |
| 1490 | } |
| 1491 | |
| 1492 | yylval.typed_val_int.val = c; |
| 1493 | yylval.typed_val_int.type = builtin_type (current_gdbarch)->builtin_char; |
| 1494 | |
| 1495 | c = *lexptr++; |
| 1496 | if (c != '\'') |
| 1497 | { |
| 1498 | namelen = skip_quoted (tokstart) - tokstart; |
| 1499 | if (namelen > 2) |
| 1500 | { |
| 1501 | lexptr = tokstart + namelen; |
| 1502 | if (lexptr[-1] != '\'') |
| 1503 | error ("Unmatched single quote."); |
| 1504 | namelen -= 2; |
| 1505 | tokstart++; |
| 1506 | goto tryname; |
| 1507 | } |
| 1508 | error ("Invalid character constant."); |
| 1509 | } |
| 1510 | return INT; |
| 1511 | |
| 1512 | case '(': |
| 1513 | paren_depth++; |
| 1514 | lexptr++; |
| 1515 | return c; |
| 1516 | |
| 1517 | case ')': |
| 1518 | if (paren_depth == 0) |
| 1519 | return 0; |
| 1520 | paren_depth--; |
| 1521 | lexptr++; |
| 1522 | return c; |
| 1523 | |
| 1524 | case ',': |
| 1525 | if (comma_terminates |
| 1526 | && paren_depth == 0 |
| 1527 | && ! scanning_macro_expansion ()) |
| 1528 | return 0; |
| 1529 | lexptr++; |
| 1530 | return c; |
| 1531 | |
| 1532 | case '.': |
| 1533 | /* Might be a floating point number. */ |
| 1534 | if (lexptr[1] < '0' || lexptr[1] > '9') |
| 1535 | { |
| 1536 | if (in_parse_field) |
| 1537 | last_was_structop = 1; |
| 1538 | goto symbol; /* Nope, must be a symbol. */ |
| 1539 | } |
| 1540 | /* FALL THRU into number case. */ |
| 1541 | |
| 1542 | case '0': |
| 1543 | case '1': |
| 1544 | case '2': |
| 1545 | case '3': |
| 1546 | case '4': |
| 1547 | case '5': |
| 1548 | case '6': |
| 1549 | case '7': |
| 1550 | case '8': |
| 1551 | case '9': |
| 1552 | { |
| 1553 | /* It's a number. */ |
| 1554 | int got_dot = 0, got_e = 0, toktype; |
| 1555 | char *p = tokstart; |
| 1556 | int hex = input_radix > 10; |
| 1557 | |
| 1558 | if (c == '0' && (p[1] == 'x' || p[1] == 'X')) |
| 1559 | { |
| 1560 | p += 2; |
| 1561 | hex = 1; |
| 1562 | } |
| 1563 | else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D')) |
| 1564 | { |
| 1565 | p += 2; |
| 1566 | hex = 0; |
| 1567 | } |
| 1568 | |
| 1569 | for (;; ++p) |
| 1570 | { |
| 1571 | /* This test includes !hex because 'e' is a valid hex digit |
| 1572 | and thus does not indicate a floating point number when |
| 1573 | the radix is hex. */ |
| 1574 | if (!hex && !got_e && (*p == 'e' || *p == 'E')) |
| 1575 | got_dot = got_e = 1; |
| 1576 | /* This test does not include !hex, because a '.' always indicates |
| 1577 | a decimal floating point number regardless of the radix. */ |
| 1578 | else if (!got_dot && *p == '.') |
| 1579 | got_dot = 1; |
| 1580 | else if (got_e && (p[-1] == 'e' || p[-1] == 'E') |
| 1581 | && (*p == '-' || *p == '+')) |
| 1582 | /* This is the sign of the exponent, not the end of the |
| 1583 | number. */ |
| 1584 | continue; |
| 1585 | /* We will take any letters or digits. parse_number will |
| 1586 | complain if past the radix, or if L or U are not final. */ |
| 1587 | else if ((*p < '0' || *p > '9') |
| 1588 | && ((*p < 'a' || *p > 'z') |
| 1589 | && (*p < 'A' || *p > 'Z'))) |
| 1590 | break; |
| 1591 | } |
| 1592 | toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval); |
| 1593 | if (toktype == ERROR) |
| 1594 | { |
| 1595 | char *err_copy = (char *) alloca (p - tokstart + 1); |
| 1596 | |
| 1597 | memcpy (err_copy, tokstart, p - tokstart); |
| 1598 | err_copy[p - tokstart] = 0; |
| 1599 | error ("Invalid number \"%s\".", err_copy); |
| 1600 | } |
| 1601 | lexptr = p; |
| 1602 | return toktype; |
| 1603 | } |
| 1604 | |
| 1605 | case '+': |
| 1606 | case '-': |
| 1607 | case '*': |
| 1608 | case '/': |
| 1609 | case '%': |
| 1610 | case '|': |
| 1611 | case '&': |
| 1612 | case '^': |
| 1613 | case '~': |
| 1614 | case '!': |
| 1615 | case '@': |
| 1616 | case '<': |
| 1617 | case '>': |
| 1618 | case '[': |
| 1619 | case ']': |
| 1620 | case '?': |
| 1621 | case ':': |
| 1622 | case '=': |
| 1623 | case '{': |
| 1624 | case '}': |
| 1625 | symbol: |
| 1626 | lexptr++; |
| 1627 | return c; |
| 1628 | |
| 1629 | case '"': |
| 1630 | |
| 1631 | /* Build the gdb internal form of the input string in tempbuf, |
| 1632 | translating any standard C escape forms seen. Note that the |
| 1633 | buffer is null byte terminated *only* for the convenience of |
| 1634 | debugging gdb itself and printing the buffer contents when |
| 1635 | the buffer contains no embedded nulls. Gdb does not depend |
| 1636 | upon the buffer being null byte terminated, it uses the length |
| 1637 | string instead. This allows gdb to handle C strings (as well |
| 1638 | as strings in other languages) with embedded null bytes */ |
| 1639 | |
| 1640 | tokptr = ++tokstart; |
| 1641 | tempbufindex = 0; |
| 1642 | |
| 1643 | do { |
| 1644 | char *char_start_pos = tokptr; |
| 1645 | |
| 1646 | /* Grow the static temp buffer if necessary, including allocating |
| 1647 | the first one on demand. */ |
| 1648 | if (tempbufindex + 1 >= tempbufsize) |
| 1649 | { |
| 1650 | tempbuf = (char *) realloc (tempbuf, tempbufsize += 64); |
| 1651 | } |
| 1652 | switch (*tokptr) |
| 1653 | { |
| 1654 | case '\0': |
| 1655 | case '"': |
| 1656 | /* Do nothing, loop will terminate. */ |
| 1657 | break; |
| 1658 | case '\\': |
| 1659 | tokptr++; |
| 1660 | c = parse_escape (&tokptr); |
| 1661 | if (c == -1) |
| 1662 | { |
| 1663 | continue; |
| 1664 | } |
| 1665 | tempbuf[tempbufindex++] = c; |
| 1666 | break; |
| 1667 | default: |
| 1668 | c = *tokptr++; |
| 1669 | if (! host_char_to_target (c, &c)) |
| 1670 | { |
| 1671 | int len = tokptr - char_start_pos; |
| 1672 | char *copy = alloca (len + 1); |
| 1673 | memcpy (copy, char_start_pos, len); |
| 1674 | copy[len] = '\0'; |
| 1675 | |
| 1676 | error ("There is no character corresponding to `%s' " |
| 1677 | "in the target character set `%s'.", |
| 1678 | copy, target_charset ()); |
| 1679 | } |
| 1680 | tempbuf[tempbufindex++] = c; |
| 1681 | break; |
| 1682 | } |
| 1683 | } while ((*tokptr != '"') && (*tokptr != '\0')); |
| 1684 | if (*tokptr++ != '"') |
| 1685 | { |
| 1686 | error ("Unterminated string in expression."); |
| 1687 | } |
| 1688 | tempbuf[tempbufindex] = '\0'; /* See note above */ |
| 1689 | yylval.sval.ptr = tempbuf; |
| 1690 | yylval.sval.length = tempbufindex; |
| 1691 | lexptr = tokptr; |
| 1692 | return (STRING); |
| 1693 | } |
| 1694 | |
| 1695 | if (!(c == '_' || c == '$' |
| 1696 | || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) |
| 1697 | /* We must have come across a bad character (e.g. ';'). */ |
| 1698 | error ("Invalid character '%c' in expression.", c); |
| 1699 | |
| 1700 | /* It's a name. See how long it is. */ |
| 1701 | namelen = 0; |
| 1702 | for (c = tokstart[namelen]; |
| 1703 | (c == '_' || c == '$' || (c >= '0' && c <= '9') |
| 1704 | || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');) |
| 1705 | { |
| 1706 | /* Template parameter lists are part of the name. |
| 1707 | FIXME: This mishandles `print $a<4&&$a>3'. */ |
| 1708 | |
| 1709 | if (c == '<') |
| 1710 | { |
| 1711 | /* Scan ahead to get rest of the template specification. Note |
| 1712 | that we look ahead only when the '<' adjoins non-whitespace |
| 1713 | characters; for comparison expressions, e.g. "a < b > c", |
| 1714 | there must be spaces before the '<', etc. */ |
| 1715 | |
| 1716 | char * p = find_template_name_end (tokstart + namelen); |
| 1717 | if (p) |
| 1718 | namelen = p - tokstart; |
| 1719 | break; |
| 1720 | } |
| 1721 | c = tokstart[++namelen]; |
| 1722 | } |
| 1723 | |
| 1724 | /* The token "if" terminates the expression and is NOT removed from |
| 1725 | the input stream. It doesn't count if it appears in the |
| 1726 | expansion of a macro. */ |
| 1727 | if (namelen == 2 |
| 1728 | && tokstart[0] == 'i' |
| 1729 | && tokstart[1] == 'f' |
| 1730 | && ! scanning_macro_expansion ()) |
| 1731 | { |
| 1732 | return 0; |
| 1733 | } |
| 1734 | |
| 1735 | lexptr += namelen; |
| 1736 | |
| 1737 | tryname: |
| 1738 | |
| 1739 | /* Catch specific keywords. Should be done with a data structure. */ |
| 1740 | switch (namelen) |
| 1741 | { |
| 1742 | case 8: |
| 1743 | if (strncmp (tokstart, "unsigned", 8) == 0) |
| 1744 | return UNSIGNED; |
| 1745 | if (current_language->la_language == language_cplus |
| 1746 | && strncmp (tokstart, "template", 8) == 0) |
| 1747 | return TEMPLATE; |
| 1748 | if (strncmp (tokstart, "volatile", 8) == 0) |
| 1749 | return VOLATILE_KEYWORD; |
| 1750 | break; |
| 1751 | case 6: |
| 1752 | if (strncmp (tokstart, "struct", 6) == 0) |
| 1753 | return STRUCT; |
| 1754 | if (strncmp (tokstart, "signed", 6) == 0) |
| 1755 | return SIGNED_KEYWORD; |
| 1756 | if (strncmp (tokstart, "sizeof", 6) == 0) |
| 1757 | return SIZEOF; |
| 1758 | if (strncmp (tokstart, "double", 6) == 0) |
| 1759 | return DOUBLE_KEYWORD; |
| 1760 | break; |
| 1761 | case 5: |
| 1762 | if (current_language->la_language == language_cplus) |
| 1763 | { |
| 1764 | if (strncmp (tokstart, "false", 5) == 0) |
| 1765 | return FALSEKEYWORD; |
| 1766 | if (strncmp (tokstart, "class", 5) == 0) |
| 1767 | return CLASS; |
| 1768 | } |
| 1769 | if (strncmp (tokstart, "union", 5) == 0) |
| 1770 | return UNION; |
| 1771 | if (strncmp (tokstart, "short", 5) == 0) |
| 1772 | return SHORT; |
| 1773 | if (strncmp (tokstart, "const", 5) == 0) |
| 1774 | return CONST_KEYWORD; |
| 1775 | break; |
| 1776 | case 4: |
| 1777 | if (strncmp (tokstart, "enum", 4) == 0) |
| 1778 | return ENUM; |
| 1779 | if (strncmp (tokstart, "long", 4) == 0) |
| 1780 | return LONG; |
| 1781 | if (current_language->la_language == language_cplus) |
| 1782 | { |
| 1783 | if (strncmp (tokstart, "true", 4) == 0) |
| 1784 | return TRUEKEYWORD; |
| 1785 | } |
| 1786 | break; |
| 1787 | case 3: |
| 1788 | if (strncmp (tokstart, "int", 3) == 0) |
| 1789 | return INT_KEYWORD; |
| 1790 | break; |
| 1791 | default: |
| 1792 | break; |
| 1793 | } |
| 1794 | |
| 1795 | yylval.sval.ptr = tokstart; |
| 1796 | yylval.sval.length = namelen; |
| 1797 | |
| 1798 | if (*tokstart == '$') |
| 1799 | { |
| 1800 | write_dollar_variable (yylval.sval); |
| 1801 | return VARIABLE; |
| 1802 | } |
| 1803 | |
| 1804 | /* Use token-type BLOCKNAME for symbols that happen to be defined as |
| 1805 | functions or symtabs. If this is not so, then ... |
| 1806 | Use token-type TYPENAME for symbols that happen to be defined |
| 1807 | currently as names of types; NAME for other symbols. |
| 1808 | The caller is not constrained to care about the distinction. */ |
| 1809 | { |
| 1810 | char *tmp = copy_name (yylval.sval); |
| 1811 | struct symbol *sym; |
| 1812 | int is_a_field_of_this = 0; |
| 1813 | int hextype; |
| 1814 | |
| 1815 | sym = lookup_symbol (tmp, expression_context_block, |
| 1816 | VAR_DOMAIN, |
| 1817 | current_language->la_language == language_cplus |
| 1818 | ? &is_a_field_of_this : (int *) NULL); |
| 1819 | /* Call lookup_symtab, not lookup_partial_symtab, in case there are |
| 1820 | no psymtabs (coff, xcoff, or some future change to blow away the |
| 1821 | psymtabs once once symbols are read). */ |
| 1822 | if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) |
| 1823 | { |
| 1824 | yylval.ssym.sym = sym; |
| 1825 | yylval.ssym.is_a_field_of_this = is_a_field_of_this; |
| 1826 | return BLOCKNAME; |
| 1827 | } |
| 1828 | else if (!sym) |
| 1829 | { /* See if it's a file name. */ |
| 1830 | struct symtab *symtab; |
| 1831 | |
| 1832 | symtab = lookup_symtab (tmp); |
| 1833 | |
| 1834 | if (symtab) |
| 1835 | { |
| 1836 | yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK); |
| 1837 | return FILENAME; |
| 1838 | } |
| 1839 | } |
| 1840 | |
| 1841 | if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF) |
| 1842 | { |
| 1843 | /* NOTE: carlton/2003-09-25: There used to be code here to |
| 1844 | handle nested types. It didn't work very well. See the |
| 1845 | comment before qualified_type for more info. */ |
| 1846 | yylval.tsym.type = SYMBOL_TYPE (sym); |
| 1847 | return TYPENAME; |
| 1848 | } |
| 1849 | yylval.tsym.type |
| 1850 | = language_lookup_primitive_type_by_name (current_language, |
| 1851 | current_gdbarch, tmp); |
| 1852 | if (yylval.tsym.type != NULL) |
| 1853 | return TYPENAME; |
| 1854 | |
| 1855 | /* Input names that aren't symbols but ARE valid hex numbers, |
| 1856 | when the input radix permits them, can be names or numbers |
| 1857 | depending on the parse. Note we support radixes > 16 here. */ |
| 1858 | if (!sym && |
| 1859 | ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) || |
| 1860 | (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10))) |
| 1861 | { |
| 1862 | YYSTYPE newlval; /* Its value is ignored. */ |
| 1863 | hextype = parse_number (tokstart, namelen, 0, &newlval); |
| 1864 | if (hextype == INT) |
| 1865 | { |
| 1866 | yylval.ssym.sym = sym; |
| 1867 | yylval.ssym.is_a_field_of_this = is_a_field_of_this; |
| 1868 | return NAME_OR_INT; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | /* Any other kind of symbol */ |
| 1873 | yylval.ssym.sym = sym; |
| 1874 | yylval.ssym.is_a_field_of_this = is_a_field_of_this; |
| 1875 | if (in_parse_field && *lexptr == '\0') |
| 1876 | saw_name_at_eof = 1; |
| 1877 | return NAME; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | int |
| 1882 | c_parse (void) |
| 1883 | { |
| 1884 | last_was_structop = 0; |
| 1885 | saw_name_at_eof = 0; |
| 1886 | return yyparse (); |
| 1887 | } |
| 1888 | |
| 1889 | void |
| 1890 | yyerror (msg) |
| 1891 | char *msg; |
| 1892 | { |
| 1893 | if (prev_lexptr) |
| 1894 | lexptr = prev_lexptr; |
| 1895 | |
| 1896 | error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr); |
| 1897 | } |