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

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

#
Happy | 1999 lines | 1767 code | 232 blank | 0 comment | 0 complexity | 139f38cb20592b2fb452df510a848ade 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;objc-lang.h&quot; /* For Obj-C language constructs. */
  64. #include &quot;bfd.h&quot; /* Required by objfiles.h. */
  65. #include &quot;symfile.h&quot; /* Required by objfiles.h. */
  66. #include &quot;objfiles.h&quot; /* For have_full_symbols and have_partial_symbols */
  67. #include &quot;completer.h&quot; /* For skip_quoted. */
  68. #include &quot;charset.h&quot;
  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; NSSTRING /* Obj-C Foundation &quot;NSString&quot; literal */
  176. %token &lt;sval&gt; SELECTOR /* Obj-C &quot;@selector&quot; pseudo-operator */
  177. %token &lt;ssym&gt; NAME /* BLOCKNAME defined below to give it higher precedence. */
  178. %token &lt;tsym&gt; TYPENAME
  179. %token &lt;class&gt; CLASSNAME /* Obj-C Class name */
  180. %type &lt;sval&gt; name
  181. %type &lt;ssym&gt; name_not_typename
  182. %type &lt;tsym&gt; typename
  183. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  184. but which would parse as a valid number in the current input radix.
  185. E.g. &quot;c&quot; when input_radix==16. Depending on the parse, it will be
  186. turned into a name or into a number. */
  187. %token &lt;ssym&gt; NAME_OR_INT
  188. %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
  189. %token TEMPLATE
  190. %token ERROR
  191. /* Special type cases, put in to allow the parser to distinguish 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. exp : '&amp;' exp %prec UNARY
  238. { write_exp_elt_opcode (UNOP_ADDR); }
  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. /* The rules below parse Obj-C message calls of the form:
  297. '[' target selector {':' argument}* ']' */
  298. exp : '[' TYPENAME
  299. {
  300. CORE_ADDR class;
  301. class = lookup_objc_class (copy_name ($2.stoken));
  302. if (class == 0)
  303. error (&quot;%s is not an ObjC Class&quot;,
  304. copy_name ($2.stoken));
  305. write_exp_elt_opcode (OP_LONG);
  306. write_exp_elt_type (builtin_type_int);
  307. write_exp_elt_longcst ((LONGEST) class);
  308. write_exp_elt_opcode (OP_LONG);
  309. start_msglist();
  310. }
  311. msglist ']'
  312. { write_exp_elt_opcode (OP_MSGCALL);
  313. end_msglist();
  314. write_exp_elt_opcode (OP_MSGCALL);
  315. }
  316. ;
  317. exp : '[' CLASSNAME
  318. {
  319. write_exp_elt_opcode (OP_LONG);
  320. write_exp_elt_type (builtin_type_int);
  321. write_exp_elt_longcst ((LONGEST) $2.class);
  322. write_exp_elt_opcode (OP_LONG);
  323. start_msglist();
  324. }
  325. msglist ']'
  326. { write_exp_elt_opcode (OP_MSGCALL);
  327. end_msglist();
  328. write_exp_elt_opcode (OP_MSGCALL);
  329. }
  330. ;
  331. exp : '[' exp
  332. { start_msglist(); }
  333. msglist ']'
  334. { write_exp_elt_opcode (OP_MSGCALL);
  335. end_msglist();
  336. write_exp_elt_opcode (OP_MSGCALL);
  337. }
  338. ;
  339. msglist : name
  340. { add_msglist(&amp;$1, 0); }
  341. | msgarglist
  342. ;
  343. msgarglist : msgarg
  344. | msgarglist msgarg
  345. ;
  346. msgarg : name ':' exp
  347. { add_msglist(&amp;$1, 1); }
  348. | ':' exp /* Unnamed argument. */
  349. { add_msglist(0, 1); }
  350. | ',' exp /* Variable number of arguments. */
  351. { add_msglist(0, 0); }
  352. ;
  353. exp : exp '('
  354. /* This is to save the value of arglist_len
  355. being accumulated by an outer function call. */
  356. { start_arglist (); }
  357. arglist ')' %prec ARROW
  358. { write_exp_elt_opcode (OP_FUNCALL);
  359. write_exp_elt_longcst ((LONGEST) end_arglist ());
  360. write_exp_elt_opcode (OP_FUNCALL); }
  361. ;
  362. lcurly : '{'
  363. { start_arglist (); }
  364. ;
  365. arglist :
  366. ;
  367. arglist : exp
  368. { arglist_len = 1; }
  369. ;
  370. arglist : arglist ',' exp %prec ABOVE_COMMA
  371. { arglist_len++; }
  372. ;
  373. rcurly : '}'
  374. { $$ = end_arglist () - 1; }
  375. ;
  376. exp : lcurly arglist rcurly %prec ARROW
  377. { write_exp_elt_opcode (OP_ARRAY);
  378. write_exp_elt_longcst ((LONGEST) 0);
  379. write_exp_elt_longcst ((LONGEST) $3);
  380. write_exp_elt_opcode (OP_ARRAY); }
  381. ;
  382. exp : lcurly type rcurly exp %prec UNARY
  383. { write_exp_elt_opcode (UNOP_MEMVAL);
  384. write_exp_elt_type ($2);
  385. write_exp_elt_opcode (UNOP_MEMVAL); }
  386. ;
  387. exp : '(' type ')' exp %prec UNARY
  388. { write_exp_elt_opcode (UNOP_CAST);
  389. write_exp_elt_type ($2);
  390. write_exp_elt_opcode (UNOP_CAST); }
  391. ;
  392. exp : '(' exp1 ')'
  393. { }
  394. ;
  395. /* Binary operators in order of decreasing precedence. */
  396. exp : exp '@' exp
  397. { write_exp_elt_opcode (BINOP_REPEAT); }
  398. ;
  399. exp : exp '*' exp
  400. { write_exp_elt_opcode (BINOP_MUL); }
  401. ;
  402. exp : exp '/' exp
  403. { write_exp_elt_opcode (BINOP_DIV); }
  404. ;
  405. exp : exp '%' exp
  406. { write_exp_elt_opcode (BINOP_REM); }
  407. ;
  408. exp : exp '+' exp
  409. { write_exp_elt_opcode (BINOP_ADD); }
  410. ;
  411. exp : exp '-' exp
  412. { write_exp_elt_opcode (BINOP_SUB); }
  413. ;
  414. exp : exp LSH exp
  415. { write_exp_elt_opcode (BINOP_LSH); }
  416. ;
  417. exp : exp RSH exp
  418. { write_exp_elt_opcode (BINOP_RSH); }
  419. ;
  420. exp : exp EQUAL exp
  421. { write_exp_elt_opcode (BINOP_EQUAL); }
  422. ;
  423. exp : exp NOTEQUAL exp
  424. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  425. ;
  426. exp : exp LEQ exp
  427. { write_exp_elt_opcode (BINOP_LEQ); }
  428. ;
  429. exp : exp GEQ exp
  430. { write_exp_elt_opcode (BINOP_GEQ); }
  431. ;
  432. exp : exp '&lt;' exp
  433. { write_exp_elt_opcode (BINOP_LESS); }
  434. ;
  435. exp : exp '&gt;' exp
  436. { write_exp_elt_opcode (BINOP_GTR); }
  437. ;
  438. exp : exp '&amp;' exp
  439. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  440. ;
  441. exp : exp '^' exp
  442. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  443. ;
  444. exp : exp '|' exp
  445. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  446. ;
  447. exp : exp ANDAND exp
  448. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  449. ;
  450. exp : exp OROR exp
  451. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  452. ;
  453. exp : exp '?' exp ':' exp %prec '?'
  454. { write_exp_elt_opcode (TERNOP_COND); }
  455. ;
  456. exp : exp '=' exp
  457. { write_exp_elt_opcode (BINOP_ASSIGN); }
  458. ;
  459. exp : exp ASSIGN_MODIFY exp
  460. { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
  461. write_exp_elt_opcode ($2);
  462. write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
  463. ;
  464. exp : INT
  465. { write_exp_elt_opcode (OP_LONG);
  466. write_exp_elt_type ($1.type);
  467. write_exp_elt_longcst ((LONGEST)($1.val));
  468. write_exp_elt_opcode (OP_LONG); }
  469. ;
  470. exp : NAME_OR_INT
  471. { YYSTYPE val;
  472. parse_number ($1.stoken.ptr, $1.stoken.length, 0, &amp;val);
  473. write_exp_elt_opcode (OP_LONG);
  474. write_exp_elt_type (val.typed_val_int.type);
  475. write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
  476. write_exp_elt_opcode (OP_LONG);
  477. }
  478. ;
  479. exp : FLOAT
  480. { write_exp_elt_opcode (OP_DOUBLE);
  481. write_exp_elt_type ($1.type);
  482. write_exp_elt_dblcst ($1.dval);
  483. write_exp_elt_opcode (OP_DOUBLE); }
  484. ;
  485. exp : variable
  486. ;
  487. exp : VARIABLE
  488. /* Already written by write_dollar_variable. */
  489. ;
  490. exp : SELECTOR
  491. {
  492. write_exp_elt_opcode (OP_SELECTOR);
  493. write_exp_string ($1);
  494. write_exp_elt_opcode (OP_SELECTOR); }
  495. exp : SIZEOF '(' type ')' %prec UNARY
  496. { write_exp_elt_opcode (OP_LONG);
  497. write_exp_elt_type (builtin_type_int);
  498. CHECK_TYPEDEF ($3);
  499. write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
  500. write_exp_elt_opcode (OP_LONG); }
  501. ;
  502. exp : STRING
  503. { /* C strings are converted into array constants with
  504. an explicit null byte added at the end. Thus
  505. the array upper bound is the string length.
  506. There is no such thing in C as a completely empty
  507. string. */
  508. char *sp = $1.ptr; int count = $1.length;
  509. while (count-- &gt; 0)
  510. {
  511. write_exp_elt_opcode (OP_LONG);
  512. write_exp_elt_type (builtin_type_char);
  513. write_exp_elt_longcst ((LONGEST)(*sp++));
  514. write_exp_elt_opcode (OP_LONG);
  515. }
  516. write_exp_elt_opcode (OP_LONG);
  517. write_exp_elt_type (builtin_type_char);
  518. write_exp_elt_longcst ((LONGEST)'\0');
  519. write_exp_elt_opcode (OP_LONG);
  520. write_exp_elt_opcode (OP_ARRAY);
  521. write_exp_elt_longcst ((LONGEST) 0);
  522. write_exp_elt_longcst ((LONGEST) ($1.length));
  523. write_exp_elt_opcode (OP_ARRAY); }
  524. ;
  525. exp : NSSTRING /* ObjC NextStep NSString constant
  526. * of the form '@' '&quot;' string '&quot;'.
  527. */
  528. { write_exp_elt_opcode (OP_NSSTRING);
  529. write_exp_string ($1);
  530. write_exp_elt_opcode (OP_NSSTRING); }
  531. ;
  532. /* C++. */
  533. exp : TRUEKEYWORD
  534. { write_exp_elt_opcode (OP_LONG);
  535. write_exp_elt_type (builtin_type_bool);
  536. write_exp_elt_longcst ((LONGEST) 1);
  537. write_exp_elt_opcode (OP_LONG); }
  538. ;
  539. exp : FALSEKEYWORD
  540. { write_exp_elt_opcode (OP_LONG);
  541. write_exp_elt_type (builtin_type_bool);
  542. write_exp_elt_longcst ((LONGEST) 0);
  543. write_exp_elt_opcode (OP_LONG); }
  544. ;
  545. /* end of C++. */
  546. block : BLOCKNAME
  547. {
  548. if ($1.sym)
  549. $$ = SYMBOL_BLOCK_VALUE ($1.sym);
  550. else
  551. error (&quot;No file or function \&quot;%s\&quot;.&quot;,
  552. copy_name ($1.stoken));
  553. }
  554. | FILENAME
  555. {
  556. $$ = $1;
  557. }
  558. ;
  559. block : block COLONCOLON name
  560. { struct symbol *tem
  561. = lookup_symbol (copy_name ($3), $1,
  562. VAR_NAMESPACE, (int *) NULL,
  563. (struct symtab **) NULL);
  564. if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  565. error (&quot;No function \&quot;%s\&quot; in specified context.&quot;,
  566. copy_name ($3));
  567. $$ = SYMBOL_BLOCK_VALUE (tem); }
  568. ;
  569. variable: block COLONCOLON name
  570. { struct symbol *sym;
  571. sym = lookup_symbol (copy_name ($3), $1,
  572. VAR_NAMESPACE, (int *) NULL,
  573. (struct symtab **) NULL);
  574. if (sym == 0)
  575. error (&quot;No symbol \&quot;%s\&quot; in specified context.&quot;,
  576. copy_name ($3));
  577. write_exp_elt_opcode (OP_VAR_VALUE);
  578. /* block_found is set by lookup_symbol. */
  579. write_exp_elt_block (block_found);
  580. write_exp_elt_sym (sym);
  581. write_exp_elt_opcode (OP_VAR_VALUE); }
  582. ;
  583. qualified_name: typebase COLONCOLON name
  584. {
  585. struct type *type = $1;
  586. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  587. &amp;&amp; TYPE_CODE (type) != TYPE_CODE_UNION)
  588. error (&quot;`%s' is not defined as an aggregate type.&quot;,
  589. TYPE_NAME (type));
  590. write_exp_elt_opcode (OP_SCOPE);
  591. write_exp_elt_type (type);
  592. write_exp_string ($3);
  593. write_exp_elt_opcode (OP_SCOPE);
  594. }
  595. | typebase COLONCOLON '~' name
  596. {
  597. struct type *type = $1;
  598. struct stoken tmp_token;
  599. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  600. &amp;&amp; TYPE_CODE (type) != TYPE_CODE_UNION)
  601. error (&quot;`%s' is not defined as an aggregate type.&quot;,
  602. TYPE_NAME (type));
  603. tmp_token.ptr = (char*) alloca ($4.length + 2);
  604. tmp_token.length = $4.length + 1;
  605. tmp_token.ptr[0] = '~';
  606. memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
  607. tmp_token.ptr[tmp_token.length] = 0;
  608. /* Check for valid destructor name. */
  609. destructor_name_p (tmp_token.ptr, type);
  610. write_exp_elt_opcode (OP_SCOPE);
  611. write_exp_elt_type (type);
  612. write_exp_string (tmp_token);
  613. write_exp_elt_opcode (OP_SCOPE);
  614. }
  615. ;
  616. variable: qualified_name
  617. | COLONCOLON name
  618. {
  619. char *name = copy_name ($2);
  620. struct symbol *sym;
  621. struct minimal_symbol *msymbol;
  622. sym =
  623. lookup_symbol (name, (const struct block *) NULL,
  624. VAR_NAMESPACE, (int *) NULL,
  625. (struct symtab **) NULL);
  626. if (sym)
  627. {
  628. write_exp_elt_opcode (OP_VAR_VALUE);
  629. write_exp_elt_block (NULL);
  630. write_exp_elt_sym (sym);
  631. write_exp_elt_opcode (OP_VAR_VALUE);
  632. break;
  633. }
  634. msymbol = lookup_minimal_symbol (name, NULL, NULL);
  635. if (msymbol != NULL)
  636. {
  637. write_exp_msymbol (msymbol,
  638. lookup_function_type (builtin_type_int),
  639. builtin_type_int);
  640. }
  641. else
  642. if (!have_full_symbols () &amp;&amp; !have_partial_symbols () &amp;&amp; !have_minimal_symbols ())
  643. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  644. else
  645. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;, name);
  646. }
  647. ;
  648. variable: name_not_typename
  649. { struct symbol *sym = $1.sym;
  650. if (sym)
  651. {
  652. if (symbol_read_needs_frame (sym))
  653. {
  654. if (innermost_block == 0 ||
  655. contained_in (block_found,
  656. innermost_block))
  657. innermost_block = block_found;
  658. }
  659. write_exp_elt_opcode (OP_VAR_VALUE);
  660. /* We want to use the selected frame, not
  661. another more inner frame which happens to
  662. be in the same block. */
  663. write_exp_elt_block (NULL);
  664. write_exp_elt_sym (sym);
  665. write_exp_elt_opcode (OP_VAR_VALUE);
  666. }
  667. else if ($1.is_a_field_of_this)
  668. {
  669. /* C++/Obj-C: it hangs off of `this'. Must
  670. not inadvertently convert from a method call
  671. to data ref. */
  672. if (innermost_block == 0 ||
  673. contained_in (block_found, innermost_block))
  674. innermost_block = block_found;
  675. if (current_language-&gt;la_language == language_cplus)
  676. {
  677. write_exp_elt_opcode (OP_THIS);
  678. write_exp_elt_opcode (OP_THIS);
  679. }
  680. else if (current_language-&gt;la_language == language_objc
  681. || current_language-&gt;la_language == language_objcplus)
  682. {
  683. write_exp_elt_opcode (OP_SELF);
  684. write_exp_elt_opcode (OP_SELF);
  685. }
  686. write_exp_elt_opcode (STRUCTOP_PTR);
  687. write_exp_string ($1.stoken);
  688. write_exp_elt_opcode (STRUCTOP_PTR);
  689. }
  690. else
  691. {
  692. struct minimal_symbol *msymbol;
  693. register char *arg = copy_name ($1.stoken);
  694. msymbol =
  695. lookup_minimal_symbol (arg, NULL, NULL);
  696. if (msymbol != NULL)
  697. {
  698. write_exp_msymbol (msymbol,
  699. lookup_function_type (builtin_type_int),
  700. builtin_type_int);
  701. }
  702. else if (!have_full_symbols () &amp;&amp; !have_partial_symbols () &amp;&amp; !have_minimal_symbols ())
  703. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  704. else
  705. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  706. copy_name ($1.stoken));
  707. }
  708. }
  709. ;
  710. space_identifier : '@' NAME
  711. { push_type_address_space (copy_name ($2.stoken));
  712. push_type (tp_space_identifier);
  713. }
  714. ;
  715. const_or_volatile: const_or_volatile_noopt
  716. |
  717. ;
  718. cv_with_space_id : const_or_volatile space_identifier const_or_volatile
  719. ;
  720. const_or_volatile_or_space_identifier_noopt: cv_with_space_id
  721. | const_or_volatile_noopt
  722. ;
  723. const_or_volatile_or_space_identifier:
  724. const_or_volatile_or_space_identifier_noopt
  725. |
  726. ;
  727. abs_decl: '*'
  728. { push_type (tp_pointer); $$ = 0; }
  729. | '*' abs_decl
  730. { push_type (tp_pointer); $$ = $2; }
  731. | '&amp;'
  732. { push_type (tp_reference); $$ = 0; }
  733. | '&amp;' abs_decl
  734. { push_type (tp_reference); $$ = $2; }
  735. | direct_abs_decl
  736. ;
  737. direct_abs_decl: '(' abs_decl ')'
  738. { $$ = $2; }
  739. | direct_abs_decl array_mod
  740. {
  741. push_type_int ($2);
  742. push_type (tp_array);
  743. }
  744. | array_mod
  745. {
  746. push_type_int ($1);
  747. push_type (tp_array);
  748. $$ = 0;
  749. }
  750. | direct_abs_decl func_mod
  751. { push_type (tp_function); }
  752. | func_mod
  753. { push_type (tp_function); }
  754. ;
  755. array_mod: '[' ']'
  756. { $$ = -1; }
  757. | '[' INT ']'
  758. { $$ = $2.val; }
  759. ;
  760. func_mod: '(' ')'
  761. { $$ = 0; }
  762. | '(' nonempty_typelist ')'
  763. { free ((PTR)$2); $$ = 0; }
  764. ;
  765. /* We used to try to recognize more pointer to member types here, but
  766. that didn't work (shift/reduce conflicts meant that these rules never
  767. got executed). The problem is that
  768. int (foo::bar::baz::bizzle)
  769. is a function type but
  770. int (foo::bar::baz::bizzle::*)
  771. is a pointer to member type. Stroustrup loses again! */
  772. type : ptype
  773. | typebase COLONCOLON '*'
  774. { $$ = lookup_member_type (builtin_type_int, $1); }
  775. ;
  776. typebase /* Implements (approximately): (type-qualifier)* type-specifier */
  777. : TYPENAME
  778. { $$ = $1.type; }
  779. | CLASSNAME
  780. {
  781. if ($1.type == NULL)
  782. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  783. copy_name($1.stoken));
  784. else
  785. $$ = $1.type;
  786. }
  787. | INT_KEYWORD
  788. { $$ = builtin_type_int; }
  789. | LONG
  790. { $$ = builtin_type_long; }
  791. | SHORT
  792. { $$ = builtin_type_short; }
  793. | LONG INT_KEYWORD
  794. { $$ = builtin_type_long; }
  795. | LONG SIGNED_KEYWORD INT_KEYWORD
  796. { $$ = builtin_type_long; }
  797. | LONG SIGNED_KEYWORD
  798. { $$ = builtin_type_long; }
  799. | SIGNED_KEYWORD LONG INT_KEYWORD
  800. { $$ = builtin_type_long; }
  801. | UNSIGNED LONG INT_KEYWORD
  802. { $$ = builtin_type_unsigned_long; }
  803. | LONG UNSIGNED INT_KEYWORD
  804. { $$ = builtin_type_unsigned_long; }
  805. | LONG UNSIGNED
  806. { $$ = builtin_type_unsigned_long; }
  807. | LONG LONG
  808. { $$ = builtin_type_long_long; }
  809. | LONG LONG INT_KEYWORD
  810. { $$ = builtin_type_long_long; }
  811. | LONG LONG SIGNED_KEYWORD INT_KEYWORD
  812. { $$ = builtin_type_long_long; }
  813. | LONG LONG SIGNED_KEYWORD
  814. { $$ = builtin_type_long_long; }
  815. | SIGNED_KEYWORD LONG LONG
  816. { $$ = builtin_type_long_long; }
  817. | UNSIGNED LONG LONG
  818. { $$ = builtin_type_unsigned_long_long; }
  819. | UNSIGNED LONG LONG INT_KEYWORD
  820. { $$ = builtin_type_unsigned_long_long; }
  821. | LONG LONG UNSIGNED
  822. { $$ = builtin_type_unsigned_long_long; }
  823. | LONG LONG UNSIGNED INT_KEYWORD
  824. { $$ = builtin_type_unsigned_long_long; }
  825. | SIGNED_KEYWORD LONG LONG
  826. { $$ = lookup_signed_typename (&quot;long long&quot;); }
  827. | SIGNED_KEYWORD LONG LONG INT_KEYWORD
  828. { $$ = lookup_signed_typename (&quot;long long&quot;); }
  829. | SHORT INT_KEYWORD
  830. { $$ = builtin_type_short; }
  831. | SHORT SIGNED_KEYWORD INT_KEYWORD
  832. { $$ = builtin_type_short; }
  833. | SHORT SIGNED_KEYWORD
  834. { $$ = builtin_type_short; }
  835. | UNSIGNED SHORT INT_KEYWORD
  836. { $$ = builtin_type_unsigned_short; }
  837. | SHORT UNSIGNED
  838. { $$ = builtin_type_unsigned_short; }
  839. | SHORT UNSIGNED INT_KEYWORD
  840. { $$ = builtin_type_unsigned_short; }
  841. | DOUBLE_KEYWORD
  842. { $$ = builtin_type_double; }
  843. | LONG DOUBLE_KEYWORD
  844. { $$ = builtin_type_long_double; }
  845. | STRUCT name
  846. { $$ = lookup_struct (copy_name ($2),
  847. expression_context_block); }
  848. | CLASS name
  849. { $$ = lookup_struct (copy_name ($2),
  850. expression_context_block); }
  851. | UNION name
  852. { $$ = lookup_union (copy_name ($2),
  853. expression_context_block); }
  854. | ENUM name
  855. { $$ = lookup_enum (copy_name ($2),
  856. expression_context_block); }
  857. | UNSIGNED typename
  858. { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
  859. | UNSIGNED
  860. { $$ = builtin_type_unsigned_int; }
  861. | SIGNED_KEYWORD typename
  862. { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
  863. | SIGNED_KEYWORD
  864. { $$ = builtin_type_int; }
  865. /* It appears that this rule for templates is never
  866. reduced; template recognition happens by lookahead
  867. in the token processing code in yylex. */
  868. | TEMPLATE name '&lt;' type '&gt;'
  869. { $$ = lookup_template_type(copy_name($2), $4,
  870. expression_context_block);
  871. }
  872. | const_or_volatile_or_space_identifier_noopt typebase
  873. { $$ = follow_types ($2); }
  874. | typebase const_or_volatile_or_space_identifier_noopt
  875. { $$ = follow_types ($1); }
  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. ptype : typebase
  910. | ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
  911. { $$ = follow_types ($1); }
  912. ;
  913. const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
  914. | VOLATILE_KEYWORD CONST_KEYWORD
  915. ;
  916. const_or_volatile_noopt: const_and_volatile
  917. { push_type (tp_const);
  918. push_type (tp_volatile);
  919. }
  920. | CONST_KEYWORD
  921. { push_type (tp_const); }
  922. | VOLATILE_KEYWORD
  923. { push_type (tp_volatile); }
  924. ;
  925. name : NAME { $$ = $1.stoken; }
  926. | BLOCKNAME { $$ = $1.stoken; }
  927. | TYPENAME { $$ = $1.stoken; }
  928. | CLASSNAME { $$ = $1.stoken; }
  929. | NAME_OR_INT { $$ = $1.stoken; }
  930. ;
  931. name_not_typename : NAME
  932. | BLOCKNAME
  933. /* These would be useful if name_not_typename was useful, but it is just
  934. a fake for &quot;variable&quot;, so these cause reduce/reduce conflicts because
  935. the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
  936. =exp) or just an exp. If name_not_typename was ever used in an lvalue
  937. context where only a name could occur, this might be useful.
  938. | NAME_OR_INT
  939. */
  940. ;
  941. %%
  942. /* Take care of parsing a number (anything that starts with a digit).
  943. Set yylval and return the token type; update lexptr.
  944. LEN is the number of characters in it. */
  945. /*** Needs some error checking for the float case ***/
  946. static int
  947. parse_number (p, len, parsed_float, putithere)
  948. register char *p;
  949. register int len;
  950. int parsed_float;
  951. YYSTYPE *putithere;
  952. {
  953. /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
  954. here, and we do kind of silly things like cast to unsigned. */
  955. register LONGEST n = 0;
  956. register LONGEST prevn = 0;
  957. ULONGEST un;
  958. register int i = 0;
  959. register int c;
  960. register int base = input_radix;
  961. int unsigned_p = 0;
  962. /* Number of &quot;L&quot; suffixes encountered. */
  963. int long_p = 0;
  964. /* We have found a &quot;L&quot; or &quot;U&quot; suffix. */
  965. int found_suffix = 0;
  966. ULONGEST high_bit;
  967. struct type *signed_type;
  968. struct type *unsigned_type;
  969. if (parsed_float)
  970. {
  971. /* It's a float since it contains a point or an exponent. */
  972. char c;
  973. int num = 0; /* number of tokens scanned by scanf */
  974. char saved_char = p[len];
  975. p[len] = 0; /* null-terminate the token */
  976. if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (float))
  977. num = sscanf (p, &quot;%g%c&quot;, (float *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  978. else if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (double))
  979. num = sscanf (p, &quot;%lg%c&quot;, (double *) &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  980. else
  981. {
  982. #ifdef SCANF_HAS_LONG_DOUBLE
  983. num = sscanf (p, &quot;%Lg%c&quot;, &amp;putithere-&gt;typed_val_float.dval,&amp;c);
  984. #else
  985. /* Scan it into a double, then assign it to the long double.
  986. This at least wins with values representable in the range
  987. of doubles. */
  988. double temp;
  989. num = sscanf (p, &quot;%lg%c&quot;, &amp;temp,&amp;c);
  990. putithere-&gt;typed_val_float.dval = temp;
  991. #endif
  992. }
  993. p[len] = saved_char; /* restore the input stream */
  994. if (num != 1) /* check scanf found ONLY a float ... */
  995. return ERROR;
  996. /* See if it has `f' or `l' suffix (float or long double). */
  997. c = tolower (p[len - 1]);
  998. if (c == 'f')
  999. putithere-&gt;typed_val_float.type = builtin_type_float;
  1000. else if (c == 'l')
  1001. putithere-&gt;typed_val_float.type = builtin_type_long_double;
  1002. else if (isdigit (c) || c == '.')
  1003. putithere-&gt;typed_val_float.type = builtin_type_double;
  1004. else
  1005. return ERROR;
  1006. return FLOAT;
  1007. }
  1008. /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  1009. if (p[0] == '0')
  1010. switch (p[1])
  1011. {
  1012. case 'x':
  1013. case 'X':
  1014. if (len &gt;= 3)
  1015. {
  1016. p += 2;
  1017. base = 16;
  1018. len -= 2;
  1019. }
  1020. break;
  1021. case 't':
  1022. case 'T':
  1023. case 'd':
  1024. case 'D':
  1025. if (len &gt;= 3)
  1026. {
  1027. p += 2;
  1028. base = 10;
  1029. len -= 2;
  1030. }
  1031. break;
  1032. default:
  1033. base = 8;
  1034. break;
  1035. }
  1036. while (len-- &gt; 0)
  1037. {
  1038. c = *p++;
  1039. if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')
  1040. c += 'a' - 'A';
  1041. if (c != 'l' &amp;&amp; c != 'u')
  1042. n *= base;
  1043. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1044. {
  1045. if (found_suffix)
  1046. return ERROR;
  1047. n += i = c - '0';
  1048. }
  1049. else
  1050. {
  1051. if (base &gt; 10 &amp;&amp; c &gt;= 'a' &amp;&amp; c &lt;= 'f')
  1052. {
  1053. if (found_suffix)
  1054. return ERROR;
  1055. n += i = c - 'a' + 10;
  1056. }
  1057. else if (c == 'l')
  1058. {
  1059. ++long_p;
  1060. found_suffix = 1;
  1061. }
  1062. else if (c == 'u')
  1063. {
  1064. unsigned_p = 1;
  1065. found_suffix = 1;
  1066. }
  1067. else
  1068. return ERROR; /* Char not a digit */
  1069. }
  1070. if (i &gt;= base)
  1071. return ERROR; /* Invalid digit in this base */
  1072. /* Portably test for overflow (only works for nonzero values, so make
  1073. a second check for zero). FIXME: Can't we just make n and prevn
  1074. unsigned and avoid this? */
  1075. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; (prevn &gt;= n) &amp;&amp; n != 0)
  1076. unsigned_p = 1; /* Try something unsigned */
  1077. /* Portably test for unsigned overflow.
  1078. FIXME: This check is wrong; for example it doesn't find overflow
  1079. on 0x123456789 when LONGEST is 32 bits. */
  1080. if (c != 'l' &amp;&amp; c != 'u' &amp;&amp; n != 0)
  1081. {
  1082. if ((unsigned_p &amp;&amp; (ULONGEST) prevn &gt;= (ULONGEST) n))
  1083. error (&quot;Numeric constant too large.&quot;);
  1084. }
  1085. prevn = n;
  1086. }
  1087. /* An integer constant is an int, a long, or a long long. An L
  1088. suffix forces it to be long; an LL suffix forces it to be long
  1089. long. If not forced to a larger size, it gets the first type of
  1090. the above that it fits in. To figure out whether it fits, we
  1091. shift it right and see whether anything remains. Note that we
  1092. can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  1093. operation, because many compilers will warn about such a shift
  1094. (which always produces a zero result). Sometimes TARGET_INT_BIT
  1095. or TARGET_LONG_BIT will be that big, sometimes not. To deal with
  1096. the case where it is we just always shift the value more than
  1097. once, with fewer bits each time. */
  1098. un = (ULONGEST)n &gt;&gt; 2;
  1099. if (long_p == 0
  1100. &amp;&amp; (un &gt;&gt; (TARGET_INT_BIT - 2)) == 0)
  1101. {
  1102. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_INT_BIT-1);
  1103. /* A large decimal (not hex or octal) constant (between INT_MAX
  1104. and UINT_MAX) is a long or unsigned long, according to ANSI,
  1105. never an unsigned int, but this code treats it as unsigned
  1106. int. This probably should be fixed. GCC gives a warning on
  1107. such constants. */
  1108. unsigned_type = builtin_type_unsigned_int;
  1109. signed_type = builtin_type_int;
  1110. }
  1111. else if (long_p &lt;= 1
  1112. &amp;&amp; (un &gt;&gt; (TARGET_LONG_BIT - 2)) == 0)
  1113. {
  1114. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_LONG_BIT-1);
  1115. unsigned_type = builtin_type_unsigned_long;
  1116. signed_type = builtin_type_long;
  1117. }
  1118. else
  1119. {
  1120. int shift;
  1121. if (sizeof (ULONGEST) * HOST_CHAR_BIT &lt; TARGET_LONG_LONG_BIT)
  1122. /* A long long does not fit in a LONGEST. */
  1123. shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
  1124. else
  1125. shift = (TARGET_LONG_LONG_BIT - 1);
  1126. high_bit = (ULONGEST) 1 &lt;&lt; shift;
  1127. unsigned_type = builtin_type_unsigned_long_long;
  1128. signed_type = builtin_type_long_long;
  1129. }
  1130. putithere-&gt;typed_val_int.val = n;
  1131. /* If the high bit of the worked out type is set then this number
  1132. has to be unsigned. */
  1133. if (unsigned_p || (n &amp; high_bit))
  1134. {
  1135. putithere-&gt;typed_val_int.type = unsigned_type;
  1136. }
  1137. else
  1138. {
  1139. putithere-&gt;typed_val_int.type = signed_type;
  1140. }
  1141. return INT;
  1142. }
  1143. struct token
  1144. {
  1145. char *operator;
  1146. int token;
  1147. enum exp_opcode opcode;
  1148. };
  1149. static const struct token tokentab3[] =
  1150. {
  1151. {&quot;&gt;&gt;=&quot;, ASSIGN_MODIFY, BINOP_RSH},
  1152. {&quot;&lt;&lt;=&quot;, ASSIGN_MODIFY, BINOP_LSH}
  1153. };
  1154. static const struct token tokentab2[] =
  1155. {
  1156. {&quot;+=&quot;, ASSIGN_MODIFY, BINOP_ADD},
  1157. {&quot;-=&quot;, ASSIGN_MODIFY, BINOP_SUB},
  1158. {&quot;*=&quot;, ASSIGN_MODIFY, BINOP_MUL},
  1159. {&quot;/=&quot;, ASSIGN_MODIFY, BINOP_DIV},
  1160. {&quot;%=&quot;, ASSIGN_MODIFY, BINOP_REM},
  1161. {&quot;|=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_IOR},
  1162. {&quot;&amp;=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_AND},
  1163. {&quot;^=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_XOR},
  1164. {&quot;++&quot;, INCREMENT, BINOP_END},
  1165. {&quot;--&quot;, DECREMENT, BINOP_END},
  1166. {&quot;-&gt;&quot;, ARROW, BINOP_END},
  1167. {&quot;&amp;&amp;&quot;, ANDAND, BINOP_END},
  1168. {&quot;||&quot;, OROR, BINOP_END},
  1169. {&quot;::&quot;, COLONCOLON, BINOP_END},
  1170. {&quot;&lt;&lt;&quot;, LSH, BINOP_END},
  1171. {&quot;&gt;&gt;&quot;, RSH, BINOP_END},
  1172. {&quot;==&quot;, EQUAL, BINOP_END},
  1173. {&quot;!=&quot;, NOTEQUAL, BINOP_END},
  1174. {&quot;&lt;=&quot;, LEQ, BINOP_END},
  1175. {&quot;&gt;=&quot;, GEQ, BINOP_END}
  1176. };
  1177. /* Read one token, getting characters through lexptr. */
  1178. static int
  1179. yylex ()
  1180. {
  1181. int c;
  1182. int namelen;
  1183. unsigned int i;
  1184. int tokchr;
  1185. char *tokstart;
  1186. char *tokptr;
  1187. int tempbufindex;
  1188. static char *tempbuf;
  1189. static int tempbufsize;
  1190. struct symbol * sym_class = NULL;
  1191. char * token_string = NULL;
  1192. int class_prefix = 0;
  1193. int unquoted_expr;
  1194. retry:
  1195. /* Check if this is a macro invocation that we need to expand. */
  1196. if (! scanning_macro_expansion ())
  1197. {
  1198. char *expanded = macro_expand_next (&amp;lexptr,
  1199. expression_macro_lookup_func,
  1200. expression_macro_lookup_baton);
  1201. if (expanded)
  1202. scan_macro_expansion (expanded);
  1203. }
  1204. prev_lexptr = lexptr;
  1205. unquoted_expr = 1;
  1206. tokstart = lexptr;
  1207. /* See if it is a special token of length 3. */
  1208. for (i = 0; i &lt; sizeof tokentab3 / sizeof tokentab3[0]; i++)
  1209. if (STREQN (tokstart, tokentab3[i].operator, 3))
  1210. {
  1211. lexptr += 3;
  1212. yylval.opcode = tokentab3[i].opcode;
  1213. return tokentab3[i].token;
  1214. }
  1215. /* See if it is a special token of length 2. */
  1216. for (i = 0; i &lt; sizeof tokentab2 / sizeof tokentab2[0]; i++)
  1217. if (STREQN (tokstart, tokentab2[i].operator, 2))
  1218. {
  1219. lexptr += 2;
  1220. yylval.opcode = tokentab2[i].opcode;
  1221. return tokentab2[i].token;
  1222. }
  1223. switch (tokchr = *tokstart)
  1224. {
  1225. case 0:
  1226. /* If we were just scanning the result of a macro expansion,
  1227. then we need to resume scanning the original text.
  1228. Otherwise, we were already scanning the original text, and
  1229. we're really done. */
  1230. if (scanning_macro_expansion ())
  1231. {
  1232. finished_macro_expansion ();
  1233. goto retry;
  1234. }
  1235. else
  1236. return 0;
  1237. case ' ':
  1238. case '\t':
  1239. case '\n':
  1240. lexptr++;
  1241. goto retry;
  1242. case '\'':
  1243. /* We either have a character constant ('0' or '\177' for example)
  1244. or we have a quoted symbol reference ('foo(int,int)' in C++
  1245. for example). */
  1246. lexptr++;
  1247. c = *lexptr++;
  1248. if (c == '\\')
  1249. c = parse_escape (&amp;lexptr);
  1250. else if (c == '\'')
  1251. error (&quot;Empty character constant.&quot;);
  1252. else if (! host_char_to_target (c, &amp;c))
  1253. {
  1254. int toklen = lexptr - tokstart + 1;
  1255. char *tok = alloca (toklen + 1);
  1256. memcpy (tok, tokstart, toklen);
  1257. tok[toklen] = '\0';
  1258. error (&quot;There is no character corresponding to %s in the target &quot;
  1259. &quot;character set `%s'.&quot;, tok, target_charset ());
  1260. }
  1261. yylval.typed_val_int.val = c;
  1262. yylval.typed_val_int.type = builtin_type_char;
  1263. c = *lexptr++;
  1264. if (c != '\'')
  1265. {
  1266. namelen = skip_quoted (tokstart, get_gdb_completer_word_break_characters ())
  1267. - tokstart;
  1268. if (namelen &gt; 2)
  1269. {
  1270. lexptr = tokstart + namelen;
  1271. unquoted_expr = 0;
  1272. if (lexptr[-1] != '\'')
  1273. error (&quot;Unmatched single quote.&quot;);
  1274. namelen -= 2;
  1275. tokstart++;
  1276. goto tryname;
  1277. }
  1278. error (&quot;Invalid character constant.&quot;);
  1279. }
  1280. return INT;
  1281. case '(':
  1282. paren_depth++;
  1283. lexptr++;
  1284. return '(';
  1285. case ')':
  1286. if (paren_depth == 0)
  1287. return 0;
  1288. paren_depth--;
  1289. lexptr++;
  1290. return ')';
  1291. case ',':
  1292. if (comma_terminates
  1293. &amp;&amp; paren_depth == 0
  1294. &amp;&amp; ! scanning_macro_expansion ())
  1295. return 0;
  1296. lexptr++;
  1297. return ',';
  1298. case '.':
  1299. /* Might be a floating point number. */
  1300. if (lexptr[1] &lt; '0' || lexptr[1] &gt; '9')
  1301. goto symbol; /* Nope, must be a symbol. */
  1302. /* FALL THRU into number case. */
  1303. case '0':
  1304. case '1':
  1305. case '2':
  1306. case '3':
  1307. case '4':
  1308. case '5':
  1309. case '6':
  1310. case '7':
  1311. case '8':
  1312. case '9':
  1313. {
  1314. /* It's a number. */
  1315. int got_dot = 0, got_e = 0, toktype;
  1316. register char *p = tokstart;
  1317. int hex = input_radix &gt; 10;
  1318. if (tokchr == '0' &amp;&amp; (p[1] == 'x' || p[1] == 'X'))
  1319. {
  1320. p += 2;
  1321. hex = 1;
  1322. }
  1323. else if (tokchr == '0' &amp;&amp; (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  1324. {
  1325. p += 2;
  1326. hex = 0;
  1327. }
  1328. for (;; ++p)
  1329. {
  1330. /* This test includes !hex because 'e' is a valid hex digit
  1331. and thus does not indicate a floating point number when
  1332. the radix is hex. */
  1333. if (!hex &amp;&amp; !got_e &amp;&amp; (*p == 'e' || *p == 'E'))
  1334. got_dot = got_e = 1;
  1335. /* This test does not include !hex, because a '.' always indicates
  1336. a decimal floating point number regardless of the radix. */
  1337. else if (!got_dot &amp;&amp; *p == '.')
  1338. got_dot = 1;
  1339. else if (got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E')
  1340. &amp;&amp; (*p == '-' || *p == '+'))
  1341. /* This is the sign of the exponent, not the end of the
  1342. number. */
  1343. continue;
  1344. /* We will take any letters or digits. parse_number will
  1345. complain if past the radix, or if L or U are not final. */
  1346. else if ((*p &lt; '0' || *p &gt; '9')
  1347. &amp;&amp; ((*p &lt; 'a' || *p &gt; 'z')
  1348. &amp;&amp; (*p &lt; 'A' || *p &gt; 'Z')))
  1349. break;
  1350. }
  1351. toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &amp;yylval);
  1352. if (toktype == ERROR)
  1353. {
  1354. char *err_copy = (char *) alloca (p - tokstart + 1);
  1355. memcpy (err_copy, tokstart, p - tokstart);
  1356. err_copy[p - tokstart] = 0;
  1357. error (&quot;Invalid number \&quot;%s\&quot;.&quot;, err_copy);
  1358. }
  1359. lexptr = p;
  1360. return toktype;
  1361. }
  1362. case '+':
  1363. case '-':
  1364. case '*':
  1365. case '/':
  1366. case '%':
  1367. case '|':
  1368. case '&amp;':
  1369. case '^':
  1370. case '~':
  1371. case '!':
  1372. case '&lt;':
  1373. case '&gt;':
  1374. case '[':
  1375. case ']':
  1376. case '?':
  1377. case ':':
  1378. case '=':
  1379. case '{':
  1380. case '}':
  1381. symbol:
  1382. lexptr++;
  1383. return tokchr;
  1384. case '@':
  1385. if (strncmp (tokstart, &quot;@selector&quot;, 9) == 0)
  1386. {
  1387. tokptr = strchr (tokstart, '(');
  1388. if (tokptr == NULL)
  1389. error (&quot;Missing '(' in @selector(...)&quot;);
  1390. tempbufindex = 0;
  1391. /* skip the '(' */
  1392. tokptr++;
  1393. do {
  1394. /* Grow the static temp buffer if necessary, including allocating
  1395. the first one on demand. */
  1396. if (tempbufindex + 1 &gt;= tempbufsize)
  1397. {
  1398. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1399. }
  1400. tempbuf[tempbufindex++] = *tokptr++;
  1401. } while ((*tokptr != ')') &amp;&amp; (*tokptr != '\0'));
  1402. if (*tokptr++ != ')')
  1403. error (&quot;Missing ')' in @selector(...)&quot;);
  1404. tempbuf[tempbufindex] = '\0';
  1405. yylval.sval.ptr = tempbuf;
  1406. yylval.sval.length = tempbufindex;
  1407. lexptr = tokptr;
  1408. return SELECTOR;
  1409. }
  1410. if (tokstart[1] != '&quot;')
  1411. {
  1412. lexptr++;
  1413. return tokchr;
  1414. }
  1415. /* Obj-C NSString constant: fall through and parse like STRING. */
  1416. tokstart++;
  1417. case '&quot;':
  1418. /* Build the gdb internal form of the input string in tempbuf,
  1419. translating any standard C escape forms seen. Note that the
  1420. buffer is null byte terminated *only* for the convenience of
  1421. debugging gdb itself and printing the buffer contents when
  1422. the buffer contains no embedded nulls. Gdb does not depend
  1423. upon the buffer being null byte terminated, it uses the length
  1424. string instead. This allows gdb to handle C strings (as well
  1425. as strings in other languages) with embedded null bytes */
  1426. tokptr = ++tokstart;
  1427. tempbufindex = 0;
  1428. do {
  1429. char *char_start_pos = tokptr;
  1430. /* Grow the static temp buffer if necessary, including allocating
  1431. the first one on demand. */
  1432. if (tempbufindex + 1 &gt;= tempbufsize)
  1433. {
  1434. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1435. }
  1436. switch (*tokptr)
  1437. {
  1438. case '\0':
  1439. case '&quot;':
  1440. /* Do nothing, loop will terminate. */
  1441. break;
  1442. case '\\':
  1443. tokptr++;
  1444. c = parse_escape (&amp;tokptr);
  1445. if (c == -1)
  1446. {
  1447. continue;
  1448. }
  1449. tempbuf[tempbufindex++] = c;
  1450. break;
  1451. default:
  1452. c = *tokptr++;
  1453. if (! host_char_to_target (c, &amp;c))
  1454. {
  1455. int len = tokptr - char_start_pos;
  1456. char *copy = alloca (len + 1);
  1457. memcpy (copy, char_start_pos, len);
  1458. copy[len] = '\0';
  1459. error (&quot;There is no character corresponding to `%s' &quot;
  1460. &quot;in the target character set `%s'.&quot;,
  1461. copy, target_charset ());
  1462. }
  1463. tempbuf[tempbufindex++] = c;
  1464. break;
  1465. }
  1466. } while ((*tokptr != '&quot;') &amp;&amp; (*tokptr != '\0'));
  1467. if (*tokptr++ != '&quot;')
  1468. {
  1469. error (&quot;Unterminated string in expression.&quot;);
  1470. }
  1471. tempbuf[tempbufindex] = '\0'; /* See note above */
  1472. yylval.sval.ptr = tempbuf;
  1473. yylval.sval.length = tempbufindex;
  1474. lexptr = tokptr;
  1475. return (tokchr == '@' ? NSSTRING : STRING);
  1476. }
  1477. if (!(tokchr == '_' || tokchr == '$' ||
  1478. (tokchr &gt;= 'a' &amp;&amp; tokchr &lt;= 'z') || (tokchr &gt;= 'A' &amp;&amp; tokchr &lt;= 'Z')))
  1479. /* We must have come across a bad character (e.g. ';'). */
  1480. error (&quot;Invalid character '%c' in expression.&quot;, tokchr);
  1481. /* It's a name. See how long it is. */
  1482. namelen = 0;
  1483. for (c = tokstart[namelen];
  1484. (c == '_' || c == '$' || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  1485. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || c == '&lt;');)
  1486. {
  1487. /* Template parameter lists are part of the name.
  1488. FIXME: This mishandles `print $a&lt;4&amp;&amp;$a&gt;3'. */
  1489. if (c == '&lt;')
  1490. {
  1491. /* Scan ahead to get rest of the template specification. Note
  1492. that we look ahead only when the '&lt;' adjoins non-whitespace
  1493. characters; for comparison expressions, e.g. &quot;a &lt; b &gt; c&quot;,
  1494. there must be spaces before the '&lt;', etc. */
  1495. char * p = find_template_name_end (tokstart + namelen);
  1496. if (p)
  1497. namelen = p - tokstart;
  1498. break;
  1499. }
  1500. c = tokstart[++namelen];
  1501. }
  1502. /* The token &quot;if&quot; terminates the expression and is NOT removed from
  1503. the input stream. It doesn't count if it appears in the
  1504. expansion of a macro. */
  1505. if (namelen == 2
  1506. &amp;&amp; tokstart[0] == 'i'
  1507. &amp;&amp; tokstart[1] == 'f'
  1508. &amp;&amp; ! scanning_macro_expansion ())
  1509. {
  1510. return 0;
  1511. }
  1512. lexptr += namelen;
  1513. tryname:
  1514. /* Catch specific keywords. Should be done with a data structure. */
  1515. switch (namelen)
  1516. {
  1517. case 8:
  1518. if (STREQN (tokstart, &quot;unsigned&quot;, 8))
  1519. return UNSIGNED;
  1520. if (current_language-&gt;la_language == language_cplus
  1521. &amp;&amp; STREQN (tokstart, &quot;template&quot;, 8))
  1522. return TEMPLATE;
  1523. if (STREQN (tokstart, &quot;volatile&quot;, 8))
  1524. return VOLATILE_KEYWORD;
  1525. break;
  1526. case 6:
  1527. if (STREQN (tokstart, &quot;struct&quot;, 6))
  1528. return STRUCT;
  1529. if (STREQN (tokstart, &quot;signed&quot;, 6))
  1530. return SIGNED_KEYWORD;
  1531. if (STREQN (tokstart, &quot;sizeof&quot;, 6))
  1532. return SIZEOF;
  1533. if (STREQN (tokstart, &quot;double&quot;, 6))
  1534. return DOUBLE_KEYWORD;
  1535. break;
  1536. case 5:
  1537. if (current_language-&gt;la_language == language_cplus)
  1538. {
  1539. if (STREQN (tokstart, &quot;false&quot;, 5))
  1540. return FALSEKEYWORD;
  1541. if (STREQN (tokstart, &quot;class&quot;, 5))
  1542. return CLASS;
  1543. }
  1544. if (STREQN (tokstart, &quot;union&quot;, 5))
  1545. return UNION;
  1546. if (STREQN (tokstart, &quot;short&quot;, 5))
  1547. return SHORT;
  1548. if (STREQN (tokstart, &quot;const&quot;, 5))
  1549. return CONST_KEYWORD;
  1550. break;
  1551. case 4:
  1552. if (STREQN (tokstart, &quot;enum&quot;, 4))
  1553. return ENUM;
  1554. if (STREQN (tokstart, &quot;long&quot;, 4))
  1555. return LONG;
  1556. if (current_language-&gt;la_language == language_cplus)
  1557. {
  1558. if (STREQN (tokstart, &quot;true&quot;, 4))
  1559. return TRUEKEYWORD;
  1560. }
  1561. break;
  1562. case 3:
  1563. if (STREQN (tokstart, &quot;int&quot;, 3))
  1564. return INT_KEYWORD;
  1565. break;
  1566. default:
  1567. break;
  1568. }
  1569. yylval.sval.ptr = tokstart;
  1570. yylval.sval.length = namelen;
  1571. if (*tokstart == '$')
  1572. {
  1573. write_dollar_variable (yylval.sval);
  1574. return VARIABLE;
  1575. }
  1576. /* Look ahead and see if we can consume more of the input
  1577. string to get a reasonable class/namespace spec or a
  1578. fully-qualified name. This is a kludge to get around the
  1579. HP aCC compiler's generation of symbol names with embedded
  1580. colons for namespace and …

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