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