OSDN Git Service

d29d4a88822b176a48ca7c913384534f77a4776f
[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, 0)); }
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), 1);
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                     $$ = $3;
2237                   else
2238                     {
2239                       cp_error ("`%T' does not have a nested type named `%D'",
2240                                 $2, $3);
2241                       $$ = xref_tag
2242                         (current_aggr, make_anon_name (), NULL_TREE, 1);
2243                       $$ = TYPE_MAIN_DECL ($$);
2244                     }
2245                 }
2246         | aggr template_type
2247                 { current_aggr = $$; $$ = $2; }
2248         | aggr nested_name_specifier template_type
2249                 { current_aggr = $$; $$ = $3; }
2250         ;
2251
2252 do_xref_defn:
2253           /* empty */  %prec EMPTY
2254                 { $<ttype>$ = xref_tag (current_aggr, $<ttype>0, NULL_TREE, 0); }
2255         ;
2256
2257 named_class_head:
2258           named_class_head_sans_basetype  %prec EMPTY
2259                 { $$ = xref_tag (current_aggr, $1, NULL_TREE, 1); }
2260         | named_class_head_sans_basetype_defn do_xref_defn
2261           maybe_base_class_list  %prec EMPTY
2262                 { 
2263                   $$ = $<ttype>2;
2264                   if ($3)
2265                     xref_basetypes (current_aggr, $1, $<ttype>2, $3); 
2266                 }
2267         | named_complex_class_head_sans_basetype maybe_base_class_list
2268                 { 
2269                   $$ = TREE_TYPE ($1);
2270                   if (TREE_INT_CST_LOW (current_aggr) == union_type 
2271                       && TREE_CODE ($$) != UNION_TYPE)
2272                     cp_pedwarn ("`union' tag used in declaring `%#T'", $$);
2273                   else if (TREE_CODE ($$) == UNION_TYPE
2274                            && TREE_INT_CST_LOW (current_aggr) != union_type)
2275                     cp_pedwarn ("non-`union' tag used in declaring `%#T'", $$);
2276                   if ($2)
2277                     {
2278                       if (IS_AGGR_TYPE ($$) && CLASSTYPE_USE_TEMPLATE ($$))
2279                         {
2280                           if (CLASSTYPE_IMPLICIT_INSTANTIATION ($$)
2281                               && TYPE_SIZE ($$) == NULL_TREE)
2282                             {
2283                               SET_CLASSTYPE_TEMPLATE_SPECIALIZATION ($$);
2284                               if (processing_template_decl)
2285                                 push_template_decl (TYPE_MAIN_DECL ($$));
2286                             }
2287                           else if (CLASSTYPE_TEMPLATE_INSTANTIATION ($$))
2288                             cp_error ("specialization after instantiation of `%T'", $$);
2289                         }
2290                       xref_basetypes (current_aggr, $1, $$, $2); 
2291                     }
2292                 }
2293         ;
2294
2295 unnamed_class_head:
2296           aggr '{'
2297                 { $$ = xref_tag ($$, make_anon_name (), NULL_TREE, 0);
2298                   yyungetc ('{', 1); }
2299         ;
2300
2301 class_head:
2302           unnamed_class_head
2303         | named_class_head
2304         ;
2305
2306 maybe_base_class_list:
2307           /* empty */  %prec EMPTY
2308                 { $$ = NULL_TREE; }
2309         | ':' see_typename  %prec EMPTY
2310                 { yyungetc(':', 1); $$ = NULL_TREE; }
2311         | ':' see_typename base_class_list  %prec EMPTY
2312                 { $$ = $3; }
2313         ;
2314
2315 base_class_list:
2316           base_class
2317         | base_class_list ',' see_typename base_class
2318                 { $$ = chainon ($$, $4); }
2319         ;
2320
2321 base_class:
2322           base_class.1
2323                 {
2324                   tree type = TREE_TYPE ($1);
2325                   if (! is_aggr_type (type, 1))
2326                     $$ = NULL_TREE;
2327                   else if (current_aggr == signature_type_node
2328                            && (! type) && (! IS_SIGNATURE (type)))
2329                     {
2330                       error ("class name not allowed as base signature");
2331                       $$ = NULL_TREE;
2332                     }
2333                   else if (current_aggr == signature_type_node)
2334                     {
2335                       sorry ("signature inheritance, base type `%s' ignored",
2336                              IDENTIFIER_POINTER ($$));
2337                       $$ = build_tree_list (access_public_node, type);
2338                     }
2339                   else if (type && IS_SIGNATURE (type))
2340                     {
2341                       error ("signature name not allowed as base class");
2342                       $$ = NULL_TREE;
2343                     }
2344                   else
2345                     $$ = build_tree_list (access_default_node, type);
2346                 }
2347         | base_class_access_list see_typename base_class.1
2348                 {
2349                   tree type = TREE_TYPE ($3);
2350                   if (current_aggr == signature_type_node)
2351                     error ("access and source specifiers not allowed in signature");
2352                   if (! IS_AGGR_TYPE (type))
2353                     $$ = NULL_TREE;
2354                   else if (current_aggr == signature_type_node
2355                            && (! type) && (! IS_SIGNATURE (type)))
2356                     {
2357                       error ("class name not allowed as base signature");
2358                       $$ = NULL_TREE;
2359                     }
2360                   else if (current_aggr == signature_type_node)
2361                     {
2362                       sorry ("signature inheritance, base type `%s' ignored",
2363                              IDENTIFIER_POINTER ($$));
2364                       $$ = build_tree_list (access_public_node, type);
2365                     }
2366                   else if (type && IS_SIGNATURE (type))
2367                     {
2368                       error ("signature name not allowed as base class");
2369                       $$ = NULL_TREE;
2370                     }
2371                   else
2372                     $$ = build_tree_list ($$, type);
2373                 }
2374         ;
2375
2376 base_class.1:
2377           complete_type_name
2378         | TYPENAME_KEYWORD nested_name_specifier identifier
2379                 { $$ = TYPE_MAIN_DECL (make_typename_type ($2, $3)); }
2380         | TYPENAME_KEYWORD global_scope nested_name_specifier identifier
2381                 { $$ = TYPE_MAIN_DECL (make_typename_type ($3, $4)); }
2382         | SIGOF '(' expr ')'
2383                 {
2384                   if (current_aggr == signature_type_node)
2385                     {
2386                       if (IS_AGGR_TYPE (TREE_TYPE ($3)))
2387                         {
2388                           sorry ("`sigof' as base signature specifier");
2389                           $$ = TREE_TYPE ($3);
2390                         }
2391                       else
2392                         {
2393                           error ("`sigof' applied to non-aggregate expression");
2394                           $$ = error_mark_node;
2395                         }
2396                     }
2397                   else
2398                     {
2399                       error ("`sigof' in struct or class declaration");
2400                       $$ = error_mark_node;
2401                     }
2402                 }
2403         | SIGOF '(' type_id ')'
2404                 {
2405                   if (current_aggr == signature_type_node)
2406                     {
2407                       if (IS_AGGR_TYPE (groktypename ($3.t)))
2408                         {
2409                           sorry ("`sigof' as base signature specifier");
2410                           $$ = groktypename ($3.t);
2411                         }
2412                       else
2413                         {
2414                           error ("`sigof' applied to non-aggregate expression");
2415                           $$ = error_mark_node;
2416                         }
2417                     }
2418                   else
2419                     {
2420                       error ("`sigof' in struct or class declaration");
2421                       $$ = error_mark_node;
2422                     }
2423                 }
2424         ;
2425
2426 base_class_access_list:
2427           VISSPEC see_typename
2428         | SCSPEC see_typename
2429                 { if ($<ttype>$ != ridpointers[(int)RID_VIRTUAL])
2430                     sorry ("non-virtual access");
2431                   $$ = access_default_virtual_node; }
2432         | base_class_access_list VISSPEC see_typename
2433                 { int err = 0;
2434                   if ($2 == access_protected_node)
2435                     {
2436                       warning ("`protected' access not implemented");
2437                       $2 = access_public_node;
2438                       err++;
2439                     }
2440                   else if ($2 == access_public_node)
2441                     {
2442                       if ($1 == access_private_node)
2443                         {
2444                         mixed:
2445                           error ("base class cannot be public and private");
2446                         }
2447                       else if ($1 == access_default_virtual_node)
2448                         $$ = access_public_virtual_node;
2449                     }
2450                   else /* $2 == access_private_node */
2451                     {
2452                       if ($1 == access_public_node)
2453                         goto mixed;
2454                       else if ($1 == access_default_virtual_node)
2455                         $$ = access_private_virtual_node;
2456                     }
2457                 }
2458         | base_class_access_list SCSPEC see_typename
2459                 { if ($2 != ridpointers[(int)RID_VIRTUAL])
2460                     sorry ("non-virtual access");
2461                   if ($$ == access_public_node)
2462                     $$ = access_public_virtual_node;
2463                   else if ($$ == access_private_node)
2464                     $$ = access_private_virtual_node; }
2465         ;
2466
2467 left_curly:
2468           '{'
2469                 { tree t = $<ttype>0;
2470                   push_obstacks_nochange ();
2471                   end_temporary_allocation ();
2472
2473                   if (! IS_AGGR_TYPE (t))
2474                     {
2475                       t = $<ttype>0 = make_lang_type (RECORD_TYPE);
2476                       TYPE_NAME (t) = get_identifier ("erroneous type");
2477                     }
2478                   if (TYPE_SIZE (t))
2479                     duplicate_tag_error (t);
2480                   if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
2481                     {
2482                       t = make_lang_type (TREE_CODE (t));
2483                       pushtag (TYPE_IDENTIFIER ($<ttype>0), t, 0);
2484                       $<ttype>0 = t;
2485                     }
2486                   if (processing_template_decl && TYPE_CONTEXT (t)
2487                       && ! current_class_type)
2488                     push_template_decl (TYPE_STUB_DECL (t));
2489                   pushclass (t, 0);
2490                   TYPE_BEING_DEFINED (t) = 1;
2491                   if (IS_AGGR_TYPE (t) && CLASSTYPE_USE_TEMPLATE (t))
2492                     {
2493                       if (CLASSTYPE_IMPLICIT_INSTANTIATION (t)
2494                           && TYPE_SIZE (t) == NULL_TREE)
2495                         {
2496                           SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (t);
2497                           if (processing_template_decl)
2498                             push_template_decl (TYPE_MAIN_DECL (t));
2499                         }
2500                       else if (CLASSTYPE_TEMPLATE_INSTANTIATION (t))
2501                         cp_error ("specialization after instantiation of `%T'", t);
2502                     }
2503                   /* Reset the interface data, at the earliest possible
2504                      moment, as it might have been set via a class foo;
2505                      before.  */
2506                   /* Don't change signatures.  */
2507                   if (! IS_SIGNATURE (t))
2508                     {
2509                       extern tree pending_vtables;
2510                       int needs_writing;
2511                       tree name = TYPE_IDENTIFIER (t);
2512
2513                       if (! ANON_AGGRNAME_P (name))
2514                         {
2515                           CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2516                           SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2517                             (t, interface_unknown);
2518                         }
2519
2520                       /* Record how to set the access of this class's
2521                          virtual functions.  If write_virtuals == 2 or 3, then
2522                          inline virtuals are ``extern inline''.  */
2523                       switch (write_virtuals)
2524                         {
2525                         case 0:
2526                         case 1:
2527                           needs_writing = 1;
2528                           break;
2529                         case 2:
2530                           needs_writing = !! value_member (name, pending_vtables);
2531                           break;
2532                         case 3:
2533                           needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t)
2534                             && CLASSTYPE_INTERFACE_KNOWN (t);
2535                           break;
2536                         default:
2537                           needs_writing = 0;
2538                         }
2539                       CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
2540                     }
2541 #if 0
2542                   t = TYPE_IDENTIFIER ($<ttype>0);
2543                   if (t && IDENTIFIER_TEMPLATE (t))
2544                     overload_template_name (t, 1);
2545 #endif
2546                 }
2547         ;
2548
2549 self_reference:
2550           /* empty */
2551                 {
2552                   if (CLASSTYPE_TEMPLATE_INFO (current_class_type))
2553                     $$ = NULL_TREE;
2554                   else
2555                     $$ = build_self_reference ();
2556                 }
2557         ;
2558
2559 opt.component_decl_list:
2560           self_reference
2561                 { if ($$) $$ = build_tree_list (access_public_node, $$); }
2562         | self_reference component_decl_list
2563                 {
2564                   if (current_aggr == signature_type_node)
2565                     $$ = build_tree_list (access_public_node, $2);
2566                   else
2567                     $$ = build_tree_list (access_default_node, $2);
2568                   if ($1) $$ = tree_cons (access_public_node, $1, $$);
2569                 }
2570         | opt.component_decl_list VISSPEC ':' component_decl_list
2571                 {
2572                   tree visspec = $2;
2573
2574                   if (current_aggr == signature_type_node)
2575                     {
2576                       error ("access specifier not allowed in signature");
2577                       visspec = access_public_node;
2578                     }
2579                   $$ = chainon ($$, build_tree_list (visspec, $4));
2580                 }
2581         | opt.component_decl_list VISSPEC ':'
2582                 {
2583                   if (current_aggr == signature_type_node)
2584                     error ("access specifier not allowed in signature");
2585                 }
2586         ;
2587
2588 /* Note: we no longer warn about the semicolon after a component_decl_list.
2589    ARM $9.2 says that the semicolon is optional, and therefore allowed.  */
2590 component_decl_list:
2591           component_decl
2592                 { if ($$ == void_type_node) $$ = NULL_TREE; 
2593                 }
2594         | component_decl_list component_decl
2595                 { /* In pushdecl, we created a reverse list of names
2596                      in this binding level.  Make sure that the chain
2597                      of what we're trying to add isn't the item itself
2598                      (which can happen with what pushdecl's doing).  */
2599                   if ($2 != NULL_TREE && $2 != void_type_node)
2600                     {
2601                       if (TREE_CHAIN ($2) != $$)
2602                         $$ = chainon ($$, $2);
2603                       else
2604                         $$ = $2;
2605                     }
2606                 }
2607         ;
2608
2609 component_decl:
2610           component_decl_1 ';'
2611                 { }
2612         | component_decl_1 '}'
2613                 { error ("missing ';' before right brace");
2614                   yyungetc ('}', 0); }
2615         /* C++: handle constructors, destructors and inline functions */
2616         /* note that INLINE is like a TYPESPEC */
2617         | fn.def2 ':' /* base_init compstmt */
2618                 { $$ = finish_method ($$); }
2619         | fn.def2 TRY /* base_init compstmt */
2620                 { $$ = finish_method ($$); }
2621         | fn.def2 RETURN /* base_init compstmt */
2622                 { $$ = finish_method ($$); }
2623         | fn.def2 '{' /* nodecls compstmt */
2624                 { $$ = finish_method ($$); }
2625         | ';'
2626                 { $$ = NULL_TREE; }
2627         ;
2628
2629 component_decl_1:
2630         /* Do not add a "typed_declspecs declarator" rule here for
2631            speed; we need to call grok_x_components for enums, so the
2632            speedup would be insignificant.  */
2633           typed_declspecs components
2634                 { $$ = grok_x_components ($1.t, $2); }
2635         | declmods notype_components
2636                 { $$ = grok_x_components ($1, $2); }
2637         | notype_declarator maybeasm maybe_attribute maybe_init
2638                 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2639                                   build_tree_list ($3, NULL_TREE)); }
2640         | constructor_declarator maybeasm maybe_attribute maybe_init
2641                 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2642                                   build_tree_list ($3, NULL_TREE)); }
2643         | ':' expr_no_commas
2644                 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
2645         | error
2646                 { $$ = NULL_TREE; }
2647
2648         /* These rules introduce a reduce/reduce conflict; in
2649                 typedef int foo, bar;
2650                 class A {
2651                   foo (bar);
2652                 };
2653            should "A::foo" be declared as a function or "A::bar" as a data
2654            member? In other words, is "bar" an after_type_declarator or a
2655            parmlist? */
2656         | declmods component_constructor_declarator maybeasm maybe_attribute maybe_init
2657                 { tree specs, attrs;
2658                   split_specs_attrs ($1, &specs, &attrs);
2659                   $$ = grokfield ($2, specs, $5, $3,
2660                                   build_tree_list ($4, attrs)); }
2661         | component_constructor_declarator maybeasm maybe_attribute maybe_init
2662                 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2663                                   build_tree_list ($3, NULL_TREE)); }
2664         | using_decl
2665                 { $$ = do_class_using_decl ($1); }
2666         ;
2667
2668 /* The case of exactly one component is handled directly by component_decl.  */
2669 /* ??? Huh? ^^^ */
2670 components:
2671           /* empty: possibly anonymous */
2672                 { $$ = NULL_TREE; }
2673         | component_declarator0
2674         | components ',' component_declarator
2675                 {
2676                   /* In this context, void_type_node encodes
2677                      friends.  They have been recorded elsewhere.  */
2678                   if ($$ == void_type_node)
2679                     $$ = $3;
2680                   else
2681                     $$ = chainon ($$, $3);
2682                 }
2683         ;
2684
2685 notype_components:
2686           /* empty: possibly anonymous */
2687                 { $$ = NULL_TREE; }
2688         | notype_component_declarator0
2689         | notype_components ',' notype_component_declarator
2690                 {
2691                   /* In this context, void_type_node encodes
2692                      friends.  They have been recorded elsewhere.  */
2693                   if ($$ == void_type_node)
2694                     $$ = $3;
2695                   else
2696                     $$ = chainon ($$, $3);
2697                 }
2698         ;
2699
2700 component_declarator0:
2701           after_type_component_declarator0
2702         | notype_component_declarator0
2703         ;
2704
2705 component_declarator:
2706           after_type_component_declarator
2707         | notype_component_declarator
2708         ;
2709
2710 after_type_component_declarator0:
2711           after_type_declarator maybeasm maybe_attribute maybe_init
2712                 { split_specs_attrs ($<ttype>0, &current_declspecs,
2713                                      &prefix_attributes);
2714                   $<ttype>0 = current_declspecs;
2715                   $$ = grokfield ($$, current_declspecs, $4, $2,
2716                                   build_tree_list ($3, prefix_attributes)); }
2717         | TYPENAME ':' expr_no_commas maybe_attribute
2718                 { split_specs_attrs ($<ttype>0, &current_declspecs,
2719                                      &prefix_attributes);
2720                   $<ttype>0 = current_declspecs;
2721                   $$ = grokbitfield ($$, current_declspecs, $3);
2722                   cplus_decl_attributes ($$, $4, prefix_attributes); }
2723         ;
2724
2725 notype_component_declarator0:
2726           notype_declarator maybeasm maybe_attribute maybe_init
2727                 { split_specs_attrs ($<ttype>0, &current_declspecs,
2728                                      &prefix_attributes);
2729                   $<ttype>0 = current_declspecs;
2730                   $$ = grokfield ($$, current_declspecs, $4, $2,
2731                                   build_tree_list ($3, prefix_attributes)); }
2732         | constructor_declarator maybeasm maybe_attribute maybe_init
2733                 { split_specs_attrs ($<ttype>0, &current_declspecs,
2734                                      &prefix_attributes);
2735                   $<ttype>0 = current_declspecs;
2736                   $$ = grokfield ($$, current_declspecs, $4, $2,
2737                                   build_tree_list ($3, prefix_attributes)); }
2738         | IDENTIFIER ':' expr_no_commas maybe_attribute
2739                 { split_specs_attrs ($<ttype>0, &current_declspecs,
2740                                      &prefix_attributes);
2741                   $<ttype>0 = current_declspecs;
2742                   $$ = grokbitfield ($$, current_declspecs, $3);
2743                   cplus_decl_attributes ($$, $4, prefix_attributes); }
2744         | ':' expr_no_commas maybe_attribute
2745                 { split_specs_attrs ($<ttype>0, &current_declspecs,
2746                                      &prefix_attributes);
2747                   $<ttype>0 = current_declspecs;
2748                   $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2749                   cplus_decl_attributes ($$, $3, prefix_attributes); }
2750         ;
2751
2752 after_type_component_declarator:
2753           after_type_declarator maybeasm maybe_attribute maybe_init
2754                 { $$ = grokfield ($$, current_declspecs, $4, $2,
2755                                   build_tree_list ($3, prefix_attributes)); }
2756         | TYPENAME ':' expr_no_commas maybe_attribute
2757                 { $$ = grokbitfield ($$, current_declspecs, $3);
2758                   cplus_decl_attributes ($$, $4, prefix_attributes); }
2759         ;
2760
2761 notype_component_declarator:
2762           notype_declarator maybeasm maybe_attribute maybe_init
2763                 { $$ = grokfield ($$, current_declspecs, $4, $2,
2764                                   build_tree_list ($3, prefix_attributes)); }
2765         | IDENTIFIER ':' expr_no_commas maybe_attribute
2766                 { $$ = grokbitfield ($$, current_declspecs, $3);
2767                   cplus_decl_attributes ($$, $4, prefix_attributes); }
2768         | ':' expr_no_commas maybe_attribute
2769                 { $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2770                   cplus_decl_attributes ($$, $3, prefix_attributes); }
2771         ;
2772
2773 /* We chain the enumerators in reverse order.
2774    Because of the way enums are built, the order is
2775    insignificant.  Take advantage of this fact.  */
2776
2777 enumlist:
2778           enumerator
2779         | enumlist ',' enumerator
2780                 { TREE_CHAIN ($3) = $$; $$ = $3; }
2781         ;
2782
2783 enumerator:
2784           identifier
2785                 { $$ = build_enumerator ($$, NULL_TREE); }
2786         | identifier '=' expr_no_commas
2787                 { $$ = build_enumerator ($$, $3); }
2788         ;
2789
2790 /* ANSI new-type-id (5.3.4) */
2791 new_type_id:
2792           type_specifier_seq new_declarator
2793                 { $$.t = build_decl_list ($1.t, $2); 
2794                   $$.new_type_flag = $1.new_type_flag; }
2795         | type_specifier_seq  %prec EMPTY
2796                 { $$.t = build_decl_list ($1.t, NULL_TREE); 
2797                   $$.new_type_flag = $1.new_type_flag; }
2798         /* GNU extension to allow arrays of arbitrary types with
2799            non-constant dimension.  */
2800         | '(' type_id ')' '[' expr ']'
2801                 {
2802                   if (pedantic)
2803                     pedwarn ("ANSI C++ forbids array dimensions with parenthesized type in new");
2804                   $$.t = build_parse_node (ARRAY_REF, TREE_VALUE ($2.t), $5);
2805                   $$.t = build_decl_list (TREE_PURPOSE ($2.t), $$.t);
2806                   $$.new_type_flag = $2.new_type_flag;
2807                 }
2808         ;
2809
2810 cv_qualifiers:
2811           /* empty */  %prec EMPTY
2812                 { $$ = NULL_TREE; }
2813         | cv_qualifiers CV_QUALIFIER
2814                 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
2815         ;
2816
2817 nonempty_cv_qualifiers:
2818           CV_QUALIFIER
2819                 { $$.t = IDENTIFIER_AS_LIST ($1); 
2820                   $$.new_type_flag = 0; }
2821         | nonempty_cv_qualifiers CV_QUALIFIER
2822                 { $$.t = decl_tree_cons (NULL_TREE, $2, $1.t); 
2823                   $$.new_type_flag = $1.new_type_flag; }
2824         ;
2825
2826 /* These rules must follow the rules for function declarations
2827    and component declarations.  That way, longer rules are preferred.  */
2828
2829 suspend_mom:
2830           /* empty */
2831                 { $<itype>$ = suspend_momentary (); } 
2832
2833 /* An expression which will not live on the momentary obstack.  */
2834 nonmomentary_expr:
2835           suspend_mom expr
2836                 { resume_momentary ((int) $<itype>1); $$ = $2; }
2837         ;
2838
2839 /* An expression which will not live on the momentary obstack.  */
2840 maybe_parmlist:
2841           suspend_mom '(' nonnull_exprlist ')'
2842                 { resume_momentary ((int) $<itype>1); $$ = $3; }
2843         | suspend_mom '(' parmlist ')'
2844                 { resume_momentary ((int) $<itype>1); $$ = $3; }
2845         | suspend_mom LEFT_RIGHT
2846                 { resume_momentary ((int) $<itype>1); $$ = empty_parms (); }
2847         | suspend_mom '(' error ')'
2848                 { resume_momentary ((int) $<itype>1); $$ = NULL_TREE; }
2849         ;
2850
2851 /* A declarator that is allowed only after an explicit typespec.  */
2852 /* may all be followed by prec '.' */
2853 after_type_declarator:
2854           '*' nonempty_cv_qualifiers after_type_declarator  %prec UNARY
2855                 { $$ = make_pointer_declarator ($2.t, $3); }
2856         | '&' nonempty_cv_qualifiers after_type_declarator  %prec UNARY
2857                 { $$ = make_reference_declarator ($2.t, $3); }
2858         | '*' after_type_declarator  %prec UNARY
2859                 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2860         | '&' after_type_declarator  %prec UNARY
2861                 { $$ = make_reference_declarator (NULL_TREE, $2); }
2862         | ptr_to_mem cv_qualifiers after_type_declarator
2863                 { tree arg = make_pointer_declarator ($2, $3);
2864                   $$ = build_parse_node (SCOPE_REF, $1, arg);
2865                 }
2866         | direct_after_type_declarator
2867         ;
2868
2869 complete_type_name:
2870           type_name  %prec EMPTY
2871                 {
2872                   if (TREE_CODE ($1) == IDENTIFIER_NODE)
2873                     {
2874                       if (current_class_type
2875                           && TYPE_BEING_DEFINED (current_class_type)
2876                           && ! IDENTIFIER_CLASS_VALUE ($1))
2877                         {
2878                           /* Be sure to get an inherited typedef.  */
2879                           $$ = lookup_name ($1, 1);
2880                           /* Remember that this name has been used in the class
2881                              definition, as per [class.scope0] */
2882                           pushdecl_class_level ($$);
2883                         }
2884                       else
2885                         $$ = identifier_typedecl_value ($1);
2886                     }
2887                   else
2888                     $$ = $1;
2889                 }
2890         | global_scope type_name
2891                 {
2892                   if (TREE_CODE ($2) == IDENTIFIER_NODE)
2893                     $$ = identifier_typedecl_value ($2);
2894                   else
2895                     $$ = $2;
2896                   got_scope = NULL_TREE;
2897                 }
2898         | nested_type
2899         | global_scope nested_type
2900                 { $$ = $2; }
2901         ;
2902
2903 nested_type:
2904           nested_name_specifier type_name  %prec EMPTY
2905                 { $$ = get_type_decl ($2); }
2906         ;
2907
2908 direct_after_type_declarator:
2909           direct_after_type_declarator maybe_parmlist cv_qualifiers exception_specification_opt  %prec '.'
2910                 { $$ = make_call_declarator ($$, $2, $3, $4); }
2911         | direct_after_type_declarator '[' nonmomentary_expr ']'
2912                 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2913         | direct_after_type_declarator '[' ']'
2914                 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2915         | '(' after_type_declarator ')'
2916                 { $$ = $2; }
2917         | nested_name_specifier type_name  %prec EMPTY
2918                 { push_nested_class ($1, 3);
2919                   $$ = build_parse_node (SCOPE_REF, $$, $2);
2920                   TREE_COMPLEXITY ($$) = current_class_depth; }
2921         | type_name  %prec EMPTY
2922         ;
2923
2924 /* A declarator allowed whether or not there has been
2925    an explicit typespec.  These cannot redeclare a typedef-name.  */
2926
2927 notype_declarator:
2928           '*' nonempty_cv_qualifiers notype_declarator  %prec UNARY
2929                 { $$ = make_pointer_declarator ($2.t, $3); }
2930         | '&' nonempty_cv_qualifiers notype_declarator  %prec UNARY
2931                 { $$ = make_reference_declarator ($2.t, $3); }
2932         | '*' notype_declarator  %prec UNARY
2933                 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2934         | '&' notype_declarator  %prec UNARY
2935                 { $$ = make_reference_declarator (NULL_TREE, $2); }
2936         | ptr_to_mem cv_qualifiers notype_declarator
2937                 { tree arg = make_pointer_declarator ($2, $3);
2938                   $$ = build_parse_node (SCOPE_REF, $1, arg);
2939                 }
2940         | direct_notype_declarator
2941         ;
2942
2943 complex_notype_declarator:
2944           '*' nonempty_cv_qualifiers notype_declarator  %prec UNARY
2945                 { $$ = make_pointer_declarator ($2.t, $3); }
2946         | '&' nonempty_cv_qualifiers notype_declarator  %prec UNARY
2947                 { $$ = make_reference_declarator ($2.t, $3); }
2948         | '*' complex_notype_declarator  %prec UNARY
2949                 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2950         | '&' complex_notype_declarator  %prec UNARY
2951                 { $$ = make_reference_declarator (NULL_TREE, $2); }
2952         | ptr_to_mem cv_qualifiers notype_declarator
2953                 { tree arg = make_pointer_declarator ($2, $3);
2954                   $$ = build_parse_node (SCOPE_REF, $1, arg);
2955                 }
2956         | complex_direct_notype_declarator
2957         ;
2958
2959 complex_direct_notype_declarator:
2960           direct_notype_declarator maybe_parmlist cv_qualifiers exception_specification_opt  %prec '.'
2961                 { $$ = make_call_declarator ($$, $2, $3, $4); }
2962         | '(' complex_notype_declarator ')'
2963                 { $$ = $2; }
2964         | direct_notype_declarator '[' nonmomentary_expr ']'
2965                 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2966         | direct_notype_declarator '[' ']'
2967                 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2968         | notype_qualified_id
2969                 { if (OP0 ($$) != current_class_type)
2970                     {
2971                       push_nested_class (OP0 ($$), 3);
2972                       TREE_COMPLEXITY ($$) = current_class_depth;
2973                     }
2974                 }
2975         ;
2976
2977 qualified_id:
2978           nested_name_specifier unqualified_id
2979                 { got_scope = NULL_TREE;
2980                   $$ = build_parse_node (SCOPE_REF, $$, $2); }
2981         ;
2982
2983 notype_qualified_id:
2984           nested_name_specifier notype_unqualified_id
2985                 { got_scope = NULL_TREE;
2986                   $$ = build_parse_node (SCOPE_REF, $$, $2); }
2987         ;
2988
2989 overqualified_id:
2990           notype_qualified_id
2991         | global_scope notype_qualified_id
2992                 { $$ = $2; }
2993         ;
2994
2995 functional_cast:
2996           typespec '(' nonnull_exprlist ')'
2997                 { $$ = build_functional_cast ($1.t, $3); }
2998         | typespec '(' expr_or_declarator ')'
2999                 { $$ = reparse_decl_as_expr ($1.t, $3); }
3000         | typespec fcast_or_absdcl  %prec EMPTY
3001                 { $$ = reparse_absdcl_as_expr ($1.t, $2); }
3002         ;
3003
3004 type_name:
3005           TYPENAME
3006         | SELFNAME
3007         | template_type  %prec EMPTY
3008         ;
3009
3010 nested_name_specifier:
3011           nested_name_specifier_1
3012         | nested_name_specifier nested_name_specifier_1
3013                 { $$ = $2; }
3014         ;
3015
3016 /* Why the @#$%^& do type_name and notype_identifier need to be expanded
3017    inline here?!?  (jason) */
3018 nested_name_specifier_1:
3019           TYPENAME SCOPE
3020                 {
3021                   if (TREE_CODE ($1) == IDENTIFIER_NODE)
3022                     {
3023                       $$ = lastiddecl;
3024                       /* Remember that this name has been used in the class
3025                          definition, as per [class.scope0] */
3026                       if (current_class_type
3027                           && TYPE_BEING_DEFINED (current_class_type)
3028                           && ! IDENTIFIER_CLASS_VALUE ($1))
3029                         pushdecl_class_level ($$);
3030                     }
3031                   got_scope = $$ = TREE_TYPE ($$);
3032                 }
3033         | SELFNAME SCOPE
3034                 {
3035                   if (TREE_CODE ($1) == IDENTIFIER_NODE)
3036                     $$ = lastiddecl;
3037                   got_scope = $$ = TREE_TYPE ($$);
3038                 }
3039         | NSNAME SCOPE
3040                 { got_scope = $$ = $1; }
3041         | template_type SCOPE
3042                 { got_scope = $$ = complete_type (TREE_TYPE ($1)); }
3043 /*      These break 'const i;'
3044         | IDENTIFIER SCOPE
3045                 {
3046                  failed_scope:
3047                   cp_error ("`%D' is not an aggregate typedef", 
3048                             lastiddecl ? lastiddecl : $$);
3049                   $$ = error_mark_node;
3050                 }
3051         | PTYPENAME SCOPE
3052                 { goto failed_scope; } */
3053         ;
3054
3055 complex_type_name:
3056           global_scope type_name
3057                 {
3058                   if (TREE_CODE ($2) == IDENTIFIER_NODE)
3059                     $$ = identifier_typedecl_value ($2);
3060                   else
3061                     $$ = $2;
3062                   got_scope = NULL_TREE;
3063                 }
3064         | nested_type
3065         | global_scope nested_type
3066                 { $$ = $2; }
3067         ;
3068
3069 ptr_to_mem:
3070           nested_name_specifier '*'
3071                 { got_scope = NULL_TREE; }
3072         | global_scope nested_name_specifier '*'
3073                 { $$ = $2; got_scope = NULL_TREE; }
3074         ;
3075
3076 /* All uses of explicit global scope must go through this nonterminal so
3077    that got_scope will be set before yylex is called to get the next token.  */
3078 global_scope:
3079           SCOPE
3080                 { got_scope = void_type_node; }
3081         ;
3082
3083 /* ANSI new-declarator (5.3.4) */
3084 new_declarator:
3085           '*' cv_qualifiers new_declarator
3086                 { $$ = make_pointer_declarator ($2, $3); }
3087         | '*' cv_qualifiers  %prec EMPTY
3088                 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3089         | '&' cv_qualifiers new_declarator  %prec EMPTY
3090                 { $$ = make_reference_declarator ($2, $3); }
3091         | '&' cv_qualifiers  %prec EMPTY
3092                 { $$ = make_reference_declarator ($2, NULL_TREE); }
3093         | ptr_to_mem cv_qualifiers  %prec EMPTY
3094                 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3095                   $$ = build_parse_node (SCOPE_REF, $1, arg);
3096                 }
3097         | ptr_to_mem cv_qualifiers new_declarator
3098                 { tree arg = make_pointer_declarator ($2, $3);
3099                   $$ = build_parse_node (SCOPE_REF, $1, arg);
3100                 }
3101         | direct_new_declarator  %prec EMPTY
3102         ;
3103
3104 /* ANSI direct-new-declarator (5.3.4) */
3105 direct_new_declarator:
3106           '[' expr ']'
3107                 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3108         | direct_new_declarator '[' nonmomentary_expr ']'
3109                 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3110         ;
3111
3112 /* ANSI abstract-declarator (8.1) */
3113 absdcl:
3114           '*' nonempty_cv_qualifiers absdcl
3115                 { $$ = make_pointer_declarator ($2.t, $3); }
3116         | '*' absdcl
3117                 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3118         | '*' nonempty_cv_qualifiers  %prec EMPTY
3119                 { $$ = make_pointer_declarator ($2.t, NULL_TREE); }
3120         | '*'  %prec EMPTY
3121                 { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
3122         | '&' nonempty_cv_qualifiers absdcl
3123                 { $$ = make_reference_declarator ($2.t, $3); }
3124         | '&' absdcl
3125                 { $$ = make_reference_declarator (NULL_TREE, $2); }
3126         | '&' nonempty_cv_qualifiers  %prec EMPTY
3127                 { $$ = make_reference_declarator ($2.t, NULL_TREE); }
3128         | '&'  %prec EMPTY
3129                 { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
3130         | ptr_to_mem cv_qualifiers  %prec EMPTY
3131                 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3132                   $$ = build_parse_node (SCOPE_REF, $1, arg);
3133                 }
3134         | ptr_to_mem cv_qualifiers absdcl
3135                 { tree arg = make_pointer_declarator ($2, $3);
3136                   $$ = build_parse_node (SCOPE_REF, $1, arg);
3137                 }
3138         | direct_abstract_declarator  %prec EMPTY
3139         ;
3140
3141 /* ANSI direct-abstract-declarator (8.1) */
3142 direct_abstract_declarator:
3143           '(' absdcl ')'
3144                 { $$ = $2; }
3145           /* `(typedef)1' is `int'.  */
3146         | PAREN_STAR_PAREN
3147         | direct_abstract_declarator '(' parmlist ')' cv_qualifiers exception_specification_opt  %prec '.'
3148                 { $$ = make_call_declarator ($$, $3, $5, $6); }
3149         | direct_abstract_declarator LEFT_RIGHT cv_qualifiers exception_specification_opt  %prec '.'
3150                 { $$ = make_call_declarator ($$, empty_parms (), $3, $4); }
3151         | direct_abstract_declarator '[' nonmomentary_expr ']'  %prec '.'
3152                 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3153         | direct_abstract_declarator '[' ']'  %prec '.'
3154                 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
3155         | '(' complex_parmlist ')' cv_qualifiers exception_specification_opt  %prec '.'
3156                 { $$ = make_call_declarator (NULL_TREE, $2, $4, $5); }
3157         | regcast_or_absdcl cv_qualifiers exception_specification_opt  %prec '.'
3158                 { set_quals_and_spec ($$, $2, $3); }
3159         | fcast_or_absdcl cv_qualifiers exception_specification_opt  %prec '.'
3160                 { set_quals_and_spec ($$, $2, $3); }
3161         | '[' nonmomentary_expr ']'  %prec '.'
3162                 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3163         | '[' ']'  %prec '.'
3164                 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
3165         ;
3166
3167 /* For C++, decls and stmts can be intermixed, so we don't need to
3168    have a special rule that won't start parsing the stmt section
3169    until we have a stmt that parses without errors.  */
3170
3171 stmts:
3172           stmt
3173         | errstmt
3174         | stmts stmt
3175         | stmts errstmt
3176         ;
3177
3178 errstmt:
3179           error ';'
3180         ;
3181
3182 /* build the LET_STMT node before parsing its contents,
3183   so that any LET_STMTs within the context can have their display pointers
3184   set up to point at this one.  */
3185
3186 .pushlevel:
3187           /* empty */
3188                 { do_pushlevel (); }
3189         ;
3190
3191 .poplevel:
3192           /* empty */
3193                 { $$ = do_poplevel (); }
3194         ;
3195
3196 /* Read zero or more forward-declarations for labels
3197    that nested functions can jump to.  */
3198 maybe_label_decls:
3199           /* empty */
3200         | label_decls
3201                 { if (pedantic)
3202                     pedwarn ("ANSI C++ forbids label declarations"); }
3203         ;
3204
3205 label_decls:
3206           label_decl
3207         | label_decls label_decl
3208         ;
3209
3210 label_decl:
3211           LABEL identifiers_or_typenames ';'
3212                 { tree link;
3213                   for (link = $2; link; link = TREE_CHAIN (link))
3214                     {
3215                       tree label = shadow_label (TREE_VALUE (link));
3216                       C_DECLARED_LABEL_FLAG (label) = 1;
3217                       declare_nonlocal_label (label);
3218                     }
3219                 }
3220         ;
3221
3222 /* This is the body of a function definition.
3223    It causes syntax errors to ignore to the next openbrace.  */
3224 compstmt_or_error:
3225           compstmt
3226                 {}
3227         | error compstmt
3228         ;
3229
3230 compstmt:
3231           '{'
3232                 {
3233                   if (processing_template_decl)
3234                     {
3235                       $<ttype>$ = build_min_nt (COMPOUND_STMT, NULL_TREE);
3236                       add_tree ($<ttype>$);
3237                     }
3238                 }
3239           .pushlevel compstmtend .poplevel
3240                 {
3241                   if (processing_template_decl)
3242                     {
3243                       TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
3244                       TREE_CHAIN ($<ttype>2) = NULL_TREE;
3245                       last_tree = $<ttype>2;
3246                     }
3247                   $$ = $5;
3248                 }
3249         ;
3250
3251 simple_if:
3252           IF
3253                 {
3254                   if (processing_template_decl)
3255                     {
3256                       $<ttype>$ = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE,
3257                                                 NULL_TREE);
3258                       add_tree ($<ttype>$);
3259                     }
3260                   cond_stmt_keyword = "if";
3261                 }
3262           .pushlevel paren_cond_or_null
3263                 {
3264                   if (processing_template_decl)
3265                     {
3266                       if (last_tree != $<ttype>2)
3267                         {
3268                           TREE_OPERAND ($<ttype>2, 0) = last_tree;
3269                           TREE_CHAIN ($<ttype>2) = NULL_TREE;
3270                           last_tree = $<ttype>2;
3271                         }
3272                       else
3273                         TREE_OPERAND ($<ttype>2, 0) = $4;
3274                     }
3275                   else
3276                     {
3277                       emit_line_note (input_filename, lineno);
3278                       expand_start_cond ($4, 0);
3279                     }
3280                 }
3281           implicitly_scoped_stmt
3282                 {
3283                   if (processing_template_decl)
3284                     {
3285                       TREE_OPERAND ($<ttype>2, 1) = TREE_CHAIN ($<ttype>2);
3286                       TREE_CHAIN ($<ttype>2) = NULL_TREE;
3287                       $<ttype>$ = last_tree = $<ttype>2;
3288                     }
3289                 }
3290         ;
3291
3292 implicitly_scoped_stmt:
3293           compstmt
3294                 { finish_stmt (); }
3295         | .pushlevel
3296                 {
3297                   if (processing_template_decl)
3298                     {
3299                       $<ttype>$ = build_min_nt (COMPOUND_STMT, NULL_TREE);
3300                       add_tree ($<ttype>$);
3301                     }
3302                 }
3303           simple_stmt .poplevel
3304                 {
3305                   if (processing_template_decl)
3306                     {
3307                       TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
3308                       TREE_CHAIN ($<ttype>2) = NULL_TREE;
3309                       last_tree = $<ttype>2;
3310                     }
3311                   $$ = $4;
3312                 }
3313         ;
3314
3315 stmt:
3316           compstmt
3317                 { finish_stmt (); }
3318         | simple_stmt
3319         ;
3320
3321 simple_stmt:
3322           decl
3323                 { finish_stmt (); }
3324         | expr ';'
3325                 {
3326                   tree expr = $1;
3327                   if (! processing_template_decl)
3328                     {
3329                       emit_line_note (input_filename, lineno);
3330                       /* Do default conversion if safe and possibly important,
3331                          in case within ({...}).  */
3332                       if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
3333                            && lvalue_p (expr))
3334                           || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
3335                         expr = default_conversion (expr);
3336                     }
3337                   cplus_expand_expr_stmt (expr);
3338                   clear_momentary ();
3339                   finish_stmt (); }
3340         | simple_if ELSE
3341                 { if (! processing_template_decl) expand_start_else (); }
3342           implicitly_scoped_stmt
3343                 {
3344                   if (processing_template_decl)
3345                     {
3346                       TREE_OPERAND ($<ttype>1, 2) = TREE_CHAIN ($<ttype>1);
3347                       TREE_CHAIN ($<ttype>1) = NULL_TREE;
3348                       last_tree = $<ttype>1;
3349                     }
3350                   else
3351                     expand_end_cond ();
3352                 }
3353           .poplevel
3354                 { finish_stmt (); }
3355         | simple_if  %prec IF
3356                 { if (! processing_template_decl) expand_end_cond ();
3357                   do_poplevel ();
3358                   finish_stmt (); }
3359         | WHILE
3360                 {
3361                   if (processing_template_decl)
3362                     {
3363                       $<ttype>$ = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
3364                       add_tree ($<ttype>$);
3365                     }
3366                   else
3367                     {
3368                       emit_nop ();
3369                       emit_line_note (input_filename, lineno);
3370                       expand_start_loop (1); 
3371                     }
3372                   cond_stmt_keyword = "while";
3373                 }
3374           .pushlevel paren_cond_or_null
3375                 {
3376                   if (processing_template_decl)
3377                     {
3378                       if (last_tree != $<ttype>2)
3379                         {
3380                           TREE_OPERAND ($<ttype>2, 0) = last_tree;
3381                           TREE_CHAIN ($<ttype>2) = NULL_TREE;
3382                           last_tree = $<ttype>2;
3383                         }
3384                       else
3385                         TREE_OPERAND ($<ttype>2, 0) = $4;
3386                     }
3387                   else
3388                     {
3389                       emit_line_note (input_filename, lineno);
3390                       expand_exit_loop_if_false (0, $4);
3391                     }
3392                 }
3393           already_scoped_stmt .poplevel
3394                 {
3395                   if (processing_template_decl)
3396                     {
3397                       TREE_OPERAND ($<ttype>2, 1) = TREE_CHAIN ($<ttype>2);
3398                       TREE_CHAIN ($<ttype>2) = NULL_TREE;
3399                       last_tree = $<ttype>2;
3400                     }
3401                   else
3402                     expand_end_loop ();
3403                   finish_stmt ();
3404                 }
3405         | DO
3406                 {
3407                   if (processing_template_decl)
3408                     {
3409                       $<ttype>$ = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
3410                       add_tree ($<ttype>$);
3411                     }
3412                   else
3413                     {
3414                       emit_nop ();
3415                       emit_line_note (input_filename, lineno);
3416                       expand_start_loop_continue_elsewhere (1);
3417                     }
3418                 }
3419           implicitly_scoped_stmt WHILE
3420                 {
3421                   if (processing_template_decl)
3422                     {
3423                       TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
3424                       TREE_CHAIN ($<ttype>2) = NULL_TREE;
3425                       last_tree = $<ttype>2;
3426                     }
3427                   else
3428                     {
3429                       expand_loop_continue_here ();
3430                       cond_stmt_keyword = "do";
3431                     }
3432                 }
3433           paren_expr_or_null ';'
3434                 {
3435                   if (processing_template_decl)
3436                     TREE_OPERAND ($<ttype>2, 1) = $6;
3437                   else
3438                     {
3439                       emit_line_note (input_filename, lineno);
3440                       expand_exit_loop_if_false (0, $6);
3441                       expand_end_loop ();
3442                     }
3443                   clear_momentary ();
3444                   finish_stmt ();
3445                 }
3446         | FOR
3447                 { if (processing_template_decl)
3448                     {
3449                       $<ttype>$ = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE, 
3450                                                 NULL_TREE, NULL_TREE);
3451                       add_tree ($<ttype>$);
3452                     }
3453                   else
3454                     emit_line_note (input_filename, lineno);
3455                   if (flag_new_for_scope > 0)
3456                     {
3457                       /* Conditionalize .pushlevel */
3458                       pushlevel (0);
3459                       note_level_for_for ();
3460                       clear_last_expr ();
3461                       push_momentary ();
3462                       expand_start_bindings (0);
3463                     }
3464                 }
3465           '(' for.init.statement
3466                 {
3467                   if (processing_template_decl)
3468                     {
3469                       if (last_tree != $<ttype>2)
3470                         {
3471                           TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
3472                           TREE_CHAIN ($<ttype>2) = NULL_TREE;
3473                           last_tree = $<ttype>2;
3474                         }
3475                     }
3476                   else
3477                     {
3478                       emit_nop ();
3479                       emit_line_note (input_filename, lineno);
3480                       expand_start_loop_continue_elsewhere (1); 
3481                     }
3482                 }
3483           .pushlevel xcond ';'
3484                 {
3485                   if (processing_template_decl)
3486                     {
3487                       if (last_tree != $<ttype>2)
3488                         {
3489                           TREE_OPERAND ($<ttype>2, 1) = last_tree;
3490                           TREE_CHAIN ($<ttype>2) = NULL_TREE;
3491                           last_tree = $<ttype>2;
3492                         }
3493                       else
3494                         TREE_OPERAND ($<ttype>2, 1) = $7;
3495                     }
3496                   else
3497                     {
3498                       emit_line_note (input_filename, lineno);
3499                       if ($7) expand_exit_loop_if_false (0, $7);
3500                     }
3501                 }
3502           xexpr ')'
3503                 /* Don't let the tree nodes for $10 be discarded
3504                    by clear_momentary during the parsing of the next stmt.  */
3505                 {
3506                   if (processing_template_decl)
3507                     TREE_OPERAND ($<ttype>2, 2) = $10;
3508                   push_momentary ();
3509                 }
3510           already_scoped_stmt .poplevel
3511                 {
3512                   if (processing_template_decl)
3513                     {
3514                       TREE_OPERAND ($<ttype>2, 3) = TREE_CHAIN ($<ttype>2);
3515                       TREE_CHAIN ($<ttype>2) = NULL_TREE;
3516                       last_tree = $<ttype>2;
3517                     }
3518                   else
3519                     {
3520                       emit_line_note (input_filename, lineno);
3521                       expand_loop_continue_here ();
3522                       if ($10) cplus_expand_expr_stmt ($10);
3523                       expand_end_loop ();
3524                     }
3525                   pop_momentary ();
3526                   if (flag_new_for_scope > 0)
3527                     {
3528                       do_poplevel ();
3529                     }
3530                   finish_stmt (); }
3531         | SWITCH .pushlevel '(' condition ')'
3532                 {
3533                   if (processing_template_decl)
3534                     {
3535                       $<ttype>$ = build_min_nt (SWITCH_STMT, $4, NULL_TREE);
3536                       add_tree ($<ttype>$);
3537                     }
3538                   else
3539                     {
3540                       emit_line_note (input_filename, lineno);
3541                       c_expand_start_case ($4);
3542                     }
3543                   push_switch ();
3544                   /* Don't let the tree nodes for $4 be discarded by
3545                      clear_momentary during the parsing of the next stmt.  */
3546                   push_momentary ();
3547                 }
3548           implicitly_scoped_stmt
3549                 {
3550                   if (processing_template_decl)
3551                     {
3552                       TREE_OPERAND ($<ttype>6, 1) = TREE_CHAIN ($<ttype>6);
3553                       TREE_CHAIN ($<ttype>6) = NULL_TREE;
3554                       last_tree = $<ttype>6;
3555                     }
3556                   else
3557                     expand_end_case ($4);
3558                   pop_momentary ();
3559                   pop_switch (); 
3560                 }
3561           .poplevel
3562                 { finish_stmt (); }
3563         | CASE expr_no_commas ':'
3564                 { do_case ($2, NULL_TREE); }
3565           stmt
3566         | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
3567                 { do_case ($2, $4); }
3568           stmt
3569         | DEFAULT ':'
3570                 { do_case (NULL_TREE, NULL_TREE); }
3571           stmt
3572         | BREAK ';'
3573                 { emit_line_note (input_filename, lineno);
3574                   if (processing_template_decl)
3575                     add_tree (build_min_nt (BREAK_STMT));
3576                   else if ( ! expand_exit_something ())
3577                     error ("break statement not within loop or switch"); }
3578         | CONTINUE ';'
3579                 { emit_line_note (input_filename, lineno);
3580                   if (processing_template_decl)
3581                     add_tree (build_min_nt (CONTINUE_STMT));
3582                   else if (! expand_continue_loop (0))
3583                     error ("continue statement not within a loop"); }
3584         | RETURN ';'
3585                 { emit_line_note (input_filename, lineno);
3586                   c_expand_return (NULL_TREE); }
3587         | RETURN expr ';'
3588                 { emit_line_note (input_filename, lineno);
3589                   c_expand_return ($2);
3590                   finish_stmt ();
3591                 }
3592         | asm_keyword maybe_cv_qualifier '(' string ')' ';'
3593                 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3594                   emit_line_note (input_filename, lineno);
3595                   expand_asm ($4);
3596                   finish_stmt ();
3597                 }
3598         /* This is the case with just output operands.  */
3599         | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ')' ';'
3600                 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3601                   emit_line_note (input_filename, lineno);
3602                   c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
3603                                          $2 == ridpointers[(int)RID_VOLATILE],
3604                                          input_filename, lineno);
3605                   finish_stmt ();
3606                 }
3607         /* This is the case with input operands as well.  */
3608         | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':' asm_operands ')' ';'
3609                 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3610                   emit_line_note (input_filename, lineno);
3611                   c_expand_asm_operands ($4, $6, $8, NULL_TREE,
3612                                          $2 == ridpointers[(int)RID_VOLATILE],
3613                                          input_filename, lineno);
3614                   finish_stmt ();
3615                 }
3616         /* This is the case with clobbered registers as well.  */
3617         | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':'
3618           asm_operands ':' asm_clobbers ')' ';'
3619                 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3620                   emit_line_note (input_filename, lineno);
3621                   c_expand_asm_operands ($4, $6, $8, $10,
3622                                          $2 == ridpointers[(int)RID_VOLATILE],
3623                                          input_filename, lineno);
3624                   finish_stmt ();
3625                 }
3626         | GOTO '*' expr ';'
3627                 {
3628                   if (processing_template_decl)
3629                     add_tree (build_min_nt (GOTO_STMT, $3));
3630                   else
3631                     { emit_line_note (input_filename, lineno);
3632                       expand_computed_goto ($3); }
3633                 }
3634         | GOTO identifier ';'
3635                 {
3636                   if (processing_template_decl)
3637                     add_tree (build_min_nt (GOTO_STMT, $2));
3638                   else
3639                     {
3640                       tree decl;
3641                       emit_line_note (input_filename, lineno);
3642                       decl = lookup_label ($2);
3643                       TREE_USED (decl) = 1;
3644                       expand_goto (decl); 
3645                     }
3646                 }
3647         | label_colon stmt
3648                 { finish_stmt (); }
3649         | label_colon '}'
3650                 { error ("label must be followed by statement");
3651                   yyungetc ('}', 0);
3652                   finish_stmt (); }
3653         | ';'
3654                 { finish_stmt (); }
3655         | try_block
3656         ;
3657
3658 function_try_block:
3659           TRY
3660                 {
3661                   if (! current_function_parms_stored)
3662                     store_parm_decls ();
3663                   expand_start_early_try_stmts ();
3664                 }
3665           ctor_initializer_opt compstmt_or_error
3666                 { expand_start_all_catch (); }
3667           handler_seq
3668                 {
3669                   int nested = (hack_decl_function_context
3670                                 (current_function_decl) != NULL_TREE);
3671                   expand_end_all_catch ();
3672                   finish_function (lineno, (int)$3, nested);
3673                 }
3674         ;
3675
3676 try_block:
3677           TRY
3678                 { expand_start_try_stmts (); }
3679           compstmt
3680                 { expand_start_all_catch (); }
3681           handler_seq
3682                 { expand_end_all_catch (); }
3683         ;
3684
3685 handler_seq:
3686           /* empty */
3687         | handler_seq CATCH .pushlevel handler_args compstmt
3688                 { expand_end_catch_block (); }
3689           .poplevel
3690         ;
3691
3692 type_specifier_seq:
3693           typed_typespecs  %prec EMPTY
3694         | nonempty_cv_qualifiers  %prec EMPTY
3695         ;
3696
3697 handler_args:
3698           '(' ELLIPSIS ')'
3699                 { expand_start_catch_block (NULL_TREE, NULL_TREE); }
3700         /* This doesn't allow reference parameters, the below does.
3701         | '(' type_specifier_seq absdcl ')'
3702                 { check_for_new_type ("inside exception declarations", $2);
3703                   expand_start_catch_block ($2.t, $3); }
3704         | '(' type_specifier_seq ')'
3705                 { check_for_new_type ("inside exception declarations", $2);
3706                   expand_start_catch_block ($2.t, NULL_TREE); }
3707         | '(' type_specifier_seq notype_declarator ')'
3708                 { check_for_new_type ("inside exception declarations", $2);
3709                   expand_start_catch_block ($2.t, $3); }
3710         | '(' typed_typespecs after_type_declarator ')'
3711                 { check_for_new_type ("inside exception declarations", $2);
3712                   expand_start_catch_block ($2.t, $3); }
3713         This allows reference parameters...  */
3714         | '(' parm ')'
3715                 { check_for_new_type ("inside exception declarations", $2);
3716                   expand_start_catch_block (TREE_PURPOSE ($2.t),
3717                                             TREE_VALUE ($2.t)); }
3718         ;
3719
3720 label_colon:
3721           IDENTIFIER ':'
3722                 { tree label;
3723                 do_label:
3724                   label = define_label (input_filename, lineno, $1);
3725                   if (label && ! minimal_parse_mode)
3726                     expand_label (label);
3727                 }
3728         | PTYPENAME ':'
3729                 { goto do_label; }
3730         | TYPENAME ':'
3731                 { goto do_label; }
3732         | SELFNAME ':'
3733                 { goto do_label; }
3734         ;
3735
3736 for.init.statement:
3737           xexpr ';'
3738                 { if ($1) cplus_expand_expr_stmt ($1); }
3739         | decl
3740         | '{' compstmtend
3741                 { if (pedantic)
3742                     pedwarn ("ANSI C++ forbids compound statements inside for initializations");
3743                 }
3744         ;
3745
3746 /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
3747
3748 maybe_cv_qualifier:
3749           /* empty */
3750                 { emit_line_note (input_filename, lineno);
3751                   $$ = NULL_TREE; }
3752         | CV_QUALIFIER
3753                 { emit_line_note (input_filename, lineno); }
3754         ;
3755
3756 xexpr:
3757           /* empty */
3758                 { $$ = NULL_TREE; }
3759         | expr
3760         | error
3761                 { $$ = NULL_TREE; }
3762         ;
3763
3764 /* These are the operands other than the first string and colon
3765    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
3766 asm_operands:
3767           /* empty */
3768                 { $$ = NULL_TREE; }
3769         | nonnull_asm_operands
3770         ;
3771
3772 nonnull_asm_operands:
3773           asm_operand
3774         | nonnull_asm_operands ',' asm_operand
3775                 { $$ = chainon ($$, $3); }
3776         ;
3777
3778 asm_operand:
3779           STRING '(' expr ')'
3780                 { $$ = build_tree_list ($$, $3); }
3781         ;
3782
3783 asm_clobbers:
3784           STRING
3785                 { $$ = tree_cons (NULL_TREE, $$, NULL_TREE); }
3786         | asm_clobbers ',' STRING
3787                 { $$ = tree_cons (NULL_TREE, $3, $$); }
3788         ;
3789
3790 /* This is what appears inside the parens in a function declarator.
3791    Its value is represented in the format that grokdeclarator expects.
3792
3793    In C++, declaring a function with no parameters
3794    means that that function takes *no* parameters.  */
3795
3796 parmlist:
3797           /* empty */
3798                 {
3799                   $$ = empty_parms();
3800                 }
3801         | complex_parmlist
3802         | type_id
3803                 { $$ = tree_cons (NULL_TREE, $1.t, void_list_node);
3804                   TREE_PARMLIST ($$) = 1; 
3805                   check_for_new_type ("inside parameter list", $1); }
3806         ;
3807
3808 /* This nonterminal does not include the common sequence '(' type_id ')',
3809    as it is ambiguous and must be disambiguated elsewhere.  */
3810 complex_parmlist:
3811           parms
3812                 {
3813                   $$ = chainon ($$, void_list_node);
3814                   TREE_PARMLIST ($$) = 1;
3815                 }
3816         | parms_comma ELLIPSIS
3817                 {
3818                   TREE_PARMLIST ($$) = 1;
3819                 }
3820         /* C++ allows an ellipsis without a separating ',' */
3821         | parms ELLIPSIS
3822                 {
3823                   TREE_PARMLIST ($$) = 1;
3824                 }
3825         | type_id ELLIPSIS
3826                 {
3827                   $$ = build_tree_list (NULL_TREE, $1.t); 
3828                   TREE_PARMLIST ($$) = 1;
3829                 }
3830         | ELLIPSIS
3831                 {
3832                   $$ = NULL_TREE;
3833                 }
3834         | TYPENAME_ELLIPSIS
3835                 {
3836                   TREE_PARMLIST ($$) = 1;
3837                 }
3838         | parms TYPENAME_ELLIPSIS
3839                 {
3840                   TREE_PARMLIST ($$) = 1;
3841                 }
3842         | type_id TYPENAME_ELLIPSIS
3843                 {
3844                   $$ = build_tree_list (NULL_TREE, $1.t);
3845                   TREE_PARMLIST ($$) = 1;
3846                 }
3847         | parms ':'
3848                 {
3849                   /* This helps us recover from really nasty
3850                      parse errors, for example, a missing right
3851                      parenthesis.  */
3852                   yyerror ("possibly missing ')'");
3853                   $$ = chainon ($$, void_list_node);
3854                   TREE_PARMLIST ($$) = 1;
3855                   yyungetc (':', 0);
3856                   yychar = ')';
3857                 }
3858         | type_id ':'
3859                 {
3860                   /* This helps us recover from really nasty
3861                      parse errors, for example, a missing right
3862                      parenthesis.  */
3863                   yyerror ("possibly missing ')'");
3864                   $$ = tree_cons (NULL_TREE, $1.t, void_list_node);
3865                   TREE_PARMLIST ($$) = 1;
3866                   yyungetc (':', 0);
3867                   yychar = ')';
3868                 }
3869         ;
3870
3871 /* A nonempty list of parameter declarations or type names.  */
3872 parms:
3873           named_parm
3874                 { check_for_new_type ("in a parameter list", $1);
3875                   $$ = build_tree_list (NULL_TREE, $1.t); }
3876         | parm '=' init
3877                 { check_for_new_type ("in a parameter list", $1);
3878                   $$ = build_tree_list ($3, $1.t); }
3879         | parms_comma full_parm
3880                 { check_for_new_type ("in a parameter list", $2);
3881                   $$ = chainon ($$, $2.t); }
3882         | parms_comma bad_parm
3883                 { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
3884         | parms_comma bad_parm '=' init
3885                 { $$ = chainon ($$, build_tree_list ($4, $2)); }
3886         ;
3887
3888 parms_comma:
3889           parms ','
3890         | type_id ','
3891                 { check_for_new_type ("in a parameter list", $1);
3892                   $$ = build_tree_list (NULL_TREE, $1.t); }
3893         ;
3894
3895 /* A single parameter declaration or parameter type name,
3896    as found in a parmlist.  */
3897 named_parm:
3898         /* Here we expand typed_declspecs inline to avoid mis-parsing of
3899            TYPESPEC IDENTIFIER.  */
3900           typed_declspecs1 declarator
3901                 { tree specs = strip_attrs ($1.t);
3902                   $$.new_type_flag = $1.new_type_flag;
3903                   $$.t = build_tree_list (specs, $2); }
3904         | typed_typespecs declarator
3905                 { $$.t = build_tree_list ($1.t, $2); 
3906                   $$.new_type_flag = $1.new_type_flag; }
3907         | typespec declarator
3908                 { $$.t = build_tree_list (get_decl_list ($1.t), $2); 
3909                   $$.new_type_flag = $1.new_type_flag; }
3910         | typed_declspecs1 absdcl
3911                 { tree specs = strip_attrs ($1.t);
3912                   $$.t = build_tree_list (specs, $2);
3913                   $$.new_type_flag = $1.new_type_flag; }
3914         | typed_declspecs1  %prec EMPTY
3915                 { tree specs = strip_attrs ($1.t);
3916                   $$.t = build_tree_list (specs, NULL_TREE); 
3917                   $$.new_type_flag = $1.new_type_flag; }
3918         | declmods notype_declarator
3919                 { tree specs = strip_attrs ($1);
3920                   $$.t = build_tree_list (specs, $2); 
3921                   $$.new_type_flag = 0; }
3922         ;
3923
3924 full_parm:
3925           parm maybe_init
3926                 { $$.t = build_tree_list ($2, $1.t);
3927                   $$.new_type_flag = $1.new_type_flag;  }
3928         ;
3929
3930 parm:
3931           named_parm
3932         | type_id
3933         ;
3934
3935 see_typename:
3936           /* empty */  %prec EMPTY
3937                 { see_typename (); }
3938         ;
3939
3940 bad_parm:
3941           /* empty */ %prec EMPTY
3942                 {
3943                   error ("type specifier omitted for parameter");
3944                   $$ = build_tree_list (integer_type_node, NULL_TREE);
3945                 }
3946         | notype_declarator
3947                 {
3948                   error ("type specifier omitted for parameter");
3949                   if (TREE_CODE ($$) == SCOPE_REF
3950                       && TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TYPE_PARM)
3951                     cp_error ("  perhaps you want `typename %E' to make it a type", $$);
3952                   $$ = build_tree_list (integer_type_node, $$);
3953                 }
3954         ;
3955
3956 exception_specification_opt:
3957           /* empty */  %prec EMPTY
3958                 { $$ = NULL_TREE; }
3959         | THROW '(' ansi_raise_identifiers  ')'  %prec EMPTY
3960                 { $$ = $3; }
3961         | THROW LEFT_RIGHT  %prec EMPTY
3962                 { $$ = build_decl_list (NULL_TREE, NULL_TREE); }
3963         ;
3964
3965 ansi_raise_identifier:
3966           type_id
3967                 { $$ = build_decl_list (NULL_TREE, groktypename($1.t)); }
3968         ;
3969
3970 ansi_raise_identifiers:
3971           ansi_raise_identifier
3972         | ansi_raise_identifiers ',' ansi_raise_identifier
3973                 {
3974                   TREE_CHAIN ($3) = $$;
3975                   $$ = $3;
3976                 }
3977         ;
3978
3979 conversion_declarator:
3980           /* empty */  %prec EMPTY
3981                 { $$ = NULL_TREE; }
3982         | '*' cv_qualifiers conversion_declarator
3983                 { $$ = make_pointer_declarator ($2, $3); }
3984         | '&' cv_qualifiers conversion_declarator
3985                 { $$ = make_reference_declarator ($2, $3); }
3986         | ptr_to_mem cv_qualifiers conversion_declarator
3987                 { tree arg = make_pointer_declarator ($2, $3);
3988                   $$ = build_parse_node (SCOPE_REF, $1, arg);
3989                 }
3990         ;
3991
3992 operator:
3993           OPERATOR
3994                 { got_scope = NULL_TREE; }
3995         ;
3996
3997 operator_name:
3998           operator '*'
3999                 { $$ = ansi_opname[MULT_EXPR]; }
4000         | operator '/'
4001                 { $$ = ansi_opname[TRUNC_DIV_EXPR]; }
4002         | operator '%'
4003                 { $$ = ansi_opname[TRUNC_MOD_EXPR]; }
4004         | operator '+'
4005                 { $$ = ansi_opname[PLUS_EXPR]; }
4006         | operator '-'
4007                 { $$ = ansi_opname[MINUS_EXPR]; }
4008         | operator '&'
4009                 { $$ = ansi_opname[BIT_AND_EXPR]; }
4010         | operator '|'
4011                 { $$ = ansi_opname[BIT_IOR_EXPR]; }
4012         | operator '^'
4013                 { $$ = ansi_opname[BIT_XOR_EXPR]; }
4014         | operator '~'
4015                 { $$ = ansi_opname[BIT_NOT_EXPR]; }
4016         | operator ','
4017                 { $$ = ansi_opname[COMPOUND_EXPR]; }
4018         | operator ARITHCOMPARE
4019                 { $$ = ansi_opname[$2]; }
4020         | operator '<'
4021                 { $$ = ansi_opname[LT_EXPR]; }
4022         | operator '>'
4023                 { $$ = ansi_opname[GT_EXPR]; }
4024         | operator EQCOMPARE
4025                 { $$ = ansi_opname[$2]; }
4026         | operator ASSIGN
4027                 { $$ = ansi_assopname[$2]; }
4028         | operator '='
4029                 { $$ = ansi_opname [MODIFY_EXPR]; }
4030         | operator LSHIFT
4031                 { $$ = ansi_opname[$2]; }
4032         | operator RSHIFT
4033                 { $$ = ansi_opname[$2]; }
4034         | operator PLUSPLUS
4035                 { $$ = ansi_opname[POSTINCREMENT_EXPR]; }
4036         | operator MINUSMINUS
4037                 { $$ = ansi_opname[PREDECREMENT_EXPR]; }
4038         | operator ANDAND
4039                 { $$ = ansi_opname[TRUTH_ANDIF_EXPR]; }
4040         | operator OROR
4041                 { $$ = ansi_opname[TRUTH_ORIF_EXPR]; }
4042         | operator '!'
4043                 { $$ = ansi_opname[TRUTH_NOT_EXPR]; }
4044         | operator '?' ':'
4045                 { $$ = ansi_opname[COND_EXPR]; }
4046         | operator MIN_MAX
4047                 { $$ = ansi_opname[$2]; }
4048         | operator POINTSAT  %prec EMPTY
4049                 { $$ = ansi_opname[COMPONENT_REF]; }
4050         | operator POINTSAT_STAR  %prec EMPTY
4051                 { $$ = ansi_opname[MEMBER_REF]; }
4052         | operator LEFT_RIGHT
4053                 { $$ = ansi_opname[CALL_EXPR]; }
4054         | operator '[' ']'
4055                 { $$ = ansi_opname[ARRAY_REF]; }
4056         | operator NEW  %prec EMPTY
4057                 { $$ = ansi_opname[NEW_EXPR]; }
4058         | operator DELETE  %prec EMPTY
4059                 { $$ = ansi_opname[DELETE_EXPR]; }
4060         | operator NEW '[' ']'
4061                 { $$ = ansi_opname[VEC_NEW_EXPR]; }
4062         | operator DELETE '[' ']'
4063                 { $$ = ansi_opname[VEC_DELETE_EXPR]; }
4064         /* Names here should be looked up in class scope ALSO.  */
4065         | operator type_specifier_seq conversion_declarator
4066                 { $$ = grokoptypename ($2.t, $3); }
4067         | operator error
4068                 { $$ = ansi_opname[ERROR_MARK]; }
4069         ;
4070
4071 %%
4072
4073 #ifdef SPEW_DEBUG
4074 const char *
4075 debug_yytranslate (value)
4076     int value;
4077 {
4078   return yytname[YYTRANSLATE (value)];
4079 }
4080
4081 #endif