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