PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/gdb/c-exp.y

https://bitbucket.org/tari/prizm-binutils
Happy | 2991 lines | 2623 code | 368 blank | 0 comment | 0 complexity | 90014cb9512b092061e412d26c50923a MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause, GPL-3.0, AGPL-3.0, LGPL-2.1, GPL-2.0, 0BSD, Unlicense, MPL-2.0-no-copyleft-exception

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

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