PageRenderTime 69ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

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