Use -static when testing --gc-sections on native targets
[official-gcc.git] / gcc / cp / parse.y
blobd1d2c1648259b00cb94ef624f91bf5917dbf5494
1 /* YACC parser for C++ syntax.
2 Copyright (C) 1988, 89, 93-98, 1999, 2000 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 PARAMS ((void));
66 static void parse_decl PARAMS ((tree, 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 static inline tree
74 empty_parms ()
76 tree parms;
78 if (strict_prototype
79 || current_class_type != NULL)
80 parms = void_list_node;
81 else
82 parms = NULL_TREE;
83 return parms;
88 %start program
90 %union {
91 long itype;
92 tree ttype;
93 char *strtype;
94 enum tree_code code;
95 flagged_type_tree ftype;
96 struct pending_inline *pi;
99 /* All identifiers that are not reserved words
100 and are not declared typedefs in the current block */
101 %token IDENTIFIER
103 /* All identifiers that are declared typedefs in the current block.
104 In some contexts, they are treated just like IDENTIFIER,
105 but they can also serve as typespecs in declarations. */
106 %token TYPENAME
107 %token SELFNAME
109 /* A template function. */
110 %token PFUNCNAME
112 /* Reserved words that specify storage class.
113 yylval contains an IDENTIFIER_NODE which indicates which one. */
114 %token SCSPEC
116 /* Reserved words that specify type.
117 yylval contains an IDENTIFIER_NODE which indicates which one. */
118 %token TYPESPEC
120 /* Reserved words that qualify type: "const" or "volatile".
121 yylval contains an IDENTIFIER_NODE which indicates which one. */
122 %token CV_QUALIFIER
124 /* Character or numeric constants.
125 yylval is the node for the constant. */
126 %token CONSTANT
128 /* String constants in raw form.
129 yylval is a STRING_CST node. */
130 %token STRING
132 /* "...", used for functions with variable arglists. */
133 %token ELLIPSIS
135 /* the reserved words */
136 /* SCO include files test "ASM", so use something else. */
137 %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
138 %token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF
139 %token SIGOF
140 %token ATTRIBUTE EXTENSION LABEL
141 %token REALPART IMAGPART VA_ARG
143 /* the reserved words... C++ extensions */
144 %token <ttype> AGGR
145 %token <ttype> VISSPEC
146 %token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE
147 %token NAMESPACE TYPENAME_KEYWORD USING
148 %token LEFT_RIGHT TEMPLATE
149 %token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
150 %token <itype> SCOPE
152 /* Define the operator tokens and their precedences.
153 The value is an integer because, if used, it is the tree code
154 to use in the expression made from the operator. */
156 %left EMPTY /* used to resolve s/r with epsilon */
158 %left error
160 /* Add precedence rules to solve dangling else s/r conflict */
161 %nonassoc IF
162 %nonassoc ELSE
164 %left IDENTIFIER PFUNCNAME TYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD
166 %left '{' ',' ';'
168 %nonassoc THROW
169 %right <code> ':'
170 %right <code> ASSIGN '='
171 %right <code> '?'
172 %left <code> OROR
173 %left <code> ANDAND
174 %left <code> '|'
175 %left <code> '^'
176 %left <code> '&'
177 %left <code> MIN_MAX
178 %left <code> EQCOMPARE
179 %left <code> ARITHCOMPARE '<' '>'
180 %left <code> LSHIFT RSHIFT
181 %left <code> '+' '-'
182 %left <code> '*' '/' '%'
183 %left <code> POINTSAT_STAR DOT_STAR
184 %right <code> UNARY PLUSPLUS MINUSMINUS '~'
185 %left HYPERUNARY
186 %left <ttype> LEFT_RIGHT
187 %left <code> POINTSAT '.' '(' '['
189 %right SCOPE /* C++ extension */
190 %nonassoc NEW DELETE TRY CATCH
192 %type <code> unop
194 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist
195 %type <ttype> PFUNCNAME maybe_identifier
196 %type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
197 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
198 %type <ttype> reserved_declspecs boolean.literal
199 %type <ttype> reserved_typespecquals
200 %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
201 %type <ttype> init initlist maybeasm maybe_init defarg defarg1
202 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
203 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
204 %type <ttype> any_word
206 %type <ttype> compstmt implicitly_scoped_stmt
208 %type <ttype> declarator notype_declarator after_type_declarator
209 %type <ttype> notype_declarator_intern absdcl_intern
210 %type <ttype> after_type_declarator_intern
211 %type <ttype> direct_notype_declarator direct_after_type_declarator
212 %type <itype> components notype_components
213 %type <ttype> component_decl component_decl_1
214 %type <ttype> component_declarator component_declarator0
215 %type <ttype> notype_component_declarator notype_component_declarator0
216 %type <ttype> after_type_component_declarator after_type_component_declarator0
217 %type <ttype> absdcl cv_qualifiers
218 %type <ttype> direct_abstract_declarator conversion_declarator
219 %type <ttype> new_declarator direct_new_declarator
220 %type <ttype> xexpr parmlist parms bad_parm
221 %type <ttype> identifiers_or_typenames
222 %type <ttype> fcast_or_absdcl regcast_or_absdcl
223 %type <ttype> expr_or_declarator expr_or_declarator_intern
224 %type <ttype> complex_notype_declarator
225 %type <ttype> notype_unqualified_id unqualified_id qualified_id
226 %type <ttype> template_id do_id object_template_id notype_template_declarator
227 %type <ttype> overqualified_id notype_qualified_id any_id
228 %type <ttype> complex_direct_notype_declarator functional_cast
229 %type <ttype> complex_parmlist parms_comma
230 %type <ttype> namespace_qualifier namespace_using_decl
232 %type <ftype> type_id new_type_id typed_typespecs typespec typed_declspecs
233 %type <ftype> typed_declspecs1 type_specifier_seq nonempty_cv_qualifiers
234 %type <ftype> structsp typespecqual_reserved parm named_parm full_parm
235 %type <ftype> declmods
237 %type <itype> extension
239 /* C++ extensions */
240 %token <ttype> PTYPENAME
241 %token <ttype> EXTERN_LANG_STRING ALL
242 %token <ttype> PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER
243 %token <pi> PRE_PARSED_FUNCTION_DECL
244 %type <ttype> component_constructor_declarator
245 %type <ttype> fn.def2 return_id constructor_declarator
246 %type <pi> fn.defpen
247 %type <itype> ctor_initializer_opt function_try_block
248 %type <ttype> named_class_head_sans_basetype
249 %type <ftype> class_head named_class_head
250 %type <ftype> named_complex_class_head_sans_basetype
251 %type <ttype> unnamed_class_head
252 %type <ttype> base_class_list
253 %type <ttype> base_class_access_list
254 %type <ttype> base_class maybe_base_class_list base_class.1
255 %type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers
256 %type <ttype> operator_name
257 %type <ttype> object aggr
258 %type <itype> new delete
259 /* %type <ttype> primary_no_id */
260 %type <ttype> maybe_parmlist
261 %type <itype> member_init_list
262 %type <ttype> template_header template_parm_list template_parm
263 %type <ttype> template_type_parm template_template_parm
264 %type <code> template_close_bracket
265 %type <ttype> apparent_template_type
266 %type <ttype> template_type template_arg_list template_arg_list_opt
267 %type <ttype> template_arg
268 %type <ttype> condition xcond paren_cond_or_null
269 %type <ttype> type_name nested_name_specifier nested_type ptr_to_mem
270 %type <ttype> complete_type_name notype_identifier nonnested_type
271 %type <ttype> complex_type_name nested_name_specifier_1
272 %type <ttype> new_initializer new_placement
273 %type <ttype> using_decl
274 %type <ttype> typename_sub typename_sub0 typename_sub1 typename_sub2
275 %type <ttype> explicit_template_type
276 /* in order to recognize aggr tags as defining and thus shadowing. */
277 %token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
278 %type <ttype> named_class_head_sans_basetype_defn
279 %type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN
280 %type <ttype> handler_args
281 %type <ttype> self_template_type .finish_template_type
283 %token NSNAME
284 %type <ttype> NSNAME
286 /* Used in lex.c for parsing pragmas. */
287 %token END_OF_LINE
289 /* lex.c and pt.c depend on this being the last token. Define
290 any new tokens before this one! */
291 %token END_OF_SAVED_INPUT
294 /* List of types and structure classes of the current declaration. */
295 static tree current_declspecs;
297 /* List of prefix attributes in effect.
298 Prefix attributes are parsed by the reserved_declspecs and declmods
299 rules. They create a list that contains *both* declspecs and attrs. */
300 /* ??? It is not clear yet that all cases where an attribute can now appear in
301 a declspec list have been updated. */
302 static tree prefix_attributes;
304 /* When defining an aggregate, this is the kind of the most recent one
305 being defined. (For example, this might be class_type_node.) */
306 static tree current_aggr;
308 /* When defining an enumeration, this is the type of the enumeration. */
309 static tree current_enum_type;
311 /* Tell yyparse how to print a token's value, if yydebug is set. */
313 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
314 extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
315 extern tree combine_strings PARAMS ((tree));
317 static void
318 parse_decl (declarator, specs_attrs, lookups, attributes, initialized, decl)
319 tree declarator;
320 tree specs_attrs;
321 tree lookups;
322 tree attributes;
323 int initialized;
324 tree* decl;
326 initial_deferred_type_access_control (lookups);
328 split_specs_attrs (specs_attrs, &current_declspecs, &prefix_attributes);
329 if (current_declspecs
330 && TREE_CODE (current_declspecs) != TREE_LIST)
331 current_declspecs = build_decl_list (NULL_TREE, current_declspecs);
332 if (have_extern_spec && !used_extern_spec)
334 current_declspecs = decl_tree_cons (NULL_TREE,
335 get_identifier ("extern"),
336 current_declspecs);
337 used_extern_spec = 1;
339 *decl = start_decl (declarator, current_declspecs, initialized,
340 attributes, prefix_attributes);
343 void
344 cp_parse_init ()
346 ggc_add_tree_root (&current_declspecs, 1);
347 ggc_add_tree_root (&prefix_attributes, 1);
348 ggc_add_tree_root (&current_aggr, 1);
349 ggc_add_tree_root (&current_enum_type, 1);
354 program:
355 /* empty */
356 | extdefs
357 { finish_translation_unit (); }
360 /* the reason for the strange actions in this rule
361 is so that notype_initdecls when reached via datadef
362 can find a valid list of type and sc specs in $0. */
364 extdefs:
365 { $<ttype>$ = NULL_TREE; }
366 lang_extdef
367 { $<ttype>$ = NULL_TREE; }
368 | extdefs lang_extdef
369 { $<ttype>$ = NULL_TREE; }
372 extdefs_opt:
373 extdefs
374 | /* empty */
377 .hush_warning:
378 { have_extern_spec = 1;
379 used_extern_spec = 0;
380 $<ttype>$ = NULL_TREE; }
382 .warning_ok:
383 { have_extern_spec = 0; }
386 extension:
387 EXTENSION
388 { $$ = pedantic;
389 pedantic = 0; }
392 asm_keyword:
393 ASM_KEYWORD
396 lang_extdef:
397 { if (pending_lang_change) do_pending_lang_change();
398 type_lookups = NULL_TREE; }
399 extdef
400 { if (! toplevel_bindings_p ())
401 pop_everything (); }
404 extdef:
405 fndef eat_saved_input
406 { if (pending_inlines) do_pending_inlines (); }
407 | datadef
408 { if (pending_inlines) do_pending_inlines (); }
409 | template_def
410 { if (pending_inlines) do_pending_inlines (); }
411 | asm_keyword '(' string ')' ';'
412 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
413 assemble_asm ($3); }
414 | extern_lang_string '{' extdefs_opt '}'
415 { pop_lang_context (); }
416 | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
417 { if (pending_inlines) do_pending_inlines ();
418 pop_lang_context (); }
419 | extern_lang_string .hush_warning datadef .warning_ok
420 { if (pending_inlines) do_pending_inlines ();
421 pop_lang_context (); }
422 | NAMESPACE identifier '{'
423 { push_namespace ($2); }
424 extdefs_opt '}'
425 { pop_namespace (); }
426 | NAMESPACE '{'
427 { push_namespace (NULL_TREE); }
428 extdefs_opt '}'
429 { pop_namespace (); }
430 | namespace_alias
431 | using_decl ';'
432 { do_toplevel_using_decl ($1); }
433 | using_directive
434 | extension extdef
435 { pedantic = $1; }
438 namespace_alias:
439 NAMESPACE identifier '='
440 { begin_only_namespace_names (); }
441 any_id ';'
443 end_only_namespace_names ();
444 if (lastiddecl)
445 $5 = lastiddecl;
446 do_namespace_alias ($2, $5);
450 using_decl:
451 USING qualified_id
452 { $$ = $2; }
453 | USING global_scope qualified_id
454 { $$ = $3; }
455 | USING global_scope unqualified_id
456 { $$ = $3; }
459 namespace_using_decl:
460 USING namespace_qualifier identifier
461 { $$ = build_parse_node (SCOPE_REF, $2, $3); }
462 | USING global_scope identifier
463 { $$ = build_parse_node (SCOPE_REF, global_namespace, $3); }
464 | USING global_scope namespace_qualifier identifier
465 { $$ = build_parse_node (SCOPE_REF, $3, $4); }
468 using_directive:
469 USING NAMESPACE
470 { begin_only_namespace_names (); }
471 any_id ';'
473 end_only_namespace_names ();
474 /* If no declaration was found, the using-directive is
475 invalid. Since that was not reported, we need the
476 identifier for the error message. */
477 if (TREE_CODE ($4) == IDENTIFIER_NODE && lastiddecl)
478 $4 = lastiddecl;
479 do_using_directive ($4);
483 namespace_qualifier:
484 NSNAME SCOPE
486 if (TREE_CODE ($$) == IDENTIFIER_NODE)
487 $$ = lastiddecl;
488 got_scope = $$;
490 | namespace_qualifier NSNAME SCOPE
492 $$ = $2;
493 if (TREE_CODE ($$) == IDENTIFIER_NODE)
494 $$ = lastiddecl;
495 got_scope = $$;
498 any_id:
499 unqualified_id
500 | qualified_id
501 | global_scope qualified_id
502 { $$ = $2; }
503 | global_scope unqualified_id
504 { $$ = $2; }
507 extern_lang_string:
508 EXTERN_LANG_STRING
509 { push_lang_context ($1); }
510 | extern_lang_string EXTERN_LANG_STRING
511 { if (current_lang_name != $2)
512 cp_error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name);
513 pop_lang_context (); push_lang_context ($2); }
516 template_header:
517 TEMPLATE '<'
518 { begin_template_parm_list (); }
519 template_parm_list '>'
520 { $$ = end_template_parm_list ($4); }
521 | TEMPLATE '<' '>'
522 { begin_specialization();
523 $$ = NULL_TREE; }
526 template_parm_list:
527 template_parm
528 { $$ = process_template_parm (NULL_TREE, $1); }
529 | template_parm_list ',' template_parm
530 { $$ = process_template_parm ($1, $3); }
533 maybe_identifier:
534 identifier
535 { $$ = $1; }
536 | /* empty */
537 { $$ = NULL_TREE; }
539 template_type_parm:
540 aggr maybe_identifier
541 { $$ = finish_template_type_parm ($1, $2); }
542 | TYPENAME_KEYWORD maybe_identifier
543 { $$ = finish_template_type_parm (class_type_node, $2); }
546 template_template_parm:
547 template_header aggr maybe_identifier
548 { $$ = finish_template_template_parm ($2, $3); }
551 template_parm:
552 /* The following rules introduce a new reduce/reduce
553 conflict on the ',' and '>' input tokens: they are valid
554 prefixes for a `structsp', which means they could match a
555 nameless parameter. See 14.6, paragraph 3.
556 By putting them before the `parm' rule, we get
557 their match before considering them nameless parameter
558 declarations. */
559 template_type_parm
560 { $$ = build_tree_list (NULL_TREE, $1); }
561 | template_type_parm '=' type_id
562 { $$ = build_tree_list (groktypename ($3.t), $1); }
563 | parm
564 { $$ = build_tree_list (NULL_TREE, $1.t); }
565 | parm '=' expr_no_commas %prec ARITHCOMPARE
566 { $$ = build_tree_list ($3, $1.t); }
567 | template_template_parm
568 { $$ = build_tree_list (NULL_TREE, $1); }
569 | template_template_parm '=' template_arg
571 if (TREE_CODE ($3) != TEMPLATE_DECL
572 && TREE_CODE ($3) != TEMPLATE_TEMPLATE_PARM
573 && TREE_CODE ($3) != TYPE_DECL)
575 error ("invalid default template argument");
576 $3 = error_mark_node;
578 $$ = build_tree_list ($3, $1);
582 template_def:
583 template_header template_extdef
584 { finish_template_decl ($1); }
585 | template_header error %prec EMPTY
586 { finish_template_decl ($1); }
589 template_extdef:
590 fndef eat_saved_input
591 { if (pending_inlines) do_pending_inlines (); }
592 | template_datadef
593 { if (pending_inlines) do_pending_inlines (); }
594 | template_def
595 { if (pending_inlines) do_pending_inlines (); }
596 | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
597 { if (pending_inlines) do_pending_inlines ();
598 pop_lang_context (); }
599 | extern_lang_string .hush_warning template_datadef .warning_ok
600 { if (pending_inlines) do_pending_inlines ();
601 pop_lang_context (); }
602 | extension template_extdef
603 { pedantic = $1; }
606 template_datadef:
607 nomods_initdecls ';'
608 | declmods notype_initdecls ';'
610 | typed_declspecs initdecls ';'
611 { note_list_got_semicolon ($1.t); }
612 | structsp ';'
613 { maybe_process_partial_specialization ($1.t);
614 note_got_semicolon ($1.t); }
617 datadef:
618 nomods_initdecls ';'
619 | declmods notype_initdecls ';'
621 | typed_declspecs initdecls ';'
622 { note_list_got_semicolon ($1.t); }
623 | declmods ';'
624 { pedwarn ("empty declaration"); }
625 | explicit_instantiation ';'
626 | typed_declspecs ';'
628 tree t, attrs;
629 split_specs_attrs ($1.t, &t, &attrs);
630 shadow_tag (t);
631 note_list_got_semicolon ($1.t);
633 | error ';'
634 | error '}'
635 | ';'
638 ctor_initializer_opt:
639 nodecls
640 { $$ = 0; }
641 | base_init
642 { $$ = 1; }
645 maybe_return_init:
646 /* empty */
647 | return_init
648 | return_init ';'
651 eat_saved_input:
652 /* empty */
653 | END_OF_SAVED_INPUT
656 fndef:
657 fn.def1 maybe_return_init ctor_initializer_opt compstmt_or_error
658 { expand_body (finish_function (lineno, (int)$3)); }
659 | fn.def1 maybe_return_init function_try_block
660 { expand_body (finish_function (lineno, (int)$3)); }
661 | fn.def1 maybe_return_init error
665 constructor_declarator:
666 nested_name_specifier SELFNAME '('
667 { $$ = begin_constructor_declarator ($1, $2); }
668 parmlist ')' cv_qualifiers exception_specification_opt
669 { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
670 | nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
671 { $$ = begin_constructor_declarator ($1, $2);
672 $$ = make_call_declarator ($$, empty_parms (), $4, $5);
674 | global_scope nested_name_specifier SELFNAME '('
675 { $$ = begin_constructor_declarator ($2, $3); }
676 parmlist ')' cv_qualifiers exception_specification_opt
677 { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
678 | global_scope nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
679 { $$ = begin_constructor_declarator ($2, $3);
680 $$ = make_call_declarator ($$, empty_parms (), $5, $6);
682 | nested_name_specifier self_template_type '('
683 { $$ = begin_constructor_declarator ($1, $2); }
684 parmlist ')' cv_qualifiers exception_specification_opt
685 { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
686 | nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
687 { $$ = begin_constructor_declarator ($1, $2);
688 $$ = make_call_declarator ($$, empty_parms (), $4, $5);
690 | global_scope nested_name_specifier self_template_type '('
691 { $$ = begin_constructor_declarator ($2, $3); }
692 parmlist ')' cv_qualifiers exception_specification_opt
693 { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
694 | global_scope nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
695 { $$ = begin_constructor_declarator ($2, $3);
696 $$ = make_call_declarator ($$, empty_parms (), $5, $6);
700 fn.def1:
701 typed_declspecs declarator
702 { if (!begin_function_definition ($1.t, $1.lookups, $2))
703 YYERROR1; }
704 | declmods notype_declarator
705 { if (!begin_function_definition ($1.t, NULL_TREE, $2))
706 YYERROR1; }
707 | notype_declarator
708 { if (!begin_function_definition (NULL_TREE, NULL_TREE, $1))
709 YYERROR1; }
710 | declmods constructor_declarator
711 { if (!begin_function_definition ($1.t, NULL_TREE, $2))
712 YYERROR1; }
713 | constructor_declarator
714 { if (!begin_function_definition (NULL_TREE, NULL_TREE, $1))
715 YYERROR1; }
718 component_constructor_declarator:
719 SELFNAME '(' parmlist ')' cv_qualifiers exception_specification_opt
720 { $$ = make_call_declarator ($1, $3, $5, $6); }
721 | SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
722 { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
723 | self_template_type '(' parmlist ')' cv_qualifiers exception_specification_opt
724 { $$ = make_call_declarator ($1, $3, $5, $6); }
725 | self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
726 { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
729 /* more C++ complexity. See component_decl for a comment on the
730 reduce/reduce conflict introduced by these rules. */
731 fn.def2:
732 declmods component_constructor_declarator
733 { tree specs, attrs;
734 split_specs_attrs ($1.t, &specs, &attrs);
735 attrs = build_tree_list (attrs, NULL_TREE);
736 $$ = start_method (specs, $2, attrs);
737 rest_of_mdef:
738 if (! $$)
739 YYERROR1;
740 if (yychar == YYEMPTY)
741 yychar = YYLEX;
742 reinit_parse_for_method (yychar, $$); }
743 | component_constructor_declarator
744 { $$ = start_method (NULL_TREE, $1, NULL_TREE);
745 goto rest_of_mdef; }
746 | typed_declspecs declarator
747 { tree specs, attrs;
748 split_specs_attrs ($1.t, &specs, &attrs);
749 attrs = build_tree_list (attrs, NULL_TREE);
750 $$ = start_method (specs, $2, attrs); goto rest_of_mdef; }
751 | declmods notype_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 | notype_declarator
757 { $$ = start_method (NULL_TREE, $$, NULL_TREE);
758 goto rest_of_mdef; }
759 | declmods constructor_declarator
760 { tree specs, attrs;
761 split_specs_attrs ($1.t, &specs, &attrs);
762 attrs = build_tree_list (attrs, NULL_TREE);
763 $$ = start_method (specs, $2, attrs); goto rest_of_mdef; }
764 | constructor_declarator
765 { $$ = start_method (NULL_TREE, $$, NULL_TREE);
766 goto rest_of_mdef; }
769 return_id:
770 RETURN_KEYWORD IDENTIFIER
772 if (! current_function_parms_stored)
773 store_parm_decls ();
774 $$ = $2;
778 return_init:
779 return_id maybe_init
780 { finish_named_return_value ($<ttype>$, $2); }
781 | return_id '(' nonnull_exprlist ')'
782 { finish_named_return_value ($<ttype>$, $3); }
783 | return_id LEFT_RIGHT
784 { finish_named_return_value ($<ttype>$, NULL_TREE); }
787 base_init:
788 ':' .set_base_init member_init_list
790 if ($3 == 0)
791 error ("no base initializers given following ':'");
792 setup_vtbl_ptr ();
796 .set_base_init:
797 /* empty */
799 if (! current_function_parms_stored)
800 store_parm_decls ();
802 if (DECL_CONSTRUCTOR_P (current_function_decl))
803 /* Make a contour for the initializer list. */
804 do_pushlevel ();
805 else if (current_class_type == NULL_TREE)
806 error ("base initializers not allowed for non-member functions");
807 else if (! DECL_CONSTRUCTOR_P (current_function_decl))
808 error ("only constructors take base initializers");
812 member_init_list:
813 /* empty */
814 { $$ = 0; }
815 | member_init
816 { $$ = 1; }
817 | member_init_list ',' member_init
818 | member_init_list error
821 member_init:
822 '(' nonnull_exprlist ')'
824 if (current_class_name)
825 pedwarn ("anachronistic old style base class initializer");
826 expand_member_init (current_class_ref, NULL_TREE, $2);
828 | LEFT_RIGHT
830 if (current_class_name)
831 pedwarn ("anachronistic old style base class initializer");
832 expand_member_init (current_class_ref, NULL_TREE, void_type_node);
834 | notype_identifier '(' nonnull_exprlist ')'
835 { expand_member_init (current_class_ref, $1, $3); }
836 | notype_identifier LEFT_RIGHT
837 { expand_member_init (current_class_ref, $1, void_type_node); }
838 | nonnested_type '(' nonnull_exprlist ')'
839 { expand_member_init (current_class_ref, $1, $3); }
840 | nonnested_type LEFT_RIGHT
841 { expand_member_init (current_class_ref, $1, void_type_node); }
842 | typename_sub '(' nonnull_exprlist ')'
843 { expand_member_init (current_class_ref, TYPE_MAIN_DECL ($1),
844 $3); }
845 | typename_sub LEFT_RIGHT
846 { expand_member_init (current_class_ref, TYPE_MAIN_DECL ($1),
847 void_type_node); }
848 | error
851 identifier:
852 IDENTIFIER
853 | TYPENAME
854 | SELFNAME
855 | PTYPENAME
856 | NSNAME
859 notype_identifier:
860 IDENTIFIER
861 | PTYPENAME
862 | NSNAME %prec EMPTY
865 identifier_defn:
866 IDENTIFIER_DEFN
867 | TYPENAME_DEFN
868 | PTYPENAME_DEFN
871 explicit_instantiation:
872 TEMPLATE begin_explicit_instantiation typespec ';'
873 { do_type_instantiation ($3.t, NULL_TREE);
874 yyungetc (';', 1); }
875 end_explicit_instantiation
876 | TEMPLATE begin_explicit_instantiation typed_declspecs declarator
877 { tree specs = strip_attrs ($3.t);
878 do_decl_instantiation (specs, $4, NULL_TREE); }
879 end_explicit_instantiation
880 | TEMPLATE begin_explicit_instantiation notype_declarator
881 { do_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
882 end_explicit_instantiation
883 | TEMPLATE begin_explicit_instantiation constructor_declarator
884 { do_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
885 end_explicit_instantiation
886 | SCSPEC TEMPLATE begin_explicit_instantiation typespec ';'
887 { do_type_instantiation ($4.t, $1);
888 yyungetc (';', 1); }
889 end_explicit_instantiation
890 | SCSPEC TEMPLATE begin_explicit_instantiation typed_declspecs
891 declarator
892 { tree specs = strip_attrs ($4.t);
893 do_decl_instantiation (specs, $5, $1); }
894 end_explicit_instantiation
895 | SCSPEC TEMPLATE begin_explicit_instantiation notype_declarator
896 { do_decl_instantiation (NULL_TREE, $4, $1); }
897 end_explicit_instantiation
898 | SCSPEC TEMPLATE begin_explicit_instantiation constructor_declarator
899 { do_decl_instantiation (NULL_TREE, $4, $1); }
900 end_explicit_instantiation
903 begin_explicit_instantiation:
904 { begin_explicit_instantiation(); }
906 end_explicit_instantiation:
907 { end_explicit_instantiation(); }
909 /* The TYPENAME expansions are to deal with use of a template class name as
910 a template within the class itself, where the template decl is hidden by
911 a type decl. Got all that? */
913 template_type:
914 PTYPENAME '<' template_arg_list_opt template_close_bracket
915 .finish_template_type
916 { $$ = $5; }
917 | TYPENAME '<' template_arg_list_opt template_close_bracket
918 .finish_template_type
919 { $$ = $5; }
920 | self_template_type
923 apparent_template_type:
924 template_type
925 | identifier '<' template_arg_list_opt '>'
926 .finish_template_type
927 { $$ = $5; }
929 self_template_type:
930 SELFNAME '<' template_arg_list_opt template_close_bracket
931 .finish_template_type
932 { $$ = $5; }
935 .finish_template_type:
937 if (yychar == YYEMPTY)
938 yychar = YYLEX;
940 $$ = finish_template_type ($<ttype>-3, $<ttype>-1,
941 yychar == SCOPE);
944 template_close_bracket:
946 | RSHIFT
948 /* Handle `Class<Class<Type>>' without space in the `>>' */
949 pedwarn ("`>>' should be `> >' in template class name");
950 yyungetc ('>', 1);
954 template_arg_list_opt:
955 /* empty */
956 { $$ = NULL_TREE; }
957 | template_arg_list
960 template_arg_list:
961 template_arg
962 { $$ = build_tree_list (NULL_TREE, $$); }
963 | template_arg_list ',' template_arg
964 { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); }
967 template_arg:
968 type_id
969 { $$ = groktypename ($1.t); }
970 | PTYPENAME
971 { $$ = lastiddecl; }
972 | expr_no_commas %prec ARITHCOMPARE
975 unop:
977 { $$ = NEGATE_EXPR; }
978 | '+'
979 { $$ = CONVERT_EXPR; }
980 | PLUSPLUS
981 { $$ = PREINCREMENT_EXPR; }
982 | MINUSMINUS
983 { $$ = PREDECREMENT_EXPR; }
984 | '!'
985 { $$ = TRUTH_NOT_EXPR; }
988 expr:
989 nontrivial_exprlist
990 { $$ = build_x_compound_expr ($$); }
991 | expr_no_commas
994 paren_expr_or_null:
995 LEFT_RIGHT
996 { error ("ANSI C++ forbids an empty condition for `%s'",
997 cond_stmt_keyword);
998 $$ = integer_zero_node; }
999 | '(' expr ')'
1000 { $$ = $2; }
1003 paren_cond_or_null:
1004 LEFT_RIGHT
1005 { error ("ANSI C++ forbids an empty condition for `%s'",
1006 cond_stmt_keyword);
1007 $$ = integer_zero_node; }
1008 | '(' condition ')'
1009 { $$ = $2; }
1012 xcond:
1013 /* empty */
1014 { $$ = NULL_TREE; }
1015 | condition
1016 | error
1017 { $$ = NULL_TREE; }
1020 condition:
1021 type_specifier_seq declarator maybeasm maybe_attribute '='
1023 tree d;
1024 for (d = getdecls (); d; d = TREE_CHAIN (d))
1025 if (TREE_CODE (d) == TYPE_DECL) {
1026 tree s = TREE_TYPE (d);
1027 if (TREE_CODE (s) == RECORD_TYPE)
1028 cp_error ("definition of class `%T' in condition", s);
1029 else if (TREE_CODE (s) == ENUMERAL_TYPE)
1030 cp_error ("definition of enum `%T' in condition", s);
1033 current_declspecs = $1.t;
1034 $<ttype>$ = start_decl ($<ttype>2, current_declspecs, 1,
1035 $4, /*prefix_attributes*/ NULL_TREE);
1037 init
1039 cp_finish_decl ($<ttype>6, $7, $4, LOOKUP_ONLYCONVERTING);
1040 $$ = convert_from_reference ($<ttype>6);
1041 if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE)
1042 cp_error ("definition of array `%#D' in condition", $$);
1044 | expr
1047 compstmtend:
1049 | maybe_label_decls stmts '}'
1050 | maybe_label_decls stmts error '}'
1051 | maybe_label_decls error '}'
1054 already_scoped_stmt:
1056 { $<ttype>$ = begin_compound_stmt (1); }
1057 compstmtend
1058 { finish_compound_stmt (1, $<ttype>2); }
1059 | simple_stmt
1063 nontrivial_exprlist:
1064 expr_no_commas ',' expr_no_commas
1065 { $$ = tree_cons (NULL_TREE, $$,
1066 build_tree_list (NULL_TREE, $3)); }
1067 | expr_no_commas ',' error
1068 { $$ = tree_cons (NULL_TREE, $$,
1069 build_tree_list (NULL_TREE, error_mark_node)); }
1070 | nontrivial_exprlist ',' expr_no_commas
1071 { chainon ($$, build_tree_list (NULL_TREE, $3)); }
1072 | nontrivial_exprlist ',' error
1073 { chainon ($$, build_tree_list (NULL_TREE, error_mark_node)); }
1076 nonnull_exprlist:
1077 expr_no_commas
1078 { $$ = build_tree_list (NULL_TREE, $$); }
1079 | nontrivial_exprlist
1082 unary_expr:
1083 primary %prec UNARY
1084 { $$ = $1; }
1085 /* __extension__ turns off -pedantic for following primary. */
1086 | extension cast_expr %prec UNARY
1087 { $$ = $2;
1088 pedantic = $1; }
1089 | '*' cast_expr %prec UNARY
1090 { $$ = build_x_indirect_ref ($2, "unary *"); }
1091 | '&' cast_expr %prec UNARY
1092 { $$ = build_x_unary_op (ADDR_EXPR, $2); }
1093 | '~' cast_expr
1094 { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
1095 | unop cast_expr %prec UNARY
1096 { $$ = finish_unary_op_expr ($1, $2); }
1097 /* Refer to the address of a label as a pointer. */
1098 | ANDAND identifier
1099 { if (pedantic)
1100 pedwarn ("ANSI C++ forbids `&&'");
1101 $$ = finish_label_address_expr ($2); }
1102 | SIZEOF unary_expr %prec UNARY
1103 { $$ = expr_sizeof ($2); }
1104 | SIZEOF '(' type_id ')' %prec HYPERUNARY
1105 { $$ = c_sizeof (groktypename ($3.t));
1106 check_for_new_type ("sizeof", $3); }
1107 | ALIGNOF unary_expr %prec UNARY
1108 { $$ = grok_alignof ($2); }
1109 | ALIGNOF '(' type_id ')' %prec HYPERUNARY
1110 { $$ = c_alignof (groktypename ($3.t));
1111 check_for_new_type ("alignof", $3); }
1113 /* The %prec EMPTY's here are required by the = init initializer
1114 syntax extension; see below. */
1115 | new new_type_id %prec EMPTY
1116 { $$ = build_new (NULL_TREE, $2.t, NULL_TREE, $1);
1117 check_for_new_type ("new", $2); }
1118 | new new_type_id new_initializer
1119 { $$ = build_new (NULL_TREE, $2.t, $3, $1);
1120 check_for_new_type ("new", $2); }
1121 | new new_placement new_type_id %prec EMPTY
1122 { $$ = build_new ($2, $3.t, NULL_TREE, $1);
1123 check_for_new_type ("new", $3); }
1124 | new new_placement new_type_id new_initializer
1125 { $$ = build_new ($2, $3.t, $4, $1);
1126 check_for_new_type ("new", $3); }
1127 | new '(' type_id ')'
1128 %prec EMPTY
1129 { $$ = build_new (NULL_TREE, groktypename($3.t),
1130 NULL_TREE, $1);
1131 check_for_new_type ("new", $3); }
1132 | new '(' type_id ')' new_initializer
1133 { $$ = build_new (NULL_TREE, groktypename($3.t), $5, $1);
1134 check_for_new_type ("new", $3); }
1135 | new new_placement '(' type_id ')' %prec EMPTY
1136 { $$ = build_new ($2, groktypename($4.t), NULL_TREE, $1);
1137 check_for_new_type ("new", $4); }
1138 | new new_placement '(' type_id ')' new_initializer
1139 { $$ = build_new ($2, groktypename($4.t), $6, $1);
1140 check_for_new_type ("new", $4); }
1142 | delete cast_expr %prec UNARY
1143 { $$ = delete_sanity ($2, NULL_TREE, 0, $1); }
1144 | delete '[' ']' cast_expr %prec UNARY
1145 { $$ = delete_sanity ($4, NULL_TREE, 1, $1);
1146 if (yychar == YYEMPTY)
1147 yychar = YYLEX; }
1148 | delete '[' expr ']' cast_expr %prec UNARY
1149 { $$ = delete_sanity ($5, $3, 2, $1);
1150 if (yychar == YYEMPTY)
1151 yychar = YYLEX; }
1152 | REALPART cast_expr %prec UNARY
1153 { $$ = build_x_unary_op (REALPART_EXPR, $2); }
1154 | IMAGPART cast_expr %prec UNARY
1155 { $$ = build_x_unary_op (IMAGPART_EXPR, $2); }
1156 | VA_ARG '(' expr_no_commas ',' type_id ')'
1157 { $$ = build_x_va_arg ($3, groktypename ($5.t));
1158 check_for_new_type ("__builtin_va_arg", $5); }
1161 new_placement:
1162 '(' nonnull_exprlist ')'
1163 { $$ = $2; }
1164 | '{' nonnull_exprlist '}'
1165 { cp_pedwarn ("old style placement syntax, use () instead");
1166 $$ = $2; }
1169 new_initializer:
1170 '(' nonnull_exprlist ')'
1171 { $$ = $2; }
1172 | LEFT_RIGHT
1173 { $$ = NULL_TREE; }
1174 | '(' typespec ')'
1176 cp_error ("`%T' is not a valid expression", $2.t);
1177 $$ = error_mark_node;
1179 /* GNU extension so people can use initializer lists. Note that
1180 this alters the meaning of `new int = 1', which was previously
1181 syntactically valid but semantically invalid. */
1182 | '=' init
1184 if (pedantic)
1185 pedwarn ("ANSI C++ forbids initialization of new expression with `='");
1186 if (TREE_CODE ($2) != TREE_LIST
1187 && TREE_CODE ($2) != CONSTRUCTOR)
1188 $$ = build_tree_list (NULL_TREE, $2);
1189 else
1190 $$ = $2;
1194 /* This is necessary to postpone reduction of `int ((int)(int)(int))'. */
1195 regcast_or_absdcl:
1196 '(' type_id ')' %prec EMPTY
1197 { $2.t = finish_parmlist (build_tree_list (NULL_TREE, $2.t), 0);
1198 $$ = make_call_declarator (NULL_TREE, $2.t, NULL_TREE, NULL_TREE);
1199 check_for_new_type ("cast", $2); }
1200 | regcast_or_absdcl '(' type_id ')' %prec EMPTY
1201 { $3.t = finish_parmlist (build_tree_list (NULL_TREE, $3.t), 0);
1202 $$ = make_call_declarator ($$, $3.t, NULL_TREE, NULL_TREE);
1203 check_for_new_type ("cast", $3); }
1206 cast_expr:
1207 unary_expr
1208 | regcast_or_absdcl unary_expr %prec UNARY
1209 { $$ = reparse_absdcl_as_casts ($$, $2); }
1210 | regcast_or_absdcl '{' initlist maybecomma '}' %prec UNARY
1212 tree init = build_nt (CONSTRUCTOR, NULL_TREE,
1213 nreverse ($3));
1214 if (pedantic)
1215 pedwarn ("ANSI C++ forbids constructor-expressions");
1216 /* Indicate that this was a GNU C constructor expression. */
1217 TREE_HAS_CONSTRUCTOR (init) = 1;
1219 $$ = reparse_absdcl_as_casts ($$, init);
1223 expr_no_commas:
1224 cast_expr
1225 /* Handle general members. */
1226 | expr_no_commas POINTSAT_STAR expr_no_commas
1227 { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
1228 | expr_no_commas DOT_STAR expr_no_commas
1229 { $$ = build_m_component_ref ($$, $3); }
1230 | expr_no_commas '+' expr_no_commas
1231 { $$ = build_x_binary_op ($2, $$, $3); }
1232 | expr_no_commas '-' expr_no_commas
1233 { $$ = build_x_binary_op ($2, $$, $3); }
1234 | expr_no_commas '*' expr_no_commas
1235 { $$ = build_x_binary_op ($2, $$, $3); }
1236 | expr_no_commas '/' expr_no_commas
1237 { $$ = build_x_binary_op ($2, $$, $3); }
1238 | expr_no_commas '%' expr_no_commas
1239 { $$ = build_x_binary_op ($2, $$, $3); }
1240 | expr_no_commas LSHIFT expr_no_commas
1241 { $$ = build_x_binary_op ($2, $$, $3); }
1242 | expr_no_commas RSHIFT expr_no_commas
1243 { $$ = build_x_binary_op ($2, $$, $3); }
1244 | expr_no_commas ARITHCOMPARE expr_no_commas
1245 { $$ = build_x_binary_op ($2, $$, $3); }
1246 | expr_no_commas '<' expr_no_commas
1247 { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
1248 | expr_no_commas '>' expr_no_commas
1249 { $$ = build_x_binary_op (GT_EXPR, $$, $3); }
1250 | expr_no_commas EQCOMPARE expr_no_commas
1251 { $$ = build_x_binary_op ($2, $$, $3); }
1252 | expr_no_commas MIN_MAX expr_no_commas
1253 { $$ = build_x_binary_op ($2, $$, $3); }
1254 | expr_no_commas '&' expr_no_commas
1255 { $$ = build_x_binary_op ($2, $$, $3); }
1256 | expr_no_commas '|' expr_no_commas
1257 { $$ = build_x_binary_op ($2, $$, $3); }
1258 | expr_no_commas '^' expr_no_commas
1259 { $$ = build_x_binary_op ($2, $$, $3); }
1260 | expr_no_commas ANDAND expr_no_commas
1261 { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
1262 | expr_no_commas OROR expr_no_commas
1263 { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
1264 | expr_no_commas '?' xexpr ':' expr_no_commas
1265 { $$ = build_x_conditional_expr ($$, $3, $5); }
1266 | expr_no_commas '=' expr_no_commas
1267 { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
1268 if ($$ != error_mark_node)
1269 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
1270 | expr_no_commas ASSIGN expr_no_commas
1271 { $$ = build_x_modify_expr ($$, $2, $3); }
1272 | THROW
1273 { $$ = build_throw (NULL_TREE); }
1274 | THROW expr_no_commas
1275 { $$ = build_throw ($2); }
1276 /* These extensions are not defined. The second arg to build_m_component_ref
1277 is old, build_m_component_ref now does an implicit
1278 build_indirect_ref (x, NULL_PTR) on the second argument.
1279 | object '&' expr_no_commas %prec UNARY
1280 { $$ = build_m_component_ref ($$, build_x_unary_op (ADDR_EXPR, $3)); }
1281 | object unop expr_no_commas %prec UNARY
1282 { $$ = build_m_component_ref ($$, build_x_unary_op ($2, $3)); }
1283 | object '(' type_id ')' expr_no_commas %prec UNARY
1284 { tree type = groktypename ($3.t);
1285 $$ = build_m_component_ref ($$, build_c_cast (type, $5)); }
1286 | object primary_no_id %prec UNARY
1287 { $$ = build_m_component_ref ($$, $2); }
1291 notype_unqualified_id:
1292 '~' see_typename identifier
1293 { $$ = build_parse_node (BIT_NOT_EXPR, $3); }
1294 | '~' see_typename template_type
1295 { $$ = build_parse_node (BIT_NOT_EXPR, $3); }
1296 | template_id
1297 | operator_name
1298 | IDENTIFIER
1299 | PTYPENAME
1300 | NSNAME %prec EMPTY
1303 do_id:
1305 /* If lastiddecl is a TREE_LIST, it's a baselink, which
1306 means that we're in an expression like S::f<int>, so
1307 don't do_identifier; we only do that for unqualified
1308 identifiers. */
1309 if (lastiddecl && TREE_CODE (lastiddecl) != TREE_LIST)
1310 $$ = do_identifier ($<ttype>-1, 1, NULL_TREE);
1311 else
1312 $$ = $<ttype>-1;
1315 template_id:
1316 PFUNCNAME '<' do_id template_arg_list_opt template_close_bracket
1317 { $$ = lookup_template_function ($3, $4); }
1318 | operator_name '<' do_id template_arg_list_opt template_close_bracket
1319 { $$ = lookup_template_function ($3, $4); }
1322 object_template_id:
1323 TEMPLATE identifier '<' template_arg_list_opt template_close_bracket
1324 { $$ = lookup_template_function ($2, $4); }
1325 | TEMPLATE PFUNCNAME '<' template_arg_list_opt template_close_bracket
1326 { $$ = lookup_template_function ($2, $4); }
1327 | TEMPLATE operator_name '<' template_arg_list_opt
1328 template_close_bracket
1329 { $$ = lookup_template_function ($2, $4); }
1332 unqualified_id:
1333 notype_unqualified_id
1334 | TYPENAME
1335 | SELFNAME
1338 expr_or_declarator_intern:
1339 expr_or_declarator
1340 | attributes expr_or_declarator
1342 /* Provide support for '(' attributes '*' declarator ')'
1343 etc */
1344 $$ = decl_tree_cons ($1, $2, NULL_TREE);
1348 expr_or_declarator:
1349 notype_unqualified_id
1350 | '*' expr_or_declarator_intern %prec UNARY
1351 { $$ = build_parse_node (INDIRECT_REF, $2); }
1352 | '&' expr_or_declarator_intern %prec UNARY
1353 { $$ = build_parse_node (ADDR_EXPR, $2); }
1354 | '(' expr_or_declarator_intern ')'
1355 { $$ = $2; }
1358 notype_template_declarator:
1359 IDENTIFIER '<' template_arg_list_opt template_close_bracket
1360 { $$ = lookup_template_function ($1, $3); }
1361 | NSNAME '<' template_arg_list template_close_bracket
1362 { $$ = lookup_template_function ($1, $3); }
1365 direct_notype_declarator:
1366 complex_direct_notype_declarator
1367 /* This precedence declaration is to prefer this reduce
1368 to the Koenig lookup shift in primary, below. I hate yacc. */
1369 | notype_unqualified_id %prec '('
1370 | notype_template_declarator
1371 | '(' expr_or_declarator_intern ')'
1372 { $$ = finish_decl_parsing ($2); }
1375 primary:
1376 notype_unqualified_id
1378 if (TREE_CODE ($1) == BIT_NOT_EXPR)
1379 $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($1, 0));
1380 else
1381 $$ = finish_id_expr ($1);
1383 | CONSTANT
1384 | boolean.literal
1385 | string
1387 $$ = combine_strings ($$);
1388 /* combine_strings doesn't set up TYPE_MAIN_VARIANT of
1389 a const array the way we want, so fix it. */
1390 if (flag_const_strings)
1391 TREE_TYPE ($$) = build_cplus_array_type
1392 (TREE_TYPE (TREE_TYPE ($$)),
1393 TYPE_DOMAIN (TREE_TYPE ($$)));
1395 | '(' expr ')'
1396 { $$ = finish_parenthesized_expr ($2); }
1397 | '(' expr_or_declarator_intern ')'
1398 { $2 = reparse_decl_as_expr (NULL_TREE, $2);
1399 $$ = finish_parenthesized_expr ($2); }
1400 | '(' error ')'
1401 { $$ = error_mark_node; }
1402 | '('
1403 { tree scope = current_scope ();
1404 if (!scope || TREE_CODE (scope) != FUNCTION_DECL)
1406 error ("braced-group within expression allowed only inside a function");
1407 YYERROR;
1409 if (pedantic)
1410 pedwarn ("ANSI C++ forbids braced-groups within expressions");
1411 $<ttype>$ = begin_stmt_expr ();
1413 compstmt ')'
1414 { $$ = finish_stmt_expr ($<ttype>2); }
1415 /* Koenig lookup support
1416 We could store lastiddecl in $1 to avoid another lookup,
1417 but that would result in many additional reduce/reduce conflicts. */
1418 | notype_unqualified_id '(' nonnull_exprlist ')'
1419 { $$ = finish_call_expr ($1, $3, 1); }
1420 | notype_unqualified_id LEFT_RIGHT
1421 { $$ = finish_call_expr ($1, NULL_TREE, 1); }
1422 | primary '(' nonnull_exprlist ')'
1423 { $$ = finish_call_expr ($1, $3, 0); }
1424 | primary LEFT_RIGHT
1425 { $$ = finish_call_expr ($1, NULL_TREE, 0); }
1426 | primary '[' expr ']'
1427 { $$ = grok_array_decl ($$, $3); }
1428 | primary PLUSPLUS
1429 { $$ = finish_increment_expr ($1, POSTINCREMENT_EXPR); }
1430 | primary MINUSMINUS
1431 { $$ = finish_increment_expr ($1, POSTDECREMENT_EXPR); }
1432 /* C++ extensions */
1433 | THIS
1434 { $$ = finish_this_expr (); }
1435 | CV_QUALIFIER '(' nonnull_exprlist ')'
1437 /* This is a C cast in C++'s `functional' notation
1438 using the "implicit int" extension so that:
1439 `const (3)' is equivalent to `const int (3)'. */
1440 tree type;
1442 type = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
1443 type = groktypename (build_decl_list (type, NULL_TREE));
1444 $$ = build_functional_cast (type, $3);
1446 | functional_cast
1447 | DYNAMIC_CAST '<' type_id '>' '(' expr ')'
1448 { tree type = groktypename ($3.t);
1449 check_for_new_type ("dynamic_cast", $3);
1450 $$ = build_dynamic_cast (type, $6); }
1451 | STATIC_CAST '<' type_id '>' '(' expr ')'
1452 { tree type = groktypename ($3.t);
1453 check_for_new_type ("static_cast", $3);
1454 $$ = build_static_cast (type, $6); }
1455 | REINTERPRET_CAST '<' type_id '>' '(' expr ')'
1456 { tree type = groktypename ($3.t);
1457 check_for_new_type ("reinterpret_cast", $3);
1458 $$ = build_reinterpret_cast (type, $6); }
1459 | CONST_CAST '<' type_id '>' '(' expr ')'
1460 { tree type = groktypename ($3.t);
1461 check_for_new_type ("const_cast", $3);
1462 $$ = build_const_cast (type, $6); }
1463 | TYPEID '(' expr ')'
1464 { $$ = build_typeid ($3); }
1465 | TYPEID '(' type_id ')'
1466 { tree type = groktypename ($3.t);
1467 check_for_new_type ("typeid", $3);
1468 $$ = get_typeid (TYPE_MAIN_VARIANT (type)); }
1469 | global_scope IDENTIFIER
1470 { $$ = do_scoped_id ($2, 1); }
1471 | global_scope template_id
1472 { $$ = $2; }
1473 | global_scope operator_name
1475 got_scope = NULL_TREE;
1476 if (TREE_CODE ($2) == IDENTIFIER_NODE)
1477 $$ = do_scoped_id ($2, 1);
1478 else
1479 $$ = $2;
1481 | overqualified_id %prec HYPERUNARY
1482 { $$ = build_offset_ref (OP0 ($$), OP1 ($$)); }
1483 | overqualified_id '(' nonnull_exprlist ')'
1484 { $$ = finish_qualified_call_expr ($1, $3); }
1485 | overqualified_id LEFT_RIGHT
1486 { $$ = finish_qualified_call_expr ($1, NULL_TREE); }
1487 | object object_template_id %prec UNARY
1489 $$ = build_x_component_ref ($$, $2, NULL_TREE, 1);
1491 | object object_template_id '(' nonnull_exprlist ')'
1492 { $$ = finish_object_call_expr ($2, $1, $4); }
1493 | object object_template_id LEFT_RIGHT
1494 { $$ = finish_object_call_expr ($2, $1, NULL_TREE); }
1495 | object unqualified_id %prec UNARY
1496 { $$ = build_x_component_ref ($$, $2, NULL_TREE, 1); }
1497 | object overqualified_id %prec UNARY
1498 { if (processing_template_decl)
1499 $$ = build_min_nt (COMPONENT_REF, $1, $2);
1500 else
1501 $$ = build_object_ref ($$, OP0 ($2), OP1 ($2)); }
1502 | object unqualified_id '(' nonnull_exprlist ')'
1503 { $$ = finish_object_call_expr ($2, $1, $4); }
1504 | object unqualified_id LEFT_RIGHT
1505 { $$ = finish_object_call_expr ($2, $1, NULL_TREE); }
1506 | object overqualified_id '(' nonnull_exprlist ')'
1507 { $$ = finish_qualified_object_call_expr ($2, $1, $4); }
1508 | object overqualified_id LEFT_RIGHT
1509 { $$ = finish_qualified_object_call_expr ($2, $1, NULL_TREE); }
1510 /* p->int::~int() is valid -- 12.4 */
1511 | object '~' TYPESPEC LEFT_RIGHT
1512 { $$ = finish_pseudo_destructor_call_expr ($1, NULL_TREE, $3); }
1513 | object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT
1514 { $$ = finish_pseudo_destructor_call_expr ($1, $2, $5); }
1515 | object error
1517 $$ = error_mark_node;
1521 /* Not needed for now.
1523 primary_no_id:
1524 '(' expr ')'
1525 { $$ = $2; }
1526 | '(' error ')'
1527 { $$ = error_mark_node; }
1528 | '('
1529 { if (current_function_decl == 0)
1531 error ("braced-group within expression allowed only inside a function");
1532 YYERROR;
1534 $<ttype>$ = expand_start_stmt_expr (); }
1535 compstmt ')'
1536 { if (pedantic)
1537 pedwarn ("ANSI C++ forbids braced-groups within expressions");
1538 $$ = expand_end_stmt_expr ($<ttype>2); }
1539 | primary_no_id '(' nonnull_exprlist ')'
1540 { $$ = build_x_function_call ($$, $3, current_class_ref); }
1541 | primary_no_id LEFT_RIGHT
1542 { $$ = build_x_function_call ($$, NULL_TREE, current_class_ref); }
1543 | primary_no_id '[' expr ']'
1544 { goto do_array; }
1545 | primary_no_id PLUSPLUS
1546 { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
1547 | primary_no_id MINUSMINUS
1548 { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
1549 | SCOPE IDENTIFIER
1550 { goto do_scoped_id; }
1551 | SCOPE operator_name
1552 { if (TREE_CODE ($2) == IDENTIFIER_NODE)
1553 goto do_scoped_id;
1554 goto do_scoped_operator;
1559 new:
1561 { $$ = 0; }
1562 | global_scope NEW
1563 { got_scope = NULL_TREE; $$ = 1; }
1566 delete:
1567 DELETE
1568 { $$ = 0; }
1569 | global_scope delete
1570 { got_scope = NULL_TREE; $$ = 1; }
1573 boolean.literal:
1574 CXX_TRUE
1575 { $$ = boolean_true_node; }
1576 | CXX_FALSE
1577 { $$ = boolean_false_node; }
1580 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
1581 string:
1582 STRING
1583 | string STRING
1584 { $$ = chainon ($$, $2); }
1587 nodecls:
1588 /* empty */
1590 if (! current_function_parms_stored)
1591 store_parm_decls ();
1592 setup_vtbl_ptr ();
1596 object:
1597 primary '.'
1598 { got_object = TREE_TYPE ($$); }
1599 | primary POINTSAT
1601 $$ = build_x_arrow ($$);
1602 got_object = TREE_TYPE ($$);
1606 decl:
1607 typespec initdecls ';'
1609 if ($1.t && IS_AGGR_TYPE_CODE (TREE_CODE ($1.t)))
1610 note_got_semicolon ($1.t);
1612 | typed_declspecs initdecls ';'
1614 note_list_got_semicolon ($1.t);
1616 | declmods notype_initdecls ';'
1618 | typed_declspecs ';'
1620 shadow_tag ($1.t);
1621 note_list_got_semicolon ($1.t);
1623 | declmods ';'
1624 { warning ("empty declaration"); }
1625 | extension decl
1626 { pedantic = $1; }
1629 /* Any kind of declarator (thus, all declarators allowed
1630 after an explicit typespec). */
1632 declarator:
1633 after_type_declarator %prec EMPTY
1634 | notype_declarator %prec EMPTY
1637 /* This is necessary to postpone reduction of `int()()()()'. */
1638 fcast_or_absdcl:
1639 LEFT_RIGHT %prec EMPTY
1640 { $$ = make_call_declarator (NULL_TREE, empty_parms (),
1641 NULL_TREE, NULL_TREE); }
1642 | fcast_or_absdcl LEFT_RIGHT %prec EMPTY
1643 { $$ = make_call_declarator ($$, empty_parms (), NULL_TREE,
1644 NULL_TREE); }
1647 /* ANSI type-id (8.1) */
1648 type_id:
1649 typed_typespecs absdcl
1650 { $$.t = build_decl_list ($1.t, $2);
1651 $$.new_type_flag = $1.new_type_flag; }
1652 | nonempty_cv_qualifiers absdcl
1653 { $$.t = build_decl_list ($1.t, $2);
1654 $$.new_type_flag = $1.new_type_flag; }
1655 | typespec absdcl
1656 { $$.t = build_decl_list (build_decl_list (NULL_TREE, $1.t),
1657 $2);
1658 $$.new_type_flag = $1.new_type_flag; }
1659 | typed_typespecs %prec EMPTY
1660 { $$.t = build_decl_list ($1.t, NULL_TREE);
1661 $$.new_type_flag = $1.new_type_flag; }
1662 | nonempty_cv_qualifiers %prec EMPTY
1663 { $$.t = build_decl_list ($1.t, NULL_TREE);
1664 $$.new_type_flag = $1.new_type_flag; }
1667 /* Declspecs which contain at least one type specifier or typedef name.
1668 (Just `const' or `volatile' is not enough.)
1669 A typedef'd name following these is taken as a name to be declared.
1670 In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
1672 typed_declspecs:
1673 typed_typespecs %prec EMPTY
1674 { $$.lookups = type_lookups; }
1675 | typed_declspecs1
1676 { $$.lookups = type_lookups; }
1679 typed_declspecs1:
1680 declmods typespec
1681 { $$.t = decl_tree_cons (NULL_TREE, $2.t, $1.t);
1682 $$.new_type_flag = $2.new_type_flag; }
1683 | typespec reserved_declspecs %prec HYPERUNARY
1684 { $$.t = decl_tree_cons (NULL_TREE, $1.t, $2);
1685 $$.new_type_flag = $1.new_type_flag; }
1686 | typespec reserved_typespecquals reserved_declspecs
1687 { $$.t = decl_tree_cons (NULL_TREE, $1.t, chainon ($2, $3));
1688 $$.new_type_flag = $1.new_type_flag; }
1689 | declmods typespec reserved_declspecs
1690 { $$.t = decl_tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
1691 $$.new_type_flag = $2.new_type_flag; }
1692 | declmods typespec reserved_typespecquals
1693 { $$.t = decl_tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
1694 $$.new_type_flag = $2.new_type_flag; }
1695 | declmods typespec reserved_typespecquals reserved_declspecs
1696 { $$.t = decl_tree_cons (NULL_TREE, $2.t,
1697 chainon ($3, chainon ($4, $1.t)));
1698 $$.new_type_flag = $2.new_type_flag; }
1701 reserved_declspecs:
1702 SCSPEC
1703 { if (extra_warnings)
1704 warning ("`%s' is not at beginning of declaration",
1705 IDENTIFIER_POINTER ($$));
1706 $$ = build_decl_list (NULL_TREE, $$); }
1707 | reserved_declspecs typespecqual_reserved
1708 { $$ = decl_tree_cons (NULL_TREE, $2.t, $$); }
1709 | reserved_declspecs SCSPEC
1710 { if (extra_warnings)
1711 warning ("`%s' is not at beginning of declaration",
1712 IDENTIFIER_POINTER ($2));
1713 $$ = decl_tree_cons (NULL_TREE, $2, $$); }
1714 | reserved_declspecs attributes
1715 { $$ = decl_tree_cons ($2, NULL_TREE, $1); }
1716 | attributes
1717 { $$ = decl_tree_cons ($1, NULL_TREE, NULL_TREE); }
1720 /* List of just storage classes and type modifiers.
1721 A declaration can start with just this, but then it cannot be used
1722 to redeclare a typedef-name.
1723 In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
1725 /* We use hash_tree_cons for lists of typeless declspecs so that they end
1726 up on a persistent obstack. Otherwise, they could appear at the
1727 beginning of something like
1729 static const struct { int foo () { } } b;
1731 and would be discarded after we finish compiling foo. We don't need to
1732 worry once we see a type. */
1734 declmods:
1735 nonempty_cv_qualifiers %prec EMPTY
1736 { $$.lookups = NULL_TREE; TREE_STATIC ($$.t) = 1; }
1737 | SCSPEC
1739 $$.t = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
1740 $$.new_type_flag = 0; $$.lookups = NULL_TREE;
1742 | declmods CV_QUALIFIER
1744 $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
1745 TREE_STATIC ($$.t) = 1;
1747 | declmods SCSPEC
1749 if (extra_warnings && TREE_STATIC ($$.t))
1750 warning ("`%s' is not at beginning of declaration",
1751 IDENTIFIER_POINTER ($2));
1752 $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
1753 TREE_STATIC ($$.t) = TREE_STATIC ($1.t);
1755 | declmods attributes
1756 { $$.t = hash_tree_cons ($2, NULL_TREE, $1.t); }
1757 | attributes %prec EMPTY
1759 $$.t = hash_tree_cons ($1, NULL_TREE, NULL_TREE);
1760 $$.new_type_flag = 0; $$.lookups = NULL_TREE;
1764 /* Used instead of declspecs where storage classes are not allowed
1765 (that is, for typenames and structure components).
1767 C++ can takes storage classes for structure components.
1768 Don't accept a typedef-name if anything but a modifier precedes it. */
1770 typed_typespecs:
1771 typespec %prec EMPTY
1772 { $$.t = build_decl_list (NULL_TREE, $1.t);
1773 $$.new_type_flag = $1.new_type_flag; }
1774 | nonempty_cv_qualifiers typespec
1775 { $$.t = decl_tree_cons (NULL_TREE, $2.t, $1.t);
1776 $$.new_type_flag = $2.new_type_flag; }
1777 | typespec reserved_typespecquals
1778 { $$.t = decl_tree_cons (NULL_TREE, $1.t, $2);
1779 $$.new_type_flag = $1.new_type_flag; }
1780 | nonempty_cv_qualifiers typespec reserved_typespecquals
1781 { $$.t = decl_tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
1782 $$.new_type_flag = $2.new_type_flag; }
1785 reserved_typespecquals:
1786 typespecqual_reserved
1787 { $$ = build_decl_list (NULL_TREE, $1.t); }
1788 | reserved_typespecquals typespecqual_reserved
1789 { $$ = decl_tree_cons (NULL_TREE, $2.t, $1); }
1792 /* A typespec (but not a type qualifier).
1793 Once we have seen one of these in a declaration,
1794 if a typedef name appears then it is being redeclared. */
1796 typespec:
1797 structsp
1798 { $$.lookups = NULL_TREE; }
1799 | TYPESPEC %prec EMPTY
1800 { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
1801 | complete_type_name
1802 { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
1803 | TYPEOF '(' expr ')'
1804 { $$.t = finish_typeof ($3);
1805 $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
1806 | TYPEOF '(' type_id ')'
1807 { $$.t = groktypename ($3.t);
1808 $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
1809 | SIGOF '(' expr ')'
1810 { tree type = TREE_TYPE ($3);
1812 $$.new_type_flag = 0; $$.lookups = NULL_TREE;
1813 if (IS_AGGR_TYPE (type))
1815 sorry ("sigof type specifier");
1816 $$.t = type;
1818 else
1820 error ("`sigof' applied to non-aggregate expression");
1821 $$.t = error_mark_node;
1824 | SIGOF '(' type_id ')'
1825 { tree type = groktypename ($3.t);
1827 $$.new_type_flag = 0; $$.lookups = NULL_TREE;
1828 if (IS_AGGR_TYPE (type))
1830 sorry ("sigof type specifier");
1831 $$.t = type;
1833 else
1835 error("`sigof' applied to non-aggregate type");
1836 $$.t = error_mark_node;
1841 /* A typespec that is a reserved word, or a type qualifier. */
1843 typespecqual_reserved:
1844 TYPESPEC
1845 { $$.t = $1; $$.new_type_flag = 0; }
1846 | CV_QUALIFIER
1847 { $$.t = $1; $$.new_type_flag = 0; }
1848 | structsp
1851 initdecls:
1852 initdcl0
1853 | initdecls ',' initdcl
1854 { check_multiple_declarators (); }
1857 notype_initdecls:
1858 notype_initdcl0
1859 | notype_initdecls ',' initdcl
1860 { check_multiple_declarators (); }
1863 nomods_initdecls:
1864 nomods_initdcl0
1865 | nomods_initdecls ',' initdcl
1866 { check_multiple_declarators (); }
1869 maybeasm:
1870 /* empty */
1871 { $$ = NULL_TREE; }
1872 | asm_keyword '(' string ')'
1873 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); $$ = $3; }
1876 initdcl:
1877 declarator maybeasm maybe_attribute '='
1879 deferred_type_access_control ();
1880 $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1,
1881 $3, prefix_attributes);
1883 init
1884 /* Note how the declaration of the variable is in effect while its init is parsed! */
1885 { cp_finish_decl ($<ttype>5, $6, $2, LOOKUP_ONLYCONVERTING); }
1886 | declarator maybeasm maybe_attribute
1888 deferred_type_access_control ();
1889 $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 0,
1890 $3, prefix_attributes);
1891 cp_finish_decl ($<ttype>$, NULL_TREE, $2, 0);
1895 /* This rule assumes a certain configuration of the parser stack.
1896 In particular, $0, the element directly before the beginning of
1897 this rule on the stack, must be a maybeasm. $-1 must be a
1898 declarator or notype_declarator. And $-2 must be some declmods
1899 or declspecs. We can't move the maybeasm into this rule because
1900 we need that reduce so we prefer fn.def1 when appropriate. */
1901 initdcl0_innards:
1902 maybe_attribute '='
1903 { parse_decl ($<ttype>-1, $<ftype>-2.t, $<ftype>-2.lookups,
1904 $1, 1, &$<ttype>$); }
1905 /* Note how the declaration of the variable is in effect
1906 while its init is parsed! */
1907 init
1908 { cp_finish_decl ($<ttype>3, $4, $<ttype>0,
1909 LOOKUP_ONLYCONVERTING); }
1910 | maybe_attribute
1911 { tree d;
1912 parse_decl ($<ttype>-1, $<ftype>-2.t, $<ftype>-2.lookups,
1913 $1, 0, &d);
1914 cp_finish_decl (d, NULL_TREE, $<ttype>0, 0); }
1917 initdcl0:
1918 declarator maybeasm initdcl0_innards
1922 notype_initdcl0:
1923 notype_declarator maybeasm initdcl0_innards
1927 nomods_initdcl0:
1928 notype_declarator maybeasm
1929 { /* Set things up as initdcl0_innards expects. */
1930 $<ttype>2 = $1;
1931 $1 = NULL_TREE; }
1932 initdcl0_innards
1934 | constructor_declarator maybeasm maybe_attribute
1935 { tree d;
1936 parse_decl ($1, NULL_TREE, NULL_TREE, $3, 0, &d);
1937 cp_finish_decl (d, NULL_TREE, $2, 0); }
1940 /* the * rules are dummies to accept the Apollo extended syntax
1941 so that the header files compile. */
1942 maybe_attribute:
1943 /* empty */
1944 { $$ = NULL_TREE; }
1945 | attributes
1946 { $$ = $1; }
1949 attributes:
1950 attribute
1951 { $$ = $1; }
1952 | attributes attribute
1953 { $$ = chainon ($1, $2); }
1956 attribute:
1957 ATTRIBUTE '(' '(' attribute_list ')' ')'
1958 { $$ = $4; }
1961 attribute_list:
1962 attrib
1963 { $$ = $1; }
1964 | attribute_list ',' attrib
1965 { $$ = chainon ($1, $3); }
1968 attrib:
1969 /* empty */
1970 { $$ = NULL_TREE; }
1971 | any_word
1972 { $$ = build_tree_list ($1, NULL_TREE); }
1973 | any_word '(' IDENTIFIER ')'
1974 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1975 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1976 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1977 | any_word '(' nonnull_exprlist ')'
1978 { $$ = build_tree_list ($1, $3); }
1981 /* This still leaves out most reserved keywords,
1982 shouldn't we include them? */
1984 any_word:
1985 identifier
1986 | SCSPEC
1987 | TYPESPEC
1988 | CV_QUALIFIER
1991 /* A nonempty list of identifiers, including typenames. */
1992 identifiers_or_typenames:
1993 identifier
1994 { $$ = build_tree_list (NULL_TREE, $1); }
1995 | identifiers_or_typenames ',' identifier
1996 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
1999 maybe_init:
2000 /* empty */ %prec EMPTY
2001 { $$ = NULL_TREE; }
2002 | '=' init
2003 { $$ = $2; }
2005 /* If we are processing a template, we don't want to expand this
2006 initializer yet. */
2008 init:
2009 expr_no_commas %prec '='
2010 | '{' '}'
2011 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
2012 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2013 | '{' initlist '}'
2014 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2015 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2016 | '{' initlist ',' '}'
2017 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2018 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2019 | error
2020 { $$ = NULL_TREE; }
2023 /* This chain is built in reverse order,
2024 and put in forward order where initlist is used. */
2025 initlist:
2026 init
2027 { $$ = build_tree_list (NULL_TREE, $$); }
2028 | initlist ',' init
2029 { $$ = tree_cons (NULL_TREE, $3, $$); }
2030 /* These are for labeled elements. */
2031 | '[' expr_no_commas ']' init
2032 { $$ = build_tree_list ($2, $4); }
2033 | identifier ':' init
2034 { $$ = build_tree_list ($$, $3); }
2035 | initlist ',' identifier ':' init
2036 { $$ = tree_cons ($3, $5, $$); }
2039 fn.defpen:
2040 PRE_PARSED_FUNCTION_DECL
2041 { start_function (NULL_TREE, $1->fndecl, NULL_TREE,
2042 (SF_DEFAULT | SF_PRE_PARSED
2043 | SF_INCLASS_INLINE));
2044 reinit_parse_for_function (); }
2046 pending_inline:
2047 fn.defpen maybe_return_init ctor_initializer_opt compstmt_or_error
2049 expand_body (finish_function (lineno, (int)$3 | 2));
2050 process_next_inline ($1);
2052 | fn.defpen maybe_return_init function_try_block
2054 expand_body (finish_function (lineno, (int)$3 | 2));
2055 process_next_inline ($1);
2057 | fn.defpen maybe_return_init error
2059 finish_function (lineno, 2);
2060 process_next_inline ($1); }
2063 pending_inlines:
2064 /* empty */
2065 | pending_inlines pending_inline eat_saved_input
2068 /* A regurgitated default argument. The value of DEFARG_MARKER will be
2069 the TREE_LIST node for the parameter in question. */
2070 defarg_again:
2071 DEFARG_MARKER expr_no_commas END_OF_SAVED_INPUT
2072 { replace_defarg ($1, $2); }
2073 | DEFARG_MARKER error END_OF_SAVED_INPUT
2074 { replace_defarg ($1, error_mark_node); }
2076 pending_defargs:
2077 /* empty */ %prec EMPTY
2078 | pending_defargs defarg_again
2079 { do_pending_defargs (); }
2080 | pending_defargs error
2081 { do_pending_defargs (); }
2084 structsp:
2085 ENUM identifier '{'
2086 { $<ttype>$ = current_enum_type;
2087 current_enum_type = start_enum ($2); }
2088 enumlist_opt '}'
2089 { $$.t = finish_enum (current_enum_type);
2090 $$.new_type_flag = 1;
2091 current_enum_type = $<ttype>4;
2092 check_for_missing_semicolon ($$.t); }
2093 | ENUM '{'
2094 { $<ttype>$ = current_enum_type;
2095 current_enum_type = start_enum (make_anon_name ()); }
2096 enumlist_opt '}'
2097 { $$.t = finish_enum (current_enum_type);
2098 $$.new_type_flag = 1;
2099 current_enum_type = $<ttype>3;
2100 check_for_missing_semicolon ($$.t); }
2101 | ENUM identifier
2102 { $$.t = xref_tag (enum_type_node, $2, 1);
2103 $$.new_type_flag = 0; }
2104 | ENUM complex_type_name
2105 { $$.t = xref_tag (enum_type_node, $2, 1);
2106 $$.new_type_flag = 0; }
2107 | TYPENAME_KEYWORD typename_sub
2108 { $$.t = $2;
2109 $$.new_type_flag = 0;
2110 if (!processing_template_decl)
2111 cp_pedwarn ("using `typename' outside of template"); }
2112 /* C++ extensions, merged with C to avoid shift/reduce conflicts */
2113 | class_head '{'
2114 { $1.t = begin_class_definition ($1.t); }
2115 opt.component_decl_list '}' maybe_attribute
2117 int semi;
2119 if (yychar == YYEMPTY)
2120 yychar = YYLEX;
2121 semi = yychar == ';';
2123 $<ttype>$ = finish_class_definition ($1.t, $6, semi,
2124 $1.new_type_flag);
2126 pending_defargs
2128 begin_inline_definitions ();
2130 pending_inlines
2132 finish_inline_definitions ();
2133 $$.t = $<ttype>7;
2134 $$.new_type_flag = 1;
2136 | class_head %prec EMPTY
2138 if ($1.new_type_flag && $1.t != error_mark_node)
2139 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL ($1.t)));
2140 $$.new_type_flag = 0;
2141 if ($1.t == error_mark_node)
2142 $$.t = $1.t;
2143 else if (TYPE_BINFO ($1.t) == NULL_TREE)
2145 cp_error ("%T is not a class type", $1.t);
2146 $$.t = error_mark_node;
2148 else
2150 $$.t = $1.t;
2151 /* struct B: public A; is not accepted by the WP grammar. */
2152 if (CLASS_TYPE_P ($$.t)
2153 && TYPE_BINFO_BASETYPES ($$.t)
2154 && !TYPE_SIZE ($$.t)
2155 && ! TYPE_BEING_DEFINED ($$.t))
2156 cp_error ("base clause without member specification for `%#T'",
2157 $$.t);
2162 maybecomma:
2163 /* empty */
2164 | ','
2167 maybecomma_warn:
2168 /* empty */
2169 | ','
2170 { if (pedantic && !in_system_header)
2171 pedwarn ("comma at end of enumerator list"); }
2174 aggr:
2175 AGGR
2176 | aggr SCSPEC
2177 { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2178 | aggr TYPESPEC
2179 { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2180 | aggr CV_QUALIFIER
2181 { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2182 | aggr AGGR
2183 { error ("no body nor ';' separates two class, struct or union declarations"); }
2184 | aggr attributes
2185 { $$ = build_decl_list ($2, $1); }
2188 named_class_head_sans_basetype:
2189 aggr identifier
2191 current_aggr = $1;
2192 $$ = $2;
2196 named_class_head_sans_basetype_defn:
2197 aggr identifier_defn %prec EMPTY
2198 { current_aggr = $$; $$ = $2; }
2199 | named_class_head_sans_basetype '{'
2200 { yyungetc ('{', 1); }
2201 | named_class_head_sans_basetype ':'
2202 { yyungetc (':', 1); }
2205 named_complex_class_head_sans_basetype:
2206 aggr nested_name_specifier identifier
2208 current_aggr = $1;
2209 $$.t = handle_class_head ($1, $2, $3);
2210 $$.new_type_flag = 1;
2212 | aggr global_scope nested_name_specifier identifier
2214 current_aggr = $1;
2215 $$.t = handle_class_head ($1, $3, $4);
2216 $$.new_type_flag = 1;
2218 | aggr global_scope identifier
2220 current_aggr = $1;
2221 $$.t = handle_class_head ($1, NULL_TREE, $3);
2222 $$.new_type_flag = 1;
2224 | aggr apparent_template_type
2226 current_aggr = $1;
2227 $$.t = $2;
2228 $$.new_type_flag = 0;
2230 | aggr nested_name_specifier apparent_template_type
2232 current_aggr = $1;
2233 $$.t = $3;
2234 if (CP_DECL_CONTEXT ($$.t))
2235 push_scope (CP_DECL_CONTEXT ($$.t));
2236 $$.new_type_flag = 1;
2240 named_class_head:
2241 named_class_head_sans_basetype %prec EMPTY
2243 $$.t = xref_tag (current_aggr, $1, 1);
2244 $$.new_type_flag = 0;
2246 | named_class_head_sans_basetype_defn
2247 { $<ttype>$ = xref_tag (current_aggr, $1, 0); }
2248 /* Class name is unqualified, so we look for base classes
2249 in the current scope. */
2250 maybe_base_class_list %prec EMPTY
2252 $$.t = $<ttype>2;
2253 $$.new_type_flag = 0;
2254 if ($3)
2255 xref_basetypes (current_aggr, $1, $<ttype>2, $3);
2257 | named_complex_class_head_sans_basetype
2258 maybe_base_class_list
2260 if ($1.t != error_mark_node)
2262 $$.t = TREE_TYPE ($1.t);
2263 $$.new_type_flag = $1.new_type_flag;
2264 if (current_aggr == union_type_node
2265 && TREE_CODE ($$.t) != UNION_TYPE)
2266 cp_pedwarn ("`union' tag used in declaring `%#T'",
2267 $$.t);
2268 else if (TREE_CODE ($$.t) == UNION_TYPE
2269 && current_aggr != union_type_node)
2270 cp_pedwarn ("non-`union' tag used in declaring `%#T'", $$);
2271 else if (TREE_CODE ($$.t) == RECORD_TYPE)
2272 /* We might be specializing a template with a different
2273 class-key; deal. */
2274 CLASSTYPE_DECLARED_CLASS ($$.t)
2275 = (current_aggr == class_type_node);
2276 if ($2)
2278 maybe_process_partial_specialization ($$.t);
2279 xref_basetypes (current_aggr, $1.t, $$.t, $2);
2285 unnamed_class_head:
2286 aggr '{'
2287 { $$ = xref_tag ($$, make_anon_name (), 0);
2288 yyungetc ('{', 1); }
2291 /* The tree output of this nonterminal a declarationf or the type
2292 named. If NEW_TYPE_FLAG is set, then the name used in this
2293 class-head was explicitly qualified, e.g.: `struct X::Y'. We have
2294 already called push_scope for X. */
2295 class_head:
2296 unnamed_class_head
2298 $$.t = $1;
2299 $$.new_type_flag = 0;
2301 | named_class_head
2304 maybe_base_class_list:
2305 /* empty */ %prec EMPTY
2306 { $$ = NULL_TREE; }
2307 | ':' see_typename %prec EMPTY
2308 { yyungetc(':', 1); $$ = NULL_TREE; }
2309 | ':' see_typename base_class_list %prec EMPTY
2310 { $$ = $3; }
2313 base_class_list:
2314 base_class
2315 | base_class_list ',' see_typename base_class
2316 { $$ = chainon ($$, $4); }
2319 base_class:
2320 base_class.1
2321 { $$ = finish_base_specifier (access_default_node, $1); }
2322 | base_class_access_list see_typename base_class.1
2323 { $$ = finish_base_specifier ($1, $3); }
2326 base_class.1:
2327 typename_sub
2328 { if ($$ == error_mark_node)
2330 else if (!TYPE_P ($$))
2331 $$ = error_mark_node;
2332 else
2333 $$ = TYPE_MAIN_DECL ($1); }
2334 | nonnested_type
2337 base_class_access_list:
2338 VISSPEC see_typename
2339 | SCSPEC see_typename
2340 { if ($1 != ridpointers[(int)RID_VIRTUAL])
2341 cp_error ("`%D' access", $1);
2342 $$ = access_default_virtual_node; }
2343 | base_class_access_list VISSPEC see_typename
2345 if ($1 != access_default_virtual_node)
2346 error ("multiple access specifiers");
2347 else if ($2 == access_public_node)
2348 $$ = access_public_virtual_node;
2349 else if ($2 == access_protected_node)
2350 $$ = access_protected_virtual_node;
2351 else /* $2 == access_private_node */
2352 $$ = access_private_virtual_node;
2354 | base_class_access_list SCSPEC see_typename
2355 { if ($2 != ridpointers[(int)RID_VIRTUAL])
2356 cp_error ("`%D' access", $2);
2357 else if ($$ == access_public_node)
2358 $$ = access_public_virtual_node;
2359 else if ($$ == access_protected_node)
2360 $$ = access_protected_virtual_node;
2361 else if ($$ == access_private_node)
2362 $$ = access_private_virtual_node;
2363 else
2364 error ("multiple `virtual' specifiers");
2368 opt.component_decl_list:
2369 | component_decl_list
2370 | opt.component_decl_list access_specifier component_decl_list
2371 | opt.component_decl_list access_specifier
2374 access_specifier:
2375 VISSPEC ':'
2377 current_access_specifier = $1;
2381 /* Note: we no longer warn about the semicolon after a component_decl_list.
2382 ARM $9.2 says that the semicolon is optional, and therefore allowed. */
2383 component_decl_list:
2384 component_decl
2386 finish_member_declaration ($1);
2388 | component_decl_list component_decl
2390 finish_member_declaration ($2);
2394 component_decl:
2395 component_decl_1 ';'
2396 | component_decl_1 '}'
2397 { error ("missing ';' before right brace");
2398 yyungetc ('}', 0); }
2399 /* C++: handle constructors, destructors and inline functions */
2400 /* note that INLINE is like a TYPESPEC */
2401 | fn.def2 ':' /* base_init compstmt */
2402 { $$ = finish_method ($$); }
2403 | fn.def2 TRY /* base_init compstmt */
2404 { $$ = finish_method ($$); }
2405 | fn.def2 RETURN_KEYWORD /* base_init compstmt */
2406 { $$ = finish_method ($$); }
2407 | fn.def2 '{' /* nodecls compstmt */
2408 { $$ = finish_method ($$); }
2409 | ';'
2410 { $$ = NULL_TREE; }
2411 | extension component_decl
2412 { $$ = $2;
2413 pedantic = $1; }
2414 | template_header component_decl
2416 if ($2)
2417 $$ = finish_member_template_decl ($2);
2418 else
2419 /* The component was already processed. */
2420 $$ = NULL_TREE;
2422 finish_template_decl ($1);
2424 | template_header typed_declspecs ';'
2426 $$ = finish_member_class_template ($2.t);
2427 finish_template_decl ($1);
2431 component_decl_1:
2432 /* Do not add a "typed_declspecs declarator" rule here for
2433 speed; we need to call grok_x_components for enums, so the
2434 speedup would be insignificant. */
2435 typed_declspecs components
2437 /* Most of the productions for component_decl only
2438 allow the creation of one new member, so we call
2439 finish_member_declaration in component_decl_list.
2440 For this rule and the next, however, there can be
2441 more than one member, e.g.:
2443 int i, j;
2445 and we need the first member to be fully
2446 registered before the second is processed.
2447 Therefore, the rules for components take care of
2448 this processing. To avoid registering the
2449 components more than once, we send NULL_TREE up
2450 here; that lets finish_member_declaration know
2451 that there is nothing to do. */
2452 if (!$2)
2453 grok_x_components ($1.t);
2454 $$ = NULL_TREE;
2456 | declmods notype_components
2458 if (!$2)
2459 grok_x_components ($1.t);
2460 $$ = NULL_TREE;
2462 | notype_declarator maybeasm maybe_attribute maybe_init
2463 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2464 build_tree_list ($3, NULL_TREE)); }
2465 | constructor_declarator maybeasm maybe_attribute maybe_init
2466 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2467 build_tree_list ($3, NULL_TREE)); }
2468 | ':' expr_no_commas
2469 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
2470 | error
2471 { $$ = NULL_TREE; }
2473 /* These rules introduce a reduce/reduce conflict; in
2474 typedef int foo, bar;
2475 class A {
2476 foo (bar);
2478 should "A::foo" be declared as a function or "A::bar" as a data
2479 member? In other words, is "bar" an after_type_declarator or a
2480 parmlist? */
2481 | declmods component_constructor_declarator maybeasm maybe_attribute maybe_init
2482 { tree specs, attrs;
2483 split_specs_attrs ($1.t, &specs, &attrs);
2484 $$ = grokfield ($2, specs, $5, $3,
2485 build_tree_list ($4, attrs)); }
2486 | component_constructor_declarator maybeasm maybe_attribute maybe_init
2487 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2488 build_tree_list ($3, NULL_TREE)); }
2489 | using_decl
2490 { $$ = do_class_using_decl ($1); }
2492 /* The case of exactly one component is handled directly by component_decl. */
2493 /* ??? Huh? ^^^ */
2494 components:
2495 /* empty: possibly anonymous */
2496 { $$ = 0; }
2497 | component_declarator0
2499 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2500 $1 = finish_member_template_decl ($1);
2501 finish_member_declaration ($1);
2502 $$ = 1;
2504 | components ',' component_declarator
2506 check_multiple_declarators ();
2507 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2508 $3 = finish_member_template_decl ($3);
2509 finish_member_declaration ($3);
2510 $$ = 2;
2514 notype_components:
2515 /* empty: possibly anonymous */
2516 { $$ = 0; }
2517 | notype_component_declarator0
2519 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2520 $1 = finish_member_template_decl ($1);
2521 finish_member_declaration ($1);
2522 $$ = 1;
2524 | notype_components ',' notype_component_declarator
2526 check_multiple_declarators ();
2527 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2528 $3 = finish_member_template_decl ($3);
2529 finish_member_declaration ($3);
2530 $$ = 2;
2534 component_declarator0:
2535 after_type_component_declarator0
2536 | notype_component_declarator0
2539 component_declarator:
2540 after_type_component_declarator
2541 | notype_component_declarator
2544 after_type_component_declarator0:
2545 after_type_declarator maybeasm maybe_attribute maybe_init
2546 { split_specs_attrs ($<ttype>0, &current_declspecs,
2547 &prefix_attributes);
2548 $<ttype>0 = current_declspecs;
2549 $$ = grokfield ($$, current_declspecs, $4, $2,
2550 build_tree_list ($3, prefix_attributes)); }
2551 | TYPENAME ':' expr_no_commas maybe_attribute
2552 { split_specs_attrs ($<ttype>0, &current_declspecs,
2553 &prefix_attributes);
2554 $<ttype>0 = current_declspecs;
2555 $$ = grokbitfield ($$, current_declspecs, $3);
2556 cplus_decl_attributes ($$, $4, prefix_attributes); }
2559 notype_component_declarator0:
2560 notype_declarator maybeasm maybe_attribute maybe_init
2561 { split_specs_attrs ($<ttype>0, &current_declspecs,
2562 &prefix_attributes);
2563 $<ttype>0 = current_declspecs;
2564 $$ = grokfield ($$, current_declspecs, $4, $2,
2565 build_tree_list ($3, prefix_attributes)); }
2566 | constructor_declarator maybeasm maybe_attribute maybe_init
2567 { split_specs_attrs ($<ttype>0, &current_declspecs,
2568 &prefix_attributes);
2569 $<ttype>0 = current_declspecs;
2570 $$ = grokfield ($$, current_declspecs, $4, $2,
2571 build_tree_list ($3, prefix_attributes)); }
2572 | IDENTIFIER ':' expr_no_commas maybe_attribute
2573 { split_specs_attrs ($<ttype>0, &current_declspecs,
2574 &prefix_attributes);
2575 $<ttype>0 = current_declspecs;
2576 $$ = grokbitfield ($$, current_declspecs, $3);
2577 cplus_decl_attributes ($$, $4, prefix_attributes); }
2578 | ':' expr_no_commas maybe_attribute
2579 { split_specs_attrs ($<ttype>0, &current_declspecs,
2580 &prefix_attributes);
2581 $<ttype>0 = current_declspecs;
2582 $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2583 cplus_decl_attributes ($$, $3, prefix_attributes); }
2586 after_type_component_declarator:
2587 after_type_declarator maybeasm maybe_attribute maybe_init
2588 { $$ = grokfield ($$, current_declspecs, $4, $2,
2589 build_tree_list ($3, prefix_attributes)); }
2590 | TYPENAME ':' expr_no_commas maybe_attribute
2591 { $$ = grokbitfield ($$, current_declspecs, $3);
2592 cplus_decl_attributes ($$, $4, prefix_attributes); }
2595 notype_component_declarator:
2596 notype_declarator maybeasm maybe_attribute maybe_init
2597 { $$ = grokfield ($$, current_declspecs, $4, $2,
2598 build_tree_list ($3, prefix_attributes)); }
2599 | IDENTIFIER ':' expr_no_commas maybe_attribute
2600 { $$ = grokbitfield ($$, current_declspecs, $3);
2601 cplus_decl_attributes ($$, $4, prefix_attributes); }
2602 | ':' expr_no_commas maybe_attribute
2603 { $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2604 cplus_decl_attributes ($$, $3, prefix_attributes); }
2607 enumlist_opt:
2608 enumlist maybecomma_warn
2609 | maybecomma_warn
2612 /* We chain the enumerators in reverse order.
2613 Because of the way enums are built, the order is
2614 insignificant. Take advantage of this fact. */
2616 enumlist:
2617 enumerator
2618 | enumlist ',' enumerator
2621 enumerator:
2622 identifier
2623 { build_enumerator ($1, NULL_TREE, current_enum_type); }
2624 | identifier '=' expr_no_commas
2625 { build_enumerator ($1, $3, current_enum_type); }
2628 /* ANSI new-type-id (5.3.4) */
2629 new_type_id:
2630 type_specifier_seq new_declarator
2631 { $$.t = build_decl_list ($1.t, $2);
2632 $$.new_type_flag = $1.new_type_flag; }
2633 | type_specifier_seq %prec EMPTY
2634 { $$.t = build_decl_list ($1.t, NULL_TREE);
2635 $$.new_type_flag = $1.new_type_flag; }
2636 /* GNU extension to allow arrays of arbitrary types with
2637 non-constant dimension. */
2638 | '(' type_id ')' '[' expr ']'
2640 if (pedantic)
2641 pedwarn ("ANSI C++ forbids array dimensions with parenthesized type in new");
2642 $$.t = build_parse_node (ARRAY_REF, TREE_VALUE ($2.t), $5);
2643 $$.t = build_decl_list (TREE_PURPOSE ($2.t), $$.t);
2644 $$.new_type_flag = $2.new_type_flag;
2648 cv_qualifiers:
2649 /* empty */ %prec EMPTY
2650 { $$ = NULL_TREE; }
2651 | cv_qualifiers CV_QUALIFIER
2652 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
2655 nonempty_cv_qualifiers:
2656 CV_QUALIFIER
2657 { $$.t = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
2658 $$.new_type_flag = 0; }
2659 | nonempty_cv_qualifiers CV_QUALIFIER
2660 { $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
2661 $$.new_type_flag = $1.new_type_flag; }
2664 /* These rules must follow the rules for function declarations
2665 and component declarations. That way, longer rules are preferred. */
2667 /* An expression which will not live on the momentary obstack. */
2668 maybe_parmlist:
2669 '(' nonnull_exprlist ')'
2670 { $$ = $2; }
2671 | '(' parmlist ')'
2672 { $$ = $2; }
2673 | LEFT_RIGHT
2674 { $$ = empty_parms (); }
2675 | '(' error ')'
2676 { $$ = NULL_TREE; }
2679 /* A declarator that is allowed only after an explicit typespec. */
2681 after_type_declarator_intern:
2682 after_type_declarator
2683 | attributes after_type_declarator
2685 /* Provide support for '(' attributes '*' declarator ')'
2686 etc */
2687 $$ = decl_tree_cons ($1, $2, NULL_TREE);
2691 /* may all be followed by prec '.' */
2692 after_type_declarator:
2693 '*' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY
2694 { $$ = make_pointer_declarator ($2.t, $3); }
2695 | '&' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY
2696 { $$ = make_reference_declarator ($2.t, $3); }
2697 | '*' after_type_declarator_intern %prec UNARY
2698 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2699 | '&' after_type_declarator_intern %prec UNARY
2700 { $$ = make_reference_declarator (NULL_TREE, $2); }
2701 | ptr_to_mem cv_qualifiers after_type_declarator_intern
2702 { tree arg = make_pointer_declarator ($2, $3);
2703 $$ = build_parse_node (SCOPE_REF, $1, arg);
2705 | direct_after_type_declarator
2708 direct_after_type_declarator:
2709 direct_after_type_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
2710 { $$ = make_call_declarator ($$, $2, $3, $4); }
2711 | direct_after_type_declarator '[' expr ']'
2712 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2713 | direct_after_type_declarator '[' ']'
2714 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2715 | '(' after_type_declarator_intern ')'
2716 { $$ = $2; }
2717 | nested_name_specifier type_name %prec EMPTY
2718 { push_nested_class ($1, 3);
2719 $$ = build_parse_node (SCOPE_REF, $$, $2);
2720 TREE_COMPLEXITY ($$) = current_class_depth; }
2721 | type_name %prec EMPTY
2724 nonnested_type:
2725 type_name %prec EMPTY
2727 if (TREE_CODE ($1) == IDENTIFIER_NODE)
2729 $$ = lookup_name ($1, 1);
2730 maybe_note_name_used_in_class ($1, $$);
2732 else
2733 $$ = $1;
2735 | global_scope type_name
2737 if (TREE_CODE ($2) == IDENTIFIER_NODE)
2738 $$ = IDENTIFIER_GLOBAL_VALUE ($2);
2739 else
2740 $$ = $2;
2741 got_scope = NULL_TREE;
2745 complete_type_name:
2746 nonnested_type
2747 | nested_type
2748 | global_scope nested_type
2749 { $$ = $2; }
2752 nested_type:
2753 nested_name_specifier type_name %prec EMPTY
2754 { $$ = get_type_decl ($2); }
2757 /* A declarator allowed whether or not there has been
2758 an explicit typespec. These cannot redeclare a typedef-name. */
2760 notype_declarator_intern:
2761 notype_declarator
2762 | attributes notype_declarator
2764 /* Provide support for '(' attributes '*' declarator ')'
2765 etc */
2766 $$ = decl_tree_cons ($1, $2, NULL_TREE);
2770 notype_declarator:
2771 '*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
2772 { $$ = make_pointer_declarator ($2.t, $3); }
2773 | '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
2774 { $$ = make_reference_declarator ($2.t, $3); }
2775 | '*' notype_declarator_intern %prec UNARY
2776 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2777 | '&' notype_declarator_intern %prec UNARY
2778 { $$ = make_reference_declarator (NULL_TREE, $2); }
2779 | ptr_to_mem cv_qualifiers notype_declarator_intern
2780 { tree arg = make_pointer_declarator ($2, $3);
2781 $$ = build_parse_node (SCOPE_REF, $1, arg);
2783 | direct_notype_declarator
2786 complex_notype_declarator:
2787 '*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
2788 { $$ = make_pointer_declarator ($2.t, $3); }
2789 | '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
2790 { $$ = make_reference_declarator ($2.t, $3); }
2791 | '*' complex_notype_declarator %prec UNARY
2792 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2793 | '&' complex_notype_declarator %prec UNARY
2794 { $$ = make_reference_declarator (NULL_TREE, $2); }
2795 | ptr_to_mem cv_qualifiers notype_declarator_intern
2796 { tree arg = make_pointer_declarator ($2, $3);
2797 $$ = build_parse_node (SCOPE_REF, $1, arg);
2799 | complex_direct_notype_declarator
2802 complex_direct_notype_declarator:
2803 direct_notype_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
2804 { $$ = make_call_declarator ($$, $2, $3, $4); }
2805 | '(' complex_notype_declarator ')'
2806 { $$ = $2; }
2807 | direct_notype_declarator '[' expr ']'
2808 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2809 | direct_notype_declarator '[' ']'
2810 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2811 | notype_qualified_id
2812 { enter_scope_of ($1); }
2813 | nested_name_specifier notype_template_declarator
2814 { got_scope = NULL_TREE;
2815 $$ = build_parse_node (SCOPE_REF, $1, $2);
2816 enter_scope_of ($$);
2820 qualified_id:
2821 nested_name_specifier unqualified_id
2822 { got_scope = NULL_TREE;
2823 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2824 | nested_name_specifier object_template_id
2825 { got_scope = NULL_TREE;
2826 $$ = build_parse_node (SCOPE_REF, $1, $2); }
2829 notype_qualified_id:
2830 nested_name_specifier notype_unqualified_id
2831 { got_scope = NULL_TREE;
2832 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2833 | nested_name_specifier object_template_id
2834 { got_scope = NULL_TREE;
2835 $$ = build_parse_node (SCOPE_REF, $1, $2); }
2838 overqualified_id:
2839 notype_qualified_id
2840 | global_scope notype_qualified_id
2841 { $$ = $2; }
2844 functional_cast:
2845 typespec '(' nonnull_exprlist ')'
2846 { $$ = build_functional_cast ($1.t, $3); }
2847 | typespec '(' expr_or_declarator_intern ')'
2848 { $$ = reparse_decl_as_expr ($1.t, $3); }
2849 | typespec fcast_or_absdcl %prec EMPTY
2850 { $$ = reparse_absdcl_as_expr ($1.t, $2); }
2853 type_name:
2854 TYPENAME
2855 | SELFNAME
2856 | template_type %prec EMPTY
2859 nested_name_specifier:
2860 nested_name_specifier_1
2861 | nested_name_specifier nested_name_specifier_1
2862 { $$ = $2; }
2863 | nested_name_specifier TEMPLATE explicit_template_type SCOPE
2864 { got_scope = $$
2865 = make_typename_type ($1, $3, /*complain=*/1); }
2868 /* Why the @#$%^& do type_name and notype_identifier need to be expanded
2869 inline here?!? (jason) */
2870 nested_name_specifier_1:
2871 TYPENAME SCOPE
2873 if (TREE_CODE ($1) == IDENTIFIER_NODE)
2875 $$ = lastiddecl;
2876 maybe_note_name_used_in_class ($1, $$);
2878 got_scope = $$ =
2879 complete_type (TYPE_MAIN_VARIANT (TREE_TYPE ($$)));
2881 | SELFNAME SCOPE
2883 if (TREE_CODE ($1) == IDENTIFIER_NODE)
2884 $$ = lastiddecl;
2885 got_scope = $$ = TREE_TYPE ($$);
2887 | NSNAME SCOPE
2889 if (TREE_CODE ($$) == IDENTIFIER_NODE)
2890 $$ = lastiddecl;
2891 got_scope = $$;
2893 | template_type SCOPE
2894 { got_scope = $$ = complete_type (TREE_TYPE ($1)); }
2895 /* These break 'const i;'
2896 | IDENTIFIER SCOPE
2898 failed_scope:
2899 cp_error ("`%D' is not an aggregate typedef",
2900 lastiddecl ? lastiddecl : $$);
2901 $$ = error_mark_node;
2903 | PTYPENAME SCOPE
2904 { goto failed_scope; } */
2907 typename_sub:
2908 typename_sub0
2909 | global_scope typename_sub0
2910 { $$ = $2; }
2913 typename_sub0:
2914 typename_sub1 identifier %prec EMPTY
2916 if (TREE_CODE_CLASS (TREE_CODE ($1)) == 't')
2917 $$ = make_typename_type ($1, $2, /*complain=*/1);
2918 else if (TREE_CODE ($2) == IDENTIFIER_NODE)
2919 cp_error ("`%T' is not a class or namespace", $2);
2920 else
2922 $$ = $2;
2923 if (TREE_CODE ($$) == TYPE_DECL)
2924 $$ = TREE_TYPE ($$);
2927 | typename_sub1 template_type %prec EMPTY
2928 { $$ = TREE_TYPE ($2); }
2929 | typename_sub1 explicit_template_type %prec EMPTY
2930 { $$ = make_typename_type ($1, $2, /*complain=*/1); }
2931 | typename_sub1 TEMPLATE explicit_template_type %prec EMPTY
2932 { $$ = make_typename_type ($1, $3, /*complain=*/1); }
2935 typename_sub1:
2936 typename_sub2
2938 if (TREE_CODE ($1) == IDENTIFIER_NODE)
2939 cp_error ("`%T' is not a class or namespace", $1);
2941 | typename_sub1 typename_sub2
2943 if (TREE_CODE_CLASS (TREE_CODE ($1)) == 't')
2944 $$ = make_typename_type ($1, $2, /*complain=*/1);
2945 else if (TREE_CODE ($2) == IDENTIFIER_NODE)
2946 cp_error ("`%T' is not a class or namespace", $2);
2947 else
2949 $$ = $2;
2950 if (TREE_CODE ($$) == TYPE_DECL)
2951 $$ = TREE_TYPE ($$);
2954 | typename_sub1 explicit_template_type SCOPE
2955 { got_scope = $$
2956 = make_typename_type ($1, $2, /*complain=*/1); }
2957 | typename_sub1 TEMPLATE explicit_template_type SCOPE
2958 { got_scope = $$
2959 = make_typename_type ($1, $3, /*complain=*/1); }
2962 typename_sub2:
2963 TYPENAME SCOPE
2965 if (TREE_CODE ($1) != IDENTIFIER_NODE)
2966 $1 = lastiddecl;
2968 /* Retrieve the type for the identifier, which might involve
2969 some computation. */
2970 got_scope = $$ = complete_type (IDENTIFIER_TYPE_VALUE ($1));
2972 if ($$ == error_mark_node)
2973 cp_error ("`%T' is not a class or namespace", $1);
2975 | SELFNAME SCOPE
2977 if (TREE_CODE ($1) != IDENTIFIER_NODE)
2978 $$ = lastiddecl;
2979 got_scope = $$ = complete_type (TREE_TYPE ($$));
2981 | template_type SCOPE
2982 { got_scope = $$ = complete_type (TREE_TYPE ($$)); }
2983 | PTYPENAME SCOPE
2984 | IDENTIFIER SCOPE
2985 | NSNAME SCOPE
2987 if (TREE_CODE ($$) == IDENTIFIER_NODE)
2988 $$ = lastiddecl;
2989 got_scope = $$;
2993 explicit_template_type:
2994 identifier '<' template_arg_list_opt template_close_bracket
2995 { $$ = build_min_nt (TEMPLATE_ID_EXPR, $1, $3); }
2998 complex_type_name:
2999 global_scope type_name
3001 if (TREE_CODE ($2) == IDENTIFIER_NODE)
3002 $$ = IDENTIFIER_GLOBAL_VALUE ($2);
3003 else
3004 $$ = $2;
3005 got_scope = NULL_TREE;
3007 | nested_type
3008 | global_scope nested_type
3009 { $$ = $2; }
3012 ptr_to_mem:
3013 nested_name_specifier '*'
3014 { got_scope = NULL_TREE; }
3015 | global_scope nested_name_specifier '*'
3016 { $$ = $2; got_scope = NULL_TREE; }
3019 /* All uses of explicit global scope must go through this nonterminal so
3020 that got_scope will be set before yylex is called to get the next token. */
3021 global_scope:
3022 SCOPE
3023 { got_scope = void_type_node; }
3026 /* ANSI new-declarator (5.3.4) */
3027 new_declarator:
3028 '*' cv_qualifiers new_declarator
3029 { $$ = make_pointer_declarator ($2, $3); }
3030 | '*' cv_qualifiers %prec EMPTY
3031 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3032 | '&' cv_qualifiers new_declarator %prec EMPTY
3033 { $$ = make_reference_declarator ($2, $3); }
3034 | '&' cv_qualifiers %prec EMPTY
3035 { $$ = make_reference_declarator ($2, NULL_TREE); }
3036 | ptr_to_mem cv_qualifiers %prec EMPTY
3037 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3038 $$ = build_parse_node (SCOPE_REF, $1, arg);
3040 | ptr_to_mem cv_qualifiers new_declarator
3041 { tree arg = make_pointer_declarator ($2, $3);
3042 $$ = build_parse_node (SCOPE_REF, $1, arg);
3044 | direct_new_declarator %prec EMPTY
3047 /* ANSI direct-new-declarator (5.3.4) */
3048 direct_new_declarator:
3049 '[' expr ']'
3050 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3051 | direct_new_declarator '[' expr ']'
3052 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3055 absdcl_intern:
3056 absdcl
3057 | attributes absdcl
3059 /* Provide support for '(' attributes '*' declarator ')'
3060 etc */
3061 $$ = decl_tree_cons ($1, $2, NULL_TREE);
3065 /* ANSI abstract-declarator (8.1) */
3066 absdcl:
3067 '*' nonempty_cv_qualifiers absdcl_intern
3068 { $$ = make_pointer_declarator ($2.t, $3); }
3069 | '*' absdcl_intern
3070 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3071 | '*' nonempty_cv_qualifiers %prec EMPTY
3072 { $$ = make_pointer_declarator ($2.t, NULL_TREE); }
3073 | '*' %prec EMPTY
3074 { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
3075 | '&' nonempty_cv_qualifiers absdcl_intern
3076 { $$ = make_reference_declarator ($2.t, $3); }
3077 | '&' absdcl_intern
3078 { $$ = make_reference_declarator (NULL_TREE, $2); }
3079 | '&' nonempty_cv_qualifiers %prec EMPTY
3080 { $$ = make_reference_declarator ($2.t, NULL_TREE); }
3081 | '&' %prec EMPTY
3082 { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
3083 | ptr_to_mem cv_qualifiers %prec EMPTY
3084 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3085 $$ = build_parse_node (SCOPE_REF, $1, arg);
3087 | ptr_to_mem cv_qualifiers absdcl_intern
3088 { tree arg = make_pointer_declarator ($2, $3);
3089 $$ = build_parse_node (SCOPE_REF, $1, arg);
3091 | direct_abstract_declarator %prec EMPTY
3094 /* ANSI direct-abstract-declarator (8.1) */
3095 direct_abstract_declarator:
3096 '(' absdcl_intern ')'
3097 { $$ = $2; }
3098 /* `(typedef)1' is `int'. */
3099 | direct_abstract_declarator '(' parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
3100 { $$ = make_call_declarator ($$, $3, $5, $6); }
3101 | direct_abstract_declarator LEFT_RIGHT cv_qualifiers exception_specification_opt %prec '.'
3102 { $$ = make_call_declarator ($$, empty_parms (), $3, $4); }
3103 | direct_abstract_declarator '[' expr ']' %prec '.'
3104 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3105 | direct_abstract_declarator '[' ']' %prec '.'
3106 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
3107 | '(' complex_parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
3108 { $$ = make_call_declarator (NULL_TREE, $2, $4, $5); }
3109 | regcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
3110 { set_quals_and_spec ($$, $2, $3); }
3111 | fcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
3112 { set_quals_and_spec ($$, $2, $3); }
3113 | '[' expr ']' %prec '.'
3114 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3115 | '[' ']' %prec '.'
3116 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
3119 /* For C++, decls and stmts can be intermixed, so we don't need to
3120 have a special rule that won't start parsing the stmt section
3121 until we have a stmt that parses without errors. */
3123 stmts:
3124 stmt
3125 | errstmt
3126 | stmts stmt
3127 | stmts errstmt
3130 errstmt:
3131 error ';'
3134 /* Read zero or more forward-declarations for labels
3135 that nested functions can jump to. */
3136 maybe_label_decls:
3137 /* empty */
3138 | label_decls
3139 { if (pedantic)
3140 pedwarn ("ANSI C++ forbids label declarations"); }
3143 label_decls:
3144 label_decl
3145 | label_decls label_decl
3148 label_decl:
3149 LABEL identifiers_or_typenames ';'
3151 while ($2)
3153 finish_label_decl (TREE_VALUE ($2));
3154 $2 = TREE_CHAIN ($2);
3159 /* This is the body of a function definition.
3160 It causes syntax errors to ignore to the next openbrace. */
3161 compstmt_or_error:
3162 compstmt
3164 | error compstmt
3167 compstmt:
3169 { $<ttype>$ = begin_compound_stmt (0); }
3170 compstmtend
3171 { $$ = finish_compound_stmt (0, $<ttype>2); }
3174 simple_if:
3177 $<ttype>$ = begin_if_stmt ();
3178 cond_stmt_keyword = "if";
3180 paren_cond_or_null
3181 { finish_if_stmt_cond ($3, $<ttype>2); }
3182 implicitly_scoped_stmt
3183 { $<ttype>$ = finish_then_clause ($<ttype>2); }
3186 implicitly_scoped_stmt:
3187 compstmt
3188 | { $<ttype>$ = begin_compound_stmt (0); }
3189 simple_stmt
3190 { $$ = finish_compound_stmt (0, $<ttype>1); }
3193 stmt:
3194 compstmt
3196 | simple_stmt
3199 simple_stmt:
3200 decl
3201 { finish_stmt (); }
3202 | expr ';'
3203 { finish_expr_stmt ($1); }
3204 | simple_if ELSE
3205 { begin_else_clause (); }
3206 implicitly_scoped_stmt
3208 finish_else_clause ($<ttype>1);
3209 finish_if_stmt ();
3211 | simple_if %prec IF
3212 { finish_if_stmt (); }
3213 | WHILE
3215 $<ttype>$ = begin_while_stmt ();
3216 cond_stmt_keyword = "while";
3218 paren_cond_or_null
3219 { finish_while_stmt_cond ($3, $<ttype>2); }
3220 already_scoped_stmt
3221 { finish_while_stmt ($<ttype>2); }
3222 | DO
3223 { $<ttype>$ = begin_do_stmt (); }
3224 implicitly_scoped_stmt WHILE
3226 finish_do_body ($<ttype>2);
3227 cond_stmt_keyword = "do";
3229 paren_expr_or_null ';'
3230 { finish_do_stmt ($6, $<ttype>2); }
3231 | FOR
3232 { $<ttype>$ = begin_for_stmt (); }
3233 '(' for.init.statement
3234 { finish_for_init_stmt ($<ttype>2); }
3235 xcond ';'
3236 { finish_for_cond ($6, $<ttype>2); }
3237 xexpr ')'
3238 { finish_for_expr ($9, $<ttype>2); }
3239 already_scoped_stmt
3240 { finish_for_stmt ($9, $<ttype>2); }
3241 | SWITCH
3242 { $<ttype>$ = begin_switch_stmt (); }
3243 '(' condition ')'
3244 { finish_switch_cond ($4, $<ttype>2); }
3245 implicitly_scoped_stmt
3246 { finish_switch_stmt ($4, $<ttype>2); }
3247 | CASE expr_no_commas ':'
3248 { finish_case_label ($2, NULL_TREE); }
3249 stmt
3250 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
3251 { finish_case_label ($2, $4); }
3252 stmt
3253 | DEFAULT ':'
3254 { finish_case_label (NULL_TREE, NULL_TREE); }
3255 stmt
3256 | BREAK ';'
3257 { finish_break_stmt (); }
3258 | CONTINUE ';'
3259 { finish_continue_stmt (); }
3260 | RETURN_KEYWORD ';'
3261 { finish_return_stmt (NULL_TREE); }
3262 | RETURN_KEYWORD expr ';'
3263 { finish_return_stmt ($2); }
3264 | asm_keyword maybe_cv_qualifier '(' string ')' ';'
3266 finish_asm_stmt ($2, $4, NULL_TREE, NULL_TREE,
3267 NULL_TREE);
3269 /* This is the case with just output operands. */
3270 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ')' ';'
3272 finish_asm_stmt ($2, $4, $6, NULL_TREE,
3273 NULL_TREE);
3275 /* This is the case with input operands as well. */
3276 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':' asm_operands ')' ';'
3277 { finish_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
3278 | asm_keyword maybe_cv_qualifier '(' string SCOPE asm_operands ')' ';'
3279 { finish_asm_stmt ($2, $4, NULL_TREE, $6, NULL_TREE); }
3280 /* This is the case with clobbered registers as well. */
3281 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':'
3282 asm_operands ':' asm_clobbers ')' ';'
3283 { finish_asm_stmt ($2, $4, $6, $8, $10); }
3284 | asm_keyword maybe_cv_qualifier '(' string SCOPE asm_operands ':'
3285 asm_clobbers ')' ';'
3286 { finish_asm_stmt ($2, $4, NULL_TREE, $6, $8); }
3287 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands SCOPE
3288 asm_clobbers ')' ';'
3289 { finish_asm_stmt ($2, $4, $6, NULL_TREE, $8); }
3290 | GOTO '*' expr ';'
3292 if (pedantic)
3293 pedwarn ("ANSI C++ forbids computed gotos");
3294 finish_goto_stmt ($3);
3296 | GOTO identifier ';'
3297 { finish_goto_stmt ($2); }
3298 | label_colon stmt
3299 | label_colon '}'
3300 { error ("label must be followed by statement");
3301 yyungetc ('}', 0); }
3302 | ';'
3303 { finish_stmt (); }
3304 | try_block
3305 | using_directive
3306 | namespace_using_decl
3307 { do_local_using_decl ($1); }
3308 | namespace_alias
3311 function_try_block:
3313 { $<ttype>$ = begin_function_try_block (); }
3314 ctor_initializer_opt compstmt
3315 { finish_function_try_block ($<ttype>2); }
3316 handler_seq
3318 finish_function_handler_sequence ($<ttype>2);
3319 $$ = $3;
3323 try_block:
3325 { $<ttype>$ = begin_try_block (); }
3326 compstmt
3327 { finish_try_block ($<ttype>2); }
3328 handler_seq
3329 { finish_handler_sequence ($<ttype>2); }
3332 handler_seq:
3333 handler
3334 | handler_seq handler
3337 handler:
3338 CATCH
3339 { $<ttype>$ = begin_handler(); }
3340 handler_args
3341 { $<ttype>$ = finish_handler_parms ($3, $<ttype>2); }
3342 compstmt
3343 { finish_handler ($<ttype>4, $<ttype>2); }
3346 type_specifier_seq:
3347 typed_typespecs %prec EMPTY
3348 | nonempty_cv_qualifiers %prec EMPTY
3351 handler_args:
3352 '(' ELLIPSIS ')'
3353 { $$ = NULL_TREE; }
3354 /* This doesn't allow reference parameters, the below does.
3355 | '(' type_specifier_seq absdcl ')'
3356 { check_for_new_type ("inside exception declarations", $2);
3357 expand_start_catch_block ($2.t, $3); }
3358 | '(' type_specifier_seq ')'
3359 { check_for_new_type ("inside exception declarations", $2);
3360 expand_start_catch_block ($2.t, NULL_TREE); }
3361 | '(' type_specifier_seq notype_declarator ')'
3362 { check_for_new_type ("inside exception declarations", $2);
3363 expand_start_catch_block ($2.t, $3); }
3364 | '(' typed_typespecs after_type_declarator ')'
3365 { check_for_new_type ("inside exception declarations", $2);
3366 expand_start_catch_block ($2.t, $3); }
3367 This allows reference parameters... */
3368 | '(' parm ')'
3370 check_for_new_type ("inside exception declarations", $2);
3371 $$ = start_handler_parms (TREE_PURPOSE ($2.t),
3372 TREE_VALUE ($2.t));
3376 label_colon:
3377 IDENTIFIER ':'
3378 { finish_label_stmt ($1); }
3379 | PTYPENAME ':'
3380 { finish_label_stmt ($1); }
3381 | TYPENAME ':'
3382 { finish_label_stmt ($1); }
3383 | SELFNAME ':'
3384 { finish_label_stmt ($1); }
3387 for.init.statement:
3388 xexpr ';'
3389 { finish_expr_stmt ($1); }
3390 | decl
3391 | '{' compstmtend
3392 { if (pedantic)
3393 pedwarn ("ANSI C++ forbids compound statements inside for initializations");
3397 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
3399 maybe_cv_qualifier:
3400 /* empty */
3401 { emit_line_note (input_filename, lineno);
3402 $$ = NULL_TREE; }
3403 | CV_QUALIFIER
3404 { emit_line_note (input_filename, lineno); }
3407 xexpr:
3408 /* empty */
3409 { $$ = NULL_TREE; }
3410 | expr
3411 | error
3412 { $$ = NULL_TREE; }
3415 /* These are the operands other than the first string and colon
3416 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
3417 asm_operands:
3418 /* empty */
3419 { $$ = NULL_TREE; }
3420 | nonnull_asm_operands
3423 nonnull_asm_operands:
3424 asm_operand
3425 | nonnull_asm_operands ',' asm_operand
3426 { $$ = chainon ($$, $3); }
3429 asm_operand:
3430 STRING '(' expr ')'
3431 { $$ = build_tree_list ($$, $3); }
3434 asm_clobbers:
3435 STRING
3436 { $$ = tree_cons (NULL_TREE, $$, NULL_TREE); }
3437 | asm_clobbers ',' STRING
3438 { $$ = tree_cons (NULL_TREE, $3, $$); }
3441 /* This is what appears inside the parens in a function declarator.
3442 Its value is represented in the format that grokdeclarator expects.
3444 In C++, declaring a function with no parameters
3445 means that that function takes *no* parameters. */
3447 parmlist:
3448 /* empty */
3450 $$ = empty_parms();
3452 | complex_parmlist
3453 | type_id
3454 { $$ = finish_parmlist (build_tree_list (NULL_TREE, $1.t), 0);
3455 check_for_new_type ("inside parameter list", $1); }
3458 /* This nonterminal does not include the common sequence '(' type_id ')',
3459 as it is ambiguous and must be disambiguated elsewhere. */
3460 complex_parmlist:
3461 parms
3462 { $$ = finish_parmlist ($$, 0); }
3463 | parms_comma ELLIPSIS
3464 { $$ = finish_parmlist ($1, 1); }
3465 /* C++ allows an ellipsis without a separating ',' */
3466 | parms ELLIPSIS
3467 { $$ = finish_parmlist ($1, 1); }
3468 | type_id ELLIPSIS
3469 { $$ = finish_parmlist (build_tree_list (NULL_TREE,
3470 $1.t), 1); }
3471 | ELLIPSIS
3472 { $$ = finish_parmlist (NULL_TREE, 1); }
3473 | parms ':'
3475 /* This helps us recover from really nasty
3476 parse errors, for example, a missing right
3477 parenthesis. */
3478 yyerror ("possibly missing ')'");
3479 $$ = finish_parmlist ($1, 0);
3480 yyungetc (':', 0);
3481 yychar = ')';
3483 | type_id ':'
3485 /* This helps us recover from really nasty
3486 parse errors, for example, a missing right
3487 parenthesis. */
3488 yyerror ("possibly missing ')'");
3489 $$ = finish_parmlist (build_tree_list (NULL_TREE,
3490 $1.t), 0);
3491 yyungetc (':', 0);
3492 yychar = ')';
3496 /* A default argument to a */
3497 defarg:
3499 { maybe_snarf_defarg (); }
3500 defarg1
3501 { $$ = $3; }
3504 defarg1:
3505 DEFARG
3506 | init
3509 /* A nonempty list of parameter declarations or type names. */
3510 parms:
3511 named_parm
3512 { check_for_new_type ("in a parameter list", $1);
3513 $$ = build_tree_list (NULL_TREE, $1.t); }
3514 | parm defarg
3515 { check_for_new_type ("in a parameter list", $1);
3516 $$ = build_tree_list ($2, $1.t); }
3517 | parms_comma full_parm
3518 { check_for_new_type ("in a parameter list", $2);
3519 $$ = chainon ($$, $2.t); }
3520 | parms_comma bad_parm
3521 { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
3522 | parms_comma bad_parm '=' init
3523 { $$ = chainon ($$, build_tree_list ($4, $2)); }
3526 parms_comma:
3527 parms ','
3528 | type_id ','
3529 { check_for_new_type ("in a parameter list", $1);
3530 $$ = build_tree_list (NULL_TREE, $1.t); }
3533 /* A single parameter declaration or parameter type name,
3534 as found in a parmlist. */
3535 named_parm:
3536 /* Here we expand typed_declspecs inline to avoid mis-parsing of
3537 TYPESPEC IDENTIFIER. */
3538 typed_declspecs1 declarator
3539 { tree specs = strip_attrs ($1.t);
3540 $$.new_type_flag = $1.new_type_flag;
3541 $$.t = build_tree_list (specs, $2); }
3542 | typed_typespecs declarator
3543 { $$.t = build_tree_list ($1.t, $2);
3544 $$.new_type_flag = $1.new_type_flag; }
3545 | typespec declarator
3546 { $$.t = build_tree_list (build_decl_list (NULL_TREE, $1.t),
3547 $2);
3548 $$.new_type_flag = $1.new_type_flag; }
3549 | typed_declspecs1 absdcl
3550 { tree specs = strip_attrs ($1.t);
3551 $$.t = build_tree_list (specs, $2);
3552 $$.new_type_flag = $1.new_type_flag; }
3553 | typed_declspecs1 %prec EMPTY
3554 { tree specs = strip_attrs ($1.t);
3555 $$.t = build_tree_list (specs, NULL_TREE);
3556 $$.new_type_flag = $1.new_type_flag; }
3557 | declmods notype_declarator
3558 { tree specs = strip_attrs ($1.t);
3559 $$.t = build_tree_list (specs, $2);
3560 $$.new_type_flag = 0; }
3563 full_parm:
3564 parm
3565 { $$.t = build_tree_list (NULL_TREE, $1.t);
3566 $$.new_type_flag = $1.new_type_flag; }
3567 | parm defarg
3568 { $$.t = build_tree_list ($2, $1.t);
3569 $$.new_type_flag = $1.new_type_flag; }
3572 parm:
3573 named_parm
3574 | type_id
3577 see_typename:
3578 /* empty */ %prec EMPTY
3579 { see_typename (); }
3582 bad_parm:
3583 /* empty */ %prec EMPTY
3585 error ("type specifier omitted for parameter");
3586 $$ = build_tree_list (integer_type_node, NULL_TREE);
3588 | notype_declarator
3590 error ("type specifier omitted for parameter");
3591 if (TREE_CODE ($$) == SCOPE_REF
3592 && (TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TYPE_PARM
3593 || TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TEMPLATE_PARM))
3594 cp_error (" perhaps you want `typename %E' to make it a type", $$);
3595 $$ = build_tree_list (integer_type_node, $$);
3599 exception_specification_opt:
3600 /* empty */ %prec EMPTY
3601 { $$ = NULL_TREE; }
3602 | THROW '(' ansi_raise_identifiers ')' %prec EMPTY
3603 { $$ = $3; }
3604 | THROW LEFT_RIGHT %prec EMPTY
3605 { $$ = empty_except_spec; }
3608 ansi_raise_identifier:
3609 type_id
3611 check_for_new_type ("exception specifier", $1);
3612 $$ = groktypename ($1.t);
3616 ansi_raise_identifiers:
3617 ansi_raise_identifier
3618 { $$ = add_exception_specifier (NULL_TREE, $1, 1); }
3619 | ansi_raise_identifiers ',' ansi_raise_identifier
3620 { $$ = add_exception_specifier ($1, $3, 1); }
3623 conversion_declarator:
3624 /* empty */ %prec EMPTY
3625 { $$ = NULL_TREE; }
3626 | '*' cv_qualifiers conversion_declarator
3627 { $$ = make_pointer_declarator ($2, $3); }
3628 | '&' cv_qualifiers conversion_declarator
3629 { $$ = make_reference_declarator ($2, $3); }
3630 | ptr_to_mem cv_qualifiers conversion_declarator
3631 { tree arg = make_pointer_declarator ($2, $3);
3632 $$ = build_parse_node (SCOPE_REF, $1, arg);
3636 operator:
3637 OPERATOR
3638 { got_scope = NULL_TREE; }
3641 operator_name:
3642 operator '*'
3643 { $$ = ansi_opname[MULT_EXPR]; }
3644 | operator '/'
3645 { $$ = ansi_opname[TRUNC_DIV_EXPR]; }
3646 | operator '%'
3647 { $$ = ansi_opname[TRUNC_MOD_EXPR]; }
3648 | operator '+'
3649 { $$ = ansi_opname[PLUS_EXPR]; }
3650 | operator '-'
3651 { $$ = ansi_opname[MINUS_EXPR]; }
3652 | operator '&'
3653 { $$ = ansi_opname[BIT_AND_EXPR]; }
3654 | operator '|'
3655 { $$ = ansi_opname[BIT_IOR_EXPR]; }
3656 | operator '^'
3657 { $$ = ansi_opname[BIT_XOR_EXPR]; }
3658 | operator '~'
3659 { $$ = ansi_opname[BIT_NOT_EXPR]; }
3660 | operator ','
3661 { $$ = ansi_opname[COMPOUND_EXPR]; }
3662 | operator ARITHCOMPARE
3663 { $$ = ansi_opname[$2]; }
3664 | operator '<'
3665 { $$ = ansi_opname[LT_EXPR]; }
3666 | operator '>'
3667 { $$ = ansi_opname[GT_EXPR]; }
3668 | operator EQCOMPARE
3669 { $$ = ansi_opname[$2]; }
3670 | operator ASSIGN
3671 { $$ = ansi_assopname[$2]; }
3672 | operator '='
3673 { $$ = ansi_opname [MODIFY_EXPR]; }
3674 | operator LSHIFT
3675 { $$ = ansi_opname[$2]; }
3676 | operator RSHIFT
3677 { $$ = ansi_opname[$2]; }
3678 | operator PLUSPLUS
3679 { $$ = ansi_opname[POSTINCREMENT_EXPR]; }
3680 | operator MINUSMINUS
3681 { $$ = ansi_opname[PREDECREMENT_EXPR]; }
3682 | operator ANDAND
3683 { $$ = ansi_opname[TRUTH_ANDIF_EXPR]; }
3684 | operator OROR
3685 { $$ = ansi_opname[TRUTH_ORIF_EXPR]; }
3686 | operator '!'
3687 { $$ = ansi_opname[TRUTH_NOT_EXPR]; }
3688 | operator '?' ':'
3689 { $$ = ansi_opname[COND_EXPR]; }
3690 | operator MIN_MAX
3691 { $$ = ansi_opname[$2]; }
3692 | operator POINTSAT %prec EMPTY
3693 { $$ = ansi_opname[COMPONENT_REF]; }
3694 | operator POINTSAT_STAR %prec EMPTY
3695 { $$ = ansi_opname[MEMBER_REF]; }
3696 | operator LEFT_RIGHT
3697 { $$ = ansi_opname[CALL_EXPR]; }
3698 | operator '[' ']'
3699 { $$ = ansi_opname[ARRAY_REF]; }
3700 | operator NEW %prec EMPTY
3701 { $$ = ansi_opname[NEW_EXPR]; }
3702 | operator DELETE %prec EMPTY
3703 { $$ = ansi_opname[DELETE_EXPR]; }
3704 | operator NEW '[' ']'
3705 { $$ = ansi_opname[VEC_NEW_EXPR]; }
3706 | operator DELETE '[' ']'
3707 { $$ = ansi_opname[VEC_DELETE_EXPR]; }
3708 /* Names here should be looked up in class scope ALSO. */
3709 | operator type_specifier_seq conversion_declarator
3710 { $$ = grokoptypename ($2.t, $3); }
3711 | operator error
3712 { $$ = ansi_opname[ERROR_MARK]; }
3717 #ifdef SPEW_DEBUG
3718 const char *
3719 debug_yytranslate (value)
3720 int value;
3722 return yytname[YYTRANSLATE (value)];
3725 #endif