PageRenderTime 65ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Happy | 2059 lines | 1818 code | 241 blank | 0 comment | 0 complexity | 5404727ad7ebbda71892b292904b2875 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD

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

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