PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Happy | 1870 lines | 1658 code | 212 blank | 0 comment | 0 complexity | 0628a591ba1dc6499e4794cfd97e12e4 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0, GPL-2.0, ISC, LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, WTFPL, MIT, AGPL-1.0, AGPL-3.0

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

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>objc-exp.y</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">objc-exp.y&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. /* YACC parser for C expressions, for GDB.
  24. Copyright 1986, 1989, 1990, 1991, 1993, 1994, 2002 Free Software
  25. Foundation, Inc.
  26. This program is free software; you can redistribute it and/or modify
  27. it under the terms of the GNU General Public License as published by
  28. the Free Software Foundation; either version 2 of the License, or
  29. (at your option) any later version.
  30. This program is distributed in the hope that it will be useful,
  31. but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. GNU General Public License for more details.
  34. You should have received a copy of the GNU General Public License
  35. along with this program; if not, write to the Free Software
  36. Foundation, Inc., 59 Temple Place - Suite 330,
  37. Boston, MA 02111-1307, USA. */
  38. /* Parse a C expression from text in a string, and return the result
  39. as a struct expression pointer. That structure contains arithmetic
  40. operations in reverse polish, with constants represented by
  41. operations that are followed by special data. See expression.h for
  42. the details of the format. What is important here is that it can
  43. be built up sequentially during the process of parsing; the lower
  44. levels of the tree always come first in the result.
  45. Note that malloc's and realloc's in this file are transformed to
  46. xmalloc and xrealloc respectively by the same sed command in the
  47. makefile that remaps any other malloc/realloc inserted by the
  48. parser generator. Doing this with #defines and trying to control
  49. the interaction with include files (&lt;malloc.h&gt; and &lt;stdlib.h&gt; for
  50. example) just became too messy, particularly when such includes can
  51. be inserted at random times by the parser generator. */
  52. %{
  53. #include &quot;defs.h&quot;
  54. #include &quot;gdb_string.h&quot;
  55. #include &lt;ctype.h&gt;
  56. #include &quot;expression.h&quot;
  57. #include &quot;objc-lang.h&quot; /* For objc language constructs. */
  58. #include &quot;value.h&quot;
  59. #include &quot;parser-defs.h&quot;
  60. #include &quot;language.h&quot;
  61. #include &quot;c-lang.h&quot;
  62. #include &quot;bfd.h&quot; /* Required by objfiles.h. */
  63. #include &quot;symfile.h&quot; /* Required by objfiles.h. */
  64. #include &quot;objfiles.h&quot; /* For have_full_symbols and have_partial_symbols. */
  65. #include &quot;top.h&quot;
  66. #include &quot;completer.h&quot; /* For skip_quoted(). */
  67. #include &quot;block.h&quot;
  68. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
  69. etc), as well as gratuitiously global symbol names, so we can have
  70. multiple yacc generated parsers in gdb. Note that these are only
  71. the variables produced by yacc. If other parser generators (bison,
  72. byacc, etc) produce additional global names that conflict at link
  73. time, then those parser generators need to be fixed instead of
  74. adding those names to this list. */
  75. #define yymaxdepth objc_maxdepth
  76. #define yyparse objc_parse
  77. #define yylex objc_lex
  78. #define yyerror objc_error
  79. #define yylval objc_lval
  80. #define yychar objc_char
  81. #define yydebug objc_debug
  82. #define yypact objc_pact
  83. #define yyr1 objc_r1
  84. #define yyr2 objc_r2
  85. #define yydef objc_def
  86. #define yychk objc_chk
  87. #define yypgo objc_pgo
  88. #define yyact objc_act
  89. #define yyexca objc_exca
  90. #define yyerrflag objc_errflag
  91. #define yynerrs objc_nerrs
  92. #define yyps objc_ps
  93. #define yypv objc_pv
  94. #define yys objc_s
  95. #define yy_yys objc_yys
  96. #define yystate objc_state
  97. #define yytmp objc_tmp
  98. #define yyv objc_v
  99. #define yy_yyv objc_yyv
  100. #define yyval objc_val
  101. #define yylloc objc_lloc
  102. #define yyreds objc_reds /* With YYDEBUG defined */
  103. #define yytoks objc_toks /* With YYDEBUG defined */
  104. #define yyname objc_name /* With YYDEBUG defined */
  105. #define yyrule objc_rule /* With YYDEBUG defined */
  106. #define yylhs objc_yylhs
  107. #define yylen objc_yylen
  108. #define yydefred objc_yydefred
  109. #define yydgoto objc_yydgoto
  110. #define yysindex objc_yysindex
  111. #define yyrindex objc_yyrindex
  112. #define yygindex objc_yygindex
  113. #define yytable objc_yytable
  114. #define yycheck objc_yycheck
  115. #ifndef YYDEBUG
  116. #define YYDEBUG 0 /* Default to no yydebug support. */
  117. #endif
  118. int
  119. yyparse PARAMS ((void));
  120. static int
  121. yylex PARAMS ((void));
  122. void
  123. yyerror PARAMS ((char *));
  124. %}
  125. /* Although the yacc &quot;value&quot; of an expression is not used,
  126. since the result is stored in the structure being created,
  127. other node types do have values. */
  128. %union
  129. {
  130. LONGEST lval;
  131. struct {
  132. LONGEST val;
  133. struct type *type;
  134. } typed_val_int;
  135. struct {
  136. DOUBLEST dval;
  137. struct type *type;
  138. } typed_val_float;
  139. struct symbol *sym;
  140. struct type *tval;
  141. struct stoken sval;
  142. struct ttype tsym;
  143. struct symtoken ssym;
  144. int voidval;
  145. struct block *bval;
  146. enum exp_opcode opcode;
  147. struct internalvar *ivar;
  148. struct objc_class_str class;
  149. struct type **tvec;
  150. int *ivec;
  151. }
  152. %{
  153. /* YYSTYPE gets defined by %union. */
  154. static int
  155. parse_number PARAMS ((char *, int, int, YYSTYPE *));
  156. %}
  157. %type &lt;voidval&gt; exp exp1 type_exp start variable qualified_name lcurly
  158. %type &lt;lval&gt; rcurly
  159. %type &lt;tval&gt; type typebase
  160. %type &lt;tvec&gt; nonempty_typelist
  161. /* %type &lt;bval&gt; block */
  162. /* Fancy type parsing. */
  163. %type &lt;voidval&gt; func_mod direct_abs_decl abs_decl
  164. %type &lt;tval&gt; ptype
  165. %type &lt;lval&gt; array_mod
  166. %token &lt;typed_val_int&gt; INT
  167. %token &lt;typed_val_float&gt; FLOAT
  168. /* Both NAME and TYPENAME tokens represent symbols in the input, and
  169. both convey their data as strings. But a TYPENAME is a string that
  170. happens to be defined as a typedef or builtin type name (such as
  171. int or char) and a NAME is any other symbol. Contexts where this
  172. distinction is not important can use the nonterminal &quot;name&quot;, which
  173. matches either NAME or TYPENAME. */
  174. %token &lt;sval&gt; STRING
  175. %token &lt;sval&gt; NSSTRING /* ObjC Foundation &quot;NSString&quot; literal */
  176. %token &lt;sval&gt; SELECTOR /* ObjC &quot;@selector&quot; pseudo-operator */
  177. %token &lt;ssym&gt; NAME /* BLOCKNAME defined below to give it higher precedence. */
  178. %token &lt;tsym&gt; TYPENAME
  179. %token &lt;class&gt; CLASSNAME /* ObjC Class name */
  180. %type &lt;sval&gt; name
  181. %type &lt;ssym&gt; name_not_typename
  182. %type &lt;tsym&gt; typename
  183. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  184. but which would parse as a valid number in the current input radix.
  185. E.g. &quot;c&quot; when input_radix==16. Depending on the parse, it will be
  186. turned into a name or into a number. */
  187. %token &lt;ssym&gt; NAME_OR_INT
  188. %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
  189. %token TEMPLATE
  190. %token ERROR
  191. /* Special type cases, put in to allow the parser to distinguish
  192. different legal basetypes. */
  193. %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
  194. %token &lt;voidval&gt; VARIABLE
  195. %token &lt;opcode&gt; ASSIGN_MODIFY
  196. %left ','
  197. %left ABOVE_COMMA
  198. %right '=' ASSIGN_MODIFY
  199. %right '?'
  200. %left OROR
  201. %left ANDAND
  202. %left '|'
  203. %left '^'
  204. %left '&amp;'
  205. %left EQUAL NOTEQUAL
  206. %left '&lt;' '&gt;' LEQ GEQ
  207. %left LSH RSH
  208. %left '@'
  209. %left '+' '-'
  210. %left '*' '/' '%'
  211. %right UNARY INCREMENT DECREMENT
  212. %right ARROW '.' '[' '('
  213. %token &lt;ssym&gt; BLOCKNAME
  214. %type &lt;bval&gt; block
  215. %left COLONCOLON
  216. %%
  217. start : exp1
  218. | type_exp
  219. ;
  220. type_exp: type
  221. { write_exp_elt_opcode(OP_TYPE);
  222. write_exp_elt_type($1);
  223. write_exp_elt_opcode(OP_TYPE);}
  224. ;
  225. /* Expressions, including the comma operator. */
  226. exp1 : exp
  227. | exp1 ',' exp
  228. { write_exp_elt_opcode (BINOP_COMMA); }
  229. ;
  230. /* Expressions, not including the comma operator. */
  231. exp : '*' exp %prec UNARY
  232. { write_exp_elt_opcode (UNOP_IND); }
  233. ;
  234. exp : '&amp;' exp %prec UNARY
  235. { write_exp_elt_opcode (UNOP_ADDR); }
  236. ;
  237. exp : '-' exp %prec UNARY
  238. { write_exp_elt_opcode (UNOP_NEG); }
  239. ;
  240. exp : '!' exp %prec UNARY
  241. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  242. ;
  243. exp : '~' exp %prec UNARY
  244. { write_exp_elt_opcode (UNOP_COMPLEMENT); }
  245. ;
  246. exp : INCREMENT exp %prec UNARY
  247. { write_exp_elt_opcode (UNOP_PREINCREMENT); }
  248. ;
  249. exp : DECREMENT exp %prec UNARY
  250. { write_exp_elt_opcode (UNOP_PREDECREMENT); }
  251. ;
  252. exp : exp INCREMENT %prec UNARY
  253. { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
  254. ;
  255. exp : exp DECREMENT %prec UNARY
  256. { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
  257. ;
  258. exp : SIZEOF exp %prec UNARY
  259. { write_exp_elt_opcode (UNOP_SIZEOF); }
  260. ;
  261. exp : exp ARROW name
  262. { write_exp_elt_opcode (STRUCTOP_PTR);
  263. write_exp_string ($3);
  264. write_exp_elt_opcode (STRUCTOP_PTR); }
  265. ;
  266. exp : exp ARROW qualified_name
  267. { /* exp-&gt;type::name becomes exp-&gt;*(&amp;type::name) */
  268. /* Note: this doesn't work if name is a
  269. static member! FIXME */
  270. write_exp_elt_opcode (UNOP_ADDR);
  271. write_exp_elt_opcode (STRUCTOP_MPTR); }
  272. ;
  273. exp : exp ARROW '*' exp
  274. { write_exp_elt_opcode (STRUCTOP_MPTR); }
  275. ;
  276. exp : exp '.' name
  277. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  278. write_exp_string ($3);
  279. write_exp_elt_opcode (STRUCTOP_STRUCT); }
  280. ;
  281. exp : exp '.' qualified_name
  282. { /* exp.type::name becomes exp.*(&amp;type::name) */
  283. /* Note: this doesn't work if name is a
  284. static member! FIXME */
  285. write_exp_elt_opcode (UNOP_ADDR);
  286. write_exp_elt_opcode (STRUCTOP_MEMBER); }
  287. ;
  288. exp : exp '.' '*' exp
  289. { write_exp_elt_opcode (STRUCTOP_MEMBER); }
  290. ;
  291. exp : exp '[' exp1 ']'
  292. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  293. ;
  294. /*
  295. * The rules below parse ObjC message calls of the form:
  296. * '[' target selector {':' argument}* ']'
  297. */
  298. exp : '[' TYPENAME
  299. {
  300. CORE_ADDR class;
  301. class = lookup_objc_class (copy_name ($2.stoken));
  302. if (class == 0)
  303. error (&quot;%s is not an ObjC Class&quot;,
  304. copy_name ($2.stoken));
  305. write_exp_elt_opcode (OP_LONG);
  306. write_exp_elt_type (builtin_type_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. /* C++/ObjC: it hangs off of `this'/'self'.
  662. Must not inadvertently convert from a
  663. method call to data ref. */
  664. if (innermost_block == 0 ||
  665. contained_in (block_found, innermost_block))
  666. innermost_block = block_found;
  667. write_exp_elt_opcode (OP_OBJC_SELF);
  668. write_exp_elt_opcode (OP_OBJC_SELF);
  669. write_exp_elt_opcode (STRUCTOP_PTR);
  670. write_exp_string ($1.stoken);
  671. write_exp_elt_opcode (STRUCTOP_PTR);
  672. }
  673. else
  674. {
  675. struct minimal_symbol *msymbol;
  676. char *arg = copy_name ($1.stoken);
  677. msymbol =
  678. lookup_minimal_symbol (arg, NULL, NULL);
  679. if (msymbol != NULL)
  680. {
  681. write_exp_msymbol (msymbol,
  682. lookup_function_type (builtin_type_int),
  683. builtin_type_int);
  684. }
  685. else if (!have_full_symbols () &amp;&amp;
  686. !have_partial_symbols ())
  687. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  688. else
  689. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  690. copy_name ($1.stoken));
  691. }
  692. }
  693. ;
  694. ptype : typebase
  695. /* &quot;const&quot; and &quot;volatile&quot; are curently ignored. A type
  696. qualifier before the type is currently handled in the
  697. typebase rule. The reason for recognizing these here
  698. (shift/reduce conflicts) might be obsolete now that some
  699. pointer to member rules have been deleted. */
  700. | typebase CONST_KEYWORD
  701. | typebase VOLATILE_KEYWORD
  702. | typebase abs_decl
  703. { $$ = follow_types ($1); }
  704. | typebase CONST_KEYWORD abs_decl
  705. { $$ = follow_types ($1); }
  706. | typebase VOLATILE_KEYWORD abs_decl
  707. { $$ = follow_types ($1); }
  708. ;
  709. abs_decl: '*'
  710. { push_type (tp_pointer); $$ = 0; }
  711. | '*' abs_decl
  712. { push_type (tp_pointer); $$ = $2; }
  713. | '&amp;'
  714. { push_type (tp_reference); $$ = 0; }
  715. | '&amp;' abs_decl
  716. { push_type (tp_reference); $$ = $2; }
  717. | direct_abs_decl
  718. ;
  719. direct_abs_decl: '(' abs_decl ')'
  720. { $$ = $2; }
  721. | direct_abs_decl array_mod
  722. {
  723. push_type_int ($2);
  724. push_type (tp_array);
  725. }
  726. | array_mod
  727. {
  728. push_type_int ($1);
  729. push_type (tp_array);
  730. $$ = 0;
  731. }
  732. | direct_abs_decl func_mod
  733. { push_type (tp_function); }
  734. | func_mod
  735. { push_type (tp_function); }
  736. ;
  737. array_mod: '[' ']'
  738. { $$ = -1; }
  739. | '[' INT ']'
  740. { $$ = $2.val; }
  741. ;
  742. func_mod: '(' ')'
  743. { $$ = 0; }
  744. | '(' nonempty_typelist ')'
  745. { free ($2); $$ = 0; }
  746. ;
  747. /* We used to try to recognize more pointer to member types here, but
  748. that didn't work (shift/reduce conflicts meant that these rules
  749. never got executed). The problem is that
  750. int (foo::bar::baz::bizzle)
  751. is a function type but
  752. int (foo::bar::baz::bizzle::*)
  753. is a pointer to member type. Stroustrup loses again! */
  754. type : ptype
  755. | typebase COLONCOLON '*'
  756. { $$ = lookup_member_type (builtin_type_int, $1); }
  757. ;
  758. typebase /* Implements (approximately): (type-qualifier)* type-specifier. */
  759. : TYPENAME
  760. { $$ = $1.type; }
  761. | CLASSNAME
  762. {
  763. if ($1.type == NULL)
  764. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  765. copy_name($1.stoken));
  766. else
  767. $$ = $1.type;
  768. }
  769. | INT_KEYWORD
  770. { $$ = builtin_type_int; }
  771. | LONG
  772. { $$ = builtin_type_long; }
  773. | SHORT
  774. { $$ = builtin_type_short; }
  775. | LONG INT_KEYWORD
  776. { $$ = builtin_type_long; }
  777. | UNSIGNED LONG INT_KEYWORD
  778. { $$ = builtin_type_unsigned_long; }
  779. | LONG LONG
  780. { $$ = builtin_type_long_long; }
  781. | LONG LONG INT_KEYWORD
  782. { $$ = builtin_type_long_long; }
  783. | UNSIGNED LONG LONG
  784. { $$ = builtin_type_unsigned_long_long; }
  785. | UNSIGNED LONG LONG INT_KEYWORD
  786. { $$ = builtin_type_unsigned_long_long; }
  787. | SHORT INT_KEYWORD
  788. { $$ = builtin_type_short; }
  789. | UNSIGNED SHORT INT_KEYWORD
  790. { $$ = builtin_type_unsigned_short; }
  791. | DOUBLE_KEYWORD
  792. { $$ = builtin_type_double; }
  793. | LONG DOUBLE_KEYWORD
  794. { $$ = builtin_type_long_double; }
  795. | STRUCT name
  796. { $$ = lookup_struct (copy_name ($2),
  797. expression_context_block); }
  798. | CLASS name
  799. { $$ = lookup_struct (copy_name ($2),
  800. expression_context_block); }
  801. | UNION name
  802. { $$ = lookup_union (copy_name ($2),
  803. expression_context_block); }
  804. | ENUM name
  805. { $$ = lookup_enum (copy_name ($2),
  806. expression_context_block); }
  807. | UNSIGNED typename
  808. { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
  809. | UNSIGNED
  810. { $$ = builtin_type_unsigned_int; }
  811. | SIGNED_KEYWORD typename
  812. { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
  813. | SIGNED_KEYWORD
  814. { $$ = builtin_type_int; }
  815. | TEMPLATE name '&lt;' type '&gt;'
  816. { $$ = lookup_template_type(copy_name($2), $4,
  817. expression_context_block);
  818. }
  819. /* &quot;const&quot; and &quot;volatile&quot; are curently ignored. A type
  820. qualifier after the type is handled in the ptype rule. I
  821. think these could be too. */
  822. | CONST_KEYWORD typebase { $$ = $2; }
  823. | VOLATILE_KEYWORD typebase { $$ = $2; }
  824. ;
  825. typename: TYPENAME
  826. | INT_KEYWORD
  827. {
  828. $$.stoken.ptr = &quot;int&quot;;
  829. $$.stoken.length = 3;
  830. $$.type = builtin_type_int;
  831. }
  832. | LONG
  833. {
  834. $$.stoken.ptr = &quot;long&quot;;
  835. $$.stoken.length = 4;
  836. $$.type = builtin_type_long;
  837. }
  838. | SHORT
  839. {
  840. $$.stoken.ptr = &quot;short&quot;;
  841. $$.stoken.length = 5;
  842. $$.type = builtin_type_short;
  843. }
  844. ;
  845. nonempty_typelist
  846. : type
  847. { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
  848. $&lt;ivec&gt;$[0] = 1; /* Number of types in vector. */
  849. $$[1] = $1;
  850. }
  851. | nonempty_typelist ',' type
  852. { int len = sizeof (struct type *) * (++($&lt;ivec&gt;1[0]) + 1);
  853. $$ = (struct type **) realloc ((char *) $1, len);
  854. $$[$&lt;ivec&gt;$[0]] = $3;
  855. }
  856. ;
  857. name : NAME { $$ = $1.stoken; }
  858. | BLOCKNAME { $$ = $1.stoken; }
  859. | TYPENAME { $$ = $1.stoken; }
  860. | CLASSNAME { $$ = $1.stoken; }
  861. | NAME_OR_INT { $$ = $1.stoken; }
  862. ;
  863. name_not_typename : NAME
  864. | BLOCKNAME
  865. /* These would be useful if name_not_typename was useful, but it is
  866. just a fake for &quot;variable&quot;, so these cause reduce/reduce conflicts
  867. because the parser can't tell whether NAME_OR_INT is a
  868. name_not_typename (=variable, =exp) or just an exp. If
  869. name_not_typename was ever used in an lvalue context where only a
  870. name could occur, this might be useful. */
  871. /* | NAME_OR_INT */
  872. ;
  873. %%
  874. /* Take care of parsing a number (anything that starts with a digit).
  875. Set yylval and return the token type; update lexptr. LEN is the
  876. number of characters in it. */
  877. /*** Needs some error checking for the float case. ***/
  878. /* APPLE LOCAL: I replaced the objc-exp.y version with the c-exp.y
  879. version. There were inessential differences which had no good
  880. purpose, and only made maintaining them harder. I really should
  881. extract this into a separate .c file &amp; #include it here. */
  882. static int
  883. parse_number (p, len, parsed_float, putithere)
  884. char *p;
  885. int len;
  886. int parsed_float;
  887. YYSTYPE *putithere;
  888. {
  889. /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
  890. here, and we do kind of silly things like cast to unsigned. */
  891. LONGEST n = 0;
  892. LONGEST prevn = 0;
  893. ULONGEST un;
  894. int i = 0;
  895. int c;
  896. int base = input_radix;
  897. int unsigned_p = 0;
  898. /* Number of &quot;L&quot; suffixes encountered. */
  899. int long_p = 0;
  900. /* We have found a &quot;L&quot; or &quot;U&quot; suffix. */
  901. int found_suffix = 0;
  902. ULONGEST high_bit;
  903. struct type *signed_type;
  904. struct type *unsigned_type;
  905. if (parsed_float)
  906. {
  907. /* It's a float since it contains a point or an exponent. */
  908. char c;
  909. int num = 0; /* number of tokens scanned by scanf */
  910. char saved_char = p[len];
  911. p[len] = 0; /* null-terminate the token */
  912. if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (float))
  913. num = sscanf (p, &quot;%g%c&quot;, (float *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  914. else if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (double))
  915. num = sscanf (p, &quot;%lg%c&quot;, (double *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  916. else
  917. {
  918. #ifdef SCANF_HAS_LONG_DOUBLE
  919. num = sscanf (p, &quot;%Lg%c&quot;, &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  920. #else
  921. /* Scan it into a double, then assign it to the long double.
  922. This at least wins with values representable in the range
  923. of doubles. */
  924. double temp;
  925. num = sscanf (p, &quot;%lg%c&quot;, &amp;temp,&amp;c);
  926. putithere-&gt;typed_val_float.dval = temp;
  927. #endif
  928. }
  929. p[len] = saved_char; /* restore the input stream */
  930. if (num == 1) /* check scanf found ONLY a float ... */
  931. putithere-&gt;typed_val_float.type =
  932. builtin_type (current_gdbarch)-&gt;builtin_double;
  933. else if (num == 2)
  934. {
  935. /* See if it has `f' or `l' suffix (float or long double). */
  936. c = tolower (p[len - 1]);
  937. /* There's no way to tell, using sscanf, whether we actually
  938. did ingest all the input. But this check will catch things
  939. like: 123fghi.jklmn, though of course it will be fooled by
  940. 123fghi.jklmf. I'm not really all that worried about this,
  941. however. */
  942. if (c != p[len-1])
  943. return ERROR;
  944. if (c == 'f')
  945. putithere-&gt;typed_val_float.type = builtin_type (current_gdbarch)-&gt;builtin_float;
  946. else if (c == 'l')
  947. putithere-&gt;typed_val_float.type = builtin_type (current_gdbarch)-&gt;builtin_long_double;
  948. else
  949. return ERROR;
  950. }
  951. else
  952. return ERROR;
  953. return FLOAT;
  954. }
  955. /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  956. if (p[0] == '0')
  957. switch (p[1])
  958. {
  959. case 'x':
  960. case 'X':
  961. if (len &gt;= 3)
  962. {
  963. p += 2;
  964. base = 16;
  965. len -= 2;
  966. }
  967. break;
  968. case 't':
  969. case 'T':
  970. case 'd':
  971. case 'D':
  972. if (len &gt;= 3)
  973. {
  974. p += 2;
  975. base = 10;
  976. len -= 2;
  977. }
  978. break;
  979. default:
  980. base = 8;
  981. break;
  982. }
  983. while (len-- &gt; 0)
  984. {
  985. c = *p++;
  986. if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')
  987. c += 'a' - 'A';
  988. if (c != 'l' &amp;&amp; c != 'u')
  989. n *= base;
  990. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  991. {
  992. if (found_suffix)
  993. return ERROR;
  994. n += i = c - '0';
  995. }
  996. else
  997. {
  998. if (base &gt; 10 &amp;&amp; c &gt;= 'a' &amp;&amp; c &lt;= 'f')
  999. {
  1000. if (found_suffix)
  1001. return ERROR;
  1002. n += i = c - 'a' + 10;
  1003. }
  1004. else if (c == 'l')
  1005. {
  1006. ++long_p;
  1007. found_suffix = 1;
  1008. }
  1009. else if (c == 'u')
  1010. {
  1011. unsigned_p = 1;
  1012. found_suffix = 1;
  1013. }
  1014. else
  1015. return ERROR; /* Char not a digit */
  1016. }
  1017. if (i &gt;= base)
  1018. return ERROR; /* Invalid digit in this base */
  1019. /* Portably test for overflow (only works for nonzero values, so make
  1020. a second check for zero). FIXME: Can't we just make n and prevn
  1021. unsigned and avoid this? */
  1022. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; (prevn &gt;= n) &amp;&amp; n != 0)
  1023. unsigned_p = 1; /* Try something unsigned */
  1024. /* Portably test for unsigned overflow.
  1025. FIXME: This check is wrong; for example it doesn't find overflow
  1026. on 0x123456789 when LONGEST is 32 bits. */
  1027. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; n != 0)
  1028. {
  1029. if ((unsigned_p &amp;&amp; (ULONGEST) prevn &gt;= (ULONGEST) n))
  1030. error (&quot;Numeric constant too large.&quot;);
  1031. }
  1032. prevn = n;
  1033. }
  1034. /* An integer constant is an int, a long, or a long long. An L
  1035. suffix forces it to be long; an LL suffix forces it to be long
  1036. long. If not forced to a larger size, it gets the first type of
  1037. the above that it fits in. To figure out whether it fits, we
  1038. shift it right and see whether anything remains. Note that we
  1039. can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  1040. operation, because many compilers will warn about such a shift
  1041. (which always produces a zero result). Sometimes TARGET_INT_BIT
  1042. or TARGET_LONG_BIT will be that big, sometimes not. To deal with
  1043. the case where it is we just always shift the value more than
  1044. once, with fewer bits each time. */
  1045. un = (ULONGEST)n &gt;&gt; 2;
  1046. if (long_p == 0
  1047. &amp;&amp; (un &gt;&gt; (TARGET_INT_BIT - 2)) == 0)
  1048. {
  1049. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_INT_BIT-1);
  1050. /* A large decimal (not hex or octal) constant (between INT_MAX
  1051. and UINT_MAX) is a long or unsigned long, according to ANSI,
  1052. never an unsigned int, but this code treats it as unsigned
  1053. int. This probably should be fixed. GCC gives a warning on
  1054. such constants. */
  1055. unsigned_type = builtin_type (current_gdbarch)-&gt;builtin_unsigned_int;
  1056. signed_type = builtin_type (current_gdbarch)-&gt;builtin_int;
  1057. }
  1058. else if (long_p &lt;= 1
  1059. &amp;&amp; (un &gt;&gt; (TARGET_LONG_BIT - 2)) == 0)
  1060. {
  1061. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_LONG_BIT-1);
  1062. unsigned_type = builtin_type (current_gdbarch)-&gt;builtin_unsigned_long;
  1063. signed_type = builtin_type (current_gdbarch)-&gt;builtin_long;
  1064. }
  1065. else
  1066. {
  1067. int shift;
  1068. if (sizeof (ULONGEST) * HOST_CHAR_BIT &lt; TARGET_LONG_LONG_BIT)
  1069. /* A long long does not fit in a LONGEST. */
  1070. shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
  1071. else
  1072. shift = (TARGET_LONG_LONG_BIT - 1);
  1073. high_bit = (ULONGEST) 1 &lt;&lt; shift;
  1074. unsigned_type = builtin_type (current_gdbarch)-&gt;builtin_unsigned_long_long;
  1075. signed_type = builtin_type (current_gdbarch)-&gt;builtin_long_long;
  1076. }
  1077. putithere-&gt;typed_val_int.val = n;
  1078. /* If the high bit of the worked out type is set then this number
  1079. has to be unsigned. */
  1080. if (unsigned_p || (n &amp; high_bit))
  1081. {
  1082. putithere-&gt;typed_val_int.type = unsigned_type;
  1083. }
  1084. else
  1085. {
  1086. putithere-&gt;typed_val_int.type = signed_type;
  1087. }
  1088. return INT;
  1089. }
  1090. struct token
  1091. {
  1092. char *operator;
  1093. int token;
  1094. enum exp_opcode opcode;
  1095. };
  1096. static const struct token tokentab3[] =
  1097. {
  1098. {&quot;&gt;&gt;=&quot;, ASSIGN_MODIFY, BINOP_RSH},
  1099. {&quot;&lt;&lt;=&quot;, ASSIGN_MODIFY, BINOP_LSH}
  1100. };
  1101. static const struct token tokentab2[] =
  1102. {
  1103. {&quot;+=&quot;, ASSIGN_MODIFY, BINOP_ADD},
  1104. {&quot;-=&quot;, ASSIGN_MODIFY, BINOP_SUB},
  1105. {&quot;*=&quot;, ASSIGN_MODIFY, BINOP_MUL},
  1106. {&quot;/=&quot;, ASSIGN_MODIFY, BINOP_DIV},
  1107. {&quot;%=&quot;, ASSIGN_MODIFY, BINOP_REM},
  1108. {&quot;|=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_IOR},
  1109. {&quot;&amp;=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_AND},
  1110. {&quot;^=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_XOR},
  1111. {&quot;++&quot;, INCREMENT, BINOP_END},
  1112. {&quot;--&quot;, DECREMENT, BINOP_END},
  1113. {&quot;-&gt;&quot;, ARROW, BINOP_END},
  1114. {&quot;&amp;&amp;&quot;, ANDAND, BINOP_END},
  1115. {&quot;||&quot;, OROR, BINOP_END},
  1116. {&quot;::&quot;, COLONCOLON, BINOP_END},
  1117. {&quot;&lt;&lt;&quot;, LSH, BINOP_END},
  1118. {&quot;&gt;&gt;&quot;, RSH, BINOP_END},
  1119. {&quot;==&quot;, EQUAL, BINOP_END},
  1120. {&quot;!=&quot;, NOTEQUAL, BINOP_END},
  1121. {&quot;&lt;=&quot;, LEQ, BINOP_END},
  1122. {&quot;&gt;=&quot;, GEQ, BINOP_END}
  1123. };
  1124. /* Read one token, getting characters through lexptr. */
  1125. static int
  1126. yylex ()
  1127. {
  1128. int c, tokchr;
  1129. int namelen;
  1130. unsigned int i;
  1131. char *tokstart;
  1132. char *tokptr;
  1133. int tempbufindex;
  1134. static char *tempbuf;
  1135. static int tempbufsize;
  1136. retry:
  1137. tokstart = lexptr;
  1138. /* See if it is a special token of length 3. */
  1139. for (i = 0; i &lt; sizeof tokentab3 / sizeof tokentab3[0]; i++)
  1140. if (DEPRECATED_STREQN (tokstart, tokentab3[i].operator, 3))
  1141. {
  1142. lexptr += 3;
  1143. yylval.opcode = tokentab3[i].opcode;
  1144. return tokentab3[i].token;
  1145. }
  1146. /* See if it is a special token of length 2. */
  1147. for (i = 0; i &lt; sizeof tokentab2 / sizeof tokentab2[0]; i++)
  1148. if (DEPRECATED_STREQN (tokstart, tokentab2[i].operator, 2))
  1149. {
  1150. lexptr += 2;
  1151. yylval.opcode = tokentab2[i].opcode;
  1152. return tokentab2[i].token;
  1153. }
  1154. /* APPLE LOCAL: initialize c to the first character here.
  1155. It's used that way below where we go to parse a number. */
  1156. switch (tokchr = c = *tokstart)
  1157. {
  1158. case 0:
  1159. return 0;
  1160. case ' ':
  1161. case '\t':
  1162. case '\n':
  1163. lexptr++;
  1164. goto retry;
  1165. case '\'':
  1166. /* We either have a character constant ('0' or '\177' for
  1167. example) or we have a quoted symbol reference ('foo(int,int)'
  1168. in C++ for example). */
  1169. lexptr++;
  1170. c = *lexptr++;
  1171. if (c == '\\')
  1172. c = parse_escape (&amp;lexptr);
  1173. else if (c == '\'')
  1174. error (&quot;Empty character constant.&quot;);
  1175. yylval.typed_val_int.val = c;
  1176. yylval.typed_val_int.type = builtin_type_char;
  1177. c = *lexptr++;
  1178. if (c != '\'')
  1179. {
  1180. namelen = skip_quoted (tokstart) - tokstart;
  1181. if (namelen &gt; 2)
  1182. {
  1183. lexptr = tokstart + namelen;
  1184. if (lexptr[-1] != '\'')
  1185. error (&quot;Unmatched single quote.&quot;);
  1186. namelen -= 2;
  1187. tokstart++;
  1188. goto tryname;
  1189. }
  1190. error (&quot;Invalid character constant.&quot;);
  1191. }
  1192. return INT;
  1193. case '(':
  1194. paren_depth++;
  1195. lexptr++;
  1196. return '(';
  1197. case ')':
  1198. if (paren_depth == 0)
  1199. return 0;
  1200. paren_depth--;
  1201. lexptr++;
  1202. return ')';
  1203. case ',':
  1204. if (comma_terminates &amp;&amp; paren_depth == 0)
  1205. return 0;
  1206. lexptr++;
  1207. return ',';
  1208. case '.':
  1209. /* Might be a floating point number. */
  1210. if (lexptr[1] &lt; '0' || lexptr[1] &gt; '9')
  1211. goto symbol; /* Nope, must be a symbol. */
  1212. /* FALL THRU into number case. */
  1213. case '0':
  1214. case '1':
  1215. case '2':
  1216. case '3':
  1217. case '4':
  1218. case '5':
  1219. case '6':
  1220. case '7':
  1221. case '8':
  1222. case '9':
  1223. {
  1224. /* APPLE LOCAL: I replaced the code here (which was probably
  1225. originally from NeXT) with the c-exp.y version. The
  1226. original objc-exp.y version claimed to do better error
  1227. checking, but I'm unconvinced of that, and in the process
  1228. it rejects all type modifiers, which seems too high a
  1229. price to pay for some unclear benefit. */
  1230. /* It's a number. */
  1231. int got_dot = 0, got_e = 0, toktype;
  1232. char *p = tokstart;
  1233. int hex = input_radix &gt; 10;
  1234. if (c == '0' &amp;&amp; (p[1] == 'x' || p[1] == 'X'))
  1235. {
  1236. p += 2;
  1237. hex = 1;
  1238. }
  1239. else if (c == '0' &amp;&amp; (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  1240. {
  1241. p += 2;
  1242. hex = 0;
  1243. }
  1244. for (;; ++p)
  1245. {
  1246. /* This test includes !hex because 'e' is a valid hex digit
  1247. and thus does not indicate a floating point number when
  1248. the radix is hex. */
  1249. if (!hex &amp;&amp; !got_e &amp;&amp; (*p == 'e' || *p == 'E'))
  1250. got_dot = got_e = 1;
  1251. /* This test does not include !hex, because a '.' always indicates
  1252. a decimal floating point number regardless of the radix. */
  1253. else if (!got_dot &amp;&amp; *p == '.')
  1254. got_dot = 1;
  1255. else if (got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E')
  1256. &amp;&amp; (*p == '-' || *p == '+'))
  1257. /* This is the sign of the exponent, not the end of the
  1258. number. */
  1259. continue;
  1260. /* We will take any letters or digits. parse_number will
  1261. complain if past the radix, or if L or U are not final. */
  1262. else if ((*p &lt; '0' || *p &gt; '9')
  1263. &amp;&amp; ((*p &lt; 'a' || *p &gt; 'z')
  1264. &amp;&amp; (*p &lt; 'A' || *p &gt; 'Z')))
  1265. break;
  1266. }
  1267. toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &amp;yylval);
  1268. if (toktype == ERROR)
  1269. {
  1270. char *err_copy = (char *) alloca (p - tokstart + 1);
  1271. memcpy (err_copy, tokstart, p - tokstart);
  1272. err_copy[p - tokstart] = 0;
  1273. error (&quot;Invalid number \&quot;%s\&quot;.&quot;, err_copy);
  1274. }
  1275. lexptr = p;
  1276. return toktype;
  1277. /* END APPLE LOCAL */
  1278. }
  1279. case '+':
  1280. case '-':
  1281. case '*':
  1282. case '/':
  1283. case '%':
  1284. case '|':
  1285. case '&amp;':
  1286. case '^':
  1287. case '~':
  1288. case '!':
  1289. #if 0
  1290. case '@': /* Moved out below. */
  1291. #endif
  1292. case '&lt;':
  1293. case '&gt;':
  1294. case '[':
  1295. case ']':
  1296. case '?':
  1297. case ':':
  1298. case '=':
  1299. case '{':
  1300. case '}':
  1301. symbol:
  1302. lexptr++;
  1303. return tokchr;
  1304. case '@':
  1305. if (strncmp(tokstart, &quot;@selector&quot;, 9) == 0)
  1306. {
  1307. tokptr = strchr(tokstart, '(');
  1308. if (tokptr == NULL)
  1309. {
  1310. error (&quot;Missing '(' in @selector(...)&quot;);
  1311. }
  1312. tempbufindex = 0;
  1313. tokptr++; /* Skip the '('. */
  1314. do {
  1315. /* Grow the static temp buffer if necessary, including
  1316. allocating the first one on demand. */
  1317. if (tempbufindex + 1 &gt;= tempbufsize)
  1318. {
  1319. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1320. }
  1321. tempbuf[tempbufindex++] = *tokptr++;
  1322. } while ((*tokptr != ')') &amp;&amp; (*tokptr != '\0'));
  1323. if (*tokptr++ != ')')
  1324. {
  1325. error (&quot;Missing ')' in @selector(...)&quot;);
  1326. }
  1327. tempbuf[tempbufindex] = '\0';
  1328. yylval.sval.ptr = tempbuf;
  1329. yylval.sval.length = tempbufindex;
  1330. lexptr = tokptr;
  1331. return SELECTOR;
  1332. }
  1333. if (tokstart[1] != '&quot;')
  1334. {
  1335. lexptr++;
  1336. return tokchr;
  1337. }
  1338. /* ObjC NextStep NSString constant: fall thru and parse like
  1339. STRING. */
  1340. tokstart++;
  1341. case '&quot;':
  1342. /* Build the gdb internal form of the input string in tempbuf,
  1343. translating any standard C escape forms seen. Note that the
  1344. buffer is null byte terminated *only* for the convenience of
  1345. debugging gdb itself and printing the buffer contents when
  1346. the buffer contains no embedded nulls. Gdb does not depend
  1347. upon the buffer being null byte terminated, it uses the
  1348. length string instead. This allows gdb to handle C strings
  1349. (as well as strings in other languages) with embedded null
  1350. bytes. */
  1351. tokptr = ++tokstart;
  1352. tempbufindex = 0;
  1353. do {
  1354. /* Grow the static temp buffer if necessary, including
  1355. allocating the first one on demand. */
  1356. if (tempbufindex + 1 &gt;= tempbufsize)
  1357. {
  1358. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1359. }
  1360. switch (*tokptr)
  1361. {
  1362. case '\0':
  1363. case '&quot;':
  1364. /* Do nothing, loop will terminate. */
  1365. break;
  1366. case '\\':
  1367. tokptr++;
  1368. c = parse_escape (&amp;tokptr);
  1369. if (c == -1)
  1370. {
  1371. continue;
  1372. }
  1373. tempbuf[tempbufindex++] = c;
  1374. break;
  1375. default:
  1376. tempbuf[tempbufindex++] = *tokptr++;
  1377. break;
  1378. }
  1379. } while ((*tokptr != '&quot;') &amp;&amp; (*tokptr != '\0'));
  1380. if (*tokptr++ != '&quot;')
  1381. {
  1382. error (&quot;Unterminated string in expression.&quot;);
  1383. }
  1384. tempbuf[tempbufindex] = '\0'; /* See note above. */
  1385. yylval.sval.ptr = tempbuf;
  1386. yylval.sval.length = tempbufindex;
  1387. lexptr = tokptr;
  1388. return (tokchr == '@' ? NSSTRING : STRING);
  1389. }
  1390. if (!(tokchr == '_' || tokchr == '$' ||
  1391. (tokchr &gt;= 'a' &amp;&amp; tokchr &lt;= 'z') || (tokchr &gt;= 'A' &amp;&amp; tokchr &lt;= 'Z')))
  1392. /* We must have come across a bad character (e.g. ';'). */
  1393. error (&quot;Invalid character '%c' in expression.&quot;, c);
  1394. /* It's a name. See how long it is. */
  1395. namelen = 0;
  1396. for (c = tokstart[namelen];
  1397. (c == '_' || c == '$' || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1398. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || c == '&lt;');)
  1399. {
  1400. if (c == '&lt;')
  1401. {
  1402. /* APPLE LOCAL: Make the template search code match the
  1403. version in c-exp.y. */
  1404. /* Template parameter lists are part of the name.
  1405. FIXME: This mishandles `print $a&lt;4&amp;&amp;$a&gt;3'. */
  1406. /* Scan ahead to get rest of the template specification. Note
  1407. that we look ahead only when the '&lt;' adjoins non-whitespace
  1408. characters; for comparison expressions, e.g. &quot;a &lt; b &gt; c&quot;,
  1409. there must be spaces before the '&lt;', etc. */
  1410. char * p = find_template_name_end (tokstart + namelen);
  1411. if (p)
  1412. namelen = p - tokstart;
  1413. break;
  1414. /* END APPLE LOCAL */
  1415. }
  1416. c = tokstart[++namelen];
  1417. }
  1418. /* The token &quot;if&quot; terminates the expression and is NOT
  1419. removed from the input stream. */
  1420. if (namelen == 2 &amp;&amp; tokstart[0] == 'i' &amp;&amp; tokstart[1] == 'f')
  1421. {
  1422. return 0;
  1423. }
  1424. lexptr += namelen;
  1425. tryname:
  1426. /* Catch specific keywords. Should be done with a data structure. */
  1427. switch (namelen)
  1428. {
  1429. case 8:
  1430. if (DEPRECATED_STREQN (tokstart, &quot;unsigned&quot;, 8))
  1431. return UNSIGNED;
  1432. if ((current_language-&gt;la_language == language_cplus
  1433. || current_language-&gt;la_language == language_objcplus)
  1434. &amp;&amp; strncmp (tokstart, &quot;template&quot;, 8) == 0)
  1435. return TEMPLATE;
  1436. if (DEPRECATED_STREQN (tokstart, &quot;volatile&quot;, 8))
  1437. return VOLATILE_KEYWORD;
  1438. break;
  1439. case 6:
  1440. if (DEPRECATED_STREQN (tokstart, &quot;struct&quot;, 6))
  1441. return STRUCT;
  1442. if (DEPRECATED_STREQN (tokstart, &quot;signed&quot;, 6))
  1443. return SIGNED_KEYWORD;
  1444. if (DEPRECATED_STREQN (tokstart, &quot;sizeof&quot;, 6))
  1445. return SIZEOF;
  1446. if (DEPRECATED_STREQN (tokstart, &quot;double&quot;, 6))
  1447. return DOUBLE_KEYWORD;
  1448. break;
  1449. case 5:
  1450. if ((current_language-&gt;la_language == language_cplus
  1451. || current_language-&gt;la_language == language_objcplus)
  1452. &amp;&amp; strncmp (tokstart, &quot;class&quot;, 5) == 0)
  1453. return CLASS;
  1454. if (DEPRECATED_STREQN (tokstart, &quot;union&quot;, 5))
  1455. return UNION;
  1456. if (DEPRECATED_STREQN (tokstart, &quot;short&quot;, 5))
  1457. return SHORT;
  1458. if (DEPRECATED_STREQN (tokstart, &quot;const&quot;, 5))
  1459. return CONST_KEYWORD;
  1460. break;
  1461. case 4:
  1462. if (DEPRECATED_STREQN (tokstart, &quot;enum&quot;, 4))
  1463. return ENUM;
  1464. if (DEPRECATED_STREQN (tokstart, &quot;long&quot;, 4))
  1465. return LONG;
  1466. break;
  1467. case 3:
  1468. if (DEPRECATED_STREQN (tokstart, &quot;int&quot;, 3))
  1469. return INT_KEYWORD;
  1470. break;
  1471. default:
  1472. break;
  1473. }
  1474. yylval.sval.ptr = tokstart;
  1475. yylval.sval.length = namelen;
  1476. if (*tokstart == '$')
  1477. {
  1478. write_dollar_variable (yylval.sval);
  1479. return VARIABLE;
  1480. }
  1481. /* Use token-type BLOCKNAME for symbols that happen to be defined as
  1482. functions or symtabs. If this is not so, then ...
  1483. Use token-type TYPENAME for symbols that happen to be defined
  1484. currently as names of types; NAME for other symbols.
  1485. The caller is not constrained to care about the distinction. */
  1486. {
  1487. char *tmp = copy_name (yylval.sval);
  1488. struct symbol *sym;
  1489. int is_a_field_of_this = 0, *need_this;
  1490. int hextype;
  1491. if (current_language-&gt;la_language == language_cplus
  1492. || current_language-&gt;la_language == language_objc
  1493. || current_language-&gt;la_language == language_objcplus)
  1494. need_this = &amp;is_a_field_of_this;
  1495. else
  1496. need_this = (int *) NULL;
  1497. sym = lookup_symbol (tmp, expression_context_block,
  1498. VAR_DOMAIN,
  1499. need_this,
  1500. (struct symtab **) NULL);
  1501. /* Call lookup_symtab, not lookup_partial_symtab, in case there
  1502. are no psymtabs (coff, xcoff, or some future change to blow
  1503. away the psymtabs once symbols are read). */
  1504. if ((sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_BLOCK) ||
  1505. lookup_symtab (tmp))
  1506. {
  1507. yylval.ssym.sym = sym;
  1508. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1509. return BLOCKNAME;
  1510. }
  1511. if (sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  1512. {
  1513. #if 1
  1514. /* Despite the following flaw, we need to keep this code
  1515. enabled. Because we can get called from
  1516. check_stub_method, if we don't handle nested types then
  1517. it screws many operations in any program which uses
  1518. nested types. */
  1519. /* In &quot;A::x&quot;, if x is a member function of A and there
  1520. happens to be a type (nested or not, since the stabs
  1521. don't make that distinction) named x, then this code
  1522. incorrectly thinks we are dealing with nested types
  1523. rather than a member function. */
  1524. char *p;
  1525. char *namestart;
  1526. struct symbol *best_sym;
  1527. /* Look ahead to detect nested types. This probably should
  1528. be done in the grammar, but trying seemed to introduce a
  1529. lot of shift/reduce and reduce/reduce conflicts. It's
  1530. possible that it could be done, though. Or perhaps a
  1531. non-grammar, but less ad hoc, approach would work well. */
  1532. /* Since we do not currently have any way of distinguishing
  1533. a nested type from a non-nested one (the stabs don't tell
  1534. us whether a type is nested), we just ignore the
  1535. containing type. */
  1536. p = lexptr;
  1537. best_sym = sym;
  1538. while (1)
  1539. {
  1540. /* Skip whitespace. */
  1541. while (*p == ' ' || *p == '\t' || *p == '\n')
  1542. ++p;
  1543. if (*p == ':' &amp;&amp; p[1] == ':')
  1544. {
  1545. /* Skip the `::'. */
  1546. p += 2;
  1547. /* Skip whitespace. */
  1548. while (*p == ' ' || *p == '\t' || *p == '\n')
  1549. ++p;
  1550. namestart = p;
  1551. while (*p == '_' || *p == '$' || (*p &gt;= '0' &amp;&amp; *p &lt;= '9')
  1552. || (*p &gt;= 'a' &amp;&amp; *p &lt;= 'z')
  1553. || (*p &gt;= 'A' &amp;&amp; *p &lt;= 'Z'))
  1554. ++p;
  1555. if (p != namestart)
  1556. {
  1557. struct symbol *cur_sym;
  1558. /* As big as the whole rest of the expression,
  1559. which is at least big enough. */
  1560. char *ncopy = alloca (s

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