PageRenderTime 81ms CodeModel.GetById 36ms RepoModel.GetById 0ms 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

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

  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

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