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

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

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