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