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