]> gcc.gnu.org Git - gcc.git/blob - gcc/cp/parse.y
63rd 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 TYPENAME_KEYWORD
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 | TYPENAME_KEYWORD complex_type_name
2189 { $$ = $2; }
2190 /* C++ extensions, merged with C to avoid shift/reduce conflicts */
2191 | class_head left_curly opt.component_decl_list '}'
2192 {
2193 int semi;
2194 tree id;
2195
2196 #if 0
2197 /* Need to rework class nesting in the
2198 presence of nested classes, etc. */
2199 shadow_tag (CLASSTYPE_AS_LIST ($$)); */
2200 #endif
2201 if (yychar == YYEMPTY)
2202 yychar = YYLEX;
2203 semi = yychar == ';';
2204 /* finish_struct nukes this anyway; if
2205 finish_exception does too, then it can go. */
2206 if (semi)
2207 note_got_semicolon ($$);
2208
2209 if (TREE_CODE ($$) == ENUMERAL_TYPE)
2210 /* $$ = $1 from default rule. */;
2211 else
2212 {
2213 $$ = finish_struct ($$, $3, semi);
2214 if (semi) note_got_semicolon ($$);
2215 }
2216
2217 pop_obstacks ();
2218
2219 id = TYPE_IDENTIFIER ($$);
2220 if (id && IDENTIFIER_TEMPLATE (id))
2221 {
2222 tree decl;
2223
2224 /* I don't know if the copying of this TYPE_DECL is
2225 * really needed. However, it's such a small per-
2226 * formance penalty that the extra safety is a bargain.
2227 * - niklas@appli.se
2228 */
2229 push_obstacks (&permanent_obstack, &permanent_obstack);
2230 decl = copy_node (lookup_name (id, 0));
2231 if (DECL_LANG_SPECIFIC (decl))
2232 copy_lang_decl (decl);
2233 pop_obstacks ();
2234 undo_template_name_overload (id, 0);
2235 pushdecl_top_level (decl);
2236 }
2237 if (! semi)
2238 check_for_missing_semicolon ($$); }
2239 | class_head %prec EMPTY
2240 {
2241 /* struct B: public A; is not accepted by the WP grammar. */
2242 if (TYPE_BINFO_BASETYPES ($$) && !TYPE_SIZE ($$)
2243 && ! TYPE_BEING_DEFINED ($$))
2244 cp_error ("base clause without member specification for `%#T'",
2245 $$);
2246 }
2247 ;
2248
2249 maybecomma:
2250 /* empty */
2251 | ','
2252 ;
2253
2254 maybecomma_warn:
2255 /* empty */
2256 | ','
2257 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
2258 ;
2259
2260 aggr: AGGR
2261 | aggr SCSPEC
2262 { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2263 | aggr TYPESPEC
2264 { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2265 | aggr TYPE_QUAL
2266 { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2267 | aggr AGGR
2268 { error ("no body nor ';' separates two class, struct or union declarations"); }
2269 ;
2270
2271 specialization:
2272 aggr template_type_name ';'
2273 {
2274 yyungetc (';', 1); current_aggr = $$; $$ = $2;
2275 if ($<ttype>0 == ridpointers[(int) RID_TEMPLATE])
2276 instantiate_class_template ($$, 2);
2277 }
2278 ;
2279
2280 named_class_head_sans_basetype:
2281 aggr identifier
2282 { current_aggr = $$; $$ = $2; }
2283 | aggr complex_type_name
2284 { current_aggr = $$; $$ = $2; }
2285 | aggr template_type %prec EMPTY
2286 { current_aggr = $$; $$ = $2; }
2287 | specialization
2288 ;
2289
2290 named_class_head_sans_basetype_defn:
2291 aggr identifier_defn %prec EMPTY
2292 { current_aggr = $$; $$ = $2; }
2293 | aggr template_type_name '{'
2294 { yyungetc ('{', 1);
2295 aggr2:
2296 current_aggr = $$;
2297 $$ = $2;
2298 overload_template_name ($$, 0); }
2299 | aggr template_type_name ':'
2300 { yyungetc (':', 1); goto aggr2; }
2301 ;
2302
2303 do_xref_defn: /* empty */ %prec EMPTY
2304 { $<ttype>$ = xref_tag (current_aggr, $<ttype>0, NULL_TREE, 0); }
2305 ;
2306
2307 named_class_head:
2308 named_class_head_sans_basetype %prec EMPTY
2309 { $$ = xref_tag (current_aggr, $1, NULL_TREE, 1); }
2310 | named_class_head_sans_basetype_defn do_xref_defn
2311 maybe_base_class_list %prec EMPTY
2312 {
2313 $$ = $<ttype>2;
2314 if ($3)
2315 xref_basetypes (current_aggr, $1, $<ttype>2, $3);
2316 }
2317 ;
2318
2319 unnamed_class_head: aggr '{'
2320 { $$ = xref_tag ($$, make_anon_name (), NULL_TREE, 0);
2321 yyungetc ('{', 1); }
2322 ;
2323
2324 class_head: unnamed_class_head | named_class_head ;
2325
2326 maybe_base_class_list:
2327 %prec EMPTY /* empty */
2328 { $$ = NULL_TREE; }
2329 | ':' %prec EMPTY
2330 { yyungetc(':', 1); $$ = NULL_TREE; }
2331 | ':' base_class_list %prec EMPTY
2332 { $$ = $2; }
2333 ;
2334
2335 base_class_list:
2336 base_class
2337 | base_class_list ',' base_class
2338 { $$ = chainon ($$, $3); }
2339 ;
2340
2341 base_class:
2342 base_class.1
2343 {
2344 tree type;
2345 do_base_class1:
2346 type = IDENTIFIER_TYPE_VALUE ($$);
2347 if (! is_aggr_typedef ($$, 1))
2348 $$ = NULL_TREE;
2349 else if (current_aggr == signature_type_node
2350 && (! type) && (! IS_SIGNATURE (type)))
2351 {
2352 error ("class name not allowed as base signature");
2353 $$ = NULL_TREE;
2354 }
2355 else if (current_aggr == signature_type_node)
2356 {
2357 sorry ("signature inheritance, base type `%s' ignored",
2358 IDENTIFIER_POINTER ($$));
2359 $$ = build_tree_list ((tree)access_public, $$);
2360 }
2361 else if (type && IS_SIGNATURE (type))
2362 {
2363 error ("signature name not allowed as base class");
2364 $$ = NULL_TREE;
2365 }
2366 else
2367 $$ = build_tree_list ((tree)access_default, $$);
2368 }
2369 | base_class_access_list base_class.1
2370 {
2371 tree type;
2372 do_base_class2:
2373 type = IDENTIFIER_TYPE_VALUE ($2);
2374 if (current_aggr == signature_type_node)
2375 error ("access and source specifiers not allowed in signature");
2376 if (! is_aggr_typedef ($2, 1))
2377 $$ = NULL_TREE;
2378 else if (current_aggr == signature_type_node
2379 && (! type) && (! IS_SIGNATURE (type)))
2380 {
2381 error ("class name not allowed as base signature");
2382 $$ = NULL_TREE;
2383 }
2384 else if (current_aggr == signature_type_node)
2385 {
2386 sorry ("signature inheritance, base type `%s' ignored",
2387 IDENTIFIER_POINTER ($$));
2388 $$ = build_tree_list ((tree)access_public, $2);
2389 }
2390 else if (type && IS_SIGNATURE (type))
2391 {
2392 error ("signature name not allowed as base class");
2393 $$ = NULL_TREE;
2394 }
2395 else
2396 $$ = build_tree_list ((tree) $$, $2);
2397 }
2398 ;
2399
2400 base_class.1:
2401 complete_type_name
2402 | SIGOF '(' expr ')'
2403 {
2404 if (current_aggr == signature_type_node)
2405 {
2406 if (IS_AGGR_TYPE (TREE_TYPE ($3)))
2407 {
2408 sorry ("`sigof' as base signature specifier");
2409 /* need to return some dummy signature identifier */
2410 $$ = $3;
2411 }
2412 else
2413 {
2414 error ("`sigof' applied to non-aggregate expression");
2415 $$ = error_mark_node;
2416 }
2417 }
2418 else
2419 {
2420 error ("`sigof' in struct or class declaration");
2421 $$ = error_mark_node;
2422 }
2423 }
2424 | SIGOF '(' type_id ')'
2425 {
2426 if (current_aggr == signature_type_node)
2427 {
2428 if (IS_AGGR_TYPE (groktypename ($3)))
2429 {
2430 sorry ("`sigof' as base signature specifier");
2431 /* need to return some dummy signature identifier */
2432 $$ = $3;
2433 }
2434 else
2435 {
2436 error ("`sigof' applied to non-aggregate expression");
2437 $$ = error_mark_node;
2438 }
2439 }
2440 else
2441 {
2442 error ("`sigof' in struct or class declaration");
2443 $$ = error_mark_node;
2444 }
2445 }
2446 ;
2447
2448 base_class_access_list:
2449 VISSPEC
2450 | SCSPEC
2451 { if ($<ttype>$ != ridpointers[(int)RID_VIRTUAL])
2452 sorry ("non-virtual access");
2453 $$ = access_default_virtual; }
2454 | base_class_access_list VISSPEC
2455 { int err = 0;
2456 if ($2 == access_protected)
2457 {
2458 warning ("`protected' access not implemented");
2459 $2 = access_public;
2460 err++;
2461 }
2462 else if ($2 == access_public)
2463 {
2464 if ($1 == access_private)
2465 {
2466 mixed:
2467 error ("base class cannot be public and private");
2468 }
2469 else if ($1 == access_default_virtual)
2470 $$ = access_public_virtual;
2471 }
2472 else /* $2 == access_private */
2473 {
2474 if ($1 == access_public)
2475 goto mixed;
2476 else if ($1 == access_default_virtual)
2477 $$ = access_private_virtual;
2478 }
2479 }
2480 | base_class_access_list SCSPEC
2481 { if ($2 != ridpointers[(int)RID_VIRTUAL])
2482 sorry ("non-virtual access");
2483 if ($$ == access_public)
2484 $$ = access_public_virtual;
2485 else if ($$ == access_private)
2486 $$ = access_private_virtual; }
2487 ;
2488
2489 left_curly: '{'
2490 { tree t = $<ttype>0;
2491 push_obstacks_nochange ();
2492 end_temporary_allocation ();
2493
2494 if (! IS_AGGR_TYPE (t))
2495 {
2496 t = $<ttype>0 = make_lang_type (RECORD_TYPE);
2497 TYPE_NAME (t) = get_identifier ("erroneous type");
2498 }
2499 if (TYPE_SIZE (t))
2500 duplicate_tag_error (t);
2501 if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
2502 {
2503 t = make_lang_type (TREE_CODE (t));
2504 pushtag (TYPE_IDENTIFIER ($<ttype>0), t, 0);
2505 $<ttype>0 = t;
2506 }
2507 pushclass (t, 0);
2508 TYPE_BEING_DEFINED (t) = 1;
2509 /* Reset the interface data, at the earliest possible
2510 moment, as it might have been set via a class foo;
2511 before. */
2512 /* Don't change signatures. */
2513 if (! IS_SIGNATURE (t))
2514 {
2515 extern tree pending_vtables;
2516 int needs_writing;
2517 tree name = TYPE_IDENTIFIER (t);
2518
2519 if (! ANON_AGGRNAME_P (name))
2520 {
2521 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2522 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2523 (t, interface_unknown);
2524 }
2525
2526 /* Record how to set the access of this class's
2527 virtual functions. If write_virtuals == 2 or 3, then
2528 inline virtuals are ``extern inline''. */
2529 switch (write_virtuals)
2530 {
2531 case 0:
2532 case 1:
2533 needs_writing = 1;
2534 break;
2535 case 2:
2536 needs_writing = !! value_member (name, pending_vtables);
2537 break;
2538 case 3:
2539 needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t)
2540 && CLASSTYPE_INTERFACE_KNOWN (t);
2541 break;
2542 default:
2543 needs_writing = 0;
2544 }
2545 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
2546 }
2547 #if 0
2548 t = TYPE_IDENTIFIER ($<ttype>0);
2549 if (t && IDENTIFIER_TEMPLATE (t))
2550 overload_template_name (t, 1);
2551 #endif
2552 }
2553 ;
2554
2555 opt.component_decl_list:
2556 /* empty */
2557 { $$ = NULL_TREE; }
2558 | component_decl_list
2559 {
2560 if (current_aggr == signature_type_node)
2561 $$ = build_tree_list ((tree) access_public, $$);
2562 else
2563 $$ = build_tree_list ((tree) access_default, $$);
2564 }
2565 | opt.component_decl_list VISSPEC ':' component_decl_list
2566 {
2567 tree visspec = (tree) $2;
2568
2569 if (current_aggr == signature_type_node)
2570 {
2571 error ("access specifier not allowed in signature");
2572 visspec = (tree) access_public;
2573 }
2574 $$ = chainon ($$, build_tree_list (visspec, $4));
2575 }
2576 | opt.component_decl_list VISSPEC ':'
2577 {
2578 if (current_aggr == signature_type_node)
2579 error ("access specifier not allowed in signature");
2580 }
2581 ;
2582
2583 /* Note: we no longer warn about the semicolon after a component_decl_list.
2584 ARM $9.2 says that the semicolon is optional, and therefore allowed. */
2585 component_decl_list:
2586 component_decl
2587 { if ($$ == void_type_node) $$ = NULL_TREE;
2588 }
2589 | component_decl_list component_decl
2590 { /* In pushdecl, we created a reverse list of names
2591 in this binding level. Make sure that the chain
2592 of what we're trying to add isn't the item itself
2593 (which can happen with what pushdecl's doing). */
2594 if ($2 != NULL_TREE && $2 != void_type_node)
2595 {
2596 if (TREE_CHAIN ($2) != $$)
2597 $$ = chainon ($$, $2);
2598 else
2599 $$ = $2;
2600 }
2601 }
2602 | component_decl_list ';'
2603 ;
2604
2605 component_decl:
2606 component_decl_1 ';'
2607 | component_decl_1 '}'
2608 { error ("missing ';' before right brace");
2609 yyungetc ('}', 0); }
2610 /* C++: handle constructors, destructors and inline functions */
2611 /* note that INLINE is like a TYPESPEC */
2612 | fn.def2 ':' /* base_init compstmt */
2613 { $$ = finish_method ($$); }
2614 | fn.def2 '{' /* nodecls compstmt */
2615 { $$ = finish_method ($$); }
2616 ;
2617
2618 component_decl_1:
2619 /* Do not add a "typed_declspecs declarator" rule here for
2620 speed; we need to call grok_x_components for enums, so the
2621 speedup would be insignificant. */
2622 typed_declspecs components
2623 {
2624 $$ = grok_x_components ($$, $2);
2625 }
2626 | declmods notype_components
2627 {
2628 $$ = grok_x_components ($$, $2);
2629 }
2630 | notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2631 { $$ = grokfield ($$, NULL_TREE, $2, $5, $3);
2632 cplus_decl_attributes ($$, $4, prefix_attributes); }
2633 | ':' expr_no_commas
2634 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
2635 | error
2636 { $$ = NULL_TREE; }
2637
2638 /* These rules introduce a reduce/reduce conflict; in
2639 typedef int foo, bar;
2640 class A {
2641 foo (bar);
2642 };
2643 should "A::foo" be declared as a function or "A::bar" as a data
2644 member? In other words, is "bar" an after_type_declarator or a
2645 parmlist? */
2646 | typed_declspecs '(' parmlist ')' type_quals exception_specification_opt maybeasm maybe_attribute maybe_init
2647 { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
2648 $3, $5);
2649 $$ = grokfield ($$, TREE_CHAIN ($1), $6, $9, $7);
2650 cplus_decl_attributes ($$, $8, prefix_attributes); }
2651 | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt maybeasm maybe_attribute maybe_init
2652 { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
2653 empty_parms (), $3);
2654 $$ = grokfield ($$, TREE_CHAIN ($1), $4, $7, $5);
2655 cplus_decl_attributes ($$, $6, prefix_attributes); }
2656 | using_decl
2657 ;
2658
2659 /* The case of exactly one component is handled directly by component_decl. */
2660 components:
2661 /* empty: possibly anonymous */
2662 { $$ = NULL_TREE; }
2663 | component_declarator0
2664 | components ',' component_declarator
2665 {
2666 /* In this context, void_type_node encodes
2667 friends. They have been recorded elsewhere. */
2668 if ($$ == void_type_node)
2669 $$ = $3;
2670 else
2671 $$ = chainon ($$, $3);
2672 }
2673 ;
2674
2675 notype_components:
2676 /* empty: possibly anonymous */
2677 { $$ = NULL_TREE; }
2678 | notype_component_declarator0
2679 | notype_components ',' notype_component_declarator
2680 {
2681 /* In this context, void_type_node encodes
2682 friends. They have been recorded elsewhere. */
2683 if ($$ == void_type_node)
2684 $$ = $3;
2685 else
2686 $$ = chainon ($$, $3);
2687 }
2688 ;
2689
2690 component_declarator0:
2691 after_type_component_declarator0
2692 | notype_component_declarator0
2693 ;
2694
2695 component_declarator:
2696 after_type_component_declarator
2697 | notype_component_declarator
2698 ;
2699
2700 after_type_component_declarator0:
2701 after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2702 { current_declspecs = $<ttype>0;
2703 $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2704 cplus_decl_attributes ($$, $4, prefix_attributes); }
2705 | TYPENAME ':' expr_no_commas maybe_attribute
2706 { current_declspecs = $<ttype>0;
2707 $$ = grokbitfield ($$, current_declspecs, $3);
2708 cplus_decl_attributes ($$, $4, prefix_attributes); }
2709 ;
2710
2711 notype_component_declarator0:
2712 notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2713 { current_declspecs = $<ttype>0;
2714 $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2715 cplus_decl_attributes ($$, $4, prefix_attributes); }
2716 | IDENTIFIER ':' expr_no_commas maybe_attribute
2717 { current_declspecs = $<ttype>0;
2718 $$ = grokbitfield ($$, current_declspecs, $3);
2719 cplus_decl_attributes ($$, $4, prefix_attributes); }
2720 | ':' expr_no_commas maybe_attribute
2721 { current_declspecs = $<ttype>0;
2722 $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2723 cplus_decl_attributes ($$, $3, prefix_attributes); }
2724 ;
2725
2726 after_type_component_declarator:
2727 after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2728 { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2729 cplus_decl_attributes ($$, $4, prefix_attributes); }
2730 | TYPENAME ':' expr_no_commas maybe_attribute
2731 { $$ = grokbitfield ($$, current_declspecs, $3);
2732 cplus_decl_attributes ($$, $4, prefix_attributes); }
2733 ;
2734
2735 notype_component_declarator:
2736 notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
2737 { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
2738 cplus_decl_attributes ($$, $4, prefix_attributes); }
2739 | IDENTIFIER ':' expr_no_commas maybe_attribute
2740 { $$ = grokbitfield ($$, current_declspecs, $3);
2741 cplus_decl_attributes ($$, $4, prefix_attributes); }
2742 | ':' expr_no_commas maybe_attribute
2743 { $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
2744 cplus_decl_attributes ($$, $3, prefix_attributes); }
2745 ;
2746
2747 /* We chain the enumerators in reverse order.
2748 Because of the way enums are built, the order is
2749 insignificant. Take advantage of this fact. */
2750
2751 enumlist:
2752 enumerator
2753 | enumlist ',' enumerator
2754 { TREE_CHAIN ($3) = $$; $$ = $3; }
2755 ;
2756
2757 enumerator:
2758 identifier
2759 { $$ = build_enumerator ($$, NULL_TREE); }
2760 | identifier '=' expr_no_commas
2761 { $$ = build_enumerator ($$, $3); }
2762 ;
2763
2764 /* ANSI new-type-id (5.3.4) */
2765 new_type_id:
2766 type_specifier_seq new_declarator
2767 { $$ = build_decl_list ($$, $2); }
2768 | type_specifier_seq %prec EMPTY
2769 { $$ = build_decl_list ($$, NULL_TREE); }
2770 /* GNU extension to allow arrays of arbitrary types with
2771 non-constant dimension. */
2772 | '(' type_id ')' '[' expr ']'
2773 {
2774 if (pedantic)
2775 pedwarn ("ANSI C++ forbids array dimensions with parenthesized type in new");
2776 $$ = build_parse_node (ARRAY_REF, TREE_VALUE ($2), $5);
2777 $$ = build_decl_list (TREE_PURPOSE ($2), $$);
2778 }
2779 ;
2780
2781 type_quals:
2782 /* empty */ %prec EMPTY
2783 { $$ = NULL_TREE; }
2784 | type_quals TYPE_QUAL
2785 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
2786 ;
2787
2788 nonempty_type_quals:
2789 TYPE_QUAL
2790 { $$ = IDENTIFIER_AS_LIST ($$); }
2791 | nonempty_type_quals TYPE_QUAL
2792 { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
2793 ;
2794
2795 /* These rules must follow the rules for function declarations
2796 and component declarations. That way, longer rules are preferred. */
2797
2798 /* An expression which will not live on the momentary obstack. */
2799 nonmomentary_expr:
2800 { $<itype>$ = suspend_momentary (); } expr
2801 { resume_momentary ((int) $<itype>1); $$ = $2; }
2802 ;
2803
2804 /* A declarator that is allowed only after an explicit typespec. */
2805 /* may all be followed by prec '.' */
2806 after_type_declarator:
2807 '*' nonempty_type_quals after_type_declarator %prec UNARY
2808 { $$ = make_pointer_declarator ($2, $3); }
2809 | '&' nonempty_type_quals after_type_declarator %prec UNARY
2810 { $$ = make_reference_declarator ($2, $3); }
2811 | '*' after_type_declarator %prec UNARY
2812 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2813 | '&' after_type_declarator %prec UNARY
2814 { $$ = make_reference_declarator (NULL_TREE, $2); }
2815 | ptr_to_mem type_quals after_type_declarator
2816 { tree arg = make_pointer_declarator ($2, $3);
2817 $$ = build_parse_node (SCOPE_REF, $1, arg);
2818 }
2819 | direct_after_type_declarator
2820 ;
2821
2822 qualified_type_name:
2823 type_name %prec EMPTY
2824 {
2825 /* Remember that this name has been used in the class
2826 definition, as per [class.scope0] */
2827 if (current_class_type
2828 && TYPE_BEING_DEFINED (current_class_type)
2829 && ! IDENTIFIER_CLASS_VALUE ($$))
2830 {
2831 tree t = lookup_name ($$, -2);
2832 if (t)
2833 pushdecl_class_level (t);
2834 }
2835 }
2836 | nested_type
2837 ;
2838
2839 nested_type:
2840 nested_name_specifier type_name %prec EMPTY
2841 { $$ = $2; }
2842 ;
2843
2844 direct_after_type_declarator:
2845 direct_after_type_declarator '(' nonnull_exprlist ')' type_quals %prec '.'
2846 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2847 | direct_after_type_declarator '(' parmlist ')' type_quals %prec '.'
2848 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2849 | direct_after_type_declarator LEFT_RIGHT type_quals %prec '.'
2850 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
2851 | direct_after_type_declarator '(' error ')' type_quals %prec '.'
2852 { $$ = build_parse_node (CALL_EXPR, $$, NULL_TREE, NULL_TREE); }
2853 | direct_after_type_declarator '[' nonmomentary_expr ']'
2854 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2855 | direct_after_type_declarator '[' ']'
2856 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2857 | '(' after_type_declarator ')'
2858 { $$ = $2; }
2859 | nested_name_specifier type_name %prec EMPTY
2860 { push_nested_class (TREE_TYPE ($$), 3);
2861 $$ = build_parse_node (SCOPE_REF, $$, $2);
2862 TREE_COMPLEXITY ($$) = current_class_depth; }
2863 | type_name %prec EMPTY
2864 ;
2865
2866 /* A declarator allowed whether or not there has been
2867 an explicit typespec. These cannot redeclare a typedef-name. */
2868
2869 notype_declarator:
2870 '*' nonempty_type_quals notype_declarator %prec UNARY
2871 { $$ = make_pointer_declarator ($2, $3); }
2872 | '&' nonempty_type_quals notype_declarator %prec UNARY
2873 { $$ = make_reference_declarator ($2, $3); }
2874 | '*' notype_declarator %prec UNARY
2875 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2876 | '&' notype_declarator %prec UNARY
2877 { $$ = make_reference_declarator (NULL_TREE, $2); }
2878 | ptr_to_mem type_quals notype_declarator
2879 { tree arg = make_pointer_declarator ($2, $3);
2880 $$ = build_parse_node (SCOPE_REF, $1, arg);
2881 }
2882 | direct_notype_declarator
2883 ;
2884
2885 complex_notype_declarator:
2886 '*' nonempty_type_quals notype_declarator %prec UNARY
2887 { $$ = make_pointer_declarator ($2, $3); }
2888 | '&' nonempty_type_quals notype_declarator %prec UNARY
2889 { $$ = make_reference_declarator ($2, $3); }
2890 | '*' complex_notype_declarator %prec UNARY
2891 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2892 | '&' complex_notype_declarator %prec UNARY
2893 { $$ = make_reference_declarator (NULL_TREE, $2); }
2894 | ptr_to_mem type_quals notype_declarator
2895 { tree arg = make_pointer_declarator ($2, $3);
2896 $$ = build_parse_node (SCOPE_REF, $1, arg);
2897 }
2898 | complex_direct_notype_declarator
2899 ;
2900
2901 complex_direct_notype_declarator:
2902 direct_notype_declarator '(' nonnull_exprlist ')' type_quals %prec '.'
2903 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2904 | direct_notype_declarator '(' parmlist ')' type_quals %prec '.'
2905 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
2906 | direct_notype_declarator LEFT_RIGHT type_quals %prec '.'
2907 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
2908 | direct_notype_declarator '(' error ')' type_quals %prec '.'
2909 { $$ = build_parse_node (CALL_EXPR, $$, NULL_TREE, NULL_TREE); }
2910 | '(' complex_notype_declarator ')'
2911 { $$ = $2; }
2912 | direct_notype_declarator '[' nonmomentary_expr ']'
2913 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
2914 | direct_notype_declarator '[' ']'
2915 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
2916 | notype_qualified_id
2917 { push_nested_class (TREE_TYPE (OP0 ($$)), 3);
2918 TREE_COMPLEXITY ($$) = current_class_depth; }
2919 ;
2920
2921 qualified_id:
2922 nested_name_specifier unqualified_id
2923 { got_scope = NULL_TREE;
2924 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2925 ;
2926
2927 notype_qualified_id:
2928 nested_name_specifier notype_unqualified_id
2929 { got_scope = NULL_TREE;
2930 $$ = build_parse_node (SCOPE_REF, $$, $2); }
2931 ;
2932
2933 overqualified_id:
2934 notype_qualified_id
2935 | global_scope notype_qualified_id
2936 { $$ = $2; }
2937 ;
2938
2939 functional_cast:
2940 typespec '(' nonnull_exprlist ')'
2941 { $$ = build_functional_cast ($$, $3); }
2942 | typespec '(' expr_or_declarator ')'
2943 { $$ = reparse_decl_as_expr ($$, $3); }
2944 | typespec fcast_or_absdcl %prec EMPTY
2945 { $$ = reparse_absdcl_as_expr ($$, $2); }
2946 ;
2947
2948 type_name:
2949 TYPENAME
2950 | template_type %prec EMPTY
2951 ;
2952
2953 nested_name_specifier:
2954 nested_name_specifier_1
2955 | nested_name_specifier nested_name_specifier_1
2956 { $$ = $2; }
2957 ;
2958
2959 /* Why the @#$%^& do type_name and notype_identifier need to be expanded
2960 inline here?!? (jason) */
2961 nested_name_specifier_1:
2962 TYPENAME SCOPE
2963 { got_scope = TREE_TYPE ($$); }
2964 | NSNAME SCOPE
2965 { got_scope = TREE_TYPE ($$); }
2966 | template_type SCOPE
2967 { got_scope = TREE_TYPE ($$); }
2968 /* These break 'const i;'
2969 | IDENTIFIER SCOPE
2970 {
2971 failed_scope:
2972 cp_error ("`%D' is not an aggregate typedef",
2973 lastiddecl ? lastiddecl : $$);
2974 $$ = error_mark_node;
2975 }
2976 | PTYPENAME SCOPE
2977 { goto failed_scope; } */
2978 ;
2979
2980 complete_type_name:
2981 qualified_type_name
2982 | global_scope qualified_type_name
2983 { $$ = $2; }
2984 ;
2985
2986 complex_type_name:
2987 nested_type
2988 | global_scope qualified_type_name
2989 { $$ = $2; }
2990 ;
2991
2992 ptr_to_mem:
2993 nested_name_specifier '*'
2994 { got_scope = NULL_TREE; }
2995 | global_scope nested_name_specifier '*'
2996 { $$ = $2; got_scope = NULL_TREE; }
2997 ;
2998
2999 /* All uses of explicit global scope must go through this nonterminal so
3000 that got_scope will be set before yylex is called to get the next token. */
3001 global_scope:
3002 SCOPE
3003 { got_scope = void_type_node; }
3004 ;
3005
3006 /* ANSI new-declarator (5.3.4) */
3007 new_declarator:
3008 '*' type_quals new_declarator
3009 { $$ = make_pointer_declarator ($2, $3); }
3010 | '*' type_quals %prec EMPTY
3011 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3012 | '&' type_quals new_declarator %prec EMPTY
3013 { $$ = make_reference_declarator ($2, $3); }
3014 | '&' type_quals %prec EMPTY
3015 { $$ = make_reference_declarator ($2, NULL_TREE); }
3016 | ptr_to_mem type_quals %prec EMPTY
3017 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3018 $$ = build_parse_node (SCOPE_REF, $1, arg);
3019 }
3020 | ptr_to_mem type_quals new_declarator
3021 { tree arg = make_pointer_declarator ($2, $3);
3022 $$ = build_parse_node (SCOPE_REF, $1, arg);
3023 }
3024 | direct_new_declarator %prec EMPTY
3025 ;
3026
3027 /* ANSI direct-new-declarator (5.3.4) */
3028 direct_new_declarator:
3029 '[' expr ']'
3030 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3031 | direct_new_declarator '[' nonmomentary_expr ']'
3032 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3033 ;
3034
3035 /* ANSI abstract-declarator (8.1) */
3036 absdcl:
3037 '*' nonempty_type_quals absdcl
3038 { $$ = make_pointer_declarator ($2, $3); }
3039 | '*' absdcl
3040 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3041 | '*' nonempty_type_quals %prec EMPTY
3042 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3043 | '*' %prec EMPTY
3044 { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
3045 | '&' nonempty_type_quals absdcl
3046 { $$ = make_reference_declarator ($2, $3); }
3047 | '&' absdcl
3048 { $$ = make_reference_declarator (NULL_TREE, $2); }
3049 | '&' nonempty_type_quals %prec EMPTY
3050 { $$ = make_reference_declarator ($2, NULL_TREE); }
3051 | '&' %prec EMPTY
3052 { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
3053 | ptr_to_mem type_quals %prec EMPTY
3054 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3055 $$ = build_parse_node (SCOPE_REF, $1, arg);
3056 }
3057 | ptr_to_mem type_quals absdcl
3058 { tree arg = make_pointer_declarator ($2, $3);
3059 $$ = build_parse_node (SCOPE_REF, $1, arg);
3060 }
3061 | direct_abstract_declarator %prec EMPTY
3062 ;
3063
3064 /* ANSI direct-abstract-declarator (8.1) */
3065 direct_abstract_declarator:
3066 '(' absdcl ')'
3067 { $$ = $2; }
3068 /* `(typedef)1' is `int'. */
3069 | PAREN_STAR_PAREN
3070 | direct_abstract_declarator '(' parmlist ')' type_quals %prec '.'
3071 { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
3072 | direct_abstract_declarator LEFT_RIGHT type_quals %prec '.'
3073 { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
3074 | direct_abstract_declarator '[' nonmomentary_expr ']' %prec '.'
3075 { $$ = build_parse_node (ARRAY_REF, $$, $3); }
3076 | direct_abstract_declarator '[' ']' %prec '.'
3077 { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
3078 | '(' complex_parmlist ')' type_quals %prec '.'
3079 { $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2, $4); }
3080 | regcast_or_absdcl type_quals %prec '.'
3081 { TREE_OPERAND ($$, 2) = $2; }
3082 | fcast_or_absdcl type_quals %prec '.'
3083 { TREE_OPERAND ($$, 2) = $2; }
3084 | '[' nonmomentary_expr ']' %prec '.'
3085 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
3086 | '[' ']' %prec '.'
3087 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
3088 ;
3089
3090 /* For C++, decls and stmts can be intermixed, so we don't need to
3091 have a special rule that won't start parsing the stmt section
3092 until we have a stmt that parses without errors. */
3093
3094 stmts:
3095 stmt
3096 | errstmt
3097 | stmts stmt
3098 | stmts errstmt
3099 ;
3100
3101 errstmt: error ';'
3102 ;
3103
3104 /* build the LET_STMT node before parsing its contents,
3105 so that any LET_STMTs within the context can have their display pointers
3106 set up to point at this one. */
3107
3108 .pushlevel: /* empty */
3109 { emit_line_note (input_filename, lineno);
3110 pushlevel (0);
3111 clear_last_expr ();
3112 push_momentary ();
3113 expand_start_bindings (0); }
3114 ;
3115
3116 /* Read zero or more forward-declarations for labels
3117 that nested functions can jump to. */
3118 maybe_label_decls:
3119 /* empty */
3120 | label_decls
3121 { if (pedantic)
3122 pedwarn ("ANSI C++ forbids label declarations"); }
3123 ;
3124
3125 label_decls:
3126 label_decl
3127 | label_decls label_decl
3128 ;
3129
3130 label_decl:
3131 LABEL identifiers_or_typenames ';'
3132 { tree link;
3133 for (link = $2; link; link = TREE_CHAIN (link))
3134 {
3135 tree label = shadow_label (TREE_VALUE (link));
3136 C_DECLARED_LABEL_FLAG (label) = 1;
3137 declare_nonlocal_label (label);
3138 }
3139 }
3140 ;
3141
3142 /* This is the body of a function definition.
3143 It causes syntax errors to ignore to the next openbrace. */
3144 compstmt_or_error:
3145 compstmt
3146 {}
3147 | error compstmt
3148 ;
3149
3150 compstmt: '{' .pushlevel '}'
3151 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3152 $$ = poplevel (kept_level_p (), 1, 0);
3153 pop_momentary (); }
3154 | '{' .pushlevel maybe_label_decls stmts '}'
3155 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3156 $$ = poplevel (kept_level_p (), 1, 0);
3157 pop_momentary (); }
3158 | '{' .pushlevel maybe_label_decls stmts error '}'
3159 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3160 $$ = poplevel (kept_level_p (), 0, 0);
3161 pop_momentary (); }
3162 | '{' .pushlevel maybe_label_decls error '}'
3163 { expand_end_bindings (getdecls (), kept_level_p(), 1);
3164 $$ = poplevel (kept_level_p (), 0, 0);
3165 pop_momentary (); }
3166 ;
3167
3168 simple_if:
3169 IF
3170 { cond_stmt_keyword = "if"; }
3171 .pushlevel paren_cond_or_null
3172 { emit_line_note (input_filename, lineno);
3173 expand_start_cond ($4, 0); }
3174 implicitly_scoped_stmt
3175 ;
3176
3177 implicitly_scoped_stmt:
3178 compstmt
3179 { finish_stmt (); }
3180 | .pushlevel simple_stmt
3181 { expand_end_bindings (getdecls (), kept_level_p (), 1);
3182 $$ = poplevel (kept_level_p (), 1, 0);
3183 pop_momentary (); }
3184 ;
3185
3186 stmt:
3187 compstmt
3188 { finish_stmt (); }
3189 | simple_stmt
3190 ;
3191
3192 simple_stmt:
3193 decl
3194 { finish_stmt (); }
3195 | expr ';'
3196 {
3197 tree expr = $1;
3198 emit_line_note (input_filename, lineno);
3199 /* Do default conversion if safe and possibly important,
3200 in case within ({...}). */
3201 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
3202 && lvalue_p (expr))
3203 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
3204 expr = default_conversion (expr);
3205 cplus_expand_expr_stmt (expr);
3206 clear_momentary ();
3207 finish_stmt (); }
3208 | simple_if ELSE
3209 { expand_start_else (); }
3210 implicitly_scoped_stmt
3211 { expand_end_cond ();
3212 expand_end_bindings (getdecls (), kept_level_p (), 1);
3213 poplevel (kept_level_p (), 1, 0);
3214 pop_momentary ();
3215 finish_stmt (); }
3216 | simple_if %prec IF
3217 { expand_end_cond ();
3218 expand_end_bindings (getdecls (), kept_level_p (), 1);
3219 poplevel (kept_level_p (), 1, 0);
3220 pop_momentary ();
3221 finish_stmt (); }
3222 | WHILE
3223 { emit_nop ();
3224 emit_line_note (input_filename, lineno);
3225 expand_start_loop (1);
3226 cond_stmt_keyword = "while"; }
3227 .pushlevel paren_cond_or_null
3228 { expand_exit_loop_if_false (0, $4); }
3229 already_scoped_stmt
3230 { expand_end_bindings (getdecls (), kept_level_p (), 1);
3231 poplevel (kept_level_p (), 1, 0);
3232 pop_momentary ();
3233 expand_end_loop ();
3234 finish_stmt (); }
3235 | DO
3236 { emit_nop ();
3237 emit_line_note (input_filename, lineno);
3238 expand_start_loop_continue_elsewhere (1); }
3239 implicitly_scoped_stmt WHILE
3240 { expand_loop_continue_here ();
3241 cond_stmt_keyword = "do"; }
3242 paren_expr_or_null ';'
3243 { emit_line_note (input_filename, lineno);
3244 expand_exit_loop_if_false (0, $6);
3245 expand_end_loop ();
3246 clear_momentary ();
3247 finish_stmt (); }
3248 | forhead.1
3249 { emit_nop ();
3250 emit_line_note (input_filename, lineno);
3251 if ($1) cplus_expand_expr_stmt ($1);
3252 expand_start_loop_continue_elsewhere (1); }
3253 .pushlevel xcond ';'
3254 { emit_line_note (input_filename, lineno);
3255 if ($4) expand_exit_loop_if_false (0, $4); }
3256 xexpr ')'
3257 /* Don't let the tree nodes for $7 be discarded
3258 by clear_momentary during the parsing of the next stmt. */
3259 { push_momentary (); }
3260 already_scoped_stmt
3261 { emit_line_note (input_filename, lineno);
3262 expand_end_bindings (getdecls (), kept_level_p (), 1);
3263 poplevel (kept_level_p (), 1, 0);
3264 pop_momentary ();
3265 expand_loop_continue_here ();
3266 if ($7) cplus_expand_expr_stmt ($7);
3267 pop_momentary ();
3268 expand_end_loop ();
3269 finish_stmt (); }
3270 | forhead.2
3271 { emit_nop ();
3272 emit_line_note (input_filename, lineno);
3273 expand_start_loop_continue_elsewhere (1); }
3274 .pushlevel xcond ';'
3275 { emit_line_note (input_filename, lineno);
3276 if ($4) expand_exit_loop_if_false (0, $4); }
3277 xexpr ')'
3278 /* Don't let the tree nodes for $7 be discarded
3279 by clear_momentary during the parsing of the next stmt. */
3280 { push_momentary ();
3281 $<itype>8 = lineno; }
3282 already_scoped_stmt
3283 { emit_line_note (input_filename, (int) $<itype>8);
3284 expand_end_bindings (getdecls (), kept_level_p (), 1);
3285 poplevel (kept_level_p (), 1, 0);
3286 pop_momentary ();
3287 expand_loop_continue_here ();
3288 if ($7) cplus_expand_expr_stmt ($7);
3289 pop_momentary ();
3290 expand_end_loop ();
3291 finish_stmt ();
3292 }
3293 | SWITCH .pushlevel '(' condition ')'
3294 { emit_line_note (input_filename, lineno);
3295 c_expand_start_case ($4);
3296 /* Don't let the tree nodes for $4 be discarded by
3297 clear_momentary during the parsing of the next stmt. */
3298 push_momentary (); }
3299 implicitly_scoped_stmt
3300 { expand_end_case ($4);
3301 pop_momentary ();
3302 expand_end_bindings (getdecls (), kept_level_p (), 1);
3303 poplevel (kept_level_p (), 1, 0);
3304 pop_momentary ();
3305 finish_stmt (); }
3306 | CASE expr_no_commas ':'
3307 { register tree value = check_cp_case_value ($2);
3308 register tree label
3309 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3310
3311 if (value != error_mark_node)
3312 {
3313 tree duplicate;
3314 int success = pushcase (value, convert_and_check,
3315 label, &duplicate);
3316 if (success == 1)
3317 cp_error ("case label `%E' not within a switch statement", $2);
3318 else if (success == 2)
3319 {
3320 cp_error ("duplicate case value `%E'", $2);
3321 cp_error_at ("previously used here", duplicate);
3322 }
3323 else if (success == 3)
3324 warning ("case value out of range");
3325 else if (success == 5)
3326 cp_error ("case label `%E' within scope of cleanup or variable array", $2);
3327 }
3328 define_case_label (label);
3329 }
3330 stmt
3331 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
3332 { register tree value1 = check_cp_case_value ($2);
3333 register tree value2 = check_cp_case_value ($4);
3334 register tree label
3335 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3336
3337 if (pedantic)
3338 pedwarn ("ANSI C++ forbids range expressions in switch statement");
3339 if (value1 != error_mark_node
3340 && value2 != error_mark_node)
3341 {
3342 tree duplicate;
3343 int success = pushcase_range (value1, value2,
3344 convert_and_check, label,
3345 &duplicate);
3346 if (success == 1)
3347 error ("case label not within a switch statement");
3348 else if (success == 2)
3349 {
3350 error ("duplicate (or overlapping) case value");
3351 error_with_decl (duplicate, "this is the first entry overlapping that value");
3352 }
3353 else if (success == 3)
3354 warning ("case value out of range");
3355 else if (success == 4)
3356 warning ("empty range specified");
3357 else if (success == 5)
3358 error ("case label within scope of cleanup or variable array");
3359 }
3360 define_case_label (label);
3361 }
3362 stmt
3363 | DEFAULT ':'
3364 {
3365 tree duplicate;
3366 register tree label
3367 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3368 int success = pushcase (NULL_TREE, 0, label, &duplicate);
3369 if (success == 1)
3370 error ("default label not within a switch statement");
3371 else if (success == 2)
3372 {
3373 error ("multiple default labels in one switch");
3374 error_with_decl (duplicate, "this is the first default label");
3375 }
3376 define_case_label (NULL_TREE);
3377 }
3378 stmt
3379 | BREAK ';'
3380 { emit_line_note (input_filename, lineno);
3381 if ( ! expand_exit_something ())
3382 error ("break statement not within loop or switch"); }
3383 | CONTINUE ';'
3384 { emit_line_note (input_filename, lineno);
3385 if (! expand_continue_loop (0))
3386 error ("continue statement not within a loop"); }
3387 | RETURN ';'
3388 { emit_line_note (input_filename, lineno);
3389 c_expand_return (NULL_TREE); }
3390 | RETURN expr ';'
3391 { emit_line_note (input_filename, lineno);
3392 c_expand_return ($2);
3393 finish_stmt ();
3394 }
3395 | asm_keyword maybe_type_qual '(' string ')' ';'
3396 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3397 emit_line_note (input_filename, lineno);
3398 expand_asm ($4);
3399 finish_stmt ();
3400 }
3401 /* This is the case with just output operands. */
3402 | asm_keyword maybe_type_qual '(' string ':' asm_operands ')' ';'
3403 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3404 emit_line_note (input_filename, lineno);
3405 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
3406 $2 == ridpointers[(int)RID_VOLATILE],
3407 input_filename, lineno);
3408 finish_stmt ();
3409 }
3410 /* This is the case with input operands as well. */
3411 | asm_keyword maybe_type_qual '(' string ':' asm_operands ':' asm_operands ')' ';'
3412 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3413 emit_line_note (input_filename, lineno);
3414 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
3415 $2 == ridpointers[(int)RID_VOLATILE],
3416 input_filename, lineno);
3417 finish_stmt ();
3418 }
3419 /* This is the case with clobbered registers as well. */
3420 | asm_keyword maybe_type_qual '(' string ':' asm_operands ':'
3421 asm_operands ':' asm_clobbers ')' ';'
3422 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
3423 emit_line_note (input_filename, lineno);
3424 c_expand_asm_operands ($4, $6, $8, $10,
3425 $2 == ridpointers[(int)RID_VOLATILE],
3426 input_filename, lineno);
3427 finish_stmt ();
3428 }
3429 | GOTO '*' expr ';'
3430 { emit_line_note (input_filename, lineno);
3431 expand_computed_goto ($3); }
3432 | GOTO identifier ';'
3433 { tree decl;
3434 emit_line_note (input_filename, lineno);
3435 decl = lookup_label ($2);
3436 TREE_USED (decl) = 1;
3437 expand_goto (decl); }
3438 | label_colon stmt
3439 { finish_stmt (); }
3440 | label_colon '}'
3441 { error ("label must be followed by statement");
3442 yyungetc ('}', 0);
3443 finish_stmt (); }
3444 | ';'
3445 { finish_stmt (); }
3446 | try_block
3447 ;
3448
3449 try_block:
3450 TRY '{' .pushlevel
3451 { expand_start_try_stmts (); }
3452 ansi_try_stmts
3453 { expand_end_try_stmts ();
3454 expand_start_all_catch (); }
3455 handler_seq
3456 { expand_end_all_catch (); }
3457 ;
3458
3459 ansi_try_stmts:
3460 '}'
3461 /* An empty try block is degenerate, but it's better to
3462 do extra work here than to do all the special-case work
3463 everywhere else. */
3464 { expand_end_bindings (0,1,1);
3465 poplevel (2,0,0);
3466 }
3467 | stmts '}'
3468 { expand_end_bindings (0,1,1);
3469 poplevel (2,0,0);
3470 }
3471 | error '}'
3472 { expand_end_bindings (0,1,1);
3473 poplevel (2,0,0);
3474 }
3475 ;
3476
3477 handler_seq:
3478 /* empty */
3479 | handler_seq CATCH
3480 { emit_line_note (input_filename, lineno); }
3481 .pushlevel handler_args compstmt
3482 { expand_end_catch_block ();
3483 expand_end_bindings (getdecls (), kept_level_p (), 1);
3484 poplevel (kept_level_p (), 1, 0);
3485 pop_momentary ();
3486 }
3487 ;
3488
3489 type_specifier_seq:
3490 typed_typespecs %prec EMPTY
3491 | nonempty_type_quals %prec EMPTY
3492 ;
3493
3494 handler_args:
3495 '(' ELLIPSIS ')'
3496 { expand_start_catch_block (NULL_TREE, NULL_TREE); }
3497 /* This doesn't allow reference parameters, the below does.
3498 | '(' type_specifier_seq absdcl ')'
3499 { expand_start_catch_block ($2, $3); }
3500 | '(' type_specifier_seq ')'
3501 { expand_start_catch_block ($2, NULL_TREE); }
3502 | '(' type_specifier_seq notype_declarator ')'
3503 { expand_start_catch_block ($2, $3); }
3504 | '(' typed_typespecs after_type_declarator ')'
3505 { expand_start_catch_block ($2, $3); }
3506 This allows reference parameters... */
3507 | '(' parm ')'
3508 { expand_start_catch_block (TREE_PURPOSE ($2),
3509 TREE_VALUE ($2)); }
3510 ;
3511
3512 label_colon:
3513 IDENTIFIER ':'
3514 { tree label;
3515 do_label:
3516 label = define_label (input_filename, lineno, $1);
3517 if (label)
3518 expand_label (label);
3519 }
3520 | PTYPENAME ':'
3521 { goto do_label; }
3522 | TYPENAME ':'
3523 { goto do_label; }
3524 ;
3525
3526 forhead.1:
3527 FOR '(' ';'
3528 { $$ = NULL_TREE; }
3529 | FOR '(' expr ';'
3530 { $$ = $3; }
3531 | FOR '(' '{' '}'
3532 { $$ = NULL_TREE; }
3533 ;
3534
3535 forhead.2:
3536 FOR '(' decl
3537 { $$ = 0; }
3538 | FOR '(' error ';'
3539 { $$ = 0; }
3540 | FOR '(' '{' .pushlevel stmts '}'
3541 { $$ = 1; }
3542 | FOR '(' '{' .pushlevel error '}'
3543 { $$ = -1; }
3544 ;
3545
3546 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
3547
3548 maybe_type_qual:
3549 /* empty */
3550 { emit_line_note (input_filename, lineno);
3551 $$ = NULL_TREE; }
3552 | TYPE_QUAL
3553 { emit_line_note (input_filename, lineno); }
3554 ;
3555
3556 xexpr:
3557 /* empty */
3558 { $$ = NULL_TREE; }
3559 | expr
3560 | error
3561 { $$ = NULL_TREE; }
3562 ;
3563
3564 /* These are the operands other than the first string and colon
3565 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
3566 asm_operands: /* empty */
3567 { $$ = NULL_TREE; }
3568 | nonnull_asm_operands
3569 ;
3570
3571 nonnull_asm_operands:
3572 asm_operand
3573 | nonnull_asm_operands ',' asm_operand
3574 { $$ = chainon ($$, $3); }
3575 ;
3576
3577 asm_operand:
3578 STRING '(' expr ')'
3579 { $$ = build_tree_list ($$, $3); }
3580 ;
3581
3582 asm_clobbers:
3583 STRING
3584 { $$ = tree_cons (NULL_TREE, $$, NULL_TREE); }
3585 | asm_clobbers ',' STRING
3586 { $$ = tree_cons (NULL_TREE, $3, $$); }
3587 ;
3588
3589 /* This is what appears inside the parens in a function declarator.
3590 Its value is represented in the format that grokdeclarator expects.
3591
3592 In C++, declaring a function with no parameters
3593 means that that function takes *no* parameters. */
3594
3595 parmlist: /* empty */
3596 {
3597 if (strict_prototype)
3598 $$ = void_list_node;
3599 else
3600 $$ = NULL_TREE;
3601 }
3602 | complex_parmlist
3603 | type_id
3604 { $$ = tree_cons (NULL_TREE, $$, void_list_node);
3605 TREE_PARMLIST ($$) = 1; }
3606 ;
3607
3608 /* This nonterminal does not include the common sequence '(' type_id ')',
3609 as it is ambiguous and must be disambiguated elsewhere. */
3610 complex_parmlist:
3611 parms
3612 {
3613 $$ = chainon ($$, void_list_node);
3614 TREE_PARMLIST ($$) = 1;
3615 }
3616 | parms_comma ELLIPSIS
3617 {
3618 TREE_PARMLIST ($$) = 1;
3619 }
3620 /* C++ allows an ellipsis without a separating ',' */
3621 | parms ELLIPSIS
3622 {
3623 TREE_PARMLIST ($$) = 1;
3624 }
3625 | type_id ELLIPSIS
3626 {
3627 $$ = build_tree_list (NULL_TREE, $$);
3628 TREE_PARMLIST ($$) = 1;
3629 }
3630 | ELLIPSIS
3631 {
3632 /* ARM $8.2.5 has this as a boxed-off comment. */
3633 if (pedantic)
3634 warning ("use of `...' without a first argument is non-portable");
3635 $$ = NULL_TREE;
3636 }
3637 | TYPENAME_ELLIPSIS
3638 {
3639 TREE_PARMLIST ($$) = 1;
3640 }
3641 | parms TYPENAME_ELLIPSIS
3642 {
3643 TREE_PARMLIST ($$) = 1;
3644 }
3645 | type_id TYPENAME_ELLIPSIS
3646 {
3647 $$ = build_tree_list (NULL_TREE, $$);
3648 TREE_PARMLIST ($$) = 1;
3649 }
3650 | parms ':'
3651 {
3652 /* This helps us recover from really nasty
3653 parse errors, for example, a missing right
3654 parenthesis. */
3655 yyerror ("possibly missing ')'");
3656 $$ = chainon ($$, void_list_node);
3657 TREE_PARMLIST ($$) = 1;
3658 yyungetc (':', 0);
3659 yychar = ')';
3660 }
3661 | type_id ':'
3662 {
3663 /* This helps us recover from really nasty
3664 parse errors, for example, a missing right
3665 parenthesis. */
3666 yyerror ("possibly missing ')'");
3667 $$ = tree_cons (NULL_TREE, $$, void_list_node);
3668 TREE_PARMLIST ($$) = 1;
3669 yyungetc (':', 0);
3670 yychar = ')';
3671 }
3672 ;
3673
3674 /* A nonempty list of parameter declarations or type names. */
3675 parms:
3676 named_parm
3677 { $$ = build_tree_list (NULL_TREE, $$); }
3678 | parm '=' init
3679 { $$ = build_tree_list ($3, $$); }
3680 | parms_comma full_parm
3681 { $$ = chainon ($$, $2); }
3682 | parms_comma bad_parm
3683 { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
3684 | parms_comma bad_parm '=' init
3685 { $$ = chainon ($$, build_tree_list ($4, $2)); }
3686 ;
3687
3688 parms_comma:
3689 parms ','
3690 | type_id ','
3691 { $$ = build_tree_list (NULL_TREE, $$); }
3692 ;
3693
3694 /* A single parameter declaration or parameter type name,
3695 as found in a parmlist. The first four cases make up for 10%
3696 of the time spent parsing C++. We cannot use them because
3697 of `int id[]' which won't get parsed properly. */
3698 named_parm:
3699 /*
3700 typed_declspecs dont_see_typename '*' IDENTIFIER
3701 { $$ = build_tree_list ($$, build_parse_node (INDIRECT_REF, $4));
3702 see_typename (); }
3703 | typed_declspecs dont_see_typename '&' IDENTIFIER
3704 { $$ = build_tree_list ($$, build_parse_node (ADDR_EXPR, $4));
3705 see_typename (); }
3706 | TYPENAME IDENTIFIER
3707 { $$ = build_tree_list (get_decl_list ($$), $2); }
3708 | TYPESPEC IDENTIFIER
3709 { $$ = build_tree_list (get_decl_list ($$), $2); }
3710 | */
3711 /* Here we expand typed_declspecs inline to avoid mis-parsing of
3712 TYPESPEC IDENTIFIER. */
3713 typed_declspecs1 declarator
3714 { $$ = build_tree_list ($$, $2); }
3715 | typed_typespecs declarator
3716 { $$ = build_tree_list ($$, $2); }
3717 | typespec declarator
3718 { $$ = build_tree_list (get_decl_list ($$), $2); }
3719 | typed_declspecs1 absdcl
3720 { $$ = build_tree_list ($$, $2); }
3721 | typed_declspecs1 %prec EMPTY
3722 { $$ = build_tree_list ($$, NULL_TREE); }
3723 | declmods notype_declarator
3724 { $$ = build_tree_list ($$, $2); }
3725 ;
3726
3727 full_parm:
3728 parm maybe_init
3729 { $$ = build_tree_list ($2, $$); }
3730 ;
3731
3732 parm:
3733 named_parm
3734 | type_id
3735 ;
3736
3737 see_typename: %prec EMPTY
3738 { see_typename (); }
3739 ;
3740
3741 /*
3742 dont_see_typename: %prec EMPTY
3743 { dont_see_typename (); }
3744 ;
3745
3746 try_for_typename:
3747 {
3748 if ($<ttype>-1 == error_mark_node)
3749 $$ = 0;
3750 else
3751 {
3752 $$ = 1;
3753 pushclass ($<ttype>-1, 1);
3754 }
3755 }
3756 ;
3757 */
3758
3759 bad_parm:
3760 /* empty */ %prec EMPTY
3761 {
3762 error ("type specifier omitted for parameter");
3763 $$ = build_tree_list (integer_type_node, NULL_TREE);
3764 }
3765 | notype_declarator
3766 {
3767 error ("type specifier omitted for parameter");
3768 $$ = build_tree_list (integer_type_node, $$);
3769 }
3770 ;
3771
3772 exception_specification_opt:
3773 %prec EMPTY /* empty */
3774 { $$ = NULL_TREE; }
3775 | THROW '(' ansi_raise_identifiers ')' %prec EMPTY
3776 { $$ = $3; }
3777 | THROW LEFT_RIGHT %prec EMPTY
3778 { $$ = build_decl_list (NULL_TREE, NULL_TREE); }
3779 ;
3780
3781 ansi_raise_identifier:
3782 type_id
3783 { $$ = build_decl_list (NULL_TREE, groktypename($$)); }
3784 ;
3785
3786 ansi_raise_identifiers:
3787 ansi_raise_identifier
3788 | ansi_raise_identifiers ',' ansi_raise_identifier
3789 {
3790 TREE_CHAIN ($3) = $$;
3791 $$ = $3;
3792 }
3793 ;
3794
3795 conversion_declarator:
3796 /* empty */ %prec EMPTY
3797 { $$ = NULL_TREE; }
3798 | '*' type_quals conversion_declarator
3799 { $$ = make_pointer_declarator ($2, $3); }
3800 | '&' type_quals conversion_declarator
3801 { $$ = make_reference_declarator ($2, $3); }
3802 | ptr_to_mem type_quals conversion_declarator
3803 { tree arg = make_pointer_declarator ($2, $3);
3804 $$ = build_parse_node (SCOPE_REF, $1, arg);
3805 }
3806 ;
3807
3808 operator: OPERATOR
3809 { got_scope = NULL_TREE; }
3810 ;
3811
3812 operator_name:
3813 operator '*'
3814 { $$ = ansi_opname[MULT_EXPR]; }
3815 | operator '/'
3816 { $$ = ansi_opname[TRUNC_DIV_EXPR]; }
3817 | operator '%'
3818 { $$ = ansi_opname[TRUNC_MOD_EXPR]; }
3819 | operator '+'
3820 { $$ = ansi_opname[PLUS_EXPR]; }
3821 | operator '-'
3822 { $$ = ansi_opname[MINUS_EXPR]; }
3823 | operator '&'
3824 { $$ = ansi_opname[BIT_AND_EXPR]; }
3825 | operator '|'
3826 { $$ = ansi_opname[BIT_IOR_EXPR]; }
3827 | operator '^'
3828 { $$ = ansi_opname[BIT_XOR_EXPR]; }
3829 | operator '~'
3830 { $$ = ansi_opname[BIT_NOT_EXPR]; }
3831 | operator ','
3832 { $$ = ansi_opname[COMPOUND_EXPR]; }
3833 | operator ARITHCOMPARE
3834 { $$ = ansi_opname[$2]; }
3835 | operator '<'
3836 { $$ = ansi_opname[LT_EXPR]; }
3837 | operator '>'
3838 { $$ = ansi_opname[GT_EXPR]; }
3839 | operator EQCOMPARE
3840 { $$ = ansi_opname[$2]; }
3841 | operator ASSIGN
3842 { $$ = ansi_assopname[$2]; }
3843 | operator '='
3844 { $$ = ansi_opname [MODIFY_EXPR]; }
3845 | operator LSHIFT
3846 { $$ = ansi_opname[$2]; }
3847 | operator RSHIFT
3848 { $$ = ansi_opname[$2]; }
3849 | operator PLUSPLUS
3850 { $$ = ansi_opname[POSTINCREMENT_EXPR]; }
3851 | operator MINUSMINUS
3852 { $$ = ansi_opname[PREDECREMENT_EXPR]; }
3853 | operator ANDAND
3854 { $$ = ansi_opname[TRUTH_ANDIF_EXPR]; }
3855 | operator OROR
3856 { $$ = ansi_opname[TRUTH_ORIF_EXPR]; }
3857 | operator '!'
3858 { $$ = ansi_opname[TRUTH_NOT_EXPR]; }
3859 | operator '?' ':'
3860 { $$ = ansi_opname[COND_EXPR]; }
3861 | operator MIN_MAX
3862 { $$ = ansi_opname[$2]; }
3863 | operator POINTSAT %prec EMPTY
3864 { $$ = ansi_opname[COMPONENT_REF]; }
3865 | operator POINTSAT_STAR %prec EMPTY
3866 { $$ = ansi_opname[MEMBER_REF]; }
3867 | operator LEFT_RIGHT
3868 { $$ = ansi_opname[CALL_EXPR]; }
3869 | operator '[' ']'
3870 { $$ = ansi_opname[ARRAY_REF]; }
3871 | operator NEW %prec EMPTY
3872 { $$ = ansi_opname[NEW_EXPR]; }
3873 | operator DELETE %prec EMPTY
3874 { $$ = ansi_opname[DELETE_EXPR]; }
3875 | operator NEW '[' ']'
3876 { $$ = ansi_opname[VEC_NEW_EXPR]; }
3877 | operator DELETE '[' ']'
3878 { $$ = ansi_opname[VEC_DELETE_EXPR]; }
3879 /* Names here should be looked up in class scope ALSO. */
3880 | operator type_specifier_seq conversion_declarator
3881 { $$ = grokoptypename ($2, $3); }
3882 | operator error
3883 { $$ = ansi_opname[ERROR_MARK]; }
3884 ;
3885
3886 %%
3887
3888 #ifdef SPEW_DEBUG
3889 const char *
3890 debug_yytranslate (value)
3891 int value;
3892 {
3893 return yytname[YYTRANSLATE (value)];
3894 }
3895
3896 #endif
This page took 0.208731 seconds and 5 git commands to generate.