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