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