PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/opensource.apple.com/source/gdb/gdb-186.1/src/gdb/c-exp.y

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