1 /* YACC parser for C++ syntax.
2 Copyright (C) 1988, 1989, 1993 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* This grammar is based on the GNU CC grammar. */
24 /* Note: Bison automatically applies a default action of "$$ = $1" for
25 all derivations; this is applied before the explicit action, if one
26 is given. Keep this in mind when reading the actions. */
28 /* Also note: this version contains experimental exception
29 handling features. They could break, change, disappear,
30 or otherwise exhibit volatile behavior. Don't depend on
31 me (Michael Tiemann) to protect you from any negative impact
32 this may have on your professional, personal, or spiritual life.
34 NEWS FLASH: This version now supports the exception handling
35 syntax of Stroustrup's 2nd edition, if -fansi-exceptions is given.
36 THIS IS WORK IN PROGRESS!!! The type of the 'throw' and the
37 'catch' much match EXACTLY (no inheritance support or coercions).
38 Also, throw-specifications of functions don't work.
39 Destructors aren't called correctly. Etc, etc. --Per Bothner.
43 /* Cause the `yydebug' variable to be defined. */
57 /* Since parsers are distinct for each language, put the language string
58 definition here. (fnf) */
59 char *language_string = "GNU C++";
61 extern tree void_list_node;
62 extern struct obstack permanent_obstack;
68 extern int end_of_file;
69 extern int current_class_depth;
73 /* Like YYERROR but do call yyerror. */
74 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
76 #define OP0(NODE) (TREE_OPERAND (NODE, 0))
77 #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 char *cond_stmt_keyword;
83 /* Nonzero if we have an `extern "C"' acting as an extern specifier. */
89 /* Cons up an empty parameter list. */
99 parms = void_list_node;
108 %union {long itype; tree ttype; char *strtype; enum tree_code code; }
110 /* All identifiers that are not reserved words
111 and are not declared typedefs in the current block */
114 /* All identifiers that are declared typedefs in the current block.
115 In some contexts, they are treated just like IDENTIFIER,
116 but they can also serve as typespecs in declarations. */
119 /* Reserved words that specify storage class.
120 yylval contains an IDENTIFIER_NODE which indicates which one. */
123 /* Reserved words that specify type.
124 yylval contains an IDENTIFIER_NODE which indicates which one. */
127 /* Reserved words that qualify type: "const" or "volatile".
128 yylval contains an IDENTIFIER_NODE which indicates which one. */
131 /* Character or numeric constants.
132 yylval is the node for the constant. */
135 /* String constants in raw form.
136 yylval is a STRING_CST node. */
139 /* "...", used for functions with variable arglists. */
142 /* the reserved words */
143 /* SCO include files test "ASM", so use something else. */
144 %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
145 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD GCC_ASM_KEYWORD TYPEOF ALIGNOF
146 %token HEADOF CLASSOF SIGOF
147 %token ATTRIBUTE EXTENSION LABEL
149 /* the reserved words... C++ extensions */
151 %token <itype> VISSPEC
152 %token DELETE NEW OVERLOAD THIS OPERATOR CXX_TRUE CXX_FALSE
153 %token NAMESPACE TYPENAME_KEYWORD USING
154 %token LEFT_RIGHT TEMPLATE
155 %token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
158 /* Define the operator tokens and their precedences.
159 The value is an integer because, if used, it is the tree code
160 to use in the expression made from the operator. */
162 %left EMPTY /* used to resolve s/r with epsilon */
166 /* Add precedence rules to solve dangling else s/r conflict */
170 %left IDENTIFIER TYPENAME PTYPENAME SCSPEC TYPESPEC TYPE_QUAL ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME
176 %right <code> ASSIGN '='
184 %left <code> EQCOMPARE
185 %left <code> ARITHCOMPARE '<' '>'
186 %left <code> LSHIFT RSHIFT
188 %left <code> '*' '/' '%'
189 %left <code> POINTSAT_STAR DOT_STAR
190 %right <code> UNARY PLUSPLUS MINUSMINUS '~'
192 %left <ttype> PAREN_STAR_PAREN LEFT_RIGHT
193 %left <code> POINTSAT '.' '(' '['
195 %right SCOPE /* C++ extension */
196 %nonassoc NEW DELETE TRY CATCH
200 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist
201 %type <ttype> paren_expr_or_null nontrivial_exprlist
202 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
203 %type <ttype> typed_declspecs reserved_declspecs boolean.literal
204 %type <ttype> typed_typespecs reserved_typespecquals
205 %type <ttype> declmods typespec typespecqual_reserved
206 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
207 %type <itype> initdecls notype_initdecls initdcl /* C++ modification */
208 %type <ttype> init initlist maybeasm maybe_init
209 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
210 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
211 %type <ttype> any_word
213 %type <ttype> compstmt implicitly_scoped_stmt
215 %type <ttype> declarator notype_declarator after_type_declarator
216 %type <ttype> direct_notype_declarator direct_after_type_declarator
218 %type <ttype> structsp opt.component_decl_list component_decl_list
219 %type <ttype> component_decl components component_declarator
220 %type <ttype> notype_components notype_component_declarator
221 %type <ttype> after_type_component_declarator after_type_component_declarator0
222 %type <ttype> notype_component_declarator0 component_decl_1
223 %type <ttype> enumlist enumerator
224 %type <ttype> type_id absdcl type_quals
225 %type <ttype> direct_abstract_declarator conversion_declarator
226 %type <ttype> new_type_id new_declarator direct_new_declarator
227 %type <ttype> xexpr parmlist parms parm bad_parm full_parm
228 %type <ttype> identifiers_or_typenames
229 %type <ttype> fcast_or_absdcl regcast_or_absdcl sub_cast_expr
230 %type <ttype> expr_or_declarator complex_notype_declarator
231 %type <ttype> notype_unqualified_id unqualified_id qualified_id
232 %type <ttype> overqualified_id notype_qualified_id any_id
233 %type <ttype> complex_direct_notype_declarator functional_cast
234 %type <ttype> named_parm complex_parmlist typed_declspecs1 parms_comma
237 %token <ttype> TYPENAME_ELLIPSIS PTYPENAME
238 %token <ttype> PRE_PARSED_FUNCTION_DECL EXTERN_LANG_STRING ALL
239 %token <ttype> PRE_PARSED_CLASS_DECL
240 %type <ttype> fn.def1 /* Not really! */
241 %type <ttype> fn.def2 return_id
242 %type <ttype> named_class_head named_class_head_sans_basetype
243 %type <ttype> unnamed_class_head
244 %type <ttype> class_head base_class_list
245 %type <itype> base_class_access_list
246 %type <ttype> base_class maybe_base_class_list base_class.1
247 %type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers
248 %type <ttype> component_declarator0
249 %type <ttype> forhead.1 operator_name
250 %type <ttype> object aggr
251 %type <itype> new delete
252 /* %type <ttype> primary_no_id */
253 %type <ttype> nonmomentary_expr
254 %type <itype> forhead.2 initdcl0 notype_initdcl0 member_init_list
255 %type <ttype> template_header template_parm_list template_parm
256 %type <ttype> template_type_parm
257 %type <ttype> template_type template_arg_list template_arg
258 %type <ttype> template_instantiation template_type_name tmpl.2
259 %type <ttype> template_instantiate_once template_instantiate_some
260 %type <itype> fn_tmpl_end
261 /* %type <itype> try_for_typename */
262 %type <ttype> condition xcond paren_cond_or_null
263 %type <ttype> type_name nested_name_specifier nested_type ptr_to_mem
264 %type <ttype> qualified_type_name complete_type_name notype_identifier
265 %type <ttype> complex_type_name nested_name_specifier_1
266 %type <itype> nomods_initdecls nomods_initdcl0
267 %type <ttype> new_initializer new_placement specialization type_specifier_seq
268 %type <ttype> using_decl
270 /* in order to recognize aggr tags as defining and thus shadowing. */
271 %token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
272 %type <ttype> named_class_head_sans_basetype_defn
273 %type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN
278 %type <strtype> .pushlevel
280 /* Used in lex.c for parsing pragmas. */
283 /* lex.c and pt.c depends on this being the last token. Define
284 any new tokens before this one! */
285 %token END_OF_SAVED_INPUT
288 /* List of types and structure classes of the current declaration. */
289 static tree current_declspecs;
290 static tree prefix_attributes = NULL_TREE;
292 /* When defining an aggregate, this is the most recent one being defined. */
293 static tree current_aggr;
295 /* Tell yyparse how to print a token's value, if yydebug is set. */
297 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
298 extern void yyprint ();
299 extern tree combine_strings PROTO((tree));
306 /* In case there were missing closebraces,
307 get us back to the global binding level. */
308 while (! global_bindings_p ())
314 /* the reason for the strange actions in this rule
315 is so that notype_initdecls when reached via datadef
316 can find a valid list of type and sc specs in $0. */
319 { $<ttype>$ = NULL_TREE; } lang_extdef
320 { $<ttype>$ = NULL_TREE; }
321 | extdefs lang_extdef
322 { $<ttype>$ = NULL_TREE; }
331 { have_extern_spec = 1;
332 used_extern_spec = 0;
333 $<ttype>$ = NULL_TREE; }
336 { have_extern_spec = 0; }
345 { if (pending_lang_change) do_pending_lang_change(); }
347 { if (! global_bindings_p () && ! pseudo_global_level_p())
353 { if (pending_inlines) do_pending_inlines (); }
355 { if (pending_inlines) do_pending_inlines (); }
357 { if (pending_inlines) do_pending_inlines (); }
359 | asm_keyword '(' string ')' ';'
360 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
362 | extern_lang_string '{' extdefs_opt '}'
363 { pop_lang_context (); }
364 | extern_lang_string .hush_warning fndef .warning_ok
365 { if (pending_inlines) do_pending_inlines ();
366 pop_lang_context (); }
367 | extern_lang_string .hush_warning datadef .warning_ok
368 { if (pending_inlines) do_pending_inlines ();
369 pop_lang_context (); }
370 | NAMESPACE identifier '{'
371 { push_namespace ($2); }
373 { pop_namespace (); }
375 { push_namespace (NULL_TREE); }
377 { pop_namespace (); }
378 | NAMESPACE identifier '=' any_id ';'
379 { do_namespace_alias ($2, $4); }
382 | USING NAMESPACE any_id ';'
383 { do_using_directive ($3); }
388 { $$ = do_using_decl ($2); }
389 | USING global_scope qualified_id
390 { $$ = do_using_decl ($3); }
391 | USING global_scope unqualified_id
392 { $$ = do_using_decl ($3); }
398 | global_scope qualified_id
400 | global_scope unqualified_id
406 { push_lang_context ($1); }
407 | extern_lang_string EXTERN_LANG_STRING
408 { if (current_lang_name != $2)
409 cp_error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name);
410 pop_lang_context (); push_lang_context ($2); }
415 { begin_template_parm_list (); }
416 template_parm_list '>'
417 { $$ = end_template_parm_list ($4); }
422 { $$ = process_template_parm (NULL_TREE, $1); }
423 | template_parm_list ',' template_parm
424 { $$ = process_template_parm ($1, $3); }
430 $$ = build_tree_list ($1, NULL_TREE);
432 if (TREE_PURPOSE ($$) == signature_type_node)
433 sorry ("signature as template type parameter");
434 else if (TREE_PURPOSE ($$) != class_type_node)
435 pedwarn ("template type parameters must use the keyword `class'");
438 { $$ = build_tree_list ($1, $2); goto ttpa; }
442 /* The following rules introduce a new reduce/reduce
443 conflict on the ',' and '>' input tokens: they are valid
444 prefixes for a `structsp', which means they could match a
445 nameless parameter. See 14.6, paragraph 3.
446 By putting them before the `parm' rule, we get
447 their match before considering them nameless parameter
450 { $$ = build_tree_list (NULL_TREE, $$); }
451 | template_type_parm '=' typespec
452 { $$ = build_tree_list ($3, $$); }
457 OVERLOAD ov_identifiers ';'
458 { warning ("use of `overload' is an anachronism"); }
461 ov_identifiers: IDENTIFIER
462 { declare_overloaded ($1); }
463 | ov_identifiers ',' IDENTIFIER
464 { declare_overloaded ($3); }
468 /* Class template declarations go here; they aren't normal class
469 declarations, because we can't process the bodies yet. */
470 template_header named_class_head_sans_basetype '{'
471 { yychar = '{'; goto template1; }
473 | template_header named_class_head_sans_basetype_defn '{'
474 { yychar = '{'; goto template1; }
476 | template_header named_class_head_sans_basetype ':'
477 { yychar = ':'; goto template1; }
479 | template_header named_class_head_sans_basetype_defn ':'
483 if (current_aggr == signature_type_node)
484 sorry ("template type defining a signature");
485 /* Maybe pedantic warning for union?
486 How about an enum? :-) */
487 end_template_decl ($1, $2, current_aggr, 1);
488 reinit_parse_for_template (yychar, $1, $2);
492 | template_header named_class_head_sans_basetype ';'
494 end_template_decl ($1, $2, current_aggr, 0);
495 /* declare $2 as template name with $1 parm list */
497 | template_header named_class_head_sans_basetype_defn ';'
499 end_template_decl ($1, $2, current_aggr, 0);
500 /* declare $2 as template name with $1 parm list */
502 | template_header /* notype_initdcl0 ';' */
503 notype_declarator exception_specification_opt maybeasm maybe_attribute
508 int def = ($6 != ';');
509 momentary = suspend_momentary ();
510 d = start_decl ($<ttype>2, /*current_declspecs*/NULL_TREE, 0,
512 cplus_decl_attributes (d, $5, prefix_attributes);
513 finish_decl (d, NULL_TREE, $4, 0, 0);
514 end_template_decl ($1, d, 0, def);
516 reinit_parse_for_template ((int) $6, $1, d);
517 resume_momentary (momentary);
519 | template_header typed_declspecs /*initdcl0*/
520 declarator exception_specification_opt maybeasm maybe_attribute
525 int def = ($7 != ';');
527 current_declspecs = $2;
528 momentary = suspend_momentary ();
529 d = start_decl ($<ttype>3, current_declspecs,
531 cplus_decl_attributes (d, $6, prefix_attributes);
532 finish_decl (d, NULL_TREE, $5, 0, 0);
533 end_template_decl ($1, d, 0, def);
536 reinit_parse_for_template ((int) $7, $1, d);
539 note_list_got_semicolon ($<ttype>2);
540 resume_momentary (momentary);
542 | template_header declmods notype_declarator fn_tmpl_end
544 int def = ($4 != ';');
545 tree d = start_decl ($<ttype>3, $<ttype>2, 0, NULL_TREE);
546 finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
547 end_template_decl ($1, d, 0, def);
549 reinit_parse_for_template ((int) $4, $1, d);
551 /* Try to recover from syntax errors in templates. */
552 | template_header error '}' { end_template_decl ($1, 0, 0, 0); }
553 | template_header error ';' { end_template_decl ($1, 0, 0, 0); }
556 fn_tmpl_end: '{' { $$ = '{'; }
560 | RETURN { $$ = RETURN; }
566 | declmods notype_initdecls ';'
568 /* Normal case to make fast: "const i;". */
569 | declmods notype_declarator ';'
571 d = start_decl ($<ttype>2, $<ttype>$, 0, NULL_TREE);
572 finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
574 | typed_declspecs initdecls ';'
576 note_list_got_semicolon ($<ttype>$);
578 /* Normal case: make this fast. */
579 | typed_declspecs declarator ';'
581 d = start_decl ($<ttype>2, $<ttype>$, 0, NULL_TREE);
582 finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
583 note_list_got_semicolon ($<ttype>$);
586 { pedwarn ("empty declaration"); }
587 | explicit_instantiation ';'
588 | typed_declspecs ';'
592 if (TREE_CODE (t) == TREE_LIST
593 && TREE_PURPOSE (t) == NULL_TREE)
597 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (t)))
599 if (CLASSTYPE_USE_TEMPLATE (t) == 0)
600 SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (t);
601 else if (CLASSTYPE_TEMPLATE_INSTANTIATION (t))
602 error ("override declaration for already-expanded template");
605 note_list_got_semicolon ($<ttype>$);
613 fn.def1 base_init compstmt_or_error
615 finish_function (lineno, 1, 0);
616 /* finish_function performs these three statements:
618 expand_end_bindings (getdecls (), 1, 0);
621 expand_end_bindings (0, 0, 0);
624 if ($<ttype>$) process_next_inline ($<ttype>$);
626 | fn.def1 return_init base_init compstmt_or_error
628 finish_function (lineno, 1, 0);
629 /* finish_function performs these three statements:
631 expand_end_bindings (getdecls (), 1, 0);
634 expand_end_bindings (0, 0, 0);
637 if ($<ttype>$) process_next_inline ($<ttype>$);
639 | fn.def1 nodecls compstmt_or_error
640 { finish_function (lineno, 0, 0);
641 if ($<ttype>$) process_next_inline ($<ttype>$); }
642 | fn.def1 return_init ';' nodecls compstmt_or_error
643 { finish_function (lineno, 0, 0);
644 if ($<ttype>$) process_next_inline ($<ttype>$); }
645 | fn.def1 return_init nodecls compstmt_or_error
646 { finish_function (lineno, 0, 0);
647 if ($<ttype>$) process_next_inline ($<ttype>$); }
648 | typed_declspecs declarator error
650 | declmods notype_declarator error
652 | notype_declarator error
657 typed_declspecs declarator exception_specification_opt
658 { if (! start_function ($$, $2, $3, 0))
660 reinit_parse_for_function ();
662 | declmods notype_declarator exception_specification_opt
663 { if (! start_function ($$, $2, $3, 0))
665 reinit_parse_for_function ();
667 | notype_declarator exception_specification_opt
668 { if (! start_function (NULL_TREE, $$, $2, 0))
670 reinit_parse_for_function ();
672 | PRE_PARSED_FUNCTION_DECL
673 { start_function (NULL_TREE, TREE_VALUE ($$), NULL_TREE, 1);
674 reinit_parse_for_function (); }
677 /* more C++ complexity. See component_decl for a comment on the
678 reduce/reduce conflict introduced by these rules. */
680 typed_declspecs '(' parmlist ')' type_quals exception_specification_opt
682 $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1), $3, $5);
683 $$ = start_method (TREE_CHAIN ($1), $$, $6);
687 if (yychar == YYEMPTY)
689 reinit_parse_for_method (yychar, $$); }
690 | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt
692 $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
694 $$ = start_method (TREE_CHAIN ($1), $$, $4);
697 | typed_declspecs declarator exception_specification_opt
698 { $$ = start_method ($$, $2, $3); goto rest_of_mdef; }
699 | declmods notype_declarator exception_specification_opt
700 { $$ = start_method ($$, $2, $3); goto rest_of_mdef; }
701 | notype_declarator exception_specification_opt
702 { $$ = start_method (NULL_TREE, $$, $2); goto rest_of_mdef; }
705 return_id: RETURN IDENTIFIER
707 if (! current_function_parms_stored)
713 return_init: return_id maybe_init
714 { store_return_init ($<ttype>$, $2); }
715 | return_id '(' nonnull_exprlist ')'
716 { store_return_init ($<ttype>$, $3); }
717 | return_id LEFT_RIGHT
718 { store_return_init ($<ttype>$, NULL_TREE); }
722 ':' .set_base_init member_init_list
725 error ("no base initializers given following ':'");
727 /* Always keep the BLOCK node associated with the outermost
728 pair of curley braces of a function. These are needed
729 for correct operation of dwarfout.c. */
737 if (! current_function_parms_stored)
740 /* Flag that we are processing base and member initializers. */
741 current_vtable_decl = error_mark_node;
743 if (DECL_CONSTRUCTOR_P (current_function_decl))
745 /* Make a contour for the initializer list. */
748 expand_start_bindings (0);
750 else if (current_class_type == NULL_TREE)
751 error ("base initializers not allowed for non-member functions");
752 else if (! DECL_CONSTRUCTOR_P (current_function_decl))
753 error ("only constructors take base initializers");
762 | member_init_list ',' member_init
763 | member_init_list error
766 member_init: '(' nonnull_exprlist ')'
768 if (current_class_name && !flag_traditional)
769 pedwarn ("anachronistic old style base class initializer");
770 expand_member_init (C_C_D, NULL_TREE, $2);
774 if (current_class_name && !flag_traditional)
775 pedwarn ("anachronistic old style base class initializer");
776 expand_member_init (C_C_D, NULL_TREE, void_type_node);
778 | notype_identifier '(' nonnull_exprlist ')'
779 { expand_member_init (C_C_D, $<ttype>$, $3); }
780 | notype_identifier LEFT_RIGHT
781 { expand_member_init (C_C_D, $<ttype>$, void_type_node); }
782 | complete_type_name '(' nonnull_exprlist ')'
783 { expand_member_init (C_C_D, $<ttype>$, $3); }
784 | complete_type_name LEFT_RIGHT
785 { expand_member_init (C_C_D, $<ttype>$, void_type_node); }
787 | notype_qualified_id '(' nonnull_exprlist ')'
789 do_member_init (OP0 ($1), OP1 ($1), $3);
791 | notype_qualified_id LEFT_RIGHT
793 do_member_init (OP0 ($1), OP1 ($1), void_type_node);
816 explicit_instantiation:
817 TEMPLATE specialization template_instantiation
818 { do_type_instantiation ($3 ? $3 : $2, NULL_TREE); }
819 | TEMPLATE typed_declspecs declarator
820 { do_function_instantiation ($2, $3, NULL_TREE); }
821 | SCSPEC TEMPLATE specialization template_instantiation
822 { do_type_instantiation ($4 ? $4 : $3, $1); }
823 | SCSPEC TEMPLATE typed_declspecs declarator
824 { do_function_instantiation ($3, $4, $1); }
828 template_type_name tmpl.2 template_instantiation
833 PTYPENAME '<' template_arg_list '>'
834 { $$ = lookup_template_class ($$, $3, NULL_TREE); }
836 { $$ = lookup_template_class ($$, NULL_TREE, NULL_TREE); }
837 | TYPENAME '<' template_arg_list '>'
838 { $$ = lookup_template_class ($$, $3, NULL_TREE); }
842 /* empty */ %prec EMPTY
843 { $$ = instantiate_class_template ($<ttype>0, 1); }
848 { $$ = build_tree_list (NULL_TREE, $$); }
849 | template_arg_list ',' template_arg
850 { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); }
855 { $$ = groktypename ($$); }
856 | expr_no_commas %prec UNARY
859 template_instantiate_once:
860 PRE_PARSED_CLASS_DECL maybe_base_class_list
864 tmpl = TREE_PURPOSE (IDENTIFIER_TEMPLATE ($1));
865 t = xref_tag (DECL_TEMPLATE_INFO (tmpl)->aggr, $1, $2, 0);
866 set_current_level_tags_transparency (1);
867 my_friendly_assert (TREE_CODE (t) == RECORD_TYPE
868 || TREE_CODE (t) == UNION_TYPE, 257);
871 /* Now, put a copy of the decl in global scope, to avoid
872 recursive expansion. */
873 decl = IDENTIFIER_LOCAL_VALUE ($1);
875 decl = IDENTIFIER_CLASS_VALUE ($1);
876 /* Now, put a copy of the decl in global scope, to avoid
877 recursive expansion. */
880 /* Need to copy it to clear the chain pointer,
881 and need to get it into permanent storage. */
882 my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 258);
883 push_obstacks (&permanent_obstack, &permanent_obstack);
884 decl = copy_node (decl);
885 if (DECL_LANG_SPECIFIC (decl))
886 copy_lang_decl (decl);
888 pushdecl_top_level (decl);
890 /* Kludge; see instantiate_class_template. */
891 TYPE_BEING_DEFINED (t) = 0;
893 left_curly opt.component_decl_list '}'
895 tree t = finish_struct ($<ttype>3, $5, 0);
898 end_template_instantiation ($1);
900 repo_template_used (t);
902 /* Now go after the methods & class data. */
903 instantiate_member_templates ($1);
907 CLASSTYPE_GOT_SEMICOLON (t) = 1;
911 template_instantiation:
914 | template_instantiate_once
918 template_instantiate_some:
920 { $$ = NULL_TREE; /* never used from here... */}
921 | template_instantiate_once template_instantiate_some
926 { $$ = NEGATE_EXPR; }
928 { $$ = CONVERT_EXPR; }
930 { $$ = PREINCREMENT_EXPR; }
932 { $$ = PREDECREMENT_EXPR; }
934 { $$ = TRUTH_NOT_EXPR; }
937 expr: nontrivial_exprlist
938 { $$ = build_x_compound_expr ($$); }
944 { error ("ANSI C++ forbids an empty condition for `%s'",
946 $$ = integer_zero_node; }
948 { $$ = condition_conversion ($2); }
953 { error ("ANSI C++ forbids an empty condition for `%s'",
955 $$ = integer_zero_node; }
957 { $$ = condition_conversion ($2); }
964 { $$ = condition_conversion ($$); }
970 type_specifier_seq declarator exception_specification_opt maybeasm maybe_attribute '='
973 for (d = getdecls (); d; d = TREE_CHAIN (d))
974 if (TREE_CODE (d) == TYPE_DECL) {
975 tree s = TREE_TYPE (d);
976 if (TREE_CODE (s) == RECORD_TYPE)
977 cp_error ("definition of class `%T' in condition", s);
978 else if (TREE_CODE (s) == ENUMERAL_TYPE)
979 cp_error ("definition of enum `%T' in condition", s);
982 current_declspecs = $1;
983 $<itype>6 = suspend_momentary ();
984 $<ttype>$ = start_decl ($<ttype>2, current_declspecs, 1, $3);
985 cplus_decl_attributes ($<ttype>$, $5, prefix_attributes);
989 finish_decl ($<ttype>7, $8, $5, 0, LOOKUP_ONLYCONVERTING);
990 resume_momentary ($<itype>6);
992 if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE)
993 cp_error ("definition of array `%#D' in condition", $$);
1001 | '{' maybe_label_decls stmts '}'
1003 | '{' maybe_label_decls error '}'
1009 nontrivial_exprlist:
1010 expr_no_commas ',' expr_no_commas
1011 { $$ = tree_cons (NULL_TREE, $$,
1012 build_tree_list (NULL_TREE, $3)); }
1013 | expr_no_commas ',' error
1014 { $$ = tree_cons (NULL_TREE, $$,
1015 build_tree_list (NULL_TREE, error_mark_node)); }
1016 | nontrivial_exprlist ',' expr_no_commas
1017 { chainon ($$, build_tree_list (NULL_TREE, $3)); }
1018 | nontrivial_exprlist ',' error
1019 { chainon ($$, build_tree_list (NULL_TREE, error_mark_node)); }
1024 { $$ = build_tree_list (NULL_TREE, $$); }
1025 | nontrivial_exprlist
1032 if (TREE_CODE ($$) == TYPE_EXPR)
1033 $$ = build_component_type_expr (C_C_D, $$, NULL_TREE, 1);
1036 /* __extension__ turns off -pedantic for following primary. */
1038 { $<itype>1 = pedantic;
1040 cast_expr %prec UNARY
1042 pedantic = $<itype>1; }
1043 | '*' cast_expr %prec UNARY
1044 { $$ = build_x_indirect_ref ($2, "unary *"); }
1045 | '&' cast_expr %prec UNARY
1046 { $$ = build_x_unary_op (ADDR_EXPR, $2); }
1048 { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
1049 | unop cast_expr %prec UNARY
1050 { $$ = build_x_unary_op ($1, $2);
1051 if ($1 == NEGATE_EXPR && TREE_CODE ($2) == INTEGER_CST)
1052 TREE_NEGATED_INT ($$) = 1;
1053 overflow_warning ($$);
1055 /* Refer to the address of a label as a pointer. */
1057 { tree label = lookup_label ($2);
1058 if (label == NULL_TREE)
1059 $$ = null_pointer_node;
1062 TREE_USED (label) = 1;
1063 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
1064 TREE_CONSTANT ($$) = 1;
1067 | SIZEOF unary_expr %prec UNARY
1068 { if (TREE_CODE ($2) == COMPONENT_REF
1069 && DECL_BIT_FIELD (TREE_OPERAND ($2, 1)))
1070 error ("sizeof applied to a bit-field");
1071 /* ANSI says arrays and functions are converted inside comma.
1072 But we can't really convert them in build_compound_expr
1073 because that would break commas in lvalues.
1074 So do the conversion here if operand was a comma. */
1075 if (TREE_CODE ($2) == COMPOUND_EXPR
1076 && (TREE_CODE (TREE_TYPE ($2)) == ARRAY_TYPE
1077 || TREE_CODE (TREE_TYPE ($2)) == FUNCTION_TYPE))
1078 $2 = default_conversion ($2);
1079 else if (TREE_CODE ($2) == TREE_LIST)
1081 tree t = TREE_VALUE ($2);
1084 && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1085 || is_overloaded_fn (t)))
1086 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1088 $$ = c_sizeof (TREE_TYPE ($2)); }
1089 | SIZEOF '(' type_id ')' %prec HYPERUNARY
1090 { $$ = c_sizeof (groktypename ($3)); }
1091 | ALIGNOF unary_expr %prec UNARY
1092 { $$ = grok_alignof ($2); }
1093 | ALIGNOF '(' type_id ')' %prec HYPERUNARY
1094 { $$ = c_alignof (groktypename ($3)); }
1096 /* The %prec EMPTY's here are required by the = init initializer
1097 syntax extension; see below. */
1098 | new new_type_id %prec EMPTY
1099 { $$ = build_new (NULL_TREE, $2, NULL_TREE, $1); }
1100 | new new_type_id new_initializer
1101 { $$ = build_new (NULL_TREE, $2, $3, $1); }
1102 | new new_placement new_type_id %prec EMPTY
1103 { $$ = build_new ($2, $3, NULL_TREE, $1); }
1104 | new new_placement new_type_id new_initializer
1105 { $$ = build_new ($2, $3, $4, $1); }
1106 | new '(' type_id ')' %prec EMPTY
1107 { $$ = build_new (NULL_TREE, groktypename($3),
1109 | new '(' type_id ')' new_initializer
1110 { $$ = build_new (NULL_TREE, groktypename($3), $5, $1); }
1111 | new new_placement '(' type_id ')' %prec EMPTY
1112 { $$ = build_new ($2, groktypename($4), NULL_TREE, $1); }
1113 | new new_placement '(' type_id ')' new_initializer
1114 { $$ = build_new ($2, groktypename($4), $6, $1); }
1116 | delete cast_expr %prec UNARY
1117 { $$ = delete_sanity ($2, NULL_TREE, 0, $1); }
1118 | delete '[' ']' cast_expr %prec UNARY
1119 { $$ = delete_sanity ($4, NULL_TREE, 1, $1);
1120 if (yychar == YYEMPTY)
1122 | delete '[' expr ']' cast_expr %prec UNARY
1123 { $$ = delete_sanity ($5, $3, 2, $1);
1124 if (yychar == YYEMPTY)
1129 '(' nonnull_exprlist ')'
1131 | '{' nonnull_exprlist '}'
1134 pedwarn ("old style placement syntax, use () instead");
1139 '(' nonnull_exprlist ')'
1145 cp_error ("`%T' is not a valid expression", $2);
1146 $$ = error_mark_node;
1148 /* GNU extension so people can use initializer lists. Note that
1149 this alters the meaning of `new int = 1', which was previously
1150 syntactically valid but semantically invalid. */
1154 pedwarn ("ANSI C++ forbids initialization of new expression with `='");
1159 /* This is necessary to postpone reduction of `int ((int)(int)(int))'. */
1161 '(' type_id ')' %prec EMPTY
1162 { $2 = tree_cons (NULL_TREE, $2, void_list_node);
1163 TREE_PARMLIST ($2) = 1;
1164 $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2,
1166 | regcast_or_absdcl '(' type_id ')' %prec EMPTY
1167 { $3 = tree_cons (NULL_TREE, $3, void_list_node);
1168 TREE_PARMLIST ($3) = 1;
1169 $$ = build_parse_node (CALL_EXPR, $$, $3, NULL_TREE); }
1174 | regcast_or_absdcl sub_cast_expr %prec UNARY
1175 { $$ = reparse_absdcl_as_casts ($$, $2); }
1176 | regcast_or_absdcl '{' initlist maybecomma '}' %prec UNARY
1178 tree init = build_nt (CONSTRUCTOR, NULL_TREE,
1181 pedwarn ("ANSI C++ forbids constructor-expressions");
1182 /* Indicate that this was a GNU C constructor expression. */
1183 TREE_HAS_CONSTRUCTOR (init) = 1;
1185 $$ = reparse_absdcl_as_casts ($$, init);
1191 | HEADOF '(' expr ')'
1192 { $$ = build_headof ($3); }
1193 | CLASSOF '(' expr ')'
1194 { $$ = build_classof ($3); }
1195 | CLASSOF '(' TYPENAME ')'
1196 { if (is_aggr_typedef ($3, 1))
1198 tree type = IDENTIFIER_TYPE_VALUE ($3);
1199 if (! IS_SIGNATURE(type))
1200 $$ = CLASSTYPE_RTTI (type);
1203 sorry ("signature name as argument of `classof'");
1204 $$ = error_mark_node;
1208 $$ = error_mark_node;
1214 /* Handle general members. */
1215 | expr_no_commas POINTSAT_STAR expr_no_commas
1216 { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
1217 | expr_no_commas DOT_STAR expr_no_commas
1218 { $$ = build_m_component_ref ($$, $3); }
1219 | expr_no_commas '+' expr_no_commas
1220 { $$ = build_x_binary_op ($2, $$, $3); }
1221 | expr_no_commas '-' expr_no_commas
1222 { $$ = build_x_binary_op ($2, $$, $3); }
1223 | expr_no_commas '*' expr_no_commas
1224 { $$ = build_x_binary_op ($2, $$, $3); }
1225 | expr_no_commas '/' expr_no_commas
1226 { $$ = build_x_binary_op ($2, $$, $3); }
1227 | expr_no_commas '%' expr_no_commas
1228 { $$ = build_x_binary_op ($2, $$, $3); }
1229 | expr_no_commas LSHIFT expr_no_commas
1230 { $$ = build_x_binary_op ($2, $$, $3); }
1231 | expr_no_commas RSHIFT expr_no_commas
1232 { $$ = build_x_binary_op ($2, $$, $3); }
1233 | expr_no_commas ARITHCOMPARE expr_no_commas
1234 { $$ = build_x_binary_op ($2, $$, $3); }
1235 | expr_no_commas '<' expr_no_commas
1236 { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
1237 | expr_no_commas '>' expr_no_commas
1238 { $$ = build_x_binary_op (GT_EXPR, $$, $3); }
1239 | expr_no_commas EQCOMPARE expr_no_commas
1240 { $$ = build_x_binary_op ($2, $$, $3); }
1241 | expr_no_commas MIN_MAX expr_no_commas
1242 { $$ = build_x_binary_op ($2, $$, $3); }
1243 | expr_no_commas '&' expr_no_commas
1244 { $$ = build_x_binary_op ($2, $$, $3); }
1245 | expr_no_commas '|' expr_no_commas
1246 { $$ = build_x_binary_op ($2, $$, $3); }
1247 | expr_no_commas '^' expr_no_commas
1248 { $$ = build_x_binary_op ($2, $$, $3); }
1249 | expr_no_commas ANDAND expr_no_commas
1250 { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
1251 | expr_no_commas OROR expr_no_commas
1252 { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
1253 | expr_no_commas '?' xexpr ':' expr_no_commas
1254 { $$ = build_x_conditional_expr ($$, $3, $5); }
1255 | expr_no_commas '=' expr_no_commas
1256 { $$ = build_modify_expr ($$, NOP_EXPR, $3);
1257 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
1258 | expr_no_commas ASSIGN expr_no_commas
1259 { register tree rval;
1260 if ((rval = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, $$, $3,
1264 $$ = build_modify_expr ($$, $2, $3); }
1266 { $$ = build_throw (NULL_TREE); }
1267 | THROW expr_no_commas
1268 { $$ = build_throw ($2); }
1269 /* These extensions are not defined. The second arg to build_m_component_ref
1270 is old, build_m_component_ref now does an implicit
1271 build_indirect_ref (x, NULL_PTR) on the second argument.
1272 | object '&' expr_no_commas %prec UNARY
1273 { $$ = build_m_component_ref ($$, build_x_unary_op (ADDR_EXPR, $3)); }
1274 | object unop expr_no_commas %prec UNARY
1275 { $$ = build_m_component_ref ($$, build_x_unary_op ($2, $3)); }
1276 | object '(' type_id ')' expr_no_commas %prec UNARY
1277 { tree type = groktypename ($3);
1278 $$ = build_m_component_ref ($$, build_c_cast (type, $5, 0)); }
1279 | object primary_no_id %prec UNARY
1280 { $$ = build_m_component_ref ($$, $2); }
1284 notype_unqualified_id:
1285 '~' see_typename identifier
1286 { $$ = build_parse_node (BIT_NOT_EXPR, $3); }
1290 | NSNAME %prec EMPTY
1294 notype_unqualified_id
1299 notype_unqualified_id
1300 | '*' expr_or_declarator %prec UNARY
1301 { $$ = build_parse_node (INDIRECT_REF, $2); }
1302 | '&' expr_or_declarator %prec UNARY
1303 { $$ = build_parse_node (ADDR_EXPR, $2); }
1304 | '(' expr_or_declarator ')'
1308 direct_notype_declarator:
1309 complex_direct_notype_declarator
1310 | notype_unqualified_id
1311 | '(' expr_or_declarator ')'
1312 { $$ = finish_decl_parsing ($2); }
1316 notype_unqualified_id
1318 if (TREE_CODE ($$) == BIT_NOT_EXPR)
1319 $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($$, 0));
1320 else if (IDENTIFIER_OPNAME_P ($$))
1323 $$ = lookup_name (op, 0);
1324 if ($$ == NULL_TREE)
1326 if (op != ansi_opname[ERROR_MARK])
1327 error ("operator %s not defined",
1328 operator_name_string (op));
1329 $$ = error_mark_node;
1333 $$ = do_identifier ($$);
1338 { $$ = combine_strings ($$); }
1342 class = TREE_CODE_CLASS (TREE_CODE ($$));
1343 if (class == 'e' || class == '1'
1344 || class == '2' || class == '<')
1345 /* This inhibits warnings in truthvalue_conversion. */
1346 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
1347 | '(' expr_or_declarator ')'
1349 $$ = reparse_decl_as_expr (NULL_TREE, $2);
1350 class = TREE_CODE_CLASS (TREE_CODE ($$));
1351 if (class == 'e' || class == '1'
1352 || class == '2' || class == '<')
1353 /* This inhibits warnings in truthvalue_conversion. */
1354 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
1356 { $$ = error_mark_node; }
1358 { if (current_function_decl == 0)
1360 error ("braced-group within expression allowed only inside a function");
1364 $<ttype>$ = expand_start_stmt_expr (); }
1368 pedwarn ("ANSI C++ forbids braced-groups within expressions");
1369 rtl_exp = expand_end_stmt_expr ($<ttype>2);
1370 /* The statements have side effects, so the group does. */
1371 TREE_SIDE_EFFECTS (rtl_exp) = 1;
1373 if (TREE_CODE ($3) == BLOCK)
1375 /* Make a BIND_EXPR for the BLOCK already made. */
1376 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
1377 NULL_TREE, rtl_exp, $3);
1378 /* Remove the block from the tree at this point.
1379 It gets put back at the proper place
1380 when the BIND_EXPR is expanded. */
1386 | primary '(' nonnull_exprlist ')'
1387 { /* [eichin:19911016.1902EST] */
1388 $<ttype>$ = build_x_function_call ($1, $3, current_class_decl);
1389 /* here we instantiate_class_template as needed... */
1390 do_pending_templates ();
1391 } template_instantiate_some {
1392 if (TREE_CODE ($<ttype>5) == CALL_EXPR
1393 && TREE_TYPE ($<ttype>5) != void_type_node)
1394 $$ = require_complete_type ($<ttype>5);
1398 | primary LEFT_RIGHT
1400 $$ = build_x_function_call ($$, NULL_TREE, current_class_decl);
1401 if (TREE_CODE ($$) == CALL_EXPR
1402 && TREE_TYPE ($$) != void_type_node)
1403 $$ = require_complete_type ($$);
1405 | primary '[' expr ']'
1406 { $$ = grok_array_decl ($$, $3); }
1408 { /* If we get an OFFSET_REF, turn it into what it really
1409 means (e.g., a COMPONENT_REF). This way if we've got,
1410 say, a reference to a static member that's being operated
1411 on, we don't end up trying to find a member operator for
1412 the class it's in. */
1413 if (TREE_CODE ($$) == OFFSET_REF)
1414 $$ = resolve_offset_ref ($$);
1415 $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
1416 | primary MINUSMINUS
1417 { if (TREE_CODE ($$) == OFFSET_REF)
1418 $$ = resolve_offset_ref ($$);
1419 $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
1420 /* C++ extensions */
1422 { if (current_class_decl)
1424 #ifdef WARNING_ABOUT_CCD
1425 TREE_USED (current_class_decl) = 1;
1427 $$ = current_class_decl;
1429 else if (current_function_decl
1430 && DECL_STATIC_FUNCTION_P (current_function_decl))
1432 error ("`this' is unavailable for static member functions");
1433 $$ = error_mark_node;
1437 if (current_function_decl)
1438 error ("invalid use of `this' in non-member function");
1440 error ("invalid use of `this' at top level");
1441 $$ = error_mark_node;
1444 | TYPE_QUAL '(' nonnull_exprlist ')'
1449 /* This is a C cast in C++'s `functional' notation. */
1450 if ($3 == error_mark_node)
1452 $$ = error_mark_node;
1456 if ($3 == NULL_TREE)
1458 error ("cannot cast null list to type `%s'",
1459 IDENTIFIER_POINTER (TYPE_NAME (id)));
1460 $$ = error_mark_node;
1465 /* type is not set! (mrs) */
1466 if (type == error_mark_node)
1467 $$ = error_mark_node;
1471 if (id == ridpointers[(int) RID_CONST])
1472 type = build_type_variant (integer_type_node, 1, 0);
1473 else if (id == ridpointers[(int) RID_VOLATILE])
1474 type = build_type_variant (integer_type_node, 0, 1);
1476 /* should not be able to get here (mrs) */
1477 else if (id == ridpointers[(int) RID_FRIEND])
1479 error ("cannot cast expression to `friend' type");
1480 $$ = error_mark_node;
1484 else my_friendly_abort (79);
1485 $$ = build_c_cast (type, build_compound_expr ($3), 1);
1489 | DYNAMIC_CAST '<' type_id '>' '(' expr ')'
1490 { tree type = groktypename ($3);
1491 $$ = build_dynamic_cast (type, $6); }
1492 | STATIC_CAST '<' type_id '>' '(' expr ')'
1493 { tree type = groktypename ($3);
1494 $$ = build_static_cast (type, $6); }
1495 | REINTERPRET_CAST '<' type_id '>' '(' expr ')'
1496 { tree type = groktypename ($3);
1497 $$ = build_reinterpret_cast (type, $6); }
1498 | CONST_CAST '<' type_id '>' '(' expr ')'
1499 { tree type = groktypename ($3);
1500 $$ = build_const_cast (type, $6); }
1501 | TYPEID '(' expr ')'
1502 { $$ = build_typeid ($3); }
1503 | TYPEID '(' type_id ')'
1504 { tree type = groktypename ($3);
1505 $$ = get_typeid (TYPE_MAIN_VARIANT (type)); }
1506 | global_scope IDENTIFIER
1509 $$ = IDENTIFIER_GLOBAL_VALUE ($2);
1510 if (yychar == YYEMPTY)
1514 if (yychar == '(' || yychar == LEFT_RIGHT)
1515 $$ = implicitly_declare ($2);
1518 if (IDENTIFIER_GLOBAL_VALUE ($2) != error_mark_node)
1519 error ("undeclared variable `%s' (first use here)",
1520 IDENTIFIER_POINTER ($2));
1521 $$ = error_mark_node;
1522 /* Prevent repeated error messages. */
1523 IDENTIFIER_GLOBAL_VALUE ($2) = error_mark_node;
1528 if (TREE_CODE ($$) == ADDR_EXPR)
1529 assemble_external (TREE_OPERAND ($$, 0));
1531 assemble_external ($$);
1534 if (TREE_CODE ($$) == CONST_DECL)
1536 /* XXX CHS - should we set TREE_USED of the constant? */
1537 $$ = DECL_INITIAL ($$);
1538 /* This is to prevent an enum whose value is 0
1539 from being considered a null pointer constant. */
1540 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
1541 TREE_CONSTANT ($$) = 1;
1545 | global_scope operator_name
1547 got_scope = NULL_TREE;
1548 if (TREE_CODE ($2) == IDENTIFIER_NODE)
1552 | overqualified_id %prec HYPERUNARY
1553 { $$ = build_offset_ref (OP0 ($$), OP1 ($$)); }
1554 | overqualified_id '(' nonnull_exprlist ')'
1555 { $$ = build_member_call (OP0 ($$), OP1 ($$), $3); }
1556 | overqualified_id LEFT_RIGHT
1557 { $$ = build_member_call (OP0 ($$), OP1 ($$), NULL_TREE); }
1558 | object unqualified_id %prec UNARY
1559 { got_object = NULL_TREE;
1560 $$ = build_component_ref ($$, $2, NULL_TREE, 1); }
1561 | object overqualified_id %prec UNARY
1562 { got_object = NULL_TREE;
1563 $$ = build_object_ref ($$, OP0 ($2), OP1 ($2)); }
1564 | object unqualified_id '(' nonnull_exprlist ')'
1566 got_object = NULL_TREE;
1568 /* This is a future direction of this code, but because
1569 build_x_function_call cannot always undo what is done
1570 in build_component_ref entirely yet, we cannot do this. */
1571 $$ = build_x_function_call (build_component_ref ($$, $2, NULL_TREE, 1), $4, $$);
1572 if (TREE_CODE ($$) == CALL_EXPR
1573 && TREE_TYPE ($$) != void_type_node)
1574 $$ = require_complete_type ($$);
1576 $$ = build_method_call ($$, $2, $4, NULL_TREE,
1577 (LOOKUP_NORMAL|LOOKUP_AGGR));
1580 | object unqualified_id LEFT_RIGHT
1582 got_object = NULL_TREE;
1584 /* This is a future direction of this code, but because
1585 build_x_function_call cannot always undo what is done
1586 in build_component_ref entirely yet, we cannot do this. */
1587 $$ = build_x_function_call (build_component_ref ($$, $2, NULL_TREE, 1), NULL_TREE, $$);
1588 if (TREE_CODE ($$) == CALL_EXPR
1589 && TREE_TYPE ($$) != void_type_node)
1590 $$ = require_complete_type ($$);
1592 $$ = build_method_call ($$, $2, NULL_TREE, NULL_TREE,
1593 (LOOKUP_NORMAL|LOOKUP_AGGR));
1596 | object overqualified_id '(' nonnull_exprlist ')'
1598 got_object = NULL_TREE;
1599 if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (OP0 ($2))))
1601 warning ("signature name in scope resolution ignored");
1602 $$ = build_method_call ($$, OP1 ($2), $4, NULL_TREE,
1603 (LOOKUP_NORMAL|LOOKUP_AGGR));
1606 $$ = build_scoped_method_call ($$, OP0 ($2), OP1 ($2), $4);
1608 | object overqualified_id LEFT_RIGHT
1610 got_object = NULL_TREE;
1611 if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (OP0 ($2))))
1613 warning ("signature name in scope resolution ignored");
1614 $$ = build_method_call ($$, OP1 ($2), NULL_TREE, NULL_TREE,
1615 (LOOKUP_NORMAL|LOOKUP_AGGR));
1618 $$ = build_scoped_method_call ($$, OP0 ($2), OP1 ($2), NULL_TREE);
1620 /* p->int::~int() is valid -- 12.4 */
1621 | object '~' TYPESPEC LEFT_RIGHT
1623 got_object = NULL_TREE;
1624 if (IDENTIFIER_GLOBAL_VALUE ($3)
1625 && (TREE_CODE (TREE_TYPE ($1))
1626 != TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE ($3)))))
1627 cp_error ("`%E' is not of type `%T'", $1, $3);
1628 $$ = convert (void_type_node, $1);
1630 | object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT
1632 got_object = NULL_TREE;
1634 cp_error ("destructor specifier `%T::~%T()' must have matching names", $2, $5);
1635 if (TREE_CODE (TREE_TYPE ($1))
1636 != TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE ($2))))
1637 cp_error ("`%E' is not of type `%T'", $1, $2);
1638 $$ = convert (void_type_node, $1);
1642 got_object = NULL_TREE;
1643 $$ = error_mark_node;
1647 /* Not needed for now.
1653 { $$ = error_mark_node; }
1655 { if (current_function_decl == 0)
1657 error ("braced-group within expression allowed only inside a function");
1660 $<ttype>$ = expand_start_stmt_expr (); }
1663 pedwarn ("ANSI C++ forbids braced-groups within expressions");
1664 $$ = expand_end_stmt_expr ($<ttype>2); }
1665 | primary_no_id '(' nonnull_exprlist ')'
1666 { $$ = build_x_function_call ($$, $3, current_class_decl); }
1667 | primary_no_id LEFT_RIGHT
1668 { $$ = build_x_function_call ($$, NULL_TREE, current_class_decl); }
1669 | primary_no_id '[' expr ']'
1671 | primary_no_id PLUSPLUS
1672 { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
1673 | primary_no_id MINUSMINUS
1674 { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
1676 { goto do_scoped_id; }
1677 | SCOPE operator_name
1678 { if (TREE_CODE ($2) == IDENTIFIER_NODE)
1680 goto do_scoped_operator;
1688 { got_scope = NULL_TREE; $$ = 1; }
1693 | global_scope delete
1694 { got_scope = NULL_TREE; $$ = 1; }
1699 { $$ = boolean_true_node; }
1701 { $$ = boolean_false_node; }
1704 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
1708 { $$ = chainon ($$, $2); }
1714 if (! current_function_parms_stored)
1715 store_parm_decls ();
1717 /* Always keep the BLOCK node associated with the outermost
1718 pair of curley braces of a function. These are needed
1719 for correct operation of dwarfout.c. */
1725 { got_object = TREE_TYPE ($$); }
1728 $$ = build_x_arrow ($$);
1729 got_object = TREE_TYPE ($$);
1733 setattrs: /* empty */
1734 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
1738 /* Normal case: make this fast. */
1739 typespec declarator ';'
1740 { tree d = get_decl_list ($1);
1741 int yes = suspend_momentary ();
1742 d = start_decl ($2, d, 0, NULL_TREE);
1743 finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
1744 resume_momentary (yes);
1745 if (IS_AGGR_TYPE_CODE (TREE_CODE ($1)))
1746 note_got_semicolon ($1);
1748 | typed_declspecs declarator ';'
1750 int yes = suspend_momentary ();
1751 d = start_decl ($2, d, 0, NULL_TREE);
1752 finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
1753 resume_momentary (yes);
1754 note_list_got_semicolon ($1);
1756 | typespec initdecls ';'
1758 resume_momentary ($2);
1759 if (IS_AGGR_TYPE_CODE (TREE_CODE ($1)))
1760 note_got_semicolon ($1);
1762 | typed_declspecs initdecls ';'
1764 resume_momentary ($2);
1765 note_list_got_semicolon ($1);
1767 | declmods notype_initdecls ';'
1768 { resume_momentary ($2); }
1769 | typed_declspecs ';'
1772 note_list_got_semicolon ($1);
1775 { warning ("empty declaration"); }
1778 /* Any kind of declarator (thus, all declarators allowed
1779 after an explicit typespec). */
1782 after_type_declarator %prec EMPTY
1783 | notype_declarator %prec EMPTY
1786 /* This is necessary to postpone reduction of `int()()()()'. */
1788 LEFT_RIGHT %prec EMPTY
1789 { $$ = build_parse_node (CALL_EXPR, NULL_TREE, empty_parms (),
1791 | fcast_or_absdcl LEFT_RIGHT %prec EMPTY
1792 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (),
1796 /* ANSI type-id (8.1) */
1798 typed_typespecs absdcl
1799 { $$ = build_decl_list ($$, $2); }
1800 | nonempty_type_quals absdcl
1801 { $$ = build_decl_list ($$, $2); }
1803 { $$ = build_decl_list (get_decl_list ($$), $2); }
1804 | typed_typespecs %prec EMPTY
1805 { $$ = build_decl_list ($$, NULL_TREE); }
1806 | nonempty_type_quals %prec EMPTY
1807 { $$ = build_decl_list ($$, NULL_TREE); }
1810 /* Declspecs which contain at least one type specifier or typedef name.
1811 (Just `const' or `volatile' is not enough.)
1812 A typedef'd name following these is taken as a name to be declared. */
1815 typed_typespecs %prec EMPTY
1821 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
1822 | typespec reserved_declspecs %prec HYPERUNARY
1823 { $$ = decl_tree_cons (NULL_TREE, $$, $2); }
1824 | typespec reserved_typespecquals reserved_declspecs
1825 { $$ = decl_tree_cons (NULL_TREE, $$, chainon ($2, $3)); }
1826 | declmods typespec reserved_declspecs
1827 { $$ = decl_tree_cons (NULL_TREE, $2, chainon ($3, $$)); }
1828 | declmods typespec reserved_typespecquals
1829 { $$ = decl_tree_cons (NULL_TREE, $2, chainon ($3, $$)); }
1830 | declmods typespec reserved_typespecquals reserved_declspecs
1831 { $$ = decl_tree_cons (NULL_TREE, $2,
1832 chainon ($3, chainon ($4, $$))); }
1837 { if (extra_warnings)
1838 warning ("`%s' is not at beginning of declaration",
1839 IDENTIFIER_POINTER ($$));
1840 $$ = build_decl_list (NULL_TREE, $$); }
1841 | reserved_declspecs typespecqual_reserved
1842 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
1843 | reserved_declspecs SCSPEC
1844 { if (extra_warnings)
1845 warning ("`%s' is not at beginning of declaration",
1846 IDENTIFIER_POINTER ($2));
1847 $$ = decl_tree_cons (NULL_TREE, $2, $$); }
1848 | reserved_declspecs attributes setattrs
1850 | attributes setattrs
1854 /* List of just storage classes and type modifiers.
1855 A declaration can start with just this, but then it cannot be used
1856 to redeclare a typedef-name. */
1859 nonempty_type_quals %prec EMPTY
1860 { TREE_STATIC ($$) = 1; }
1862 { $$ = IDENTIFIER_AS_LIST ($$); }
1863 | declmods TYPE_QUAL
1864 { $$ = decl_tree_cons (NULL_TREE, $2, $$);
1865 TREE_STATIC ($$) = 1; }
1867 { if (extra_warnings && TREE_STATIC ($$))
1868 warning ("`%s' is not at beginning of declaration",
1869 IDENTIFIER_POINTER ($2));
1870 $$ = decl_tree_cons (NULL_TREE, $2, $$);
1871 TREE_STATIC ($$) = TREE_STATIC ($1); }
1872 | declmods attributes setattrs
1874 | attributes setattrs
1879 /* Used instead of declspecs where storage classes are not allowed
1880 (that is, for typenames and structure components).
1882 C++ can takes storage classes for structure components.
1883 Don't accept a typedef-name if anything but a modifier precedes it. */
1886 typespec %prec EMPTY
1887 { $$ = get_decl_list ($$); }
1888 | nonempty_type_quals typespec
1889 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
1890 | typespec reserved_typespecquals
1891 { $$ = decl_tree_cons (NULL_TREE, $$, $2); }
1892 | nonempty_type_quals typespec reserved_typespecquals
1893 { $$ = decl_tree_cons (NULL_TREE, $2, chainon ($3, $$)); }
1896 reserved_typespecquals:
1897 typespecqual_reserved
1898 { $$ = build_decl_list (NULL_TREE, $$); }
1899 | reserved_typespecquals typespecqual_reserved
1900 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
1903 /* A typespec (but not a type qualifier).
1904 Once we have seen one of these in a declaration,
1905 if a typedef name appears then it is being redeclared. */
1908 | TYPESPEC %prec EMPTY
1909 | complete_type_name
1910 | TYPEOF '(' expr ')'
1911 { $$ = TREE_TYPE ($3);
1913 pedwarn ("ANSI C++ forbids `typeof'"); }
1914 | TYPEOF '(' type_id ')'
1915 { $$ = groktypename ($3);
1917 pedwarn ("ANSI C++ forbids `typeof'"); }
1918 | SIGOF '(' expr ')'
1919 { tree type = TREE_TYPE ($3);
1921 if (IS_AGGR_TYPE (type))
1923 sorry ("sigof type specifier");
1928 error ("`sigof' applied to non-aggregate expression");
1929 $$ = error_mark_node;
1932 | SIGOF '(' type_id ')'
1933 { tree type = groktypename ($3);
1935 if (IS_AGGR_TYPE (type))
1937 sorry ("sigof type specifier");
1942 error("`sigof' applied to non-aggregate type");
1943 $$ = error_mark_node;
1948 /* A typespec that is a reserved word, or a type qualifier. */
1950 typespecqual_reserved: TYPESPEC
1957 | initdecls ',' initdcl
1962 | notype_initdecls ',' initdcl
1967 | nomods_initdecls ',' initdcl
1973 | asm_keyword '(' string ')'
1974 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); $$ = $3; }
1978 declarator exception_specification_opt maybeasm maybe_attribute '='
1979 { current_declspecs = $<ttype>0;
1980 if (TREE_CODE (current_declspecs) != TREE_LIST)
1981 current_declspecs = get_decl_list (current_declspecs);
1982 if (have_extern_spec && !used_extern_spec)
1984 current_declspecs = decl_tree_cons
1985 (NULL_TREE, get_identifier ("extern"),
1987 used_extern_spec = 1;
1989 $<itype>5 = suspend_momentary ();
1990 $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2);
1991 cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
1993 /* Note how the declaration of the variable is in effect while its init is parsed! */
1994 { finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING);
1996 | declarator exception_specification_opt maybeasm maybe_attribute
1998 current_declspecs = $<ttype>0;
1999 if (TREE_CODE (current_declspecs) != TREE_LIST)
2000 current_declspecs = get_decl_list (current_declspecs);
2001 if (have_extern_spec && !used_extern_spec)
2003 current_declspecs = decl_tree_cons
2004 (NULL_TREE, get_identifier ("extern"),
2006 used_extern_spec = 1;
2008 $$ = suspend_momentary ();
2009 d = start_decl ($<ttype>1, current_declspecs, 0, $2);
2010 cplus_decl_attributes (d, $4, prefix_attributes);
2011 finish_decl (d, NULL_TREE, $3, 0, 0); }
2015 declarator exception_specification_opt maybeasm maybe_attribute '='
2016 { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2);
2017 cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
2019 /* Note how the declaration of the variable is in effect while its init is parsed! */
2020 { finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING); }
2021 | declarator exception_specification_opt maybeasm maybe_attribute
2022 { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 0, $2);
2023 cplus_decl_attributes ($<ttype>$, $4, prefix_attributes);
2024 finish_decl ($<ttype>$, NULL_TREE, $3, 0, 0); }
2028 notype_declarator exception_specification_opt maybeasm maybe_attribute '='
2029 { current_declspecs = $<ttype>0;
2030 $<itype>5 = suspend_momentary ();
2031 $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2);
2032 cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
2034 /* Note how the declaration of the variable is in effect while its init is parsed! */
2035 { finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING);
2037 | notype_declarator exception_specification_opt maybeasm maybe_attribute
2039 current_declspecs = $<ttype>0;
2040 $$ = suspend_momentary ();
2041 d = start_decl ($<ttype>1, current_declspecs, 0, $2);
2042 cplus_decl_attributes (d, $4, prefix_attributes);
2043 finish_decl (d, NULL_TREE, $3, 0, 0); }
2047 notype_declarator exception_specification_opt maybeasm maybe_attribute '='
2048 { current_declspecs = NULL_TREE;
2049 $<itype>5 = suspend_momentary ();
2050 $<ttype>$ = start_decl ($1, current_declspecs, 1, $2);
2051 cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
2053 /* Note how the declaration of the variable is in effect while its init is parsed! */
2054 { finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING);
2056 | notype_declarator exception_specification_opt maybeasm maybe_attribute
2058 current_declspecs = NULL_TREE;
2059 $$ = suspend_momentary ();
2060 d = start_decl ($1, current_declspecs, 0, $2);
2061 cplus_decl_attributes (d, $4, prefix_attributes);
2062 finish_decl (d, NULL_TREE, $3, 0, 0); }
2065 /* the * rules are dummies to accept the Apollo extended syntax
2066 so that the header files compile. */
2077 | attributes attribute
2078 { $$ = chainon ($1, $2); }
2082 ATTRIBUTE '(' '(' attribute_list ')' ')'
2088 { $$ = build_tree_list (NULL_TREE, $1); }
2089 | attribute_list ',' attrib
2090 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2098 | any_word '(' IDENTIFIER ')'
2099 { $$ = tree_cons ($1, NULL_TREE, build_tree_list (NULL_TREE, $3)); }
2100 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
2101 { $$ = tree_cons ($1, NULL_TREE, tree_cons (NULL_TREE, $3, $5)); }
2102 | any_word '(' nonnull_exprlist ')'
2103 { $$ = tree_cons ($1, NULL_TREE, $3); }
2106 /* This still leaves out most reserved keywords,
2107 shouldn't we include them? */
2116 /* A nonempty list of identifiers, including typenames. */
2117 identifiers_or_typenames:
2119 { $$ = build_tree_list (NULL_TREE, $1); }
2120 | identifiers_or_typenames ',' identifier
2121 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2125 %prec EMPTY /* empty */
2131 expr_no_commas %prec '='
2133 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
2134 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2136 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2137 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2138 | '{' initlist ',' '}'
2139 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2140 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2145 /* This chain is built in reverse order,
2146 and put in forward order where initlist is used. */
2149 { $$ = build_tree_list (NULL_TREE, $$); }
2151 { $$ = tree_cons (NULL_TREE, $3, $$); }
2152 /* These are for labeled elements. */
2153 | '[' expr_no_commas ']' init
2154 { $$ = build_tree_list ($2, $4); }
2155 | initlist ',' CASE expr_no_commas ':' init
2156 { $$ = tree_cons ($4, $6, $$); }
2157 | identifier ':' init
2158 { $$ = build_tree_list ($$, $3); }
2159 | initlist ',' identifier ':' init
2160 { $$ = tree_cons ($3, $5, $$); }
2165 { $<itype>3 = suspend_momentary ();
2166 $$ = start_enum ($2); }
2167 enumlist maybecomma_warn '}'
2168 { $$ = finish_enum ($<ttype>4, $5);
2169 resume_momentary ((int) $<itype>3);
2170 check_for_missing_semicolon ($<ttype>4); }
2171 | ENUM identifier '{' '}'
2172 { $$ = finish_enum (start_enum ($2), NULL_TREE);
2173 check_for_missing_semicolon ($$); }
2175 { $<itype>2 = suspend_momentary ();
2176 $$ = start_enum (make_anon_name ()); }
2177 enumlist maybecomma_warn '}'
2178 { $$ = finish_enum ($<ttype>3, $4);
2179 resume_momentary ((int) $<itype>1);
2180 check_for_missing_semicolon ($<ttype>3); }
2182 { $$ = finish_enum (start_enum (make_anon_name()), NULL_TREE);
2183 check_for_missing_semicolon ($$); }
2185 { $$ = xref_tag (enum_type_node, $2, NULL_TREE, 1); }
2186 | ENUM complex_type_name
2187 { $$ = xref_tag (enum_type_node, $2, NULL_TREE, 1); }
2189 /* C++ extensions, merged with C to avoid shift/reduce conflicts */
2190 | class_head left_curly opt.component_decl_list '}'
2196 /* Need to rework class nesting in the
2197 presence of nested classes, etc. */
2198 shadow_tag (CLASSTYPE_AS_LIST ($$)); */
2200 if (yychar == YYEMPTY)
2202 semi = yychar == ';';
2203 /* finish_struct nukes this anyway; if
2204 finish_exception does too, then it can go. */
2206 note_got_semicolon ($$);
2208 if (TREE_CODE ($$) == ENUMERAL_TYPE)
2209 /* $$ = $1 from default rule. */;
2212 $$ = finish_struct ($$, $3, semi);
2213 if (semi) note_got_semicolon ($$);
2218 id = TYPE_IDENTIFIER ($$);
2219 if (id && IDENTIFIER_TEMPLATE (id))
2223 /* I don't know if the copying of this TYPE_DECL is
2224 * really needed. However, it's such a small per-
2225 * formance penalty that the extra safety is a bargain.
2228 push_obstacks (&permanent_obstack, &permanent_obstack);
2229 decl = copy_node (lookup_name (id, 0));
2230 if (DECL_LANG_SPECIFIC (decl))
2231 copy_lang_decl (decl);
2233 undo_template_name_overload (id, 0);
2234 pushdecl_top_level (decl);
2237 check_for_missing_semicolon ($$); }
2238 | class_head %prec EMPTY
2240 /* struct B: public A; is not accepted by the WP grammar. */
2241 if (TYPE_BINFO_BASETYPES ($$) && !TYPE_SIZE ($$)
2242 && ! TYPE_BEING_DEFINED ($$))
2243 cp_error ("base clause without member specification for `%#T'",
2256 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
2261 { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2263 { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2265 { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2267 { error ("no body nor ';' separates two class, struct or union declarations"); }
2271 aggr template_type_name ';'
2273 yyungetc (';', 1); current_aggr = $$; $$ = $2;
2274 if ($<ttype>0 == ridpointers[(int) RID_TEMPLATE])
2275 instantiate_class_template ($$, 2);
2279 named_class_head_sans_basetype:
2281 { current_aggr = $$; $$ = $2; }
2282 | aggr complex_type_name
2283 { current_aggr = $$; $$ = $2; }
2284 | aggr template_type %prec EMPTY
2285 { current_aggr = $$; $$ = $2; }
2289 named_class_head_sans_basetype_defn:
2290 aggr identifier_defn %prec EMPTY
2291 { current_aggr = $$; $$ = $2; }
2292 | aggr template_type_name '{'
2293 { yyungetc ('{', 1);
2297 overload_template_name ($$, 0); }
2298 | aggr template_type_name ':'
2299 { yyungetc (':', 1); goto aggr2; }
2302 do_xref_defn: /* empty */ %prec EMPTY
2303 { $<ttype>$ = xref_tag (current_aggr, $<ttype>0, NULL_TREE, 0); }
2307 named_class_head_sans_basetype %prec EMPTY
2308 { $$ = xref_tag (current_aggr, $1, NULL_TREE, 1); }
2309 | named_class_head_sans_basetype_defn do_xref_defn
2310 maybe_base_class_list %prec EMPTY
2314 xref_basetypes (current_aggr, $1, $<ttype>2, $3);
2318 unnamed_class_head: aggr '{'
2319 { $$ = xref_tag ($$, make_anon_name (), NULL_TREE, 0);
2320 yyungetc ('{', 1); }
2323 class_head: unnamed_class_head | named_class_head ;
2325 maybe_base_class_list:
2326 %prec EMPTY /* empty */
2329 { yyungetc(':', 1); $$ = NULL_TREE; }
2330 | ':' base_class_list %prec EMPTY
2336 | base_class_list ',' base_class
2337 { $$ = chainon ($$, $3); }
2345 type = IDENTIFIER_TYPE_VALUE ($$);
2346 if (! is_aggr_typedef ($$, 1))
2348 else if (current_aggr == signature_type_node
2349 && (! type) && (! IS_SIGNATURE (type)))
2351 error ("class name not allowed as base signature");
2354 else if (current_aggr == signature_type_node)
2356 sorry ("signature inheritance, base type `%s' ignored",
2357 IDENTIFIER_POINTER ($$));
2358 $$ = build_tree_list ((tree)access_public, $$);
2360 else if (type && IS_SIGNATURE (type))
2362 error ("signature name not allowed as base class");
2366 $$ = build_tree_list ((tree)access_default, $$);
2368 | base_class_access_list base_class.1
2372 type = IDENTIFIER_TYPE_VALUE ($2);
2373 if (current_aggr == signature_type_node)
2374 error ("access and source specifiers not allowed in signature");
2375 if (! is_aggr_typedef ($2, 1))
2377 else if (current_aggr == signature_type_node
2378 && (! type) && (! IS_SIGNATURE (type)))
2380 error ("class name not allowed as base signature");
2383 else if (current_aggr == signature_type_node)
2385 sorry ("signature inheritance, base type `%s' ignored",
2386 IDENTIFIER_POINTER ($$));
2387 $$ = build_tree_list ((tree)access_public, $2);
2389 else if (type && IS_SIGNATURE (type))
2391 error ("signature name not allowed as base class");
2395 $$ = build_tree_list ((tree) $$, $2);
2401 | SIGOF '(' expr ')'
2403 if (current_aggr == signature_type_node)
2405 if (IS_AGGR_TYPE (TREE_TYPE ($3)))
2407 sorry ("`sigof' as base signature specifier");
2408 /* need to return some dummy signature identifier */
2413 error ("`sigof' applied to non-aggregate expression");
2414 $$ = error_mark_node;
2419 error ("`sigof' in struct or class declaration");
2420 $$ = error_mark_node;
2423 | SIGOF '(' type_id ')'
2425 if (current_aggr == signature_type_node)
2427 if (IS_AGGR_TYPE (groktypename ($3)))
2429 sorry ("`sigof' as base signature specifier");
2430 /* need to return some dummy signature identifier */
2435 error ("`sigof' applied to non-aggregate expression");
2436 $$ = error_mark_node;
2441 error ("`sigof' in struct or class declaration");
2442 $$ = error_mark_node;
2447 base_class_access_list:
2450 { if ($<ttype>$ != ridpointers[(int)RID_VIRTUAL])
2451 sorry ("non-virtual access");
2452 $$ = access_default_virtual; }
2453 | base_class_access_list VISSPEC
2455 if ($2 == access_protected)
2457 warning ("`protected' access not implemented");
2461 else if ($2 == access_public)
2463 if ($1 == access_private)
2466 error ("base class cannot be public and private");
2468 else if ($1 == access_default_virtual)
2469 $$ = access_public_virtual;
2471 else /* $2 == access_private */
2473 if ($1 == access_public)
2475 else if ($1 == access_default_virtual)
2476 $$ = access_private_virtual;
2479 | base_class_access_list SCSPEC
2480 { if ($2 != ridpointers[(int)RID_VIRTUAL])
2481 sorry ("non-virtual access");
2482 if ($$ == access_public)
2483 $$ = access_public_virtual;
2484 else if ($$ == access_private)
2485 $$ = access_private_virtual; }
2489 { tree t = $<ttype>0;
2490 push_obstacks_nochange ();
2491 end_temporary_allocation ();
2493 if (! IS_AGGR_TYPE (t))
2495 t = $<ttype>0 = make_lang_type (RECORD_TYPE);
2496 TYPE_NAME (t) = get_identifier ("erroneous type");
2499 duplicate_tag_error (t);
2500 if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
2502 t = make_lang_type (TREE_CODE (t));
2503 pushtag (TYPE_IDENTIFIER ($<ttype>0), t, 0);
2507 TYPE_BEING_DEFINED (t) = 1;
2508 /* Reset the interface data, at the earliest possible
2509 moment, as it might have been set via a class foo;
2511 /* Don't change signatures. */
2512 if (! IS_SIGNATURE (t))
2514 extern tree pending_vtables;
2516 tree name = TYPE_IDENTIFIER (t);
2518 if (! ANON_AGGRNAME_P (name))
2520 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2521 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2522 (t, interface_unknown);
2525 /* Record how to set the access of this class's
2526 virtual functions. If write_virtuals == 2 or 3, then
2527 inline virtuals are ``extern inline''. */
2528 switch (write_virtuals)
2535 needs_writing = !! value_member (name, pending_vtables);
2538 needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t)
2539 && CLASSTYPE_INTERFACE_KNOWN (t);
2544 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
2547 t = TYPE_IDENTIFIER ($<ttype>0);
2548 if (t && IDENTIFIER_TEMPLATE (t))
2549 overload_template_name (t, 1);
2554 opt.component_decl_list:
2557 | component_decl_list
2559 if (current_aggr == signature_type_node)
2560 $$ = build_tree_list ((tree) access_public, $$);
2562 $$ = build_tree_list ((tree) access_default, $$);
2564 | opt.component_decl_list VISSPEC ':' component_decl_list
2566 tree visspec = (tree) $2;
2568 if (current_aggr == signature_type_node)
2570 error ("access specifier not allowed in signature");
2571 visspec = (tree) access_public;
2573 $$ = chainon ($$, build_tree_list (visspec, $4));
2575 | opt.component_decl_list VISSPEC ':'
2577 if (current_aggr == signature_type_node)
2578 error ("access specifier not allowed in signature");
2582 /* Note: we no longer warn about the semicolon after a component_decl_list.
2583 ARM $9.2 says that the semicolon is optional, and therefore allowed. */
2584 component_decl_list:
2586 { if ($$ == void_type_node) $$ = NULL_TREE;
2588 | component_decl_list component_decl
2589 { /* In pushdecl, we created a reverse list of names
2590 in this binding level. Make sure that the chain
2591 of what we're trying to add isn't the item itself
2592 (which can happen with what pushdecl's doing). */
2593 if ($2 != NULL_TREE && $2 != void_type_node)
2595 if (TREE_CHAIN ($2) != $$)
2596 $$ = chainon ($$, $2);
2601 | component_decl_list ';'
2605 component_decl_1 ';'
2606 | component_decl_1 '}'
2607 { error ("missing ';' before right brace");
2608 yyungetc ('}', 0); }
2609 /* C++: handle constructors, destructors and inline functions */
2610 /* note that INLINE is like a TYPESPEC */
2611 | fn.def2 ':' /* base_init compstmt */
2612 { $$ = finish_method ($$); }
2613 | fn.def2 '{' /* nodecls compstmt */
2614 { $$ = finish_method ($$); }
2618 /* Do not add a "typed_declspecs declarator" rule here for
2619 speed; we need to call grok_x_components for enums, so the
2620 speedup would be insignificant. */
2621 typed_declspecs components
2623 $$ = grok_x_components ($$, $2);
2625 | declmods notype_components
2627 $$ = grok_x_components ($$, $2);
2629 | notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2630 { $$ = grokfield ($$, NULL_TREE, $2, $5, $3);
2631 cplus_decl_attributes ($$, $4, prefix_attributes); }
2632 | ':' expr_no_commas
2633 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
2637 /* These rules introduce a reduce/reduce conflict; in
2638 typedef int foo, bar;
2642 should "A::foo" be declared as a function or "A::bar" as a data
2643 member? In other words, is "bar" an after_type_declarator or a
2645 | typed_declspecs '(' parmlist ')' type_quals exception_specification_opt maybeasm maybe_attribute maybe_init
2646 { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
2648 $$ = grokfield ($$, TREE_CHAIN ($1), $6, $9, $7);
2649 cplus_decl_attributes ($$, $8, prefix_attributes); }
2650 | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt maybeasm maybe_attribute maybe_init
2651 { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
2652 empty_parms (), $3);
2653 $$ = grokfield ($$, TREE_CHAIN ($1), $4, $7, $5);
2654 cplus_decl_attributes ($$, $6, prefix_attributes); }
2658 /* The case of exactly one component is handled directly by component_decl. */
2660 /* empty: possibly anonymous */
2662 | component_declarator0
2663 | components ',' component_declarator
2665 /* In this context, void_type_node encodes
2666 friends. They have been recorded elsewhere. */
2667 if ($$ == void_type_node)
2670 $$ = chainon ($$, $3);
2675 /* empty: possibly anonymous */
2677 | notype_component_declarator0
2678 | notype_components ',' notype_component_declarator
2680 /* In this context, void_type_node encodes
2681 friends. They have been recorded elsewhere. */
2682 if ($$ == void_type_node)
2685 $$ = chainon ($$, $3);
2689 component_declarator0:
2690 after_type_component_declarator0
2691 | notype_component_declarator0
2694 component_declarator:
2695 after_type_component_declarator
2696 | notype_component_declarator
2699 after_type_component_declarator0:
2700 after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2701 { current_declspecs = $<ttype>0;
2702 $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2703 cplus_decl_attributes ($$, $4, prefix_attributes); }
2704 | TYPENAME ':' expr_no_commas maybe_attribute
2705 { current_declspecs = $<ttype>0;
2706 $$ = grokbitfield ($$, current_declspecs, $3);
2707 cplus_decl_attributes ($$, $4, prefix_attributes); }
2710 notype_component_declarator0:
2711 notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2712 { current_declspecs = $<ttype>0;
2713 $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2714 cplus_decl_attributes ($$, $4, prefix_attributes); }
2715 | IDENTIFIER ':' expr_no_commas maybe_attribute
2716 { current_declspecs = $<ttype>0;
2717 $$ = grokbitfield ($$, current_declspecs, $3);
2718 cplus_decl_attributes ($$, $4, prefix_attributes); }
2719 | ':' expr_no_commas maybe_attribute
2720 { current_declspecs = $<ttype>0;
2721 $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2722 cplus_decl_attributes ($$, $3, prefix_attributes); }
2725 after_type_component_declarator:
2726 after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2727 { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2728 cplus_decl_attributes ($$, $4, prefix_attributes); }
2729 | TYPENAME ':' expr_no_commas maybe_attribute
2730 { $$ = grokbitfield ($$, current_declspecs, $3);
2731 cplus_decl_attributes ($$, $4, prefix_attributes); }
2734 notype_component_declarator:
2735 notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2736 { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2737 cplus_decl_attributes ($$, $4, prefix_attributes); }
2738 | IDENTIFIER ':' expr_no_commas maybe_attribute
2739 { $$ = grokbitfield ($$, current_declspecs, $3);
2740 cplus_decl_attributes ($$, $4, prefix_attributes); }
2741 | ':' expr_no_commas maybe_attribute
2742 { $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2743 cplus_decl_attributes ($$, $3, prefix_attributes); }
2746 /* We chain the enumerators in reverse order.
2747 Because of the way enums are built, the order is
2748 insignificant. Take advantage of this fact. */
2752 | enumlist ',' enumerator
2753 { TREE_CHAIN ($3) = $$; $$ = $3; }
2758 { $$ = build_enumerator ($$, NULL_TREE); }
2759 | identifier '=' expr_no_commas
2760 { $$ = build_enumerator ($$, $3); }
2763 /* ANSI new-type-id (5.3.4) */
2765 type_specifier_seq new_declarator
2766 { $$ = build_decl_list ($$, $2); }
2767 | type_specifier_seq %prec EMPTY
2768 { $$ = build_decl_list ($$, NULL_TREE); }
2769 /* GNU extension to allow arrays of arbitrary types with
2770 non-constant dimension. */
2771 | '(' type_id ')' '[' expr ']'
2774 pedwarn ("ANSI C++ forbids array dimensions with parenthesized type in new");
2775 $$ = build_parse_node (ARRAY_REF, TREE_VALUE ($2), $5);
2776 $$ = build_decl_list (TREE_PURPOSE ($2), $$);
2781 /* empty */ %prec EMPTY
2783 | type_quals TYPE_QUAL
2784 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
2787 nonempty_type_quals:
2789 { $$ = IDENTIFIER_AS_LIST ($$); }
2790 | nonempty_type_quals TYPE_QUAL
2791 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
2794 /* These rules must follow the rules for function declarations
2795 and component declarations. That way, longer rules are preferred. */
2797 /* An expression which will not live on the momentary obstack. */
2799 { $<itype>$ = suspend_momentary (); } expr
2800 { resume_momentary ((int) $<itype>1); $$ = $2; }
2803 /* A declarator that is allowed only after an explicit typespec. */
2804 /* may all be followed by prec '.' */
2805 after_type_declarator:
2806 '*' nonempty_type_quals after_type_declarator %prec UNARY
2807 { $$ = make_pointer_declarator ($2, $3); }
2808 | '&' nonempty_type_quals after_type_declarator %prec UNARY
2809 { $$ = make_reference_declarator ($2, $3); }
2810 | '*' after_type_declarator %prec UNARY
2811 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2812 | '&' after_type_declarator %prec UNARY
2813 { $$ = make_reference_declarator (NULL_TREE, $2); }
2814 | ptr_to_mem type_quals after_type_declarator
2815 { tree arg = make_pointer_declarator ($2, $3);
2816 $$ = build_parse_node (SCOPE_REF, $1, arg);
2818 | direct_after_type_declarator
2821 qualified_type_name:
2822 type_name %prec EMPTY
2824 /* Remember that this name has been used in the class
2825 definition, as per [class.scope0] */
2826 if (current_class_type
2827 && TYPE_BEING_DEFINED (current_class_type)
2828 && ! IDENTIFIER_CLASS_VALUE ($$))
2830 tree t = lookup_name ($$, -2);
2832 pushdecl_class_level (t);
2839 nested_name_specifier type_name %prec EMPTY
2843 direct_after_type_declarator:
2844 direct_after_type_declarator '(' nonnull_exprlist ')' type_quals %prec '.'
2845 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2846 | direct_after_type_declarator '(' parmlist ')' type_quals %prec '.'
2847 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2848 | direct_after_type_declarator LEFT_RIGHT type_quals %prec '.'
2849 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
2850 | direct_after_type_declarator '(' error ')' type_quals %prec '.'
2851 { $$ = build_parse_node (CALL_EXPR, $$, NULL_TREE, NULL_TREE); }
2852 | direct_after_type_declarator '[' nonmomentary_expr ']'
2853 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2854 | direct_after_type_declarator '[' ']'
2855 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2856 | '(' after_type_declarator ')'
2858 | nested_name_specifier type_name %prec EMPTY
2859 { push_nested_class (TREE_TYPE ($$), 3);
2860 $$ = build_parse_node (SCOPE_REF, $$, $2);
2861 TREE_COMPLEXITY ($$) = current_class_depth; }
2862 | type_name %prec EMPTY
2865 /* A declarator allowed whether or not there has been
2866 an explicit typespec. These cannot redeclare a typedef-name. */
2869 '*' nonempty_type_quals notype_declarator %prec UNARY
2870 { $$ = make_pointer_declarator ($2, $3); }
2871 | '&' nonempty_type_quals notype_declarator %prec UNARY
2872 { $$ = make_reference_declarator ($2, $3); }
2873 | '*' notype_declarator %prec UNARY
2874 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2875 | '&' notype_declarator %prec UNARY
2876 { $$ = make_reference_declarator (NULL_TREE, $2); }
2877 | ptr_to_mem type_quals notype_declarator
2878 { tree arg = make_pointer_declarator ($2, $3);
2879 $$ = build_parse_node (SCOPE_REF, $1, arg);
2881 | direct_notype_declarator
2884 complex_notype_declarator:
2885 '*' nonempty_type_quals notype_declarator %prec UNARY
2886 { $$ = make_pointer_declarator ($2, $3); }
2887 | '&' nonempty_type_quals notype_declarator %prec UNARY
2888 { $$ = make_reference_declarator ($2, $3); }
2889 | '*' complex_notype_declarator %prec UNARY
2890 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2891 | '&' complex_notype_declarator %prec UNARY
2892 { $$ = make_reference_declarator (NULL_TREE, $2); }
2893 | ptr_to_mem type_quals notype_declarator
2894 { tree arg = make_pointer_declarator ($2, $3);
2895 $$ = build_parse_node (SCOPE_REF, $1, arg);
2897 | complex_direct_notype_declarator
2900 complex_direct_notype_declarator:
2901 direct_notype_declarator '(' nonnull_exprlist ')' type_quals %prec '.'
2902 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2903 | direct_notype_declarator '(' parmlist ')' type_quals %prec '.'
2904 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2905 | direct_notype_declarator LEFT_RIGHT type_quals %prec '.'
2906 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
2907 | direct_notype_declarator '(' error ')' type_quals %prec '.'
2908 { $$ = build_parse_node (CALL_EXPR, $$, NULL_TREE, NULL_TREE); }
2909 | '(' complex_notype_declarator ')'
2911 | direct_notype_declarator '[' nonmomentary_expr ']'
2912 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2913 | direct_notype_declarator '[' ']'
2914 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2915 | notype_qualified_id
2916 { push_nested_class (TREE_TYPE (OP0 ($$)), 3);
2917 TREE_COMPLEXITY ($$) = current_class_depth; }
2921 nested_name_specifier unqualified_id
2922 { got_scope = NULL_TREE;
2923 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2926 notype_qualified_id:
2927 nested_name_specifier notype_unqualified_id
2928 { got_scope = NULL_TREE;
2929 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2934 | global_scope notype_qualified_id
2939 typespec '(' nonnull_exprlist ')'
2940 { $$ = build_functional_cast ($$, $3); }
2941 | typespec '(' expr_or_declarator ')'
2942 { $$ = reparse_decl_as_expr ($$, $3); }
2943 | typespec fcast_or_absdcl %prec EMPTY
2944 { $$ = reparse_absdcl_as_expr ($$, $2); }
2949 | template_type %prec EMPTY
2952 nested_name_specifier:
2953 nested_name_specifier_1
2954 | nested_name_specifier nested_name_specifier_1
2958 /* Why the @#$%^& do type_name and notype_identifier need to be expanded
2959 inline here?!? (jason) */
2960 nested_name_specifier_1:
2962 { got_scope = TREE_TYPE ($$); }
2964 { got_scope = TREE_TYPE ($$); }
2965 | template_type SCOPE
2966 { got_scope = TREE_TYPE ($$); }
2967 /* These break 'const i;'
2971 cp_error ("`%D' is not an aggregate typedef",
2972 lastiddecl ? lastiddecl : $$);
2973 $$ = error_mark_node;
2976 { goto failed_scope; } */
2981 | global_scope qualified_type_name
2987 | global_scope qualified_type_name
2992 nested_name_specifier '*'
2993 { got_scope = NULL_TREE; }
2994 | global_scope nested_name_specifier '*'
2995 { $$ = $2; got_scope = NULL_TREE; }
2998 /* All uses of explicit global scope must go through this nonterminal so
2999 that got_scope will be set before yylex is called to get the next token. */
3002 { got_scope = void_type_node; }
3005 /* ANSI new-declarator (5.3.4) */
3007 '*' type_quals new_declarator
3008 { $$ = make_pointer_declarator ($2, $3); }
3009 | '*' type_quals %prec EMPTY
3010 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3011 | '&' type_quals new_declarator %prec EMPTY
3012 { $$ = make_reference_declarator ($2, $3); }
3013 | '&' type_quals %prec EMPTY
3014 { $$ = make_reference_declarator ($2, NULL_TREE); }
3015 | ptr_to_mem type_quals %prec EMPTY
3016 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3017 $$ = build_parse_node (SCOPE_REF, $1, arg);
3019 | ptr_to_mem type_quals new_declarator
3020 { tree arg = make_pointer_declarator ($2, $3);
3021 $$ = build_parse_node (SCOPE_REF, $1, arg);
3023 | direct_new_declarator %prec EMPTY
3026 /* ANSI direct-new-declarator (5.3.4) */
3027 direct_new_declarator:
3029 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3030 | direct_new_declarator '[' nonmomentary_expr ']'
3031 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3034 /* ANSI abstract-declarator (8.1) */
3036 '*' nonempty_type_quals absdcl
3037 { $$ = make_pointer_declarator ($2, $3); }
3039 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3040 | '*' nonempty_type_quals %prec EMPTY
3041 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3043 { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
3044 | '&' nonempty_type_quals absdcl
3045 { $$ = make_reference_declarator ($2, $3); }
3047 { $$ = make_reference_declarator (NULL_TREE, $2); }
3048 | '&' nonempty_type_quals %prec EMPTY
3049 { $$ = make_reference_declarator ($2, NULL_TREE); }
3051 { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
3052 | ptr_to_mem type_quals %prec EMPTY
3053 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3054 $$ = build_parse_node (SCOPE_REF, $1, arg);
3056 | ptr_to_mem type_quals absdcl
3057 { tree arg = make_pointer_declarator ($2, $3);
3058 $$ = build_parse_node (SCOPE_REF, $1, arg);
3060 | direct_abstract_declarator %prec EMPTY
3063 /* ANSI direct-abstract-declarator (8.1) */
3064 direct_abstract_declarator:
3067 /* `(typedef)1' is `int'. */
3069 | direct_abstract_declarator '(' parmlist ')' type_quals %prec '.'
3070 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
3071 | direct_abstract_declarator LEFT_RIGHT type_quals %prec '.'
3072 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
3073 | direct_abstract_declarator '[' nonmomentary_expr ']' %prec '.'
3074 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3075 | direct_abstract_declarator '[' ']' %prec '.'
3076 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
3077 | '(' complex_parmlist ')' type_quals %prec '.'
3078 { $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2, $4); }
3079 | regcast_or_absdcl type_quals %prec '.'
3080 { TREE_OPERAND ($$, 2) = $2; }
3081 | fcast_or_absdcl type_quals %prec '.'
3082 { TREE_OPERAND ($$, 2) = $2; }
3083 | '[' nonmomentary_expr ']' %prec '.'
3084 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3086 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
3089 /* For C++, decls and stmts can be intermixed, so we don't need to
3090 have a special rule that won't start parsing the stmt section
3091 until we have a stmt that parses without errors. */
3103 /* build the LET_STMT node before parsing its contents,
3104 so that any LET_STMTs within the context can have their display pointers
3105 set up to point at this one. */
3107 .pushlevel: /* empty */
3108 { emit_line_note (input_filename, lineno);
3112 expand_start_bindings (0); }
3115 /* Read zero or more forward-declarations for labels
3116 that nested functions can jump to. */
3121 pedwarn ("ANSI C++ forbids label declarations"); }
3126 | label_decls label_decl
3130 LABEL identifiers_or_typenames ';'
3132 for (link = $2; link; link = TREE_CHAIN (link))
3134 tree label = shadow_label (TREE_VALUE (link));
3135 C_DECLARED_LABEL_FLAG (label) = 1;
3136 declare_nonlocal_label (label);
3141 /* This is the body of a function definition.
3142 It causes syntax errors to ignore to the next openbrace. */
3149 compstmt: '{' .pushlevel '}'
3150 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3151 $$ = poplevel (kept_level_p (), 1, 0);
3153 | '{' .pushlevel maybe_label_decls stmts '}'
3154 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3155 $$ = poplevel (kept_level_p (), 1, 0);
3157 | '{' .pushlevel maybe_label_decls stmts error '}'
3158 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3159 $$ = poplevel (kept_level_p (), 0, 0);
3161 | '{' .pushlevel maybe_label_decls error '}'
3162 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3163 $$ = poplevel (kept_level_p (), 0, 0);
3169 { cond_stmt_keyword = "if"; }
3170 .pushlevel paren_cond_or_null
3171 { emit_line_note (input_filename, lineno);
3172 expand_start_cond ($4, 0); }
3173 implicitly_scoped_stmt
3176 implicitly_scoped_stmt:
3179 | .pushlevel simple_stmt
3180 { expand_end_bindings (getdecls (), kept_level_p (), 1);
3181 $$ = poplevel (kept_level_p (), 1, 0);
3197 emit_line_note (input_filename, lineno);
3198 /* Do default conversion if safe and possibly important,
3199 in case within ({...}). */
3200 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
3202 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
3203 expr = default_conversion (expr);
3204 cplus_expand_expr_stmt (expr);
3208 { expand_start_else (); }
3209 implicitly_scoped_stmt
3210 { expand_end_cond ();
3211 expand_end_bindings (getdecls (), kept_level_p (), 1);
3212 poplevel (kept_level_p (), 1, 0);
3215 | simple_if %prec IF
3216 { expand_end_cond ();
3217 expand_end_bindings (getdecls (), kept_level_p (), 1);
3218 poplevel (kept_level_p (), 1, 0);
3223 emit_line_note (input_filename, lineno);
3224 expand_start_loop (1);
3225 cond_stmt_keyword = "while"; }
3226 .pushlevel paren_cond_or_null
3227 { expand_exit_loop_if_false (0, $4); }
3229 { expand_end_bindings (getdecls (), kept_level_p (), 1);
3230 poplevel (kept_level_p (), 1, 0);
3236 emit_line_note (input_filename, lineno);
3237 expand_start_loop_continue_elsewhere (1); }
3238 implicitly_scoped_stmt WHILE
3239 { expand_loop_continue_here ();
3240 cond_stmt_keyword = "do"; }
3241 paren_expr_or_null ';'
3242 { emit_line_note (input_filename, lineno);
3243 expand_exit_loop_if_false (0, $6);
3249 emit_line_note (input_filename, lineno);
3250 if ($1) cplus_expand_expr_stmt ($1);
3251 expand_start_loop_continue_elsewhere (1); }
3252 .pushlevel xcond ';'
3253 { emit_line_note (input_filename, lineno);
3254 if ($4) expand_exit_loop_if_false (0, $4); }
3256 /* Don't let the tree nodes for $7 be discarded
3257 by clear_momentary during the parsing of the next stmt. */
3258 { push_momentary (); }
3260 { emit_line_note (input_filename, lineno);
3261 expand_end_bindings (getdecls (), kept_level_p (), 1);
3262 poplevel (kept_level_p (), 1, 0);
3264 expand_loop_continue_here ();
3265 if ($7) cplus_expand_expr_stmt ($7);
3271 emit_line_note (input_filename, lineno);
3272 expand_start_loop_continue_elsewhere (1); }
3273 .pushlevel xcond ';'
3274 { emit_line_note (input_filename, lineno);
3275 if ($4) expand_exit_loop_if_false (0, $4); }
3277 /* Don't let the tree nodes for $7 be discarded
3278 by clear_momentary during the parsing of the next stmt. */
3279 { push_momentary ();
3280 $<itype>8 = lineno; }
3282 { emit_line_note (input_filename, (int) $<itype>8);
3283 expand_end_bindings (getdecls (), kept_level_p (), 1);
3284 poplevel (kept_level_p (), 1, 0);
3286 expand_loop_continue_here ();
3287 if ($7) cplus_expand_expr_stmt ($7);
3292 | SWITCH .pushlevel '(' condition ')'
3293 { emit_line_note (input_filename, lineno);
3294 c_expand_start_case ($4);
3295 /* Don't let the tree nodes for $4 be discarded by
3296 clear_momentary during the parsing of the next stmt. */
3297 push_momentary (); }
3298 implicitly_scoped_stmt
3299 { expand_end_case ($4);
3301 expand_end_bindings (getdecls (), kept_level_p (), 1);
3302 poplevel (kept_level_p (), 1, 0);
3305 | CASE expr_no_commas ':'
3306 { register tree value = check_cp_case_value ($2);
3308 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3310 if (value != error_mark_node)
3313 int success = pushcase (value, convert_and_check,
3316 cp_error ("case label `%E' not within a switch statement", $2);
3317 else if (success == 2)
3319 cp_error ("duplicate case value `%E'", $2);
3320 cp_error_at ("previously used here", duplicate);
3322 else if (success == 3)
3323 warning ("case value out of range");
3324 else if (success == 5)
3325 cp_error ("case label `%E' within scope of cleanup or variable array", $2);
3327 define_case_label (label);
3330 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
3331 { register tree value1 = check_cp_case_value ($2);
3332 register tree value2 = check_cp_case_value ($4);
3334 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3337 pedwarn ("ANSI C++ forbids range expressions in switch statement");
3338 if (value1 != error_mark_node
3339 && value2 != error_mark_node)
3342 int success = pushcase_range (value1, value2,
3343 convert_and_check, label,
3346 error ("case label not within a switch statement");
3347 else if (success == 2)
3349 error ("duplicate (or overlapping) case value");
3350 error_with_decl (duplicate, "this is the first entry overlapping that value");
3352 else if (success == 3)
3353 warning ("case value out of range");
3354 else if (success == 4)
3355 warning ("empty range specified");
3356 else if (success == 5)
3357 error ("case label within scope of cleanup or variable array");
3359 define_case_label (label);
3366 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3367 int success = pushcase (NULL_TREE, 0, label, &duplicate);
3369 error ("default label not within a switch statement");
3370 else if (success == 2)
3372 error ("multiple default labels in one switch");
3373 error_with_decl (duplicate, "this is the first default label");
3375 define_case_label (NULL_TREE);
3379 { emit_line_note (input_filename, lineno);
3380 if ( ! expand_exit_something ())
3381 error ("break statement not within loop or switch"); }
3383 { emit_line_note (input_filename, lineno);
3384 if (! expand_continue_loop (0))
3385 error ("continue statement not within a loop"); }
3387 { emit_line_note (input_filename, lineno);
3388 c_expand_return (NULL_TREE); }
3390 { emit_line_note (input_filename, lineno);
3391 c_expand_return ($2);
3394 | asm_keyword maybe_type_qual '(' string ')' ';'
3395 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3396 emit_line_note (input_filename, lineno);
3400 /* This is the case with just output operands. */
3401 | asm_keyword maybe_type_qual '(' string ':' asm_operands ')' ';'
3402 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3403 emit_line_note (input_filename, lineno);
3404 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
3405 $2 == ridpointers[(int)RID_VOLATILE],
3406 input_filename, lineno);
3409 /* This is the case with input operands as well. */
3410 | asm_keyword maybe_type_qual '(' string ':' asm_operands ':' asm_operands ')' ';'
3411 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3412 emit_line_note (input_filename, lineno);
3413 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
3414 $2 == ridpointers[(int)RID_VOLATILE],
3415 input_filename, lineno);
3418 /* This is the case with clobbered registers as well. */
3419 | asm_keyword maybe_type_qual '(' string ':' asm_operands ':'
3420 asm_operands ':' asm_clobbers ')' ';'
3421 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3422 emit_line_note (input_filename, lineno);
3423 c_expand_asm_operands ($4, $6, $8, $10,
3424 $2 == ridpointers[(int)RID_VOLATILE],
3425 input_filename, lineno);
3429 { emit_line_note (input_filename, lineno);
3430 expand_computed_goto ($3); }
3431 | GOTO identifier ';'
3433 emit_line_note (input_filename, lineno);
3434 decl = lookup_label ($2);
3435 TREE_USED (decl) = 1;
3436 expand_goto (decl); }
3440 { error ("label must be followed by statement");
3450 { expand_start_try_stmts (); }
3452 { expand_end_try_stmts ();
3453 expand_start_all_catch (); }
3455 { expand_end_all_catch (); }
3460 /* An empty try block is degenerate, but it's better to
3461 do extra work here than to do all the special-case work
3463 { expand_end_bindings (0,1,1);
3467 { expand_end_bindings (0,1,1);
3471 { expand_end_bindings (0,1,1);
3479 { emit_line_note (input_filename, lineno); }
3480 .pushlevel handler_args compstmt
3481 { expand_end_catch_block ();
3482 expand_end_bindings (getdecls (), kept_level_p (), 1);
3483 poplevel (kept_level_p (), 1, 0);
3489 typed_typespecs %prec EMPTY
3490 | nonempty_type_quals %prec EMPTY
3495 { expand_start_catch_block (NULL_TREE, NULL_TREE); }
3496 /* This doesn't allow reference parameters, the below does.
3497 | '(' type_specifier_seq absdcl ')'
3498 { expand_start_catch_block ($2, $3); }
3499 | '(' type_specifier_seq ')'
3500 { expand_start_catch_block ($2, NULL_TREE); }
3501 | '(' type_specifier_seq notype_declarator ')'
3502 { expand_start_catch_block ($2, $3); }
3503 | '(' typed_typespecs after_type_declarator ')'
3504 { expand_start_catch_block ($2, $3); }
3505 This allows reference parameters... */
3507 { expand_start_catch_block (TREE_PURPOSE ($2),
3515 label = define_label (input_filename, lineno, $1);
3517 expand_label (label);
3539 | FOR '(' '{' .pushlevel stmts '}'
3541 | FOR '(' '{' .pushlevel error '}'
3545 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
3549 { emit_line_note (input_filename, lineno);
3552 { emit_line_note (input_filename, lineno); }
3563 /* These are the operands other than the first string and colon
3564 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
3565 asm_operands: /* empty */
3567 | nonnull_asm_operands
3570 nonnull_asm_operands:
3572 | nonnull_asm_operands ',' asm_operand
3573 { $$ = chainon ($$, $3); }
3578 { $$ = build_tree_list ($$, $3); }
3583 { $$ = tree_cons (NULL_TREE, $$, NULL_TREE); }
3584 | asm_clobbers ',' STRING
3585 { $$ = tree_cons (NULL_TREE, $3, $$); }
3588 /* This is what appears inside the parens in a function declarator.
3589 Its value is represented in the format that grokdeclarator expects.
3591 In C++, declaring a function with no parameters
3592 means that that function takes *no* parameters. */
3594 parmlist: /* empty */
3596 if (strict_prototype)
3597 $$ = void_list_node;
3603 { $$ = tree_cons (NULL_TREE, $$, void_list_node);
3604 TREE_PARMLIST ($$) = 1; }
3607 /* This nonterminal does not include the common sequence '(' type_id ')',
3608 as it is ambiguous and must be disambiguated elsewhere. */
3612 $$ = chainon ($$, void_list_node);
3613 TREE_PARMLIST ($$) = 1;
3615 | parms_comma ELLIPSIS
3617 TREE_PARMLIST ($$) = 1;
3619 /* C++ allows an ellipsis without a separating ',' */
3622 TREE_PARMLIST ($$) = 1;
3626 $$ = build_tree_list (NULL_TREE, $$);
3627 TREE_PARMLIST ($$) = 1;
3631 /* ARM $8.2.5 has this as a boxed-off comment. */
3633 warning ("use of `...' without a first argument is non-portable");
3638 TREE_PARMLIST ($$) = 1;
3640 | parms TYPENAME_ELLIPSIS
3642 TREE_PARMLIST ($$) = 1;
3644 | type_id TYPENAME_ELLIPSIS
3646 $$ = build_tree_list (NULL_TREE, $$);
3647 TREE_PARMLIST ($$) = 1;
3651 /* This helps us recover from really nasty
3652 parse errors, for example, a missing right
3654 yyerror ("possibly missing ')'");
3655 $$ = chainon ($$, void_list_node);
3656 TREE_PARMLIST ($$) = 1;
3662 /* This helps us recover from really nasty
3663 parse errors, for example, a missing right
3665 yyerror ("possibly missing ')'");
3666 $$ = tree_cons (NULL_TREE, $$, void_list_node);
3667 TREE_PARMLIST ($$) = 1;
3673 /* A nonempty list of parameter declarations or type names. */
3676 { $$ = build_tree_list (NULL_TREE, $$); }
3678 { $$ = build_tree_list ($3, $$); }
3679 | parms_comma full_parm
3680 { $$ = chainon ($$, $2); }
3681 | parms_comma bad_parm
3682 { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
3683 | parms_comma bad_parm '=' init
3684 { $$ = chainon ($$, build_tree_list ($4, $2)); }
3690 { $$ = build_tree_list (NULL_TREE, $$); }
3693 /* A single parameter declaration or parameter type name,
3694 as found in a parmlist. The first four cases make up for 10%
3695 of the time spent parsing C++. We cannot use them because
3696 of `int id[]' which won't get parsed properly. */
3699 typed_declspecs dont_see_typename '*' IDENTIFIER
3700 { $$ = build_tree_list ($$, build_parse_node (INDIRECT_REF, $4));
3702 | typed_declspecs dont_see_typename '&' IDENTIFIER
3703 { $$ = build_tree_list ($$, build_parse_node (ADDR_EXPR, $4));
3705 | TYPENAME IDENTIFIER
3706 { $$ = build_tree_list (get_decl_list ($$), $2); }
3707 | TYPESPEC IDENTIFIER
3708 { $$ = build_tree_list (get_decl_list ($$), $2); }
3710 /* Here we expand typed_declspecs inline to avoid mis-parsing of
3711 TYPESPEC IDENTIFIER. */
3712 typed_declspecs1 declarator
3713 { $$ = build_tree_list ($$, $2); }
3714 | typed_typespecs declarator
3715 { $$ = build_tree_list ($$, $2); }
3716 | typespec declarator
3717 { $$ = build_tree_list (get_decl_list ($$), $2); }
3718 | typed_declspecs1 absdcl
3719 { $$ = build_tree_list ($$, $2); }
3720 | typed_declspecs1 %prec EMPTY
3721 { $$ = build_tree_list ($$, NULL_TREE); }
3722 | declmods notype_declarator
3723 { $$ = build_tree_list ($$, $2); }
3728 { $$ = build_tree_list ($2, $$); }
3736 see_typename: %prec EMPTY
3737 { see_typename (); }
3741 dont_see_typename: %prec EMPTY
3742 { dont_see_typename (); }
3747 if ($<ttype>-1 == error_mark_node)
3752 pushclass ($<ttype>-1, 1);
3759 /* empty */ %prec EMPTY
3761 error ("type specifier omitted for parameter");
3762 $$ = build_tree_list (integer_type_node, NULL_TREE);
3766 error ("type specifier omitted for parameter");
3767 $$ = build_tree_list (integer_type_node, $$);
3771 exception_specification_opt:
3772 %prec EMPTY /* empty */
3774 | THROW '(' ansi_raise_identifiers ')' %prec EMPTY
3776 | THROW LEFT_RIGHT %prec EMPTY
3777 { $$ = build_decl_list (NULL_TREE, NULL_TREE); }
3780 ansi_raise_identifier:
3782 { $$ = build_decl_list (NULL_TREE, groktypename($$)); }
3785 ansi_raise_identifiers:
3786 ansi_raise_identifier
3787 | ansi_raise_identifiers ',' ansi_raise_identifier
3789 TREE_CHAIN ($3) = $$;
3794 conversion_declarator:
3795 /* empty */ %prec EMPTY
3797 | '*' type_quals conversion_declarator
3798 { $$ = make_pointer_declarator ($2, $3); }
3799 | '&' type_quals conversion_declarator
3800 { $$ = make_reference_declarator ($2, $3); }
3801 | ptr_to_mem type_quals conversion_declarator
3802 { tree arg = make_pointer_declarator ($2, $3);
3803 $$ = build_parse_node (SCOPE_REF, $1, arg);
3808 { got_scope = NULL_TREE; }
3813 { $$ = ansi_opname[MULT_EXPR]; }
3815 { $$ = ansi_opname[TRUNC_DIV_EXPR]; }
3817 { $$ = ansi_opname[TRUNC_MOD_EXPR]; }
3819 { $$ = ansi_opname[PLUS_EXPR]; }
3821 { $$ = ansi_opname[MINUS_EXPR]; }
3823 { $$ = ansi_opname[BIT_AND_EXPR]; }
3825 { $$ = ansi_opname[BIT_IOR_EXPR]; }
3827 { $$ = ansi_opname[BIT_XOR_EXPR]; }
3829 { $$ = ansi_opname[BIT_NOT_EXPR]; }
3831 { $$ = ansi_opname[COMPOUND_EXPR]; }
3832 | operator ARITHCOMPARE
3833 { $$ = ansi_opname[$2]; }
3835 { $$ = ansi_opname[LT_EXPR]; }
3837 { $$ = ansi_opname[GT_EXPR]; }
3838 | operator EQCOMPARE
3839 { $$ = ansi_opname[$2]; }
3841 { $$ = ansi_assopname[$2]; }
3843 { $$ = ansi_opname [MODIFY_EXPR]; }
3845 { $$ = ansi_opname[$2]; }
3847 { $$ = ansi_opname[$2]; }
3849 { $$ = ansi_opname[POSTINCREMENT_EXPR]; }
3850 | operator MINUSMINUS
3851 { $$ = ansi_opname[PREDECREMENT_EXPR]; }
3853 { $$ = ansi_opname[TRUTH_ANDIF_EXPR]; }
3855 { $$ = ansi_opname[TRUTH_ORIF_EXPR]; }
3857 { $$ = ansi_opname[TRUTH_NOT_EXPR]; }
3859 { $$ = ansi_opname[COND_EXPR]; }
3861 { $$ = ansi_opname[$2]; }
3862 | operator POINTSAT %prec EMPTY
3863 { $$ = ansi_opname[COMPONENT_REF]; }
3864 | operator POINTSAT_STAR %prec EMPTY
3865 { $$ = ansi_opname[MEMBER_REF]; }
3866 | operator LEFT_RIGHT
3867 { $$ = ansi_opname[CALL_EXPR]; }
3869 { $$ = ansi_opname[ARRAY_REF]; }
3870 | operator NEW %prec EMPTY
3871 { $$ = ansi_opname[NEW_EXPR]; }
3872 | operator DELETE %prec EMPTY
3873 { $$ = ansi_opname[DELETE_EXPR]; }
3874 | operator NEW '[' ']'
3875 { $$ = ansi_opname[VEC_NEW_EXPR]; }
3876 | operator DELETE '[' ']'
3877 { $$ = ansi_opname[VEC_DELETE_EXPR]; }
3878 /* Names here should be looked up in class scope ALSO. */
3879 | operator type_specifier_seq conversion_declarator
3880 { $$ = grokoptypename ($2, $3); }
3882 { $$ = ansi_opname[ERROR_MARK]; }
3889 debug_yytranslate (value)
3892 return yytname[YYTRANSLATE (value)];