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