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

/interfaces/gcc/c_files/cp/parse.y

https://github.com/gitpan/Introspector
Happy | 4271 lines | 3889 code | 382 blank | 0 comment | 0 complexity | 1f4dce27c026967d5033e07c51589ef4 MD5 | raw file

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

  1. /* YACC parser for C++ syntax.
  2. Copyright (C) 1988, 1989, 1993, 1994, 1995, 1996, 1997, 1998,
  3. 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
  4. Hacked by Michael Tiemann (tiemann@cygnus.com)
  5. This file is part of GNU CC.
  6. GNU CC 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 2, or (at your option)
  9. any later version.
  10. GNU CC 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 GNU CC; see the file COPYING. If not, write to
  16. the Free Software Foundation, 59 Temple Place - Suite 330,
  17. Boston, MA 02111-1307, USA. */
  18. /* This grammar is based on the GNU CC grammar. */
  19. /* Note: Bison automatically applies a default action of "$$ = $1" for
  20. all derivations; this is applied before the explicit action, if one
  21. is given. Keep this in mind when reading the actions. */
  22. %{
  23. #include "config.h"
  24. #include "system.h"
  25. #include "tree.h"
  26. #include "input.h"
  27. #include "flags.h"
  28. #include "cp-tree.h"
  29. #include "decl.h"
  30. #include "lex.h"
  31. #include "c-pragma.h" /* For YYDEBUG definition. */
  32. #include "output.h"
  33. #include "except.h"
  34. #include "toplev.h"
  35. #include "ggc.h"
  36. /* Like YYERROR but do call yyerror. */
  37. #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
  38. /* Like the default stack expander, except (1) use realloc when possible,
  39. (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
  40. Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
  41. give malloced_yyvs its proper type. This is ok since all we need from
  42. it is to be able to free it. */
  43. static short *malloced_yyss;
  44. static void *malloced_yyvs;
  45. #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ) \
  46. do { \
  47. size_t newsize; \
  48. short *newss; \
  49. YYSTYPE *newvs; \
  50. newsize = *(YYSSZ) *= 2; \
  51. if (malloced_yyss) \
  52. { \
  53. newss = (short *) \
  54. really_call_realloc (*(SS), newsize * sizeof (short)); \
  55. newvs = (YYSTYPE *) \
  56. really_call_realloc (*(VS), newsize * sizeof (YYSTYPE)); \
  57. } \
  58. else \
  59. { \
  60. newss = (short *) really_call_malloc (newsize * sizeof (short)); \
  61. newvs = (YYSTYPE *) really_call_malloc (newsize * sizeof (YYSTYPE)); \
  62. if (newss) \
  63. memcpy (newss, *(SS), (SSSIZE)); \
  64. if (newvs) \
  65. memcpy (newvs, *(VS), (VSSIZE)); \
  66. } \
  67. if (!newss || !newvs) \
  68. { \
  69. yyerror (MSG); \
  70. return 2; \
  71. } \
  72. *(SS) = newss; \
  73. *(VS) = newvs; \
  74. malloced_yyss = newss; \
  75. malloced_yyvs = (void *) newvs; \
  76. } while (0)
  77. #define OP0(NODE) (TREE_OPERAND (NODE, 0))
  78. #define OP1(NODE) (TREE_OPERAND (NODE, 1))
  79. /* Contains the statement keyword (if/while/do) to include in an
  80. error message if the user supplies an empty conditional expression. */
  81. static const char *cond_stmt_keyword;
  82. /* List of types and structure classes of the current declaration. */
  83. static GTY(()) tree current_declspecs;
  84. /* List of prefix attributes in effect.
  85. Prefix attributes are parsed by the reserved_declspecs and declmods
  86. rules. They create a list that contains *both* declspecs and attrs. */
  87. /* ??? It is not clear yet that all cases where an attribute can now appear in
  88. a declspec list have been updated. */
  89. static GTY(()) tree prefix_attributes;
  90. /* When defining an enumeration, this is the type of the enumeration. */
  91. static GTY(()) tree current_enum_type;
  92. /* When parsing a conversion operator name, this is the scope of the
  93. operator itself. */
  94. static GTY(()) tree saved_scopes;
  95. static tree empty_parms PARAMS ((void));
  96. static tree parse_decl0 PARAMS ((tree, tree, tree, tree, int));
  97. static tree parse_decl PARAMS ((tree, tree, int));
  98. static void parse_end_decl PARAMS ((tree, tree, tree));
  99. static tree parse_field0 PARAMS ((tree, tree, tree, tree, tree, tree));
  100. static tree parse_field PARAMS ((tree, tree, tree, tree));
  101. static tree parse_bitfield0 PARAMS ((tree, tree, tree, tree, tree));
  102. static tree parse_bitfield PARAMS ((tree, tree, tree));
  103. static tree parse_method PARAMS ((tree, tree, tree));
  104. static void frob_specs PARAMS ((tree, tree));
  105. static void check_class_key PARAMS ((tree, tree));
  106. static tree parse_scoped_id PARAMS ((tree));
  107. static tree parse_xref_tag (tree, tree, int);
  108. static tree parse_handle_class_head (tree, tree, tree, int, int *);
  109. static void parse_decl_instantiation (tree, tree, tree);
  110. static int parse_begin_function_definition (tree, tree);
  111. static tree parse_finish_call_expr (tree, tree, int);
  112. /* Cons up an empty parameter list. */
  113. static inline tree
  114. empty_parms ()
  115. {
  116. tree parms;
  117. #ifndef NO_IMPLICIT_EXTERN_C
  118. if (in_system_header && current_class_type == NULL
  119. && current_lang_name == lang_name_c)
  120. parms = NULL_TREE;
  121. else
  122. #endif
  123. parms = void_list_node;
  124. return parms;
  125. }
  126. /* Record the decl-specifiers, attributes and type lookups from the
  127. decl-specifier-seq in a declaration. */
  128. static void
  129. frob_specs (specs_attrs, lookups)
  130. tree specs_attrs, lookups;
  131. {
  132. save_type_access_control (lookups);
  133. split_specs_attrs (specs_attrs, &current_declspecs, &prefix_attributes);
  134. if (current_declspecs
  135. && TREE_CODE (current_declspecs) != TREE_LIST)
  136. current_declspecs = build_tree_list (NULL_TREE, current_declspecs);
  137. if (have_extern_spec)
  138. {
  139. /* We have to indicate that there is an "extern", but that it
  140. was part of a language specifier. For instance,
  141. extern "C" typedef int (*Ptr) ();
  142. is well formed. */
  143. current_declspecs = tree_cons (error_mark_node,
  144. get_identifier ("extern"),
  145. current_declspecs);
  146. have_extern_spec = false;
  147. }
  148. }
  149. static tree
  150. parse_decl (declarator, attributes, initialized)
  151. tree declarator, attributes;
  152. int initialized;
  153. {
  154. return start_decl (declarator, current_declspecs, initialized,
  155. attributes, prefix_attributes);
  156. }
  157. static tree
  158. parse_decl0 (declarator, specs_attrs, lookups, attributes, initialized)
  159. tree declarator, specs_attrs, lookups, attributes;
  160. int initialized;
  161. {
  162. frob_specs (specs_attrs, lookups);
  163. return parse_decl (declarator, attributes, initialized);
  164. }
  165. static void
  166. parse_end_decl (decl, init, asmspec)
  167. tree decl, init, asmspec;
  168. {
  169. /* If decl is NULL_TREE, then this was a variable declaration using
  170. () syntax for the initializer, so we handled it in grokdeclarator. */
  171. if (decl)
  172. decl_type_access_control (decl);
  173. cp_finish_decl (decl, init, asmspec, init ? LOOKUP_ONLYCONVERTING : 0);
  174. }
  175. static tree
  176. parse_field (declarator, attributes, asmspec, init)
  177. tree declarator, attributes, asmspec, init;
  178. {
  179. tree d = grokfield (declarator, current_declspecs, init, asmspec,
  180. chainon (attributes, prefix_attributes));
  181. decl_type_access_control (d);
  182. return d;
  183. }
  184. static tree
  185. parse_field0 (declarator, specs_attrs, lookups, attributes, asmspec, init)
  186. tree declarator, specs_attrs, lookups, attributes, asmspec, init;
  187. {
  188. frob_specs (specs_attrs, lookups);
  189. return parse_field (declarator, attributes, asmspec, init);
  190. }
  191. static tree
  192. parse_bitfield (declarator, attributes, width)
  193. tree declarator, attributes, width;
  194. {
  195. tree d = grokbitfield (declarator, current_declspecs, width);
  196. cplus_decl_attributes (&d, chainon (attributes, prefix_attributes), 0);
  197. decl_type_access_control (d);
  198. return d;
  199. }
  200. static tree
  201. parse_bitfield0 (declarator, specs_attrs, lookups, attributes, width)
  202. tree declarator, specs_attrs, lookups, attributes, width;
  203. {
  204. frob_specs (specs_attrs, lookups);
  205. return parse_bitfield (declarator, attributes, width);
  206. }
  207. static tree
  208. parse_method (declarator, specs_attrs, lookups)
  209. tree declarator, specs_attrs, lookups;
  210. {
  211. tree d;
  212. frob_specs (specs_attrs, lookups);
  213. d = start_method (current_declspecs, declarator, prefix_attributes);
  214. decl_type_access_control (d);
  215. return d;
  216. }
  217. static void
  218. check_class_key (key, aggr)
  219. tree key;
  220. tree aggr;
  221. {
  222. if (TREE_CODE (key) == TREE_LIST)
  223. key = TREE_VALUE (key);
  224. if ((key == union_type_node) != (TREE_CODE (aggr) == UNION_TYPE))
  225. pedwarn ("`%s' tag used in naming `%#T'",
  226. key == union_type_node ? "union"
  227. : key == record_type_node ? "struct" : "class", aggr);
  228. }
  229. %}
  230. %start program
  231. %union { GTY(())
  232. long itype;
  233. tree ttype;
  234. char *strtype;
  235. enum tree_code code;
  236. flagged_type_tree ftype;
  237. struct unparsed_text *pi;
  238. }
  239. /* All identifiers that are not reserved words
  240. and are not declared typedefs in the current block */
  241. %token IDENTIFIER
  242. /* All identifiers that are declared typedefs in the current block.
  243. In some contexts, they are treated just like IDENTIFIER,
  244. but they can also serve as typespecs in declarations. */
  245. %token tTYPENAME
  246. %token SELFNAME
  247. /* A template function. */
  248. %token PFUNCNAME
  249. /* Reserved words that specify storage class.
  250. yylval contains an IDENTIFIER_NODE which indicates which one. */
  251. %token SCSPEC
  252. /* Reserved words that specify type.
  253. yylval contains an IDENTIFIER_NODE which indicates which one. */
  254. %token TYPESPEC
  255. /* Reserved words that qualify type: "const" or "volatile".
  256. yylval contains an IDENTIFIER_NODE which indicates which one. */
  257. %token CV_QUALIFIER
  258. /* Character or numeric constants.
  259. yylval is the node for the constant. */
  260. %token CONSTANT
  261. /* __func__, __FUNCTION__ or __PRETTY_FUNCTION__.
  262. yylval contains an IDENTIFIER_NODE which indicates which one. */
  263. %token <ttype> VAR_FUNC_NAME
  264. /* String constants in raw form.
  265. yylval is a STRING_CST node. */
  266. %token STRING
  267. /* "...", used for functions with variable arglists. */
  268. %token ELLIPSIS
  269. /* the reserved words */
  270. /* SCO include files test "ASM", so use something else. */
  271. %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  272. %token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF
  273. %token SIGOF
  274. %token ATTRIBUTE EXTENSION LABEL
  275. %token REALPART IMAGPART VA_ARG
  276. /* the reserved words... C++ extensions */
  277. %token <ttype> AGGR
  278. %token <ttype> VISSPEC
  279. %token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE
  280. %token NAMESPACE TYPENAME_KEYWORD USING
  281. %token LEFT_RIGHT TEMPLATE
  282. %token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
  283. %token SCOPE EXPORT
  284. /* Define the operator tokens and their precedences.
  285. The value is an integer because, if used, it is the tree code
  286. to use in the expression made from the operator. */
  287. %left EMPTY /* used to resolve s/r with epsilon */
  288. %left error
  289. /* Add precedence rules to solve dangling else s/r conflict */
  290. %nonassoc IF
  291. %nonassoc ELSE
  292. %left IDENTIFIER PFUNCNAME tTYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD ATTRIBUTE
  293. %left '{' ',' ';'
  294. %nonassoc THROW
  295. %right <code> ':'
  296. %right <code> ASSIGN '='
  297. %right <code> '?'
  298. %left <code> OROR
  299. %left <code> ANDAND
  300. %left <code> '|'
  301. %left <code> '^'
  302. %left <code> '&'
  303. %left <code> MIN_MAX
  304. %left <code> EQCOMPARE
  305. %left <code> ARITHCOMPARE '<' '>'
  306. %left <code> LSHIFT RSHIFT
  307. %left <code> '+' '-'
  308. %left <code> '*' '/' '%'
  309. %left <code> POINTSAT_STAR DOT_STAR
  310. %right <code> UNARY PLUSPLUS MINUSMINUS '~'
  311. %left HYPERUNARY
  312. %left <ttype> LEFT_RIGHT
  313. %left <code> POINTSAT '.' '(' '['
  314. %right SCOPE /* C++ extension */
  315. %nonassoc NEW DELETE TRY CATCH
  316. %type <code> unop
  317. %type <ttype> identifier IDENTIFIER tTYPENAME CONSTANT expr nonnull_exprlist
  318. %type <ttype> PFUNCNAME maybe_identifier
  319. %type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
  320. %type <ttype> expr_no_commas expr_no_comma_rangle
  321. %type <ttype> cast_expr unary_expr primary STRING
  322. %type <ttype> reserved_declspecs boolean_literal
  323. %type <ttype> reserved_typespecquals
  324. %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
  325. %type <ttype> init initlist maybeasm maybe_init defarg defarg1
  326. %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
  327. %type <ttype> maybe_attribute attributes attribute attribute_list attrib
  328. %type <ttype> any_word
  329. %type <itype> save_lineno
  330. %type <ttype> simple_stmt simple_if
  331. %type <ttype> declarator notype_declarator after_type_declarator
  332. %type <ttype> notype_declarator_intern absdcl_intern
  333. %type <ttype> after_type_declarator_intern
  334. %type <ttype> direct_notype_declarator direct_after_type_declarator
  335. %type <itype> components notype_components
  336. %type <ttype> component_decl component_decl_1
  337. %type <ttype> component_declarator component_declarator0
  338. %type <ttype> notype_component_declarator notype_component_declarator0
  339. %type <ttype> after_type_component_declarator after_type_component_declarator0
  340. %type <ttype> absdcl cv_qualifiers
  341. %type <ttype> direct_abstract_declarator conversion_declarator
  342. %type <ttype> new_declarator direct_new_declarator
  343. %type <ttype> xexpr parmlist parms bad_parm
  344. %type <ttype> identifiers_or_typenames
  345. %type <ttype> fcast_or_absdcl regcast_or_absdcl
  346. %type <ttype> expr_or_declarator expr_or_declarator_intern
  347. %type <ttype> complex_notype_declarator
  348. %type <ttype> notype_unqualified_id unqualified_id qualified_id
  349. %type <ttype> template_id do_id object_template_id notype_template_declarator
  350. %type <ttype> overqualified_id notype_qualified_id any_id
  351. %type <ttype> complex_direct_notype_declarator functional_cast
  352. %type <ttype> complex_parmlist parms_comma
  353. %type <ttype> namespace_qualifier namespace_using_decl
  354. %type <ftype> type_id new_type_id typed_typespecs typespec typed_declspecs
  355. %type <ftype> typed_declspecs1 type_specifier_seq nonempty_cv_qualifiers
  356. %type <ftype> structsp typespecqual_reserved parm named_parm full_parm
  357. %type <ftype> declmods
  358. %type <itype> extension
  359. /* C++ extensions */
  360. %token <ttype> PTYPENAME
  361. %token <ttype> EXTERN_LANG_STRING ALL
  362. %token <ttype> PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER
  363. %token <pi> PRE_PARSED_FUNCTION_DECL
  364. %type <ttype> component_constructor_declarator
  365. %type <ttype> fn_def2 return_id constructor_declarator
  366. %type <ttype> begin_function_body_
  367. %type <ttype> class_head class_head_apparent_template
  368. %type <ftype> class_head_decl class_head_defn
  369. %type <ttype> base_class_list
  370. %type <ttype> base_class_access_list
  371. %type <ttype> base_class maybe_base_class_list base_class_1
  372. %type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers
  373. %type <ttype> operator_name
  374. %type <ttype> object aggr
  375. %type <itype> new delete
  376. /* %type <ttype> primary_no_id */
  377. %type <ttype> maybe_parmlist
  378. %type <ttype> member_init
  379. %type <ftype> member_init_list
  380. %type <ttype> template_parm_header template_spec_header template_header
  381. %type <ttype> template_parm_list template_parm
  382. %type <ttype> template_type_parm template_template_parm
  383. %type <code> template_close_bracket
  384. %type <ttype> apparent_template_type
  385. %type <ttype> template_type template_arg_list template_arg_list_opt
  386. %type <ttype> template_arg
  387. %type <ttype> condition xcond paren_cond_or_null
  388. %type <ttype> type_name nested_name_specifier nested_type ptr_to_mem
  389. %type <ttype> complete_type_name notype_identifier nonnested_type
  390. %type <ttype> complex_type_name nested_name_specifier_1
  391. %type <ttype> new_initializer new_placement
  392. %type <ttype> using_decl
  393. %type <ttype> typename_sub typename_sub0 typename_sub1 typename_sub2
  394. %type <ttype> explicit_template_type
  395. /* in order to recognize aggr tags as defining and thus shadowing. */
  396. %token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
  397. %type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN
  398. %type <ttype> handler_args
  399. %type <ttype> self_template_type finish_template_type_
  400. %token NSNAME
  401. %type <ttype> NSNAME
  402. /* Used in lex.c for parsing pragmas. */
  403. %token END_OF_LINE
  404. /* lex.c and pt.c depend on this being the last token. Define
  405. any new tokens before this one! */
  406. %token END_OF_SAVED_INPUT
  407. %{
  408. /* Tell yyparse how to print a token's value, if yydebug is set. */
  409. #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  410. extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
  411. %}
  412. %%
  413. program:
  414. /* empty */
  415. { finish_translation_unit (); }
  416. | extdefs
  417. { finish_translation_unit (); }
  418. ;
  419. /* the reason for the strange actions in this rule
  420. is so that notype_initdecls when reached via datadef
  421. can find a valid list of type and sc specs in $0. */
  422. extdefs:
  423. { $<ttype>$ = NULL_TREE; }
  424. lang_extdef
  425. { $<ttype>$ = NULL_TREE; ggc_collect (); }
  426. | extdefs lang_extdef
  427. { $<ttype>$ = NULL_TREE; ggc_collect (); }
  428. ;
  429. extdefs_opt:
  430. extdefs
  431. | /* empty */
  432. ;
  433. .hush_warning:
  434. { have_extern_spec = true;
  435. $<ttype>$ = NULL_TREE; }
  436. ;
  437. .warning_ok:
  438. { have_extern_spec = false; }
  439. ;
  440. extension:
  441. EXTENSION
  442. { $$ = pedantic;
  443. pedantic = 0; }
  444. ;
  445. asm_keyword:
  446. ASM_KEYWORD
  447. ;
  448. lang_extdef:
  449. { if (pending_lang_change) do_pending_lang_change();
  450. type_lookups = NULL_TREE; }
  451. extdef
  452. { if (! toplevel_bindings_p ())
  453. pop_everything (); }
  454. ;
  455. extdef:
  456. fndef eat_saved_input
  457. { do_pending_inlines (); }
  458. | datadef
  459. { do_pending_inlines (); }
  460. | EXPORT
  461. { warning ("keyword `export' not implemented, and will be ignored"); }
  462. template_def
  463. { do_pending_inlines (); }
  464. | template_def
  465. { do_pending_inlines (); }
  466. | asm_keyword '(' STRING ')' ';'
  467. { assemble_asm ($3); }
  468. | extern_lang_string '{' extdefs_opt '}'
  469. { pop_lang_context (); }
  470. | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
  471. { do_pending_inlines (); pop_lang_context (); }
  472. | extern_lang_string .hush_warning datadef .warning_ok
  473. { do_pending_inlines (); pop_lang_context (); }
  474. | NAMESPACE identifier '{'
  475. { push_namespace ($2); }
  476. extdefs_opt '}'
  477. { pop_namespace (); }
  478. | NAMESPACE '{'
  479. { push_namespace (NULL_TREE); }
  480. extdefs_opt '}'
  481. { pop_namespace (); }
  482. | namespace_alias
  483. | using_decl ';'
  484. { do_toplevel_using_decl ($1); }
  485. | using_directive
  486. | extension extdef
  487. { pedantic = $1; }
  488. ;
  489. namespace_alias:
  490. NAMESPACE identifier '='
  491. { begin_only_namespace_names (); }
  492. any_id ';'
  493. {
  494. end_only_namespace_names ();
  495. if (lastiddecl)
  496. $5 = lastiddecl;
  497. do_namespace_alias ($2, $5);
  498. }
  499. ;
  500. using_decl:
  501. USING qualified_id
  502. { $$ = $2; }
  503. | USING global_scope qualified_id
  504. { $$ = $3; }
  505. | USING global_scope unqualified_id
  506. { $$ = $3; }
  507. ;
  508. namespace_using_decl:
  509. USING namespace_qualifier identifier
  510. { $$ = build_nt (SCOPE_REF, $2, $3); }
  511. | USING global_scope identifier
  512. { $$ = build_nt (SCOPE_REF, global_namespace, $3); }
  513. | USING global_scope namespace_qualifier identifier
  514. { $$ = build_nt (SCOPE_REF, $3, $4); }
  515. ;
  516. using_directive:
  517. USING NAMESPACE
  518. { begin_only_namespace_names (); }
  519. any_id ';'
  520. {
  521. end_only_namespace_names ();
  522. /* If no declaration was found, the using-directive is
  523. invalid. Since that was not reported, we need the
  524. identifier for the error message. */
  525. if (TREE_CODE ($4) == IDENTIFIER_NODE && lastiddecl)
  526. $4 = lastiddecl;
  527. do_using_directive ($4);
  528. }
  529. ;
  530. namespace_qualifier:
  531. NSNAME SCOPE
  532. {
  533. if (TREE_CODE ($$) == IDENTIFIER_NODE)
  534. $$ = lastiddecl;
  535. got_scope = $$;
  536. }
  537. | namespace_qualifier NSNAME SCOPE
  538. {
  539. $$ = $2;
  540. if (TREE_CODE ($$) == IDENTIFIER_NODE)
  541. $$ = lastiddecl;
  542. got_scope = $$;
  543. }
  544. ;
  545. any_id:
  546. unqualified_id
  547. | qualified_id
  548. | global_scope qualified_id
  549. { $$ = $2; }
  550. | global_scope unqualified_id
  551. { $$ = $2; }
  552. ;
  553. extern_lang_string:
  554. EXTERN_LANG_STRING
  555. { push_lang_context ($1); }
  556. | extern_lang_string EXTERN_LANG_STRING
  557. { if (current_lang_name != $2)
  558. error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name);
  559. pop_lang_context (); push_lang_context ($2); }
  560. ;
  561. template_parm_header:
  562. TEMPLATE '<'
  563. { begin_template_parm_list (); }
  564. template_parm_list '>'
  565. { $$ = end_template_parm_list ($4); }
  566. ;
  567. template_spec_header:
  568. TEMPLATE '<' '>'
  569. { begin_specialization();
  570. $$ = NULL_TREE; }
  571. ;
  572. template_header:
  573. template_parm_header
  574. | template_spec_header
  575. ;
  576. template_parm_list:
  577. template_parm
  578. { $$ = process_template_parm (NULL_TREE, $1); }
  579. | template_parm_list ',' template_parm
  580. { $$ = process_template_parm ($1, $3); }
  581. ;
  582. maybe_identifier:
  583. identifier
  584. { $$ = $1; }
  585. | /* empty */
  586. { $$ = NULL_TREE; }
  587. ;
  588. template_type_parm:
  589. aggr maybe_identifier
  590. { $$ = finish_template_type_parm ($1, $2); }
  591. | TYPENAME_KEYWORD maybe_identifier
  592. { $$ = finish_template_type_parm (class_type_node, $2); }
  593. ;
  594. template_template_parm:
  595. template_parm_header aggr maybe_identifier
  596. { $$ = finish_template_template_parm ($2, $3); }
  597. ;
  598. template_parm:
  599. /* The following rules introduce a new reduce/reduce
  600. conflict on the ',' and '>' input tokens: they are valid
  601. prefixes for a `structsp', which means they could match a
  602. nameless parameter. See 14.6, paragraph 3.
  603. By putting them before the `parm' rule, we get
  604. their match before considering them nameless parameter
  605. declarations. */
  606. template_type_parm
  607. { $$ = build_tree_list (NULL_TREE, $1); }
  608. | template_type_parm '=' type_id
  609. { $$ = build_tree_list (groktypename ($3.t), $1); }
  610. | parm
  611. { $$ = build_tree_list (NULL_TREE, $1.t); }
  612. | parm '=' expr_no_comma_rangle
  613. { $$ = build_tree_list ($3, $1.t); }
  614. | template_template_parm
  615. { $$ = build_tree_list (NULL_TREE, $1); }
  616. | template_template_parm '=' template_arg
  617. {
  618. $3 = check_template_template_default_arg ($3);
  619. $$ = build_tree_list ($3, $1);
  620. }
  621. ;
  622. template_def:
  623. template_header template_extdef
  624. { finish_template_decl ($1); }
  625. | template_header error %prec EMPTY
  626. { finish_template_decl ($1); }
  627. ;
  628. template_extdef:
  629. fndef eat_saved_input
  630. { do_pending_inlines (); }
  631. | template_datadef
  632. { do_pending_inlines (); }
  633. | template_def
  634. { do_pending_inlines (); }
  635. | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
  636. { do_pending_inlines ();
  637. pop_lang_context (); }
  638. | extern_lang_string .hush_warning template_datadef .warning_ok
  639. { do_pending_inlines ();
  640. pop_lang_context (); }
  641. | extension template_extdef
  642. { pedantic = $1; }
  643. ;
  644. template_datadef:
  645. nomods_initdecls ';'
  646. | declmods notype_initdecls ';'
  647. {}
  648. | typed_declspecs initdecls ';'
  649. { note_list_got_semicolon ($1.t); }
  650. | structsp ';'
  651. {
  652. if ($1.t != error_mark_node)
  653. {
  654. maybe_process_partial_specialization ($1.t);
  655. note_got_semicolon ($1.t);
  656. }
  657. }
  658. ;
  659. datadef:
  660. nomods_initdecls ';'
  661. | declmods notype_initdecls ';'
  662. {}
  663. | typed_declspecs initdecls ';'
  664. { note_list_got_semicolon ($1.t); }
  665. | declmods ';'
  666. { pedwarn ("empty declaration"); }
  667. | explicit_instantiation ';'
  668. | typed_declspecs ';'
  669. {
  670. tree t, attrs;
  671. split_specs_attrs ($1.t, &t, &attrs);
  672. shadow_tag (t);
  673. note_list_got_semicolon ($1.t);
  674. }
  675. | error ';'
  676. | error '}'
  677. | error END_OF_SAVED_INPUT
  678. { end_input (); }
  679. | ';'
  680. | bad_decl
  681. ;
  682. ctor_initializer_opt:
  683. nodecls
  684. | base_init
  685. ;
  686. maybe_return_init:
  687. /* empty */
  688. | return_init
  689. | return_init ';'
  690. ;
  691. eat_saved_input:
  692. /* empty */
  693. | END_OF_SAVED_INPUT
  694. ;
  695. /* The outermost block of a function really begins before the
  696. mem-initializer-list, so we open one there and suppress the one that
  697. actually corresponds to the curly braces. */
  698. function_body:
  699. begin_function_body_ ctor_initializer_opt save_lineno '{'
  700. { $<ttype>$ = begin_compound_stmt (/*has_no_scope=*/1); }
  701. compstmtend
  702. {
  703. STMT_LINENO ($<ttype>5) = $3;
  704. finish_compound_stmt (/*has_no_scope=*/1, $<ttype>5);
  705. finish_function_body ($1);
  706. }
  707. ;
  708. fndef:
  709. fn.def1 maybe_return_init function_body
  710. { expand_body (finish_function (0)); }
  711. | fn.def1 maybe_return_init function_try_block
  712. { expand_body (finish_function (0)); }
  713. | fn.def1 maybe_return_init error
  714. { }
  715. ;
  716. constructor_declarator:
  717. nested_name_specifier SELFNAME '('
  718. { $$ = begin_constructor_declarator ($1, $2); }
  719. parmlist ')' cv_qualifiers exception_specification_opt
  720. { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
  721. | nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
  722. { $$ = begin_constructor_declarator ($1, $2);
  723. $$ = make_call_declarator ($$, empty_parms (), $4, $5);
  724. }
  725. | global_scope nested_name_specifier SELFNAME '('
  726. { $$ = begin_constructor_declarator ($2, $3); }
  727. parmlist ')' cv_qualifiers exception_specification_opt
  728. { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
  729. | global_scope nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
  730. { $$ = begin_constructor_declarator ($2, $3);
  731. $$ = make_call_declarator ($$, empty_parms (), $5, $6);
  732. }
  733. | nested_name_specifier self_template_type '('
  734. { $$ = begin_constructor_declarator ($1, $2); }
  735. parmlist ')' cv_qualifiers exception_specification_opt
  736. { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
  737. | nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
  738. { $$ = begin_constructor_declarator ($1, $2);
  739. $$ = make_call_declarator ($$, empty_parms (), $4, $5);
  740. }
  741. | global_scope nested_name_specifier self_template_type '('
  742. { $$ = begin_constructor_declarator ($2, $3); }
  743. parmlist ')' cv_qualifiers exception_specification_opt
  744. { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
  745. | global_scope nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
  746. { $$ = begin_constructor_declarator ($2, $3);
  747. $$ = make_call_declarator ($$, empty_parms (), $5, $6);
  748. }
  749. ;
  750. fn.def1:
  751. typed_declspecs declarator
  752. { check_for_new_type ("return type", $1);
  753. if (!parse_begin_function_definition ($1.t, $2))
  754. YYERROR1; }
  755. | declmods notype_declarator
  756. { if (!parse_begin_function_definition ($1.t, $2))
  757. YYERROR1; }
  758. | notype_declarator
  759. { if (!parse_begin_function_definition (NULL_TREE, $1))
  760. YYERROR1; }
  761. | declmods constructor_declarator
  762. { if (!parse_begin_function_definition ($1.t, $2))
  763. YYERROR1; }
  764. | constructor_declarator
  765. { if (!parse_begin_function_definition (NULL_TREE, $1))
  766. YYERROR1; }
  767. ;
  768. /* ANSI allows optional parentheses around constructor class names.
  769. See ISO/IEC 14882:1998(E) 12.1. */
  770. component_constructor_declarator:
  771. SELFNAME '(' parmlist ')' cv_qualifiers exception_specification_opt
  772. { $$ = make_call_declarator ($1, $3, $5, $6); }
  773. | '(' SELFNAME ')' '(' parmlist ')' cv_qualifiers
  774. exception_specification_opt
  775. { $$ = make_call_declarator ($2, $5, $7, $8); }
  776. | SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
  777. { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
  778. | '(' SELFNAME ')' LEFT_RIGHT cv_qualifiers exception_specification_opt
  779. { $$ = make_call_declarator ($2, empty_parms (), $5, $6); }
  780. | self_template_type '(' parmlist ')' cv_qualifiers exception_specification_opt
  781. { $$ = make_call_declarator ($1, $3, $5, $6); }
  782. | self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
  783. { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
  784. ;
  785. /* more C++ complexity. See component_decl for a comment on the
  786. reduce/reduce conflict introduced by these rules. */
  787. fn_def2:
  788. declmods component_constructor_declarator
  789. { $$ = parse_method ($2, $1.t, $1.lookups);
  790. rest_of_mdef:
  791. if (! $$)
  792. YYERROR1;
  793. if (yychar == YYEMPTY)
  794. yychar = YYLEX;
  795. snarf_method ($$); }
  796. | component_constructor_declarator
  797. { $$ = parse_method ($1, NULL_TREE, NULL_TREE);
  798. goto rest_of_mdef; }
  799. | typed_declspecs declarator
  800. { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
  801. | declmods notype_declarator
  802. { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
  803. | notype_declarator
  804. { $$ = parse_method ($1, NULL_TREE, NULL_TREE);
  805. goto rest_of_mdef; }
  806. | declmods constructor_declarator
  807. { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
  808. | constructor_declarator
  809. { $$ = parse_method ($1, NULL_TREE, NULL_TREE);
  810. goto rest_of_mdef; }
  811. ;
  812. return_id:
  813. RETURN_KEYWORD IDENTIFIER
  814. {
  815. $$ = $2;
  816. }
  817. ;
  818. return_init:
  819. return_id maybe_init
  820. { finish_named_return_value ($<ttype>$, $2); }
  821. | return_id '(' nonnull_exprlist ')'
  822. { finish_named_return_value ($<ttype>$, $3); }
  823. | return_id LEFT_RIGHT
  824. { finish_named_return_value ($<ttype>$, NULL_TREE); }
  825. ;
  826. base_init:
  827. ':' { begin_mem_initializers (); } member_init_list
  828. {
  829. if ($3.new_type_flag == 0)
  830. error ("no base or member initializers given following ':'");
  831. finish_mem_initializers ($3.t);
  832. }
  833. ;
  834. begin_function_body_:
  835. /* empty */
  836. {
  837. $$ = begin_function_body ();
  838. }
  839. ;
  840. member_init_list:
  841. /* empty */
  842. {
  843. $$.new_type_flag = 0;
  844. $$.t = NULL_TREE;
  845. }
  846. | member_init
  847. {
  848. $$.new_type_flag = 1;
  849. $$.t = $1;
  850. }
  851. | member_init_list ',' member_init
  852. {
  853. if ($3)
  854. {
  855. $$.new_type_flag = 1;
  856. TREE_CHAIN ($3) = $1.t;
  857. $$.t = $3;
  858. }
  859. else
  860. $$ = $1;
  861. }
  862. | member_init_list error
  863. ;
  864. member_init:
  865. '(' nonnull_exprlist ')'
  866. {
  867. if (current_class_name)
  868. pedwarn ("anachronistic old style base class initializer");
  869. $$ = expand_member_init (NULL_TREE, $2);
  870. }
  871. | LEFT_RIGHT
  872. {
  873. if (current_class_name)
  874. pedwarn ("anachronistic old style base class initializer");
  875. $$ = expand_member_init (NULL_TREE,
  876. void_type_node);
  877. }
  878. | notype_identifier '(' nonnull_exprlist ')'
  879. { $$ = expand_member_init ($1, $3); }
  880. | notype_identifier LEFT_RIGHT
  881. { $$ = expand_member_init ($1, void_type_node); }
  882. | nonnested_type '(' nonnull_exprlist ')'
  883. { $$ = expand_member_init ($1, $3); }
  884. | nonnested_type LEFT_RIGHT
  885. { $$ = expand_member_init ($1, void_type_node); }
  886. | typename_sub '(' nonnull_exprlist ')'
  887. { $$ = expand_member_init ($1, $3); }
  888. | typename_sub LEFT_RIGHT
  889. { $$ = expand_member_init ($1, void_type_node); }
  890. | error
  891. { $$ = NULL_TREE; }
  892. ;
  893. identifier:
  894. IDENTIFIER
  895. | tTYPENAME
  896. | SELFNAME
  897. | PTYPENAME
  898. | NSNAME
  899. ;
  900. notype_identifier:
  901. IDENTIFIER
  902. | PTYPENAME
  903. | NSNAME %prec EMPTY
  904. ;
  905. identifier_defn:
  906. IDENTIFIER_DEFN
  907. | TYPENAME_DEFN
  908. | PTYPENAME_DEFN
  909. ;
  910. explicit_instantiation:
  911. TEMPLATE begin_explicit_instantiation typespec ';'
  912. { do_type_instantiation ($3.t, NULL_TREE, 1);
  913. yyungetc (';', 1); }
  914. end_explicit_instantiation
  915. | TEMPLATE begin_explicit_instantiation typed_declspecs declarator
  916. { tree specs = strip_attrs ($3.t);
  917. parse_decl_instantiation (specs, $4, NULL_TREE); }
  918. end_explicit_instantiation
  919. | TEMPLATE begin_explicit_instantiation notype_declarator
  920. { parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
  921. end_explicit_instantiation
  922. | TEMPLATE begin_explicit_instantiation constructor_declarator
  923. { parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
  924. end_explicit_instantiation
  925. | SCSPEC TEMPLATE begin_explicit_instantiation typespec ';'
  926. { do_type_instantiation ($4.t, $1, 1);
  927. yyungetc (';', 1); }
  928. end_explicit_instantiation
  929. {}
  930. | SCSPEC TEMPLATE begin_explicit_instantiation typed_declspecs
  931. declarator
  932. { tree specs = strip_attrs ($4.t);
  933. parse_decl_instantiation (specs, $5, $1); }
  934. end_explicit_instantiation
  935. {}
  936. | SCSPEC TEMPLATE begin_explicit_instantiation notype_declarator
  937. { parse_decl_instantiation (NULL_TREE, $4, $1); }
  938. end_explicit_instantiation
  939. {}
  940. | SCSPEC TEMPLATE begin_explicit_instantiation constructor_declarator
  941. { parse_decl_instantiation (NULL_TREE, $4, $1); }
  942. end_explicit_instantiation
  943. {}
  944. ;
  945. begin_explicit_instantiation:
  946. { begin_explicit_instantiation(); }
  947. ;
  948. end_explicit_instantiation:
  949. { end_explicit_instantiation(); }
  950. ;
  951. /* The TYPENAME expansions are to deal with use of a template class name as
  952. a template within the class itself, where the template decl is hidden by
  953. a type decl. Got all that? */
  954. template_type:
  955. PTYPENAME '<' template_arg_list_opt template_close_bracket
  956. finish_template_type_
  957. { $$ = $5; }
  958. | tTYPENAME '<' template_arg_list_opt template_close_bracket
  959. finish_template_type_
  960. { $$ = $5; }
  961. | self_template_type
  962. ;
  963. apparent_template_type:
  964. template_type
  965. | identifier '<' template_arg_list_opt '>'
  966. finish_template_type_
  967. { $$ = $5; }
  968. ;
  969. self_template_type:
  970. SELFNAME '<' template_arg_list_opt template_close_bracket
  971. finish_template_type_
  972. { $$ = $5; }
  973. ;
  974. finish_template_type_:
  975. {
  976. if (yychar == YYEMPTY)
  977. yychar = YYLEX;
  978. $$ = finish_template_type ($<ttype>-3, $<ttype>-1,
  979. yychar == SCOPE);
  980. }
  981. ;
  982. template_close_bracket:
  983. '>'
  984. | RSHIFT
  985. {
  986. /* Handle `Class<Class<Type>>' without space in the `>>' */
  987. pedwarn ("`>>' should be `> >' in template class name");
  988. yyungetc ('>', 1);
  989. }
  990. ;
  991. template_arg_list_opt:
  992. /* empty */
  993. { $$ = NULL_TREE; }
  994. | template_arg_list
  995. ;
  996. template_arg_list:
  997. template_arg
  998. { $$ = build_tree_list (NULL_TREE, $$); }
  999. | template_arg_list ',' template_arg
  1000. { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); }
  1001. ;
  1002. template_arg:
  1003. type_id
  1004. { $$ = groktypename ($1.t); }
  1005. | PTYPENAME
  1006. {
  1007. $$ = lastiddecl;
  1008. if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
  1009. $$ = TREE_TYPE ($$);
  1010. }
  1011. | global_scope PTYPENAME
  1012. {
  1013. $$ = lastiddecl;
  1014. if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
  1015. $$ = TREE_TYPE ($$);
  1016. }
  1017. | expr_no_comma_rangle
  1018. | nested_name_specifier TEMPLATE identifier
  1019. {
  1020. if (!processing_template_decl)
  1021. {
  1022. error ("use of template qualifier outside template");
  1023. $$ = error_mark_node;
  1024. }
  1025. else
  1026. $$ = make_unbound_class_template ($1, $3, tf_error | tf_parsing);
  1027. }
  1028. ;
  1029. unop:
  1030. '-'
  1031. { $$ = NEGATE_EXPR; }
  1032. | '+'
  1033. { $$ = CONVERT_EXPR; }
  1034. | PLUSPLUS
  1035. { $$ = PREINCREMENT_EXPR; }
  1036. | MINUSMINUS
  1037. { $$ = PREDECREMENT_EXPR; }
  1038. | '!'
  1039. { $$ = TRUTH_NOT_EXPR; }
  1040. ;
  1041. expr:
  1042. nontrivial_exprlist
  1043. { $$ = build_x_compound_expr ($$); }
  1044. | expr_no_commas
  1045. ;
  1046. paren_expr_or_null:
  1047. LEFT_RIGHT
  1048. { error ("ISO C++ forbids an empty condition for `%s'",
  1049. cond_stmt_keyword);
  1050. $$ = integer_zero_node; }
  1051. | '(' expr ')'
  1052. { $$ = $2; }
  1053. ;
  1054. paren_cond_or_null:
  1055. LEFT_RIGHT
  1056. { error ("ISO C++ forbids an empty condition for `%s'",
  1057. cond_stmt_keyword);
  1058. $$ = integer_zero_node; }
  1059. | '(' condition ')'
  1060. { $$ = $2; }
  1061. ;
  1062. xcond:
  1063. /* empty */
  1064. { $$ = NULL_TREE; }
  1065. | condition
  1066. | error
  1067. { $$ = NULL_TREE; }
  1068. ;
  1069. condition:
  1070. type_specifier_seq declarator maybeasm maybe_attribute '='
  1071. { {
  1072. tree d;
  1073. for (d = getdecls (); d; d = TREE_CHAIN (d))
  1074. if (TREE_CODE (d) == TYPE_DECL) {
  1075. tree s = TREE_TYPE (d);
  1076. if (TREE_CODE (s) == RECORD_TYPE)
  1077. error ("definition of class `%T' in condition", s);
  1078. else if (TREE_CODE (s) == ENUMERAL_TYPE)
  1079. error ("definition of enum `%T' in condition", s);
  1080. }
  1081. }
  1082. current_declspecs = $1.t;
  1083. $<ttype>$ = parse_decl ($<ttype>2, $4, 1);
  1084. }
  1085. init
  1086. {
  1087. parse_end_decl ($<ttype>6, $7, $4);
  1088. $$ = convert_from_reference ($<ttype>6);
  1089. if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE)
  1090. error ("definition of array `%#D' in condition", $$);
  1091. }
  1092. | expr
  1093. ;
  1094. compstmtend:
  1095. '}'
  1096. | maybe_label_decls stmts '}'
  1097. | maybe_label_decls stmts error '}'
  1098. | maybe_label_decls error '}'
  1099. ;
  1100. nontrivial_exprlist:
  1101. expr_no_commas ',' expr_no_commas
  1102. { $$ = tree_cons (NULL_TREE, $$,
  1103. build_tree_list (NULL_TREE, $3)); }
  1104. | expr_no_commas ',' error
  1105. { $$ = tree_cons (NULL_TREE, $$,
  1106. build_tree_list (NULL_TREE, error_mark_node)); }
  1107. | nontrivial_exprlist ',' expr_no_commas
  1108. { chainon ($$, build_tree_list (NULL_TREE, $3)); }
  1109. | nontrivial_exprlist ',' error
  1110. { chainon ($$, build_tree_list (NULL_TREE, error_mark_node)); }
  1111. ;
  1112. nonnull_exprlist:
  1113. expr_no_commas
  1114. { $$ = build_tree_list (NULL_TREE, $$); }
  1115. | nontrivial_exprlist
  1116. ;
  1117. unary_expr:
  1118. primary %prec UNARY
  1119. { $$ = $1; }
  1120. /* __extension__ turns off -pedantic for following primary. */
  1121. | extension cast_expr %prec UNARY
  1122. { $$ = $2;
  1123. pedantic = $1; }
  1124. | '*' cast_expr %prec UNARY
  1125. { $$ = build_x_indirect_ref ($2, "unary *"); }
  1126. | '&' cast_expr %prec UNARY
  1127. { $$ = build_x_unary_op (ADDR_EXPR, $2); }
  1128. | '~' cast_expr
  1129. { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
  1130. | unop cast_expr %prec UNARY
  1131. { $$ = finish_unary_op_expr ($1, $2); }
  1132. /* Refer to the address of a label as a pointer. */
  1133. | ANDAND identifier
  1134. { $$ = finish_label_address_expr ($2); }
  1135. | sizeof unary_expr %prec UNARY
  1136. { $$ = finish_sizeof ($2);
  1137. skip_evaluation--; }
  1138. | sizeof '(' type_id ')' %prec HYPERUNARY
  1139. { $$ = finish_sizeof (groktypename ($3.t));
  1140. check_for_new_type ("sizeof", $3);
  1141. skip_evaluation--; }
  1142. | alignof unary_expr %prec UNARY
  1143. { $$ = finish_alignof ($2);
  1144. skip_evaluation--; }
  1145. | alignof '(' type_id ')' %prec HYPERUNARY
  1146. { $$ = finish_alignof (groktypename ($3.t));
  1147. check_for_new_type ("alignof", $3);
  1148. skip_evaluation--; }
  1149. /* The %prec EMPTY's here are required by the = init initializer
  1150. syntax extension; see below. */
  1151. | new new_type_id %prec EMPTY
  1152. { $$ = build_new (NULL_TREE, $2.t, NULL_TREE, $1);
  1153. check_for_new_type ("new", $2); }
  1154. | new new_type_id new_initializer
  1155. { $$ = build_new (NULL_TREE, $2.t, $3, $1);
  1156. check_for_new_type ("new", $2); }
  1157. | new new_placement new_type_id %prec EMPTY
  1158. { $$ = build_new ($2, $3.t, NULL_TREE, $1);
  1159. check_for_new_type ("new", $3); }
  1160. | new new_placement new_type_id new_initializer
  1161. { $$ = build_new ($2, $3.t, $4, $1);
  1162. check_for_new_type ("new", $3); }
  1163. | new '(' type_id ')'
  1164. %prec EMPTY
  1165. { $$ = build_new (NULL_TREE, groktypename($3.t),
  1166. NULL_TREE, $1);
  1167. check_for_new_type ("new", $3); }
  1168. | new '(' type_id ')' new_initializer
  1169. { $$ = build_new (NULL_TREE, groktypename($3.t), $5, $1);
  1170. check_for_new_type ("new", $3); }
  1171. | new new_placement '(' type_id ')' %prec EMPTY
  1172. { $$ = build_new ($2, groktypename($4.t), NULL_TREE, $1);
  1173. check_for_new_type ("new", $4); }
  1174. | new new_placement '(' type_id ')' new_initializer
  1175. { $$ = build_new ($2, groktypename($4.t), $6, $1);
  1176. check_for_new_type ("new", $4); }
  1177. | delete cast_expr %prec UNARY
  1178. { $$ = delete_sanity ($2, NULL_TREE, 0, $1); }
  1179. | delete '[' ']' cast_expr %prec UNARY
  1180. { $$ = delete_sanity ($4, NULL_TREE, 1, $1);
  1181. if (yychar == YYEMPTY)
  1182. yychar = YYLEX; }
  1183. | delete '[' expr ']' cast_expr %prec UNARY
  1184. { $$ = delete_sanity ($5, $3, 2, $1);
  1185. if (yychar == YYEMPTY)
  1186. yychar = YYLEX; }
  1187. | REALPART cast_expr %prec UNARY
  1188. { $$ = build_x_unary_op (REALPART_EXPR, $2); }
  1189. | IMAGPART cast_expr %prec UNARY
  1190. { $$ = build_x_unary_op (IMAGPART_EXPR, $2); }
  1191. ;
  1192. new_placement:
  1193. '(' nonnull_exprlist ')'
  1194. { $$ = $2; }
  1195. | '{' nonnull_exprlist '}'
  1196. { pedwarn ("old style placement syntax, use () instead");
  1197. $$ = $2; }
  1198. ;
  1199. new_initializer:
  1200. '(' nonnull_exprlist ')'
  1201. { $$ = $2; }
  1202. | LEFT_RIGHT
  1203. { $$ = void_zero_node; }
  1204. | '(' typespec ')'
  1205. {
  1206. error ("`%T' is not a valid expression", $2.t);
  1207. $$ = error_mark_node;
  1208. }
  1209. | '=' init
  1210. {
  1211. /* This was previously allowed as an extension, but
  1212. was removed in G++ 3.3. */
  1213. error ("initialization of new expression with `='");
  1214. $$ = error_mark_node;
  1215. }
  1216. ;
  1217. /* This is necessary to postpone reduction of `int ((int)(int)(int))'. */
  1218. regcast_or_absdcl:
  1219. '(' type_id ')' %prec EMPTY
  1220. { $2.t = finish_parmlist (build_tree_list (NULL_TREE, $2.t), 0);
  1221. $$ = make_call_declarator (NULL_TREE, $2.t, NULL_TREE, NULL_TREE);
  1222. check_for_new_type ("cast", $2); }
  1223. | regcast_or_absdcl '(' type_id ')' %prec EMPTY
  1224. { $3.t = finish_parmlist (build_tree_list (NULL_TREE, $3.t), 0);
  1225. $$ = make_call_declarator ($$, $3.t, NULL_TREE, NULL_TREE);
  1226. check_for_new_type ("cast", $3); }
  1227. ;
  1228. cast_expr:
  1229. unary_expr
  1230. | regcast_or_absdcl unary_expr %prec UNARY
  1231. { $$ = reparse_absdcl_as_casts ($$, $2); }
  1232. | regcast_or_absdcl '{' initlist maybecomma '}' %prec UNARY
  1233. {
  1234. tree init = build_nt (CONSTRUCTOR, NULL_TREE,
  1235. nreverse ($3));
  1236. if (pedantic)
  1237. pedwarn ("ISO C++ forbids compound literals");
  1238. /* Indicate that this was a C99 compound literal. */
  1239. TREE_HAS_CONSTRUCTOR (init) = 1;
  1240. $$ = reparse_absdcl_as_casts ($$, init);
  1241. }
  1242. ;
  1243. expr_no_commas:
  1244. cast_expr
  1245. /* Handle general members. */
  1246. | expr_no_commas POINTSAT_STAR expr_no_commas
  1247. { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
  1248. | expr_no_commas DOT_STAR expr_no_commas
  1249. { $$ = build_m_component_ref ($$, $3); }
  1250. | expr_no_commas '+' expr_no_commas
  1251. { $$ = build_x_binary_op ($2, $$, $3); }
  1252. | expr_no_commas '-' expr_no_commas
  1253. { $$ = build_x_binary_op ($2, $$, $3); }
  1254. | expr_no_commas '*' expr_no_commas
  1255. { $$ = build_x_binary_op ($2, $$, $3); }
  1256. | expr_no_commas '/' expr_no_commas
  1257. { $$ = build_x_binary_op ($2, $$, $3); }
  1258. | expr_no_commas '%' expr_no_commas
  1259. { $$ = build_x_binary_op ($2, $$, $3); }
  1260. | expr_no_commas LSHIFT expr_no_commas
  1261. { $$ = build_x_binary_op ($2, $$, $3); }
  1262. | expr_no_commas RSHIFT expr_no_commas
  1263. { $$ = build_x_binary_op ($2, $$, $3); }
  1264. | expr_no_commas ARITHCOMPARE expr_no_commas
  1265. { $$ = build_x_binary_op ($2, $$, $3); }
  1266. | expr_no_commas '<' expr_no_commas
  1267. { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
  1268. | expr_no_commas '>' expr_no_commas
  1269. { $$ = build_x_binary_op (GT_EXPR, $$, $3); }
  1270. | expr_no_commas EQCOMPARE expr_no_commas
  1271. { $$ = build_x_binary_op ($2, $$, $3); }
  1272. | expr_no_commas MIN_MAX expr_no_commas
  1273. { $$ = build_x_binary_op ($2, $$, $3); }
  1274. | expr_no_commas '&' expr_no_commas
  1275. { $$ = build_x_binary_op ($2, $$, $3); }
  1276. | expr_no_commas '|' expr_no_commas
  1277. { $$ = build_x_binary_op ($2, $$, $3); }
  1278. | expr_no_commas '^' expr_no_commas
  1279. { $$ = build_x_binary_op ($2, $$, $3); }
  1280. | expr_no_commas ANDAND expr_no_commas
  1281. { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
  1282. | expr_no_commas OROR expr_no_commas
  1283. { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
  1284. | expr_no_commas '?' xexpr ':' expr_no_commas
  1285. { $$ = build_x_conditional_expr ($$, $3, $5); }
  1286. | expr_no_commas '=' expr_no_commas
  1287. { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
  1288. if ($$ != error_mark_node)
  1289. C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
  1290. | expr_no_commas ASSIGN expr_no_commas
  1291. { $$ = build_x_modify_expr ($$, $2, $3); }
  1292. | THROW
  1293. { $$ = build_throw (NULL_TREE); }
  1294. | THROW expr_no_commas
  1295. { $$ = build_throw ($2); }
  1296. ;
  1297. expr_no_comma_rangle:
  1298. cast_expr
  1299. /* Handle general members. */
  1300. | expr_no_comma_rangle POINTSAT_STAR expr_no_comma_rangle
  1301. { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
  1302. | expr_no_comma_rangle DOT_STAR expr_no_comma_rangle
  1303. { $$ = build_m_component_ref ($$, $3); }
  1304. | expr_no_comma_rangle '+' expr_no_comma_rangle
  1305. { $$ = build_x_binary_op ($2, $$, $3); }
  1306. | expr_no_comma_rangle '-' expr_no_comma_rangle
  1307. { $$ = build_x_binary_op ($2, $$, $3); }
  1308. | expr_no_comma_rangle '*' expr_no_comma_rangle
  1309. { $$ = build_x_binary_op ($2, $$, $3); }
  1310. | expr_no_comma_rangle '/' expr_no_comma_rangle
  1311. { $$ = build_x_binary_op ($2, $$, $3); }
  1312. | expr_no_comma_rangle '%' expr_no_comma_rangle
  1313. { $$ = build_x_binary_op ($2, $$, $3); }
  1314. | expr_no_comma_rangle LSHIFT expr_no_comma_rangle
  1315. { $$ = build_x_binary_op ($2, $$, $3); }
  1316. | expr_no_comma_rangle RSHIFT expr_no_comma_rangle
  1317. { $$ = build_x_binary_op ($2, $$, $3); }
  1318. | expr_no_comma_rangle ARITHCOMPARE expr_no_comma_rangle
  1319. { $$ = build_x_binary_op ($2, $$, $3); }
  1320. | expr_no_comma_rangle '<' expr_no_comma_rangle
  1321. { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
  1322. | expr_no_comma_rangle EQCOMPARE expr_no_comma_rangle
  1323. { $$ = build_x_binary_op ($2, $$, $3); }
  1324. | expr_no_comma_rangle MIN_MAX expr_no_comma_rangle
  1325. { $$ = build_x_binary_op ($2, $$, $3); }
  1326. | expr_no_comma_rangle '&' expr_no_comma_rangle
  1327. { $$ = build_x_binary_op ($2, $$, $3); }
  1328. | expr_no_comma_rangle '|' expr_no_comma_rangle
  1329. { $$ = build_x_binary_op ($2, $$, $3); }
  1330. | expr_no_comma_rangle '^' expr_no_comma_rangle
  1331. { $$ = build_x_binary_op ($2, $$, $3); }
  1332. | expr_no_comma_rangle ANDAND expr_no_comma_rangle
  1333. { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
  1334. | expr_no_comma_rangle OROR expr_no_comma_rangle
  1335. { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
  1336. | expr_no_comma_rangle '?' xexpr ':' expr_no_comma_rangle
  1337. { $$ = build_x_conditional_expr ($$, $3, $5); }
  1338. | expr_no_comma_rangle '=' expr_no_comma_rangle
  1339. { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
  1340. if ($$ != error_mark_node)
  1341. C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
  1342. | expr_no_comma_rangle ASSIGN expr_no_comma_rangle
  1343. { $$ = build_x_modify_expr ($$, $2, $3); }
  1344. | THROW
  1345. { $$ = build_throw (NULL_TREE); }
  1346. | THROW expr_no_comma_rangle
  1347. { $$ = build_throw ($2); }
  1348. ;
  1349. notype_unqualified_id:
  1350. '~' see_typename identifier
  1351. { $$ = build_nt (BIT_NOT_EXPR, $3); }
  1352. | '~' see_typename template_type
  1353. { $$ = build_nt (BIT_NOT_EXPR, $3); }
  1354. | template_id
  1355. | operator_name
  1356. | IDENTIFIER
  1357. | PTYPENAME
  1358. | NSNAME %prec EMPTY
  1359. ;
  1360. do_id:
  1361. {
  1362. /* If lastiddecl is a BASELINK we're in an
  1363. expression like S::f<int>, so don't
  1364. do_identifier; we only do that for unqualified
  1365. identifiers. */
  1366. if (!lastiddecl || !BASELINK_P (lastiddecl))
  1367. $$ = do_identifier ($<ttype>-1, 3, NULL_TREE);
  1368. else
  1369. $$ = $<ttype>-1;
  1370. }
  1371. ;
  1372. template_id:
  1373. PFUNCNAME '<' do_id template_arg_list_opt template_close_bracket
  1374. {
  1375. tree template_name = $3;
  1376. if (TREE_CODE (template_name) == COMPONENT_REF)
  1377. template_name = TREE_OPERAND (template_name, 1);
  1378. $$ = lookup_template_function (template_name, $4);
  1379. }
  1380. | operator_name '<' do_id template_arg_list_opt template_close_bracket
  1381. {
  1382. tree template_name = $3;
  1383. if (TREE_CODE (template_name) == COMPONENT_REF)
  1384. template_name = TREE_OPERAND (template_name, 1);
  1385. $$ = lookup_template_function (template_name, $4);
  1386. }
  1387. ;
  1388. object_template_id:
  1389. TEMPLATE identifier '<' template_arg_list_opt template_close_bracket
  1390. { $$ = lookup_template_function ($2, $4); }
  1391. | TEMPLATE PFUNCNAME '<' template_arg_list_opt template_close_bracket
  1392. { $$ = lookup_template_function ($2, $4); }
  1393. | TEMPLATE operator_name '<' template_arg_list_opt
  1394. template_close_bracket
  1395. { $$ = lookup_template_function ($2, $4); }
  1396. ;
  1397. unqualified_id:
  1398. notype_unqualified_id
  1399. | tTYPENAME
  1400. | SELFNAME
  1401. ;
  1402. expr_or_declarator_intern:
  1403. expr_or_declarator
  1404. | attributes expr_or_declarator
  1405. {
  1406. /* Provide support for '(' attributes '*' declarator ')'
  1407. etc */
  1408. $$ = tree_cons ($1, $2, NULL_TREE);
  1409. }
  1410. ;
  1411. expr_or_declarator:
  1412. notype_unqualified_id
  1413. | '*' expr_or_declarator_intern %prec UNARY
  1414. { $$ = build_nt (INDIRECT_REF, $2); }
  1415. | '&' expr_or_declarator_intern %prec UNARY
  1416. { $$ = build_nt (ADDR_EXPR, $2); }
  1417. | '(' expr_or_declarator_intern ')'
  1418. { $$ = $2; }
  1419. ;
  1420. notype_template_declarator:
  1421. IDENTIFIER '<' template_arg_list_opt template_close_bracket
  1422. { $$ = lookup_template_function ($1, $3); }
  1423. | NSNAME '<' template_arg_list template_close_bracket
  1424. { $$ = lookup_template_function ($1, $3); }
  1425. ;
  1426. direct_notype_declarator:
  1427. complex_direct_notype_declarator
  1428. /* This precedence declaration is to prefer this reduce
  1429. to the Koenig lookup shift in primary, below. I hate yacc. */
  1430. | notype_unqualified_id %prec '('
  1431. | notype_template_declarator
  1432. | '(' expr_or_declarator_intern ')'
  1433. { $$ = finish_decl_parsing ($2); }
  1434. ;
  1435. primary:
  1436. notype_unqualified_id
  1437. {
  1438. if (TREE_CODE ($1) == BIT_NOT_EXPR)
  1439. $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($1, 0));
  1440. else
  1441. $$ = finish_id_expr ($1);
  1442. }
  1443. | CONSTANT
  1444. | boolean_literal
  1445. | STRING
  1446. {
  1447. $$ = fix_string_type ($$);
  1448. /* fix_string_type doesn't set up TYPE_MAIN_VARIANT of
  1449. a const array the way we want, so fix it. */
  1450. if (flag_const_strings)
  1451. TREE_TYPE ($$) = build_cplus_array_type
  1452. (TREE_TYPE (TREE_TYPE ($$)),
  1453. TYPE_DOMAIN (TREE_TYPE ($$)));
  1454. }
  1455. | VAR_FUNC_NAME
  1456. { $$ = finish_fname ($1); }
  1457. | '(' expr ')'
  1458. { $$ = finish_parenthesized_expr ($2); }
  1459. | '(' expr_or_declarator_intern ')'
  1460. { $2 = reparse_decl_as_expr (NULL_TREE, $2);
  1461. $$ = finish_parenthesized_expr ($2); }
  1462. | '(' error ')'
  1463. { $$ = error_mark_node; }
  1464. | '('
  1465. { if (!at_function_scope_p ())
  1466. {
  1467. error ("braced-group within expression allowed only inside a function");
  1468. YYERROR;
  1469. }
  1470. if (pedantic)
  1471. pedwarn ("ISO C++ forbids braced-groups within expressions");
  1472. $<ttype>$ = begin_stmt_expr ();
  1473. }
  1474. compstmt_or_stmtexpr ')'
  1475. { $$ = finish_stmt_expr ($<ttype>2); }
  1476. /* Koenig lookup support
  1477. We could store lastiddecl in $1 to avoid another lookup,
  1478. but that would result in many additional reduce/reduce conflicts. */
  1479. | notype_unqualified_id '(' nonnull_exprlist ')'
  1480. { $$ = parse_finish_call_expr ($1, $3, 1); }
  1481. | notype_unqualified_id LEFT_RIGHT
  1482. { $$ = parse_finish_call_expr ($1, NULL_TREE, 1); }
  1483. | primary '(' nonnull_exprlist ')'
  1484. { $$ = parse_finish_call_expr ($1, $3, 0); }
  1485. | primary LEFT_RIGHT
  1486. { $$ = parse_finish_call_expr ($1, NULL_TREE, 0); }
  1487. | VA_ARG '(' expr_no_commas ',' type_id ')'
  1488. { $$ = build_x_va_arg ($3, groktypename ($5.t));
  1489. check_for_new_type ("__builtin_va_arg", $5); }
  1490. | primary '[' expr ']'
  1491. { $$ = grok

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