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