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