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