PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/opensource.apple.com/source/gdb/gdb-330.1/src/gdb/c-exp.y

#
Happy | 2000 lines | 1768 code | 232 blank | 0 comment | 0 complexity | 1cb0234ed25409705b09ca434941e6f9 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>c-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">c-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, 1992, 1993, 1994, 1995, 1996, 1997,
  25. 1998, 1999, 2000
  26. Free Software Foundation, Inc.
  27. This file is part of GDB.
  28. This program is free software; you can redistribute it and/or modify
  29. it under the terms of the GNU General Public License as published by
  30. the Free Software Foundation; either version 2 of the License, or
  31. (at your option) any later version.
  32. This program is distributed in the hope that it will be useful,
  33. but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. GNU General Public License for more details.
  36. You should have received a copy of the GNU General Public License
  37. along with this program; if not, write to the Free Software
  38. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  39. /* Parse a C expression from text in a string,
  40. and return the result as a struct expression pointer.
  41. That structure contains arithmetic operations in reverse polish,
  42. with constants represented by operations that are followed by special data.
  43. See expression.h for the details of the format.
  44. What is important here is that it can be built up sequentially
  45. during the process of parsing; the lower levels of the tree always
  46. come first in the result.
  47. Note that malloc's and realloc's in this file are transformed to
  48. xmalloc and xrealloc respectively by the same sed command in the
  49. makefile that remaps any other malloc/realloc inserted by the parser
  50. generator. Doing this with #defines and trying to control the interaction
  51. with include files (&lt;malloc.h&gt; and &lt;stdlib.h&gt; for example) just became
  52. too messy, particularly when such includes can be inserted at random
  53. times by the parser generator. */
  54. %{
  55. #include &quot;defs.h&quot;
  56. #include &quot;gdb_string.h&quot;
  57. #include &lt;ctype.h&gt;
  58. #include &quot;expression.h&quot;
  59. #include &quot;value.h&quot;
  60. #include &quot;parser-defs.h&quot;
  61. #include &quot;language.h&quot;
  62. #include &quot;c-lang.h&quot;
  63. #include &quot;bfd.h&quot; /* Required by objfiles.h. */
  64. #include &quot;symfile.h&quot; /* Required by objfiles.h. */
  65. #include &quot;objfiles.h&quot; /* For have_full_symbols and have_partial_symbols */
  66. #include &quot;charset.h&quot;
  67. #include &quot;completer.h&quot;
  68. #include &quot;objc-lang.h&quot; /* For ObjC language constructs. */
  69. /* Flag indicating we're dealing with HP-compiled objects */
  70. extern int hp_som_som_object_present;
  71. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  72. as well as gratuitiously global symbol names, so we can have multiple
  73. yacc generated parsers in gdb. Note that these are only the variables
  74. produced by yacc. If other parser generators (bison, byacc, etc) produce
  75. additional global names that conflict at link time, then those parser
  76. generators need to be fixed instead of adding those names to this list. */
  77. #define yymaxdepth c_maxdepth
  78. #define yyparse c_parse
  79. #define yylex c_lex
  80. #define yyerror c_error
  81. #define yylval c_lval
  82. #define yychar c_char
  83. #define yydebug c_debug
  84. #define yypact c_pact
  85. #define yyr1 c_r1
  86. #define yyr2 c_r2
  87. #define yydef c_def
  88. #define yychk c_chk
  89. #define yypgo c_pgo
  90. #define yyact c_act
  91. #define yyexca c_exca
  92. #define yyerrflag c_errflag
  93. #define yynerrs c_nerrs
  94. #define yyps c_ps
  95. #define yypv c_pv
  96. #define yys c_s
  97. #define yy_yys c_yys
  98. #define yystate c_state
  99. #define yytmp c_tmp
  100. #define yyv c_v
  101. #define yy_yyv c_yyv
  102. #define yyval c_val
  103. #define yylloc c_lloc
  104. #define yyreds c_reds /* With YYDEBUG defined */
  105. #define yytoks c_toks /* With YYDEBUG defined */
  106. #define yyname c_name /* With YYDEBUG defined */
  107. #define yyrule c_rule /* With YYDEBUG defined */
  108. #define yylhs c_yylhs
  109. #define yylen c_yylen
  110. #define yydefred c_yydefred
  111. #define yydgoto c_yydgoto
  112. #define yysindex c_yysindex
  113. #define yyrindex c_yyrindex
  114. #define yygindex c_yygindex
  115. #define yytable c_yytable
  116. #define yycheck c_yycheck
  117. #ifndef YYDEBUG
  118. #define YYDEBUG 1 /* Default to yydebug support */
  119. #endif
  120. #define YYFPRINTF parser_fprintf
  121. int yyparse (void);
  122. static int yylex (void);
  123. void yyerror (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 parse_number (char *, int, int, YYSTYPE *);
  155. %}
  156. %type &lt;voidval&gt; exp exp1 type_exp start variable qualified_name lcurly
  157. %type &lt;lval&gt; rcurly
  158. %type &lt;tval&gt; type typebase
  159. %type &lt;tvec&gt; nonempty_typelist
  160. /* %type &lt;bval&gt; block */
  161. /* Fancy type parsing. */
  162. %type &lt;voidval&gt; func_mod direct_abs_decl abs_decl
  163. %type &lt;tval&gt; ptype
  164. %type &lt;lval&gt; array_mod
  165. %token &lt;typed_val_int&gt; INT
  166. %token &lt;typed_val_float&gt; FLOAT
  167. /* Both NAME and TYPENAME tokens represent symbols in the input,
  168. and both convey their data as strings.
  169. But a TYPENAME is a string that happens to be defined as a typedef
  170. or builtin type name (such as int or char)
  171. and a NAME is any other symbol.
  172. Contexts where this distinction is not important can use the
  173. nonterminal &quot;name&quot;, which matches either NAME or TYPENAME. */
  174. %token &lt;sval&gt; STRING
  175. %token &lt;sval&gt; OBJC_NSSTRING /* ObjC Foundation &quot;NSString&quot; literal */
  176. %token &lt;sval&gt; OBJC_SELECTOR /* ObjC &quot;@selector&quot; pseudo-operator */
  177. %token &lt;class&gt; OBJC_CLASSNAME /* ObjC Class name */
  178. %token &lt;ssym&gt; NAME /* BLOCKNAME defined below to give it higher precedence. */
  179. %token &lt;tsym&gt; TYPENAME
  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 different
  192. 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. /* C++ */
  197. %token TRUEKEYWORD
  198. %token FALSEKEYWORD
  199. %left ','
  200. %left ABOVE_COMMA
  201. %right '=' ASSIGN_MODIFY
  202. %right '?'
  203. %left OROR
  204. %left ANDAND
  205. %left '|'
  206. %left '^'
  207. %left '&amp;'
  208. %left EQUAL NOTEQUAL
  209. %left '&lt;' '&gt;' LEQ GEQ
  210. %left LSH RSH
  211. %left '@'
  212. %left '+' '-'
  213. %left '*' '/' '%'
  214. %right UNARY INCREMENT DECREMENT
  215. %right ARROW '.' '[' '('
  216. %token &lt;ssym&gt; BLOCKNAME
  217. %token &lt;bval&gt; FILENAME
  218. %type &lt;bval&gt; block
  219. %left COLONCOLON
  220. %%
  221. start : exp1
  222. | type_exp
  223. ;
  224. type_exp: type
  225. { write_exp_elt_opcode(OP_TYPE);
  226. write_exp_elt_type($1);
  227. write_exp_elt_opcode(OP_TYPE);}
  228. ;
  229. /* Expressions, including the comma operator. */
  230. exp1 : exp
  231. | exp1 ',' exp
  232. { write_exp_elt_opcode (BINOP_COMMA); }
  233. ;
  234. /* Expressions, not including the comma operator. */
  235. exp : '*' exp %prec UNARY
  236. { write_exp_elt_opcode (UNOP_IND); }
  237. ;
  238. exp : '&amp;' exp %prec UNARY
  239. { write_exp_elt_opcode (UNOP_ADDR); }
  240. ;
  241. exp : '-' exp %prec UNARY
  242. { write_exp_elt_opcode (UNOP_NEG); }
  243. ;
  244. exp : '!' exp %prec UNARY
  245. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  246. ;
  247. exp : '~' exp %prec UNARY
  248. { write_exp_elt_opcode (UNOP_COMPLEMENT); }
  249. ;
  250. exp : INCREMENT exp %prec UNARY
  251. { write_exp_elt_opcode (UNOP_PREINCREMENT); }
  252. ;
  253. exp : DECREMENT exp %prec UNARY
  254. { write_exp_elt_opcode (UNOP_PREDECREMENT); }
  255. ;
  256. exp : exp INCREMENT %prec UNARY
  257. { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
  258. ;
  259. exp : exp DECREMENT %prec UNARY
  260. { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
  261. ;
  262. exp : SIZEOF exp %prec UNARY
  263. { write_exp_elt_opcode (UNOP_SIZEOF); }
  264. ;
  265. exp : exp ARROW name
  266. { write_exp_elt_opcode (STRUCTOP_PTR);
  267. write_exp_string ($3);
  268. write_exp_elt_opcode (STRUCTOP_PTR); }
  269. ;
  270. exp : exp ARROW qualified_name
  271. { /* exp-&gt;type::name becomes exp-&gt;*(&amp;type::name) */
  272. /* Note: this doesn't work if name is a
  273. static member! FIXME */
  274. write_exp_elt_opcode (UNOP_ADDR);
  275. write_exp_elt_opcode (STRUCTOP_MPTR); }
  276. ;
  277. exp : exp ARROW '*' exp
  278. { write_exp_elt_opcode (STRUCTOP_MPTR); }
  279. ;
  280. exp : exp '.' name
  281. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  282. write_exp_string ($3);
  283. write_exp_elt_opcode (STRUCTOP_STRUCT); }
  284. ;
  285. exp : exp '.' qualified_name
  286. { /* exp.type::name becomes exp.*(&amp;type::name) */
  287. /* Note: this doesn't work if name is a
  288. static member! FIXME */
  289. write_exp_elt_opcode (UNOP_ADDR);
  290. write_exp_elt_opcode (STRUCTOP_MEMBER); }
  291. ;
  292. exp : exp '.' '*' exp
  293. { write_exp_elt_opcode (STRUCTOP_MEMBER); }
  294. ;
  295. exp : exp '[' exp1 ']'
  296. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  297. ;
  298. /* The rules below parse ObjC message calls of the form:
  299. '[' target selector {':' argument}* ']' */
  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_int);
  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 : '[' OBJC_CLASSNAME
  320. {
  321. write_exp_elt_opcode (OP_LONG);
  322. write_exp_elt_type (builtin_type_int);
  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 argument. */
  351. { add_msglist(0, 1); }
  352. | ',' exp /* Variable number of arguments. */
  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 : OBJC_SELECTOR
  493. {
  494. write_exp_elt_opcode (OP_OBJC_SELECTOR);
  495. write_exp_string ($1);
  496. write_exp_elt_opcode (OP_OBJC_SELECTOR); }
  497. exp : SIZEOF '(' type ')' %prec UNARY
  498. { write_exp_elt_opcode (OP_LONG);
  499. write_exp_elt_type (builtin_type_int);
  500. CHECK_TYPEDEF ($3);
  501. write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
  502. write_exp_elt_opcode (OP_LONG); }
  503. ;
  504. exp : STRING
  505. { /* C strings are converted into array constants with
  506. an explicit null byte added at the end. Thus
  507. the array upper bound is the string length.
  508. There is no 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 : OBJC_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. /* C++. */
  535. exp : TRUEKEYWORD
  536. { write_exp_elt_opcode (OP_LONG);
  537. write_exp_elt_type (builtin_type_bool);
  538. write_exp_elt_longcst ((LONGEST) 1);
  539. write_exp_elt_opcode (OP_LONG); }
  540. ;
  541. exp : FALSEKEYWORD
  542. { write_exp_elt_opcode (OP_LONG);
  543. write_exp_elt_type (builtin_type_bool);
  544. write_exp_elt_longcst ((LONGEST) 0);
  545. write_exp_elt_opcode (OP_LONG); }
  546. ;
  547. /* end of C++. */
  548. block : BLOCKNAME
  549. {
  550. if ($1.sym)
  551. $$ = SYMBOL_BLOCK_VALUE ($1.sym);
  552. else
  553. error (&quot;No file or function \&quot;%s\&quot;.&quot;,
  554. copy_name ($1.stoken));
  555. }
  556. | FILENAME
  557. {
  558. $$ = $1;
  559. }
  560. ;
  561. block : block COLONCOLON name
  562. { struct symbol *tem
  563. = lookup_symbol (copy_name ($3), $1,
  564. VAR_NAMESPACE, (int *) NULL,
  565. (struct symtab **) NULL);
  566. if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  567. error (&quot;No function \&quot;%s\&quot; in specified context.&quot;,
  568. copy_name ($3));
  569. $$ = SYMBOL_BLOCK_VALUE (tem); }
  570. ;
  571. variable: block COLONCOLON name
  572. { struct symbol *sym;
  573. sym = lookup_symbol (copy_name ($3), $1,
  574. VAR_NAMESPACE, (int *) NULL,
  575. (struct symtab **) NULL);
  576. if (sym == 0)
  577. error (&quot;No symbol \&quot;%s\&quot; in specified context.&quot;,
  578. copy_name ($3));
  579. write_exp_elt_opcode (OP_VAR_VALUE);
  580. /* block_found is set by lookup_symbol. */
  581. write_exp_elt_block (block_found);
  582. write_exp_elt_sym (sym);
  583. write_exp_elt_opcode (OP_VAR_VALUE); }
  584. ;
  585. qualified_name: typebase COLONCOLON name
  586. {
  587. struct type *type = $1;
  588. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  589. &amp;&amp; TYPE_CODE (type) != TYPE_CODE_UNION)
  590. error (&quot;`%s' is not defined as an aggregate type.&quot;,
  591. TYPE_NAME (type));
  592. write_exp_elt_opcode (OP_SCOPE);
  593. write_exp_elt_type (type);
  594. write_exp_string ($3);
  595. write_exp_elt_opcode (OP_SCOPE);
  596. }
  597. | typebase COLONCOLON '~' name
  598. {
  599. struct type *type = $1;
  600. struct stoken tmp_token;
  601. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  602. &amp;&amp; TYPE_CODE (type) != TYPE_CODE_UNION)
  603. error (&quot;`%s' is not defined as an aggregate type.&quot;,
  604. TYPE_NAME (type));
  605. tmp_token.ptr = (char*) alloca ($4.length + 2);
  606. tmp_token.length = $4.length + 1;
  607. tmp_token.ptr[0] = '~';
  608. memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
  609. tmp_token.ptr[tmp_token.length] = 0;
  610. /* Check for valid destructor name. */
  611. destructor_name_p (tmp_token.ptr, type);
  612. write_exp_elt_opcode (OP_SCOPE);
  613. write_exp_elt_type (type);
  614. write_exp_string (tmp_token);
  615. write_exp_elt_opcode (OP_SCOPE);
  616. }
  617. ;
  618. variable: qualified_name
  619. | COLONCOLON name
  620. {
  621. char *name = copy_name ($2);
  622. struct symbol *sym;
  623. struct minimal_symbol *msymbol;
  624. sym =
  625. lookup_symbol (name, (const struct block *) NULL,
  626. VAR_NAMESPACE, (int *) NULL,
  627. (struct symtab **) NULL);
  628. if (sym)
  629. {
  630. write_exp_elt_opcode (OP_VAR_VALUE);
  631. write_exp_elt_block (NULL);
  632. write_exp_elt_sym (sym);
  633. write_exp_elt_opcode (OP_VAR_VALUE);
  634. break;
  635. }
  636. msymbol = lookup_minimal_symbol (name, NULL, NULL);
  637. if (msymbol != NULL)
  638. {
  639. write_exp_msymbol (msymbol,
  640. lookup_function_type (builtin_type_int),
  641. builtin_type_int);
  642. }
  643. else
  644. if (!have_full_symbols () &amp;&amp; !have_partial_symbols ())
  645. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  646. else
  647. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;, name);
  648. }
  649. ;
  650. variable: name_not_typename
  651. { struct symbol *sym = $1.sym;
  652. if (sym)
  653. {
  654. if (symbol_read_needs_frame (sym))
  655. {
  656. if (innermost_block == 0 ||
  657. contained_in (block_found,
  658. innermost_block))
  659. innermost_block = block_found;
  660. }
  661. write_exp_elt_opcode (OP_VAR_VALUE);
  662. /* We want to use the selected frame, not
  663. another more inner frame which happens to
  664. be in the same block. */
  665. write_exp_elt_block (NULL);
  666. write_exp_elt_sym (sym);
  667. write_exp_elt_opcode (OP_VAR_VALUE);
  668. }
  669. else if ($1.is_a_field_of_this)
  670. {
  671. /* C++/ObjC: it hangs off of `this'. Must
  672. not inadvertently convert from a method call
  673. to data ref. */
  674. if (innermost_block == 0 ||
  675. contained_in (block_found, innermost_block))
  676. innermost_block = block_found;
  677. if (current_language-&gt;la_language == language_cplus)
  678. {
  679. write_exp_elt_opcode (OP_THIS);
  680. write_exp_elt_opcode (OP_THIS);
  681. }
  682. else if (current_language-&gt;la_language == language_objc
  683. || current_language-&gt;la_language == language_objcplus)
  684. {
  685. write_exp_elt_opcode (OP_OBJC_SELF);
  686. write_exp_elt_opcode (OP_OBJC_SELF);
  687. }
  688. write_exp_elt_opcode (STRUCTOP_PTR);
  689. write_exp_string ($1.stoken);
  690. write_exp_elt_opcode (STRUCTOP_PTR);
  691. }
  692. else
  693. {
  694. struct minimal_symbol *msymbol;
  695. register char *arg = copy_name ($1.stoken);
  696. msymbol =
  697. lookup_minimal_symbol (arg, NULL, NULL);
  698. if (msymbol != NULL)
  699. {
  700. write_exp_msymbol (msymbol,
  701. lookup_function_type (builtin_type_int),
  702. builtin_type_int);
  703. }
  704. else if (!have_full_symbols () &amp;&amp; !have_partial_symbols ())
  705. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  706. else
  707. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  708. copy_name ($1.stoken));
  709. }
  710. }
  711. ;
  712. space_identifier : '@' NAME
  713. { push_type_address_space (copy_name ($2.stoken));
  714. push_type (tp_space_identifier);
  715. }
  716. ;
  717. const_or_volatile: const_or_volatile_noopt
  718. |
  719. ;
  720. cv_with_space_id : const_or_volatile space_identifier const_or_volatile
  721. ;
  722. const_or_volatile_or_space_identifier_noopt: cv_with_space_id
  723. | const_or_volatile_noopt
  724. ;
  725. const_or_volatile_or_space_identifier:
  726. const_or_volatile_or_space_identifier_noopt
  727. |
  728. ;
  729. abs_decl: '*'
  730. { push_type (tp_pointer); $$ = 0; }
  731. | '*' abs_decl
  732. { push_type (tp_pointer); $$ = $2; }
  733. | '&amp;'
  734. { push_type (tp_reference); $$ = 0; }
  735. | '&amp;' abs_decl
  736. { push_type (tp_reference); $$ = $2; }
  737. | direct_abs_decl
  738. ;
  739. direct_abs_decl: '(' abs_decl ')'
  740. { $$ = $2; }
  741. | direct_abs_decl array_mod
  742. {
  743. push_type_int ($2);
  744. push_type (tp_array);
  745. }
  746. | array_mod
  747. {
  748. push_type_int ($1);
  749. push_type (tp_array);
  750. $$ = 0;
  751. }
  752. | direct_abs_decl func_mod
  753. { push_type (tp_function); }
  754. | func_mod
  755. { push_type (tp_function); }
  756. ;
  757. array_mod: '[' ']'
  758. { $$ = -1; }
  759. | '[' INT ']'
  760. { $$ = $2.val; }
  761. ;
  762. func_mod: '(' ')'
  763. { $$ = 0; }
  764. | '(' nonempty_typelist ')'
  765. { free ((PTR)$2); $$ = 0; }
  766. ;
  767. /* We used to try to recognize more pointer to member types here, but
  768. that didn't work (shift/reduce conflicts meant that these rules never
  769. got executed). The problem is that
  770. int (foo::bar::baz::bizzle)
  771. is a function type but
  772. int (foo::bar::baz::bizzle::*)
  773. is a pointer to member type. Stroustrup loses again! */
  774. type : ptype
  775. | typebase COLONCOLON '*'
  776. { $$ = lookup_member_type (builtin_type_int, $1); }
  777. ;
  778. typebase /* Implements (approximately): (type-qualifier)* type-specifier */
  779. : TYPENAME
  780. { $$ = $1.type; }
  781. | OBJC_CLASSNAME
  782. {
  783. if ($1.type == NULL)
  784. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  785. copy_name($1.stoken));
  786. else
  787. $$ = $1.type;
  788. }
  789. | INT_KEYWORD
  790. { $$ = builtin_type_int; }
  791. | LONG
  792. { $$ = builtin_type_long; }
  793. | SHORT
  794. { $$ = builtin_type_short; }
  795. | LONG INT_KEYWORD
  796. { $$ = builtin_type_long; }
  797. | LONG SIGNED_KEYWORD INT_KEYWORD
  798. { $$ = builtin_type_long; }
  799. | LONG SIGNED_KEYWORD
  800. { $$ = builtin_type_long; }
  801. | SIGNED_KEYWORD LONG INT_KEYWORD
  802. { $$ = builtin_type_long; }
  803. | UNSIGNED LONG INT_KEYWORD
  804. { $$ = builtin_type_unsigned_long; }
  805. | LONG UNSIGNED INT_KEYWORD
  806. { $$ = builtin_type_unsigned_long; }
  807. | LONG UNSIGNED
  808. { $$ = builtin_type_unsigned_long; }
  809. | LONG LONG
  810. { $$ = builtin_type_long_long; }
  811. | LONG LONG INT_KEYWORD
  812. { $$ = builtin_type_long_long; }
  813. | LONG LONG SIGNED_KEYWORD INT_KEYWORD
  814. { $$ = builtin_type_long_long; }
  815. | LONG LONG SIGNED_KEYWORD
  816. { $$ = builtin_type_long_long; }
  817. | SIGNED_KEYWORD LONG LONG
  818. { $$ = builtin_type_long_long; }
  819. | UNSIGNED LONG LONG
  820. { $$ = builtin_type_unsigned_long_long; }
  821. | UNSIGNED LONG LONG INT_KEYWORD
  822. { $$ = builtin_type_unsigned_long_long; }
  823. | LONG LONG UNSIGNED
  824. { $$ = builtin_type_unsigned_long_long; }
  825. | LONG LONG UNSIGNED INT_KEYWORD
  826. { $$ = builtin_type_unsigned_long_long; }
  827. | SIGNED_KEYWORD LONG LONG
  828. { $$ = lookup_signed_typename (&quot;long long&quot;); }
  829. | SIGNED_KEYWORD LONG LONG INT_KEYWORD
  830. { $$ = lookup_signed_typename (&quot;long long&quot;); }
  831. | SHORT INT_KEYWORD
  832. { $$ = builtin_type_short; }
  833. | SHORT SIGNED_KEYWORD INT_KEYWORD
  834. { $$ = builtin_type_short; }
  835. | SHORT SIGNED_KEYWORD
  836. { $$ = builtin_type_short; }
  837. | UNSIGNED SHORT INT_KEYWORD
  838. { $$ = builtin_type_unsigned_short; }
  839. | SHORT UNSIGNED
  840. { $$ = builtin_type_unsigned_short; }
  841. | SHORT UNSIGNED 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. /* It appears that this rule for templates is never
  868. reduced; template recognition happens by lookahead
  869. in the token processing code in yylex. */
  870. | TEMPLATE name '&lt;' type '&gt;'
  871. { $$ = lookup_template_type(copy_name($2), $4,
  872. expression_context_block);
  873. }
  874. | const_or_volatile_or_space_identifier_noopt typebase
  875. { $$ = follow_types ($2); }
  876. | typebase const_or_volatile_or_space_identifier_noopt
  877. { $$ = follow_types ($1); }
  878. ;
  879. typename: TYPENAME
  880. | INT_KEYWORD
  881. {
  882. $$.stoken.ptr = &quot;int&quot;;
  883. $$.stoken.length = 3;
  884. $$.type = builtin_type_int;
  885. }
  886. | LONG
  887. {
  888. $$.stoken.ptr = &quot;long&quot;;
  889. $$.stoken.length = 4;
  890. $$.type = builtin_type_long;
  891. }
  892. | SHORT
  893. {
  894. $$.stoken.ptr = &quot;short&quot;;
  895. $$.stoken.length = 5;
  896. $$.type = builtin_type_short;
  897. }
  898. ;
  899. nonempty_typelist
  900. : type
  901. { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
  902. $&lt;ivec&gt;$[0] = 1; /* Number of types in vector */
  903. $$[1] = $1;
  904. }
  905. | nonempty_typelist ',' type
  906. { int len = sizeof (struct type *) * (++($&lt;ivec&gt;1[0]) + 1);
  907. $$ = (struct type **) realloc ((char *) $1, len);
  908. $$[$&lt;ivec&gt;$[0]] = $3;
  909. }
  910. ;
  911. ptype : typebase
  912. | ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
  913. { $$ = follow_types ($1); }
  914. ;
  915. const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
  916. | VOLATILE_KEYWORD CONST_KEYWORD
  917. ;
  918. const_or_volatile_noopt: const_and_volatile
  919. { push_type (tp_const);
  920. push_type (tp_volatile);
  921. }
  922. | CONST_KEYWORD
  923. { push_type (tp_const); }
  924. | VOLATILE_KEYWORD
  925. { push_type (tp_volatile); }
  926. ;
  927. name : NAME { $$ = $1.stoken; }
  928. | BLOCKNAME { $$ = $1.stoken; }
  929. | TYPENAME { $$ = $1.stoken; }
  930. | OBJC_CLASSNAME { $$ = $1.stoken; }
  931. | NAME_OR_INT { $$ = $1.stoken; }
  932. ;
  933. name_not_typename : NAME
  934. | BLOCKNAME
  935. /* These would be useful if name_not_typename was useful, but it is just
  936. a fake for &quot;variable&quot;, so these cause reduce/reduce conflicts because
  937. the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
  938. =exp) or just an exp. If name_not_typename was ever used in an lvalue
  939. context where only a name could occur, this might be useful.
  940. | NAME_OR_INT
  941. */
  942. ;
  943. %%
  944. /* Take care of parsing a number (anything that starts with a digit).
  945. Set yylval and return the token type; update lexptr.
  946. LEN is the number of characters in it. */
  947. /*** Needs some error checking for the float case ***/
  948. static int
  949. parse_number (p, len, parsed_float, putithere)
  950. register char *p;
  951. register int len;
  952. int parsed_float;
  953. YYSTYPE *putithere;
  954. {
  955. /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
  956. here, and we do kind of silly things like cast to unsigned. */
  957. register LONGEST n = 0;
  958. register LONGEST prevn = 0;
  959. ULONGEST un;
  960. register int i = 0;
  961. register int c;
  962. register int base = input_radix;
  963. int unsigned_p = 0;
  964. /* Number of &quot;L&quot; suffixes encountered. */
  965. int long_p = 0;
  966. /* We have found a &quot;L&quot; or &quot;U&quot; suffix. */
  967. int found_suffix = 0;
  968. ULONGEST high_bit;
  969. struct type *signed_type;
  970. struct type *unsigned_type;
  971. if (parsed_float)
  972. {
  973. /* It's a float since it contains a point or an exponent. */
  974. char c;
  975. int num = 0; /* number of tokens scanned by scanf */
  976. char saved_char = p[len];
  977. p[len] = 0; /* null-terminate the token */
  978. if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (float))
  979. num = sscanf (p, &quot;%g%c&quot;, (float *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  980. else if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (double))
  981. num = sscanf (p, &quot;%lg%c&quot;, (double *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  982. else
  983. {
  984. #ifdef SCANF_HAS_LONG_DOUBLE
  985. num = sscanf (p, &quot;%Lg%c&quot;, &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  986. #else
  987. /* Scan it into a double, then assign it to the long double.
  988. This at least wins with values representable in the range
  989. of doubles. */
  990. double temp;
  991. num = sscanf (p, &quot;%lg%c&quot;, &amp;temp,&amp;c);
  992. putithere-&gt;typed_val_float.dval = temp;
  993. #endif
  994. }
  995. p[len] = saved_char; /* restore the input stream */
  996. if (num != 1) /* check scanf found ONLY a float ... */
  997. return ERROR;
  998. /* See if it has `f' or `l' suffix (float or long double). */
  999. c = tolower (p[len - 1]);
  1000. if (c == 'f')
  1001. putithere-&gt;typed_val_float.type = builtin_type_float;
  1002. else if (c == 'l')
  1003. putithere-&gt;typed_val_float.type = builtin_type_long_double;
  1004. else if (isdigit (c) || c == '.')
  1005. putithere-&gt;typed_val_float.type = builtin_type_double;
  1006. else
  1007. return ERROR;
  1008. return FLOAT;
  1009. }
  1010. /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  1011. if (p[0] == '0')
  1012. switch (p[1])
  1013. {
  1014. case 'x':
  1015. case 'X':
  1016. if (len &gt;= 3)
  1017. {
  1018. p += 2;
  1019. base = 16;
  1020. len -= 2;
  1021. }
  1022. break;
  1023. case 't':
  1024. case 'T':
  1025. case 'd':
  1026. case 'D':
  1027. if (len &gt;= 3)
  1028. {
  1029. p += 2;
  1030. base = 10;
  1031. len -= 2;
  1032. }
  1033. break;
  1034. default:
  1035. base = 8;
  1036. break;
  1037. }
  1038. while (len-- &gt; 0)
  1039. {
  1040. c = *p++;
  1041. if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')
  1042. c += 'a' - 'A';
  1043. if (c != 'l' &amp;&amp; c != 'u')
  1044. n *= base;
  1045. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1046. {
  1047. if (found_suffix)
  1048. return ERROR;
  1049. n += i = c - '0';
  1050. }
  1051. else
  1052. {
  1053. if (base &gt; 10 &amp;&amp; c &gt;= 'a' &amp;&amp; c &lt;= 'f')
  1054. {
  1055. if (found_suffix)
  1056. return ERROR;
  1057. n += i = c - 'a' + 10;
  1058. }
  1059. else if (c == 'l')
  1060. {
  1061. ++long_p;
  1062. found_suffix = 1;
  1063. }
  1064. else if (c == 'u')
  1065. {
  1066. unsigned_p = 1;
  1067. found_suffix = 1;
  1068. }
  1069. else
  1070. return ERROR; /* Char not a digit */
  1071. }
  1072. if (i &gt;= base)
  1073. return ERROR; /* Invalid digit in this base */
  1074. /* Portably test for overflow (only works for nonzero values, so make
  1075. a second check for zero). FIXME: Can't we just make n and prevn
  1076. unsigned and avoid this? */
  1077. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; (prevn &gt;= n) &amp;&amp; n != 0)
  1078. unsigned_p = 1; /* Try something unsigned */
  1079. /* Portably test for unsigned overflow.
  1080. FIXME: This check is wrong; for example it doesn't find overflow
  1081. on 0x123456789 when LONGEST is 32 bits. */
  1082. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; n != 0)
  1083. {
  1084. if ((unsigned_p &amp;&amp; (ULONGEST) prevn &gt;= (ULONGEST) n))
  1085. error (&quot;Numeric constant too large.&quot;);
  1086. }
  1087. prevn = n;
  1088. }
  1089. /* An integer constant is an int, a long, or a long long. An L
  1090. suffix forces it to be long; an LL suffix forces it to be long
  1091. long. If not forced to a larger size, it gets the first type of
  1092. the above that it fits in. To figure out whether it fits, we
  1093. shift it right and see whether anything remains. Note that we
  1094. can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  1095. operation, because many compilers will warn about such a shift
  1096. (which always produces a zero result). Sometimes TARGET_INT_BIT
  1097. or TARGET_LONG_BIT will be that big, sometimes not. To deal with
  1098. the case where it is we just always shift the value more than
  1099. once, with fewer bits each time. */
  1100. un = (ULONGEST)n &gt;&gt; 2;
  1101. if (long_p == 0
  1102. &amp;&amp; (un &gt;&gt; (TARGET_INT_BIT - 2)) == 0)
  1103. {
  1104. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_INT_BIT-1);
  1105. /* A large decimal (not hex or octal) constant (between INT_MAX
  1106. and UINT_MAX) is a long or unsigned long, according to ANSI,
  1107. never an unsigned int, but this code treats it as unsigned
  1108. int. This probably should be fixed. GCC gives a warning on
  1109. such constants. */
  1110. unsigned_type = builtin_type_unsigned_int;
  1111. signed_type = builtin_type_int;
  1112. }
  1113. else if (long_p &lt;= 1
  1114. &amp;&amp; (un &gt;&gt; (TARGET_LONG_BIT - 2)) == 0)
  1115. {
  1116. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_LONG_BIT-1);
  1117. unsigned_type = builtin_type_unsigned_long;
  1118. signed_type = builtin_type_long;
  1119. }
  1120. else
  1121. {
  1122. int shift;
  1123. if (sizeof (ULONGEST) * HOST_CHAR_BIT &lt; TARGET_LONG_LONG_BIT)
  1124. /* A long long does not fit in a LONGEST. */
  1125. shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
  1126. else
  1127. shift = (TARGET_LONG_LONG_BIT - 1);
  1128. high_bit = (ULONGEST) 1 &lt;&lt; shift;
  1129. unsigned_type = builtin_type_unsigned_long_long;
  1130. signed_type = builtin_type_long_long;
  1131. }
  1132. putithere-&gt;typed_val_int.val = n;
  1133. /* If the high bit of the worked out type is set then this number
  1134. has to be unsigned. */
  1135. if (unsigned_p || (n &amp; high_bit))
  1136. {
  1137. putithere-&gt;typed_val_int.type = unsigned_type;
  1138. }
  1139. else
  1140. {
  1141. putithere-&gt;typed_val_int.type = signed_type;
  1142. }
  1143. return INT;
  1144. }
  1145. struct token
  1146. {
  1147. char *operator;
  1148. int token;
  1149. enum exp_opcode opcode;
  1150. };
  1151. static const struct token tokentab3[] =
  1152. {
  1153. {&quot;&gt;&gt;=&quot;, ASSIGN_MODIFY, BINOP_RSH},
  1154. {&quot;&lt;&lt;=&quot;, ASSIGN_MODIFY, BINOP_LSH}
  1155. };
  1156. static const struct token tokentab2[] =
  1157. {
  1158. {&quot;+=&quot;, ASSIGN_MODIFY, BINOP_ADD},
  1159. {&quot;-=&quot;, ASSIGN_MODIFY, BINOP_SUB},
  1160. {&quot;*=&quot;, ASSIGN_MODIFY, BINOP_MUL},
  1161. {&quot;/=&quot;, ASSIGN_MODIFY, BINOP_DIV},
  1162. {&quot;%=&quot;, ASSIGN_MODIFY, BINOP_REM},
  1163. {&quot;|=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_IOR},
  1164. {&quot;&amp;=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_AND},
  1165. {&quot;^=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_XOR},
  1166. {&quot;++&quot;, INCREMENT, BINOP_END},
  1167. {&quot;--&quot;, DECREMENT, BINOP_END},
  1168. {&quot;-&gt;&quot;, ARROW, BINOP_END},
  1169. {&quot;&amp;&amp;&quot;, ANDAND, BINOP_END},
  1170. {&quot;||&quot;, OROR, BINOP_END},
  1171. {&quot;::&quot;, COLONCOLON, BINOP_END},
  1172. {&quot;&lt;&lt;&quot;, LSH, BINOP_END},
  1173. {&quot;&gt;&gt;&quot;, RSH, BINOP_END},
  1174. {&quot;==&quot;, EQUAL, BINOP_END},
  1175. {&quot;!=&quot;, NOTEQUAL, BINOP_END},
  1176. {&quot;&lt;=&quot;, LEQ, BINOP_END},
  1177. {&quot;&gt;=&quot;, GEQ, BINOP_END}
  1178. };
  1179. /* Read one token, getting characters through lexptr. */
  1180. static int
  1181. yylex ()
  1182. {
  1183. int c;
  1184. int tokchar;
  1185. int namelen;
  1186. unsigned int i;
  1187. char *tokstart;
  1188. char *tokptr;
  1189. int tempbufindex;
  1190. static char *tempbuf;
  1191. static int tempbufsize;
  1192. struct symbol * sym_class = NULL;
  1193. char * token_string = NULL;
  1194. int class_prefix = 0;
  1195. int unquoted_expr;
  1196. retry:
  1197. /* Check if this is a macro invocation that we need to expand. */
  1198. if (! scanning_macro_expansion ())
  1199. {
  1200. char *expanded = macro_expand_next (&amp;lexptr,
  1201. expression_macro_lookup_func,
  1202. expression_macro_lookup_baton);
  1203. if (expanded)
  1204. scan_macro_expansion (expanded);
  1205. }
  1206. prev_lexptr = lexptr;
  1207. unquoted_expr = 1;
  1208. tokstart = lexptr;
  1209. /* See if it is a special token of length 3. */
  1210. for (i = 0; i &lt; sizeof tokentab3 / sizeof tokentab3[0]; i++)
  1211. if (STREQN (tokstart, tokentab3[i].operator, 3))
  1212. {
  1213. lexptr += 3;
  1214. yylval.opcode = tokentab3[i].opcode;
  1215. return tokentab3[i].token;
  1216. }
  1217. /* See if it is a special token of length 2. */
  1218. for (i = 0; i &lt; sizeof tokentab2 / sizeof tokentab2[0]; i++)
  1219. if (STREQN (tokstart, tokentab2[i].operator, 2))
  1220. {
  1221. lexptr += 2;
  1222. yylval.opcode = tokentab2[i].opcode;
  1223. return tokentab2[i].token;
  1224. }
  1225. switch (tokchar = c = *tokstart)
  1226. {
  1227. case 0:
  1228. /* If we were just scanning the result of a macro expansion,
  1229. then we need to resume scanning the original text.
  1230. Otherwise, we were already scanning the original text, and
  1231. we're really done. */
  1232. if (scanning_macro_expansion ())
  1233. {
  1234. finished_macro_expansion ();
  1235. goto retry;
  1236. }
  1237. else
  1238. return 0;
  1239. case ' ':
  1240. case '\t':
  1241. case '\n':
  1242. lexptr++;
  1243. goto retry;
  1244. case '\'':
  1245. /* We either have a character constant ('0' or '\177' for example)
  1246. or we have a quoted symbol reference ('foo(int,int)' in C++
  1247. for example). */
  1248. lexptr++;
  1249. c = *lexptr++;
  1250. if (c == '\\')
  1251. c = parse_escape (&amp;lexptr);
  1252. else if (c == '\'')
  1253. error (&quot;Empty character constant.&quot;);
  1254. else if (! host_char_to_target (c, &amp;c))
  1255. {
  1256. int toklen = lexptr - tokstart + 1;
  1257. char *tok = alloca (toklen + 1);
  1258. memcpy (tok, tokstart, toklen);
  1259. tok[toklen] = '\0';
  1260. error (&quot;There is no character corresponding to %s in the target &quot;
  1261. &quot;character set `%s'.&quot;, tok, target_charset ());
  1262. }
  1263. yylval.typed_val_int.val = c;
  1264. yylval.typed_val_int.type = builtin_type_char;
  1265. c = *lexptr++;
  1266. if (c != '\'')
  1267. {
  1268. namelen = skip_quoted (tokstart) - tokstart;
  1269. if (namelen &gt; 2)
  1270. {
  1271. lexptr = tokstart + namelen;
  1272. unquoted_expr = 0;
  1273. if (lexptr[-1] != '\'')
  1274. error (&quot;Unmatched single quote.&quot;);
  1275. namelen -= 2;
  1276. tokstart++;
  1277. goto tryname;
  1278. }
  1279. error (&quot;Invalid character constant.&quot;);
  1280. }
  1281. return INT;
  1282. case '(':
  1283. paren_depth++;
  1284. lexptr++;
  1285. return c;
  1286. case ')':
  1287. if (paren_depth == 0)
  1288. return 0;
  1289. paren_depth--;
  1290. lexptr++;
  1291. return c;
  1292. case ',':
  1293. if (comma_terminates
  1294. &amp;&amp; paren_depth == 0
  1295. &amp;&amp; ! scanning_macro_expansion ())
  1296. return 0;
  1297. lexptr++;
  1298. return c;
  1299. case '.':
  1300. /* Might be a floating point number. */
  1301. if (lexptr[1] &lt; '0' || lexptr[1] &gt; '9')
  1302. goto symbol; /* Nope, must be a symbol. */
  1303. /* FALL THRU into number case. */
  1304. case '0':
  1305. case '1':
  1306. case '2':
  1307. case '3':
  1308. case '4':
  1309. case '5':
  1310. case '6':
  1311. case '7':
  1312. case '8':
  1313. case '9':
  1314. {
  1315. /* It's a number. */
  1316. int got_dot = 0, got_e = 0, toktype;
  1317. register char *p = tokstart;
  1318. int hex = input_radix &gt; 10;
  1319. if (c == '0' &amp;&amp; (p[1] == 'x' || p[1] == 'X'))
  1320. {
  1321. p += 2;
  1322. hex = 1;
  1323. }
  1324. else if (c == '0' &amp;&amp; (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  1325. {
  1326. p += 2;
  1327. hex = 0;
  1328. }
  1329. for (;; ++p)
  1330. {
  1331. /* This test includes !hex because 'e' is a valid hex digit
  1332. and thus does not indicate a floating point number when
  1333. the radix is hex. */
  1334. if (!hex &amp;&amp; !got_e &amp;&amp; (*p == 'e' || *p == 'E'))
  1335. got_dot = got_e = 1;
  1336. /* This test does not include !hex, because a '.' always indicates
  1337. a decimal floating point number regardless of the radix. */
  1338. else if (!got_dot &amp;&amp; *p == '.')
  1339. got_dot = 1;
  1340. else if (got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E')
  1341. &amp;&amp; (*p == '-' || *p == '+'))
  1342. /* This is the sign of the exponent, not the end of the
  1343. number. */
  1344. continue;
  1345. /* We will take any letters or digits. parse_number will
  1346. complain if past the radix, or if L or U are not final. */
  1347. else if ((*p &lt; '0' || *p &gt; '9')
  1348. &amp;&amp; ((*p &lt; 'a' || *p &gt; 'z')
  1349. &amp;&amp; (*p &lt; 'A' || *p &gt; 'Z')))
  1350. break;
  1351. }
  1352. toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &amp;yylval);
  1353. if (toktype == ERROR)
  1354. {
  1355. char *err_copy = (char *) alloca (p - tokstart + 1);
  1356. memcpy (err_copy, tokstart, p - tokstart);
  1357. err_copy[p - tokstart] = 0;
  1358. error (&quot;Invalid number \&quot;%s\&quot;.&quot;, err_copy);
  1359. }
  1360. lexptr = p;
  1361. return toktype;
  1362. }
  1363. case '+':
  1364. case '-':
  1365. case '*':
  1366. case '/':
  1367. case '%':
  1368. case '|':
  1369. case '&amp;':
  1370. case '^':
  1371. case '~':
  1372. case '!':
  1373. case '&lt;':
  1374. case '&gt;':
  1375. case '[':
  1376. case ']':
  1377. case '?':
  1378. case ':':
  1379. case '=':
  1380. case '{':
  1381. case '}':
  1382. symbol:
  1383. lexptr++;
  1384. return c;
  1385. case '@':
  1386. if (strncmp (tokstart, &quot;@selector&quot;, 9) == 0)
  1387. {
  1388. tokptr = strchr (tokstart, '(');
  1389. if (tokptr == NULL)
  1390. error (&quot;Missing '(' in @selector(...)&quot;);
  1391. tempbufindex = 0;
  1392. /* skip the '(' */
  1393. tokptr++;
  1394. do {
  1395. /* Grow the static temp buffer if necessary, including allocating
  1396. the first one on demand. */
  1397. if (tempbufindex + 1 &gt;= tempbufsize)
  1398. {
  1399. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1400. }
  1401. tempbuf[tempbufindex++] = *tokptr++;
  1402. } while ((*tokptr != ')') &amp;&amp; (*tokptr != '\0'));
  1403. if (*tokptr++ != ')')
  1404. error (&quot;Missing ')' in @selector(...)&quot;);
  1405. tempbuf[tempbufindex] = '\0';
  1406. yylval.sval.ptr = tempbuf;
  1407. yylval.sval.length = tempbufindex;
  1408. lexptr = tokptr;
  1409. return OBJC_SELECTOR;
  1410. }
  1411. if (tokstart[1] != '&quot;')
  1412. {
  1413. lexptr++;
  1414. return c;
  1415. }
  1416. /* ObjC NSString constant: fall through and parse like STRING. */
  1417. tokstart++;
  1418. case '&quot;':
  1419. /* Build the gdb internal form of the input string in tempbuf,
  1420. translating any standard C escape forms seen. Note that the
  1421. buffer is null byte terminated *only* for the convenience of
  1422. debugging gdb itself and printing the buffer contents when
  1423. the buffer contains no embedded nulls. Gdb does not depend
  1424. upon the buffer being null byte terminated, it uses the length
  1425. string instead. This allows gdb to handle C strings (as well
  1426. as strings in other languages) with embedded null bytes */
  1427. tokptr = tokstart + 1;
  1428. tempbufindex = 0;
  1429. do {
  1430. char *char_start_pos = tokptr;
  1431. /* Grow the static temp buffer if necessary, including allocating
  1432. the first one on demand. */
  1433. if (tempbufindex + 1 &gt;= tempbufsize)
  1434. {
  1435. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1436. }
  1437. switch (*tokptr)
  1438. {
  1439. case '\0':
  1440. case '&quot;':
  1441. /* Do nothing, loop will terminate. */
  1442. break;
  1443. case '\\':
  1444. tokptr++;
  1445. c = parse_escape (&amp;tokptr);
  1446. if (c == -1)
  1447. {
  1448. continue;
  1449. }
  1450. tempbuf[tempbufindex++] = c;
  1451. break;
  1452. default:
  1453. c = *tokptr++;
  1454. if (! host_char_to_target (c, &amp;c))
  1455. {
  1456. int len = tokptr - char_start_pos;
  1457. char *copy = alloca (len + 1);
  1458. memcpy (copy, char_start_pos, len);
  1459. copy[len] = '\0';
  1460. error (&quot;There is no character corresponding to `%s' &quot;
  1461. &quot;in the target character set `%s'.&quot;,
  1462. copy, target_charset ());
  1463. }
  1464. tempbuf[tempbufindex++] = c;
  1465. break;
  1466. }
  1467. } while ((*tokptr != '&quot;') &amp;&amp; (*tokptr != '\0'));
  1468. if (*tokptr++ != '&quot;')
  1469. {
  1470. error (&quot;Unterminated string in expression.&quot;);
  1471. }
  1472. tempbuf[tempbufindex] = '\0'; /* See note above */
  1473. yylval.sval.ptr = tempbuf;
  1474. yylval.sval.length = tempbufindex;
  1475. lexptr = tokptr;
  1476. return (tokchar == '@' ? OBJC_NSSTRING : STRING);
  1477. }
  1478. if (!(c == '_' || c == '$'
  1479. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')))
  1480. /* We must have come across a bad character (e.g. ';'). */
  1481. error (&quot;Invalid character '%c' in expression.&quot;, c);
  1482. /* It's a name. See how long it is. */
  1483. namelen = 0;
  1484. for (c = tokstart[namelen];
  1485. (c == '_' || c == '$' || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1486. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || c == '&lt;');)
  1487. {
  1488. /* Template parameter lists are part of the name.
  1489. FIXME: This mishandles `print $a&lt;4&amp;&amp;$a&gt;3'. */
  1490. if (c == '&lt;')
  1491. {
  1492. /* Scan ahead to get rest of the template specification. Note
  1493. that we look ahead only when the '&lt;' adjoins non-whitespace
  1494. characters; for comparison expressions, e.g. &quot;a &lt; b &gt; c&quot;,
  1495. there must be spaces before the '&lt;', etc. */
  1496. char * p = find_template_name_end (tokstart + namelen);
  1497. if (p)
  1498. namelen = p - tokstart;
  1499. break;
  1500. }
  1501. c = tokstart[++namelen];
  1502. }
  1503. /* The token &quot;if&quot; terminates the expression and is NOT removed from
  1504. the input stream. It doesn't count if it appears in the
  1505. expansion of a macro. */
  1506. if (namelen == 2
  1507. &amp;&amp; tokstart[0] == 'i'
  1508. &amp;&amp; tokstart[1] == 'f'
  1509. &amp;&amp; ! scanning_macro_expansion ())
  1510. {
  1511. return 0;
  1512. }
  1513. lexptr += namelen;
  1514. tryname:
  1515. /* Catch specific keywords. Should be done with a data structure. */
  1516. switch (namelen)
  1517. {
  1518. case 8:
  1519. if (STREQN (tokstart, &quot;unsigned&quot;, 8))
  1520. return UNSIGNED;
  1521. if (current_language-&gt;la_language == language_cplus
  1522. &amp;&amp; STREQN (tokstart, &quot;template&quot;, 8))
  1523. return TEMPLATE;
  1524. if (STREQN (tokstart, &quot;volatile&quot;, 8))
  1525. return VOLATILE_KEYWORD;
  1526. break;
  1527. case 6:
  1528. if (STREQN (tokstart, &quot;struct&quot;, 6))
  1529. return STRUCT;
  1530. if (STREQN (tokstart, &quot;signed&quot;, 6))
  1531. return SIGNED_KEYWORD;
  1532. if (STREQN (tokstart, &quot;sizeof&quot;, 6))
  1533. return SIZEOF;
  1534. if (STREQN (tokstart, &quot;double&quot;, 6))
  1535. return DOUBLE_KEYWORD;
  1536. break;
  1537. case 5:
  1538. if (current_language-&gt;la_language == language_cplus)
  1539. {
  1540. if (STREQN (tokstart, &quot;false&quot;, 5))
  1541. return FALSEKEYWORD;
  1542. if (STREQN (tokstart, &quot;class&quot;, 5))
  1543. return CLASS;
  1544. }
  1545. if (STREQN (tokstart, &quot;union&quot;, 5))
  1546. return UNION;
  1547. if (STREQN (tokstart, &quot;short&quot;, 5))
  1548. return SHORT;
  1549. if (STREQN (tokstart, &quot;const&quot;, 5))
  1550. return CONST_KEYWORD;
  1551. break;
  1552. case 4:
  1553. if (STREQN (tokstart, &quot;enum&quot;, 4))
  1554. return ENUM;
  1555. if (STREQN (tokstart, &quot;long&quot;, 4))
  1556. return LONG;
  1557. if (current_language-&gt;la_language == language_cplus)
  1558. {
  1559. if (STREQN (tokstart, &quot;true&quot;, 4))
  1560. return TRUEKEYWORD;
  1561. }
  1562. break;
  1563. case 3:
  1564. if (STREQN (tokstart, &quot;int&quot;, 3))
  1565. return INT_KEYWORD;
  1566. break;
  1567. default:
  1568. break;
  1569. }
  1570. yylval.sval.ptr = tokstart;
  1571. yylval.sval.length = namelen;
  1572. if (*tokstart == '$')
  1573. {
  1574. write_dollar_variable (yylval.sval);
  1575. return VARIABLE;
  1576. }
  1577. /* Look ahead and see if we can consume more of the input
  1578. string to get a reasonable class/namespace spec or a
  1579. fully-qualified name. This is a kludge to get around the
  1580. HP aCC compiler's generation of symbol names with embedded
  1581. colons for namespace and nested classes. */
  1582. if (unquoted_expr)
  1583. {
  1584. /* Only do it if not inside single quotes *…

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