PageRenderTime 59ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/opensource.apple.com/source/gcc_legacy/gcc_legacy-938/gcc/cp/parse.y

#
Happy | 2076 lines | 1872 code | 204 blank | 0 comment | 0 complexity | 94b25433a210e1805fcce9ac3c471821 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0, GPL-2.0, ISC, LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, WTFPL, MIT, AGPL-1.0, AGPL-3.0

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

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>parse.y</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">parse.y&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. /* YACC parser for C++ syntax.
  24. Copyright (C) 1988, 89, 93-98, 1999 Free Software Foundation, Inc.
  25. Hacked by Michael Tiemann (<a href="mailto:tiemann@cygnus.com">tiemann@cygnus.com</a>)
  26. This file is part of GNU CC.
  27. GNU CC is free software; you can redistribute it and/or modify
  28. it under the terms of the GNU General Public License as published by
  29. the Free Software Foundation; either version 2, or (at your option)
  30. any later version.
  31. GNU CC is distributed in the hope that it will be useful,
  32. but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. GNU General Public License for more details.
  35. You should have received a copy of the GNU General Public License
  36. along with GNU CC; see the file COPYING. If not, write to
  37. the Free Software Foundation, 59 Temple Place - Suite 330,
  38. Boston, MA 02111-1307, USA. */
  39. /* This grammar is based on the GNU CC grammar. */
  40. /* Note: Bison automatically applies a default action of &quot;$$ = $1&quot; for
  41. all derivations; this is applied before the explicit action, if one
  42. is given. Keep this in mind when reading the actions. */
  43. %{
  44. /* Cause the `yydebug' variable to be defined. */
  45. #define YYDEBUG 1
  46. #include &quot;config.h&quot;
  47. #include &quot;system.h&quot;
  48. #include &quot;tree.h&quot;
  49. #include &quot;input.h&quot;
  50. #include &quot;flags.h&quot;
  51. #include &quot;lex.h&quot;
  52. #include &quot;cp-tree.h&quot;
  53. #include &quot;output.h&quot;
  54. #include &quot;except.h&quot;
  55. #include &quot;toplev.h&quot;
  56. /* Since parsers are distinct for each language, put the language string
  57. definition here. (fnf) */
  58. char *language_string = &quot;GNU C++&quot;;
  59. extern tree void_list_node;
  60. extern struct obstack permanent_obstack;
  61. extern int end_of_file;
  62. /* Like YYERROR but do call yyerror. */
  63. #define YYERROR1 { yyerror (&quot;syntax error&quot;); YYERROR; }
  64. #define OP0(NODE) (TREE_OPERAND (NODE, 0))
  65. #define OP1(NODE) (TREE_OPERAND (NODE, 1))
  66. /* Contains the statement keyword (if/while/do) to include in an
  67. error message if the user supplies an empty conditional expression. */
  68. static const char *cond_stmt_keyword;
  69. static tree empty_parms PROTO((void));
  70. static int parse_decl PROTO((tree, tree, tree, int, tree *));
  71. /* Nonzero if we have an `extern &quot;C&quot;' acting as an extern specifier. */
  72. int have_extern_spec;
  73. int used_extern_spec;
  74. /* Cons up an empty parameter list. */
  75. #ifdef __GNUC__
  76. __inline
  77. #endif
  78. static tree
  79. empty_parms ()
  80. {
  81. tree parms;
  82. if (strict_prototype
  83. || current_class_type != NULL)
  84. parms = void_list_node;
  85. else
  86. parms = NULL_TREE;
  87. return parms;
  88. }
  89. %}
  90. %start program
  91. %union {long itype; tree ttype; char *strtype; enum tree_code code; flagged_type_tree ftype; }
  92. /* All identifiers that are not reserved words
  93. and are not declared typedefs in the current block */
  94. %token IDENTIFIER
  95. /* All identifiers that are declared typedefs in the current block.
  96. In some contexts, they are treated just like IDENTIFIER,
  97. but they can also serve as typespecs in declarations. */
  98. %token TYPENAME
  99. %token SELFNAME
  100. /* A template function. */
  101. %token PFUNCNAME
  102. /* Reserved words that specify storage class.
  103. yylval contains an IDENTIFIER_NODE which indicates which one. */
  104. %token SCSPEC
  105. /* Reserved words that specify type.
  106. yylval contains an IDENTIFIER_NODE which indicates which one. */
  107. %token TYPESPEC
  108. /* Reserved words that qualify type: &quot;const&quot; or &quot;volatile&quot;.
  109. yylval contains an IDENTIFIER_NODE which indicates which one. */
  110. %token CV_QUALIFIER
  111. /* Character or numeric constants.
  112. yylval is the node for the constant. */
  113. %token CONSTANT
  114. /* String constants in raw form.
  115. yylval is a STRING_CST node. */
  116. %token STRING
  117. /* &quot;...&quot;, used for functions with variable arglists. */
  118. %token ELLIPSIS
  119. /* the reserved words */
  120. /* SCO include files test &quot;ASM&quot;, so use something else. */
  121. %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  122. %token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF
  123. %token SIGOF
  124. %token ATTRIBUTE EXTENSION LABEL
  125. %token REALPART IMAGPART
  126. %token VEC_STEP
  127. /* the reserved words... C++ extensions */
  128. %token &lt;ttype&gt; AGGR
  129. %token &lt;ttype&gt; VISSPEC
  130. %token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE
  131. %token NAMESPACE TYPENAME_KEYWORD USING
  132. %token LEFT_RIGHT TEMPLATE
  133. %token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
  134. %token &lt;itype&gt; SCOPE
  135. /* Define the operator tokens and their precedences.
  136. The value is an integer because, if used, it is the tree code
  137. to use in the expression made from the operator. */
  138. %left EMPTY /* used to resolve s/r with epsilon */
  139. %left error
  140. /* Add precedence rules to solve dangling else s/r conflict */
  141. %nonassoc IF
  142. %nonassoc ELSE
  143. %left IDENTIFIER PFUNCNAME TYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD
  144. %left '{' ',' ';'
  145. %nonassoc THROW
  146. %right &lt;code&gt; ':'
  147. %right &lt;code&gt; ASSIGN '='
  148. %right &lt;code&gt; '?'
  149. %left &lt;code&gt; OROR
  150. %left &lt;code&gt; ANDAND
  151. %left &lt;code&gt; '|'
  152. %left &lt;code&gt; '^'
  153. %left &lt;code&gt; '&amp;'
  154. %left &lt;code&gt; MIN_MAX
  155. %left &lt;code&gt; EQCOMPARE
  156. %left &lt;code&gt; ARITHCOMPARE '&lt;' '&gt;'
  157. %left &lt;code&gt; LSHIFT RSHIFT
  158. %left &lt;code&gt; '+' '-'
  159. %left &lt;code&gt; '*' '/' '%'
  160. %left &lt;code&gt; POINTSAT_STAR DOT_STAR
  161. %right &lt;code&gt; UNARY PLUSPLUS MINUSMINUS '~'
  162. %left HYPERUNARY
  163. %left &lt;ttype&gt; PAREN_STAR_PAREN LEFT_RIGHT
  164. %left &lt;code&gt; POINTSAT '.' '(' '['
  165. %right SCOPE /* C++ extension */
  166. %nonassoc NEW DELETE TRY CATCH
  167. %type &lt;code&gt; unop
  168. %type &lt;ttype&gt; identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist
  169. %type &lt;ttype&gt; PFUNCNAME maybe_identifier
  170. %type &lt;ttype&gt; paren_expr_or_null nontrivial_exprlist SELFNAME
  171. %type &lt;ttype&gt; expr_no_commas cast_expr unary_expr primary string STRING
  172. %type &lt;ttype&gt; reserved_declspecs boolean.literal
  173. %type &lt;ttype&gt; reserved_typespecquals
  174. %type &lt;ttype&gt; declmods
  175. %type &lt;ttype&gt; SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
  176. %type &lt;itype&gt; initdecls notype_initdecls initdcl /* C++ modification */
  177. %type &lt;ttype&gt; init initlist maybeasm maybe_init defarg defarg1
  178. %type &lt;ttype&gt; asm_operands nonnull_asm_operands asm_operand asm_clobbers
  179. %type &lt;ttype&gt; maybe_attribute attributes attribute attribute_list attrib
  180. %type &lt;ttype&gt; any_word
  181. %type &lt;ttype&gt; compstmt implicitly_scoped_stmt
  182. %type &lt;ttype&gt; declarator notype_declarator after_type_declarator
  183. %type &lt;ttype&gt; notype_declarator_intern absdcl_intern
  184. %type &lt;ttype&gt; after_type_declarator_intern
  185. %type &lt;ttype&gt; direct_notype_declarator direct_after_type_declarator
  186. %type &lt;itype&gt; components notype_components
  187. %type &lt;ttype&gt; component_decl component_decl_1
  188. %type &lt;ttype&gt; component_declarator component_declarator0
  189. %type &lt;ttype&gt; notype_component_declarator notype_component_declarator0
  190. %type &lt;ttype&gt; after_type_component_declarator after_type_component_declarator0
  191. %type &lt;ttype&gt; enumlist enumerator
  192. %type &lt;ttype&gt; absdcl cv_qualifiers
  193. %type &lt;ttype&gt; direct_abstract_declarator conversion_declarator
  194. %type &lt;ttype&gt; new_declarator direct_new_declarator
  195. %type &lt;ttype&gt; xexpr parmlist parms bad_parm
  196. %type &lt;ttype&gt; identifiers_or_typenames
  197. %type &lt;ttype&gt; fcast_or_absdcl regcast_or_absdcl
  198. %type &lt;ttype&gt; expr_or_declarator expr_or_declarator_intern
  199. %type &lt;ttype&gt; complex_notype_declarator
  200. %type &lt;ttype&gt; notype_unqualified_id unqualified_id qualified_id
  201. %type &lt;ttype&gt; template_id do_id object_template_id notype_template_declarator
  202. %type &lt;ttype&gt; overqualified_id notype_qualified_id any_id
  203. %type &lt;ttype&gt; complex_direct_notype_declarator functional_cast
  204. %type &lt;ttype&gt; complex_parmlist parms_comma
  205. %type &lt;ttype&gt; namespace_qualifier namespace_using_decl
  206. %type &lt;ftype&gt; type_id new_type_id typed_typespecs typespec typed_declspecs
  207. %type &lt;ftype&gt; typed_declspecs1 type_specifier_seq nonempty_cv_qualifiers
  208. %type &lt;ftype&gt; structsp typespecqual_reserved parm named_parm full_parm
  209. /* C++ extensions */
  210. %token &lt;ttype&gt; PTYPENAME
  211. %token &lt;ttype&gt; PRE_PARSED_FUNCTION_DECL EXTERN_LANG_STRING ALL
  212. %token &lt;ttype&gt; PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER
  213. %type &lt;ttype&gt; component_constructor_declarator
  214. %type &lt;ttype&gt; fn.def2 return_id fn.defpen constructor_declarator
  215. %type &lt;itype&gt; ctor_initializer_opt function_try_block
  216. %type &lt;ttype&gt; named_class_head_sans_basetype
  217. %type &lt;ftype&gt; class_head named_class_head
  218. %type &lt;ftype&gt; named_complex_class_head_sans_basetype
  219. %type &lt;ttype&gt; unnamed_class_head
  220. %type &lt;ttype&gt; base_class_list
  221. %type &lt;ttype&gt; base_class_access_list
  222. %type &lt;ttype&gt; base_class maybe_base_class_list base_class.1
  223. %type &lt;ttype&gt; exception_specification_opt ansi_raise_identifier ansi_raise_identifiers
  224. %type &lt;ttype&gt; operator_name
  225. %type &lt;ttype&gt; object aggr
  226. %type &lt;itype&gt; new delete .begin_new_placement
  227. /* %type &lt;ttype&gt; primary_no_id */
  228. %type &lt;ttype&gt; nonmomentary_expr maybe_parmlist
  229. %type &lt;itype&gt; initdcl0 notype_initdcl0 member_init_list initdcl0_innards
  230. %type &lt;ttype&gt; template_header template_parm_list template_parm
  231. %type &lt;ttype&gt; template_type_parm template_template_parm
  232. %type &lt;code&gt; template_close_bracket
  233. %type &lt;ttype&gt; apparent_template_type
  234. %type &lt;ttype&gt; template_type template_arg_list template_arg_list_opt
  235. %type &lt;ttype&gt; template_arg
  236. %type &lt;ttype&gt; condition xcond paren_cond_or_null
  237. %type &lt;ttype&gt; type_name nested_name_specifier nested_type ptr_to_mem
  238. %type &lt;ttype&gt; complete_type_name notype_identifier nonnested_type
  239. %type &lt;ttype&gt; complex_type_name nested_name_specifier_1
  240. %type &lt;ttype&gt; new_initializer new_placement
  241. %type &lt;ttype&gt; using_decl
  242. %type &lt;ttype&gt; typename_sub typename_sub0 typename_sub1 typename_sub2
  243. %type &lt;ttype&gt; explicit_template_type
  244. /* in order to recognize aggr tags as defining and thus shadowing. */
  245. %token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
  246. %type &lt;ttype&gt; named_class_head_sans_basetype_defn
  247. %type &lt;ttype&gt; identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN
  248. %type &lt;ttype&gt; self_template_type .finish_template_type
  249. %token NSNAME
  250. %type &lt;ttype&gt; NSNAME
  251. /* Used in lex.c for parsing pragmas. */
  252. %token END_OF_LINE
  253. /* lex.c and pt.c depend on this being the last token. Define
  254. any new tokens before this one! */
  255. %token END_OF_SAVED_INPUT
  256. %{
  257. /* List of types and structure classes of the current declaration. */
  258. static tree current_declspecs;
  259. /* List of prefix attributes in effect.
  260. Prefix attributes are parsed by the reserved_declspecs and declmods
  261. rules. They create a list that contains *both* declspecs and attrs. */
  262. /* ??? It is not clear yet that all cases where an attribute can now appear in
  263. a declspec list have been updated. */
  264. static tree prefix_attributes;
  265. /* When defining an aggregate, this is the kind of the most recent one
  266. being defined. (For example, this might be class_type_node.) */
  267. tree current_aggr;
  268. /* When defining an enumeration, this is the type of the enumeration. */
  269. static tree current_enum_type;
  270. /* Tell yyparse how to print a token's value, if yydebug is set. */
  271. #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  272. extern void yyprint PROTO((FILE *, int, YYSTYPE));
  273. extern tree combine_strings PROTO((tree));
  274. static int
  275. parse_decl(declarator, specs_attrs, attributes, initialized, decl)
  276. tree declarator;
  277. tree specs_attrs;
  278. tree attributes;
  279. int initialized;
  280. tree* decl;
  281. {
  282. int sm;
  283. split_specs_attrs (specs_attrs, &amp;current_declspecs, &amp;prefix_attributes);
  284. if (current_declspecs
  285. &amp;&amp; TREE_CODE (current_declspecs) != TREE_LIST)
  286. current_declspecs = build_decl_list (NULL_TREE, current_declspecs);
  287. if (have_extern_spec &amp;&amp; !used_extern_spec)
  288. {
  289. current_declspecs = decl_tree_cons (NULL_TREE,
  290. get_identifier (&quot;extern&quot;),
  291. current_declspecs);
  292. used_extern_spec = 1;
  293. }
  294. sm = suspend_momentary ();
  295. *decl = start_decl (declarator, current_declspecs, initialized,
  296. attributes, prefix_attributes);
  297. return sm;
  298. }
  299. %}
  300. %%
  301. program:
  302. /* empty */
  303. | extdefs
  304. { finish_translation_unit (); }
  305. ;
  306. /* the reason for the strange actions in this rule
  307. is so that notype_initdecls when reached via datadef
  308. can find a valid list of type and sc specs in $0. */
  309. extdefs:
  310. { $&lt;ttype&gt;$ = NULL_TREE; }
  311. lang_extdef
  312. { $&lt;ttype&gt;$ = NULL_TREE; }
  313. | extdefs lang_extdef
  314. { $&lt;ttype&gt;$ = NULL_TREE; }
  315. ;
  316. extdefs_opt:
  317. extdefs
  318. | /* empty */
  319. ;
  320. .hush_warning:
  321. { have_extern_spec = 1;
  322. used_extern_spec = 0;
  323. $&lt;ttype&gt;$ = NULL_TREE; }
  324. ;
  325. .warning_ok:
  326. { have_extern_spec = 0; }
  327. ;
  328. extension:
  329. EXTENSION
  330. { $&lt;itype&gt;$ = pedantic;
  331. pedantic = 0; }
  332. ;
  333. asm_keyword:
  334. ASM_KEYWORD
  335. ;
  336. lang_extdef:
  337. { if (pending_lang_change) do_pending_lang_change(); }
  338. extdef
  339. { if (! toplevel_bindings_p () &amp;&amp; ! pseudo_global_level_p())
  340. pop_everything (); }
  341. ;
  342. extdef:
  343. fndef eat_saved_input
  344. { if (pending_inlines) do_pending_inlines (); }
  345. | datadef
  346. { if (pending_inlines) do_pending_inlines (); }
  347. | template_def
  348. { if (pending_inlines) do_pending_inlines (); }
  349. | asm_keyword '(' string ')' ';'
  350. { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
  351. assemble_asm ($3); }
  352. | extern_lang_string '{' extdefs_opt '}'
  353. { pop_lang_context (); }
  354. | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
  355. { if (pending_inlines) do_pending_inlines ();
  356. pop_lang_context (); }
  357. | extern_lang_string .hush_warning datadef .warning_ok
  358. { if (pending_inlines) do_pending_inlines ();
  359. pop_lang_context (); }
  360. | NAMESPACE identifier '{'
  361. { push_namespace ($2); }
  362. extdefs_opt '}'
  363. { pop_namespace (); }
  364. | NAMESPACE '{'
  365. { push_namespace (NULL_TREE); }
  366. extdefs_opt '}'
  367. { pop_namespace (); }
  368. | namespace_alias
  369. | using_decl ';'
  370. { do_toplevel_using_decl ($1); }
  371. | using_directive
  372. | extension extdef
  373. { pedantic = $&lt;itype&gt;1; }
  374. ;
  375. namespace_alias:
  376. NAMESPACE identifier '='
  377. { begin_only_namespace_names (); }
  378. any_id ';'
  379. {
  380. end_only_namespace_names ();
  381. if (lastiddecl)
  382. $5 = lastiddecl;
  383. do_namespace_alias ($2, $5);
  384. }
  385. ;
  386. using_decl:
  387. USING qualified_id
  388. { $$ = $2; }
  389. | USING global_scope qualified_id
  390. { $$ = $3; }
  391. | USING global_scope unqualified_id
  392. { $$ = $3; }
  393. ;
  394. namespace_using_decl:
  395. USING namespace_qualifier identifier
  396. { $$ = build_parse_node (SCOPE_REF, $2, $3); }
  397. | USING global_scope identifier
  398. { $$ = build_parse_node (SCOPE_REF, global_namespace, $3); }
  399. | USING global_scope namespace_qualifier identifier
  400. { $$ = build_parse_node (SCOPE_REF, $3, $4); }
  401. ;
  402. using_directive:
  403. USING NAMESPACE
  404. { begin_only_namespace_names (); }
  405. any_id ';'
  406. {
  407. end_only_namespace_names ();
  408. /* If no declaration was found, the using-directive is
  409. invalid. Since that was not reported, we need the
  410. identifier for the error message. */
  411. if (TREE_CODE ($4) == IDENTIFIER_NODE &amp;&amp; lastiddecl)
  412. $4 = lastiddecl;
  413. do_using_directive ($4);
  414. }
  415. ;
  416. namespace_qualifier:
  417. NSNAME SCOPE
  418. {
  419. if (TREE_CODE ($$) == IDENTIFIER_NODE)
  420. $$ = lastiddecl;
  421. got_scope = $$;
  422. }
  423. | namespace_qualifier NSNAME SCOPE
  424. {
  425. $$ = $2;
  426. if (TREE_CODE ($$) == IDENTIFIER_NODE)
  427. $$ = lastiddecl;
  428. got_scope = $$;
  429. }
  430. any_id:
  431. unqualified_id
  432. | qualified_id
  433. | global_scope qualified_id
  434. { $$ = $2; }
  435. | global_scope unqualified_id
  436. { $$ = $2; }
  437. ;
  438. extern_lang_string:
  439. EXTERN_LANG_STRING
  440. { push_lang_context ($1); }
  441. | extern_lang_string EXTERN_LANG_STRING
  442. { if (current_lang_name != $2)
  443. cp_error (&quot;use of linkage spec `%D' is different from previous spec `%D'&quot;, $2, current_lang_name);
  444. pop_lang_context (); push_lang_context ($2); }
  445. ;
  446. template_header:
  447. TEMPLATE '&lt;'
  448. { begin_template_parm_list (); }
  449. template_parm_list '&gt;'
  450. { $$ = end_template_parm_list ($4); }
  451. | TEMPLATE '&lt;' '&gt;'
  452. { begin_specialization();
  453. $$ = NULL_TREE; }
  454. ;
  455. template_parm_list:
  456. template_parm
  457. { $$ = process_template_parm (NULL_TREE, $1); }
  458. | template_parm_list ',' template_parm
  459. { $$ = process_template_parm ($1, $3); }
  460. ;
  461. maybe_identifier:
  462. identifier
  463. { $$ = $1; }
  464. | /* empty */
  465. { $$ = NULL_TREE; }
  466. template_type_parm:
  467. aggr maybe_identifier
  468. { $$ = finish_template_type_parm ($1, $2); }
  469. | TYPENAME_KEYWORD maybe_identifier
  470. { $$ = finish_template_type_parm (class_type_node, $2); }
  471. ;
  472. template_template_parm:
  473. template_header aggr maybe_identifier
  474. { $$ = finish_template_template_parm ($2, $3); }
  475. ;
  476. template_parm:
  477. /* The following rules introduce a new reduce/reduce
  478. conflict on the ',' and '&gt;' input tokens: they are valid
  479. prefixes for a `structsp', which means they could match a
  480. nameless parameter. See 14.6, paragraph 3.
  481. By putting them before the `parm' rule, we get
  482. their match before considering them nameless parameter
  483. declarations. */
  484. template_type_parm
  485. { $$ = build_tree_list (NULL_TREE, $1); }
  486. | template_type_parm '=' type_id
  487. { $$ = build_tree_list (groktypename ($3.t), $1); }
  488. | parm
  489. { $$ = build_tree_list (NULL_TREE, $1.t); }
  490. | parm '=' expr_no_commas %prec ARITHCOMPARE
  491. { $$ = build_tree_list ($3, $1.t); }
  492. | template_template_parm
  493. { $$ = build_tree_list (NULL_TREE, $1); }
  494. | template_template_parm '=' template_arg
  495. {
  496. if (TREE_CODE ($3) != TEMPLATE_DECL
  497. &amp;&amp; TREE_CODE ($3) != TEMPLATE_TEMPLATE_PARM
  498. &amp;&amp; TREE_CODE ($3) != TYPE_DECL)
  499. {
  500. error (&quot;invalid default template argument&quot;);
  501. $3 = error_mark_node;
  502. }
  503. $$ = build_tree_list ($3, $1);
  504. }
  505. ;
  506. template_def:
  507. template_header template_extdef
  508. { finish_template_decl ($1); }
  509. | template_header error %prec EMPTY
  510. { finish_template_decl ($1); }
  511. ;
  512. template_extdef:
  513. fndef eat_saved_input
  514. { if (pending_inlines) do_pending_inlines (); }
  515. | template_datadef
  516. { if (pending_inlines) do_pending_inlines (); }
  517. | template_def
  518. { if (pending_inlines) do_pending_inlines (); }
  519. | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
  520. { if (pending_inlines) do_pending_inlines ();
  521. pop_lang_context (); }
  522. | extern_lang_string .hush_warning template_datadef .warning_ok
  523. { if (pending_inlines) do_pending_inlines ();
  524. pop_lang_context (); }
  525. | extension template_extdef
  526. { pedantic = $&lt;itype&gt;1; }
  527. ;
  528. template_datadef:
  529. nomods_initdecls ';'
  530. | declmods notype_initdecls ';'
  531. {}
  532. | typed_declspecs initdecls ';'
  533. { note_list_got_semicolon ($1.t); }
  534. | structsp ';'
  535. { maybe_process_partial_specialization ($1.t);
  536. note_got_semicolon ($1.t); }
  537. ;
  538. datadef:
  539. nomods_initdecls ';'
  540. | declmods notype_initdecls ';'
  541. {}
  542. | typed_declspecs initdecls ';'
  543. { note_list_got_semicolon ($1.t); }
  544. | declmods ';'
  545. { pedwarn (&quot;empty declaration&quot;); }
  546. | explicit_instantiation ';'
  547. | typed_declspecs ';'
  548. {
  549. tree t, attrs;
  550. split_specs_attrs ($1.t, &amp;t, &amp;attrs);
  551. shadow_tag (t);
  552. note_list_got_semicolon ($1.t);
  553. }
  554. | error ';'
  555. | error '}'
  556. | ';'
  557. ;
  558. ctor_initializer_opt:
  559. nodecls
  560. { $$ = 0; }
  561. | base_init
  562. { $$ = 1; }
  563. ;
  564. maybe_return_init:
  565. /* empty */
  566. | return_init
  567. | return_init ';'
  568. ;
  569. eat_saved_input:
  570. /* empty */
  571. | END_OF_SAVED_INPUT
  572. ;
  573. fndef:
  574. fn.def1 maybe_return_init ctor_initializer_opt compstmt_or_error
  575. { finish_function (lineno, (int)$3, 0); }
  576. | fn.def1 maybe_return_init function_try_block
  577. {
  578. int nested = (hack_decl_function_context
  579. (current_function_decl) != NULL_TREE);
  580. finish_function (lineno, (int)$3, nested);
  581. }
  582. | fn.def1 maybe_return_init error
  583. { }
  584. ;
  585. constructor_declarator:
  586. nested_name_specifier SELFNAME '('
  587. { $$ = begin_constructor_declarator ($1, $2); }
  588. parmlist ')' cv_qualifiers exception_specification_opt
  589. { $$ = make_call_declarator ($&lt;ttype&gt;4, $5, $7, $8); }
  590. | nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
  591. { $$ = begin_constructor_declarator ($1, $2);
  592. $$ = make_call_declarator ($$, empty_parms (), $4, $5);
  593. }
  594. | global_scope nested_name_specifier SELFNAME '('
  595. { $$ = begin_constructor_declarator ($2, $3); }
  596. parmlist ')' cv_qualifiers exception_specification_opt
  597. { $$ = make_call_declarator ($&lt;ttype&gt;5, $6, $8, $9); }
  598. | global_scope nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
  599. { $$ = begin_constructor_declarator ($2, $3);
  600. $$ = make_call_declarator ($$, empty_parms (), $5, $6);
  601. }
  602. | nested_name_specifier self_template_type '('
  603. { $$ = begin_constructor_declarator ($1, $2); }
  604. parmlist ')' cv_qualifiers exception_specification_opt
  605. { $$ = make_call_declarator ($&lt;ttype&gt;4, $5, $7, $8); }
  606. | nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
  607. { $$ = begin_constructor_declarator ($1, $2);
  608. $$ = make_call_declarator ($$, empty_parms (), $4, $5);
  609. }
  610. | global_scope nested_name_specifier self_template_type '('
  611. { $$ = begin_constructor_declarator ($2, $3); }
  612. parmlist ')' cv_qualifiers exception_specification_opt
  613. { $$ = make_call_declarator ($&lt;ttype&gt;5, $6, $8, $9); }
  614. | global_scope nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
  615. { $$ = begin_constructor_declarator ($2, $3);
  616. $$ = make_call_declarator ($$, empty_parms (), $5, $6);
  617. }
  618. ;
  619. fn.def1:
  620. typed_declspecs declarator
  621. { if (!begin_function_definition ($1.t, $2))
  622. YYERROR1; }
  623. | declmods notype_declarator
  624. { if (!begin_function_definition ($1, $2))
  625. YYERROR1; }
  626. | notype_declarator
  627. { if (!begin_function_definition (NULL_TREE, $1))
  628. YYERROR1; }
  629. | declmods constructor_declarator
  630. { if (!begin_function_definition ($1, $2))
  631. YYERROR1; }
  632. | constructor_declarator
  633. { if (!begin_function_definition (NULL_TREE, $1))
  634. YYERROR1; }
  635. ;
  636. component_constructor_declarator:
  637. SELFNAME '(' parmlist ')' cv_qualifiers exception_specification_opt
  638. { $$ = make_call_declarator ($1, $3, $5, $6); }
  639. | SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
  640. { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
  641. | self_template_type '(' parmlist ')' cv_qualifiers exception_specification_opt
  642. { $$ = make_call_declarator ($1, $3, $5, $6); }
  643. | self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
  644. { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
  645. ;
  646. /* more C++ complexity. See component_decl for a comment on the
  647. reduce/reduce conflict introduced by these rules. */
  648. fn.def2:
  649. declmods component_constructor_declarator
  650. { tree specs, attrs;
  651. split_specs_attrs ($1, &amp;specs, &amp;attrs);
  652. attrs = build_tree_list (attrs, NULL_TREE);
  653. $$ = start_method (specs, $2, attrs);
  654. rest_of_mdef:
  655. if (! $$)
  656. YYERROR1;
  657. if (yychar == YYEMPTY)
  658. yychar = YYLEX;
  659. reinit_parse_for_method (yychar, $$); }
  660. | component_constructor_declarator
  661. { $$ = start_method (NULL_TREE, $1, NULL_TREE);
  662. goto rest_of_mdef; }
  663. | typed_declspecs declarator
  664. { tree specs, attrs;
  665. split_specs_attrs ($1.t, &amp;specs, &amp;attrs);
  666. attrs = build_tree_list (attrs, NULL_TREE);
  667. $$ = start_method (specs, $2, attrs); goto rest_of_mdef; }
  668. | declmods notype_declarator
  669. { tree specs, attrs;
  670. split_specs_attrs ($1, &amp;specs, &amp;attrs);
  671. attrs = build_tree_list (attrs, NULL_TREE);
  672. $$ = start_method (specs, $2, attrs); goto rest_of_mdef; }
  673. | notype_declarator
  674. { $$ = start_method (NULL_TREE, $$, NULL_TREE);
  675. goto rest_of_mdef; }
  676. | declmods constructor_declarator
  677. { tree specs, attrs;
  678. split_specs_attrs ($1, &amp;specs, &amp;attrs);
  679. attrs = build_tree_list (attrs, NULL_TREE);
  680. $$ = start_method (specs, $2, attrs); goto rest_of_mdef; }
  681. | constructor_declarator
  682. { $$ = start_method (NULL_TREE, $$, NULL_TREE);
  683. goto rest_of_mdef; }
  684. ;
  685. return_id:
  686. RETURN_KEYWORD IDENTIFIER
  687. {
  688. if (! current_function_parms_stored)
  689. store_parm_decls ();
  690. $$ = $2;
  691. }
  692. ;
  693. return_init:
  694. return_id maybe_init
  695. { store_return_init ($&lt;ttype&gt;$, $2); }
  696. | return_id '(' nonnull_exprlist ')'
  697. { store_return_init ($&lt;ttype&gt;$, $3); }
  698. | return_id LEFT_RIGHT
  699. { store_return_init ($&lt;ttype&gt;$, NULL_TREE); }
  700. ;
  701. base_init:
  702. ':' .set_base_init member_init_list
  703. {
  704. if ($3 == 0)
  705. error (&quot;no base initializers given following ':'&quot;);
  706. setup_vtbl_ptr ();
  707. /* Always keep the BLOCK node associated with the outermost
  708. pair of curley braces of a function. These are needed
  709. for correct operation of dwarfout.c. */
  710. keep_next_level ();
  711. }
  712. ;
  713. .set_base_init:
  714. /* empty */
  715. {
  716. if (! current_function_parms_stored)
  717. store_parm_decls ();
  718. if (DECL_CONSTRUCTOR_P (current_function_decl))
  719. {
  720. /* Make a contour for the initializer list. */
  721. pushlevel (0);
  722. clear_last_expr ();
  723. expand_start_bindings (0);
  724. }
  725. else if (current_class_type == NULL_TREE)
  726. error (&quot;base initializers not allowed for non-member functions&quot;);
  727. else if (! DECL_CONSTRUCTOR_P (current_function_decl))
  728. error (&quot;only constructors take base initializers&quot;);
  729. }
  730. ;
  731. member_init_list:
  732. /* empty */
  733. { $$ = 0; }
  734. | member_init
  735. { $$ = 1; }
  736. | member_init_list ',' member_init
  737. | member_init_list error
  738. ;
  739. member_init:
  740. '(' nonnull_exprlist ')'
  741. {
  742. if (current_class_name)
  743. pedwarn (&quot;anachronistic old style base class initializer&quot;);
  744. expand_member_init (current_class_ref, NULL_TREE, $2);
  745. }
  746. | LEFT_RIGHT
  747. {
  748. if (current_class_name)
  749. pedwarn (&quot;anachronistic old style base class initializer&quot;);
  750. expand_member_init (current_class_ref, NULL_TREE, void_type_node);
  751. }
  752. | notype_identifier '(' nonnull_exprlist ')'
  753. { expand_member_init (current_class_ref, $1, $3); }
  754. | notype_identifier LEFT_RIGHT
  755. { expand_member_init (current_class_ref, $1, void_type_node); }
  756. | nonnested_type '(' nonnull_exprlist ')'
  757. { expand_member_init (current_class_ref, $1, $3); }
  758. | nonnested_type LEFT_RIGHT
  759. { expand_member_init (current_class_ref, $1, void_type_node); }
  760. | typename_sub '(' nonnull_exprlist ')'
  761. { expand_member_init (current_class_ref, TYPE_MAIN_DECL ($1),
  762. $3); }
  763. | typename_sub LEFT_RIGHT
  764. { expand_member_init (current_class_ref, TYPE_MAIN_DECL ($1),
  765. void_type_node); }
  766. ;
  767. identifier:
  768. IDENTIFIER
  769. | TYPENAME
  770. | SELFNAME
  771. | PTYPENAME
  772. | NSNAME
  773. ;
  774. notype_identifier:
  775. IDENTIFIER
  776. | PTYPENAME
  777. | NSNAME %prec EMPTY
  778. ;
  779. identifier_defn:
  780. IDENTIFIER_DEFN
  781. | TYPENAME_DEFN
  782. | PTYPENAME_DEFN
  783. ;
  784. explicit_instantiation:
  785. TEMPLATE begin_explicit_instantiation typespec ';'
  786. { do_type_instantiation ($3.t, NULL_TREE);
  787. yyungetc (';', 1); }
  788. end_explicit_instantiation
  789. | TEMPLATE begin_explicit_instantiation typed_declspecs declarator
  790. { tree specs = strip_attrs ($3.t);
  791. do_decl_instantiation (specs, $4, NULL_TREE); }
  792. end_explicit_instantiation
  793. | TEMPLATE begin_explicit_instantiation notype_declarator
  794. { do_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
  795. end_explicit_instantiation
  796. | TEMPLATE begin_explicit_instantiation constructor_declarator
  797. { do_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
  798. end_explicit_instantiation
  799. | SCSPEC TEMPLATE begin_explicit_instantiation typespec ';'
  800. { do_type_instantiation ($4.t, $1);
  801. yyungetc (';', 1); }
  802. end_explicit_instantiation
  803. | SCSPEC TEMPLATE begin_explicit_instantiation typed_declspecs
  804. declarator
  805. { tree specs = strip_attrs ($4.t);
  806. do_decl_instantiation (specs, $5, $1); }
  807. end_explicit_instantiation
  808. | SCSPEC TEMPLATE begin_explicit_instantiation notype_declarator
  809. { do_decl_instantiation (NULL_TREE, $4, $1); }
  810. end_explicit_instantiation
  811. | SCSPEC TEMPLATE begin_explicit_instantiation constructor_declarator
  812. { do_decl_instantiation (NULL_TREE, $4, $1); }
  813. end_explicit_instantiation
  814. ;
  815. begin_explicit_instantiation:
  816. { begin_explicit_instantiation(); }
  817. end_explicit_instantiation:
  818. { end_explicit_instantiation(); }
  819. /* The TYPENAME expansions are to deal with use of a template class name as
  820. a template within the class itself, where the template decl is hidden by
  821. a type decl. Got all that? */
  822. template_type:
  823. PTYPENAME '&lt;' template_arg_list_opt template_close_bracket
  824. .finish_template_type
  825. { $$ = $5; }
  826. | TYPENAME '&lt;' template_arg_list_opt template_close_bracket
  827. .finish_template_type
  828. { $$ = $5; }
  829. | self_template_type
  830. ;
  831. apparent_template_type:
  832. template_type
  833. | identifier '&lt;' template_arg_list_opt '&gt;'
  834. .finish_template_type
  835. { $$ = $5; }
  836. self_template_type:
  837. SELFNAME '&lt;' template_arg_list_opt template_close_bracket
  838. .finish_template_type
  839. { $$ = $5; }
  840. ;
  841. .finish_template_type:
  842. {
  843. if (yychar == YYEMPTY)
  844. yychar = YYLEX;
  845. $$ = finish_template_type ($&lt;ttype&gt;-3, $&lt;ttype&gt;-1,
  846. yychar == SCOPE);
  847. }
  848. template_close_bracket:
  849. '&gt;'
  850. | RSHIFT
  851. {
  852. /* Handle `Class&lt;Class&lt;Type&gt;&gt;' without space in the `&gt;&gt;' */
  853. pedwarn (&quot;`&gt;&gt;' should be `&gt; &gt;' in template class name&quot;);
  854. yyungetc ('&gt;', 1);
  855. }
  856. ;
  857. template_arg_list_opt:
  858. /* empty */
  859. { $$ = NULL_TREE; }
  860. | template_arg_list
  861. ;
  862. template_arg_list:
  863. template_arg
  864. { $$ = build_tree_list (NULL_TREE, $$); }
  865. | template_arg_list ',' template_arg
  866. { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); }
  867. ;
  868. template_arg:
  869. type_id
  870. { $$ = groktypename ($1.t); }
  871. | PTYPENAME
  872. { $$ = lastiddecl; }
  873. | expr_no_commas %prec ARITHCOMPARE
  874. ;
  875. unop:
  876. '-'
  877. { $$ = NEGATE_EXPR; }
  878. | '+'
  879. { $$ = CONVERT_EXPR; }
  880. | PLUSPLUS
  881. { $$ = PREINCREMENT_EXPR; }
  882. | MINUSMINUS
  883. { $$ = PREDECREMENT_EXPR; }
  884. | '!'
  885. { $$ = TRUTH_NOT_EXPR; }
  886. ;
  887. expr:
  888. nontrivial_exprlist
  889. { $$ = build_x_compound_expr ($$); }
  890. | expr_no_commas
  891. ;
  892. paren_expr_or_null:
  893. LEFT_RIGHT
  894. { error (&quot;ANSI C++ forbids an empty condition for `%s'&quot;,
  895. cond_stmt_keyword);
  896. $$ = integer_zero_node; }
  897. | '(' expr ')'
  898. { $$ = $2; }
  899. ;
  900. paren_cond_or_null:
  901. LEFT_RIGHT
  902. { error (&quot;ANSI C++ forbids an empty condition for `%s'&quot;,
  903. cond_stmt_keyword);
  904. $$ = integer_zero_node; }
  905. | '(' condition ')'
  906. { $$ = $2; }
  907. ;
  908. xcond:
  909. /* empty */
  910. { $$ = NULL_TREE; }
  911. | condition
  912. | error
  913. { $$ = NULL_TREE; }
  914. ;
  915. condition:
  916. type_specifier_seq declarator maybeasm maybe_attribute '='
  917. { {
  918. tree d;
  919. for (d = getdecls (); d; d = TREE_CHAIN (d))
  920. if (TREE_CODE (d) == TYPE_DECL) {
  921. tree s = TREE_TYPE (d);
  922. if (TREE_CODE (s) == RECORD_TYPE)
  923. cp_error (&quot;definition of class `%T' in condition&quot;, s);
  924. else if (TREE_CODE (s) == ENUMERAL_TYPE)
  925. cp_error (&quot;definition of enum `%T' in condition&quot;, s);
  926. }
  927. }
  928. current_declspecs = $1.t;
  929. $&lt;itype&gt;5 = suspend_momentary ();
  930. $&lt;ttype&gt;$ = start_decl ($&lt;ttype&gt;2, current_declspecs, 1,
  931. $4, /*prefix_attributes*/ NULL_TREE);
  932. }
  933. init
  934. {
  935. cp_finish_decl ($&lt;ttype&gt;6, $7, $4, 1, LOOKUP_ONLYCONVERTING);
  936. resume_momentary ($&lt;itype&gt;5);
  937. $$ = convert_from_reference ($&lt;ttype&gt;6);
  938. if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE)
  939. cp_error (&quot;definition of array `%#D' in condition&quot;, $$);
  940. }
  941. | expr
  942. ;
  943. compstmtend:
  944. '}'
  945. | maybe_label_decls stmts '}'
  946. | maybe_label_decls stmts error '}'
  947. | maybe_label_decls error '}'
  948. ;
  949. already_scoped_stmt:
  950. '{'
  951. { $&lt;ttype&gt;$ = begin_compound_stmt (1); }
  952. compstmtend
  953. { finish_compound_stmt (1, $&lt;ttype&gt;2); }
  954. | simple_stmt
  955. ;
  956. nontrivial_exprlist:
  957. expr_no_commas ',' expr_no_commas
  958. { $$ = expr_tree_cons (NULL_TREE, $$,
  959. build_expr_list (NULL_TREE, $3)); }
  960. | expr_no_commas ',' error
  961. { $$ = expr_tree_cons (NULL_TREE, $$,
  962. build_expr_list (NULL_TREE, error_mark_node)); }
  963. | nontrivial_exprlist ',' expr_no_commas
  964. { chainon ($$, build_expr_list (NULL_TREE, $3)); }
  965. | nontrivial_exprlist ',' error
  966. { chainon ($$, build_expr_list (NULL_TREE, error_mark_node)); }
  967. ;
  968. nonnull_exprlist:
  969. expr_no_commas
  970. { $$ = build_expr_list (NULL_TREE, $$); }
  971. | nontrivial_exprlist
  972. ;
  973. unary_expr:
  974. primary %prec UNARY
  975. { $$ = $1; }
  976. /* __extension__ turns off -pedantic for following primary. */
  977. | extension cast_expr %prec UNARY
  978. { $$ = $2;
  979. pedantic = $&lt;itype&gt;1; }
  980. | '*' cast_expr %prec UNARY
  981. { $$ = build_x_indirect_ref ($2, &quot;unary *&quot;); }
  982. | '&amp;' cast_expr %prec UNARY
  983. { $$ = build_x_unary_op (ADDR_EXPR, $2); }
  984. | '~' cast_expr
  985. { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
  986. | unop cast_expr %prec UNARY
  987. { $$ = finish_unary_op_expr ($1, $2); }
  988. /* Refer to the address of a label as a pointer. */
  989. | ANDAND identifier
  990. { if (pedantic)
  991. pedwarn (&quot;ANSI C++ forbids `&amp;&amp;'&quot;);
  992. $$ = finish_label_address_expr ($2); }
  993. | SIZEOF unary_expr %prec UNARY
  994. { $$ = expr_sizeof ($2); }
  995. | SIZEOF '(' type_id ')' %prec HYPERUNARY
  996. { $$ = c_sizeof (groktypename ($3.t));
  997. check_for_new_type (&quot;sizeof&quot;, $3); }
  998. | ALIGNOF unary_expr %prec UNARY
  999. { $$ = grok_alignof ($2); }
  1000. | ALIGNOF '(' type_id ')' %prec HYPERUNARY
  1001. { $$ = c_alignof (groktypename ($3.t));
  1002. check_for_new_type (&quot;alignof&quot;, $3); }
  1003. | VEC_STEP unary_expr %prec UNARY
  1004. { $$ = c_vec_step_expr ($2); }
  1005. | VEC_STEP '(' type_id ')' %prec HYPERUNARY
  1006. { $$ = c_vec_step (groktypename ($3.t)); }
  1007. /* The %prec EMPTY's here are required by the = init initializer
  1008. syntax extension; see below. */
  1009. | new new_type_id %prec EMPTY
  1010. { $$ = build_new (NULL_TREE, $2.t, NULL_TREE, $1);
  1011. check_for_new_type (&quot;new&quot;, $2); }
  1012. | new new_type_id new_initializer
  1013. { $$ = build_new (NULL_TREE, $2.t, $3, $1);
  1014. check_for_new_type (&quot;new&quot;, $2); }
  1015. | new new_placement new_type_id %prec EMPTY
  1016. { $$ = build_new ($2, $3.t, NULL_TREE, $1);
  1017. check_for_new_type (&quot;new&quot;, $3); }
  1018. | new new_placement new_type_id new_initializer
  1019. { $$ = build_new ($2, $3.t, $4, $1);
  1020. check_for_new_type (&quot;new&quot;, $3); }
  1021. /* The .begin_new_placement in the following rules is
  1022. necessary to avoid shift/reduce conflicts that lead to
  1023. mis-parsing some expressions. Of course, these constructs
  1024. are not really new-placement and it is bogus to call
  1025. begin_new_placement. But, the parser cannot always tell at this
  1026. point whether the next thing is an expression or a type-id,
  1027. so there is nothing we can do. Fortunately,
  1028. begin_new_placement does nothing harmful. When we rewrite
  1029. the parser, this lossage should be removed, of course. */
  1030. | new '(' .begin_new_placement type_id .finish_new_placement
  1031. %prec EMPTY
  1032. { $$ = build_new (NULL_TREE, groktypename($4.t),
  1033. NULL_TREE, $1);
  1034. check_for_new_type (&quot;new&quot;, $4); }
  1035. | new '(' .begin_new_placement type_id .finish_new_placement
  1036. new_initializer
  1037. { $$ = build_new (NULL_TREE, groktypename($4.t), $6, $1);
  1038. check_for_new_type (&quot;new&quot;, $4); }
  1039. | new new_placement '(' .begin_new_placement type_id
  1040. .finish_new_placement %prec EMPTY
  1041. { $$ = build_new ($2, groktypename($5.t), NULL_TREE, $1);
  1042. check_for_new_type (&quot;new&quot;, $5); }
  1043. | new new_placement '(' .begin_new_placement type_id
  1044. .finish_new_placement new_initializer
  1045. { $$ = build_new ($2, groktypename($5.t), $7, $1);
  1046. check_for_new_type (&quot;new&quot;, $5); }
  1047. | delete cast_expr %prec UNARY
  1048. { $$ = delete_sanity ($2, NULL_TREE, 0, $1); }
  1049. | delete '[' ']' cast_expr %prec UNARY
  1050. { $$ = delete_sanity ($4, NULL_TREE, 1, $1);
  1051. if (yychar == YYEMPTY)
  1052. yychar = YYLEX; }
  1053. | delete '[' expr ']' cast_expr %prec UNARY
  1054. { $$ = delete_sanity ($5, $3, 2, $1);
  1055. if (yychar == YYEMPTY)
  1056. yychar = YYLEX; }
  1057. | REALPART cast_expr %prec UNARY
  1058. { $$ = build_x_unary_op (REALPART_EXPR, $2); }
  1059. | IMAGPART cast_expr %prec UNARY
  1060. { $$ = build_x_unary_op (IMAGPART_EXPR, $2); }
  1061. ;
  1062. /* Note this rule is not suitable for use in new_placement
  1063. since it uses NULL_TREE as the argument to
  1064. finish_new_placement. This rule serves only to avoid
  1065. reduce/reduce conflicts in unary_expr. See the comments
  1066. there on the use of begin/finish_new_placement. */
  1067. .finish_new_placement:
  1068. ')'
  1069. { finish_new_placement (NULL_TREE, $&lt;itype&gt;-1); }
  1070. .begin_new_placement:
  1071. { $$ = begin_new_placement (); }
  1072. new_placement:
  1073. '(' .begin_new_placement nonnull_exprlist ')'
  1074. { $$ = finish_new_placement ($3, $2); }
  1075. | '{' .begin_new_placement nonnull_exprlist '}'
  1076. { cp_pedwarn (&quot;old style placement syntax, use () instead&quot;);
  1077. $$ = finish_new_placement ($3, $2); }
  1078. ;
  1079. new_initializer:
  1080. '(' nonnull_exprlist ')'
  1081. { $$ = $2; }
  1082. | LEFT_RIGHT
  1083. { $$ = NULL_TREE; }
  1084. | '(' typespec ')'
  1085. {
  1086. cp_error (&quot;`%T' is not a valid expression&quot;, $2.t);
  1087. $$ = error_mark_node;
  1088. }
  1089. /* GNU extension so people can use initializer lists. Note that
  1090. this alters the meaning of `new int = 1', which was previously
  1091. syntactically valid but semantically invalid. */
  1092. | '=' init
  1093. {
  1094. if (pedantic)
  1095. pedwarn (&quot;ANSI C++ forbids initialization of new expression with `='&quot;);
  1096. if (TREE_CODE ($2) != TREE_LIST
  1097. &amp;&amp; TREE_CODE ($2) != CONSTRUCTOR)
  1098. $$ = build_expr_list (NULL_TREE, $2);
  1099. else
  1100. $$ = $2;
  1101. }
  1102. ;
  1103. /* This is necessary to postpone reduction of `int ((int)(int)(int))'. */
  1104. regcast_or_absdcl:
  1105. '(' type_id ')' %prec EMPTY
  1106. { $2.t = finish_parmlist (build_tree_list (NULL_TREE, $2.t), 0);
  1107. $$ = make_call_declarator (NULL_TREE, $2.t, NULL_TREE, NULL_TREE);
  1108. check_for_new_type (&quot;cast&quot;, $2); }
  1109. | regcast_or_absdcl '(' type_id ')' %prec EMPTY
  1110. { $3.t = finish_parmlist (build_tree_list (NULL_TREE, $3.t), 0);
  1111. $$ = make_call_declarator ($$, $3.t, NULL_TREE, NULL_TREE);
  1112. check_for_new_type (&quot;cast&quot;, $3); }
  1113. ;
  1114. cast_expr:
  1115. unary_expr
  1116. | regcast_or_absdcl '(' nontrivial_exprlist ')' %prec UNARY
  1117. { $$ = reparse_absdcl_as_casts_or_vector_constant ($$, $3); }
  1118. | regcast_or_absdcl unary_expr %prec UNARY
  1119. { $$ = reparse_absdcl_as_casts_or_vector_constant ($$, $2); }
  1120. | regcast_or_absdcl '{' initlist maybecomma '}' %prec UNARY
  1121. {
  1122. tree init = build_nt (CONSTRUCTOR, NULL_TREE,
  1123. nreverse ($3));
  1124. if (pedantic)
  1125. pedwarn (&quot;ANSI C++ forbids constructor-expressions&quot;);
  1126. /* Indicate that this was a GNU C constructor expression. */
  1127. TREE_HAS_CONSTRUCTOR (init) = 1;
  1128. $$ = reparse_absdcl_as_casts ($$, init);
  1129. }
  1130. ;
  1131. expr_no_commas:
  1132. cast_expr
  1133. /* Handle general members. */
  1134. | expr_no_commas POINTSAT_STAR expr_no_commas
  1135. { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
  1136. | expr_no_commas DOT_STAR expr_no_commas
  1137. { $$ = build_m_component_ref ($$, $3); }
  1138. | expr_no_commas '+' expr_no_commas
  1139. { $$ = build_x_binary_op ($2, $$, $3); }
  1140. | expr_no_commas '-' expr_no_commas
  1141. { $$ = build_x_binary_op ($2, $$, $3); }
  1142. | expr_no_commas '*' expr_no_commas
  1143. { $$ = build_x_binary_op ($2, $$, $3); }
  1144. | expr_no_commas '/' expr_no_commas
  1145. { $$ = build_x_binary_op ($2, $$, $3); }
  1146. | expr_no_commas '%' expr_no_commas
  1147. { $$ = build_x_binary_op ($2, $$, $3); }
  1148. | expr_no_commas LSHIFT expr_no_commas
  1149. { $$ = build_x_binary_op ($2, $$, $3); }
  1150. | expr_no_commas RSHIFT expr_no_commas
  1151. { $$ = build_x_binary_op ($2, $$, $3); }
  1152. | expr_no_commas ARITHCOMPARE expr_no_commas
  1153. { $$ = build_x_binary_op ($2, $$, $3); }
  1154. | expr_no_commas '&lt;' expr_no_commas
  1155. { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
  1156. | expr_no_commas '&gt;' expr_no_commas
  1157. { $$ = build_x_binary_op (GT_EXPR, $$, $3); }
  1158. | expr_no_commas EQCOMPARE expr_no_commas
  1159. { $$ = build_x_binary_op ($2, $$, $3); }
  1160. | expr_no_commas MIN_MAX expr_no_commas
  1161. { $$ = build_x_binary_op ($2, $$, $3); }
  1162. | expr_no_commas '&amp;' expr_no_commas
  1163. { $$ = build_x_binary_op ($2, $$, $3); }
  1164. | expr_no_commas '|' expr_no_commas
  1165. { $$ = build_x_binary_op ($2, $$, $3); }
  1166. | expr_no_commas '^' expr_no_commas
  1167. { $$ = build_x_binary_op ($2, $$, $3); }
  1168. | expr_no_commas ANDAND expr_no_commas
  1169. { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
  1170. | expr_no_commas OROR expr_no_commas
  1171. { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
  1172. | expr_no_commas '?' xexpr ':' expr_no_commas
  1173. { $$ = build_x_conditional_expr ($$, $3, $5); }
  1174. | expr_no_commas '=' expr_no_commas
  1175. { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
  1176. if ($$ != error_mark_node)
  1177. C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
  1178. | expr_no_commas ASSIGN expr_no_commas
  1179. { $$ = build_x_modify_expr ($$, $2, $3); }
  1180. | THROW
  1181. { $$ = build_throw (NULL_TREE); }
  1182. | THROW expr_no_commas
  1183. { $$ = build_throw ($2); }
  1184. /* These extensions are not defined. The second arg to build_m_component_ref
  1185. is old, build_m_component_ref now does an implicit
  1186. build_indirect_ref (x, NULL_PTR) on the second argument.
  1187. | object '&amp;' expr_no_commas %prec UNARY
  1188. { $$ = build_m_component_ref ($$, build_x_unary_op (ADDR_EXPR, $3)); }
  1189. | object unop expr_no_commas %prec UNARY
  1190. { $$ = build_m_component_ref ($$, build_x_unary_op ($2, $3)); }
  1191. | object '(' type_id ')' expr_no_commas %prec UNARY
  1192. { tree type = groktypename ($3.t);
  1193. $$ = build_m_component_ref ($$, build_c_cast (type, $5)); }
  1194. | object primary_no_id %prec UNARY
  1195. { $$ = build_m_component_ref ($$, $2); }
  1196. */
  1197. ;
  1198. notype_unqualified_id:
  1199. '~' see_typename identifier
  1200. { $$ = build_parse_node (BIT_NOT_EXPR, $3); }
  1201. | '~' see_typename template_type
  1202. { $$ = build_parse_node (BIT_NOT_EXPR, $3); }
  1203. | template_id
  1204. | operator_name
  1205. | IDENTIFIER
  1206. | PTYPENAME
  1207. | NSNAME %prec EMPTY
  1208. ;
  1209. do_id:
  1210. {
  1211. /* If lastiddecl is a TREE_LIST, it's a baselink, which
  1212. means that we're in an expression like S::f&lt;int&gt;, so
  1213. don't do_identifier; we only do that for unqualified
  1214. identifiers. */
  1215. if (lastiddecl &amp;&amp; TREE_CODE (lastiddecl) != TREE_LIST)
  1216. $$ = do_identifier ($&lt;ttype&gt;-1, 1, NULL_TREE);
  1217. else
  1218. $$ = $&lt;ttype&gt;-1;
  1219. }
  1220. template_id:
  1221. PFUNCNAME '&lt;' do_id template_arg_list_opt template_close_bracket
  1222. { $$ = lookup_template_function ($3, $4); }
  1223. | operator_name '&lt;' do_id template_arg_list_opt template_close_bracket
  1224. { $$ = lookup_template_function ($3, $4); }
  1225. ;
  1226. object_template_id:
  1227. TEMPLATE identifier '&lt;' template_arg_list_opt template_close_bracket
  1228. { $$ = lookup_template_function ($2, $4); }
  1229. | TEMPLATE PFUNCNAME '&lt;' template_arg_list_opt template_close_bracket
  1230. { $$ = lookup_template_function ($2, $4); }
  1231. | TEMPLATE operator_name '&lt;' template_arg_list_opt
  1232. template_close_bracket
  1233. { $$ = lookup_template_function ($2, $4); }
  1234. ;
  1235. unqualified_id:
  1236. notype_unqualified_id
  1237. | TYPENAME
  1238. | SELFNAME
  1239. ;
  1240. expr_or_declarator_intern:
  1241. expr_or_declarator
  1242. | attributes expr_or_declarator
  1243. {
  1244. /* Provide support for '(' attributes '*' declarator ')'
  1245. etc */
  1246. $$ = decl_tree_cons ($1, $2, NULL_TREE);
  1247. }
  1248. ;
  1249. expr_or_declarator:
  1250. notype_unqualified_id
  1251. | '*' expr_or_declarator_intern %prec UNARY
  1252. { $$ = build_parse_node (INDIRECT_REF, $2); }
  1253. | '&amp;' expr_or_declarator_intern %prec UNARY
  1254. { $$ = build_parse_node (ADDR_EXPR, $2); }
  1255. | '(' expr_or_declarator_intern ')'
  1256. { $$ = $2; }
  1257. ;
  1258. notype_template_declarator:
  1259. IDENTIFIER '&lt;' template_arg_list_opt template_close_bracket
  1260. { $$ = lookup_template_function ($1, $3); }
  1261. | NSNAME '&lt;' template_arg_list template_close_bracket
  1262. { $$ = lookup_template_function ($1, $3); }
  1263. ;
  1264. direct_notype_declarator:
  1265. complex_direct_notype_declarator
  1266. /* This precedence declaration is to prefer this reduce
  1267. to the Koenig lookup shift in primary, below. I hate yacc. */
  1268. | notype_unqualified_id %prec '('
  1269. | notype_template_declarator
  1270. | '(' expr_or_declarator_intern ')'
  1271. { $$ = finish_decl_parsing ($2); }
  1272. ;
  1273. primary:
  1274. notype_unqualified_id
  1275. {
  1276. if (TREE_CODE ($1) == BIT_NOT_EXPR)
  1277. $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($1, 0));
  1278. else
  1279. $$ = finish_id_expr ($1);
  1280. }
  1281. | CONSTANT
  1282. | boolean.literal
  1283. | string
  1284. {
  1285. if (processing_template_decl)
  1286. push_obstacks (&amp;permanent_obstack, &amp;permanent_obstack);
  1287. $$ = combine_strings ($$);
  1288. /* combine_strings doesn't set up TYPE_MAIN_VARIANT of
  1289. a const array the way we want, so fix it. */
  1290. if (flag_const_strings)
  1291. TREE_TYPE ($$) = build_cplus_array_type
  1292. (TREE_TYPE (TREE_TYPE ($$)),
  1293. TYPE_DOMAIN (TREE_TYPE ($$)));
  1294. if (processing_template_decl)
  1295. pop_obstacks ();
  1296. }
  1297. | '(' expr ')'
  1298. { $$ = finish_parenthesized_expr ($2); }
  1299. | '(' expr_or_declarator_intern ')'
  1300. { $2 = reparse_decl_as_expr (NULL_TREE, $2);
  1301. $$ = finish_parenthesized_expr ($2); }
  1302. | '(' error ')'
  1303. { $$ = error_mark_node; }
  1304. | '('
  1305. { tree scope = current_scope ();
  1306. if (!scope || TREE_CODE (scope) != FUNCTION_DECL)
  1307. {
  1308. error (&quot;braced-group within expression allowed only inside a function&quot;);
  1309. YYERROR;
  1310. }
  1311. if (pedantic)
  1312. pedwarn (&quot;ANSI C++ forbids braced-groups within expressions&quot;);
  1313. $&lt;ttype&gt;$ = begin_stmt_expr ();
  1314. }
  1315. compstmt ')'
  1316. { $$ = finish_stmt_expr ($&lt;ttype&gt;2, $3); }
  1317. /* Koenig lookup support
  1318. We could store lastiddecl in $1 to avoid another lookup,
  1319. but that would result in many additional reduce/reduce conflicts. */
  1320. | notype_unqualified_id '(' nonnull_exprlist ')'
  1321. { $$ = finish_call_expr ($1, $3, 1); }
  1322. | notype_unqualified_id LEFT_RIGHT
  1323. { $$ = finish_call_expr ($1, NULL_TREE, 1); }
  1324. | primary '(' nonnull_exprlist ')'
  1325. { $$ = finish_call_expr ($1, $3, 0); }
  1326. | primary LEFT_RIGHT
  1327. { $$ = finish_call_expr ($1, NULL_TREE, 0); }
  1328. | primary '[' expr ']'
  1329. { $$ = grok_array_decl ($$, $3); }
  1330. | primary PLUSPLUS
  1331. { $$ = finish_increment_expr ($1, POSTINCREMENT_EXPR); }
  1332. | primary MINUSMINUS
  1333. { $$ = finish_increment_expr ($1, POSTDECREMENT_EXPR); }
  1334. /* C++ extensions */
  1335. | THIS
  1336. { $$ = finish_this_expr (); }
  1337. | CV_QUALIFIER '(' nonnull_exprlist ')'
  1338. {
  1339. /* This is a C cast in C++'s `functional' notation
  1340. using the &quot;implicit int&quot; extension so that:
  1341. `const (3)' is equivalent to `const int (3)'. */
  1342. tree type;
  1343. if ($3 == error_mark_node)
  1344. {
  1345. $$ = error_mark_node;
  1346. break;
  1347. }
  1348. type = cp_build_qualified_type (integer_type_node,
  1349. cp_type_qual_from_rid ($1));
  1350. $$ = build_c_cast (type, build_compound_expr ($3));
  1351. }
  1352. | functional_cast
  1353. | DYNAMIC_CAST '&lt;' type_id '&gt;' '(' expr ')'
  1354. { tree type = groktypename ($3.t);
  1355. check_for_new_type (&quot;dynamic_cast&quot;, $3);
  1356. $$ = build_dynamic_cast (type, $6); }
  1357. | STATIC_CAST '&lt;' type_id '&gt;' '(' expr ')'
  1358. { tree type = groktypename ($3.t);
  1359. check_for_new_type (&quot;static_cast&quot;, $3);
  1360. $$ = build_static_cast (type, $6); }
  1361. | REINTERPRET_CAST '&lt;' type_id '&gt;' '(' expr ')'
  1362. { tree type = groktypename ($3.t);
  1363. check_for_new_type (&quot;reinterpret_cast&quot;, $3);
  1364. $$ = build_reinterpret_cast (type, $6); }
  1365. | CONST_CAST '&lt;' type_id '&gt;' '(' expr ')'
  1366. { tree type = groktypename ($3.t);
  1367. check_for_new_type (&quot;const_cast&quot;, $3);
  1368. $$ = build_const_cast (type, $6); }
  1369. | TYPEID '(' expr ')'
  1370. { $$ = build_x_typeid ($3); }
  1371. | TYPEID '(' type_id ')'
  1372. { tree type = groktypename ($3.t);
  1373. check_for_new_type (&quot;typeid&quot;, $3);
  1374. $$ = get_typeid (TYPE_MAIN_VARIANT (type)); }
  1375. | global_scope IDENTIFIER
  1376. { $$ = do_scoped_id ($2, 1); }
  1377. | global_scope template_id
  1378. { $$ = $2; }
  1379. | global_scope operator_name
  1380. {
  1381. got_scope = NULL_TREE;
  1382. if (TREE_CODE ($2) == IDENTIFIER_NODE)
  1383. $$ = do_scoped_id ($2, 1);
  1384. else
  1385. $$ = $2;
  1386. }
  1387. | overqualified_id %prec HYPERUNARY
  1388. { $$ = build_offset_ref (OP0 ($$), OP1 ($$)); }
  1389. | overqualif

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