PageRenderTime 72ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

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

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