PageRenderTime 65ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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