PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/osprey/kgccfe/gnu/cp/parse.y

https://bitbucket.org/osunix/open64
Happy | 4237 lines | 3855 code | 382 blank | 0 comment | 0 complexity | 8e59930d517f99696d21637ecc240a54 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0, GPL-3.0

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

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