PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

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