PageRenderTime 75ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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