PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

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

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