PageRenderTime 66ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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