PageRenderTime 68ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Happy | 1904 lines | 1687 code | 217 blank | 0 comment | 0 complexity | 2dae2a985214d741aa7d6a219bba49c6 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0-no-copyleft-exception, MPL-2.0, JSON, 0BSD, LGPL-2.1, Apache-2.0, BSD-3-Clause, ISC, LGPL-2.0, WTFPL, MIT

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_void_data_ptr);
  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_void_data_ptr);
  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. struct symbol *func;
  662. enum runtime_type runtime = OBJC_RUNTIME;
  663. /* C++/ObjC: it hangs off of `this'/'self'.
  664. Must not inadvertently convert from a
  665. method call to data ref. */
  666. if (innermost_block == 0 ||
  667. contained_in (block_found, innermost_block))
  668. innermost_block = block_found;
  669. if (innermost_block)
  670. {
  671. func = BLOCK_FUNCTION (innermost_block);
  672. }
  673. else
  674. func = NULL;
  675. /* If this is an ObjC++ file we could have either
  676. a C++ function or an ObjC function - which
  677. determines whether OP_OBJC_SELF or OP_THIS is
  678. the right opcode to add here. */
  679. if (func
  680. &amp;&amp; TYPE_RUNTIME (SYMBOL_TYPE (func)) != OBJC_RUNTIME)
  681. {
  682. if (SYMBOL_LANGUAGE(func) == language_cplus
  683. || SYMBOL_LANGUAGE(func) == language_objcplus)
  684. {
  685. runtime = CPLUS_RUNTIME;
  686. }
  687. }
  688. if (runtime == OBJC_RUNTIME)
  689. {
  690. write_exp_elt_opcode (OP_OBJC_SELF);
  691. write_exp_elt_opcode (OP_OBJC_SELF);
  692. }
  693. else
  694. {
  695. write_exp_elt_opcode (OP_THIS);
  696. write_exp_elt_opcode (OP_THIS);
  697. }
  698. write_exp_elt_opcode (STRUCTOP_PTR);
  699. write_exp_string ($1.stoken);
  700. write_exp_elt_opcode (STRUCTOP_PTR);
  701. }
  702. else
  703. {
  704. struct minimal_symbol *msymbol;
  705. char *arg = copy_name ($1.stoken);
  706. msymbol =
  707. lookup_minimal_symbol (arg, NULL, NULL);
  708. if (msymbol != NULL)
  709. {
  710. write_exp_msymbol (msymbol,
  711. lookup_function_type (builtin_type_int),
  712. builtin_type_int);
  713. }
  714. else if (!have_full_symbols () &amp;&amp;
  715. !have_partial_symbols ())
  716. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  717. else
  718. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  719. copy_name ($1.stoken));
  720. }
  721. }
  722. ;
  723. ptype : typebase
  724. /* &quot;const&quot; and &quot;volatile&quot; are curently ignored. A type
  725. qualifier before the type is currently handled in the
  726. typebase rule. The reason for recognizing these here
  727. (shift/reduce conflicts) might be obsolete now that some
  728. pointer to member rules have been deleted. */
  729. | typebase CONST_KEYWORD
  730. | typebase VOLATILE_KEYWORD
  731. | typebase abs_decl
  732. { $$ = follow_types ($1); }
  733. | typebase CONST_KEYWORD abs_decl
  734. { $$ = follow_types ($1); }
  735. | typebase VOLATILE_KEYWORD abs_decl
  736. { $$ = follow_types ($1); }
  737. ;
  738. abs_decl: '*'
  739. { push_type (tp_pointer); $$ = 0; }
  740. | '*' abs_decl
  741. { push_type (tp_pointer); $$ = $2; }
  742. | '&amp;'
  743. { push_type (tp_reference); $$ = 0; }
  744. | '&amp;' abs_decl
  745. { push_type (tp_reference); $$ = $2; }
  746. | direct_abs_decl
  747. ;
  748. direct_abs_decl: '(' abs_decl ')'
  749. { $$ = $2; }
  750. | direct_abs_decl array_mod
  751. {
  752. push_type_int ($2);
  753. push_type (tp_array);
  754. }
  755. | array_mod
  756. {
  757. push_type_int ($1);
  758. push_type (tp_array);
  759. $$ = 0;
  760. }
  761. | direct_abs_decl func_mod
  762. { push_type (tp_function); }
  763. | func_mod
  764. { push_type (tp_function); }
  765. ;
  766. array_mod: '[' ']'
  767. { $$ = -1; }
  768. | '[' INT ']'
  769. { $$ = $2.val; }
  770. ;
  771. func_mod: '(' ')'
  772. { $$ = 0; }
  773. | '(' nonempty_typelist ')'
  774. { free ($2); $$ = 0; }
  775. ;
  776. /* We used to try to recognize more pointer to member types here, but
  777. that didn't work (shift/reduce conflicts meant that these rules
  778. never got executed). The problem is that
  779. int (foo::bar::baz::bizzle)
  780. is a function type but
  781. int (foo::bar::baz::bizzle::*)
  782. is a pointer to member type. Stroustrup loses again! */
  783. type : ptype
  784. | typebase COLONCOLON '*'
  785. { $$ = lookup_member_type (builtin_type_int, $1); }
  786. ;
  787. typebase /* Implements (approximately): (type-qualifier)* type-specifier. */
  788. : TYPENAME
  789. { $$ = $1.type; }
  790. | CLASSNAME
  791. {
  792. if ($1.type == NULL)
  793. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  794. copy_name($1.stoken));
  795. else
  796. $$ = $1.type;
  797. }
  798. | INT_KEYWORD
  799. { $$ = builtin_type_int; }
  800. | LONG
  801. { $$ = builtin_type_long; }
  802. | SHORT
  803. { $$ = builtin_type_short; }
  804. | LONG INT_KEYWORD
  805. { $$ = builtin_type_long; }
  806. | UNSIGNED LONG INT_KEYWORD
  807. { $$ = builtin_type_unsigned_long; }
  808. | LONG LONG
  809. { $$ = builtin_type_long_long; }
  810. | LONG LONG INT_KEYWORD
  811. { $$ = builtin_type_long_long; }
  812. | UNSIGNED LONG LONG
  813. { $$ = builtin_type_unsigned_long_long; }
  814. | UNSIGNED LONG LONG INT_KEYWORD
  815. { $$ = builtin_type_unsigned_long_long; }
  816. | SHORT INT_KEYWORD
  817. { $$ = builtin_type_short; }
  818. | UNSIGNED SHORT INT_KEYWORD
  819. { $$ = builtin_type_unsigned_short; }
  820. | DOUBLE_KEYWORD
  821. { $$ = builtin_type_double; }
  822. | LONG DOUBLE_KEYWORD
  823. { $$ = builtin_type_long_double; }
  824. | STRUCT name
  825. { $$ = lookup_struct (copy_name ($2),
  826. expression_context_block); }
  827. | CLASS name
  828. { $$ = lookup_struct (copy_name ($2),
  829. expression_context_block); }
  830. | UNION name
  831. { $$ = lookup_union (copy_name ($2),
  832. expression_context_block); }
  833. | ENUM name
  834. { $$ = lookup_enum (copy_name ($2),
  835. expression_context_block); }
  836. | UNSIGNED typename
  837. { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
  838. | UNSIGNED
  839. { $$ = builtin_type_unsigned_int; }
  840. | SIGNED_KEYWORD typename
  841. { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
  842. | SIGNED_KEYWORD
  843. { $$ = builtin_type_int; }
  844. | TEMPLATE name '&lt;' type '&gt;'
  845. { $$ = lookup_template_type(copy_name($2), $4,
  846. expression_context_block);
  847. }
  848. /* &quot;const&quot; and &quot;volatile&quot; are curently ignored. A type
  849. qualifier after the type is handled in the ptype rule. I
  850. think these could be too. */
  851. | CONST_KEYWORD typebase { $$ = $2; }
  852. | VOLATILE_KEYWORD typebase { $$ = $2; }
  853. ;
  854. typename: TYPENAME
  855. | INT_KEYWORD
  856. {
  857. $$.stoken.ptr = &quot;int&quot;;
  858. $$.stoken.length = 3;
  859. $$.type = builtin_type_int;
  860. }
  861. | LONG
  862. {
  863. $$.stoken.ptr = &quot;long&quot;;
  864. $$.stoken.length = 4;
  865. $$.type = builtin_type_long;
  866. }
  867. | SHORT
  868. {
  869. $$.stoken.ptr = &quot;short&quot;;
  870. $$.stoken.length = 5;
  871. $$.type = builtin_type_short;
  872. }
  873. ;
  874. nonempty_typelist
  875. : type
  876. { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
  877. $&lt;ivec&gt;$[0] = 1; /* Number of types in vector. */
  878. $$[1] = $1;
  879. }
  880. | nonempty_typelist ',' type
  881. { int len = sizeof (struct type *) * (++($&lt;ivec&gt;1[0]) + 1);
  882. $$ = (struct type **) realloc ((char *) $1, len);
  883. $$[$&lt;ivec&gt;$[0]] = $3;
  884. }
  885. ;
  886. name : NAME { $$ = $1.stoken; }
  887. | BLOCKNAME { $$ = $1.stoken; }
  888. | TYPENAME { $$ = $1.stoken; }
  889. | CLASSNAME { $$ = $1.stoken; }
  890. | NAME_OR_INT { $$ = $1.stoken; }
  891. ;
  892. name_not_typename : NAME
  893. | BLOCKNAME
  894. /* These would be useful if name_not_typename was useful, but it is
  895. just a fake for &quot;variable&quot;, so these cause reduce/reduce conflicts
  896. because the parser can't tell whether NAME_OR_INT is a
  897. name_not_typename (=variable, =exp) or just an exp. If
  898. name_not_typename was ever used in an lvalue context where only a
  899. name could occur, this might be useful. */
  900. /* | NAME_OR_INT */
  901. ;
  902. %%
  903. /* Take care of parsing a number (anything that starts with a digit).
  904. Set yylval and return the token type; update lexptr. LEN is the
  905. number of characters in it. */
  906. /*** Needs some error checking for the float case. ***/
  907. /* APPLE LOCAL: I replaced the objc-exp.y version with the c-exp.y
  908. version. There were inessential differences which had no good
  909. purpose, and only made maintaining them harder. I really should
  910. extract this into a separate .c file &amp; #include it here. */
  911. static int
  912. parse_number (p, len, parsed_float, putithere)
  913. char *p;
  914. int len;
  915. int parsed_float;
  916. YYSTYPE *putithere;
  917. {
  918. /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
  919. here, and we do kind of silly things like cast to unsigned. */
  920. LONGEST n = 0;
  921. LONGEST prevn = 0;
  922. ULONGEST un;
  923. int i = 0;
  924. int c;
  925. int base = input_radix;
  926. int unsigned_p = 0;
  927. /* Number of &quot;L&quot; suffixes encountered. */
  928. int long_p = 0;
  929. /* We have found a &quot;L&quot; or &quot;U&quot; suffix. */
  930. int found_suffix = 0;
  931. ULONGEST high_bit;
  932. struct type *signed_type;
  933. struct type *unsigned_type;
  934. if (parsed_float)
  935. {
  936. /* It's a float since it contains a point or an exponent. */
  937. char c;
  938. int num = 0; /* number of tokens scanned by scanf */
  939. char saved_char = p[len];
  940. p[len] = 0; /* null-terminate the token */
  941. if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (float))
  942. num = sscanf (p, &quot;%g%c&quot;, (float *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  943. else if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (double))
  944. num = sscanf (p, &quot;%lg%c&quot;, (double *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  945. else
  946. {
  947. #ifdef SCANF_HAS_LONG_DOUBLE
  948. num = sscanf (p, &quot;%Lg%c&quot;, &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  949. #else
  950. /* Scan it into a double, then assign it to the long double.
  951. This at least wins with values representable in the range
  952. of doubles. */
  953. double temp;
  954. num = sscanf (p, &quot;%lg%c&quot;, &amp;temp,&amp;c);
  955. putithere-&gt;typed_val_float.dval = temp;
  956. #endif
  957. }
  958. p[len] = saved_char; /* restore the input stream */
  959. if (num == 1) /* check scanf found ONLY a float ... */
  960. putithere-&gt;typed_val_float.type =
  961. builtin_type (current_gdbarch)-&gt;builtin_double;
  962. else if (num == 2)
  963. {
  964. /* See if it has `f' or `l' suffix (float or long double). */
  965. c = tolower (p[len - 1]);
  966. /* There's no way to tell, using sscanf, whether we actually
  967. did ingest all the input. But this check will catch things
  968. like: 123fghi.jklmn, though of course it will be fooled by
  969. 123fghi.jklmf. I'm not really all that worried about this,
  970. however. */
  971. if (c != p[len-1])
  972. return ERROR;
  973. if (c == 'f')
  974. putithere-&gt;typed_val_float.type = builtin_type (current_gdbarch)-&gt;builtin_float;
  975. else if (c == 'l')
  976. putithere-&gt;typed_val_float.type = builtin_type (current_gdbarch)-&gt;builtin_long_double;
  977. else
  978. return ERROR;
  979. }
  980. else
  981. return ERROR;
  982. return FLOAT;
  983. }
  984. /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  985. if (p[0] == '0')
  986. switch (p[1])
  987. {
  988. case 'x':
  989. case 'X':
  990. if (len &gt;= 3)
  991. {
  992. p += 2;
  993. base = 16;
  994. len -= 2;
  995. }
  996. break;
  997. case 't':
  998. case 'T':
  999. case 'd':
  1000. case 'D':
  1001. if (len &gt;= 3)
  1002. {
  1003. p += 2;
  1004. base = 10;
  1005. len -= 2;
  1006. }
  1007. break;
  1008. default:
  1009. base = 8;
  1010. break;
  1011. }
  1012. while (len-- &gt; 0)
  1013. {
  1014. c = *p++;
  1015. if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')
  1016. c += 'a' - 'A';
  1017. if (c != 'l' &amp;&amp; c != 'u')
  1018. n *= base;
  1019. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1020. {
  1021. if (found_suffix)
  1022. return ERROR;
  1023. n += i = c - '0';
  1024. }
  1025. else
  1026. {
  1027. if (base &gt; 10 &amp;&amp; c &gt;= 'a' &amp;&amp; c &lt;= 'f')
  1028. {
  1029. if (found_suffix)
  1030. return ERROR;
  1031. n += i = c - 'a' + 10;
  1032. }
  1033. else if (c == 'l')
  1034. {
  1035. ++long_p;
  1036. found_suffix = 1;
  1037. }
  1038. else if (c == 'u')
  1039. {
  1040. unsigned_p = 1;
  1041. found_suffix = 1;
  1042. }
  1043. else
  1044. return ERROR; /* Char not a digit */
  1045. }
  1046. if (i &gt;= base)
  1047. return ERROR; /* Invalid digit in this base */
  1048. /* Portably test for overflow (only works for nonzero values, so make
  1049. a second check for zero). FIXME: Can't we just make n and prevn
  1050. unsigned and avoid this? */
  1051. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; (prevn &gt;= n) &amp;&amp; n != 0)
  1052. unsigned_p = 1; /* Try something unsigned */
  1053. /* Portably test for unsigned overflow.
  1054. FIXME: This check is wrong; for example it doesn't find overflow
  1055. on 0x123456789 when LONGEST is 32 bits. */
  1056. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; n != 0)
  1057. {
  1058. if ((unsigned_p &amp;&amp; (ULONGEST) prevn &gt;= (ULONGEST) n))
  1059. error (&quot;Numeric constant too large.&quot;);
  1060. }
  1061. prevn = n;
  1062. }
  1063. /* An integer constant is an int, a long, or a long long. An L
  1064. suffix forces it to be long; an LL suffix forces it to be long
  1065. long. If not forced to a larger size, it gets the first type of
  1066. the above that it fits in. To figure out whether it fits, we
  1067. shift it right and see whether anything remains. Note that we
  1068. can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  1069. operation, because many compilers will warn about such a shift
  1070. (which always produces a zero result). Sometimes TARGET_INT_BIT
  1071. or TARGET_LONG_BIT will be that big, sometimes not. To deal with
  1072. the case where it is we just always shift the value more than
  1073. once, with fewer bits each time. */
  1074. un = (ULONGEST)n &gt;&gt; 2;
  1075. if (long_p == 0
  1076. &amp;&amp; (un &gt;&gt; (TARGET_INT_BIT - 2)) == 0)
  1077. {
  1078. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_INT_BIT-1);
  1079. /* A large decimal (not hex or octal) constant (between INT_MAX
  1080. and UINT_MAX) is a long or unsigned long, according to ANSI,
  1081. never an unsigned int, but this code treats it as unsigned
  1082. int. This probably should be fixed. GCC gives a warning on
  1083. such constants. */
  1084. unsigned_type = builtin_type (current_gdbarch)-&gt;builtin_unsigned_int;
  1085. signed_type = builtin_type (current_gdbarch)-&gt;builtin_int;
  1086. }
  1087. else if (long_p &lt;= 1
  1088. &amp;&amp; (un &gt;&gt; (TARGET_LONG_BIT - 2)) == 0)
  1089. {
  1090. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_LONG_BIT-1);
  1091. unsigned_type = builtin_type (current_gdbarch)-&gt;builtin_unsigned_long;
  1092. signed_type = builtin_type (current_gdbarch)-&gt;builtin_long;
  1093. }
  1094. else
  1095. {
  1096. int shift;
  1097. if (sizeof (ULONGEST) * HOST_CHAR_BIT &lt; TARGET_LONG_LONG_BIT)
  1098. /* A long long does not fit in a LONGEST. */
  1099. shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
  1100. else
  1101. shift = (TARGET_LONG_LONG_BIT - 1);
  1102. high_bit = (ULONGEST) 1 &lt;&lt; shift;
  1103. unsigned_type = builtin_type (current_gdbarch)-&gt;builtin_unsigned_long_long;
  1104. signed_type = builtin_type (current_gdbarch)-&gt;builtin_long_long;
  1105. }
  1106. putithere-&gt;typed_val_int.val = n;
  1107. /* If the high bit of the worked out type is set then this number
  1108. has to be unsigned. */
  1109. if (unsigned_p || (n &amp; high_bit))
  1110. {
  1111. putithere-&gt;typed_val_int.type = unsigned_type;
  1112. }
  1113. else
  1114. {
  1115. putithere-&gt;typed_val_int.type = signed_type;
  1116. }
  1117. return INT;
  1118. }
  1119. struct token
  1120. {
  1121. char *operator;
  1122. int token;
  1123. enum exp_opcode opcode;
  1124. };
  1125. static const struct token tokentab3[] =
  1126. {
  1127. {&quot;&gt;&gt;=&quot;, ASSIGN_MODIFY, BINOP_RSH},
  1128. {&quot;&lt;&lt;=&quot;, ASSIGN_MODIFY, BINOP_LSH}
  1129. };
  1130. static const struct token tokentab2[] =
  1131. {
  1132. {&quot;+=&quot;, ASSIGN_MODIFY, BINOP_ADD},
  1133. {&quot;-=&quot;, ASSIGN_MODIFY, BINOP_SUB},
  1134. {&quot;*=&quot;, ASSIGN_MODIFY, BINOP_MUL},
  1135. {&quot;/=&quot;, ASSIGN_MODIFY, BINOP_DIV},
  1136. {&quot;%=&quot;, ASSIGN_MODIFY, BINOP_REM},
  1137. {&quot;|=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_IOR},
  1138. {&quot;&amp;=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_AND},
  1139. {&quot;^=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_XOR},
  1140. {&quot;++&quot;, INCREMENT, BINOP_END},
  1141. {&quot;--&quot;, DECREMENT, BINOP_END},
  1142. {&quot;-&gt;&quot;, ARROW, BINOP_END},
  1143. {&quot;&amp;&amp;&quot;, ANDAND, BINOP_END},
  1144. {&quot;||&quot;, OROR, BINOP_END},
  1145. {&quot;::&quot;, COLONCOLON, BINOP_END},
  1146. {&quot;&lt;&lt;&quot;, LSH, BINOP_END},
  1147. {&quot;&gt;&gt;&quot;, RSH, BINOP_END},
  1148. {&quot;==&quot;, EQUAL, BINOP_END},
  1149. {&quot;!=&quot;, NOTEQUAL, BINOP_END},
  1150. {&quot;&lt;=&quot;, LEQ, BINOP_END},
  1151. {&quot;&gt;=&quot;, GEQ, BINOP_END}
  1152. };
  1153. /* Read one token, getting characters through lexptr. */
  1154. static int
  1155. yylex ()
  1156. {
  1157. int c, tokchr;
  1158. int namelen;
  1159. unsigned int i;
  1160. char *tokstart;
  1161. char *tokptr;
  1162. int tempbufindex;
  1163. static char *tempbuf;
  1164. static int tempbufsize;
  1165. retry:
  1166. tokstart = lexptr;
  1167. /* See if it is a special token of length 3. */
  1168. for (i = 0; i &lt; sizeof tokentab3 / sizeof tokentab3[0]; i++)
  1169. if (DEPRECATED_STREQN (tokstart, tokentab3[i].operator, 3))
  1170. {
  1171. lexptr += 3;
  1172. yylval.opcode = tokentab3[i].opcode;
  1173. return tokentab3[i].token;
  1174. }
  1175. /* See if it is a special token of length 2. */
  1176. for (i = 0; i &lt; sizeof tokentab2 / sizeof tokentab2[0]; i++)
  1177. if (DEPRECATED_STREQN (tokstart, tokentab2[i].operator, 2))
  1178. {
  1179. lexptr += 2;
  1180. yylval.opcode = tokentab2[i].opcode;
  1181. return tokentab2[i].token;
  1182. }
  1183. /* APPLE LOCAL: initialize c to the first character here.
  1184. It's used that way below where we go to parse a number. */
  1185. switch (tokchr = c = *tokstart)
  1186. {
  1187. case 0:
  1188. return 0;
  1189. case ' ':
  1190. case '\t':
  1191. case '\n':
  1192. lexptr++;
  1193. goto retry;
  1194. case '\'':
  1195. /* We either have a character constant ('0' or '\177' for
  1196. example) or we have a quoted symbol reference ('foo(int,int)'
  1197. in C++ for example). */
  1198. lexptr++;
  1199. c = *lexptr++;
  1200. if (c == '\\')
  1201. c = parse_escape (&amp;lexptr);
  1202. else if (c == '\'')
  1203. error (&quot;Empty character constant.&quot;);
  1204. yylval.typed_val_int.val = c;
  1205. yylval.typed_val_int.type = builtin_type_char;
  1206. c = *lexptr++;
  1207. if (c != '\'')
  1208. {
  1209. namelen = skip_quoted (tokstart) - tokstart;
  1210. if (namelen &gt; 2)
  1211. {
  1212. lexptr = tokstart + namelen;
  1213. if (lexptr[-1] != '\'')
  1214. error (&quot;Unmatched single quote.&quot;);
  1215. namelen -= 2;
  1216. tokstart++;
  1217. goto tryname;
  1218. }
  1219. error (&quot;Invalid character constant.&quot;);
  1220. }
  1221. return INT;
  1222. case '(':
  1223. paren_depth++;
  1224. lexptr++;
  1225. return '(';
  1226. case ')':
  1227. if (paren_depth == 0)
  1228. return 0;
  1229. paren_depth--;
  1230. lexptr++;
  1231. return ')';
  1232. case ',':
  1233. if (comma_terminates &amp;&amp; paren_depth == 0)
  1234. return 0;
  1235. lexptr++;
  1236. return ',';
  1237. case '.':
  1238. /* Might be a floating point number. */
  1239. if (lexptr[1] &lt; '0' || lexptr[1] &gt; '9')
  1240. goto symbol; /* Nope, must be a symbol. */
  1241. /* FALL THRU into number case. */
  1242. case '0':
  1243. case '1':
  1244. case '2':
  1245. case '3':
  1246. case '4':
  1247. case '5':
  1248. case '6':
  1249. case '7':
  1250. case '8':
  1251. case '9':
  1252. {
  1253. /* APPLE LOCAL: I replaced the code here (which was probably
  1254. originally from NeXT) with the c-exp.y version. The
  1255. original objc-exp.y version claimed to do better error
  1256. checking, but I'm unconvinced of that, and in the process
  1257. it rejects all type modifiers, which seems too high a
  1258. price to pay for some unclear benefit. */
  1259. /* It's a number. */
  1260. int got_dot = 0, got_e = 0, toktype;
  1261. char *p = tokstart;
  1262. int hex = input_radix &gt; 10;
  1263. if (c == '0' &amp;&amp; (p[1] == 'x' || p[1] == 'X'))
  1264. {
  1265. p += 2;
  1266. hex = 1;
  1267. }
  1268. else if (c == '0' &amp;&amp; (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  1269. {
  1270. p += 2;
  1271. hex = 0;
  1272. }
  1273. for (;; ++p)
  1274. {
  1275. /* This test includes !hex because 'e' is a valid hex digit
  1276. and thus does not indicate a floating point number when
  1277. the radix is hex. */
  1278. if (!hex &amp;&amp; !got_e &amp;&amp; (*p == 'e' || *p == 'E'))
  1279. got_dot = got_e = 1;
  1280. /* This test does not include !hex, because a '.' always indicates
  1281. a decimal floating point number regardless of the radix. */
  1282. else if (!got_dot &amp;&amp; *p == '.')
  1283. got_dot = 1;
  1284. else if (got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E')
  1285. &amp;&amp; (*p == '-' || *p == '+'))
  1286. /* This is the sign of the exponent, not the end of the
  1287. number. */
  1288. continue;
  1289. /* We will take any letters or digits. parse_number will
  1290. complain if past the radix, or if L or U are not final. */
  1291. else if ((*p &lt; '0' || *p &gt; '9')
  1292. &amp;&amp; ((*p &lt; 'a' || *p &gt; 'z')
  1293. &amp;&amp; (*p &lt; 'A' || *p &gt; 'Z')))
  1294. break;
  1295. }
  1296. toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &amp;yylval);
  1297. if (toktype == ERROR)
  1298. {
  1299. char *err_copy = (char *) alloca (p - tokstart + 1);
  1300. memcpy (err_copy, tokstart, p - tokstart);
  1301. err_copy[p - tokstart] = 0;
  1302. error (&quot;Invalid number \&quot;%s\&quot;.&quot;, err_copy);
  1303. }
  1304. lexptr = p;
  1305. return toktype;
  1306. /* END APPLE LOCAL */
  1307. }
  1308. case '+':
  1309. case '-':
  1310. case '*':
  1311. case '/':
  1312. case '%':
  1313. case '|':
  1314. case '&amp;':
  1315. case '^':
  1316. case '~':
  1317. case '!':
  1318. #if 0
  1319. case '@': /* Moved out below. */
  1320. #endif
  1321. case '&lt;':
  1322. case '&gt;':
  1323. case '[':
  1324. case ']':
  1325. case '?':
  1326. case ':':
  1327. case '=':
  1328. case '{':
  1329. case '}':
  1330. symbol:
  1331. lexptr++;
  1332. return tokchr;
  1333. case '@':
  1334. if (strncmp(tokstart, &quot;@selector&quot;, 9) == 0)
  1335. {
  1336. tokptr = strchr(tokstart, '(');
  1337. if (tokptr == NULL)
  1338. {
  1339. error (&quot;Missing '(' in @selector(...)&quot;);
  1340. }
  1341. tempbufindex = 0;
  1342. tokptr++; /* Skip the '('. */
  1343. do {
  1344. /* Grow the static temp buffer if necessary, including
  1345. allocating the first one on demand. */
  1346. if (tempbufindex + 1 &gt;= tempbufsize)
  1347. {
  1348. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1349. }
  1350. tempbuf[tempbufindex++] = *tokptr++;
  1351. } while ((*tokptr != ')') &amp;&amp; (*tokptr != '\0'));
  1352. if (*tokptr++ != ')')
  1353. {
  1354. error (&quot;Missing ')' in @selector(...)&quot;);
  1355. }
  1356. tempbuf[tempbufindex] = '\0';
  1357. yylval.sval.ptr = tempbuf;
  1358. yylval.sval.length = tempbufindex;
  1359. lexptr = tokptr;
  1360. return SELECTOR;
  1361. }
  1362. if (tokstart[1] != '&quot;')
  1363. {
  1364. lexptr++;
  1365. return tokchr;
  1366. }
  1367. /* ObjC NextStep NSString constant: fall thru and parse like
  1368. STRING. */
  1369. tokstart++;
  1370. case '&quot;':
  1371. /* Build the gdb internal form of the input string in tempbuf,
  1372. translating any standard C escape forms seen. Note that the
  1373. buffer is null byte terminated *only* for the convenience of
  1374. debugging gdb itself and printing the buffer contents when
  1375. the buffer contains no embedded nulls. Gdb does not depend
  1376. upon the buffer being null byte terminated, it uses the
  1377. length string instead. This allows gdb to handle C strings
  1378. (as well as strings in other languages) with embedded null
  1379. bytes. */
  1380. tokptr = ++tokstart;
  1381. tempbufindex = 0;
  1382. do {
  1383. /* Grow the static temp buffer if necessary, including
  1384. allocating the first one on demand. */
  1385. if (tempbufindex + 1 &gt;= tempbufsize)
  1386. {
  1387. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1388. }
  1389. switch (*tokptr)
  1390. {
  1391. case '\0':
  1392. case '&quot;':
  1393. /* Do nothing, loop will terminate. */
  1394. break;
  1395. case '\\':
  1396. tokptr++;
  1397. c = parse_escape (&amp;tokptr);
  1398. if (c == -1)
  1399. {
  1400. continue;
  1401. }
  1402. tempbuf[tempbufindex++] = c;
  1403. break;
  1404. default:
  1405. tempbuf[tempbufindex++] = *tokptr++;
  1406. break;
  1407. }
  1408. } while ((*tokptr != '&quot;') &amp;&amp; (*tokptr != '\0'));
  1409. if (*tokptr++ != '&quot;')
  1410. {
  1411. error (&quot;Unterminated string in expression.&quot;);
  1412. }
  1413. tempbuf[tempbufindex] = '\0'; /* See note above. */
  1414. yylval.sval.ptr = tempbuf;
  1415. yylval.sval.length = tempbufindex;
  1416. lexptr = tokptr;
  1417. return (tokchr == '@' ? NSSTRING : STRING);
  1418. }
  1419. if (!(tokchr == '_' || tokchr == '$' ||
  1420. (tokchr &gt;= 'a' &amp;&amp; tokchr &lt;= 'z') || (tokchr &gt;= 'A' &amp;&amp; tokchr &lt;= 'Z')))
  1421. /* We must have come across a bad character (e.g. ';'). */
  1422. error (&quot;Invalid character '%c' in expression.&quot;, c);
  1423. /* It's a name. See how long it is. */
  1424. namelen = 0;
  1425. for (c = tokstart[namelen];
  1426. (c == '_' || c == '$' || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1427. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || c == '&lt;');)
  1428. {
  1429. if (c == '&lt;')
  1430. {
  1431. /* APPLE LOCAL: Make the template search code match the
  1432. version in c-exp.y. */
  1433. /* Template parameter lists are part of the name.
  1434. FIXME: This mishandles `print $a&lt;4&amp;&amp;$a&gt;3'. */
  1435. /* Scan ahead to get rest of the template specification. Note
  1436. that we look ahead only when the '&lt;' adjoins non-whitespace
  1437. characters; for comparison expressions, e.g. &quot;a &lt; b &gt; c&quot;,
  1438. there must be spaces before the '&lt;', etc. */
  1439. char * p = find_template_name_end (tokstart + namelen);
  1440. if (p)
  1441. namelen = p - tokstart;
  1442. break;
  1443. /* END APPLE LOCAL */
  1444. }
  1445. c = tokstart[++namelen];
  1446. }
  1447. /* The token &quot;if&quot; terminates the expression and is NOT
  1448. removed from the input stream. */
  1449. if (namelen == 2 &amp;&amp; tokstart[0] == 'i' &amp;&amp; tokstart[1] == 'f')
  1450. {
  1451. return 0;
  1452. }
  1453. lexptr += namelen;
  1454. tryname:
  1455. /* Catch specific keywords. Should be done with a data structure. */
  1456. switch (namelen)
  1457. {
  1458. case 8:
  1459. if (DEPRECATED_STREQN (tokstart, &quot;unsigned&quot;, 8))
  1460. return UNSIGNED;
  1461. if ((current_language-&gt;la_language == language_cplus
  1462. || current_language-&gt;la_language == language_objcplus)
  1463. &amp;&amp; strncmp (tokstart, &quot;template&quot;, 8) == 0)
  1464. return TEMPLATE;
  1465. if (DEPRECATED_STREQN (tokstart, &quot;volatile&quot;, 8))
  1466. return VOLATILE_KEYWORD;
  1467. break;
  1468. case 6:
  1469. if (DEPRECATED_STREQN (tokstart, &quot;struct&quot;, 6))
  1470. return STRUCT;
  1471. if (DEPRECATED_STREQN (tokstart, &quot;signed&quot;, 6))
  1472. return SIGNED_KEYWORD;
  1473. if (DEPRECATED_STREQN (tokstart, &quot;sizeof&quot;, 6))
  1474. return SIZEOF;
  1475. if (DEPRECATED_STREQN (tokstart, &quot;double&quot;, 6))
  1476. return DOUBLE_KEYWORD;
  1477. break;
  1478. case 5:
  1479. if ((current_language-&gt;la_language == language_cplus
  1480. || current_language-&gt;la_language == language_objcplus)
  1481. &amp;&amp; strncmp (tokstart, &quot;class&quot;, 5) == 0)
  1482. return CLASS;
  1483. if (DEPRECATED_STREQN (tokstart, &quot;union&quot;, 5))
  1484. return UNION;
  1485. if (DEPRECATED_STREQN (tokstart, &quot;short&quot;, 5))
  1486. return SHORT;
  1487. if (DEPRECATED_STREQN (tokstart, &quot;const&quot;, 5))
  1488. return CONST_KEYWORD;
  1489. break;
  1490. case 4:
  1491. if (DEPRECATED_STREQN (tokstart, &quot;enum&quot;, 4))
  1492. return ENUM;
  1493. if (DEPRECATED_STREQN (tokstart, &quot;long&quot;, 4))
  1494. return LONG;
  1495. break;
  1496. case 3:
  1497. if (DEPRECATED_STREQN (tokstart, &quot;int&quot;, 3))
  1498. return INT_KEYWORD;
  1499. break;
  1500. default:
  1501. break;
  1502. }
  1503. yylval.sval.ptr = tokstart;
  1504. yylval.sval.length = namelen;
  1505. if (*tokstart == '$')
  1506. {
  1507. write_dollar_variable (yylval.sval);
  1508. return VARIABLE;
  1509. }
  1510. /* Use token-type BLOCKNAME for symbols that happen to be defined as
  1511. functions or symtabs. If this is not so, then ...
  1512. Use token-type TYPENAME for symbols that happen to be defined
  1513. currently as names of types; NAME for other symbols.
  1514. The caller is not constrained to care about the distinction. */
  1515. {
  1516. char *tmp = copy_name (yylval.sval);
  1517. struct symbol *sym;
  1518. int is_a_field_of_this = 0, *need_this;
  1519. int hextype;
  1520. if (current_language-&gt;la_language == language_cplus
  1521. || current_language-&gt;la_language == language_objc
  1522. || current_language-&gt;la_language == language_objcplus)
  1523. need_this = &amp;is_a_field_of_this;
  1524. else
  1525. need_this = (int *) NULL;
  1526. sym = lookup_symbol (tmp, expression_context_block,
  1527. VAR_DOMAIN,
  1528. need_this,
  1529. (struct symtab **) NULL);
  1530. /* Call lookup_symtab, not lookup_partial_symtab, in case there
  1531. are no psymtabs (coff, xcoff, or some future change to blow
  1532. away the psymtabs once symbols are read). */
  1533. if ((sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_BLOCK) ||
  1534. lookup_symtab (tmp))
  1535. {
  1536. yylval.ssym.sym = sym;
  1537. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1538. return BLOCKNAME;
  1539. }
  1540. if (sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  1541. {
  1542. #if 1
  1543. /* Despite the following flaw, we need to keep this code
  1544. enabled. Because we can get called from
  1545. check_stub_method, if we don't handle nested types then
  1546. it screws many operations in any program which uses
  1547. nested types. */
  1548. /* In &quot;A::x&quot;, if x is a memb…

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