PageRenderTime 69ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/src/netbsd/src/gnu/dist/gdb6/gdb/c-exp.y

https://bitbucket.org/killerpenguinassassins/open_distrib_devel
Happy | 1805 lines | 1582 code | 223 blank | 0 comment | 0 complexity | 43f273d0e47aaf7ec132e623c9a39c63 MD5 | raw file
Possible License(s): CC0-1.0, MIT, LGPL-2.0, LGPL-3.0, WTFPL, GPL-2.0, BSD-2-Clause, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0, JSON, BSD-3-Clause-No-Nuclear-License-2014, LGPL-2.1, CPL-1.0, AGPL-1.0, 0BSD, ISC, Apache-2.0, GPL-3.0, IPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file