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 TYPENAME_KEYWORD
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); }
2188 | TYPENAME_KEYWORD complex_type_name
2190 /* C++ extensions, merged with C to avoid shift/reduce conflicts */
2191 | class_head left_curly opt.component_decl_list '}'
2197 /* Need to rework class nesting in the
2198 presence of nested classes, etc. */
2199 shadow_tag (CLASSTYPE_AS_LIST ($$)); */
2201 if (yychar == YYEMPTY)
2203 semi = yychar == ';';
2204 /* finish_struct nukes this anyway; if
2205 finish_exception does too, then it can go. */
2207 note_got_semicolon ($$);
2209 if (TREE_CODE ($$) == ENUMERAL_TYPE)
2210 /* $$ = $1 from default rule. */;
2213 $$ = finish_struct ($$, $3, semi);
2214 if (semi) note_got_semicolon ($$);
2219 id = TYPE_IDENTIFIER ($$);
2220 if (id && IDENTIFIER_TEMPLATE (id))
2224 /* I don't know if the copying of this TYPE_DECL is
2225 * really needed. However, it's such a small per-
2226 * formance penalty that the extra safety is a bargain.
2229 push_obstacks (&permanent_obstack, &permanent_obstack);
2230 decl = copy_node (lookup_name (id, 0));
2231 if (DECL_LANG_SPECIFIC (decl))
2232 copy_lang_decl (decl);
2234 undo_template_name_overload (id, 0);
2235 pushdecl_top_level (decl);
2238 check_for_missing_semicolon ($$); }
2239 | class_head %prec EMPTY
2241 /* struct B: public A; is not accepted by the WP grammar. */
2242 if (TYPE_BINFO_BASETYPES ($$) && !TYPE_SIZE ($$)
2243 && ! TYPE_BEING_DEFINED ($$))
2244 cp_error ("base clause without member specification for `%#T'",
2257 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
2262 { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2264 { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2266 { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2268 { error ("no body nor ';' separates two class, struct or union declarations"); }
2272 aggr template_type_name ';'
2274 yyungetc (';', 1); current_aggr = $$; $$ = $2;
2275 if ($<ttype>0 == ridpointers[(int) RID_TEMPLATE])
2276 instantiate_class_template ($$, 2);
2280 named_class_head_sans_basetype:
2282 { current_aggr = $$; $$ = $2; }
2283 | aggr complex_type_name
2284 { current_aggr = $$; $$ = $2; }
2285 | aggr template_type %prec EMPTY
2286 { current_aggr = $$; $$ = $2; }
2290 named_class_head_sans_basetype_defn:
2291 aggr identifier_defn %prec EMPTY
2292 { current_aggr = $$; $$ = $2; }
2293 | aggr template_type_name '{'
2294 { yyungetc ('{', 1);
2298 overload_template_name ($$, 0); }
2299 | aggr template_type_name ':'
2300 { yyungetc (':', 1); goto aggr2; }
2303 do_xref_defn: /* empty */ %prec EMPTY
2304 { $<ttype>$ = xref_tag (current_aggr, $<ttype>0, NULL_TREE, 0); }
2308 named_class_head_sans_basetype %prec EMPTY
2309 { $$ = xref_tag (current_aggr, $1, NULL_TREE, 1); }
2310 | named_class_head_sans_basetype_defn do_xref_defn
2311 maybe_base_class_list %prec EMPTY
2315 xref_basetypes (current_aggr, $1, $<ttype>2, $3);
2319 unnamed_class_head: aggr '{'
2320 { $$ = xref_tag ($$, make_anon_name (), NULL_TREE, 0);
2321 yyungetc ('{', 1); }
2324 class_head: unnamed_class_head | named_class_head ;
2326 maybe_base_class_list:
2327 %prec EMPTY /* empty */
2330 { yyungetc(':', 1); $$ = NULL_TREE; }
2331 | ':' base_class_list %prec EMPTY
2337 | base_class_list ',' base_class
2338 { $$ = chainon ($$, $3); }
2346 type = IDENTIFIER_TYPE_VALUE ($$);
2347 if (! is_aggr_typedef ($$, 1))
2349 else if (current_aggr == signature_type_node
2350 && (! type) && (! IS_SIGNATURE (type)))
2352 error ("class name not allowed as base signature");
2355 else if (current_aggr == signature_type_node)
2357 sorry ("signature inheritance, base type `%s' ignored",
2358 IDENTIFIER_POINTER ($$));
2359 $$ = build_tree_list ((tree)access_public, $$);
2361 else if (type && IS_SIGNATURE (type))
2363 error ("signature name not allowed as base class");
2367 $$ = build_tree_list ((tree)access_default, $$);
2369 | base_class_access_list base_class.1
2373 type = IDENTIFIER_TYPE_VALUE ($2);
2374 if (current_aggr == signature_type_node)
2375 error ("access and source specifiers not allowed in signature");
2376 if (! is_aggr_typedef ($2, 1))
2378 else if (current_aggr == signature_type_node
2379 && (! type) && (! IS_SIGNATURE (type)))
2381 error ("class name not allowed as base signature");
2384 else if (current_aggr == signature_type_node)
2386 sorry ("signature inheritance, base type `%s' ignored",
2387 IDENTIFIER_POINTER ($$));
2388 $$ = build_tree_list ((tree)access_public, $2);
2390 else if (type && IS_SIGNATURE (type))
2392 error ("signature name not allowed as base class");
2396 $$ = build_tree_list ((tree) $$, $2);
2402 | SIGOF '(' expr ')'
2404 if (current_aggr == signature_type_node)
2406 if (IS_AGGR_TYPE (TREE_TYPE ($3)))
2408 sorry ("`sigof' as base signature specifier");
2409 /* need to return some dummy signature identifier */
2414 error ("`sigof' applied to non-aggregate expression");
2415 $$ = error_mark_node;
2420 error ("`sigof' in struct or class declaration");
2421 $$ = error_mark_node;
2424 | SIGOF '(' type_id ')'
2426 if (current_aggr == signature_type_node)
2428 if (IS_AGGR_TYPE (groktypename ($3)))
2430 sorry ("`sigof' as base signature specifier");
2431 /* need to return some dummy signature identifier */
2436 error ("`sigof' applied to non-aggregate expression");
2437 $$ = error_mark_node;
2442 error ("`sigof' in struct or class declaration");
2443 $$ = error_mark_node;
2448 base_class_access_list:
2451 { if ($<ttype>$ != ridpointers[(int)RID_VIRTUAL])
2452 sorry ("non-virtual access");
2453 $$ = access_default_virtual; }
2454 | base_class_access_list VISSPEC
2456 if ($2 == access_protected)
2458 warning ("`protected' access not implemented");
2462 else if ($2 == access_public)
2464 if ($1 == access_private)
2467 error ("base class cannot be public and private");
2469 else if ($1 == access_default_virtual)
2470 $$ = access_public_virtual;
2472 else /* $2 == access_private */
2474 if ($1 == access_public)
2476 else if ($1 == access_default_virtual)
2477 $$ = access_private_virtual;
2480 | base_class_access_list SCSPEC
2481 { if ($2 != ridpointers[(int)RID_VIRTUAL])
2482 sorry ("non-virtual access");
2483 if ($$ == access_public)
2484 $$ = access_public_virtual;
2485 else if ($$ == access_private)
2486 $$ = access_private_virtual; }
2490 { tree t = $<ttype>0;
2491 push_obstacks_nochange ();
2492 end_temporary_allocation ();
2494 if (! IS_AGGR_TYPE (t))
2496 t = $<ttype>0 = make_lang_type (RECORD_TYPE);
2497 TYPE_NAME (t) = get_identifier ("erroneous type");
2500 duplicate_tag_error (t);
2501 if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
2503 t = make_lang_type (TREE_CODE (t));
2504 pushtag (TYPE_IDENTIFIER ($<ttype>0), t, 0);
2508 TYPE_BEING_DEFINED (t) = 1;
2509 /* Reset the interface data, at the earliest possible
2510 moment, as it might have been set via a class foo;
2512 /* Don't change signatures. */
2513 if (! IS_SIGNATURE (t))
2515 extern tree pending_vtables;
2517 tree name = TYPE_IDENTIFIER (t);
2519 if (! ANON_AGGRNAME_P (name))
2521 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2522 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2523 (t, interface_unknown);
2526 /* Record how to set the access of this class's
2527 virtual functions. If write_virtuals == 2 or 3, then
2528 inline virtuals are ``extern inline''. */
2529 switch (write_virtuals)
2536 needs_writing = !! value_member (name, pending_vtables);
2539 needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t)
2540 && CLASSTYPE_INTERFACE_KNOWN (t);
2545 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
2548 t = TYPE_IDENTIFIER ($<ttype>0);
2549 if (t && IDENTIFIER_TEMPLATE (t))
2550 overload_template_name (t, 1);
2555 opt.component_decl_list:
2558 | component_decl_list
2560 if (current_aggr == signature_type_node)
2561 $$ = build_tree_list ((tree) access_public, $$);
2563 $$ = build_tree_list ((tree) access_default, $$);
2565 | opt.component_decl_list VISSPEC ':' component_decl_list
2567 tree visspec = (tree) $2;
2569 if (current_aggr == signature_type_node)
2571 error ("access specifier not allowed in signature");
2572 visspec = (tree) access_public;
2574 $$ = chainon ($$, build_tree_list (visspec, $4));
2576 | opt.component_decl_list VISSPEC ':'
2578 if (current_aggr == signature_type_node)
2579 error ("access specifier not allowed in signature");
2583 /* Note: we no longer warn about the semicolon after a component_decl_list.
2584 ARM $9.2 says that the semicolon is optional, and therefore allowed. */
2585 component_decl_list:
2587 { if ($$ == void_type_node) $$ = NULL_TREE;
2589 | component_decl_list component_decl
2590 { /* In pushdecl, we created a reverse list of names
2591 in this binding level. Make sure that the chain
2592 of what we're trying to add isn't the item itself
2593 (which can happen with what pushdecl's doing). */
2594 if ($2 != NULL_TREE && $2 != void_type_node)
2596 if (TREE_CHAIN ($2) != $$)
2597 $$ = chainon ($$, $2);
2602 | component_decl_list ';'
2606 component_decl_1 ';'
2607 | component_decl_1 '}'
2608 { error ("missing ';' before right brace");
2609 yyungetc ('}', 0); }
2610 /* C++: handle constructors, destructors and inline functions */
2611 /* note that INLINE is like a TYPESPEC */
2612 | fn.def2 ':' /* base_init compstmt */
2613 { $$ = finish_method ($$); }
2614 | fn.def2 '{' /* nodecls compstmt */
2615 { $$ = finish_method ($$); }
2619 /* Do not add a "typed_declspecs declarator" rule here for
2620 speed; we need to call grok_x_components for enums, so the
2621 speedup would be insignificant. */
2622 typed_declspecs components
2624 $$ = grok_x_components ($$, $2);
2626 | declmods notype_components
2628 $$ = grok_x_components ($$, $2);
2630 | notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2631 { $$ = grokfield ($$, NULL_TREE, $2, $5, $3);
2632 cplus_decl_attributes ($$, $4, prefix_attributes); }
2633 | ':' expr_no_commas
2634 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
2638 /* These rules introduce a reduce/reduce conflict; in
2639 typedef int foo, bar;
2643 should "A::foo" be declared as a function or "A::bar" as a data
2644 member? In other words, is "bar" an after_type_declarator or a
2646 | typed_declspecs '(' parmlist ')' type_quals exception_specification_opt maybeasm maybe_attribute maybe_init
2647 { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
2649 $$ = grokfield ($$, TREE_CHAIN ($1), $6, $9, $7);
2650 cplus_decl_attributes ($$, $8, prefix_attributes); }
2651 | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt maybeasm maybe_attribute maybe_init
2652 { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
2653 empty_parms (), $3);
2654 $$ = grokfield ($$, TREE_CHAIN ($1), $4, $7, $5);
2655 cplus_decl_attributes ($$, $6, prefix_attributes); }
2659 /* The case of exactly one component is handled directly by component_decl. */
2661 /* empty: possibly anonymous */
2663 | component_declarator0
2664 | components ',' component_declarator
2666 /* In this context, void_type_node encodes
2667 friends. They have been recorded elsewhere. */
2668 if ($$ == void_type_node)
2671 $$ = chainon ($$, $3);
2676 /* empty: possibly anonymous */
2678 | notype_component_declarator0
2679 | notype_components ',' notype_component_declarator
2681 /* In this context, void_type_node encodes
2682 friends. They have been recorded elsewhere. */
2683 if ($$ == void_type_node)
2686 $$ = chainon ($$, $3);
2690 component_declarator0:
2691 after_type_component_declarator0
2692 | notype_component_declarator0
2695 component_declarator:
2696 after_type_component_declarator
2697 | notype_component_declarator
2700 after_type_component_declarator0:
2701 after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2702 { current_declspecs = $<ttype>0;
2703 $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2704 cplus_decl_attributes ($$, $4, prefix_attributes); }
2705 | TYPENAME ':' expr_no_commas maybe_attribute
2706 { current_declspecs = $<ttype>0;
2707 $$ = grokbitfield ($$, current_declspecs, $3);
2708 cplus_decl_attributes ($$, $4, prefix_attributes); }
2711 notype_component_declarator0:
2712 notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2713 { current_declspecs = $<ttype>0;
2714 $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2715 cplus_decl_attributes ($$, $4, prefix_attributes); }
2716 | IDENTIFIER ':' expr_no_commas maybe_attribute
2717 { current_declspecs = $<ttype>0;
2718 $$ = grokbitfield ($$, current_declspecs, $3);
2719 cplus_decl_attributes ($$, $4, prefix_attributes); }
2720 | ':' expr_no_commas maybe_attribute
2721 { current_declspecs = $<ttype>0;
2722 $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2723 cplus_decl_attributes ($$, $3, prefix_attributes); }
2726 after_type_component_declarator:
2727 after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2728 { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2729 cplus_decl_attributes ($$, $4, prefix_attributes); }
2730 | TYPENAME ':' expr_no_commas maybe_attribute
2731 { $$ = grokbitfield ($$, current_declspecs, $3);
2732 cplus_decl_attributes ($$, $4, prefix_attributes); }
2735 notype_component_declarator:
2736 notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2737 { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2738 cplus_decl_attributes ($$, $4, prefix_attributes); }
2739 | IDENTIFIER ':' expr_no_commas maybe_attribute
2740 { $$ = grokbitfield ($$, current_declspecs, $3);
2741 cplus_decl_attributes ($$, $4, prefix_attributes); }
2742 | ':' expr_no_commas maybe_attribute
2743 { $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2744 cplus_decl_attributes ($$, $3, prefix_attributes); }
2747 /* We chain the enumerators in reverse order.
2748 Because of the way enums are built, the order is
2749 insignificant. Take advantage of this fact. */
2753 | enumlist ',' enumerator
2754 { TREE_CHAIN ($3) = $$; $$ = $3; }
2759 { $$ = build_enumerator ($$, NULL_TREE); }
2760 | identifier '=' expr_no_commas
2761 { $$ = build_enumerator ($$, $3); }
2764 /* ANSI new-type-id (5.3.4) */
2766 type_specifier_seq new_declarator
2767 { $$ = build_decl_list ($$, $2); }
2768 | type_specifier_seq %prec EMPTY
2769 { $$ = build_decl_list ($$, NULL_TREE); }
2770 /* GNU extension to allow arrays of arbitrary types with
2771 non-constant dimension. */
2772 | '(' type_id ')' '[' expr ']'
2775 pedwarn ("ANSI C++ forbids array dimensions with parenthesized type in new");
2776 $$ = build_parse_node (ARRAY_REF, TREE_VALUE ($2), $5);
2777 $$ = build_decl_list (TREE_PURPOSE ($2), $$);
2782 /* empty */ %prec EMPTY
2784 | type_quals TYPE_QUAL
2785 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
2788 nonempty_type_quals:
2790 { $$ = IDENTIFIER_AS_LIST ($$); }
2791 | nonempty_type_quals TYPE_QUAL
2792 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
2795 /* These rules must follow the rules for function declarations
2796 and component declarations. That way, longer rules are preferred. */
2798 /* An expression which will not live on the momentary obstack. */
2800 { $<itype>$ = suspend_momentary (); } expr
2801 { resume_momentary ((int) $<itype>1); $$ = $2; }
2804 /* A declarator that is allowed only after an explicit typespec. */
2805 /* may all be followed by prec '.' */
2806 after_type_declarator:
2807 '*' nonempty_type_quals after_type_declarator %prec UNARY
2808 { $$ = make_pointer_declarator ($2, $3); }
2809 | '&' nonempty_type_quals after_type_declarator %prec UNARY
2810 { $$ = make_reference_declarator ($2, $3); }
2811 | '*' after_type_declarator %prec UNARY
2812 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2813 | '&' after_type_declarator %prec UNARY
2814 { $$ = make_reference_declarator (NULL_TREE, $2); }
2815 | ptr_to_mem type_quals after_type_declarator
2816 { tree arg = make_pointer_declarator ($2, $3);
2817 $$ = build_parse_node (SCOPE_REF, $1, arg);
2819 | direct_after_type_declarator
2822 qualified_type_name:
2823 type_name %prec EMPTY
2825 /* Remember that this name has been used in the class
2826 definition, as per [class.scope0] */
2827 if (current_class_type
2828 && TYPE_BEING_DEFINED (current_class_type)
2829 && ! IDENTIFIER_CLASS_VALUE ($$))
2831 tree t = lookup_name ($$, -2);
2833 pushdecl_class_level (t);
2840 nested_name_specifier type_name %prec EMPTY
2844 direct_after_type_declarator:
2845 direct_after_type_declarator '(' nonnull_exprlist ')' type_quals %prec '.'
2846 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2847 | direct_after_type_declarator '(' parmlist ')' type_quals %prec '.'
2848 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2849 | direct_after_type_declarator LEFT_RIGHT type_quals %prec '.'
2850 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
2851 | direct_after_type_declarator '(' error ')' type_quals %prec '.'
2852 { $$ = build_parse_node (CALL_EXPR, $$, NULL_TREE, NULL_TREE); }
2853 | direct_after_type_declarator '[' nonmomentary_expr ']'
2854 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2855 | direct_after_type_declarator '[' ']'
2856 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2857 | '(' after_type_declarator ')'
2859 | nested_name_specifier type_name %prec EMPTY
2860 { push_nested_class (TREE_TYPE ($$), 3);
2861 $$ = build_parse_node (SCOPE_REF, $$, $2);
2862 TREE_COMPLEXITY ($$) = current_class_depth; }
2863 | type_name %prec EMPTY
2866 /* A declarator allowed whether or not there has been
2867 an explicit typespec. These cannot redeclare a typedef-name. */
2870 '*' nonempty_type_quals notype_declarator %prec UNARY
2871 { $$ = make_pointer_declarator ($2, $3); }
2872 | '&' nonempty_type_quals notype_declarator %prec UNARY
2873 { $$ = make_reference_declarator ($2, $3); }
2874 | '*' notype_declarator %prec UNARY
2875 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2876 | '&' notype_declarator %prec UNARY
2877 { $$ = make_reference_declarator (NULL_TREE, $2); }
2878 | ptr_to_mem type_quals notype_declarator
2879 { tree arg = make_pointer_declarator ($2, $3);
2880 $$ = build_parse_node (SCOPE_REF, $1, arg);
2882 | direct_notype_declarator
2885 complex_notype_declarator:
2886 '*' nonempty_type_quals notype_declarator %prec UNARY
2887 { $$ = make_pointer_declarator ($2, $3); }
2888 | '&' nonempty_type_quals notype_declarator %prec UNARY
2889 { $$ = make_reference_declarator ($2, $3); }
2890 | '*' complex_notype_declarator %prec UNARY
2891 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2892 | '&' complex_notype_declarator %prec UNARY
2893 { $$ = make_reference_declarator (NULL_TREE, $2); }
2894 | ptr_to_mem type_quals notype_declarator
2895 { tree arg = make_pointer_declarator ($2, $3);
2896 $$ = build_parse_node (SCOPE_REF, $1, arg);
2898 | complex_direct_notype_declarator
2901 complex_direct_notype_declarator:
2902 direct_notype_declarator '(' nonnull_exprlist ')' type_quals %prec '.'
2903 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2904 | direct_notype_declarator '(' parmlist ')' type_quals %prec '.'
2905 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2906 | direct_notype_declarator LEFT_RIGHT type_quals %prec '.'
2907 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
2908 | direct_notype_declarator '(' error ')' type_quals %prec '.'
2909 { $$ = build_parse_node (CALL_EXPR, $$, NULL_TREE, NULL_TREE); }
2910 | '(' complex_notype_declarator ')'
2912 | direct_notype_declarator '[' nonmomentary_expr ']'
2913 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2914 | direct_notype_declarator '[' ']'
2915 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2916 | notype_qualified_id
2917 { push_nested_class (TREE_TYPE (OP0 ($$)), 3);
2918 TREE_COMPLEXITY ($$) = current_class_depth; }
2922 nested_name_specifier unqualified_id
2923 { got_scope = NULL_TREE;
2924 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2927 notype_qualified_id:
2928 nested_name_specifier notype_unqualified_id
2929 { got_scope = NULL_TREE;
2930 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2935 | global_scope notype_qualified_id
2940 typespec '(' nonnull_exprlist ')'
2941 { $$ = build_functional_cast ($$, $3); }
2942 | typespec '(' expr_or_declarator ')'
2943 { $$ = reparse_decl_as_expr ($$, $3); }
2944 | typespec fcast_or_absdcl %prec EMPTY
2945 { $$ = reparse_absdcl_as_expr ($$, $2); }
2950 | template_type %prec EMPTY
2953 nested_name_specifier:
2954 nested_name_specifier_1
2955 | nested_name_specifier nested_name_specifier_1
2959 /* Why the @#$%^& do type_name and notype_identifier need to be expanded
2960 inline here?!? (jason) */
2961 nested_name_specifier_1:
2963 { got_scope = TREE_TYPE ($$); }
2965 { got_scope = TREE_TYPE ($$); }
2966 | template_type SCOPE
2967 { got_scope = TREE_TYPE ($$); }
2968 /* These break 'const i;'
2972 cp_error ("`%D' is not an aggregate typedef",
2973 lastiddecl ? lastiddecl : $$);
2974 $$ = error_mark_node;
2977 { goto failed_scope; } */
2982 | global_scope qualified_type_name
2988 | global_scope qualified_type_name
2993 nested_name_specifier '*'
2994 { got_scope = NULL_TREE; }
2995 | global_scope nested_name_specifier '*'
2996 { $$ = $2; got_scope = NULL_TREE; }
2999 /* All uses of explicit global scope must go through this nonterminal so
3000 that got_scope will be set before yylex is called to get the next token. */
3003 { got_scope = void_type_node; }
3006 /* ANSI new-declarator (5.3.4) */
3008 '*' type_quals new_declarator
3009 { $$ = make_pointer_declarator ($2, $3); }
3010 | '*' type_quals %prec EMPTY
3011 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3012 | '&' type_quals new_declarator %prec EMPTY
3013 { $$ = make_reference_declarator ($2, $3); }
3014 | '&' type_quals %prec EMPTY
3015 { $$ = make_reference_declarator ($2, NULL_TREE); }
3016 | ptr_to_mem type_quals %prec EMPTY
3017 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3018 $$ = build_parse_node (SCOPE_REF, $1, arg);
3020 | ptr_to_mem type_quals new_declarator
3021 { tree arg = make_pointer_declarator ($2, $3);
3022 $$ = build_parse_node (SCOPE_REF, $1, arg);
3024 | direct_new_declarator %prec EMPTY
3027 /* ANSI direct-new-declarator (5.3.4) */
3028 direct_new_declarator:
3030 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3031 | direct_new_declarator '[' nonmomentary_expr ']'
3032 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3035 /* ANSI abstract-declarator (8.1) */
3037 '*' nonempty_type_quals absdcl
3038 { $$ = make_pointer_declarator ($2, $3); }
3040 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3041 | '*' nonempty_type_quals %prec EMPTY
3042 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3044 { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
3045 | '&' nonempty_type_quals absdcl
3046 { $$ = make_reference_declarator ($2, $3); }
3048 { $$ = make_reference_declarator (NULL_TREE, $2); }
3049 | '&' nonempty_type_quals %prec EMPTY
3050 { $$ = make_reference_declarator ($2, NULL_TREE); }
3052 { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
3053 | ptr_to_mem type_quals %prec EMPTY
3054 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3055 $$ = build_parse_node (SCOPE_REF, $1, arg);
3057 | ptr_to_mem type_quals absdcl
3058 { tree arg = make_pointer_declarator ($2, $3);
3059 $$ = build_parse_node (SCOPE_REF, $1, arg);
3061 | direct_abstract_declarator %prec EMPTY
3064 /* ANSI direct-abstract-declarator (8.1) */
3065 direct_abstract_declarator:
3068 /* `(typedef)1' is `int'. */
3070 | direct_abstract_declarator '(' parmlist ')' type_quals %prec '.'
3071 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
3072 | direct_abstract_declarator LEFT_RIGHT type_quals %prec '.'
3073 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
3074 | direct_abstract_declarator '[' nonmomentary_expr ']' %prec '.'
3075 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3076 | direct_abstract_declarator '[' ']' %prec '.'
3077 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
3078 | '(' complex_parmlist ')' type_quals %prec '.'
3079 { $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2, $4); }
3080 | regcast_or_absdcl type_quals %prec '.'
3081 { TREE_OPERAND ($$, 2) = $2; }
3082 | fcast_or_absdcl type_quals %prec '.'
3083 { TREE_OPERAND ($$, 2) = $2; }
3084 | '[' nonmomentary_expr ']' %prec '.'
3085 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3087 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
3090 /* For C++, decls and stmts can be intermixed, so we don't need to
3091 have a special rule that won't start parsing the stmt section
3092 until we have a stmt that parses without errors. */
3104 /* build the LET_STMT node before parsing its contents,
3105 so that any LET_STMTs within the context can have their display pointers
3106 set up to point at this one. */
3108 .pushlevel: /* empty */
3109 { emit_line_note (input_filename, lineno);
3113 expand_start_bindings (0); }
3116 /* Read zero or more forward-declarations for labels
3117 that nested functions can jump to. */
3122 pedwarn ("ANSI C++ forbids label declarations"); }
3127 | label_decls label_decl
3131 LABEL identifiers_or_typenames ';'
3133 for (link = $2; link; link = TREE_CHAIN (link))
3135 tree label = shadow_label (TREE_VALUE (link));
3136 C_DECLARED_LABEL_FLAG (label) = 1;
3137 declare_nonlocal_label (label);
3142 /* This is the body of a function definition.
3143 It causes syntax errors to ignore to the next openbrace. */
3150 compstmt: '{' .pushlevel '}'
3151 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3152 $$ = poplevel (kept_level_p (), 1, 0);
3154 | '{' .pushlevel maybe_label_decls stmts '}'
3155 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3156 $$ = poplevel (kept_level_p (), 1, 0);
3158 | '{' .pushlevel maybe_label_decls stmts error '}'
3159 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3160 $$ = poplevel (kept_level_p (), 0, 0);
3162 | '{' .pushlevel maybe_label_decls error '}'
3163 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3164 $$ = poplevel (kept_level_p (), 0, 0);
3170 { cond_stmt_keyword = "if"; }
3171 .pushlevel paren_cond_or_null
3172 { emit_line_note (input_filename, lineno);
3173 expand_start_cond ($4, 0); }
3174 implicitly_scoped_stmt
3177 implicitly_scoped_stmt:
3180 | .pushlevel simple_stmt
3181 { expand_end_bindings (getdecls (), kept_level_p (), 1);
3182 $$ = poplevel (kept_level_p (), 1, 0);
3198 emit_line_note (input_filename, lineno);
3199 /* Do default conversion if safe and possibly important,
3200 in case within ({...}). */
3201 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
3203 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
3204 expr = default_conversion (expr);
3205 cplus_expand_expr_stmt (expr);
3209 { expand_start_else (); }
3210 implicitly_scoped_stmt
3211 { expand_end_cond ();
3212 expand_end_bindings (getdecls (), kept_level_p (), 1);
3213 poplevel (kept_level_p (), 1, 0);
3216 | simple_if %prec IF
3217 { expand_end_cond ();
3218 expand_end_bindings (getdecls (), kept_level_p (), 1);
3219 poplevel (kept_level_p (), 1, 0);
3224 emit_line_note (input_filename, lineno);
3225 expand_start_loop (1);
3226 cond_stmt_keyword = "while"; }
3227 .pushlevel paren_cond_or_null
3228 { expand_exit_loop_if_false (0, $4); }
3230 { expand_end_bindings (getdecls (), kept_level_p (), 1);
3231 poplevel (kept_level_p (), 1, 0);
3237 emit_line_note (input_filename, lineno);
3238 expand_start_loop_continue_elsewhere (1); }
3239 implicitly_scoped_stmt WHILE
3240 { expand_loop_continue_here ();
3241 cond_stmt_keyword = "do"; }
3242 paren_expr_or_null ';'
3243 { emit_line_note (input_filename, lineno);
3244 expand_exit_loop_if_false (0, $6);
3250 emit_line_note (input_filename, lineno);
3251 if ($1) cplus_expand_expr_stmt ($1);
3252 expand_start_loop_continue_elsewhere (1); }
3253 .pushlevel xcond ';'
3254 { emit_line_note (input_filename, lineno);
3255 if ($4) expand_exit_loop_if_false (0, $4); }
3257 /* Don't let the tree nodes for $7 be discarded
3258 by clear_momentary during the parsing of the next stmt. */
3259 { push_momentary (); }
3261 { emit_line_note (input_filename, lineno);
3262 expand_end_bindings (getdecls (), kept_level_p (), 1);
3263 poplevel (kept_level_p (), 1, 0);
3265 expand_loop_continue_here ();
3266 if ($7) cplus_expand_expr_stmt ($7);
3272 emit_line_note (input_filename, lineno);
3273 expand_start_loop_continue_elsewhere (1); }
3274 .pushlevel xcond ';'
3275 { emit_line_note (input_filename, lineno);
3276 if ($4) expand_exit_loop_if_false (0, $4); }
3278 /* Don't let the tree nodes for $7 be discarded
3279 by clear_momentary during the parsing of the next stmt. */
3280 { push_momentary ();
3281 $<itype>8 = lineno; }
3283 { emit_line_note (input_filename, (int) $<itype>8);
3284 expand_end_bindings (getdecls (), kept_level_p (), 1);
3285 poplevel (kept_level_p (), 1, 0);
3287 expand_loop_continue_here ();
3288 if ($7) cplus_expand_expr_stmt ($7);
3293 | SWITCH .pushlevel '(' condition ')'
3294 { emit_line_note (input_filename, lineno);
3295 c_expand_start_case ($4);
3296 /* Don't let the tree nodes for $4 be discarded by
3297 clear_momentary during the parsing of the next stmt. */
3298 push_momentary (); }
3299 implicitly_scoped_stmt
3300 { expand_end_case ($4);
3302 expand_end_bindings (getdecls (), kept_level_p (), 1);
3303 poplevel (kept_level_p (), 1, 0);
3306 | CASE expr_no_commas ':'
3307 { register tree value = check_cp_case_value ($2);
3309 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3311 if (value != error_mark_node)
3314 int success = pushcase (value, convert_and_check,
3317 cp_error ("case label `%E' not within a switch statement", $2);
3318 else if (success == 2)
3320 cp_error ("duplicate case value `%E'", $2);
3321 cp_error_at ("previously used here", duplicate);
3323 else if (success == 3)
3324 warning ("case value out of range");
3325 else if (success == 5)
3326 cp_error ("case label `%E' within scope of cleanup or variable array", $2);
3328 define_case_label (label);
3331 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
3332 { register tree value1 = check_cp_case_value ($2);
3333 register tree value2 = check_cp_case_value ($4);
3335 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3338 pedwarn ("ANSI C++ forbids range expressions in switch statement");
3339 if (value1 != error_mark_node
3340 && value2 != error_mark_node)
3343 int success = pushcase_range (value1, value2,
3344 convert_and_check, label,
3347 error ("case label not within a switch statement");
3348 else if (success == 2)
3350 error ("duplicate (or overlapping) case value");
3351 error_with_decl (duplicate, "this is the first entry overlapping that value");
3353 else if (success == 3)
3354 warning ("case value out of range");
3355 else if (success == 4)
3356 warning ("empty range specified");
3357 else if (success == 5)
3358 error ("case label within scope of cleanup or variable array");
3360 define_case_label (label);
3367 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3368 int success = pushcase (NULL_TREE, 0, label, &duplicate);
3370 error ("default label not within a switch statement");
3371 else if (success == 2)
3373 error ("multiple default labels in one switch");
3374 error_with_decl (duplicate, "this is the first default label");
3376 define_case_label (NULL_TREE);
3380 { emit_line_note (input_filename, lineno);
3381 if ( ! expand_exit_something ())
3382 error ("break statement not within loop or switch"); }
3384 { emit_line_note (input_filename, lineno);
3385 if (! expand_continue_loop (0))
3386 error ("continue statement not within a loop"); }
3388 { emit_line_note (input_filename, lineno);
3389 c_expand_return (NULL_TREE); }
3391 { emit_line_note (input_filename, lineno);
3392 c_expand_return ($2);
3395 | asm_keyword maybe_type_qual '(' string ')' ';'
3396 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3397 emit_line_note (input_filename, lineno);
3401 /* This is the case with just output operands. */
3402 | asm_keyword maybe_type_qual '(' string ':' asm_operands ')' ';'
3403 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3404 emit_line_note (input_filename, lineno);
3405 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
3406 $2 == ridpointers[(int)RID_VOLATILE],
3407 input_filename, lineno);
3410 /* This is the case with input operands as well. */
3411 | asm_keyword maybe_type_qual '(' string ':' asm_operands ':' asm_operands ')' ';'
3412 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3413 emit_line_note (input_filename, lineno);
3414 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
3415 $2 == ridpointers[(int)RID_VOLATILE],
3416 input_filename, lineno);
3419 /* This is the case with clobbered registers as well. */
3420 | asm_keyword maybe_type_qual '(' string ':' asm_operands ':'
3421 asm_operands ':' asm_clobbers ')' ';'
3422 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3423 emit_line_note (input_filename, lineno);
3424 c_expand_asm_operands ($4, $6, $8, $10,
3425 $2 == ridpointers[(int)RID_VOLATILE],
3426 input_filename, lineno);
3430 { emit_line_note (input_filename, lineno);
3431 expand_computed_goto ($3); }
3432 | GOTO identifier ';'
3434 emit_line_note (input_filename, lineno);
3435 decl = lookup_label ($2);
3436 TREE_USED (decl) = 1;
3437 expand_goto (decl); }
3441 { error ("label must be followed by statement");
3451 { expand_start_try_stmts (); }
3453 { expand_end_try_stmts ();
3454 expand_start_all_catch (); }
3456 { expand_end_all_catch (); }
3461 /* An empty try block is degenerate, but it's better to
3462 do extra work here than to do all the special-case work
3464 { expand_end_bindings (0,1,1);
3468 { expand_end_bindings (0,1,1);
3472 { expand_end_bindings (0,1,1);
3480 { emit_line_note (input_filename, lineno); }
3481 .pushlevel handler_args compstmt
3482 { expand_end_catch_block ();
3483 expand_end_bindings (getdecls (), kept_level_p (), 1);
3484 poplevel (kept_level_p (), 1, 0);
3490 typed_typespecs %prec EMPTY
3491 | nonempty_type_quals %prec EMPTY
3496 { expand_start_catch_block (NULL_TREE, NULL_TREE); }
3497 /* This doesn't allow reference parameters, the below does.
3498 | '(' type_specifier_seq absdcl ')'
3499 { expand_start_catch_block ($2, $3); }
3500 | '(' type_specifier_seq ')'
3501 { expand_start_catch_block ($2, NULL_TREE); }
3502 | '(' type_specifier_seq notype_declarator ')'
3503 { expand_start_catch_block ($2, $3); }
3504 | '(' typed_typespecs after_type_declarator ')'
3505 { expand_start_catch_block ($2, $3); }
3506 This allows reference parameters... */
3508 { expand_start_catch_block (TREE_PURPOSE ($2),
3516 label = define_label (input_filename, lineno, $1);
3518 expand_label (label);
3540 | FOR '(' '{' .pushlevel stmts '}'
3542 | FOR '(' '{' .pushlevel error '}'
3546 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
3550 { emit_line_note (input_filename, lineno);
3553 { emit_line_note (input_filename, lineno); }
3564 /* These are the operands other than the first string and colon
3565 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
3566 asm_operands: /* empty */
3568 | nonnull_asm_operands
3571 nonnull_asm_operands:
3573 | nonnull_asm_operands ',' asm_operand
3574 { $$ = chainon ($$, $3); }
3579 { $$ = build_tree_list ($$, $3); }
3584 { $$ = tree_cons (NULL_TREE, $$, NULL_TREE); }
3585 | asm_clobbers ',' STRING
3586 { $$ = tree_cons (NULL_TREE, $3, $$); }
3589 /* This is what appears inside the parens in a function declarator.
3590 Its value is represented in the format that grokdeclarator expects.
3592 In C++, declaring a function with no parameters
3593 means that that function takes *no* parameters. */
3595 parmlist: /* empty */
3597 if (strict_prototype)
3598 $$ = void_list_node;
3604 { $$ = tree_cons (NULL_TREE, $$, void_list_node);
3605 TREE_PARMLIST ($$) = 1; }
3608 /* This nonterminal does not include the common sequence '(' type_id ')',
3609 as it is ambiguous and must be disambiguated elsewhere. */
3613 $$ = chainon ($$, void_list_node);
3614 TREE_PARMLIST ($$) = 1;
3616 | parms_comma ELLIPSIS
3618 TREE_PARMLIST ($$) = 1;
3620 /* C++ allows an ellipsis without a separating ',' */
3623 TREE_PARMLIST ($$) = 1;
3627 $$ = build_tree_list (NULL_TREE, $$);
3628 TREE_PARMLIST ($$) = 1;
3632 /* ARM $8.2.5 has this as a boxed-off comment. */
3634 warning ("use of `...' without a first argument is non-portable");
3639 TREE_PARMLIST ($$) = 1;
3641 | parms TYPENAME_ELLIPSIS
3643 TREE_PARMLIST ($$) = 1;
3645 | type_id TYPENAME_ELLIPSIS
3647 $$ = build_tree_list (NULL_TREE, $$);
3648 TREE_PARMLIST ($$) = 1;
3652 /* This helps us recover from really nasty
3653 parse errors, for example, a missing right
3655 yyerror ("possibly missing ')'");
3656 $$ = chainon ($$, void_list_node);
3657 TREE_PARMLIST ($$) = 1;
3663 /* This helps us recover from really nasty
3664 parse errors, for example, a missing right
3666 yyerror ("possibly missing ')'");
3667 $$ = tree_cons (NULL_TREE, $$, void_list_node);
3668 TREE_PARMLIST ($$) = 1;
3674 /* A nonempty list of parameter declarations or type names. */
3677 { $$ = build_tree_list (NULL_TREE, $$); }
3679 { $$ = build_tree_list ($3, $$); }
3680 | parms_comma full_parm
3681 { $$ = chainon ($$, $2); }
3682 | parms_comma bad_parm
3683 { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
3684 | parms_comma bad_parm '=' init
3685 { $$ = chainon ($$, build_tree_list ($4, $2)); }
3691 { $$ = build_tree_list (NULL_TREE, $$); }
3694 /* A single parameter declaration or parameter type name,
3695 as found in a parmlist. The first four cases make up for 10%
3696 of the time spent parsing C++. We cannot use them because
3697 of `int id[]' which won't get parsed properly. */
3700 typed_declspecs dont_see_typename '*' IDENTIFIER
3701 { $$ = build_tree_list ($$, build_parse_node (INDIRECT_REF, $4));
3703 | typed_declspecs dont_see_typename '&' IDENTIFIER
3704 { $$ = build_tree_list ($$, build_parse_node (ADDR_EXPR, $4));
3706 | TYPENAME IDENTIFIER
3707 { $$ = build_tree_list (get_decl_list ($$), $2); }
3708 | TYPESPEC IDENTIFIER
3709 { $$ = build_tree_list (get_decl_list ($$), $2); }
3711 /* Here we expand typed_declspecs inline to avoid mis-parsing of
3712 TYPESPEC IDENTIFIER. */
3713 typed_declspecs1 declarator
3714 { $$ = build_tree_list ($$, $2); }
3715 | typed_typespecs declarator
3716 { $$ = build_tree_list ($$, $2); }
3717 | typespec declarator
3718 { $$ = build_tree_list (get_decl_list ($$), $2); }
3719 | typed_declspecs1 absdcl
3720 { $$ = build_tree_list ($$, $2); }
3721 | typed_declspecs1 %prec EMPTY
3722 { $$ = build_tree_list ($$, NULL_TREE); }
3723 | declmods notype_declarator
3724 { $$ = build_tree_list ($$, $2); }
3729 { $$ = build_tree_list ($2, $$); }
3737 see_typename: %prec EMPTY
3738 { see_typename (); }
3742 dont_see_typename: %prec EMPTY
3743 { dont_see_typename (); }
3748 if ($<ttype>-1 == error_mark_node)
3753 pushclass ($<ttype>-1, 1);
3760 /* empty */ %prec EMPTY
3762 error ("type specifier omitted for parameter");
3763 $$ = build_tree_list (integer_type_node, NULL_TREE);
3767 error ("type specifier omitted for parameter");
3768 $$ = build_tree_list (integer_type_node, $$);
3772 exception_specification_opt:
3773 %prec EMPTY /* empty */
3775 | THROW '(' ansi_raise_identifiers ')' %prec EMPTY
3777 | THROW LEFT_RIGHT %prec EMPTY
3778 { $$ = build_decl_list (NULL_TREE, NULL_TREE); }
3781 ansi_raise_identifier:
3783 { $$ = build_decl_list (NULL_TREE, groktypename($$)); }
3786 ansi_raise_identifiers:
3787 ansi_raise_identifier
3788 | ansi_raise_identifiers ',' ansi_raise_identifier
3790 TREE_CHAIN ($3) = $$;
3795 conversion_declarator:
3796 /* empty */ %prec EMPTY
3798 | '*' type_quals conversion_declarator
3799 { $$ = make_pointer_declarator ($2, $3); }
3800 | '&' type_quals conversion_declarator
3801 { $$ = make_reference_declarator ($2, $3); }
3802 | ptr_to_mem type_quals conversion_declarator
3803 { tree arg = make_pointer_declarator ($2, $3);
3804 $$ = build_parse_node (SCOPE_REF, $1, arg);
3809 { got_scope = NULL_TREE; }
3814 { $$ = ansi_opname[MULT_EXPR]; }
3816 { $$ = ansi_opname[TRUNC_DIV_EXPR]; }
3818 { $$ = ansi_opname[TRUNC_MOD_EXPR]; }
3820 { $$ = ansi_opname[PLUS_EXPR]; }
3822 { $$ = ansi_opname[MINUS_EXPR]; }
3824 { $$ = ansi_opname[BIT_AND_EXPR]; }
3826 { $$ = ansi_opname[BIT_IOR_EXPR]; }
3828 { $$ = ansi_opname[BIT_XOR_EXPR]; }
3830 { $$ = ansi_opname[BIT_NOT_EXPR]; }
3832 { $$ = ansi_opname[COMPOUND_EXPR]; }
3833 | operator ARITHCOMPARE
3834 { $$ = ansi_opname[$2]; }
3836 { $$ = ansi_opname[LT_EXPR]; }
3838 { $$ = ansi_opname[GT_EXPR]; }
3839 | operator EQCOMPARE
3840 { $$ = ansi_opname[$2]; }
3842 { $$ = ansi_assopname[$2]; }
3844 { $$ = ansi_opname [MODIFY_EXPR]; }
3846 { $$ = ansi_opname[$2]; }
3848 { $$ = ansi_opname[$2]; }
3850 { $$ = ansi_opname[POSTINCREMENT_EXPR]; }
3851 | operator MINUSMINUS
3852 { $$ = ansi_opname[PREDECREMENT_EXPR]; }
3854 { $$ = ansi_opname[TRUTH_ANDIF_EXPR]; }
3856 { $$ = ansi_opname[TRUTH_ORIF_EXPR]; }
3858 { $$ = ansi_opname[TRUTH_NOT_EXPR]; }
3860 { $$ = ansi_opname[COND_EXPR]; }
3862 { $$ = ansi_opname[$2]; }
3863 | operator POINTSAT %prec EMPTY
3864 { $$ = ansi_opname[COMPONENT_REF]; }
3865 | operator POINTSAT_STAR %prec EMPTY
3866 { $$ = ansi_opname[MEMBER_REF]; }
3867 | operator LEFT_RIGHT
3868 { $$ = ansi_opname[CALL_EXPR]; }
3870 { $$ = ansi_opname[ARRAY_REF]; }
3871 | operator NEW %prec EMPTY
3872 { $$ = ansi_opname[NEW_EXPR]; }
3873 | operator DELETE %prec EMPTY
3874 { $$ = ansi_opname[DELETE_EXPR]; }
3875 | operator NEW '[' ']'
3876 { $$ = ansi_opname[VEC_NEW_EXPR]; }
3877 | operator DELETE '[' ']'
3878 { $$ = ansi_opname[VEC_DELETE_EXPR]; }
3879 /* Names here should be looked up in class scope ALSO. */
3880 | operator type_specifier_seq conversion_declarator
3881 { $$ = grokoptypename ($2, $3); }
3883 { $$ = ansi_opname[ERROR_MARK]; }
3890 debug_yytranslate (value)
3893 return yytname[YYTRANSLATE (value)];