PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Happy | 2029 lines | 1791 code | 238 blank | 0 comment | 0 complexity | 6c22a87aafd264e0069ba84e2fa9ae64 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0-no-copyleft-exception, MPL-2.0, JSON, 0BSD, LGPL-2.1, Apache-2.0, BSD-3-Clause, ISC, LGPL-2.0, WTFPL, MIT

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

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