PageRenderTime 67ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Happy | 1472 lines | 1295 code | 177 blank | 0 comment | 0 complexity | b8193d0c3887d31f1d98587d9e1004e8 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>p-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">p-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 Pascal expressions, for GDB.
  24. Copyright (C) 2000
  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. /* This file is derived from c-exp.y */
  39. /* Parse a Pascal expression from text in a string,
  40. and return the result as a struct expression pointer.
  41. That structure contains arithmetic operations in reverse polish,
  42. with constants represented by operations that are followed by special data.
  43. See expression.h for the details of the format.
  44. What is important here is that it can be built up sequentially
  45. during the process of parsing; the lower levels of the tree always
  46. come first in the result.
  47. Note that malloc's and realloc's in this file are transformed to
  48. xmalloc and xrealloc respectively by the same sed command in the
  49. makefile that remaps any other malloc/realloc inserted by the parser
  50. generator. Doing this with #defines and trying to control the interaction
  51. with include files (&lt;malloc.h&gt; and &lt;stdlib.h&gt; for example) just became
  52. too messy, particularly when such includes can be inserted at random
  53. times by the parser generator. */
  54. /* FIXME: there are still 21 shift/reduce conflicts
  55. Other known bugs or limitations:
  56. - pascal string operations are not supported at all.
  57. - there are some problems with boolean types.
  58. - Pascal type hexadecimal constants are not supported
  59. because they conflict with the internal variables format.
  60. Probably also lots of other problems, less well defined PM */
  61. %{
  62. #include &quot;defs.h&quot;
  63. #include &quot;gdb_string.h&quot;
  64. #include &lt;ctype.h&gt;
  65. #include &quot;expression.h&quot;
  66. #include &quot;value.h&quot;
  67. #include &quot;parser-defs.h&quot;
  68. #include &quot;language.h&quot;
  69. #include &quot;p-lang.h&quot;
  70. #include &quot;bfd.h&quot; /* Required by objfiles.h. */
  71. #include &quot;symfile.h&quot; /* Required by objfiles.h. */
  72. #include &quot;objfiles.h&quot; /* For have_full_symbols and have_partial_symbols */
  73. #include &quot;top.h&quot;
  74. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  75. as well as gratuitiously global symbol names, so we can have multiple
  76. yacc generated parsers in gdb. Note that these are only the variables
  77. produced by yacc. If other parser generators (bison, byacc, etc) produce
  78. additional global names that conflict at link time, then those parser
  79. generators need to be fixed instead of adding those names to this list. */
  80. #define yymaxdepth pascal_maxdepth
  81. #define yyparse pascal_parse
  82. #define yylex pascal_lex
  83. #define yyerror pascal_error
  84. #define yylval pascal_lval
  85. #define yychar pascal_char
  86. #define yydebug pascal_debug
  87. #define yypact pascal_pact
  88. #define yyr1 pascal_r1
  89. #define yyr2 pascal_r2
  90. #define yydef pascal_def
  91. #define yychk pascal_chk
  92. #define yypgo pascal_pgo
  93. #define yyact pascal_act
  94. #define yyexca pascal_exca
  95. #define yyerrflag pascal_errflag
  96. #define yynerrs pascal_nerrs
  97. #define yyps pascal_ps
  98. #define yypv pascal_pv
  99. #define yys pascal_s
  100. #define yy_yys pascal_yys
  101. #define yystate pascal_state
  102. #define yytmp pascal_tmp
  103. #define yyv pascal_v
  104. #define yy_yyv pascal_yyv
  105. #define yyval pascal_val
  106. #define yylloc pascal_lloc
  107. #define yyreds pascal_reds /* With YYDEBUG defined */
  108. #define yytoks pascal_toks /* With YYDEBUG defined */
  109. #define yylhs pascal_yylhs
  110. #define yylen pascal_yylen
  111. #define yydefred pascal_yydefred
  112. #define yydgoto pascal_yydgoto
  113. #define yysindex pascal_yysindex
  114. #define yyrindex pascal_yyrindex
  115. #define yygindex pascal_yygindex
  116. #define yytable pascal_yytable
  117. #define yycheck pascal_yycheck
  118. #ifndef YYDEBUG
  119. #define YYDEBUG 0 /* Default to no yydebug support */
  120. #endif
  121. int yyparse (void);
  122. static int yylex (void);
  123. void
  124. yyerror (char *);
  125. static char * uptok (char *, int);
  126. %}
  127. /* Although the yacc &quot;value&quot; of an expression is not used,
  128. since the result is stored in the structure being created,
  129. other node types do have values. */
  130. %union
  131. {
  132. LONGEST lval;
  133. struct {
  134. LONGEST val;
  135. struct type *type;
  136. } typed_val_int;
  137. struct {
  138. DOUBLEST dval;
  139. struct type *type;
  140. } typed_val_float;
  141. struct symbol *sym;
  142. struct type *tval;
  143. struct stoken sval;
  144. struct ttype tsym;
  145. struct symtoken ssym;
  146. int voidval;
  147. struct block *bval;
  148. enum exp_opcode opcode;
  149. struct internalvar *ivar;
  150. struct type **tvec;
  151. int *ivec;
  152. }
  153. %{
  154. /* YYSTYPE gets defined by %union */
  155. static int
  156. parse_number (char *, int, int, YYSTYPE *);
  157. %}
  158. %type &lt;voidval&gt; exp exp1 type_exp start variable qualified_name
  159. %type &lt;tval&gt; type typebase
  160. /* %type &lt;bval&gt; block */
  161. /* Fancy type parsing. */
  162. %type &lt;tval&gt; ptype
  163. %token &lt;typed_val_int&gt; INT
  164. %token &lt;typed_val_float&gt; FLOAT
  165. /* Both NAME and TYPENAME tokens represent symbols in the input,
  166. and both convey their data as strings.
  167. But a TYPENAME is a string that happens to be defined as a typedef
  168. or builtin type name (such as int or char)
  169. and a NAME is any other symbol.
  170. Contexts where this distinction is not important can use the
  171. nonterminal &quot;name&quot;, which matches either NAME or TYPENAME. */
  172. %token &lt;sval&gt; STRING
  173. %token &lt;ssym&gt; NAME /* BLOCKNAME defined below to give it higher precedence. */
  174. %token &lt;tsym&gt; TYPENAME
  175. %type &lt;sval&gt; name
  176. %type &lt;ssym&gt; name_not_typename
  177. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  178. but which would parse as a valid number in the current input radix.
  179. E.g. &quot;c&quot; when input_radix==16. Depending on the parse, it will be
  180. turned into a name or into a number. */
  181. %token &lt;ssym&gt; NAME_OR_INT
  182. %token STRUCT CLASS SIZEOF COLONCOLON
  183. %token ERROR
  184. /* Special type cases, put in to allow the parser to distinguish different
  185. legal basetypes. */
  186. %token &lt;voidval&gt; VARIABLE
  187. /* Object pascal */
  188. %token THIS
  189. %token &lt;lval&gt; TRUE FALSE
  190. %left ','
  191. %left ABOVE_COMMA
  192. %right ASSIGN
  193. %left NOT
  194. %left OR
  195. %left XOR
  196. %left ANDAND
  197. %left '=' NOTEQUAL
  198. %left '&lt;' '&gt;' LEQ GEQ
  199. %left LSH RSH DIV MOD
  200. %left '@'
  201. %left '+' '-'
  202. %left '*' '/'
  203. %right UNARY INCREMENT DECREMENT
  204. %right ARROW '.' '[' '('
  205. %token &lt;ssym&gt; BLOCKNAME
  206. %type &lt;bval&gt; block
  207. %left COLONCOLON
  208. %%
  209. start : exp1
  210. | type_exp
  211. ;
  212. type_exp: type
  213. { write_exp_elt_opcode(OP_TYPE);
  214. write_exp_elt_type($1);
  215. write_exp_elt_opcode(OP_TYPE);}
  216. ;
  217. /* Expressions, including the comma operator. */
  218. exp1 : exp
  219. | exp1 ',' exp
  220. { write_exp_elt_opcode (BINOP_COMMA); }
  221. ;
  222. /* Expressions, not including the comma operator. */
  223. exp : exp '^' %prec UNARY
  224. { write_exp_elt_opcode (UNOP_IND); }
  225. exp : '@' exp %prec UNARY
  226. { write_exp_elt_opcode (UNOP_ADDR); }
  227. exp : '-' exp %prec UNARY
  228. { write_exp_elt_opcode (UNOP_NEG); }
  229. ;
  230. exp : NOT exp %prec UNARY
  231. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  232. ;
  233. exp : INCREMENT '(' exp ')' %prec UNARY
  234. { write_exp_elt_opcode (UNOP_PREINCREMENT); }
  235. ;
  236. exp : DECREMENT '(' exp ')' %prec UNARY
  237. { write_exp_elt_opcode (UNOP_PREDECREMENT); }
  238. ;
  239. exp : exp '.' name
  240. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  241. write_exp_string ($3);
  242. write_exp_elt_opcode (STRUCTOP_STRUCT); }
  243. ;
  244. exp : exp '[' exp1 ']'
  245. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  246. ;
  247. exp : exp '('
  248. /* This is to save the value of arglist_len
  249. being accumulated by an outer function call. */
  250. { start_arglist (); }
  251. arglist ')' %prec ARROW
  252. { write_exp_elt_opcode (OP_FUNCALL);
  253. write_exp_elt_longcst ((LONGEST) end_arglist ());
  254. write_exp_elt_opcode (OP_FUNCALL); }
  255. ;
  256. arglist :
  257. | exp
  258. { arglist_len = 1; }
  259. | arglist ',' exp %prec ABOVE_COMMA
  260. { arglist_len++; }
  261. ;
  262. exp : type '(' exp ')' %prec UNARY
  263. { write_exp_elt_opcode (UNOP_CAST);
  264. write_exp_elt_type ($1);
  265. write_exp_elt_opcode (UNOP_CAST); }
  266. ;
  267. exp : '(' exp1 ')'
  268. { }
  269. ;
  270. /* Binary operators in order of decreasing precedence. */
  271. exp : exp '*' exp
  272. { write_exp_elt_opcode (BINOP_MUL); }
  273. ;
  274. exp : exp '/' exp
  275. { write_exp_elt_opcode (BINOP_DIV); }
  276. ;
  277. exp : exp DIV exp
  278. { write_exp_elt_opcode (BINOP_INTDIV); }
  279. ;
  280. exp : exp MOD exp
  281. { write_exp_elt_opcode (BINOP_REM); }
  282. ;
  283. exp : exp '+' exp
  284. { write_exp_elt_opcode (BINOP_ADD); }
  285. ;
  286. exp : exp '-' exp
  287. { write_exp_elt_opcode (BINOP_SUB); }
  288. ;
  289. exp : exp LSH exp
  290. { write_exp_elt_opcode (BINOP_LSH); }
  291. ;
  292. exp : exp RSH exp
  293. { write_exp_elt_opcode (BINOP_RSH); }
  294. ;
  295. exp : exp '=' exp
  296. { write_exp_elt_opcode (BINOP_EQUAL); }
  297. ;
  298. exp : exp NOTEQUAL exp
  299. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  300. ;
  301. exp : exp LEQ exp
  302. { write_exp_elt_opcode (BINOP_LEQ); }
  303. ;
  304. exp : exp GEQ exp
  305. { write_exp_elt_opcode (BINOP_GEQ); }
  306. ;
  307. exp : exp '&lt;' exp
  308. { write_exp_elt_opcode (BINOP_LESS); }
  309. ;
  310. exp : exp '&gt;' exp
  311. { write_exp_elt_opcode (BINOP_GTR); }
  312. ;
  313. exp : exp ANDAND exp
  314. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  315. ;
  316. exp : exp XOR exp
  317. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  318. ;
  319. exp : exp OR exp
  320. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  321. ;
  322. exp : exp ASSIGN exp
  323. { write_exp_elt_opcode (BINOP_ASSIGN); }
  324. ;
  325. exp : TRUE
  326. { write_exp_elt_opcode (OP_BOOL);
  327. write_exp_elt_longcst ((LONGEST) $1);
  328. write_exp_elt_opcode (OP_BOOL); }
  329. ;
  330. exp : FALSE
  331. { write_exp_elt_opcode (OP_BOOL);
  332. write_exp_elt_longcst ((LONGEST) $1);
  333. write_exp_elt_opcode (OP_BOOL); }
  334. ;
  335. exp : INT
  336. { write_exp_elt_opcode (OP_LONG);
  337. write_exp_elt_type ($1.type);
  338. write_exp_elt_longcst ((LONGEST)($1.val));
  339. write_exp_elt_opcode (OP_LONG); }
  340. ;
  341. exp : NAME_OR_INT
  342. { YYSTYPE val;
  343. parse_number ($1.stoken.ptr, $1.stoken.length, 0, &amp;val);
  344. write_exp_elt_opcode (OP_LONG);
  345. write_exp_elt_type (val.typed_val_int.type);
  346. write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
  347. write_exp_elt_opcode (OP_LONG);
  348. }
  349. ;
  350. exp : FLOAT
  351. { write_exp_elt_opcode (OP_DOUBLE);
  352. write_exp_elt_type ($1.type);
  353. write_exp_elt_dblcst ($1.dval);
  354. write_exp_elt_opcode (OP_DOUBLE); }
  355. ;
  356. exp : variable
  357. ;
  358. exp : VARIABLE
  359. /* Already written by write_dollar_variable. */
  360. ;
  361. exp : SIZEOF '(' type ')' %prec UNARY
  362. { write_exp_elt_opcode (OP_LONG);
  363. write_exp_elt_type (builtin_type_int);
  364. CHECK_TYPEDEF ($3);
  365. write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
  366. write_exp_elt_opcode (OP_LONG); }
  367. ;
  368. exp : STRING
  369. { /* C strings are converted into array constants with
  370. an explicit null byte added at the end. Thus
  371. the array upper bound is the string length.
  372. There is no such thing in C as a completely empty
  373. string. */
  374. char *sp = $1.ptr; int count = $1.length;
  375. while (count-- &gt; 0)
  376. {
  377. write_exp_elt_opcode (OP_LONG);
  378. write_exp_elt_type (builtin_type_char);
  379. write_exp_elt_longcst ((LONGEST)(*sp++));
  380. write_exp_elt_opcode (OP_LONG);
  381. }
  382. write_exp_elt_opcode (OP_LONG);
  383. write_exp_elt_type (builtin_type_char);
  384. write_exp_elt_longcst ((LONGEST)'\0');
  385. write_exp_elt_opcode (OP_LONG);
  386. write_exp_elt_opcode (OP_ARRAY);
  387. write_exp_elt_longcst ((LONGEST) 0);
  388. write_exp_elt_longcst ((LONGEST) ($1.length));
  389. write_exp_elt_opcode (OP_ARRAY); }
  390. ;
  391. /* Object pascal */
  392. exp : THIS
  393. { write_exp_elt_opcode (OP_THIS);
  394. write_exp_elt_opcode (OP_THIS); }
  395. ;
  396. /* end of object pascal. */
  397. block : BLOCKNAME
  398. {
  399. if ($1.sym != 0)
  400. $$ = SYMBOL_BLOCK_VALUE ($1.sym);
  401. else
  402. {
  403. struct symtab *tem =
  404. lookup_symtab (copy_name ($1.stoken));
  405. if (tem)
  406. $$ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), STATIC_BLOCK);
  407. else
  408. error (&quot;No file or function \&quot;%s\&quot;.&quot;,
  409. copy_name ($1.stoken));
  410. }
  411. }
  412. ;
  413. block : block COLONCOLON name
  414. { struct symbol *tem
  415. = lookup_symbol (copy_name ($3), $1,
  416. VAR_NAMESPACE, (int *) NULL,
  417. (struct symtab **) NULL);
  418. if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  419. error (&quot;No function \&quot;%s\&quot; in specified context.&quot;,
  420. copy_name ($3));
  421. $$ = SYMBOL_BLOCK_VALUE (tem); }
  422. ;
  423. variable: block COLONCOLON name
  424. { struct symbol *sym;
  425. sym = lookup_symbol (copy_name ($3), $1,
  426. VAR_NAMESPACE, (int *) NULL,
  427. (struct symtab **) NULL);
  428. if (sym == 0)
  429. error (&quot;No symbol \&quot;%s\&quot; in specified context.&quot;,
  430. copy_name ($3));
  431. write_exp_elt_opcode (OP_VAR_VALUE);
  432. /* block_found is set by lookup_symbol. */
  433. write_exp_elt_block (block_found);
  434. write_exp_elt_sym (sym);
  435. write_exp_elt_opcode (OP_VAR_VALUE); }
  436. ;
  437. qualified_name: typebase COLONCOLON name
  438. {
  439. struct type *type = $1;
  440. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  441. &amp;&amp; TYPE_CODE (type) != TYPE_CODE_UNION)
  442. error (&quot;`%s' is not defined as an aggregate type.&quot;,
  443. TYPE_NAME (type));
  444. write_exp_elt_opcode (OP_SCOPE);
  445. write_exp_elt_type (type);
  446. write_exp_string ($3);
  447. write_exp_elt_opcode (OP_SCOPE);
  448. }
  449. ;
  450. variable: qualified_name
  451. | COLONCOLON name
  452. {
  453. char *name = copy_name ($2);
  454. struct symbol *sym;
  455. struct minimal_symbol *msymbol;
  456. sym =
  457. lookup_symbol (name, (const struct block *) NULL,
  458. VAR_NAMESPACE, (int *) NULL,
  459. (struct symtab **) NULL);
  460. if (sym)
  461. {
  462. write_exp_elt_opcode (OP_VAR_VALUE);
  463. write_exp_elt_block (NULL);
  464. write_exp_elt_sym (sym);
  465. write_exp_elt_opcode (OP_VAR_VALUE);
  466. break;
  467. }
  468. msymbol = lookup_minimal_symbol (name, NULL, NULL);
  469. if (msymbol != NULL)
  470. {
  471. write_exp_msymbol (msymbol,
  472. lookup_function_type (builtin_type_int),
  473. builtin_type_int);
  474. }
  475. else
  476. if (!have_full_symbols () &amp;&amp; !have_partial_symbols ())
  477. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  478. else
  479. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;, name);
  480. }
  481. ;
  482. variable: name_not_typename
  483. { struct symbol *sym = $1.sym;
  484. if (sym)
  485. {
  486. if (symbol_read_needs_frame (sym))
  487. {
  488. if (innermost_block == 0 ||
  489. contained_in (block_found,
  490. innermost_block))
  491. innermost_block = block_found;
  492. }
  493. write_exp_elt_opcode (OP_VAR_VALUE);
  494. /* We want to use the selected frame, not
  495. another more inner frame which happens to
  496. be in the same block. */
  497. write_exp_elt_block (NULL);
  498. write_exp_elt_sym (sym);
  499. write_exp_elt_opcode (OP_VAR_VALUE);
  500. }
  501. else if ($1.is_a_field_of_this)
  502. {
  503. /* Object pascal: it hangs off of `this'. Must
  504. not inadvertently convert from a method call
  505. to data ref. */
  506. if (innermost_block == 0 ||
  507. contained_in (block_found, innermost_block))
  508. innermost_block = block_found;
  509. write_exp_elt_opcode (OP_THIS);
  510. write_exp_elt_opcode (OP_THIS);
  511. write_exp_elt_opcode (STRUCTOP_PTR);
  512. write_exp_string ($1.stoken);
  513. write_exp_elt_opcode (STRUCTOP_PTR);
  514. }
  515. else
  516. {
  517. struct minimal_symbol *msymbol;
  518. register char *arg = copy_name ($1.stoken);
  519. msymbol =
  520. lookup_minimal_symbol (arg, NULL, NULL);
  521. if (msymbol != NULL)
  522. {
  523. write_exp_msymbol (msymbol,
  524. lookup_function_type (builtin_type_int),
  525. builtin_type_int);
  526. }
  527. else if (!have_full_symbols () &amp;&amp; !have_partial_symbols ())
  528. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  529. else
  530. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  531. copy_name ($1.stoken));
  532. }
  533. }
  534. ;
  535. ptype : typebase
  536. ;
  537. /* We used to try to recognize more pointer to member types here, but
  538. that didn't work (shift/reduce conflicts meant that these rules never
  539. got executed). The problem is that
  540. int (foo::bar::baz::bizzle)
  541. is a function type but
  542. int (foo::bar::baz::bizzle::*)
  543. is a pointer to member type. Stroustrup loses again! */
  544. type : ptype
  545. | typebase COLONCOLON '*'
  546. { $$ = lookup_member_type (builtin_type_int, $1); }
  547. ;
  548. typebase /* Implements (approximately): (type-qualifier)* type-specifier */
  549. : TYPENAME
  550. { $$ = $1.type; }
  551. | STRUCT name
  552. { $$ = lookup_struct (copy_name ($2),
  553. expression_context_block); }
  554. | CLASS name
  555. { $$ = lookup_struct (copy_name ($2),
  556. expression_context_block); }
  557. /* &quot;const&quot; and &quot;volatile&quot; are curently ignored. A type qualifier
  558. after the type is handled in the ptype rule. I think these could
  559. be too. */
  560. ;
  561. name : NAME { $$ = $1.stoken; }
  562. | BLOCKNAME { $$ = $1.stoken; }
  563. | TYPENAME { $$ = $1.stoken; }
  564. | NAME_OR_INT { $$ = $1.stoken; }
  565. ;
  566. name_not_typename : NAME
  567. | BLOCKNAME
  568. /* These would be useful if name_not_typename was useful, but it is just
  569. a fake for &quot;variable&quot;, so these cause reduce/reduce conflicts because
  570. the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
  571. =exp) or just an exp. If name_not_typename was ever used in an lvalue
  572. context where only a name could occur, this might be useful.
  573. | NAME_OR_INT
  574. */
  575. ;
  576. %%
  577. /* Take care of parsing a number (anything that starts with a digit).
  578. Set yylval and return the token type; update lexptr.
  579. LEN is the number of characters in it. */
  580. /*** Needs some error checking for the float case ***/
  581. static int
  582. parse_number (p, len, parsed_float, putithere)
  583. register char *p;
  584. register int len;
  585. int parsed_float;
  586. YYSTYPE *putithere;
  587. {
  588. /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
  589. here, and we do kind of silly things like cast to unsigned. */
  590. register LONGEST n = 0;
  591. register LONGEST prevn = 0;
  592. ULONGEST un;
  593. register int i = 0;
  594. register int c;
  595. register int base = input_radix;
  596. int unsigned_p = 0;
  597. /* Number of &quot;L&quot; suffixes encountered. */
  598. int long_p = 0;
  599. /* We have found a &quot;L&quot; or &quot;U&quot; suffix. */
  600. int found_suffix = 0;
  601. ULONGEST high_bit;
  602. struct type *signed_type;
  603. struct type *unsigned_type;
  604. if (parsed_float)
  605. {
  606. /* It's a float since it contains a point or an exponent. */
  607. char c;
  608. int num = 0; /* number of tokens scanned by scanf */
  609. char saved_char = p[len];
  610. p[len] = 0; /* null-terminate the token */
  611. if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (float))
  612. num = sscanf (p, &quot;%g%c&quot;, (float *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  613. else if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (double))
  614. num = sscanf (p, &quot;%lg%c&quot;, (double *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  615. else
  616. {
  617. #ifdef SCANF_HAS_LONG_DOUBLE
  618. num = sscanf (p, &quot;%Lg%c&quot;, &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  619. #else
  620. /* Scan it into a double, then assign it to the long double.
  621. This at least wins with values representable in the range
  622. of doubles. */
  623. double temp;
  624. num = sscanf (p, &quot;%lg%c&quot;, &amp;temp,&amp;c);
  625. putithere-&gt;typed_val_float.dval = temp;
  626. #endif
  627. }
  628. p[len] = saved_char; /* restore the input stream */
  629. if (num != 1) /* check scanf found ONLY a float ... */
  630. return ERROR;
  631. /* See if it has `f' or `l' suffix (float or long double). */
  632. c = tolower (p[len - 1]);
  633. if (c == 'f')
  634. putithere-&gt;typed_val_float.type = builtin_type_float;
  635. else if (c == 'l')
  636. putithere-&gt;typed_val_float.type = builtin_type_long_double;
  637. else if (isdigit (c) || c == '.')
  638. putithere-&gt;typed_val_float.type = builtin_type_double;
  639. else
  640. return ERROR;
  641. return FLOAT;
  642. }
  643. /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  644. if (p[0] == '0')
  645. switch (p[1])
  646. {
  647. case 'x':
  648. case 'X':
  649. if (len &gt;= 3)
  650. {
  651. p += 2;
  652. base = 16;
  653. len -= 2;
  654. }
  655. break;
  656. case 't':
  657. case 'T':
  658. case 'd':
  659. case 'D':
  660. if (len &gt;= 3)
  661. {
  662. p += 2;
  663. base = 10;
  664. len -= 2;
  665. }
  666. break;
  667. default:
  668. base = 8;
  669. break;
  670. }
  671. while (len-- &gt; 0)
  672. {
  673. c = *p++;
  674. if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')
  675. c += 'a' - 'A';
  676. if (c != 'l' &amp;&amp; c != 'u')
  677. n *= base;
  678. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  679. {
  680. if (found_suffix)
  681. return ERROR;
  682. n += i = c - '0';
  683. }
  684. else
  685. {
  686. if (base &gt; 10 &amp;&amp; c &gt;= 'a' &amp;&amp; c &lt;= 'f')
  687. {
  688. if (found_suffix)
  689. return ERROR;
  690. n += i = c - 'a' + 10;
  691. }
  692. else if (c == 'l')
  693. {
  694. ++long_p;
  695. found_suffix = 1;
  696. }
  697. else if (c == 'u')
  698. {
  699. unsigned_p = 1;
  700. found_suffix = 1;
  701. }
  702. else
  703. return ERROR; /* Char not a digit */
  704. }
  705. if (i &gt;= base)
  706. return ERROR; /* Invalid digit in this base */
  707. /* Portably test for overflow (only works for nonzero values, so make
  708. a second check for zero). FIXME: Can't we just make n and prevn
  709. unsigned and avoid this? */
  710. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; (prevn &gt;= n) &amp;&amp; n != 0)
  711. unsigned_p = 1; /* Try something unsigned */
  712. /* Portably test for unsigned overflow.
  713. FIXME: This check is wrong; for example it doesn't find overflow
  714. on 0x123456789 when LONGEST is 32 bits. */
  715. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; n != 0)
  716. {
  717. if ((unsigned_p &amp;&amp; (ULONGEST) prevn &gt;= (ULONGEST) n))
  718. error (&quot;Numeric constant too large.&quot;);
  719. }
  720. prevn = n;
  721. }
  722. /* An integer constant is an int, a long, or a long long. An L
  723. suffix forces it to be long; an LL suffix forces it to be long
  724. long. If not forced to a larger size, it gets the first type of
  725. the above that it fits in. To figure out whether it fits, we
  726. shift it right and see whether anything remains. Note that we
  727. can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  728. operation, because many compilers will warn about such a shift
  729. (which always produces a zero result). Sometimes TARGET_INT_BIT
  730. or TARGET_LONG_BIT will be that big, sometimes not. To deal with
  731. the case where it is we just always shift the value more than
  732. once, with fewer bits each time. */
  733. un = (ULONGEST)n &gt;&gt; 2;
  734. if (long_p == 0
  735. &amp;&amp; (un &gt;&gt; (TARGET_INT_BIT - 2)) == 0)
  736. {
  737. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_INT_BIT-1);
  738. /* A large decimal (not hex or octal) constant (between INT_MAX
  739. and UINT_MAX) is a long or unsigned long, according to ANSI,
  740. never an unsigned int, but this code treats it as unsigned
  741. int. This probably should be fixed. GCC gives a warning on
  742. such constants. */
  743. unsigned_type = builtin_type_unsigned_int;
  744. signed_type = builtin_type_int;
  745. }
  746. else if (long_p &lt;= 1
  747. &amp;&amp; (un &gt;&gt; (TARGET_LONG_BIT - 2)) == 0)
  748. {
  749. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_LONG_BIT-1);
  750. unsigned_type = builtin_type_unsigned_long;
  751. signed_type = builtin_type_long;
  752. }
  753. else
  754. {
  755. high_bit = (((ULONGEST)1)
  756. &lt;&lt; (TARGET_LONG_LONG_BIT - 32 - 1)
  757. &lt;&lt; 16
  758. &lt;&lt; 16);
  759. if (high_bit == 0)
  760. /* A long long does not fit in a LONGEST. */
  761. high_bit =
  762. (ULONGEST)1 &lt;&lt; (sizeof (LONGEST) * HOST_CHAR_BIT - 1);
  763. unsigned_type = builtin_type_unsigned_long_long;
  764. signed_type = builtin_type_long_long;
  765. }
  766. putithere-&gt;typed_val_int.val = n;
  767. /* If the high bit of the worked out type is set then this number
  768. has to be unsigned. */
  769. if (unsigned_p || (n &amp; high_bit))
  770. {
  771. putithere-&gt;typed_val_int.type = unsigned_type;
  772. }
  773. else
  774. {
  775. putithere-&gt;typed_val_int.type = signed_type;
  776. }
  777. return INT;
  778. }
  779. struct token
  780. {
  781. char *operator;
  782. int token;
  783. enum exp_opcode opcode;
  784. };
  785. static const struct token tokentab3[] =
  786. {
  787. {&quot;shr&quot;, RSH, BINOP_END},
  788. {&quot;shl&quot;, LSH, BINOP_END},
  789. {&quot;and&quot;, ANDAND, BINOP_END},
  790. {&quot;div&quot;, DIV, BINOP_END},
  791. {&quot;not&quot;, NOT, BINOP_END},
  792. {&quot;mod&quot;, MOD, BINOP_END},
  793. {&quot;inc&quot;, INCREMENT, BINOP_END},
  794. {&quot;dec&quot;, DECREMENT, BINOP_END},
  795. {&quot;xor&quot;, XOR, BINOP_END}
  796. };
  797. static const struct token tokentab2[] =
  798. {
  799. {&quot;or&quot;, OR, BINOP_END},
  800. {&quot;&lt;&gt;&quot;, NOTEQUAL, BINOP_END},
  801. {&quot;&lt;=&quot;, LEQ, BINOP_END},
  802. {&quot;&gt;=&quot;, GEQ, BINOP_END},
  803. {&quot;:=&quot;, ASSIGN, BINOP_END}
  804. };
  805. /* Allocate uppercased var */
  806. /* make an uppercased copy of tokstart */
  807. static char * uptok (tokstart, namelen)
  808. char *tokstart;
  809. int namelen;
  810. {
  811. int i;
  812. char *uptokstart = (char *)malloc(namelen+1);
  813. for (i = 0;i &lt;= namelen;i++)
  814. {
  815. if ((tokstart[i]&gt;='a' &amp;&amp; tokstart[i]&lt;='z'))
  816. uptokstart[i] = tokstart[i]-('a'-'A');
  817. else
  818. uptokstart[i] = tokstart[i];
  819. }
  820. uptokstart[namelen]='\0';
  821. return uptokstart;
  822. }
  823. /* Read one token, getting characters through lexptr. */
  824. static int
  825. yylex ()
  826. {
  827. int c;
  828. int namelen;
  829. unsigned int i;
  830. char *tokstart;
  831. char *uptokstart;
  832. char *tokptr;
  833. char *p;
  834. int tempbufindex;
  835. static char *tempbuf;
  836. static int tempbufsize;
  837. retry:
  838. tokstart = lexptr;
  839. /* See if it is a special token of length 3. */
  840. for (i = 0; i &lt; sizeof tokentab3 / sizeof tokentab3[0]; i++)
  841. if (STREQN (tokstart, tokentab3[i].operator, 3))
  842. {
  843. lexptr += 3;
  844. yylval.opcode = tokentab3[i].opcode;
  845. return tokentab3[i].token;
  846. }
  847. /* See if it is a special token of length 2. */
  848. for (i = 0; i &lt; sizeof tokentab2 / sizeof tokentab2[0]; i++)
  849. if (STREQN (tokstart, tokentab2[i].operator, 2))
  850. {
  851. lexptr += 2;
  852. yylval.opcode = tokentab2[i].opcode;
  853. return tokentab2[i].token;
  854. }
  855. switch (c = *tokstart)
  856. {
  857. case 0:
  858. return 0;
  859. case ' ':
  860. case '\t':
  861. case '\n':
  862. lexptr++;
  863. goto retry;
  864. case '\'':
  865. /* We either have a character constant ('0' or '\177' for example)
  866. or we have a quoted symbol reference ('foo(int,int)' in object pascal
  867. for example). */
  868. lexptr++;
  869. c = *lexptr++;
  870. if (c == '\\')
  871. c = parse_escape (&amp;lexptr);
  872. else if (c == '\'')
  873. error (&quot;Empty character constant.&quot;);
  874. yylval.typed_val_int.val = c;
  875. yylval.typed_val_int.type = builtin_type_char;
  876. c = *lexptr++;
  877. if (c != '\'')
  878. {
  879. namelen = skip_quoted (tokstart, gdb_completer_word_break_characters) - tokstart;
  880. if (namelen &gt; 2)
  881. {
  882. lexptr = tokstart + namelen;
  883. if (lexptr[-1] != '\'')
  884. error (&quot;Unmatched single quote.&quot;);
  885. namelen -= 2;
  886. tokstart++;
  887. uptokstart = uptok(tokstart,namelen);
  888. goto tryname;
  889. }
  890. error (&quot;Invalid character constant.&quot;);
  891. }
  892. return INT;
  893. case '(':
  894. paren_depth++;
  895. lexptr++;
  896. return c;
  897. case ')':
  898. if (paren_depth == 0)
  899. return 0;
  900. paren_depth--;
  901. lexptr++;
  902. return c;
  903. case ',':
  904. if (comma_terminates &amp;&amp; paren_depth == 0)
  905. return 0;
  906. lexptr++;
  907. return c;
  908. case '.':
  909. /* Might be a floating point number. */
  910. if (lexptr[1] &lt; '0' || lexptr[1] &gt; '9')
  911. goto symbol; /* Nope, must be a symbol. */
  912. /* FALL THRU into number case. */
  913. case '0':
  914. case '1':
  915. case '2':
  916. case '3':
  917. case '4':
  918. case '5':
  919. case '6':
  920. case '7':
  921. case '8':
  922. case '9':
  923. {
  924. /* It's a number. */
  925. int got_dot = 0, got_e = 0, toktype;
  926. register char *p = tokstart;
  927. int hex = input_radix &gt; 10;
  928. if (c == '0' &amp;&amp; (p[1] == 'x' || p[1] == 'X'))
  929. {
  930. p += 2;
  931. hex = 1;
  932. }
  933. else if (c == '0' &amp;&amp; (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  934. {
  935. p += 2;
  936. hex = 0;
  937. }
  938. for (;; ++p)
  939. {
  940. /* This test includes !hex because 'e' is a valid hex digit
  941. and thus does not indicate a floating point number when
  942. the radix is hex. */
  943. if (!hex &amp;&amp; !got_e &amp;&amp; (*p == 'e' || *p == 'E'))
  944. got_dot = got_e = 1;
  945. /* This test does not include !hex, because a '.' always indicates
  946. a decimal floating point number regardless of the radix. */
  947. else if (!got_dot &amp;&amp; *p == '.')
  948. got_dot = 1;
  949. else if (got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E')
  950. &amp;&amp; (*p == '-' || *p == '+'))
  951. /* This is the sign of the exponent, not the end of the
  952. number. */
  953. continue;
  954. /* We will take any letters or digits. parse_number will
  955. complain if past the radix, or if L or U are not final. */
  956. else if ((*p &lt; '0' || *p &gt; '9')
  957. &amp;&amp; ((*p &lt; 'a' || *p &gt; 'z')
  958. &amp;&amp; (*p &lt; 'A' || *p &gt; 'Z')))
  959. break;
  960. }
  961. toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &amp;yylval);
  962. if (toktype == ERROR)
  963. {
  964. char *err_copy = (char *) alloca (p - tokstart + 1);
  965. memcpy (err_copy, tokstart, p - tokstart);
  966. err_copy[p - tokstart] = 0;
  967. error (&quot;Invalid number \&quot;%s\&quot;.&quot;, err_copy);
  968. }
  969. lexptr = p;
  970. return toktype;
  971. }
  972. case '+':
  973. case '-':
  974. case '*':
  975. case '/':
  976. case '|':
  977. case '&amp;':
  978. case '^':
  979. case '~':
  980. case '!':
  981. case '@':
  982. case '&lt;':
  983. case '&gt;':
  984. case '[':
  985. case ']':
  986. case '?':
  987. case ':':
  988. case '=':
  989. case '{':
  990. case '}':
  991. symbol:
  992. lexptr++;
  993. return c;
  994. case '&quot;':
  995. /* Build the gdb internal form of the input string in tempbuf,
  996. translating any standard C escape forms seen. Note that the
  997. buffer is null byte terminated *only* for the convenience of
  998. debugging gdb itself and printing the buffer contents when
  999. the buffer contains no embedded nulls. Gdb does not depend
  1000. upon the buffer being null byte terminated, it uses the length
  1001. string instead. This allows gdb to handle C strings (as well
  1002. as strings in other languages) with embedded null bytes */
  1003. tokptr = ++tokstart;
  1004. tempbufindex = 0;
  1005. do {
  1006. /* Grow the static temp buffer if necessary, including allocating
  1007. the first one on demand. */
  1008. if (tempbufindex + 1 &gt;= tempbufsize)
  1009. {
  1010. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1011. }
  1012. switch (*tokptr)
  1013. {
  1014. case '\0':
  1015. case '&quot;':
  1016. /* Do nothing, loop will terminate. */
  1017. break;
  1018. case '\\':
  1019. tokptr++;
  1020. c = parse_escape (&amp;tokptr);
  1021. if (c == -1)
  1022. {
  1023. continue;
  1024. }
  1025. tempbuf[tempbufindex++] = c;
  1026. break;
  1027. default:
  1028. tempbuf[tempbufindex++] = *tokptr++;
  1029. break;
  1030. }
  1031. } while ((*tokptr != '&quot;') &amp;&amp; (*tokptr != '\0'));
  1032. if (*tokptr++ != '&quot;')
  1033. {
  1034. error (&quot;Unterminated string in expression.&quot;);
  1035. }
  1036. tempbuf[tempbufindex] = '\0'; /* See note above */
  1037. yylval.sval.ptr = tempbuf;
  1038. yylval.sval.length = tempbufindex;
  1039. lexptr = tokptr;
  1040. return (STRING);
  1041. }
  1042. if (!(c == '_' || c == '$'
  1043. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')))
  1044. /* We must have come across a bad character (e.g. ';'). */
  1045. error (&quot;Invalid character '%c' in expression.&quot;, c);
  1046. /* It's a name. See how long it is. */
  1047. namelen = 0;
  1048. for (c = tokstart[namelen];
  1049. (c == '_' || c == '$' || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1050. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || c == '&lt;');)
  1051. {
  1052. /* Template parameter lists are part of the name.
  1053. FIXME: This mishandles `print $a&lt;4&amp;&amp;$a&gt;3'. */
  1054. if (c == '&lt;')
  1055. {
  1056. int i = namelen;
  1057. int nesting_level = 1;
  1058. while (tokstart[++i])
  1059. {
  1060. if (tokstart[i] == '&lt;')
  1061. nesting_level++;
  1062. else if (tokstart[i] == '&gt;')
  1063. {
  1064. if (--nesting_level == 0)
  1065. break;
  1066. }
  1067. }
  1068. if (tokstart[i] == '&gt;')
  1069. namelen = i;
  1070. else
  1071. break;
  1072. }
  1073. /* do NOT uppercase internals because of registers !!! */
  1074. c = tokstart[++namelen];
  1075. }
  1076. uptokstart = uptok(tokstart,namelen);
  1077. /* The token &quot;if&quot; terminates the expression and is NOT
  1078. removed from the input stream. */
  1079. if (namelen == 2 &amp;&amp; uptokstart[0] == 'I' &amp;&amp; uptokstart[1] == 'F')
  1080. {
  1081. return 0;
  1082. }
  1083. lexptr += namelen;
  1084. tryname:
  1085. /* Catch specific keywords. Should be done with a data structure. */
  1086. switch (namelen)
  1087. {
  1088. case 6:
  1089. if (STREQ (uptokstart, &quot;OBJECT&quot;))
  1090. return CLASS;
  1091. if (STREQ (uptokstart, &quot;RECORD&quot;))
  1092. return STRUCT;
  1093. if (STREQ (uptokstart, &quot;SIZEOF&quot;))
  1094. return SIZEOF;
  1095. break;
  1096. case 5:
  1097. if (STREQ (uptokstart, &quot;CLASS&quot;))
  1098. return CLASS;
  1099. if (STREQ (uptokstart, &quot;FALSE&quot;))
  1100. {
  1101. yylval.lval = 0;
  1102. return FALSE;
  1103. }
  1104. break;
  1105. case 4:
  1106. if (STREQ (uptokstart, &quot;TRUE&quot;))
  1107. {
  1108. yylval.lval = 1;
  1109. return TRUE;
  1110. }
  1111. if (STREQ (uptokstart, &quot;SELF&quot;))
  1112. {
  1113. /* here we search for 'this' like
  1114. inserted in FPC stabs debug info */
  1115. static const char this_name[] =
  1116. { /* CPLUS_MARKER,*/ 't', 'h', 'i', 's', '\0' };
  1117. if (lookup_symbol (this_name, expression_context_block,
  1118. VAR_NAMESPACE, (int *) NULL,
  1119. (struct symtab **) NULL))
  1120. return THIS;
  1121. }
  1122. break;
  1123. default:
  1124. break;
  1125. }
  1126. yylval.sval.ptr = tokstart;
  1127. yylval.sval.length = namelen;
  1128. if (*tokstart == '$')
  1129. {
  1130. /* $ is the normal prefix for pascal hexadecimal values
  1131. but this conflicts with the GDB use for debugger variables
  1132. so in expression to enter hexadecimal values
  1133. we still need to use C syntax with 0xff */
  1134. write_dollar_variable (yylval.sval);
  1135. return VARIABLE;
  1136. }
  1137. /* Use token-type BLOCKNAME for symbols that happen to be defined as
  1138. functions or symtabs. If this is not so, then ...
  1139. Use token-type TYPENAME for symbols that happen to be defined
  1140. currently as names of types; NAME for other symbols.
  1141. The caller is not constrained to care about the distinction. */
  1142. {
  1143. char *tmp = copy_name (yylval.sval);
  1144. struct symbol *sym;
  1145. int is_a_field_of_this = 0;
  1146. int hextype;
  1147. sym = lookup_symbol (tmp, expression_context_block,
  1148. VAR_NAMESPACE,
  1149. &amp;is_a_field_of_this,
  1150. (struct symtab **) NULL);
  1151. /* second chance uppercased ! */
  1152. if (!sym)
  1153. {
  1154. for (i = 0;i &lt;= namelen;i++)
  1155. {
  1156. if ((tmp[i]&gt;='a' &amp;&amp; tmp[i]&lt;='z'))
  1157. tmp[i] -= ('a'-'A');
  1158. /* I am not sure that copy_name gives excatly the same result ! */
  1159. if ((tokstart[i]&gt;='a' &amp;&amp; tokstart[i]&lt;='z'))
  1160. tokstart[i] -= ('a'-'A');
  1161. }
  1162. sym = lookup_symbol (tmp, expression_context_block,
  1163. VAR_NAMESPACE,
  1164. &amp;is_a_field_of_this,
  1165. (struct symtab **) NULL);
  1166. }
  1167. /* Call lookup_symtab, not lookup_partial_symtab, in case there are
  1168. no psymtabs (coff, xcoff, or some future change to blow away the
  1169. psymtabs once once symbols are read). */
  1170. if ((sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_BLOCK) ||
  1171. lookup_symtab (tmp))
  1172. {
  1173. yylval.ssym.sym = sym;
  1174. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1175. return BLOCKNAME;
  1176. }
  1177. if (sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  1178. {
  1179. #if 1
  1180. /* Despite the following flaw, we need to keep this code enabled.
  1181. Because we can get called from check_stub_method, if we don't
  1182. handle nested types then it screws many operations in any
  1183. program which uses nested types. */
  1184. /* In &quot;A::x&quot;, if x is a member function of A and there happens
  1185. to be a type (nested or not, since the stabs don't make that
  1186. distinction) named x, then this code incorrectly thinks we
  1187. are dealing with nested types rather than a member function. */
  1188. char *p;
  1189. char *namestart;
  1190. struct symbol *best_sym;
  1191. /* Look ahead to detect nested types. This probably should be
  1192. done in the grammar, but trying seemed to introduce a lot
  1193. of shift/reduce and reduce/reduce conflicts. It's possible
  1194. that it could be done, though. Or perhaps a non-grammar, but
  1195. less ad hoc, approach would work well. */
  1196. /* Since we do not currently have any way of distinguishing
  1197. a nested type from a non-nested one (the stabs don't tell
  1198. us whether a type is nested), we just ignore the
  1199. containing type. */
  1200. p = lexptr;
  1201. best_sym = sym;
  1202. while (1)
  1203. {
  1204. /* Skip whitespace. */
  1205. while (*p == ' ' || *p == '\t' || *p == '\n')
  1206. ++p;
  1207. if (*p == ':' &amp;&amp; p[1] == ':')
  1208. {
  1209. /* Skip the `::'. */
  1210. p += 2;
  1211. /* Skip whitespace. */
  1212. while (*p == ' ' || *p == '\t' || *p == '\n')
  1213. ++p;
  1214. namestart = p;
  1215. while (*p == '_' || *p == '$' || (*p &gt;= '0' &amp;&amp; *p &lt;= '9')
  1216. || (*p &gt;= 'a' &amp;&amp; *p &lt;= 'z')
  1217. || (*p &gt;= 'A' &amp;&amp; *p &lt;= 'Z'))
  1218. ++p;
  1219. if (p != namestart)
  1220. {
  1221. struct symbol *cur_sym;
  1222. /* As big as the whole rest of the expression, which is
  1223. at least big enough. */
  1224. char *ncopy = alloca (strlen (tmp)+strlen (namestart)+3);
  1225. char *tmp1;
  1226. tmp1 = ncopy;
  1227. memcpy (tmp1, tmp, strlen (tmp));
  1228. tmp1 += strlen (tmp);
  1229. memcpy (tmp1, &quot;::&quot;, 2);
  1230. tmp1 += 2;
  1231. memcpy (tmp1, namestart, p - namestart);
  1232. tmp1[p - namestart] = '\0';
  1233. cur_sym = lookup_symbol (ncopy, expression_context_block,
  1234. VAR_NAMESPACE, (int *) NULL,
  1235. (struct symtab **) NULL);
  1236. if (cur_sym)
  1237. {
  1238. if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
  1239. {
  1240. best_sym = cur_sym;
  1241. lexptr = p;
  1242. }
  1243. else
  1244. break;
  1245. }
  1246. else
  1247. break;
  1248. }
  1249. else
  1250. break;
  1251. }
  1252. else
  1253. break;
  1254. }
  1255. yylval.tsym.type = SYMBOL_TYPE (best_sym);
  1256. #else /* not 0 */
  1257. yylval.tsym.type = SYMBOL_TYPE (sym);
  1258. #endif /* not 0 */
  1259. return TYPENAME;
  1260. }
  1261. if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
  1262. return TYPENAME;
  1263. /* Input names that aren't symbols but ARE valid hex numbers,
  1264. when the input radix permits them, can be names or numbers
  1265. depending on the parse. Note we support radixes &gt; 16 here. */
  1266. if (!sym &amp;&amp;
  1267. ((tokstart[0] &gt;= 'a' &amp;&amp; tokstart[0] &lt; 'a' + input_radix - 10) ||
  1268. (tokstart[0] &gt;= 'A' &amp;&amp; tokstart[0] &lt; 'A' + input_radix - 10)))
  1269. {
  1270. YYSTYPE newlval; /* Its value is ignored. */
  1271. hextype = parse_number (tokstart, namelen, 0, &amp;newlval);
  1272. if (hextype == INT)
  1273. {
  1274. yylval.ssym.sym = sym;
  1275. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1276. return NAME_OR_INT;
  1277. }
  1278. }
  1279. free(uptokstart);
  1280. /* Any other kind of symbol */
  1281. yylval.ssym.sym = sym;
  1282. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1283. return NAME;
  1284. }
  1285. }
  1286. void
  1287. yyerror (msg)
  1288. char *msg;
  1289. {
  1290. error (&quot;A %s in expression, near `%s'.&quot;, (msg ? msg : &quot;error&quot;), lexptr);
  1291. }
  1292. </pre>
  1293. <hr />
  1294. </body></html>