13a728b111c1242f9ad9bb520d0782f5762121c1
[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 if (processing_template_arg)
1385 {
1386 tree id;
1387 arg_looking_for_template = processing_template_arg;
1388 id = lookup_name ($$, 0);
1389 arg_looking_for_template = 0;
1390
1391 if (!id || id == error_mark_node
1392 || (TREE_CODE (id) != TEMPLATE_DECL
1393 && TREE_CODE (id) != TEMPLATE_TEMPLATE_PARM))
1394 id = do_identifier ($$, 1);
1395 $$ = id;
1396 }
1397 else
1398 $$ = do_identifier ($$, 1);
1399 }
1400 | CONSTANT
1401 | boolean.literal
1402 | string
1403 {
1404 if (processing_template_decl)
1405 push_obstacks (&permanent_obstack, &permanent_obstack);
1406 $$ = combine_strings ($$);
1407 if (processing_template_decl)
1408 pop_obstacks ();
1409 }
1410 | '(' expr ')'
1411 { char class;
1412 $$ = $2;
1413 class = TREE_CODE_CLASS (TREE_CODE ($$));
1414 if (class == 'e' || class == '1'
1415 || class == '2' || class == '<')
1416 /* This inhibits warnings in truthvalue_conversion. */
1417 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
1418 | '(' expr_or_declarator ')'
1419 { char class;
1420 $$ = reparse_decl_as_expr (NULL_TREE, $2);
1421 class = TREE_CODE_CLASS (TREE_CODE ($$));
1422 if (class == 'e' || class == '1'
1423 || class == '2' || class == '<')
1424 /* This inhibits warnings in truthvalue_conversion. */
1425 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
1426 | '(' error ')'
1427 { $$ = error_mark_node; }
1428 | '('
1429 { if (current_function_decl == 0)
1430 {
1431 error ("braced-group within expression allowed only inside a function");
1432 YYERROR;
1433 }
1434 keep_next_level ();
1435 $<ttype>$ = expand_start_stmt_expr (); }
1436 compstmt ')'
1437 { tree rtl_exp;
1438 if (pedantic)
1439 pedwarn ("ANSI C++ forbids braced-groups within expressions");
1440 rtl_exp = expand_end_stmt_expr ($<ttype>2);
1441 /* The statements have side effects, so the group does. */
1442 TREE_SIDE_EFFECTS (rtl_exp) = 1;
1443
1444 if (TREE_CODE ($3) == BLOCK)
1445 {
1446 /* Make a BIND_EXPR for the BLOCK already made. */
1447 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
1448 NULL_TREE, rtl_exp, $3);
1449 /* Remove the block from the tree at this point.
1450 It gets put back at the proper place
1451 when the BIND_EXPR is expanded. */
1452 delete_block ($3);
1453 }
1454 else
1455 $$ = $3;
1456 }
1457 | primary '(' nonnull_exprlist ')'
1458 {
1459 $$ = build_x_function_call ($1, $3, current_class_ref);
1460 if (TREE_CODE ($$) == CALL_EXPR
1461 && TREE_TYPE ($$) != void_type_node)
1462 $$ = require_complete_type ($$);
1463 }
1464 | primary LEFT_RIGHT
1465 {
1466 $$ = build_x_function_call ($$, NULL_TREE, current_class_ref);
1467 if (TREE_CODE ($$) == CALL_EXPR
1468 && TREE_TYPE ($$) != void_type_node)
1469 $$ = require_complete_type ($$);
1470 }
1471 | primary '[' expr ']'
1472 { $$ = grok_array_decl ($$, $3); }
1473 | primary PLUSPLUS
1474 { /* If we get an OFFSET_REF, turn it into what it really
1475 means (e.g., a COMPONENT_REF). This way if we've got,
1476 say, a reference to a static member that's being operated
1477 on, we don't end up trying to find a member operator for
1478 the class it's in. */
1479 if (TREE_CODE ($$) == OFFSET_REF)
1480 $$ = resolve_offset_ref ($$);
1481 $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
1482 | primary MINUSMINUS
1483 { if (TREE_CODE ($$) == OFFSET_REF)
1484 $$ = resolve_offset_ref ($$);
1485 $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
1486 /* C++ extensions */
1487 | THIS
1488 { if (current_class_ptr)
1489 {
1490 #ifdef WARNING_ABOUT_CCD
1491 TREE_USED (current_class_ptr) = 1;
1492 #endif
1493 $$ = current_class_ptr;
1494 }
1495 else if (current_function_decl
1496 && DECL_STATIC_FUNCTION_P (current_function_decl))
1497 {
1498 error ("`this' is unavailable for static member functions");
1499 $$ = error_mark_node;
1500 }
1501 else
1502 {
1503 if (current_function_decl)
1504 error ("invalid use of `this' in non-member function");
1505 else
1506 error ("invalid use of `this' at top level");
1507 $$ = error_mark_node;
1508 }
1509 }
1510 | CV_QUALIFIER '(' nonnull_exprlist ')'
1511 {
1512 tree type;
1513 tree id = $$;
1514
1515 /* This is a C cast in C++'s `functional' notation. */
1516 if ($3 == error_mark_node)
1517 {
1518 $$ = error_mark_node;
1519 break;
1520 }
1521 #if 0
1522 if ($3 == NULL_TREE)
1523 {
1524 error ("cannot cast null list to type `%s'",
1525 IDENTIFIER_POINTER (TYPE_NAME (id)));
1526 $$ = error_mark_node;
1527 break;
1528 }
1529 #endif
1530 #if 0
1531 /* type is not set! (mrs) */
1532 if (type == error_mark_node)
1533 $$ = error_mark_node;
1534 else
1535 #endif
1536 {
1537 if (id == ridpointers[(int) RID_CONST])
1538 type = build_type_variant (integer_type_node, 1, 0);
1539 else if (id == ridpointers[(int) RID_VOLATILE])
1540 type = build_type_variant (integer_type_node, 0, 1);
1541 #if 0
1542 /* should not be able to get here (mrs) */
1543 else if (id == ridpointers[(int) RID_FRIEND])
1544 {
1545 error ("cannot cast expression to `friend' type");
1546 $$ = error_mark_node;
1547 break;
1548 }
1549 #endif
1550 else my_friendly_abort (79);
1551 $$ = build_c_cast (type, build_compound_expr ($3));
1552 }
1553 }
1554 | functional_cast
1555 | DYNAMIC_CAST '<' type_id '>' '(' expr ')'
1556 { tree type = groktypename ($3.t);
1557 check_for_new_type ("dynamic_cast", $3);
1558 $$ = build_dynamic_cast (type, $6); }
1559 | STATIC_CAST '<' type_id '>' '(' expr ')'
1560 { tree type = groktypename ($3.t);
1561 check_for_new_type ("static_cast", $3);
1562 $$ = build_static_cast (type, $6); }
1563 | REINTERPRET_CAST '<' type_id '>' '(' expr ')'
1564 { tree type = groktypename ($3.t);
1565 check_for_new_type ("reinterpret_cast", $3);
1566 $$ = build_reinterpret_cast (type, $6); }
1567 | CONST_CAST '<' type_id '>' '(' expr ')'
1568 { tree type = groktypename ($3.t);
1569 check_for_new_type ("const_cast", $3);
1570 $$ = build_const_cast (type, $6); }
1571 | TYPEID '(' expr ')'
1572 { $$ = build_x_typeid ($3); }
1573 | TYPEID '(' type_id ')'
1574 { tree type = groktypename ($3.t);
1575 check_for_new_type ("typeid", $3);
1576 $$ = get_typeid (TYPE_MAIN_VARIANT (type)); }
1577 | global_scope IDENTIFIER
1578 { $$ = do_scoped_id ($2, 1); }
1579 | global_scope operator_name
1580 {
1581 got_scope = NULL_TREE;
1582 if (TREE_CODE ($2) == IDENTIFIER_NODE)
1583 $$ = do_scoped_id ($2, 1);
1584 else
1585 $$ = $2;
1586 }
1587 | overqualified_id %prec HYPERUNARY
1588 { $$ = build_offset_ref (OP0 ($$), OP1 ($$)); }
1589 | overqualified_id '(' nonnull_exprlist ')'
1590 { if (processing_template_decl)
1591 $$ = build_min_nt (CALL_EXPR, copy_to_permanent ($1), $3, NULL_TREE);
1592 else
1593 $$ = build_member_call (OP0 ($$), OP1 ($$), $3); }
1594 | overqualified_id LEFT_RIGHT
1595 { if (processing_template_decl)
1596 $$ = build_min_nt (CALL_EXPR, copy_to_permanent ($1),
1597 NULL_TREE, NULL_TREE);
1598 else
1599 $$ = build_member_call (OP0 ($$), OP1 ($$), NULL_TREE); }
1600 | object object_template_id %prec UNARY
1601 {
1602 $$ = build_x_component_ref ($$, $2, NULL_TREE, 1);
1603 }
1604 | object object_template_id '(' nonnull_exprlist ')'
1605 {
1606 $$ = build_method_call ($1, $2, $4,
1607 NULL_TREE, LOOKUP_NORMAL);
1608 }
1609 | object object_template_id LEFT_RIGHT
1610 {
1611 $$ = build_method_call ($1, $2, NULL_TREE,
1612 NULL_TREE, LOOKUP_NORMAL);
1613 }
1614 | object unqualified_id %prec UNARY
1615 { $$ = build_x_component_ref ($$, $2, NULL_TREE, 1); }
1616 | object overqualified_id %prec UNARY
1617 { if (processing_template_decl)
1618 $$ = build_min_nt (COMPONENT_REF, $1, copy_to_permanent ($2));
1619 else
1620 $$ = build_object_ref ($$, OP0 ($2), OP1 ($2)); }
1621 | object unqualified_id '(' nonnull_exprlist ')'
1622 {
1623 #if 0
1624 /* This is a future direction of this code, but because
1625 build_x_function_call cannot always undo what is done
1626 in build_component_ref entirely yet, we cannot do this. */
1627 $$ = build_x_function_call (build_component_ref ($$, $2, NULL_TREE, 1), $4, current_class_ref);
1628 if (TREE_CODE ($$) == CALL_EXPR
1629 && TREE_TYPE ($$) != void_type_node)
1630 $$ = require_complete_type ($$);
1631 #else
1632 $$ = build_method_call ($$, $2, $4, NULL_TREE,
1633 LOOKUP_NORMAL);
1634 #endif
1635 }
1636 | object unqualified_id LEFT_RIGHT
1637 {
1638 #if 0
1639 /* This is a future direction of this code, but because
1640 build_x_function_call cannot always undo what is done
1641 in build_component_ref entirely yet, we cannot do this. */
1642 $$ = build_x_function_call (build_component_ref ($$, $2, NULL_TREE, 1), NULL_TREE, current_class_ref);
1643 if (TREE_CODE ($$) == CALL_EXPR
1644 && TREE_TYPE ($$) != void_type_node)
1645 $$ = require_complete_type ($$);
1646 #else
1647 $$ = build_method_call ($$, $2, NULL_TREE, NULL_TREE,
1648 LOOKUP_NORMAL);
1649 #endif
1650 }
1651 | object overqualified_id '(' nonnull_exprlist ')'
1652 {
1653 if (IS_SIGNATURE (OP0 ($2)))
1654 {
1655 warning ("signature name in scope resolution ignored");
1656 $$ = build_method_call ($$, OP1 ($2), $4, NULL_TREE,
1657 LOOKUP_NORMAL);
1658 }
1659 else
1660 $$ = build_scoped_method_call ($$, OP0 ($2), OP1 ($2), $4);
1661 }
1662 | object overqualified_id LEFT_RIGHT
1663 {
1664 if (IS_SIGNATURE (OP0 ($2)))
1665 {
1666 warning ("signature name in scope resolution ignored");
1667 $$ = build_method_call ($$, OP1 ($2), NULL_TREE, NULL_TREE,
1668 LOOKUP_NORMAL);
1669 }
1670 else
1671 $$ = build_scoped_method_call ($$, OP0 ($2), OP1 ($2), NULL_TREE);
1672 }
1673 /* p->int::~int() is valid -- 12.4 */
1674 | object '~' TYPESPEC LEFT_RIGHT
1675 {
1676 if (IDENTIFIER_GLOBAL_VALUE ($3)
1677 && (TREE_CODE (TREE_TYPE ($1))
1678 != TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE ($3)))))
1679 cp_error ("`%E' is not of type `%T'", $1, $3);
1680 $$ = cp_convert (void_type_node, $1);
1681 }
1682 | object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT
1683 {
1684 if ($2 != $5)
1685 cp_error ("destructor specifier `%T::~%T()' must have matching names", $2, $5);
1686 if (TREE_CODE (TREE_TYPE ($1))
1687 != TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE ($2))))
1688 cp_error ("`%E' is not of type `%T'", $1, $2);
1689 $$ = cp_convert (void_type_node, $1);
1690 }
1691 | object error
1692 {
1693 $$ = error_mark_node;
1694 }
1695 ;
1696
1697 /* Not needed for now.
1698
1699 primary_no_id:
1700 '(' expr ')'
1701 { $$ = $2; }
1702 | '(' error ')'
1703 { $$ = error_mark_node; }
1704 | '('
1705 { if (current_function_decl == 0)
1706 {
1707 error ("braced-group within expression allowed only inside a function");
1708 YYERROR;
1709 }
1710 $<ttype>$ = expand_start_stmt_expr (); }
1711 compstmt ')'
1712 { if (pedantic)
1713 pedwarn ("ANSI C++ forbids braced-groups within expressions");
1714 $$ = expand_end_stmt_expr ($<ttype>2); }
1715 | primary_no_id '(' nonnull_exprlist ')'
1716 { $$ = build_x_function_call ($$, $3, current_class_ref); }
1717 | primary_no_id LEFT_RIGHT
1718 { $$ = build_x_function_call ($$, NULL_TREE, current_class_ref); }
1719 | primary_no_id '[' expr ']'
1720 { goto do_array; }
1721 | primary_no_id PLUSPLUS
1722 { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
1723 | primary_no_id MINUSMINUS
1724 { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
1725 | SCOPE IDENTIFIER
1726 { goto do_scoped_id; }
1727 | SCOPE operator_name
1728 { if (TREE_CODE ($2) == IDENTIFIER_NODE)
1729 goto do_scoped_id;
1730 goto do_scoped_operator;
1731 }
1732 ;
1733 */
1734
1735 new:
1736 NEW
1737 { $$ = 0; }
1738 | global_scope NEW
1739 { got_scope = NULL_TREE; $$ = 1; }
1740 ;
1741
1742 delete:
1743 DELETE
1744 { $$ = 0; }
1745 | global_scope delete
1746 { got_scope = NULL_TREE; $$ = 1; }
1747 ;
1748
1749 boolean.literal:
1750 CXX_TRUE
1751 { $$ = boolean_true_node; }
1752 | CXX_FALSE
1753 { $$ = boolean_false_node; }
1754 ;
1755
1756 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
1757 string:
1758 STRING
1759 | string STRING
1760 { $$ = chainon ($$, $2); }
1761 ;
1762
1763 nodecls:
1764 /* empty */
1765 {
1766 if (! current_function_parms_stored)
1767 store_parm_decls ();
1768 setup_vtbl_ptr ();
1769 /* Always keep the BLOCK node associated with the outermost
1770 pair of curley braces of a function. These are needed
1771 for correct operation of dwarfout.c. */
1772 keep_next_level ();
1773 }
1774 ;
1775
1776 object:
1777 primary '.'
1778 { got_object = TREE_TYPE ($$); }
1779 | primary POINTSAT
1780 {
1781 $$ = build_x_arrow ($$);
1782 got_object = TREE_TYPE ($$);
1783 }
1784 ;
1785
1786 decl:
1787 typespec initdecls ';'
1788 {
1789 resume_momentary ($2);
1790 if ($1.t && IS_AGGR_TYPE_CODE (TREE_CODE ($1.t)))
1791 note_got_semicolon ($1.t);
1792 }
1793 | typed_declspecs initdecls ';'
1794 {
1795 resume_momentary ($2);
1796 note_list_got_semicolon ($1.t);
1797 }
1798 | declmods notype_initdecls ';'
1799 { resume_momentary ($2); }
1800 | typed_declspecs ';'
1801 {
1802 shadow_tag ($1.t);
1803 note_list_got_semicolon ($1.t);
1804 }
1805 | declmods ';'
1806 { warning ("empty declaration"); }
1807 | extension decl
1808 { pedantic = $<itype>1; }
1809 ;
1810
1811 /* Any kind of declarator (thus, all declarators allowed
1812 after an explicit typespec). */
1813
1814 declarator:
1815 after_type_declarator %prec EMPTY
1816 | notype_declarator %prec EMPTY
1817 ;
1818
1819 /* This is necessary to postpone reduction of `int()()()()'. */
1820 fcast_or_absdcl:
1821 LEFT_RIGHT %prec EMPTY
1822 { $$ = make_call_declarator (NULL_TREE, empty_parms (),
1823 NULL_TREE, NULL_TREE); }
1824 | fcast_or_absdcl LEFT_RIGHT %prec EMPTY
1825 { $$ = make_call_declarator ($$, empty_parms (), NULL_TREE,
1826 NULL_TREE); }
1827 ;
1828
1829 /* ANSI type-id (8.1) */
1830 type_id:
1831 typed_typespecs absdcl
1832 { $$.t = build_decl_list ($1.t, $2);
1833 $$.new_type_flag = $1.new_type_flag; }
1834 | nonempty_cv_qualifiers absdcl
1835 { $$.t = build_decl_list ($1.t, $2);
1836 $$.new_type_flag = $1.new_type_flag; }
1837 | typespec absdcl
1838 { $$.t = build_decl_list (get_decl_list ($1.t), $2);
1839 $$.new_type_flag = $1.new_type_flag; }
1840 | typed_typespecs %prec EMPTY
1841 { $$.t = build_decl_list ($1.t, NULL_TREE);
1842 $$.new_type_flag = $1.new_type_flag; }
1843 | nonempty_cv_qualifiers %prec EMPTY
1844 { $$.t = build_decl_list ($1.t, NULL_TREE);
1845 $$.new_type_flag = $1.new_type_flag; }
1846 ;
1847
1848 /* Declspecs which contain at least one type specifier or typedef name.
1849 (Just `const' or `volatile' is not enough.)
1850 A typedef'd name following these is taken as a name to be declared.
1851 In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
1852
1853 typed_declspecs:
1854 typed_typespecs %prec EMPTY
1855 | typed_declspecs1
1856 ;
1857
1858 typed_declspecs1:
1859 declmods typespec
1860 { $$.t = decl_tree_cons (NULL_TREE, $2.t, $1);
1861 $$.new_type_flag = $2.new_type_flag; }
1862 | typespec reserved_declspecs %prec HYPERUNARY
1863 { $$.t = decl_tree_cons (NULL_TREE, $1.t, $2);
1864 $$.new_type_flag = $1.new_type_flag; }
1865 | typespec reserved_typespecquals reserved_declspecs
1866 { $$.t = decl_tree_cons (NULL_TREE, $1.t, chainon ($2, $3));
1867 $$.new_type_flag = $1.new_type_flag; }
1868 | declmods typespec reserved_declspecs
1869 { $$.t = decl_tree_cons (NULL_TREE, $2.t, chainon ($3, $1));
1870 $$.new_type_flag = $2.new_type_flag; }
1871 | declmods typespec reserved_typespecquals
1872 { $$.t = decl_tree_cons (NULL_TREE, $2.t, chainon ($3, $1));
1873 $$.new_type_flag = $2.new_type_flag; }
1874 | declmods typespec reserved_typespecquals reserved_declspecs
1875 { $$.t = decl_tree_cons (NULL_TREE, $2.t,
1876 chainon ($3, chainon ($4, $1)));
1877 $$.new_type_flag = $2.new_type_flag; }
1878 ;
1879
1880 reserved_declspecs:
1881 SCSPEC
1882 { if (extra_warnings)
1883 warning ("`%s' is not at beginning of declaration",
1884 IDENTIFIER_POINTER ($$));
1885 $$ = build_decl_list (NULL_TREE, $$); }
1886 | reserved_declspecs typespecqual_reserved
1887 { $$ = decl_tree_cons (NULL_TREE, $2.t, $$); }
1888 | reserved_declspecs SCSPEC
1889 { if (extra_warnings)
1890 warning ("`%s' is not at beginning of declaration",
1891 IDENTIFIER_POINTER ($2));
1892 $$ = decl_tree_cons (NULL_TREE, $2, $$); }
1893 | reserved_declspecs attributes
1894 { $$ = decl_tree_cons ($2, NULL_TREE, $1); }
1895 | attributes
1896 { $$ = decl_tree_cons ($1, NULL_TREE, NULL_TREE); }
1897 ;
1898
1899 /* List of just storage classes and type modifiers.
1900 A declaration can start with just this, but then it cannot be used
1901 to redeclare a typedef-name.
1902 In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
1903
1904 declmods:
1905 nonempty_cv_qualifiers %prec EMPTY
1906 { $$ = $1.t; TREE_STATIC ($$) = 1; }
1907 | SCSPEC
1908 { $$ = IDENTIFIER_AS_LIST ($$); }
1909 | declmods CV_QUALIFIER
1910 { $$ = decl_tree_cons (NULL_TREE, $2, $$);
1911 TREE_STATIC ($$) = 1; }
1912 | declmods SCSPEC
1913 { if (extra_warnings && TREE_STATIC ($$))
1914 warning ("`%s' is not at beginning of declaration",
1915 IDENTIFIER_POINTER ($2));
1916 $$ = decl_tree_cons (NULL_TREE, $2, $$);
1917 TREE_STATIC ($$) = TREE_STATIC ($1); }
1918 | declmods attributes
1919 { $$ = decl_tree_cons ($2, NULL_TREE, $1); }
1920 | attributes
1921 { $$ = decl_tree_cons ($1, NULL_TREE, NULL_TREE); }
1922 ;
1923
1924 /* Used instead of declspecs where storage classes are not allowed
1925 (that is, for typenames and structure components).
1926
1927 C++ can takes storage classes for structure components.
1928 Don't accept a typedef-name if anything but a modifier precedes it. */
1929
1930 typed_typespecs:
1931 typespec %prec EMPTY
1932 { $$.t = get_decl_list ($1.t);
1933 $$.new_type_flag = $1.new_type_flag; }
1934 | nonempty_cv_qualifiers typespec
1935 { $$.t = decl_tree_cons (NULL_TREE, $2.t, $1.t);
1936 $$.new_type_flag = $2.new_type_flag; }
1937 | typespec reserved_typespecquals
1938 { $$.t = decl_tree_cons (NULL_TREE, $1.t, $2);
1939 $$.new_type_flag = $1.new_type_flag; }
1940 | nonempty_cv_qualifiers typespec reserved_typespecquals
1941 { $$.t = decl_tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
1942 $$.new_type_flag = $1.new_type_flag; }
1943 ;
1944
1945 reserved_typespecquals:
1946 typespecqual_reserved
1947 { $$ = build_decl_list (NULL_TREE, $1.t); }
1948 | reserved_typespecquals typespecqual_reserved
1949 { $$ = decl_tree_cons (NULL_TREE, $2.t, $1); }
1950 ;
1951
1952 /* A typespec (but not a type qualifier).
1953 Once we have seen one of these in a declaration,
1954 if a typedef name appears then it is being redeclared. */
1955
1956 typespec:
1957 structsp
1958 | TYPESPEC %prec EMPTY
1959 { $$.t = $1; $$.new_type_flag = 0; }
1960 | complete_type_name
1961 { $$.t = $1; $$.new_type_flag = 0; }
1962 | TYPEOF '(' expr ')'
1963 { $$.t = TREE_TYPE ($3);
1964 $$.new_type_flag = 0; }
1965 | TYPEOF '(' type_id ')'
1966 { $$.t = groktypename ($3.t);
1967 $$.new_type_flag = 0; }
1968 | SIGOF '(' expr ')'
1969 { tree type = TREE_TYPE ($3);
1970
1971 $$.new_type_flag = 0;
1972 if (IS_AGGR_TYPE (type))
1973 {
1974 sorry ("sigof type specifier");
1975 $$.t = type;
1976 }
1977 else
1978 {
1979 error ("`sigof' applied to non-aggregate expression");
1980 $$.t = error_mark_node;
1981 }
1982 }
1983 | SIGOF '(' type_id ')'
1984 { tree type = groktypename ($3.t);
1985
1986 $$.new_type_flag = 0;
1987 if (IS_AGGR_TYPE (type))
1988 {
1989 sorry ("sigof type specifier");
1990 $$.t = type;
1991 }
1992 else
1993 {
1994 error("`sigof' applied to non-aggregate type");
1995 $$.t = error_mark_node;
1996 }
1997 }
1998 ;
1999
2000 /* A typespec that is a reserved word, or a type qualifier. */
2001
2002 typespecqual_reserved:
2003 TYPESPEC
2004 { $$.t = $1; $$.new_type_flag = 0; }
2005 | CV_QUALIFIER
2006 { $$.t = $1; $$.new_type_flag = 0; }
2007 | structsp
2008 ;
2009
2010 initdecls:
2011 initdcl0
2012 | initdecls ',' initdcl
2013 ;
2014
2015 notype_initdecls:
2016 notype_initdcl0
2017 | notype_initdecls ',' initdcl
2018 ;
2019
2020 nomods_initdecls:
2021 nomods_initdcl0
2022 | nomods_initdecls ',' initdcl
2023 ;
2024
2025 maybeasm:
2026 /* empty */
2027 { $$ = NULL_TREE; }
2028 | asm_keyword '(' string ')'
2029 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); $$ = $3; }
2030 ;
2031
2032 initdcl0:
2033 declarator maybeasm maybe_attribute '='
2034 { split_specs_attrs ($<ttype>0, &current_declspecs,
2035 &prefix_attributes);
2036 if (current_declspecs
2037 && TREE_CODE (current_declspecs) != TREE_LIST)
2038 current_declspecs = get_decl_list (current_declspecs);
2039 if (have_extern_spec && !used_extern_spec)
2040 {
2041 current_declspecs = decl_tree_cons
2042 (NULL_TREE, get_identifier ("extern"),
2043 current_declspecs);
2044 used_extern_spec = 1;
2045 }
2046 $<itype>4 = suspend_momentary ();
2047 $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1);
2048 cplus_decl_attributes ($<ttype>$, $3, prefix_attributes); }
2049 init
2050 /* Note how the declaration of the variable is in effect while its init is parsed! */
2051 { cp_finish_decl ($<ttype>5, $6, $2, 1, LOOKUP_ONLYCONVERTING);
2052 $$ = $<itype>4; }
2053 | declarator maybeasm maybe_attribute
2054 { tree d;
2055 split_specs_attrs ($<ttype>0, &current_declspecs,
2056 &prefix_attributes);
2057 if (current_declspecs
2058 && TREE_CODE (current_declspecs) != TREE_LIST)
2059 current_declspecs = get_decl_list (current_declspecs);
2060 if (have_extern_spec && !used_extern_spec)
2061 {
2062 current_declspecs = decl_tree_cons
2063 (NULL_TREE, get_identifier ("extern"),
2064 current_declspecs);
2065 used_extern_spec = 1;
2066 }
2067 $$ = suspend_momentary ();
2068 d = start_decl ($<ttype>1, current_declspecs, 0);
2069 cplus_decl_attributes (d, $3, prefix_attributes);
2070 cp_finish_decl (d, NULL_TREE, $2, 1, 0); }
2071 ;
2072
2073 initdcl:
2074 declarator maybeasm maybe_attribute '='
2075 { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1);
2076 cplus_decl_attributes ($<ttype>$, $3, prefix_attributes); }
2077 init
2078 /* Note how the declaration of the variable is in effect while its init is parsed! */
2079 { cp_finish_decl ($<ttype>5, $6, $2, 1, LOOKUP_ONLYCONVERTING); }
2080 | declarator maybeasm maybe_attribute
2081 { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 0);
2082 cplus_decl_attributes ($<ttype>$, $3, prefix_attributes);
2083 cp_finish_decl ($<ttype>$, NULL_TREE, $2, 1, 0); }
2084 ;
2085
2086 notype_initdcl0:
2087 notype_declarator maybeasm maybe_attribute '='
2088 { split_specs_attrs ($<ttype>0, &current_declspecs,
2089 &prefix_attributes);
2090 $<itype>4 = suspend_momentary ();
2091 $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1);
2092 cplus_decl_attributes ($<ttype>$, $3, prefix_attributes); }
2093 init
2094 /* Note how the declaration of the variable is in effect while its init is parsed! */
2095 { cp_finish_decl ($<ttype>5, $6, $2, 1, LOOKUP_ONLYCONVERTING);
2096 $$ = $<itype>4; }
2097 | notype_declarator maybeasm maybe_attribute
2098 { tree d;
2099 split_specs_attrs ($<ttype>0, &current_declspecs,
2100 &prefix_attributes);
2101 $$ = suspend_momentary ();
2102 d = start_decl ($<ttype>1, current_declspecs, 0);
2103 cplus_decl_attributes (d, $3, prefix_attributes);
2104 cp_finish_decl (d, NULL_TREE, $2, 1, 0); }
2105 ;
2106
2107 nomods_initdcl0:
2108 notype_declarator maybeasm maybe_attribute '='
2109 { current_declspecs = NULL_TREE;
2110 prefix_attributes = NULL_TREE;
2111 $<itype>4 = suspend_momentary ();
2112 $<ttype>$ = start_decl ($1, current_declspecs, 1);
2113 cplus_decl_attributes ($<ttype>$, $3, prefix_attributes); }
2114 init
2115 /* Note how the declaration of the variable is in effect while its init is parsed! */
2116 { cp_finish_decl ($<ttype>5, $6, $2, 1, LOOKUP_ONLYCONVERTING);
2117 $$ = $<itype>4; }
2118 | notype_declarator maybeasm maybe_attribute
2119 { tree d;
2120 current_declspecs = NULL_TREE;
2121 prefix_attributes = NULL_TREE;
2122 $$ = suspend_momentary ();
2123 d = start_decl ($1, current_declspecs, 0);
2124 cplus_decl_attributes (d, $3, prefix_attributes);
2125 cp_finish_decl (d, NULL_TREE, $2, 1, 0); }
2126 ;
2127
2128 /* the * rules are dummies to accept the Apollo extended syntax
2129 so that the header files compile. */
2130 maybe_attribute:
2131 /* empty */
2132 { $$ = NULL_TREE; }
2133 | attributes
2134 { $$ = $1; }
2135 ;
2136
2137 attributes:
2138 attribute
2139 { $$ = $1; }
2140 | attributes attribute
2141 { $$ = chainon ($1, $2); }
2142 ;
2143
2144 attribute:
2145 ATTRIBUTE '(' '(' attribute_list ')' ')'
2146 { $$ = $4; }
2147 ;
2148
2149 attribute_list:
2150 attrib
2151 { $$ = $1; }
2152 | attribute_list ',' attrib
2153 { $$ = chainon ($1, $3); }
2154 ;
2155
2156 attrib:
2157 /* empty */
2158 { $$ = NULL_TREE; }
2159 | any_word
2160 { $$ = build_tree_list ($1, NULL_TREE); }
2161 | any_word '(' IDENTIFIER ')'
2162 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
2163 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
2164 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
2165 | any_word '(' nonnull_exprlist ')'
2166 { $$ = build_tree_list ($1, $3); }
2167 ;
2168
2169 /* This still leaves out most reserved keywords,
2170 shouldn't we include them? */
2171
2172 any_word:
2173 identifier
2174 | SCSPEC
2175 | TYPESPEC
2176 | CV_QUALIFIER
2177 ;
2178
2179 /* A nonempty list of identifiers, including typenames. */
2180 identifiers_or_typenames:
2181 identifier
2182 { $$ = build_tree_list (NULL_TREE, $1); }
2183 | identifiers_or_typenames ',' identifier
2184 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2185 ;
2186
2187 maybe_init:
2188 /* empty */ %prec EMPTY
2189 { $$ = NULL_TREE; }
2190 | '=' init
2191 { $$ = $2; }
2192
2193 /* If we are processing a template, we don't want to expand this
2194 initializer yet. */
2195
2196 init:
2197 expr_no_commas %prec '='
2198 | '{' '}'
2199 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
2200 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2201 | '{' initlist '}'
2202 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2203 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2204 | '{' initlist ',' '}'
2205 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2206 TREE_HAS_CONSTRUCTOR ($$) = 1; }
2207 | error
2208 { $$ = NULL_TREE; }
2209 ;
2210
2211 /* This chain is built in reverse order,
2212 and put in forward order where initlist is used. */
2213 initlist:
2214 init
2215 { $$ = build_tree_list (NULL_TREE, $$); }
2216 | initlist ',' init
2217 { $$ = expr_tree_cons (NULL_TREE, $3, $$); }
2218 /* These are for labeled elements. */
2219 | '[' expr_no_commas ']' init
2220 { $$ = build_expr_list ($2, $4); }
2221 | initlist ',' CASE expr_no_commas ':' init
2222 { $$ = expr_tree_cons ($4, $6, $$); }
2223 | identifier ':' init
2224 { $$ = build_expr_list ($$, $3); }
2225 | initlist ',' identifier ':' init
2226 { $$ = expr_tree_cons ($3, $5, $$); }
2227 ;
2228
2229 fn.defpen:
2230 PRE_PARSED_FUNCTION_DECL
2231 { start_function (NULL_TREE, TREE_VALUE ($1),
2232 NULL_TREE, 1);
2233 reinit_parse_for_function (); }
2234
2235 pending_inline:
2236 fn.defpen maybe_return_init ctor_initializer_opt compstmt_or_error
2237 {
2238 int nested = (hack_decl_function_context
2239 (current_function_decl) != NULL_TREE);
2240 finish_function (lineno, (int)$3, nested);
2241 process_next_inline ($1);
2242 }
2243 | fn.defpen maybe_return_init function_try_block
2244 { process_next_inline ($1); }
2245 | fn.defpen maybe_return_init error
2246 { process_next_inline ($1); }
2247 ;
2248
2249 pending_inlines:
2250 /* empty */
2251 | pending_inlines pending_inline eat_saved_input
2252 ;
2253
2254 /* A regurgitated default argument. The value of DEFARG_MARKER will be
2255 the TREE_LIST node for the parameter in question. */
2256 defarg_again:
2257 DEFARG_MARKER expr_no_commas END_OF_SAVED_INPUT
2258 { replace_defarg ($1, $2); }
2259 | DEFARG_MARKER error END_OF_SAVED_INPUT
2260 { replace_defarg ($1, error_mark_node); }
2261
2262 pending_defargs:
2263 /* empty */ %prec EMPTY
2264 | pending_defargs defarg_again
2265 { do_pending_defargs (); }
2266 | pending_defargs error
2267 { do_pending_defargs (); }
2268 ;
2269
2270 structsp:
2271 ENUM identifier '{'
2272 { $<itype>3 = suspend_momentary ();
2273 $<ttype>$ = start_enum ($2); }
2274 enumlist maybecomma_warn '}'
2275 { $$.t = finish_enum ($<ttype>4, $5);
2276 $$.new_type_flag = 1;
2277 resume_momentary ((int) $<itype>3);
2278 check_for_missing_semicolon ($<ttype>4); }
2279 | ENUM identifier '{' '}'
2280 { $$.t = finish_enum (start_enum ($2), NULL_TREE);
2281 $$.new_type_flag = 1;
2282 check_for_missing_semicolon ($$.t); }
2283 | ENUM '{'
2284 { $<itype>2 = suspend_momentary ();
2285 $<ttype>$ = start_enum (make_anon_name ()); }
2286 enumlist maybecomma_warn '}'
2287 { $$.t = finish_enum ($<ttype>3, $4);
2288 resume_momentary ((int) $<itype>1);
2289 check_for_missing_semicolon ($<ttype>3);
2290 $$.new_type_flag = 1; }
2291 | ENUM '{' '}'
2292 { $$.t = finish_enum (start_enum (make_anon_name()), NULL_TREE);
2293 $$.new_type_flag = 1;
2294 check_for_missing_semicolon ($$.t); }
2295 | ENUM identifier
2296 { $$.t = xref_tag (enum_type_node, $2, NULL_TREE, 1);
2297 $$.new_type_flag = 0; }
2298 | ENUM complex_type_name
2299 { $$.t = xref_tag (enum_type_node, $2, NULL_TREE, 1);
2300 $$.new_type_flag = 0; }
2301 | TYPENAME_KEYWORD typename_sub
2302 { $$.t = $2;
2303 $$.new_type_flag = 0; }
2304 /* C++ extensions, merged with C to avoid shift/reduce conflicts */
2305 | class_head left_curly
2306 opt.component_decl_list '}' maybe_attribute
2307 {
2308 int semi;
2309 tree id;
2310
2311 $<ttype>$ = $1;
2312 #if 0
2313 /* Need to rework class nesting in the
2314 presence of nested classes, etc. */
2315 shadow_tag (CLASSTYPE_AS_LIST ($1)); */
2316 #endif
2317 if (yychar == YYEMPTY)
2318 yychar = YYLEX;
2319 semi = yychar == ';';
2320 /* finish_struct nukes this anyway; if
2321 finish_exception does too, then it can go. */
2322 if (semi)
2323 note_got_semicolon ($1);
2324
2325 if (TREE_CODE ($1) == ENUMERAL_TYPE)
2326 ;
2327 else
2328 {
2329 $<ttype>$ = finish_struct ($1, $3, $5, semi);
2330 if (semi) note_got_semicolon ($<ttype>$);
2331 }
2332
2333 pop_obstacks ();
2334
2335 if (! semi)
2336 check_for_missing_semicolon ($1);
2337 if (current_scope () == current_function_decl)
2338 do_pending_defargs ();
2339 }
2340 pending_defargs
2341 {
2342 if (pending_inlines
2343 && current_scope () == current_function_decl)
2344 do_pending_inlines ();
2345 }
2346 pending_inlines
2347 {
2348 $$.t = $<ttype>6;
2349 $$.new_type_flag = 1;
2350 if (current_class_type == NULL_TREE)
2351 clear_inline_text_obstack ();
2352
2353 /* Undo the begin_tree in left_curly. */
2354 end_tree ();
2355 }
2356 | class_head %prec EMPTY
2357 {
2358 $$.new_type_flag = 0;
2359 if (TYPE_BINFO ($1) == NULL_TREE)
2360 {
2361 cp_error ("%T is not a class type", $1);
2362 $$.t = error_mark_node;
2363 }
2364 else
2365 {
2366 $$.t = $1;
2367 /* struct B: public A; is not accepted by the WP grammar. */
2368 if (TYPE_BINFO_BASETYPES ($$.t) && !TYPE_SIZE ($$.t)
2369 && ! TYPE_BEING_DEFINED ($$.t))
2370 cp_error ("base clause without member specification for `%#T'",
2371 $$.t);
2372 }
2373 }
2374 ;
2375
2376 maybecomma:
2377 /* empty */
2378 | ','
2379 ;
2380
2381 maybecomma_warn:
2382 /* empty */
2383 | ','
2384 { if (pedantic && !in_system_header)
2385 pedwarn ("comma at end of enumerator list"); }
2386 ;
2387
2388 aggr:
2389 AGGR
2390 | aggr SCSPEC
2391 { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2392 | aggr TYPESPEC
2393 { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2394 | aggr CV_QUALIFIER
2395 { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2396 | aggr AGGR
2397 { error ("no body nor ';' separates two class, struct or union declarations"); }
2398 ;
2399
2400 named_class_head_sans_basetype:
2401 aggr identifier
2402 { current_aggr = $$; $$ = $2; }
2403 ;
2404
2405 named_class_head_sans_basetype_defn:
2406 aggr identifier_defn %prec EMPTY
2407 { current_aggr = $$; $$ = $2; }
2408 ;
2409
2410 named_complex_class_head_sans_basetype:
2411 aggr nested_name_specifier identifier
2412 {
2413 current_aggr = $1;
2414 $$ = handle_class_head ($1, $2, $3);
2415 }
2416 | aggr global_scope nested_name_specifier identifier
2417 {
2418 current_aggr = $1;
2419 $$ = handle_class_head ($1, $3, $4);
2420 }
2421 | aggr global_scope identifier
2422 {
2423 current_aggr = $1;
2424 $$ = handle_class_head ($1, NULL_TREE, $3);
2425 }
2426 | aggr template_type
2427 { current_aggr = $$; $$ = $2; }
2428 | aggr nested_name_specifier template_type
2429 { current_aggr = $$; $$ = $3; }
2430 ;
2431
2432 do_xref_defn:
2433 /* empty */ %prec EMPTY
2434 { $<ttype>$ = xref_tag (current_aggr, $<ttype>0, NULL_TREE, 0); }
2435 ;
2436
2437 named_class_head:
2438 named_class_head_sans_basetype %prec EMPTY
2439 { $$ = xref_tag (current_aggr, $1, NULL_TREE, 1); }
2440 | named_class_head_sans_basetype_defn do_xref_defn
2441 maybe_base_class_list %prec EMPTY
2442 {
2443 $$ = $<ttype>2;
2444 if ($3)
2445 xref_basetypes (current_aggr, $1, $<ttype>2, $3);
2446 }
2447 | named_complex_class_head_sans_basetype maybe_base_class_list
2448 {
2449 $$ = TREE_TYPE ($1);
2450 if (TREE_INT_CST_LOW (current_aggr) == union_type
2451 && TREE_CODE ($$) != UNION_TYPE)
2452 cp_pedwarn ("`union' tag used in declaring `%#T'", $$);
2453 else if (TREE_CODE ($$) == UNION_TYPE
2454 && TREE_INT_CST_LOW (current_aggr) != union_type)
2455 cp_pedwarn ("non-`union' tag used in declaring `%#T'", $$);
2456 if ($2)
2457 {
2458 if (IS_AGGR_TYPE ($$) && CLASSTYPE_USE_TEMPLATE ($$))
2459 {
2460 if (CLASSTYPE_IMPLICIT_INSTANTIATION ($$)
2461 && TYPE_SIZE ($$) == NULL_TREE)
2462 {
2463 SET_CLASSTYPE_TEMPLATE_SPECIALIZATION ($$);
2464 if (processing_template_decl)
2465 push_template_decl (TYPE_MAIN_DECL ($$));
2466 }
2467 else if (CLASSTYPE_TEMPLATE_INSTANTIATION ($$))
2468 cp_error ("specialization after instantiation of `%T'", $$);
2469 }
2470 xref_basetypes (current_aggr, $1, $$, $2);
2471 }
2472 }
2473 ;
2474
2475 unnamed_class_head:
2476 aggr '{'
2477 { $$ = xref_tag ($$, make_anon_name (), NULL_TREE, 0);
2478 yyungetc ('{', 1); }
2479 ;
2480
2481 class_head:
2482 unnamed_class_head
2483 | named_class_head
2484 ;
2485
2486 maybe_base_class_list:
2487 /* empty */ %prec EMPTY
2488 { $$ = NULL_TREE; }
2489 | ':' see_typename %prec EMPTY
2490 { yyungetc(':', 1); $$ = NULL_TREE; }
2491 | ':' see_typename base_class_list %prec EMPTY
2492 { $$ = $3; }
2493 ;
2494
2495 base_class_list:
2496 base_class
2497 | base_class_list ',' see_typename base_class
2498 { $$ = chainon ($$, $4); }
2499 ;
2500
2501 base_class:
2502 base_class.1
2503 {
2504 tree type = TREE_TYPE ($1);
2505 if (! is_aggr_type (type, 1))
2506 $$ = NULL_TREE;
2507 else if (current_aggr == signature_type_node
2508 && (! type) && (! IS_SIGNATURE (type)))
2509 {
2510 error ("class name not allowed as base signature");
2511 $$ = NULL_TREE;
2512 }
2513 else if (current_aggr == signature_type_node)
2514 {
2515 sorry ("signature inheritance, base type `%s' ignored",
2516 IDENTIFIER_POINTER ($$));
2517 $$ = build_tree_list (access_public_node, type);
2518 }
2519 else if (type && IS_SIGNATURE (type))
2520 {
2521 error ("signature name not allowed as base class");
2522 $$ = NULL_TREE;
2523 }
2524 else
2525 $$ = build_tree_list (access_default_node, type);
2526 }
2527 | base_class_access_list see_typename base_class.1
2528 {
2529 tree type = TREE_TYPE ($3);
2530 if (current_aggr == signature_type_node)
2531 error ("access and source specifiers not allowed in signature");
2532 if (! IS_AGGR_TYPE (type))
2533 $$ = NULL_TREE;
2534 else if (current_aggr == signature_type_node
2535 && (! type) && (! IS_SIGNATURE (type)))
2536 {
2537 error ("class name not allowed as base signature");
2538 $$ = NULL_TREE;
2539 }
2540 else if (current_aggr == signature_type_node)
2541 {
2542 sorry ("signature inheritance, base type `%s' ignored",
2543 IDENTIFIER_POINTER ($$));
2544 $$ = build_tree_list (access_public_node, type);
2545 }
2546 else if (type && IS_SIGNATURE (type))
2547 {
2548 error ("signature name not allowed as base class");
2549 $$ = NULL_TREE;
2550 }
2551 else
2552 $$ = build_tree_list ($$, type);
2553 }
2554 ;
2555
2556 base_class.1:
2557 typename_sub
2558 { $$ = TYPE_MAIN_DECL ($1); }
2559 | nonnested_type
2560 | SIGOF '(' expr ')'
2561 {
2562 if (current_aggr == signature_type_node)
2563 {
2564 if (IS_AGGR_TYPE (TREE_TYPE ($3)))
2565 {
2566 sorry ("`sigof' as base signature specifier");
2567 $$ = TREE_TYPE ($3);
2568 }
2569 else
2570 {
2571 error ("`sigof' applied to non-aggregate expression");
2572 $$ = error_mark_node;
2573 }
2574 }
2575 else
2576 {
2577 error ("`sigof' in struct or class declaration");
2578 $$ = error_mark_node;
2579 }
2580 }
2581 | SIGOF '(' type_id ')'
2582 {
2583 if (current_aggr == signature_type_node)
2584 {
2585 if (IS_AGGR_TYPE (groktypename ($3.t)))
2586 {
2587 sorry ("`sigof' as base signature specifier");
2588 $$ = groktypename ($3.t);
2589 }
2590 else
2591 {
2592 error ("`sigof' applied to non-aggregate expression");
2593 $$ = error_mark_node;
2594 }
2595 }
2596 else
2597 {
2598 error ("`sigof' in struct or class declaration");
2599 $$ = error_mark_node;
2600 }
2601 }
2602 ;
2603
2604 base_class_access_list:
2605 VISSPEC see_typename
2606 | SCSPEC see_typename
2607 { if ($<ttype>$ != ridpointers[(int)RID_VIRTUAL])
2608 sorry ("non-virtual access");
2609 $$ = access_default_virtual_node; }
2610 | base_class_access_list VISSPEC see_typename
2611 { int err = 0;
2612 if ($2 == access_protected_node)
2613 {
2614 warning ("`protected' access not implemented");
2615 $2 = access_public_node;
2616 err++;
2617 }
2618 else if ($2 == access_public_node)
2619 {
2620 if ($1 == access_private_node)
2621 {
2622 mixed:
2623 error ("base class cannot be public and private");
2624 }
2625 else if ($1 == access_default_virtual_node)
2626 $$ = access_public_virtual_node;
2627 }
2628 else /* $2 == access_private_node */
2629 {
2630 if ($1 == access_public_node)
2631 goto mixed;
2632 else if ($1 == access_default_virtual_node)
2633 $$ = access_private_virtual_node;
2634 }
2635 }
2636 | base_class_access_list SCSPEC see_typename
2637 { if ($2 != ridpointers[(int)RID_VIRTUAL])
2638 sorry ("non-virtual access");
2639 if ($$ == access_public_node)
2640 $$ = access_public_virtual_node;
2641 else if ($$ == access_private_node)
2642 $$ = access_private_virtual_node; }
2643 ;
2644
2645 left_curly:
2646 '{'
2647 { tree t = $<ttype>0;
2648 push_obstacks_nochange ();
2649 end_temporary_allocation ();
2650
2651 if (t == error_mark_node
2652 || ! IS_AGGR_TYPE (t))
2653 {
2654 t = $<ttype>0 = make_lang_type (RECORD_TYPE);
2655 pushtag (make_anon_name (), t, 0);
2656 }
2657 if (TYPE_SIZE (t))
2658 duplicate_tag_error (t);
2659 if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
2660 {
2661 t = make_lang_type (TREE_CODE (t));
2662 pushtag (TYPE_IDENTIFIER ($<ttype>0), t, 0);
2663 $<ttype>0 = t;
2664 }
2665 if (processing_template_decl && TYPE_CONTEXT (t)
2666 && ! current_class_type)
2667 push_template_decl (TYPE_STUB_DECL (t));
2668 pushclass (t, 0);
2669 TYPE_BEING_DEFINED (t) = 1;
2670 if (IS_AGGR_TYPE (t) && CLASSTYPE_USE_TEMPLATE (t))
2671 {
2672 if (CLASSTYPE_IMPLICIT_INSTANTIATION (t)
2673 && TYPE_SIZE (t) == NULL_TREE)
2674 {
2675 SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (t);
2676 if (processing_template_decl)
2677 push_template_decl (TYPE_MAIN_DECL (t));
2678 }
2679 else if (CLASSTYPE_TEMPLATE_INSTANTIATION (t))
2680 cp_error ("specialization after instantiation of `%T'", t);
2681 }
2682 /* Reset the interface data, at the earliest possible
2683 moment, as it might have been set via a class foo;
2684 before. */
2685 /* Don't change signatures. */
2686 if (! IS_SIGNATURE (t))
2687 {
2688 extern tree pending_vtables;
2689 int needs_writing;
2690 tree name = TYPE_IDENTIFIER (t);
2691
2692 if (! ANON_AGGRNAME_P (name))
2693 {
2694 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2695 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2696 (t, interface_unknown);
2697 }
2698
2699 /* Record how to set the access of this class's
2700 virtual functions. If write_virtuals == 2 or 3, then
2701 inline virtuals are ``extern inline''. */
2702 switch (write_virtuals)
2703 {
2704 case 0:
2705 case 1:
2706 needs_writing = 1;
2707 break;
2708 case 2:
2709 needs_writing = !! value_member (name, pending_vtables);
2710 break;
2711 case 3:
2712 needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t)
2713 && CLASSTYPE_INTERFACE_KNOWN (t);
2714 break;
2715 default:
2716 needs_writing = 0;
2717 }
2718 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
2719 }
2720 #if 0
2721 t = TYPE_IDENTIFIER ($<ttype>0);
2722 if (t && IDENTIFIER_TEMPLATE (t))
2723 overload_template_name (t, 1);
2724 #endif
2725 reset_specialization();
2726
2727 /* In case this is a local class within a template
2728 function, we save the current tree structure so
2729 that we can get it back later. */
2730 begin_tree ();
2731 }
2732 ;
2733
2734 self_reference:
2735 /* empty */
2736 {
2737 $$ = build_self_reference ();
2738 }
2739 ;
2740
2741 opt.component_decl_list:
2742 self_reference
2743 { if ($$) $$ = build_tree_list (access_public_node, $$); }
2744 | self_reference component_decl_list
2745 {
2746 if (current_aggr == signature_type_node)
2747 $$ = build_tree_list (access_public_node, $2);
2748 else
2749 $$ = build_tree_list (access_default_node, $2);
2750 if ($1) $$ = tree_cons (access_public_node, $1, $$);
2751 }
2752 | opt.component_decl_list VISSPEC ':' component_decl_list
2753 {
2754 tree visspec = $2;
2755
2756 if (current_aggr == signature_type_node)
2757 {
2758 error ("access specifier not allowed in signature");
2759 visspec = access_public_node;
2760 }
2761 $$ = chainon ($$, build_tree_list (visspec, $4));
2762 }
2763 | opt.component_decl_list VISSPEC ':'
2764 {
2765 if (current_aggr == signature_type_node)
2766 error ("access specifier not allowed in signature");
2767 }
2768 ;
2769
2770 /* Note: we no longer warn about the semicolon after a component_decl_list.
2771 ARM $9.2 says that the semicolon is optional, and therefore allowed. */
2772 component_decl_list:
2773 component_decl
2774 { if ($$ == void_type_node) $$ = NULL_TREE;
2775 }
2776 | component_decl_list component_decl
2777 { /* In pushdecl, we created a reverse list of names
2778 in this binding level. Make sure that the chain
2779 of what we're trying to add isn't the item itself
2780 (which can happen with what pushdecl's doing). */
2781 if ($2 != NULL_TREE && $2 != void_type_node)
2782 {
2783 if (TREE_CHAIN ($2) != $$)
2784 $$ = chainon ($$, $2);
2785 else
2786 $$ = $2;
2787 }
2788 }
2789 ;
2790
2791 component_decl:
2792 component_decl_1 ';'
2793 { }
2794 | component_decl_1 '}'
2795 { error ("missing ';' before right brace");
2796 yyungetc ('}', 0); }
2797 /* C++: handle constructors, destructors and inline functions */
2798 /* note that INLINE is like a TYPESPEC */
2799 | fn.def2 ':' /* base_init compstmt */
2800 { $$ = finish_method ($$); }
2801 | fn.def2 TRY /* base_init compstmt */
2802 { $$ = finish_method ($$); }
2803 | fn.def2 RETURN /* base_init compstmt */
2804 { $$ = finish_method ($$); }
2805 | fn.def2 '{' /* nodecls compstmt */
2806 { $$ = finish_method ($$); }
2807 | ';'
2808 { $$ = NULL_TREE; }
2809 | extension component_decl
2810 { $$ = $2;
2811 pedantic = $<itype>1; }
2812 ;
2813
2814 component_decl_1:
2815 /* Do not add a "typed_declspecs declarator" rule here for
2816 speed; we need to call grok_x_components for enums, so the
2817 speedup would be insignificant. */
2818 typed_declspecs components
2819 { $$ = grok_x_components ($1.t, $2); }
2820 | declmods notype_components
2821 { $$ = grok_x_components ($1, $2); }
2822 | notype_declarator maybeasm maybe_attribute maybe_init
2823 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2824 build_tree_list ($3, NULL_TREE)); }
2825 | constructor_declarator maybeasm maybe_attribute maybe_init
2826 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2827 build_tree_list ($3, NULL_TREE)); }
2828 | ':' expr_no_commas
2829 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
2830 | error
2831 { $$ = NULL_TREE; }
2832
2833 /* These rules introduce a reduce/reduce conflict; in
2834 typedef int foo, bar;
2835 class A {
2836 foo (bar);
2837 };
2838 should "A::foo" be declared as a function or "A::bar" as a data
2839 member? In other words, is "bar" an after_type_declarator or a
2840 parmlist? */
2841 | declmods component_constructor_declarator maybeasm maybe_attribute maybe_init
2842 { tree specs, attrs;
2843 split_specs_attrs ($1, &specs, &attrs);
2844 $$ = grokfield ($2, specs, $5, $3,
2845 build_tree_list ($4, attrs)); }
2846 | component_constructor_declarator maybeasm maybe_attribute maybe_init
2847 { $$ = grokfield ($$, NULL_TREE, $4, $2,
2848 build_tree_list ($3, NULL_TREE)); }
2849 | using_decl
2850 { $$ = do_class_using_decl ($1); }
2851 | template_header component_decl_1
2852 { $$ = finish_member_template_decl ($1, $2); }
2853
2854 /* The case of exactly one component is handled directly by component_decl. */
2855 /* ??? Huh? ^^^ */
2856 components:
2857 /* empty: possibly anonymous */
2858 { $$ = NULL_TREE; }
2859 | component_declarator0
2860 | components ',' component_declarator
2861 {
2862 /* In this context, void_type_node encodes
2863 friends. They have been recorded elsewhere. */
2864 if ($$ == void_type_node)
2865 $$ = $3;
2866 else
2867 $$ = chainon ($$, $3);
2868 }
2869 ;
2870
2871 notype_components:
2872 /* empty: possibly anonymous */
2873 { $$ = NULL_TREE; }
2874 | notype_component_declarator0
2875 | notype_components ',' notype_component_declarator
2876 {
2877 /* In this context, void_type_node encodes
2878 friends. They have been recorded elsewhere. */
2879 if ($$ == void_type_node)
2880 $$ = $3;
2881 else
2882 $$ = chainon ($$, $3);
2883 }
2884 ;
2885
2886 component_declarator0:
2887 after_type_component_declarator0
2888 | notype_component_declarator0
2889 ;
2890
2891 component_declarator:
2892 after_type_component_declarator
2893 | notype_component_declarator
2894 ;
2895
2896 after_type_component_declarator0:
2897 after_type_declarator maybeasm maybe_attribute maybe_init
2898 { split_specs_attrs ($<ttype>0, &current_declspecs,
2899 &prefix_attributes);
2900 $<ttype>0 = current_declspecs;
2901 $$ = grokfield ($$, current_declspecs, $4, $2,
2902 build_tree_list ($3, prefix_attributes)); }
2903 | TYPENAME ':' expr_no_commas maybe_attribute
2904 { split_specs_attrs ($<ttype>0, &current_declspecs,
2905 &prefix_attributes);
2906 $<ttype>0 = current_declspecs;
2907 $$ = grokbitfield ($$, current_declspecs, $3);
2908 cplus_decl_attributes ($$, $4, prefix_attributes); }
2909 ;
2910
2911 notype_component_declarator0:
2912 notype_declarator maybeasm maybe_attribute maybe_init
2913 { split_specs_attrs ($<ttype>0, &current_declspecs,
2914 &prefix_attributes);
2915 $<ttype>0 = current_declspecs;
2916 $$ = grokfield ($$, current_declspecs, $4, $2,
2917 build_tree_list ($3, prefix_attributes)); }
2918 | constructor_declarator maybeasm maybe_attribute maybe_init
2919 { split_specs_attrs ($<ttype>0, &current_declspecs,
2920 &prefix_attributes);
2921 $<ttype>0 = current_declspecs;
2922 $$ = grokfield ($$, current_declspecs, $4, $2,
2923 build_tree_list ($3, prefix_attributes)); }
2924 | IDENTIFIER ':' expr_no_commas maybe_attribute
2925 { split_specs_attrs ($<ttype>0, &current_declspecs,
2926 &prefix_attributes);
2927 $<ttype>0 = current_declspecs;
2928 $$ = grokbitfield ($$, current_declspecs, $3);
2929 cplus_decl_attributes ($$, $4, prefix_attributes); }
2930 | ':' expr_no_commas maybe_attribute
2931 { split_specs_attrs ($<ttype>0, &current_declspecs,
2932 &prefix_attributes);
2933 $<ttype>0 = current_declspecs;
2934 $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2935 cplus_decl_attributes ($$, $3, prefix_attributes); }
2936 ;
2937
2938 after_type_component_declarator:
2939 after_type_declarator maybeasm maybe_attribute maybe_init
2940 { $$ = grokfield ($$, current_declspecs, $4, $2,
2941 build_tree_list ($3, prefix_attributes)); }
2942 | TYPENAME ':' expr_no_commas maybe_attribute
2943 { $$ = grokbitfield ($$, current_declspecs, $3);
2944 cplus_decl_attributes ($$, $4, prefix_attributes); }
2945 ;
2946
2947 notype_component_declarator:
2948 notype_declarator maybeasm maybe_attribute maybe_init
2949 { $$ = grokfield ($$, current_declspecs, $4, $2,
2950 build_tree_list ($3, prefix_attributes)); }
2951 | IDENTIFIER ':' expr_no_commas maybe_attribute
2952 { $$ = grokbitfield ($$, current_declspecs, $3);
2953 cplus_decl_attributes ($$, $4, prefix_attributes); }
2954 | ':' expr_no_commas maybe_attribute
2955 { $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2956 cplus_decl_attributes ($$, $3, prefix_attributes); }
2957 ;
2958
2959 /* We chain the enumerators in reverse order.
2960 Because of the way enums are built, the order is
2961 insignificant. Take advantage of this fact. */
2962
2963 enumlist:
2964 enumerator
2965 | enumlist ',' enumerator
2966 { TREE_CHAIN ($3) = $$; $$ = $3; }
2967 ;
2968
2969 enumerator:
2970 identifier
2971 { $$ = build_enumerator ($$, NULL_TREE); }
2972 | identifier '=' expr_no_commas
2973 { $$ = build_enumerator ($$, $3); }
2974 ;
2975
2976 /* ANSI new-type-id (5.3.4) */
2977 new_type_id:
2978 type_specifier_seq new_declarator
2979 { $$.t = build_decl_list ($1.t, $2);
2980 $$.new_type_flag = $1.new_type_flag; }
2981 | type_specifier_seq %prec EMPTY
2982 { $$.t = build_decl_list ($1.t, NULL_TREE);
2983 $$.new_type_flag = $1.new_type_flag; }
2984 /* GNU extension to allow arrays of arbitrary types with
2985 non-constant dimension. */
2986 | '(' type_id ')' '[' expr ']'
2987 {
2988 if (pedantic)
2989 pedwarn ("ANSI C++ forbids array dimensions with parenthesized type in new");
2990 $$.t = build_parse_node (ARRAY_REF, TREE_VALUE ($2.t), $5);
2991 $$.t = build_decl_list (TREE_PURPOSE ($2.t), $$.t);
2992 $$.new_type_flag = $2.new_type_flag;
2993 }
2994 ;
2995
2996 cv_qualifiers:
2997 /* empty */ %prec EMPTY
2998 { $$ = NULL_TREE; }
2999 | cv_qualifiers CV_QUALIFIER
3000 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
3001 ;
3002
3003 nonempty_cv_qualifiers:
3004 CV_QUALIFIER
3005 { $$.t = IDENTIFIER_AS_LIST ($1);
3006 $$.new_type_flag = 0; }
3007 | nonempty_cv_qualifiers CV_QUALIFIER
3008 { $$.t = decl_tree_cons (NULL_TREE, $2, $1.t);
3009 $$.new_type_flag = $1.new_type_flag; }
3010 ;
3011
3012 /* These rules must follow the rules for function declarations
3013 and component declarations. That way, longer rules are preferred. */
3014
3015 suspend_mom:
3016 /* empty */
3017 { $<itype>$ = suspend_momentary (); }
3018
3019 /* An expression which will not live on the momentary obstack. */
3020 nonmomentary_expr:
3021 suspend_mom expr
3022 { resume_momentary ((int) $<itype>1); $$ = $2; }
3023 ;
3024
3025 /* An expression which will not live on the momentary obstack. */
3026 maybe_parmlist:
3027 suspend_mom '(' nonnull_exprlist ')'
3028 { resume_momentary ((int) $<itype>1); $$ = $3; }
3029 | suspend_mom '(' parmlist ')'
3030 { resume_momentary ((int) $<itype>1); $$ = $3; }
3031 | suspend_mom LEFT_RIGHT
3032 { resume_momentary ((int) $<itype>1); $$ = empty_parms (); }
3033 | suspend_mom '(' error ')'
3034 { resume_momentary ((int) $<itype>1); $$ = NULL_TREE; }
3035 ;
3036
3037 /* A declarator that is allowed only after an explicit typespec. */
3038 /* may all be followed by prec '.' */
3039 after_type_declarator:
3040 '*' nonempty_cv_qualifiers after_type_declarator %prec UNARY
3041 { $$ = make_pointer_declarator ($2.t, $3); }
3042 | '&' nonempty_cv_qualifiers after_type_declarator %prec UNARY
3043 { $$ = make_reference_declarator ($2.t, $3); }
3044 | '*' after_type_declarator %prec UNARY
3045 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3046 | '&' after_type_declarator %prec UNARY
3047 { $$ = make_reference_declarator (NULL_TREE, $2); }
3048 | ptr_to_mem cv_qualifiers after_type_declarator
3049 { tree arg = make_pointer_declarator ($2, $3);
3050 $$ = build_parse_node (SCOPE_REF, $1, arg);
3051 }
3052 | direct_after_type_declarator
3053 ;
3054
3055 nonnested_type:
3056 type_name %prec EMPTY
3057 {
3058 if (TREE_CODE ($1) == IDENTIFIER_NODE)
3059 {
3060 arg_looking_for_template = processing_template_arg;
3061 $$ = lookup_name ($1, 1);
3062 arg_looking_for_template = 0;
3063
3064 if (current_class_type
3065 && TYPE_BEING_DEFINED (current_class_type)
3066 && ! IDENTIFIER_CLASS_VALUE ($1))
3067 {
3068 /* Remember that this name has been used in the class
3069 definition, as per [class.scope0] */
3070 pushdecl_class_level ($$);
3071 }
3072 }
3073 else
3074 $$ = $1;
3075 }
3076 | global_scope type_name
3077 {
3078 if (TREE_CODE ($2) == IDENTIFIER_NODE)
3079 $$ = IDENTIFIER_GLOBAL_VALUE ($2);
3080 else
3081 $$ = $2;
3082 got_scope = NULL_TREE;
3083 }
3084 ;
3085
3086 complete_type_name:
3087 nonnested_type
3088 | nested_type
3089 | global_scope nested_type
3090 { $$ = $2; }
3091 ;
3092
3093 nested_type:
3094 nested_name_specifier type_name %prec EMPTY
3095 { $$ = get_type_decl ($2); }
3096 ;
3097
3098 direct_after_type_declarator:
3099 direct_after_type_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
3100 { $$ = make_call_declarator ($$, $2, $3, $4); }
3101 | direct_after_type_declarator '[' nonmomentary_expr ']'
3102 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3103 | direct_after_type_declarator '[' ']'
3104 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
3105 | '(' after_type_declarator ')'
3106 { $$ = $2; }
3107 | nested_name_specifier type_name %prec EMPTY
3108 { push_nested_class ($1, 3);
3109 $$ = build_parse_node (SCOPE_REF, $$, $2);
3110 TREE_COMPLEXITY ($$) = current_class_depth; }
3111 | type_name %prec EMPTY
3112 ;
3113
3114 /* A declarator allowed whether or not there has been
3115 an explicit typespec. These cannot redeclare a typedef-name. */
3116
3117 notype_declarator:
3118 '*' nonempty_cv_qualifiers notype_declarator %prec UNARY
3119 { $$ = make_pointer_declarator ($2.t, $3); }
3120 | '&' nonempty_cv_qualifiers notype_declarator %prec UNARY
3121 { $$ = make_reference_declarator ($2.t, $3); }
3122 | '*' notype_declarator %prec UNARY
3123 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3124 | '&' notype_declarator %prec UNARY
3125 { $$ = make_reference_declarator (NULL_TREE, $2); }
3126 | ptr_to_mem cv_qualifiers notype_declarator
3127 { tree arg = make_pointer_declarator ($2, $3);
3128 $$ = build_parse_node (SCOPE_REF, $1, arg);
3129 }
3130 | direct_notype_declarator
3131 ;
3132
3133 complex_notype_declarator:
3134 '*' nonempty_cv_qualifiers notype_declarator %prec UNARY
3135 { $$ = make_pointer_declarator ($2.t, $3); }
3136 | '&' nonempty_cv_qualifiers notype_declarator %prec UNARY
3137 { $$ = make_reference_declarator ($2.t, $3); }
3138 | '*' complex_notype_declarator %prec UNARY
3139 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3140 | '&' complex_notype_declarator %prec UNARY
3141 { $$ = make_reference_declarator (NULL_TREE, $2); }
3142 | ptr_to_mem cv_qualifiers notype_declarator
3143 { tree arg = make_pointer_declarator ($2, $3);
3144 $$ = build_parse_node (SCOPE_REF, $1, arg);
3145 }
3146 | complex_direct_notype_declarator
3147 ;
3148
3149 complex_direct_notype_declarator:
3150 direct_notype_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
3151 { $$ = make_call_declarator ($$, $2, $3, $4); }
3152 | '(' complex_notype_declarator ')'
3153 { $$ = $2; }
3154 | direct_notype_declarator '[' nonmomentary_expr ']'
3155 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3156 | direct_notype_declarator '[' ']'
3157 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
3158 | notype_qualified_id
3159 { if (OP0 ($$) != current_class_type)
3160 {
3161 push_nested_class (OP0 ($$), 3);
3162 TREE_COMPLEXITY ($$) = current_class_depth;
3163 }
3164 }
3165 | nested_name_specifier notype_template_declarator
3166 { got_scope = NULL_TREE;
3167 $$ = build_parse_node (SCOPE_REF, $1, $2);
3168 if ($1 != current_class_type)
3169 {
3170 push_nested_class ($1, 3);
3171 TREE_COMPLEXITY ($$) = current_class_depth;
3172 }
3173 }
3174 ;
3175
3176 qualified_id:
3177 nested_name_specifier unqualified_id
3178 { got_scope = NULL_TREE;
3179 $$ = build_parse_node (SCOPE_REF, $$, $2); }
3180 | nested_name_specifier object_template_id
3181 { got_scope = NULL_TREE;
3182 $$ = build_parse_node (SCOPE_REF, $1, $2); }
3183 ;
3184
3185 notype_qualified_id:
3186 nested_name_specifier notype_unqualified_id
3187 { got_scope = NULL_TREE;
3188 $$ = build_parse_node (SCOPE_REF, $$, $2); }
3189 | nested_name_specifier object_template_id
3190 { got_scope = NULL_TREE;
3191 $$ = build_parse_node (SCOPE_REF, $1, $2); }
3192 ;
3193
3194 overqualified_id:
3195 notype_qualified_id
3196 | global_scope notype_qualified_id
3197 { $$ = $2; }
3198 ;
3199
3200 functional_cast:
3201 typespec '(' nonnull_exprlist ')'
3202 { $$ = build_functional_cast ($1.t, $3); }
3203 | typespec '(' expr_or_declarator ')'
3204 { $$ = reparse_decl_as_expr ($1.t, $3); }
3205 | typespec fcast_or_absdcl %prec EMPTY
3206 { $$ = reparse_absdcl_as_expr ($1.t, $2); }
3207 ;
3208
3209 type_name:
3210 TYPENAME
3211 | SELFNAME
3212 | template_type %prec EMPTY
3213 ;
3214
3215 nested_name_specifier:
3216 nested_name_specifier_1
3217 | nested_name_specifier nested_name_specifier_1
3218 { $$ = $2; }
3219 ;
3220
3221 /* Why the @#$%^& do type_name and notype_identifier need to be expanded
3222 inline here?!? (jason) */
3223 nested_name_specifier_1:
3224 TYPENAME SCOPE
3225 {
3226 if (TREE_CODE ($1) == IDENTIFIER_NODE)
3227 {
3228 $$ = lastiddecl;
3229 /* Remember that this name has been used in the class
3230 definition, as per [class.scope0] */
3231 if (current_class_type
3232 && TYPE_BEING_DEFINED (current_class_type)
3233 && ! IDENTIFIER_CLASS_VALUE ($1))
3234 pushdecl_class_level ($$);
3235 }
3236 got_scope = $$ = TREE_TYPE ($$);
3237 }
3238 | SELFNAME SCOPE
3239 {
3240 if (TREE_CODE ($1) == IDENTIFIER_NODE)
3241 $$ = lastiddecl;
3242 got_scope = $$ = TREE_TYPE ($$);
3243 }
3244 | NSNAME SCOPE
3245 {
3246 if (TREE_CODE ($$) == IDENTIFIER_NODE)
3247 $$ = lastiddecl;
3248 got_scope = $$;
3249 }
3250 | template_type SCOPE
3251 { got_scope = $$ = complete_type (TREE_TYPE ($1)); }
3252 /* These break 'const i;'
3253 | IDENTIFIER SCOPE
3254 {
3255 failed_scope:
3256 cp_error ("`%D' is not an aggregate typedef",
3257 lastiddecl ? lastiddecl : $$);
3258 $$ = error_mark_node;
3259 }
3260 | PTYPENAME SCOPE
3261 { goto failed_scope; } */
3262 ;
3263
3264 typename_sub:
3265 typename_sub0
3266 | global_scope typename_sub0
3267 { $$ = $2; }
3268 ;
3269
3270 typename_sub0:
3271 typename_sub1 identifier
3272 {
3273 if (TREE_CODE_CLASS (TREE_CODE ($1)) == 't')
3274 $$ = make_typename_type ($1, $2);
3275 else if (TREE_CODE ($2) == IDENTIFIER_NODE)
3276 cp_error ("`%T' is not a class or namespace", $2);
3277 else
3278 {
3279 $$ = $2;
3280 if (TREE_CODE ($$) == TYPE_DECL)
3281 $$ = TREE_TYPE ($$);
3282 }
3283 }
3284 ;
3285
3286 typename_sub1:
3287 typename_sub2
3288 {
3289 if (TREE_CODE ($1) == IDENTIFIER_NODE)
3290 cp_error ("`%T' is not a class or namespace", $1);
3291 }
3292 | typename_sub1 typename_sub2
3293 {
3294 if (TREE_CODE_CLASS (TREE_CODE ($1)) == 't')
3295 $$ = make_typename_type ($1, $2);
3296 else if (TREE_CODE ($2) == IDENTIFIER_NODE)
3297 cp_error ("`%T' is not a class or namespace", $2);
3298 else
3299 {
3300 $$ = $2;
3301 if (TREE_CODE ($$) == TYPE_DECL)
3302 $$ = TREE_TYPE ($$);
3303 }
3304 }
3305 ;
3306
3307 typename_sub2:
3308 TYPENAME SCOPE
3309 {
3310 if (TREE_CODE ($1) != IDENTIFIER_NODE)
3311 $$ = lastiddecl;
3312 got_scope = $$ = complete_type (TREE_TYPE ($$));
3313 }
3314 | SELFNAME SCOPE
3315 {
3316 if (TREE_CODE ($1) != IDENTIFIER_NODE)
3317 $$ = lastiddecl;
3318 got_scope = $$ = complete_type (TREE_TYPE ($$));
3319 }
3320 | template_type SCOPE
3321 { got_scope = $$ = complete_type (TREE_TYPE ($$)); }
3322 | PTYPENAME SCOPE
3323 | IDENTIFIER SCOPE
3324 | NSNAME SCOPE
3325 {
3326 if (TREE_CODE ($$) == IDENTIFIER_NODE)
3327 $$ = lastiddecl;
3328 got_scope = $$;
3329 }
3330 ;
3331
3332 complex_type_name:
3333 global_scope type_name
3334 {
3335 if (TREE_CODE ($2) == IDENTIFIER_NODE)
3336 $$ = IDENTIFIER_GLOBAL_VALUE ($2);
3337 else
3338 $$ = $2;
3339 got_scope = NULL_TREE;
3340 }
3341 | nested_type
3342 | global_scope nested_type
3343 { $$ = $2; }
3344 ;
3345
3346 ptr_to_mem:
3347 nested_name_specifier '*'
3348 { got_scope = NULL_TREE; }
3349 | global_scope nested_name_specifier '*'
3350 { $$ = $2; got_scope = NULL_TREE; }
3351 ;
3352
3353 /* All uses of explicit global scope must go through this nonterminal so
3354 that got_scope will be set before yylex is called to get the next token. */
3355 global_scope:
3356 SCOPE
3357 { got_scope = void_type_node; }
3358 ;
3359
3360 /* ANSI new-declarator (5.3.4) */
3361 new_declarator:
3362 '*' cv_qualifiers new_declarator
3363 { $$ = make_pointer_declarator ($2, $3); }
3364 | '*' cv_qualifiers %prec EMPTY
3365 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3366 | '&' cv_qualifiers new_declarator %prec EMPTY
3367 { $$ = make_reference_declarator ($2, $3); }
3368 | '&' cv_qualifiers %prec EMPTY
3369 { $$ = make_reference_declarator ($2, NULL_TREE); }
3370 | ptr_to_mem cv_qualifiers %prec EMPTY
3371 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3372 $$ = build_parse_node (SCOPE_REF, $1, arg);
3373 }
3374 | ptr_to_mem cv_qualifiers new_declarator
3375 { tree arg = make_pointer_declarator ($2, $3);
3376 $$ = build_parse_node (SCOPE_REF, $1, arg);
3377 }
3378 | direct_new_declarator %prec EMPTY
3379 ;
3380
3381 /* ANSI direct-new-declarator (5.3.4) */
3382 direct_new_declarator:
3383 '[' expr ']'
3384 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3385 | direct_new_declarator '[' nonmomentary_expr ']'
3386 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3387 ;
3388
3389 /* ANSI abstract-declarator (8.1) */
3390 absdcl:
3391 '*' nonempty_cv_qualifiers absdcl
3392 { $$ = make_pointer_declarator ($2.t, $3); }
3393 | '*' absdcl
3394 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3395 | '*' nonempty_cv_qualifiers %prec EMPTY
3396 { $$ = make_pointer_declarator ($2.t, NULL_TREE); }
3397 | '*' %prec EMPTY
3398 { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
3399 | '&' nonempty_cv_qualifiers absdcl
3400 { $$ = make_reference_declarator ($2.t, $3); }
3401 | '&' absdcl
3402 { $$ = make_reference_declarator (NULL_TREE, $2); }
3403 | '&' nonempty_cv_qualifiers %prec EMPTY
3404 { $$ = make_reference_declarator ($2.t, NULL_TREE); }
3405 | '&' %prec EMPTY
3406 { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
3407 | ptr_to_mem cv_qualifiers %prec EMPTY
3408 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3409 $$ = build_parse_node (SCOPE_REF, $1, arg);
3410 }
3411 | ptr_to_mem cv_qualifiers absdcl
3412 { tree arg = make_pointer_declarator ($2, $3);
3413 $$ = build_parse_node (SCOPE_REF, $1, arg);
3414 }
3415 | direct_abstract_declarator %prec EMPTY
3416 ;
3417
3418 /* ANSI direct-abstract-declarator (8.1) */
3419 direct_abstract_declarator:
3420 '(' absdcl ')'
3421 { $$ = $2; }
3422 /* `(typedef)1' is `int'. */
3423 | PAREN_STAR_PAREN
3424 | direct_abstract_declarator '(' parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
3425 { $$ = make_call_declarator ($$, $3, $5, $6); }
3426 | direct_abstract_declarator LEFT_RIGHT cv_qualifiers exception_specification_opt %prec '.'
3427 { $$ = make_call_declarator ($$, empty_parms (), $3, $4); }
3428 | direct_abstract_declarator '[' nonmomentary_expr ']' %prec '.'
3429 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3430 | direct_abstract_declarator '[' ']' %prec '.'
3431 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
3432 | '(' complex_parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
3433 { $$ = make_call_declarator (NULL_TREE, $2, $4, $5); }
3434 | regcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
3435 { set_quals_and_spec ($$, $2, $3); }
3436 | fcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
3437 { set_quals_and_spec ($$, $2, $3); }
3438 | '[' nonmomentary_expr ']' %prec '.'
3439 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3440 | '[' ']' %prec '.'
3441 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
3442 ;
3443
3444 /* For C++, decls and stmts can be intermixed, so we don't need to
3445 have a special rule that won't start parsing the stmt section
3446 until we have a stmt that parses without errors. */
3447
3448 stmts:
3449 stmt
3450 | errstmt
3451 | stmts stmt
3452 | stmts errstmt
3453 ;
3454
3455 errstmt:
3456 error ';'
3457 ;
3458
3459 /* build the LET_STMT node before parsing its contents,
3460 so that any LET_STMTs within the context can have their display pointers
3461 set up to point at this one. */
3462
3463 .pushlevel:
3464 /* empty */
3465 { do_pushlevel (); }
3466 ;
3467
3468 .poplevel:
3469 /* empty */
3470 { $$ = do_poplevel (); }
3471 ;
3472
3473 /* Read zero or more forward-declarations for labels
3474 that nested functions can jump to. */
3475 maybe_label_decls:
3476 /* empty */
3477 | label_decls
3478 { if (pedantic)
3479 pedwarn ("ANSI C++ forbids label declarations"); }
3480 ;
3481
3482 label_decls:
3483 label_decl
3484 | label_decls label_decl
3485 ;
3486
3487 label_decl:
3488 LABEL identifiers_or_typenames ';'
3489 { tree link;
3490 for (link = $2; link; link = TREE_CHAIN (link))
3491 {
3492 tree label = shadow_label (TREE_VALUE (link));
3493 C_DECLARED_LABEL_FLAG (label) = 1;
3494 declare_nonlocal_label (label);
3495 }
3496 }
3497 ;
3498
3499 /* This is the body of a function definition.
3500 It causes syntax errors to ignore to the next openbrace. */
3501 compstmt_or_error:
3502 compstmt
3503 {}
3504 | error compstmt
3505 ;
3506
3507 compstmt:
3508 '{'
3509 {
3510 if (processing_template_decl)
3511 {
3512 $<ttype>$ = build_min_nt (COMPOUND_STMT, NULL_TREE);
3513 add_tree ($<ttype>$);
3514 }
3515 }
3516 .pushlevel compstmtend .poplevel
3517 {
3518 if (processing_template_decl)
3519 {
3520 TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
3521 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3522 last_tree = $<ttype>2;
3523 }
3524 $$ = $5;
3525 }
3526 ;
3527
3528 simple_if:
3529 IF
3530 {
3531 if (processing_template_decl)
3532 {
3533 $<ttype>$ = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE,
3534 NULL_TREE);
3535 add_tree ($<ttype>$);
3536 }
3537 cond_stmt_keyword = "if";
3538 }
3539 .pushlevel paren_cond_or_null
3540 {
3541 if (processing_template_decl)
3542 {
3543 if (last_tree != $<ttype>2)
3544 {
3545 TREE_OPERAND ($<ttype>2, 0) = last_tree;
3546 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3547 last_tree = $<ttype>2;
3548 }
3549 else
3550 TREE_OPERAND ($<ttype>2, 0) = $4;
3551 }
3552 else
3553 {
3554 emit_line_note (input_filename, lineno);
3555 expand_start_cond ($4, 0);
3556 }
3557 }
3558 implicitly_scoped_stmt
3559 {
3560 if (processing_template_decl)
3561 {
3562 TREE_OPERAND ($<ttype>2, 1) = TREE_CHAIN ($<ttype>2);
3563 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3564 $<ttype>$ = last_tree = $<ttype>2;
3565 }
3566 }
3567 ;
3568
3569 implicitly_scoped_stmt:
3570 compstmt
3571 { finish_stmt (); }
3572 | .pushlevel
3573 {
3574 if (processing_template_decl)
3575 {
3576 $<ttype>$ = build_min_nt (COMPOUND_STMT, NULL_TREE);
3577 add_tree ($<ttype>$);
3578 }
3579 }
3580 simple_stmt .poplevel
3581 {
3582 if (processing_template_decl)
3583 {
3584 TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
3585 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3586 last_tree = $<ttype>2;
3587 }
3588 $$ = $4;
3589 }
3590 ;
3591
3592 stmt:
3593 compstmt
3594 { finish_stmt (); }
3595 | simple_stmt
3596 ;
3597
3598 simple_stmt:
3599 decl
3600 { finish_stmt (); }
3601 | expr ';'
3602 {
3603 tree expr = $1;
3604 if (! processing_template_decl)
3605 {
3606 emit_line_note (input_filename, lineno);
3607 /* Do default conversion if safe and possibly important,
3608 in case within ({...}). */
3609 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
3610 && lvalue_p (expr))
3611 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
3612 expr = default_conversion (expr);
3613 }
3614 cplus_expand_expr_stmt (expr);
3615 clear_momentary ();
3616 finish_stmt (); }
3617 | simple_if ELSE
3618 { if (! processing_template_decl) expand_start_else (); }
3619 implicitly_scoped_stmt
3620 {
3621 if (processing_template_decl)
3622 {
3623 TREE_OPERAND ($<ttype>1, 2) = TREE_CHAIN ($<ttype>1);
3624 TREE_CHAIN ($<ttype>1) = NULL_TREE;
3625 last_tree = $<ttype>1;
3626 }
3627 else
3628 expand_end_cond ();
3629 }
3630 .poplevel
3631 { finish_stmt (); }
3632 | simple_if %prec IF
3633 { if (! processing_template_decl) expand_end_cond ();
3634 do_poplevel ();
3635 finish_stmt (); }
3636 | WHILE
3637 {
3638 if (processing_template_decl)
3639 {
3640 $<ttype>$ = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
3641 add_tree ($<ttype>$);
3642 }
3643 else
3644 {
3645 emit_nop ();
3646 emit_line_note (input_filename, lineno);
3647 expand_start_loop (1);
3648 }
3649 cond_stmt_keyword = "while";
3650 }
3651 .pushlevel paren_cond_or_null
3652 {
3653 if (processing_template_decl)
3654 {
3655 if (last_tree != $<ttype>2)
3656 {
3657 TREE_OPERAND ($<ttype>2, 0) = last_tree;
3658 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3659 last_tree = $<ttype>2;
3660 }
3661 else
3662 TREE_OPERAND ($<ttype>2, 0) = $4;
3663 }
3664 else
3665 {
3666 emit_line_note (input_filename, lineno);
3667 expand_exit_loop_if_false (0, $4);
3668 }
3669 }
3670 already_scoped_stmt .poplevel
3671 {
3672 if (processing_template_decl)
3673 {
3674 TREE_OPERAND ($<ttype>2, 1) = TREE_CHAIN ($<ttype>2);
3675 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3676 last_tree = $<ttype>2;
3677 }
3678 else
3679 expand_end_loop ();
3680 finish_stmt ();
3681 }
3682 | DO
3683 {
3684 if (processing_template_decl)
3685 {
3686 $<ttype>$ = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
3687 add_tree ($<ttype>$);
3688 }
3689 else
3690 {
3691 emit_nop ();
3692 emit_line_note (input_filename, lineno);
3693 expand_start_loop_continue_elsewhere (1);
3694 }
3695 }
3696 implicitly_scoped_stmt WHILE
3697 {
3698 if (processing_template_decl)
3699 {
3700 TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
3701 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3702 last_tree = $<ttype>2;
3703 }
3704 else
3705 {
3706 expand_loop_continue_here ();
3707 cond_stmt_keyword = "do";
3708 }
3709 }
3710 paren_expr_or_null ';'
3711 {
3712 if (processing_template_decl)
3713 TREE_OPERAND ($<ttype>2, 1) = $6;
3714 else
3715 {
3716 emit_line_note (input_filename, lineno);
3717 expand_exit_loop_if_false (0, $6);
3718 expand_end_loop ();
3719 }
3720 clear_momentary ();
3721 finish_stmt ();
3722 }
3723 | FOR
3724 { if (processing_template_decl)
3725 {
3726 $<ttype>$ = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
3727 NULL_TREE, NULL_TREE);
3728 add_tree ($<ttype>$);
3729 }
3730 else
3731 emit_line_note (input_filename, lineno);
3732 if (flag_new_for_scope > 0)
3733 {
3734 /* Conditionalize .pushlevel */
3735 pushlevel (0);
3736 note_level_for_for ();
3737 clear_last_expr ();
3738 push_momentary ();
3739 expand_start_bindings (0);
3740 }
3741 }
3742 '(' for.init.statement
3743 {
3744 if (processing_template_decl)
3745 {
3746 if (last_tree != $<ttype>2)
3747 {
3748 TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
3749 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3750 last_tree = $<ttype>2;
3751 }
3752 }
3753 else
3754 {
3755 emit_nop ();
3756 emit_line_note (input_filename, lineno);
3757 expand_start_loop_continue_elsewhere (1);
3758 }
3759 }
3760 .pushlevel xcond ';'
3761 {
3762 if (processing_template_decl)
3763 {
3764 if (last_tree != $<ttype>2)
3765 {
3766 TREE_OPERAND ($<ttype>2, 1) = last_tree;
3767 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3768 last_tree = $<ttype>2;
3769 }
3770 else
3771 TREE_OPERAND ($<ttype>2, 1) = $7;
3772 }
3773 else
3774 {
3775 emit_line_note (input_filename, lineno);
3776 if ($7) expand_exit_loop_if_false (0, $7);
3777 }
3778 }
3779 xexpr ')'
3780 /* Don't let the tree nodes for $10 be discarded
3781 by clear_momentary during the parsing of the next stmt. */
3782 {
3783 if (processing_template_decl)
3784 TREE_OPERAND ($<ttype>2, 2) = $10;
3785 push_momentary ();
3786 }
3787 already_scoped_stmt .poplevel
3788 {
3789 if (processing_template_decl)
3790 {
3791 TREE_OPERAND ($<ttype>2, 3) = TREE_CHAIN ($<ttype>2);
3792 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3793 last_tree = $<ttype>2;
3794 }
3795 else
3796 {
3797 emit_line_note (input_filename, lineno);
3798 expand_loop_continue_here ();
3799 if ($10) cplus_expand_expr_stmt ($10);
3800 expand_end_loop ();
3801 }
3802 pop_momentary ();
3803 if (flag_new_for_scope > 0)
3804 {
3805 do_poplevel ();
3806 }
3807 finish_stmt (); }
3808 | SWITCH .pushlevel '(' condition ')'
3809 {
3810 if (processing_template_decl)
3811 {
3812 $<ttype>$ = build_min_nt (SWITCH_STMT, $4, NULL_TREE);
3813 add_tree ($<ttype>$);
3814 }
3815 else
3816 {
3817 emit_line_note (input_filename, lineno);
3818 c_expand_start_case ($4);
3819 }
3820 push_switch ();
3821 /* Don't let the tree nodes for $4 be discarded by
3822 clear_momentary during the parsing of the next stmt. */
3823 push_momentary ();
3824 }
3825 implicitly_scoped_stmt
3826 {
3827 if (processing_template_decl)
3828 {
3829 TREE_OPERAND ($<ttype>6, 1) = TREE_CHAIN ($<ttype>6);
3830 TREE_CHAIN ($<ttype>6) = NULL_TREE;
3831 last_tree = $<ttype>6;
3832 }
3833 else
3834 expand_end_case ($4);
3835 pop_momentary ();
3836 pop_switch ();
3837 }
3838 .poplevel
3839 { finish_stmt (); }
3840 | CASE expr_no_commas ':'
3841 { do_case ($2, NULL_TREE); }
3842 stmt
3843 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
3844 { do_case ($2, $4); }
3845 stmt
3846 | DEFAULT ':'
3847 { do_case (NULL_TREE, NULL_TREE); }
3848 stmt
3849 | BREAK ';'
3850 { emit_line_note (input_filename, lineno);
3851 if (processing_template_decl)
3852 add_tree (build_min_nt (BREAK_STMT));
3853 else if ( ! expand_exit_something ())
3854 error ("break statement not within loop or switch"); }
3855 | CONTINUE ';'
3856 { emit_line_note (input_filename, lineno);
3857 if (processing_template_decl)
3858 add_tree (build_min_nt (CONTINUE_STMT));
3859 else if (! expand_continue_loop (0))
3860 error ("continue statement not within a loop"); }
3861 | RETURN ';'
3862 { emit_line_note (input_filename, lineno);
3863 c_expand_return (NULL_TREE); }
3864 | RETURN expr ';'
3865 { emit_line_note (input_filename, lineno);
3866 c_expand_return ($2);
3867 finish_stmt ();
3868 }
3869 | asm_keyword maybe_cv_qualifier '(' string ')' ';'
3870 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3871 emit_line_note (input_filename, lineno);
3872 expand_asm ($4);
3873 finish_stmt ();
3874 }
3875 /* This is the case with just output operands. */
3876 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ')' ';'
3877 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3878 emit_line_note (input_filename, lineno);
3879 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
3880 $2 == ridpointers[(int)RID_VOLATILE],
3881 input_filename, lineno);
3882 finish_stmt ();
3883 }
3884 /* This is the case with input operands as well. */
3885 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':' asm_operands ')' ';'
3886 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3887 emit_line_note (input_filename, lineno);
3888 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
3889 $2 == ridpointers[(int)RID_VOLATILE],
3890 input_filename, lineno);
3891 finish_stmt ();
3892 }
3893 /* This is the case with clobbered registers as well. */
3894 | asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':'
3895 asm_operands ':' asm_clobbers ')' ';'
3896 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3897 emit_line_note (input_filename, lineno);
3898 c_expand_asm_operands ($4, $6, $8, $10,
3899 $2 == ridpointers[(int)RID_VOLATILE],
3900 input_filename, lineno);
3901 finish_stmt ();
3902 }
3903 | GOTO '*' expr ';'
3904 {
3905 if (processing_template_decl)
3906 add_tree (build_min_nt (GOTO_STMT, $3));
3907 else
3908 { emit_line_note (input_filename, lineno);
3909 expand_computed_goto ($3); }
3910 }
3911 | GOTO identifier ';'
3912 {
3913 if (processing_template_decl)
3914 add_tree (build_min_nt (GOTO_STMT, $2));
3915 else
3916 {
3917 tree decl;
3918 emit_line_note (input_filename, lineno);
3919 decl = lookup_label ($2);
3920 TREE_USED (decl) = 1;
3921 expand_goto (decl);
3922 }
3923 }
3924 | label_colon stmt
3925 { finish_stmt (); }
3926 | label_colon '}'
3927 { error ("label must be followed by statement");
3928 yyungetc ('}', 0);
3929 finish_stmt (); }
3930 | ';'
3931 { finish_stmt (); }
3932 | try_block
3933 ;
3934
3935 function_try_block:
3936 TRY
3937 {
3938 if (! current_function_parms_stored)
3939 store_parm_decls ();
3940 expand_start_early_try_stmts ();
3941 }
3942 ctor_initializer_opt compstmt
3943 { expand_start_all_catch (); }
3944 handler_seq
3945 {
3946 int nested = (hack_decl_function_context
3947 (current_function_decl) != NULL_TREE);
3948 expand_end_all_catch ();
3949 finish_function (lineno, (int)$3, nested);
3950 }
3951 ;
3952
3953 try_block:
3954 TRY
3955 {
3956 if (processing_template_decl)
3957 {
3958 $<ttype>$ = build_min_nt (TRY_BLOCK, NULL_TREE,
3959 NULL_TREE);
3960 add_tree ($<ttype>$);
3961 }
3962 else
3963 {
3964 emit_line_note (input_filename, lineno);
3965 expand_start_try_stmts ();
3966 }
3967 }
3968 compstmt
3969 {
3970 if (processing_template_decl)
3971 {
3972 TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
3973 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3974 last_tree = $<ttype>2;
3975 }
3976 else
3977 expand_start_all_catch ();
3978 }
3979 handler_seq
3980 {
3981 if (processing_template_decl)
3982 {
3983 TREE_OPERAND ($<ttype>2, 1) = TREE_CHAIN ($<ttype>2);
3984 TREE_CHAIN ($<ttype>2) = NULL_TREE;
3985 last_tree = $<ttype>2;
3986 }
3987 else
3988 expand_end_all_catch ();
3989 }
3990 ;
3991
3992 handler_seq:
3993 handler
3994 | handler_seq handler
3995 ;
3996
3997 handler:
3998 CATCH
3999 {
4000 if (processing_template_decl)
4001 {
4002 $<ttype>$ = build_min_nt (HANDLER, NULL_TREE,
4003 NULL_TREE);
4004 add_tree ($<ttype>$);
4005 }
4006 }
4007 .pushlevel handler_args
4008 {
4009 if (processing_template_decl)
4010 {
4011 TREE_OPERAND ($<ttype>2, 0) = TREE_CHAIN ($<ttype>2);
4012 TREE_CHAIN ($<ttype>2) = NULL_TREE;
4013 last_tree = $<ttype>2;
4014 }
4015 }
4016 compstmt
4017 {
4018 if (processing_template_decl)
4019 {
4020 TREE_OPERAND ($<ttype>2, 1) = TREE_CHAIN ($<ttype>2);
4021 TREE_CHAIN ($<ttype>2) = NULL_TREE;
4022 last_tree = $<ttype>2;
4023 }
4024 else
4025 expand_end_catch_block ();
4026 }
4027 .poplevel
4028 ;
4029
4030 type_specifier_seq:
4031 typed_typespecs %prec EMPTY
4032 | nonempty_cv_qualifiers %prec EMPTY
4033 ;
4034
4035 handler_args:
4036 '(' ELLIPSIS ')'
4037 { expand_start_catch_block (NULL_TREE, NULL_TREE); }
4038 /* This doesn't allow reference parameters, the below does.
4039 | '(' type_specifier_seq absdcl ')'
4040 { check_for_new_type ("inside exception declarations", $2);
4041 expand_start_catch_block ($2.t, $3); }
4042 | '(' type_specifier_seq ')'
4043 { check_for_new_type ("inside exception declarations", $2);
4044 expand_start_catch_block ($2.t, NULL_TREE); }
4045 | '(' type_specifier_seq notype_declarator ')'
4046 { check_for_new_type ("inside exception declarations", $2);
4047 expand_start_catch_block ($2.t, $3); }
4048 | '(' typed_typespecs after_type_declarator ')'
4049 { check_for_new_type ("inside exception declarations", $2);
4050 expand_start_catch_block ($2.t, $3); }
4051 This allows reference parameters... */
4052 | '(' parm ')'
4053 { check_for_new_type ("inside exception declarations", $2);
4054 expand_start_catch_block (TREE_PURPOSE ($2.t),
4055 TREE_VALUE ($2.t)); }
4056 ;
4057
4058 label_colon:
4059 IDENTIFIER ':'
4060 { tree label;
4061 do_label:
4062 label = define_label (input_filename, lineno, $1);
4063 if (label && ! minimal_parse_mode)
4064 expand_label (label);
4065 }
4066 | PTYPENAME ':'
4067 { goto do_label; }
4068 | TYPENAME ':'
4069 { goto do_label; }
4070 | SELFNAME ':'
4071 { goto do_label; }
4072 ;
4073
4074 for.init.statement:
4075 xexpr ';'
4076 { if ($1) cplus_expand_expr_stmt ($1); }
4077 | decl
4078 | '{' compstmtend
4079 { if (pedantic)
4080 pedwarn ("ANSI C++ forbids compound statements inside for initializations");
4081 }
4082 ;
4083
4084 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
4085
4086 maybe_cv_qualifier:
4087 /* empty */
4088 { emit_line_note (input_filename, lineno);
4089 $$ = NULL_TREE; }
4090 | CV_QUALIFIER
4091 { emit_line_note (input_filename, lineno); }
4092 ;
4093
4094 xexpr:
4095 /* empty */
4096 { $$ = NULL_TREE; }
4097 | expr
4098 | error
4099 { $$ = NULL_TREE; }
4100 ;
4101
4102 /* These are the operands other than the first string and colon
4103 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
4104 asm_operands:
4105 /* empty */
4106 { $$ = NULL_TREE; }
4107 | nonnull_asm_operands
4108 ;
4109
4110 nonnull_asm_operands:
4111 asm_operand
4112 | nonnull_asm_operands ',' asm_operand
4113 { $$ = chainon ($$, $3); }
4114 ;
4115
4116 asm_operand:
4117 STRING '(' expr ')'
4118 { $$ = build_tree_list ($$, $3); }
4119 ;
4120
4121 asm_clobbers:
4122 STRING
4123 { $$ = tree_cons (NULL_TREE, $$, NULL_TREE); }
4124 | asm_clobbers ',' STRING
4125 { $$ = tree_cons (NULL_TREE, $3, $$); }
4126 ;
4127
4128 /* This is what appears inside the parens in a function declarator.
4129 Its value is represented in the format that grokdeclarator expects.
4130
4131 In C++, declaring a function with no parameters
4132 means that that function takes *no* parameters. */
4133
4134 parmlist:
4135 /* empty */
4136 {
4137 $$ = empty_parms();
4138 }
4139 | complex_parmlist
4140 | type_id
4141 { $$ = tree_cons (NULL_TREE, $1.t, void_list_node);
4142 TREE_PARMLIST ($$) = 1;
4143 check_for_new_type ("inside parameter list", $1); }
4144 ;
4145
4146 /* This nonterminal does not include the common sequence '(' type_id ')',
4147 as it is ambiguous and must be disambiguated elsewhere. */
4148 complex_parmlist:
4149 parms
4150 {
4151 $$ = chainon ($$, void_list_node);
4152 TREE_PARMLIST ($$) = 1;
4153 }
4154 | parms_comma ELLIPSIS
4155 {
4156 TREE_PARMLIST ($$) = 1;
4157 }
4158 /* C++ allows an ellipsis without a separating ',' */
4159 | parms ELLIPSIS
4160 {
4161 TREE_PARMLIST ($$) = 1;
4162 }
4163 | type_id ELLIPSIS
4164 {
4165 $$ = build_tree_list (NULL_TREE, $1.t);
4166 TREE_PARMLIST ($$) = 1;
4167 }
4168 | ELLIPSIS
4169 {
4170 $$ = NULL_TREE;
4171 }
4172 | TYPENAME_ELLIPSIS
4173 {
4174 TREE_PARMLIST ($$) = 1;
4175 }
4176 | parms TYPENAME_ELLIPSIS
4177 {
4178 TREE_PARMLIST ($$) = 1;
4179 }
4180 | type_id TYPENAME_ELLIPSIS
4181 {
4182 $$ = build_tree_list (NULL_TREE, $1.t);
4183 TREE_PARMLIST ($$) = 1;
4184 }
4185 | parms ':'
4186 {
4187 /* This helps us recover from really nasty
4188 parse errors, for example, a missing right
4189 parenthesis. */
4190 yyerror ("possibly missing ')'");
4191 $$ = chainon ($$, void_list_node);
4192 TREE_PARMLIST ($$) = 1;
4193 yyungetc (':', 0);
4194 yychar = ')';
4195 }
4196 | type_id ':'
4197 {
4198 /* This helps us recover from really nasty
4199 parse errors, for example, a missing right
4200 parenthesis. */
4201 yyerror ("possibly missing ')'");
4202 $$ = tree_cons (NULL_TREE, $1.t, void_list_node);
4203 TREE_PARMLIST ($$) = 1;
4204 yyungetc (':', 0);
4205 yychar = ')';
4206 }
4207 ;
4208
4209 /* A default argument to a */
4210 defarg:
4211 '='
4212 { maybe_snarf_defarg (); }
4213 defarg1
4214 { $$ = $3; }
4215 ;
4216
4217 defarg1:
4218 DEFARG
4219 | init
4220 ;
4221
4222 /* A nonempty list of parameter declarations or type names. */
4223 parms:
4224 named_parm
4225 { check_for_new_type ("in a parameter list", $1);
4226 $$ = build_tree_list (NULL_TREE, $1.t); }
4227 | parm defarg
4228 { check_for_new_type ("in a parameter list", $1);
4229 $$ = build_tree_list ($2, $1.t); }
4230 | parms_comma full_parm
4231 { check_for_new_type ("in a parameter list", $2);
4232 $$ = chainon ($$, $2.t); }
4233 | parms_comma bad_parm
4234 { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
4235 | parms_comma bad_parm '=' init
4236 { $$ = chainon ($$, build_tree_list ($4, $2)); }
4237 ;
4238
4239 parms_comma:
4240 parms ','
4241 | type_id ','
4242 { check_for_new_type ("in a parameter list", $1);
4243 $$ = build_tree_list (NULL_TREE, $1.t); }
4244 ;
4245
4246 /* A single parameter declaration or parameter type name,
4247 as found in a parmlist. */
4248 named_parm:
4249 /* Here we expand typed_declspecs inline to avoid mis-parsing of
4250 TYPESPEC IDENTIFIER. */
4251 typed_declspecs1 declarator
4252 { tree specs = strip_attrs ($1.t);
4253 $$.new_type_flag = $1.new_type_flag;
4254 $$.t = build_tree_list (specs, $2); }
4255 | typed_typespecs declarator
4256 { $$.t = build_tree_list ($1.t, $2);
4257 $$.new_type_flag = $1.new_type_flag; }
4258 | typespec declarator
4259 { $$.t = build_tree_list (get_decl_list ($1.t), $2);
4260 $$.new_type_flag = $1.new_type_flag; }
4261 | typed_declspecs1 absdcl
4262 { tree specs = strip_attrs ($1.t);
4263 $$.t = build_tree_list (specs, $2);
4264 $$.new_type_flag = $1.new_type_flag; }
4265 | typed_declspecs1 %prec EMPTY
4266 { tree specs = strip_attrs ($1.t);
4267 $$.t = build_tree_list (specs, NULL_TREE);
4268 $$.new_type_flag = $1.new_type_flag; }
4269 | declmods notype_declarator
4270 { tree specs = strip_attrs ($1);
4271 $$.t = build_tree_list (specs, $2);
4272 $$.new_type_flag = 0; }
4273 ;
4274
4275 full_parm:
4276 parm
4277 { $$.t = build_tree_list (NULL_TREE, $1.t);
4278 $$.new_type_flag = $1.new_type_flag; }
4279 | parm defarg
4280 { $$.t = build_tree_list ($2, $1.t);
4281 $$.new_type_flag = $1.new_type_flag; }
4282 ;
4283
4284 parm:
4285 named_parm
4286 | type_id
4287 ;
4288
4289 see_typename:
4290 /* empty */ %prec EMPTY
4291 { see_typename (); }
4292 ;
4293
4294 bad_parm:
4295 /* empty */ %prec EMPTY
4296 {
4297 error ("type specifier omitted for parameter");
4298 $$ = build_tree_list (integer_type_node, NULL_TREE);
4299 }
4300 | notype_declarator
4301 {
4302 error ("type specifier omitted for parameter");
4303 if (TREE_CODE ($$) == SCOPE_REF
4304 && (TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TYPE_PARM
4305 || TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TEMPLATE_PARM))
4306 cp_error (" perhaps you want `typename %E' to make it a type", $$);
4307 $$ = build_tree_list (integer_type_node, $$);
4308 }
4309 ;
4310
4311 exception_specification_opt:
4312 /* empty */ %prec EMPTY
4313 { $$ = NULL_TREE; }
4314 | THROW '(' ansi_raise_identifiers ')' %prec EMPTY
4315 { $$ = $3; }
4316 | THROW LEFT_RIGHT %prec EMPTY
4317 { $$ = build_decl_list (NULL_TREE, NULL_TREE); }
4318 ;
4319
4320 ansi_raise_identifier:
4321 type_id
4322 { $$ = build_decl_list (NULL_TREE, groktypename($1.t)); }
4323 ;
4324
4325 ansi_raise_identifiers:
4326 ansi_raise_identifier
4327 | ansi_raise_identifiers ',' ansi_raise_identifier
4328 {
4329 TREE_CHAIN ($3) = $$;
4330 $$ = $3;
4331 }
4332 ;
4333
4334 conversion_declarator:
4335 /* empty */ %prec EMPTY
4336 { $$ = NULL_TREE; }
4337 | '*' cv_qualifiers conversion_declarator
4338 { $$ = make_pointer_declarator ($2, $3); }
4339 | '&' cv_qualifiers conversion_declarator
4340 { $$ = make_reference_declarator ($2, $3); }
4341 | ptr_to_mem cv_qualifiers conversion_declarator
4342 { tree arg = make_pointer_declarator ($2, $3);
4343 $$ = build_parse_node (SCOPE_REF, $1, arg);
4344 }
4345 ;
4346
4347 operator:
4348 OPERATOR
4349 { got_scope = NULL_TREE; }
4350 ;
4351
4352 operator_name:
4353 operator '*'
4354 { $$ = ansi_opname[MULT_EXPR]; }
4355 | operator '/'
4356 { $$ = ansi_opname[TRUNC_DIV_EXPR]; }
4357 | operator '%'
4358 { $$ = ansi_opname[TRUNC_MOD_EXPR]; }
4359 | operator '+'
4360 { $$ = ansi_opname[PLUS_EXPR]; }
4361 | operator '-'
4362 { $$ = ansi_opname[MINUS_EXPR]; }
4363 | operator '&'
4364 { $$ = ansi_opname[BIT_AND_EXPR]; }
4365 | operator '|'
4366 { $$ = ansi_opname[BIT_IOR_EXPR]; }
4367 | operator '^'
4368 { $$ = ansi_opname[BIT_XOR_EXPR]; }
4369 | operator '~'
4370 { $$ = ansi_opname[BIT_NOT_EXPR]; }
4371 | operator ','
4372 { $$ = ansi_opname[COMPOUND_EXPR]; }
4373 | operator ARITHCOMPARE
4374 { $$ = ansi_opname[$2]; }
4375 | operator '<'
4376 { $$ = ansi_opname[LT_EXPR]; }
4377 | operator '>'
4378 { $$ = ansi_opname[GT_EXPR]; }
4379 | operator EQCOMPARE
4380 { $$ = ansi_opname[$2]; }
4381 | operator ASSIGN
4382 { $$ = ansi_assopname[$2]; }
4383 | operator '='
4384 { $$ = ansi_opname [MODIFY_EXPR]; }
4385 | operator LSHIFT
4386 { $$ = ansi_opname[$2]; }
4387 | operator RSHIFT
4388 { $$ = ansi_opname[$2]; }
4389 | operator PLUSPLUS
4390 { $$ = ansi_opname[POSTINCREMENT_EXPR]; }
4391 | operator MINUSMINUS
4392 { $$ = ansi_opname[PREDECREMENT_EXPR]; }
4393 | operator ANDAND
4394 { $$ = ansi_opname[TRUTH_ANDIF_EXPR]; }
4395 | operator OROR
4396 { $$ = ansi_opname[TRUTH_ORIF_EXPR]; }
4397 | operator '!'
4398 { $$ = ansi_opname[TRUTH_NOT_EXPR]; }
4399 | operator '?' ':'
4400 { $$ = ansi_opname[COND_EXPR]; }
4401 | operator MIN_MAX
4402 { $$ = ansi_opname[$2]; }
4403 | operator POINTSAT %prec EMPTY
4404 { $$ = ansi_opname[COMPONENT_REF]; }
4405 | operator POINTSAT_STAR %prec EMPTY
4406 { $$ = ansi_opname[MEMBER_REF]; }
4407 | operator LEFT_RIGHT
4408 { $$ = ansi_opname[CALL_EXPR]; }
4409 | operator '[' ']'
4410 { $$ = ansi_opname[ARRAY_REF]; }
4411 | operator NEW %prec EMPTY
4412 { $$ = ansi_opname[NEW_EXPR]; }
4413 | operator DELETE %prec EMPTY
4414 { $$ = ansi_opname[DELETE_EXPR]; }
4415 | operator NEW '[' ']'
4416 { $$ = ansi_opname[VEC_NEW_EXPR]; }
4417 | operator DELETE '[' ']'
4418 { $$ = ansi_opname[VEC_DELETE_EXPR]; }
4419 /* Names here should be looked up in class scope ALSO. */
4420 | operator type_specifier_seq conversion_declarator
4421 { $$ = grokoptypename ($2.t, $3); }
4422 | operator error
4423 { $$ = ansi_opname[ERROR_MARK]; }
4424 ;
4425
4426 %%
4427
4428 #ifdef SPEW_DEBUG
4429 const char *
4430 debug_yytranslate (value)
4431 int value;
4432 {
4433 return yytname[YYTRANSLATE (value)];
4434 }
4435
4436 #endif