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