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