PageRenderTime 69ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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