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