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