PageRenderTime 65ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Happy | 1842 lines | 1633 code | 209 blank | 0 comment | 0 complexity | c4dae4f3bfaea8394bf4d5aa7b2d511a 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

Large files files are truncated, but you can click here to view the full file

  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>objc-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">objc-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 C expressions, for GDB.
  24. Copyright 1986, 1989, 1990, 1991, 1993, 1994, 2002 Free Software
  25. Foundation, Inc.
  26. This program is free software; you can redistribute it and/or modify
  27. it under the terms of the GNU General Public License as published by
  28. the Free Software Foundation; either version 2 of the License, or
  29. (at your option) any later version.
  30. This program is distributed in the hope that it will be useful,
  31. but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. GNU General Public License for more details.
  34. You should have received a copy of the GNU General Public License
  35. along with this program; if not, write to the Free Software
  36. Foundation, Inc., 59 Temple Place - Suite 330,
  37. Boston, MA 02111-1307, USA. */
  38. /* Parse a C expression from text in a string, and return the result
  39. as a struct expression pointer. That structure contains arithmetic
  40. operations in reverse polish, with constants represented by
  41. operations that are followed by special data. See expression.h for
  42. the details of the format. What is important here is that it can
  43. be built up sequentially during the process of parsing; the lower
  44. levels of the tree always come first in the result.
  45. Note that malloc's and realloc's in this file are transformed to
  46. xmalloc and xrealloc respectively by the same sed command in the
  47. makefile that remaps any other malloc/realloc inserted by the
  48. parser generator. Doing this with #defines and trying to control
  49. the interaction with include files (&lt;malloc.h&gt; and &lt;stdlib.h&gt; for
  50. example) just became too messy, particularly when such includes can
  51. be inserted at random times by the parser generator. */
  52. %{
  53. #include &quot;defs.h&quot;
  54. #include &quot;gdb_string.h&quot;
  55. #include &lt;ctype.h&gt;
  56. #include &quot;expression.h&quot;
  57. #include &quot;objc-lang.h&quot; /* For objc language constructs. */
  58. #include &quot;value.h&quot;
  59. #include &quot;parser-defs.h&quot;
  60. #include &quot;language.h&quot;
  61. #include &quot;c-lang.h&quot;
  62. #include &quot;bfd.h&quot; /* Required by objfiles.h. */
  63. #include &quot;symfile.h&quot; /* Required by objfiles.h. */
  64. #include &quot;objfiles.h&quot; /* For have_full_symbols and have_partial_symbols. */
  65. #include &quot;top.h&quot;
  66. #include &quot;completer.h&quot; /* For skip_quoted(). */
  67. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
  68. etc), as well as gratuitiously global symbol names, so we can have
  69. multiple yacc generated parsers in gdb. Note that these are only
  70. the variables produced by yacc. If other parser generators (bison,
  71. byacc, etc) produce additional global names that conflict at link
  72. time, then those parser generators need to be fixed instead of
  73. adding those names to this list. */
  74. #define yymaxdepth objc_maxdepth
  75. #define yyparse objc_parse
  76. #define yylex objc_lex
  77. #define yyerror objc_error
  78. #define yylval objc_lval
  79. #define yychar objc_char
  80. #define yydebug objc_debug
  81. #define yypact objc_pact
  82. #define yyr1 objc_r1
  83. #define yyr2 objc_r2
  84. #define yydef objc_def
  85. #define yychk objc_chk
  86. #define yypgo objc_pgo
  87. #define yyact objc_act
  88. #define yyexca objc_exca
  89. #define yyerrflag objc_errflag
  90. #define yynerrs objc_nerrs
  91. #define yyps objc_ps
  92. #define yypv objc_pv
  93. #define yys objc_s
  94. #define yy_yys objc_yys
  95. #define yystate objc_state
  96. #define yytmp objc_tmp
  97. #define yyv objc_v
  98. #define yy_yyv objc_yyv
  99. #define yyval objc_val
  100. #define yylloc objc_lloc
  101. #define yyreds objc_reds /* With YYDEBUG defined */
  102. #define yytoks objc_toks /* With YYDEBUG defined */
  103. #define yyname objc_name /* With YYDEBUG defined */
  104. #define yyrule objc_rule /* With YYDEBUG defined */
  105. #define yylhs objc_yylhs
  106. #define yylen objc_yylen
  107. #define yydefred objc_yydefred
  108. #define yydgoto objc_yydgoto
  109. #define yysindex objc_yysindex
  110. #define yyrindex objc_yyrindex
  111. #define yygindex objc_yygindex
  112. #define yytable objc_yytable
  113. #define yycheck objc_yycheck
  114. #ifndef YYDEBUG
  115. #define YYDEBUG 0 /* Default to no yydebug support. */
  116. #endif
  117. int
  118. yyparse PARAMS ((void));
  119. static int
  120. yylex PARAMS ((void));
  121. void
  122. yyerror PARAMS ((char *));
  123. %}
  124. /* Although the yacc &quot;value&quot; of an expression is not used,
  125. since the result is stored in the structure being created,
  126. other node types do have values. */
  127. %union
  128. {
  129. LONGEST lval;
  130. struct {
  131. LONGEST val;
  132. struct type *type;
  133. } typed_val_int;
  134. struct {
  135. DOUBLEST dval;
  136. struct type *type;
  137. } typed_val_float;
  138. struct symbol *sym;
  139. struct type *tval;
  140. struct stoken sval;
  141. struct ttype tsym;
  142. struct symtoken ssym;
  143. int voidval;
  144. struct block *bval;
  145. enum exp_opcode opcode;
  146. struct internalvar *ivar;
  147. struct objc_class_str class;
  148. struct type **tvec;
  149. int *ivec;
  150. }
  151. %{
  152. /* YYSTYPE gets defined by %union. */
  153. static int
  154. parse_number PARAMS ((char *, int, int, YYSTYPE *));
  155. %}
  156. %type &lt;voidval&gt; exp exp1 type_exp start variable qualified_name lcurly
  157. %type &lt;lval&gt; rcurly
  158. %type &lt;tval&gt; type typebase
  159. %type &lt;tvec&gt; nonempty_typelist
  160. /* %type &lt;bval&gt; block */
  161. /* Fancy type parsing. */
  162. %type &lt;voidval&gt; func_mod direct_abs_decl abs_decl
  163. %type &lt;tval&gt; ptype
  164. %type &lt;lval&gt; array_mod
  165. %token &lt;typed_val_int&gt; INT
  166. %token &lt;typed_val_float&gt; FLOAT
  167. /* Both NAME and TYPENAME tokens represent symbols in the input, and
  168. both convey their data as strings. But a TYPENAME is a string that
  169. happens to be defined as a typedef or builtin type name (such as
  170. int or char) and a NAME is any other symbol. Contexts where this
  171. distinction is not important can use the nonterminal &quot;name&quot;, which
  172. matches either NAME or TYPENAME. */
  173. %token &lt;sval&gt; STRING
  174. %token &lt;sval&gt; NSSTRING /* ObjC Foundation &quot;NSString&quot; literal */
  175. %token &lt;sval&gt; SELECTOR /* ObjC &quot;@selector&quot; pseudo-operator */
  176. %token &lt;ssym&gt; NAME /* BLOCKNAME defined below to give it higher precedence. */
  177. %token &lt;tsym&gt; TYPENAME
  178. %token &lt;class&gt; CLASSNAME /* ObjC Class name */
  179. %type &lt;sval&gt; name
  180. %type &lt;ssym&gt; name_not_typename
  181. %type &lt;tsym&gt; typename
  182. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  183. but which would parse as a valid number in the current input radix.
  184. E.g. &quot;c&quot; when input_radix==16. Depending on the parse, it will be
  185. turned into a name or into a number. */
  186. %token &lt;ssym&gt; NAME_OR_INT
  187. %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
  188. %token TEMPLATE
  189. %token ERROR
  190. /* Special type cases, put in to allow the parser to distinguish
  191. different legal basetypes. */
  192. %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
  193. %token &lt;voidval&gt; VARIABLE
  194. %token &lt;opcode&gt; ASSIGN_MODIFY
  195. %left ','
  196. %left ABOVE_COMMA
  197. %right '=' ASSIGN_MODIFY
  198. %right '?'
  199. %left OROR
  200. %left ANDAND
  201. %left '|'
  202. %left '^'
  203. %left '&amp;'
  204. %left EQUAL NOTEQUAL
  205. %left '&lt;' '&gt;' LEQ GEQ
  206. %left LSH RSH
  207. %left '@'
  208. %left '+' '-'
  209. %left '*' '/' '%'
  210. %right UNARY INCREMENT DECREMENT
  211. %right ARROW '.' '[' '('
  212. %token &lt;ssym&gt; BLOCKNAME
  213. %type &lt;bval&gt; block
  214. %left COLONCOLON
  215. %%
  216. start : exp1
  217. | type_exp
  218. ;
  219. type_exp: type
  220. { write_exp_elt_opcode(OP_TYPE);
  221. write_exp_elt_type($1);
  222. write_exp_elt_opcode(OP_TYPE);}
  223. ;
  224. /* Expressions, including the comma operator. */
  225. exp1 : exp
  226. | exp1 ',' exp
  227. { write_exp_elt_opcode (BINOP_COMMA); }
  228. ;
  229. /* Expressions, not including the comma operator. */
  230. exp : '*' exp %prec UNARY
  231. { write_exp_elt_opcode (UNOP_IND); }
  232. exp : '&amp;' exp %prec UNARY
  233. { write_exp_elt_opcode (UNOP_ADDR); }
  234. exp : '-' exp %prec UNARY
  235. { write_exp_elt_opcode (UNOP_NEG); }
  236. ;
  237. exp : '!' exp %prec UNARY
  238. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  239. ;
  240. exp : '~' exp %prec UNARY
  241. { write_exp_elt_opcode (UNOP_COMPLEMENT); }
  242. ;
  243. exp : INCREMENT exp %prec UNARY
  244. { write_exp_elt_opcode (UNOP_PREINCREMENT); }
  245. ;
  246. exp : DECREMENT exp %prec UNARY
  247. { write_exp_elt_opcode (UNOP_PREDECREMENT); }
  248. ;
  249. exp : exp INCREMENT %prec UNARY
  250. { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
  251. ;
  252. exp : exp DECREMENT %prec UNARY
  253. { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
  254. ;
  255. exp : SIZEOF exp %prec UNARY
  256. { write_exp_elt_opcode (UNOP_SIZEOF); }
  257. ;
  258. exp : exp ARROW name
  259. { write_exp_elt_opcode (STRUCTOP_PTR);
  260. write_exp_string ($3);
  261. write_exp_elt_opcode (STRUCTOP_PTR); }
  262. ;
  263. exp : exp ARROW qualified_name
  264. { /* exp-&gt;type::name becomes exp-&gt;*(&amp;type::name) */
  265. /* Note: this doesn't work if name is a
  266. static member! FIXME */
  267. write_exp_elt_opcode (UNOP_ADDR);
  268. write_exp_elt_opcode (STRUCTOP_MPTR); }
  269. ;
  270. exp : exp ARROW '*' exp
  271. { write_exp_elt_opcode (STRUCTOP_MPTR); }
  272. ;
  273. exp : exp '.' name
  274. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  275. write_exp_string ($3);
  276. write_exp_elt_opcode (STRUCTOP_STRUCT); }
  277. ;
  278. exp : exp '.' qualified_name
  279. { /* exp.type::name becomes exp.*(&amp;type::name) */
  280. /* Note: this doesn't work if name is a
  281. static member! FIXME */
  282. write_exp_elt_opcode (UNOP_ADDR);
  283. write_exp_elt_opcode (STRUCTOP_MEMBER); }
  284. ;
  285. exp : exp '.' '*' exp
  286. { write_exp_elt_opcode (STRUCTOP_MEMBER); }
  287. ;
  288. exp : exp '[' exp1 ']'
  289. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  290. ;
  291. /*
  292. * The rules below parse ObjC message calls of the form:
  293. * '[' target selector {':' argument}* ']'
  294. */
  295. exp : '[' TYPENAME
  296. {
  297. CORE_ADDR class;
  298. class = lookup_objc_class (copy_name ($2.stoken));
  299. if (class == 0)
  300. error (&quot;%s is not an ObjC Class&quot;,
  301. copy_name ($2.stoken));
  302. write_exp_elt_opcode (OP_LONG);
  303. write_exp_elt_type (builtin_type_int);
  304. write_exp_elt_longcst ((LONGEST) class);
  305. write_exp_elt_opcode (OP_LONG);
  306. start_msglist();
  307. }
  308. msglist ']'
  309. { write_exp_elt_opcode (OP_OBJC_MSGCALL);
  310. end_msglist();
  311. write_exp_elt_opcode (OP_OBJC_MSGCALL);
  312. }
  313. ;
  314. exp : '[' CLASSNAME
  315. {
  316. write_exp_elt_opcode (OP_LONG);
  317. write_exp_elt_type (builtin_type_int);
  318. write_exp_elt_longcst ((LONGEST) $2.class);
  319. write_exp_elt_opcode (OP_LONG);
  320. start_msglist();
  321. }
  322. msglist ']'
  323. { write_exp_elt_opcode (OP_OBJC_MSGCALL);
  324. end_msglist();
  325. write_exp_elt_opcode (OP_OBJC_MSGCALL);
  326. }
  327. ;
  328. exp : '[' exp
  329. { start_msglist(); }
  330. msglist ']'
  331. { write_exp_elt_opcode (OP_OBJC_MSGCALL);
  332. end_msglist();
  333. write_exp_elt_opcode (OP_OBJC_MSGCALL);
  334. }
  335. ;
  336. msglist : name
  337. { add_msglist(&amp;$1, 0); }
  338. | msgarglist
  339. ;
  340. msgarglist : msgarg
  341. | msgarglist msgarg
  342. ;
  343. msgarg : name ':' exp
  344. { add_msglist(&amp;$1, 1); }
  345. | ':' exp /* Unnamed arg. */
  346. { add_msglist(0, 1); }
  347. | ',' exp /* Variable number of args. */
  348. { add_msglist(0, 0); }
  349. ;
  350. exp : exp '('
  351. /* This is to save the value of arglist_len
  352. being accumulated by an outer function call. */
  353. { start_arglist (); }
  354. arglist ')' %prec ARROW
  355. { write_exp_elt_opcode (OP_FUNCALL);
  356. write_exp_elt_longcst ((LONGEST) end_arglist ());
  357. write_exp_elt_opcode (OP_FUNCALL); }
  358. ;
  359. lcurly : '{'
  360. { start_arglist (); }
  361. ;
  362. arglist :
  363. ;
  364. arglist : exp
  365. { arglist_len = 1; }
  366. ;
  367. arglist : arglist ',' exp %prec ABOVE_COMMA
  368. { arglist_len++; }
  369. ;
  370. rcurly : '}'
  371. { $$ = end_arglist () - 1; }
  372. ;
  373. exp : lcurly arglist rcurly %prec ARROW
  374. { write_exp_elt_opcode (OP_ARRAY);
  375. write_exp_elt_longcst ((LONGEST) 0);
  376. write_exp_elt_longcst ((LONGEST) $3);
  377. write_exp_elt_opcode (OP_ARRAY); }
  378. ;
  379. exp : lcurly type rcurly exp %prec UNARY
  380. { write_exp_elt_opcode (UNOP_MEMVAL);
  381. write_exp_elt_type ($2);
  382. write_exp_elt_opcode (UNOP_MEMVAL); }
  383. ;
  384. exp : '(' type ')' exp %prec UNARY
  385. { write_exp_elt_opcode (UNOP_CAST);
  386. write_exp_elt_type ($2);
  387. write_exp_elt_opcode (UNOP_CAST); }
  388. ;
  389. exp : '(' exp1 ')'
  390. { }
  391. ;
  392. /* Binary operators in order of decreasing precedence. */
  393. exp : exp '@' exp
  394. { write_exp_elt_opcode (BINOP_REPEAT); }
  395. ;
  396. exp : exp '*' exp
  397. { write_exp_elt_opcode (BINOP_MUL); }
  398. ;
  399. exp : exp '/' exp
  400. { write_exp_elt_opcode (BINOP_DIV); }
  401. ;
  402. exp : exp '%' exp
  403. { write_exp_elt_opcode (BINOP_REM); }
  404. ;
  405. exp : exp '+' exp
  406. { write_exp_elt_opcode (BINOP_ADD); }
  407. ;
  408. exp : exp '-' exp
  409. { write_exp_elt_opcode (BINOP_SUB); }
  410. ;
  411. exp : exp LSH exp
  412. { write_exp_elt_opcode (BINOP_LSH); }
  413. ;
  414. exp : exp RSH exp
  415. { write_exp_elt_opcode (BINOP_RSH); }
  416. ;
  417. exp : exp EQUAL exp
  418. { write_exp_elt_opcode (BINOP_EQUAL); }
  419. ;
  420. exp : exp NOTEQUAL exp
  421. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  422. ;
  423. exp : exp LEQ exp
  424. { write_exp_elt_opcode (BINOP_LEQ); }
  425. ;
  426. exp : exp GEQ exp
  427. { write_exp_elt_opcode (BINOP_GEQ); }
  428. ;
  429. exp : exp '&lt;' exp
  430. { write_exp_elt_opcode (BINOP_LESS); }
  431. ;
  432. exp : exp '&gt;' exp
  433. { write_exp_elt_opcode (BINOP_GTR); }
  434. ;
  435. exp : exp '&amp;' exp
  436. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  437. ;
  438. exp : exp '^' exp
  439. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  440. ;
  441. exp : exp '|' exp
  442. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  443. ;
  444. exp : exp ANDAND exp
  445. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  446. ;
  447. exp : exp OROR exp
  448. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  449. ;
  450. exp : exp '?' exp ':' exp %prec '?'
  451. { write_exp_elt_opcode (TERNOP_COND); }
  452. ;
  453. exp : exp '=' exp
  454. { write_exp_elt_opcode (BINOP_ASSIGN); }
  455. ;
  456. exp : exp ASSIGN_MODIFY exp
  457. { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
  458. write_exp_elt_opcode ($2);
  459. write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
  460. ;
  461. exp : INT
  462. { write_exp_elt_opcode (OP_LONG);
  463. write_exp_elt_type ($1.type);
  464. write_exp_elt_longcst ((LONGEST)($1.val));
  465. write_exp_elt_opcode (OP_LONG); }
  466. ;
  467. exp : NAME_OR_INT
  468. { YYSTYPE val;
  469. parse_number ($1.stoken.ptr, $1.stoken.length, 0, &amp;val);
  470. write_exp_elt_opcode (OP_LONG);
  471. write_exp_elt_type (val.typed_val_int.type);
  472. write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
  473. write_exp_elt_opcode (OP_LONG);
  474. }
  475. ;
  476. exp : FLOAT
  477. { write_exp_elt_opcode (OP_DOUBLE);
  478. write_exp_elt_type ($1.type);
  479. write_exp_elt_dblcst ($1.dval);
  480. write_exp_elt_opcode (OP_DOUBLE); }
  481. ;
  482. exp : variable
  483. ;
  484. exp : VARIABLE
  485. /* Already written by write_dollar_variable. */
  486. ;
  487. exp : SELECTOR
  488. {
  489. write_exp_elt_opcode (OP_OBJC_SELECTOR);
  490. write_exp_string ($1);
  491. write_exp_elt_opcode (OP_OBJC_SELECTOR); }
  492. exp : SIZEOF '(' type ')' %prec UNARY
  493. { write_exp_elt_opcode (OP_LONG);
  494. write_exp_elt_type (builtin_type_int);
  495. CHECK_TYPEDEF ($3);
  496. write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
  497. write_exp_elt_opcode (OP_LONG); }
  498. ;
  499. exp : STRING
  500. { /* C strings are converted into array
  501. constants with an explicit null byte
  502. added at the end. Thus the array upper
  503. bound is the string length. There is no
  504. such thing in C as a completely empty
  505. string. */
  506. char *sp = $1.ptr; int count = $1.length;
  507. while (count-- &gt; 0)
  508. {
  509. write_exp_elt_opcode (OP_LONG);
  510. write_exp_elt_type (builtin_type_char);
  511. write_exp_elt_longcst ((LONGEST)(*sp++));
  512. write_exp_elt_opcode (OP_LONG);
  513. }
  514. write_exp_elt_opcode (OP_LONG);
  515. write_exp_elt_type (builtin_type_char);
  516. write_exp_elt_longcst ((LONGEST)'\0');
  517. write_exp_elt_opcode (OP_LONG);
  518. write_exp_elt_opcode (OP_ARRAY);
  519. write_exp_elt_longcst ((LONGEST) 0);
  520. write_exp_elt_longcst ((LONGEST) ($1.length));
  521. write_exp_elt_opcode (OP_ARRAY); }
  522. ;
  523. exp : NSSTRING /* ObjC NextStep NSString constant
  524. * of the form '@' '&quot;' string '&quot;'.
  525. */
  526. { write_exp_elt_opcode (OP_OBJC_NSSTRING);
  527. write_exp_string ($1);
  528. write_exp_elt_opcode (OP_OBJC_NSSTRING); }
  529. ;
  530. block : BLOCKNAME
  531. {
  532. if ($1.sym != 0)
  533. $$ = SYMBOL_BLOCK_VALUE ($1.sym);
  534. else
  535. {
  536. struct symtab *tem =
  537. lookup_symtab (copy_name ($1.stoken));
  538. if (tem)
  539. $$ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), STATIC_BLOCK);
  540. else
  541. error (&quot;No file or function \&quot;%s\&quot;.&quot;,
  542. copy_name ($1.stoken));
  543. }
  544. }
  545. ;
  546. block : block COLONCOLON name
  547. { struct symbol *tem
  548. = lookup_symbol (copy_name ($3), $1,
  549. VAR_NAMESPACE, (int *) NULL,
  550. (struct symtab **) NULL);
  551. if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  552. error (&quot;No function \&quot;%s\&quot; in specified context.&quot;,
  553. copy_name ($3));
  554. $$ = SYMBOL_BLOCK_VALUE (tem); }
  555. ;
  556. variable: block COLONCOLON name
  557. { struct symbol *sym;
  558. sym = lookup_symbol (copy_name ($3), $1,
  559. VAR_NAMESPACE, (int *) NULL,
  560. (struct symtab **) NULL);
  561. if (sym == 0)
  562. error (&quot;No symbol \&quot;%s\&quot; in specified context.&quot;,
  563. copy_name ($3));
  564. write_exp_elt_opcode (OP_VAR_VALUE);
  565. /* block_found is set by lookup_symbol. */
  566. write_exp_elt_block (block_found);
  567. write_exp_elt_sym (sym);
  568. write_exp_elt_opcode (OP_VAR_VALUE); }
  569. ;
  570. qualified_name: typebase COLONCOLON name
  571. {
  572. struct type *type = $1;
  573. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  574. &amp;&amp; TYPE_CODE (type) != TYPE_CODE_UNION)
  575. error (&quot;`%s' is not defined as an aggregate type.&quot;,
  576. TYPE_NAME (type));
  577. write_exp_elt_opcode (OP_SCOPE);
  578. write_exp_elt_type (type);
  579. write_exp_string ($3);
  580. write_exp_elt_opcode (OP_SCOPE);
  581. }
  582. | typebase COLONCOLON '~' name
  583. {
  584. struct type *type = $1;
  585. struct stoken tmp_token;
  586. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  587. &amp;&amp; TYPE_CODE (type) != TYPE_CODE_UNION)
  588. error (&quot;`%s' is not defined as an aggregate type.&quot;,
  589. TYPE_NAME (type));
  590. if (!STREQ (type_name_no_tag (type), $4.ptr))
  591. error (&quot;invalid destructor `%s::~%s'&quot;,
  592. type_name_no_tag (type), $4.ptr);
  593. tmp_token.ptr = (char*) alloca ($4.length + 2);
  594. tmp_token.length = $4.length + 1;
  595. tmp_token.ptr[0] = '~';
  596. memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
  597. tmp_token.ptr[tmp_token.length] = 0;
  598. write_exp_elt_opcode (OP_SCOPE);
  599. write_exp_elt_type (type);
  600. write_exp_string (tmp_token);
  601. write_exp_elt_opcode (OP_SCOPE);
  602. }
  603. ;
  604. variable: qualified_name
  605. | COLONCOLON name
  606. {
  607. char *name = copy_name ($2);
  608. struct symbol *sym;
  609. struct minimal_symbol *msymbol;
  610. sym =
  611. lookup_symbol (name, (const struct block *) NULL,
  612. VAR_NAMESPACE, (int *) NULL,
  613. (struct symtab **) NULL);
  614. if (sym)
  615. {
  616. write_exp_elt_opcode (OP_VAR_VALUE);
  617. write_exp_elt_block (NULL);
  618. write_exp_elt_sym (sym);
  619. write_exp_elt_opcode (OP_VAR_VALUE);
  620. break;
  621. }
  622. msymbol = lookup_minimal_symbol (name, NULL, NULL);
  623. if (msymbol != NULL)
  624. {
  625. write_exp_msymbol (msymbol,
  626. lookup_function_type (builtin_type_int),
  627. builtin_type_int);
  628. }
  629. else
  630. if (!have_full_symbols () &amp;&amp; !have_partial_symbols ())
  631. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  632. else
  633. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;, name);
  634. }
  635. ;
  636. variable: name_not_typename
  637. { struct symbol *sym = $1.sym;
  638. if (sym)
  639. {
  640. if (symbol_read_needs_frame (sym))
  641. {
  642. if (innermost_block == 0 ||
  643. contained_in (block_found,
  644. innermost_block))
  645. innermost_block = block_found;
  646. }
  647. write_exp_elt_opcode (OP_VAR_VALUE);
  648. /* We want to use the selected frame, not
  649. another more inner frame which happens to
  650. be in the same block. */
  651. write_exp_elt_block (NULL);
  652. write_exp_elt_sym (sym);
  653. write_exp_elt_opcode (OP_VAR_VALUE);
  654. }
  655. else if ($1.is_a_field_of_this)
  656. {
  657. /* C++/ObjC: it hangs off of `this'/'self'.
  658. Must not inadvertently convert from a
  659. method call to data ref. */
  660. if (innermost_block == 0 ||
  661. contained_in (block_found, innermost_block))
  662. innermost_block = block_found;
  663. write_exp_elt_opcode (OP_OBJC_SELF);
  664. write_exp_elt_opcode (OP_OBJC_SELF);
  665. write_exp_elt_opcode (STRUCTOP_PTR);
  666. write_exp_string ($1.stoken);
  667. write_exp_elt_opcode (STRUCTOP_PTR);
  668. }
  669. else
  670. {
  671. struct minimal_symbol *msymbol;
  672. register char *arg = copy_name ($1.stoken);
  673. msymbol =
  674. lookup_minimal_symbol (arg, NULL, NULL);
  675. if (msymbol != NULL)
  676. {
  677. write_exp_msymbol (msymbol,
  678. lookup_function_type (builtin_type_int),
  679. builtin_type_int);
  680. }
  681. else if (!have_full_symbols () &amp;&amp;
  682. !have_partial_symbols ())
  683. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  684. else
  685. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  686. copy_name ($1.stoken));
  687. }
  688. }
  689. ;
  690. ptype : typebase
  691. /* &quot;const&quot; and &quot;volatile&quot; are curently ignored. A type
  692. qualifier before the type is currently handled in the
  693. typebase rule. The reason for recognizing these here
  694. (shift/reduce conflicts) might be obsolete now that some
  695. pointer to member rules have been deleted. */
  696. | typebase CONST_KEYWORD
  697. | typebase VOLATILE_KEYWORD
  698. | typebase abs_decl
  699. { $$ = follow_types ($1); }
  700. | typebase CONST_KEYWORD abs_decl
  701. { $$ = follow_types ($1); }
  702. | typebase VOLATILE_KEYWORD abs_decl
  703. { $$ = follow_types ($1); }
  704. ;
  705. abs_decl: '*'
  706. { push_type (tp_pointer); $$ = 0; }
  707. | '*' abs_decl
  708. { push_type (tp_pointer); $$ = $2; }
  709. | '&amp;'
  710. { push_type (tp_reference); $$ = 0; }
  711. | '&amp;' abs_decl
  712. { push_type (tp_reference); $$ = $2; }
  713. | direct_abs_decl
  714. ;
  715. direct_abs_decl: '(' abs_decl ')'
  716. { $$ = $2; }
  717. | direct_abs_decl array_mod
  718. {
  719. push_type_int ($2);
  720. push_type (tp_array);
  721. }
  722. | array_mod
  723. {
  724. push_type_int ($1);
  725. push_type (tp_array);
  726. $$ = 0;
  727. }
  728. | direct_abs_decl func_mod
  729. { push_type (tp_function); }
  730. | func_mod
  731. { push_type (tp_function); }
  732. ;
  733. array_mod: '[' ']'
  734. { $$ = -1; }
  735. | '[' INT ']'
  736. { $$ = $2.val; }
  737. ;
  738. func_mod: '(' ')'
  739. { $$ = 0; }
  740. | '(' nonempty_typelist ')'
  741. { free ((PTR)$2); $$ = 0; }
  742. ;
  743. /* We used to try to recognize more pointer to member types here, but
  744. that didn't work (shift/reduce conflicts meant that these rules
  745. never got executed). The problem is that
  746. int (foo::bar::baz::bizzle)
  747. is a function type but
  748. int (foo::bar::baz::bizzle::*)
  749. is a pointer to member type. Stroustrup loses again! */
  750. type : ptype
  751. | typebase COLONCOLON '*'
  752. { $$ = lookup_member_type (builtin_type_int, $1); }
  753. ;
  754. typebase /* Implements (approximately): (type-qualifier)* type-specifier. */
  755. : TYPENAME
  756. { $$ = $1.type; }
  757. | CLASSNAME
  758. {
  759. if ($1.type == NULL)
  760. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  761. copy_name($1.stoken));
  762. else
  763. $$ = $1.type;
  764. }
  765. | INT_KEYWORD
  766. { $$ = builtin_type_int; }
  767. | LONG
  768. { $$ = builtin_type_long; }
  769. | SHORT
  770. { $$ = builtin_type_short; }
  771. | LONG INT_KEYWORD
  772. { $$ = builtin_type_long; }
  773. | UNSIGNED LONG INT_KEYWORD
  774. { $$ = builtin_type_unsigned_long; }
  775. | LONG LONG
  776. { $$ = builtin_type_long_long; }
  777. | LONG LONG INT_KEYWORD
  778. { $$ = builtin_type_long_long; }
  779. | UNSIGNED LONG LONG
  780. { $$ = builtin_type_unsigned_long_long; }
  781. | UNSIGNED LONG LONG INT_KEYWORD
  782. { $$ = builtin_type_unsigned_long_long; }
  783. | SHORT INT_KEYWORD
  784. { $$ = builtin_type_short; }
  785. | UNSIGNED SHORT INT_KEYWORD
  786. { $$ = builtin_type_unsigned_short; }
  787. | DOUBLE_KEYWORD
  788. { $$ = builtin_type_double; }
  789. | LONG DOUBLE_KEYWORD
  790. { $$ = builtin_type_long_double; }
  791. | STRUCT name
  792. { $$ = lookup_struct (copy_name ($2),
  793. expression_context_block); }
  794. | CLASS name
  795. { $$ = lookup_struct (copy_name ($2),
  796. expression_context_block); }
  797. | UNION name
  798. { $$ = lookup_union (copy_name ($2),
  799. expression_context_block); }
  800. | ENUM name
  801. { $$ = lookup_enum (copy_name ($2),
  802. expression_context_block); }
  803. | UNSIGNED typename
  804. { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
  805. | UNSIGNED
  806. { $$ = builtin_type_unsigned_int; }
  807. | SIGNED_KEYWORD typename
  808. { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
  809. | SIGNED_KEYWORD
  810. { $$ = builtin_type_int; }
  811. | TEMPLATE name '&lt;' type '&gt;'
  812. { $$ = lookup_template_type(copy_name($2), $4,
  813. expression_context_block);
  814. }
  815. /* &quot;const&quot; and &quot;volatile&quot; are curently ignored. A type
  816. qualifier after the type is handled in the ptype rule. I
  817. think these could be too. */
  818. | CONST_KEYWORD typebase { $$ = $2; }
  819. | VOLATILE_KEYWORD typebase { $$ = $2; }
  820. ;
  821. typename: TYPENAME
  822. | INT_KEYWORD
  823. {
  824. $$.stoken.ptr = &quot;int&quot;;
  825. $$.stoken.length = 3;
  826. $$.type = builtin_type_int;
  827. }
  828. | LONG
  829. {
  830. $$.stoken.ptr = &quot;long&quot;;
  831. $$.stoken.length = 4;
  832. $$.type = builtin_type_long;
  833. }
  834. | SHORT
  835. {
  836. $$.stoken.ptr = &quot;short&quot;;
  837. $$.stoken.length = 5;
  838. $$.type = builtin_type_short;
  839. }
  840. ;
  841. nonempty_typelist
  842. : type
  843. { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
  844. $&lt;ivec&gt;$[0] = 1; /* Number of types in vector. */
  845. $$[1] = $1;
  846. }
  847. | nonempty_typelist ',' type
  848. { int len = sizeof (struct type *) * (++($&lt;ivec&gt;1[0]) + 1);
  849. $$ = (struct type **) realloc ((char *) $1, len);
  850. $$[$&lt;ivec&gt;$[0]] = $3;
  851. }
  852. ;
  853. name : NAME { $$ = $1.stoken; }
  854. | BLOCKNAME { $$ = $1.stoken; }
  855. | TYPENAME { $$ = $1.stoken; }
  856. | CLASSNAME { $$ = $1.stoken; }
  857. | NAME_OR_INT { $$ = $1.stoken; }
  858. ;
  859. name_not_typename : NAME
  860. | BLOCKNAME
  861. /* These would be useful if name_not_typename was useful, but it is
  862. just a fake for &quot;variable&quot;, so these cause reduce/reduce conflicts
  863. because the parser can't tell whether NAME_OR_INT is a
  864. name_not_typename (=variable, =exp) or just an exp. If
  865. name_not_typename was ever used in an lvalue context where only a
  866. name could occur, this might be useful. */
  867. /* | NAME_OR_INT */
  868. ;
  869. %%
  870. /* Take care of parsing a number (anything that starts with a digit).
  871. Set yylval and return the token type; update lexptr. LEN is the
  872. number of characters in it. */
  873. /*** Needs some error checking for the float case. ***/
  874. static int
  875. parse_number (p, len, parsed_float, putithere)
  876. register char *p;
  877. register int len;
  878. int parsed_float;
  879. YYSTYPE *putithere;
  880. {
  881. /* FIXME: Shouldn't these be unsigned? We don't deal with negative
  882. values here, and we do kind of silly things like cast to
  883. unsigned. */
  884. register LONGEST n = 0;
  885. register LONGEST prevn = 0;
  886. unsigned LONGEST un;
  887. register int i = 0;
  888. register int c;
  889. register int base = input_radix;
  890. int unsigned_p = 0;
  891. /* Number of &quot;L&quot; suffixes encountered. */
  892. int long_p = 0;
  893. /* We have found a &quot;L&quot; or &quot;U&quot; suffix. */
  894. int found_suffix = 0;
  895. unsigned LONGEST high_bit;
  896. struct type *signed_type;
  897. struct type *unsigned_type;
  898. if (parsed_float)
  899. {
  900. char c;
  901. /* It's a float since it contains a point or an exponent. */
  902. if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (float))
  903. sscanf (p, &quot;%g&quot;, (float *)&amp;putithere-&gt;typed_val_float.dval);
  904. else if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (double))
  905. sscanf (p, &quot;%lg&quot;, (double *)&amp;putithere-&gt;typed_val_float.dval);
  906. else
  907. {
  908. #ifdef PRINTF_HAS_LONG_DOUBLE
  909. sscanf (p, &quot;%Lg&quot;, &amp;putithere-&gt;typed_val_float.dval);
  910. #else
  911. /* Scan it into a double, then assign it to the long double.
  912. This at least wins with values representable in the range
  913. of doubles. */
  914. double temp;
  915. sscanf (p, &quot;%lg&quot;, &amp;temp);
  916. putithere-&gt;typed_val_float.dval = temp;
  917. #endif
  918. }
  919. /* See if it has `f' or `l' suffix (float or long double). */
  920. c = tolower (p[len - 1]);
  921. if (c == 'f')
  922. putithere-&gt;typed_val_float.type = builtin_type_float;
  923. else if (c == 'l')
  924. putithere-&gt;typed_val_float.type = builtin_type_long_double;
  925. else if (isdigit (c) || c == '.')
  926. putithere-&gt;typed_val_float.type = builtin_type_double;
  927. else
  928. return ERROR;
  929. return FLOAT;
  930. }
  931. /* Handle base-switching prefixes 0x, 0t, 0d, and 0. */
  932. if (p[0] == '0')
  933. switch (p[1])
  934. {
  935. case 'x':
  936. case 'X':
  937. if (len &gt;= 3)
  938. {
  939. p += 2;
  940. base = 16;
  941. len -= 2;
  942. }
  943. break;
  944. case 't':
  945. case 'T':
  946. case 'd':
  947. case 'D':
  948. if (len &gt;= 3)
  949. {
  950. p += 2;
  951. base = 10;
  952. len -= 2;
  953. }
  954. break;
  955. default:
  956. base = 8;
  957. break;
  958. }
  959. while (len-- &gt; 0)
  960. {
  961. c = *p++;
  962. if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')
  963. c += 'a' - 'A';
  964. if (c != 'l' &amp;&amp; c != 'u')
  965. n *= base;
  966. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  967. {
  968. if (found_suffix)
  969. return ERROR;
  970. n += i = c - '0';
  971. }
  972. else
  973. {
  974. if (base &gt; 10 &amp;&amp; c &gt;= 'a' &amp;&amp; c &lt;= 'f')
  975. {
  976. if (found_suffix)
  977. return ERROR;
  978. n += i = c - 'a' + 10;
  979. }
  980. else if (c == 'l')
  981. {
  982. ++long_p;
  983. found_suffix = 1;
  984. }
  985. else if (c == 'u')
  986. {
  987. unsigned_p = 1;
  988. found_suffix = 1;
  989. }
  990. else
  991. return ERROR; /* Char not a digit. */
  992. }
  993. if (i &gt;= base)
  994. return ERROR; /* Invalid digit in this base. */
  995. /* Portably test for overflow (only works for nonzero values, so
  996. make a second check for zero). FIXME: Can't we just make n
  997. and prevn unsigned and avoid this? */
  998. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; (prevn &gt;= n) &amp;&amp; n != 0)
  999. unsigned_p = 1; /* Try something unsigned. */
  1000. /* Portably test for unsigned overflow.
  1001. FIXME: This check is wrong; for example it doesn't find
  1002. overflow on 0x123456789 when LONGEST is 32 bits. */
  1003. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; n != 0)
  1004. {
  1005. if ((unsigned_p &amp;&amp; (unsigned LONGEST) prevn &gt;= (unsigned LONGEST) n))
  1006. error (&quot;Numeric constant too large.&quot;);
  1007. }
  1008. prevn = n;
  1009. }
  1010. /* An integer constant is an int, a long, or a long long. An L
  1011. suffix forces it to be long; an LL suffix forces it to be long
  1012. long. If not forced to a larger size, it gets the first type of
  1013. the above that it fits in. To figure out whether it fits, we
  1014. shift it right and see whether anything remains. Note that we
  1015. can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  1016. operation, because many compilers will warn about such a shift
  1017. (which always produces a zero result). Sometimes TARGET_INT_BIT
  1018. or TARGET_LONG_BIT will be that big, sometimes not. To deal with
  1019. the case where it is we just always shift the value more than
  1020. once, with fewer bits each time. */
  1021. un = (unsigned LONGEST)n &gt;&gt; 2;
  1022. if (long_p == 0
  1023. &amp;&amp; (un &gt;&gt; (TARGET_INT_BIT - 2)) == 0)
  1024. {
  1025. high_bit = ((unsigned LONGEST)1) &lt;&lt; (TARGET_INT_BIT-1);
  1026. /* A large decimal (not hex or octal) constant (between INT_MAX
  1027. and UINT_MAX) is a long or unsigned long, according to ANSI,
  1028. never an unsigned int, but this code treats it as unsigned
  1029. int. This probably should be fixed. GCC gives a warning on
  1030. such constants. */
  1031. unsigned_type = builtin_type_unsigned_int;
  1032. signed_type = builtin_type_int;
  1033. }
  1034. else if (long_p &lt;= 1
  1035. &amp;&amp; (un &gt;&gt; (TARGET_LONG_BIT - 2)) == 0)
  1036. {
  1037. high_bit = ((unsigned LONGEST)1) &lt;&lt; (TARGET_LONG_BIT-1);
  1038. unsigned_type = builtin_type_unsigned_long;
  1039. signed_type = builtin_type_long;
  1040. }
  1041. else
  1042. {
  1043. high_bit = (((unsigned LONGEST)1)
  1044. &lt;&lt; (TARGET_LONG_LONG_BIT - 32 - 1)
  1045. &lt;&lt; 16
  1046. &lt;&lt; 16);
  1047. if (high_bit == 0)
  1048. /* A long long does not fit in a LONGEST. */
  1049. high_bit =
  1050. (unsigned LONGEST)1 &lt;&lt; (sizeof (LONGEST) * HOST_CHAR_BIT - 1);
  1051. unsigned_type = builtin_type_unsigned_long_long;
  1052. signed_type = builtin_type_long_long;
  1053. }
  1054. putithere-&gt;typed_val_int.val = n;
  1055. /* If the high bit of the worked out type is set then this number
  1056. has to be unsigned. */
  1057. if (unsigned_p || (n &amp; high_bit))
  1058. {
  1059. putithere-&gt;typed_val_int.type = unsigned_type;
  1060. }
  1061. else
  1062. {
  1063. putithere-&gt;typed_val_int.type = signed_type;
  1064. }
  1065. return INT;
  1066. }
  1067. struct token
  1068. {
  1069. char *operator;
  1070. int token;
  1071. enum exp_opcode opcode;
  1072. };
  1073. static const struct token tokentab3[] =
  1074. {
  1075. {&quot;&gt;&gt;=&quot;, ASSIGN_MODIFY, BINOP_RSH},
  1076. {&quot;&lt;&lt;=&quot;, ASSIGN_MODIFY, BINOP_LSH}
  1077. };
  1078. static const struct token tokentab2[] =
  1079. {
  1080. {&quot;+=&quot;, ASSIGN_MODIFY, BINOP_ADD},
  1081. {&quot;-=&quot;, ASSIGN_MODIFY, BINOP_SUB},
  1082. {&quot;*=&quot;, ASSIGN_MODIFY, BINOP_MUL},
  1083. {&quot;/=&quot;, ASSIGN_MODIFY, BINOP_DIV},
  1084. {&quot;%=&quot;, ASSIGN_MODIFY, BINOP_REM},
  1085. {&quot;|=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_IOR},
  1086. {&quot;&amp;=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_AND},
  1087. {&quot;^=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_XOR},
  1088. {&quot;++&quot;, INCREMENT, BINOP_END},
  1089. {&quot;--&quot;, DECREMENT, BINOP_END},
  1090. {&quot;-&gt;&quot;, ARROW, BINOP_END},
  1091. {&quot;&amp;&amp;&quot;, ANDAND, BINOP_END},
  1092. {&quot;||&quot;, OROR, BINOP_END},
  1093. {&quot;::&quot;, COLONCOLON, BINOP_END},
  1094. {&quot;&lt;&lt;&quot;, LSH, BINOP_END},
  1095. {&quot;&gt;&gt;&quot;, RSH, BINOP_END},
  1096. {&quot;==&quot;, EQUAL, BINOP_END},
  1097. {&quot;!=&quot;, NOTEQUAL, BINOP_END},
  1098. {&quot;&lt;=&quot;, LEQ, BINOP_END},
  1099. {&quot;&gt;=&quot;, GEQ, BINOP_END}
  1100. };
  1101. /* Read one token, getting characters through lexptr. */
  1102. static int
  1103. yylex ()
  1104. {
  1105. int c, tokchr;
  1106. int namelen;
  1107. unsigned int i;
  1108. char *tokstart;
  1109. char *tokptr;
  1110. int tempbufindex;
  1111. static char *tempbuf;
  1112. static int tempbufsize;
  1113. retry:
  1114. tokstart = lexptr;
  1115. /* See if it is a special token of length 3. */
  1116. for (i = 0; i &lt; sizeof tokentab3 / sizeof tokentab3[0]; i++)
  1117. if (STREQN (tokstart, tokentab3[i].operator, 3))
  1118. {
  1119. lexptr += 3;
  1120. yylval.opcode = tokentab3[i].opcode;
  1121. return tokentab3[i].token;
  1122. }
  1123. /* See if it is a special token of length 2. */
  1124. for (i = 0; i &lt; sizeof tokentab2 / sizeof tokentab2[0]; i++)
  1125. if (STREQN (tokstart, tokentab2[i].operator, 2))
  1126. {
  1127. lexptr += 2;
  1128. yylval.opcode = tokentab2[i].opcode;
  1129. return tokentab2[i].token;
  1130. }
  1131. c = 0;
  1132. switch (tokchr = *tokstart)
  1133. {
  1134. case 0:
  1135. return 0;
  1136. case ' ':
  1137. case '\t':
  1138. case '\n':
  1139. lexptr++;
  1140. goto retry;
  1141. case '\'':
  1142. /* We either have a character constant ('0' or '\177' for
  1143. example) or we have a quoted symbol reference ('foo(int,int)'
  1144. in C++ for example). */
  1145. lexptr++;
  1146. c = *lexptr++;
  1147. if (c == '\\')
  1148. c = parse_escape (&amp;lexptr);
  1149. else if (c == '\'')
  1150. error (&quot;Empty character constant.&quot;);
  1151. yylval.typed_val_int.val = c;
  1152. yylval.typed_val_int.type = builtin_type_char;
  1153. c = *lexptr++;
  1154. if (c != '\'')
  1155. {
  1156. namelen = skip_quoted (tokstart) - tokstart;
  1157. if (namelen &gt; 2)
  1158. {
  1159. lexptr = tokstart + namelen;
  1160. if (lexptr[-1] != '\'')
  1161. error (&quot;Unmatched single quote.&quot;);
  1162. namelen -= 2;
  1163. tokstart++;
  1164. goto tryname;
  1165. }
  1166. error (&quot;Invalid character constant.&quot;);
  1167. }
  1168. return INT;
  1169. case '(':
  1170. paren_depth++;
  1171. lexptr++;
  1172. return '(';
  1173. case ')':
  1174. if (paren_depth == 0)
  1175. return 0;
  1176. paren_depth--;
  1177. lexptr++;
  1178. return ')';
  1179. case ',':
  1180. if (comma_terminates &amp;&amp; paren_depth == 0)
  1181. return 0;
  1182. lexptr++;
  1183. return ',';
  1184. case '.':
  1185. /* Might be a floating point number. */
  1186. if (lexptr[1] &lt; '0' || lexptr[1] &gt; '9')
  1187. goto symbol; /* Nope, must be a symbol. */
  1188. /* FALL THRU into number case. */
  1189. case '0':
  1190. case '1':
  1191. case '2':
  1192. case '3':
  1193. case '4':
  1194. case '5':
  1195. case '6':
  1196. case '7':
  1197. case '8':
  1198. case '9':
  1199. {
  1200. /* It's a number. */
  1201. int got_dot = 0, got_e = 0, toktype = FLOAT;
  1202. /* Initialize toktype to anything other than ERROR. */
  1203. register char *p = tokstart;
  1204. int hex = input_radix &gt; 10;
  1205. int local_radix = input_radix;
  1206. if (tokchr == '0' &amp;&amp; (p[1] == 'x' || p[1] == 'X'))
  1207. {
  1208. p += 2;
  1209. hex = 1;
  1210. local_radix = 16;
  1211. }
  1212. else if (tokchr == '0' &amp;&amp; (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  1213. {
  1214. p += 2;
  1215. hex = 0;
  1216. local_radix = 10;
  1217. }
  1218. for (;; ++p)
  1219. {
  1220. /* This test includes !hex because 'e' is a valid hex digit
  1221. and thus does not indicate a floating point number when
  1222. the radix is hex. */
  1223. if (!hex &amp;&amp; (*p == 'e' || *p == 'E'))
  1224. if (got_e)
  1225. toktype = ERROR; /* Only one 'e' in a float. */
  1226. else
  1227. got_e = 1;
  1228. /* This test does not include !hex, because a '.' always
  1229. indicates a decimal floating point number regardless of
  1230. the radix. */
  1231. else if (*p == '.')
  1232. if (got_dot)
  1233. toktype = ERROR; /* Only one '.' in a float. */
  1234. else
  1235. got_dot = 1;
  1236. else if (got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E') &amp;&amp;
  1237. (*p == '-' || *p == '+'))
  1238. /* This is the sign of the exponent, not the end of the
  1239. number. */
  1240. continue;
  1241. /* Always take decimal digits; parse_number handles radix
  1242. error. */
  1243. else if (*p &gt;= '0' &amp;&amp; *p &lt;= '9')
  1244. continue;
  1245. /* We will take letters only if hex is true, and only up
  1246. to what the input radix would permit. FSF was content
  1247. to rely on parse_number to validate; but it leaks. */
  1248. else if (*p &gt;= 'a' &amp;&amp; *p &lt;= 'z')
  1249. {
  1250. if (!hex || *p &gt;= ('a' + local_radix - 10))
  1251. toktype = ERROR;
  1252. }
  1253. else if (*p &gt;= 'A' &amp;&amp; *p &lt;= 'Z')
  1254. {
  1255. if (!hex || *p &gt;= ('A' + local_radix - 10))
  1256. toktype = ERROR;
  1257. }
  1258. else break;
  1259. }
  1260. if (toktype != ERROR)
  1261. toktype = parse_number (tokstart, p - tokstart,
  1262. got_dot | got_e, &amp;yylval);
  1263. if (toktype == ERROR)
  1264. {
  1265. char *err_copy = (char *) alloca (p - tokstart + 1);
  1266. memcpy (err_copy, tokstart, p - tokstart);
  1267. err_copy[p - tokstart] = 0;
  1268. error (&quot;Invalid number \&quot;%s\&quot;.&quot;, err_copy);
  1269. }
  1270. lexptr = p;
  1271. return toktype;
  1272. }
  1273. case '+':
  1274. case '-':
  1275. case '*':
  1276. case '/':
  1277. case '%':
  1278. case '|':
  1279. case '&amp;':
  1280. case '^':
  1281. case '~':
  1282. case '!':
  1283. #if 0
  1284. case '@': /* Moved out below. */
  1285. #endif
  1286. case '&lt;':
  1287. case '&gt;':
  1288. case '[':
  1289. case ']':
  1290. case '?':
  1291. case ':':
  1292. case '=':
  1293. case '{':
  1294. case '}':
  1295. symbol:
  1296. lexptr++;
  1297. return tokchr;
  1298. case '@':
  1299. if (strncmp(tokstart, &quot;@selector&quot;, 9) == 0)
  1300. {
  1301. tokptr = strchr(tokstart, '(');
  1302. if (tokptr == NULL)
  1303. {
  1304. error (&quot;Missing '(' in @selector(...)&quot;);
  1305. }
  1306. tempbufindex = 0;
  1307. tokptr++; /* Skip the '('. */
  1308. do {
  1309. /* Grow the static temp buffer if necessary, including
  1310. allocating the first one on demand. */
  1311. if (tempbufindex + 1 &gt;= tempbufsize)
  1312. {
  1313. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1314. }
  1315. tempbuf[tempbufindex++] = *tokptr++;
  1316. } while ((*tokptr != ')') &amp;&amp; (*tokptr != '\0'));
  1317. if (*tokptr++ != ')')
  1318. {
  1319. error (&quot;Missing ')' in @selector(...)&quot;);
  1320. }
  1321. tempbuf[tempbufindex] = '\0';
  1322. yylval.sval.ptr = tempbuf;
  1323. yylval.sval.length = tempbufindex;
  1324. lexptr = tokptr;
  1325. return SELECTOR;
  1326. }
  1327. if (tokstart[1] != '&quot;')
  1328. {
  1329. lexptr++;
  1330. return tokchr;
  1331. }
  1332. /* ObjC NextStep NSString constant: fall thru and parse like
  1333. STRING. */
  1334. tokstart++;
  1335. case '&quot;':
  1336. /* Build the gdb internal form of the input string in tempbuf,
  1337. translating any standard C escape forms seen. Note that the
  1338. buffer is null byte terminated *only* for the convenience of
  1339. debugging gdb itself and printing the buffer contents when
  1340. the buffer contains no embedded nulls. Gdb does not depend
  1341. upon the buffer being null byte terminated, it uses the
  1342. length string instead. This allows gdb to handle C strings
  1343. (as well as strings in other languages) with embedded null
  1344. bytes. */
  1345. tokptr = ++tokstart;
  1346. tempbufindex = 0;
  1347. do {
  1348. /* Grow the static temp buffer if necessary, including
  1349. allocating the first one on demand. */
  1350. if (tempbufindex + 1 &gt;= tempbufsize)
  1351. {
  1352. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1353. }
  1354. switch (*tokptr)
  1355. {
  1356. case '\0':
  1357. case '&quot;':
  1358. /* Do nothing, loop will terminate. */
  1359. break;
  1360. case '\\':
  1361. tokptr++;
  1362. c = parse_escape (&amp;tokptr);
  1363. if (c == -1)
  1364. {
  1365. continue;
  1366. }
  1367. tempbuf[tempbufindex++] = c;
  1368. break;
  1369. default:
  1370. tempbuf[tempbufindex++] = *tokptr++;
  1371. break;
  1372. }
  1373. } while ((*tokptr != '&quot;') &amp;&amp; (*tokptr != '\0'));
  1374. if (*tokptr++ != '&quot;')
  1375. {
  1376. error (&quot;Unterminated string in expression.&quot;);
  1377. }
  1378. tempbuf[tempbufindex] = '\0'; /* See note above. */
  1379. yylval.sval.ptr = tempbuf;
  1380. yylval.sval.length = tempbufindex;
  1381. lexptr = tokptr;
  1382. return (tokchr == '@' ? NSSTRING : STRING);
  1383. }
  1384. if (!(tokchr == '_' || tokchr == '$' ||
  1385. (tokchr &gt;= 'a' &amp;&amp; tokchr &lt;= 'z') || (tokchr &gt;= 'A' &amp;&amp; tokchr &lt;= 'Z')))
  1386. /* We must have come across a bad character (e.g. ';'). */
  1387. error (&quot;Invalid character '%c' in expression.&quot;, c);
  1388. /* It's a name. See how long it is. */
  1389. namelen = 0;
  1390. for (c = tokstart[namelen];
  1391. (c == '_' || c == '$' || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1392. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || c == '&lt;');)
  1393. {
  1394. if (c == '&lt;')
  1395. {
  1396. int i = namelen;
  1397. while (tokstart[++i] &amp;&amp; tokstart[i] != '&gt;');
  1398. if (tokstart[i] == '&gt;')
  1399. namelen = i;
  1400. }
  1401. c = tokstart[++namelen];
  1402. }
  1403. /* The token &quot;if&quot; terminates the expression and is NOT
  1404. removed from the input stream. */
  1405. if (namelen == 2 &amp;&amp; tokstart[0] == 'i' &amp;&amp; tokstart[1] == 'f')
  1406. {
  1407. return 0;
  1408. }
  1409. lexptr += namelen;
  1410. tryname:
  1411. /* Catch specific keywords. Should be done with a data structure. */
  1412. switch (namelen)
  1413. {
  1414. case 8:
  1415. if (STREQN (tokstart, &quot;unsigned&quot;, 8))
  1416. return UNSIGNED;
  1417. if (current_language-&gt;la_language == language_cplus
  1418. &amp;&amp; STREQN (tokstart, &quot;template&quot;, 8))
  1419. return TEMPLATE;
  1420. if (STREQN (tokstart, &quot;volatile&quot;, 8))
  1421. return VOLATILE_KEYWORD;
  1422. break;
  1423. case 6:
  1424. if (STREQN (tokstart, &quot;struct&quot;, 6))
  1425. return STRUCT;
  1426. if (STREQN (tokstart, &quot;signed&quot;, 6))
  1427. return SIGNED_KEYWORD;
  1428. if (STREQN (tokstart, &quot;sizeof&quot;, 6))
  1429. return SIZEOF;
  1430. if (STREQN (tokstart, &quot;double&quot;, 6))
  1431. return DOUBLE_KEYWORD;
  1432. break;
  1433. case 5:
  1434. if ((current_language-&gt;la_language == language_cplus)
  1435. &amp;&amp; STREQN (tokstart, &quot;class&quot;, 5))
  1436. return CLASS;
  1437. if (STREQN (tokstart, &quot;union&quot;, 5))
  1438. return UNION;
  1439. if (STREQN (tokstart, &quot;short&quot;, 5))
  1440. return SHORT;
  1441. if (STREQN (tokstart, &quot;const&quot;, 5))
  1442. return CONST_KEYWORD;
  1443. break;
  1444. case 4:
  1445. if (STREQN (tokstart, &quot;enum&quot;, 4))
  1446. return ENUM;
  1447. if (STREQN (tokstart, &quot;long&quot;, 4))
  1448. return LONG;
  1449. break;
  1450. case 3:
  1451. if (STREQN (tokstart, &quot;int&quot;, 3))
  1452. return INT_KEYWORD;
  1453. break;
  1454. default:
  1455. break;
  1456. }
  1457. yylval.sval.ptr = tokstart;
  1458. yylval.sval.length = namelen;
  1459. if (*tokstart == '$')
  1460. {
  1461. write_dollar_variable (yylval.sval);
  1462. return VARIABLE;
  1463. }
  1464. /* Use token-type BLOCKNAME for symbols that happen to be defined as
  1465. functions or symtabs. If this is not so, then ...
  1466. Use token-type TYPENAME for symbols that happen to be defined
  1467. currently as names of types; NAME for other symbols.
  1468. The caller is not constrained to care about the distinction. */
  1469. {
  1470. char *tmp = copy_name (yylval.sval);
  1471. struct symbol *sym;
  1472. int is_a_field_of_this = 0, *need_this;
  1473. int hextype;
  1474. if (current_language-&gt;la_language == language_cplus ||
  1475. current_language-&gt;la_language == language_objc)
  1476. need_this = &amp;is_a_field_of_this;
  1477. else
  1478. need_this = (int *) NULL;
  1479. sym = lookup_symbol (tmp, expression_context_block,
  1480. VAR_NAMESPACE,
  1481. need_this,
  1482. (struct symtab **) NULL);
  1483. /* Call lookup_symtab, not lookup_partial_symtab, in case there
  1484. are no psymtabs (coff, xcoff, or some future change to blow
  1485. away the psymtabs once symbols are read). */
  1486. if ((sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_BLOCK) ||
  1487. lookup_symtab (tmp))
  1488. {
  1489. yylval.ssym.sym = sym;
  1490. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1491. return BLOCKNAME;
  1492. }
  1493. if (sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  1494. {
  1495. #if 1
  1496. /* Despite the following flaw, we need to keep this code
  1497. enabled. Because we can get called from
  1498. check_stub_method, if we don't handle nested types then
  1499. it screws many operations in any program which uses
  1500. nested types. */
  1501. /* In &quot;A::x&quot;, if x is a member function of A and there
  1502. happens to be a type (nested or not, since the stabs
  1503. don't make that distinction) named x, then this code
  1504. incorrectly thinks we are dealing with nested types
  1505. rather than a member function. */
  1506. char *p;
  1507. char *namestart;
  1508. struct symbol *best_sym;
  1509. /* Look ahead to detect nested types. This probably should
  1510. be done in the grammar, but trying seemed to introduce a
  1511. lot of shift/reduce and reduce/reduce conflicts. It's
  1512. possible that it could be done, though. Or perhaps a
  1513. non-grammar, but less ad hoc, approach would work well. */
  1514. /* Since we do not currently have any way of distinguishing
  1515. a nested type from a non-nested one (the stabs don't tell
  1516. us whether a type is nested), we just ignore the
  1517. containing type. */
  1518. p = lexptr;
  1519. best_sym = sym;
  1520. while (1)
  1521. {
  1522. /* Skip whitespace. */
  1523. while (*p == ' ' || *p == '\t' || *p == '\n')
  1524. ++p;
  1525. if (*p == ':' &amp;&amp; p[1] == ':')
  1526. {
  1527. /* Skip the `::'. */
  1528. p += 2;
  1529. /* Skip whitespace. */
  1530. while (*p == ' ' || *p == '\t' || *p == '\n')
  1531. ++p;
  1532. namestart = p;
  1533. while (*p == '_' || *p == '$' || (*p &gt;= '0' &amp;&amp; *p &lt;= '9')
  1534. || (*p &gt;= 'a' &amp;&amp; *p &lt;= 'z')
  1535. || (*p &gt;= 'A' &amp;&amp; *p &lt;= 'Z'))
  1536. ++p;
  1537. if (p != namestart)
  1538. {
  1539. struct symbol *cur_sym;
  1540. /* As big as the whole rest of the expression,
  1541. which is at least big enough. */
  1542. char *ncopy = alloca (strlen (tmp) +
  1543. strlen (namestart) + 3);
  1544. char *tmp1;
  1545. tmp1 = ncopy;
  1546. memcpy (tmp1, tmp, strlen (tmp));
  1547. tmp1 += strlen (tmp);
  1548. memcpy (tmp1, &quot;::&quot;, 2);
  1549. tmp1 += 2;
  1550. memcpy (tmp1, namestart, p - namestart);
  1551. tmp1[p - namestart] = '\0';
  1552. cur_sym = lookup_symbol (ncopy,
  1553. expression_context_block,
  1554. VAR_NAMESPACE, (int *) NULL,
  1555. (struct symtab **) NULL);
  1556. if (cur_sym)
  1557. {
  1558. if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
  1559. {
  1560. best_sym = cur_sym;
  1561. lexptr = p;
  1562. }
  1563. else
  1564. break;
  1565. }
  1566. else
  1567. break;
  1568. }
  1569. else
  1570. break;
  1571. }
  1572. else
  1573. break;
  1574. }
  1575. yylval.tsym.type = SYMBOL_TYPE (best_sym);
  1576. #else /* not 0 */
  1577. yylval.tsym.type = SYMBOL_TYPE (sym);
  1578. #endif /* not 0 */
  1579. return TYPENAME;
  1580. }
  1581. if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
  1582. return TYPENAME;
  1583. /* See if it's an ObjC classname. */
  1584. if (!sym)
  1585. {
  1586. CORE_ADDR Class = lookup_objc_class(tmp);
  1587. if (Class)
  1588. {
  1589. extern struct symbol *lookup_struct_typedef();
  1590. yylval.class.class = Class;
  1591. if ((sym = lookup_struct_typedef (tmp,
  1592. expression_context_block,
  1593. 1)))
  1594. yylval.class.type = SYMBOL_TYPE (sym);
  1595. return CLASSNAME;
  1596. }
  1597. }
  1598. /* Input names that aren't symbols but ARE valid hex numbers,
  1599. when the input radix permits them, can be names or numbers
  1600. depending on the parse. Note we support radixes &gt; 16 here. */
  1601. if (!sym &amp;&amp;
  1602. ((tokstart[0] &gt;= 'a' &amp;&amp; tokstart[0] &lt; 'a' + input_radix - 10) ||
  1603. (tokstart[0] &gt;= 'A' &amp;&amp; tokstart[0] &lt; 'A' + input_radix - 10)))
  1604. {
  1605. YYSTYPE newlval; /* Its value is…

Large files files are truncated, but you can click here to view the full file