PageRenderTime 60ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/interfaces/gcc/c_files/cp/parse.y

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