PageRenderTime 68ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/gdb/gdb/c-exp.y

https://review.tizen.org/git/
Happy | 2626 lines | 2296 code | 330 blank | 0 comment | 0 complexity | 12ef63c17302924b4711bbd4ad020923 MD5 | raw file
Possible License(s): GPL-3.0, AGPL-3.0, GPL-2.0, MPL-2.0, JSON, WTFPL, CC-BY-SA-4.0, CC-BY-3.0, BSD-3-Clause, LGPL-2.0, MPL-2.0-no-copyleft-exception, AGPL-1.0, 0BSD, Zlib, Unlicense, BSD-2-Clause, Apache-2.0, LGPL-3.0, ISC, MIT, CC-BY-SA-3.0, CC0-1.0, LGPL-2.1

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

  1. /* YACC parser for C expressions, for GDB.
  2. Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
  3. 1998, 1999, 2000, 2003, 2004, 2006, 2007, 2008, 2009, 2010
  4. Free Software Foundation, Inc.
  5. This file is part of GDB.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. /* Parse a C expression from text in a string,
  17. and return the result as a struct expression pointer.
  18. That structure contains arithmetic operations in reverse polish,
  19. with constants represented by operations that are followed by special data.
  20. See expression.h for the details of the format.
  21. What is important here is that it can be built up sequentially
  22. during the process of parsing; the lower levels of the tree always
  23. come first in the result.
  24. Note that malloc's and realloc's in this file are transformed to
  25. xmalloc and xrealloc respectively by the same sed command in the
  26. makefile that remaps any other malloc/realloc inserted by the parser
  27. generator. Doing this with #defines and trying to control the interaction
  28. with include files (<malloc.h> and <stdlib.h> for example) just became
  29. too messy, particularly when such includes can be inserted at random
  30. times by the parser generator. */
  31. %{
  32. #include "defs.h"
  33. #include "gdb_string.h"
  34. #include <ctype.h>
  35. #include "expression.h"
  36. #include "value.h"
  37. #include "parser-defs.h"
  38. #include "language.h"
  39. #include "c-lang.h"
  40. #include "bfd.h" /* Required by objfiles.h. */
  41. #include "symfile.h" /* Required by objfiles.h. */
  42. #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
  43. #include "charset.h"
  44. #include "block.h"
  45. #include "cp-support.h"
  46. #include "dfp.h"
  47. #include "gdb_assert.h"
  48. #include "macroscope.h"
  49. #define parse_type builtin_type (parse_gdbarch)
  50. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  51. as well as gratuitiously global symbol names, so we can have multiple
  52. yacc generated parsers in gdb. Note that these are only the variables
  53. produced by yacc. If other parser generators (bison, byacc, etc) produce
  54. additional global names that conflict at link time, then those parser
  55. generators need to be fixed instead of adding those names to this list. */
  56. #define yymaxdepth c_maxdepth
  57. #define yyparse c_parse_internal
  58. #define yylex c_lex
  59. #define yyerror c_error
  60. #define yylval c_lval
  61. #define yychar c_char
  62. #define yydebug c_debug
  63. #define yypact c_pact
  64. #define yyr1 c_r1
  65. #define yyr2 c_r2
  66. #define yydef c_def
  67. #define yychk c_chk
  68. #define yypgo c_pgo
  69. #define yyact c_act
  70. #define yyexca c_exca
  71. #define yyerrflag c_errflag
  72. #define yynerrs c_nerrs
  73. #define yyps c_ps
  74. #define yypv c_pv
  75. #define yys c_s
  76. #define yy_yys c_yys
  77. #define yystate c_state
  78. #define yytmp c_tmp
  79. #define yyv c_v
  80. #define yy_yyv c_yyv
  81. #define yyval c_val
  82. #define yylloc c_lloc
  83. #define yyreds c_reds /* With YYDEBUG defined */
  84. #define yytoks c_toks /* With YYDEBUG defined */
  85. #define yyname c_name /* With YYDEBUG defined */
  86. #define yyrule c_rule /* With YYDEBUG defined */
  87. #define yylhs c_yylhs
  88. #define yylen c_yylen
  89. #define yydefred c_yydefred
  90. #define yydgoto c_yydgoto
  91. #define yysindex c_yysindex
  92. #define yyrindex c_yyrindex
  93. #define yygindex c_yygindex
  94. #define yytable c_yytable
  95. #define yycheck c_yycheck
  96. #ifndef YYDEBUG
  97. #define YYDEBUG 1 /* Default to yydebug support */
  98. #endif
  99. #define YYFPRINTF parser_fprintf
  100. int yyparse (void);
  101. static int yylex (void);
  102. void yyerror (char *);
  103. %}
  104. /* Although the yacc "value" of an expression is not used,
  105. since the result is stored in the structure being created,
  106. other node types do have values. */
  107. %union
  108. {
  109. LONGEST lval;
  110. struct {
  111. LONGEST val;
  112. struct type *type;
  113. } typed_val_int;
  114. struct {
  115. DOUBLEST dval;
  116. struct type *type;
  117. } typed_val_float;
  118. struct {
  119. gdb_byte val[16];
  120. struct type *type;
  121. } typed_val_decfloat;
  122. struct symbol *sym;
  123. struct type *tval;
  124. struct stoken sval;
  125. struct typed_stoken tsval;
  126. struct ttype tsym;
  127. struct symtoken ssym;
  128. int voidval;
  129. struct block *bval;
  130. enum exp_opcode opcode;
  131. struct internalvar *ivar;
  132. struct stoken_vector svec;
  133. struct type **tvec;
  134. int *ivec;
  135. }
  136. %{
  137. /* YYSTYPE gets defined by %union */
  138. static int parse_number (char *, int, int, YYSTYPE *);
  139. static struct stoken operator_stoken (const char *);
  140. %}
  141. %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
  142. %type <lval> rcurly
  143. %type <tval> type typebase
  144. %type <tvec> nonempty_typelist
  145. /* %type <bval> block */
  146. /* Fancy type parsing. */
  147. %type <voidval> func_mod direct_abs_decl abs_decl
  148. %type <tval> ptype
  149. %type <lval> array_mod
  150. %token <typed_val_int> INT
  151. %token <typed_val_float> FLOAT
  152. %token <typed_val_decfloat> DECFLOAT
  153. /* Both NAME and TYPENAME tokens represent symbols in the input,
  154. and both convey their data as strings.
  155. But a TYPENAME is a string that happens to be defined as a typedef
  156. or builtin type name (such as int or char)
  157. and a NAME is any other symbol.
  158. Contexts where this distinction is not important can use the
  159. nonterminal "name", which matches either NAME or TYPENAME. */
  160. %token <tsval> STRING
  161. %token <tsval> CHAR
  162. %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
  163. %token <ssym> UNKNOWN_CPP_NAME
  164. %token <voidval> COMPLETE
  165. %token <tsym> TYPENAME
  166. %type <sval> name
  167. %type <svec> string_exp
  168. %type <ssym> name_not_typename
  169. %type <tsym> typename
  170. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  171. but which would parse as a valid number in the current input radix.
  172. E.g. "c" when input_radix==16. Depending on the parse, it will be
  173. turned into a name or into a number. */
  174. %token <ssym> NAME_OR_INT
  175. %token OPERATOR
  176. %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
  177. %token TEMPLATE
  178. %token ERROR
  179. %token NEW DELETE
  180. %type <sval> operator
  181. %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
  182. /* Special type cases, put in to allow the parser to distinguish different
  183. legal basetypes. */
  184. %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
  185. %token <sval> VARIABLE
  186. %token <opcode> ASSIGN_MODIFY
  187. /* C++ */
  188. %token TRUEKEYWORD
  189. %token FALSEKEYWORD
  190. %left ','
  191. %left ABOVE_COMMA
  192. %right '=' ASSIGN_MODIFY
  193. %right '?'
  194. %left OROR
  195. %left ANDAND
  196. %left '|'
  197. %left '^'
  198. %left '&'
  199. %left EQUAL NOTEQUAL
  200. %left '<' '>' LEQ GEQ
  201. %left LSH RSH
  202. %left '@'
  203. %left '+' '-'
  204. %left '*' '/' '%'
  205. %right UNARY INCREMENT DECREMENT
  206. %right ARROW ARROW_STAR '.' DOT_STAR '[' '('
  207. %token <ssym> BLOCKNAME
  208. %token <bval> FILENAME
  209. %type <bval> block
  210. %left COLONCOLON
  211. %%
  212. start : exp1
  213. | type_exp
  214. ;
  215. type_exp: type
  216. { write_exp_elt_opcode(OP_TYPE);
  217. write_exp_elt_type($1);
  218. write_exp_elt_opcode(OP_TYPE);}
  219. ;
  220. /* Expressions, including the comma operator. */
  221. exp1 : exp
  222. | exp1 ',' exp
  223. { write_exp_elt_opcode (BINOP_COMMA); }
  224. ;
  225. /* Expressions, not including the comma operator. */
  226. exp : '*' exp %prec UNARY
  227. { write_exp_elt_opcode (UNOP_IND); }
  228. ;
  229. exp : '&' exp %prec UNARY
  230. { write_exp_elt_opcode (UNOP_ADDR); }
  231. ;
  232. exp : '-' exp %prec UNARY
  233. { write_exp_elt_opcode (UNOP_NEG); }
  234. ;
  235. exp : '+' exp %prec UNARY
  236. { write_exp_elt_opcode (UNOP_PLUS); }
  237. ;
  238. exp : '!' exp %prec UNARY
  239. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  240. ;
  241. exp : '~' exp %prec UNARY
  242. { write_exp_elt_opcode (UNOP_COMPLEMENT); }
  243. ;
  244. exp : INCREMENT exp %prec UNARY
  245. { write_exp_elt_opcode (UNOP_PREINCREMENT); }
  246. ;
  247. exp : DECREMENT exp %prec UNARY
  248. { write_exp_elt_opcode (UNOP_PREDECREMENT); }
  249. ;
  250. exp : exp INCREMENT %prec UNARY
  251. { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
  252. ;
  253. exp : exp DECREMENT %prec UNARY
  254. { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
  255. ;
  256. exp : SIZEOF exp %prec UNARY
  257. { write_exp_elt_opcode (UNOP_SIZEOF); }
  258. ;
  259. exp : exp ARROW name
  260. { write_exp_elt_opcode (STRUCTOP_PTR);
  261. write_exp_string ($3);
  262. write_exp_elt_opcode (STRUCTOP_PTR); }
  263. ;
  264. exp : exp ARROW name COMPLETE
  265. { mark_struct_expression ();
  266. write_exp_elt_opcode (STRUCTOP_PTR);
  267. write_exp_string ($3);
  268. write_exp_elt_opcode (STRUCTOP_PTR); }
  269. ;
  270. exp : exp ARROW COMPLETE
  271. { struct stoken s;
  272. mark_struct_expression ();
  273. write_exp_elt_opcode (STRUCTOP_PTR);
  274. s.ptr = "";
  275. s.length = 0;
  276. write_exp_string (s);
  277. write_exp_elt_opcode (STRUCTOP_PTR); }
  278. ;
  279. exp : exp ARROW qualified_name
  280. { /* exp->type::name becomes exp->*(&type::name) */
  281. /* Note: this doesn't work if name is a
  282. static member! FIXME */
  283. write_exp_elt_opcode (UNOP_ADDR);
  284. write_exp_elt_opcode (STRUCTOP_MPTR); }
  285. ;
  286. exp : exp ARROW_STAR exp
  287. { write_exp_elt_opcode (STRUCTOP_MPTR); }
  288. ;
  289. exp : exp '.' name
  290. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  291. write_exp_string ($3);
  292. write_exp_elt_opcode (STRUCTOP_STRUCT); }
  293. ;
  294. exp : exp '.' name COMPLETE
  295. { mark_struct_expression ();
  296. write_exp_elt_opcode (STRUCTOP_STRUCT);
  297. write_exp_string ($3);
  298. write_exp_elt_opcode (STRUCTOP_STRUCT); }
  299. ;
  300. exp : exp '.' COMPLETE
  301. { struct stoken s;
  302. mark_struct_expression ();
  303. write_exp_elt_opcode (STRUCTOP_STRUCT);
  304. s.ptr = "";
  305. s.length = 0;
  306. write_exp_string (s);
  307. write_exp_elt_opcode (STRUCTOP_STRUCT); }
  308. ;
  309. exp : exp '.' qualified_name
  310. { /* exp.type::name becomes exp.*(&type::name) */
  311. /* Note: this doesn't work if name is a
  312. static member! FIXME */
  313. write_exp_elt_opcode (UNOP_ADDR);
  314. write_exp_elt_opcode (STRUCTOP_MEMBER); }
  315. ;
  316. exp : exp DOT_STAR exp
  317. { write_exp_elt_opcode (STRUCTOP_MEMBER); }
  318. ;
  319. exp : exp '[' exp1 ']'
  320. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  321. ;
  322. exp : exp '('
  323. /* This is to save the value of arglist_len
  324. being accumulated by an outer function call. */
  325. { start_arglist (); }
  326. arglist ')' %prec ARROW
  327. { write_exp_elt_opcode (OP_FUNCALL);
  328. write_exp_elt_longcst ((LONGEST) end_arglist ());
  329. write_exp_elt_opcode (OP_FUNCALL); }
  330. ;
  331. exp : UNKNOWN_CPP_NAME '('
  332. {
  333. /* This could potentially be a an argument defined
  334. lookup function (Koenig). */
  335. write_exp_elt_opcode (OP_ADL_FUNC);
  336. write_exp_elt_block (expression_context_block);
  337. write_exp_elt_sym (NULL); /* Placeholder. */
  338. write_exp_string ($1.stoken);
  339. write_exp_elt_opcode (OP_ADL_FUNC);
  340. /* This is to save the value of arglist_len
  341. being accumulated by an outer function call. */
  342. start_arglist ();
  343. }
  344. arglist ')' %prec ARROW
  345. {
  346. write_exp_elt_opcode (OP_FUNCALL);
  347. write_exp_elt_longcst ((LONGEST) end_arglist ());
  348. write_exp_elt_opcode (OP_FUNCALL);
  349. }
  350. ;
  351. lcurly : '{'
  352. { start_arglist (); }
  353. ;
  354. arglist :
  355. ;
  356. arglist : exp
  357. { arglist_len = 1; }
  358. ;
  359. arglist : arglist ',' exp %prec ABOVE_COMMA
  360. { arglist_len++; }
  361. ;
  362. exp : exp '(' nonempty_typelist ')' const_or_volatile
  363. { int i;
  364. write_exp_elt_opcode (TYPE_INSTANCE);
  365. write_exp_elt_longcst ((LONGEST) $<ivec>3[0]);
  366. for (i = 0; i < $<ivec>3[0]; ++i)
  367. write_exp_elt_type ($<tvec>3[i + 1]);
  368. write_exp_elt_longcst((LONGEST) $<ivec>3[0]);
  369. write_exp_elt_opcode (TYPE_INSTANCE);
  370. free ($3);
  371. }
  372. ;
  373. rcurly : '}'
  374. { $$ = end_arglist () - 1; }
  375. ;
  376. exp : lcurly arglist rcurly %prec ARROW
  377. { write_exp_elt_opcode (OP_ARRAY);
  378. write_exp_elt_longcst ((LONGEST) 0);
  379. write_exp_elt_longcst ((LONGEST) $3);
  380. write_exp_elt_opcode (OP_ARRAY); }
  381. ;
  382. exp : lcurly type rcurly exp %prec UNARY
  383. { write_exp_elt_opcode (UNOP_MEMVAL);
  384. write_exp_elt_type ($2);
  385. write_exp_elt_opcode (UNOP_MEMVAL); }
  386. ;
  387. exp : '(' type ')' exp %prec UNARY
  388. { write_exp_elt_opcode (UNOP_CAST);
  389. write_exp_elt_type ($2);
  390. write_exp_elt_opcode (UNOP_CAST); }
  391. ;
  392. exp : '(' exp1 ')'
  393. { }
  394. ;
  395. /* Binary operators in order of decreasing precedence. */
  396. exp : exp '@' exp
  397. { write_exp_elt_opcode (BINOP_REPEAT); }
  398. ;
  399. exp : exp '*' exp
  400. { write_exp_elt_opcode (BINOP_MUL); }
  401. ;
  402. exp : exp '/' exp
  403. { write_exp_elt_opcode (BINOP_DIV); }
  404. ;
  405. exp : exp '%' exp
  406. { write_exp_elt_opcode (BINOP_REM); }
  407. ;
  408. exp : exp '+' exp
  409. { write_exp_elt_opcode (BINOP_ADD); }
  410. ;
  411. exp : exp '-' exp
  412. { write_exp_elt_opcode (BINOP_SUB); }
  413. ;
  414. exp : exp LSH exp
  415. { write_exp_elt_opcode (BINOP_LSH); }
  416. ;
  417. exp : exp RSH exp
  418. { write_exp_elt_opcode (BINOP_RSH); }
  419. ;
  420. exp : exp EQUAL exp
  421. { write_exp_elt_opcode (BINOP_EQUAL); }
  422. ;
  423. exp : exp NOTEQUAL exp
  424. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  425. ;
  426. exp : exp LEQ exp
  427. { write_exp_elt_opcode (BINOP_LEQ); }
  428. ;
  429. exp : exp GEQ exp
  430. { write_exp_elt_opcode (BINOP_GEQ); }
  431. ;
  432. exp : exp '<' exp
  433. { write_exp_elt_opcode (BINOP_LESS); }
  434. ;
  435. exp : exp '>' exp
  436. { write_exp_elt_opcode (BINOP_GTR); }
  437. ;
  438. exp : exp '&' exp
  439. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  440. ;
  441. exp : exp '^' exp
  442. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  443. ;
  444. exp : exp '|' exp
  445. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  446. ;
  447. exp : exp ANDAND exp
  448. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  449. ;
  450. exp : exp OROR exp
  451. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  452. ;
  453. exp : exp '?' exp ':' exp %prec '?'
  454. { write_exp_elt_opcode (TERNOP_COND); }
  455. ;
  456. exp : exp '=' exp
  457. { write_exp_elt_opcode (BINOP_ASSIGN); }
  458. ;
  459. exp : exp ASSIGN_MODIFY exp
  460. { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
  461. write_exp_elt_opcode ($2);
  462. write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
  463. ;
  464. exp : INT
  465. { write_exp_elt_opcode (OP_LONG);
  466. write_exp_elt_type ($1.type);
  467. write_exp_elt_longcst ((LONGEST)($1.val));
  468. write_exp_elt_opcode (OP_LONG); }
  469. ;
  470. exp : CHAR
  471. {
  472. struct stoken_vector vec;
  473. vec.len = 1;
  474. vec.tokens = &$1;
  475. write_exp_string_vector ($1.type, &vec);
  476. }
  477. ;
  478. exp : NAME_OR_INT
  479. { YYSTYPE val;
  480. parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
  481. write_exp_elt_opcode (OP_LONG);
  482. write_exp_elt_type (val.typed_val_int.type);
  483. write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
  484. write_exp_elt_opcode (OP_LONG);
  485. }
  486. ;
  487. exp : FLOAT
  488. { write_exp_elt_opcode (OP_DOUBLE);
  489. write_exp_elt_type ($1.type);
  490. write_exp_elt_dblcst ($1.dval);
  491. write_exp_elt_opcode (OP_DOUBLE); }
  492. ;
  493. exp : DECFLOAT
  494. { write_exp_elt_opcode (OP_DECFLOAT);
  495. write_exp_elt_type ($1.type);
  496. write_exp_elt_decfloatcst ($1.val);
  497. write_exp_elt_opcode (OP_DECFLOAT); }
  498. ;
  499. exp : variable
  500. ;
  501. exp : VARIABLE
  502. {
  503. write_dollar_variable ($1);
  504. }
  505. ;
  506. exp : SIZEOF '(' type ')' %prec UNARY
  507. { write_exp_elt_opcode (OP_LONG);
  508. write_exp_elt_type (parse_type->builtin_int);
  509. CHECK_TYPEDEF ($3);
  510. write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
  511. write_exp_elt_opcode (OP_LONG); }
  512. ;
  513. exp : REINTERPRET_CAST '<' type '>' '(' exp ')' %prec UNARY
  514. { write_exp_elt_opcode (UNOP_REINTERPRET_CAST);
  515. write_exp_elt_type ($3);
  516. write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
  517. ;
  518. exp : STATIC_CAST '<' type '>' '(' exp ')' %prec UNARY
  519. { write_exp_elt_opcode (UNOP_CAST);
  520. write_exp_elt_type ($3);
  521. write_exp_elt_opcode (UNOP_CAST); }
  522. ;
  523. exp : DYNAMIC_CAST '<' type '>' '(' exp ')' %prec UNARY
  524. { write_exp_elt_opcode (UNOP_DYNAMIC_CAST);
  525. write_exp_elt_type ($3);
  526. write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
  527. ;
  528. exp : CONST_CAST '<' type '>' '(' exp ')' %prec UNARY
  529. { /* We could do more error checking here, but
  530. it doesn't seem worthwhile. */
  531. write_exp_elt_opcode (UNOP_CAST);
  532. write_exp_elt_type ($3);
  533. write_exp_elt_opcode (UNOP_CAST); }
  534. ;
  535. string_exp:
  536. STRING
  537. {
  538. /* We copy the string here, and not in the
  539. lexer, to guarantee that we do not leak a
  540. string. Note that we follow the
  541. NUL-termination convention of the
  542. lexer. */
  543. struct typed_stoken *vec = XNEW (struct typed_stoken);
  544. $$.len = 1;
  545. $$.tokens = vec;
  546. vec->type = $1.type;
  547. vec->length = $1.length;
  548. vec->ptr = malloc ($1.length + 1);
  549. memcpy (vec->ptr, $1.ptr, $1.length + 1);
  550. }
  551. | string_exp STRING
  552. {
  553. /* Note that we NUL-terminate here, but just
  554. for convenience. */
  555. char *p;
  556. ++$$.len;
  557. $$.tokens = realloc ($$.tokens,
  558. $$.len * sizeof (struct typed_stoken));
  559. p = malloc ($2.length + 1);
  560. memcpy (p, $2.ptr, $2.length + 1);
  561. $$.tokens[$$.len - 1].type = $2.type;
  562. $$.tokens[$$.len - 1].length = $2.length;
  563. $$.tokens[$$.len - 1].ptr = p;
  564. }
  565. ;
  566. exp : string_exp
  567. {
  568. int i;
  569. enum c_string_type type = C_STRING;
  570. for (i = 0; i < $1.len; ++i)
  571. {
  572. switch ($1.tokens[i].type)
  573. {
  574. case C_STRING:
  575. break;
  576. case C_WIDE_STRING:
  577. case C_STRING_16:
  578. case C_STRING_32:
  579. if (type != C_STRING
  580. && type != $1.tokens[i].type)
  581. error ("Undefined string concatenation.");
  582. type = $1.tokens[i].type;
  583. break;
  584. default:
  585. /* internal error */
  586. internal_error (__FILE__, __LINE__,
  587. "unrecognized type in string concatenation");
  588. }
  589. }
  590. write_exp_string_vector (type, &$1);
  591. for (i = 0; i < $1.len; ++i)
  592. free ($1.tokens[i].ptr);
  593. free ($1.tokens);
  594. }
  595. ;
  596. /* C++. */
  597. exp : TRUEKEYWORD
  598. { write_exp_elt_opcode (OP_LONG);
  599. write_exp_elt_type (parse_type->builtin_bool);
  600. write_exp_elt_longcst ((LONGEST) 1);
  601. write_exp_elt_opcode (OP_LONG); }
  602. ;
  603. exp : FALSEKEYWORD
  604. { write_exp_elt_opcode (OP_LONG);
  605. write_exp_elt_type (parse_type->builtin_bool);
  606. write_exp_elt_longcst ((LONGEST) 0);
  607. write_exp_elt_opcode (OP_LONG); }
  608. ;
  609. /* end of C++. */
  610. block : BLOCKNAME
  611. {
  612. if ($1.sym)
  613. $$ = SYMBOL_BLOCK_VALUE ($1.sym);
  614. else
  615. error ("No file or function \"%s\".",
  616. copy_name ($1.stoken));
  617. }
  618. | FILENAME
  619. {
  620. $$ = $1;
  621. }
  622. ;
  623. block : block COLONCOLON name
  624. { struct symbol *tem
  625. = lookup_symbol (copy_name ($3), $1,
  626. VAR_DOMAIN, (int *) NULL);
  627. if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  628. error ("No function \"%s\" in specified context.",
  629. copy_name ($3));
  630. $$ = SYMBOL_BLOCK_VALUE (tem); }
  631. ;
  632. variable: block COLONCOLON name
  633. { struct symbol *sym;
  634. sym = lookup_symbol (copy_name ($3), $1,
  635. VAR_DOMAIN, (int *) NULL);
  636. if (sym == 0)
  637. error ("No symbol \"%s\" in specified context.",
  638. copy_name ($3));
  639. write_exp_elt_opcode (OP_VAR_VALUE);
  640. /* block_found is set by lookup_symbol. */
  641. write_exp_elt_block (block_found);
  642. write_exp_elt_sym (sym);
  643. write_exp_elt_opcode (OP_VAR_VALUE); }
  644. ;
  645. qualified_name: TYPENAME COLONCOLON name
  646. {
  647. struct type *type = $1.type;
  648. CHECK_TYPEDEF (type);
  649. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  650. && TYPE_CODE (type) != TYPE_CODE_UNION
  651. && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
  652. error ("`%s' is not defined as an aggregate type.",
  653. TYPE_NAME (type));
  654. write_exp_elt_opcode (OP_SCOPE);
  655. write_exp_elt_type (type);
  656. write_exp_string ($3);
  657. write_exp_elt_opcode (OP_SCOPE);
  658. }
  659. | TYPENAME COLONCOLON '~' name
  660. {
  661. struct type *type = $1.type;
  662. struct stoken tmp_token;
  663. CHECK_TYPEDEF (type);
  664. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  665. && TYPE_CODE (type) != TYPE_CODE_UNION
  666. && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
  667. error ("`%s' is not defined as an aggregate type.",
  668. TYPE_NAME (type));
  669. tmp_token.ptr = (char*) alloca ($4.length + 2);
  670. tmp_token.length = $4.length + 1;
  671. tmp_token.ptr[0] = '~';
  672. memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
  673. tmp_token.ptr[tmp_token.length] = 0;
  674. /* Check for valid destructor name. */
  675. destructor_name_p (tmp_token.ptr, type);
  676. write_exp_elt_opcode (OP_SCOPE);
  677. write_exp_elt_type (type);
  678. write_exp_string (tmp_token);
  679. write_exp_elt_opcode (OP_SCOPE);
  680. }
  681. | TYPENAME COLONCOLON name COLONCOLON name
  682. {
  683. char *copy = copy_name ($3);
  684. error (_("No type \"%s\" within class "
  685. "or namespace \"%s\"."),
  686. copy, TYPE_NAME ($1.type));
  687. }
  688. ;
  689. variable: qualified_name
  690. | COLONCOLON name_not_typename
  691. {
  692. char *name = copy_name ($2.stoken);
  693. struct symbol *sym;
  694. struct minimal_symbol *msymbol;
  695. sym =
  696. lookup_symbol (name, (const struct block *) NULL,
  697. VAR_DOMAIN, (int *) NULL);
  698. if (sym)
  699. {
  700. write_exp_elt_opcode (OP_VAR_VALUE);
  701. write_exp_elt_block (NULL);
  702. write_exp_elt_sym (sym);
  703. write_exp_elt_opcode (OP_VAR_VALUE);
  704. break;
  705. }
  706. msymbol = lookup_minimal_symbol (name, NULL, NULL);
  707. if (msymbol != NULL)
  708. write_exp_msymbol (msymbol);
  709. else if (!have_full_symbols () && !have_partial_symbols ())
  710. error ("No symbol table is loaded. Use the \"file\" command.");
  711. else
  712. error ("No symbol \"%s\" in current context.", name);
  713. }
  714. ;
  715. variable: name_not_typename
  716. { struct symbol *sym = $1.sym;
  717. if (sym)
  718. {
  719. if (symbol_read_needs_frame (sym))
  720. {
  721. if (innermost_block == 0
  722. || contained_in (block_found,
  723. innermost_block))
  724. innermost_block = block_found;
  725. }
  726. write_exp_elt_opcode (OP_VAR_VALUE);
  727. /* We want to use the selected frame, not
  728. another more inner frame which happens to
  729. be in the same block. */
  730. write_exp_elt_block (NULL);
  731. write_exp_elt_sym (sym);
  732. write_exp_elt_opcode (OP_VAR_VALUE);
  733. }
  734. else if ($1.is_a_field_of_this)
  735. {
  736. /* C++: it hangs off of `this'. Must
  737. not inadvertently convert from a method call
  738. to data ref. */
  739. if (innermost_block == 0
  740. || contained_in (block_found,
  741. innermost_block))
  742. innermost_block = block_found;
  743. write_exp_elt_opcode (OP_THIS);
  744. write_exp_elt_opcode (OP_THIS);
  745. write_exp_elt_opcode (STRUCTOP_PTR);
  746. write_exp_string ($1.stoken);
  747. write_exp_elt_opcode (STRUCTOP_PTR);
  748. }
  749. else
  750. {
  751. struct minimal_symbol *msymbol;
  752. char *arg = copy_name ($1.stoken);
  753. msymbol =
  754. lookup_minimal_symbol (arg, NULL, NULL);
  755. if (msymbol != NULL)
  756. write_exp_msymbol (msymbol);
  757. else if (!have_full_symbols () && !have_partial_symbols ())
  758. error ("No symbol table is loaded. Use the \"file\" command.");
  759. else
  760. error ("No symbol \"%s\" in current context.",
  761. copy_name ($1.stoken));
  762. }
  763. }
  764. ;
  765. space_identifier : '@' NAME
  766. { push_type_address_space (copy_name ($2.stoken));
  767. push_type (tp_space_identifier);
  768. }
  769. ;
  770. const_or_volatile: const_or_volatile_noopt
  771. |
  772. ;
  773. cv_with_space_id : const_or_volatile space_identifier const_or_volatile
  774. ;
  775. const_or_volatile_or_space_identifier_noopt: cv_with_space_id
  776. | const_or_volatile_noopt
  777. ;
  778. const_or_volatile_or_space_identifier:
  779. const_or_volatile_or_space_identifier_noopt
  780. |
  781. ;
  782. abs_decl: '*'
  783. { push_type (tp_pointer); $$ = 0; }
  784. | '*' abs_decl
  785. { push_type (tp_pointer); $$ = $2; }
  786. | '&'
  787. { push_type (tp_reference); $$ = 0; }
  788. | '&' abs_decl
  789. { push_type (tp_reference); $$ = $2; }
  790. | direct_abs_decl
  791. ;
  792. direct_abs_decl: '(' abs_decl ')'
  793. { $$ = $2; }
  794. | direct_abs_decl array_mod
  795. {
  796. push_type_int ($2);
  797. push_type (tp_array);
  798. }
  799. | array_mod
  800. {
  801. push_type_int ($1);
  802. push_type (tp_array);
  803. $$ = 0;
  804. }
  805. | direct_abs_decl func_mod
  806. { push_type (tp_function); }
  807. | func_mod
  808. { push_type (tp_function); }
  809. ;
  810. array_mod: '[' ']'
  811. { $$ = -1; }
  812. | '[' INT ']'
  813. { $$ = $2.val; }
  814. ;
  815. func_mod: '(' ')'
  816. { $$ = 0; }
  817. | '(' nonempty_typelist ')'
  818. { free ($2); $$ = 0; }
  819. ;
  820. /* We used to try to recognize pointer to member types here, but
  821. that didn't work (shift/reduce conflicts meant that these rules never
  822. got executed). The problem is that
  823. int (foo::bar::baz::bizzle)
  824. is a function type but
  825. int (foo::bar::baz::bizzle::*)
  826. is a pointer to member type. Stroustrup loses again! */
  827. type : ptype
  828. ;
  829. typebase /* Implements (approximately): (type-qualifier)* type-specifier */
  830. : TYPENAME
  831. { $$ = $1.type; }
  832. | INT_KEYWORD
  833. { $$ = parse_type->builtin_int; }
  834. | LONG
  835. { $$ = parse_type->builtin_long; }
  836. | SHORT
  837. { $$ = parse_type->builtin_short; }
  838. | LONG INT_KEYWORD
  839. { $$ = parse_type->builtin_long; }
  840. | LONG SIGNED_KEYWORD INT_KEYWORD
  841. { $$ = parse_type->builtin_long; }
  842. | LONG SIGNED_KEYWORD
  843. { $$ = parse_type->builtin_long; }
  844. | SIGNED_KEYWORD LONG INT_KEYWORD
  845. { $$ = parse_type->builtin_long; }
  846. | UNSIGNED LONG INT_KEYWORD
  847. { $$ = parse_type->builtin_unsigned_long; }
  848. | LONG UNSIGNED INT_KEYWORD
  849. { $$ = parse_type->builtin_unsigned_long; }
  850. | LONG UNSIGNED
  851. { $$ = parse_type->builtin_unsigned_long; }
  852. | LONG LONG
  853. { $$ = parse_type->builtin_long_long; }
  854. | LONG LONG INT_KEYWORD
  855. { $$ = parse_type->builtin_long_long; }
  856. | LONG LONG SIGNED_KEYWORD INT_KEYWORD
  857. { $$ = parse_type->builtin_long_long; }
  858. | LONG LONG SIGNED_KEYWORD
  859. { $$ = parse_type->builtin_long_long; }
  860. | SIGNED_KEYWORD LONG LONG
  861. { $$ = parse_type->builtin_long_long; }
  862. | SIGNED_KEYWORD LONG LONG INT_KEYWORD
  863. { $$ = parse_type->builtin_long_long; }
  864. | UNSIGNED LONG LONG
  865. { $$ = parse_type->builtin_unsigned_long_long; }
  866. | UNSIGNED LONG LONG INT_KEYWORD
  867. { $$ = parse_type->builtin_unsigned_long_long; }
  868. | LONG LONG UNSIGNED
  869. { $$ = parse_type->builtin_unsigned_long_long; }
  870. | LONG LONG UNSIGNED INT_KEYWORD
  871. { $$ = parse_type->builtin_unsigned_long_long; }
  872. | SHORT INT_KEYWORD
  873. { $$ = parse_type->builtin_short; }
  874. | SHORT SIGNED_KEYWORD INT_KEYWORD
  875. { $$ = parse_type->builtin_short; }
  876. | SHORT SIGNED_KEYWORD
  877. { $$ = parse_type->builtin_short; }
  878. | UNSIGNED SHORT INT_KEYWORD
  879. { $$ = parse_type->builtin_unsigned_short; }
  880. | SHORT UNSIGNED
  881. { $$ = parse_type->builtin_unsigned_short; }
  882. | SHORT UNSIGNED INT_KEYWORD
  883. { $$ = parse_type->builtin_unsigned_short; }
  884. | DOUBLE_KEYWORD
  885. { $$ = parse_type->builtin_double; }
  886. | LONG DOUBLE_KEYWORD
  887. { $$ = parse_type->builtin_long_double; }
  888. | STRUCT name
  889. { $$ = lookup_struct (copy_name ($2),
  890. expression_context_block); }
  891. | CLASS name
  892. { $$ = lookup_struct (copy_name ($2),
  893. expression_context_block); }
  894. | UNION name
  895. { $$ = lookup_union (copy_name ($2),
  896. expression_context_block); }
  897. | ENUM name
  898. { $$ = lookup_enum (copy_name ($2),
  899. expression_context_block); }
  900. | UNSIGNED typename
  901. { $$ = lookup_unsigned_typename (parse_language,
  902. parse_gdbarch,
  903. TYPE_NAME($2.type)); }
  904. | UNSIGNED
  905. { $$ = parse_type->builtin_unsigned_int; }
  906. | SIGNED_KEYWORD typename
  907. { $$ = lookup_signed_typename (parse_language,
  908. parse_gdbarch,
  909. TYPE_NAME($2.type)); }
  910. | SIGNED_KEYWORD
  911. { $$ = parse_type->builtin_int; }
  912. /* It appears that this rule for templates is never
  913. reduced; template recognition happens by lookahead
  914. in the token processing code in yylex. */
  915. | TEMPLATE name '<' type '>'
  916. { $$ = lookup_template_type(copy_name($2), $4,
  917. expression_context_block);
  918. }
  919. | const_or_volatile_or_space_identifier_noopt typebase
  920. { $$ = follow_types ($2); }
  921. | typebase const_or_volatile_or_space_identifier_noopt
  922. { $$ = follow_types ($1); }
  923. ;
  924. typename: TYPENAME
  925. | INT_KEYWORD
  926. {
  927. $$.stoken.ptr = "int";
  928. $$.stoken.length = 3;
  929. $$.type = parse_type->builtin_int;
  930. }
  931. | LONG
  932. {
  933. $$.stoken.ptr = "long";
  934. $$.stoken.length = 4;
  935. $$.type = parse_type->builtin_long;
  936. }
  937. | SHORT
  938. {
  939. $$.stoken.ptr = "short";
  940. $$.stoken.length = 5;
  941. $$.type = parse_type->builtin_short;
  942. }
  943. ;
  944. nonempty_typelist
  945. : type
  946. { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
  947. $<ivec>$[0] = 1; /* Number of types in vector */
  948. $$[1] = $1;
  949. }
  950. | nonempty_typelist ',' type
  951. { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
  952. $$ = (struct type **) realloc ((char *) $1, len);
  953. $$[$<ivec>$[0]] = $3;
  954. }
  955. ;
  956. ptype : typebase
  957. | ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
  958. { $$ = follow_types ($1); }
  959. ;
  960. const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
  961. | VOLATILE_KEYWORD CONST_KEYWORD
  962. ;
  963. const_or_volatile_noopt: const_and_volatile
  964. { push_type (tp_const);
  965. push_type (tp_volatile);
  966. }
  967. | CONST_KEYWORD
  968. { push_type (tp_const); }
  969. | VOLATILE_KEYWORD
  970. { push_type (tp_volatile); }
  971. ;
  972. operator: OPERATOR NEW
  973. { $$ = operator_stoken (" new"); }
  974. | OPERATOR DELETE
  975. { $$ = operator_stoken (" delete"); }
  976. | OPERATOR NEW '[' ']'
  977. { $$ = operator_stoken (" new[]"); }
  978. | OPERATOR DELETE '[' ']'
  979. { $$ = operator_stoken (" delete[]"); }
  980. | OPERATOR '+'
  981. { $$ = operator_stoken ("+"); }
  982. | OPERATOR '-'
  983. { $$ = operator_stoken ("-"); }
  984. | OPERATOR '*'
  985. { $$ = operator_stoken ("*"); }
  986. | OPERATOR '/'
  987. { $$ = operator_stoken ("/"); }
  988. | OPERATOR '%'
  989. { $$ = operator_stoken ("%"); }
  990. | OPERATOR '^'
  991. { $$ = operator_stoken ("^"); }
  992. | OPERATOR '&'
  993. { $$ = operator_stoken ("&"); }
  994. | OPERATOR '|'
  995. { $$ = operator_stoken ("|"); }
  996. | OPERATOR '~'
  997. { $$ = operator_stoken ("~"); }
  998. | OPERATOR '!'
  999. { $$ = operator_stoken ("!"); }
  1000. | OPERATOR '='
  1001. { $$ = operator_stoken ("="); }
  1002. | OPERATOR '<'
  1003. { $$ = operator_stoken ("<"); }
  1004. | OPERATOR '>'
  1005. { $$ = operator_stoken (">"); }
  1006. | OPERATOR ASSIGN_MODIFY
  1007. { const char *op = "unknown";
  1008. switch ($2)
  1009. {
  1010. case BINOP_RSH:
  1011. op = ">>=";
  1012. break;
  1013. case BINOP_LSH:
  1014. op = "<<=";
  1015. break;
  1016. case BINOP_ADD:
  1017. op = "+=";
  1018. break;
  1019. case BINOP_SUB:
  1020. op = "-=";
  1021. break;
  1022. case BINOP_MUL:
  1023. op = "*=";
  1024. break;
  1025. case BINOP_DIV:
  1026. op = "/=";
  1027. break;
  1028. case BINOP_REM:
  1029. op = "%=";
  1030. break;
  1031. case BINOP_BITWISE_IOR:
  1032. op = "|=";
  1033. break;
  1034. case BINOP_BITWISE_AND:
  1035. op = "&=";
  1036. break;
  1037. case BINOP_BITWISE_XOR:
  1038. op = "^=";
  1039. break;
  1040. default:
  1041. break;
  1042. }
  1043. $$ = operator_stoken (op);
  1044. }
  1045. | OPERATOR LSH
  1046. { $$ = operator_stoken ("<<"); }
  1047. | OPERATOR RSH
  1048. { $$ = operator_stoken (">>"); }
  1049. | OPERATOR EQUAL
  1050. { $$ = operator_stoken ("=="); }
  1051. | OPERATOR NOTEQUAL
  1052. { $$ = operator_stoken ("!="); }
  1053. | OPERATOR LEQ
  1054. { $$ = operator_stoken ("<="); }
  1055. | OPERATOR GEQ
  1056. { $$ = operator_stoken (">="); }
  1057. | OPERATOR ANDAND
  1058. { $$ = operator_stoken ("&&"); }
  1059. | OPERATOR OROR
  1060. { $$ = operator_stoken ("||"); }
  1061. | OPERATOR INCREMENT
  1062. { $$ = operator_stoken ("++"); }
  1063. | OPERATOR DECREMENT
  1064. { $$ = operator_stoken ("--"); }
  1065. | OPERATOR ','
  1066. { $$ = operator_stoken (","); }
  1067. | OPERATOR ARROW_STAR
  1068. { $$ = operator_stoken ("->*"); }
  1069. | OPERATOR ARROW
  1070. { $$ = operator_stoken ("->"); }
  1071. | OPERATOR '(' ')'
  1072. { $$ = operator_stoken ("()"); }
  1073. | OPERATOR '[' ']'
  1074. { $$ = operator_stoken ("[]"); }
  1075. | OPERATOR ptype
  1076. { char *name;
  1077. long length;
  1078. struct ui_file *buf = mem_fileopen ();
  1079. c_print_type ($2, NULL, buf, -1, 0);
  1080. name = ui_file_xstrdup (buf, &length);
  1081. ui_file_delete (buf);
  1082. $$ = operator_stoken (name);
  1083. free (name);
  1084. }
  1085. ;
  1086. name : NAME { $$ = $1.stoken; }
  1087. | BLOCKNAME { $$ = $1.stoken; }
  1088. | TYPENAME { $$ = $1.stoken; }
  1089. | NAME_OR_INT { $$ = $1.stoken; }
  1090. | UNKNOWN_CPP_NAME { $$ = $1.stoken; }
  1091. | operator { $$ = $1; }
  1092. ;
  1093. name_not_typename : NAME
  1094. | BLOCKNAME
  1095. /* These would be useful if name_not_typename was useful, but it is just
  1096. a fake for "variable", so these cause reduce/reduce conflicts because
  1097. the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
  1098. =exp) or just an exp. If name_not_typename was ever used in an lvalue
  1099. context where only a name could occur, this might be useful.
  1100. | NAME_OR_INT
  1101. */
  1102. | operator
  1103. {
  1104. $$.stoken = $1;
  1105. $$.sym = lookup_symbol ($1.ptr,
  1106. expression_context_block,
  1107. VAR_DOMAIN,
  1108. &$$.is_a_field_of_this);
  1109. }
  1110. | UNKNOWN_CPP_NAME
  1111. ;
  1112. %%
  1113. /* Returns a stoken of the operator name given by OP (which does not
  1114. include the string "operator"). */
  1115. static struct stoken
  1116. operator_stoken (const char *op)
  1117. {
  1118. static const char *operator_string = "operator";
  1119. struct stoken st = { NULL, 0 };
  1120. st.length = strlen (operator_string) + strlen (op);
  1121. st.ptr = malloc (st.length + 1);
  1122. strcpy (st.ptr, operator_string);
  1123. strcat (st.ptr, op);
  1124. /* The toplevel (c_parse) will free the memory allocated here. */
  1125. make_cleanup (free, st.ptr);
  1126. return st;
  1127. };
  1128. /* Take care of parsing a number (anything that starts with a digit).
  1129. Set yylval and return the token type; update lexptr.
  1130. LEN is the number of characters in it. */
  1131. /*** Needs some error checking for the float case ***/
  1132. static int
  1133. parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
  1134. {
  1135. /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
  1136. here, and we do kind of silly things like cast to unsigned. */
  1137. LONGEST n = 0;
  1138. LONGEST prevn = 0;
  1139. ULONGEST un;
  1140. int i = 0;
  1141. int c;
  1142. int base = input_radix;
  1143. int unsigned_p = 0;
  1144. /* Number of "L" suffixes encountered. */
  1145. int long_p = 0;
  1146. /* We have found a "L" or "U" suffix. */
  1147. int found_suffix = 0;
  1148. ULONGEST high_bit;
  1149. struct type *signed_type;
  1150. struct type *unsigned_type;
  1151. if (parsed_float)
  1152. {
  1153. /* It's a float since it contains a point or an exponent. */
  1154. char *s;
  1155. int num; /* number of tokens scanned by scanf */
  1156. char saved_char;
  1157. /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
  1158. point. Return DECFLOAT. */
  1159. if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
  1160. {
  1161. p[len - 2] = '\0';
  1162. putithere->typed_val_decfloat.type
  1163. = parse_type->builtin_decfloat;
  1164. decimal_from_string (putithere->typed_val_decfloat.val, 4,
  1165. gdbarch_byte_order (parse_gdbarch), p);
  1166. p[len - 2] = 'd';
  1167. return DECFLOAT;
  1168. }
  1169. if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
  1170. {
  1171. p[len - 2] = '\0';
  1172. putithere->typed_val_decfloat.type
  1173. = parse_type->builtin_decdouble;
  1174. decimal_from_string (putithere->typed_val_decfloat.val, 8,
  1175. gdbarch_byte_order (parse_gdbarch), p);
  1176. p[len - 2] = 'd';
  1177. return DECFLOAT;
  1178. }
  1179. if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
  1180. {
  1181. p[len - 2] = '\0';
  1182. putithere->typed_val_decfloat.type
  1183. = parse_type->builtin_declong;
  1184. decimal_from_string (putithere->typed_val_decfloat.val, 16,
  1185. gdbarch_byte_order (parse_gdbarch), p);
  1186. p[len - 2] = 'd';
  1187. return DECFLOAT;
  1188. }
  1189. s = malloc (len);
  1190. saved_char = p[len];
  1191. p[len] = 0; /* null-terminate the token */
  1192. num = sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%s",
  1193. &putithere->typed_val_float.dval, s);
  1194. p[len] = saved_char; /* restore the input stream */
  1195. if (num == 0)
  1196. {
  1197. free (s);
  1198. return ERROR;
  1199. }
  1200. if (num == 1)
  1201. putithere->typed_val_float.type =
  1202. parse_type->builtin_double;
  1203. if (num == 2 )
  1204. {
  1205. /* See if it has any float suffix: 'f' for float, 'l' for long
  1206. double. */
  1207. if (!strcasecmp (s, "f"))
  1208. putithere->typed_val_float.type =
  1209. parse_type->builtin_float;
  1210. else if (!strcasecmp (s, "l"))
  1211. putithere->typed_val_float.type =
  1212. parse_type->builtin_long_double;
  1213. else
  1214. {
  1215. free (s);
  1216. return ERROR;
  1217. }
  1218. }
  1219. free (s);
  1220. return FLOAT;
  1221. }
  1222. /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  1223. if (p[0] == '0')
  1224. switch (p[1])
  1225. {
  1226. case 'x':
  1227. case 'X':
  1228. if (len >= 3)
  1229. {
  1230. p += 2;
  1231. base = 16;
  1232. len -= 2;
  1233. }
  1234. break;
  1235. case 'b':
  1236. case 'B':
  1237. if (len >= 3)
  1238. {
  1239. p += 2;
  1240. base = 2;
  1241. len -= 2;
  1242. }
  1243. break;
  1244. case 't':
  1245. case 'T':
  1246. case 'd':
  1247. case 'D':
  1248. if (len >= 3)
  1249. {
  1250. p += 2;
  1251. base = 10;
  1252. len -= 2;
  1253. }
  1254. break;
  1255. default:
  1256. base = 8;
  1257. break;
  1258. }
  1259. while (len-- > 0)
  1260. {
  1261. c = *p++;
  1262. if (c >= 'A' && c <= 'Z')
  1263. c += 'a' - 'A';
  1264. if (c != 'l' && c != 'u')
  1265. n *= base;
  1266. if (c >= '0' && c <= '9')
  1267. {
  1268. if (found_suffix)
  1269. return ERROR;
  1270. n += i = c - '0';
  1271. }
  1272. else
  1273. {
  1274. if (base > 10 && c >= 'a' && c <= 'f')
  1275. {
  1276. if (found_suffix)
  1277. return ERROR;
  1278. n += i = c - 'a' + 10;
  1279. }
  1280. else if (c == 'l')
  1281. {
  1282. ++long_p;
  1283. found_suffix = 1;
  1284. }
  1285. else if (c == 'u')
  1286. {
  1287. unsigned_p = 1;
  1288. found_suffix = 1;
  1289. }
  1290. else
  1291. return ERROR; /* Char not a digit */
  1292. }
  1293. if (i >= base)
  1294. return ERROR; /* Invalid digit in this base */
  1295. /* Portably test for overflow (only works for nonzero values, so make
  1296. a second check for zero). FIXME: Can't we just make n and prevn
  1297. unsigned and avoid this? */
  1298. if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
  1299. unsigned_p = 1; /* Try something unsigned */
  1300. /* Portably test for unsigned overflow.
  1301. FIXME: This check is wrong; for example it doesn't find overflow
  1302. on 0x123456789 when LONGEST is 32 bits. */
  1303. if (c != 'l' && c != 'u' && n != 0)
  1304. {
  1305. if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
  1306. error ("Numeric constant too large.");
  1307. }
  1308. prevn = n;
  1309. }
  1310. /* An integer constant is an int, a long, or a long long. An L
  1311. suffix forces it to be long; an LL suffix forces it to be long
  1312. long. If not forced to a larger size, it gets the first type of
  1313. the above that it fits in. To figure out whether it fits, we
  1314. shift it right and see whether anything remains. Note that we
  1315. can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  1316. operation, because many compilers will warn about such a shift
  1317. (which always produces a zero result). Sometimes gdbarch_int_bit
  1318. or gdbarch_long_bit will be that big, sometimes not. To deal with
  1319. the case where it is we just always shift the value more than
  1320. once, with fewer bits each time. */
  1321. un = (ULONGEST)n >> 2;
  1322. if (long_p == 0
  1323. && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
  1324. {
  1325. high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
  1326. /* A large decimal (not hex or octal) constant (between INT_MAX
  1327. and UINT_MAX) is a long or unsigned long, according to ANSI,
  1328. never an unsigned int, but this code treats it as unsigned
  1329. int. This probably should be fixed. GCC gives a warning on
  1330. such constants. */
  1331. unsigned_type = parse_type->builtin_unsigned_int;
  1332. signed_type = parse_type->builtin_int;
  1333. }
  1334. else if (long_p <= 1
  1335. && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
  1336. {
  1337. high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
  1338. unsigned_type = parse_type->builtin_unsigned_long;
  1339. signed_type = parse_type->builtin_long;
  1340. }
  1341. else
  1342. {
  1343. int shift;
  1344. if (sizeof (ULONGEST) * HOST_CHAR_BIT
  1345. < gdbarch_long_long_bit (parse_gdbarch))
  1346. /* A long long does not fit in a LONGEST. */
  1347. shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
  1348. else
  1349. shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
  1350. high_bit = (ULONGEST) 1 << shift;
  1351. unsigned_type = parse_type->builtin_unsigned_long_long;
  1352. signed_type = parse_type->builtin_long_long;
  1353. }
  1354. putithere->typed_val_int.val = n;
  1355. /* If the high bit of the worked out type is set then this number
  1356. has to be unsigned. */
  1357. if (unsigned_p || (n & high_bit))
  1358. {
  1359. putithere->typed_val_int.type = unsigned_type;
  1360. }
  1361. else
  1362. {
  1363. putithere->typed_val_int.type = signed_type;
  1364. }
  1365. return INT;
  1366. }
  1367. /* Temporary obstack used for holding strings. */
  1368. static struct obstack tempbuf;
  1369. static int tempbuf_init;
  1370. /* Parse a C escape sequence. The initial backslash of the sequence
  1371. is at (*PTR)[-1]. *PTR will be updated to point to just after the
  1372. last character of the sequence. If OUTPUT is not NULL, the
  1373. translated form of the escape sequence will be written there. If
  1374. OUTPUT is NULL, no output is written and the call will only affect
  1375. *PTR. If an escape sequence is expressed in target bytes, then the
  1376. entire sequence will simply be copied to OUTPUT. Return 1 if any
  1377. character was emitted, 0 otherwise. */
  1378. int
  1379. c_parse_escape (char **ptr, struct obstack *output)
  1380. {
  1381. char *tokptr = *ptr;
  1382. int result = 1;
  1383. /* Some escape sequences undergo character set conversion. Those we
  1384. translate here. */
  1385. switch (*tokptr)
  1386. {
  1387. /* Hex escapes do not undergo character set conversion, so keep
  1388. the escape sequence for later. */
  1389. case 'x':
  1390. if (output)
  1391. obstack_grow_str (output, "\\x");
  1392. ++tokptr;
  1393. if (!isxdigit (*tokptr))
  1394. error (_("\\x escape without a following hex digit"));
  1395. while (isxdigit (*tokptr))
  1396. {
  1397. if (output)
  1398. obstack_1grow (output, *tokptr);
  1399. ++tokptr;
  1400. }
  1401. break;
  1402. /* Octal escapes do not undergo character set conversion, so
  1403. keep the escape sequence for later. */
  1404. case '0':
  1405. case '1':
  1406. case '2':
  1407. case '3':
  1408. case '4':
  1409. case '5':
  1410. case '6':
  1411. case '7':
  1412. {
  1413. int i;
  1414. if (output)
  1415. obstack_grow_str (output, "\\");
  1416. for (i = 0;
  1417. i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
  1418. ++i)
  1419. {
  1420. if (output)
  1421. obstack_1grow (output, *tokptr);
  1422. ++tokptr;
  1423. }
  1424. }
  1425. break;
  1426. /* We handle UCNs later. We could handle them here, but that
  1427. would mean a spurious error in the case where the UCN could
  1428. be converted to the target charset but not the host
  1429. charset. */
  1430. case 'u':
  1431. case 'U':
  1432. {
  1433. char c = *tokptr;
  1434. int i, len = c == 'U' ? 8 : 4;
  1435. if (output)
  1436. {
  1437. obstack_1grow (output, '\\');
  1438. obstack_1grow (output, *tokptr);
  1439. }
  1440. ++tokptr;
  1441. if (!isxdigit (*tokptr))
  1442. error (_("\\%c escape without a following hex digit"), c);
  1443. for (i = 0; i < len && isxdigit (*tokptr); ++i)
  1444. {
  1445. if (output)
  1446. obstack_1grow (output, *tokptr);
  1447. ++tokptr;
  1448. }
  1449. }
  1450. break;
  1451. /* We must pass backslash through so that it does not
  1452. cause quoting during the second expansion. */
  1453. case '\\':
  1454. if (output)
  1455. obstack_grow_str (output, "\\\\");
  1456. ++tokptr;
  1457. break;
  1458. /* Escapes which undergo conversion. */
  1459. case 'a':
  1460. if (output)
  1461. obstack_1grow (output, '\a');
  1462. ++tokptr;
  1463. break;
  1464. case 'b':
  1465. if (output)
  1466. obstack_1grow (output, '\b');
  1467. ++tokptr;
  1468. break;
  1469. case 'f':
  1470. if (output)
  1471. obstack_1grow (output, '\f');
  1472. ++tokptr;
  1473. break;
  1474. case 'n':
  1475. if (output)
  1476. obstack_1grow (output, '\n');
  1477. ++tokptr;
  1478. break;
  1479. case 'r':
  1480. if (output)
  1481. obstack_1grow (output, '\r');
  1482. ++tokptr;
  1483. break;
  1484. case 't':
  1485. if (output)
  1486. obstack_1grow (output, '\t');
  1487. ++tokptr;
  1488. break;
  1489. case 'v':
  1490. if (output)
  1491. obstack_1grow (output, '\v');
  1492. ++tokptr;
  1493. break;
  1494. /* GCC extension. */
  1495. case 'e':
  1496. if (output)
  1497. obstack_1grow (output, HOST_ESCAPE_CHAR);
  1498. ++tokptr;
  1499. break;
  1500. /* Backslash-newline expands to nothing at all. */
  1501. case '\n':
  1502. ++tokptr;
  1503. result = 0;
  1504. break;
  1505. /* A few escapes just expand to the character itself. */
  1506. case '\'':
  1507. case '\"':
  1508. case '?':
  1509. /* GCC extensions. */
  1510. case '(':
  1511. case '{':
  1512. case '[':
  1513. case '%':
  1514. /* Unrecognized escapes turn into the character itself. */
  1515. default:
  1516. if (output)
  1517. obstack_1grow (output, *tokptr);
  1518. ++tokptr;
  1519. break;
  1520. }
  1521. *ptr = tokptr;
  1522. return result;
  1523. }
  1524. /* Parse a string or character literal from TOKPTR. The string or
  1525. character may be wide or unicode. *OUTPTR is set to just after the
  1526. end of the literal in the input string. The resulting token is
  1527. stored in VALUE. This returns a token value, either STRING or
  1528. CHAR, depending on what was parsed. *HOST_CHARS is set to the
  1529. number of host characters in the literal. */
  1530. static int
  1531. parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
  1532. int *host_chars)
  1533. {
  1534. int quote;
  1535. enum c_string_type type;
  1536. /* Build the gdb internal form of the input string in tempbuf. Note
  1537. that the buffer is null byte terminated *only* for the
  1538. convenience of debugging gdb itself and printing the buffer
  1539. contents when the buffer contains no embedded nulls. Gdb does
  1540. not depend upon the buffer being null byte terminated, it uses
  1541. the length string instead. This allows gdb to handle C strings
  1542. (as well as strings in other languages) with embedded null
  1543. bytes */
  1544. if (!tempbuf_init)
  1545. tempbuf_init = 1;
  1546. else
  1547. obstack_free (&tempbuf, NULL);
  1548. obstack_init (&tempbuf);
  1549. /* Record the string type. */
  1550. if (*tokptr == 'L')
  1551. {
  1552. type = C_WIDE_STRING;
  1553. ++tokptr;
  1554. }
  1555. else if (*tokptr == 'u')
  1556. {
  1557. type = C_STRING_16;
  1558. ++tokptr;
  1559. }
  1560. else if (*tokptr == 'U')
  1561. {
  1562. type = C_STRING_32;
  1563. ++tokptr;
  1564. }
  1565. else
  1566. type = C_STRING;
  1567. /* Skip the quote. */
  1568. quote = *tokptr;
  1569. if (quote == '\'')
  1570. type |= C_CHAR;
  1571. ++tokptr;
  1572. *host_chars = 0;
  1573. while (*tokptr)
  1574. {
  1575. char c = *tokptr;
  1576. if (c == '\\')
  1577. {
  1578. ++tokptr;
  1579. *host_chars += c_parse_escape (&tokptr, &tempbuf);
  1580. }
  1581. else if (c == quote)
  1582. break;
  1583. else
  1584. {
  1585. obstack_1grow (&tempbuf, c);
  1586. ++tokptr;
  1587. /* FIXME: this does the wrong thing with multi-byte host
  1588. characters. We could use mbrlen here, but that would
  1589. make "set host-charset" a bit less useful. */
  1590. ++*host_chars;
  1591. }
  1592. }
  1593. if (*tokptr != quote)
  1594. {
  1595. if (quote == '"')
  1596. error ("Unterminated string in expression.");
  1597. else
  1598. error ("Unmatched single quote.");
  1599. }
  1600. ++tokptr;
  1601. value->type = type;
  1602. value->ptr = obstack_base (&tempbuf);
  1603. value->length = obstack_object_size (&tempbuf);
  1604. *outptr = tokptr;
  1605. return quote == '"' ? STRING : CHAR;
  1606. }
  1607. struct token
  1608. {
  1609. char *operator;
  1610. int token;
  1611. enum exp_opcode opcode;
  1612. int cxx_only;
  1613. };
  1614. static const struct token tokentab3[] =
  1615. {
  1616. {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
  1617. {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
  1618. {"->*", ARROW_STAR, BINOP_END, 1}
  1619. };
  1620. static const struct token tokentab2[] =
  1621. {
  1622. {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
  1623. {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
  1624. {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
  1625. {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
  1626. {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
  1627. {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
  1628. {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
  1629. {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
  1630. {"++", INCREMENT, BINOP_END, 0},
  1631. {"--", DECREMENT, BINOP_END, 0},
  1632. {"->", ARROW, BINOP_END, 0},
  1633. {"&&", ANDAND, BINOP_END, 0},
  1634. {"||", OROR, BINOP_END, 0},
  1635. /* "::" is *not* only C++: gdb overrides its meaning in several
  1636. different ways, e.g., 'filename'::func, function::variable. */
  1637. {"::", COLONCOLON, BINOP_END, 0},
  1638. {"<<", LSH, BINOP_END, 0},
  1639. {">>", RSH, BINOP_END, 0},
  1640. {"==", EQUAL, BINOP_END, 0},
  1641. {"!=", NOTEQUAL, BINOP_END, 0},
  1642. {"<=", LEQ, BINOP_END, 0},
  1643. {">=", GEQ, BINOP_END, 0},
  1644. {".*", DOT_STAR, BINOP_END, 1}
  1645. };
  1646. /* Identifier-like tokens. */
  1647. static const struct token ident_tokens[] =
  1648. {
  1649. {"unsigned", UNSIGNED, OP_NULL, 0},
  1650. {"template", TEMPLATE, OP_NULL, 1},
  1651. {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
  1652. {"struct", STRUCT, OP_NULL, 0},
  1653. {"signed", SIGNED_KEYWORD, OP_NULL, 0},
  1654. {"sizeof", SIZEOF, OP_NULL, 0},
  1655. {"double", DOUBLE_KEYWORD, OP_NULL, 0},
  1656. {"false", FALSEKEYWORD, OP_NULL, 1},
  1657. {"class", CLASS, OP_NULL, 1},
  1658. {"union", UNION, OP_NULL, 0},
  1659. {"short", SHORT, OP_NULL, 0},
  1660. {"const", CONST_KEYWORD, OP_NULL, 0},
  1661. {"enum", ENUM, OP_NULL, 0},
  1662. {"long", LONG, OP_NULL, 0},
  1663. {"true", TRUEKEYWORD, OP_NULL, 1},
  1664. {"int", INT_KEYWORD, OP_NULL, 0},
  1665. {"new", NEW, OP_NULL, 1},
  1666. {"delete", DELETE, OP_NULL, 1},
  1667. {"operator", OPERATOR, OP_NULL, 1},
  1668. {"and", ANDAND, BINOP_END, 1},
  1669. {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, 1},
  1670. {"bitand", '&', OP_NULL, 1},
  1671. {"bitor", '|', OP_NULL, 1},
  1672. {"compl", '~', OP_NULL, 1},
  1673. {"not", '!', OP_NULL, 1},
  1674. {"not_eq", NOTEQUAL, BINOP_END, 1},
  1675. {"or", OROR, BINOP_END, 1},
  1676. {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 1},
  1677. {"xor", '^', OP_NULL, 1},
  1678. {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 1},
  1679. {"const_cast", CONST_CAST, OP_NULL, 1 },
  1680. {"dynamic_cast", DYNAMIC_CAST, OP_NULL, 1 },
  1681. {"static_cast", STATIC_CAST, OP_NULL, 1 },
  1682. {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, 1 }
  1683. };
  1684. /* When we find that lexptr (the global var defined in parse.c) is
  1685. pointing at a macro invocation, we expand the invocation, and call
  1686. scan_macro_expansion to save the old lexptr here and point lexptr
  1687. into the expanded text. When we reach the end of that, we call
  1688. end_macro_expansion to pop back to the value we saved here. The
  1689. macro expansion code promises to return only fully-expanded text,
  1690. so we don't need to "push" more than one level.
  1691. This is disgusting, of course. It would be cleaner to do all macro
  1692. expansion beforehand, and then hand that to lexptr. But we don't
  1693. really know where the expression ends. Remember, in a command like
  1694. (gdb) break *ADDRESS if CONDITION

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