* cp-tree.h (begin_switch_stmt): Adjust prototype.
[official-gcc.git] / gcc / cp / parse.y
blob1b1c8b557e29437bb9dfec25fd3f564abefdd7f9
1 /* YACC parser for C++ syntax.
2 Copyright (C) 1988, 89, 93-98, 1999 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)
10 any later version.
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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This grammar is based on the GNU CC grammar. */
25 /* Note: Bison automatically applies a default action of "$$ = $1" for
26 all derivations; this is applied before the explicit action, if one
27 is given. Keep this in mind when reading the actions. */
30 /* Cause the `yydebug' variable to be defined. */
31 #define YYDEBUG 1
33 #include "config.h"
35 #include "system.h"
37 #include "tree.h"
38 #include "input.h"
39 #include "flags.h"
40 #include "lex.h"
41 #include "cp-tree.h"
42 #include "output.h"
43 #include "except.h"
44 #include "toplev.h"
45 #include "ggc.h"
47 /* Since parsers are distinct for each language, put the language string
48 definition here. (fnf) */
49 const char * const language_string = "GNU C++";
51 extern struct obstack permanent_obstack;
53 extern int end_of_file;
55 /* Like YYERROR but do call yyerror. */
56 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
58 #define OP0(NODE) (TREE_OPERAND (NODE, 0))
59 #define OP1(NODE) (TREE_OPERAND (NODE, 1))
61 /* Contains the statement keyword (if/while/do) to include in an
62 error message if the user supplies an empty conditional expression. */
63 static const char *cond_stmt_keyword;
65 static tree empty_parms PROTO((void));
66 static int parse_decl PROTO((tree, tree, tree, int, tree *));
68 /* Nonzero if we have an `extern "C"' acting as an extern specifier. */
69 int have_extern_spec;
70 int used_extern_spec;
72 /* Cons up an empty parameter list. */
73 #ifdef __GNUC__
74 __inline
75 #endif
76 static tree
77 empty_parms ()
79 tree parms;
81 if (strict_prototype
82 || current_class_type != NULL)
83 parms = void_list_node;
84 else
85 parms = NULL_TREE;
86 return parms;
91 %start program
93 %union {
94 long itype;
95 tree ttype;
96 char *strtype;
97 enum tree_code code;
98 flagged_type_tree ftype;
99 struct pending_inline *pi;
102 /* All identifiers that are not reserved words
103 and are not declared typedefs in the current block */
104 %token IDENTIFIER
106 /* All identifiers that are declared typedefs in the current block.
107 In some contexts, they are treated just like IDENTIFIER,
108 but they can also serve as typespecs in declarations. */
109 %token TYPENAME
110 %token SELFNAME
112 /* A template function. */
113 %token PFUNCNAME
115 /* Reserved words that specify storage class.
116 yylval contains an IDENTIFIER_NODE which indicates which one. */
117 %token SCSPEC
119 /* Reserved words that specify type.
120 yylval contains an IDENTIFIER_NODE which indicates which one. */
121 %token TYPESPEC
123 /* Reserved words that qualify type: "const" or "volatile".
124 yylval contains an IDENTIFIER_NODE which indicates which one. */
125 %token CV_QUALIFIER
127 /* Character or numeric constants.
128 yylval is the node for the constant. */
129 %token CONSTANT
131 /* String constants in raw form.
132 yylval is a STRING_CST node. */
133 %token STRING
135 /* "...", used for functions with variable arglists. */
136 %token ELLIPSIS
138 /* the reserved words */
139 /* SCO include files test "ASM", so use something else. */
140 %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
141 %token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF
142 %token SIGOF
143 %token ATTRIBUTE EXTENSION LABEL
144 %token REALPART IMAGPART VA_ARG
146 /* the reserved words... C++ extensions */
147 %token <ttype> AGGR
148 %token <ttype> VISSPEC
149 %token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE
150 %token NAMESPACE TYPENAME_KEYWORD USING
151 %token LEFT_RIGHT TEMPLATE
152 %token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
153 %token <itype> SCOPE
155 /* Define the operator tokens and their precedences.
156 The value is an integer because, if used, it is the tree code
157 to use in the expression made from the operator. */
159 %left EMPTY /* used to resolve s/r with epsilon */
161 %left error
163 /* Add precedence rules to solve dangling else s/r conflict */
164 %nonassoc IF
165 %nonassoc ELSE
167 %left IDENTIFIER PFUNCNAME TYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD
169 %left '{' ',' ';'
171 %nonassoc THROW
172 %right <code> ':'
173 %right <code> ASSIGN '='
174 %right <code> '?'
175 %left <code> OROR
176 %left <code> ANDAND
177 %left <code> '|'
178 %left <code> '^'
179 %left <code> '&'
180 %left <code> MIN_MAX
181 %left <code> EQCOMPARE
182 %left <code> ARITHCOMPARE '<' '>'
183 %left <code> LSHIFT RSHIFT
184 %left <code> '+' '-'
185 %left <code> '*' '/' '%'
186 %left <code> POINTSAT_STAR DOT_STAR
187 %right <code> UNARY PLUSPLUS MINUSMINUS '~'
188 %left HYPERUNARY
189 %left <ttype> LEFT_RIGHT
190 %left <code> POINTSAT '.' '(' '['
192 %right SCOPE /* C++ extension */
193 %nonassoc NEW DELETE TRY CATCH
195 %type <code> unop
197 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist
198 %type <ttype> PFUNCNAME maybe_identifier
199 %type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
200 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
201 %type <ttype> reserved_declspecs boolean.literal
202 %type <ttype> reserved_typespecquals
203 %type <ttype> declmods
204 %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
205 %type <itype> initdecls notype_initdecls initdcl /* C++ modification */
206 %type <ttype> init initlist maybeasm maybe_init defarg defarg1
207 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
208 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
209 %type <ttype> any_word
211 %type <ttype> compstmt implicitly_scoped_stmt
213 %type <ttype> declarator notype_declarator after_type_declarator
214 %type <ttype> notype_declarator_intern absdcl_intern
215 %type <ttype> after_type_declarator_intern
216 %type <ttype> direct_notype_declarator direct_after_type_declarator
217 %type <itype> components notype_components
218 %type <ttype> component_decl component_decl_1
219 %type <ttype> component_declarator component_declarator0
220 %type <ttype> notype_component_declarator notype_component_declarator0
221 %type <ttype> after_type_component_declarator after_type_component_declarator0
222 %type <ttype> enumlist_opt enumlist enumerator
223 %type <ttype> absdcl cv_qualifiers
224 %type <ttype> direct_abstract_declarator conversion_declarator
225 %type <ttype> new_declarator direct_new_declarator
226 %type <ttype> xexpr parmlist parms bad_parm
227 %type <ttype> identifiers_or_typenames
228 %type <ttype> fcast_or_absdcl regcast_or_absdcl
229 %type <ttype> expr_or_declarator expr_or_declarator_intern
230 %type <ttype> complex_notype_declarator
231 %type <ttype> notype_unqualified_id unqualified_id qualified_id
232 %type <ttype> template_id do_id object_template_id notype_template_declarator
233 %type <ttype> overqualified_id notype_qualified_id any_id
234 %type <ttype> complex_direct_notype_declarator functional_cast
235 %type <ttype> complex_parmlist parms_comma
236 %type <ttype> namespace_qualifier namespace_using_decl
238 %type <ftype> type_id new_type_id typed_typespecs typespec typed_declspecs
239 %type <ftype> typed_declspecs1 type_specifier_seq nonempty_cv_qualifiers
240 %type <ftype> structsp typespecqual_reserved parm named_parm full_parm
242 %type <itype> extension
244 /* C++ extensions */
245 %token <ttype> PTYPENAME
246 %token <ttype> EXTERN_LANG_STRING ALL
247 %token <ttype> PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER
248 %token <pi> PRE_PARSED_FUNCTION_DECL
249 %type <ttype> component_constructor_declarator
250 %type <ttype> fn.def2 return_id constructor_declarator
251 %type <pi> fn.defpen
252 %type <itype> ctor_initializer_opt function_try_block
253 %type <ttype> named_class_head_sans_basetype
254 %type <ftype> class_head named_class_head
255 %type <ftype> named_complex_class_head_sans_basetype
256 %type <ttype> unnamed_class_head
257 %type <ttype> base_class_list
258 %type <ttype> base_class_access_list
259 %type <ttype> base_class maybe_base_class_list base_class.1
260 %type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers
261 %type <ttype> operator_name
262 %type <ttype> object aggr
263 %type <itype> new delete .begin_new_placement
264 /* %type <ttype> primary_no_id */
265 %type <ttype> nonmomentary_expr maybe_parmlist
266 %type <itype> initdcl0 notype_initdcl0 member_init_list initdcl0_innards
267 %type <ttype> template_header template_parm_list template_parm
268 %type <ttype> template_type_parm template_template_parm
269 %type <code> template_close_bracket
270 %type <ttype> apparent_template_type
271 %type <ttype> template_type template_arg_list template_arg_list_opt
272 %type <ttype> template_arg
273 %type <ttype> condition xcond paren_cond_or_null
274 %type <ttype> type_name nested_name_specifier nested_type ptr_to_mem
275 %type <ttype> complete_type_name notype_identifier nonnested_type
276 %type <ttype> complex_type_name nested_name_specifier_1
277 %type <ttype> new_initializer new_placement
278 %type <ttype> using_decl
279 %type <ttype> typename_sub typename_sub0 typename_sub1 typename_sub2
280 %type <ttype> explicit_template_type
281 /* in order to recognize aggr tags as defining and thus shadowing. */
282 %token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
283 %type <ttype> named_class_head_sans_basetype_defn
284 %type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN
286 %type <ttype> self_template_type .finish_template_type
288 %token NSNAME
289 %type <ttype> NSNAME
291 /* Used in lex.c for parsing pragmas. */
292 %token END_OF_LINE
294 /* lex.c and pt.c depend on this being the last token. Define
295 any new tokens before this one! */
296 %token END_OF_SAVED_INPUT
299 /* List of types and structure classes of the current declaration. */
300 static tree current_declspecs;
302 /* List of prefix attributes in effect.
303 Prefix attributes are parsed by the reserved_declspecs and declmods
304 rules. They create a list that contains *both* declspecs and attrs. */
305 /* ??? It is not clear yet that all cases where an attribute can now appear in
306 a declspec list have been updated. */
307 static tree prefix_attributes;
309 /* When defining an aggregate, this is the kind of the most recent one
310 being defined. (For example, this might be class_type_node.) */
311 static tree current_aggr;
313 /* When defining an enumeration, this is the type of the enumeration. */
314 static tree current_enum_type;
316 /* Tell yyparse how to print a token's value, if yydebug is set. */
318 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
319 extern void yyprint PROTO((FILE *, int, YYSTYPE));
320 extern tree combine_strings PROTO((tree));
322 static int
323 parse_decl (declarator, specs_attrs, attributes, initialized, decl)
324 tree declarator;
325 tree specs_attrs;
326 tree attributes;
327 int initialized;
328 tree* decl;
330 int sm;
332 split_specs_attrs (specs_attrs, &current_declspecs, &prefix_attributes);
333 if (current_declspecs
334 && TREE_CODE (current_declspecs) != TREE_LIST)
335 current_declspecs = build_decl_list (NULL_TREE, current_declspecs);
336 if (have_extern_spec && !used_extern_spec)
338 current_declspecs = decl_tree_cons (NULL_TREE,
339 get_identifier ("extern"),
340 current_declspecs);
341 used_extern_spec = 1;
343 sm = suspend_momentary ();
344 *decl = start_decl (declarator, current_declspecs, initialized,
345 attributes, prefix_attributes);
346 return sm;
349 void
350 cp_parse_init ()
352 ggc_add_tree_root (&current_declspecs, 1);
353 ggc_add_tree_root (&prefix_attributes, 1);
354 ggc_add_tree_root (&current_aggr, 1);
355 ggc_add_tree_root (&current_enum_type, 1);
360 program:
361 /* empty */
362 | extdefs
363 { finish_translation_unit (); }
366 /* the reason for the strange actions in this rule
367 is so that notype_initdecls when reached via datadef
368 can find a valid list of type and sc specs in $0. */
370 extdefs:
371 { $<ttype>$ = NULL_TREE; }
372 lang_extdef
373 { $<ttype>$ = NULL_TREE; }
374 | extdefs lang_extdef
375 { $<ttype>$ = NULL_TREE; }
378 extdefs_opt:
379 extdefs
380 | /* empty */
383 .hush_warning:
384 { have_extern_spec = 1;
385 used_extern_spec = 0;
386 $<ttype>$ = NULL_TREE; }
388 .warning_ok:
389 { have_extern_spec = 0; }
392 extension:
393 EXTENSION
394 { $$ = pedantic;
395 pedantic = 0; }
398 asm_keyword:
399 ASM_KEYWORD
402 lang_extdef:
403 { if (pending_lang_change) do_pending_lang_change(); }
404 extdef
405 { if (! toplevel_bindings_p ())
406 pop_everything (); }
409 extdef:
410 fndef eat_saved_input
411 { if (pending_inlines) do_pending_inlines (); }
412 | datadef
413 { if (pending_inlines) do_pending_inlines (); }
414 | template_def
415 { if (pending_inlines) do_pending_inlines (); }
416 | asm_keyword '(' string ')' ';'
417 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
418 assemble_asm ($3); }
419 | extern_lang_string '{' extdefs_opt '}'
420 { pop_lang_context (); }
421 | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
422 { if (pending_inlines) do_pending_inlines ();
423 pop_lang_context (); }
424 | extern_lang_string .hush_warning datadef .warning_ok
425 { if (pending_inlines) do_pending_inlines ();
426 pop_lang_context (); }
427 | NAMESPACE identifier '{'
428 { push_namespace ($2); }
429 extdefs_opt '}'
430 { pop_namespace (); }
431 | NAMESPACE '{'
432 { push_namespace (NULL_TREE); }
433 extdefs_opt '}'
434 { pop_namespace (); }
435 | namespace_alias
436 | using_decl ';'
437 { do_toplevel_using_decl ($1); }
438 | using_directive
439 | extension extdef
440 { pedantic = $1; }
443 namespace_alias:
444 NAMESPACE identifier '='
445 { begin_only_namespace_names (); }
446 any_id ';'
448 end_only_namespace_names ();
449 if (lastiddecl)
450 $5 = lastiddecl;
451 do_namespace_alias ($2, $5);
455 using_decl:
456 USING qualified_id
457 { $$ = $2; }
458 | USING global_scope qualified_id
459 { $$ = $3; }
460 | USING global_scope unqualified_id
461 { $$ = $3; }
464 namespace_using_decl:
465 USING namespace_qualifier identifier
466 { $$ = build_parse_node (SCOPE_REF, $2, $3); }
467 | USING global_scope identifier
468 { $$ = build_parse_node (SCOPE_REF, global_namespace, $3); }
469 | USING global_scope namespace_qualifier identifier
470 { $$ = build_parse_node (SCOPE_REF, $3, $4); }
473 using_directive:
474 USING NAMESPACE
475 { begin_only_namespace_names (); }
476 any_id ';'
478 end_only_namespace_names ();
479 /* If no declaration was found, the using-directive is
480 invalid. Since that was not reported, we need the
481 identifier for the error message. */
482 if (TREE_CODE ($4) == IDENTIFIER_NODE && lastiddecl)
483 $4 = lastiddecl;
484 do_using_directive ($4);
488 namespace_qualifier:
489 NSNAME SCOPE
491 if (TREE_CODE ($$) == IDENTIFIER_NODE)
492 $$ = lastiddecl;
493 got_scope = $$;
495 | namespace_qualifier NSNAME SCOPE
497 $$ = $2;
498 if (TREE_CODE ($$) == IDENTIFIER_NODE)
499 $$ = lastiddecl;
500 got_scope = $$;
503 any_id:
504 unqualified_id
505 | qualified_id
506 | global_scope qualified_id
507 { $$ = $2; }
508 | global_scope unqualified_id
509 { $$ = $2; }
512 extern_lang_string:
513 EXTERN_LANG_STRING
514 { push_lang_context ($1); }
515 | extern_lang_string EXTERN_LANG_STRING
516 { if (current_lang_name != $2)
517 cp_error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name);
518 pop_lang_context (); push_lang_context ($2); }
521 template_header:
522 TEMPLATE '<'
523 { begin_template_parm_list (); }
524 template_parm_list '>'
525 { $$ = end_template_parm_list ($4); }
526 | TEMPLATE '<' '>'
527 { begin_specialization();
528 $$ = NULL_TREE; }
531 template_parm_list:
532 template_parm
533 { $$ = process_template_parm (NULL_TREE, $1); }
534 | template_parm_list ',' template_parm
535 { $$ = process_template_parm ($1, $3); }
538 maybe_identifier:
539 identifier
540 { $$ = $1; }
541 | /* empty */
542 { $$ = NULL_TREE; }
544 template_type_parm:
545 aggr maybe_identifier
546 { $$ = finish_template_type_parm ($1, $2); }
547 | TYPENAME_KEYWORD maybe_identifier
548 { $$ = finish_template_type_parm (class_type_node, $2); }
551 template_template_parm:
552 template_header aggr maybe_identifier
553 { $$ = finish_template_template_parm ($2, $3); }
556 template_parm:
557 /* The following rules introduce a new reduce/reduce
558 conflict on the ',' and '>' input tokens: they are valid
559 prefixes for a `structsp', which means they could match a
560 nameless parameter. See 14.6, paragraph 3.
561 By putting them before the `parm' rule, we get
562 their match before considering them nameless parameter
563 declarations. */
564 template_type_parm
565 { $$ = build_tree_list (NULL_TREE, $1); }
566 | template_type_parm '=' type_id
567 { $$ = build_tree_list (groktypename ($3.t), $1); }
568 | parm
569 { $$ = build_tree_list (NULL_TREE, $1.t); }
570 | parm '=' expr_no_commas %prec ARITHCOMPARE
571 { $$ = build_tree_list ($3, $1.t); }
572 | template_template_parm
573 { $$ = build_tree_list (NULL_TREE, $1); }
574 | template_template_parm '=' template_arg
576 if (TREE_CODE ($3) != TEMPLATE_DECL
577 && TREE_CODE ($3) != TEMPLATE_TEMPLATE_PARM
578 && TREE_CODE ($3) != TYPE_DECL)
580 error ("invalid default template argument");
581 $3 = error_mark_node;
583 $$ = build_tree_list ($3, $1);
587 template_def:
588 template_header template_extdef
589 { finish_template_decl ($1); }
590 | template_header error %prec EMPTY
591 { finish_template_decl ($1); }
594 template_extdef:
595 fndef eat_saved_input
596 { if (pending_inlines) do_pending_inlines (); }
597 | template_datadef
598 { if (pending_inlines) do_pending_inlines (); }
599 | template_def
600 { if (pending_inlines) do_pending_inlines (); }
601 | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
602 { if (pending_inlines) do_pending_inlines ();
603 pop_lang_context (); }
604 | extern_lang_string .hush_warning template_datadef .warning_ok
605 { if (pending_inlines) do_pending_inlines ();
606 pop_lang_context (); }
607 | extension template_extdef
608 { pedantic = $1; }
611 template_datadef:
612 nomods_initdecls ';'
613 | declmods notype_initdecls ';'
615 | typed_declspecs initdecls ';'
616 { note_list_got_semicolon ($1.t); }
617 | structsp ';'
618 { maybe_process_partial_specialization ($1.t);
619 note_got_semicolon ($1.t); }
622 datadef:
623 nomods_initdecls ';'
624 | declmods notype_initdecls ';'
626 | typed_declspecs initdecls ';'
627 { note_list_got_semicolon ($1.t); }
628 | declmods ';'
629 { pedwarn ("empty declaration"); }
630 | explicit_instantiation ';'
631 | typed_declspecs ';'
633 tree t, attrs;
634 split_specs_attrs ($1.t, &t, &attrs);
635 shadow_tag (t);
636 note_list_got_semicolon ($1.t);
638 | error ';'
639 | error '}'
640 | ';'
643 ctor_initializer_opt:
644 nodecls
645 { $$ = 0; }
646 | base_init
647 { $$ = 1; }
650 maybe_return_init:
651 /* empty */
652 | return_init
653 | return_init ';'
656 eat_saved_input:
657 /* empty */
658 | END_OF_SAVED_INPUT
661 fndef:
662 fn.def1 maybe_return_init ctor_initializer_opt compstmt_or_error
663 { finish_function (lineno, (int)$3); }
664 | fn.def1 maybe_return_init function_try_block
665 { finish_function (lineno, (int)$3); }
666 | fn.def1 maybe_return_init error
670 constructor_declarator:
671 nested_name_specifier SELFNAME '('
672 { $$ = begin_constructor_declarator ($1, $2); }
673 parmlist ')' cv_qualifiers exception_specification_opt
674 { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
675 | nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
676 { $$ = begin_constructor_declarator ($1, $2);
677 $$ = make_call_declarator ($$, empty_parms (), $4, $5);
679 | global_scope nested_name_specifier SELFNAME '('
680 { $$ = begin_constructor_declarator ($2, $3); }
681 parmlist ')' cv_qualifiers exception_specification_opt
682 { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
683 | global_scope nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
684 { $$ = begin_constructor_declarator ($2, $3);
685 $$ = make_call_declarator ($$, empty_parms (), $5, $6);
687 | nested_name_specifier self_template_type '('
688 { $$ = begin_constructor_declarator ($1, $2); }
689 parmlist ')' cv_qualifiers exception_specification_opt
690 { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
691 | nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
692 { $$ = begin_constructor_declarator ($1, $2);
693 $$ = make_call_declarator ($$, empty_parms (), $4, $5);
695 | global_scope nested_name_specifier self_template_type '('
696 { $$ = begin_constructor_declarator ($2, $3); }
697 parmlist ')' cv_qualifiers exception_specification_opt
698 { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
699 | global_scope nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
700 { $$ = begin_constructor_declarator ($2, $3);
701 $$ = make_call_declarator ($$, empty_parms (), $5, $6);
705 fn.def1:
706 typed_declspecs declarator
707 { if (!begin_function_definition ($1.t, $2))
708 YYERROR1; }
709 | declmods notype_declarator
710 { if (!begin_function_definition ($1, $2))
711 YYERROR1; }
712 | notype_declarator
713 { if (!begin_function_definition (NULL_TREE, $1))
714 YYERROR1; }
715 | declmods constructor_declarator
716 { if (!begin_function_definition ($1, $2))
717 YYERROR1; }
718 | constructor_declarator
719 { if (!begin_function_definition (NULL_TREE, $1))
720 YYERROR1; }
723 component_constructor_declarator:
724 SELFNAME '(' parmlist ')' cv_qualifiers exception_specification_opt
725 { $$ = make_call_declarator ($1, $3, $5, $6); }
726 | SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
727 { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
728 | self_template_type '(' parmlist ')' cv_qualifiers exception_specification_opt
729 { $$ = make_call_declarator ($1, $3, $5, $6); }
730 | self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
731 { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
734 /* more C++ complexity. See component_decl for a comment on the
735 reduce/reduce conflict introduced by these rules. */
736 fn.def2:
737 declmods component_constructor_declarator
738 { tree specs, attrs;
739 split_specs_attrs ($1, &specs, &attrs);
740 attrs = build_tree_list (attrs, NULL_TREE);
741 $$ = start_method (specs, $2, attrs);
742 rest_of_mdef:
743 if (! $$)
744 YYERROR1;
745 if (yychar == YYEMPTY)
746 yychar = YYLEX;
747 reinit_parse_for_method (yychar, $$); }
748 | component_constructor_declarator
749 { $$ = start_method (NULL_TREE, $1, NULL_TREE);
750 goto rest_of_mdef; }
751 | typed_declspecs declarator
752 { tree specs, attrs;
753 split_specs_attrs ($1.t, &specs, &attrs);
754 attrs = build_tree_list (attrs, NULL_TREE);
755 $$ = start_method (specs, $2, attrs); goto rest_of_mdef; }
756 | declmods notype_declarator
757 { tree specs, attrs;
758 split_specs_attrs ($1, &specs, &attrs);
759 attrs = build_tree_list (attrs, NULL_TREE);
760 $$ = start_method (specs, $2, attrs); goto rest_of_mdef; }
761 | notype_declarator
762 { $$ = start_method (NULL_TREE, $$, NULL_TREE);
763 goto rest_of_mdef; }
764 | declmods constructor_declarator
765 { tree specs, attrs;
766 split_specs_attrs ($1, &specs, &attrs);
767 attrs = build_tree_list (attrs, NULL_TREE);
768 $$ = start_method (specs, $2, attrs); goto rest_of_mdef; }
769 | constructor_declarator
770 { $$ = start_method (NULL_TREE, $$, NULL_TREE);
771 goto rest_of_mdef; }
774 return_id:
775 RETURN_KEYWORD IDENTIFIER
777 if (! current_function_parms_stored)
778 store_parm_decls ();
779 $$ = $2;
783 return_init:
784 return_id maybe_init
785 { finish_named_return_value ($<ttype>$, $2); }
786 | return_id '(' nonnull_exprlist ')'
787 { finish_named_return_value ($<ttype>$, $3); }
788 | return_id LEFT_RIGHT
789 { finish_named_return_value ($<ttype>$, NULL_TREE); }
792 base_init:
793 ':' .set_base_init member_init_list
795 if ($3 == 0)
796 error ("no base initializers given following ':'");
797 setup_vtbl_ptr ();
801 .set_base_init:
802 /* empty */
804 if (! current_function_parms_stored)
805 store_parm_decls ();
807 if (DECL_CONSTRUCTOR_P (current_function_decl))
809 /* Make a contour for the initializer list. */
810 pushlevel (0);
811 clear_last_expr ();
812 expand_start_bindings (0);
814 else if (current_class_type == NULL_TREE)
815 error ("base initializers not allowed for non-member functions");
816 else if (! DECL_CONSTRUCTOR_P (current_function_decl))
817 error ("only constructors take base initializers");
821 member_init_list:
822 /* empty */
823 { $$ = 0; }
824 | member_init
825 { $$ = 1; }
826 | member_init_list ',' member_init
827 | member_init_list error
830 member_init:
831 '(' nonnull_exprlist ')'
833 if (current_class_name)
834 pedwarn ("anachronistic old style base class initializer");
835 expand_member_init (current_class_ref, NULL_TREE, $2);
837 | LEFT_RIGHT
839 if (current_class_name)
840 pedwarn ("anachronistic old style base class initializer");
841 expand_member_init (current_class_ref, NULL_TREE, void_type_node);
843 | notype_identifier '(' nonnull_exprlist ')'
844 { expand_member_init (current_class_ref, $1, $3); }
845 | notype_identifier LEFT_RIGHT
846 { expand_member_init (current_class_ref, $1, void_type_node); }
847 | nonnested_type '(' nonnull_exprlist ')'
848 { expand_member_init (current_class_ref, $1, $3); }
849 | nonnested_type LEFT_RIGHT
850 { expand_member_init (current_class_ref, $1, void_type_node); }
851 | typename_sub '(' nonnull_exprlist ')'
852 { expand_member_init (current_class_ref, TYPE_MAIN_DECL ($1),
853 $3); }
854 | typename_sub LEFT_RIGHT
855 { expand_member_init (current_class_ref, TYPE_MAIN_DECL ($1),
856 void_type_node); }
859 identifier:
860 IDENTIFIER
861 | TYPENAME
862 | SELFNAME
863 | PTYPENAME
864 | NSNAME
867 notype_identifier:
868 IDENTIFIER
869 | PTYPENAME
870 | NSNAME %prec EMPTY
873 identifier_defn:
874 IDENTIFIER_DEFN
875 | TYPENAME_DEFN
876 | PTYPENAME_DEFN
879 explicit_instantiation:
880 TEMPLATE begin_explicit_instantiation typespec ';'
881 { do_type_instantiation ($3.t, NULL_TREE);
882 yyungetc (';', 1); }
883 end_explicit_instantiation
884 | TEMPLATE begin_explicit_instantiation typed_declspecs declarator
885 { tree specs = strip_attrs ($3.t);
886 do_decl_instantiation (specs, $4, NULL_TREE); }
887 end_explicit_instantiation
888 | TEMPLATE begin_explicit_instantiation notype_declarator
889 { do_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
890 end_explicit_instantiation
891 | TEMPLATE begin_explicit_instantiation constructor_declarator
892 { do_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
893 end_explicit_instantiation
894 | SCSPEC TEMPLATE begin_explicit_instantiation typespec ';'
895 { do_type_instantiation ($4.t, $1);
896 yyungetc (';', 1); }
897 end_explicit_instantiation
898 | SCSPEC TEMPLATE begin_explicit_instantiation typed_declspecs
899 declarator
900 { tree specs = strip_attrs ($4.t);
901 do_decl_instantiation (specs, $5, $1); }
902 end_explicit_instantiation
903 | SCSPEC TEMPLATE begin_explicit_instantiation notype_declarator
904 { do_decl_instantiation (NULL_TREE, $4, $1); }
905 end_explicit_instantiation
906 | SCSPEC TEMPLATE begin_explicit_instantiation constructor_declarator
907 { do_decl_instantiation (NULL_TREE, $4, $1); }
908 end_explicit_instantiation
911 begin_explicit_instantiation:
912 { begin_explicit_instantiation(); }
914 end_explicit_instantiation:
915 { end_explicit_instantiation(); }
917 /* The TYPENAME expansions are to deal with use of a template class name as
918 a template within the class itself, where the template decl is hidden by
919 a type decl. Got all that? */
921 template_type:
922 PTYPENAME '<' template_arg_list_opt template_close_bracket
923 .finish_template_type
924 { $$ = $5; }
925 | TYPENAME '<' template_arg_list_opt template_close_bracket
926 .finish_template_type
927 { $$ = $5; }
928 | self_template_type
931 apparent_template_type:
932 template_type
933 | identifier '<' template_arg_list_opt '>'
934 .finish_template_type
935 { $$ = $5; }
937 self_template_type:
938 SELFNAME '<' template_arg_list_opt template_close_bracket
939 .finish_template_type
940 { $$ = $5; }
943 .finish_template_type:
945 if (yychar == YYEMPTY)
946 yychar = YYLEX;
948 $$ = finish_template_type ($<ttype>-3, $<ttype>-1,
949 yychar == SCOPE);
952 template_close_bracket:
954 | RSHIFT
956 /* Handle `Class<Class<Type>>' without space in the `>>' */
957 pedwarn ("`>>' should be `> >' in template class name");
958 yyungetc ('>', 1);
962 template_arg_list_opt:
963 /* empty */
964 { $$ = NULL_TREE; }
965 | template_arg_list
968 template_arg_list:
969 template_arg
970 { $$ = build_tree_list (NULL_TREE, $$); }
971 | template_arg_list ',' template_arg
972 { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); }
975 template_arg:
976 type_id
977 { $$ = groktypename ($1.t); }
978 | PTYPENAME
979 { $$ = lastiddecl; }
980 | expr_no_commas %prec ARITHCOMPARE
983 unop:
985 { $$ = NEGATE_EXPR; }
986 | '+'
987 { $$ = CONVERT_EXPR; }
988 | PLUSPLUS
989 { $$ = PREINCREMENT_EXPR; }
990 | MINUSMINUS
991 { $$ = PREDECREMENT_EXPR; }
992 | '!'
993 { $$ = TRUTH_NOT_EXPR; }
996 expr:
997 nontrivial_exprlist
998 { $$ = build_x_compound_expr ($$); }
999 | expr_no_commas
1002 paren_expr_or_null:
1003 LEFT_RIGHT
1004 { error ("ANSI C++ forbids an empty condition for `%s'",
1005 cond_stmt_keyword);
1006 $$ = integer_zero_node; }
1007 | '(' expr ')'
1008 { $$ = $2; }
1011 paren_cond_or_null:
1012 LEFT_RIGHT
1013 { error ("ANSI C++ forbids an empty condition for `%s'",
1014 cond_stmt_keyword);
1015 $$ = integer_zero_node; }
1016 | '(' condition ')'
1017 { $$ = $2; }
1020 xcond:
1021 /* empty */
1022 { $$ = NULL_TREE; }
1023 | condition
1024 | error
1025 { $$ = NULL_TREE; }
1028 condition:
1029 type_specifier_seq declarator maybeasm maybe_attribute '='
1031 tree d;
1032 for (d = getdecls (); d; d = TREE_CHAIN (d))
1033 if (TREE_CODE (d) == TYPE_DECL) {
1034 tree s = TREE_TYPE (d);
1035 if (TREE_CODE (s) == RECORD_TYPE)
1036 cp_error ("definition of class `%T' in condition", s);
1037 else if (TREE_CODE (s) == ENUMERAL_TYPE)
1038 cp_error ("definition of enum `%T' in condition", s);
1041 current_declspecs = $1.t;
1042 $<itype>5 = suspend_momentary ();
1043 $<ttype>$ = start_decl ($<ttype>2, current_declspecs, 1,
1044 $4, /*prefix_attributes*/ NULL_TREE);
1046 init
1048 cp_finish_decl ($<ttype>6, $7, $4, 1, LOOKUP_ONLYCONVERTING);
1049 resume_momentary ($<itype>5);
1050 $$ = convert_from_reference ($<ttype>6);
1051 if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE)
1052 cp_error ("definition of array `%#D' in condition", $$);
1054 | expr
1057 compstmtend:
1059 | maybe_label_decls stmts '}'
1060 | maybe_label_decls stmts error '}'
1061 | maybe_label_decls error '}'
1064 already_scoped_stmt:
1066 { $<ttype>$ = begin_compound_stmt (1); }
1067 compstmtend
1068 { finish_compound_stmt (1, $<ttype>2); }
1069 | simple_stmt
1073 nontrivial_exprlist:
1074 expr_no_commas ',' expr_no_commas
1075 { $$ = tree_cons (NULL_TREE, $$,
1076 build_expr_list (NULL_TREE, $3)); }
1077 | expr_no_commas ',' error
1078 { $$ = tree_cons (NULL_TREE, $$,
1079 build_expr_list (NULL_TREE, error_mark_node)); }
1080 | nontrivial_exprlist ',' expr_no_commas
1081 { chainon ($$, build_expr_list (NULL_TREE, $3)); }
1082 | nontrivial_exprlist ',' error
1083 { chainon ($$, build_expr_list (NULL_TREE, error_mark_node)); }
1086 nonnull_exprlist:
1087 expr_no_commas
1088 { $$ = build_expr_list (NULL_TREE, $$); }
1089 | nontrivial_exprlist
1092 unary_expr:
1093 primary %prec UNARY
1094 { $$ = $1; }
1095 /* __extension__ turns off -pedantic for following primary. */
1096 | extension cast_expr %prec UNARY
1097 { $$ = $2;
1098 pedantic = $1; }
1099 | '*' cast_expr %prec UNARY
1100 { $$ = build_x_indirect_ref ($2, "unary *"); }
1101 | '&' cast_expr %prec UNARY
1102 { $$ = build_x_unary_op (ADDR_EXPR, $2); }
1103 | '~' cast_expr
1104 { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
1105 | unop cast_expr %prec UNARY
1106 { $$ = finish_unary_op_expr ($1, $2); }
1107 /* Refer to the address of a label as a pointer. */
1108 | ANDAND identifier
1109 { if (pedantic)
1110 pedwarn ("ANSI C++ forbids `&&'");
1111 $$ = finish_label_address_expr ($2); }
1112 | SIZEOF unary_expr %prec UNARY
1113 { $$ = expr_sizeof ($2); }
1114 | SIZEOF '(' type_id ')' %prec HYPERUNARY
1115 { $$ = c_sizeof (groktypename ($3.t));
1116 check_for_new_type ("sizeof", $3); }
1117 | ALIGNOF unary_expr %prec UNARY
1118 { $$ = grok_alignof ($2); }
1119 | ALIGNOF '(' type_id ')' %prec HYPERUNARY
1120 { $$ = c_alignof (groktypename ($3.t));
1121 check_for_new_type ("alignof", $3); }
1123 /* The %prec EMPTY's here are required by the = init initializer
1124 syntax extension; see below. */
1125 | new new_type_id %prec EMPTY
1126 { $$ = build_new (NULL_TREE, $2.t, NULL_TREE, $1);
1127 check_for_new_type ("new", $2); }
1128 | new new_type_id new_initializer
1129 { $$ = build_new (NULL_TREE, $2.t, $3, $1);
1130 check_for_new_type ("new", $2); }
1131 | new new_placement new_type_id %prec EMPTY
1132 { $$ = build_new ($2, $3.t, NULL_TREE, $1);
1133 check_for_new_type ("new", $3); }
1134 | new new_placement new_type_id new_initializer
1135 { $$ = build_new ($2, $3.t, $4, $1);
1136 check_for_new_type ("new", $3); }
1137 /* The .begin_new_placement in the following rules is
1138 necessary to avoid shift/reduce conflicts that lead to
1139 mis-parsing some expressions. Of course, these constructs
1140 are not really new-placement and it is bogus to call
1141 begin_new_placement. But, the parser cannot always tell at this
1142 point whether the next thing is an expression or a type-id,
1143 so there is nothing we can do. Fortunately,
1144 begin_new_placement does nothing harmful. When we rewrite
1145 the parser, this lossage should be removed, of course. */
1146 | new '(' .begin_new_placement type_id .finish_new_placement
1147 %prec EMPTY
1148 { $$ = build_new (NULL_TREE, groktypename($4.t),
1149 NULL_TREE, $1);
1150 check_for_new_type ("new", $4); }
1151 | new '(' .begin_new_placement type_id .finish_new_placement
1152 new_initializer
1153 { $$ = build_new (NULL_TREE, groktypename($4.t), $6, $1);
1154 check_for_new_type ("new", $4); }
1155 | new new_placement '(' .begin_new_placement type_id
1156 .finish_new_placement %prec EMPTY
1157 { $$ = build_new ($2, groktypename($5.t), NULL_TREE, $1);
1158 check_for_new_type ("new", $5); }
1159 | new new_placement '(' .begin_new_placement type_id
1160 .finish_new_placement new_initializer
1161 { $$ = build_new ($2, groktypename($5.t), $7, $1);
1162 check_for_new_type ("new", $5); }
1164 | delete cast_expr %prec UNARY
1165 { $$ = delete_sanity ($2, NULL_TREE, 0, $1); }
1166 | delete '[' ']' cast_expr %prec UNARY
1167 { $$ = delete_sanity ($4, NULL_TREE, 1, $1);
1168 if (yychar == YYEMPTY)
1169 yychar = YYLEX; }
1170 | delete '[' expr ']' cast_expr %prec UNARY
1171 { $$ = delete_sanity ($5, $3, 2, $1);
1172 if (yychar == YYEMPTY)
1173 yychar = YYLEX; }
1174 | REALPART cast_expr %prec UNARY
1175 { $$ = build_x_unary_op (REALPART_EXPR, $2); }
1176 | IMAGPART cast_expr %prec UNARY
1177 { $$ = build_x_unary_op (IMAGPART_EXPR, $2); }
1178 | VA_ARG '(' expr_no_commas ',' type_id ')'
1179 { $$ = build_va_arg ($3, groktypename ($5.t));
1180 check_for_new_type ("__builtin_va_arg", $5); }
1183 /* Note this rule is not suitable for use in new_placement
1184 since it uses NULL_TREE as the argument to
1185 finish_new_placement. This rule serves only to avoid
1186 reduce/reduce conflicts in unary_expr. See the comments
1187 there on the use of begin/finish_new_placement. */
1188 .finish_new_placement:
1190 { finish_new_placement (NULL_TREE, $<itype>-1); }
1192 .begin_new_placement:
1193 { $$ = begin_new_placement (); }
1195 new_placement:
1196 '(' .begin_new_placement nonnull_exprlist ')'
1197 { $$ = finish_new_placement ($3, $2); }
1198 | '{' .begin_new_placement nonnull_exprlist '}'
1199 { cp_pedwarn ("old style placement syntax, use () instead");
1200 $$ = finish_new_placement ($3, $2); }
1203 new_initializer:
1204 '(' nonnull_exprlist ')'
1205 { $$ = $2; }
1206 | LEFT_RIGHT
1207 { $$ = NULL_TREE; }
1208 | '(' typespec ')'
1210 cp_error ("`%T' is not a valid expression", $2.t);
1211 $$ = error_mark_node;
1213 /* GNU extension so people can use initializer lists. Note that
1214 this alters the meaning of `new int = 1', which was previously
1215 syntactically valid but semantically invalid. */
1216 | '=' init
1218 if (pedantic)
1219 pedwarn ("ANSI C++ forbids initialization of new expression with `='");
1220 if (TREE_CODE ($2) != TREE_LIST
1221 && TREE_CODE ($2) != CONSTRUCTOR)
1222 $$ = build_expr_list (NULL_TREE, $2);
1223 else
1224 $$ = $2;
1228 /* This is necessary to postpone reduction of `int ((int)(int)(int))'. */
1229 regcast_or_absdcl:
1230 '(' type_id ')' %prec EMPTY
1231 { $2.t = finish_parmlist (build_tree_list (NULL_TREE, $2.t), 0);
1232 $$ = make_call_declarator (NULL_TREE, $2.t, NULL_TREE, NULL_TREE);
1233 check_for_new_type ("cast", $2); }
1234 | regcast_or_absdcl '(' type_id ')' %prec EMPTY
1235 { $3.t = finish_parmlist (build_tree_list (NULL_TREE, $3.t), 0);
1236 $$ = make_call_declarator ($$, $3.t, NULL_TREE, NULL_TREE);
1237 check_for_new_type ("cast", $3); }
1240 cast_expr:
1241 unary_expr
1242 | regcast_or_absdcl unary_expr %prec UNARY
1243 { $$ = reparse_absdcl_as_casts ($$, $2); }
1244 | regcast_or_absdcl '{' initlist maybecomma '}' %prec UNARY
1246 tree init = build_nt (CONSTRUCTOR, NULL_TREE,
1247 nreverse ($3));
1248 if (pedantic)
1249 pedwarn ("ANSI C++ forbids constructor-expressions");
1250 /* Indicate that this was a GNU C constructor expression. */
1251 TREE_HAS_CONSTRUCTOR (init) = 1;
1253 $$ = reparse_absdcl_as_casts ($$, init);
1257 expr_no_commas:
1258 cast_expr
1259 /* Handle general members. */
1260 | expr_no_commas POINTSAT_STAR expr_no_commas
1261 { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
1262 | expr_no_commas DOT_STAR expr_no_commas
1263 { $$ = build_m_component_ref ($$, $3); }
1264 | expr_no_commas '+' expr_no_commas
1265 { $$ = build_x_binary_op ($2, $$, $3); }
1266 | expr_no_commas '-' expr_no_commas
1267 { $$ = build_x_binary_op ($2, $$, $3); }
1268 | expr_no_commas '*' expr_no_commas
1269 { $$ = build_x_binary_op ($2, $$, $3); }
1270 | expr_no_commas '/' expr_no_commas
1271 { $$ = build_x_binary_op ($2, $$, $3); }
1272 | expr_no_commas '%' expr_no_commas
1273 { $$ = build_x_binary_op ($2, $$, $3); }
1274 | expr_no_commas LSHIFT expr_no_commas
1275 { $$ = build_x_binary_op ($2, $$, $3); }
1276 | expr_no_commas RSHIFT expr_no_commas
1277 { $$ = build_x_binary_op ($2, $$, $3); }
1278 | expr_no_commas ARITHCOMPARE expr_no_commas
1279 { $$ = build_x_binary_op ($2, $$, $3); }
1280 | expr_no_commas '<' expr_no_commas
1281 { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
1282 | expr_no_commas '>' expr_no_commas
1283 { $$ = build_x_binary_op (GT_EXPR, $$, $3); }
1284 | expr_no_commas EQCOMPARE expr_no_commas
1285 { $$ = build_x_binary_op ($2, $$, $3); }
1286 | expr_no_commas MIN_MAX expr_no_commas
1287 { $$ = build_x_binary_op ($2, $$, $3); }
1288 | expr_no_commas '&' expr_no_commas
1289 { $$ = build_x_binary_op ($2, $$, $3); }
1290 | expr_no_commas '|' expr_no_commas
1291 { $$ = build_x_binary_op ($2, $$, $3); }
1292 | expr_no_commas '^' expr_no_commas
1293 { $$ = build_x_binary_op ($2, $$, $3); }
1294 | expr_no_commas ANDAND expr_no_commas
1295 { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
1296 | expr_no_commas OROR expr_no_commas
1297 { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
1298 | expr_no_commas '?' xexpr ':' expr_no_commas
1299 { $$ = build_x_conditional_expr ($$, $3, $5); }
1300 | expr_no_commas '=' expr_no_commas
1301 { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
1302 if ($$ != error_mark_node)
1303 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
1304 | expr_no_commas ASSIGN expr_no_commas
1305 { $$ = build_x_modify_expr ($$, $2, $3); }
1306 | THROW
1307 { $$ = build_throw (NULL_TREE); }
1308 | THROW expr_no_commas
1309 { $$ = build_throw ($2); }
1310 /* These extensions are not defined. The second arg to build_m_component_ref
1311 is old, build_m_component_ref now does an implicit
1312 build_indirect_ref (x, NULL_PTR) on the second argument.
1313 | object '&' expr_no_commas %prec UNARY
1314 { $$ = build_m_component_ref ($$, build_x_unary_op (ADDR_EXPR, $3)); }
1315 | object unop expr_no_commas %prec UNARY
1316 { $$ = build_m_component_ref ($$, build_x_unary_op ($2, $3)); }
1317 | object '(' type_id ')' expr_no_commas %prec UNARY
1318 { tree type = groktypename ($3.t);
1319 $$ = build_m_component_ref ($$, build_c_cast (type, $5)); }
1320 | object primary_no_id %prec UNARY
1321 { $$ = build_m_component_ref ($$, $2); }
1325 notype_unqualified_id:
1326 '~' see_typename identifier
1327 { $$ = build_parse_node (BIT_NOT_EXPR, $3); }
1328 | '~' see_typename template_type
1329 { $$ = build_parse_node (BIT_NOT_EXPR, $3); }
1330 | template_id
1331 | operator_name
1332 | IDENTIFIER
1333 | PTYPENAME
1334 | NSNAME %prec EMPTY
1337 do_id:
1339 /* If lastiddecl is a TREE_LIST, it's a baselink, which
1340 means that we're in an expression like S::f<int>, so
1341 don't do_identifier; we only do that for unqualified
1342 identifiers. */
1343 if (lastiddecl && TREE_CODE (lastiddecl) != TREE_LIST)
1344 $$ = do_identifier ($<ttype>-1, 1, NULL_TREE);
1345 else
1346 $$ = $<ttype>-1;
1349 template_id:
1350 PFUNCNAME '<' do_id template_arg_list_opt template_close_bracket
1351 { $$ = lookup_template_function ($3, $4); }
1352 | operator_name '<' do_id template_arg_list_opt template_close_bracket
1353 { $$ = lookup_template_function ($3, $4); }
1356 object_template_id:
1357 TEMPLATE identifier '<' template_arg_list_opt template_close_bracket
1358 { $$ = lookup_template_function ($2, $4); }
1359 | TEMPLATE PFUNCNAME '<' template_arg_list_opt template_close_bracket
1360 { $$ = lookup_template_function ($2, $4); }
1361 | TEMPLATE operator_name '<' template_arg_list_opt
1362 template_close_bracket
1363 { $$ = lookup_template_function ($2, $4); }
1366 unqualified_id:
1367 notype_unqualified_id
1368 | TYPENAME
1369 | SELFNAME
1372 expr_or_declarator_intern:
1373 expr_or_declarator
1374 | attributes expr_or_declarator
1376 /* Provide support for '(' attributes '*' declarator ')'
1377 etc */
1378 $$ = decl_tree_cons ($1, $2, NULL_TREE);
1382 expr_or_declarator:
1383 notype_unqualified_id
1384 | '*' expr_or_declarator_intern %prec UNARY
1385 { $$ = build_parse_node (INDIRECT_REF, $2); }
1386 | '&' expr_or_declarator_intern %prec UNARY
1387 { $$ = build_parse_node (ADDR_EXPR, $2); }
1388 | '(' expr_or_declarator_intern ')'
1389 { $$ = $2; }
1392 notype_template_declarator:
1393 IDENTIFIER '<' template_arg_list_opt template_close_bracket
1394 { $$ = lookup_template_function ($1, $3); }
1395 | NSNAME '<' template_arg_list template_close_bracket
1396 { $$ = lookup_template_function ($1, $3); }
1399 direct_notype_declarator:
1400 complex_direct_notype_declarator
1401 /* This precedence declaration is to prefer this reduce
1402 to the Koenig lookup shift in primary, below. I hate yacc. */
1403 | notype_unqualified_id %prec '('
1404 | notype_template_declarator
1405 | '(' expr_or_declarator_intern ')'
1406 { $$ = finish_decl_parsing ($2); }
1409 primary:
1410 notype_unqualified_id
1412 if (TREE_CODE ($1) == BIT_NOT_EXPR)
1413 $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($1, 0));
1414 else
1415 $$ = finish_id_expr ($1);
1417 | CONSTANT
1418 | boolean.literal
1419 | string
1421 if (processing_template_decl)
1422 push_obstacks (&permanent_obstack, &permanent_obstack);
1423 $$ = combine_strings ($$);
1424 /* combine_strings doesn't set up TYPE_MAIN_VARIANT of
1425 a const array the way we want, so fix it. */
1426 if (flag_const_strings)
1427 TREE_TYPE ($$) = build_cplus_array_type
1428 (TREE_TYPE (TREE_TYPE ($$)),
1429 TYPE_DOMAIN (TREE_TYPE ($$)));
1430 if (processing_template_decl)
1431 pop_obstacks ();
1433 | '(' expr ')'
1434 { $$ = finish_parenthesized_expr ($2); }
1435 | '(' expr_or_declarator_intern ')'
1436 { $2 = reparse_decl_as_expr (NULL_TREE, $2);
1437 $$ = finish_parenthesized_expr ($2); }
1438 | '(' error ')'
1439 { $$ = error_mark_node; }
1440 | '('
1441 { tree scope = current_scope ();
1442 if (!scope || TREE_CODE (scope) != FUNCTION_DECL)
1444 error ("braced-group within expression allowed only inside a function");
1445 YYERROR;
1447 if (pedantic)
1448 pedwarn ("ANSI C++ forbids braced-groups within expressions");
1449 $<ttype>$ = begin_stmt_expr ();
1451 compstmt ')'
1452 { $$ = finish_stmt_expr ($<ttype>2, $3); }
1453 /* Koenig lookup support
1454 We could store lastiddecl in $1 to avoid another lookup,
1455 but that would result in many additional reduce/reduce conflicts. */
1456 | notype_unqualified_id '(' nonnull_exprlist ')'
1457 { $$ = finish_call_expr ($1, $3, 1); }
1458 | notype_unqualified_id LEFT_RIGHT
1459 { $$ = finish_call_expr ($1, NULL_TREE, 1); }
1460 | primary '(' nonnull_exprlist ')'
1461 { $$ = finish_call_expr ($1, $3, 0); }
1462 | primary LEFT_RIGHT
1463 { $$ = finish_call_expr ($1, NULL_TREE, 0); }
1464 | primary '[' expr ']'
1465 { $$ = grok_array_decl ($$, $3); }
1466 | primary PLUSPLUS
1467 { $$ = finish_increment_expr ($1, POSTINCREMENT_EXPR); }
1468 | primary MINUSMINUS
1469 { $$ = finish_increment_expr ($1, POSTDECREMENT_EXPR); }
1470 /* C++ extensions */
1471 | THIS
1472 { $$ = finish_this_expr (); }
1473 | CV_QUALIFIER '(' nonnull_exprlist ')'
1475 /* This is a C cast in C++'s `functional' notation
1476 using the "implicit int" extension so that:
1477 `const (3)' is equivalent to `const int (3)'. */
1478 tree type;
1480 if ($3 == error_mark_node)
1482 $$ = error_mark_node;
1483 break;
1486 type = cp_build_qualified_type (integer_type_node,
1487 cp_type_qual_from_rid ($1));
1488 $$ = build_c_cast (type, build_compound_expr ($3));
1490 | functional_cast
1491 | DYNAMIC_CAST '<' type_id '>' '(' expr ')'
1492 { tree type = groktypename ($3.t);
1493 check_for_new_type ("dynamic_cast", $3);
1494 $$ = build_dynamic_cast (type, $6); }
1495 | STATIC_CAST '<' type_id '>' '(' expr ')'
1496 { tree type = groktypename ($3.t);
1497 check_for_new_type ("static_cast", $3);
1498 $$ = build_static_cast (type, $6); }
1499 | REINTERPRET_CAST '<' type_id '>' '(' expr ')'
1500 { tree type = groktypename ($3.t);
1501 check_for_new_type ("reinterpret_cast", $3);
1502 $$ = build_reinterpret_cast (type, $6); }
1503 | CONST_CAST '<' type_id '>' '(' expr ')'
1504 { tree type = groktypename ($3.t);
1505 check_for_new_type ("const_cast", $3);
1506 $$ = build_const_cast (type, $6); }
1507 | TYPEID '(' expr ')'
1508 { $$ = build_x_typeid ($3); }
1509 | TYPEID '(' type_id ')'
1510 { tree type = groktypename ($3.t);
1511 check_for_new_type ("typeid", $3);
1512 $$ = get_typeid (TYPE_MAIN_VARIANT (type)); }
1513 | global_scope IDENTIFIER
1514 { $$ = do_scoped_id ($2, 1); }
1515 | global_scope template_id
1516 { $$ = $2; }
1517 | global_scope operator_name
1519 got_scope = NULL_TREE;
1520 if (TREE_CODE ($2) == IDENTIFIER_NODE)
1521 $$ = do_scoped_id ($2, 1);
1522 else
1523 $$ = $2;
1525 | overqualified_id %prec HYPERUNARY
1526 { $$ = build_offset_ref (OP0 ($$), OP1 ($$)); }
1527 | overqualified_id '(' nonnull_exprlist ')'
1528 { $$ = finish_qualified_call_expr ($1, $3); }
1529 | overqualified_id LEFT_RIGHT
1530 { $$ = finish_qualified_call_expr ($1, NULL_TREE); }
1531 | object object_template_id %prec UNARY
1533 $$ = build_x_component_ref ($$, $2, NULL_TREE, 1);
1535 | object object_template_id '(' nonnull_exprlist ')'
1536 { $$ = finish_object_call_expr ($2, $1, $4); }
1537 | object object_template_id LEFT_RIGHT
1538 { $$ = finish_object_call_expr ($2, $1, NULL_TREE); }
1539 | object unqualified_id %prec UNARY
1540 { $$ = build_x_component_ref ($$, $2, NULL_TREE, 1); }
1541 | object overqualified_id %prec UNARY
1542 { if (processing_template_decl)
1543 $$ = build_min_nt (COMPONENT_REF, $1, $2);
1544 else
1545 $$ = build_object_ref ($$, OP0 ($2), OP1 ($2)); }
1546 | object unqualified_id '(' nonnull_exprlist ')'
1547 { $$ = finish_object_call_expr ($2, $1, $4); }
1548 | object unqualified_id LEFT_RIGHT
1549 { $$ = finish_object_call_expr ($2, $1, NULL_TREE); }
1550 | object overqualified_id '(' nonnull_exprlist ')'
1551 { $$ = finish_qualified_object_call_expr ($2, $1, $4); }
1552 | object overqualified_id LEFT_RIGHT
1553 { $$ = finish_qualified_object_call_expr ($2, $1, NULL_TREE); }
1554 /* p->int::~int() is valid -- 12.4 */
1555 | object '~' TYPESPEC LEFT_RIGHT
1556 { $$ = finish_pseudo_destructor_call_expr ($1, NULL_TREE, $3); }
1557 | object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT
1558 { $$ = finish_pseudo_destructor_call_expr ($1, $2, $5); }
1559 | object error
1561 $$ = error_mark_node;
1565 /* Not needed for now.
1567 primary_no_id:
1568 '(' expr ')'
1569 { $$ = $2; }
1570 | '(' error ')'
1571 { $$ = error_mark_node; }
1572 | '('
1573 { if (current_function_decl == 0)
1575 error ("braced-group within expression allowed only inside a function");
1576 YYERROR;
1578 $<ttype>$ = expand_start_stmt_expr (); }
1579 compstmt ')'
1580 { if (pedantic)
1581 pedwarn ("ANSI C++ forbids braced-groups within expressions");
1582 $$ = expand_end_stmt_expr ($<ttype>2); }
1583 | primary_no_id '(' nonnull_exprlist ')'
1584 { $$ = build_x_function_call ($$, $3, current_class_ref); }
1585 | primary_no_id LEFT_RIGHT
1586 { $$ = build_x_function_call ($$, NULL_TREE, current_class_ref); }
1587 | primary_no_id '[' expr ']'
1588 { goto do_array; }
1589 | primary_no_id PLUSPLUS
1590 { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
1591 | primary_no_id MINUSMINUS
1592 { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
1593 | SCOPE IDENTIFIER
1594 { goto do_scoped_id; }
1595 | SCOPE operator_name
1596 { if (TREE_CODE ($2) == IDENTIFIER_NODE)
1597 goto do_scoped_id;
1598 goto do_scoped_operator;
1603 new:
1605 { $$ = 0; }
1606 | global_scope NEW
1607 { got_scope = NULL_TREE; $$ = 1; }
1610 delete:
1611 DELETE
1612 { $$ = 0; }
1613 | global_scope delete
1614 { got_scope = NULL_TREE; $$ = 1; }
1617 boolean.literal:
1618 CXX_TRUE
1619 { $$ = boolean_true_node; }
1620 | CXX_FALSE
1621 { $$ = boolean_false_node; }
1624 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
1625 string:
1626 STRING
1627 | string STRING
1628 { $$ = chainon ($$, $2); }
1631 nodecls:
1632 /* empty */
1634 if (! current_function_parms_stored)
1635 store_parm_decls ();
1636 setup_vtbl_ptr ();
1640 object:
1641 primary '.'
1642 { got_object = TREE_TYPE ($$); }
1643 | primary POINTSAT
1645 $$ = build_x_arrow ($$);
1646 got_object = TREE_TYPE ($$);
1650 decl:
1651 typespec initdecls ';'
1653 resume_momentary ($2);
1654 if ($1.t && IS_AGGR_TYPE_CODE (TREE_CODE ($1.t)))
1655 note_got_semicolon ($1.t);
1657 | typed_declspecs initdecls ';'
1659 resume_momentary ($2);
1660 note_list_got_semicolon ($1.t);
1662 | declmods notype_initdecls ';'
1663 { resume_momentary ($2); }
1664 | typed_declspecs ';'
1666 shadow_tag ($1.t);
1667 note_list_got_semicolon ($1.t);
1669 | declmods ';'
1670 { warning ("empty declaration"); }
1671 | extension decl
1672 { pedantic = $1; }
1675 /* Any kind of declarator (thus, all declarators allowed
1676 after an explicit typespec). */
1678 declarator:
1679 after_type_declarator %prec EMPTY
1680 | notype_declarator %prec EMPTY
1683 /* This is necessary to postpone reduction of `int()()()()'. */
1684 fcast_or_absdcl:
1685 LEFT_RIGHT %prec EMPTY
1686 { $$ = make_call_declarator (NULL_TREE, empty_parms (),
1687 NULL_TREE, NULL_TREE); }
1688 | fcast_or_absdcl LEFT_RIGHT %prec EMPTY
1689 { $$ = make_call_declarator ($$, empty_parms (), NULL_TREE,
1690 NULL_TREE); }
1693 /* ANSI type-id (8.1) */
1694 type_id:
1695 typed_typespecs absdcl
1696 { $$.t = build_decl_list ($1.t, $2);
1697 $$.new_type_flag = $1.new_type_flag; }
1698 | nonempty_cv_qualifiers absdcl
1699 { $$.t = build_decl_list ($1.t, $2);
1700 $$.new_type_flag = $1.new_type_flag; }
1701 | typespec absdcl
1702 { $$.t = build_decl_list (build_decl_list (NULL_TREE, $1.t),
1703 $2);
1704 $$.new_type_flag = $1.new_type_flag; }
1705 | typed_typespecs %prec EMPTY
1706 { $$.t = build_decl_list ($1.t, NULL_TREE);
1707 $$.new_type_flag = $1.new_type_flag; }
1708 | nonempty_cv_qualifiers %prec EMPTY
1709 { $$.t = build_decl_list ($1.t, NULL_TREE);
1710 $$.new_type_flag = $1.new_type_flag; }
1713 /* Declspecs which contain at least one type specifier or typedef name.
1714 (Just `const' or `volatile' is not enough.)
1715 A typedef'd name following these is taken as a name to be declared.
1716 In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
1718 typed_declspecs:
1719 typed_typespecs %prec EMPTY
1720 | typed_declspecs1
1723 typed_declspecs1:
1724 declmods typespec
1725 { $$.t = decl_tree_cons (NULL_TREE, $2.t, $1);
1726 $$.new_type_flag = $2.new_type_flag; }
1727 | typespec reserved_declspecs %prec HYPERUNARY
1728 { $$.t = decl_tree_cons (NULL_TREE, $1.t, $2);
1729 $$.new_type_flag = $1.new_type_flag; }
1730 | typespec reserved_typespecquals reserved_declspecs
1731 { $$.t = decl_tree_cons (NULL_TREE, $1.t, chainon ($2, $3));
1732 $$.new_type_flag = $1.new_type_flag; }
1733 | declmods typespec reserved_declspecs
1734 { $$.t = decl_tree_cons (NULL_TREE, $2.t, chainon ($3, $1));
1735 $$.new_type_flag = $2.new_type_flag; }
1736 | declmods typespec reserved_typespecquals
1737 { $$.t = decl_tree_cons (NULL_TREE, $2.t, chainon ($3, $1));
1738 $$.new_type_flag = $2.new_type_flag; }
1739 | declmods typespec reserved_typespecquals reserved_declspecs
1740 { $$.t = decl_tree_cons (NULL_TREE, $2.t,
1741 chainon ($3, chainon ($4, $1)));
1742 $$.new_type_flag = $2.new_type_flag; }
1745 reserved_declspecs:
1746 SCSPEC
1747 { if (extra_warnings)
1748 warning ("`%s' is not at beginning of declaration",
1749 IDENTIFIER_POINTER ($$));
1750 $$ = build_decl_list (NULL_TREE, $$); }
1751 | reserved_declspecs typespecqual_reserved
1752 { $$ = decl_tree_cons (NULL_TREE, $2.t, $$); }
1753 | reserved_declspecs SCSPEC
1754 { if (extra_warnings)
1755 warning ("`%s' is not at beginning of declaration",
1756 IDENTIFIER_POINTER ($2));
1757 $$ = decl_tree_cons (NULL_TREE, $2, $$); }
1758 | reserved_declspecs attributes
1759 { $$ = decl_tree_cons ($2, NULL_TREE, $1); }
1760 | attributes
1761 { $$ = decl_tree_cons ($1, NULL_TREE, NULL_TREE); }
1764 /* List of just storage classes and type modifiers.
1765 A declaration can start with just this, but then it cannot be used
1766 to redeclare a typedef-name.
1767 In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
1769 /* We use hash_tree_cons for lists of typeless declspecs so that they end
1770 up on a persistent obstack. Otherwise, they could appear at the
1771 beginning of something like
1773 static const struct { int foo () { } } b;
1775 and would be discarded after we finish compiling foo. We don't need to
1776 worry once we see a type. */
1778 declmods:
1779 nonempty_cv_qualifiers %prec EMPTY
1780 { $$ = $1.t; TREE_STATIC ($$) = 1; }
1781 | SCSPEC
1782 { $$ = hash_tree_cons (NULL_TREE, $$, NULL_TREE); }
1783 | declmods CV_QUALIFIER
1784 { $$ = hash_tree_cons (NULL_TREE, $2, $$);
1785 TREE_STATIC ($$) = 1; }
1786 | declmods SCSPEC
1787 { if (extra_warnings && TREE_STATIC ($$))
1788 warning ("`%s' is not at beginning of declaration",
1789 IDENTIFIER_POINTER ($2));
1790 $$ = hash_tree_cons (NULL_TREE, $2, $$);
1791 TREE_STATIC ($$) = TREE_STATIC ($1); }
1792 | declmods attributes
1793 { $$ = hash_tree_cons ($2, NULL_TREE, $1); }
1794 | attributes %prec EMPTY
1795 { $$ = hash_tree_cons ($1, NULL_TREE, NULL_TREE); }
1798 /* Used instead of declspecs where storage classes are not allowed
1799 (that is, for typenames and structure components).
1801 C++ can takes storage classes for structure components.
1802 Don't accept a typedef-name if anything but a modifier precedes it. */
1804 typed_typespecs:
1805 typespec %prec EMPTY
1806 { $$.t = build_decl_list (NULL_TREE, $1.t);
1807 $$.new_type_flag = $1.new_type_flag; }
1808 | nonempty_cv_qualifiers typespec
1809 { $$.t = decl_tree_cons (NULL_TREE, $2.t, $1.t);
1810 $$.new_type_flag = $2.new_type_flag; }
1811 | typespec reserved_typespecquals
1812 { $$.t = decl_tree_cons (NULL_TREE, $1.t, $2);
1813 $$.new_type_flag = $1.new_type_flag; }
1814 | nonempty_cv_qualifiers typespec reserved_typespecquals
1815 { $$.t = decl_tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
1816 $$.new_type_flag = $1.new_type_flag; }
1819 reserved_typespecquals:
1820 typespecqual_reserved
1821 { $$ = build_decl_list (NULL_TREE, $1.t); }
1822 | reserved_typespecquals typespecqual_reserved
1823 { $$ = decl_tree_cons (NULL_TREE, $2.t, $1); }
1826 /* A typespec (but not a type qualifier).
1827 Once we have seen one of these in a declaration,
1828 if a typedef name appears then it is being redeclared. */
1830 typespec:
1831 structsp
1832 | TYPESPEC %prec EMPTY
1833 { $$.t = $1; $$.new_type_flag = 0; }
1834 | complete_type_name
1835 { $$.t = $1; $$.new_type_flag = 0; }
1836 | TYPEOF '(' expr ')'
1837 { $$.t = finish_typeof ($3);
1838 $$.new_type_flag = 0; }
1839 | TYPEOF '(' type_id ')'
1840 { $$.t = groktypename ($3.t);
1841 $$.new_type_flag = 0; }
1842 | SIGOF '(' expr ')'
1843 { tree type = TREE_TYPE ($3);
1845 $$.new_type_flag = 0;
1846 if (IS_AGGR_TYPE (type))
1848 sorry ("sigof type specifier");
1849 $$.t = type;
1851 else
1853 error ("`sigof' applied to non-aggregate expression");
1854 $$.t = error_mark_node;
1857 | SIGOF '(' type_id ')'
1858 { tree type = groktypename ($3.t);
1860 $$.new_type_flag = 0;
1861 if (IS_AGGR_TYPE (type))
1863 sorry ("sigof type specifier");
1864 $$.t = type;
1866 else
1868 error("`sigof' applied to non-aggregate type");
1869 $$.t = error_mark_node;
1874 /* A typespec that is a reserved word, or a type qualifier. */
1876 typespecqual_reserved:
1877 TYPESPEC
1878 { $$.t = $1; $$.new_type_flag = 0; }
1879 | CV_QUALIFIER
1880 { $$.t = $1; $$.new_type_flag = 0; }
1881 | structsp
1884 initdecls:
1885 initdcl0
1886 | initdecls ',' initdcl
1887 { check_multiple_declarators (); }
1890 notype_initdecls:
1891 notype_initdcl0
1892 | notype_initdecls ',' initdcl
1893 { check_multiple_declarators (); }
1896 nomods_initdecls:
1897 nomods_initdcl0
1898 | nomods_initdecls ',' initdcl
1899 { check_multiple_declarators (); }
1902 maybeasm:
1903 /* empty */
1904 { $$ = NULL_TREE; }
1905 | asm_keyword '(' string ')'
1906 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); $$ = $3; }
1909 initdcl:
1910 declarator maybeasm maybe_attribute '='
1911 { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1,
1912 $3, prefix_attributes); }
1913 init
1914 /* Note how the declaration of the variable is in effect while its init is parsed! */
1915 { cp_finish_decl ($<ttype>5, $6, $2, 1, LOOKUP_ONLYCONVERTING); }
1916 | declarator maybeasm maybe_attribute
1917 { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 0,
1918 $3, prefix_attributes);
1919 cp_finish_decl ($<ttype>$, NULL_TREE, $2, 1, 0); }
1922 /* This rule assumes a certain configuration of the parser stack.
1923 In particular, $0, the element directly before the beginning of
1924 this rule on the stack, must be a maybeasm. $-1 must be a
1925 declarator or notype_declarator. And $-2 must be some declmods
1926 or declspecs. We can't move the maybeasm into this rule because
1927 we need that reduce so we prefer fn.def1 when appropriate. */
1928 initdcl0_innards:
1929 maybe_attribute '='
1930 { $<itype>2 = parse_decl ($<ttype>-1, $<ttype>-2,
1931 $1, 1, &$<ttype>$); }
1932 /* Note how the declaration of the variable is in effect
1933 while its init is parsed! */
1934 init
1935 { cp_finish_decl ($<ttype>3, $4, $<ttype>0, 1,
1936 LOOKUP_ONLYCONVERTING);
1937 $$ = $<itype>2; }
1938 | maybe_attribute
1939 { tree d;
1940 $$ = parse_decl ($<ttype>-1, $<ttype>-2, $1, 0, &d);
1941 cp_finish_decl (d, NULL_TREE, $<ttype>0, 1, 0); }
1944 initdcl0:
1945 declarator maybeasm initdcl0_innards
1946 { $$ = $3; }
1948 notype_initdcl0:
1949 notype_declarator maybeasm initdcl0_innards
1950 { $$ = $3; }
1953 nomods_initdcl0:
1954 notype_declarator maybeasm
1955 { /* Set things up as initdcl0_innards expects. */
1956 $<ttype>2 = $1;
1957 $1 = NULL_TREE; }
1958 initdcl0_innards
1960 | constructor_declarator maybeasm maybe_attribute
1961 { tree d;
1962 parse_decl($1, NULL_TREE, $3, 0, &d);
1963 cp_finish_decl (d, NULL_TREE, $2, 1, 0); }
1966 /* the * rules are dummies to accept the Apollo extended syntax
1967 so that the header files compile. */
1968 maybe_attribute:
1969 /* empty */
1970 { $$ = NULL_TREE; }
1971 | attributes
1972 { $$ = $1; }
1975 attributes:
1976 attribute
1977 { $$ = $1; }
1978 | attributes attribute
1979 { $$ = chainon ($1, $2); }
1982 attribute:
1983 ATTRIBUTE '(' '(' attribute_list ')' ')'
1984 { $$ = $4; }
1987 attribute_list:
1988 attrib
1989 { $$ = $1; }
1990 | attribute_list ',' attrib
1991 { $$ = chainon ($1, $3); }
1994 attrib:
1995 /* empty */
1996 { $$ = NULL_TREE; }
1997 | any_word
1998 { $$ = build_tree_list ($1, NULL_TREE); }
1999 | any_word '(' IDENTIFIER ')'
2000 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
2001 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
2002 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
2003 | any_word '(' nonnull_exprlist ')'
2004 { $$ = build_tree_list ($1, $3); }
2007 /* This still leaves out most reserved keywords,
2008 shouldn't we include them? */
2010 any_word:
2011 identifier
2012 | SCSPEC
2013 | TYPESPEC
2014 | CV_QUALIFIER
2017 /* A nonempty list of identifiers, including typenames. */
2018 identifiers_or_typenames:
2019 identifier
2020 { $$ = build_tree_list (NULL_TREE, $1); }
2021 | identifiers_or_typenames ',' identifier
2022 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2025 maybe_init:
2026 /* empty */ %prec EMPTY
2027 { $$ = NULL_TREE; }
2028 | '=' init
2029 { $$ = $2; }
2031 /* If we are processing a template, we don't want to expand this
2032 initializer yet. */
2034 init:
2035 expr_no_commas %prec '='
2036 | '{' '}'
2037 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
2038 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2039 | '{' initlist '}'
2040 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2041 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2042 | '{' initlist ',' '}'
2043 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2044 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2045 | error
2046 { $$ = NULL_TREE; }
2049 /* This chain is built in reverse order,
2050 and put in forward order where initlist is used. */
2051 initlist:
2052 init
2053 { $$ = build_tree_list (NULL_TREE, $$); }
2054 | initlist ',' init
2055 { $$ = tree_cons (NULL_TREE, $3, $$); }
2056 /* These are for labeled elements. */
2057 | '[' expr_no_commas ']' init
2058 { $$ = build_expr_list ($2, $4); }
2059 | identifier ':' init
2060 { $$ = build_expr_list ($$, $3); }
2061 | initlist ',' identifier ':' init
2062 { $$ = tree_cons ($3, $5, $$); }
2065 fn.defpen:
2066 PRE_PARSED_FUNCTION_DECL
2067 { start_function (NULL_TREE, $1->fndecl, NULL_TREE,
2068 (SF_DEFAULT | SF_PRE_PARSED
2069 | SF_INCLASS_INLINE));
2070 reinit_parse_for_function (); }
2072 pending_inline:
2073 fn.defpen maybe_return_init ctor_initializer_opt compstmt_or_error
2075 finish_function (lineno, (int)$3 | 2);
2076 process_next_inline ($1);
2078 | fn.defpen maybe_return_init function_try_block
2080 finish_function (lineno, (int)$3 | 2);
2081 process_next_inline ($1);
2083 | fn.defpen maybe_return_init error
2084 { free_after_compilation (current_function);
2085 current_function = NULL;
2086 process_next_inline ($1); }
2089 pending_inlines:
2090 /* empty */
2091 | pending_inlines pending_inline eat_saved_input
2094 /* A regurgitated default argument. The value of DEFARG_MARKER will be
2095 the TREE_LIST node for the parameter in question. */
2096 defarg_again:
2097 DEFARG_MARKER expr_no_commas END_OF_SAVED_INPUT
2098 { replace_defarg ($1, $2); }
2099 | DEFARG_MARKER error END_OF_SAVED_INPUT
2100 { replace_defarg ($1, error_mark_node); }
2102 pending_defargs:
2103 /* empty */ %prec EMPTY
2104 | pending_defargs defarg_again
2105 { do_pending_defargs (); }
2106 | pending_defargs error
2107 { do_pending_defargs (); }
2110 structsp:
2111 ENUM identifier '{'
2112 { $<itype>3 = suspend_momentary ();
2113 $<ttype>$ = current_enum_type;
2114 current_enum_type = start_enum ($2); }
2115 enumlist_opt '}'
2116 { TYPE_VALUES (current_enum_type) = $5;
2117 $$.t = finish_enum (current_enum_type);
2118 $$.new_type_flag = 1;
2119 current_enum_type = $<ttype>4;
2120 resume_momentary ((int) $<itype>3);
2121 check_for_missing_semicolon ($$.t); }
2122 | ENUM '{'
2123 { $<itype>2 = suspend_momentary ();
2124 $<ttype>$ = current_enum_type;
2125 current_enum_type = start_enum (make_anon_name ()); }
2126 enumlist_opt '}'
2127 { TYPE_VALUES (current_enum_type) = $4;
2128 $$.t = finish_enum (current_enum_type);
2129 $$.new_type_flag = 1;
2130 current_enum_type = $<ttype>3;
2131 resume_momentary ((int) $<itype>1);
2132 check_for_missing_semicolon ($$.t); }
2133 | ENUM identifier
2134 { $$.t = xref_tag (enum_type_node, $2, 1);
2135 $$.new_type_flag = 0; }
2136 | ENUM complex_type_name
2137 { $$.t = xref_tag (enum_type_node, $2, 1);
2138 $$.new_type_flag = 0; }
2139 | TYPENAME_KEYWORD typename_sub
2140 { $$.t = $2;
2141 $$.new_type_flag = 0;
2142 if (!processing_template_decl)
2143 cp_pedwarn ("using `typename' outside of template"); }
2144 /* C++ extensions, merged with C to avoid shift/reduce conflicts */
2145 | class_head '{'
2146 { $1.t = begin_class_definition ($1.t); }
2147 opt.component_decl_list '}' maybe_attribute
2149 int semi;
2151 if (yychar == YYEMPTY)
2152 yychar = YYLEX;
2153 semi = yychar == ';';
2155 $<ttype>$ = finish_class_definition ($1.t, $6, semi,
2156 $1.new_type_flag);
2158 pending_defargs
2160 begin_inline_definitions ();
2162 pending_inlines
2164 finish_inline_definitions ();
2165 $$.t = $<ttype>7;
2166 $$.new_type_flag = 1;
2168 | class_head %prec EMPTY
2170 if ($1.new_type_flag && $1.t != error_mark_node)
2171 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL ($1.t)));
2172 $$.new_type_flag = 0;
2173 if ($1.t == error_mark_node)
2174 $$.t = $1.t;
2175 else if (TYPE_BINFO ($1.t) == NULL_TREE)
2177 cp_error ("%T is not a class type", $1.t);
2178 $$.t = error_mark_node;
2180 else
2182 $$.t = $1.t;
2183 /* struct B: public A; is not accepted by the WP grammar. */
2184 if (TYPE_BINFO_BASETYPES ($$.t) && !TYPE_SIZE ($$.t)
2185 && ! TYPE_BEING_DEFINED ($$.t))
2186 cp_error ("base clause without member specification for `%#T'",
2187 $$.t);
2192 maybecomma:
2193 /* empty */
2194 | ','
2197 maybecomma_warn:
2198 /* empty */
2199 | ','
2200 { if (pedantic && !in_system_header)
2201 pedwarn ("comma at end of enumerator list"); }
2204 aggr:
2205 AGGR
2206 | aggr SCSPEC
2207 { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2208 | aggr TYPESPEC
2209 { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2210 | aggr CV_QUALIFIER
2211 { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2212 | aggr AGGR
2213 { error ("no body nor ';' separates two class, struct or union declarations"); }
2214 | aggr attributes
2215 { $$ = build_decl_list ($2, $1); }
2218 named_class_head_sans_basetype:
2219 aggr identifier
2221 current_aggr = $1;
2222 $$ = $2;
2226 named_class_head_sans_basetype_defn:
2227 aggr identifier_defn %prec EMPTY
2228 { current_aggr = $$; $$ = $2; }
2229 | named_class_head_sans_basetype '{'
2230 { yyungetc ('{', 1); }
2231 | named_class_head_sans_basetype ':'
2232 { yyungetc (':', 1); }
2235 named_complex_class_head_sans_basetype:
2236 aggr nested_name_specifier identifier
2238 current_aggr = $1;
2239 $$.t = handle_class_head ($1, $2, $3);
2240 $$.new_type_flag = 1;
2242 | aggr global_scope nested_name_specifier identifier
2244 current_aggr = $1;
2245 $$.t = handle_class_head ($1, $3, $4);
2246 $$.new_type_flag = 1;
2248 | aggr global_scope identifier
2250 current_aggr = $1;
2251 $$.t = handle_class_head ($1, NULL_TREE, $3);
2252 $$.new_type_flag = 1;
2254 | aggr apparent_template_type
2256 current_aggr = $1;
2257 $$.t = $2;
2258 $$.new_type_flag = 0;
2260 | aggr nested_name_specifier apparent_template_type
2262 current_aggr = $1;
2263 $$.t = $3;
2264 if (CP_DECL_CONTEXT ($$.t))
2265 push_scope (CP_DECL_CONTEXT ($$.t));
2266 $$.new_type_flag = 1;
2270 named_class_head:
2271 named_class_head_sans_basetype %prec EMPTY
2273 $$.t = xref_tag (current_aggr, $1, 1);
2274 $$.new_type_flag = 0;
2276 | named_class_head_sans_basetype_defn
2277 { $<ttype>$ = xref_tag (current_aggr, $1, 0); }
2278 /* Class name is unqualified, so we look for base classes
2279 in the current scope. */
2280 maybe_base_class_list %prec EMPTY
2282 $$.t = $<ttype>2;
2283 $$.new_type_flag = 0;
2284 if ($3)
2285 xref_basetypes (current_aggr, $1, $<ttype>2, $3);
2287 | named_complex_class_head_sans_basetype
2288 maybe_base_class_list
2290 if ($1.t != error_mark_node)
2292 $$.t = TREE_TYPE ($1.t);
2293 $$.new_type_flag = $1.new_type_flag;
2294 if (current_aggr == union_type_node
2295 && TREE_CODE ($$.t) != UNION_TYPE)
2296 cp_pedwarn ("`union' tag used in declaring `%#T'",
2297 $$.t);
2298 else if (TREE_CODE ($$.t) == UNION_TYPE
2299 && current_aggr != union_type_node)
2300 cp_pedwarn ("non-`union' tag used in declaring `%#T'", $$);
2301 else if (TREE_CODE ($$.t) == RECORD_TYPE)
2302 /* We might be specializing a template with a different
2303 class-key; deal. */
2304 CLASSTYPE_DECLARED_CLASS ($$.t)
2305 = (current_aggr == class_type_node);
2306 if ($2)
2308 maybe_process_partial_specialization ($$.t);
2309 xref_basetypes (current_aggr, $1.t, $$.t, $2);
2315 unnamed_class_head:
2316 aggr '{'
2317 { $$ = xref_tag ($$, make_anon_name (), 0);
2318 yyungetc ('{', 1); }
2321 /* The tree output of this nonterminal a declarationf or the type
2322 named. If NEW_TYPE_FLAG is set, then the name used in this
2323 class-head was explicitly qualified, e.g.: `struct X::Y'. We have
2324 already called push_scope for X. */
2325 class_head:
2326 unnamed_class_head
2328 $$.t = $1;
2329 $$.new_type_flag = 0;
2331 | named_class_head
2334 maybe_base_class_list:
2335 /* empty */ %prec EMPTY
2336 { $$ = NULL_TREE; }
2337 | ':' see_typename %prec EMPTY
2338 { yyungetc(':', 1); $$ = NULL_TREE; }
2339 | ':' see_typename base_class_list %prec EMPTY
2340 { $$ = $3; }
2343 base_class_list:
2344 base_class
2345 | base_class_list ',' see_typename base_class
2346 { $$ = chainon ($$, $4); }
2349 base_class:
2350 base_class.1
2351 { $$ = finish_base_specifier (access_default_node, $1); }
2352 | base_class_access_list see_typename base_class.1
2353 { $$ = finish_base_specifier ($1, $3); }
2356 base_class.1:
2357 typename_sub
2358 { if ($$ != error_mark_node) $$ = TYPE_MAIN_DECL ($1); }
2359 | nonnested_type
2362 base_class_access_list:
2363 VISSPEC see_typename
2364 | SCSPEC see_typename
2365 { if ($1 != ridpointers[(int)RID_VIRTUAL])
2366 cp_error ("`%D' access", $1);
2367 $$ = access_default_virtual_node; }
2368 | base_class_access_list VISSPEC see_typename
2370 if ($1 != access_default_virtual_node)
2371 error ("multiple access specifiers");
2372 else if ($2 == access_public_node)
2373 $$ = access_public_virtual_node;
2374 else if ($2 == access_protected_node)
2375 $$ = access_protected_virtual_node;
2376 else /* $2 == access_private_node */
2377 $$ = access_private_virtual_node;
2379 | base_class_access_list SCSPEC see_typename
2380 { if ($2 != ridpointers[(int)RID_VIRTUAL])
2381 cp_error ("`%D' access", $2);
2382 else if ($$ == access_public_node)
2383 $$ = access_public_virtual_node;
2384 else if ($$ == access_protected_node)
2385 $$ = access_protected_virtual_node;
2386 else if ($$ == access_private_node)
2387 $$ = access_private_virtual_node;
2388 else
2389 error ("multiple `virtual' specifiers");
2393 opt.component_decl_list:
2394 | component_decl_list
2395 | opt.component_decl_list access_specifier component_decl_list
2396 | opt.component_decl_list access_specifier
2399 access_specifier:
2400 VISSPEC ':'
2402 current_access_specifier = $1;
2406 /* Note: we no longer warn about the semicolon after a component_decl_list.
2407 ARM $9.2 says that the semicolon is optional, and therefore allowed. */
2408 component_decl_list:
2409 component_decl
2411 finish_member_declaration ($1);
2413 | component_decl_list component_decl
2415 finish_member_declaration ($2);
2419 component_decl:
2420 component_decl_1 ';'
2421 | component_decl_1 '}'
2422 { error ("missing ';' before right brace");
2423 yyungetc ('}', 0); }
2424 /* C++: handle constructors, destructors and inline functions */
2425 /* note that INLINE is like a TYPESPEC */
2426 | fn.def2 ':' /* base_init compstmt */
2427 { $$ = finish_method ($$); }
2428 | fn.def2 TRY /* base_init compstmt */
2429 { $$ = finish_method ($$); }
2430 | fn.def2 RETURN_KEYWORD /* base_init compstmt */
2431 { $$ = finish_method ($$); }
2432 | fn.def2 '{' /* nodecls compstmt */
2433 { $$ = finish_method ($$); }
2434 | ';'
2435 { $$ = NULL_TREE; }
2436 | extension component_decl
2437 { $$ = $2;
2438 pedantic = $1; }
2439 | template_header component_decl
2441 if ($2)
2442 $$ = finish_member_template_decl ($2);
2443 else
2444 /* The component was already processed. */
2445 $$ = NULL_TREE;
2447 finish_template_decl ($1);
2449 | template_header typed_declspecs ';'
2451 $$ = finish_member_class_template ($2.t);
2452 finish_template_decl ($1);
2456 component_decl_1:
2457 /* Do not add a "typed_declspecs declarator" rule here for
2458 speed; we need to call grok_x_components for enums, so the
2459 speedup would be insignificant. */
2460 typed_declspecs components
2462 /* Most of the productions for component_decl only
2463 allow the creation of one new member, so we call
2464 finish_member_declaration in component_decl_list.
2465 For this rule and the next, however, there can be
2466 more than one member, e.g.:
2468 int i, j;
2470 and we need the first member to be fully
2471 registered before the second is processed.
2472 Therefore, the rules for components take care of
2473 this processing. To avoid registering the
2474 components more than once, we send NULL_TREE up
2475 here; that lets finish_member_declaration know
2476 that there is nothing to do. */
2477 if (!$2)
2478 grok_x_components ($1.t);
2479 $$ = NULL_TREE;
2481 | declmods notype_components
2483 if (!$2)
2484 grok_x_components ($1);
2485 $$ = NULL_TREE;
2487 | notype_declarator maybeasm maybe_attribute maybe_init
2488 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2489 build_tree_list ($3, NULL_TREE)); }
2490 | constructor_declarator maybeasm maybe_attribute maybe_init
2491 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2492 build_tree_list ($3, NULL_TREE)); }
2493 | ':' expr_no_commas
2494 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
2495 | error
2496 { $$ = NULL_TREE; }
2498 /* These rules introduce a reduce/reduce conflict; in
2499 typedef int foo, bar;
2500 class A {
2501 foo (bar);
2503 should "A::foo" be declared as a function or "A::bar" as a data
2504 member? In other words, is "bar" an after_type_declarator or a
2505 parmlist? */
2506 | declmods component_constructor_declarator maybeasm maybe_attribute maybe_init
2507 { tree specs, attrs;
2508 split_specs_attrs ($1, &specs, &attrs);
2509 $$ = grokfield ($2, specs, $5, $3,
2510 build_tree_list ($4, attrs)); }
2511 | component_constructor_declarator maybeasm maybe_attribute maybe_init
2512 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2513 build_tree_list ($3, NULL_TREE)); }
2514 | using_decl
2515 { $$ = do_class_using_decl ($1); }
2517 /* The case of exactly one component is handled directly by component_decl. */
2518 /* ??? Huh? ^^^ */
2519 components:
2520 /* empty: possibly anonymous */
2521 { $$ = 0; }
2522 | component_declarator0
2524 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2525 $1 = finish_member_template_decl ($1);
2526 finish_member_declaration ($1);
2527 $$ = 1;
2529 | components ',' component_declarator
2531 check_multiple_declarators ();
2532 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2533 $3 = finish_member_template_decl ($3);
2534 finish_member_declaration ($3);
2535 $$ = 2;
2539 notype_components:
2540 /* empty: possibly anonymous */
2541 { $$ = 0; }
2542 | notype_component_declarator0
2544 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2545 $1 = finish_member_template_decl ($1);
2546 finish_member_declaration ($1);
2547 $$ = 1;
2549 | notype_components ',' notype_component_declarator
2551 check_multiple_declarators ();
2552 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2553 $3 = finish_member_template_decl ($3);
2554 finish_member_declaration ($3);
2555 $$ = 2;
2559 component_declarator0:
2560 after_type_component_declarator0
2561 | notype_component_declarator0
2564 component_declarator:
2565 after_type_component_declarator
2566 | notype_component_declarator
2569 after_type_component_declarator0:
2570 after_type_declarator maybeasm maybe_attribute maybe_init
2571 { split_specs_attrs ($<ttype>0, &current_declspecs,
2572 &prefix_attributes);
2573 $<ttype>0 = current_declspecs;
2574 $$ = grokfield ($$, current_declspecs, $4, $2,
2575 build_tree_list ($3, prefix_attributes)); }
2576 | TYPENAME ':' expr_no_commas maybe_attribute
2577 { split_specs_attrs ($<ttype>0, &current_declspecs,
2578 &prefix_attributes);
2579 $<ttype>0 = current_declspecs;
2580 $$ = grokbitfield ($$, current_declspecs, $3);
2581 cplus_decl_attributes ($$, $4, prefix_attributes); }
2584 notype_component_declarator0:
2585 notype_declarator maybeasm maybe_attribute maybe_init
2586 { split_specs_attrs ($<ttype>0, &current_declspecs,
2587 &prefix_attributes);
2588 $<ttype>0 = current_declspecs;
2589 $$ = grokfield ($$, current_declspecs, $4, $2,
2590 build_tree_list ($3, prefix_attributes)); }
2591 | constructor_declarator maybeasm maybe_attribute maybe_init
2592 { split_specs_attrs ($<ttype>0, &current_declspecs,
2593 &prefix_attributes);
2594 $<ttype>0 = current_declspecs;
2595 $$ = grokfield ($$, current_declspecs, $4, $2,
2596 build_tree_list ($3, prefix_attributes)); }
2597 | IDENTIFIER ':' expr_no_commas maybe_attribute
2598 { split_specs_attrs ($<ttype>0, &current_declspecs,
2599 &prefix_attributes);
2600 $<ttype>0 = current_declspecs;
2601 $$ = grokbitfield ($$, current_declspecs, $3);
2602 cplus_decl_attributes ($$, $4, prefix_attributes); }
2603 | ':' expr_no_commas maybe_attribute
2604 { split_specs_attrs ($<ttype>0, &current_declspecs,
2605 &prefix_attributes);
2606 $<ttype>0 = current_declspecs;
2607 $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2608 cplus_decl_attributes ($$, $3, prefix_attributes); }
2611 after_type_component_declarator:
2612 after_type_declarator maybeasm maybe_attribute maybe_init
2613 { $$ = grokfield ($$, current_declspecs, $4, $2,
2614 build_tree_list ($3, prefix_attributes)); }
2615 | TYPENAME ':' expr_no_commas maybe_attribute
2616 { $$ = grokbitfield ($$, current_declspecs, $3);
2617 cplus_decl_attributes ($$, $4, prefix_attributes); }
2620 notype_component_declarator:
2621 notype_declarator maybeasm maybe_attribute maybe_init
2622 { $$ = grokfield ($$, current_declspecs, $4, $2,
2623 build_tree_list ($3, prefix_attributes)); }
2624 | IDENTIFIER ':' expr_no_commas maybe_attribute
2625 { $$ = grokbitfield ($$, current_declspecs, $3);
2626 cplus_decl_attributes ($$, $4, prefix_attributes); }
2627 | ':' expr_no_commas maybe_attribute
2628 { $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2629 cplus_decl_attributes ($$, $3, prefix_attributes); }
2632 enumlist_opt:
2633 enumlist maybecomma_warn
2634 | maybecomma_warn
2635 { $$ = NULL_TREE; }
2638 /* We chain the enumerators in reverse order.
2639 Because of the way enums are built, the order is
2640 insignificant. Take advantage of this fact. */
2642 enumlist:
2643 enumerator
2644 | enumlist ',' enumerator
2645 { TREE_CHAIN ($3) = $$; $$ = $3; }
2648 enumerator:
2649 identifier
2650 { $$ = build_enumerator ($$, NULL_TREE, current_enum_type); }
2651 | identifier '=' expr_no_commas
2652 { $$ = build_enumerator ($$, $3, current_enum_type); }
2655 /* ANSI new-type-id (5.3.4) */
2656 new_type_id:
2657 type_specifier_seq new_declarator
2658 { $$.t = build_decl_list ($1.t, $2);
2659 $$.new_type_flag = $1.new_type_flag; }
2660 | type_specifier_seq %prec EMPTY
2661 { $$.t = build_decl_list ($1.t, NULL_TREE);
2662 $$.new_type_flag = $1.new_type_flag; }
2663 /* GNU extension to allow arrays of arbitrary types with
2664 non-constant dimension. For the use of begin_new_placement
2665 here, see the comments in unary_expr above. */
2666 | '(' .begin_new_placement type_id .finish_new_placement
2667 '[' expr ']'
2669 if (pedantic)
2670 pedwarn ("ANSI C++ forbids array dimensions with parenthesized type in new");
2671 $$.t = build_parse_node (ARRAY_REF, TREE_VALUE ($3.t), $6);
2672 $$.t = build_decl_list (TREE_PURPOSE ($3.t), $$.t);
2673 $$.new_type_flag = $3.new_type_flag;
2677 cv_qualifiers:
2678 /* empty */ %prec EMPTY
2679 { $$ = NULL_TREE; }
2680 | cv_qualifiers CV_QUALIFIER
2681 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
2684 nonempty_cv_qualifiers:
2685 CV_QUALIFIER
2686 { $$.t = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
2687 $$.new_type_flag = 0; }
2688 | nonempty_cv_qualifiers CV_QUALIFIER
2689 { $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
2690 $$.new_type_flag = $1.new_type_flag; }
2693 /* These rules must follow the rules for function declarations
2694 and component declarations. That way, longer rules are preferred. */
2696 suspend_mom:
2697 /* empty */
2698 { $<itype>$ = suspend_momentary (); }
2700 /* An expression which will not live on the momentary obstack. */
2701 nonmomentary_expr:
2702 suspend_mom expr
2703 { resume_momentary ((int) $<itype>1); $$ = $2; }
2706 /* An expression which will not live on the momentary obstack. */
2707 maybe_parmlist:
2708 suspend_mom '(' nonnull_exprlist ')'
2709 { resume_momentary ((int) $<itype>1); $$ = $3; }
2710 | suspend_mom '(' parmlist ')'
2711 { resume_momentary ((int) $<itype>1); $$ = $3; }
2712 | suspend_mom LEFT_RIGHT
2713 { resume_momentary ((int) $<itype>1); $$ = empty_parms (); }
2714 | suspend_mom '(' error ')'
2715 { resume_momentary ((int) $<itype>1); $$ = NULL_TREE; }
2718 /* A declarator that is allowed only after an explicit typespec. */
2720 after_type_declarator_intern:
2721 after_type_declarator
2722 | attributes after_type_declarator
2724 /* Provide support for '(' attributes '*' declarator ')'
2725 etc */
2726 $$ = decl_tree_cons ($1, $2, NULL_TREE);
2730 /* may all be followed by prec '.' */
2731 after_type_declarator:
2732 '*' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY
2733 { $$ = make_pointer_declarator ($2.t, $3); }
2734 | '&' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY
2735 { $$ = make_reference_declarator ($2.t, $3); }
2736 | '*' after_type_declarator_intern %prec UNARY
2737 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2738 | '&' after_type_declarator_intern %prec UNARY
2739 { $$ = make_reference_declarator (NULL_TREE, $2); }
2740 | ptr_to_mem cv_qualifiers after_type_declarator_intern
2741 { tree arg = make_pointer_declarator ($2, $3);
2742 $$ = build_parse_node (SCOPE_REF, $1, arg);
2744 | direct_after_type_declarator
2747 direct_after_type_declarator:
2748 direct_after_type_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
2749 { $$ = make_call_declarator ($$, $2, $3, $4); }
2750 | direct_after_type_declarator '[' nonmomentary_expr ']'
2751 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2752 | direct_after_type_declarator '[' ']'
2753 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2754 | '(' after_type_declarator_intern ')'
2755 { $$ = $2; }
2756 | nested_name_specifier type_name %prec EMPTY
2757 { push_nested_class ($1, 3);
2758 $$ = build_parse_node (SCOPE_REF, $$, $2);
2759 TREE_COMPLEXITY ($$) = current_class_depth; }
2760 | type_name %prec EMPTY
2763 nonnested_type:
2764 type_name %prec EMPTY
2766 if (TREE_CODE ($1) == IDENTIFIER_NODE)
2768 $$ = lookup_name ($1, 1);
2769 maybe_note_name_used_in_class ($1, $$);
2771 else
2772 $$ = $1;
2774 | global_scope type_name
2776 if (TREE_CODE ($2) == IDENTIFIER_NODE)
2777 $$ = IDENTIFIER_GLOBAL_VALUE ($2);
2778 else
2779 $$ = $2;
2780 got_scope = NULL_TREE;
2784 complete_type_name:
2785 nonnested_type
2786 | nested_type
2787 | global_scope nested_type
2788 { $$ = $2; }
2791 nested_type:
2792 nested_name_specifier type_name %prec EMPTY
2793 { $$ = get_type_decl ($2); }
2796 /* A declarator allowed whether or not there has been
2797 an explicit typespec. These cannot redeclare a typedef-name. */
2799 notype_declarator_intern:
2800 notype_declarator
2801 | attributes notype_declarator
2803 /* Provide support for '(' attributes '*' declarator ')'
2804 etc */
2805 $$ = decl_tree_cons ($1, $2, NULL_TREE);
2809 notype_declarator:
2810 '*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
2811 { $$ = make_pointer_declarator ($2.t, $3); }
2812 | '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
2813 { $$ = make_reference_declarator ($2.t, $3); }
2814 | '*' notype_declarator_intern %prec UNARY
2815 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2816 | '&' notype_declarator_intern %prec UNARY
2817 { $$ = make_reference_declarator (NULL_TREE, $2); }
2818 | ptr_to_mem cv_qualifiers notype_declarator_intern
2819 { tree arg = make_pointer_declarator ($2, $3);
2820 $$ = build_parse_node (SCOPE_REF, $1, arg);
2822 | direct_notype_declarator
2825 complex_notype_declarator:
2826 '*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
2827 { $$ = make_pointer_declarator ($2.t, $3); }
2828 | '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
2829 { $$ = make_reference_declarator ($2.t, $3); }
2830 | '*' complex_notype_declarator %prec UNARY
2831 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2832 | '&' complex_notype_declarator %prec UNARY
2833 { $$ = make_reference_declarator (NULL_TREE, $2); }
2834 | ptr_to_mem cv_qualifiers notype_declarator_intern
2835 { tree arg = make_pointer_declarator ($2, $3);
2836 $$ = build_parse_node (SCOPE_REF, $1, arg);
2838 | complex_direct_notype_declarator
2841 complex_direct_notype_declarator:
2842 direct_notype_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
2843 { $$ = make_call_declarator ($$, $2, $3, $4); }
2844 | '(' complex_notype_declarator ')'
2845 { $$ = $2; }
2846 | direct_notype_declarator '[' nonmomentary_expr ']'
2847 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2848 | direct_notype_declarator '[' ']'
2849 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2850 | notype_qualified_id
2851 { enter_scope_of ($1); }
2852 | nested_name_specifier notype_template_declarator
2853 { got_scope = NULL_TREE;
2854 $$ = build_parse_node (SCOPE_REF, $1, $2);
2855 enter_scope_of ($$);
2859 qualified_id:
2860 nested_name_specifier unqualified_id
2861 { got_scope = NULL_TREE;
2862 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2863 | nested_name_specifier object_template_id
2864 { got_scope = NULL_TREE;
2865 $$ = build_parse_node (SCOPE_REF, $1, $2); }
2868 notype_qualified_id:
2869 nested_name_specifier notype_unqualified_id
2870 { got_scope = NULL_TREE;
2871 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2872 | nested_name_specifier object_template_id
2873 { got_scope = NULL_TREE;
2874 $$ = build_parse_node (SCOPE_REF, $1, $2); }
2877 overqualified_id:
2878 notype_qualified_id
2879 | global_scope notype_qualified_id
2880 { $$ = $2; }
2883 functional_cast:
2884 typespec '(' nonnull_exprlist ')'
2885 { $$ = build_functional_cast ($1.t, $3); }
2886 | typespec '(' expr_or_declarator_intern ')'
2887 { $$ = reparse_decl_as_expr ($1.t, $3); }
2888 | typespec fcast_or_absdcl %prec EMPTY
2889 { $$ = reparse_absdcl_as_expr ($1.t, $2); }
2891 type_name:
2892 TYPENAME
2893 | SELFNAME
2894 | template_type %prec EMPTY
2897 nested_name_specifier:
2898 nested_name_specifier_1
2899 | nested_name_specifier nested_name_specifier_1
2900 { $$ = $2; }
2901 | nested_name_specifier TEMPLATE explicit_template_type SCOPE
2902 { got_scope = $$ = make_typename_type ($1, $3); }
2905 /* Why the @#$%^& do type_name and notype_identifier need to be expanded
2906 inline here?!? (jason) */
2907 nested_name_specifier_1:
2908 TYPENAME SCOPE
2910 if (TREE_CODE ($1) == IDENTIFIER_NODE)
2912 $$ = lastiddecl;
2913 maybe_note_name_used_in_class ($1, $$);
2915 got_scope = $$ =
2916 complete_type (TYPE_MAIN_VARIANT (TREE_TYPE ($$)));
2918 | SELFNAME SCOPE
2920 if (TREE_CODE ($1) == IDENTIFIER_NODE)
2921 $$ = lastiddecl;
2922 got_scope = $$ = TREE_TYPE ($$);
2924 | NSNAME SCOPE
2926 if (TREE_CODE ($$) == IDENTIFIER_NODE)
2927 $$ = lastiddecl;
2928 got_scope = $$;
2930 | template_type SCOPE
2931 { got_scope = $$ = complete_type (TREE_TYPE ($1)); }
2932 /* These break 'const i;'
2933 | IDENTIFIER SCOPE
2935 failed_scope:
2936 cp_error ("`%D' is not an aggregate typedef",
2937 lastiddecl ? lastiddecl : $$);
2938 $$ = error_mark_node;
2940 | PTYPENAME SCOPE
2941 { goto failed_scope; } */
2944 typename_sub:
2945 typename_sub0
2946 | global_scope typename_sub0
2947 { $$ = $2; }
2950 typename_sub0:
2951 typename_sub1 identifier %prec EMPTY
2953 if (TREE_CODE_CLASS (TREE_CODE ($1)) == 't')
2954 $$ = make_typename_type ($1, $2);
2955 else if (TREE_CODE ($2) == IDENTIFIER_NODE)
2956 cp_error ("`%T' is not a class or namespace", $2);
2957 else
2959 $$ = $2;
2960 if (TREE_CODE ($$) == TYPE_DECL)
2961 $$ = TREE_TYPE ($$);
2964 | typename_sub1 template_type %prec EMPTY
2965 { $$ = TREE_TYPE ($2); }
2966 | typename_sub1 explicit_template_type %prec EMPTY
2967 { $$ = make_typename_type ($1, $2); }
2968 | typename_sub1 TEMPLATE explicit_template_type %prec EMPTY
2969 { $$ = make_typename_type ($1, $3); }
2972 typename_sub1:
2973 typename_sub2
2975 if (TREE_CODE ($1) == IDENTIFIER_NODE)
2976 cp_error ("`%T' is not a class or namespace", $1);
2978 | typename_sub1 typename_sub2
2980 if (TREE_CODE_CLASS (TREE_CODE ($1)) == 't')
2981 $$ = make_typename_type ($1, $2);
2982 else if (TREE_CODE ($2) == IDENTIFIER_NODE)
2983 cp_error ("`%T' is not a class or namespace", $2);
2984 else
2986 $$ = $2;
2987 if (TREE_CODE ($$) == TYPE_DECL)
2988 $$ = TREE_TYPE ($$);
2991 | typename_sub1 explicit_template_type SCOPE
2992 { got_scope = $$ = make_typename_type ($1, $2); }
2993 | typename_sub1 TEMPLATE explicit_template_type SCOPE
2994 { got_scope = $$ = make_typename_type ($1, $3); }
2997 typename_sub2:
2998 TYPENAME SCOPE
3000 if (TREE_CODE ($1) != IDENTIFIER_NODE)
3001 $1 = lastiddecl;
3003 /* Retrieve the type for the identifier, which might involve
3004 some computation. */
3005 got_scope = $$ = complete_type (IDENTIFIER_TYPE_VALUE ($1));
3007 if ($$ == error_mark_node)
3008 cp_error ("`%T' is not a class or namespace", $1);
3010 | SELFNAME SCOPE
3012 if (TREE_CODE ($1) != IDENTIFIER_NODE)
3013 $$ = lastiddecl;
3014 got_scope = $$ = complete_type (TREE_TYPE ($$));
3016 | template_type SCOPE
3017 { got_scope = $$ = complete_type (TREE_TYPE ($$)); }
3018 | PTYPENAME SCOPE
3019 | IDENTIFIER SCOPE
3020 | NSNAME SCOPE
3022 if (TREE_CODE ($$) == IDENTIFIER_NODE)
3023 $$ = lastiddecl;
3024 got_scope = $$;
3028 explicit_template_type:
3029 identifier '<' template_arg_list_opt template_close_bracket
3030 { $$ = build_min_nt (TEMPLATE_ID_EXPR, $1, $3); }
3033 complex_type_name:
3034 global_scope type_name
3036 if (TREE_CODE ($2) == IDENTIFIER_NODE)
3037 $$ = IDENTIFIER_GLOBAL_VALUE ($2);
3038 else
3039 $$ = $2;
3040 got_scope = NULL_TREE;
3042 | nested_type
3043 | global_scope nested_type
3044 { $$ = $2; }
3047 ptr_to_mem:
3048 nested_name_specifier '*'
3049 { got_scope = NULL_TREE; }
3050 | global_scope nested_name_specifier '*'
3051 { $$ = $2; got_scope = NULL_TREE; }
3054 /* All uses of explicit global scope must go through this nonterminal so
3055 that got_scope will be set before yylex is called to get the next token. */
3056 global_scope:
3057 SCOPE
3058 { got_scope = void_type_node; }
3061 /* ANSI new-declarator (5.3.4) */
3062 new_declarator:
3063 '*' cv_qualifiers new_declarator
3064 { $$ = make_pointer_declarator ($2, $3); }
3065 | '*' cv_qualifiers %prec EMPTY
3066 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3067 | '&' cv_qualifiers new_declarator %prec EMPTY
3068 { $$ = make_reference_declarator ($2, $3); }
3069 | '&' cv_qualifiers %prec EMPTY
3070 { $$ = make_reference_declarator ($2, NULL_TREE); }
3071 | ptr_to_mem cv_qualifiers %prec EMPTY
3072 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3073 $$ = build_parse_node (SCOPE_REF, $1, arg);
3075 | ptr_to_mem cv_qualifiers new_declarator
3076 { tree arg = make_pointer_declarator ($2, $3);
3077 $$ = build_parse_node (SCOPE_REF, $1, arg);
3079 | direct_new_declarator %prec EMPTY
3082 /* ANSI direct-new-declarator (5.3.4) */
3083 direct_new_declarator:
3084 '[' expr ']'
3085 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3086 | direct_new_declarator '[' nonmomentary_expr ']'
3087 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3090 absdcl_intern:
3091 absdcl
3092 | attributes absdcl
3094 /* Provide support for '(' attributes '*' declarator ')'
3095 etc */
3096 $$ = decl_tree_cons ($1, $2, NULL_TREE);
3100 /* ANSI abstract-declarator (8.1) */
3101 absdcl:
3102 '*' nonempty_cv_qualifiers absdcl_intern
3103 { $$ = make_pointer_declarator ($2.t, $3); }
3104 | '*' absdcl_intern
3105 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3106 | '*' nonempty_cv_qualifiers %prec EMPTY
3107 { $$ = make_pointer_declarator ($2.t, NULL_TREE); }
3108 | '*' %prec EMPTY
3109 { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
3110 | '&' nonempty_cv_qualifiers absdcl_intern
3111 { $$ = make_reference_declarator ($2.t, $3); }
3112 | '&' absdcl_intern
3113 { $$ = make_reference_declarator (NULL_TREE, $2); }
3114 | '&' nonempty_cv_qualifiers %prec EMPTY
3115 { $$ = make_reference_declarator ($2.t, NULL_TREE); }
3116 | '&' %prec EMPTY
3117 { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
3118 | ptr_to_mem cv_qualifiers %prec EMPTY
3119 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3120 $$ = build_parse_node (SCOPE_REF, $1, arg);
3122 | ptr_to_mem cv_qualifiers absdcl_intern
3123 { tree arg = make_pointer_declarator ($2, $3);
3124 $$ = build_parse_node (SCOPE_REF, $1, arg);
3126 | direct_abstract_declarator %prec EMPTY
3129 /* ANSI direct-abstract-declarator (8.1) */
3130 direct_abstract_declarator:
3131 '(' absdcl_intern ')'
3132 { $$ = $2; }
3133 /* `(typedef)1' is `int'. */
3134 | direct_abstract_declarator '(' parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
3135 { $$ = make_call_declarator ($$, $3, $5, $6); }
3136 | direct_abstract_declarator LEFT_RIGHT cv_qualifiers exception_specification_opt %prec '.'
3137 { $$ = make_call_declarator ($$, empty_parms (), $3, $4); }
3138 | direct_abstract_declarator '[' nonmomentary_expr ']' %prec '.'
3139 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3140 | direct_abstract_declarator '[' ']' %prec '.'
3141 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
3142 | '(' complex_parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
3143 { $$ = make_call_declarator (NULL_TREE, $2, $4, $5); }
3144 | regcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
3145 { set_quals_and_spec ($$, $2, $3); }
3146 | fcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
3147 { set_quals_and_spec ($$, $2, $3); }
3148 | '[' nonmomentary_expr ']' %prec '.'
3149 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3150 | '[' ']' %prec '.'
3151 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
3154 /* For C++, decls and stmts can be intermixed, so we don't need to
3155 have a special rule that won't start parsing the stmt section
3156 until we have a stmt that parses without errors. */
3158 stmts:
3159 stmt
3160 | errstmt
3161 | stmts stmt
3162 | stmts errstmt
3165 errstmt:
3166 error ';'
3169 /* Read zero or more forward-declarations for labels
3170 that nested functions can jump to. */
3171 maybe_label_decls:
3172 /* empty */
3173 | label_decls
3174 { if (pedantic)
3175 pedwarn ("ANSI C++ forbids label declarations"); }
3178 label_decls:
3179 label_decl
3180 | label_decls label_decl
3183 label_decl:
3184 LABEL identifiers_or_typenames ';'
3186 while ($2)
3188 finish_label_decl (TREE_VALUE ($2));
3189 $2 = TREE_CHAIN ($2);
3194 /* This is the body of a function definition.
3195 It causes syntax errors to ignore to the next openbrace. */
3196 compstmt_or_error:
3197 compstmt
3199 | error compstmt
3202 compstmt:
3204 { $<ttype>$ = begin_compound_stmt (0); }
3205 compstmtend
3206 { $$ = finish_compound_stmt (0, $<ttype>2); }
3209 simple_if:
3212 $<ttype>$ = begin_if_stmt ();
3213 cond_stmt_keyword = "if";
3215 paren_cond_or_null
3216 { finish_if_stmt_cond ($3, $<ttype>2); }
3217 implicitly_scoped_stmt
3218 { $<ttype>$ = finish_then_clause ($<ttype>2); }
3221 implicitly_scoped_stmt:
3222 compstmt
3223 | { $<ttype>$ = begin_compound_stmt (0); }
3224 simple_stmt
3225 { $$ = finish_compound_stmt (0, $<ttype>1); }
3228 stmt:
3229 compstmt
3231 | simple_stmt
3234 simple_stmt:
3235 decl
3236 { finish_stmt (); }
3237 | expr ';'
3238 { finish_expr_stmt ($1); }
3239 | simple_if ELSE
3240 { begin_else_clause (); }
3241 implicitly_scoped_stmt
3243 finish_else_clause ($<ttype>1);
3244 finish_if_stmt ();
3246 | simple_if %prec IF
3247 { finish_if_stmt (); }
3248 | WHILE
3250 $<ttype>$ = begin_while_stmt ();
3251 cond_stmt_keyword = "while";
3253 paren_cond_or_null
3254 { finish_while_stmt_cond ($3, $<ttype>2); }
3255 already_scoped_stmt
3256 { finish_while_stmt ($<ttype>2); }
3257 | DO
3258 { $<ttype>$ = begin_do_stmt (); }
3259 implicitly_scoped_stmt WHILE
3261 finish_do_body ($<ttype>2);
3262 cond_stmt_keyword = "do";
3264 paren_expr_or_null ';'
3265 { finish_do_stmt ($6, $<ttype>2); }
3266 | FOR
3267 { $<ttype>$ = begin_for_stmt (); }
3268 '(' for.init.statement
3269 { finish_for_init_stmt ($<ttype>2); }
3270 xcond ';'
3271 { finish_for_cond ($6, $<ttype>2); }
3272 xexpr ')'
3273 { finish_for_expr ($9, $<ttype>2); }
3274 already_scoped_stmt
3275 { finish_for_stmt ($9, $<ttype>2); }
3276 | SWITCH
3277 { $<ttype>$ = begin_switch_stmt (); }
3278 '(' condition ')'
3279 { finish_switch_cond ($4, $<ttype>2); }
3280 implicitly_scoped_stmt
3281 { finish_switch_stmt ($4, $<ttype>6); }
3282 | CASE expr_no_commas ':'
3283 { finish_case_label ($2, NULL_TREE); }
3284 stmt
3285 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
3286 { finish_case_label ($2, $4); }
3287 stmt
3288 | DEFAULT ':'
3289 { finish_case_label (NULL_TREE, NULL_TREE); }
3290 stmt
3291 | BREAK ';'
3292 { finish_break_stmt (); }
3293 | CONTINUE ';'
3294 { finish_continue_stmt (); }
3295 | RETURN_KEYWORD ';'
3296 { finish_return_stmt (NULL_TREE); }
3297 | RETURN_KEYWORD expr ';'
3298 { finish_return_stmt ($2); }
3299 | asm_keyword maybe_cv_qualifier '(' string ')' ';'
3301 finish_asm_stmt ($2, $4, NULL_TREE, NULL_TREE,
3302 NULL_TREE);
3304 /* This is the case with just output operands. */
3305 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ')' ';'
3307 finish_asm_stmt ($2, $4, $6, NULL_TREE,
3308 NULL_TREE);
3310 /* This is the case with input operands as well. */
3311 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':' asm_operands ')' ';'
3312 { finish_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
3313 /* This is the case with clobbered registers as well. */
3314 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':'
3315 asm_operands ':' asm_clobbers ')' ';'
3316 { finish_asm_stmt ($2, $4, $6, $8, $10); }
3317 | GOTO '*' expr ';'
3319 if (pedantic)
3320 pedwarn ("ANSI C++ forbids computed gotos");
3321 finish_goto_stmt ($3);
3323 | GOTO identifier ';'
3324 { finish_goto_stmt ($2); }
3325 | label_colon stmt
3326 { finish_stmt (); }
3327 | label_colon '}'
3328 { error ("label must be followed by statement");
3329 yyungetc ('}', 0);
3330 finish_stmt (); }
3331 | ';'
3332 { finish_stmt (); }
3333 | try_block
3334 | using_directive
3335 | namespace_using_decl
3336 { do_local_using_decl ($1); }
3337 | namespace_alias
3340 function_try_block:
3342 { $<ttype>$ = begin_function_try_block (); }
3343 ctor_initializer_opt compstmt
3344 { finish_function_try_block ($<ttype>2); }
3345 handler_seq
3347 finish_function_handler_sequence ($<ttype>2);
3348 $$ = $3;
3352 try_block:
3354 { $<ttype>$ = begin_try_block (); }
3355 compstmt
3356 { finish_try_block ($<ttype>2); }
3357 handler_seq
3358 { finish_handler_sequence ($<ttype>2); }
3361 handler_seq:
3362 handler
3363 | handler_seq handler
3366 handler:
3367 CATCH
3368 { $<ttype>$ = begin_handler(); }
3369 handler_args
3370 { finish_handler_parms ($<ttype>2); }
3371 compstmt
3372 { finish_handler ($<ttype>2); }
3375 type_specifier_seq:
3376 typed_typespecs %prec EMPTY
3377 | nonempty_cv_qualifiers %prec EMPTY
3380 handler_args:
3381 '(' ELLIPSIS ')'
3382 { expand_start_catch_block (NULL_TREE); }
3383 /* This doesn't allow reference parameters, the below does.
3384 | '(' type_specifier_seq absdcl ')'
3385 { check_for_new_type ("inside exception declarations", $2);
3386 expand_start_catch_block ($2.t, $3); }
3387 | '(' type_specifier_seq ')'
3388 { check_for_new_type ("inside exception declarations", $2);
3389 expand_start_catch_block ($2.t, NULL_TREE); }
3390 | '(' type_specifier_seq notype_declarator ')'
3391 { check_for_new_type ("inside exception declarations", $2);
3392 expand_start_catch_block ($2.t, $3); }
3393 | '(' typed_typespecs after_type_declarator ')'
3394 { check_for_new_type ("inside exception declarations", $2);
3395 expand_start_catch_block ($2.t, $3); }
3396 This allows reference parameters... */
3397 | '(' parm ')'
3399 check_for_new_type ("inside exception declarations", $2);
3400 start_handler_parms (TREE_PURPOSE ($2.t),
3401 TREE_VALUE ($2.t));
3405 label_colon:
3406 IDENTIFIER ':'
3407 { finish_label_stmt ($1); }
3408 | PTYPENAME ':'
3409 { finish_label_stmt ($1); }
3410 | TYPENAME ':'
3411 { finish_label_stmt ($1); }
3412 | SELFNAME ':'
3413 { finish_label_stmt ($1); }
3416 for.init.statement:
3417 xexpr ';'
3418 { finish_expr_stmt ($1); }
3419 | decl
3420 | '{' compstmtend
3421 { if (pedantic)
3422 pedwarn ("ANSI C++ forbids compound statements inside for initializations");
3426 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
3428 maybe_cv_qualifier:
3429 /* empty */
3430 { emit_line_note (input_filename, lineno);
3431 $$ = NULL_TREE; }
3432 | CV_QUALIFIER
3433 { emit_line_note (input_filename, lineno); }
3436 xexpr:
3437 /* empty */
3438 { $$ = NULL_TREE; }
3439 | expr
3440 | error
3441 { $$ = NULL_TREE; }
3444 /* These are the operands other than the first string and colon
3445 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
3446 asm_operands:
3447 /* empty */
3448 { $$ = NULL_TREE; }
3449 | nonnull_asm_operands
3452 nonnull_asm_operands:
3453 asm_operand
3454 | nonnull_asm_operands ',' asm_operand
3455 { $$ = chainon ($$, $3); }
3458 asm_operand:
3459 STRING '(' expr ')'
3460 { $$ = build_tree_list ($$, $3); }
3463 asm_clobbers:
3464 STRING
3465 { $$ = tree_cons (NULL_TREE, $$, NULL_TREE); }
3466 | asm_clobbers ',' STRING
3467 { $$ = tree_cons (NULL_TREE, $3, $$); }
3470 /* This is what appears inside the parens in a function declarator.
3471 Its value is represented in the format that grokdeclarator expects.
3473 In C++, declaring a function with no parameters
3474 means that that function takes *no* parameters. */
3476 parmlist:
3477 /* empty */
3479 $$ = empty_parms();
3481 | complex_parmlist
3482 | type_id
3483 { $$ = finish_parmlist (build_tree_list (NULL_TREE, $1.t), 0);
3484 check_for_new_type ("inside parameter list", $1); }
3487 /* This nonterminal does not include the common sequence '(' type_id ')',
3488 as it is ambiguous and must be disambiguated elsewhere. */
3489 complex_parmlist:
3490 parms
3491 { $$ = finish_parmlist ($$, 0); }
3492 | parms_comma ELLIPSIS
3493 { $$ = finish_parmlist ($1, 1); }
3494 /* C++ allows an ellipsis without a separating ',' */
3495 | parms ELLIPSIS
3496 { $$ = finish_parmlist ($1, 1); }
3497 | type_id ELLIPSIS
3498 { $$ = finish_parmlist (build_tree_list (NULL_TREE,
3499 $1.t), 1); }
3500 | ELLIPSIS
3501 { $$ = finish_parmlist (NULL_TREE, 1); }
3502 | parms ':'
3504 /* This helps us recover from really nasty
3505 parse errors, for example, a missing right
3506 parenthesis. */
3507 yyerror ("possibly missing ')'");
3508 $$ = finish_parmlist ($1, 0);
3509 yyungetc (':', 0);
3510 yychar = ')';
3512 | type_id ':'
3514 /* This helps us recover from really nasty
3515 parse errors, for example, a missing right
3516 parenthesis. */
3517 yyerror ("possibly missing ')'");
3518 $$ = finish_parmlist (build_tree_list (NULL_TREE,
3519 $1.t), 0);
3520 yyungetc (':', 0);
3521 yychar = ')';
3525 /* A default argument to a */
3526 defarg:
3528 { maybe_snarf_defarg (); }
3529 defarg1
3530 { $$ = $3; }
3533 defarg1:
3534 DEFARG
3535 | init
3538 /* A nonempty list of parameter declarations or type names. */
3539 parms:
3540 named_parm
3541 { check_for_new_type ("in a parameter list", $1);
3542 $$ = build_tree_list (NULL_TREE, $1.t); }
3543 | parm defarg
3544 { check_for_new_type ("in a parameter list", $1);
3545 $$ = build_tree_list ($2, $1.t); }
3546 | parms_comma full_parm
3547 { check_for_new_type ("in a parameter list", $2);
3548 $$ = chainon ($$, $2.t); }
3549 | parms_comma bad_parm
3550 { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
3551 | parms_comma bad_parm '=' init
3552 { $$ = chainon ($$, build_tree_list ($4, $2)); }
3555 parms_comma:
3556 parms ','
3557 | type_id ','
3558 { check_for_new_type ("in a parameter list", $1);
3559 $$ = build_tree_list (NULL_TREE, $1.t); }
3562 /* A single parameter declaration or parameter type name,
3563 as found in a parmlist. */
3564 named_parm:
3565 /* Here we expand typed_declspecs inline to avoid mis-parsing of
3566 TYPESPEC IDENTIFIER. */
3567 typed_declspecs1 declarator
3568 { tree specs = strip_attrs ($1.t);
3569 $$.new_type_flag = $1.new_type_flag;
3570 $$.t = build_tree_list (specs, $2); }
3571 | typed_typespecs declarator
3572 { $$.t = build_tree_list ($1.t, $2);
3573 $$.new_type_flag = $1.new_type_flag; }
3574 | typespec declarator
3575 { $$.t = build_tree_list (build_decl_list (NULL_TREE, $1.t),
3576 $2);
3577 $$.new_type_flag = $1.new_type_flag; }
3578 | typed_declspecs1 absdcl
3579 { tree specs = strip_attrs ($1.t);
3580 $$.t = build_tree_list (specs, $2);
3581 $$.new_type_flag = $1.new_type_flag; }
3582 | typed_declspecs1 %prec EMPTY
3583 { tree specs = strip_attrs ($1.t);
3584 $$.t = build_tree_list (specs, NULL_TREE);
3585 $$.new_type_flag = $1.new_type_flag; }
3586 | declmods notype_declarator
3587 { tree specs = strip_attrs ($1);
3588 $$.t = build_tree_list (specs, $2);
3589 $$.new_type_flag = 0; }
3592 full_parm:
3593 parm
3594 { $$.t = build_tree_list (NULL_TREE, $1.t);
3595 $$.new_type_flag = $1.new_type_flag; }
3596 | parm defarg
3597 { $$.t = build_tree_list ($2, $1.t);
3598 $$.new_type_flag = $1.new_type_flag; }
3601 parm:
3602 named_parm
3603 | type_id
3606 see_typename:
3607 /* empty */ %prec EMPTY
3608 { see_typename (); }
3611 bad_parm:
3612 /* empty */ %prec EMPTY
3614 error ("type specifier omitted for parameter");
3615 $$ = build_tree_list (integer_type_node, NULL_TREE);
3617 | notype_declarator
3619 error ("type specifier omitted for parameter");
3620 if (TREE_CODE ($$) == SCOPE_REF
3621 && (TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TYPE_PARM
3622 || TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TEMPLATE_PARM))
3623 cp_error (" perhaps you want `typename %E' to make it a type", $$);
3624 $$ = build_tree_list (integer_type_node, $$);
3628 exception_specification_opt:
3629 /* empty */ %prec EMPTY
3630 { $$ = NULL_TREE; }
3631 | THROW '(' ansi_raise_identifiers ')' %prec EMPTY
3632 { $$ = $3; }
3633 | THROW LEFT_RIGHT %prec EMPTY
3634 { $$ = empty_except_spec; }
3637 ansi_raise_identifier:
3638 type_id
3640 check_for_new_type ("exception specifier", $1);
3641 $$ = groktypename ($1.t);
3645 ansi_raise_identifiers:
3646 ansi_raise_identifier
3647 { $$ = add_exception_specifier (NULL_TREE, $1, 1); }
3648 | ansi_raise_identifiers ',' ansi_raise_identifier
3649 { $$ = add_exception_specifier ($1, $3, 1); }
3652 conversion_declarator:
3653 /* empty */ %prec EMPTY
3654 { $$ = NULL_TREE; }
3655 | '*' cv_qualifiers conversion_declarator
3656 { $$ = make_pointer_declarator ($2, $3); }
3657 | '&' cv_qualifiers conversion_declarator
3658 { $$ = make_reference_declarator ($2, $3); }
3659 | ptr_to_mem cv_qualifiers conversion_declarator
3660 { tree arg = make_pointer_declarator ($2, $3);
3661 $$ = build_parse_node (SCOPE_REF, $1, arg);
3665 operator:
3666 OPERATOR
3667 { got_scope = NULL_TREE; }
3670 operator_name:
3671 operator '*'
3672 { $$ = ansi_opname[MULT_EXPR]; }
3673 | operator '/'
3674 { $$ = ansi_opname[TRUNC_DIV_EXPR]; }
3675 | operator '%'
3676 { $$ = ansi_opname[TRUNC_MOD_EXPR]; }
3677 | operator '+'
3678 { $$ = ansi_opname[PLUS_EXPR]; }
3679 | operator '-'
3680 { $$ = ansi_opname[MINUS_EXPR]; }
3681 | operator '&'
3682 { $$ = ansi_opname[BIT_AND_EXPR]; }
3683 | operator '|'
3684 { $$ = ansi_opname[BIT_IOR_EXPR]; }
3685 | operator '^'
3686 { $$ = ansi_opname[BIT_XOR_EXPR]; }
3687 | operator '~'
3688 { $$ = ansi_opname[BIT_NOT_EXPR]; }
3689 | operator ','
3690 { $$ = ansi_opname[COMPOUND_EXPR]; }
3691 | operator ARITHCOMPARE
3692 { $$ = ansi_opname[$2]; }
3693 | operator '<'
3694 { $$ = ansi_opname[LT_EXPR]; }
3695 | operator '>'
3696 { $$ = ansi_opname[GT_EXPR]; }
3697 | operator EQCOMPARE
3698 { $$ = ansi_opname[$2]; }
3699 | operator ASSIGN
3700 { $$ = ansi_assopname[$2]; }
3701 | operator '='
3702 { $$ = ansi_opname [MODIFY_EXPR]; }
3703 | operator LSHIFT
3704 { $$ = ansi_opname[$2]; }
3705 | operator RSHIFT
3706 { $$ = ansi_opname[$2]; }
3707 | operator PLUSPLUS
3708 { $$ = ansi_opname[POSTINCREMENT_EXPR]; }
3709 | operator MINUSMINUS
3710 { $$ = ansi_opname[PREDECREMENT_EXPR]; }
3711 | operator ANDAND
3712 { $$ = ansi_opname[TRUTH_ANDIF_EXPR]; }
3713 | operator OROR
3714 { $$ = ansi_opname[TRUTH_ORIF_EXPR]; }
3715 | operator '!'
3716 { $$ = ansi_opname[TRUTH_NOT_EXPR]; }
3717 | operator '?' ':'
3718 { $$ = ansi_opname[COND_EXPR]; }
3719 | operator MIN_MAX
3720 { $$ = ansi_opname[$2]; }
3721 | operator POINTSAT %prec EMPTY
3722 { $$ = ansi_opname[COMPONENT_REF]; }
3723 | operator POINTSAT_STAR %prec EMPTY
3724 { $$ = ansi_opname[MEMBER_REF]; }
3725 | operator LEFT_RIGHT
3726 { $$ = ansi_opname[CALL_EXPR]; }
3727 | operator '[' ']'
3728 { $$ = ansi_opname[ARRAY_REF]; }
3729 | operator NEW %prec EMPTY
3730 { $$ = ansi_opname[NEW_EXPR]; }
3731 | operator DELETE %prec EMPTY
3732 { $$ = ansi_opname[DELETE_EXPR]; }
3733 | operator NEW '[' ']'
3734 { $$ = ansi_opname[VEC_NEW_EXPR]; }
3735 | operator DELETE '[' ']'
3736 { $$ = ansi_opname[VEC_DELETE_EXPR]; }
3737 /* Names here should be looked up in class scope ALSO. */
3738 | operator type_specifier_seq conversion_declarator
3739 { $$ = grokoptypename ($2.t, $3); }
3740 | operator error
3741 { $$ = ansi_opname[ERROR_MARK]; }
3746 #ifdef SPEW_DEBUG
3747 const char *
3748 debug_yytranslate (value)
3749 int value;
3751 return yytname[YYTRANSLATE (value)];
3754 #endif