OSDN Git Service

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