PageRenderTime 86ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/osprey/kg++fe/gnu/parse.y

https://bitbucket.org/osunix/open64
Happy | 4998 lines | 4537 code | 461 blank | 0 comment | 0 complexity | 0526240d65a09eb832332774a4ed6222 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0, GPL-3.0
  1. /*
  2. Copyright 2003, 2004, 2005, 2006 PathScale, Inc. All Rights Reserved.
  3. File modified February 23, 2005 by PathScale, Inc. to add OpenMP support.
  4. */
  5. /* YACC parser for C++ syntax.
  6. Copyright (C) 1988, 1989, 1993, 1994, 1995, 1996, 1997, 1998,
  7. 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
  8. Hacked by Michael Tiemann (tiemann@cygnus.com)
  9. This file is part of GNU CC.
  10. GNU CC is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. GNU CC is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING. If not, write to
  20. the Free Software Foundation, 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA. */
  22. /* This grammar is based on the GNU CC grammar. */
  23. /* Note: Bison automatically applies a default action of "$$ = $1" for
  24. all derivations; this is applied before the explicit action, if one
  25. is given. Keep this in mind when reading the actions. */
  26. %{
  27. #include "config.h"
  28. #include "system.h"
  29. #include "tree.h"
  30. #include "omp_types.h"
  31. #include "omp_directive.h"
  32. #include "input.h"
  33. #include "flags.h"
  34. #include "cp-tree.h"
  35. #include "decl.h"
  36. #include "lex.h"
  37. #include "c-pragma.h" /* For YYDEBUG definition. */
  38. #include "output.h"
  39. #include "toplev.h"
  40. #include "ggc.h"
  41. /* Like YYERROR but do call yyerror. */
  42. #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
  43. /* Like the default stack expander, except (1) use realloc when possible,
  44. (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
  45. Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
  46. give malloced_yyvs its proper type. This is ok since all we need from
  47. it is to be able to free it. */
  48. static short *malloced_yyss;
  49. static void *malloced_yyvs;
  50. static int class_template_ok_as_expr;
  51. #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ) \
  52. do { \
  53. size_t newsize; \
  54. short *newss; \
  55. YYSTYPE *newvs; \
  56. newsize = *(YYSSZ) *= 2; \
  57. if (malloced_yyss) \
  58. { \
  59. newss = (short *) \
  60. really_call_realloc (*(SS), newsize * sizeof (short)); \
  61. newvs = (YYSTYPE *) \
  62. really_call_realloc (*(VS), newsize * sizeof (YYSTYPE)); \
  63. } \
  64. else \
  65. { \
  66. newss = (short *) really_call_malloc (newsize * sizeof (short)); \
  67. newvs = (YYSTYPE *) really_call_malloc (newsize * sizeof (YYSTYPE)); \
  68. if (newss) \
  69. memcpy (newss, *(SS), (SSSIZE)); \
  70. if (newvs) \
  71. memcpy (newvs, *(VS), (VSSIZE)); \
  72. } \
  73. if (!newss || !newvs) \
  74. { \
  75. yyerror (MSG); \
  76. return 2; \
  77. } \
  78. *(SS) = newss; \
  79. *(VS) = newvs; \
  80. malloced_yyss = newss; \
  81. malloced_yyvs = (void *) newvs; \
  82. } while (0)
  83. #define OP0(NODE) (TREE_OPERAND (NODE, 0))
  84. #define OP1(NODE) (TREE_OPERAND (NODE, 1))
  85. /* Contains the statement keyword (if/while/do) to include in an
  86. error message if the user supplies an empty conditional expression. */
  87. static const char *cond_stmt_keyword;
  88. /* List of types and structure classes of the current declaration. */
  89. static GTY(()) tree current_declspecs;
  90. /* List of prefix attributes in effect.
  91. Prefix attributes are parsed by the reserved_declspecs and declmods
  92. rules. They create a list that contains *both* declspecs and attrs. */
  93. /* ??? It is not clear yet that all cases where an attribute can now appear in
  94. a declspec list have been updated. */
  95. static GTY(()) tree prefix_attributes;
  96. /* When defining an enumeration, this is the type of the enumeration. */
  97. static GTY(()) tree current_enum_type;
  98. /* When parsing a conversion operator name, this is the scope of the
  99. operator itself. */
  100. static GTY(()) tree saved_scopes;
  101. static tree empty_parms PARAMS ((void));
  102. static tree parse_decl0 PARAMS ((tree, tree, tree, tree, int));
  103. static tree parse_decl PARAMS ((tree, tree, int));
  104. static void parse_end_decl PARAMS ((tree, tree, tree));
  105. static tree parse_field0 PARAMS ((tree, tree, tree, tree, tree, tree));
  106. static tree parse_field PARAMS ((tree, tree, tree, tree));
  107. static tree parse_bitfield0 PARAMS ((tree, tree, tree, tree, tree));
  108. static tree parse_bitfield PARAMS ((tree, tree, tree));
  109. static tree parse_method PARAMS ((tree, tree, tree));
  110. static void frob_specs PARAMS ((tree, tree));
  111. static void check_class_key PARAMS ((tree, tree));
  112. static tree parse_scoped_id PARAMS ((tree));
  113. static tree parse_xref_tag (tree, tree, int);
  114. static tree parse_handle_class_head (tree, tree, tree, int, int *);
  115. static void parse_decl_instantiation (tree, tree, tree);
  116. static int parse_begin_function_definition (tree, tree);
  117. static tree parse_finish_call_expr (tree, tree, int);
  118. bool In_MP_Region = false;
  119. static bool In_MP_Section = false;
  120. #define MAX_MP_NESTING 10
  121. static GTY(()) tree mp_locals[MAX_MP_NESTING];
  122. static int mp_nesting = -1;
  123. /* Cons up an empty parameter list. */
  124. static inline tree
  125. empty_parms ()
  126. {
  127. tree parms;
  128. #ifndef NO_IMPLICIT_EXTERN_C
  129. if (in_system_header && current_class_type == NULL
  130. && current_lang_name == lang_name_c)
  131. parms = NULL_TREE;
  132. else
  133. #endif
  134. parms = void_list_node;
  135. return parms;
  136. }
  137. /* Record the decl-specifiers, attributes and type lookups from the
  138. decl-specifier-seq in a declaration. */
  139. static void
  140. frob_specs (specs_attrs, lookups)
  141. tree specs_attrs, lookups;
  142. {
  143. save_type_access_control (lookups);
  144. split_specs_attrs (specs_attrs, &current_declspecs, &prefix_attributes);
  145. if (current_declspecs
  146. && TREE_CODE (current_declspecs) != TREE_LIST)
  147. current_declspecs = build_tree_list (NULL_TREE, current_declspecs);
  148. if (have_extern_spec)
  149. {
  150. /* We have to indicate that there is an "extern", but that it
  151. was part of a language specifier. For instance,
  152. extern "C" typedef int (*Ptr) ();
  153. is well formed. */
  154. current_declspecs = tree_cons (error_mark_node,
  155. get_identifier ("extern"),
  156. current_declspecs);
  157. have_extern_spec = false;
  158. }
  159. }
  160. static tree
  161. parse_decl (declarator, attributes, initialized)
  162. tree declarator, attributes;
  163. int initialized;
  164. {
  165. return start_decl (declarator, current_declspecs, initialized,
  166. attributes, prefix_attributes);
  167. }
  168. static tree
  169. parse_decl0 (declarator, specs_attrs, lookups, attributes, initialized)
  170. tree declarator, specs_attrs, lookups, attributes;
  171. int initialized;
  172. {
  173. frob_specs (specs_attrs, lookups);
  174. return parse_decl (declarator, attributes, initialized);
  175. }
  176. extern tree pop_mp_local_vars (void);
  177. /* decl must be non-NULL, return true if this variable should be treated
  178. * as an OpenMP private variable
  179. */
  180. static bool
  181. Is_shared_mp_var (tree decl)
  182. {
  183. return TREE_CODE (decl) == VAR_DECL && DECL_CONTEXT (decl) &&
  184. TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL &&
  185. TREE_CODE (DECL_CONTEXT (decl)) != RECORD_TYPE &&
  186. !DECL_EXTERNAL (decl) && !DECL_WEAK (decl) &&
  187. !TREE_STATIC (decl);
  188. }
  189. static void
  190. parse_end_decl (decl, init, asmspec)
  191. tree decl, init, asmspec;
  192. {
  193. /* If decl is NULL_TREE, then this was a variable declaration using
  194. () syntax for the initializer, so we handled it in grokdeclarator. */
  195. if (decl)
  196. decl_type_access_control (decl);
  197. cp_finish_decl (decl, init, asmspec, init ? LOOKUP_ONLYCONVERTING : 0);
  198. if (In_MP_Region && decl && Is_shared_mp_var (decl))
  199. mp_locals[mp_nesting] = chainon (mp_locals[mp_nesting],
  200. build_tree_list (NULL, decl));
  201. else if (In_MP_Region && !decl)
  202. {
  203. decl = pop_mp_local_vars ();
  204. /* This may introduce duplicate entries, some being introduced in the
  205. above if stmt also */
  206. while (decl)
  207. {
  208. if (Is_shared_mp_var (decl))
  209. mp_locals[mp_nesting] = chainon (mp_locals[mp_nesting],
  210. build_tree_list (NULL, decl));
  211. decl = pop_mp_local_vars ();
  212. }
  213. }
  214. }
  215. static tree
  216. parse_field (declarator, attributes, asmspec, init)
  217. tree declarator, attributes, asmspec, init;
  218. {
  219. tree d = grokfield (declarator, current_declspecs, init, asmspec,
  220. chainon (attributes, prefix_attributes));
  221. decl_type_access_control (d);
  222. return d;
  223. }
  224. static tree
  225. parse_field0 (declarator, specs_attrs, lookups, attributes, asmspec, init)
  226. tree declarator, specs_attrs, lookups, attributes, asmspec, init;
  227. {
  228. frob_specs (specs_attrs, lookups);
  229. return parse_field (declarator, attributes, asmspec, init);
  230. }
  231. static tree
  232. parse_bitfield (declarator, attributes, width)
  233. tree declarator, attributes, width;
  234. {
  235. tree d = grokbitfield (declarator, current_declspecs, width);
  236. cplus_decl_attributes (&d, chainon (attributes, prefix_attributes), 0);
  237. decl_type_access_control (d);
  238. return d;
  239. }
  240. static tree
  241. parse_bitfield0 (declarator, specs_attrs, lookups, attributes, width)
  242. tree declarator, specs_attrs, lookups, attributes, width;
  243. {
  244. frob_specs (specs_attrs, lookups);
  245. return parse_bitfield (declarator, attributes, width);
  246. }
  247. static tree
  248. parse_method (declarator, specs_attrs, lookups)
  249. tree declarator, specs_attrs, lookups;
  250. {
  251. tree d;
  252. frob_specs (specs_attrs, lookups);
  253. d = start_method (current_declspecs, declarator, prefix_attributes);
  254. decl_type_access_control (d);
  255. return d;
  256. }
  257. static void
  258. check_class_key (key, aggr)
  259. tree key;
  260. tree aggr;
  261. {
  262. if (TREE_CODE (key) == TREE_LIST)
  263. key = TREE_VALUE (key);
  264. if ((key == union_type_node) != (TREE_CODE (aggr) == UNION_TYPE))
  265. pedwarn ("`%s' tag used in naming `%#T'",
  266. key == union_type_node ? "union"
  267. : key == record_type_node ? "struct" : "class", aggr);
  268. }
  269. %}
  270. %start program
  271. %union { GTY(())
  272. long itype;
  273. tree ttype;
  274. char *strtype;
  275. enum tree_code code;
  276. flagged_type_tree ftype;
  277. struct unparsed_text *pi;
  278. enum reduction_op_type red_op_type;
  279. enum schedule_kind_type sch_k_type;
  280. struct parallel_clause_list * pclause_type;
  281. struct for_clause_list * for_clause_type;
  282. struct sections_clause_list * sections_clause_type;
  283. struct single_clause_list * single_clause_type;
  284. struct parallel_for_clause_list * parallel_for_clause_type;
  285. struct parallel_sections_clause_list * parallel_sections_clause_type;
  286. }
  287. /* All identifiers that are not reserved words
  288. and are not declared typedefs in the current block */
  289. %token IDENTIFIER
  290. /* All identifiers that are declared typedefs in the current block.
  291. In some contexts, they are treated just like IDENTIFIER,
  292. but they can also serve as typespecs in declarations. */
  293. %token tTYPENAME
  294. %token SELFNAME
  295. /* A template function. */
  296. %token PFUNCNAME
  297. /* Reserved words that specify storage class.
  298. yylval contains an IDENTIFIER_NODE which indicates which one. */
  299. %token SCSPEC
  300. /* Reserved words that specify type.
  301. yylval contains an IDENTIFIER_NODE which indicates which one. */
  302. %token TYPESPEC
  303. /* Reserved words that qualify type: "const" or "volatile".
  304. yylval contains an IDENTIFIER_NODE which indicates which one. */
  305. %token CV_QUALIFIER
  306. /* Character or numeric constants.
  307. yylval is the node for the constant. */
  308. %token CONSTANT
  309. /* __func__, __FUNCTION__ or __PRETTY_FUNCTION__.
  310. yylval contains an IDENTIFIER_NODE which indicates which one. */
  311. %token <ttype> VAR_FUNC_NAME
  312. /* String constants in raw form.
  313. yylval is a STRING_CST node. */
  314. %token STRING
  315. /* "...", used for functions with variable arglists. */
  316. %token ELLIPSIS
  317. %token OPTIONS_PRAGMA EXEC_FREQ_PRAGMA FREQ_NEVER FREQ_INIT FREQ_FREQUENT
  318. %token OMP_PRAGMA OMP_PARALLEL OMP_PRIVATE OMP_COPYPRIVATE
  319. %token OMP_FIRSTPRIVATE OMP_LASTPRIVATE OMP_SHARED OMP_DEFAULT OMP_NONE
  320. %token OMP_REDUCTION OMP_COPYIN OMP_DYNAMIC OMP_GUIDED OMP_RUNTIME
  321. %token OMP_ORDERED OMP_SCHEDULE OMP_NOWAIT OMP_NUM_THREADS OMP_SECTIONS
  322. %token OMP_SECTION OMP_SINGLE OMP_MASTER OMP_CRITICAL OMP_BARRIER
  323. %token OMP_ATOMIC OMP_FLUSH OMP_THREADPRIVATE
  324. %token <ttype> OMP_STATIC
  325. /* the reserved words */
  326. /* SCO include files test "ASM", so use something else. */
  327. %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  328. %token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF
  329. %token SIGOF
  330. %token ATTRIBUTE EXTENSION LABEL
  331. %token REALPART IMAGPART VA_ARG
  332. /* the reserved words... C++ extensions */
  333. %token <ttype> AGGR
  334. %token <ttype> VISSPEC
  335. %token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE OFFSETOF
  336. %token NAMESPACE TYPENAME_KEYWORD USING
  337. %token LEFT_RIGHT TEMPLATE
  338. %token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
  339. %token SCOPE EXPORT
  340. /* Define the operator tokens and their precedences.
  341. The value is an integer because, if used, it is the tree code
  342. to use in the expression made from the operator. */
  343. %left EMPTY /* used to resolve s/r with epsilon */
  344. %left error
  345. /* Add precedence rules to solve dangling else s/r conflict */
  346. %nonassoc IF
  347. %nonassoc ELSE
  348. %left IDENTIFIER PFUNCNAME tTYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD ATTRIBUTE
  349. %left '{' ',' ';'
  350. %nonassoc THROW
  351. %right <code> ':'
  352. %right <code> ASSIGN '='
  353. %right <code> '?'
  354. %left <code> OROR
  355. %left <code> ANDAND
  356. %left <code> '|'
  357. %left <code> '^'
  358. %left <code> '&'
  359. %left <code> MIN_MAX
  360. %left <code> EQCOMPARE
  361. %left <code> ARITHCOMPARE '<' '>'
  362. %left <code> LSHIFT RSHIFT
  363. %left <code> '+' '-'
  364. %left <code> '*' '/' '%'
  365. %left <code> POINTSAT_STAR DOT_STAR
  366. %right <code> UNARY PLUSPLUS MINUSMINUS '~'
  367. %left HYPERUNARY
  368. %left <ttype> LEFT_RIGHT
  369. %left <code> POINTSAT '.' '(' '['
  370. %right SCOPE /* C++ extension */
  371. %nonassoc NEW DELETE TRY CATCH
  372. %type <code> unop
  373. %type <ttype> identifier IDENTIFIER tTYPENAME CONSTANT expr nonnull_exprlist
  374. %type <ttype> PFUNCNAME maybe_identifier
  375. %type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
  376. %type <ttype> expr_no_commas expr_no_comma_rangle
  377. %type <ttype> cast_expr unary_expr primary STRING
  378. %type <ttype> reserved_declspecs boolean_literal
  379. %type <ttype> reserved_typespecquals
  380. %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
  381. %type <ttype> init initlist maybeasm maybe_init defarg defarg1
  382. %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
  383. %type <ttype> maybe_attribute attributes attribute attribute_list attrib
  384. %type <ttype> any_word unoperator
  385. %type <itype> save_lineno
  386. %type <ttype> simple_stmt simple_if
  387. %type <ttype> declarator notype_declarator after_type_declarator
  388. %type <ttype> notype_declarator_intern absdcl_intern
  389. %type <ttype> after_type_declarator_intern
  390. %type <ttype> direct_notype_declarator direct_after_type_declarator
  391. %type <itype> components notype_components
  392. %type <ttype> component_decl component_decl_1
  393. %type <ttype> component_declarator component_declarator0
  394. %type <ttype> notype_component_declarator notype_component_declarator0
  395. %type <ttype> after_type_component_declarator after_type_component_declarator0
  396. %type <ttype> absdcl cv_qualifiers
  397. %type <ttype> direct_abstract_declarator conversion_declarator
  398. %type <ttype> new_declarator direct_new_declarator
  399. %type <ttype> xexpr parmlist parms bad_parm
  400. %type <ttype> identifiers_or_typenames
  401. %type <ttype> fcast_or_absdcl regcast_or_absdcl
  402. %type <ttype> expr_or_declarator expr_or_declarator_intern
  403. %type <ttype> complex_notype_declarator
  404. %type <ttype> notype_unqualified_id unqualified_id qualified_id
  405. %type <ttype> template_id do_id object_template_id notype_template_declarator
  406. %type <ttype> overqualified_id notype_qualified_id any_id
  407. %type <ttype> complex_direct_notype_declarator functional_cast
  408. %type <ttype> complex_parmlist parms_comma
  409. %type <ttype> namespace_qualifier namespace_using_decl
  410. %type <ftype> type_id new_type_id typed_typespecs typespec typed_declspecs
  411. %type <ftype> typed_declspecs1 type_specifier_seq nonempty_cv_qualifiers
  412. %type <ftype> structsp typespecqual_reserved parm named_parm full_parm
  413. %type <ftype> declmods
  414. %type <itype> extension
  415. /* C++ extensions */
  416. %token <ttype> PTYPENAME
  417. %token <ttype> EXTERN_LANG_STRING ALL
  418. %token <ttype> PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER
  419. %token <pi> PRE_PARSED_FUNCTION_DECL
  420. %type <ttype> component_constructor_declarator
  421. %type <ttype> fn_def2 return_id constructor_declarator
  422. %type <ttype> begin_function_body_
  423. %type <ttype> class_head class_head_apparent_template
  424. %type <ftype> class_head_decl class_head_defn
  425. %type <ttype> base_class_list
  426. %type <ttype> base_class_access_list
  427. %type <ttype> base_class maybe_base_class_list base_class_1
  428. %type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers
  429. %type <ttype> operator_name
  430. %type <ttype> object aggr
  431. %type <itype> new delete
  432. /* %type <ttype> primary_no_id */
  433. %type <ttype> maybe_parmlist
  434. %type <ttype> begin_member_init member_init
  435. %type <ftype> member_init_list
  436. %type <ttype> template_parm_header template_spec_header template_header
  437. %type <ttype> template_parm_list template_parm
  438. %type <ttype> template_type_parm template_template_parm
  439. %type <code> template_close_bracket
  440. %type <ttype> apparent_template_type
  441. %type <ttype> template_type template_arg_list template_arg_list_opt
  442. %type <ttype> template_arg template_arg_1
  443. %type <ttype> condition xcond paren_cond_or_null
  444. %type <ttype> type_name nested_name_specifier nested_type ptr_to_mem
  445. %type <ttype> complete_type_name notype_identifier nonnested_type
  446. %type <ttype> complex_type_name nested_name_specifier_1
  447. %type <ttype> new_initializer new_placement
  448. %type <ttype> using_decl
  449. %type <ttype> typename_sub typename_sub0 typename_sub1 typename_sub2
  450. %type <ttype> explicit_template_type
  451. /* in order to recognize aggr tags as defining and thus shadowing. */
  452. %token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
  453. %type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN
  454. %type <ttype> handler_args
  455. %type <ttype> self_template_type finish_template_type_
  456. %token NSNAME
  457. %type <ttype> NSNAME
  458. %type <ttype> options_directive exec_freq_directive exec_freq_directive_ignore
  459. %type <ttype> freq_hint
  460. /* OpenMP */
  461. %type <ttype> variable_list critical_directive region_phrase iteration_statement
  462. %type <red_op_type> reduction_operator
  463. %type <sch_k_type> schedule_kind
  464. %type <pclause_type> parallel_clause_list parallel_clause parallel_directive
  465. %type <ttype> openmp_construct parallel_construct for_construct sections_construct
  466. %type <ttype> single_construct parallel_for_construct parallel_sections_construct
  467. %type <ttype> master_construct critical_construct atomic_construct
  468. %type <ttype> ordered_construct
  469. %type <ttype> flush_directive
  470. %type <for_clause_type> for_clause_list for_clause for_directive
  471. %type <sections_clause_type> sections_clause_list sections_clause sections_directive
  472. %type <single_clause_type> single_clause single_clause_list single_directive
  473. %type <parallel_for_clause_type> parallel_for_clause parallel_for_clause_list parallel_for_directive
  474. %type <parallel_sections_clause_type> parallel_sections_clause parallel_sections_clause_list parallel_sections_directive
  475. /* SL2 FORK JOINT PRAGMA */
  476. %token SL2_SECTIONS SL2_MINOR_SECTIONS SL2_SECTION PRAGMA_SL2 SL2_MINOR_SECTION
  477. %type <ttype> sl2_sections_construct sl2_section_scope sl2_maybe_section_sequence
  478. %type <ttype> sl2_section_sequence sl2_maybe_structured_block sl2_section_construct
  479. /* Used in lex.c for parsing pragmas. */
  480. %token END_OF_LINE
  481. /* lex.c and pt.c depend on this being the last token. Define
  482. any new tokens before this one! */
  483. %token END_OF_SAVED_INPUT
  484. %{
  485. /* Tell yyparse how to print a token's value, if yydebug is set. */
  486. #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  487. extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
  488. %}
  489. %%
  490. program:
  491. /* empty */
  492. { finish_translation_unit (); }
  493. | extdefs
  494. { finish_translation_unit (); }
  495. ;
  496. /* the reason for the strange actions in this rule
  497. is so that notype_initdecls when reached via datadef
  498. can find a valid list of type and sc specs in $0. */
  499. extdefs:
  500. { $<ttype>$ = NULL_TREE; }
  501. lang_extdef
  502. { $<ttype>$ = NULL_TREE; ggc_collect (); }
  503. | extdefs lang_extdef
  504. { $<ttype>$ = NULL_TREE; ggc_collect (); }
  505. ;
  506. extdefs_opt:
  507. extdefs
  508. | /* empty */
  509. ;
  510. .hush_warning:
  511. { have_extern_spec = true;
  512. $<ttype>$ = NULL_TREE; }
  513. ;
  514. .warning_ok:
  515. { have_extern_spec = false; }
  516. ;
  517. extension:
  518. EXTENSION
  519. { $$ = pedantic;
  520. pedantic = 0; }
  521. ;
  522. asm_keyword:
  523. ASM_KEYWORD
  524. ;
  525. lang_extdef:
  526. { if (pending_lang_change) do_pending_lang_change();
  527. type_lookups = NULL_TREE; }
  528. extdef
  529. { if (! toplevel_bindings_p ())
  530. pop_everything (); }
  531. ;
  532. extdef:
  533. fndef eat_saved_input
  534. { do_pending_inlines (); }
  535. | datadef
  536. { do_pending_inlines (); }
  537. | EXPORT
  538. { warning ("keyword `export' not implemented, and will be ignored"); }
  539. template_def
  540. { do_pending_inlines (); }
  541. | template_def
  542. { do_pending_inlines (); }
  543. | asm_keyword '(' STRING ')' ';'
  544. { assemble_asm ($3); }
  545. | extern_lang_string '{' extdefs_opt '}'
  546. { pop_lang_context (); }
  547. | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
  548. { do_pending_inlines (); pop_lang_context (); }
  549. | extern_lang_string .hush_warning datadef .warning_ok
  550. { do_pending_inlines (); pop_lang_context (); }
  551. | NAMESPACE identifier '{'
  552. { push_namespace ($2); }
  553. extdefs_opt '}'
  554. { pop_namespace (); }
  555. | NAMESPACE '{'
  556. { push_namespace (NULL_TREE); }
  557. extdefs_opt '}'
  558. { pop_namespace (); }
  559. | namespace_alias
  560. | using_decl ';'
  561. { do_toplevel_using_decl ($1); }
  562. | using_directive
  563. | extension extdef
  564. { pedantic = $1; }
  565. | threadprivate_directive
  566. | exec_freq_directive_ignore
  567. {}
  568. ;
  569. namespace_alias:
  570. NAMESPACE identifier '='
  571. { begin_only_namespace_names (); }
  572. any_id ';'
  573. {
  574. end_only_namespace_names ();
  575. if (lastiddecl)
  576. $5 = lastiddecl;
  577. do_namespace_alias ($2, $5);
  578. }
  579. ;
  580. using_decl:
  581. USING qualified_id
  582. { $$ = $2; }
  583. | USING global_scope qualified_id
  584. { $$ = $3; }
  585. | USING global_scope unqualified_id
  586. { $$ = $3; }
  587. ;
  588. namespace_using_decl:
  589. USING namespace_qualifier identifier
  590. { $$ = build_nt (SCOPE_REF, $2, $3); }
  591. | USING global_scope identifier
  592. { $$ = build_nt (SCOPE_REF, global_namespace, $3); }
  593. | USING global_scope namespace_qualifier identifier
  594. { $$ = build_nt (SCOPE_REF, $3, $4); }
  595. ;
  596. using_directive:
  597. USING NAMESPACE
  598. { begin_only_namespace_names (); }
  599. any_id
  600. {
  601. end_only_namespace_names ();
  602. /* If no declaration was found, the using-directive is
  603. invalid. Since that was not reported, we need the
  604. identifier for the error message. */
  605. if (TREE_CODE ($4) == IDENTIFIER_NODE && lastiddecl)
  606. $4 = lastiddecl;
  607. do_using_directive ($4);
  608. }
  609. maybe_attribute ';' /* GNU 3.4 feature of namespace attributes */
  610. ;
  611. namespace_qualifier:
  612. NSNAME SCOPE
  613. {
  614. if (TREE_CODE ($$) == IDENTIFIER_NODE)
  615. $$ = lastiddecl;
  616. got_scope = $$;
  617. }
  618. | namespace_qualifier NSNAME SCOPE
  619. {
  620. $$ = $2;
  621. if (TREE_CODE ($$) == IDENTIFIER_NODE)
  622. $$ = lastiddecl;
  623. got_scope = $$;
  624. }
  625. ;
  626. any_id:
  627. unqualified_id
  628. | qualified_id
  629. | global_scope qualified_id
  630. { $$ = $2; }
  631. | global_scope unqualified_id
  632. { $$ = $2; }
  633. ;
  634. extern_lang_string:
  635. EXTERN_LANG_STRING
  636. { push_lang_context ($1); }
  637. | extern_lang_string EXTERN_LANG_STRING
  638. { if (current_lang_name != $2)
  639. error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name);
  640. pop_lang_context (); push_lang_context ($2); }
  641. ;
  642. template_parm_header:
  643. TEMPLATE '<'
  644. { begin_template_parm_list (); }
  645. template_parm_list '>'
  646. { $$ = end_template_parm_list ($4); }
  647. ;
  648. template_spec_header:
  649. TEMPLATE '<' '>'
  650. { begin_specialization();
  651. $$ = NULL_TREE; }
  652. ;
  653. template_header:
  654. template_parm_header
  655. | template_spec_header
  656. ;
  657. template_parm_list:
  658. template_parm
  659. { $$ = process_template_parm (NULL_TREE, $1); }
  660. | template_parm_list ',' template_parm
  661. { $$ = process_template_parm ($1, $3); }
  662. ;
  663. maybe_identifier:
  664. identifier
  665. { $$ = $1; }
  666. | /* empty */
  667. { $$ = NULL_TREE; }
  668. ;
  669. template_type_parm:
  670. aggr maybe_identifier
  671. { $$ = finish_template_type_parm ($1, $2); }
  672. | TYPENAME_KEYWORD maybe_identifier
  673. { $$ = finish_template_type_parm (class_type_node, $2); }
  674. ;
  675. template_template_parm:
  676. template_parm_header aggr maybe_identifier
  677. { $$ = finish_template_template_parm ($2, $3); }
  678. ;
  679. template_parm:
  680. /* The following rules introduce a new reduce/reduce
  681. conflict on the ',' and '>' input tokens: they are valid
  682. prefixes for a `structsp', which means they could match a
  683. nameless parameter. See 14.6, paragraph 3.
  684. By putting them before the `parm' rule, we get
  685. their match before considering them nameless parameter
  686. declarations. */
  687. template_type_parm
  688. { $$ = build_tree_list (NULL_TREE, $1); }
  689. | template_type_parm '=' type_id
  690. { $$ = build_tree_list (groktypename ($3.t), $1); }
  691. | parm
  692. { $$ = build_tree_list (NULL_TREE, $1.t); }
  693. | parm '=' expr_no_comma_rangle
  694. { $$ = build_tree_list ($3, $1.t); }
  695. | template_template_parm
  696. { $$ = build_tree_list (NULL_TREE, $1); }
  697. | template_template_parm '=' template_arg
  698. {
  699. $3 = check_template_template_default_arg ($3);
  700. $$ = build_tree_list ($3, $1);
  701. }
  702. ;
  703. template_def:
  704. template_header template_extdef
  705. { finish_template_decl ($1); }
  706. | template_header error %prec EMPTY
  707. { finish_template_decl ($1); }
  708. ;
  709. template_extdef:
  710. fndef eat_saved_input
  711. { do_pending_inlines (); }
  712. | template_datadef
  713. { do_pending_inlines (); }
  714. | template_def
  715. { do_pending_inlines (); }
  716. | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
  717. { do_pending_inlines ();
  718. pop_lang_context (); }
  719. | extern_lang_string .hush_warning template_datadef .warning_ok
  720. { do_pending_inlines ();
  721. pop_lang_context (); }
  722. | extension template_extdef
  723. { pedantic = $1; }
  724. ;
  725. template_datadef:
  726. nomods_initdecls ';'
  727. | declmods notype_initdecls ';'
  728. {}
  729. | typed_declspecs initdecls ';'
  730. { note_list_got_semicolon ($1.t); }
  731. | structsp ';'
  732. {
  733. if ($1.t != error_mark_node)
  734. {
  735. maybe_process_partial_specialization ($1.t);
  736. note_got_semicolon ($1.t);
  737. }
  738. }
  739. ;
  740. datadef:
  741. nomods_initdecls ';'
  742. | declmods notype_initdecls ';'
  743. {}
  744. | typed_declspecs initdecls ';'
  745. { note_list_got_semicolon ($1.t); }
  746. | declmods ';'
  747. { pedwarn ("empty declaration"); }
  748. | explicit_instantiation ';'
  749. | typed_declspecs ';'
  750. {
  751. tree t, attrs;
  752. split_specs_attrs ($1.t, &t, &attrs);
  753. shadow_tag (t);
  754. note_list_got_semicolon ($1.t);
  755. }
  756. | error ';'
  757. | error '}'
  758. | error END_OF_SAVED_INPUT
  759. { end_input (); }
  760. | ';'
  761. | bad_decl
  762. ;
  763. ctor_initializer_opt:
  764. nodecls
  765. | base_init
  766. ;
  767. maybe_return_init:
  768. /* empty */
  769. | return_init
  770. | return_init ';'
  771. ;
  772. eat_saved_input:
  773. /* empty */
  774. | END_OF_SAVED_INPUT
  775. ;
  776. /* The outermost block of a function really begins before the
  777. mem-initializer-list, so we open one there and suppress the one that
  778. actually corresponds to the curly braces. */
  779. function_body:
  780. begin_function_body_ ctor_initializer_opt save_lineno '{'
  781. { $<ttype>$ = begin_compound_stmt (/*has_no_scope=*/1); }
  782. compstmtend
  783. {
  784. STMT_LINENO ($<ttype>5) = $3;
  785. finish_compound_stmt (/*has_no_scope=*/1, $<ttype>5);
  786. finish_function_body ($1);
  787. }
  788. ;
  789. fndef:
  790. fn.def1 maybe_return_init function_body
  791. { expand_body (finish_function (0)); }
  792. | fn.def1 maybe_return_init function_try_block
  793. { expand_body (finish_function (0)); }
  794. | fn.def1 maybe_return_init error
  795. { }
  796. ;
  797. constructor_declarator:
  798. nested_name_specifier SELFNAME '('
  799. { $<ttype>$ = begin_constructor_declarator ($1, $2); }
  800. parmlist ')' cv_qualifiers exception_specification_opt
  801. { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
  802. | nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
  803. { $$ = begin_constructor_declarator ($1, $2);
  804. $$ = make_call_declarator ($$, empty_parms (), $4, $5);
  805. }
  806. | global_scope nested_name_specifier SELFNAME '('
  807. { $<ttype>$ = begin_constructor_declarator ($2, $3); }
  808. parmlist ')' cv_qualifiers exception_specification_opt
  809. { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
  810. | global_scope nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
  811. { $$ = begin_constructor_declarator ($2, $3);
  812. $$ = make_call_declarator ($$, empty_parms (), $5, $6);
  813. }
  814. | nested_name_specifier self_template_type '('
  815. { $<ttype>$ = begin_constructor_declarator ($1, $2); }
  816. parmlist ')' cv_qualifiers exception_specification_opt
  817. { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
  818. | nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
  819. { $$ = begin_constructor_declarator ($1, $2);
  820. $$ = make_call_declarator ($$, empty_parms (), $4, $5);
  821. }
  822. | global_scope nested_name_specifier self_template_type '('
  823. { $<ttype>$ = begin_constructor_declarator ($2, $3); }
  824. parmlist ')' cv_qualifiers exception_specification_opt
  825. { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
  826. | global_scope nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
  827. { $$ = begin_constructor_declarator ($2, $3);
  828. $$ = make_call_declarator ($$, empty_parms (), $5, $6);
  829. }
  830. ;
  831. fn.def1:
  832. typed_declspecs declarator
  833. { check_for_new_type ("return type", $1);
  834. if (!parse_begin_function_definition ($1.t, $2))
  835. YYERROR1; }
  836. | declmods notype_declarator
  837. { if (!parse_begin_function_definition ($1.t, $2))
  838. YYERROR1; }
  839. | notype_declarator
  840. { if (!parse_begin_function_definition (NULL_TREE, $1))
  841. YYERROR1; }
  842. | declmods constructor_declarator
  843. { if (!parse_begin_function_definition ($1.t, $2))
  844. YYERROR1; }
  845. | constructor_declarator
  846. { if (!parse_begin_function_definition (NULL_TREE, $1))
  847. YYERROR1; }
  848. ;
  849. /* ANSI allows optional parentheses around constructor class names.
  850. See ISO/IEC 14882:1998(E) 12.1. */
  851. component_constructor_declarator:
  852. SELFNAME '(' parmlist ')' cv_qualifiers exception_specification_opt
  853. { $$ = make_call_declarator ($1, $3, $5, $6); }
  854. | '(' SELFNAME ')' '(' parmlist ')' cv_qualifiers
  855. exception_specification_opt
  856. { $$ = make_call_declarator ($2, $5, $7, $8); }
  857. | SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
  858. { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
  859. | '(' SELFNAME ')' LEFT_RIGHT cv_qualifiers exception_specification_opt
  860. { $$ = make_call_declarator ($2, empty_parms (), $5, $6); }
  861. | self_template_type '(' parmlist ')' cv_qualifiers exception_specification_opt
  862. { $$ = make_call_declarator ($1, $3, $5, $6); }
  863. | self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
  864. { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
  865. ;
  866. /* more C++ complexity. See component_decl for a comment on the
  867. reduce/reduce conflict introduced by these rules. */
  868. fn_def2:
  869. declmods component_constructor_declarator
  870. { $$ = parse_method ($2, $1.t, $1.lookups);
  871. rest_of_mdef:
  872. if (! $$)
  873. YYERROR1;
  874. if (yychar == YYEMPTY)
  875. yychar = YYLEX;
  876. snarf_method ($$); }
  877. | component_constructor_declarator
  878. { $$ = parse_method ($1, NULL_TREE, NULL_TREE);
  879. goto rest_of_mdef; }
  880. | typed_declspecs declarator
  881. { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
  882. | declmods notype_declarator
  883. { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
  884. | notype_declarator
  885. { $$ = parse_method ($1, NULL_TREE, NULL_TREE);
  886. goto rest_of_mdef; }
  887. | declmods constructor_declarator
  888. { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
  889. | constructor_declarator
  890. { $$ = parse_method ($1, NULL_TREE, NULL_TREE);
  891. goto rest_of_mdef; }
  892. ;
  893. return_id:
  894. RETURN_KEYWORD IDENTIFIER
  895. {
  896. $$ = $2;
  897. }
  898. ;
  899. return_init:
  900. return_id maybe_init
  901. { finish_named_return_value ($<ttype>$, $2); }
  902. | return_id '(' nonnull_exprlist ')'
  903. { finish_named_return_value ($<ttype>$, $3); }
  904. | return_id LEFT_RIGHT
  905. { finish_named_return_value ($<ttype>$, NULL_TREE); }
  906. ;
  907. base_init:
  908. ':' { begin_mem_initializers (); } member_init_list
  909. {
  910. if ($3.new_type_flag == 0)
  911. error ("no base or member initializers given following ':'");
  912. finish_mem_initializers ($3.t);
  913. }
  914. ;
  915. begin_function_body_:
  916. /* empty */
  917. {
  918. $$ = begin_function_body ();
  919. }
  920. ;
  921. member_init_list:
  922. /* empty */
  923. {
  924. $$.new_type_flag = 0;
  925. $$.t = NULL_TREE;
  926. }
  927. | member_init
  928. {
  929. $$.new_type_flag = 1;
  930. $$.t = $1;
  931. }
  932. | member_init_list ',' member_init
  933. {
  934. if ($3)
  935. {
  936. $$.new_type_flag = 1;
  937. TREE_CHAIN ($3) = $1.t;
  938. $$.t = $3;
  939. }
  940. else
  941. $$ = $1;
  942. }
  943. | member_init_list error
  944. ;
  945. begin_member_init:
  946. /* empty */
  947. {
  948. if (current_class_name)
  949. pedwarn ("anachronistic old style base class initializer");
  950. $$ = expand_member_init (NULL_TREE);
  951. in_base_initializer = $$ && !DECL_P ($$);
  952. }
  953. | notype_identifier
  954. { $$ = expand_member_init ($1);
  955. in_base_initializer = $$ && !DECL_P ($$); }
  956. | nonnested_type
  957. { $$ = expand_member_init ($1);
  958. in_base_initializer = $$ && !DECL_P ($$); }
  959. | typename_sub
  960. { $$ = expand_member_init ($1);
  961. in_base_initializer = $$ && !DECL_P ($$); }
  962. ;
  963. member_init:
  964. begin_member_init '(' nonnull_exprlist ')'
  965. { in_base_initializer = 0;
  966. $$ = $1 ? build_tree_list ($1, $3) : NULL_TREE; }
  967. | begin_member_init LEFT_RIGHT
  968. { in_base_initializer = 0;
  969. $$ = $1 ? build_tree_list ($1, void_type_node) : NULL_TREE; }
  970. | error
  971. { in_base_initializer = 0;
  972. $$ = NULL_TREE; }
  973. ;
  974. identifier:
  975. IDENTIFIER
  976. | tTYPENAME
  977. | SELFNAME
  978. | PTYPENAME
  979. | NSNAME
  980. ;
  981. notype_identifier:
  982. IDENTIFIER
  983. | PTYPENAME
  984. | NSNAME %prec EMPTY
  985. ;
  986. identifier_defn:
  987. IDENTIFIER_DEFN
  988. | TYPENAME_DEFN
  989. | PTYPENAME_DEFN
  990. ;
  991. explicit_instantiation:
  992. TEMPLATE begin_explicit_instantiation typespec ';'
  993. { do_type_instantiation ($3.t, NULL_TREE, 1);
  994. yyungetc (';', 1); }
  995. end_explicit_instantiation
  996. | TEMPLATE begin_explicit_instantiation typed_declspecs declarator
  997. { tree specs = strip_attrs ($3.t);
  998. parse_decl_instantiation (specs, $4, NULL_TREE); }
  999. end_explicit_instantiation
  1000. | TEMPLATE begin_explicit_instantiation notype_declarator
  1001. { parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
  1002. end_explicit_instantiation
  1003. | TEMPLATE begin_explicit_instantiation constructor_declarator
  1004. { parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
  1005. end_explicit_instantiation
  1006. | SCSPEC TEMPLATE begin_explicit_instantiation typespec ';'
  1007. { do_type_instantiation ($4.t, $1, 1);
  1008. yyungetc (';', 1); }
  1009. end_explicit_instantiation
  1010. {}
  1011. | SCSPEC TEMPLATE begin_explicit_instantiation typed_declspecs
  1012. declarator
  1013. { tree specs = strip_attrs ($4.t);
  1014. parse_decl_instantiation (specs, $5, $1); }
  1015. end_explicit_instantiation
  1016. {}
  1017. | SCSPEC TEMPLATE begin_explicit_instantiation notype_declarator
  1018. { parse_decl_instantiation (NULL_TREE, $4, $1); }
  1019. end_explicit_instantiation
  1020. {}
  1021. | SCSPEC TEMPLATE begin_explicit_instantiation constructor_declarator
  1022. { parse_decl_instantiation (NULL_TREE, $4, $1); }
  1023. end_explicit_instantiation
  1024. {}
  1025. ;
  1026. begin_explicit_instantiation:
  1027. { begin_explicit_instantiation(); }
  1028. ;
  1029. end_explicit_instantiation:
  1030. { end_explicit_instantiation(); }
  1031. ;
  1032. /* The TYPENAME expansions are to deal with use of a template class name as
  1033. a template within the class itself, where the template decl is hidden by
  1034. a type decl. Got all that? */
  1035. template_type:
  1036. PTYPENAME '<' template_arg_list_opt template_close_bracket
  1037. finish_template_type_
  1038. { $$ = $5; }
  1039. | tTYPENAME '<' template_arg_list_opt template_close_bracket
  1040. finish_template_type_
  1041. { $$ = $5; }
  1042. | self_template_type
  1043. ;
  1044. apparent_template_type:
  1045. template_type
  1046. | identifier '<' template_arg_list_opt '>'
  1047. finish_template_type_
  1048. { $$ = $5; }
  1049. ;
  1050. self_template_type:
  1051. SELFNAME '<' template_arg_list_opt template_close_bracket
  1052. finish_template_type_
  1053. { $$ = $5; }
  1054. ;
  1055. finish_template_type_:
  1056. {
  1057. if (yychar == YYEMPTY)
  1058. yychar = YYLEX;
  1059. $$ = finish_template_type ($<ttype>-3, $<ttype>-1,
  1060. yychar == SCOPE);
  1061. }
  1062. ;
  1063. template_close_bracket:
  1064. '>'
  1065. | RSHIFT
  1066. {
  1067. /* Handle `Class<Class<Type>>' without space in the `>>' */
  1068. pedwarn ("`>>' should be `> >' in template class name");
  1069. yyungetc ('>', 1);
  1070. }
  1071. ;
  1072. template_arg_list_opt:
  1073. /* empty */
  1074. { $$ = NULL_TREE; }
  1075. | template_arg_list
  1076. ;
  1077. template_arg_list:
  1078. template_arg
  1079. { $$ = build_tree_list (NULL_TREE, $$); }
  1080. | template_arg_list ',' template_arg
  1081. { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); }
  1082. ;
  1083. template_arg:
  1084. { ++class_template_ok_as_expr; }
  1085. template_arg_1
  1086. {
  1087. --class_template_ok_as_expr;
  1088. $$ = $2;
  1089. }
  1090. ;
  1091. template_arg_1:
  1092. type_id
  1093. { $$ = groktypename ($1.t); }
  1094. | PTYPENAME
  1095. {
  1096. $$ = lastiddecl;
  1097. if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
  1098. $$ = TREE_TYPE ($$);
  1099. }
  1100. | global_scope PTYPENAME
  1101. {
  1102. $$ = lastiddecl;
  1103. if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
  1104. $$ = TREE_TYPE ($$);
  1105. }
  1106. | expr_no_comma_rangle
  1107. | nested_name_specifier TEMPLATE identifier
  1108. {
  1109. if (!processing_template_decl)
  1110. {
  1111. error ("use of template qualifier outside template");
  1112. $$ = error_mark_node;
  1113. }
  1114. else
  1115. $$ = make_unbound_class_template ($1, $3, tf_error | tf_parsing);
  1116. }
  1117. ;
  1118. unop:
  1119. '-'
  1120. { $$ = NEGATE_EXPR; }
  1121. | '+'
  1122. { $$ = CONVERT_EXPR; }
  1123. | PLUSPLUS
  1124. { $$ = PREINCREMENT_EXPR; }
  1125. | MINUSMINUS
  1126. { $$ = PREDECREMENT_EXPR; }
  1127. | '!'
  1128. { $$ = TRUTH_NOT_EXPR; }
  1129. ;
  1130. expr:
  1131. nontrivial_exprlist
  1132. { $$ = build_x_compound_expr ($$); }
  1133. | expr_no_commas
  1134. ;
  1135. paren_expr_or_null:
  1136. LEFT_RIGHT
  1137. { error ("ISO C++ forbids an empty condition for `%s'",
  1138. cond_stmt_keyword);
  1139. $$ = integer_zero_node; }
  1140. | '(' expr ')'
  1141. { $$ = $2; }
  1142. ;
  1143. paren_cond_or_null:
  1144. LEFT_RIGHT
  1145. { error ("ISO C++ forbids an empty condition for `%s'",
  1146. cond_stmt_keyword);
  1147. $$ = integer_zero_node; }
  1148. | '(' condition ')'
  1149. { $$ = $2; }
  1150. ;
  1151. xcond:
  1152. /* empty */
  1153. { $$ = NULL_TREE; }
  1154. | condition
  1155. | error
  1156. { $$ = NULL_TREE; }
  1157. ;
  1158. condition:
  1159. type_specifier_seq declarator maybeasm maybe_attribute '='
  1160. { {
  1161. tree d;
  1162. for (d = getdecls (); d; d = TREE_CHAIN (d))
  1163. if (TREE_CODE (d) == TYPE_DECL) {
  1164. tree s = TREE_TYPE (d);
  1165. if (TREE_CODE (s) == RECORD_TYPE)
  1166. error ("definition of class `%T' in condition", s);
  1167. else if (TREE_CODE (s) == ENUMERAL_TYPE)
  1168. error ("definition of enum `%T' in condition", s);
  1169. }
  1170. }
  1171. current_declspecs = $1.t;
  1172. $<ttype>$ = parse_decl ($<ttype>2, $4, 1);
  1173. }
  1174. init
  1175. {
  1176. parse_end_decl ($<ttype>6, $7, $4);
  1177. $$ = convert_from_reference ($<ttype>6);
  1178. if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE)
  1179. error ("definition of array `%#D' in condition", $$);
  1180. }
  1181. | expr
  1182. ;
  1183. compstmtend:
  1184. '}'
  1185. | maybe_label_decls stmts '}'
  1186. | maybe_label_decls stmts error '}'
  1187. | maybe_label_decls error '}'
  1188. ;
  1189. nontrivial_exprlist:
  1190. expr_no_commas ',' expr_no_commas
  1191. { $$ = tree_cons (NULL_TREE, $$,
  1192. build_tree_list (NULL_TREE, $3)); }
  1193. | expr_no_commas ',' error
  1194. { $$ = tree_cons (NULL_TREE, $$,
  1195. build_tree_list (NULL_TREE, error_mark_node)); }
  1196. | nontrivial_exprlist ',' expr_no_commas
  1197. { chainon ($$, build_tree_list (NULL_TREE, $3)); }
  1198. | nontrivial_exprlist ',' error
  1199. { chainon ($$, build_tree_list (NULL_TREE, error_mark_node)); }
  1200. ;
  1201. nonnull_exprlist:
  1202. expr_no_commas
  1203. { $$ = build_tree_list (NULL_TREE, $$); }
  1204. | nontrivial_exprlist
  1205. ;
  1206. unary_expr:
  1207. primary %prec UNARY
  1208. { $$ = $1; }
  1209. /* __extension__ turns off -pedantic for following primary. */
  1210. | extension cast_expr %prec UNARY
  1211. { $$ = $2;
  1212. pedantic = $1; }
  1213. | '*' cast_expr %prec UNARY
  1214. { $$ = build_x_indirect_ref ($2, "unary *"); }
  1215. | '&' cast_expr %prec UNARY
  1216. { $$ = build_x_unary_op (ADDR_EXPR, $2); }
  1217. | '~' cast_expr
  1218. { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
  1219. | unop cast_expr %prec UNARY
  1220. { $$ = finish_unary_op_expr ($1, $2); }
  1221. /* Refer to the address of a label as a pointer. */
  1222. | ANDAND identifier
  1223. { $$ = finish_label_address_expr ($2); }
  1224. | sizeof unary_expr %prec UNARY
  1225. { $$ = finish_sizeof ($2);
  1226. skip_evaluation--; }
  1227. | sizeof '(' type_id ')' %prec HYPERUNARY
  1228. { $$ = finish_sizeof (groktypename ($3.t));
  1229. check_for_new_type ("sizeof", $3);
  1230. skip_evaluation--; }
  1231. | alignof unary_expr %prec UNARY
  1232. { $$ = finish_alignof ($2);
  1233. skip_evaluation--; }
  1234. | alignof '(' type_id ')' %prec HYPERUNARY
  1235. { $$ = finish_alignof (groktypename ($3.t));
  1236. check_for_new_type ("alignof", $3);
  1237. skip_evaluation--; }
  1238. /* The %prec EMPTY's here are required by the = init initializer
  1239. syntax extension; see below. */
  1240. | new new_type_id %prec EMPTY
  1241. { $$ = build_new (NULL_TREE, $2.t, NULL_TREE, $1);
  1242. check_for_new_type ("new", $2); }
  1243. | new new_type_id new_initializer
  1244. { $$ = build_new (NULL_TREE, $2.t, $3, $1);
  1245. check_for_new_type ("new", $2); }
  1246. | new new_placement new_type_id %prec EMPTY
  1247. { $$ = build_new ($2, $3.t, NULL_TREE, $1);
  1248. check_for_new_type ("new", $3); }
  1249. | new new_placement new_type_id new_initializer
  1250. { $$ = build_new ($2, $3.t, $4, $1);
  1251. check_for_new_type ("new", $3); }
  1252. | new '(' type_id ')'
  1253. %prec EMPTY
  1254. { $$ = build_new (NULL_TREE, groktypename($3.t),
  1255. NULL_TREE, $1);
  1256. check_for_new_type ("new", $3); }
  1257. | new '(' type_id ')' new_initializer
  1258. { $$ = build_new (NULL_TREE, groktypename($3.t), $5, $1);
  1259. check_for_new_type ("new", $3); }
  1260. | new new_placement '(' type_id ')' %prec EMPTY
  1261. { $$ = build_new ($2, groktypename($4.t), NULL_TREE, $1);
  1262. check_for_new_type ("new", $4); }
  1263. | new new_placement '(' type_id ')' new_initializer
  1264. { $$ = build_new ($2, groktypename($4.t), $6, $1);
  1265. check_for_new_type ("new", $4); }
  1266. | delete cast_expr %prec UNARY
  1267. { $$ = delete_sanity ($2, NULL_TREE, 0, $1); }
  1268. | delete '[' ']' cast_expr %prec UNARY
  1269. { $$ = delete_sanity ($4, NULL_TREE, 1, $1);
  1270. if (yychar == YYEMPTY)
  1271. yychar = YYLEX; }
  1272. | delete '[' expr ']' cast_expr %prec UNARY
  1273. { $$ = delete_sanity ($5, $3, 2, $1);
  1274. if (yychar == YYEMPTY)
  1275. yychar = YYLEX; }
  1276. | REALPART cast_expr %prec UNARY
  1277. { $$ = build_x_unary_op (REALPART_EXPR, $2); }
  1278. | IMAGPART cast_expr %prec UNARY
  1279. { $$ = build_x_unary_op (IMAGPART_EXPR, $2); }
  1280. ;
  1281. new_placement:
  1282. '(' nonnull_exprlist ')'
  1283. { $$ = $2; }
  1284. | '{' nonnull_exprlist '}'
  1285. { pedwarn ("old style placement syntax, use () instead");
  1286. $$ = $2; }
  1287. ;
  1288. new_initializer:
  1289. '(' nonnull_exprlist ')'
  1290. { $$ = $2; }
  1291. | LEFT_RIGHT
  1292. { $$ = void_zero_node; }
  1293. | '(' typespec ')'
  1294. {
  1295. error ("`%T' is not a valid expression", $2.t);
  1296. $$ = error_mark_node;
  1297. }
  1298. | '=' init
  1299. {
  1300. /* This was previously allowed as an extension, but
  1301. was removed in G++ 3.3. */
  1302. error ("initialization of new expression with `='");
  1303. $$ = error_mark_node;
  1304. }
  1305. ;
  1306. /* This is necessary to postpone reduction of `int ((int)(int)(int))'. */
  1307. regcast_or_absdcl:
  1308. '(' type_id ')' %prec EMPTY
  1309. { $2.t = finish_parmlist (build_tree_list (NULL_TREE, $2.t), 0);
  1310. $$ = make_call_declarator (NULL_TREE, $2.t, NULL_TREE, NULL_TREE);
  1311. check_for_new_type ("cast", $2); }
  1312. | regcast_or_absdcl '(' type_id ')' %prec EMPTY
  1313. { $3.t = finish_parmlist (build_tree_list (NULL_TREE, $3.t), 0);
  1314. $$ = make_call_declarator ($$, $3.t, NULL_TREE, NULL_TREE);
  1315. check_for_new_type ("cast", $3); }
  1316. ;
  1317. cast_expr:
  1318. unary_expr
  1319. | regcast_or_absdcl unary_expr %prec UNARY
  1320. { $$ = reparse_absdcl_as_casts ($$, $2); }
  1321. | regcast_or_absdcl '{' initlist maybecomma '}' %prec UNARY
  1322. {
  1323. tree init = build_nt (CONSTRUCTOR, NULL_TREE,
  1324. nreverse ($3));
  1325. if (pedantic)
  1326. pedwarn ("ISO C++ forbids compound literals");
  1327. /* Indicate that this was a C99 compound literal. */
  1328. TREE_HAS_CONSTRUCTOR (init) = 1;
  1329. $$ = reparse_absdcl_as_casts ($$, init);
  1330. }
  1331. ;
  1332. expr_no_commas:
  1333. cast_expr
  1334. /* Handle general members. */
  1335. | expr_no_commas POINTSAT_STAR expr_no_commas
  1336. { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
  1337. | expr_no_commas DOT_STAR expr_no_commas
  1338. { $$ = build_m_component_ref ($$, $3); }
  1339. | expr_no_commas '+' expr_no_commas
  1340. { $$ = build_x_binary_op ($2, $$, $3); }
  1341. | expr_no_commas '-' expr_no_commas
  1342. { $$ = build_x_binary_op ($2, $$, $3); }
  1343. | expr_no_commas '*' expr_no_commas
  1344. { $$ = build_x_binary_op ($2, $$, $3); }
  1345. | expr_no_commas '/' expr_no_commas
  1346. { $$ = build_x_binary_op ($2, $$, $3); }
  1347. | expr_no_commas '%' expr_no_commas
  1348. { $$ = build_x_binary_op ($2, $$, $3); }
  1349. | expr_no_commas LSHIFT expr_no_commas
  1350. { $$ = build_x_binary_op ($2, $$, $3); }
  1351. | expr_no_commas RSHIFT expr_no_commas
  1352. { $$ = build_x_binary_op ($2, $$, $3); }
  1353. | expr_no_commas ARITHCOMPARE expr_no_commas
  1354. { $$ = build_x_binary_op ($2, $$, $3); }
  1355. | expr_no_commas '<' expr_no_commas
  1356. { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
  1357. | expr_no_commas '>' expr_no_commas
  1358. { $$ = build_x_binary_op (GT_EXPR, $$, $3); }
  1359. | expr_no_commas EQCOMPARE expr_no_commas
  1360. { $$ = build_x_binary_op ($2, $$, $3); }
  1361. | expr_no_commas MIN_MAX expr_no_commas
  1362. { $$ = build_x_binary_op ($2, $$, $3); }
  1363. | expr_no_commas '&' expr_no_commas
  1364. { $$ = build_x_binary_op ($2, $$, $3); }
  1365. | expr_no_commas '|' expr_no_commas
  1366. { $$ = build_x_binary_op ($2, $$, $3); }
  1367. | expr_no_commas '^' expr_no_commas
  1368. { $$ = build_x_binary_op ($2, $$, $3); }
  1369. | expr_no_commas ANDAND expr_no_commas
  1370. { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
  1371. | expr_no_commas OROR expr_no_commas
  1372. { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
  1373. | expr_no_commas '?' xexpr ':' expr_no_commas
  1374. { $$ = build_x_conditional_expr ($$, $3, $5); }
  1375. | expr_no_commas '=' expr_no_commas
  1376. { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
  1377. if ($$ != error_mark_node)
  1378. C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
  1379. | expr_no_commas ASSIGN expr_no_commas
  1380. { $$ = build_x_modify_expr ($$, $2, $3); }
  1381. | THROW
  1382. { $$ = build_throw (NULL_TREE); }
  1383. | THROW expr_no_commas
  1384. { $$ = build_throw ($2); }
  1385. ;
  1386. expr_no_comma_rangle:
  1387. cast_expr
  1388. /* Handle general members. */
  1389. | expr_no_comma_rangle POINTSAT_STAR expr_no_comma_rangle
  1390. { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
  1391. | expr_no_comma_rangle DOT_STAR expr_no_comma_rangle
  1392. { $$ = build_m_component_ref ($$, $3); }
  1393. | expr_no_comma_rangle '+' expr_no_comma_rangle
  1394. { $$ = build_x_binary_op ($2, $$, $3); }
  1395. | expr_no_comma_rangle '-' expr_no_comma_rangle
  1396. { $$ = build_x_binary_op ($2, $$, $3); }
  1397. | expr_no_comma_rangle '*' expr_no_comma_rangle
  1398. { $$ = build_x_binary_op ($2, $$, $3); }
  1399. | expr_no_comma_rangle '/' expr_no_comma_rangle
  1400. { $$ = build_x_binary_op ($2, $$, $3); }
  1401. | expr_no_comma_rangle '%' expr_no_comma_rangle
  1402. { $$ = build_x_binary_op ($2, $$, $3); }
  1403. | expr_no_comma_rangle LSHIFT expr_no_comma_rangle
  1404. { $$ = build_x_binary_op ($2, $$, $3); }
  1405. | expr_no_comma_rangle RSHIFT expr_no_comma_rangle
  1406. { $$ = build_x_binary_op ($2, $$, $3); }
  1407. | expr_no_comma_rangle ARITHCOMPARE expr_no_comma_rangle
  1408. { $$ = build_x_binary_op ($2, $$, $3); }
  1409. | expr_no_comma_rangle '<' expr_no_comma_rangle
  1410. { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
  1411. | expr_no_comma_rangle EQCOMPARE expr_no_comma_rangle
  1412. { $$ = build_x_binary_op ($2, $$, $3); }
  1413. | expr_no_comma_rangle MIN_MAX expr_no_comma_rangle
  1414. { $$ = build_x_binary_op ($2, $$, $3); }
  1415. | expr_no_comma_rangle '&' expr_no_comma_rangle
  1416. { $$ = build_x_binary_op ($2, $$, $3); }
  1417. | expr_no_comma_rangle '|' expr_no_comma_rangle
  1418. { $$ = build_x_binary_op ($2, $$, $3); }
  1419. | expr_no_comma_rangle '^' expr_no_comma_rangle
  1420. { $$ = build_x_binary_op ($2, $$, $3); }
  1421. | expr_no_comma_rangle ANDAND expr_no_comma_rangle
  1422. { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
  1423. | expr_no_comma_rangle OROR expr_no_comma_rangle
  1424. { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
  1425. | expr_no_comma_rangle '?' xexpr ':' expr_no_comma_rangle
  1426. { $$ = build_x_conditional_expr ($$, $3, $5); }
  1427. | expr_no_comma_rangle '=' expr_no_comma_rangle
  1428. { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
  1429. if ($$ != error_mark_node)
  1430. C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
  1431. | expr_no_comma_rangle ASSIGN expr_no_comma_rangle
  1432. { $$ = build_x_modify_expr ($$, $2, $3); }
  1433. | THROW
  1434. { $$ = build_throw (NULL_TREE); }
  1435. | THROW expr_no_comma_rangle
  1436. { $$ = build_throw ($2); }
  1437. ;
  1438. notype_unqualified_id:
  1439. '~' see_typename identifier
  1440. { $$ = build_nt (BIT_NOT_EXPR, $3); }
  1441. | '~' see_typename template_type
  1442. { $$ = build_nt (BIT_NOT_EXPR, $3); }
  1443. | template_id
  1444. | operator_name
  1445. | IDENTIFIER
  1446. | PTYPENAME
  1447. | NSNAME %prec EMPTY
  1448. ;
  1449. do_id:
  1450. {
  1451. /* If lastiddecl is a BASELINK we're in an
  1452. expression like S::f<int>, so don't
  1453. do_identifier; we only do that for unqualified
  1454. identifiers. */
  1455. if (!lastiddecl || !BASELINK_P (lastiddecl))
  1456. $$ = do_identifier ($<ttype>-1, 3, NULL_TREE);
  1457. else
  1458. $$ = $<ttype>-1;
  1459. }
  1460. ;
  1461. template_id:
  1462. PFUNCNAME '<' do_id template_arg_list_opt template_close_bracket
  1463. {
  1464. tree template_name = $3;
  1465. if (TREE_CODE (template_name) == COMPONENT_REF)
  1466. template_name = TREE_OPERAND (template_name, 1);
  1467. $$ = lookup_template_function (template_name, $4);
  1468. }
  1469. | operator_name '<' do_id template_arg_list_opt template_close_bracket
  1470. {
  1471. tree template_name = $3;
  1472. if (TREE_CODE (template_name) == COMPONENT_REF)
  1473. template_name = TREE_OPERAND (template_name, 1);
  1474. $$ = lookup_template_function (template_name, $4);
  1475. }
  1476. ;
  1477. object_template_id:
  1478. TEMPLATE identifier '<' template_arg_list_opt template_close_bracket
  1479. { $$ = lookup_template_function ($2, $4); }
  1480. | TEMPLATE PFUNCNAME '<' template_arg_list_opt template_close_bracket
  1481. { $$ = lookup_template_function ($2, $4); }
  1482. | TEMPLATE operator_name '<' template_arg_list_opt
  1483. template_close_bracket
  1484. { $$ = lookup_template_function ($2, $4); }
  1485. ;
  1486. unqualified_id:
  1487. notype_unqualified_id
  1488. | tTYPENAME
  1489. | SELFNAME
  1490. ;
  1491. expr_or_declarator_intern:
  1492. expr_or_declarator
  1493. | attributes expr_or_declarator
  1494. {
  1495. /* Provide support for '(' attributes '*' declarator ')'
  1496. etc */
  1497. $$ = tree_cons ($1, $2, NULL_TREE);
  1498. }
  1499. ;
  1500. expr_or_declarator:
  1501. notype_unqualified_id
  1502. | '*' expr_or_declarator_intern %prec UNARY
  1503. { $$ = build_nt (INDIRECT_REF, $2); }
  1504. | '&' expr_or_declarator_intern %prec UNARY
  1505. { $$ = build_nt (ADDR_EXPR, $2); }
  1506. | '(' expr_or_declarator_intern ')'
  1507. { $$ = $2; }
  1508. ;
  1509. notype_template_declarator:
  1510. IDENTIFIER '<' template_arg_list_opt template_close_bracket
  1511. { $$ = lookup_template_function ($1, $3); }
  1512. | NSNAME '<' template_arg_list template_close_bracket
  1513. { $$ = lookup_template_function ($1, $3); }
  1514. ;
  1515. direct_notype_declarator:
  1516. complex_direct_notype_declarator
  1517. /* This precedence declaration is to prefer this reduce
  1518. to the Koenig lookup shift in primary, below. I hate yacc. */
  1519. | notype_unqualified_id %prec '('
  1520. | notype_template_declarator
  1521. | '(' expr_or_declarator_intern ')'
  1522. { $$ = finish_decl_parsing ($2); }
  1523. ;
  1524. primary:
  1525. notype_unqualified_id
  1526. {
  1527. if (TREE_CODE ($1) == BIT_NOT_EXPR)
  1528. $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($1, 0));
  1529. else
  1530. $$ = finish_id_expr ($1);
  1531. }
  1532. | CONSTANT
  1533. | boolean_literal
  1534. | STRING
  1535. {
  1536. $$ = fix_string_type ($$);
  1537. /* fix_string_type doesn't set up TYPE_MAIN_VARIANT of
  1538. a const array the way we want, so fix it. */
  1539. if (flag_const_strings)
  1540. TREE_TYPE ($$) = build_cplus_array_type
  1541. (TREE_TYPE (TREE_TYPE ($$)),
  1542. TYPE_DOMAIN (TREE_TYPE ($$)));
  1543. }
  1544. | VAR_FUNC_NAME
  1545. { $$ = finish_fname ($1); }
  1546. | '(' expr ')'
  1547. { $$ = finish_parenthesized_expr ($2); }
  1548. | '(' expr_or_declarator_intern ')'
  1549. { $2 = reparse_decl_as_expr (NULL_TREE, $2);
  1550. $$ = finish_parenthesized_expr ($2); }
  1551. | '(' error ')'
  1552. { $$ = error_mark_node; }
  1553. | '('
  1554. { if (!at_function_scope_p ())
  1555. {
  1556. error ("braced-group within expression allowed only inside a function");
  1557. YYERROR;
  1558. }
  1559. if (pedantic)
  1560. pedwarn ("ISO C++ forbids braced-groups within expressions");
  1561. $<ttype>$ = begin_stmt_expr ();
  1562. }
  1563. compstmt_or_stmtexpr ')'
  1564. { $$ = finish_stmt_expr ($<ttype>2); }
  1565. /* Koenig lookup support
  1566. We could store lastiddecl in $1 to avoid another lookup,
  1567. but that would result in many additional reduce/reduce conflicts. */
  1568. | notype_unqualified_id '(' nonnull_exprlist ')'
  1569. { $$ = parse_finish_call_expr ($1, $3, 1); }
  1570. | notype_unqualified_id LEFT_RIGHT
  1571. { $$ = parse_finish_call_expr ($1, NULL_TREE, 1); }
  1572. | primary '(' nonnull_exprlist ')'
  1573. { $$ = parse_finish_call_expr ($1, $3, 0); }
  1574. | primary LEFT_RIGHT
  1575. { $$ = parse_finish_call_expr ($1, NULL_TREE, 0); }
  1576. | VA_ARG '(' expr_no_commas ',' type_id ')'
  1577. { $$ = build_x_va_arg ($3, groktypename ($5.t));
  1578. check_for_new_type ("__builtin_va_arg", $5); }
  1579. | OFFSETOF '(' expr_no_commas ')'
  1580. { $$ = $3; }
  1581. | primary '[' expr ']'
  1582. { $$ = grok_array_decl ($$, $3); }
  1583. | primary PLUSPLUS
  1584. { $$ = finish_increment_expr ($1, POSTINCREMENT_EXPR); }
  1585. | primary MINUSMINUS
  1586. { $$ = finish_increment_expr ($1, POSTDECREMENT_EXPR); }
  1587. /* C++ extensions */
  1588. | THIS
  1589. { $$ = finish_this_expr (); }
  1590. | CV_QUALIFIER '(' nonnull_exprlist ')'
  1591. {
  1592. /* This is a C cast in C++'s `functional' notation
  1593. using the "implicit int" extension so that:
  1594. `const (3)' is equivalent to `const int (3)'. */
  1595. tree type;
  1596. type = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
  1597. type = groktypename (build_tree_list (type, NULL_TREE));
  1598. $$ = build_functional_cast (type, $3);
  1599. }
  1600. | functional_cast
  1601. | DYNAMIC_CAST '<' type_id '>' '(' expr ')'
  1602. { tree type = groktypename ($3.t);
  1603. check_for_new_type ("dynamic_cast", $3);
  1604. $$ = build_dynamic_cast (type, $6); }
  1605. | STATIC_CAST '<' type_id '>' '(' expr ')'
  1606. { tree type = groktypename ($3.t);
  1607. check_for_new_type ("static_cast", $3);
  1608. $$ = build_static_cast (type, $6); }
  1609. | REINTERPRET_CAST '<' type_id '>' '(' expr ')'
  1610. { tree type = groktypename ($3.t);
  1611. check_for_new_type ("reinterpret_cast", $3);
  1612. $$ = build_reinterpret_cast (type, $6); }
  1613. | CONST_CAST '<' type_id '>' '(' expr ')'
  1614. { tree type = groktypename ($3.t);
  1615. check_for_new_type ("const_cast", $3);
  1616. $$ = build_const_cast (type, $6); }
  1617. | TYPEID '(' expr ')'
  1618. { $$ = build_typeid ($3); }
  1619. | TYPEID '(' type_id ')'
  1620. { tree type = groktypename ($3.t);
  1621. check_for_new_type ("typeid", $3);
  1622. $$ = get_typeid (type); }
  1623. | global_scope IDENTIFIER
  1624. { $$ = parse_scoped_id ($2); }
  1625. | global_scope template_id
  1626. { $$ = $2; }
  1627. | global_scope operator_name
  1628. {
  1629. got_scope = NULL_TREE;
  1630. if (TREE_CODE ($2) == IDENTIFIER_NODE)
  1631. $$ = parse_scoped_id ($2);
  1632. else
  1633. $$ = $2;
  1634. }
  1635. | overqualified_id %prec HYPERUNARY
  1636. { $$ = build_offset_ref (OP0 ($$), OP1 ($$));
  1637. if (!class_template_ok_as_expr
  1638. && DECL_CLASS_TEMPLATE_P ($$))
  1639. {
  1640. error ("invalid use of template `%D'", $$);
  1641. $$ = error_mark_node;
  1642. }
  1643. }
  1644. | overqualified_id '(' nonnull_exprlist ')'
  1645. { $$ = parse_finish_call_expr ($1, $3, 0); }
  1646. | overqualified_id LEFT_RIGHT
  1647. { $$ = parse_finish_call_expr ($1, NULL_TREE, 0); }
  1648. | object object_template_id %prec UNARY
  1649. { $$ = finish_class_member_access_expr ($$, $2); }
  1650. | object object_template_id '(' nonnull_exprlist ')'
  1651. { $$ = finish_object_call_expr ($2, $1, $4); }
  1652. | object object_template_id LEFT_RIGHT
  1653. { $$ = finish_object_call_expr ($2, $1, NULL_TREE); }
  1654. | object unqualified_id %prec UNARY
  1655. { $$ = finish_class_member_access_expr ($$, $2); }
  1656. | object overqualified_id %prec UNARY
  1657. { $$ = finish_class_member_access_expr ($1, $2); }
  1658. | object unqualified_id '(' nonnull_exprlist ')'
  1659. { $$ = finish_object_call_expr ($2, $1, $4); }
  1660. | object unqualified_id LEFT_RIGHT
  1661. { $$ = finish_object_call_expr ($2, $1, NULL_TREE); }
  1662. | object overqualified_id '(' nonnull_exprlist ')'
  1663. { $$ = finish_qualified_object_call_expr ($2, $1, $4); }
  1664. | object overqualified_id LEFT_RIGHT
  1665. { $$ = finish_qualified_object_call_expr ($2, $1, NULL_TREE); }
  1666. /* p->int::~int() is valid -- 12.4 */
  1667. | object '~' TYPESPEC LEFT_RIGHT
  1668. { $$ = finish_pseudo_destructor_call_expr ($1, NULL_TREE, $3); }
  1669. | object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT
  1670. { $$ = finish_pseudo_destructor_call_expr ($1, $2, $5); }
  1671. | object error
  1672. {
  1673. $$ = error_mark_node;
  1674. }
  1675. ;
  1676. /* Not needed for now.
  1677. primary_no_id:
  1678. '(' expr ')'
  1679. { $$ = $2; }
  1680. | '(' error ')'
  1681. { $$ = error_mark_node; }
  1682. | '('
  1683. { if (current_function_decl == 0)
  1684. {
  1685. error ("braced-group within expression allowed only inside a function");
  1686. YYERROR;
  1687. }
  1688. $<ttype>$ = expand_start_stmt_expr (); }
  1689. compstmt_or_stmtexpr ')'
  1690. { if (pedantic)
  1691. pedwarn ("ISO C++ forbids braced-groups within expressions");
  1692. $$ = expand_end_stmt_expr ($<ttype>2); }
  1693. | primary_no_id '(' nonnull_exprlist ')'
  1694. { $$ = build_x_function_call ($$, $3, current_class_ref); }
  1695. | primary_no_id LEFT_RIGHT
  1696. { $$ = build_x_function_call ($$, NULL_TREE, current_class_ref); }
  1697. | primary_no_id '[' expr ']'
  1698. { goto do_array; }
  1699. | primary_no_id PLUSPLUS
  1700. { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
  1701. | primary_no_id MINUSMINUS
  1702. { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
  1703. | SCOPE IDENTIFIER
  1704. { goto do_scoped_id; }
  1705. | SCOPE operator_name
  1706. { if (TREE_CODE ($2) == IDENTIFIER_NODE)
  1707. goto do_scoped_id;
  1708. goto do_scoped_operator;
  1709. }
  1710. ;
  1711. */
  1712. new:
  1713. NEW
  1714. { $$ = 0; }
  1715. | global_scope NEW
  1716. { got_scope = NULL_TREE; $$ = 1; }
  1717. ;
  1718. delete:
  1719. DELETE
  1720. { $$ = 0; }
  1721. | global_scope delete
  1722. { got_scope = NULL_TREE; $$ = 1; }
  1723. ;
  1724. boolean_literal:
  1725. CXX_TRUE
  1726. { $$ = boolean_true_node; }
  1727. | CXX_FALSE
  1728. { $$ = boolean_false_node; }
  1729. ;
  1730. nodecls:
  1731. /* empty */
  1732. {
  1733. if (DECL_CONSTRUCTOR_P (current_function_decl))
  1734. finish_mem_initializers (NULL_TREE);
  1735. }
  1736. ;
  1737. object:
  1738. primary '.'
  1739. { got_object = TREE_TYPE ($$); }
  1740. | primary POINTSAT
  1741. {
  1742. $$ = build_x_arrow ($$);
  1743. got_object = TREE_TYPE ($$);
  1744. }
  1745. ;
  1746. decl:
  1747. typespec initdecls ';'
  1748. {
  1749. if ($1.t && IS_AGGR_TYPE_CODE (TREE_CODE ($1.t)))
  1750. note_got_semicolon ($1.t);
  1751. }
  1752. | typed_declspecs initdecls ';'
  1753. {
  1754. note_list_got_semicolon ($1.t);
  1755. }
  1756. | declmods notype_initdecls ';'
  1757. {}
  1758. | typed_declspecs ';'
  1759. {
  1760. shadow_tag ($1.t);
  1761. note_list_got_semicolon ($1.t);
  1762. }
  1763. | declmods ';'
  1764. { warning ("empty declaration"); }
  1765. | extension decl
  1766. { pedantic = $1; }
  1767. ;
  1768. /* Any kind of declarator (thus, all declarators allowed
  1769. after an explicit typespec). */
  1770. declarator:
  1771. after_type_declarator %prec EMPTY
  1772. | notype_declarator %prec EMPTY
  1773. ;
  1774. /* This is necessary to postpone reduction of `int()()()()'. */
  1775. fcast_or_absdcl:
  1776. LEFT_RIGHT %prec EMPTY
  1777. { $$ = make_call_declarator (NULL_TREE, empty_parms (),
  1778. NULL_TREE, NULL_TREE); }
  1779. | fcast_or_absdcl LEFT_RIGHT %prec EMPTY
  1780. { $$ = make_call_declarator ($$, empty_parms (), NULL_TREE,
  1781. NULL_TREE); }
  1782. ;
  1783. /* ISO type-id (8.1) */
  1784. type_id:
  1785. typed_typespecs absdcl
  1786. { $$.t = build_tree_list ($1.t, $2);
  1787. $$.new_type_flag = $1.new_type_flag; }
  1788. | nonempty_cv_qualifiers absdcl
  1789. { $$.t = build_tree_list ($1.t, $2);
  1790. $$.new_type_flag = $1.new_type_flag; }
  1791. | typespec absdcl
  1792. { $$.t = build_tree_list (build_tree_list (NULL_TREE, $1.t),
  1793. $2);
  1794. $$.new_type_flag = $1.new_type_flag; }
  1795. | typed_typespecs %prec EMPTY
  1796. { $$.t = build_tree_list ($1.t, NULL_TREE);
  1797. $$.new_type_flag = $1.new_type_flag; }
  1798. | nonempty_cv_qualifiers %prec EMPTY
  1799. { $$.t = build_tree_list ($1.t, NULL_TREE);
  1800. $$.new_type_flag = $1.new_type_flag; }
  1801. ;
  1802. /* Declspecs which contain at least one type specifier or typedef name.
  1803. (Just `const' or `volatile' is not enough.)
  1804. A typedef'd name following these is taken as a name to be declared.
  1805. In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
  1806. typed_declspecs:
  1807. typed_typespecs %prec EMPTY
  1808. { $$.lookups = type_lookups; }
  1809. | typed_declspecs1
  1810. { $$.lookups = type_lookups; }
  1811. ;
  1812. typed_declspecs1:
  1813. declmods typespec
  1814. { $$.t = tree_cons (NULL_TREE, $2.t, $1.t);
  1815. $$.new_type_flag = $2.new_type_flag; }
  1816. | typespec reserved_declspecs %prec HYPERUNARY
  1817. { $$.t = tree_cons (NULL_TREE, $1.t, $2);
  1818. $$.new_type_flag = $1.new_type_flag; }
  1819. | typespec reserved_typespecquals reserved_declspecs
  1820. { $$.t = tree_cons (NULL_TREE, $1.t, chainon ($2, $3));
  1821. $$.new_type_flag = $1.new_type_flag; }
  1822. | declmods typespec reserved_declspecs
  1823. { $$.t = tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
  1824. $$.new_type_flag = $2.new_type_flag; }
  1825. | declmods typespec reserved_typespecquals
  1826. { $$.t = tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
  1827. $$.new_type_flag = $2.new_type_flag; }
  1828. | declmods typespec reserved_typespecquals reserved_declspecs
  1829. { $$.t = tree_cons (NULL_TREE, $2.t,
  1830. chainon ($3, chainon ($4, $1.t)));
  1831. $$.new_type_flag = $2.new_type_flag; }
  1832. ;
  1833. reserved_declspecs:
  1834. SCSPEC
  1835. { if (extra_warnings)
  1836. warning ("`%s' is not at beginning of declaration",
  1837. IDENTIFIER_POINTER ($$));
  1838. $$ = build_tree_list (NULL_TREE, $$); }
  1839. | reserved_declspecs typespecqual_reserved
  1840. { $$ = tree_cons (NULL_TREE, $2.t, $$); }
  1841. | reserved_declspecs SCSPEC
  1842. { if (extra_warnings)
  1843. warning ("`%s' is not at beginning of declaration",
  1844. IDENTIFIER_POINTER ($2));
  1845. $$ = tree_cons (NULL_TREE, $2, $$); }
  1846. ;
  1847. /* List of just storage classes and type modifiers.
  1848. A declaration can start with just this, but then it cannot be used
  1849. to redeclare a typedef-name.
  1850. In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
  1851. /* We use hash_tree_cons for lists of typeless declspecs so that they end
  1852. up on a persistent obstack. Otherwise, they could appear at the
  1853. beginning of something like
  1854. static const struct { int foo () { } } b;
  1855. and would be discarded after we finish compiling foo. We don't need to
  1856. worry once we see a type. */
  1857. declmods:
  1858. nonempty_cv_qualifiers %prec EMPTY
  1859. { $$.lookups = NULL_TREE; TREE_STATIC ($$.t) = 1; }
  1860. | SCSPEC
  1861. {
  1862. $$.t = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
  1863. $$.new_type_flag = 0; $$.lookups = NULL_TREE;
  1864. }
  1865. | declmods CV_QUALIFIER
  1866. {
  1867. $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
  1868. TREE_STATIC ($$.t) = 1;
  1869. }
  1870. | declmods SCSPEC
  1871. {
  1872. if (extra_warnings && TREE_STATIC ($$.t))
  1873. warning ("`%s' is not at beginning of declaration",
  1874. IDENTIFIER_POINTER ($2));
  1875. $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
  1876. TREE_STATIC ($$.t) = TREE_STATIC ($1.t);
  1877. }
  1878. | declmods attributes
  1879. { $$.t = hash_tree_cons ($2, NULL_TREE, $1.t); }
  1880. ;
  1881. /* Used instead of declspecs where storage classes are not allowed
  1882. (that is, for typenames and structure components).
  1883. C++ can takes storage classes for structure components.
  1884. Don't accept a typedef-name if anything but a modifier precedes it. */
  1885. typed_typespecs:
  1886. typespec %prec EMPTY
  1887. { $$.t = build_tree_list (NULL_TREE, $1.t);
  1888. $$.new_type_flag = $1.new_type_flag; }
  1889. | nonempty_cv_qualifiers typespec
  1890. { $$.t = tree_cons (NULL_TREE, $2.t, $1.t);
  1891. $$.new_type_flag = $2.new_type_flag; }
  1892. | typespec reserved_typespecquals
  1893. { $$.t = tree_cons (NULL_TREE, $1.t, $2);
  1894. $$.new_type_flag = $1.new_type_flag; }
  1895. | nonempty_cv_qualifiers typespec reserved_typespecquals
  1896. { $$.t = tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
  1897. $$.new_type_flag = $2.new_type_flag; }
  1898. ;
  1899. reserved_typespecquals:
  1900. typespecqual_reserved
  1901. { $$ = build_tree_list (NULL_TREE, $1.t); }
  1902. | reserved_typespecquals typespecqual_reserved
  1903. { $$ = tree_cons (NULL_TREE, $2.t, $1); }
  1904. | reserved_typespecquals attributes
  1905. { $$ = tree_cons ($2, NULL_TREE, $1); }
  1906. | attributes %prec EMPTY
  1907. { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
  1908. ;
  1909. sizeof:
  1910. SIZEOF { skip_evaluation++; }
  1911. ;
  1912. alignof:
  1913. ALIGNOF { skip_evaluation++; }
  1914. ;
  1915. typeof:
  1916. TYPEOF { skip_evaluation++; }
  1917. ;
  1918. /* A typespec (but not a type qualifier).
  1919. Once we have seen one of these in a declaration,
  1920. if a typedef name appears then it is being redeclared. */
  1921. typespec:
  1922. structsp
  1923. { $$.lookups = NULL_TREE; }
  1924. | TYPESPEC %prec EMPTY
  1925. { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
  1926. | complete_type_name
  1927. { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
  1928. | typeof '(' expr ')'
  1929. { $$.t = finish_typeof ($3);
  1930. $$.new_type_flag = 0; $$.lookups = NULL_TREE;
  1931. skip_evaluation--; }
  1932. | typeof '(' type_id ')'
  1933. { $$.t = groktypename ($3.t);
  1934. $$.new_type_flag = 0; $$.lookups = NULL_TREE;
  1935. skip_evaluation--; }
  1936. | SIGOF '(' expr ')'
  1937. { tree type = TREE_TYPE ($3);
  1938. $$.new_type_flag = 0; $$.lookups = NULL_TREE;
  1939. if (IS_AGGR_TYPE (type))
  1940. {
  1941. sorry ("sigof type specifier");
  1942. $$.t = type;
  1943. }
  1944. else
  1945. {
  1946. error ("`sigof' applied to non-aggregate expression");
  1947. $$.t = error_mark_node;
  1948. }
  1949. }
  1950. | SIGOF '(' type_id ')'
  1951. { tree type = groktypename ($3.t);
  1952. $$.new_type_flag = 0; $$.lookups = NULL_TREE;
  1953. if (IS_AGGR_TYPE (type))
  1954. {
  1955. sorry ("sigof type specifier");
  1956. $$.t = type;
  1957. }
  1958. else
  1959. {
  1960. error("`sigof' applied to non-aggregate type");
  1961. $$.t = error_mark_node;
  1962. }
  1963. }
  1964. ;
  1965. /* A typespec that is a reserved word, or a type qualifier. */
  1966. typespecqual_reserved:
  1967. TYPESPEC
  1968. { $$.t = $1; $$.new_type_flag = 0; }
  1969. | CV_QUALIFIER
  1970. { $$.t = $1; $$.new_type_flag = 0; }
  1971. | structsp
  1972. ;
  1973. initdecls:
  1974. initdcl0
  1975. | initdecls ',' initdcl
  1976. { check_multiple_declarators (); }
  1977. ;
  1978. notype_initdecls:
  1979. notype_initdcl0
  1980. | notype_initdecls ',' initdcl
  1981. { check_multiple_declarators (); }
  1982. ;
  1983. nomods_initdecls:
  1984. nomods_initdcl0
  1985. | nomods_initdecls ',' initdcl
  1986. { check_multiple_declarators (); }
  1987. ;
  1988. maybeasm:
  1989. /* empty */
  1990. { $$ = NULL_TREE; }
  1991. | asm_keyword '(' STRING ')'
  1992. { $$ = $3; }
  1993. ;
  1994. initdcl:
  1995. declarator maybeasm maybe_attribute '='
  1996. { $<ttype>$ = parse_decl ($<ttype>1, $3, 1); }
  1997. init
  1998. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1999. { parse_end_decl ($<ttype>5, $6, $2); }
  2000. | declarator maybeasm maybe_attribute
  2001. {
  2002. $<ttype>$ = parse_decl ($<ttype>1, $3, 0);
  2003. parse_end_decl ($<ttype>$, NULL_TREE, $2);
  2004. }
  2005. ;
  2006. /* This rule assumes a certain configuration of the parser stack.
  2007. In particular, $0, the element directly before the beginning of
  2008. this rule on the stack, must be a maybeasm. $-1 must be a
  2009. declarator or notype_declarator. And $-2 must be some declmods
  2010. or declspecs. We can't move the maybeasm into this rule because
  2011. we need that reduce so we prefer fn.def1 when appropriate. */
  2012. initdcl0_innards:
  2013. maybe_attribute '='
  2014. { $<ttype>$ = parse_decl0 ($<ttype>-1, $<ftype>-2.t,
  2015. $<ftype>-2.lookups, $1, 1); }
  2016. /* Note how the declaration of the variable is in effect
  2017. while its init is parsed! */
  2018. init
  2019. { parse_end_decl ($<ttype>3, $4, $<ttype>0); }
  2020. | maybe_attribute
  2021. { tree d = parse_decl0 ($<ttype>-1, $<ftype>-2.t,
  2022. $<ftype>-2.lookups, $1, 0);
  2023. parse_end_decl (d, NULL_TREE, $<ttype>0); }
  2024. ;
  2025. initdcl0:
  2026. declarator maybeasm initdcl0_innards
  2027. {}
  2028. ;
  2029. notype_initdcl0:
  2030. notype_declarator maybeasm initdcl0_innards
  2031. {}
  2032. ;
  2033. nomods_initdcl0:
  2034. notype_declarator maybeasm
  2035. { /* Set things up as initdcl0_innards expects. */
  2036. $<ttype>$ = $2;
  2037. $2 = $1;
  2038. $<ftype>1.t = NULL_TREE;
  2039. $<ftype>1.lookups = NULL_TREE; }
  2040. initdcl0_innards
  2041. {}
  2042. | constructor_declarator maybeasm maybe_attribute
  2043. { tree d = parse_decl0 ($1, NULL_TREE, NULL_TREE, $3, 0);
  2044. parse_end_decl (d, NULL_TREE, $2); }
  2045. ;
  2046. /* the * rules are dummies to accept the Apollo extended syntax
  2047. so that the header files compile. */
  2048. maybe_attribute:
  2049. /* empty */
  2050. { $$ = NULL_TREE; }
  2051. | attributes
  2052. { $$ = $1; }
  2053. ;
  2054. attributes:
  2055. attribute
  2056. { $$ = $1; }
  2057. | attributes attribute
  2058. { $$ = chainon ($1, $2); }
  2059. ;
  2060. attribute:
  2061. ATTRIBUTE '(' '(' attribute_list ')' ')'
  2062. { $$ = $4; }
  2063. ;
  2064. attribute_list:
  2065. attrib
  2066. { $$ = $1; }
  2067. | attribute_list ',' attrib
  2068. { $$ = chainon ($1, $3); }
  2069. ;
  2070. attrib:
  2071. /* empty */
  2072. { $$ = NULL_TREE; }
  2073. | any_word
  2074. { $$ = build_tree_list ($1, NULL_TREE); }
  2075. | any_word '(' IDENTIFIER ')'
  2076. { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
  2077. | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
  2078. { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
  2079. | any_word '(' nonnull_exprlist ')'
  2080. { $$ = build_tree_list ($1, $3); }
  2081. ;
  2082. /* This still leaves out most reserved keywords,
  2083. shouldn't we include them? */
  2084. any_word:
  2085. identifier
  2086. | SCSPEC
  2087. | TYPESPEC
  2088. | CV_QUALIFIER
  2089. ;
  2090. /* A nonempty list of identifiers, including typenames. */
  2091. identifiers_or_typenames:
  2092. identifier
  2093. { $$ = build_tree_list (NULL_TREE, $1); }
  2094. | identifiers_or_typenames ',' identifier
  2095. { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  2096. ;
  2097. maybe_init:
  2098. /* empty */ %prec EMPTY
  2099. { $$ = NULL_TREE; }
  2100. | '=' init
  2101. { $$ = $2; }
  2102. ;
  2103. /* If we are processing a template, we don't want to expand this
  2104. initializer yet. */
  2105. init:
  2106. expr_no_commas %prec '='
  2107. | '{' '}'
  2108. { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
  2109. TREE_HAS_CONSTRUCTOR ($$) = 1; }
  2110. | '{' initlist '}'
  2111. { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
  2112. TREE_HAS_CONSTRUCTOR ($$) = 1; }
  2113. | '{' initlist ',' '}'
  2114. { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
  2115. TREE_HAS_CONSTRUCTOR ($$) = 1; }
  2116. | error
  2117. { $$ = NULL_TREE; }
  2118. ;
  2119. /* This chain is built in reverse order,
  2120. and put in forward order where initlist is used. */
  2121. initlist:
  2122. init
  2123. { $$ = build_tree_list (NULL_TREE, $$); }
  2124. | initlist ',' init
  2125. { $$ = tree_cons (NULL_TREE, $3, $$); }
  2126. /* These are for labeled elements. */
  2127. | '[' expr_no_commas ']' init
  2128. { $$ = build_tree_list ($2, $4); }
  2129. | identifier ':' init
  2130. { $$ = build_tree_list ($$, $3); }
  2131. | initlist ',' identifier ':' init
  2132. { $$ = tree_cons ($3, $5, $$); }
  2133. ;
  2134. pending_inline:
  2135. PRE_PARSED_FUNCTION_DECL maybe_return_init function_body
  2136. {
  2137. expand_body (finish_function (2));
  2138. process_next_inline ($1);
  2139. }
  2140. | PRE_PARSED_FUNCTION_DECL maybe_return_init function_try_block
  2141. {
  2142. expand_body (finish_function (2));
  2143. process_next_inline ($1);
  2144. }
  2145. | PRE_PARSED_FUNCTION_DECL maybe_return_init error
  2146. {
  2147. finish_function (2);
  2148. process_next_inline ($1); }
  2149. ;
  2150. pending_inlines:
  2151. /* empty */
  2152. | pending_inlines pending_inline eat_saved_input
  2153. ;
  2154. /* A regurgitated default argument. The value of DEFARG_MARKER will be
  2155. the TREE_LIST node for the parameter in question. */
  2156. defarg_again:
  2157. DEFARG_MARKER expr_no_commas END_OF_SAVED_INPUT
  2158. { replace_defarg ($1, $2); }
  2159. | DEFARG_MARKER error END_OF_SAVED_INPUT
  2160. { replace_defarg ($1, error_mark_node); }
  2161. ;
  2162. pending_defargs:
  2163. /* empty */ %prec EMPTY
  2164. | pending_defargs defarg_again
  2165. { do_pending_defargs (); }
  2166. | pending_defargs error
  2167. { do_pending_defargs (); }
  2168. ;
  2169. structsp:
  2170. ENUM identifier '{'
  2171. { $<ttype>$ = current_enum_type;
  2172. current_enum_type = start_enum ($2); }
  2173. enumlist_opt '}'
  2174. { $$.t = current_enum_type;
  2175. finish_enum (current_enum_type);
  2176. $$.new_type_flag = 1;
  2177. current_enum_type = $<ttype>4;
  2178. check_for_missing_semicolon ($$.t); }
  2179. | ENUM '{'
  2180. { $<ttype>$ = current_enum_type;
  2181. current_enum_type = start_enum (make_anon_name ()); }
  2182. enumlist_opt '}'
  2183. { $$.t = current_enum_type;
  2184. finish_enum (current_enum_type);
  2185. $$.new_type_flag = 1;
  2186. current_enum_type = $<ttype>3;
  2187. check_for_missing_semicolon ($$.t); }
  2188. | ENUM identifier
  2189. { $$.t = parse_xref_tag (enum_type_node, $2, 1);
  2190. $$.new_type_flag = 0; }
  2191. | ENUM complex_type_name
  2192. { $$.t = parse_xref_tag (enum_type_node, $2, 1);
  2193. $$.new_type_flag = 0; }
  2194. | TYPENAME_KEYWORD typename_sub
  2195. { $$.t = $2;
  2196. $$.new_type_flag = 0;
  2197. if (!processing_template_decl)
  2198. pedwarn ("using `typename' outside of template"); }
  2199. /* C++ extensions, merged with C to avoid shift/reduce conflicts */
  2200. | class_head_defn maybe_base_class_list '{'
  2201. {
  2202. if ($2 && $1.t != error_mark_node)
  2203. {
  2204. tree type = TREE_TYPE ($1.t);
  2205. if (TREE_CODE (type) == TYPENAME_TYPE)
  2206. {
  2207. if (IMPLICIT_TYPENAME_P (type))
  2208. /* In a definition of a member class template,
  2209. we will get here with an implicit typename,
  2210. a TYPENAME_TYPE with a type. */
  2211. type = TREE_TYPE (type);
  2212. else
  2213. {
  2214. error ("qualified name does not name a class");
  2215. type = error_mark_node;
  2216. }
  2217. }
  2218. maybe_process_partial_specialization (type);
  2219. xref_basetypes (type, $2);
  2220. }
  2221. $1.t = begin_class_definition (TREE_TYPE ($1.t));
  2222. check_class_key (current_aggr, $1.t);
  2223. current_aggr = NULL_TREE; }
  2224. opt.component_decl_list '}' maybe_attribute
  2225. {
  2226. int semi;
  2227. tree t;
  2228. if (yychar == YYEMPTY)
  2229. yychar = YYLEX;
  2230. semi = yychar == ';';
  2231. t = finish_class_definition ($1.t, $7, semi, $1.new_type_flag);
  2232. $<ttype>$ = t;
  2233. /* restore current_aggr */
  2234. current_aggr = TREE_CODE (t) != RECORD_TYPE
  2235. ? union_type_node
  2236. : CLASSTYPE_DECLARED_CLASS (t)
  2237. ? class_type_node : record_type_node;
  2238. }
  2239. pending_defargs
  2240. {
  2241. done_pending_defargs ();
  2242. begin_inline_definitions ();
  2243. }
  2244. pending_inlines
  2245. {
  2246. $$.t = $<ttype>8;
  2247. $$.new_type_flag = 1;
  2248. }
  2249. | class_head_decl
  2250. {
  2251. $$.t = TREE_TYPE ($1.t);
  2252. $$.new_type_flag = $1.new_type_flag;
  2253. check_class_key (current_aggr, $$.t);
  2254. }
  2255. ;
  2256. maybecomma:
  2257. /* empty */
  2258. | ','
  2259. ;
  2260. maybecomma_warn:
  2261. /* empty */
  2262. | ','
  2263. { if (pedantic && !in_system_header)
  2264. pedwarn ("comma at end of enumerator list"); }
  2265. ;
  2266. aggr:
  2267. AGGR
  2268. | aggr SCSPEC
  2269. { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
  2270. | aggr TYPESPEC
  2271. { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
  2272. | aggr CV_QUALIFIER
  2273. { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
  2274. | aggr AGGR
  2275. { error ("no body nor ';' separates two class, struct or union declarations"); }
  2276. | aggr attributes
  2277. { $$ = build_tree_list ($2, $1); }
  2278. ;
  2279. class_head:
  2280. aggr identifier
  2281. {
  2282. current_aggr = $1;
  2283. $$ = build_tree_list (NULL_TREE, $2);
  2284. }
  2285. | aggr nested_name_specifier identifier
  2286. {
  2287. current_aggr = $1;
  2288. $$ = build_tree_list ($2, $3);
  2289. }
  2290. | aggr global_scope nested_name_specifier identifier
  2291. {
  2292. current_aggr = $1;
  2293. $$ = build_tree_list ($3, $4);
  2294. }
  2295. | aggr global_scope identifier
  2296. {
  2297. current_aggr = $1;
  2298. $$ = build_tree_list (global_namespace, $3);
  2299. }
  2300. ;
  2301. class_head_apparent_template:
  2302. aggr apparent_template_type
  2303. {
  2304. current_aggr = $1;
  2305. $$ = $2;
  2306. }
  2307. | aggr nested_name_specifier apparent_template_type
  2308. {
  2309. current_aggr = $1;
  2310. $$ = $3;
  2311. }
  2312. | aggr global_scope nested_name_specifier apparent_template_type
  2313. {
  2314. current_aggr = $1;
  2315. $$ = $4;
  2316. }
  2317. ;
  2318. class_head_decl:
  2319. class_head %prec EMPTY
  2320. {
  2321. $$.t = parse_handle_class_head (current_aggr,
  2322. TREE_PURPOSE ($1),
  2323. TREE_VALUE ($1),
  2324. 0, &$$.new_type_flag);
  2325. }
  2326. | aggr identifier_defn %prec EMPTY
  2327. {
  2328. current_aggr = $1;
  2329. $$.t = TYPE_MAIN_DECL (parse_xref_tag (current_aggr, $2, 0));
  2330. $$.new_type_flag = 1;
  2331. }
  2332. | class_head_apparent_template %prec EMPTY
  2333. {
  2334. $$.t = $1;
  2335. $$.new_type_flag = 0;
  2336. }
  2337. ;
  2338. class_head_defn:
  2339. class_head '{'
  2340. {
  2341. yyungetc ('{', 1);
  2342. $$.t = parse_handle_class_head (current_aggr,
  2343. TREE_PURPOSE ($1),
  2344. TREE_VALUE ($1),
  2345. 1,
  2346. &$$.new_type_flag);
  2347. }
  2348. | class_head ':'
  2349. {
  2350. yyungetc (':', 1);
  2351. $$.t = parse_handle_class_head (current_aggr,
  2352. TREE_PURPOSE ($1),
  2353. TREE_VALUE ($1),
  2354. 1, &$$.new_type_flag);
  2355. }
  2356. | class_head_apparent_template '{'
  2357. {
  2358. yyungetc ('{', 1);
  2359. $$.t = handle_class_head_apparent_template
  2360. ($1, &$$.new_type_flag);
  2361. }
  2362. | class_head_apparent_template ':'
  2363. {
  2364. yyungetc (':', 1);
  2365. $$.t = handle_class_head_apparent_template
  2366. ($1, &$$.new_type_flag);
  2367. }
  2368. | aggr identifier_defn '{'
  2369. {
  2370. yyungetc ('{', 1);
  2371. current_aggr = $1;
  2372. $$.t = parse_handle_class_head (current_aggr,
  2373. NULL_TREE, $2,
  2374. 1, &$$.new_type_flag);
  2375. }
  2376. | aggr identifier_defn ':'
  2377. {
  2378. yyungetc (':', 1);
  2379. current_aggr = $1;
  2380. $$.t = parse_handle_class_head (current_aggr,
  2381. NULL_TREE, $2,
  2382. 1, &$$.new_type_flag);
  2383. }
  2384. | aggr '{'
  2385. {
  2386. current_aggr = $1;
  2387. $$.t = TYPE_MAIN_DECL (parse_xref_tag ($1,
  2388. make_anon_name (),
  2389. 0));
  2390. $$.new_type_flag = 0;
  2391. CLASSTYPE_DECLARED_CLASS (TREE_TYPE ($$.t))
  2392. = $1 == class_type_node;
  2393. yyungetc ('{', 1);
  2394. }
  2395. ;
  2396. maybe_base_class_list:
  2397. /* empty */
  2398. { $$ = NULL_TREE; }
  2399. | ':' see_typename
  2400. { error ("no bases given following `:'");
  2401. $$ = NULL_TREE; }
  2402. | ':' see_typename base_class_list
  2403. { $$ = $3; }
  2404. ;
  2405. base_class_list:
  2406. base_class
  2407. | base_class_list ',' see_typename base_class
  2408. { $$ = chainon ($$, $4); }
  2409. ;
  2410. base_class:
  2411. base_class_1
  2412. { $$ = finish_base_specifier (access_default_node, $1); }
  2413. | base_class_access_list see_typename base_class_1
  2414. { $$ = finish_base_specifier ($1, $3); }
  2415. ;
  2416. base_class_1:
  2417. typename_sub
  2418. { if (!TYPE_P ($$))
  2419. $$ = error_mark_node; }
  2420. | nonnested_type
  2421. { $$ = TREE_TYPE ($$); }
  2422. ;
  2423. base_class_access_list:
  2424. VISSPEC see_typename
  2425. | SCSPEC see_typename
  2426. { if ($1 != ridpointers[(int)RID_VIRTUAL])
  2427. error ("`%D' access", $1);
  2428. $$ = access_default_virtual_node; }
  2429. | base_class_access_list VISSPEC see_typename
  2430. {
  2431. if ($1 != access_default_virtual_node)
  2432. error ("multiple access specifiers");
  2433. else if ($2 == access_public_node)
  2434. $$ = access_public_virtual_node;
  2435. else if ($2 == access_protected_node)
  2436. $$ = access_protected_virtual_node;
  2437. else /* $2 == access_private_node */
  2438. $$ = access_private_virtual_node;
  2439. }
  2440. | base_class_access_list SCSPEC see_typename
  2441. { if ($2 != ridpointers[(int)RID_VIRTUAL])
  2442. error ("`%D' access", $2);
  2443. else if ($$ == access_public_node)
  2444. $$ = access_public_virtual_node;
  2445. else if ($$ == access_protected_node)
  2446. $$ = access_protected_virtual_node;
  2447. else if ($$ == access_private_node)
  2448. $$ = access_private_virtual_node;
  2449. else
  2450. error ("multiple `virtual' specifiers");
  2451. }
  2452. ;
  2453. opt.component_decl_list:
  2454. | component_decl_list
  2455. | opt.component_decl_list access_specifier component_decl_list
  2456. | opt.component_decl_list access_specifier
  2457. ;
  2458. access_specifier:
  2459. VISSPEC ':'
  2460. {
  2461. current_access_specifier = $1;
  2462. }
  2463. ;
  2464. /* Note: we no longer warn about the semicolon after a component_decl_list.
  2465. ARM $9.2 says that the semicolon is optional, and therefore allowed. */
  2466. component_decl_list:
  2467. component_decl
  2468. {
  2469. finish_member_declaration ($1);
  2470. current_aggr = NULL_TREE;
  2471. reset_type_access_control ();
  2472. }
  2473. | component_decl_list component_decl
  2474. {
  2475. finish_member_declaration ($2);
  2476. current_aggr = NULL_TREE;
  2477. reset_type_access_control ();
  2478. }
  2479. ;
  2480. component_decl:
  2481. component_decl_1 ';'
  2482. | component_decl_1 '}'
  2483. { error ("missing ';' before right brace");
  2484. yyungetc ('}', 0); }
  2485. /* C++: handle constructors, destructors and inline functions */
  2486. /* note that INLINE is like a TYPESPEC */
  2487. | fn_def2 ':' /* base_init compstmt */
  2488. { $$ = finish_method ($$); }
  2489. | fn_def2 TRY /* base_init compstmt */
  2490. { $$ = finish_method ($$); }
  2491. | fn_def2 RETURN_KEYWORD /* base_init compstmt */
  2492. { $$ = finish_method ($$); }
  2493. | fn_def2 '{' /* nodecls compstmt */
  2494. { $$ = finish_method ($$); }
  2495. | ';'
  2496. { $$ = NULL_TREE; }
  2497. | extension component_decl
  2498. { $$ = $2;
  2499. pedantic = $1; }
  2500. | template_header component_decl
  2501. {
  2502. if ($2)
  2503. $$ = finish_member_template_decl ($2);
  2504. else
  2505. /* The component was already processed. */
  2506. $$ = NULL_TREE;
  2507. finish_template_decl ($1);
  2508. }
  2509. | template_header typed_declspecs ';'
  2510. {
  2511. $$ = finish_member_class_template ($2.t);
  2512. finish_template_decl ($1);
  2513. }
  2514. | bad_decl
  2515. { $$ = NULL_TREE; }
  2516. ;
  2517. component_decl_1:
  2518. /* Do not add a "typed_declspecs declarator" rule here for
  2519. speed; we need to call grok_x_components for enums, so the
  2520. speedup would be insignificant. */
  2521. typed_declspecs components
  2522. {
  2523. /* Most of the productions for component_decl only
  2524. allow the creation of one new member, so we call
  2525. finish_member_declaration in component_decl_list.
  2526. For this rule and the next, however, there can be
  2527. more than one member, e.g.:
  2528. int i, j;
  2529. and we need the first member to be fully
  2530. registered before the second is processed.
  2531. Therefore, the rules for components take care of
  2532. this processing. To avoid registering the
  2533. components more than once, we send NULL_TREE up
  2534. here; that lets finish_member_declaration know
  2535. that there is nothing to do. */
  2536. if (!$2)
  2537. grok_x_components ($1.t);
  2538. $$ = NULL_TREE;
  2539. }
  2540. | declmods notype_components
  2541. {
  2542. if (!$2)
  2543. grok_x_components ($1.t);
  2544. $$ = NULL_TREE;
  2545. }
  2546. | notype_declarator maybeasm maybe_attribute maybe_init
  2547. { $$ = grokfield ($$, NULL_TREE, $4, $2, $3); }
  2548. | constructor_declarator maybeasm maybe_attribute maybe_init
  2549. { $$ = grokfield ($$, NULL_TREE, $4, $2, $3); }
  2550. | ':' expr_no_commas
  2551. { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
  2552. | error
  2553. { $$ = NULL_TREE; }
  2554. /* These rules introduce a reduce/reduce conflict; in
  2555. typedef int foo, bar;
  2556. class A {
  2557. foo (bar);
  2558. };
  2559. should "A::foo" be declared as a function or "A::bar" as a data
  2560. member? In other words, is "bar" an after_type_declarator or a
  2561. parmlist? */
  2562. | declmods component_constructor_declarator maybeasm maybe_attribute maybe_init
  2563. { tree specs, attrs;
  2564. split_specs_attrs ($1.t, &specs, &attrs);
  2565. $$ = grokfield ($2, specs, $5, $3,
  2566. chainon ($4, attrs)); }
  2567. | component_constructor_declarator maybeasm maybe_attribute maybe_init
  2568. { $$ = grokfield ($$, NULL_TREE, $4, $2, $3); }
  2569. | using_decl
  2570. { $$ = do_class_using_decl ($1); }
  2571. ;
  2572. /* The case of exactly one component is handled directly by component_decl. */
  2573. /* ??? Huh? ^^^ */
  2574. components:
  2575. /* empty: possibly anonymous */
  2576. { $$ = 0; }
  2577. | component_declarator0
  2578. {
  2579. if (PROCESSING_REAL_TEMPLATE_DECL_P ())
  2580. $1 = finish_member_template_decl ($1);
  2581. finish_member_declaration ($1);
  2582. $$ = 1;
  2583. }
  2584. | components ',' component_declarator
  2585. {
  2586. check_multiple_declarators ();
  2587. if (PROCESSING_REAL_TEMPLATE_DECL_P ())
  2588. $3 = finish_member_template_decl ($3);
  2589. finish_member_declaration ($3);
  2590. $$ = 2;
  2591. }
  2592. ;
  2593. notype_components:
  2594. /* empty: possibly anonymous */
  2595. { $$ = 0; }
  2596. | notype_component_declarator0
  2597. {
  2598. if (PROCESSING_REAL_TEMPLATE_DECL_P ())
  2599. $1 = finish_member_template_decl ($1);
  2600. finish_member_declaration ($1);
  2601. $$ = 1;
  2602. }
  2603. | notype_components ',' notype_component_declarator
  2604. {
  2605. check_multiple_declarators ();
  2606. if (PROCESSING_REAL_TEMPLATE_DECL_P ())
  2607. $3 = finish_member_template_decl ($3);
  2608. finish_member_declaration ($3);
  2609. $$ = 2;
  2610. }
  2611. ;
  2612. component_declarator0:
  2613. after_type_component_declarator0
  2614. | notype_component_declarator0
  2615. ;
  2616. component_declarator:
  2617. after_type_component_declarator
  2618. | notype_component_declarator
  2619. ;
  2620. after_type_component_declarator0:
  2621. after_type_declarator maybeasm maybe_attribute maybe_init
  2622. { $$ = parse_field0 ($1, $<ftype>0.t, $<ftype>0.lookups,
  2623. $3, $2, $4); }
  2624. | tTYPENAME ':' expr_no_commas maybe_attribute
  2625. { $$ = parse_bitfield0 ($1, $<ftype>0.t, $<ftype>0.lookups,
  2626. $4, $3); }
  2627. ;
  2628. notype_component_declarator0:
  2629. notype_declarator maybeasm maybe_attribute maybe_init
  2630. { $$ = parse_field0 ($1, $<ftype>0.t, $<ftype>0.lookups,
  2631. $3, $2, $4); }
  2632. | constructor_declarator maybeasm maybe_attribute maybe_init
  2633. { $$ = parse_field0 ($1, $<ftype>0.t, $<ftype>0.lookups,
  2634. $3, $2, $4); }
  2635. | IDENTIFIER ':' expr_no_commas maybe_attribute
  2636. { $$ = parse_bitfield0 ($1, $<ftype>0.t, $<ftype>0.lookups,
  2637. $4, $3); }
  2638. | ':' expr_no_commas maybe_attribute
  2639. { $$ = parse_bitfield0 (NULL_TREE, $<ftype>0.t,
  2640. $<ftype>0.lookups, $3, $2); }
  2641. ;
  2642. after_type_component_declarator:
  2643. after_type_declarator maybeasm maybe_attribute maybe_init
  2644. { $$ = parse_field ($1, $3, $2, $4); }
  2645. | tTYPENAME ':' expr_no_commas maybe_attribute
  2646. { $$ = parse_bitfield ($1, $4, $3); }
  2647. ;
  2648. notype_component_declarator:
  2649. notype_declarator maybeasm maybe_attribute maybe_init
  2650. { $$ = parse_field ($1, $3, $2, $4); }
  2651. | IDENTIFIER ':' expr_no_commas maybe_attribute
  2652. { $$ = parse_bitfield ($1, $4, $3); }
  2653. | ':' expr_no_commas maybe_attribute
  2654. { $$ = parse_bitfield (NULL_TREE, $3, $2); }
  2655. ;
  2656. enumlist_opt:
  2657. enumlist maybecomma_warn
  2658. | maybecomma_warn
  2659. ;
  2660. /* We chain the enumerators in reverse order.
  2661. Because of the way enums are built, the order is
  2662. insignificant. Take advantage of this fact. */
  2663. enumlist:
  2664. enumerator
  2665. | enumlist ',' enumerator
  2666. ;
  2667. enumerator:
  2668. identifier
  2669. { build_enumerator ($1, NULL_TREE, current_enum_type); }
  2670. | identifier '=' expr_no_commas
  2671. { build_enumerator ($1, $3, current_enum_type); }
  2672. ;
  2673. /* ISO new-type-id (5.3.4) */
  2674. new_type_id:
  2675. type_specifier_seq new_declarator
  2676. { $$.t = build_tree_list ($1.t, $2);
  2677. $$.new_type_flag = $1.new_type_flag; }
  2678. | type_specifier_seq %prec EMPTY
  2679. { $$.t = build_tree_list ($1.t, NULL_TREE);
  2680. $$.new_type_flag = $1.new_type_flag; }
  2681. /* GNU extension to allow arrays of arbitrary types with
  2682. non-constant dimension. */
  2683. | '(' type_id ')' '[' expr ']'
  2684. {
  2685. if (pedantic)
  2686. pedwarn ("ISO C++ forbids array dimensions with parenthesized type in new");
  2687. $$.t = build_nt (ARRAY_REF, TREE_VALUE ($2.t), $5);
  2688. $$.t = build_tree_list (TREE_PURPOSE ($2.t), $$.t);
  2689. $$.new_type_flag = $2.new_type_flag;
  2690. }
  2691. ;
  2692. cv_qualifiers:
  2693. /* empty */ %prec EMPTY
  2694. { $$ = NULL_TREE; }
  2695. | cv_qualifiers CV_QUALIFIER
  2696. { $$ = tree_cons (NULL_TREE, $2, $$); }
  2697. ;
  2698. nonempty_cv_qualifiers:
  2699. CV_QUALIFIER
  2700. { $$.t = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
  2701. $$.new_type_flag = 0; }
  2702. | nonempty_cv_qualifiers CV_QUALIFIER
  2703. { $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
  2704. $$.new_type_flag = $1.new_type_flag; }
  2705. | attributes %prec EMPTY
  2706. { $$.t = hash_tree_cons ($1, NULL_TREE, NULL_TREE);
  2707. $$.new_type_flag = 0; }
  2708. | nonempty_cv_qualifiers attributes %prec EMPTY
  2709. { $$.t = hash_tree_cons ($2, NULL_TREE, $1.t);
  2710. $$.new_type_flag = $1.new_type_flag; }
  2711. ;
  2712. /* These rules must follow the rules for function declarations
  2713. and component declarations. That way, longer rules are preferred. */
  2714. /* An expression which will not live on the momentary obstack. */
  2715. maybe_parmlist:
  2716. '(' nonnull_exprlist ')'
  2717. { $$ = $2; }
  2718. | '(' parmlist ')'
  2719. { $$ = $2; }
  2720. | LEFT_RIGHT
  2721. { $$ = empty_parms (); }
  2722. | '(' error ')'
  2723. { $$ = NULL_TREE; }
  2724. ;
  2725. /* A declarator that is allowed only after an explicit typespec. */
  2726. after_type_declarator_intern:
  2727. after_type_declarator
  2728. | attributes after_type_declarator
  2729. {
  2730. /* Provide support for '(' attributes '*' declarator ')'
  2731. etc */
  2732. $$ = tree_cons ($1, $2, NULL_TREE);
  2733. }
  2734. ;
  2735. /* may all be followed by prec '.' */
  2736. after_type_declarator:
  2737. '*' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY
  2738. { $$ = make_pointer_declarator ($2.t, $3); }
  2739. | '&' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY
  2740. { $$ = make_reference_declarator ($2.t, $3); }
  2741. | '*' after_type_declarator_intern %prec UNARY
  2742. { $$ = make_pointer_declarator (NULL_TREE, $2); }
  2743. | '&' after_type_declarator_intern %prec UNARY
  2744. { $$ = make_reference_declarator (NULL_TREE, $2); }
  2745. | ptr_to_mem cv_qualifiers after_type_declarator_intern
  2746. { tree arg = make_pointer_declarator ($2, $3);
  2747. $$ = build_nt (SCOPE_REF, $1, arg);
  2748. }
  2749. | direct_after_type_declarator
  2750. ;
  2751. direct_after_type_declarator:
  2752. direct_after_type_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
  2753. { $$ = make_call_declarator ($$, $2, $3, $4); }
  2754. | direct_after_type_declarator '[' expr ']'
  2755. { $$ = build_nt (ARRAY_REF, $$, $3); }
  2756. | direct_after_type_declarator '[' ']'
  2757. { $$ = build_nt (ARRAY_REF, $$, NULL_TREE); }
  2758. | '(' after_type_declarator_intern ')'
  2759. { $$ = $2; }
  2760. | nested_name_specifier type_name %prec EMPTY
  2761. { push_nested_class ($1, 3);
  2762. $$ = build_nt (SCOPE_REF, $$, $2);
  2763. TREE_COMPLEXITY ($$) = current_class_depth; }
  2764. | type_name %prec EMPTY
  2765. ;
  2766. nonnested_type:
  2767. type_name %prec EMPTY
  2768. {
  2769. if (TREE_CODE ($1) == IDENTIFIER_NODE)
  2770. {
  2771. $$ = lookup_name ($1, 1);
  2772. maybe_note_name_used_in_class ($1, $$);
  2773. }
  2774. else
  2775. $$ = $1;
  2776. }
  2777. | global_scope type_name
  2778. {
  2779. if (TREE_CODE ($2) == IDENTIFIER_NODE)
  2780. $$ = IDENTIFIER_GLOBAL_VALUE ($2);
  2781. else
  2782. $$ = $2;
  2783. got_scope = NULL_TREE;
  2784. }
  2785. ;
  2786. complete_type_name:
  2787. nonnested_type
  2788. | nested_type
  2789. | global_scope nested_type
  2790. { $$ = $2; }
  2791. ;
  2792. nested_type:
  2793. nested_name_specifier type_name %prec EMPTY
  2794. { $$ = get_type_decl ($2); }
  2795. ;
  2796. /* A declarator allowed whether or not there has been
  2797. an explicit typespec. These cannot redeclare a typedef-name. */
  2798. notype_declarator_intern:
  2799. notype_declarator
  2800. | attributes notype_declarator
  2801. {
  2802. /* Provide support for '(' attributes '*' declarator ')'
  2803. etc */
  2804. $$ = tree_cons ($1, $2, NULL_TREE);
  2805. }
  2806. ;
  2807. notype_declarator:
  2808. '*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
  2809. { $$ = make_pointer_declarator ($2.t, $3); }
  2810. | '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
  2811. { $$ = make_reference_declarator ($2.t, $3); }
  2812. | '*' notype_declarator_intern %prec UNARY
  2813. { $$ = make_pointer_declarator (NULL_TREE, $2); }
  2814. | '&' notype_declarator_intern %prec UNARY
  2815. { $$ = make_reference_declarator (NULL_TREE, $2); }
  2816. | ptr_to_mem cv_qualifiers notype_declarator_intern
  2817. { tree arg = make_pointer_declarator ($2, $3);
  2818. $$ = build_nt (SCOPE_REF, $1, arg);
  2819. }
  2820. | direct_notype_declarator
  2821. ;
  2822. complex_notype_declarator:
  2823. '*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
  2824. { $$ = make_pointer_declarator ($2.t, $3); }
  2825. | '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
  2826. { $$ = make_reference_declarator ($2.t, $3); }
  2827. | '*' complex_notype_declarator %prec UNARY
  2828. { $$ = make_pointer_declarator (NULL_TREE, $2); }
  2829. | '&' complex_notype_declarator %prec UNARY
  2830. { $$ = make_reference_declarator (NULL_TREE, $2); }
  2831. | ptr_to_mem cv_qualifiers notype_declarator_intern
  2832. { tree arg = make_pointer_declarator ($2, $3);
  2833. $$ = build_nt (SCOPE_REF, $1, arg);
  2834. }
  2835. | complex_direct_notype_declarator
  2836. ;
  2837. complex_direct_notype_declarator:
  2838. direct_notype_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
  2839. { $$ = make_call_declarator ($$, $2, $3, $4); }
  2840. | '(' complex_notype_declarator ')'
  2841. { $$ = $2; }
  2842. | direct_notype_declarator '[' expr ']'
  2843. { $$ = build_nt (ARRAY_REF, $$, $3); }
  2844. | direct_notype_declarator '[' ']'
  2845. { $$ = build_nt (ARRAY_REF, $$, NULL_TREE); }
  2846. | notype_qualified_id
  2847. { enter_scope_of ($1); }
  2848. | global_scope notype_qualified_id
  2849. { enter_scope_of ($2); $$ = $2;}
  2850. | global_scope notype_unqualified_id
  2851. { $$ = build_nt (SCOPE_REF, global_namespace, $2);
  2852. enter_scope_of ($$);
  2853. }
  2854. | nested_name_specifier notype_template_declarator
  2855. { got_scope = NULL_TREE;
  2856. $$ = build_nt (SCOPE_REF, $1, $2);
  2857. enter_scope_of ($$);
  2858. }
  2859. ;
  2860. qualified_id:
  2861. nested_name_specifier unqualified_id
  2862. { got_scope = NULL_TREE;
  2863. $$ = build_nt (SCOPE_REF, $$, $2); }
  2864. | nested_name_specifier object_template_id
  2865. { got_scope = NULL_TREE;
  2866. $$ = build_nt (SCOPE_REF, $1, $2); }
  2867. ;
  2868. notype_qualified_id:
  2869. nested_name_specifier notype_unqualified_id
  2870. { got_scope = NULL_TREE;
  2871. $$ = build_nt (SCOPE_REF, $$, $2); }
  2872. | nested_name_specifier object_template_id
  2873. { got_scope = NULL_TREE;
  2874. $$ = build_nt (SCOPE_REF, $1, $2); }
  2875. ;
  2876. overqualified_id:
  2877. notype_qualified_id
  2878. | global_scope notype_qualified_id
  2879. { $$ = $2; }
  2880. ;
  2881. functional_cast:
  2882. typespec '(' nonnull_exprlist ')'
  2883. { $$ = build_functional_cast ($1.t, $3); }
  2884. | typespec '(' expr_or_declarator_intern ')'
  2885. { $$ = reparse_decl_as_expr ($1.t, $3); }
  2886. | typespec fcast_or_absdcl %prec EMPTY
  2887. { $$ = reparse_absdcl_as_expr ($1.t, $2); }
  2888. ;
  2889. type_name:
  2890. tTYPENAME
  2891. | SELFNAME
  2892. | template_type %prec EMPTY
  2893. ;
  2894. nested_name_specifier:
  2895. nested_name_specifier_1
  2896. | nested_name_specifier nested_name_specifier_1
  2897. { $$ = $2; }
  2898. | nested_name_specifier TEMPLATE explicit_template_type SCOPE
  2899. { got_scope = $$
  2900. = make_typename_type ($1, $3, tf_error | tf_parsing); }
  2901. /* Error handling per Core 125. */
  2902. | nested_name_specifier IDENTIFIER SCOPE
  2903. { got_scope = $$
  2904. = make_typename_type ($1, $2, tf_error | tf_parsing); }
  2905. | nested_name_specifier PTYPENAME SCOPE
  2906. { got_scope = $$
  2907. = make_typename_type ($1, $2, tf_error | tf_parsing); }
  2908. ;
  2909. /* Why the @#$%^& do type_name and notype_identifier need to be expanded
  2910. inline here?!? (jason) */
  2911. nested_name_specifier_1:
  2912. tTYPENAME SCOPE
  2913. {
  2914. if (TREE_CODE ($1) == IDENTIFIER_NODE)
  2915. {
  2916. $$ = lastiddecl;
  2917. maybe_note_name_used_in_class ($1, $$);
  2918. }
  2919. got_scope = $$ =
  2920. complete_type (TYPE_MAIN_VARIANT (TREE_TYPE ($$)));
  2921. }
  2922. | SELFNAME SCOPE
  2923. {
  2924. if (TREE_CODE ($1) == IDENTIFIER_NODE)
  2925. $$ = lastiddecl;
  2926. got_scope = $$ = TREE_TYPE ($$);
  2927. }
  2928. | NSNAME SCOPE
  2929. {
  2930. if (TREE_CODE ($$) == IDENTIFIER_NODE)
  2931. $$ = lastiddecl;
  2932. got_scope = $$;
  2933. }
  2934. | template_type SCOPE
  2935. { got_scope = $$ = complete_type (TREE_TYPE ($1)); }
  2936. ;
  2937. typename_sub:
  2938. typename_sub0
  2939. | global_scope typename_sub0
  2940. { $$ = $2; }
  2941. ;
  2942. typename_sub0:
  2943. typename_sub1 identifier %prec EMPTY
  2944. {
  2945. if (TYPE_P ($1))
  2946. $$ = make_typename_type ($1, $2, tf_error | tf_parsing);
  2947. else if (TREE_CODE ($2) == IDENTIFIER_NODE)
  2948. error ("`%T' is not a class or namespace", $2);
  2949. else
  2950. {
  2951. $$ = $2;
  2952. if (TREE_CODE ($$) == TYPE_DECL)
  2953. $$ = TREE_TYPE ($$);
  2954. }
  2955. }
  2956. | typename_sub1 template_type %prec EMPTY
  2957. { $$ = TREE_TYPE ($2); }
  2958. | typename_sub1 explicit_template_type %prec EMPTY
  2959. { $$ = make_typename_type ($1, $2, tf_error | tf_parsing); }
  2960. | typename_sub1 TEMPLATE explicit_template_type %prec EMPTY
  2961. { $$ = make_typename_type ($1, $3, tf_error | tf_parsing); }
  2962. ;
  2963. typename_sub1:
  2964. typename_sub2
  2965. {
  2966. if (TREE_CODE ($1) == IDENTIFIER_NODE)
  2967. error ("`%T' is not a class or namespace", $1);
  2968. else if (TREE_CODE ($1) == TYPE_DECL)
  2969. $$ = TREE_TYPE ($1);
  2970. }
  2971. | typename_sub1 typename_sub2
  2972. {
  2973. if (TYPE_P ($1))
  2974. $$ = make_typename_type ($1, $2, tf_error | tf_parsing);
  2975. else if (TREE_CODE ($2) == IDENTIFIER_NODE)
  2976. error ("`%T' is not a class or namespace", $2);
  2977. else
  2978. {
  2979. $$ = $2;
  2980. if (TREE_CODE ($$) == TYPE_DECL)
  2981. $$ = TREE_TYPE ($$);
  2982. }
  2983. }
  2984. | typename_sub1 explicit_template_type SCOPE
  2985. { got_scope = $$
  2986. = make_typename_type ($1, $2, tf_error | tf_parsing); }
  2987. | typename_sub1 TEMPLATE explicit_template_type SCOPE
  2988. { got_scope = $$
  2989. = make_typename_type ($1, $3, tf_error | tf_parsing); }
  2990. ;
  2991. /* This needs to return a TYPE_DECL for simple names so that we don't
  2992. forget what name was used. */
  2993. typename_sub2:
  2994. tTYPENAME SCOPE
  2995. {
  2996. if (TREE_CODE ($1) != TYPE_DECL)
  2997. $$ = lastiddecl;
  2998. /* Retrieve the type for the identifier, which might involve
  2999. some computation. */
  3000. got_scope = complete_type (TREE_TYPE ($$));
  3001. if ($$ == error_mark_node)
  3002. error ("`%T' is not a class or namespace", $1);
  3003. }
  3004. | SELFNAME SCOPE
  3005. {
  3006. if (TREE_CODE ($1) != TYPE_DECL)
  3007. $$ = lastiddecl;
  3008. got_scope = complete_type (TREE_TYPE ($$));
  3009. }
  3010. | template_type SCOPE
  3011. { got_scope = $$ = complete_type (TREE_TYPE ($$)); }
  3012. | PTYPENAME SCOPE
  3013. | IDENTIFIER SCOPE
  3014. | NSNAME SCOPE
  3015. {
  3016. if (TREE_CODE ($$) == IDENTIFIER_NODE)
  3017. $$ = lastiddecl;
  3018. got_scope = $$;
  3019. }
  3020. ;
  3021. explicit_template_type:
  3022. identifier '<' template_arg_list_opt template_close_bracket
  3023. { $$ = build_min_nt (TEMPLATE_ID_EXPR, $1, $3); }
  3024. ;
  3025. complex_type_name:
  3026. global_scope type_name
  3027. {
  3028. if (TREE_CODE ($2) == IDENTIFIER_NODE)
  3029. $$ = IDENTIFIER_GLOBAL_VALUE ($2);
  3030. else
  3031. $$ = $2;
  3032. got_scope = NULL_TREE;
  3033. }
  3034. | nested_type
  3035. | global_scope nested_type
  3036. { $$ = $2; }
  3037. ;
  3038. ptr_to_mem:
  3039. nested_name_specifier '*'
  3040. { got_scope = NULL_TREE; }
  3041. | global_scope nested_name_specifier '*'
  3042. { $$ = $2; got_scope = NULL_TREE; }
  3043. ;
  3044. /* All uses of explicit global scope must go through this nonterminal so
  3045. that got_scope will be set before yylex is called to get the next token. */
  3046. global_scope:
  3047. SCOPE
  3048. { got_scope = void_type_node; }
  3049. ;
  3050. /* ISO new-declarator (5.3.4) */
  3051. new_declarator:
  3052. '*' cv_qualifiers new_declarator
  3053. { $$ = make_pointer_declarator ($2, $3); }
  3054. | '*' cv_qualifiers %prec EMPTY
  3055. { $$ = make_pointer_declarator ($2, NULL_TREE); }
  3056. | '&' cv_qualifiers new_declarator %prec EMPTY
  3057. { $$ = make_reference_declarator ($2, $3); }
  3058. | '&' cv_qualifiers %prec EMPTY
  3059. { $$ = make_reference_declarator ($2, NULL_TREE); }
  3060. | ptr_to_mem cv_qualifiers %prec EMPTY
  3061. { tree arg = make_pointer_declarator ($2, NULL_TREE);
  3062. $$ = build_nt (SCOPE_REF, $1, arg);
  3063. }
  3064. | ptr_to_mem cv_qualifiers new_declarator
  3065. { tree arg = make_pointer_declarator ($2, $3);
  3066. $$ = build_nt (SCOPE_REF, $1, arg);
  3067. }
  3068. | direct_new_declarator %prec EMPTY
  3069. ;
  3070. /* ISO direct-new-declarator (5.3.4) */
  3071. direct_new_declarator:
  3072. '[' expr ']'
  3073. { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
  3074. | direct_new_declarator '[' expr ']'
  3075. { $$ = build_nt (ARRAY_REF, $$, $3); }
  3076. ;
  3077. absdcl_intern:
  3078. absdcl
  3079. | attributes absdcl
  3080. {
  3081. /* Provide support for '(' attributes '*' declarator ')'
  3082. etc */
  3083. $$ = tree_cons ($1, $2, NULL_TREE);
  3084. }
  3085. ;
  3086. /* ISO abstract-declarator (8.1) */
  3087. absdcl:
  3088. '*' nonempty_cv_qualifiers absdcl_intern
  3089. { $$ = make_pointer_declarator ($2.t, $3); }
  3090. | '*' absdcl_intern
  3091. { $$ = make_pointer_declarator (NULL_TREE, $2); }
  3092. | '*' nonempty_cv_qualifiers %prec EMPTY
  3093. { $$ = make_pointer_declarator ($2.t, NULL_TREE); }
  3094. | '*' %prec EMPTY
  3095. { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
  3096. | '&' nonempty_cv_qualifiers absdcl_intern
  3097. { $$ = make_reference_declarator ($2.t, $3); }
  3098. | '&' absdcl_intern
  3099. { $$ = make_reference_declarator (NULL_TREE, $2); }
  3100. | '&' nonempty_cv_qualifiers %prec EMPTY
  3101. { $$ = make_reference_declarator ($2.t, NULL_TREE); }
  3102. | '&' %prec EMPTY
  3103. { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
  3104. | ptr_to_mem cv_qualifiers %prec EMPTY
  3105. { tree arg = make_pointer_declarator ($2, NULL_TREE);
  3106. $$ = build_nt (SCOPE_REF, $1, arg);
  3107. }
  3108. | ptr_to_mem cv_qualifiers absdcl_intern
  3109. { tree arg = make_pointer_declarator ($2, $3);
  3110. $$ = build_nt (SCOPE_REF, $1, arg);
  3111. }
  3112. | direct_abstract_declarator %prec EMPTY
  3113. ;
  3114. /* ISO direct-abstract-declarator (8.1) */
  3115. direct_abstract_declarator:
  3116. '(' absdcl_intern ')'
  3117. { $$ = $2; }
  3118. /* `(typedef)1' is `int'. */
  3119. | direct_abstract_declarator '(' parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
  3120. { $$ = make_call_declarator ($$, $3, $5, $6); }
  3121. | direct_abstract_declarator LEFT_RIGHT cv_qualifiers exception_specification_opt %prec '.'
  3122. { $$ = make_call_declarator ($$, empty_parms (), $3, $4); }
  3123. | direct_abstract_declarator '[' expr ']' %prec '.'
  3124. { $$ = build_nt (ARRAY_REF, $$, $3); }
  3125. | direct_abstract_declarator '[' ']' %prec '.'
  3126. { $$ = build_nt (ARRAY_REF, $$, NULL_TREE); }
  3127. | '(' complex_parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
  3128. { $$ = make_call_declarator (NULL_TREE, $2, $4, $5); }
  3129. | regcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
  3130. { set_quals_and_spec ($$, $2, $3); }
  3131. | fcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
  3132. { set_quals_and_spec ($$, $2, $3); }
  3133. | '[' expr ']' %prec '.'
  3134. { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
  3135. | '[' ']' %prec '.'
  3136. { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
  3137. ;
  3138. /* For C++, decls and stmts can be intermixed, so we don't need to
  3139. have a special rule that won't start parsing the stmt section
  3140. until we have a stmt that parses without errors. */
  3141. stmts:
  3142. stmt
  3143. | errstmt
  3144. | stmts stmt
  3145. | stmts errstmt
  3146. ;
  3147. errstmt:
  3148. error ';'
  3149. ;
  3150. /* Read zero or more forward-declarations for labels
  3151. that nested functions can jump to. */
  3152. maybe_label_decls:
  3153. /* empty */
  3154. | label_decls
  3155. { if (pedantic)
  3156. pedwarn ("ISO C++ forbids label declarations"); }
  3157. ;
  3158. label_decls:
  3159. label_decl
  3160. | label_decls label_decl
  3161. ;
  3162. label_decl:
  3163. LABEL identifiers_or_typenames ';'
  3164. {
  3165. while ($2)
  3166. {
  3167. finish_label_decl (TREE_VALUE ($2));
  3168. $2 = TREE_CHAIN ($2);
  3169. }
  3170. }
  3171. ;
  3172. compstmt_or_stmtexpr:
  3173. save_lineno '{'
  3174. { $<ttype>$ = begin_compound_stmt (0); }
  3175. compstmtend
  3176. { STMT_LINENO ($<ttype>3) = $1;
  3177. finish_compound_stmt (0, $<ttype>3); }
  3178. ;
  3179. compstmt:
  3180. compstmt_or_stmtexpr
  3181. { last_expr_type = NULL_TREE; }
  3182. ;
  3183. simple_if:
  3184. IF
  3185. { $<ttype>$ = begin_if_stmt ();
  3186. cond_stmt_keyword = "if"; }
  3187. paren_cond_or_null
  3188. { finish_if_stmt_cond ($3, $<ttype>2); }
  3189. implicitly_scoped_stmt
  3190. { $$ = $<ttype>2;
  3191. finish_then_clause ($<ttype>2); }
  3192. ;
  3193. implicitly_scoped_stmt:
  3194. compstmt
  3195. |
  3196. { $<ttype>$ = begin_compound_stmt (0); }
  3197. save_lineno simple_stmt
  3198. { STMT_LINENO ($<ttype>1) = $2;
  3199. if ($3) STMT_LINENO ($3) = $2;
  3200. finish_compound_stmt (0, $<ttype>1); }
  3201. ;
  3202. stmt:
  3203. pragma_directives
  3204. | openmp_construct
  3205. {}
  3206. | compstmt
  3207. | save_lineno simple_stmt
  3208. { if ($2) STMT_LINENO ($2) = $1; }
  3209. ;
  3210. simple_stmt:
  3211. decl
  3212. { finish_stmt ();
  3213. $$ = NULL_TREE; }
  3214. | expr ';'
  3215. { $$ = finish_expr_stmt ($1); }
  3216. | simple_if ELSE
  3217. { begin_else_clause (); }
  3218. implicitly_scoped_stmt
  3219. {
  3220. $$ = $1;
  3221. finish_else_clause ($1);
  3222. finish_if_stmt ();
  3223. }
  3224. | simple_if %prec IF
  3225. { $$ = $1;
  3226. finish_if_stmt (); }
  3227. | WHILE
  3228. {
  3229. $<ttype>$ = begin_while_stmt ();
  3230. cond_stmt_keyword = "while";
  3231. }
  3232. paren_cond_or_null
  3233. { finish_while_stmt_cond ($3, $<ttype>2); }
  3234. implicitly_scoped_stmt
  3235. { $$ = $<ttype>2;
  3236. finish_while_stmt ($<ttype>2); }
  3237. | DO
  3238. { $<ttype>$ = begin_do_stmt (); }
  3239. implicitly_scoped_stmt WHILE
  3240. {
  3241. finish_do_body ($<ttype>2);
  3242. cond_stmt_keyword = "do";
  3243. }
  3244. paren_expr_or_null ';'
  3245. { $$ = $<ttype>2;
  3246. finish_do_stmt ($6, $<ttype>2); }
  3247. | FOR
  3248. { $<ttype>$ = begin_for_stmt (); }
  3249. '(' for.init.statement
  3250. { finish_for_init_stmt ($<ttype>2); }
  3251. xcond ';'
  3252. { finish_for_cond ($6, $<ttype>2); }
  3253. xexpr ')'
  3254. { finish_for_expr ($9, $<ttype>2); }
  3255. implicitly_scoped_stmt
  3256. { $$ = $<ttype>2;
  3257. finish_for_stmt ($<ttype>2); }
  3258. | SWITCH
  3259. { $<ttype>$ = begin_switch_stmt (); }
  3260. '(' condition ')'
  3261. { finish_switch_cond ($4, $<ttype>2); }
  3262. implicitly_scoped_stmt
  3263. { $$ = $<ttype>2;
  3264. finish_switch_stmt ($<ttype>2); }
  3265. | CASE expr_no_commas ':'
  3266. { $<ttype>$ = finish_case_label ($2, NULL_TREE); }
  3267. stmt
  3268. { $$ = $<ttype>4; }
  3269. | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
  3270. { $<ttype>$ = finish_case_label ($2, $4); }
  3271. stmt
  3272. { $$ = $<ttype>6; }
  3273. | DEFAULT ':'
  3274. { $<ttype>$ = finish_case_label (NULL_TREE, NULL_TREE); }
  3275. stmt
  3276. { $$ = $<ttype>3; }
  3277. | BREAK ';'
  3278. { $$ = finish_break_stmt (); }
  3279. | CONTINUE ';'
  3280. { $$ = finish_continue_stmt (); }
  3281. | RETURN_KEYWORD ';'
  3282. { $$ = finish_return_stmt (NULL_TREE); }
  3283. | RETURN_KEYWORD expr ';'
  3284. { $$ = finish_return_stmt ($2); }
  3285. | asm_keyword maybe_cv_qualifier '(' STRING ')' ';'
  3286. { $$ = finish_asm_stmt ($2, $4, NULL_TREE, NULL_TREE,
  3287. NULL_TREE);
  3288. ASM_INPUT_P ($$) = 1; }
  3289. /* This is the case with just output operands. */
  3290. | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ')' ';'
  3291. { $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); }
  3292. /* This is the case with input operands as well. */
  3293. | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':'
  3294. asm_operands ')' ';'
  3295. { $$ = finish_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
  3296. | asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ')' ';'
  3297. { $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, NULL_TREE); }
  3298. /* This is the case with clobbered registers as well. */
  3299. | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':'
  3300. asm_operands ':' asm_clobbers ')' ';'
  3301. { $$ = finish_asm_stmt ($2, $4, $6, $8, $10); }
  3302. | asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ':'
  3303. asm_clobbers ')' ';'
  3304. { $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, $8); }
  3305. | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands SCOPE
  3306. asm_clobbers ')' ';'
  3307. { $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, $8); }
  3308. | GOTO '*' expr ';'
  3309. {
  3310. if (pedantic)
  3311. pedwarn ("ISO C++ forbids computed gotos");
  3312. $$ = finish_goto_stmt ($3);
  3313. }
  3314. | GOTO identifier ';'
  3315. { $$ = finish_goto_stmt ($2); }
  3316. | label_colon stmt
  3317. { $$ = NULL_TREE; }
  3318. | label_colon '}'
  3319. { error ("label must be followed by statement");
  3320. yyungetc ('}', 0);
  3321. $$ = NULL_TREE; }
  3322. | ';'
  3323. { finish_stmt ();
  3324. $$ = NULL_TREE; }
  3325. | try_block
  3326. { $$ = NULL_TREE; }
  3327. | using_directive
  3328. { $$ = NULL_TREE; }
  3329. | namespace_using_decl
  3330. { do_local_using_decl ($1);
  3331. $$ = NULL_TREE; }
  3332. | namespace_alias
  3333. { $$ = NULL_TREE; }
  3334. ;
  3335. function_try_block:
  3336. TRY
  3337. { $<ttype>$ = begin_function_try_block (); }
  3338. function_body
  3339. { finish_function_try_block ($<ttype>2); }
  3340. handler_seq
  3341. { finish_function_handler_sequence ($<ttype>2); }
  3342. ;
  3343. try_block:
  3344. TRY
  3345. { $<ttype>$ = begin_try_block (); }
  3346. compstmt
  3347. { finish_try_block ($<ttype>2); }
  3348. handler_seq
  3349. { finish_handler_sequence ($<ttype>2); }
  3350. ;
  3351. handler_seq:
  3352. handler
  3353. | handler_seq handler
  3354. | /* empty */
  3355. { /* Generate a fake handler block to avoid later aborts. */
  3356. tree fake_handler = begin_handler ();
  3357. finish_handler_parms (NULL_TREE, fake_handler);
  3358. finish_handler (fake_handler);
  3359. $<ttype>$ = fake_handler;
  3360. error ("must have at least one catch per try block");
  3361. }
  3362. ;
  3363. handler:
  3364. CATCH
  3365. { $<ttype>$ = begin_handler (); }
  3366. handler_args
  3367. { finish_handler_parms ($3, $<ttype>2); }
  3368. compstmt
  3369. { finish_handler ($<ttype>2); }
  3370. ;
  3371. type_specifier_seq:
  3372. typed_typespecs %prec EMPTY
  3373. | nonempty_cv_qualifiers %prec EMPTY
  3374. ;
  3375. handler_args:
  3376. '(' ELLIPSIS ')'
  3377. { $$ = NULL_TREE; }
  3378. /* This doesn't allow reference parameters, the below does.
  3379. | '(' type_specifier_seq absdcl ')'
  3380. { check_for_new_type ("inside exception declarations", $2);
  3381. expand_start_catch_block ($2.t, $3); }
  3382. | '(' type_specifier_seq ')'
  3383. { check_for_new_type ("inside exception declarations", $2);
  3384. expand_start_catch_block ($2.t, NULL_TREE); }
  3385. | '(' type_specifier_seq notype_declarator ')'
  3386. { check_for_new_type ("inside exception declarations", $2);
  3387. expand_start_catch_block ($2.t, $3); }
  3388. | '(' typed_typespecs after_type_declarator ')'
  3389. { check_for_new_type ("inside exception declarations", $2);
  3390. expand_start_catch_block ($2.t, $3); }
  3391. This allows reference parameters... */
  3392. | '(' parm ')'
  3393. {
  3394. check_for_new_type ("inside exception declarations", $2);
  3395. $$ = start_handler_parms (TREE_PURPOSE ($2.t),
  3396. TREE_VALUE ($2.t));
  3397. }
  3398. ;
  3399. label_colon:
  3400. IDENTIFIER ':'
  3401. { finish_label_stmt ($1); }
  3402. | PTYPENAME ':'
  3403. { finish_label_stmt ($1); }
  3404. | tTYPENAME ':'
  3405. { finish_label_stmt ($1); }
  3406. | SELFNAME ':'
  3407. { finish_label_stmt ($1); }
  3408. ;
  3409. for.init.statement:
  3410. xexpr ';'
  3411. { finish_expr_stmt ($1); }
  3412. | decl
  3413. | '{' compstmtend
  3414. { if (pedantic)
  3415. pedwarn ("ISO C++ forbids compound statements inside for initializations");
  3416. }
  3417. ;
  3418. /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
  3419. maybe_cv_qualifier:
  3420. /* empty */
  3421. { $$ = NULL_TREE; }
  3422. | CV_QUALIFIER
  3423. ;
  3424. xexpr:
  3425. /* empty */
  3426. { $$ = NULL_TREE; }
  3427. | expr
  3428. | error
  3429. { $$ = NULL_TREE; }
  3430. ;
  3431. /* These are the operands other than the first string and colon
  3432. in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
  3433. asm_operands:
  3434. /* empty */
  3435. { $$ = NULL_TREE; }
  3436. | nonnull_asm_operands
  3437. ;
  3438. nonnull_asm_operands:
  3439. asm_operand
  3440. | nonnull_asm_operands ',' asm_operand
  3441. { $$ = chainon ($$, $3); }
  3442. ;
  3443. asm_operand:
  3444. STRING '(' expr ')'
  3445. { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); }
  3446. | '[' identifier ']' STRING '(' expr ')'
  3447. { $2 = build_string (IDENTIFIER_LENGTH ($2),
  3448. IDENTIFIER_POINTER ($2));
  3449. $$ = build_tree_list (build_tree_list ($2, $4), $6); }
  3450. ;
  3451. asm_clobbers:
  3452. STRING
  3453. { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);}
  3454. | asm_clobbers ',' STRING
  3455. { $$ = tree_cons (NULL_TREE, $3, $1); }
  3456. ;
  3457. /* This is what appears inside the parens in a function declarator.
  3458. Its value is represented in the format that grokdeclarator expects.
  3459. In C++, declaring a function with no parameters
  3460. means that that function takes *no* parameters. */
  3461. parmlist:
  3462. /* empty */
  3463. {
  3464. $$ = empty_parms();
  3465. }
  3466. | complex_parmlist
  3467. | type_id
  3468. { $$ = finish_parmlist (build_tree_list (NULL_TREE, $1.t), 0);
  3469. check_for_new_type ("inside parameter list", $1); }
  3470. ;
  3471. /* This nonterminal does not include the common sequence '(' type_id ')',
  3472. as it is ambiguous and must be disambiguated elsewhere. */
  3473. complex_parmlist:
  3474. parms
  3475. { $$ = finish_parmlist ($$, 0); }
  3476. | parms_comma ELLIPSIS
  3477. { $$ = finish_parmlist ($1, 1); }
  3478. /* C++ allows an ellipsis without a separating ',' */
  3479. | parms ELLIPSIS
  3480. { $$ = finish_parmlist ($1, 1); }
  3481. | type_id ELLIPSIS
  3482. { $$ = finish_parmlist (build_tree_list (NULL_TREE,
  3483. $1.t), 1); }
  3484. | ELLIPSIS
  3485. { $$ = finish_parmlist (NULL_TREE, 1); }
  3486. | parms ':'
  3487. {
  3488. /* This helps us recover from really nasty
  3489. parse errors, for example, a missing right
  3490. parenthesis. */
  3491. yyerror ("possibly missing ')'");
  3492. $$ = finish_parmlist ($1, 0);
  3493. yyungetc (':', 0);
  3494. yychar = ')';
  3495. }
  3496. | type_id ':'
  3497. {
  3498. /* This helps us recover from really nasty
  3499. parse errors, for example, a missing right
  3500. parenthesis. */
  3501. yyerror ("possibly missing ')'");
  3502. $$ = finish_parmlist (build_tree_list (NULL_TREE,
  3503. $1.t), 0);
  3504. yyungetc (':', 0);
  3505. yychar = ')';
  3506. }
  3507. ;
  3508. /* A default argument to a */
  3509. defarg:
  3510. '='
  3511. { maybe_snarf_defarg (); }
  3512. defarg1
  3513. { $$ = $3; }
  3514. ;
  3515. defarg1:
  3516. DEFARG
  3517. | init
  3518. ;
  3519. /* A nonempty list of parameter declarations or type names. */
  3520. parms:
  3521. named_parm
  3522. { check_for_new_type ("in a parameter list", $1);
  3523. $$ = build_tree_list (NULL_TREE, $1.t); }
  3524. | parm defarg
  3525. { check_for_new_type ("in a parameter list", $1);
  3526. $$ = build_tree_list ($2, $1.t); }
  3527. | parms_comma full_parm
  3528. { check_for_new_type ("in a parameter list", $2);
  3529. $$ = chainon ($$, $2.t); }
  3530. | parms_comma bad_parm
  3531. { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
  3532. | parms_comma bad_parm '=' init
  3533. { $$ = chainon ($$, build_tree_list ($4, $2)); }
  3534. ;
  3535. parms_comma:
  3536. parms ','
  3537. | type_id ','
  3538. { check_for_new_type ("in a parameter list", $1);
  3539. $$ = build_tree_list (NULL_TREE, $1.t); }
  3540. ;
  3541. /* A single parameter declaration or parameter type name,
  3542. as found in a parmlist. */
  3543. /* Add support for GNU 3.4's attributes for function parameters */
  3544. named_parm:
  3545. /* Here we expand typed_declspecs inline to avoid mis-parsing of
  3546. TYPESPEC IDENTIFIER. */
  3547. typed_declspecs1 declarator maybe_attribute
  3548. { $$.new_type_flag = $1.new_type_flag;
  3549. $$.t = build_tree_list ($1.t, $2); }
  3550. | typed_typespecs declarator maybe_attribute
  3551. { $$.t = build_tree_list ($1.t, $2);
  3552. $$.new_type_flag = $1.new_type_flag; }
  3553. | typespec declarator maybe_attribute
  3554. { $$.t = build_tree_list (build_tree_list (NULL_TREE, $1.t),
  3555. $2);
  3556. $$.new_type_flag = $1.new_type_flag; }
  3557. | typed_declspecs1 absdcl maybe_attribute
  3558. { $$.t = build_tree_list ($1.t, $2);
  3559. $$.new_type_flag = $1.new_type_flag; }
  3560. | typed_declspecs1 maybe_attribute %prec EMPTY
  3561. { $$.t = build_tree_list ($1.t, NULL_TREE);
  3562. $$.new_type_flag = $1.new_type_flag; }
  3563. | declmods notype_declarator maybe_attribute
  3564. { $$.t = build_tree_list ($1.t, $2);
  3565. $$.new_type_flag = 0; }
  3566. ;
  3567. full_parm:
  3568. parm
  3569. { $$.t = build_tree_list (NULL_TREE, $1.t);
  3570. $$.new_type_flag = $1.new_type_flag; }
  3571. | parm defarg
  3572. { $$.t = build_tree_list ($2, $1.t);
  3573. $$.new_type_flag = $1.new_type_flag; }
  3574. ;
  3575. parm:
  3576. named_parm
  3577. | type_id
  3578. ;
  3579. see_typename:
  3580. /* empty */ %prec EMPTY
  3581. { see_typename (); }
  3582. ;
  3583. bad_parm:
  3584. /* empty */ %prec EMPTY
  3585. {
  3586. error ("type specifier omitted for parameter");
  3587. $$ = build_tree_list (integer_type_node, NULL_TREE);
  3588. }
  3589. | notype_declarator
  3590. {
  3591. if (TREE_CODE ($$) == SCOPE_REF)
  3592. {
  3593. if (TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TYPE_PARM
  3594. || TREE_CODE (TREE_OPERAND ($$, 0)) == BOUND_TEMPLATE_TEMPLATE_PARM)
  3595. error ("`%E' is not a type, use `typename %E' to make it one", $$, $$);
  3596. else
  3597. error ("no type `%D' in `%T'", TREE_OPERAND ($$, 1), TREE_OPERAND ($$, 0));
  3598. }
  3599. else
  3600. error ("type specifier omitted for parameter `%E'", $$);
  3601. $$ = build_tree_list (integer_type_node, $$);
  3602. }
  3603. ;
  3604. bad_decl:
  3605. IDENTIFIER template_arg_list_ignore IDENTIFIER arg_list_ignore ';'
  3606. {
  3607. error("'%D' is used as a type, but is not defined as a type.", $1);
  3608. $3 = error_mark_node;
  3609. }
  3610. ;
  3611. template_arg_list_ignore:
  3612. '<' template_arg_list_opt template_close_bracket
  3613. { }
  3614. | /* empty */
  3615. ;
  3616. arg_list_ignore:
  3617. '(' nonnull_exprlist ')'
  3618. { }
  3619. | /* empty */
  3620. ;
  3621. exception_specification_opt:
  3622. /* empty */ %prec EMPTY
  3623. { $$ = NULL_TREE; }
  3624. | THROW '(' ansi_raise_identifiers ')' %prec EMPTY
  3625. { $$ = $3; }
  3626. | THROW LEFT_RIGHT %prec EMPTY
  3627. { $$ = empty_except_spec; }
  3628. ;
  3629. ansi_raise_identifier:
  3630. type_id
  3631. {
  3632. check_for_new_type ("exception specifier", $1);
  3633. $$ = groktypename ($1.t);
  3634. }
  3635. | error
  3636. { $$ = error_mark_node; }
  3637. ;
  3638. ansi_raise_identifiers:
  3639. ansi_raise_identifier
  3640. { $$ = add_exception_specifier (NULL_TREE, $1, 1); }
  3641. | ansi_raise_identifiers ',' ansi_raise_identifier
  3642. { $$ = add_exception_specifier ($1, $3, 1); }
  3643. ;
  3644. conversion_declarator:
  3645. /* empty */ %prec EMPTY
  3646. { $$ = NULL_TREE; }
  3647. | '*' cv_qualifiers conversion_declarator
  3648. { $$ = make_pointer_declarator ($2, $3); }
  3649. | '&' cv_qualifiers conversion_declarator
  3650. { $$ = make_reference_declarator ($2, $3); }
  3651. | ptr_to_mem cv_qualifiers conversion_declarator
  3652. { tree arg = make_pointer_declarator ($2, $3);
  3653. $$ = build_nt (SCOPE_REF, $1, arg);
  3654. }
  3655. ;
  3656. operator:
  3657. OPERATOR
  3658. {
  3659. saved_scopes = tree_cons (got_scope, got_object, saved_scopes);
  3660. TREE_LANG_FLAG_0 (saved_scopes) = looking_for_typename;
  3661. /* We look for conversion-type-id's in both the class and current
  3662. scopes, just as for ID in 'ptr->ID::'. */
  3663. looking_for_typename = 1;
  3664. got_object = got_scope;
  3665. got_scope = NULL_TREE;
  3666. }
  3667. ;
  3668. unoperator:
  3669. { got_scope = TREE_PURPOSE (saved_scopes);
  3670. got_object = TREE_VALUE (saved_scopes);
  3671. looking_for_typename = TREE_LANG_FLAG_0 (saved_scopes);
  3672. saved_scopes = TREE_CHAIN (saved_scopes);
  3673. $$ = got_scope;
  3674. }
  3675. ;
  3676. operator_name:
  3677. operator '*' unoperator
  3678. { $$ = frob_opname (ansi_opname (MULT_EXPR)); }
  3679. | operator '/' unoperator
  3680. { $$ = frob_opname (ansi_opname (TRUNC_DIV_EXPR)); }
  3681. | operator '%' unoperator
  3682. { $$ = frob_opname (ansi_opname (TRUNC_MOD_EXPR)); }
  3683. | operator '+' unoperator
  3684. { $$ = frob_opname (ansi_opname (PLUS_EXPR)); }
  3685. | operator '-' unoperator
  3686. { $$ = frob_opname (ansi_opname (MINUS_EXPR)); }
  3687. | operator '&' unoperator
  3688. { $$ = frob_opname (ansi_opname (BIT_AND_EXPR)); }
  3689. | operator '|' unoperator
  3690. { $$ = frob_opname (ansi_opname (BIT_IOR_EXPR)); }
  3691. | operator '^' unoperator
  3692. { $$ = frob_opname (ansi_opname (BIT_XOR_EXPR)); }
  3693. | operator '~' unoperator
  3694. { $$ = frob_opname (ansi_opname (BIT_NOT_EXPR)); }
  3695. | operator ',' unoperator
  3696. { $$ = frob_opname (ansi_opname (COMPOUND_EXPR)); }
  3697. | operator ARITHCOMPARE unoperator
  3698. { $$ = frob_opname (ansi_opname ($2)); }
  3699. | operator '<' unoperator
  3700. { $$ = frob_opname (ansi_opname (LT_EXPR)); }
  3701. | operator '>' unoperator
  3702. { $$ = frob_opname (ansi_opname (GT_EXPR)); }
  3703. | operator EQCOMPARE unoperator
  3704. { $$ = frob_opname (ansi_opname ($2)); }
  3705. | operator ASSIGN unoperator
  3706. { $$ = frob_opname (ansi_assopname ($2)); }
  3707. | operator '=' unoperator
  3708. { $$ = frob_opname (ansi_assopname (NOP_EXPR)); }
  3709. | operator LSHIFT unoperator
  3710. { $$ = frob_opname (ansi_opname ($2)); }
  3711. | operator RSHIFT unoperator
  3712. { $$ = frob_opname (ansi_opname ($2)); }
  3713. | operator PLUSPLUS unoperator
  3714. { $$ = frob_opname (ansi_opname (POSTINCREMENT_EXPR)); }
  3715. | operator MINUSMINUS unoperator
  3716. { $$ = frob_opname (ansi_opname (PREDECREMENT_EXPR)); }
  3717. | operator ANDAND unoperator
  3718. { $$ = frob_opname (ansi_opname (TRUTH_ANDIF_EXPR)); }
  3719. | operator OROR unoperator
  3720. { $$ = frob_opname (ansi_opname (TRUTH_ORIF_EXPR)); }
  3721. | operator '!' unoperator
  3722. { $$ = frob_opname (ansi_opname (TRUTH_NOT_EXPR)); }
  3723. | operator '?' ':' unoperator
  3724. { $$ = frob_opname (ansi_opname (COND_EXPR)); }
  3725. | operator MIN_MAX unoperator
  3726. { $$ = frob_opname (ansi_opname ($2)); }
  3727. | operator POINTSAT unoperator %prec EMPTY
  3728. { $$ = frob_opname (ansi_opname (COMPONENT_REF)); }
  3729. | operator POINTSAT_STAR unoperator %prec EMPTY
  3730. { $$ = frob_opname (ansi_opname (MEMBER_REF)); }
  3731. | operator LEFT_RIGHT unoperator
  3732. { $$ = frob_opname (ansi_opname (CALL_EXPR)); }
  3733. | operator '[' ']' unoperator
  3734. { $$ = frob_opname (ansi_opname (ARRAY_REF)); }
  3735. | operator NEW unoperator %prec EMPTY
  3736. { $$ = frob_opname (ansi_opname (NEW_EXPR)); }
  3737. | operator DELETE unoperator %prec EMPTY
  3738. { $$ = frob_opname (ansi_opname (DELETE_EXPR)); }
  3739. | operator NEW '[' ']' unoperator
  3740. { $$ = frob_opname (ansi_opname (VEC_NEW_EXPR)); }
  3741. | operator DELETE '[' ']' unoperator
  3742. { $$ = frob_opname (ansi_opname (VEC_DELETE_EXPR)); }
  3743. | operator type_specifier_seq conversion_declarator unoperator
  3744. { $$ = frob_opname (grokoptypename ($2.t, $3, $4)); }
  3745. | operator error unoperator
  3746. { $$ = frob_opname (ansi_opname (ERROR_MARK)); }
  3747. ;
  3748. /* The forced readahead in here is because we might be at the end of a
  3749. line, and lineno won't be bumped until yylex absorbs the first token
  3750. on the next line. */
  3751. save_lineno:
  3752. { if (yychar == YYEMPTY)
  3753. yychar = YYLEX;
  3754. $$ = lineno; }
  3755. ;
  3756. /********************** OpenMP *********************/
  3757. parallel_construct:
  3758. parallel_directive
  3759. {
  3760. $<ttype>$ = add_stmt (build_omp_stmt (parallel_dir_b, $1));
  3761. In_MP_Region = true;
  3762. mp_nesting++;
  3763. if (mp_nesting == MAX_MP_NESTING)
  3764. {
  3765. // will see
  3766. printf ("MP nesting > %d not supported\n", MAX_MP_NESTING-1);
  3767. abort();
  3768. }
  3769. mp_locals[mp_nesting] = NULL;
  3770. }
  3771. structured_block
  3772. {
  3773. add_stmt (build_omp_stmt (parallel_dir_e, NULL));
  3774. $$ = NULL;
  3775. In_MP_Region = false;
  3776. if (mp_locals[mp_nesting])
  3777. {
  3778. $<ttype>2->omp.omp_clause_list =
  3779. chain_parallel_list_on ($<ttype>2->omp.omp_clause_list,
  3780. build_parallel_clause_list (NULL, p_private, 0, 0));
  3781. $<ttype>2->omp.omp_clause_list =
  3782. chain_parallel_list_on ($<ttype>2->omp.omp_clause_list,
  3783. build_parallel_clause_list (mp_locals[mp_nesting],
  3784. p_private, 0, 0));
  3785. }
  3786. mp_locals[mp_nesting] = NULL;
  3787. mp_nesting--;
  3788. }
  3789. ;
  3790. parallel_directive:
  3791. OMP_PRAGMA OMP_PARALLEL '\n'
  3792. { $$ = NULL; }
  3793. | OMP_PRAGMA OMP_PARALLEL parallel_clause_list '\n'
  3794. { $$ = $3; }
  3795. ;
  3796. parallel_clause_list:
  3797. parallel_clause
  3798. { $$ = $1; }
  3799. | parallel_clause_list parallel_clause
  3800. { $$ = chain_parallel_list_on ($1, $2); }
  3801. ;
  3802. parallel_clause:
  3803. IF '(' expr_no_commas ')'
  3804. { $$ = build_parallel_clause_list($3, p_if, 0, 0); }
  3805. | OMP_NUM_THREADS '(' expr_no_commas ')'
  3806. { $$ = build_parallel_clause_list($3, p_num_threads, 0, 0); }
  3807. | OMP_PRIVATE '(' variable_list ')'
  3808. { $$ = build_parallel_clause_list($3, p_private, 0, 0); }
  3809. | OMP_FIRSTPRIVATE '(' variable_list ')'
  3810. { $$ = build_parallel_clause_list($3, p_firstprivate, 0, 0); }
  3811. | OMP_SHARED '(' variable_list ')'
  3812. { $$ = build_parallel_clause_list($3, p_shared, 0, 0); }
  3813. | DEFAULT '(' OMP_SHARED ')'
  3814. { $$ = build_parallel_clause_list(NULL, p_default, default_shared, 0); } | DEFAULT '(' OMP_NONE ')'
  3815. { $$ = build_parallel_clause_list(NULL, p_default, default_none, 0); }
  3816. | OMP_REDUCTION '(' reduction_operator ':' variable_list ')'
  3817. { $$ = build_parallel_clause_list($5, p_reduction, 0, $3); }
  3818. | OMP_COPYIN '(' variable_list ')'
  3819. { $$ = build_parallel_clause_list($3, p_copyin, 0, 0); }
  3820. ;
  3821. for_construct:
  3822. for_directive
  3823. {
  3824. add_stmt (build_omp_stmt (for_dir_b, $1));
  3825. $<ttype>$ = NULL;
  3826. }
  3827. iteration_statement
  3828. { add_stmt (build_omp_stmt (for_dir_e, NULL)); $$ = NULL; }
  3829. ;
  3830. /* taken from 'stmt' */
  3831. iteration_statement:
  3832. FOR
  3833. { $<ttype>$ = begin_for_stmt ();
  3834. TREE_ADDRESSABLE ($<ttype>$) = 1; /* generate DO-loop */ }
  3835. '(' for.init.statement
  3836. { finish_for_init_stmt ($<ttype>2); }
  3837. xcond ';'
  3838. { finish_for_cond ($6, $<ttype>2); }
  3839. xexpr ')'
  3840. { finish_for_expr ($9, $<ttype>2); }
  3841. implicitly_scoped_stmt
  3842. { $$ = $<ttype>2;
  3843. finish_for_stmt ($<ttype>2); }
  3844. ;
  3845. for_directive:
  3846. OMP_PRAGMA FOR '\n'
  3847. { $$ = NULL; }
  3848. | OMP_PRAGMA FOR for_clause_list '\n'
  3849. { $$ = $3; }
  3850. ;
  3851. for_clause_list:
  3852. for_clause
  3853. { $$ = $1; }
  3854. | for_clause_list for_clause
  3855. { $$ = chain_for_list_on ($1, $2); }
  3856. ;
  3857. for_clause:
  3858. OMP_PRIVATE '(' variable_list ')'
  3859. { $$ = build_for_clause_list($3, f_private, 0, 0); }
  3860. | OMP_FIRSTPRIVATE '(' variable_list ')'
  3861. { $$ = build_for_clause_list($3, f_firstprivate, 0, 0); }
  3862. | OMP_LASTPRIVATE '(' variable_list ')'
  3863. { $$ = build_for_clause_list($3, f_lastprivate, 0, 0); }
  3864. | OMP_REDUCTION '(' reduction_operator ':' variable_list ')'
  3865. { $$ = build_for_clause_list($5, f_reduction, 0, $3); }
  3866. | OMP_SCHEDULE '(' schedule_kind ')'
  3867. { $$ = build_for_clause_list(NULL, f_schedule_1, $3, 0); }
  3868. | OMP_SCHEDULE '(' schedule_kind ',' expr_no_commas ')'
  3869. { $$ = build_for_clause_list($5, f_schedule_2, $3, 0); }
  3870. | OMP_ORDERED
  3871. { $$ = build_for_clause_list(NULL, f_ordered, 0, 0); }
  3872. | OMP_NOWAIT
  3873. { $$ = build_for_clause_list(NULL, f_nowait, 0, 0); }
  3874. ;
  3875. schedule_kind:
  3876. OMP_STATIC
  3877. {
  3878. if (strcmp (IDENTIFIER_POINTER ($1), "static"))
  3879. error ("'%s' is not a valid schedule kind\n", IDENTIFIER_POINTER ($1));
  3880. else
  3881. $$=SK_STATIC; }
  3882. | OMP_DYNAMIC
  3883. { $$=SK_DYNAMIC; }
  3884. | OMP_GUIDED
  3885. { $$=SK_GUIDED; }
  3886. | OMP_RUNTIME
  3887. { $$=SK_RUNTIME; }
  3888. ;
  3889. sections_construct:
  3890. sections_directive
  3891. {
  3892. add_stmt (build_omp_stmt (sections_cons_b, $1));
  3893. $<ttype>$ = NULL;
  3894. }
  3895. section_scope
  3896. { add_stmt (build_omp_stmt (sections_cons_e, NULL)); $$ = NULL; }
  3897. ;
  3898. sections_directive:
  3899. OMP_PRAGMA OMP_SECTIONS '\n'
  3900. { $$ = NULL; }
  3901. | OMP_PRAGMA OMP_SECTIONS sections_clause_list '\n'
  3902. { $$ = $3; }
  3903. ;
  3904. sections_clause_list:
  3905. sections_clause
  3906. { $$ = $1; }
  3907. | sections_clause_list sections_clause
  3908. { $$ = chain_sections_list_on ($1, $2); }
  3909. ;
  3910. sections_clause:
  3911. OMP_PRIVATE '(' variable_list ')'
  3912. { $$ = build_sections_clause_list($3, sections_private, 0); }
  3913. | OMP_FIRSTPRIVATE '(' variable_list ')'
  3914. { $$ = build_sections_clause_list($3, sections_firstprivate, 0); }
  3915. | OMP_LASTPRIVATE '(' variable_list ')'
  3916. { $$ = build_sections_clause_list($3, sections_lastprivate, 0); }
  3917. | OMP_REDUCTION '(' reduction_operator ':' variable_list ')'
  3918. { $$ = build_sections_clause_list($5, sections_reduction, $3); }
  3919. | OMP_NOWAIT
  3920. { $$ = build_sections_clause_list(NULL, sections_nowait, 0); }
  3921. ;
  3922. /* The first section directive is optional */
  3923. section_scope:
  3924. '{'
  3925. {
  3926. In_MP_Section = true;
  3927. add_stmt (build_omp_stmt (section_cons_b, NULL));
  3928. }
  3929. maybe_section_sequence '}'
  3930. ;
  3931. maybe_section_sequence:
  3932. section_sequence
  3933. | maybe_structured_block
  3934. | maybe_structured_block section_sequence
  3935. ;
  3936. maybe_structured_block:
  3937. structured_block
  3938. {
  3939. In_MP_Section = false;
  3940. add_stmt (build_omp_stmt (section_cons_e, NULL));
  3941. }
  3942. ;
  3943. section_sequence:
  3944. section_construct
  3945. |section_sequence section_construct
  3946. ;
  3947. section_construct:
  3948. section_directive
  3949. {
  3950. if (!In_MP_Section)
  3951. add_stmt (build_omp_stmt (section_cons_b, NULL));
  3952. else
  3953. In_MP_Section = false;
  3954. }
  3955. structured_block
  3956. {
  3957. add_stmt (build_omp_stmt (section_cons_e, NULL));
  3958. }
  3959. ;
  3960. section_directive:
  3961. OMP_PRAGMA OMP_SECTION '\n'
  3962. ;
  3963. single_construct:
  3964. single_directive
  3965. {
  3966. add_stmt (build_omp_stmt (single_cons_b, $1));
  3967. $<ttype>$ = NULL;
  3968. }
  3969. structured_block
  3970. { add_stmt (build_omp_stmt (single_cons_e, NULL)); $$ = NULL; }
  3971. ;
  3972. single_directive:
  3973. OMP_PRAGMA OMP_SINGLE '\n'
  3974. {$$ = NULL;}
  3975. | OMP_PRAGMA OMP_SINGLE single_clause_list '\n'
  3976. {$$ = $3;}
  3977. ;
  3978. single_clause_list:
  3979. single_clause
  3980. { $$ = $1; }
  3981. | single_clause_list single_clause
  3982. { $$ = chain_single_list_on ($1, $2); }
  3983. ;
  3984. single_clause:
  3985. OMP_PRIVATE '(' variable_list ')'
  3986. { $$ = build_single_clause_list($3, single_private); }
  3987. | OMP_FIRSTPRIVATE '(' variable_list ')'
  3988. { $$ = build_single_clause_list($3, single_firstprivate); }
  3989. | OMP_COPYPRIVATE '(' variable_list ')'
  3990. { $$ = build_single_clause_list($3, single_copyprivate); }
  3991. | OMP_NOWAIT
  3992. { $$ = build_single_clause_list(NULL, single_nowait); }
  3993. ;
  3994. parallel_for_construct:
  3995. parallel_for_directive
  3996. {
  3997. $<ttype>$ = add_stmt (build_omp_stmt (par_for_cons_b, $1));
  3998. In_MP_Region = true;
  3999. mp_nesting++;
  4000. if (mp_nesting == MAX_MP_NESTING)
  4001. {
  4002. // will see
  4003. printf ("MP nesting > %d not supported\n", MAX_MP_NESTING-1);
  4004. abort();
  4005. }
  4006. mp_locals[mp_nesting] = NULL;
  4007. }
  4008. iteration_statement
  4009. {
  4010. add_stmt (build_omp_stmt (par_for_cons_e, NULL));
  4011. $$ = NULL;
  4012. In_MP_Region = false;
  4013. if (mp_locals[mp_nesting])
  4014. {
  4015. $<ttype>2->omp.omp_clause_list =
  4016. chain_parallel_for_list_on ($<ttype>2->omp.omp_clause_list,
  4017. build_parallel_for_clause_list (NULL, p_for_private,
  4018. 0, 0, 0));
  4019. $<ttype>2->omp.omp_clause_list =
  4020. chain_parallel_for_list_on ($<ttype>2->omp.omp_clause_list,
  4021. build_parallel_for_clause_list (mp_locals[mp_nesting], p_for_private, 0, 0, 0));
  4022. }
  4023. mp_locals[mp_nesting] = NULL;
  4024. mp_nesting--;
  4025. }
  4026. ;
  4027. parallel_for_directive:
  4028. OMP_PRAGMA OMP_PARALLEL FOR '\n'
  4029. {$$ = NULL;}
  4030. | OMP_PRAGMA OMP_PARALLEL FOR parallel_for_clause_list '\n'
  4031. {$$ = $4;}
  4032. ;
  4033. parallel_for_clause_list:
  4034. parallel_for_clause
  4035. { $$ = $1; }
  4036. | parallel_for_clause_list parallel_for_clause
  4037. { $$ = chain_parallel_for_list_on ($1, $2); }
  4038. ;
  4039. parallel_for_clause:
  4040. IF '(' expr_no_commas ')'
  4041. { $$ = build_parallel_for_clause_list($3, p_for_if, 0, 0, 0); }
  4042. | OMP_NUM_THREADS '(' expr_no_commas ')'
  4043. { $$ = build_parallel_for_clause_list($3, p_for_num_threads, 0, 0, 0); } | OMP_PRIVATE '(' variable_list ')'
  4044. { $$ = build_parallel_for_clause_list($3, p_for_private, 0, 0, 0); }
  4045. | OMP_COPYPRIVATE '(' variable_list ')'
  4046. { $$ = build_parallel_for_clause_list($3, p_for_copyprivate, 0, 0, 0); } | OMP_FIRSTPRIVATE '(' variable_list ')'
  4047. { $$ = build_parallel_for_clause_list($3, p_for_firstprivate, 0, 0, 0); }
  4048. | OMP_LASTPRIVATE '(' variable_list ')'
  4049. { $$ = build_parallel_for_clause_list($3, p_for_lastprivate, 0, 0, 0); } | OMP_SHARED '(' variable_list ')'
  4050. { $$ = build_parallel_for_clause_list($3, p_for_shared, 0, 0, 0); }
  4051. | DEFAULT '(' OMP_SHARED ')'
  4052. { $$ = build_parallel_for_clause_list(NULL, p_for_default, default_shared, 0, 0); }
  4053. | DEFAULT '(' OMP_NONE ')'
  4054. { $$ = build_parallel_for_clause_list(NULL, p_for_default, default_none, 0, 0); }
  4055. | OMP_REDUCTION '(' reduction_operator ':' variable_list ')'
  4056. { $$ = build_parallel_for_clause_list($5, p_for_reduction, 0, 0, $3); }
  4057. | OMP_COPYIN '(' variable_list ')'
  4058. { $$ = build_parallel_for_clause_list($3, p_for_copyin, 0, 0, 0); }
  4059. | OMP_SCHEDULE '(' schedule_kind ')'
  4060. { $$ = build_parallel_for_clause_list(NULL, p_for_schedule_1, 0, $3, 0); }
  4061. | OMP_SCHEDULE '(' schedule_kind ',' expr_no_commas ')'
  4062. { $$ = build_parallel_for_clause_list($5, p_for_schedule_2, 0, $3, 0); } | OMP_ORDERED
  4063. { $$ = build_parallel_for_clause_list(NULL, p_for_ordered, 0, 0, 0); }
  4064. ;
  4065. parallel_sections_construct:
  4066. parallel_sections_directive
  4067. {
  4068. $<ttype>$ = add_stmt (build_omp_stmt (par_sctn_cons_b, $1));
  4069. In_MP_Region = true;
  4070. mp_nesting++;
  4071. if (mp_nesting == MAX_MP_NESTING)
  4072. {
  4073. // will see
  4074. printf ("MP nesting > %d not supported\n", MAX_MP_NESTING-1);
  4075. abort();
  4076. }
  4077. mp_locals[mp_nesting] = NULL;
  4078. }
  4079. section_scope
  4080. {
  4081. add_stmt (build_omp_stmt (par_sctn_cons_e, NULL));
  4082. $$ = NULL;
  4083. In_MP_Region = false;
  4084. if (mp_locals[mp_nesting])
  4085. {
  4086. $<ttype>2->omp.omp_clause_list =
  4087. chain_parallel_sections_list_on ($<ttype>2->omp.omp_clause_list,
  4088. build_parallel_sections_clause_list (NULL,
  4089. p_sections_private, 0, 0));
  4090. $<ttype>2->omp.omp_clause_list =
  4091. chain_parallel_sections_list_on ($<ttype>2->omp.omp_clause_list, build_parallel_sections_clause_list (mp_locals[mp_nesting],
  4092. p_sections_private, 0, 0));
  4093. }
  4094. mp_locals[mp_nesting] = NULL;
  4095. mp_nesting--;
  4096. }
  4097. ;
  4098. parallel_sections_directive:
  4099. OMP_PRAGMA OMP_PARALLEL OMP_SECTIONS '\n'
  4100. {$$ = NULL;}
  4101. | OMP_PRAGMA OMP_PARALLEL OMP_SECTIONS parallel_sections_clause_list '\n'
  4102. {$$ = $4;}
  4103. ;
  4104. parallel_sections_clause_list:
  4105. parallel_sections_clause
  4106. { $$=$1; }
  4107. | parallel_sections_clause_list parallel_sections_clause
  4108. { $$ = chain_parallel_sections_list_on ($1, $2); }
  4109. ;
  4110. parallel_sections_clause:
  4111. IF '(' expr_no_commas ')'
  4112. { $$ = build_parallel_sections_clause_list($3, p_sections_if, 0, 0); }
  4113. | OMP_NUM_THREADS '(' expr_no_commas ')'
  4114. { $$ = build_parallel_sections_clause_list($3, p_sections_num_threads, 0, 0); }
  4115. | OMP_PRIVATE '(' variable_list ')'
  4116. { $$ = build_parallel_sections_clause_list($3, p_sections_private, 0, 0); }
  4117. | OMP_COPYPRIVATE '(' variable_list ')'
  4118. { $$ = build_parallel_sections_clause_list($3, p_sections_copyprivate, 0, 0); }
  4119. | OMP_FIRSTPRIVATE '(' variable_list ')'
  4120. { $$ = build_parallel_sections_clause_list($3, p_sections_firstprivate, 0, 0); }
  4121. | OMP_LASTPRIVATE '(' variable_list ')'
  4122. { $$ = build_parallel_sections_clause_list($3, p_sections_lastprivate, 0, 0); }
  4123. | OMP_SHARED '(' variable_list ')'
  4124. { $$ = build_parallel_sections_clause_list($3, p_sections_shared, 0, 0); }
  4125. | DEFAULT '(' OMP_SHARED ')'
  4126. { $$ = build_parallel_sections_clause_list(NULL, p_sections_default, default_shared, 0); }
  4127. | DEFAULT '(' OMP_NONE ')'
  4128. { $$ = build_parallel_sections_clause_list(NULL, p_sections_default, default_none, 0); }
  4129. | OMP_REDUCTION '(' reduction_operator ':' variable_list ')'
  4130. { $$ = build_parallel_sections_clause_list($5, p_sections_reduction, 0, $3); }
  4131. | OMP_COPYIN '(' variable_list ')'
  4132. { $$ = build_parallel_sections_clause_list($3, p_sections_copyin, 0, 0); }
  4133. ;
  4134. master_construct:
  4135. master_directive
  4136. { add_stmt (build_omp_stmt (master_cons_b, NULL)); $<ttype>$ = NULL; }
  4137. structured_block
  4138. { add_stmt (build_omp_stmt (master_cons_e, NULL)); $$ = NULL; }
  4139. ;
  4140. master_directive:
  4141. OMP_PRAGMA OMP_MASTER '\n'
  4142. ;
  4143. critical_construct:
  4144. critical_directive
  4145. { add_stmt (build_omp_stmt (critical_cons_b, $1)); $<ttype>$ = NULL; }
  4146. structured_block
  4147. { add_stmt (build_omp_stmt (critical_cons_e, NULL)); $$ = NULL; }
  4148. ;
  4149. critical_directive:
  4150. OMP_PRAGMA OMP_CRITICAL '\n'
  4151. { $$ = NULL; }
  4152. | OMP_PRAGMA OMP_CRITICAL '(' region_phrase ')' '\n'
  4153. { $$ = $4; }
  4154. ;
  4155. region_phrase:
  4156. IDENTIFIER
  4157. { $$ = $1; }
  4158. ;
  4159. barrier_directive:
  4160. OMP_PRAGMA OMP_BARRIER '\n'
  4161. { add_stmt (build_omp_stmt (barrier_dir, NULL)); /*$$ = NULL;*/ }
  4162. ;
  4163. atomic_construct:
  4164. atomic_directive
  4165. {
  4166. add_stmt (build_omp_stmt (atomic_cons_b, NULL));
  4167. $<ttype>$ = NULL;
  4168. }
  4169. expr_no_commas ';'
  4170. {
  4171. finish_expr_stmt ($3);
  4172. add_stmt (build_omp_stmt (atomic_cons_e, NULL));
  4173. $$ = NULL;
  4174. }
  4175. ;
  4176. atomic_directive:
  4177. OMP_PRAGMA OMP_ATOMIC '\n'
  4178. ;
  4179. flush_directive:
  4180. OMP_PRAGMA OMP_FLUSH '\n'
  4181. { add_stmt (build_omp_stmt (flush_dir, NULL)); $$ = NULL; }
  4182. | OMP_PRAGMA OMP_FLUSH '(' variable_list ')' '\n'
  4183. { add_stmt (build_omp_stmt (flush_dir, $4)); $$ = NULL; }
  4184. ;
  4185. ordered_construct:
  4186. ordered_directive
  4187. { add_stmt (build_omp_stmt (ordered_cons_b, NULL)); $<ttype>$ = NULL; }
  4188. structured_block
  4189. { add_stmt (build_omp_stmt (ordered_cons_e, NULL)); $$ = NULL; }
  4190. ;
  4191. ordered_directive:
  4192. OMP_PRAGMA OMP_ORDERED '\n'
  4193. ;
  4194. threadprivate_directive:
  4195. OMP_PRAGMA OMP_THREADPRIVATE '(' variable_list ')' '\n'
  4196. { expand_threadprivate ($4); }
  4197. ;
  4198. openmp_construct:
  4199. parallel_construct
  4200. | for_construct
  4201. | sections_construct
  4202. | single_construct
  4203. | parallel_for_construct
  4204. | parallel_sections_construct
  4205. | master_construct
  4206. | critical_construct
  4207. | atomic_construct
  4208. | ordered_construct
  4209. | sl2_sections_construct
  4210. ;
  4211. sl2_sections_construct:
  4212. PRAGMA_SL2 SL2_SECTIONS '\n'
  4213. {
  4214. #ifdef TARG_SL
  4215. add_stmt(build_omp_stmt(sl2_sections_cons_b, NULL));
  4216. #endif
  4217. }
  4218. sl2_section_scope
  4219. {
  4220. #ifdef TARG_SL
  4221. add_stmt(build_omp_stmt(sl2_sections_cons_e, NULL)); $$=NULL;
  4222. #endif
  4223. }
  4224. | PRAGMA_SL2 SL2_MINOR_SECTIONS '\n'
  4225. {
  4226. #ifdef TARG_SL
  4227. add_stmt(build_omp_stmt(sl2_minor_sections_cons_b, NULL));
  4228. #endif
  4229. }
  4230. sl2_section_scope
  4231. {
  4232. #ifdef TARG_SL
  4233. add_stmt(build_omp_stmt(sl2_sections_cons_e, NULL)); $$=NULL;
  4234. #endif
  4235. }
  4236. ;
  4237. sl2_section_scope:
  4238. '{'
  4239. sl2_maybe_section_sequence
  4240. '}'
  4241. ;
  4242. sl2_maybe_section_sequence:
  4243. sl2_section_sequence
  4244. | sl2_maybe_structured_block
  4245. | sl2_maybe_structured_block sl2_section_sequence
  4246. ;
  4247. sl2_maybe_structured_block:
  4248. structured_block
  4249. ;
  4250. sl2_section_sequence:
  4251. sl2_section_construct
  4252. | sl2_section_sequence sl2_section_construct
  4253. ;
  4254. sl2_section_construct:
  4255. PRAGMA_SL2 SL2_SECTION '\n'
  4256. {
  4257. #ifdef TARG_SL
  4258. if (!In_MP_Section)
  4259. add_stmt (build_omp_stmt (sl2_section_cons_b, NULL));
  4260. else
  4261. In_MP_Section = false;
  4262. #endif
  4263. }
  4264. structured_block
  4265. {
  4266. #ifdef TARG_SL
  4267. add_stmt (build_omp_stmt (sl2_section_cons_e, NULL));
  4268. #endif
  4269. }
  4270. | PRAGMA_SL2 SL2_MINOR_SECTION '\n'
  4271. {
  4272. #ifdef TARG_SL
  4273. if (!In_MP_Section)
  4274. add_stmt (build_omp_stmt (sl2_minor_section_cons_b, NULL));
  4275. else
  4276. In_MP_Section = false;
  4277. #endif
  4278. }
  4279. structured_block
  4280. {
  4281. #ifdef TARG_SL
  4282. add_stmt (build_omp_stmt (sl2_minor_section_cons_e, NULL));
  4283. #endif
  4284. }
  4285. ;
  4286. pragma_directives:
  4287. barrier_directive
  4288. | flush_directive
  4289. {}
  4290. | threadprivate_directive
  4291. | options_directive
  4292. {}
  4293. | exec_freq_directive
  4294. {}
  4295. ;
  4296. options_directive:
  4297. OPTIONS_PRAGMA STRING '\n'
  4298. { add_stmt (build_omp_stmt (options_dir, $2)); $$ = NULL; }
  4299. ;
  4300. /* Ignore directive in global scope */
  4301. exec_freq_directive_ignore:
  4302. EXEC_FREQ_PRAGMA freq_hint_ignore IDENTIFIER '\n'
  4303. { $$ = NULL; }
  4304. ;
  4305. freq_hint_ignore:
  4306. FREQ_NEVER | FREQ_INIT | FREQ_FREQUENT
  4307. ;
  4308. exec_freq_directive:
  4309. EXEC_FREQ_PRAGMA freq_hint '\n'
  4310. { add_stmt (build_omp_stmt (exec_freq_dir, $2)); $$ = NULL; }
  4311. ;
  4312. freq_hint:
  4313. FREQ_NEVER { $$ = build_string (6, "never"); }
  4314. | FREQ_INIT { $$ = build_string (5, "init"); }
  4315. | FREQ_FREQUENT { $$ = build_string (9, "frequent"); }
  4316. ;
  4317. structured_block:
  4318. stmt
  4319. ;
  4320. variable_list:
  4321. IDENTIFIER
  4322. {
  4323. if(lookup_name($1, 0)==0)
  4324. error("Undefined variable %s", IDENTIFIER_POINTER($1));
  4325. $$ = build_tree_list (NULL_TREE, lookup_name ($1, 0));
  4326. }
  4327. |variable_list ',' IDENTIFIER
  4328. {
  4329. if (lookup_name ($3, 0) == 0)
  4330. error ("Undefined variable %s", IDENTIFIER_POINTER($3));
  4331. $$ = chainon ($1, build_tree_list (NULL_TREE, lookup_name ($3, 0)));
  4332. }
  4333. ;
  4334. reduction_operator:
  4335. '+'
  4336. {$$ = REDUCTION_OPR_ADD;}
  4337. | '*'
  4338. {$$ = REDUCTION_OPR_MPY;}
  4339. | '-'
  4340. {$$ = REDUCTION_OPR_SUB;}
  4341. | '&'
  4342. {$$ = REDUCTION_OPR_BAND;}
  4343. | '^'
  4344. {$$ = REDUCTION_OPR_BXOR;}
  4345. | '|'
  4346. {$$ = REDUCTION_OPR_BIOR;}
  4347. | ANDAND
  4348. {$$ = REDUCTION_OPR_CAND;}
  4349. | OROR
  4350. {$$ = REDUCTION_OPR_CIOR;}
  4351. ;
  4352. %%
  4353. #ifdef SPEW_DEBUG
  4354. const char *
  4355. debug_yytranslate (value)
  4356. int value;
  4357. {
  4358. return yytname[YYTRANSLATE (value)];
  4359. }
  4360. #endif
  4361. /* Free malloced parser stacks if necessary. */
  4362. void
  4363. free_parser_stacks ()
  4364. {
  4365. if (malloced_yyss)
  4366. {
  4367. free (malloced_yyss);
  4368. free (malloced_yyvs);
  4369. }
  4370. }
  4371. /* Return the value corresponding to TOKEN in the global scope. */
  4372. static tree
  4373. parse_scoped_id (token)
  4374. tree token;
  4375. {
  4376. cxx_binding binding;
  4377. cxx_binding_clear (&binding);
  4378. if (!qualified_lookup_using_namespace (token, global_namespace, &binding, 0))
  4379. binding.value = NULL;
  4380. if (yychar == YYEMPTY)
  4381. yychar = yylex();
  4382. return do_scoped_id (token, binding.value);
  4383. }
  4384. /* AGGR may be either a type node (like class_type_node) or a
  4385. TREE_LIST whose TREE_PURPOSE is a list of attributes and whose
  4386. TREE_VALUE is a type node. Set *TAG_KIND and *ATTRIBUTES to
  4387. represent the information encoded. */
  4388. static void
  4389. parse_split_aggr (tree aggr, enum tag_types *tag_kind, tree *attributes)
  4390. {
  4391. if (TREE_CODE (aggr) == TREE_LIST)
  4392. {
  4393. *attributes = TREE_PURPOSE (aggr);
  4394. aggr = TREE_VALUE (aggr);
  4395. }
  4396. else
  4397. *attributes = NULL_TREE;
  4398. *tag_kind = (enum tag_types) tree_low_cst (aggr, 1);
  4399. }
  4400. /* Like xref_tag, except that the AGGR may be either a type node (like
  4401. class_type_node) or a TREE_LIST whose TREE_PURPOSE is a list of
  4402. attributes and whose TREE_VALUE is a type node. */
  4403. static tree
  4404. parse_xref_tag (tree aggr, tree name, int globalize)
  4405. {
  4406. tree attributes;
  4407. enum tag_types tag_kind;
  4408. parse_split_aggr (aggr, &tag_kind, &attributes);
  4409. return xref_tag (tag_kind, name, attributes, globalize);
  4410. }
  4411. /* Like handle_class_head, but AGGR may be as for parse_xref_tag. */
  4412. static tree
  4413. parse_handle_class_head (tree aggr, tree scope, tree id,
  4414. int defn_p, int *new_type_p)
  4415. {
  4416. tree attributes;
  4417. enum tag_types tag_kind;
  4418. parse_split_aggr (aggr, &tag_kind, &attributes);
  4419. return handle_class_head (tag_kind, scope, id, attributes,
  4420. defn_p, new_type_p);
  4421. }
  4422. /* Like do_decl_instantiation, but the declarator has not yet been
  4423. parsed. */
  4424. static void
  4425. parse_decl_instantiation (tree declspecs, tree declarator, tree storage)
  4426. {
  4427. tree decl = grokdeclarator (declarator, declspecs, NORMAL, 0, NULL);
  4428. do_decl_instantiation (decl, storage);
  4429. }
  4430. /* Like begin_function_definition, but SPECS_ATTRS is a combined list
  4431. containing both a decl-specifier-seq and attributes. */
  4432. static int
  4433. parse_begin_function_definition (tree specs_attrs, tree declarator)
  4434. {
  4435. tree specs;
  4436. tree attrs;
  4437. split_specs_attrs (specs_attrs, &specs, &attrs);
  4438. return begin_function_definition (specs, attrs, declarator);
  4439. }
  4440. /* Like finish_call_expr, but the name for FN has not yet been
  4441. resolved. */
  4442. static tree
  4443. parse_finish_call_expr (tree fn, tree args, int koenig)
  4444. {
  4445. bool disallow_virtual;
  4446. if (TREE_CODE (fn) == OFFSET_REF)
  4447. return build_offset_ref_call_from_tree (fn, args);
  4448. if (TREE_CODE (fn) == SCOPE_REF)
  4449. {
  4450. tree scope = TREE_OPERAND (fn, 0);
  4451. tree name = TREE_OPERAND (fn, 1);
  4452. if (scope == error_mark_node || name == error_mark_node)
  4453. return error_mark_node;
  4454. if (!processing_template_decl)
  4455. fn = resolve_scoped_fn_name (scope, name);
  4456. disallow_virtual = true;
  4457. }
  4458. else
  4459. disallow_virtual = false;
  4460. if (koenig && TREE_CODE (fn) == IDENTIFIER_NODE)
  4461. {
  4462. tree f;
  4463. /* Do the Koenig lookup. */
  4464. fn = do_identifier (fn, 2, args);
  4465. /* If name lookup didn't find any matching declarations, we've
  4466. got an unbound identifier. */
  4467. if (TREE_CODE (fn) == IDENTIFIER_NODE)
  4468. {
  4469. /* For some reason, do_identifier does not resolve
  4470. conversion operator names if the only matches would be
  4471. template conversion operators. So, we do it here. */
  4472. if (IDENTIFIER_TYPENAME_P (fn) && current_class_type)
  4473. {
  4474. f = lookup_member (current_class_type, fn,
  4475. /*protect=*/1, /*want_type=*/0);
  4476. if (f)
  4477. return finish_call_expr (f, args,
  4478. /*disallow_virtual=*/false);
  4479. }
  4480. /* If the name still could not be resolved, then the program
  4481. is ill-formed. */
  4482. if (TREE_CODE (fn) == IDENTIFIER_NODE)
  4483. {
  4484. unqualified_name_lookup_error (fn);
  4485. return error_mark_node;
  4486. }
  4487. }
  4488. else if (TREE_CODE (fn) == FUNCTION_DECL
  4489. || DECL_FUNCTION_TEMPLATE_P (fn)
  4490. || TREE_CODE (fn) == OVERLOAD)
  4491. {
  4492. tree scope = DECL_CONTEXT (get_first_fn (fn));
  4493. if (scope && TYPE_P (scope))
  4494. {
  4495. tree access_scope;
  4496. if (DERIVED_FROM_P (scope, current_class_type)
  4497. && current_class_ref)
  4498. {
  4499. fn = build_baselink (lookup_base (current_class_type,
  4500. scope,
  4501. ba_any,
  4502. NULL),
  4503. TYPE_BINFO (current_class_type),
  4504. fn,
  4505. /*optype=*/NULL_TREE);
  4506. return finish_object_call_expr (fn,
  4507. current_class_ref,
  4508. args);
  4509. }
  4510. access_scope = current_class_type;
  4511. while (!DERIVED_FROM_P (scope, access_scope))
  4512. {
  4513. access_scope = TYPE_CONTEXT (access_scope);
  4514. while (DECL_P (access_scope))
  4515. access_scope = DECL_CONTEXT (access_scope);
  4516. }
  4517. fn = build_baselink (NULL_TREE,
  4518. TYPE_BINFO (access_scope),
  4519. fn,
  4520. /*optype=*/NULL_TREE);
  4521. }
  4522. }
  4523. }
  4524. if (TREE_CODE (fn) == COMPONENT_REF)
  4525. /* If the parser sees `(x->y)(bar)' we get here because the
  4526. parentheses confuse the parser. Treat this like
  4527. `x->y(bar)'. */
  4528. return finish_object_call_expr (TREE_OPERAND (fn, 1),
  4529. TREE_OPERAND (fn, 0),
  4530. args);
  4531. if (processing_template_decl)
  4532. return build_nt (CALL_EXPR, fn, args, NULL_TREE);
  4533. return build_call_from_tree (fn, args, disallow_virtual);
  4534. }
  4535. #include "gt-cp-parse.h"