PageRenderTime 83ms CodeModel.GetById 42ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Happy | 1845 lines | 1632 code | 213 blank | 0 comment | 0 complexity | 48ba71bb0f474cbc2158fb5d73359c8d 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 (C) 1986, 1989, 1990, 1991, 1993, 1994
  25. Free Software Foundation, Inc.
  26. This file is part of GDB.
  27. This program is free software; you can redistribute it and/or modify
  28. it under the terms of the GNU General Public License as published by
  29. the Free Software Foundation; either version 2 of the License, or
  30. (at your option) any later version.
  31. This program is distributed in the hope that it will be useful,
  32. but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. GNU General Public License for more details.
  35. You should have received a copy of the GNU General Public License
  36. along with this program; if not, write to the Free Software
  37. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  38. /* Parse a C expression from text in a string,
  39. and return the result as a struct expression pointer.
  40. That structure contains arithmetic operations in reverse polish,
  41. with constants represented by operations that are followed by special data.
  42. See expression.h for the details of the format.
  43. What is important here is that it can be built up sequentially
  44. during the process of parsing; the lower levels of the tree always
  45. come first in the result.
  46. Note that malloc's and realloc's in this file are transformed to
  47. xmalloc and xrealloc respectively by the same sed command in the
  48. makefile that remaps any other malloc/realloc inserted by the parser
  49. generator. Doing this with #defines and trying to control the interaction
  50. with include files (&lt;malloc.h&gt; and &lt;stdlib.h&gt; for example) just became
  51. too messy, particularly when such includes can be inserted at random
  52. times by the parser generator. */
  53. %{
  54. #include &quot;defs.h&quot;
  55. #include &quot;gdb_string.h&quot;
  56. #include &lt;ctype.h&gt;
  57. #include &quot;expression.h&quot;
  58. #include &quot;objc-lang.h&quot; /* for objc language constructs */
  59. #include &quot;value.h&quot;
  60. #include &quot;parser-defs.h&quot;
  61. #include &quot;language.h&quot;
  62. #include &quot;c-lang.h&quot;
  63. #include &quot;bfd.h&quot; /* Required by objfiles.h. */
  64. #include &quot;symfile.h&quot; /* Required by objfiles.h. */
  65. #include &quot;objfiles.h&quot; /* For have_full_symbols and have_partial_symbols */
  66. #include &quot;top.h&quot;
  67. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  68. as well as gratuitiously global symbol names, so we can have multiple
  69. yacc generated parsers in gdb. Note that these are only the variables
  70. produced by yacc. If other parser generators (bison, byacc, etc) produce
  71. additional global names that conflict at link time, then those parser
  72. generators need to be fixed instead of adding those names to this list. */
  73. #define yymaxdepth objc_maxdepth
  74. #define yyparse objc_parse
  75. #define yylex objc_lex
  76. #define yyerror objc_error
  77. #define yylval objc_lval
  78. #define yychar objc_char
  79. #define yydebug objc_debug
  80. #define yypact objc_pact
  81. #define yyr1 objc_r1
  82. #define yyr2 objc_r2
  83. #define yydef objc_def
  84. #define yychk objc_chk
  85. #define yypgo objc_pgo
  86. #define yyact objc_act
  87. #define yyexca objc_exca
  88. #define yyerrflag objc_errflag
  89. #define yynerrs objc_nerrs
  90. #define yyps objc_ps
  91. #define yypv objc_pv
  92. #define yys objc_s
  93. #define yy_yys objc_yys
  94. #define yystate objc_state
  95. #define yytmp objc_tmp
  96. #define yyv objc_v
  97. #define yy_yyv objc_yyv
  98. #define yyval objc_val
  99. #define yylloc objc_lloc
  100. #define yyreds objc_reds /* With YYDEBUG defined */
  101. #define yytoks objc_toks /* With YYDEBUG defined */
  102. #define yylhs objc_yylhs
  103. #define yylen objc_yylen
  104. #define yydefred objc_yydefred
  105. #define yydgoto objc_yydgoto
  106. #define yysindex objc_yysindex
  107. #define yyrindex objc_yyrindex
  108. #define yygindex objc_yygindex
  109. #define yytable objc_yytable
  110. #define yycheck objc_yycheck
  111. #ifndef YYDEBUG
  112. #define YYDEBUG 0 /* Default to no yydebug support */
  113. #endif
  114. int
  115. yyparse PARAMS ((void));
  116. static int
  117. yylex PARAMS ((void));
  118. void
  119. yyerror PARAMS ((char *));
  120. %}
  121. /* Although the yacc &quot;value&quot; of an expression is not used,
  122. since the result is stored in the structure being created,
  123. other node types do have values. */
  124. %union
  125. {
  126. LONGEST lval;
  127. struct {
  128. LONGEST val;
  129. struct type *type;
  130. } typed_val_int;
  131. struct {
  132. DOUBLEST dval;
  133. struct type *type;
  134. } typed_val_float;
  135. struct symbol *sym;
  136. struct type *tval;
  137. struct stoken sval;
  138. struct ttype tsym;
  139. struct symtoken ssym;
  140. int voidval;
  141. struct block *bval;
  142. enum exp_opcode opcode;
  143. struct internalvar *ivar;
  144. struct objc_class_str class;
  145. struct type **tvec;
  146. int *ivec;
  147. }
  148. %{
  149. /* YYSTYPE gets defined by %union */
  150. static int
  151. parse_number PARAMS ((char *, int, int, YYSTYPE *));
  152. %}
  153. %type &lt;voidval&gt; exp exp1 type_exp start variable qualified_name lcurly
  154. %type &lt;lval&gt; rcurly
  155. %type &lt;tval&gt; type typebase
  156. %type &lt;tvec&gt; nonempty_typelist
  157. /* %type &lt;bval&gt; block */
  158. /* Fancy type parsing. */
  159. %type &lt;voidval&gt; func_mod direct_abs_decl abs_decl
  160. %type &lt;tval&gt; ptype
  161. %type &lt;lval&gt; array_mod
  162. %token &lt;typed_val_int&gt; INT
  163. %token &lt;typed_val_float&gt; FLOAT
  164. /* Both NAME and TYPENAME tokens represent symbols in the input,
  165. and both convey their data as strings.
  166. But a TYPENAME is a string that happens to be defined as a typedef
  167. or builtin type name (such as int or char)
  168. and a NAME is any other symbol.
  169. Contexts where this distinction is not important can use the
  170. nonterminal &quot;name&quot;, which matches either NAME or TYPENAME. */
  171. %token &lt;sval&gt; STRING
  172. %token &lt;sval&gt; NSSTRING /* ObjC Foundation &quot;NSString&quot; literal */
  173. %token &lt;sval&gt; SELECTOR /* ObjC &quot;@selector&quot; pseudo-operator */
  174. %token &lt;ssym&gt; NAME /* BLOCKNAME defined below to give it higher precedence. */
  175. %token &lt;tsym&gt; TYPENAME
  176. %token &lt;class&gt; CLASSNAME /* ObjC Class name */
  177. %type &lt;sval&gt; name
  178. %type &lt;ssym&gt; name_not_typename
  179. %type &lt;tsym&gt; typename
  180. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  181. but which would parse as a valid number in the current input radix.
  182. E.g. &quot;c&quot; when input_radix==16. Depending on the parse, it will be
  183. turned into a name or into a number. */
  184. %token &lt;ssym&gt; NAME_OR_INT
  185. %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
  186. %token TEMPLATE
  187. %token ERROR
  188. /* Special type cases, put in to allow the parser to distinguish different
  189. legal basetypes. */
  190. %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
  191. %token &lt;voidval&gt; VARIABLE
  192. %token &lt;opcode&gt; ASSIGN_MODIFY
  193. /* C++ */
  194. %token THIS
  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_MSGCALL);
  310. end_msglist();
  311. write_exp_elt_opcode (OP_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_MSGCALL);
  324. end_msglist();
  325. write_exp_elt_opcode (OP_MSGCALL);
  326. }
  327. ;
  328. exp : '[' exp
  329. { start_msglist(); }
  330. msglist ']'
  331. { write_exp_elt_opcode (OP_MSGCALL);
  332. end_msglist();
  333. write_exp_elt_opcode (OP_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_SELECTOR);
  490. write_exp_string ($1);
  491. write_exp_elt_opcode (OP_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 constants with
  501. an explicit null byte added at the end. Thus
  502. the array upper bound is the string length.
  503. There is no such thing in C as a completely empty
  504. string. */
  505. char *sp = $1.ptr; int count = $1.length;
  506. while (count-- &gt; 0)
  507. {
  508. write_exp_elt_opcode (OP_LONG);
  509. write_exp_elt_type (builtin_type_char);
  510. write_exp_elt_longcst ((LONGEST)(*sp++));
  511. write_exp_elt_opcode (OP_LONG);
  512. }
  513. write_exp_elt_opcode (OP_LONG);
  514. write_exp_elt_type (builtin_type_char);
  515. write_exp_elt_longcst ((LONGEST)'\0');
  516. write_exp_elt_opcode (OP_LONG);
  517. write_exp_elt_opcode (OP_ARRAY);
  518. write_exp_elt_longcst ((LONGEST) 0);
  519. write_exp_elt_longcst ((LONGEST) ($1.length));
  520. write_exp_elt_opcode (OP_ARRAY); }
  521. ;
  522. exp : NSSTRING /* ObjC NextStep NSString constant
  523. * of the form '@' '&quot;' string '&quot;'
  524. */
  525. { write_exp_elt_opcode (OP_NSSTRING);
  526. write_exp_string ($1);
  527. write_exp_elt_opcode (OP_NSSTRING); }
  528. ;
  529. /* C++. */
  530. exp : THIS
  531. { write_exp_elt_opcode (OP_THIS);
  532. write_exp_elt_opcode (OP_THIS); }
  533. ;
  534. /* end of C++. */
  535. block : BLOCKNAME
  536. {
  537. if ($1.sym != 0)
  538. $$ = SYMBOL_BLOCK_VALUE ($1.sym);
  539. else
  540. {
  541. struct symtab *tem =
  542. lookup_symtab (copy_name ($1.stoken));
  543. if (tem)
  544. $$ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), STATIC_BLOCK);
  545. else
  546. error (&quot;No file or function \&quot;%s\&quot;.&quot;,
  547. copy_name ($1.stoken));
  548. }
  549. }
  550. ;
  551. block : block COLONCOLON name
  552. { struct symbol *tem
  553. = lookup_symbol (copy_name ($3), $1,
  554. VAR_NAMESPACE, (int *) NULL,
  555. (struct symtab **) NULL);
  556. if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  557. error (&quot;No function \&quot;%s\&quot; in specified context.&quot;,
  558. copy_name ($3));
  559. $$ = SYMBOL_BLOCK_VALUE (tem); }
  560. ;
  561. variable: block COLONCOLON name
  562. { struct symbol *sym;
  563. sym = lookup_symbol (copy_name ($3), $1,
  564. VAR_NAMESPACE, (int *) NULL,
  565. (struct symtab **) NULL);
  566. if (sym == 0)
  567. error (&quot;No symbol \&quot;%s\&quot; in specified context.&quot;,
  568. copy_name ($3));
  569. write_exp_elt_opcode (OP_VAR_VALUE);
  570. /* block_found is set by lookup_symbol. */
  571. write_exp_elt_block (block_found);
  572. write_exp_elt_sym (sym);
  573. write_exp_elt_opcode (OP_VAR_VALUE); }
  574. ;
  575. qualified_name: typebase COLONCOLON name
  576. {
  577. struct type *type = $1;
  578. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  579. &amp;&amp; TYPE_CODE (type) != TYPE_CODE_UNION)
  580. error (&quot;`%s' is not defined as an aggregate type.&quot;,
  581. TYPE_NAME (type));
  582. write_exp_elt_opcode (OP_SCOPE);
  583. write_exp_elt_type (type);
  584. write_exp_string ($3);
  585. write_exp_elt_opcode (OP_SCOPE);
  586. }
  587. | typebase COLONCOLON '~' name
  588. {
  589. struct type *type = $1;
  590. struct stoken tmp_token;
  591. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  592. &amp;&amp; TYPE_CODE (type) != TYPE_CODE_UNION)
  593. error (&quot;`%s' is not defined as an aggregate type.&quot;,
  594. TYPE_NAME (type));
  595. if (!STREQ (type_name_no_tag (type), $4.ptr))
  596. error (&quot;invalid destructor `%s::~%s'&quot;,
  597. type_name_no_tag (type), $4.ptr);
  598. tmp_token.ptr = (char*) alloca ($4.length + 2);
  599. tmp_token.length = $4.length + 1;
  600. tmp_token.ptr[0] = '~';
  601. memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
  602. tmp_token.ptr[tmp_token.length] = 0;
  603. write_exp_elt_opcode (OP_SCOPE);
  604. write_exp_elt_type (type);
  605. write_exp_string (tmp_token);
  606. write_exp_elt_opcode (OP_SCOPE);
  607. }
  608. ;
  609. variable: qualified_name
  610. | COLONCOLON name
  611. {
  612. char *name = copy_name ($2);
  613. struct symbol *sym;
  614. struct minimal_symbol *msymbol;
  615. sym =
  616. lookup_symbol (name, (const struct block *) NULL,
  617. VAR_NAMESPACE, (int *) NULL,
  618. (struct symtab **) NULL);
  619. if (sym)
  620. {
  621. write_exp_elt_opcode (OP_VAR_VALUE);
  622. write_exp_elt_block (NULL);
  623. write_exp_elt_sym (sym);
  624. write_exp_elt_opcode (OP_VAR_VALUE);
  625. break;
  626. }
  627. msymbol = lookup_minimal_symbol (name, NULL, NULL);
  628. if (msymbol != NULL)
  629. {
  630. write_exp_msymbol (msymbol,
  631. lookup_function_type (builtin_type_int),
  632. builtin_type_int);
  633. }
  634. else
  635. if (!have_full_symbols () &amp;&amp; !have_partial_symbols ())
  636. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  637. else
  638. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;, name);
  639. }
  640. ;
  641. variable: name_not_typename
  642. { struct symbol *sym = $1.sym;
  643. if (sym)
  644. {
  645. if (symbol_read_needs_frame (sym))
  646. {
  647. if (innermost_block == 0 ||
  648. contained_in (block_found,
  649. innermost_block))
  650. innermost_block = block_found;
  651. }
  652. write_exp_elt_opcode (OP_VAR_VALUE);
  653. /* We want to use the selected frame, not
  654. another more inner frame which happens to
  655. be in the same block. */
  656. write_exp_elt_block (NULL);
  657. write_exp_elt_sym (sym);
  658. write_exp_elt_opcode (OP_VAR_VALUE);
  659. }
  660. else if ($1.is_a_field_of_this)
  661. {
  662. /* C++/ObjC: it hangs off of `this'/'self'.
  663. Must not inadvertently convert from a
  664. method call to data ref. */
  665. if (innermost_block == 0 ||
  666. contained_in (block_found, innermost_block))
  667. innermost_block = block_found;
  668. write_exp_elt_opcode (OP_SELF);
  669. write_exp_elt_opcode (OP_SELF);
  670. write_exp_elt_opcode (STRUCTOP_PTR);
  671. write_exp_string ($1.stoken);
  672. write_exp_elt_opcode (STRUCTOP_PTR);
  673. }
  674. else
  675. {
  676. struct minimal_symbol *msymbol;
  677. register char *arg = copy_name ($1.stoken);
  678. msymbol =
  679. lookup_minimal_symbol (arg, NULL, NULL);
  680. if (msymbol != NULL)
  681. {
  682. write_exp_msymbol (msymbol,
  683. lookup_function_type (builtin_type_int),
  684. builtin_type_int);
  685. }
  686. else if (!have_full_symbols () &amp;&amp;
  687. !have_partial_symbols ())
  688. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  689. else
  690. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  691. copy_name ($1.stoken));
  692. }
  693. }
  694. ;
  695. ptype : typebase
  696. /* &quot;const&quot; and &quot;volatile&quot; are curently ignored. A type qualifier
  697. before the type is currently handled in the typebase rule.
  698. The reason for recognizing these here (shift/reduce conflicts)
  699. might be obsolete now that some pointer to member rules have
  700. been deleted. */
  701. | typebase CONST_KEYWORD
  702. | typebase VOLATILE_KEYWORD
  703. | typebase abs_decl
  704. { $$ = follow_types ($1); }
  705. | typebase CONST_KEYWORD abs_decl
  706. { $$ = follow_types ($1); }
  707. | typebase VOLATILE_KEYWORD abs_decl
  708. { $$ = follow_types ($1); }
  709. ;
  710. abs_decl: '*'
  711. { push_type (tp_pointer); $$ = 0; }
  712. | '*' abs_decl
  713. { push_type (tp_pointer); $$ = $2; }
  714. | '&amp;'
  715. { push_type (tp_reference); $$ = 0; }
  716. | '&amp;' abs_decl
  717. { push_type (tp_reference); $$ = $2; }
  718. | direct_abs_decl
  719. ;
  720. direct_abs_decl: '(' abs_decl ')'
  721. { $$ = $2; }
  722. | direct_abs_decl array_mod
  723. {
  724. push_type_int ($2);
  725. push_type (tp_array);
  726. }
  727. | array_mod
  728. {
  729. push_type_int ($1);
  730. push_type (tp_array);
  731. $$ = 0;
  732. }
  733. | direct_abs_decl func_mod
  734. { push_type (tp_function); }
  735. | func_mod
  736. { push_type (tp_function); }
  737. ;
  738. array_mod: '[' ']'
  739. { $$ = -1; }
  740. | '[' INT ']'
  741. { $$ = $2.val; }
  742. ;
  743. func_mod: '(' ')'
  744. { $$ = 0; }
  745. | '(' nonempty_typelist ')'
  746. { free ((PTR)$2); $$ = 0; }
  747. ;
  748. /* We used to try to recognize more pointer to member types here, but
  749. that didn't work (shift/reduce conflicts meant that these rules never
  750. got executed). The problem is that
  751. int (foo::bar::baz::bizzle)
  752. is a function type but
  753. int (foo::bar::baz::bizzle::*)
  754. is a pointer to member type. Stroustrup loses again! */
  755. type : ptype
  756. | typebase COLONCOLON '*'
  757. { $$ = lookup_member_type (builtin_type_int, $1); }
  758. ;
  759. typebase /* Implements (approximately): (type-qualifier)* type-specifier */
  760. : TYPENAME
  761. { $$ = $1.type; }
  762. | CLASSNAME
  763. {
  764. if ($1.type == NULL)
  765. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  766. copy_name($1.stoken));
  767. else
  768. $$ = $1.type;
  769. }
  770. | INT_KEYWORD
  771. { $$ = builtin_type_int; }
  772. | LONG
  773. { $$ = builtin_type_long; }
  774. | SHORT
  775. { $$ = builtin_type_short; }
  776. | LONG INT_KEYWORD
  777. { $$ = builtin_type_long; }
  778. | UNSIGNED LONG INT_KEYWORD
  779. { $$ = builtin_type_unsigned_long; }
  780. | LONG LONG
  781. { $$ = builtin_type_long_long; }
  782. | LONG LONG INT_KEYWORD
  783. { $$ = builtin_type_long_long; }
  784. | UNSIGNED LONG LONG
  785. { $$ = builtin_type_unsigned_long_long; }
  786. | UNSIGNED LONG LONG INT_KEYWORD
  787. { $$ = builtin_type_unsigned_long_long; }
  788. | SHORT INT_KEYWORD
  789. { $$ = builtin_type_short; }
  790. | UNSIGNED SHORT INT_KEYWORD
  791. { $$ = builtin_type_unsigned_short; }
  792. | DOUBLE_KEYWORD
  793. { $$ = builtin_type_double; }
  794. | LONG DOUBLE_KEYWORD
  795. { $$ = builtin_type_long_double; }
  796. | STRUCT name
  797. { $$ = lookup_struct (copy_name ($2),
  798. expression_context_block); }
  799. | CLASS name
  800. { $$ = lookup_struct (copy_name ($2),
  801. expression_context_block); }
  802. | UNION name
  803. { $$ = lookup_union (copy_name ($2),
  804. expression_context_block); }
  805. | ENUM name
  806. { $$ = lookup_enum (copy_name ($2),
  807. expression_context_block); }
  808. | UNSIGNED typename
  809. { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
  810. | UNSIGNED
  811. { $$ = builtin_type_unsigned_int; }
  812. | SIGNED_KEYWORD typename
  813. { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
  814. | SIGNED_KEYWORD
  815. { $$ = builtin_type_int; }
  816. | TEMPLATE name '&lt;' type '&gt;'
  817. { $$ = lookup_template_type(copy_name($2), $4,
  818. expression_context_block);
  819. }
  820. /* &quot;const&quot; and &quot;volatile&quot; are curently ignored. A type qualifier
  821. after the type is handled in the ptype rule. I think these could
  822. be too. */
  823. | CONST_KEYWORD typebase { $$ = $2; }
  824. | VOLATILE_KEYWORD typebase { $$ = $2; }
  825. ;
  826. typename: TYPENAME
  827. | INT_KEYWORD
  828. {
  829. $$.stoken.ptr = &quot;int&quot;;
  830. $$.stoken.length = 3;
  831. $$.type = builtin_type_int;
  832. }
  833. | LONG
  834. {
  835. $$.stoken.ptr = &quot;long&quot;;
  836. $$.stoken.length = 4;
  837. $$.type = builtin_type_long;
  838. }
  839. | SHORT
  840. {
  841. $$.stoken.ptr = &quot;short&quot;;
  842. $$.stoken.length = 5;
  843. $$.type = builtin_type_short;
  844. }
  845. ;
  846. nonempty_typelist
  847. : type
  848. { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
  849. $&lt;ivec&gt;$[0] = 1; /* Number of types in vector */
  850. $$[1] = $1;
  851. }
  852. | nonempty_typelist ',' type
  853. { int len = sizeof (struct type *) * (++($&lt;ivec&gt;1[0]) + 1);
  854. $$ = (struct type **) realloc ((char *) $1, len);
  855. $$[$&lt;ivec&gt;$[0]] = $3;
  856. }
  857. ;
  858. name : NAME { $$ = $1.stoken; }
  859. | BLOCKNAME { $$ = $1.stoken; }
  860. | TYPENAME { $$ = $1.stoken; }
  861. | CLASSNAME { $$ = $1.stoken; }
  862. | NAME_OR_INT { $$ = $1.stoken; }
  863. ;
  864. name_not_typename : NAME
  865. | BLOCKNAME
  866. /* These would be useful if name_not_typename was useful, but it is just
  867. a fake for &quot;variable&quot;, so these cause reduce/reduce conflicts because
  868. the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
  869. =exp) or just an exp. If name_not_typename was ever used in an lvalue
  870. context where only a name could occur, this might be useful.
  871. | NAME_OR_INT
  872. */
  873. ;
  874. %%
  875. /* Take care of parsing a number (anything that starts with a digit).
  876. Set yylval and return the token type; update lexptr.
  877. LEN is the number of characters in it. */
  878. /*** Needs some error checking for the float case ***/
  879. static int
  880. parse_number (p, len, parsed_float, putithere)
  881. register char *p;
  882. register int len;
  883. int parsed_float;
  884. YYSTYPE *putithere;
  885. {
  886. /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
  887. here, and we do kind of silly things like cast to unsigned. */
  888. register LONGEST n = 0;
  889. register LONGEST prevn = 0;
  890. unsigned LONGEST un;
  891. register int i = 0;
  892. register int c;
  893. register 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;, &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;, &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, 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 make
  1000. a second check for zero). FIXME: Can't we just make n and prevn
  1001. 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 overflow
  1006. 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 (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 (STREQN (tokstart, tokentab2[i].operator, 2))
  1130. {
  1131. lexptr += 2;
  1132. yylval.opcode = tokentab2[i].opcode;
  1133. return tokentab2[i].token;
  1134. }
  1135. switch (tokchr = *tokstart)
  1136. {
  1137. case 0:
  1138. return 0;
  1139. case ' ':
  1140. case '\t':
  1141. case '\n':
  1142. lexptr++;
  1143. goto retry;
  1144. case '\'':
  1145. /* We either have a character constant ('0' or '\177' for example)
  1146. or we have a quoted symbol reference ('foo(int,int)' in C++
  1147. for example). */
  1148. lexptr++;
  1149. c = *lexptr++;
  1150. if (c == '\\')
  1151. c = parse_escape (&amp;lexptr);
  1152. else if (c == '\'')
  1153. error (&quot;Empty character constant.&quot;);
  1154. yylval.typed_val_int.val = c;
  1155. yylval.typed_val_int.type = builtin_type_char;
  1156. c = *lexptr++;
  1157. if (c != '\'')
  1158. {
  1159. namelen = skip_quoted (tokstart, gdb_completer_word_break_characters)
  1160. - 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. register 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 indicates
  1233. a decimal floating point number regardless of the radix. */
  1234. else if (*p == '.')
  1235. if (got_dot)
  1236. toktype = ERROR; /* only one '.' in a float */
  1237. else
  1238. got_dot = 1;
  1239. else if (got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E') &amp;&amp;
  1240. (*p == '-' || *p == '+'))
  1241. /* This is the sign of the exponent, not the end of the
  1242. number. */
  1243. continue;
  1244. /* Always take decimal digits; parse_number handles radix error */
  1245. else if (*p &gt;= '0' &amp;&amp; *p &lt;= '9')
  1246. continue;
  1247. /* We will take letters only if hex is true, and only
  1248. up to what the input radix would permit. FSF was content
  1249. to rely on parse_number to validate; but it leaks. */
  1250. else if (*p &gt;= 'a' &amp;&amp; *p &lt;= 'z') {
  1251. if (!hex || *p &gt;= ('a' + local_radix - 10))
  1252. toktype = ERROR;
  1253. }
  1254. else if (*p &gt;= 'A' &amp;&amp; *p &lt;= 'Z') {
  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, got_dot|got_e, &amp;yylval);
  1262. if (toktype == ERROR)
  1263. {
  1264. char *err_copy = (char *) alloca (p - tokstart + 1);
  1265. memcpy (err_copy, tokstart, p - tokstart);
  1266. err_copy[p - tokstart] = 0;
  1267. error (&quot;Invalid number \&quot;%s\&quot;.&quot;, err_copy);
  1268. }
  1269. lexptr = p;
  1270. return toktype;
  1271. }
  1272. case '+':
  1273. case '-':
  1274. case '*':
  1275. case '/':
  1276. case '%':
  1277. case '|':
  1278. case '&amp;':
  1279. case '^':
  1280. case '~':
  1281. case '!':
  1282. #if 0
  1283. case '@': /* moved out below */
  1284. #endif
  1285. case '&lt;':
  1286. case '&gt;':
  1287. case '[':
  1288. case ']':
  1289. case '?':
  1290. case ':':
  1291. case '=':
  1292. case '{':
  1293. case '}':
  1294. symbol:
  1295. lexptr++;
  1296. return tokchr;
  1297. case '@':
  1298. if (strncmp(tokstart, &quot;@selector&quot;, 9) == 0)
  1299. {
  1300. tokptr = strchr(tokstart, '(');
  1301. if (tokptr == NULL)
  1302. {
  1303. error (&quot;Missing '(' in @selector(...)&quot;);
  1304. }
  1305. tempbufindex = 0;
  1306. tokptr++; /* skip the '(' */
  1307. do {
  1308. /* Grow the static temp buffer if necessary, including allocating
  1309. the first one on demand. */
  1310. if (tempbufindex + 1 &gt;= tempbufsize)
  1311. {
  1312. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1313. }
  1314. tempbuf[tempbufindex++] = *tokptr++;
  1315. } while ((*tokptr != ')') &amp;&amp; (*tokptr != '\0'));
  1316. if (*tokptr++ != ')')
  1317. {
  1318. error (&quot;Missing ')' in @selector(...)&quot;);
  1319. }
  1320. tempbuf[tempbufindex] = '\0';
  1321. yylval.sval.ptr = tempbuf;
  1322. yylval.sval.length = tempbufindex;
  1323. lexptr = tokptr;
  1324. return SELECTOR;
  1325. }
  1326. if (tokstart[1] != '&quot;')
  1327. {
  1328. lexptr++;
  1329. return tokchr;
  1330. }
  1331. /* ObjC NextStep NSString constant: fall thru and parse like STRING */
  1332. tokstart++;
  1333. case '&quot;':
  1334. /* Build the gdb internal form of the input string in tempbuf,
  1335. translating any standard C escape forms seen. Note that the
  1336. buffer is null byte terminated *only* for the convenience of
  1337. debugging gdb itself and printing the buffer contents when
  1338. the buffer contains no embedded nulls. Gdb does not depend
  1339. upon the buffer being null byte terminated, it uses the length
  1340. string instead. This allows gdb to handle C strings (as well
  1341. as strings in other languages) with embedded null bytes */
  1342. tokptr = ++tokstart;
  1343. tempbufindex = 0;
  1344. do {
  1345. /* Grow the static temp buffer if necessary, including allocating
  1346. the first one on demand. */
  1347. if (tempbufindex + 1 &gt;= tempbufsize)
  1348. {
  1349. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1350. }
  1351. switch (*tokptr)
  1352. {
  1353. case '\0':
  1354. case '&quot;':
  1355. /* Do nothing, loop will terminate. */
  1356. break;
  1357. case '\\':
  1358. tokptr++;
  1359. c = parse_escape (&amp;tokptr);
  1360. if (c == -1)
  1361. {
  1362. continue;
  1363. }
  1364. tempbuf[tempbufindex++] = c;
  1365. break;
  1366. default:
  1367. tempbuf[tempbufindex++] = *tokptr++;
  1368. break;
  1369. }
  1370. } while ((*tokptr != '&quot;') &amp;&amp; (*tokptr != '\0'));
  1371. if (*tokptr++ != '&quot;')
  1372. {
  1373. error (&quot;Unterminated string in expression.&quot;);
  1374. }
  1375. tempbuf[tempbufindex] = '\0'; /* See note above */
  1376. yylval.sval.ptr = tempbuf;
  1377. yylval.sval.length = tempbufindex;
  1378. lexptr = tokptr;
  1379. return (tokchr == '@' ? NSSTRING : STRING);
  1380. }
  1381. if (!(tokchr == '_' || tokchr == '$' ||
  1382. (tokchr &gt;= 'a' &amp;&amp; tokchr &lt;= 'z') || (tokchr &gt;= 'A' &amp;&amp; tokchr &lt;= 'Z')))
  1383. /* We must have come across a bad character (e.g. ';'). */
  1384. error (&quot;Invalid character '%c' in expression.&quot;, c);
  1385. /* It's a name. See how long it is. */
  1386. namelen = 0;
  1387. for (c = tokstart[namelen];
  1388. (c == '_' || c == '$' || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1389. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || c == '&lt;');)
  1390. {
  1391. if (c == '&lt;')
  1392. {
  1393. int i = namelen;
  1394. while (tokstart[++i] &amp;&amp; tokstart[i] != '&gt;');
  1395. if (tokstart[i] == '&gt;')
  1396. namelen = i;
  1397. }
  1398. c = tokstart[++namelen];
  1399. }
  1400. /* The token &quot;if&quot; terminates the expression and is NOT
  1401. removed from the input stream. */
  1402. if (namelen == 2 &amp;&amp; tokstart[0] == 'i' &amp;&amp; tokstart[1] == 'f')
  1403. {
  1404. return 0;
  1405. }
  1406. lexptr += namelen;
  1407. tryname:
  1408. /* Catch specific keywords. Should be done with a data structure. */
  1409. switch (namelen)
  1410. {
  1411. case 8:
  1412. if (STREQN (tokstart, &quot;unsigned&quot;, 8))
  1413. return UNSIGNED;
  1414. if (current_language-&gt;la_language == language_cplus
  1415. &amp;&amp; STREQN (tokstart, &quot;template&quot;, 8))
  1416. return TEMPLATE;
  1417. if (STREQN (tokstart, &quot;volatile&quot;, 8))
  1418. return VOLATILE_KEYWORD;
  1419. break;
  1420. case 6:
  1421. if (STREQN (tokstart, &quot;struct&quot;, 6))
  1422. return STRUCT;
  1423. if (STREQN (tokstart, &quot;signed&quot;, 6))
  1424. return SIGNED_KEYWORD;
  1425. if (STREQN (tokstart, &quot;sizeof&quot;, 6))
  1426. return SIZEOF;
  1427. if (STREQN (tokstart, &quot;double&quot;, 6))
  1428. return DOUBLE_KEYWORD;
  1429. break;
  1430. case 5:
  1431. if ((current_language-&gt;la_language == language_cplus)
  1432. &amp;&amp; STREQN (tokstart, &quot;class&quot;, 5))
  1433. return CLASS;
  1434. if (STREQN (tokstart, &quot;union&quot;, 5))
  1435. return UNION;
  1436. if (STREQN (tokstart, &quot;short&quot;, 5))
  1437. return SHORT;
  1438. if (STREQN (tokstart, &quot;const&quot;, 5))
  1439. return CONST_KEYWORD;
  1440. break;
  1441. case 4:
  1442. if (STREQN (tokstart, &quot;enum&quot;, 4))
  1443. return ENUM;
  1444. if (STREQN (tokstart, &quot;long&quot;, 4))
  1445. return LONG;
  1446. if (current_language-&gt;la_language == language_cplus
  1447. &amp;&amp; STREQN (tokstart, &quot;this&quot;, 4))
  1448. {
  1449. static const char this_name[] =
  1450. { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' };
  1451. if (lookup_symbol (this_name, expression_context_block,
  1452. VAR_NAMESPACE, (int *) NULL,
  1453. (struct symtab **) NULL))
  1454. return THIS;
  1455. }
  1456. break;
  1457. case 3:
  1458. if (STREQN (tokstart, &quot;int&quot;, 3))
  1459. return INT_KEYWORD;
  1460. break;
  1461. default:
  1462. break;
  1463. }
  1464. yylval.sval.ptr = tokstart;
  1465. yylval.sval.length = namelen;
  1466. if (*tokstart == '$')
  1467. {
  1468. write_dollar_variable (yylval.sval);
  1469. return VARIABLE;
  1470. }
  1471. /* Use token-type BLOCKNAME for symbols that happen to be defined as
  1472. functions or symtabs. If this is not so, then ...
  1473. Use token-type TYPENAME for symbols that happen to be defined
  1474. currently as names of types; NAME for other symbols.
  1475. The caller is not constrained to care about the distinction. */
  1476. {
  1477. char *tmp = copy_name (yylval.sval);
  1478. struct symbol *sym;
  1479. int is_a_field_of_this = 0, *need_this;
  1480. int hextype;
  1481. if (current_language-&gt;la_language == language_cplus ||
  1482. current_language-&gt;la_language == language_objc)
  1483. need_this = &amp;is_a_field_of_this;
  1484. else
  1485. need_this = (int *) NULL;
  1486. sym = lookup_symbol (tmp, expression_context_block,
  1487. VAR_NAMESPACE,
  1488. need_this,
  1489. (struct symtab **) NULL);
  1490. /* Call lookup_symtab, not lookup_partial_symtab, in case there are
  1491. no psymtabs (coff, xcoff, or some future change to blow away the
  1492. psymtabs once symbols are read). */
  1493. if ((sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_BLOCK) ||
  1494. lookup_symtab (tmp))
  1495. {
  1496. yylval.ssym.sym = sym;
  1497. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1498. return BLOCKNAME;
  1499. }
  1500. if (sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  1501. {
  1502. #if 1
  1503. /* Despite the following flaw, we need to keep this code enabled.
  1504. Because we can get called from check_stub_method, if we don't
  1505. handle nested types then it screws many operations in any
  1506. program which uses nested types. */
  1507. /* In &quot;A::x&quot;, if x is a member function of A and there happens
  1508. to be a type (nested or not, since the stabs don't make that
  1509. distinction) named x, then this code incorrectly thinks we
  1510. are dealing with nested types rather than a member function. */
  1511. char *p;
  1512. char *namestart;
  1513. struct symbol *best_sym;
  1514. /* Look ahead to detect nested types. This probably should be
  1515. done in the grammar, but trying seemed to introduce a lot
  1516. of shift/reduce and reduce/reduce conflicts. It's possible
  1517. that it could be done, though. Or perhaps a non-grammar, but
  1518. less ad hoc, approach would work well. */
  1519. /* Since we do not currently have any way of distinguishing
  1520. a nested type from a non-nested one (the stabs don't tell
  1521. us whether a type is nested), we just ignore the
  1522. containing type. */
  1523. p = lexptr;
  1524. best_sym = sym;
  1525. while (1)
  1526. {
  1527. /* Skip whitespace. */
  1528. while (*p == ' ' || *p == '\t' || *p == '\n')
  1529. ++p;
  1530. if (*p == ':' &amp;&amp; p[1] == ':')
  1531. {
  1532. /* Skip the `::'. */
  1533. p += 2;
  1534. /* Skip whitespace. */
  1535. while (*p == ' ' || *p == '\t' || *p == '\n')
  1536. ++p;
  1537. namestart = p;
  1538. while (*p == '_' || *p == '$' || (*p &gt;= '0' &amp;&amp; *p &lt;= '9')
  1539. || (*p &gt;= 'a' &amp;&amp; *p &lt;= 'z')
  1540. || (*p &gt;= 'A' &amp;&amp; *p &lt;= 'Z'))
  1541. ++p;
  1542. if (p != namestart)
  1543. {
  1544. struct symbol *cur_sym;
  1545. /* As big as the whole rest of the expression, which is
  1546. at least big enough. */
  1547. char *ncopy = alloca (strlen (tmp)+strlen (namestart)+3);
  1548. char *tmp1;
  1549. tmp1 = ncopy;
  1550. memcpy (tmp1, tmp, strlen (tmp));
  1551. tmp1 += strlen (tmp);
  1552. memcpy (tmp1, &quot;::&quot;, 2);
  1553. tmp1 += 2;
  1554. memcpy (tmp1, namestart, p - namestart);
  1555. tmp1[p - namestart] = '\0';
  1556. cur_sym = lookup_symbol (ncopy, expression_context_block,
  1557. VAR_NAMESPACE, (int *) NULL,
  1558. (struct symtab **) NULL);
  1559. if (cur_sym)
  1560. {
  1561. if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
  1562. {
  1563. best_sym = cur_sym;
  1564. lexptr = p;
  1565. }
  1566. else
  1567. break;
  1568. }
  1569. else
  1570. break;
  1571. }
  1572. else
  1573. break;
  1574. }
  1575. else
  1576. break;
  1577. }
  1578. yylval.tsym.type = SYMBOL_TYPE (best_sym);
  1579. #else /* not 0 */
  1580. yylval.tsym.type = SYMBOL_TYPE (sym);
  1581. #endif /* not 0 */
  1582. return TYPENAME;
  1583. }
  1584. if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
  1585. return TYPENAME;
  1586. if (!sym) /* see if it's an ObjC classname */
  1587. {
  1588. CORE_ADDR Class = lookup_objc_class(tmp);
  1589. if (Class)
  1590. {
  1591. extern struct symbol *lookup_struct_typedef();
  1592. yylval.class.class = Class;
  1593. if (sym = lookup_struct_typedef (tmp, expression_context_block, 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

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