]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* YACC parser for C++ syntax. |
d6a8bdff | 2 | Copyright (C) 1988, 1989, 1993, 1994, 1995, 1996, 1997, 1998, |
d46a33b3 | 3 | 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
8d08fdba MS |
4 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
5 | ||
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU CC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU CC; see the file COPYING. If not, write to | |
e9fa0c7c RK |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
22 | |
23 | ||
24 | /* This grammar is based on the GNU CC grammar. */ | |
25 | ||
26 | /* Note: Bison automatically applies a default action of "$$ = $1" for | |
27 | all derivations; this is applied before the explicit action, if one | |
28 | is given. Keep this in mind when reading the actions. */ | |
29 | ||
8d08fdba | 30 | %{ |
8d08fdba MS |
31 | #include "config.h" |
32 | ||
8d052bc7 | 33 | #include "system.h" |
4977bab6 ZW |
34 | #include "coretypes.h" |
35 | #include "tm.h" | |
8d08fdba MS |
36 | |
37 | #include "tree.h" | |
38 | #include "input.h" | |
39 | #include "flags.h" | |
8d08fdba | 40 | #include "cp-tree.h" |
eb8845be | 41 | #include "decl.h" |
f09f1de5 | 42 | #include "lex.h" |
81a75f0f | 43 | #include "c-pragma.h" /* For YYDEBUG definition. */ |
e8abc66f | 44 | #include "output.h" |
49c249e1 | 45 | #include "except.h" |
77dc0938 | 46 | #include "toplev.h" |
fc6af6e3 | 47 | #include "ggc.h" |
8d08fdba | 48 | |
8d08fdba MS |
49 | /* Like YYERROR but do call yyerror. */ |
50 | #define YYERROR1 { yyerror ("syntax error"); YYERROR; } | |
51 | ||
94a50397 RH |
52 | /* Like the default stack expander, except (1) use realloc when possible, |
53 | (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca. | |
54 | ||
55 | Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot | |
56 | give malloced_yyvs its proper type. This is ok since all we need from | |
57 | it is to be able to free it. */ | |
58 | ||
59 | static short *malloced_yyss; | |
60 | static void *malloced_yyvs; | |
61 | ||
62 | #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ) \ | |
63 | do { \ | |
64 | size_t newsize; \ | |
65 | short *newss; \ | |
66 | YYSTYPE *newvs; \ | |
67 | newsize = *(YYSSZ) *= 2; \ | |
68 | if (malloced_yyss) \ | |
69 | { \ | |
70 | newss = (short *) \ | |
71 | really_call_realloc (*(SS), newsize * sizeof (short)); \ | |
72 | newvs = (YYSTYPE *) \ | |
73 | really_call_realloc (*(VS), newsize * sizeof (YYSTYPE)); \ | |
74 | } \ | |
75 | else \ | |
76 | { \ | |
77 | newss = (short *) really_call_malloc (newsize * sizeof (short)); \ | |
78 | newvs = (YYSTYPE *) really_call_malloc (newsize * sizeof (YYSTYPE)); \ | |
79 | if (newss) \ | |
80 | memcpy (newss, *(SS), (SSSIZE)); \ | |
81 | if (newvs) \ | |
82 | memcpy (newvs, *(VS), (VSSIZE)); \ | |
83 | } \ | |
84 | if (!newss || !newvs) \ | |
85 | { \ | |
86 | yyerror (MSG); \ | |
87 | return 2; \ | |
88 | } \ | |
89 | *(SS) = newss; \ | |
90 | *(VS) = newvs; \ | |
91 | malloced_yyss = newss; \ | |
92 | malloced_yyvs = (void *) newvs; \ | |
93 | } while (0) | |
a28e3c7f MS |
94 | #define OP0(NODE) (TREE_OPERAND (NODE, 0)) |
95 | #define OP1(NODE) (TREE_OPERAND (NODE, 1)) | |
96 | ||
8d08fdba MS |
97 | /* Contains the statement keyword (if/while/do) to include in an |
98 | error message if the user supplies an empty conditional expression. */ | |
d8e178a0 | 99 | static const char *cond_stmt_keyword; |
8d08fdba | 100 | |
1f51a992 | 101 | /* List of types and structure classes of the current declaration. */ |
e2500fed | 102 | static GTY(()) tree current_declspecs; |
1f51a992 JM |
103 | |
104 | /* List of prefix attributes in effect. | |
105 | Prefix attributes are parsed by the reserved_declspecs and declmods | |
106 | rules. They create a list that contains *both* declspecs and attrs. */ | |
107 | /* ??? It is not clear yet that all cases where an attribute can now appear in | |
108 | a declspec list have been updated. */ | |
e2500fed | 109 | static GTY(()) tree prefix_attributes; |
1f51a992 | 110 | |
1f51a992 | 111 | /* When defining an enumeration, this is the type of the enumeration. */ |
e2500fed | 112 | static GTY(()) tree current_enum_type; |
1f51a992 | 113 | |
f2d71db6 NS |
114 | /* When parsing a conversion operator name, this is the scope of the |
115 | operator itself. */ | |
e2500fed | 116 | static GTY(()) tree saved_scopes; |
f2d71db6 | 117 | |
1f51a992 JM |
118 | static tree empty_parms PARAMS ((void)); |
119 | static tree parse_decl0 PARAMS ((tree, tree, tree, tree, int)); | |
120 | static tree parse_decl PARAMS ((tree, tree, int)); | |
121 | static void parse_end_decl PARAMS ((tree, tree, tree)); | |
122 | static tree parse_field0 PARAMS ((tree, tree, tree, tree, tree, tree)); | |
123 | static tree parse_field PARAMS ((tree, tree, tree, tree)); | |
124 | static tree parse_bitfield0 PARAMS ((tree, tree, tree, tree, tree)); | |
125 | static tree parse_bitfield PARAMS ((tree, tree, tree)); | |
126 | static tree parse_method PARAMS ((tree, tree, tree)); | |
fd87b7a7 NS |
127 | static void frob_specs PARAMS ((tree, tree)); |
128 | static void check_class_key PARAMS ((tree, tree)); | |
80b1331c | 129 | static tree parse_scoped_id PARAMS ((tree)); |
88e5899c MM |
130 | static tree parse_xref_tag (tree, tree, int); |
131 | static tree parse_handle_class_head (tree, tree, tree, int, int *); | |
eb8845be | 132 | static void parse_decl_instantiation (tree, tree, tree); |
15c7fb9c | 133 | static int parse_begin_function_definition (tree, tree); |
4ba126e4 | 134 | static tree parse_finish_call_expr (tree, tree, int); |
1f51a992 | 135 | |
8d08fdba | 136 | /* Cons up an empty parameter list. */ |
f9c4f105 | 137 | static inline tree |
8d08fdba MS |
138 | empty_parms () |
139 | { | |
140 | tree parms; | |
141 | ||
8b27e9ef | 142 | #ifndef NO_IMPLICIT_EXTERN_C |
84d901be | 143 | if (in_system_header && current_class_type == NULL |
0c10a805 | 144 | && current_lang_name == lang_name_c) |
8d08fdba | 145 | parms = NULL_TREE; |
8b27e9ef NS |
146 | else |
147 | #endif | |
148 | parms = void_list_node; | |
8d08fdba MS |
149 | return parms; |
150 | } | |
75650646 | 151 | |
1f51a992 JM |
152 | /* Record the decl-specifiers, attributes and type lookups from the |
153 | decl-specifier-seq in a declaration. */ | |
154 | ||
155 | static void | |
156 | frob_specs (specs_attrs, lookups) | |
157 | tree specs_attrs, lookups; | |
158 | { | |
159 | save_type_access_control (lookups); | |
160 | split_specs_attrs (specs_attrs, ¤t_declspecs, &prefix_attributes); | |
161 | if (current_declspecs | |
162 | && TREE_CODE (current_declspecs) != TREE_LIST) | |
1f8f4a0b | 163 | current_declspecs = build_tree_list (NULL_TREE, current_declspecs); |
594bb0e7 | 164 | if (have_extern_spec) |
1f51a992 | 165 | { |
270d8c65 NS |
166 | /* We have to indicate that there is an "extern", but that it |
167 | was part of a language specifier. For instance, | |
84d901be | 168 | |
270d8c65 NS |
169 | extern "C" typedef int (*Ptr) (); |
170 | ||
171 | is well formed. */ | |
172 | current_declspecs = tree_cons (error_mark_node, | |
84d901be | 173 | get_identifier ("extern"), |
1f8f4a0b | 174 | current_declspecs); |
594bb0e7 | 175 | have_extern_spec = false; |
1f51a992 JM |
176 | } |
177 | } | |
178 | ||
179 | static tree | |
180 | parse_decl (declarator, attributes, initialized) | |
181 | tree declarator, attributes; | |
182 | int initialized; | |
183 | { | |
184 | return start_decl (declarator, current_declspecs, initialized, | |
185 | attributes, prefix_attributes); | |
186 | } | |
187 | ||
188 | static tree | |
189 | parse_decl0 (declarator, specs_attrs, lookups, attributes, initialized) | |
190 | tree declarator, specs_attrs, lookups, attributes; | |
191 | int initialized; | |
192 | { | |
193 | frob_specs (specs_attrs, lookups); | |
194 | return parse_decl (declarator, attributes, initialized); | |
195 | } | |
196 | ||
197 | static void | |
198 | parse_end_decl (decl, init, asmspec) | |
199 | tree decl, init, asmspec; | |
200 | { | |
9fc336c7 JM |
201 | /* If decl is NULL_TREE, then this was a variable declaration using |
202 | () syntax for the initializer, so we handled it in grokdeclarator. */ | |
203 | if (decl) | |
204 | decl_type_access_control (decl); | |
1f51a992 JM |
205 | cp_finish_decl (decl, init, asmspec, init ? LOOKUP_ONLYCONVERTING : 0); |
206 | } | |
207 | ||
208 | static tree | |
209 | parse_field (declarator, attributes, asmspec, init) | |
210 | tree declarator, attributes, asmspec, init; | |
211 | { | |
212 | tree d = grokfield (declarator, current_declspecs, init, asmspec, | |
91d231cb | 213 | chainon (attributes, prefix_attributes)); |
1f51a992 JM |
214 | decl_type_access_control (d); |
215 | return d; | |
216 | } | |
217 | ||
218 | static tree | |
219 | parse_field0 (declarator, specs_attrs, lookups, attributes, asmspec, init) | |
220 | tree declarator, specs_attrs, lookups, attributes, asmspec, init; | |
221 | { | |
222 | frob_specs (specs_attrs, lookups); | |
223 | return parse_field (declarator, attributes, asmspec, init); | |
224 | } | |
225 | ||
226 | static tree | |
227 | parse_bitfield (declarator, attributes, width) | |
228 | tree declarator, attributes, width; | |
229 | { | |
230 | tree d = grokbitfield (declarator, current_declspecs, width); | |
91d231cb | 231 | cplus_decl_attributes (&d, chainon (attributes, prefix_attributes), 0); |
1f51a992 JM |
232 | decl_type_access_control (d); |
233 | return d; | |
234 | } | |
235 | ||
236 | static tree | |
237 | parse_bitfield0 (declarator, specs_attrs, lookups, attributes, width) | |
238 | tree declarator, specs_attrs, lookups, attributes, width; | |
239 | { | |
240 | frob_specs (specs_attrs, lookups); | |
241 | return parse_bitfield (declarator, attributes, width); | |
242 | } | |
243 | ||
244 | static tree | |
245 | parse_method (declarator, specs_attrs, lookups) | |
246 | tree declarator, specs_attrs, lookups; | |
247 | { | |
248 | tree d; | |
249 | frob_specs (specs_attrs, lookups); | |
250 | d = start_method (current_declspecs, declarator, prefix_attributes); | |
251 | decl_type_access_control (d); | |
252 | return d; | |
253 | } | |
254 | ||
fd87b7a7 NS |
255 | static void |
256 | check_class_key (key, aggr) | |
257 | tree key; | |
258 | tree aggr; | |
259 | { | |
29cece2e JJ |
260 | if (TREE_CODE (key) == TREE_LIST) |
261 | key = TREE_VALUE (key); | |
fd87b7a7 NS |
262 | if ((key == union_type_node) != (TREE_CODE (aggr) == UNION_TYPE)) |
263 | pedwarn ("`%s' tag used in naming `%#T'", | |
264 | key == union_type_node ? "union" | |
265 | : key == record_type_node ? "struct" : "class", aggr); | |
266 | } | |
267 | ||
8d08fdba MS |
268 | %} |
269 | ||
270 | %start program | |
271 | ||
e2500fed | 272 | %union { GTY(()) |
84d901be AD |
273 | long itype; |
274 | tree ttype; | |
275 | char *strtype; | |
276 | enum tree_code code; | |
0e5921e8 ZW |
277 | flagged_type_tree ftype; |
278 | struct unparsed_text *pi; | |
87e3dbc9 | 279 | } |
8d08fdba MS |
280 | |
281 | /* All identifiers that are not reserved words | |
282 | and are not declared typedefs in the current block */ | |
283 | %token IDENTIFIER | |
284 | ||
285 | /* All identifiers that are declared typedefs in the current block. | |
286 | In some contexts, they are treated just like IDENTIFIER, | |
287 | but they can also serve as typespecs in declarations. */ | |
84d901be | 288 | %token tTYPENAME |
a80e4195 | 289 | %token SELFNAME |
8d08fdba | 290 | |
386b8a85 | 291 | /* A template function. */ |
5408ce78 | 292 | %token PFUNCNAME |
386b8a85 | 293 | |
8d08fdba MS |
294 | /* Reserved words that specify storage class. |
295 | yylval contains an IDENTIFIER_NODE which indicates which one. */ | |
296 | %token SCSPEC | |
297 | ||
298 | /* Reserved words that specify type. | |
299 | yylval contains an IDENTIFIER_NODE which indicates which one. */ | |
300 | %token TYPESPEC | |
301 | ||
302 | /* Reserved words that qualify type: "const" or "volatile". | |
303 | yylval contains an IDENTIFIER_NODE which indicates which one. */ | |
c11b6f21 | 304 | %token CV_QUALIFIER |
8d08fdba MS |
305 | |
306 | /* Character or numeric constants. | |
307 | yylval is the node for the constant. */ | |
308 | %token CONSTANT | |
309 | ||
0ba8a114 NS |
310 | /* __func__, __FUNCTION__ or __PRETTY_FUNCTION__. |
311 | yylval contains an IDENTIFIER_NODE which indicates which one. */ | |
5f261ba9 | 312 | %token <ttype> VAR_FUNC_NAME |
0ba8a114 | 313 | |
a23c9413 NB |
314 | /* String constants in raw form. |
315 | yylval is a STRING_CST node. */ | |
8d08fdba MS |
316 | %token STRING |
317 | ||
318 | /* "...", used for functions with variable arglists. */ | |
319 | %token ELLIPSIS | |
320 | ||
321 | /* the reserved words */ | |
e92cc029 | 322 | /* SCO include files test "ASM", so use something else. */ |
8d08fdba | 323 | %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT |
3dcaad8b | 324 | %token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF |
f30432d7 | 325 | %token SIGOF |
8d08fdba | 326 | %token ATTRIBUTE EXTENSION LABEL |
4a4b0aa3 | 327 | %token REALPART IMAGPART VA_ARG |
8d08fdba MS |
328 | |
329 | /* the reserved words... C++ extensions */ | |
330 | %token <ttype> AGGR | |
be99da77 | 331 | %token <ttype> VISSPEC |
d22c8596 | 332 | %token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE |
db5ae43f | 333 | %token NAMESPACE TYPENAME_KEYWORD USING |
8d08fdba | 334 | %token LEFT_RIGHT TEMPLATE |
a4443a08 | 335 | %token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST |
447306fa | 336 | %token SCOPE EXPORT |
8d08fdba | 337 | |
8d08fdba MS |
338 | /* Define the operator tokens and their precedences. |
339 | The value is an integer because, if used, it is the tree code | |
340 | to use in the expression made from the operator. */ | |
341 | ||
342 | %left EMPTY /* used to resolve s/r with epsilon */ | |
343 | ||
344 | %left error | |
345 | ||
346 | /* Add precedence rules to solve dangling else s/r conflict */ | |
347 | %nonassoc IF | |
348 | %nonassoc ELSE | |
349 | ||
84d901be | 350 | %left IDENTIFIER PFUNCNAME tTYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD ATTRIBUTE |
8d08fdba MS |
351 | |
352 | %left '{' ',' ';' | |
353 | ||
db5ae43f | 354 | %nonassoc THROW |
6060a796 | 355 | %right <code> ':' |
8d08fdba | 356 | %right <code> ASSIGN '=' |
6060a796 | 357 | %right <code> '?' |
8d08fdba MS |
358 | %left <code> OROR |
359 | %left <code> ANDAND | |
360 | %left <code> '|' | |
361 | %left <code> '^' | |
362 | %left <code> '&' | |
363 | %left <code> MIN_MAX | |
364 | %left <code> EQCOMPARE | |
365 | %left <code> ARITHCOMPARE '<' '>' | |
366 | %left <code> LSHIFT RSHIFT | |
367 | %left <code> '+' '-' | |
368 | %left <code> '*' '/' '%' | |
51c184be MS |
369 | %left <code> POINTSAT_STAR DOT_STAR |
370 | %right <code> UNARY PLUSPLUS MINUSMINUS '~' | |
8d08fdba | 371 | %left HYPERUNARY |
66a6250f | 372 | %left <ttype> LEFT_RIGHT |
51c184be | 373 | %left <code> POINTSAT '.' '(' '[' |
8d08fdba MS |
374 | |
375 | %right SCOPE /* C++ extension */ | |
db5ae43f | 376 | %nonassoc NEW DELETE TRY CATCH |
8d08fdba MS |
377 | |
378 | %type <code> unop | |
379 | ||
84d901be | 380 | %type <ttype> identifier IDENTIFIER tTYPENAME CONSTANT expr nonnull_exprlist |
73b0fce8 | 381 | %type <ttype> PFUNCNAME maybe_identifier |
a80e4195 | 382 | %type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME |
ca5e04b2 | 383 | %type <ttype> expr_no_commas expr_no_comma_rangle |
b84a3874 | 384 | %type <ttype> cast_expr unary_expr primary STRING |
e2500fed | 385 | %type <ttype> reserved_declspecs boolean_literal |
46b02c6d | 386 | %type <ttype> reserved_typespecquals |
c11b6f21 | 387 | %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier |
42976354 | 388 | %type <ttype> init initlist maybeasm maybe_init defarg defarg1 |
8d08fdba | 389 | %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers |
2986ae00 | 390 | %type <ttype> maybe_attribute attributes attribute attribute_list attrib |
219670f1 | 391 | %type <ttype> any_word |
8d08fdba | 392 | |
3e4d04a1 RH |
393 | %type <itype> save_lineno |
394 | %type <ttype> simple_stmt simple_if | |
8d08fdba MS |
395 | |
396 | %type <ttype> declarator notype_declarator after_type_declarator | |
46ff11fd | 397 | %type <ttype> notype_declarator_intern absdcl_intern |
b607c87f | 398 | %type <ttype> after_type_declarator_intern |
51c184be | 399 | %type <ttype> direct_notype_declarator direct_after_type_declarator |
61a127b3 | 400 | %type <itype> components notype_components |
84d901be | 401 | %type <ttype> component_decl component_decl_1 |
61a127b3 | 402 | %type <ttype> component_declarator component_declarator0 |
f30432d7 | 403 | %type <ttype> notype_component_declarator notype_component_declarator0 |
51c184be | 404 | %type <ttype> after_type_component_declarator after_type_component_declarator0 |
c11b6f21 | 405 | %type <ttype> absdcl cv_qualifiers |
51c184be | 406 | %type <ttype> direct_abstract_declarator conversion_declarator |
46b02c6d | 407 | %type <ttype> new_declarator direct_new_declarator |
84d901be | 408 | %type <ttype> xexpr parmlist parms bad_parm |
8d08fdba | 409 | %type <ttype> identifiers_or_typenames |
f30432d7 | 410 | %type <ttype> fcast_or_absdcl regcast_or_absdcl |
52fbc847 JM |
411 | %type <ttype> expr_or_declarator expr_or_declarator_intern |
412 | %type <ttype> complex_notype_declarator | |
a28e3c7f | 413 | %type <ttype> notype_unqualified_id unqualified_id qualified_id |
46422d6c | 414 | %type <ttype> template_id do_id object_template_id notype_template_declarator |
6060a796 | 415 | %type <ttype> overqualified_id notype_qualified_id any_id |
51c184be | 416 | %type <ttype> complex_direct_notype_declarator functional_cast |
84d901be | 417 | %type <ttype> complex_parmlist parms_comma |
ea9635c7 | 418 | %type <ttype> namespace_qualifier namespace_using_decl |
46b02c6d MS |
419 | |
420 | %type <ftype> type_id new_type_id typed_typespecs typespec typed_declspecs | |
c11b6f21 | 421 | %type <ftype> typed_declspecs1 type_specifier_seq nonempty_cv_qualifiers |
46b02c6d | 422 | %type <ftype> structsp typespecqual_reserved parm named_parm full_parm |
70adf8a9 | 423 | %type <ftype> declmods |
8d08fdba | 424 | |
fd65a4c1 MM |
425 | %type <itype> extension |
426 | ||
8d08fdba | 427 | /* C++ extensions */ |
ce4a0391 | 428 | %token <ttype> PTYPENAME |
87e3dbc9 | 429 | %token <ttype> EXTERN_LANG_STRING ALL |
42976354 | 430 | %token <ttype> PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER |
84d901be | 431 | %token <pi> PRE_PARSED_FUNCTION_DECL |
b4c4a9ec | 432 | %type <ttype> component_constructor_declarator |
e2500fed GK |
433 | %type <ttype> fn_def2 return_id constructor_declarator |
434 | %type <ttype> begin_function_body_ | |
d46a33b3 NS |
435 | %type <ttype> class_head class_head_apparent_template |
436 | %type <ftype> class_head_decl class_head_defn | |
3d7de1fa | 437 | %type <ttype> base_class_list |
be99da77 | 438 | %type <ttype> base_class_access_list |
e2500fed | 439 | %type <ttype> base_class maybe_base_class_list base_class_1 |
e3417fcd | 440 | %type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers |
863adfc0 | 441 | %type <ttype> operator_name |
39211cd5 | 442 | %type <ttype> object aggr |
80048418 | 443 | %type <itype> new delete |
8d08fdba | 444 | /* %type <ttype> primary_no_id */ |
80048418 | 445 | %type <ttype> maybe_parmlist |
fd74ca0b MM |
446 | %type <ttype> member_init |
447 | %type <ftype> member_init_list | |
b37bf5bd NS |
448 | %type <ttype> template_parm_header template_spec_header template_header |
449 | %type <ttype> template_parm_list template_parm | |
73b0fce8 | 450 | %type <ttype> template_type_parm template_template_parm |
5566b478 | 451 | %type <code> template_close_bracket |
2e6eddfc | 452 | %type <ttype> apparent_template_type |
73b0fce8 | 453 | %type <ttype> template_type template_arg_list template_arg_list_opt |
cf776105 | 454 | %type <ttype> template_arg |
8d2733ca | 455 | %type <ttype> condition xcond paren_cond_or_null |
a28e3c7f | 456 | %type <ttype> type_name nested_name_specifier nested_type ptr_to_mem |
653cc74a | 457 | %type <ttype> complete_type_name notype_identifier nonnested_type |
a28e3c7f | 458 | %type <ttype> complex_type_name nested_name_specifier_1 |
46b02c6d | 459 | %type <ttype> new_initializer new_placement |
ad321293 | 460 | %type <ttype> using_decl |
653cc74a | 461 | %type <ttype> typename_sub typename_sub0 typename_sub1 typename_sub2 |
b2b7d40a | 462 | %type <ttype> explicit_template_type |
e92cc029 | 463 | /* in order to recognize aggr tags as defining and thus shadowing. */ |
8d08fdba | 464 | %token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN |
8d08fdba | 465 | %type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN |
b35d4555 | 466 | %type <ttype> handler_args |
e2500fed | 467 | %type <ttype> self_template_type finish_template_type_ |
67d743fe | 468 | |
6060a796 MS |
469 | %token NSNAME |
470 | %type <ttype> NSNAME | |
471 | ||
d18c083e MS |
472 | /* Used in lex.c for parsing pragmas. */ |
473 | %token END_OF_LINE | |
474 | ||
5566b478 | 475 | /* lex.c and pt.c depend on this being the last token. Define |
8d08fdba MS |
476 | any new tokens before this one! */ |
477 | %token END_OF_SAVED_INPUT | |
478 | \f | |
479 | %{ | |
8d08fdba | 480 | /* Tell yyparse how to print a token's value, if yydebug is set. */ |
8d08fdba | 481 | #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL) |
158991b7 | 482 | extern void yyprint PARAMS ((FILE *, int, YYSTYPE)); |
8d08fdba MS |
483 | %} |
484 | \f | |
485 | %% | |
c11b6f21 MS |
486 | program: |
487 | /* empty */ | |
ded41e4f | 488 | { finish_translation_unit (); } |
8d08fdba | 489 | | extdefs |
ce4a0391 | 490 | { finish_translation_unit (); } |
8d08fdba MS |
491 | ; |
492 | ||
493 | /* the reason for the strange actions in this rule | |
494 | is so that notype_initdecls when reached via datadef | |
e92cc029 | 495 | can find a valid list of type and sc specs in $0. */ |
8d08fdba MS |
496 | |
497 | extdefs: | |
c11b6f21 MS |
498 | { $<ttype>$ = NULL_TREE; } |
499 | lang_extdef | |
432aff66 | 500 | { $<ttype>$ = NULL_TREE; ggc_collect (); } |
8d08fdba | 501 | | extdefs lang_extdef |
432aff66 | 502 | { $<ttype>$ = NULL_TREE; ggc_collect (); } |
8d08fdba MS |
503 | ; |
504 | ||
6060a796 MS |
505 | extdefs_opt: |
506 | extdefs | |
507 | | /* empty */ | |
508 | ; | |
509 | ||
8d08fdba | 510 | .hush_warning: |
594bb0e7 | 511 | { have_extern_spec = true; |
8d08fdba MS |
512 | $<ttype>$ = NULL_TREE; } |
513 | ; | |
514 | .warning_ok: | |
594bb0e7 | 515 | { have_extern_spec = false; } |
8d08fdba MS |
516 | ; |
517 | ||
de22184b MS |
518 | extension: |
519 | EXTENSION | |
fd65a4c1 | 520 | { $$ = pedantic; |
de22184b MS |
521 | pedantic = 0; } |
522 | ; | |
523 | ||
8d08fdba | 524 | asm_keyword: |
2986ae00 | 525 | ASM_KEYWORD |
8d08fdba MS |
526 | ; |
527 | ||
528 | lang_extdef: | |
70adf8a9 JM |
529 | { if (pending_lang_change) do_pending_lang_change(); |
530 | type_lookups = NULL_TREE; } | |
8d08fdba | 531 | extdef |
9188c363 | 532 | { if (! toplevel_bindings_p ()) |
c11b6f21 | 533 | pop_everything (); } |
8d08fdba MS |
534 | ; |
535 | ||
536 | extdef: | |
8dff1027 | 537 | fndef eat_saved_input |
0e5921e8 | 538 | { do_pending_inlines (); } |
8d08fdba | 539 | | datadef |
0e5921e8 | 540 | { do_pending_inlines (); } |
447306fa NS |
541 | |
542 | | EXPORT | |
33bd39a2 | 543 | { warning ("keyword `export' not implemented, and will be ignored"); } |
447306fa NS |
544 | template_def |
545 | { do_pending_inlines (); } | |
8d08fdba | 546 | | template_def |
0e5921e8 | 547 | { do_pending_inlines (); } |
b84a3874 RH |
548 | | asm_keyword '(' STRING ')' ';' |
549 | { assemble_asm ($3); } | |
6060a796 | 550 | | extern_lang_string '{' extdefs_opt '}' |
8d08fdba | 551 | { pop_lang_context (); } |
8dff1027 | 552 | | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input |
0e5921e8 | 553 | { do_pending_inlines (); pop_lang_context (); } |
8d08fdba | 554 | | extern_lang_string .hush_warning datadef .warning_ok |
0e5921e8 | 555 | { do_pending_inlines (); pop_lang_context (); } |
6060a796 MS |
556 | | NAMESPACE identifier '{' |
557 | { push_namespace ($2); } | |
558 | extdefs_opt '}' | |
559 | { pop_namespace (); } | |
560 | | NAMESPACE '{' | |
561 | { push_namespace (NULL_TREE); } | |
562 | extdefs_opt '}' | |
563 | { pop_namespace (); } | |
85c6cbaf ML |
564 | | namespace_alias |
565 | | using_decl ';' | |
566 | { do_toplevel_using_decl ($1); } | |
567 | | using_directive | |
568 | | extension extdef | |
fd65a4c1 | 569 | { pedantic = $1; } |
85c6cbaf ML |
570 | ; |
571 | ||
572 | namespace_alias: | |
84d901be | 573 | NAMESPACE identifier '=' |
3e3f722c | 574 | { begin_only_namespace_names (); } |
26877584 | 575 | any_id ';' |
3e3f722c ML |
576 | { |
577 | end_only_namespace_names (); | |
578 | if (lastiddecl) | |
579 | $5 = lastiddecl; | |
580 | do_namespace_alias ($2, $5); | |
581 | } | |
6060a796 MS |
582 | ; |
583 | ||
584 | using_decl: | |
585 | USING qualified_id | |
a9aedbc2 | 586 | { $$ = $2; } |
6060a796 | 587 | | USING global_scope qualified_id |
a9aedbc2 | 588 | { $$ = $3; } |
6060a796 | 589 | | USING global_scope unqualified_id |
a9aedbc2 | 590 | { $$ = $3; } |
6060a796 MS |
591 | ; |
592 | ||
ea9635c7 ML |
593 | namespace_using_decl: |
594 | USING namespace_qualifier identifier | |
718b8ea5 | 595 | { $$ = build_nt (SCOPE_REF, $2, $3); } |
ea9635c7 | 596 | | USING global_scope identifier |
718b8ea5 | 597 | { $$ = build_nt (SCOPE_REF, global_namespace, $3); } |
ea9635c7 | 598 | | USING global_scope namespace_qualifier identifier |
718b8ea5 | 599 | { $$ = build_nt (SCOPE_REF, $3, $4); } |
ea9635c7 ML |
600 | ; |
601 | ||
26877584 JM |
602 | using_directive: |
603 | USING NAMESPACE | |
604 | { begin_only_namespace_names (); } | |
605 | any_id ';' | |
606 | { | |
607 | end_only_namespace_names (); | |
608 | /* If no declaration was found, the using-directive is | |
609 | invalid. Since that was not reported, we need the | |
610 | identifier for the error message. */ | |
611 | if (TREE_CODE ($4) == IDENTIFIER_NODE && lastiddecl) | |
612 | $4 = lastiddecl; | |
613 | do_using_directive ($4); | |
614 | } | |
615 | ; | |
616 | ||
ea9635c7 ML |
617 | namespace_qualifier: |
618 | NSNAME SCOPE | |
619 | { | |
620 | if (TREE_CODE ($$) == IDENTIFIER_NODE) | |
621 | $$ = lastiddecl; | |
622 | got_scope = $$; | |
623 | } | |
624 | | namespace_qualifier NSNAME SCOPE | |
625 | { | |
a41461c9 | 626 | $$ = $2; |
ea9635c7 ML |
627 | if (TREE_CODE ($$) == IDENTIFIER_NODE) |
628 | $$ = lastiddecl; | |
629 | got_scope = $$; | |
630 | } | |
224e6091 | 631 | ; |
ea9635c7 | 632 | |
6060a796 MS |
633 | any_id: |
634 | unqualified_id | |
635 | | qualified_id | |
636 | | global_scope qualified_id | |
637 | { $$ = $2; } | |
638 | | global_scope unqualified_id | |
639 | { $$ = $2; } | |
8d08fdba MS |
640 | ; |
641 | ||
642 | extern_lang_string: | |
28cbf42c | 643 | EXTERN_LANG_STRING |
8d08fdba | 644 | { push_lang_context ($1); } |
28cbf42c MS |
645 | | extern_lang_string EXTERN_LANG_STRING |
646 | { if (current_lang_name != $2) | |
33bd39a2 | 647 | error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name); |
28cbf42c | 648 | pop_lang_context (); push_lang_context ($2); } |
8d08fdba MS |
649 | ; |
650 | ||
b37bf5bd | 651 | template_parm_header: |
8d08fdba MS |
652 | TEMPLATE '<' |
653 | { begin_template_parm_list (); } | |
654 | template_parm_list '>' | |
655 | { $$ = end_template_parm_list ($4); } | |
b37bf5bd NS |
656 | ; |
657 | ||
658 | template_spec_header: | |
659 | TEMPLATE '<' '>' | |
84d901be | 660 | { begin_specialization(); |
386b8a85 | 661 | $$ = NULL_TREE; } |
8d08fdba MS |
662 | ; |
663 | ||
b37bf5bd NS |
664 | template_header: |
665 | template_parm_header | |
666 | | template_spec_header | |
667 | ; | |
668 | ||
8d08fdba MS |
669 | template_parm_list: |
670 | template_parm | |
671 | { $$ = process_template_parm (NULL_TREE, $1); } | |
672 | | template_parm_list ',' template_parm | |
673 | { $$ = process_template_parm ($1, $3); } | |
674 | ; | |
675 | ||
73b0fce8 KL |
676 | maybe_identifier: |
677 | identifier | |
678 | { $$ = $1; } | |
679 | | /* empty */ | |
680 | { $$ = NULL_TREE; } | |
224e6091 | 681 | ; |
73b0fce8 | 682 | |
a292b002 | 683 | template_type_parm: |
73b0fce8 | 684 | aggr maybe_identifier |
b4c4a9ec | 685 | { $$ = finish_template_type_parm ($1, $2); } |
73b0fce8 | 686 | | TYPENAME_KEYWORD maybe_identifier |
b4c4a9ec | 687 | { $$ = finish_template_type_parm (class_type_node, $2); } |
a292b002 MS |
688 | ; |
689 | ||
73b0fce8 | 690 | template_template_parm: |
b37bf5bd | 691 | template_parm_header aggr maybe_identifier |
b4c4a9ec | 692 | { $$ = finish_template_template_parm ($2, $3); } |
73b0fce8 KL |
693 | ; |
694 | ||
8d08fdba MS |
695 | template_parm: |
696 | /* The following rules introduce a new reduce/reduce | |
51c184be MS |
697 | conflict on the ',' and '>' input tokens: they are valid |
698 | prefixes for a `structsp', which means they could match a | |
699 | nameless parameter. See 14.6, paragraph 3. | |
8d08fdba MS |
700 | By putting them before the `parm' rule, we get |
701 | their match before considering them nameless parameter | |
702 | declarations. */ | |
a292b002 | 703 | template_type_parm |
5566b478 MS |
704 | { $$ = build_tree_list (NULL_TREE, $1); } |
705 | | template_type_parm '=' type_id | |
46b02c6d | 706 | { $$ = build_tree_list (groktypename ($3.t), $1); } |
5566b478 | 707 | | parm |
46b02c6d | 708 | { $$ = build_tree_list (NULL_TREE, $1.t); } |
ca5e04b2 | 709 | | parm '=' expr_no_comma_rangle |
46b02c6d | 710 | { $$ = build_tree_list ($3, $1.t); } |
73b0fce8 KL |
711 | | template_template_parm |
712 | { $$ = build_tree_list (NULL_TREE, $1); } | |
e7e66632 KL |
713 | | template_template_parm '=' template_arg |
714 | { | |
8ba658ee | 715 | $3 = check_template_template_default_arg ($3); |
e7e66632 KL |
716 | $$ = build_tree_list ($3, $1); |
717 | } | |
8d08fdba MS |
718 | ; |
719 | ||
5566b478 | 720 | template_def: |
36a117a5 MM |
721 | template_header template_extdef |
722 | { finish_template_decl ($1); } | |
723 | | template_header error %prec EMPTY | |
724 | { finish_template_decl ($1); } | |
725 | ; | |
726 | ||
727 | template_extdef: | |
728 | fndef eat_saved_input | |
0e5921e8 | 729 | { do_pending_inlines (); } |
36a117a5 | 730 | | template_datadef |
0e5921e8 | 731 | { do_pending_inlines (); } |
36a117a5 | 732 | | template_def |
0e5921e8 | 733 | { do_pending_inlines (); } |
36a117a5 | 734 | | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input |
0e5921e8 | 735 | { do_pending_inlines (); |
36a117a5 MM |
736 | pop_lang_context (); } |
737 | | extern_lang_string .hush_warning template_datadef .warning_ok | |
0e5921e8 | 738 | { do_pending_inlines (); |
36a117a5 MM |
739 | pop_lang_context (); } |
740 | | extension template_extdef | |
fd65a4c1 | 741 | { pedantic = $1; } |
36a117a5 MM |
742 | ; |
743 | ||
744 | template_datadef: | |
745 | nomods_initdecls ';' | |
746 | | declmods notype_initdecls ';' | |
747 | {} | |
748 | | typed_declspecs initdecls ';' | |
749 | { note_list_got_semicolon ($1.t); } | |
750 | | structsp ';' | |
220bce48 NS |
751 | { |
752 | if ($1.t != error_mark_node) | |
753 | { | |
754 | maybe_process_partial_specialization ($1.t); | |
755 | note_got_semicolon ($1.t); | |
756 | } | |
757 | } | |
8d08fdba MS |
758 | ; |
759 | ||
760 | datadef: | |
a28e3c7f | 761 | nomods_initdecls ';' |
8d08fdba MS |
762 | | declmods notype_initdecls ';' |
763 | {} | |
8d08fdba | 764 | | typed_declspecs initdecls ';' |
36a117a5 | 765 | { note_list_got_semicolon ($1.t); } |
8d08fdba | 766 | | declmods ';' |
8251199e | 767 | { pedwarn ("empty declaration"); } |
8d08fdba MS |
768 | | explicit_instantiation ';' |
769 | | typed_declspecs ';' | |
c11b6f21 MS |
770 | { |
771 | tree t, attrs; | |
772 | split_specs_attrs ($1.t, &t, &attrs); | |
773 | shadow_tag (t); | |
774 | note_list_got_semicolon ($1.t); | |
775 | } | |
8d08fdba MS |
776 | | error ';' |
777 | | error '}' | |
0caee1c6 JM |
778 | | error END_OF_SAVED_INPUT |
779 | { end_input (); } | |
8d08fdba | 780 | | ';' |
fd8b7a0e | 781 | | bad_decl |
8d08fdba MS |
782 | ; |
783 | ||
f30432d7 MS |
784 | ctor_initializer_opt: |
785 | nodecls | |
f30432d7 | 786 | | base_init |
f30432d7 | 787 | ; |
8d08fdba | 788 | |
f30432d7 MS |
789 | maybe_return_init: |
790 | /* empty */ | |
791 | | return_init | |
792 | | return_init ';' | |
793 | ; | |
8d08fdba | 794 | |
f30432d7 MS |
795 | eat_saved_input: |
796 | /* empty */ | |
797 | | END_OF_SAVED_INPUT | |
798 | ; | |
799 | ||
b5856475 JM |
800 | /* The outermost block of a function really begins before the |
801 | mem-initializer-list, so we open one there and suppress the one that | |
802 | actually corresponds to the curly braces. */ | |
ade3dc07 | 803 | function_body: |
e2500fed | 804 | begin_function_body_ ctor_initializer_opt save_lineno '{' |
b5856475 | 805 | { $<ttype>$ = begin_compound_stmt (/*has_no_scope=*/1); } |
84d901be | 806 | compstmtend |
b5856475 JM |
807 | { |
808 | STMT_LINENO ($<ttype>5) = $3; | |
809 | finish_compound_stmt (/*has_no_scope=*/1, $<ttype>5); | |
ade3dc07 JM |
810 | finish_function_body ($1); |
811 | } | |
812 | ; | |
813 | ||
f30432d7 | 814 | fndef: |
ade3dc07 JM |
815 | fn.def1 maybe_return_init function_body |
816 | { expand_body (finish_function (0)); } | |
f30432d7 | 817 | | fn.def1 maybe_return_init function_try_block |
ade3dc07 | 818 | { expand_body (finish_function (0)); } |
8dff1027 MS |
819 | | fn.def1 maybe_return_init error |
820 | { } | |
8d08fdba MS |
821 | ; |
822 | ||
c91a56d2 | 823 | constructor_declarator: |
84d901be | 824 | nested_name_specifier SELFNAME '(' |
b4c4a9ec | 825 | { $$ = begin_constructor_declarator ($1, $2); } |
c11b6f21 MS |
826 | parmlist ')' cv_qualifiers exception_specification_opt |
827 | { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); } | |
828 | | nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt | |
84d901be | 829 | { $$ = begin_constructor_declarator ($1, $2); |
c11b6f21 | 830 | $$ = make_call_declarator ($$, empty_parms (), $4, $5); |
c91a56d2 | 831 | } |
84d901be | 832 | | global_scope nested_name_specifier SELFNAME '(' |
b4c4a9ec | 833 | { $$ = begin_constructor_declarator ($2, $3); } |
c11b6f21 MS |
834 | parmlist ')' cv_qualifiers exception_specification_opt |
835 | { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); } | |
836 | | global_scope nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt | |
b4c4a9ec | 837 | { $$ = begin_constructor_declarator ($2, $3); |
c11b6f21 | 838 | $$ = make_call_declarator ($$, empty_parms (), $5, $6); |
c91a56d2 | 839 | } |
84d901be | 840 | | nested_name_specifier self_template_type '(' |
b4c4a9ec | 841 | { $$ = begin_constructor_declarator ($1, $2); } |
c11b6f21 MS |
842 | parmlist ')' cv_qualifiers exception_specification_opt |
843 | { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); } | |
844 | | nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt | |
b4c4a9ec | 845 | { $$ = begin_constructor_declarator ($1, $2); |
c11b6f21 | 846 | $$ = make_call_declarator ($$, empty_parms (), $4, $5); |
67d743fe | 847 | } |
84d901be | 848 | | global_scope nested_name_specifier self_template_type '(' |
b4c4a9ec | 849 | { $$ = begin_constructor_declarator ($2, $3); } |
c11b6f21 MS |
850 | parmlist ')' cv_qualifiers exception_specification_opt |
851 | { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); } | |
852 | | global_scope nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt | |
84d901be | 853 | { $$ = begin_constructor_declarator ($2, $3); |
c11b6f21 | 854 | $$ = make_call_declarator ($$, empty_parms (), $5, $6); |
67d743fe | 855 | } |
c91a56d2 MS |
856 | ; |
857 | ||
8d08fdba | 858 | fn.def1: |
c11b6f21 | 859 | typed_declspecs declarator |
2bdb0643 | 860 | { check_for_new_type ("return type", $1); |
15c7fb9c | 861 | if (!parse_begin_function_definition ($1.t, $2)) |
b4c4a9ec | 862 | YYERROR1; } |
c11b6f21 | 863 | | declmods notype_declarator |
15c7fb9c | 864 | { if (!parse_begin_function_definition ($1.t, $2)) |
b4c4a9ec | 865 | YYERROR1; } |
c11b6f21 | 866 | | notype_declarator |
15c7fb9c | 867 | { if (!parse_begin_function_definition (NULL_TREE, $1)) |
b4c4a9ec | 868 | YYERROR1; } |
c11b6f21 | 869 | | declmods constructor_declarator |
15c7fb9c | 870 | { if (!parse_begin_function_definition ($1.t, $2)) |
b4c4a9ec | 871 | YYERROR1; } |
c11b6f21 | 872 | | constructor_declarator |
15c7fb9c | 873 | { if (!parse_begin_function_definition (NULL_TREE, $1)) |
b4c4a9ec | 874 | YYERROR1; } |
8d08fdba MS |
875 | ; |
876 | ||
4806765e AH |
877 | /* ANSI allows optional parentheses around constructor class names. |
878 | See ISO/IEC 14882:1998(E) 12.1. */ | |
879 | ||
a80e4195 | 880 | component_constructor_declarator: |
4806765e AH |
881 | SELFNAME '(' parmlist ')' cv_qualifiers exception_specification_opt |
882 | { $$ = make_call_declarator ($1, $3, $5, $6); } | |
883 | | '(' SELFNAME ')' '(' parmlist ')' cv_qualifiers | |
884 | exception_specification_opt | |
885 | { $$ = make_call_declarator ($2, $5, $7, $8); } | |
886 | | SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt | |
887 | { $$ = make_call_declarator ($1, empty_parms (), $3, $4); } | |
888 | | '(' SELFNAME ')' LEFT_RIGHT cv_qualifiers exception_specification_opt | |
889 | { $$ = make_call_declarator ($2, empty_parms (), $5, $6); } | |
c11b6f21 MS |
890 | | self_template_type '(' parmlist ')' cv_qualifiers exception_specification_opt |
891 | { $$ = make_call_declarator ($1, $3, $5, $6); } | |
892 | | self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt | |
893 | { $$ = make_call_declarator ($1, empty_parms (), $3, $4); } | |
a80e4195 MS |
894 | ; |
895 | ||
51c184be MS |
896 | /* more C++ complexity. See component_decl for a comment on the |
897 | reduce/reduce conflict introduced by these rules. */ | |
e2500fed | 898 | fn_def2: |
c11b6f21 | 899 | declmods component_constructor_declarator |
1f51a992 | 900 | { $$ = parse_method ($2, $1.t, $1.lookups); |
a28e3c7f | 901 | rest_of_mdef: |
8d08fdba MS |
902 | if (! $$) |
903 | YYERROR1; | |
904 | if (yychar == YYEMPTY) | |
905 | yychar = YYLEX; | |
0e5921e8 | 906 | snarf_method ($$); } |
c11b6f21 | 907 | | component_constructor_declarator |
84d901be | 908 | { $$ = parse_method ($1, NULL_TREE, NULL_TREE); |
acf82af2 | 909 | goto rest_of_mdef; } |
c11b6f21 | 910 | | typed_declspecs declarator |
1f51a992 | 911 | { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;} |
c11b6f21 | 912 | | declmods notype_declarator |
1f51a992 | 913 | { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;} |
c11b6f21 | 914 | | notype_declarator |
84d901be | 915 | { $$ = parse_method ($1, NULL_TREE, NULL_TREE); |
acf82af2 | 916 | goto rest_of_mdef; } |
c11b6f21 | 917 | | declmods constructor_declarator |
1f51a992 | 918 | { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;} |
c11b6f21 | 919 | | constructor_declarator |
84d901be | 920 | { $$ = parse_method ($1, NULL_TREE, NULL_TREE); |
acf82af2 | 921 | goto rest_of_mdef; } |
8d08fdba MS |
922 | ; |
923 | ||
c11b6f21 | 924 | return_id: |
3dcaad8b | 925 | RETURN_KEYWORD IDENTIFIER |
8d08fdba | 926 | { |
8d08fdba MS |
927 | $$ = $2; |
928 | } | |
929 | ; | |
930 | ||
c11b6f21 MS |
931 | return_init: |
932 | return_id maybe_init | |
558475f0 | 933 | { finish_named_return_value ($<ttype>$, $2); } |
8d08fdba | 934 | | return_id '(' nonnull_exprlist ')' |
558475f0 | 935 | { finish_named_return_value ($<ttype>$, $3); } |
8d08fdba | 936 | | return_id LEFT_RIGHT |
558475f0 | 937 | { finish_named_return_value ($<ttype>$, NULL_TREE); } |
8d08fdba MS |
938 | ; |
939 | ||
940 | base_init: | |
da15dae6 | 941 | ':' { begin_mem_initializers (); } member_init_list |
8d08fdba | 942 | { |
da15dae6 | 943 | if ($3.new_type_flag == 0) |
fd74ca0b | 944 | error ("no base or member initializers given following ':'"); |
da15dae6 | 945 | finish_mem_initializers ($3.t); |
8d08fdba MS |
946 | } |
947 | ; | |
948 | ||
e2500fed | 949 | begin_function_body_: |
c11b6f21 | 950 | /* empty */ |
8d08fdba | 951 | { |
ade3dc07 | 952 | $$ = begin_function_body (); |
8d08fdba MS |
953 | } |
954 | ; | |
955 | ||
956 | member_init_list: | |
957 | /* empty */ | |
84d901be AD |
958 | { |
959 | $$.new_type_flag = 0; | |
960 | $$.t = NULL_TREE; | |
fd74ca0b | 961 | } |
8d08fdba | 962 | | member_init |
84d901be AD |
963 | { |
964 | $$.new_type_flag = 1; | |
965 | $$.t = $1; | |
fd74ca0b | 966 | } |
8d08fdba | 967 | | member_init_list ',' member_init |
84d901be AD |
968 | { |
969 | if ($3) | |
fd74ca0b | 970 | { |
84d901be | 971 | $$.new_type_flag = 1; |
fd74ca0b MM |
972 | TREE_CHAIN ($3) = $1.t; |
973 | $$.t = $3; | |
974 | } | |
975 | else | |
976 | $$ = $1; | |
977 | } | |
8d08fdba MS |
978 | | member_init_list error |
979 | ; | |
980 | ||
c11b6f21 MS |
981 | member_init: |
982 | '(' nonnull_exprlist ')' | |
8d08fdba | 983 | { |
d22c8596 | 984 | if (current_class_name) |
8251199e | 985 | pedwarn ("anachronistic old style base class initializer"); |
2282d28d | 986 | $$ = expand_member_init (NULL_TREE, $2); |
8d08fdba MS |
987 | } |
988 | | LEFT_RIGHT | |
989 | { | |
d22c8596 | 990 | if (current_class_name) |
8251199e | 991 | pedwarn ("anachronistic old style base class initializer"); |
2282d28d | 992 | $$ = expand_member_init (NULL_TREE, |
fd74ca0b | 993 | void_type_node); |
8d08fdba | 994 | } |
a28e3c7f | 995 | | notype_identifier '(' nonnull_exprlist ')' |
2282d28d | 996 | { $$ = expand_member_init ($1, $3); } |
a28e3c7f | 997 | | notype_identifier LEFT_RIGHT |
2282d28d | 998 | { $$ = expand_member_init ($1, void_type_node); } |
405a745b | 999 | | nonnested_type '(' nonnull_exprlist ')' |
2282d28d | 1000 | { $$ = expand_member_init ($1, $3); } |
405a745b | 1001 | | nonnested_type LEFT_RIGHT |
2282d28d | 1002 | { $$ = expand_member_init ($1, void_type_node); } |
405a745b | 1003 | | typename_sub '(' nonnull_exprlist ')' |
2282d28d | 1004 | { $$ = expand_member_init ($1, $3); } |
405a745b | 1005 | | typename_sub LEFT_RIGHT |
2282d28d | 1006 | { $$ = expand_member_init ($1, void_type_node); } |
273a708f | 1007 | | error |
6a1fa5f9 | 1008 | { $$ = NULL_TREE; } |
8d08fdba MS |
1009 | ; |
1010 | ||
1011 | identifier: | |
1012 | IDENTIFIER | |
84d901be | 1013 | | tTYPENAME |
a80e4195 | 1014 | | SELFNAME |
8d08fdba | 1015 | | PTYPENAME |
6060a796 | 1016 | | NSNAME |
8d08fdba MS |
1017 | ; |
1018 | ||
a28e3c7f MS |
1019 | notype_identifier: |
1020 | IDENTIFIER | |
84d901be | 1021 | | PTYPENAME |
c11b6f21 | 1022 | | NSNAME %prec EMPTY |
a28e3c7f MS |
1023 | ; |
1024 | ||
8d08fdba MS |
1025 | identifier_defn: |
1026 | IDENTIFIER_DEFN | |
1027 | | TYPENAME_DEFN | |
1028 | | PTYPENAME_DEFN | |
1029 | ; | |
1030 | ||
8d08fdba | 1031 | explicit_instantiation: |
75650646 | 1032 | TEMPLATE begin_explicit_instantiation typespec ';' |
a1bcc528 | 1033 | { do_type_instantiation ($3.t, NULL_TREE, 1); |
ca79f85d | 1034 | yyungetc (';', 1); } |
75650646 MM |
1035 | end_explicit_instantiation |
1036 | | TEMPLATE begin_explicit_instantiation typed_declspecs declarator | |
46b02c6d | 1037 | { tree specs = strip_attrs ($3.t); |
eb8845be | 1038 | parse_decl_instantiation (specs, $4, NULL_TREE); } |
75650646 MM |
1039 | end_explicit_instantiation |
1040 | | TEMPLATE begin_explicit_instantiation notype_declarator | |
eb8845be | 1041 | { parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); } |
75650646 MM |
1042 | end_explicit_instantiation |
1043 | | TEMPLATE begin_explicit_instantiation constructor_declarator | |
eb8845be | 1044 | { parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); } |
75650646 MM |
1045 | end_explicit_instantiation |
1046 | | SCSPEC TEMPLATE begin_explicit_instantiation typespec ';' | |
a1bcc528 | 1047 | { do_type_instantiation ($4.t, $1, 1); |
75650646 MM |
1048 | yyungetc (';', 1); } |
1049 | end_explicit_instantiation | |
84d901be AD |
1050 | {} |
1051 | | SCSPEC TEMPLATE begin_explicit_instantiation typed_declspecs | |
75650646 MM |
1052 | declarator |
1053 | { tree specs = strip_attrs ($4.t); | |
eb8845be | 1054 | parse_decl_instantiation (specs, $5, $1); } |
75650646 | 1055 | end_explicit_instantiation |
84d901be | 1056 | {} |
75650646 | 1057 | | SCSPEC TEMPLATE begin_explicit_instantiation notype_declarator |
eb8845be | 1058 | { parse_decl_instantiation (NULL_TREE, $4, $1); } |
75650646 | 1059 | end_explicit_instantiation |
84d901be | 1060 | {} |
75650646 | 1061 | | SCSPEC TEMPLATE begin_explicit_instantiation constructor_declarator |
eb8845be | 1062 | { parse_decl_instantiation (NULL_TREE, $4, $1); } |
75650646 | 1063 | end_explicit_instantiation |
84d901be | 1064 | {} |
75650646 MM |
1065 | ; |
1066 | ||
84d901be | 1067 | begin_explicit_instantiation: |
75650646 | 1068 | { begin_explicit_instantiation(); } |
224e6091 | 1069 | ; |
75650646 | 1070 | |
84d901be | 1071 | end_explicit_instantiation: |
75650646 | 1072 | { end_explicit_instantiation(); } |
224e6091 | 1073 | ; |
8d08fdba | 1074 | |
5566b478 MS |
1075 | /* The TYPENAME expansions are to deal with use of a template class name as |
1076 | a template within the class itself, where the template decl is hidden by | |
1077 | a type decl. Got all that? */ | |
8d08fdba | 1078 | |
5566b478 | 1079 | template_type: |
75650646 | 1080 | PTYPENAME '<' template_arg_list_opt template_close_bracket |
e2500fed | 1081 | finish_template_type_ |
36a117a5 | 1082 | { $$ = $5; } |
84d901be | 1083 | | tTYPENAME '<' template_arg_list_opt template_close_bracket |
e2500fed | 1084 | finish_template_type_ |
36a117a5 | 1085 | { $$ = $5; } |
67d743fe MS |
1086 | | self_template_type |
1087 | ; | |
1088 | ||
2e6eddfc AO |
1089 | apparent_template_type: |
1090 | template_type | |
1091 | | identifier '<' template_arg_list_opt '>' | |
e2500fed | 1092 | finish_template_type_ |
f3400fe2 | 1093 | { $$ = $5; } |
224e6091 | 1094 | ; |
2e6eddfc | 1095 | |
67d743fe | 1096 | self_template_type: |
75650646 | 1097 | SELFNAME '<' template_arg_list_opt template_close_bracket |
e2500fed | 1098 | finish_template_type_ |
36a117a5 | 1099 | { $$ = $5; } |
8d08fdba MS |
1100 | ; |
1101 | ||
e2500fed | 1102 | finish_template_type_: |
84d901be | 1103 | { |
36a117a5 MM |
1104 | if (yychar == YYEMPTY) |
1105 | yychar = YYLEX; | |
1106 | ||
84d901be | 1107 | $$ = finish_template_type ($<ttype>-3, $<ttype>-1, |
36a117a5 MM |
1108 | yychar == SCOPE); |
1109 | } | |
224e6091 | 1110 | ; |
36a117a5 | 1111 | |
5566b478 MS |
1112 | template_close_bracket: |
1113 | '>' | |
84d901be | 1114 | | RSHIFT |
5566b478 MS |
1115 | { |
1116 | /* Handle `Class<Class<Type>>' without space in the `>>' */ | |
8251199e | 1117 | pedwarn ("`>>' should be `> >' in template class name"); |
5566b478 MS |
1118 | yyungetc ('>', 1); |
1119 | } | |
8d08fdba MS |
1120 | ; |
1121 | ||
75650646 MM |
1122 | template_arg_list_opt: |
1123 | /* empty */ | |
1124 | { $$ = NULL_TREE; } | |
1125 | | template_arg_list | |
1126 | ; | |
1127 | ||
8d08fdba | 1128 | template_arg_list: |
75650646 | 1129 | template_arg |
8d08fdba MS |
1130 | { $$ = build_tree_list (NULL_TREE, $$); } |
1131 | | template_arg_list ',' template_arg | |
1132 | { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); } | |
1133 | ; | |
1134 | ||
1135 | template_arg: | |
51c184be | 1136 | type_id |
46b02c6d | 1137 | { $$ = groktypename ($1.t); } |
0e607f34 | 1138 | | PTYPENAME |
1899c3a4 KL |
1139 | { |
1140 | $$ = lastiddecl; | |
1141 | if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$)) | |
1142 | $$ = TREE_TYPE ($$); | |
1143 | } | |
fa1f3ebc KL |
1144 | | global_scope PTYPENAME |
1145 | { | |
1146 | $$ = lastiddecl; | |
1147 | if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$)) | |
1148 | $$ = TREE_TYPE ($$); | |
1149 | } | |
ca5e04b2 | 1150 | | expr_no_comma_rangle |
b8c6534b KL |
1151 | | nested_name_specifier TEMPLATE identifier |
1152 | { | |
1153 | if (!processing_template_decl) | |
1154 | { | |
33bd39a2 | 1155 | error ("use of template qualifier outside template"); |
b8c6534b KL |
1156 | $$ = error_mark_node; |
1157 | } | |
1158 | else | |
0e902d98 | 1159 | $$ = make_unbound_class_template ($1, $3, tf_error | tf_parsing); |
b8c6534b | 1160 | } |
8d08fdba MS |
1161 | ; |
1162 | ||
c11b6f21 MS |
1163 | unop: |
1164 | '-' | |
8d08fdba MS |
1165 | { $$ = NEGATE_EXPR; } |
1166 | | '+' | |
1167 | { $$ = CONVERT_EXPR; } | |
1168 | | PLUSPLUS | |
1169 | { $$ = PREINCREMENT_EXPR; } | |
1170 | | MINUSMINUS | |
1171 | { $$ = PREDECREMENT_EXPR; } | |
1172 | | '!' | |
1173 | { $$ = TRUTH_NOT_EXPR; } | |
1174 | ; | |
1175 | ||
c11b6f21 MS |
1176 | expr: |
1177 | nontrivial_exprlist | |
8d08fdba | 1178 | { $$ = build_x_compound_expr ($$); } |
8d08fdba MS |
1179 | | expr_no_commas |
1180 | ; | |
1181 | ||
1182 | paren_expr_or_null: | |
1183 | LEFT_RIGHT | |
cab1f180 | 1184 | { error ("ISO C++ forbids an empty condition for `%s'", |
8d08fdba MS |
1185 | cond_stmt_keyword); |
1186 | $$ = integer_zero_node; } | |
1187 | | '(' expr ')' | |
ad321293 | 1188 | { $$ = $2; } |
8d08fdba MS |
1189 | ; |
1190 | ||
1191 | paren_cond_or_null: | |
1192 | LEFT_RIGHT | |
cab1f180 | 1193 | { error ("ISO C++ forbids an empty condition for `%s'", |
8d08fdba MS |
1194 | cond_stmt_keyword); |
1195 | $$ = integer_zero_node; } | |
1196 | | '(' condition ')' | |
ad321293 | 1197 | { $$ = $2; } |
8d08fdba MS |
1198 | ; |
1199 | ||
1200 | xcond: | |
c11b6f21 | 1201 | /* empty */ |
8d08fdba MS |
1202 | { $$ = NULL_TREE; } |
1203 | | condition | |
1204 | | error | |
1205 | { $$ = NULL_TREE; } | |
1206 | ; | |
1207 | ||
1208 | condition: | |
c11b6f21 | 1209 | type_specifier_seq declarator maybeasm maybe_attribute '=' |
8d08fdba MS |
1210 | { { |
1211 | tree d; | |
1212 | for (d = getdecls (); d; d = TREE_CHAIN (d)) | |
1213 | if (TREE_CODE (d) == TYPE_DECL) { | |
1214 | tree s = TREE_TYPE (d); | |
1215 | if (TREE_CODE (s) == RECORD_TYPE) | |
33bd39a2 | 1216 | error ("definition of class `%T' in condition", s); |
8d08fdba | 1217 | else if (TREE_CODE (s) == ENUMERAL_TYPE) |
33bd39a2 | 1218 | error ("definition of enum `%T' in condition", s); |
8d08fdba MS |
1219 | } |
1220 | } | |
46b02c6d | 1221 | current_declspecs = $1.t; |
1f51a992 | 1222 | $<ttype>$ = parse_decl ($<ttype>2, $4, 1); |
8d08fdba | 1223 | } |
c11b6f21 | 1224 | init |
84d901be | 1225 | { |
1f51a992 | 1226 | parse_end_decl ($<ttype>6, $7, $4); |
84d901be | 1227 | $$ = convert_from_reference ($<ttype>6); |
8d08fdba | 1228 | if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE) |
84d901be | 1229 | error ("definition of array `%#D' in condition", $$); |
8d08fdba MS |
1230 | } |
1231 | | expr | |
1232 | ; | |
1233 | ||
863adfc0 MS |
1234 | compstmtend: |
1235 | '}' | |
1236 | | maybe_label_decls stmts '}' | |
1237 | | maybe_label_decls stmts error '}' | |
1238 | | maybe_label_decls error '}' | |
1239 | ; | |
1240 | ||
51c184be MS |
1241 | nontrivial_exprlist: |
1242 | expr_no_commas ',' expr_no_commas | |
84d901be | 1243 | { $$ = tree_cons (NULL_TREE, $$, |
051e6fd7 | 1244 | build_tree_list (NULL_TREE, $3)); } |
51c184be | 1245 | | expr_no_commas ',' error |
84d901be | 1246 | { $$ = tree_cons (NULL_TREE, $$, |
051e6fd7 | 1247 | build_tree_list (NULL_TREE, error_mark_node)); } |
51c184be | 1248 | | nontrivial_exprlist ',' expr_no_commas |
051e6fd7 | 1249 | { chainon ($$, build_tree_list (NULL_TREE, $3)); } |
51c184be | 1250 | | nontrivial_exprlist ',' error |
051e6fd7 | 1251 | { chainon ($$, build_tree_list (NULL_TREE, error_mark_node)); } |
51c184be MS |
1252 | ; |
1253 | ||
8d08fdba MS |
1254 | nonnull_exprlist: |
1255 | expr_no_commas | |
051e6fd7 | 1256 | { $$ = build_tree_list (NULL_TREE, $$); } |
51c184be | 1257 | | nontrivial_exprlist |
8d08fdba MS |
1258 | ; |
1259 | ||
1260 | unary_expr: | |
c11b6f21 | 1261 | primary %prec UNARY |
4ac14744 | 1262 | { $$ = $1; } |
8d08fdba | 1263 | /* __extension__ turns off -pedantic for following primary. */ |
de22184b MS |
1264 | | extension cast_expr %prec UNARY |
1265 | { $$ = $2; | |
fd65a4c1 | 1266 | pedantic = $1; } |
8d08fdba MS |
1267 | | '*' cast_expr %prec UNARY |
1268 | { $$ = build_x_indirect_ref ($2, "unary *"); } | |
1269 | | '&' cast_expr %prec UNARY | |
1270 | { $$ = build_x_unary_op (ADDR_EXPR, $2); } | |
51c184be | 1271 | | '~' cast_expr |
8d08fdba MS |
1272 | { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); } |
1273 | | unop cast_expr %prec UNARY | |
ce4a0391 | 1274 | { $$ = finish_unary_op_expr ($1, $2); } |
8d08fdba MS |
1275 | /* Refer to the address of a label as a pointer. */ |
1276 | | ANDAND identifier | |
8e93d446 | 1277 | { $$ = finish_label_address_expr ($2); } |
c01b9ec8 AO |
1278 | | sizeof unary_expr %prec UNARY |
1279 | { $$ = finish_sizeof ($2); | |
1280 | skip_evaluation--; } | |
1281 | | sizeof '(' type_id ')' %prec HYPERUNARY | |
0213a355 | 1282 | { $$ = finish_sizeof (groktypename ($3.t)); |
c01b9ec8 AO |
1283 | check_for_new_type ("sizeof", $3); |
1284 | skip_evaluation--; } | |
1285 | | alignof unary_expr %prec UNARY | |
1286 | { $$ = finish_alignof ($2); | |
1287 | skip_evaluation--; } | |
1288 | | alignof '(' type_id ')' %prec HYPERUNARY | |
84d901be | 1289 | { $$ = finish_alignof (groktypename ($3.t)); |
c01b9ec8 AO |
1290 | check_for_new_type ("alignof", $3); |
1291 | skip_evaluation--; } | |
8d08fdba | 1292 | |
39211cd5 MS |
1293 | /* The %prec EMPTY's here are required by the = init initializer |
1294 | syntax extension; see below. */ | |
c11b6f21 | 1295 | | new new_type_id %prec EMPTY |
84d901be | 1296 | { $$ = build_new (NULL_TREE, $2.t, NULL_TREE, $1); |
46b02c6d | 1297 | check_for_new_type ("new", $2); } |
39211cd5 | 1298 | | new new_type_id new_initializer |
84d901be | 1299 | { $$ = build_new (NULL_TREE, $2.t, $3, $1); |
46b02c6d | 1300 | check_for_new_type ("new", $2); } |
c11b6f21 | 1301 | | new new_placement new_type_id %prec EMPTY |
84d901be | 1302 | { $$ = build_new ($2, $3.t, NULL_TREE, $1); |
46b02c6d | 1303 | check_for_new_type ("new", $3); } |
39211cd5 | 1304 | | new new_placement new_type_id new_initializer |
84d901be | 1305 | { $$ = build_new ($2, $3.t, $4, $1); |
46b02c6d | 1306 | check_for_new_type ("new", $3); } |
80048418 | 1307 | | new '(' type_id ')' |
6d73fddc | 1308 | %prec EMPTY |
80048418 | 1309 | { $$ = build_new (NULL_TREE, groktypename($3.t), |
84d901be | 1310 | NULL_TREE, $1); |
80048418 MM |
1311 | check_for_new_type ("new", $3); } |
1312 | | new '(' type_id ')' new_initializer | |
84d901be | 1313 | { $$ = build_new (NULL_TREE, groktypename($3.t), $5, $1); |
80048418 MM |
1314 | check_for_new_type ("new", $3); } |
1315 | | new new_placement '(' type_id ')' %prec EMPTY | |
84d901be | 1316 | { $$ = build_new ($2, groktypename($4.t), NULL_TREE, $1); |
1702d32e | 1317 | check_for_new_type ("new", $4); } |
80048418 | 1318 | | new new_placement '(' type_id ')' new_initializer |
84d901be | 1319 | { $$ = build_new ($2, groktypename($4.t), $6, $1); |
46b02c6d | 1320 | check_for_new_type ("new", $4); } |
8d08fdba MS |
1321 | |
1322 | | delete cast_expr %prec UNARY | |
a28e3c7f | 1323 | { $$ = delete_sanity ($2, NULL_TREE, 0, $1); } |
8d08fdba | 1324 | | delete '[' ']' cast_expr %prec UNARY |
a28e3c7f | 1325 | { $$ = delete_sanity ($4, NULL_TREE, 1, $1); |
8d08fdba MS |
1326 | if (yychar == YYEMPTY) |
1327 | yychar = YYLEX; } | |
c11b6f21 | 1328 | | delete '[' expr ']' cast_expr %prec UNARY |
a28e3c7f | 1329 | { $$ = delete_sanity ($5, $3, 2, $1); |
8d08fdba MS |
1330 | if (yychar == YYEMPTY) |
1331 | yychar = YYLEX; } | |
37c46b43 MS |
1332 | | REALPART cast_expr %prec UNARY |
1333 | { $$ = build_x_unary_op (REALPART_EXPR, $2); } | |
1334 | | IMAGPART cast_expr %prec UNARY | |
1335 | { $$ = build_x_unary_op (IMAGPART_EXPR, $2); } | |
8d08fdba MS |
1336 | ; |
1337 | ||
39211cd5 | 1338 | new_placement: |
80048418 MM |
1339 | '(' nonnull_exprlist ')' |
1340 | { $$ = $2; } | |
1341 | | '{' nonnull_exprlist '}' | |
33bd39a2 | 1342 | { pedwarn ("old style placement syntax, use () instead"); |
80048418 | 1343 | $$ = $2; } |
39211cd5 MS |
1344 | ; |
1345 | ||
1346 | new_initializer: | |
1347 | '(' nonnull_exprlist ')' | |
1348 | { $$ = $2; } | |
1349 | | LEFT_RIGHT | |
f30efcb7 | 1350 | { $$ = void_zero_node; } |
39211cd5 MS |
1351 | | '(' typespec ')' |
1352 | { | |
33bd39a2 | 1353 | error ("`%T' is not a valid expression", $2.t); |
39211cd5 MS |
1354 | $$ = error_mark_node; |
1355 | } | |
39211cd5 MS |
1356 | | '=' init |
1357 | { | |
8e3df2de MM |
1358 | /* This was previously allowed as an extension, but |
1359 | was removed in G++ 3.3. */ | |
1360 | error ("initialization of new expression with `='"); | |
1361 | $$ = error_mark_node; | |
39211cd5 MS |
1362 | } |
1363 | ; | |
1364 | ||
51c184be MS |
1365 | /* This is necessary to postpone reduction of `int ((int)(int)(int))'. */ |
1366 | regcast_or_absdcl: | |
c11b6f21 | 1367 | '(' type_id ')' %prec EMPTY |
ce4a0391 | 1368 | { $2.t = finish_parmlist (build_tree_list (NULL_TREE, $2.t), 0); |
c11b6f21 | 1369 | $$ = make_call_declarator (NULL_TREE, $2.t, NULL_TREE, NULL_TREE); |
46b02c6d | 1370 | check_for_new_type ("cast", $2); } |
c11b6f21 | 1371 | | regcast_or_absdcl '(' type_id ')' %prec EMPTY |
84d901be | 1372 | { $3.t = finish_parmlist (build_tree_list (NULL_TREE, $3.t), 0); |
c11b6f21 | 1373 | $$ = make_call_declarator ($$, $3.t, NULL_TREE, NULL_TREE); |
46b02c6d | 1374 | check_for_new_type ("cast", $3); } |
51c184be MS |
1375 | ; |
1376 | ||
8d08fdba | 1377 | cast_expr: |
f30432d7 MS |
1378 | unary_expr |
1379 | | regcast_or_absdcl unary_expr %prec UNARY | |
51c184be MS |
1380 | { $$ = reparse_absdcl_as_casts ($$, $2); } |
1381 | | regcast_or_absdcl '{' initlist maybecomma '}' %prec UNARY | |
84d901be | 1382 | { |
51c184be | 1383 | tree init = build_nt (CONSTRUCTOR, NULL_TREE, |
84d901be | 1384 | nreverse ($3)); |
b7484fbe | 1385 | if (pedantic) |
14fc3426 JM |
1386 | pedwarn ("ISO C++ forbids compound literals"); |
1387 | /* Indicate that this was a C99 compound literal. */ | |
51c184be | 1388 | TREE_HAS_CONSTRUCTOR (init) = 1; |
8d08fdba | 1389 | |
51c184be | 1390 | $$ = reparse_absdcl_as_casts ($$, init); |
8d08fdba | 1391 | } |
51c184be MS |
1392 | ; |
1393 | ||
8d08fdba MS |
1394 | expr_no_commas: |
1395 | cast_expr | |
51c184be MS |
1396 | /* Handle general members. */ |
1397 | | expr_no_commas POINTSAT_STAR expr_no_commas | |
1398 | { $$ = build_x_binary_op (MEMBER_REF, $$, $3); } | |
1399 | | expr_no_commas DOT_STAR expr_no_commas | |
1400 | { $$ = build_m_component_ref ($$, $3); } | |
8d08fdba MS |
1401 | | expr_no_commas '+' expr_no_commas |
1402 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1403 | | expr_no_commas '-' expr_no_commas | |
1404 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1405 | | expr_no_commas '*' expr_no_commas | |
1406 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1407 | | expr_no_commas '/' expr_no_commas | |
1408 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1409 | | expr_no_commas '%' expr_no_commas | |
1410 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1411 | | expr_no_commas LSHIFT expr_no_commas | |
1412 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1413 | | expr_no_commas RSHIFT expr_no_commas | |
1414 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1415 | | expr_no_commas ARITHCOMPARE expr_no_commas | |
1416 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1417 | | expr_no_commas '<' expr_no_commas | |
1418 | { $$ = build_x_binary_op (LT_EXPR, $$, $3); } | |
1419 | | expr_no_commas '>' expr_no_commas | |
1420 | { $$ = build_x_binary_op (GT_EXPR, $$, $3); } | |
1421 | | expr_no_commas EQCOMPARE expr_no_commas | |
1422 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1423 | | expr_no_commas MIN_MAX expr_no_commas | |
1424 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1425 | | expr_no_commas '&' expr_no_commas | |
1426 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1427 | | expr_no_commas '|' expr_no_commas | |
1428 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1429 | | expr_no_commas '^' expr_no_commas | |
1430 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1431 | | expr_no_commas ANDAND expr_no_commas | |
1432 | { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); } | |
1433 | | expr_no_commas OROR expr_no_commas | |
1434 | { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); } | |
1435 | | expr_no_commas '?' xexpr ':' expr_no_commas | |
1436 | { $$ = build_x_conditional_expr ($$, $3, $5); } | |
1437 | | expr_no_commas '=' expr_no_commas | |
5566b478 | 1438 | { $$ = build_x_modify_expr ($$, NOP_EXPR, $3); |
d2e5ee5c MS |
1439 | if ($$ != error_mark_node) |
1440 | C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); } | |
8d08fdba | 1441 | | expr_no_commas ASSIGN expr_no_commas |
5566b478 | 1442 | { $$ = build_x_modify_expr ($$, $2, $3); } |
8d2733ca MS |
1443 | | THROW |
1444 | { $$ = build_throw (NULL_TREE); } | |
1445 | | THROW expr_no_commas | |
1446 | { $$ = build_throw ($2); } | |
ca5e04b2 NS |
1447 | ; |
1448 | ||
1449 | expr_no_comma_rangle: | |
1450 | cast_expr | |
1451 | /* Handle general members. */ | |
1452 | | expr_no_comma_rangle POINTSAT_STAR expr_no_comma_rangle | |
1453 | { $$ = build_x_binary_op (MEMBER_REF, $$, $3); } | |
1454 | | expr_no_comma_rangle DOT_STAR expr_no_comma_rangle | |
1455 | { $$ = build_m_component_ref ($$, $3); } | |
1456 | | expr_no_comma_rangle '+' expr_no_comma_rangle | |
1457 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1458 | | expr_no_comma_rangle '-' expr_no_comma_rangle | |
1459 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1460 | | expr_no_comma_rangle '*' expr_no_comma_rangle | |
1461 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1462 | | expr_no_comma_rangle '/' expr_no_comma_rangle | |
1463 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1464 | | expr_no_comma_rangle '%' expr_no_comma_rangle | |
1465 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1466 | | expr_no_comma_rangle LSHIFT expr_no_comma_rangle | |
1467 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1468 | | expr_no_comma_rangle RSHIFT expr_no_comma_rangle | |
1469 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1470 | | expr_no_comma_rangle ARITHCOMPARE expr_no_comma_rangle | |
1471 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1472 | | expr_no_comma_rangle '<' expr_no_comma_rangle | |
1473 | { $$ = build_x_binary_op (LT_EXPR, $$, $3); } | |
1474 | | expr_no_comma_rangle EQCOMPARE expr_no_comma_rangle | |
1475 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1476 | | expr_no_comma_rangle MIN_MAX expr_no_comma_rangle | |
1477 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1478 | | expr_no_comma_rangle '&' expr_no_comma_rangle | |
1479 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1480 | | expr_no_comma_rangle '|' expr_no_comma_rangle | |
1481 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1482 | | expr_no_comma_rangle '^' expr_no_comma_rangle | |
1483 | { $$ = build_x_binary_op ($2, $$, $3); } | |
1484 | | expr_no_comma_rangle ANDAND expr_no_comma_rangle | |
1485 | { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); } | |
1486 | | expr_no_comma_rangle OROR expr_no_comma_rangle | |
1487 | { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); } | |
1488 | | expr_no_comma_rangle '?' xexpr ':' expr_no_comma_rangle | |
1489 | { $$ = build_x_conditional_expr ($$, $3, $5); } | |
1490 | | expr_no_comma_rangle '=' expr_no_comma_rangle | |
1491 | { $$ = build_x_modify_expr ($$, NOP_EXPR, $3); | |
1492 | if ($$ != error_mark_node) | |
1493 | C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); } | |
1494 | | expr_no_comma_rangle ASSIGN expr_no_comma_rangle | |
1495 | { $$ = build_x_modify_expr ($$, $2, $3); } | |
1496 | | THROW | |
1497 | { $$ = build_throw (NULL_TREE); } | |
1498 | | THROW expr_no_comma_rangle | |
1499 | { $$ = build_throw ($2); } | |
8d08fdba MS |
1500 | ; |
1501 | ||
51c184be | 1502 | notype_unqualified_id: |
a28e3c7f | 1503 | '~' see_typename identifier |
718b8ea5 | 1504 | { $$ = build_nt (BIT_NOT_EXPR, $3); } |
eab049e2 | 1505 | | '~' see_typename template_type |
718b8ea5 | 1506 | { $$ = build_nt (BIT_NOT_EXPR, $3); } |
386b8a85 | 1507 | | template_id |
8d08fdba | 1508 | | operator_name |
51c184be | 1509 | | IDENTIFIER |
6060a796 | 1510 | | PTYPENAME |
c11b6f21 | 1511 | | NSNAME %prec EMPTY |
51c184be MS |
1512 | ; |
1513 | ||
46422d6c | 1514 | do_id: |
161c12b0 | 1515 | { |
50ad9642 MM |
1516 | /* If lastiddecl is a BASELINK we're in an |
1517 | expression like S::f<int>, so don't | |
1518 | do_identifier; we only do that for unqualified | |
161c12b0 | 1519 | identifiers. */ |
50ad9642 | 1520 | if (!lastiddecl || !BASELINK_P (lastiddecl)) |
77631fa7 | 1521 | $$ = do_identifier ($<ttype>-1, 3, NULL_TREE); |
161c12b0 JM |
1522 | else |
1523 | $$ = $<ttype>-1; | |
1524 | } | |
224e6091 | 1525 | ; |
46422d6c | 1526 | |
386b8a85 | 1527 | template_id: |
84d901be | 1528 | PFUNCNAME '<' do_id template_arg_list_opt template_close_bracket |
4ba126e4 MM |
1529 | { |
1530 | tree template_name = $3; | |
1531 | if (TREE_CODE (template_name) == COMPONENT_REF) | |
1532 | template_name = TREE_OPERAND (template_name, 1); | |
1533 | $$ = lookup_template_function (template_name, $4); | |
1534 | } | |
75650646 | 1535 | | operator_name '<' do_id template_arg_list_opt template_close_bracket |
4ba126e4 MM |
1536 | { |
1537 | tree template_name = $3; | |
1538 | if (TREE_CODE (template_name) == COMPONENT_REF) | |
1539 | template_name = TREE_OPERAND (template_name, 1); | |
1540 | $$ = lookup_template_function (template_name, $4); | |
1541 | } | |
386b8a85 JM |
1542 | ; |
1543 | ||
1544 | object_template_id: | |
75650646 | 1545 | TEMPLATE identifier '<' template_arg_list_opt template_close_bracket |
386b8a85 | 1546 | { $$ = lookup_template_function ($2, $4); } |
75650646 | 1547 | | TEMPLATE PFUNCNAME '<' template_arg_list_opt template_close_bracket |
7211716d | 1548 | { $$ = lookup_template_function ($2, $4); } |
84d901be | 1549 | | TEMPLATE operator_name '<' template_arg_list_opt |
75650646 | 1550 | template_close_bracket |
7211716d | 1551 | { $$ = lookup_template_function ($2, $4); } |
386b8a85 JM |
1552 | ; |
1553 | ||
a28e3c7f MS |
1554 | unqualified_id: |
1555 | notype_unqualified_id | |
84d901be | 1556 | | tTYPENAME |
a80e4195 | 1557 | | SELFNAME |
a28e3c7f MS |
1558 | ; |
1559 | ||
52fbc847 JM |
1560 | expr_or_declarator_intern: |
1561 | expr_or_declarator | |
1562 | | attributes expr_or_declarator | |
1563 | { | |
1564 | /* Provide support for '(' attributes '*' declarator ')' | |
1565 | etc */ | |
1f8f4a0b | 1566 | $$ = tree_cons ($1, $2, NULL_TREE); |
52fbc847 JM |
1567 | } |
1568 | ; | |
1569 | ||
51c184be | 1570 | expr_or_declarator: |
a28e3c7f | 1571 | notype_unqualified_id |
52fbc847 | 1572 | | '*' expr_or_declarator_intern %prec UNARY |
718b8ea5 | 1573 | { $$ = build_nt (INDIRECT_REF, $2); } |
52fbc847 | 1574 | | '&' expr_or_declarator_intern %prec UNARY |
718b8ea5 | 1575 | { $$ = build_nt (ADDR_EXPR, $2); } |
52fbc847 | 1576 | | '(' expr_or_declarator_intern ')' |
4cabb798 | 1577 | { $$ = $2; } |
51c184be MS |
1578 | ; |
1579 | ||
386b8a85 | 1580 | notype_template_declarator: |
75650646 | 1581 | IDENTIFIER '<' template_arg_list_opt template_close_bracket |
386b8a85 JM |
1582 | { $$ = lookup_template_function ($1, $3); } |
1583 | | NSNAME '<' template_arg_list template_close_bracket | |
1584 | { $$ = lookup_template_function ($1, $3); } | |
1585 | ; | |
84d901be | 1586 | |
51c184be MS |
1587 | direct_notype_declarator: |
1588 | complex_direct_notype_declarator | |
92ac31f1 JM |
1589 | /* This precedence declaration is to prefer this reduce |
1590 | to the Koenig lookup shift in primary, below. I hate yacc. */ | |
1591 | | notype_unqualified_id %prec '(' | |
386b8a85 | 1592 | | notype_template_declarator |
52fbc847 JM |
1593 | | '(' expr_or_declarator_intern ')' |
1594 | { $$ = finish_decl_parsing ($2); } | |
51c184be MS |
1595 | ; |
1596 | ||
1597 | primary: | |
1598 | notype_unqualified_id | |
8d08fdba | 1599 | { |
ce4a0391 MM |
1600 | if (TREE_CODE ($1) == BIT_NOT_EXPR) |
1601 | $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($1, 0)); | |
84d901be | 1602 | else |
ce4a0391 | 1603 | $$ = finish_id_expr ($1); |
84d901be | 1604 | } |
8d08fdba | 1605 | | CONSTANT |
e2500fed | 1606 | | boolean_literal |
b84a3874 | 1607 | | STRING |
5566b478 | 1608 | { |
b84a3874 RH |
1609 | $$ = fix_string_type ($$); |
1610 | /* fix_string_type doesn't set up TYPE_MAIN_VARIANT of | |
dc469f59 | 1611 | a const array the way we want, so fix it. */ |
479aecf1 JM |
1612 | if (flag_const_strings) |
1613 | TREE_TYPE ($$) = build_cplus_array_type | |
1614 | (TREE_TYPE (TREE_TYPE ($$)), | |
1615 | TYPE_DOMAIN (TREE_TYPE ($$))); | |
5566b478 | 1616 | } |
0ba8a114 | 1617 | | VAR_FUNC_NAME |
5f261ba9 | 1618 | { $$ = finish_fname ($1); } |
8d08fdba | 1619 | | '(' expr ')' |
b4c4a9ec | 1620 | { $$ = finish_parenthesized_expr ($2); } |
52fbc847 | 1621 | | '(' expr_or_declarator_intern ')' |
b4c4a9ec MM |
1622 | { $2 = reparse_decl_as_expr (NULL_TREE, $2); |
1623 | $$ = finish_parenthesized_expr ($2); } | |
8d08fdba MS |
1624 | | '(' error ')' |
1625 | { $$ = error_mark_node; } | |
1626 | | '(' | |
5f261ba9 | 1627 | { if (!at_function_scope_p ()) |
8d08fdba | 1628 | { |
8251199e | 1629 | error ("braced-group within expression allowed only inside a function"); |
8d08fdba MS |
1630 | YYERROR; |
1631 | } | |
b7484fbe | 1632 | if (pedantic) |
84d901be AD |
1633 | pedwarn ("ISO C++ forbids braced-groups within expressions"); |
1634 | $<ttype>$ = begin_stmt_expr (); | |
8d08fdba | 1635 | } |
1cf537c5 | 1636 | compstmt_or_stmtexpr ')' |
447cfcb9 | 1637 | { $$ = finish_stmt_expr ($<ttype>2); } |
a759e627 ML |
1638 | /* Koenig lookup support |
1639 | We could store lastiddecl in $1 to avoid another lookup, | |
1640 | but that would result in many additional reduce/reduce conflicts. */ | |
03d82991 | 1641 | | notype_unqualified_id '(' nonnull_exprlist ')' |
4ba126e4 | 1642 | { $$ = parse_finish_call_expr ($1, $3, 1); } |
03d82991 | 1643 | | notype_unqualified_id LEFT_RIGHT |
4ba126e4 | 1644 | { $$ = parse_finish_call_expr ($1, NULL_TREE, 1); } |
8d08fdba | 1645 | | primary '(' nonnull_exprlist ')' |
4ba126e4 | 1646 | { $$ = parse_finish_call_expr ($1, $3, 0); } |
8d08fdba | 1647 | | primary LEFT_RIGHT |
4ba126e4 | 1648 | { $$ = parse_finish_call_expr ($1, NULL_TREE, 0); } |
2f401cc8 NS |
1649 | | VA_ARG '(' expr_no_commas ',' type_id ')' |
1650 | { $$ = build_x_va_arg ($3, groktypename ($5.t)); | |
1651 | check_for_new_type ("__builtin_va_arg", $5); } | |
8d08fdba | 1652 | | primary '[' expr ']' |
8926095f | 1653 | { $$ = grok_array_decl ($$, $3); } |
8d08fdba | 1654 | | primary PLUSPLUS |
b4c4a9ec | 1655 | { $$ = finish_increment_expr ($1, POSTINCREMENT_EXPR); } |
8d08fdba | 1656 | | primary MINUSMINUS |
b4c4a9ec | 1657 | { $$ = finish_increment_expr ($1, POSTDECREMENT_EXPR); } |
8d08fdba MS |
1658 | /* C++ extensions */ |
1659 | | THIS | |
b4c4a9ec | 1660 | { $$ = finish_this_expr (); } |
c11b6f21 | 1661 | | CV_QUALIFIER '(' nonnull_exprlist ')' |
8d08fdba | 1662 | { |
91063b51 MM |
1663 | /* This is a C cast in C++'s `functional' notation |
1664 | using the "implicit int" extension so that: | |
1665 | `const (3)' is equivalent to `const int (3)'. */ | |
1666 | tree type; | |
8d08fdba | 1667 | |
ebaacb57 | 1668 | type = hash_tree_cons (NULL_TREE, $1, NULL_TREE); |
1f8f4a0b | 1669 | type = groktypename (build_tree_list (type, NULL_TREE)); |
ebaacb57 | 1670 | $$ = build_functional_cast (type, $3); |
8d08fdba | 1671 | } |
51c184be | 1672 | | functional_cast |
46b02c6d MS |
1673 | | DYNAMIC_CAST '<' type_id '>' '(' expr ')' |
1674 | { tree type = groktypename ($3.t); | |
1675 | check_for_new_type ("dynamic_cast", $3); | |
1676 | $$ = build_dynamic_cast (type, $6); } | |
1677 | | STATIC_CAST '<' type_id '>' '(' expr ')' | |
1678 | { tree type = groktypename ($3.t); | |
1679 | check_for_new_type ("static_cast", $3); | |
1680 | $$ = build_static_cast (type, $6); } | |
1681 | | REINTERPRET_CAST '<' type_id '>' '(' expr ')' | |
1682 | { tree type = groktypename ($3.t); | |
1683 | check_for_new_type ("reinterpret_cast", $3); | |
1684 | $$ = build_reinterpret_cast (type, $6); } | |
1685 | | CONST_CAST '<' type_id '>' '(' expr ')' | |
1686 | { tree type = groktypename ($3.t); | |
1687 | check_for_new_type ("const_cast", $3); | |
1688 | $$ = build_const_cast (type, $6); } | |
8d08fdba | 1689 | | TYPEID '(' expr ')' |
e5f614d7 | 1690 | { $$ = build_typeid ($3); } |
51c184be | 1691 | | TYPEID '(' type_id ')' |
46b02c6d MS |
1692 | { tree type = groktypename ($3.t); |
1693 | check_for_new_type ("typeid", $3); | |
7437519c | 1694 | $$ = get_typeid (type); } |
a28e3c7f | 1695 | | global_scope IDENTIFIER |
80b1331c | 1696 | { $$ = parse_scoped_id ($2); } |
72e61a07 JM |
1697 | | global_scope template_id |
1698 | { $$ = $2; } | |
a28e3c7f | 1699 | | global_scope operator_name |
8d08fdba | 1700 | { |
a28e3c7f | 1701 | got_scope = NULL_TREE; |
8d08fdba | 1702 | if (TREE_CODE ($2) == IDENTIFIER_NODE) |
80b1331c | 1703 | $$ = parse_scoped_id ($2); |
5566b478 MS |
1704 | else |
1705 | $$ = $2; | |
8d08fdba | 1706 | } |
c11b6f21 | 1707 | | overqualified_id %prec HYPERUNARY |
a28e3c7f MS |
1708 | { $$ = build_offset_ref (OP0 ($$), OP1 ($$)); } |
1709 | | overqualified_id '(' nonnull_exprlist ')' | |
4ba126e4 | 1710 | { $$ = parse_finish_call_expr ($1, $3, 0); } |
a28e3c7f | 1711 | | overqualified_id LEFT_RIGHT |
4ba126e4 | 1712 | { $$ = parse_finish_call_expr ($1, NULL_TREE, 0); } |
386b8a85 | 1713 | | object object_template_id %prec UNARY |
50ad9642 | 1714 | { $$ = finish_class_member_access_expr ($$, $2); } |
386b8a85 | 1715 | | object object_template_id '(' nonnull_exprlist ')' |
b4c4a9ec | 1716 | { $$ = finish_object_call_expr ($2, $1, $4); } |
386b8a85 | 1717 | | object object_template_id LEFT_RIGHT |
b4c4a9ec | 1718 | { $$ = finish_object_call_expr ($2, $1, NULL_TREE); } |
a28e3c7f | 1719 | | object unqualified_id %prec UNARY |
50ad9642 | 1720 | { $$ = finish_class_member_access_expr ($$, $2); } |
c11b6f21 | 1721 | | object overqualified_id %prec UNARY |
50ad9642 | 1722 | { $$ = finish_class_member_access_expr ($1, $2); } |
a28e3c7f | 1723 | | object unqualified_id '(' nonnull_exprlist ')' |
b4c4a9ec | 1724 | { $$ = finish_object_call_expr ($2, $1, $4); } |
a28e3c7f | 1725 | | object unqualified_id LEFT_RIGHT |
b4c4a9ec | 1726 | { $$ = finish_object_call_expr ($2, $1, NULL_TREE); } |
b7484fbe | 1727 | | object overqualified_id '(' nonnull_exprlist ')' |
b4c4a9ec | 1728 | { $$ = finish_qualified_object_call_expr ($2, $1, $4); } |
b7484fbe | 1729 | | object overqualified_id LEFT_RIGHT |
b4c4a9ec | 1730 | { $$ = finish_qualified_object_call_expr ($2, $1, NULL_TREE); } |
8d08fdba MS |
1731 | /* p->int::~int() is valid -- 12.4 */ |
1732 | | object '~' TYPESPEC LEFT_RIGHT | |
b4c4a9ec | 1733 | { $$ = finish_pseudo_destructor_call_expr ($1, NULL_TREE, $3); } |
8d08fdba | 1734 | | object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT |
b4c4a9ec | 1735 | { $$ = finish_pseudo_destructor_call_expr ($1, $2, $5); } |
e1cd6e56 MS |
1736 | | object error |
1737 | { | |
e1cd6e56 MS |
1738 | $$ = error_mark_node; |
1739 | } | |
8d08fdba MS |
1740 | ; |
1741 | ||
1742 | /* Not needed for now. | |
1743 | ||
1744 | primary_no_id: | |
1745 | '(' expr ')' | |
1746 | { $$ = $2; } | |
1747 | | '(' error ')' | |
1748 | { $$ = error_mark_node; } | |
1749 | | '(' | |
1750 | { if (current_function_decl == 0) | |
1751 | { | |
8251199e | 1752 | error ("braced-group within expression allowed only inside a function"); |
8d08fdba MS |
1753 | YYERROR; |
1754 | } | |
1755 | $<ttype>$ = expand_start_stmt_expr (); } | |
1cf537c5 | 1756 | compstmt_or_stmtexpr ')' |
b7484fbe | 1757 | { if (pedantic) |
cab1f180 | 1758 | pedwarn ("ISO C++ forbids braced-groups within expressions"); |
8d08fdba MS |
1759 | $$ = expand_end_stmt_expr ($<ttype>2); } |
1760 | | primary_no_id '(' nonnull_exprlist ')' | |
4ac14744 | 1761 | { $$ = build_x_function_call ($$, $3, current_class_ref); } |
8d08fdba | 1762 | | primary_no_id LEFT_RIGHT |
4ac14744 | 1763 | { $$ = build_x_function_call ($$, NULL_TREE, current_class_ref); } |
8d08fdba MS |
1764 | | primary_no_id '[' expr ']' |
1765 | { goto do_array; } | |
1766 | | primary_no_id PLUSPLUS | |
1767 | { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); } | |
1768 | | primary_no_id MINUSMINUS | |
1769 | { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); } | |
1770 | | SCOPE IDENTIFIER | |
1771 | { goto do_scoped_id; } | |
1772 | | SCOPE operator_name | |
1773 | { if (TREE_CODE ($2) == IDENTIFIER_NODE) | |
1774 | goto do_scoped_id; | |
1775 | goto do_scoped_operator; | |
1776 | } | |
1777 | ; | |
1778 | */ | |
1779 | ||
c11b6f21 MS |
1780 | new: |
1781 | NEW | |
8d08fdba | 1782 | { $$ = 0; } |
39211cd5 | 1783 | | global_scope NEW |
a28e3c7f | 1784 | { got_scope = NULL_TREE; $$ = 1; } |
8d08fdba MS |
1785 | ; |
1786 | ||
c11b6f21 MS |
1787 | delete: |
1788 | DELETE | |
a28e3c7f MS |
1789 | { $$ = 0; } |
1790 | | global_scope delete | |
1791 | { got_scope = NULL_TREE; $$ = 1; } | |
8d08fdba MS |
1792 | ; |
1793 | ||
e2500fed | 1794 | boolean_literal: |
2986ae00 | 1795 | CXX_TRUE |
255512c1 | 1796 | { $$ = boolean_true_node; } |
2986ae00 | 1797 | | CXX_FALSE |
255512c1 | 1798 | { $$ = boolean_false_node; } |
2986ae00 MS |
1799 | ; |
1800 | ||
8d08fdba MS |
1801 | nodecls: |
1802 | /* empty */ | |
1803 | { | |
cdd2559c JM |
1804 | if (DECL_CONSTRUCTOR_P (current_function_decl)) |
1805 | finish_mem_initializers (NULL_TREE); | |
8d08fdba MS |
1806 | } |
1807 | ; | |
1808 | ||
c11b6f21 MS |
1809 | object: |
1810 | primary '.' | |
e1cd6e56 | 1811 | { got_object = TREE_TYPE ($$); } |
8d08fdba MS |
1812 | | primary POINTSAT |
1813 | { | |
84d901be | 1814 | $$ = build_x_arrow ($$); |
e1cd6e56 | 1815 | got_object = TREE_TYPE ($$); |
8d08fdba MS |
1816 | } |
1817 | ; | |
1818 | ||
8d08fdba | 1819 | decl: |
c11b6f21 | 1820 | typespec initdecls ';' |
a28e3c7f | 1821 | { |
42976354 | 1822 | if ($1.t && IS_AGGR_TYPE_CODE (TREE_CODE ($1.t))) |
46b02c6d | 1823 | note_got_semicolon ($1.t); |
8d08fdba | 1824 | } |
a28e3c7f MS |
1825 | | typed_declspecs initdecls ';' |
1826 | { | |
46b02c6d | 1827 | note_list_got_semicolon ($1.t); |
8d08fdba | 1828 | } |
a28e3c7f | 1829 | | declmods notype_initdecls ';' |
80048418 | 1830 | {} |
8d08fdba MS |
1831 | | typed_declspecs ';' |
1832 | { | |
46b02c6d MS |
1833 | shadow_tag ($1.t); |
1834 | note_list_got_semicolon ($1.t); | |
8d08fdba MS |
1835 | } |
1836 | | declmods ';' | |
8251199e | 1837 | { warning ("empty declaration"); } |
de22184b | 1838 | | extension decl |
fd65a4c1 | 1839 | { pedantic = $1; } |
8d08fdba MS |
1840 | ; |
1841 | ||
1842 | /* Any kind of declarator (thus, all declarators allowed | |
1843 | after an explicit typespec). */ | |
1844 | ||
1845 | declarator: | |
c11b6f21 MS |
1846 | after_type_declarator %prec EMPTY |
1847 | | notype_declarator %prec EMPTY | |
51c184be MS |
1848 | ; |
1849 | ||
1850 | /* This is necessary to postpone reduction of `int()()()()'. */ | |
1851 | fcast_or_absdcl: | |
c11b6f21 MS |
1852 | LEFT_RIGHT %prec EMPTY |
1853 | { $$ = make_call_declarator (NULL_TREE, empty_parms (), | |
1854 | NULL_TREE, NULL_TREE); } | |
1855 | | fcast_or_absdcl LEFT_RIGHT %prec EMPTY | |
1856 | { $$ = make_call_declarator ($$, empty_parms (), NULL_TREE, | |
1857 | NULL_TREE); } | |
51c184be MS |
1858 | ; |
1859 | ||
cab1f180 | 1860 | /* ISO type-id (8.1) */ |
51c184be MS |
1861 | type_id: |
1862 | typed_typespecs absdcl | |
84d901be | 1863 | { $$.t = build_tree_list ($1.t, $2); |
46b02c6d | 1864 | $$.new_type_flag = $1.new_type_flag; } |
c11b6f21 | 1865 | | nonempty_cv_qualifiers absdcl |
84d901be | 1866 | { $$.t = build_tree_list ($1.t, $2); |
46b02c6d | 1867 | $$.new_type_flag = $1.new_type_flag; } |
51c184be | 1868 | | typespec absdcl |
1f8f4a0b | 1869 | { $$.t = build_tree_list (build_tree_list (NULL_TREE, $1.t), |
84d901be | 1870 | $2); |
46b02c6d | 1871 | $$.new_type_flag = $1.new_type_flag; } |
c11b6f21 | 1872 | | typed_typespecs %prec EMPTY |
1f8f4a0b | 1873 | { $$.t = build_tree_list ($1.t, NULL_TREE); |
46b02c6d | 1874 | $$.new_type_flag = $1.new_type_flag; } |
c11b6f21 | 1875 | | nonempty_cv_qualifiers %prec EMPTY |
84d901be | 1876 | { $$.t = build_tree_list ($1.t, NULL_TREE); |
46b02c6d | 1877 | $$.new_type_flag = $1.new_type_flag; } |
8d08fdba MS |
1878 | ; |
1879 | ||
1880 | /* Declspecs which contain at least one type specifier or typedef name. | |
1881 | (Just `const' or `volatile' is not enough.) | |
f30432d7 MS |
1882 | A typedef'd name following these is taken as a name to be declared. |
1883 | In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */ | |
8d08fdba MS |
1884 | |
1885 | typed_declspecs: | |
c11b6f21 | 1886 | typed_typespecs %prec EMPTY |
70adf8a9 | 1887 | { $$.lookups = type_lookups; } |
51c184be | 1888 | | typed_declspecs1 |
70adf8a9 | 1889 | { $$.lookups = type_lookups; } |
8ccc31eb | 1890 | ; |
51c184be MS |
1891 | |
1892 | typed_declspecs1: | |
1893 | declmods typespec | |
84d901be | 1894 | { $$.t = tree_cons (NULL_TREE, $2.t, $1.t); |
46b02c6d | 1895 | $$.new_type_flag = $2.new_type_flag; } |
c11b6f21 | 1896 | | typespec reserved_declspecs %prec HYPERUNARY |
84d901be | 1897 | { $$.t = tree_cons (NULL_TREE, $1.t, $2); |
46b02c6d | 1898 | $$.new_type_flag = $1.new_type_flag; } |
b7484fbe | 1899 | | typespec reserved_typespecquals reserved_declspecs |
84d901be | 1900 | { $$.t = tree_cons (NULL_TREE, $1.t, chainon ($2, $3)); |
46b02c6d | 1901 | $$.new_type_flag = $1.new_type_flag; } |
8d08fdba | 1902 | | declmods typespec reserved_declspecs |
84d901be | 1903 | { $$.t = tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t)); |
46b02c6d | 1904 | $$.new_type_flag = $2.new_type_flag; } |
8d2733ca | 1905 | | declmods typespec reserved_typespecquals |
84d901be | 1906 | { $$.t = tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t)); |
46b02c6d | 1907 | $$.new_type_flag = $2.new_type_flag; } |
8d2733ca | 1908 | | declmods typespec reserved_typespecquals reserved_declspecs |
1f8f4a0b | 1909 | { $$.t = tree_cons (NULL_TREE, $2.t, |
84d901be | 1910 | chainon ($3, chainon ($4, $1.t))); |
46b02c6d | 1911 | $$.new_type_flag = $2.new_type_flag; } |
8d08fdba MS |
1912 | ; |
1913 | ||
51c184be MS |
1914 | reserved_declspecs: |
1915 | SCSPEC | |
8d08fdba | 1916 | { if (extra_warnings) |
8251199e | 1917 | warning ("`%s' is not at beginning of declaration", |
8d08fdba | 1918 | IDENTIFIER_POINTER ($$)); |
1f8f4a0b | 1919 | $$ = build_tree_list (NULL_TREE, $$); } |
8d08fdba | 1920 | | reserved_declspecs typespecqual_reserved |
1f8f4a0b | 1921 | { $$ = tree_cons (NULL_TREE, $2.t, $$); } |
8d08fdba MS |
1922 | | reserved_declspecs SCSPEC |
1923 | { if (extra_warnings) | |
8251199e | 1924 | warning ("`%s' is not at beginning of declaration", |
8d08fdba | 1925 | IDENTIFIER_POINTER ($2)); |
1f8f4a0b | 1926 | $$ = tree_cons (NULL_TREE, $2, $$); } |
8d08fdba MS |
1927 | ; |
1928 | ||
1929 | /* List of just storage classes and type modifiers. | |
1930 | A declaration can start with just this, but then it cannot be used | |
f30432d7 MS |
1931 | to redeclare a typedef-name. |
1932 | In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */ | |
8d08fdba | 1933 | |
51632249 JM |
1934 | /* We use hash_tree_cons for lists of typeless declspecs so that they end |
1935 | up on a persistent obstack. Otherwise, they could appear at the | |
1936 | beginning of something like | |
1937 | ||
1938 | static const struct { int foo () { } } b; | |
1939 | ||
1940 | and would be discarded after we finish compiling foo. We don't need to | |
1941 | worry once we see a type. */ | |
1942 | ||
8d08fdba | 1943 | declmods: |
c11b6f21 | 1944 | nonempty_cv_qualifiers %prec EMPTY |
70adf8a9 | 1945 | { $$.lookups = NULL_TREE; TREE_STATIC ($$.t) = 1; } |
8d08fdba | 1946 | | SCSPEC |
70adf8a9 JM |
1947 | { |
1948 | $$.t = hash_tree_cons (NULL_TREE, $1, NULL_TREE); | |
1949 | $$.new_type_flag = 0; $$.lookups = NULL_TREE; | |
1950 | } | |
c11b6f21 | 1951 | | declmods CV_QUALIFIER |
70adf8a9 JM |
1952 | { |
1953 | $$.t = hash_tree_cons (NULL_TREE, $2, $1.t); | |
1954 | TREE_STATIC ($$.t) = 1; | |
1955 | } | |
8d08fdba | 1956 | | declmods SCSPEC |
70adf8a9 JM |
1957 | { |
1958 | if (extra_warnings && TREE_STATIC ($$.t)) | |
8251199e | 1959 | warning ("`%s' is not at beginning of declaration", |
8d08fdba | 1960 | IDENTIFIER_POINTER ($2)); |
70adf8a9 JM |
1961 | $$.t = hash_tree_cons (NULL_TREE, $2, $1.t); |
1962 | TREE_STATIC ($$.t) = TREE_STATIC ($1.t); | |
1963 | } | |
f30432d7 | 1964 | | declmods attributes |
70adf8a9 | 1965 | { $$.t = hash_tree_cons ($2, NULL_TREE, $1.t); } |
8d08fdba MS |
1966 | ; |
1967 | ||
8d08fdba MS |
1968 | /* Used instead of declspecs where storage classes are not allowed |
1969 | (that is, for typenames and structure components). | |
1970 | ||
1971 | C++ can takes storage classes for structure components. | |
1972 | Don't accept a typedef-name if anything but a modifier precedes it. */ | |
1973 | ||
1974 | typed_typespecs: | |
1975 | typespec %prec EMPTY | |
84d901be | 1976 | { $$.t = build_tree_list (NULL_TREE, $1.t); |
46b02c6d | 1977 | $$.new_type_flag = $1.new_type_flag; } |
c11b6f21 | 1978 | | nonempty_cv_qualifiers typespec |
84d901be | 1979 | { $$.t = tree_cons (NULL_TREE, $2.t, $1.t); |
46b02c6d | 1980 | $$.new_type_flag = $2.new_type_flag; } |
8d08fdba | 1981 | | typespec reserved_typespecquals |
84d901be | 1982 | { $$.t = tree_cons (NULL_TREE, $1.t, $2); |
46b02c6d | 1983 | $$.new_type_flag = $1.new_type_flag; } |
c11b6f21 | 1984 | | nonempty_cv_qualifiers typespec reserved_typespecquals |
84d901be | 1985 | { $$.t = tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t)); |
70adf8a9 | 1986 | $$.new_type_flag = $2.new_type_flag; } |
8d08fdba MS |
1987 | ; |
1988 | ||
1989 | reserved_typespecquals: | |
1990 | typespecqual_reserved | |
1f8f4a0b | 1991 | { $$ = build_tree_list (NULL_TREE, $1.t); } |
8d08fdba | 1992 | | reserved_typespecquals typespecqual_reserved |
1f8f4a0b | 1993 | { $$ = tree_cons (NULL_TREE, $2.t, $1); } |
e6b9638b JM |
1994 | | reserved_typespecquals attributes |
1995 | { $$ = tree_cons ($2, NULL_TREE, $1); } | |
1996 | | attributes %prec EMPTY | |
1997 | { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); } | |
8d08fdba MS |
1998 | ; |
1999 | ||
c01b9ec8 AO |
2000 | sizeof: |
2001 | SIZEOF { skip_evaluation++; } | |
2002 | ; | |
2003 | ||
2004 | alignof: | |
2005 | ALIGNOF { skip_evaluation++; } | |
2006 | ; | |
2007 | ||
2008 | typeof: | |
2009 | TYPEOF { skip_evaluation++; } | |
2010 | ; | |
2011 | ||
8d08fdba MS |
2012 | /* A typespec (but not a type qualifier). |
2013 | Once we have seen one of these in a declaration, | |
2014 | if a typedef name appears then it is being redeclared. */ | |
2015 | ||
c11b6f21 MS |
2016 | typespec: |
2017 | structsp | |
70adf8a9 | 2018 | { $$.lookups = NULL_TREE; } |
8d08fdba | 2019 | | TYPESPEC %prec EMPTY |
70adf8a9 | 2020 | { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; } |
a28e3c7f | 2021 | | complete_type_name |
70adf8a9 | 2022 | { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; } |
c01b9ec8 | 2023 | | typeof '(' expr ')' |
b894fc05 | 2024 | { $$.t = finish_typeof ($3); |
c01b9ec8 AO |
2025 | $$.new_type_flag = 0; $$.lookups = NULL_TREE; |
2026 | skip_evaluation--; } | |
2027 | | typeof '(' type_id ')' | |
46b02c6d | 2028 | { $$.t = groktypename ($3.t); |
c01b9ec8 AO |
2029 | $$.new_type_flag = 0; $$.lookups = NULL_TREE; |
2030 | skip_evaluation--; } | |
8d08fdba MS |
2031 | | SIGOF '(' expr ')' |
2032 | { tree type = TREE_TYPE ($3); | |
2033 | ||
70adf8a9 | 2034 | $$.new_type_flag = 0; $$.lookups = NULL_TREE; |
8d08fdba MS |
2035 | if (IS_AGGR_TYPE (type)) |
2036 | { | |
2037 | sorry ("sigof type specifier"); | |
46b02c6d | 2038 | $$.t = type; |
8d08fdba MS |
2039 | } |
2040 | else | |
2041 | { | |
8251199e | 2042 | error ("`sigof' applied to non-aggregate expression"); |
46b02c6d | 2043 | $$.t = error_mark_node; |
8d08fdba MS |
2044 | } |
2045 | } | |
51c184be | 2046 | | SIGOF '(' type_id ')' |
46b02c6d | 2047 | { tree type = groktypename ($3.t); |
8d08fdba | 2048 | |
70adf8a9 | 2049 | $$.new_type_flag = 0; $$.lookups = NULL_TREE; |
8d08fdba MS |
2050 | if (IS_AGGR_TYPE (type)) |
2051 | { | |
2052 | sorry ("sigof type specifier"); | |
46b02c6d | 2053 | $$.t = type; |
8d08fdba MS |
2054 | } |
2055 | else | |
2056 | { | |
8251199e | 2057 | error("`sigof' applied to non-aggregate type"); |
46b02c6d | 2058 | $$.t = error_mark_node; |
8d08fdba MS |
2059 | } |
2060 | } | |
8d08fdba MS |
2061 | ; |
2062 | ||
2063 | /* A typespec that is a reserved word, or a type qualifier. */ | |
2064 | ||
c11b6f21 MS |
2065 | typespecqual_reserved: |
2066 | TYPESPEC | |
46b02c6d | 2067 | { $$.t = $1; $$.new_type_flag = 0; } |
c11b6f21 | 2068 | | CV_QUALIFIER |
46b02c6d | 2069 | { $$.t = $1; $$.new_type_flag = 0; } |
8d08fdba MS |
2070 | | structsp |
2071 | ; | |
2072 | ||
2073 | initdecls: | |
2074 | initdcl0 | |
2075 | | initdecls ',' initdcl | |
61a127b3 | 2076 | { check_multiple_declarators (); } |
8d08fdba MS |
2077 | ; |
2078 | ||
2079 | notype_initdecls: | |
2080 | notype_initdcl0 | |
2081 | | notype_initdecls ',' initdcl | |
61a127b3 | 2082 | { check_multiple_declarators (); } |
8d08fdba MS |
2083 | ; |
2084 | ||
a28e3c7f MS |
2085 | nomods_initdecls: |
2086 | nomods_initdcl0 | |
2087 | | nomods_initdecls ',' initdcl | |
61a127b3 | 2088 | { check_multiple_declarators (); } |
a28e3c7f MS |
2089 | ; |
2090 | ||
8d08fdba MS |
2091 | maybeasm: |
2092 | /* empty */ | |
2093 | { $$ = NULL_TREE; } | |
b84a3874 RH |
2094 | | asm_keyword '(' STRING ')' |
2095 | { $$ = $3; } | |
8d08fdba MS |
2096 | ; |
2097 | ||
8d08fdba | 2098 | initdcl: |
c11b6f21 | 2099 | declarator maybeasm maybe_attribute '=' |
1f51a992 | 2100 | { $<ttype>$ = parse_decl ($<ttype>1, $3, 1); } |
8d08fdba MS |
2101 | init |
2102 | /* Note how the declaration of the variable is in effect while its init is parsed! */ | |
1f51a992 | 2103 | { parse_end_decl ($<ttype>5, $6, $2); } |
c11b6f21 | 2104 | | declarator maybeasm maybe_attribute |
70adf8a9 | 2105 | { |
1f51a992 JM |
2106 | $<ttype>$ = parse_decl ($<ttype>1, $3, 0); |
2107 | parse_end_decl ($<ttype>$, NULL_TREE, $2); | |
70adf8a9 | 2108 | } |
8d08fdba MS |
2109 | ; |
2110 | ||
22531e51 JM |
2111 | /* This rule assumes a certain configuration of the parser stack. |
2112 | In particular, $0, the element directly before the beginning of | |
2113 | this rule on the stack, must be a maybeasm. $-1 must be a | |
2114 | declarator or notype_declarator. And $-2 must be some declmods | |
2115 | or declspecs. We can't move the maybeasm into this rule because | |
2116 | we need that reduce so we prefer fn.def1 when appropriate. */ | |
153305b0 | 2117 | initdcl0_innards: |
22531e51 | 2118 | maybe_attribute '=' |
1f51a992 JM |
2119 | { $<ttype>$ = parse_decl0 ($<ttype>-1, $<ftype>-2.t, |
2120 | $<ftype>-2.lookups, $1, 1); } | |
153305b0 | 2121 | /* Note how the declaration of the variable is in effect |
84d901be | 2122 | while its init is parsed! */ |
8d08fdba | 2123 | init |
1f51a992 | 2124 | { parse_end_decl ($<ttype>3, $4, $<ttype>0); } |
22531e51 | 2125 | | maybe_attribute |
1f51a992 JM |
2126 | { tree d = parse_decl0 ($<ttype>-1, $<ftype>-2.t, |
2127 | $<ftype>-2.lookups, $1, 0); | |
2128 | parse_end_decl (d, NULL_TREE, $<ttype>0); } | |
153305b0 | 2129 | ; |
84d901be | 2130 | |
153305b0 | 2131 | initdcl0: |
22531e51 | 2132 | declarator maybeasm initdcl0_innards |
80048418 MM |
2133 | {} |
2134 | ; | |
2135 | ||
153305b0 | 2136 | notype_initdcl0: |
22531e51 | 2137 | notype_declarator maybeasm initdcl0_innards |
80048418 | 2138 | {} |
153305b0 | 2139 | ; |
84d901be | 2140 | |
a28e3c7f | 2141 | nomods_initdcl0: |
22531e51 | 2142 | notype_declarator maybeasm |
e6e81f1c PE |
2143 | { /* Set things up as initdcl0_innards expects. */ |
2144 | $<ttype>$ = $2; | |
84d901be | 2145 | $2 = $1; |
e6e81f1c PE |
2146 | $<ftype>1.t = NULL_TREE; |
2147 | $<ftype>1.lookups = NULL_TREE; } | |
84d901be | 2148 | initdcl0_innards |
153305b0 | 2149 | {} |
ced68160 | 2150 | | constructor_declarator maybeasm maybe_attribute |
1f51a992 JM |
2151 | { tree d = parse_decl0 ($1, NULL_TREE, NULL_TREE, $3, 0); |
2152 | parse_end_decl (d, NULL_TREE, $2); } | |
a28e3c7f MS |
2153 | ; |
2154 | ||
8d08fdba | 2155 | /* the * rules are dummies to accept the Apollo extended syntax |
e92cc029 | 2156 | so that the header files compile. */ |
8d08fdba | 2157 | maybe_attribute: |
c11b6f21 | 2158 | /* empty */ |
2986ae00 MS |
2159 | { $$ = NULL_TREE; } |
2160 | | attributes | |
2161 | { $$ = $1; } | |
2162 | ; | |
84d901be | 2163 | |
2986ae00 MS |
2164 | attributes: |
2165 | attribute | |
2166 | { $$ = $1; } | |
2167 | | attributes attribute | |
2168 | { $$ = chainon ($1, $2); } | |
2169 | ; | |
2170 | ||
2171 | attribute: | |
2172 | ATTRIBUTE '(' '(' attribute_list ')' ')' | |
2173 | { $$ = $4; } | |
2174 | ; | |
2175 | ||
2176 | attribute_list: | |
2177 | attrib | |
44a8d0b3 | 2178 | { $$ = $1; } |
2986ae00 | 2179 | | attribute_list ',' attrib |
44a8d0b3 | 2180 | { $$ = chainon ($1, $3); } |
2986ae00 | 2181 | ; |
84d901be | 2182 | |
2986ae00 | 2183 | attrib: |
c11b6f21 | 2184 | /* empty */ |
2986ae00 MS |
2185 | { $$ = NULL_TREE; } |
2186 | | any_word | |
44a8d0b3 | 2187 | { $$ = build_tree_list ($1, NULL_TREE); } |
2986ae00 | 2188 | | any_word '(' IDENTIFIER ')' |
44a8d0b3 | 2189 | { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); } |
2986ae00 | 2190 | | any_word '(' IDENTIFIER ',' nonnull_exprlist ')' |
44a8d0b3 | 2191 | { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); } |
2986ae00 | 2192 | | any_word '(' nonnull_exprlist ')' |
44a8d0b3 | 2193 | { $$ = build_tree_list ($1, $3); } |
2986ae00 MS |
2194 | ; |
2195 | ||
2196 | /* This still leaves out most reserved keywords, | |
2197 | shouldn't we include them? */ | |
2198 | ||
2199 | any_word: | |
2200 | identifier | |
2201 | | SCSPEC | |
2202 | | TYPESPEC | |
c11b6f21 | 2203 | | CV_QUALIFIER |
2986ae00 | 2204 | ; |
8d08fdba MS |
2205 | |
2206 | /* A nonempty list of identifiers, including typenames. */ | |
2207 | identifiers_or_typenames: | |
c11b6f21 | 2208 | identifier |
8d08fdba MS |
2209 | { $$ = build_tree_list (NULL_TREE, $1); } |
2210 | | identifiers_or_typenames ',' identifier | |
2211 | { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); } | |
2212 | ; | |
2213 | ||
e3417fcd | 2214 | maybe_init: |
c11b6f21 | 2215 | /* empty */ %prec EMPTY |
e3417fcd MS |
2216 | { $$ = NULL_TREE; } |
2217 | | '=' init | |
2218 | { $$ = $2; } | |
224e6091 | 2219 | ; |
e3417fcd | 2220 | |
5566b478 MS |
2221 | /* If we are processing a template, we don't want to expand this |
2222 | initializer yet. */ | |
2223 | ||
8d08fdba | 2224 | init: |
c11b6f21 | 2225 | expr_no_commas %prec '=' |
8d08fdba MS |
2226 | | '{' '}' |
2227 | { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE); | |
9a0e77ba | 2228 | TREE_HAS_CONSTRUCTOR ($$) = 1; } |
8d08fdba MS |
2229 | | '{' initlist '}' |
2230 | { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); | |
2231 | TREE_HAS_CONSTRUCTOR ($$) = 1; } | |
2232 | | '{' initlist ',' '}' | |
2233 | { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); | |
2234 | TREE_HAS_CONSTRUCTOR ($$) = 1; } | |
2235 | | error | |
2236 | { $$ = NULL_TREE; } | |
2237 | ; | |
2238 | ||
2239 | /* This chain is built in reverse order, | |
2240 | and put in forward order where initlist is used. */ | |
2241 | initlist: | |
2242 | init | |
2243 | { $$ = build_tree_list (NULL_TREE, $$); } | |
2244 | | initlist ',' init | |
e1b3e07d | 2245 | { $$ = tree_cons (NULL_TREE, $3, $$); } |
c8fcb331 | 2246 | /* These are for labeled elements. */ |
8d08fdba | 2247 | | '[' expr_no_commas ']' init |
051e6fd7 | 2248 | { $$ = build_tree_list ($2, $4); } |
8d08fdba | 2249 | | identifier ':' init |
051e6fd7 | 2250 | { $$ = build_tree_list ($$, $3); } |
8d08fdba | 2251 | | initlist ',' identifier ':' init |
e1b3e07d | 2252 | { $$ = tree_cons ($3, $5, $$); } |
8d08fdba MS |
2253 | ; |
2254 | ||
8dff1027 | 2255 | pending_inline: |
ade3dc07 | 2256 | PRE_PARSED_FUNCTION_DECL maybe_return_init function_body |
5566b478 | 2257 | { |
ade3dc07 | 2258 | expand_body (finish_function (2)); |
8dff1027 | 2259 | process_next_inline ($1); |
5566b478 | 2260 | } |
0e5921e8 | 2261 | | PRE_PARSED_FUNCTION_DECL maybe_return_init function_try_block |
84d901be AD |
2262 | { |
2263 | expand_body (finish_function (2)); | |
f181d4ae MM |
2264 | process_next_inline ($1); |
2265 | } | |
0e5921e8 | 2266 | | PRE_PARSED_FUNCTION_DECL maybe_return_init error |
84d901be AD |
2267 | { |
2268 | finish_function (2); | |
a8f73d4b | 2269 | process_next_inline ($1); } |
8dff1027 MS |
2270 | ; |
2271 | ||
2272 | pending_inlines: | |
2273 | /* empty */ | |
2274 | | pending_inlines pending_inline eat_saved_input | |
5566b478 MS |
2275 | ; |
2276 | ||
42976354 BK |
2277 | /* A regurgitated default argument. The value of DEFARG_MARKER will be |
2278 | the TREE_LIST node for the parameter in question. */ | |
2279 | defarg_again: | |
2280 | DEFARG_MARKER expr_no_commas END_OF_SAVED_INPUT | |
2281 | { replace_defarg ($1, $2); } | |
8dff1027 MS |
2282 | | DEFARG_MARKER error END_OF_SAVED_INPUT |
2283 | { replace_defarg ($1, error_mark_node); } | |
224e6091 | 2284 | ; |
42976354 BK |
2285 | |
2286 | pending_defargs: | |
2287 | /* empty */ %prec EMPTY | |
2288 | | pending_defargs defarg_again | |
2289 | { do_pending_defargs (); } | |
2290 | | pending_defargs error | |
2291 | { do_pending_defargs (); } | |
2292 | ; | |
2293 | ||
8d08fdba | 2294 | structsp: |
219670f1 | 2295 | ENUM identifier '{' |
80048418 | 2296 | { $<ttype>$ = current_enum_type; |
079e1098 | 2297 | current_enum_type = start_enum ($2); } |
219670f1 | 2298 | enumlist_opt '}' |
968b956a | 2299 | { $$.t = current_enum_type; |
219670f1 | 2300 | finish_enum (current_enum_type); |
46b02c6d | 2301 | $$.new_type_flag = 1; |
079e1098 | 2302 | current_enum_type = $<ttype>4; |
079e1098 | 2303 | check_for_missing_semicolon ($$.t); } |
219670f1 | 2304 | | ENUM '{' |
80048418 | 2305 | { $<ttype>$ = current_enum_type; |
079e1098 | 2306 | current_enum_type = start_enum (make_anon_name ()); } |
219670f1 | 2307 | enumlist_opt '}' |
968b956a | 2308 | { $$.t = current_enum_type; |
219670f1 | 2309 | finish_enum (current_enum_type); |
079e1098 | 2310 | $$.new_type_flag = 1; |
6a8f78d5 | 2311 | current_enum_type = $<ttype>3; |
079e1098 | 2312 | check_for_missing_semicolon ($$.t); } |
8d08fdba | 2313 | | ENUM identifier |
88e5899c | 2314 | { $$.t = parse_xref_tag (enum_type_node, $2, 1); |
46b02c6d | 2315 | $$.new_type_flag = 0; } |
a28e3c7f | 2316 | | ENUM complex_type_name |
88e5899c | 2317 | { $$.t = parse_xref_tag (enum_type_node, $2, 1); |
46b02c6d | 2318 | $$.new_type_flag = 0; } |
653cc74a JM |
2319 | | TYPENAME_KEYWORD typename_sub |
2320 | { $$.t = $2; | |
84d901be | 2321 | $$.new_type_flag = 0; |
ea6021e8 | 2322 | if (!processing_template_decl) |
33bd39a2 | 2323 | pedwarn ("using `typename' outside of template"); } |
8d08fdba | 2324 | /* C++ extensions, merged with C to avoid shift/reduce conflicts */ |
d46a33b3 NS |
2325 | | class_head_defn maybe_base_class_list '{' |
2326 | { | |
2327 | if ($2 && $1.t != error_mark_node) | |
2328 | { | |
2329 | tree type = TREE_TYPE ($1.t); | |
84d901be | 2330 | |
d46a33b3 NS |
2331 | if (TREE_CODE (type) == TYPENAME_TYPE) |
2332 | /* In a definition of a member class template, | |
2333 | we will get here with an implicit typename, | |
2334 | a TYPENAME_TYPE with a type. */ | |
2335 | type = TREE_TYPE (type); | |
2336 | maybe_process_partial_specialization (type); | |
da15dae6 | 2337 | xref_basetypes (type, $2); |
d46a33b3 | 2338 | } |
84d901be | 2339 | $1.t = begin_class_definition (TREE_TYPE ($1.t)); |
fd87b7a7 | 2340 | check_class_key (current_aggr, $1.t); |
4b054b80 | 2341 | current_aggr = NULL_TREE; } |
386b8a85 | 2342 | opt.component_decl_list '}' maybe_attribute |
84d901be | 2343 | { |
8d08fdba | 2344 | int semi; |
4b054b80 | 2345 | tree t; |
8d08fdba | 2346 | |
8d08fdba MS |
2347 | if (yychar == YYEMPTY) |
2348 | yychar = YYLEX; | |
2349 | semi = yychar == ';'; | |
8d08fdba | 2350 | |
d46a33b3 | 2351 | t = finish_class_definition ($1.t, $7, semi, $1.new_type_flag); |
4b054b80 NS |
2352 | $<ttype>$ = t; |
2353 | ||
2354 | /* restore current_aggr */ | |
2355 | current_aggr = TREE_CODE (t) != RECORD_TYPE | |
2356 | ? union_type_node | |
2357 | : CLASSTYPE_DECLARED_CLASS (t) | |
2358 | ? class_type_node : record_type_node; | |
42976354 BK |
2359 | } |
2360 | pending_defargs | |
51632249 | 2361 | { |
96a1e32d | 2362 | done_pending_defargs (); |
51632249 JM |
2363 | begin_inline_definitions (); |
2364 | } | |
5566b478 | 2365 | pending_inlines |
51632249 | 2366 | { |
d46a33b3 | 2367 | $$.t = $<ttype>8; |
84d901be | 2368 | $$.new_type_flag = 1; |
51632249 | 2369 | } |
d46a33b3 | 2370 | | class_head_decl |
8d08fdba | 2371 | { |
d46a33b3 NS |
2372 | $$.t = TREE_TYPE ($1.t); |
2373 | $$.new_type_flag = $1.new_type_flag; | |
fd87b7a7 | 2374 | check_class_key (current_aggr, $$.t); |
8d08fdba MS |
2375 | } |
2376 | ; | |
2377 | ||
2378 | maybecomma: | |
2379 | /* empty */ | |
2380 | | ',' | |
2381 | ; | |
2382 | ||
2383 | maybecomma_warn: | |
2384 | /* empty */ | |
2385 | | ',' | |
594740f3 | 2386 | { if (pedantic && !in_system_header) |
8251199e | 2387 | pedwarn ("comma at end of enumerator list"); } |
8d08fdba MS |
2388 | ; |
2389 | ||
c11b6f21 MS |
2390 | aggr: |
2391 | AGGR | |
8d08fdba | 2392 | | aggr SCSPEC |
8251199e | 2393 | { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); } |
8d08fdba | 2394 | | aggr TYPESPEC |
8251199e | 2395 | { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); } |
c11b6f21 | 2396 | | aggr CV_QUALIFIER |
8251199e | 2397 | { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); } |
8d08fdba | 2398 | | aggr AGGR |
8251199e | 2399 | { error ("no body nor ';' separates two class, struct or union declarations"); } |
dc8263bc | 2400 | | aggr attributes |
1f8f4a0b | 2401 | { $$ = build_tree_list ($2, $1); } |
8d08fdba MS |
2402 | ; |
2403 | ||
d46a33b3 | 2404 | class_head: |
8d08fdba | 2405 | aggr identifier |
d46a33b3 NS |
2406 | { |
2407 | current_aggr = $1; | |
2408 | $$ = build_tree_list (NULL_TREE, $2); | |
61a127b3 | 2409 | } |
d46a33b3 | 2410 | | aggr nested_name_specifier identifier |
fc378698 MS |
2411 | { |
2412 | current_aggr = $1; | |
d46a33b3 | 2413 | $$ = build_tree_list ($2, $3); |
f62dbf03 JM |
2414 | } |
2415 | | aggr global_scope nested_name_specifier identifier | |
2416 | { | |
2417 | current_aggr = $1; | |
d46a33b3 | 2418 | $$ = build_tree_list ($3, $4); |
f62dbf03 JM |
2419 | } |
2420 | | aggr global_scope identifier | |
2421 | { | |
2422 | current_aggr = $1; | |
d46a33b3 | 2423 | $$ = build_tree_list (global_namespace, $3); |
fc378698 | 2424 | } |
d46a33b3 NS |
2425 | ; |
2426 | ||
2427 | class_head_apparent_template: | |
2428 | aggr apparent_template_type | |
84d901be AD |
2429 | { |
2430 | current_aggr = $1; | |
d46a33b3 | 2431 | $$ = $2; |
3d7de1fa | 2432 | } |
2e6eddfc | 2433 | | aggr nested_name_specifier apparent_template_type |
84d901be AD |
2434 | { |
2435 | current_aggr = $1; | |
d46a33b3 | 2436 | $$ = $3; |
3d7de1fa | 2437 | } |
f1880e13 | 2438 | | aggr global_scope nested_name_specifier apparent_template_type |
84d901be AD |
2439 | { |
2440 | current_aggr = $1; | |
d46a33b3 | 2441 | $$ = $4; |
f1880e13 | 2442 | } |
07674418 MS |
2443 | ; |
2444 | ||
d46a33b3 NS |
2445 | class_head_decl: |
2446 | class_head %prec EMPTY | |
2447 | { | |
88e5899c MM |
2448 | $$.t = parse_handle_class_head (current_aggr, |
2449 | TREE_PURPOSE ($1), | |
2450 | TREE_VALUE ($1), | |
2451 | 0, &$$.new_type_flag); | |
3d7de1fa | 2452 | } |
d46a33b3 NS |
2453 | | aggr identifier_defn %prec EMPTY |
2454 | { | |
2455 | current_aggr = $1; | |
88e5899c | 2456 | $$.t = TYPE_MAIN_DECL (parse_xref_tag (current_aggr, $2, 0)); |
d46a33b3 | 2457 | $$.new_type_flag = 1; |
8d08fdba | 2458 | } |
d46a33b3 NS |
2459 | | class_head_apparent_template %prec EMPTY |
2460 | { | |
2461 | $$.t = $1; | |
2462 | $$.new_type_flag = 0; | |
07674418 | 2463 | } |
8d08fdba MS |
2464 | ; |
2465 | ||
d46a33b3 NS |
2466 | class_head_defn: |
2467 | class_head '{' | |
2468 | { | |
2469 | yyungetc ('{', 1); | |
88e5899c MM |
2470 | $$.t = parse_handle_class_head (current_aggr, |
2471 | TREE_PURPOSE ($1), | |
2472 | TREE_VALUE ($1), | |
2473 | 1, | |
2474 | &$$.new_type_flag); | |
d46a33b3 NS |
2475 | } |
2476 | | class_head ':' | |
2477 | { | |
2478 | yyungetc (':', 1); | |
88e5899c MM |
2479 | $$.t = parse_handle_class_head (current_aggr, |
2480 | TREE_PURPOSE ($1), | |
2481 | TREE_VALUE ($1), | |
2482 | 1, &$$.new_type_flag); | |
d46a33b3 NS |
2483 | } |
2484 | | class_head_apparent_template '{' | |
2485 | { | |
2486 | yyungetc ('{', 1); | |
2487 | $$.t = $1; | |
2488 | $$.new_type_flag = 0; | |
3807621a NS |
2489 | if (TREE_CODE (TREE_TYPE ($1)) == RECORD_TYPE) |
2490 | /* We might be specializing a template with a different | |
2491 | class-key. */ | |
2492 | CLASSTYPE_DECLARED_CLASS (TREE_TYPE ($1)) | |
2493 | = (current_aggr == class_type_node); | |
d46a33b3 NS |
2494 | } |
2495 | | class_head_apparent_template ':' | |
2496 | { | |
2497 | yyungetc (':', 1); | |
3d7de1fa MM |
2498 | $$.t = $1; |
2499 | $$.new_type_flag = 0; | |
3807621a NS |
2500 | if (TREE_CODE (TREE_TYPE ($1)) == RECORD_TYPE) |
2501 | /* We might be specializing a template with a different | |
2502 | class-key. */ | |
2503 | CLASSTYPE_DECLARED_CLASS (TREE_TYPE ($1)) | |
2504 | = (current_aggr == class_type_node); | |
3d7de1fa | 2505 | } |
d46a33b3 NS |
2506 | | aggr identifier_defn '{' |
2507 | { | |
2508 | yyungetc ('{', 1); | |
2509 | current_aggr = $1; | |
88e5899c MM |
2510 | $$.t = parse_handle_class_head (current_aggr, |
2511 | NULL_TREE, $2, | |
2512 | 1, &$$.new_type_flag); | |
d46a33b3 NS |
2513 | } |
2514 | | aggr identifier_defn ':' | |
2515 | { | |
2516 | yyungetc (':', 1); | |
2517 | current_aggr = $1; | |
88e5899c MM |
2518 | $$.t = parse_handle_class_head (current_aggr, |
2519 | NULL_TREE, $2, | |
2520 | 1, &$$.new_type_flag); | |
d46a33b3 NS |
2521 | } |
2522 | | aggr '{' | |
2523 | { | |
2524 | current_aggr = $1; | |
88e5899c MM |
2525 | $$.t = TYPE_MAIN_DECL (parse_xref_tag ($1, |
2526 | make_anon_name (), | |
2527 | 0)); | |
d46a33b3 | 2528 | $$.new_type_flag = 0; |
f6a83eb0 JB |
2529 | CLASSTYPE_DECLARED_CLASS (TREE_TYPE ($$.t)) |
2530 | = $1 == class_type_node; | |
d46a33b3 NS |
2531 | yyungetc ('{', 1); |
2532 | } | |
c11b6f21 | 2533 | ; |
8d08fdba MS |
2534 | |
2535 | maybe_base_class_list: | |
d46a33b3 | 2536 | /* empty */ |
8d08fdba | 2537 | { $$ = NULL_TREE; } |
d46a33b3 NS |
2538 | | ':' see_typename |
2539 | { error ("no bases given following `:'"); | |
2540 | $$ = NULL_TREE; } | |
2541 | | ':' see_typename base_class_list | |
f30432d7 | 2542 | { $$ = $3; } |
8d08fdba MS |
2543 | ; |
2544 | ||
2545 | base_class_list: | |
2546 | base_class | |
f30432d7 MS |
2547 | | base_class_list ',' see_typename base_class |
2548 | { $$ = chainon ($$, $4); } | |
8d08fdba MS |
2549 | ; |
2550 | ||
2551 | base_class: | |
e2500fed | 2552 | base_class_1 |
6eabb241 | 2553 | { $$ = finish_base_specifier (access_default_node, $1); } |
e2500fed | 2554 | | base_class_access_list see_typename base_class_1 |
6eabb241 | 2555 | { $$ = finish_base_specifier ($1, $3); } |
8d08fdba MS |
2556 | ; |
2557 | ||
e2500fed | 2558 | base_class_1: |
653cc74a | 2559 | typename_sub |
bb92901d NS |
2560 | { if (!TYPE_P ($$)) |
2561 | $$ = error_mark_node; } | |
653cc74a | 2562 | | nonnested_type |
bb92901d | 2563 | { $$ = TREE_TYPE ($$); } |
8d08fdba MS |
2564 | ; |
2565 | ||
2566 | base_class_access_list: | |
f30432d7 MS |
2567 | VISSPEC see_typename |
2568 | | SCSPEC see_typename | |
d8b55a76 | 2569 | { if ($1 != ridpointers[(int)RID_VIRTUAL]) |
33bd39a2 | 2570 | error ("`%D' access", $1); |
be99da77 | 2571 | $$ = access_default_virtual_node; } |
f30432d7 | 2572 | | base_class_access_list VISSPEC see_typename |
d8b55a76 JM |
2573 | { |
2574 | if ($1 != access_default_virtual_node) | |
8251199e | 2575 | error ("multiple access specifiers"); |
be99da77 | 2576 | else if ($2 == access_public_node) |
d8b55a76 JM |
2577 | $$ = access_public_virtual_node; |
2578 | else if ($2 == access_protected_node) | |
2579 | $$ = access_protected_virtual_node; | |
be99da77 | 2580 | else /* $2 == access_private_node */ |
d8b55a76 | 2581 | $$ = access_private_virtual_node; |
8d08fdba | 2582 | } |
f30432d7 | 2583 | | base_class_access_list SCSPEC see_typename |
8d08fdba | 2584 | { if ($2 != ridpointers[(int)RID_VIRTUAL]) |
33bd39a2 | 2585 | error ("`%D' access", $2); |
d8b55a76 | 2586 | else if ($$ == access_public_node) |
be99da77 | 2587 | $$ = access_public_virtual_node; |
d8b55a76 JM |
2588 | else if ($$ == access_protected_node) |
2589 | $$ = access_protected_virtual_node; | |
be99da77 | 2590 | else if ($$ == access_private_node) |
d8b55a76 JM |
2591 | $$ = access_private_virtual_node; |
2592 | else | |
8251199e | 2593 | error ("multiple `virtual' specifiers"); |
d8b55a76 | 2594 | } |
8d08fdba MS |
2595 | ; |
2596 | ||
8d08fdba | 2597 | opt.component_decl_list: |
d6479fe7 | 2598 | | component_decl_list |
61a127b3 | 2599 | | opt.component_decl_list access_specifier component_decl_list |
84d901be | 2600 | | opt.component_decl_list access_specifier |
61a127b3 | 2601 | ; |
8d08fdba | 2602 | |
61a127b3 MM |
2603 | access_specifier: |
2604 | VISSPEC ':' | |
2605 | { | |
61a127b3 MM |
2606 | current_access_specifier = $1; |
2607 | } | |
8d08fdba MS |
2608 | ; |
2609 | ||
2610 | /* Note: we no longer warn about the semicolon after a component_decl_list. | |
2611 | ARM $9.2 says that the semicolon is optional, and therefore allowed. */ | |
2612 | component_decl_list: | |
2613 | component_decl | |
84d901be | 2614 | { |
61a127b3 | 2615 | finish_member_declaration ($1); |
4b054b80 | 2616 | current_aggr = NULL_TREE; |
788bf0e3 | 2617 | reset_type_access_control (); |
8d08fdba MS |
2618 | } |
2619 | | component_decl_list component_decl | |
84d901be | 2620 | { |
61a127b3 | 2621 | finish_member_declaration ($2); |
4b054b80 | 2622 | current_aggr = NULL_TREE; |
788bf0e3 | 2623 | reset_type_access_control (); |
8d08fdba | 2624 | } |
8d08fdba MS |
2625 | ; |
2626 | ||
2627 | component_decl: | |
a28e3c7f MS |
2628 | component_decl_1 ';' |
2629 | | component_decl_1 '}' | |
8251199e | 2630 | { error ("missing ';' before right brace"); |
a28e3c7f MS |
2631 | yyungetc ('}', 0); } |
2632 | /* C++: handle constructors, destructors and inline functions */ | |
2633 | /* note that INLINE is like a TYPESPEC */ | |
e2500fed | 2634 | | fn_def2 ':' /* base_init compstmt */ |
a28e3c7f | 2635 | { $$ = finish_method ($$); } |
e2500fed | 2636 | | fn_def2 TRY /* base_init compstmt */ |
f30432d7 | 2637 | { $$ = finish_method ($$); } |
e2500fed | 2638 | | fn_def2 RETURN_KEYWORD /* base_init compstmt */ |
f30432d7 | 2639 | { $$ = finish_method ($$); } |
e2500fed | 2640 | | fn_def2 '{' /* nodecls compstmt */ |
a28e3c7f | 2641 | { $$ = finish_method ($$); } |
a5894242 MS |
2642 | | ';' |
2643 | { $$ = NULL_TREE; } | |
de22184b MS |
2644 | | extension component_decl |
2645 | { $$ = $2; | |
fd65a4c1 | 2646 | pedantic = $1; } |
93cdc044 | 2647 | | template_header component_decl |
84d901be | 2648 | { |
61a127b3 MM |
2649 | if ($2) |
2650 | $$ = finish_member_template_decl ($2); | |
2651 | else | |
2652 | /* The component was already processed. */ | |
2653 | $$ = NULL_TREE; | |
2654 | ||
2655 | finish_template_decl ($1); | |
2656 | } | |
93cdc044 | 2657 | | template_header typed_declspecs ';' |
84d901be AD |
2658 | { |
2659 | $$ = finish_member_class_template ($2.t); | |
61a127b3 MM |
2660 | finish_template_decl ($1); |
2661 | } | |
fd8b7a0e GP |
2662 | | bad_decl |
2663 | { $$ = NULL_TREE; } | |
a28e3c7f MS |
2664 | ; |
2665 | ||
2666 | component_decl_1: | |
2667 | /* Do not add a "typed_declspecs declarator" rule here for | |
51c184be MS |
2668 | speed; we need to call grok_x_components for enums, so the |
2669 | speedup would be insignificant. */ | |
a28e3c7f | 2670 | typed_declspecs components |
61a127b3 MM |
2671 | { |
2672 | /* Most of the productions for component_decl only | |
2673 | allow the creation of one new member, so we call | |
2674 | finish_member_declaration in component_decl_list. | |
2675 | For this rule and the next, however, there can be | |
2676 | more than one member, e.g.: | |
2677 | ||
2678 | int i, j; | |
2679 | ||
2680 | and we need the first member to be fully | |
2681 | registered before the second is processed. | |
2682 | Therefore, the rules for components take care of | |
2683 | this processing. To avoid registering the | |
2684 | components more than once, we send NULL_TREE up | |
0c0aac2f | 2685 | here; that lets finish_member_declaration know |
61a127b3 MM |
2686 | that there is nothing to do. */ |
2687 | if (!$2) | |
2688 | grok_x_components ($1.t); | |
2689 | $$ = NULL_TREE; | |
2690 | } | |
a28e3c7f | 2691 | | declmods notype_components |
84d901be | 2692 | { |
61a127b3 | 2693 | if (!$2) |
70adf8a9 | 2694 | grok_x_components ($1.t); |
84d901be | 2695 | $$ = NULL_TREE; |
61a127b3 | 2696 | } |
c11b6f21 | 2697 | | notype_declarator maybeasm maybe_attribute maybe_init |
91d231cb | 2698 | { $$ = grokfield ($$, NULL_TREE, $4, $2, $3); } |
c11b6f21 | 2699 | | constructor_declarator maybeasm maybe_attribute maybe_init |
91d231cb | 2700 | { $$ = grokfield ($$, NULL_TREE, $4, $2, $3); } |
a28e3c7f | 2701 | | ':' expr_no_commas |
8d08fdba | 2702 | { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); } |
8d08fdba MS |
2703 | | error |
2704 | { $$ = NULL_TREE; } | |
2705 | ||
a28e3c7f MS |
2706 | /* These rules introduce a reduce/reduce conflict; in |
2707 | typedef int foo, bar; | |
2708 | class A { | |
2709 | foo (bar); | |
2710 | }; | |
2711 | should "A::foo" be declared as a function or "A::bar" as a data | |
2712 | member? In other words, is "bar" an after_type_declarator or a | |
2713 | parmlist? */ | |
c11b6f21 | 2714 | | declmods component_constructor_declarator maybeasm maybe_attribute maybe_init |
f30432d7 | 2715 | { tree specs, attrs; |
70adf8a9 | 2716 | split_specs_attrs ($1.t, &specs, &attrs); |
c11b6f21 | 2717 | $$ = grokfield ($2, specs, $5, $3, |
91d231cb | 2718 | chainon ($4, attrs)); } |
c11b6f21 | 2719 | | component_constructor_declarator maybeasm maybe_attribute maybe_init |
91d231cb | 2720 | { $$ = grokfield ($$, NULL_TREE, $4, $2, $3); } |
6060a796 | 2721 | | using_decl |
a9aedbc2 | 2722 | { $$ = do_class_using_decl ($1); } |
224e6091 | 2723 | ; |
8d08fdba | 2724 | |
e92cc029 | 2725 | /* The case of exactly one component is handled directly by component_decl. */ |
f30432d7 | 2726 | /* ??? Huh? ^^^ */ |
8d08fdba MS |
2727 | components: |
2728 | /* empty: possibly anonymous */ | |
61a127b3 | 2729 | { $$ = 0; } |
8d08fdba | 2730 | | component_declarator0 |
84d901be | 2731 | { |
61a127b3 MM |
2732 | if (PROCESSING_REAL_TEMPLATE_DECL_P ()) |
2733 | $1 = finish_member_template_decl ($1); | |
84d901be | 2734 | finish_member_declaration ($1); |
61a127b3 MM |
2735 | $$ = 1; |
2736 | } | |
8d08fdba | 2737 | | components ',' component_declarator |
84d901be | 2738 | { |
61a127b3 MM |
2739 | check_multiple_declarators (); |
2740 | if (PROCESSING_REAL_TEMPLATE_DECL_P ()) | |
2741 | $3 = finish_member_template_decl ($3); | |
2742 | finish_member_declaration ($3); | |
2743 | $$ = 2; | |
8d08fdba MS |
2744 | } |
2745 | ; | |
2746 | ||
51c184be MS |
2747 | notype_components: |
2748 | /* empty: possibly anonymous */ | |
61a127b3 | 2749 | { $$ = 0; } |
51c184be | 2750 | | notype_component_declarator0 |
84d901be | 2751 | { |
61a127b3 MM |
2752 | if (PROCESSING_REAL_TEMPLATE_DECL_P ()) |
2753 | $1 = finish_member_template_decl ($1); | |
2754 | finish_member_declaration ($1); | |
2755 | $$ = 1; | |
2756 | } | |
51c184be | 2757 | | notype_components ',' notype_component_declarator |
84d901be | 2758 | { |
61a127b3 MM |
2759 | check_multiple_declarators (); |
2760 | if (PROCESSING_REAL_TEMPLATE_DECL_P ()) | |
2761 | $3 = finish_member_template_decl ($3); | |
84d901be | 2762 | finish_member_declaration ($3); |
61a127b3 | 2763 | $$ = 2; |
51c184be MS |
2764 | } |
2765 | ; | |
2766 | ||
8d08fdba | 2767 | component_declarator0: |
51c184be MS |
2768 | after_type_component_declarator0 |
2769 | | notype_component_declarator0 | |
2770 | ; | |
2771 | ||
2772 | component_declarator: | |
2773 | after_type_component_declarator | |
2774 | | notype_component_declarator | |
2775 | ; | |
2776 | ||
2777 | after_type_component_declarator0: | |
c11b6f21 | 2778 | after_type_declarator maybeasm maybe_attribute maybe_init |
1f51a992 JM |
2779 | { $$ = parse_field0 ($1, $<ftype>0.t, $<ftype>0.lookups, |
2780 | $3, $2, $4); } | |
84d901be | 2781 | | tTYPENAME ':' expr_no_commas maybe_attribute |
1f51a992 JM |
2782 | { $$ = parse_bitfield0 ($1, $<ftype>0.t, $<ftype>0.lookups, |
2783 | $4, $3); } | |
51c184be MS |
2784 | ; |
2785 | ||
2786 | notype_component_declarator0: | |
c11b6f21 | 2787 | notype_declarator maybeasm maybe_attribute maybe_init |
1f51a992 JM |
2788 | { $$ = parse_field0 ($1, $<ftype>0.t, $<ftype>0.lookups, |
2789 | $3, $2, $4); } | |
c11b6f21 | 2790 | | constructor_declarator maybeasm maybe_attribute maybe_init |
1f51a992 JM |
2791 | { $$ = parse_field0 ($1, $<ftype>0.t, $<ftype>0.lookups, |
2792 | $3, $2, $4); } | |
51c184be | 2793 | | IDENTIFIER ':' expr_no_commas maybe_attribute |
1f51a992 JM |
2794 | { $$ = parse_bitfield0 ($1, $<ftype>0.t, $<ftype>0.lookups, |
2795 | $4, $3); } | |
8d08fdba | 2796 | | ':' expr_no_commas maybe_attribute |
1f51a992 JM |
2797 | { $$ = parse_bitfield0 (NULL_TREE, $<ftype>0.t, |
2798 | $<ftype>0.lookups, $3, $2); } | |
8d08fdba MS |
2799 | ; |
2800 | ||
51c184be | 2801 | after_type_component_declarator: |
c11b6f21 | 2802 | after_type_declarator maybeasm maybe_attribute maybe_init |
1f51a992 | 2803 | { $$ = parse_field ($1, $3, $2, $4); } |
84d901be | 2804 | | tTYPENAME ':' expr_no_commas maybe_attribute |
1f51a992 | 2805 | { $$ = parse_bitfield ($1, $4, $3); } |
51c184be MS |
2806 | ; |
2807 | ||
2808 | notype_component_declarator: | |
c11b6f21 | 2809 | notype_declarator maybeasm maybe_attribute maybe_init |
1f51a992 | 2810 | { $$ = parse_field ($1, $3, $2, $4); } |
51c184be | 2811 | | IDENTIFIER ':' expr_no_commas maybe_attribute |
1f51a992 | 2812 | { $$ = parse_bitfield ($1, $4, $3); } |
8d08fdba | 2813 | | ':' expr_no_commas maybe_attribute |
1f51a992 | 2814 | { $$ = parse_bitfield (NULL_TREE, $3, $2); } |
8d08fdba MS |
2815 | ; |
2816 | ||
30ff8252 NS |
2817 | enumlist_opt: |
2818 | enumlist maybecomma_warn | |
2819 | | maybecomma_warn | |
30ff8252 NS |
2820 | ; |
2821 | ||
8d08fdba MS |
2822 | /* We chain the enumerators in reverse order. |
2823 | Because of the way enums are built, the order is | |
2824 | insignificant. Take advantage of this fact. */ | |
2825 | ||
2826 | enumlist: | |
2827 | enumerator | |
2828 | | enumlist ',' enumerator | |
8d08fdba MS |
2829 | ; |
2830 | ||
2831 | enumerator: | |
2832 | identifier | |
58595203 | 2833 | { build_enumerator ($1, NULL_TREE, current_enum_type); } |
8d08fdba | 2834 | | identifier '=' expr_no_commas |
58595203 | 2835 | { build_enumerator ($1, $3, current_enum_type); } |
8d08fdba MS |
2836 | ; |
2837 | ||
cab1f180 | 2838 | /* ISO new-type-id (5.3.4) */ |
51c184be | 2839 | new_type_id: |
a4443a08 | 2840 | type_specifier_seq new_declarator |
84d901be | 2841 | { $$.t = build_tree_list ($1.t, $2); |
46b02c6d | 2842 | $$.new_type_flag = $1.new_type_flag; } |
c11b6f21 | 2843 | | type_specifier_seq %prec EMPTY |
84d901be | 2844 | { $$.t = build_tree_list ($1.t, NULL_TREE); |
46b02c6d | 2845 | $$.new_type_flag = $1.new_type_flag; } |
39211cd5 | 2846 | /* GNU extension to allow arrays of arbitrary types with |
80048418 MM |
2847 | non-constant dimension. */ |
2848 | | '(' type_id ')' '[' expr ']' | |
39211cd5 | 2849 | { |
b7484fbe | 2850 | if (pedantic) |
cab1f180 | 2851 | pedwarn ("ISO C++ forbids array dimensions with parenthesized type in new"); |
718b8ea5 | 2852 | $$.t = build_nt (ARRAY_REF, TREE_VALUE ($2.t), $5); |
1f8f4a0b | 2853 | $$.t = build_tree_list (TREE_PURPOSE ($2.t), $$.t); |
80048418 | 2854 | $$.new_type_flag = $2.new_type_flag; |
39211cd5 | 2855 | } |
8d08fdba MS |
2856 | ; |
2857 | ||
c11b6f21 MS |
2858 | cv_qualifiers: |
2859 | /* empty */ %prec EMPTY | |
51c184be | 2860 | { $$ = NULL_TREE; } |
c11b6f21 | 2861 | | cv_qualifiers CV_QUALIFIER |
1f8f4a0b | 2862 | { $$ = tree_cons (NULL_TREE, $2, $$); } |
51c184be MS |
2863 | ; |
2864 | ||
c11b6f21 MS |
2865 | nonempty_cv_qualifiers: |
2866 | CV_QUALIFIER | |
51632249 | 2867 | { $$.t = hash_tree_cons (NULL_TREE, $1, NULL_TREE); |
46b02c6d | 2868 | $$.new_type_flag = 0; } |
c11b6f21 | 2869 | | nonempty_cv_qualifiers CV_QUALIFIER |
84d901be | 2870 | { $$.t = hash_tree_cons (NULL_TREE, $2, $1.t); |
46b02c6d | 2871 | $$.new_type_flag = $1.new_type_flag; } |
98884b26 | 2872 | | attributes %prec EMPTY |
84d901be | 2873 | { $$.t = hash_tree_cons ($1, NULL_TREE, NULL_TREE); |
98884b26 JM |
2874 | $$.new_type_flag = 0; } |
2875 | | nonempty_cv_qualifiers attributes %prec EMPTY | |
84d901be | 2876 | { $$.t = hash_tree_cons ($2, NULL_TREE, $1.t); |
98884b26 | 2877 | $$.new_type_flag = $1.new_type_flag; } |
8d08fdba MS |
2878 | ; |
2879 | ||
8d08fdba MS |
2880 | /* These rules must follow the rules for function declarations |
2881 | and component declarations. That way, longer rules are preferred. */ | |
2882 | ||
a5894242 MS |
2883 | /* An expression which will not live on the momentary obstack. */ |
2884 | maybe_parmlist: | |
80048418 MM |
2885 | '(' nonnull_exprlist ')' |
2886 | { $$ = $2; } | |
2887 | | '(' parmlist ')' | |
2888 | { $$ = $2; } | |
2889 | | LEFT_RIGHT | |
2890 | { $$ = empty_parms (); } | |
2891 | | '(' error ')' | |
2892 | { $$ = NULL_TREE; } | |
a5894242 MS |
2893 | ; |
2894 | ||
8d08fdba | 2895 | /* A declarator that is allowed only after an explicit typespec. */ |
b607c87f JM |
2896 | |
2897 | after_type_declarator_intern: | |
2898 | after_type_declarator | |
2899 | | attributes after_type_declarator | |
2900 | { | |
2901 | /* Provide support for '(' attributes '*' declarator ')' | |
2902 | etc */ | |
1f8f4a0b | 2903 | $$ = tree_cons ($1, $2, NULL_TREE); |
b607c87f JM |
2904 | } |
2905 | ; | |
2906 | ||
8d08fdba MS |
2907 | /* may all be followed by prec '.' */ |
2908 | after_type_declarator: | |
b607c87f | 2909 | '*' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY |
46b02c6d | 2910 | { $$ = make_pointer_declarator ($2.t, $3); } |
b607c87f | 2911 | | '&' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY |
46b02c6d | 2912 | { $$ = make_reference_declarator ($2.t, $3); } |
b607c87f | 2913 | | '*' after_type_declarator_intern %prec UNARY |
51c184be | 2914 | { $$ = make_pointer_declarator (NULL_TREE, $2); } |
b607c87f | 2915 | | '&' after_type_declarator_intern %prec UNARY |
51c184be | 2916 | { $$ = make_reference_declarator (NULL_TREE, $2); } |
b607c87f | 2917 | | ptr_to_mem cv_qualifiers after_type_declarator_intern |
a28e3c7f | 2918 | { tree arg = make_pointer_declarator ($2, $3); |
718b8ea5 | 2919 | $$ = build_nt (SCOPE_REF, $1, arg); |
51c184be MS |
2920 | } |
2921 | | direct_after_type_declarator | |
8d08fdba MS |
2922 | ; |
2923 | ||
b607c87f JM |
2924 | direct_after_type_declarator: |
2925 | direct_after_type_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.' | |
2926 | { $$ = make_call_declarator ($$, $2, $3, $4); } | |
80048418 | 2927 | | direct_after_type_declarator '[' expr ']' |
718b8ea5 | 2928 | { $$ = build_nt (ARRAY_REF, $$, $3); } |
b607c87f | 2929 | | direct_after_type_declarator '[' ']' |
718b8ea5 | 2930 | { $$ = build_nt (ARRAY_REF, $$, NULL_TREE); } |
b607c87f JM |
2931 | | '(' after_type_declarator_intern ')' |
2932 | { $$ = $2; } | |
2933 | | nested_name_specifier type_name %prec EMPTY | |
2934 | { push_nested_class ($1, 3); | |
718b8ea5 | 2935 | $$ = build_nt (SCOPE_REF, $$, $2); |
b607c87f JM |
2936 | TREE_COMPLEXITY ($$) = current_class_depth; } |
2937 | | type_name %prec EMPTY | |
2938 | ; | |
2939 | ||
653cc74a | 2940 | nonnested_type: |
c11b6f21 | 2941 | type_name %prec EMPTY |
8d2733ca | 2942 | { |
cffa8729 MS |
2943 | if (TREE_CODE ($1) == IDENTIFIER_NODE) |
2944 | { | |
5951f637 | 2945 | $$ = lookup_name ($1, 1); |
8f032717 | 2946 | maybe_note_name_used_in_class ($1, $$); |
cffa8729 MS |
2947 | } |
2948 | else | |
2949 | $$ = $1; | |
2950 | } | |
2951 | | global_scope type_name | |
2952 | { | |
2953 | if (TREE_CODE ($2) == IDENTIFIER_NODE) | |
5951f637 | 2954 | $$ = IDENTIFIER_GLOBAL_VALUE ($2); |
cffa8729 MS |
2955 | else |
2956 | $$ = $2; | |
2957 | got_scope = NULL_TREE; | |
8d2733ca | 2958 | } |
653cc74a JM |
2959 | ; |
2960 | ||
2961 | complete_type_name: | |
2962 | nonnested_type | |
a28e3c7f | 2963 | | nested_type |
cffa8729 MS |
2964 | | global_scope nested_type |
2965 | { $$ = $2; } | |
a28e3c7f MS |
2966 | ; |
2967 | ||
2968 | nested_type: | |
c11b6f21 | 2969 | nested_name_specifier type_name %prec EMPTY |
5566b478 | 2970 | { $$ = get_type_decl ($2); } |
a28e3c7f MS |
2971 | ; |
2972 | ||
8d08fdba MS |
2973 | /* A declarator allowed whether or not there has been |
2974 | an explicit typespec. These cannot redeclare a typedef-name. */ | |
2975 | ||
52fbc847 JM |
2976 | notype_declarator_intern: |
2977 | notype_declarator | |
2978 | | attributes notype_declarator | |
2979 | { | |
2980 | /* Provide support for '(' attributes '*' declarator ')' | |
2981 | etc */ | |
1f8f4a0b | 2982 | $$ = tree_cons ($1, $2, NULL_TREE); |
52fbc847 JM |
2983 | } |
2984 | ; | |
84d901be | 2985 | |
8d08fdba | 2986 | notype_declarator: |
52fbc847 | 2987 | '*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY |
46b02c6d | 2988 | { $$ = make_pointer_declarator ($2.t, $3); } |
52fbc847 | 2989 | | '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY |
46b02c6d | 2990 | { $$ = make_reference_declarator ($2.t, $3); } |
52fbc847 | 2991 | | '*' notype_declarator_intern %prec UNARY |
51c184be | 2992 | { $$ = make_pointer_declarator (NULL_TREE, $2); } |
52fbc847 | 2993 | | '&' notype_declarator_intern %prec UNARY |
51c184be | 2994 | { $$ = make_reference_declarator (NULL_TREE, $2); } |
52fbc847 | 2995 | | ptr_to_mem cv_qualifiers notype_declarator_intern |
a28e3c7f | 2996 | { tree arg = make_pointer_declarator ($2, $3); |
718b8ea5 | 2997 | $$ = build_nt (SCOPE_REF, $1, arg); |
51c184be MS |
2998 | } |
2999 | | direct_notype_declarator | |
3000 | ; | |
3001 | ||
a28e3c7f | 3002 | complex_notype_declarator: |
52fbc847 | 3003 | '*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY |
46b02c6d | 3004 | { $$ = make_pointer_declarator ($2.t, $3); } |
52fbc847 | 3005 | | '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY |
46b02c6d | 3006 | { $$ = make_reference_declarator ($2.t, $3); } |
a28e3c7f | 3007 | | '*' complex_notype_declarator %prec UNARY |
51c184be | 3008 | { $$ = make_pointer_declarator (NULL_TREE, $2); } |
a28e3c7f | 3009 | | '&' complex_notype_declarator %prec UNARY |
51c184be | 3010 | { $$ = make_reference_declarator (NULL_TREE, $2); } |
52fbc847 | 3011 | | ptr_to_mem cv_qualifiers notype_declarator_intern |
a28e3c7f | 3012 | { tree arg = make_pointer_declarator ($2, $3); |
718b8ea5 | 3013 | $$ = build_nt (SCOPE_REF, $1, arg); |
51c184be MS |
3014 | } |
3015 | | complex_direct_notype_declarator | |
3016 | ; | |
3017 | ||
3018 | complex_direct_notype_declarator: | |
c11b6f21 MS |
3019 | direct_notype_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.' |
3020 | { $$ = make_call_declarator ($$, $2, $3, $4); } | |
a28e3c7f | 3021 | | '(' complex_notype_declarator ')' |
8d08fdba | 3022 | { $$ = $2; } |
80048418 | 3023 | | direct_notype_declarator '[' expr ']' |
718b8ea5 | 3024 | { $$ = build_nt (ARRAY_REF, $$, $3); } |
51c184be | 3025 | | direct_notype_declarator '[' ']' |
718b8ea5 | 3026 | { $$ = build_nt (ARRAY_REF, $$, NULL_TREE); } |
b7484fbe | 3027 | | notype_qualified_id |
648f19f6 | 3028 | { enter_scope_of ($1); } |
40f1e342 JM |
3029 | | global_scope notype_qualified_id |
3030 | { enter_scope_of ($2); $$ = $2;} | |
3031 | | global_scope notype_unqualified_id | |
718b8ea5 | 3032 | { $$ = build_nt (SCOPE_REF, global_namespace, $2); |
84d901be | 3033 | enter_scope_of ($$); |
40f1e342 | 3034 | } |
386b8a85 JM |
3035 | | nested_name_specifier notype_template_declarator |
3036 | { got_scope = NULL_TREE; | |
718b8ea5 | 3037 | $$ = build_nt (SCOPE_REF, $1, $2); |
648f19f6 | 3038 | enter_scope_of ($$); |
386b8a85 | 3039 | } |
a28e3c7f | 3040 | ; |
8d08fdba | 3041 | |
a28e3c7f | 3042 | qualified_id: |
c11b6f21 | 3043 | nested_name_specifier unqualified_id |
a28e3c7f | 3044 | { got_scope = NULL_TREE; |
718b8ea5 | 3045 | $$ = build_nt (SCOPE_REF, $$, $2); } |
386b8a85 JM |
3046 | | nested_name_specifier object_template_id |
3047 | { got_scope = NULL_TREE; | |
718b8ea5 | 3048 | $$ = build_nt (SCOPE_REF, $1, $2); } |
a28e3c7f | 3049 | ; |
51c184be | 3050 | |
a28e3c7f | 3051 | notype_qualified_id: |
c11b6f21 | 3052 | nested_name_specifier notype_unqualified_id |
a28e3c7f | 3053 | { got_scope = NULL_TREE; |
718b8ea5 | 3054 | $$ = build_nt (SCOPE_REF, $$, $2); } |
386b8a85 JM |
3055 | | nested_name_specifier object_template_id |
3056 | { got_scope = NULL_TREE; | |
718b8ea5 | 3057 | $$ = build_nt (SCOPE_REF, $1, $2); } |
a28e3c7f MS |
3058 | ; |
3059 | ||
3060 | overqualified_id: | |
3061 | notype_qualified_id | |
3062 | | global_scope notype_qualified_id | |
3063 | { $$ = $2; } | |
51c184be MS |
3064 | ; |
3065 | ||
3066 | functional_cast: | |
3067 | typespec '(' nonnull_exprlist ')' | |
46b02c6d | 3068 | { $$ = build_functional_cast ($1.t, $3); } |
52fbc847 | 3069 | | typespec '(' expr_or_declarator_intern ')' |
46b02c6d | 3070 | { $$ = reparse_decl_as_expr ($1.t, $3); } |
c11b6f21 | 3071 | | typespec fcast_or_absdcl %prec EMPTY |
46b02c6d | 3072 | { $$ = reparse_absdcl_as_expr ($1.t, $2); } |
8d08fdba | 3073 | ; |
70adf8a9 | 3074 | |
a28e3c7f | 3075 | type_name: |
84d901be | 3076 | tTYPENAME |
a80e4195 | 3077 | | SELFNAME |
c11b6f21 | 3078 | | template_type %prec EMPTY |
a28e3c7f | 3079 | ; |
8d08fdba | 3080 | |
a28e3c7f MS |
3081 | nested_name_specifier: |
3082 | nested_name_specifier_1 | |
3083 | | nested_name_specifier nested_name_specifier_1 | |
3084 | { $$ = $2; } | |
2604412d | 3085 | | nested_name_specifier TEMPLATE explicit_template_type SCOPE |
84d901be | 3086 | { got_scope = $$ |
0e902d98 | 3087 | = make_typename_type ($1, $3, tf_error | tf_parsing); } |
8a2b77e7 JM |
3088 | /* Error handling per Core 125. */ |
3089 | | nested_name_specifier IDENTIFIER SCOPE | |
84d901be | 3090 | { got_scope = $$ |
0e902d98 | 3091 | = make_typename_type ($1, $2, tf_error | tf_parsing); } |
8a2b77e7 | 3092 | | nested_name_specifier PTYPENAME SCOPE |
84d901be | 3093 | { got_scope = $$ |
0e902d98 | 3094 | = make_typename_type ($1, $2, tf_error | tf_parsing); } |
a28e3c7f MS |
3095 | ; |
3096 | ||
3097 | /* Why the @#$%^& do type_name and notype_identifier need to be expanded | |
3098 | inline here?!? (jason) */ | |
3099 | nested_name_specifier_1: | |
84d901be | 3100 | tTYPENAME SCOPE |
45537677 | 3101 | { |
a80e4195 MS |
3102 | if (TREE_CODE ($1) == IDENTIFIER_NODE) |
3103 | { | |
3104 | $$ = lastiddecl; | |
8f032717 | 3105 | maybe_note_name_used_in_class ($1, $$); |
a80e4195 | 3106 | } |
b3f738da MM |
3107 | got_scope = $$ = |
3108 | complete_type (TYPE_MAIN_VARIANT (TREE_TYPE ($$))); | |
a80e4195 MS |
3109 | } |
3110 | | SELFNAME SCOPE | |
3111 | { | |
3112 | if (TREE_CODE ($1) == IDENTIFIER_NODE) | |
3113 | $$ = lastiddecl; | |
45537677 MS |
3114 | got_scope = $$ = TREE_TYPE ($$); |
3115 | } | |
6060a796 | 3116 | | NSNAME SCOPE |
6633d636 MS |
3117 | { |
3118 | if (TREE_CODE ($$) == IDENTIFIER_NODE) | |
3119 | $$ = lastiddecl; | |
653cc74a | 3120 | got_scope = $$; |
6633d636 | 3121 | } |
a28e3c7f | 3122 | | template_type SCOPE |
5566b478 | 3123 | { got_scope = $$ = complete_type (TREE_TYPE ($1)); } |
8d08fdba MS |
3124 | ; |
3125 | ||
653cc74a JM |
3126 | typename_sub: |
3127 | typename_sub0 | |
3128 | | global_scope typename_sub0 | |
3129 | { $$ = $2; } | |
3130 | ; | |
3131 | ||
3132 | typename_sub0: | |
11686454 | 3133 | typename_sub1 identifier %prec EMPTY |
653cc74a | 3134 | { |
2f939d94 | 3135 | if (TYPE_P ($1)) |
0e902d98 | 3136 | $$ = make_typename_type ($1, $2, tf_error | tf_parsing); |
653cc74a | 3137 | else if (TREE_CODE ($2) == IDENTIFIER_NODE) |
33bd39a2 | 3138 | error ("`%T' is not a class or namespace", $2); |
653cc74a | 3139 | else |
d3959d60 JM |
3140 | { |
3141 | $$ = $2; | |
3142 | if (TREE_CODE ($$) == TYPE_DECL) | |
3143 | $$ = TREE_TYPE ($$); | |
3144 | } | |
653cc74a | 3145 | } |
11686454 JM |
3146 | | typename_sub1 template_type %prec EMPTY |
3147 | { $$ = TREE_TYPE ($2); } | |
11686454 | 3148 | | typename_sub1 explicit_template_type %prec EMPTY |
0e902d98 | 3149 | { $$ = make_typename_type ($1, $2, tf_error | tf_parsing); } |
2604412d | 3150 | | typename_sub1 TEMPLATE explicit_template_type %prec EMPTY |
0e902d98 | 3151 | { $$ = make_typename_type ($1, $3, tf_error | tf_parsing); } |
653cc74a JM |
3152 | ; |
3153 | ||
3154 | typename_sub1: | |
3155 | typename_sub2 | |
3156 | { | |
3157 | if (TREE_CODE ($1) == IDENTIFIER_NODE) | |
33bd39a2 | 3158 | error ("`%T' is not a class or namespace", $1); |
477f6664 JM |
3159 | else if (TREE_CODE ($1) == TYPE_DECL) |
3160 | $$ = TREE_TYPE ($1); | |
653cc74a JM |
3161 | } |
3162 | | typename_sub1 typename_sub2 | |
3163 | { | |
2f939d94 | 3164 | if (TYPE_P ($1)) |
0e902d98 | 3165 | $$ = make_typename_type ($1, $2, tf_error | tf_parsing); |
653cc74a | 3166 | else if (TREE_CODE ($2) == IDENTIFIER_NODE) |
33bd39a2 | 3167 | error ("`%T' is not a class or namespace", $2); |
653cc74a | 3168 | else |
d3959d60 JM |
3169 | { |
3170 | $$ = $2; | |
3171 | if (TREE_CODE ($$) == TYPE_DECL) | |
3172 | $$ = TREE_TYPE ($$); | |
3173 | } | |
653cc74a | 3174 | } |
b2b7d40a | 3175 | | typename_sub1 explicit_template_type SCOPE |
84d901be | 3176 | { got_scope = $$ |
0e902d98 | 3177 | = make_typename_type ($1, $2, tf_error | tf_parsing); } |
2604412d | 3178 | | typename_sub1 TEMPLATE explicit_template_type SCOPE |
84d901be | 3179 | { got_scope = $$ |
0e902d98 | 3180 | = make_typename_type ($1, $3, tf_error | tf_parsing); } |
653cc74a JM |
3181 | ; |
3182 | ||
477f6664 JM |
3183 | /* This needs to return a TYPE_DECL for simple names so that we don't |
3184 | forget what name was used. */ | |
653cc74a | 3185 | typename_sub2: |
84d901be | 3186 | tTYPENAME SCOPE |
653cc74a | 3187 | { |
477f6664 JM |
3188 | if (TREE_CODE ($1) != TYPE_DECL) |
3189 | $$ = lastiddecl; | |
8857f91e | 3190 | |
2c73f9f5 ML |
3191 | /* Retrieve the type for the identifier, which might involve |
3192 | some computation. */ | |
477f6664 | 3193 | got_scope = complete_type (TREE_TYPE ($$)); |
8857f91e MM |
3194 | |
3195 | if ($$ == error_mark_node) | |
33bd39a2 | 3196 | error ("`%T' is not a class or namespace", $1); |
653cc74a JM |
3197 | } |
3198 | | SELFNAME SCOPE | |
3199 | { | |
477f6664 | 3200 | if (TREE_CODE ($1) != TYPE_DECL) |
653cc74a | 3201 | $$ = lastiddecl; |
477f6664 | 3202 | got_scope = complete_type (TREE_TYPE ($$)); |
653cc74a JM |
3203 | } |
3204 | | template_type SCOPE | |
3205 | { got_scope = $$ = complete_type (TREE_TYPE ($$)); } | |
3206 | | PTYPENAME SCOPE | |
3207 | | IDENTIFIER SCOPE | |
3208 | | NSNAME SCOPE | |
3209 | { | |
3210 | if (TREE_CODE ($$) == IDENTIFIER_NODE) | |
3211 | $$ = lastiddecl; | |
3212 | got_scope = $$; | |
3213 | } | |
3214 | ; | |
3215 | ||
b2b7d40a | 3216 | explicit_template_type: |
2604412d JM |
3217 | identifier '<' template_arg_list_opt template_close_bracket |
3218 | { $$ = build_min_nt (TEMPLATE_ID_EXPR, $1, $3); } | |
b2b7d40a JM |
3219 | ; |
3220 | ||
a28e3c7f | 3221 | complex_type_name: |
cffa8729 MS |
3222 | global_scope type_name |
3223 | { | |
3224 | if (TREE_CODE ($2) == IDENTIFIER_NODE) | |
5951f637 | 3225 | $$ = IDENTIFIER_GLOBAL_VALUE ($2); |
cffa8729 MS |
3226 | else |
3227 | $$ = $2; | |
3228 | got_scope = NULL_TREE; | |
3229 | } | |
3230 | | nested_type | |
3231 | | global_scope nested_type | |
a28e3c7f MS |
3232 | { $$ = $2; } |
3233 | ; | |
3234 | ||
3235 | ptr_to_mem: | |
3236 | nested_name_specifier '*' | |
3237 | { got_scope = NULL_TREE; } | |
3238 | | global_scope nested_name_specifier '*' | |
3239 | { $$ = $2; got_scope = NULL_TREE; } | |
3240 | ; | |
3241 | ||
3242 | /* All uses of explicit global scope must go through this nonterminal so | |
e92cc029 | 3243 | that got_scope will be set before yylex is called to get the next token. */ |
a28e3c7f MS |
3244 | global_scope: |
3245 | SCOPE | |
3246 | { got_scope = void_type_node; } | |
8d08fdba MS |
3247 | ; |
3248 | ||
cab1f180 | 3249 | /* ISO new-declarator (5.3.4) */ |
51c184be | 3250 | new_declarator: |
c11b6f21 | 3251 | '*' cv_qualifiers new_declarator |
8d08fdba | 3252 | { $$ = make_pointer_declarator ($2, $3); } |
c11b6f21 | 3253 | | '*' cv_qualifiers %prec EMPTY |
8d08fdba | 3254 | { $$ = make_pointer_declarator ($2, NULL_TREE); } |
c11b6f21 | 3255 | | '&' cv_qualifiers new_declarator %prec EMPTY |
51c184be | 3256 | { $$ = make_reference_declarator ($2, $3); } |
c11b6f21 | 3257 | | '&' cv_qualifiers %prec EMPTY |
51c184be | 3258 | { $$ = make_reference_declarator ($2, NULL_TREE); } |
c11b6f21 | 3259 | | ptr_to_mem cv_qualifiers %prec EMPTY |
a28e3c7f | 3260 | { tree arg = make_pointer_declarator ($2, NULL_TREE); |
718b8ea5 | 3261 | $$ = build_nt (SCOPE_REF, $1, arg); |
51c184be | 3262 | } |
c11b6f21 | 3263 | | ptr_to_mem cv_qualifiers new_declarator |
a28e3c7f | 3264 | { tree arg = make_pointer_declarator ($2, $3); |
718b8ea5 | 3265 | $$ = build_nt (SCOPE_REF, $1, arg); |
51c184be | 3266 | } |
c11b6f21 | 3267 | | direct_new_declarator %prec EMPTY |
51c184be MS |
3268 | ; |
3269 | ||
cab1f180 | 3270 | /* ISO direct-new-declarator (5.3.4) */ |
51c184be | 3271 | direct_new_declarator: |
b283d5d7 | 3272 | '[' expr ']' |
718b8ea5 | 3273 | { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); } |
80048418 | 3274 | | direct_new_declarator '[' expr ']' |
718b8ea5 | 3275 | { $$ = build_nt (ARRAY_REF, $$, $3); } |
51c184be MS |
3276 | ; |
3277 | ||
46ff11fd JM |
3278 | absdcl_intern: |
3279 | absdcl | |
3280 | | attributes absdcl | |
3281 | { | |
3282 | /* Provide support for '(' attributes '*' declarator ')' | |
3283 | etc */ | |
1f8f4a0b | 3284 | $$ = tree_cons ($1, $2, NULL_TREE); |
46ff11fd JM |
3285 | } |
3286 | ; | |
84d901be | 3287 | |
cab1f180 | 3288 | /* ISO abstract-declarator (8.1) */ |
a28e3c7f | 3289 | absdcl: |
46ff11fd | 3290 | '*' nonempty_cv_qualifiers absdcl_intern |
46b02c6d | 3291 | { $$ = make_pointer_declarator ($2.t, $3); } |
46ff11fd | 3292 | | '*' absdcl_intern |
51c184be | 3293 | { $$ = make_pointer_declarator (NULL_TREE, $2); } |
c11b6f21 | 3294 | | '*' nonempty_cv_qualifiers %prec EMPTY |
46b02c6d | 3295 | { $$ = make_pointer_declarator ($2.t, NULL_TREE); } |
c11b6f21 | 3296 | | '*' %prec EMPTY |
a0a33927 | 3297 | { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); } |
46ff11fd | 3298 | | '&' nonempty_cv_qualifiers absdcl_intern |
46b02c6d | 3299 | { $$ = make_reference_declarator ($2.t, $3); } |
46ff11fd | 3300 | | '&' absdcl_intern |
51c184be | 3301 | { $$ = make_reference_declarator (NULL_TREE, $2); } |
c11b6f21 | 3302 | | '&' nonempty_cv_qualifiers %prec EMPTY |
46b02c6d | 3303 | { $$ = make_reference_declarator ($2.t, NULL_TREE); } |
c11b6f21 | 3304 | | '&' %prec EMPTY |
a0a33927 | 3305 | { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); } |
c11b6f21 | 3306 | | ptr_to_mem cv_qualifiers %prec EMPTY |
a28e3c7f | 3307 | { tree arg = make_pointer_declarator ($2, NULL_TREE); |
718b8ea5 | 3308 | $$ = build_nt (SCOPE_REF, $1, arg); |
51c184be | 3309 | } |
46ff11fd | 3310 | | ptr_to_mem cv_qualifiers absdcl_intern |
a28e3c7f | 3311 | { tree arg = make_pointer_declarator ($2, $3); |
718b8ea5 | 3312 | $$ = build_nt (SCOPE_REF, $1, arg); |
51c184be | 3313 | } |
c11b6f21 | 3314 | | direct_abstract_declarator %prec EMPTY |
51c184be MS |
3315 | ; |
3316 | ||
cab1f180 | 3317 | /* ISO direct-abstract-declarator (8.1) */ |
51c184be | 3318 | direct_abstract_declarator: |
46ff11fd | 3319 | '(' absdcl_intern ')' |
a28e3c7f | 3320 | { $$ = $2; } |
51c184be | 3321 | /* `(typedef)1' is `int'. */ |
c11b6f21 MS |
3322 | | direct_abstract_declarator '(' parmlist ')' cv_qualifiers exception_specification_opt %prec '.' |
3323 | { $$ = make_call_declarator ($$, $3, $5, $6); } | |
3324 | | direct_abstract_declarator LEFT_RIGHT cv_qualifiers exception_specification_opt %prec '.' | |
3325 | { $$ = make_call_declarator ($$, empty_parms (), $3, $4); } | |
80048418 | 3326 | | direct_abstract_declarator '[' expr ']' %prec '.' |
718b8ea5 | 3327 | { $$ = build_nt (ARRAY_REF, $$, $3); } |
51c184be | 3328 | | direct_abstract_declarator '[' ']' %prec '.' |
718b8ea5 | 3329 | { $$ = build_nt (ARRAY_REF, $$, NULL_TREE); } |
c11b6f21 MS |
3330 | | '(' complex_parmlist ')' cv_qualifiers exception_specification_opt %prec '.' |
3331 | { $$ = make_call_declarator (NULL_TREE, $2, $4, $5); } | |
3332 | | regcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.' | |
3333 | { set_quals_and_spec ($$, $2, $3); } | |
3334 | | fcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.' | |
3335 | { set_quals_and_spec ($$, $2, $3); } | |
80048418 | 3336 | | '[' expr ']' %prec '.' |
718b8ea5 | 3337 | { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); } |
8d08fdba | 3338 | | '[' ']' %prec '.' |
718b8ea5 | 3339 | { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); } |
8d08fdba MS |
3340 | ; |
3341 | ||
8d08fdba MS |
3342 | /* For C++, decls and stmts can be intermixed, so we don't need to |
3343 | have a special rule that won't start parsing the stmt section | |
3344 | until we have a stmt that parses without errors. */ | |
3345 | ||
3346 | stmts: | |
3347 | stmt | |
3348 | | errstmt | |
3349 | | stmts stmt | |
3350 | | stmts errstmt | |
3351 | ; | |
3352 | ||
c11b6f21 MS |
3353 | errstmt: |
3354 | error ';' | |
8d08fdba MS |
3355 | ; |
3356 | ||
8d08fdba MS |
3357 | /* Read zero or more forward-declarations for labels |
3358 | that nested functions can jump to. */ | |
3359 | maybe_label_decls: | |
3360 | /* empty */ | |
3361 | | label_decls | |
b7484fbe | 3362 | { if (pedantic) |
cab1f180 | 3363 | pedwarn ("ISO C++ forbids label declarations"); } |
8d08fdba MS |
3364 | ; |
3365 | ||
3366 | label_decls: | |
3367 | label_decl | |
3368 | | label_decls label_decl | |
3369 | ; | |
3370 | ||
3371 | label_decl: | |
3372 | LABEL identifiers_or_typenames ';' | |
84d901be | 3373 | { |
acef433b | 3374 | while ($2) |
8d08fdba | 3375 | { |
acef433b MM |
3376 | finish_label_decl (TREE_VALUE ($2)); |
3377 | $2 = TREE_CHAIN ($2); | |
8d08fdba MS |
3378 | } |
3379 | } | |
3380 | ; | |
3381 | ||
1cf537c5 | 3382 | compstmt_or_stmtexpr: |
3e4d04a1 | 3383 | save_lineno '{' |
ad321293 | 3384 | { $<ttype>$ = begin_compound_stmt (0); } |
84d901be | 3385 | compstmtend |
3e4d04a1 RH |
3386 | { STMT_LINENO ($<ttype>3) = $1; |
3387 | finish_compound_stmt (0, $<ttype>3); } | |
8d08fdba MS |
3388 | ; |
3389 | ||
1cf537c5 JJ |
3390 | compstmt: |
3391 | compstmt_or_stmtexpr | |
3392 | { last_expr_type = NULL_TREE; } | |
3393 | ; | |
3394 | ||
8d08fdba MS |
3395 | simple_if: |
3396 | IF | |
3e4d04a1 RH |
3397 | { $<ttype>$ = begin_if_stmt (); |
3398 | cond_stmt_keyword = "if"; } | |
ad321293 MM |
3399 | paren_cond_or_null |
3400 | { finish_if_stmt_cond ($3, $<ttype>2); } | |
3401 | implicitly_scoped_stmt | |
3e4d04a1 RH |
3402 | { $$ = $<ttype>2; |
3403 | finish_then_clause ($<ttype>2); } | |
8d08fdba MS |
3404 | ; |
3405 | ||
3406 | implicitly_scoped_stmt: | |
3407 | compstmt | |
84d901be | 3408 | | |
3e4d04a1 | 3409 | { $<ttype>$ = begin_compound_stmt (0); } |
84d901be | 3410 | save_lineno simple_stmt |
3e4d04a1 RH |
3411 | { STMT_LINENO ($<ttype>1) = $2; |
3412 | if ($3) STMT_LINENO ($3) = $2; | |
3413 | finish_compound_stmt (0, $<ttype>1); } | |
8d08fdba MS |
3414 | ; |
3415 | ||
3416 | stmt: | |
3417 | compstmt | |
3e4d04a1 RH |
3418 | | save_lineno simple_stmt |
3419 | { if ($2) STMT_LINENO ($2) = $1; } | |
8d08fdba MS |
3420 | ; |
3421 | ||
3422 | simple_stmt: | |
3423 | decl | |
3e4d04a1 RH |
3424 | { finish_stmt (); |
3425 | $$ = NULL_TREE; } | |
8d08fdba | 3426 | | expr ';' |
3e4d04a1 | 3427 | { $$ = finish_expr_stmt ($1); } |
8d08fdba | 3428 | | simple_if ELSE |
ad321293 | 3429 | { begin_else_clause (); } |
8d2733ca | 3430 | implicitly_scoped_stmt |
84d901be | 3431 | { |
3e4d04a1 | 3432 | $$ = $1; |
84d901be | 3433 | finish_else_clause ($1); |
ad321293 | 3434 | finish_if_stmt (); |
5566b478 | 3435 | } |
c11b6f21 | 3436 | | simple_if %prec IF |
3e4d04a1 RH |
3437 | { $$ = $1; |
3438 | finish_if_stmt (); } | |
8d08fdba | 3439 | | WHILE |
5566b478 | 3440 | { |
ad321293 | 3441 | $<ttype>$ = begin_while_stmt (); |
5566b478 MS |
3442 | cond_stmt_keyword = "while"; |
3443 | } | |
ad321293 MM |
3444 | paren_cond_or_null |
3445 | { finish_while_stmt_cond ($3, $<ttype>2); } | |
b02922a4 | 3446 | implicitly_scoped_stmt |
3e4d04a1 RH |
3447 | { $$ = $<ttype>2; |
3448 | finish_while_stmt ($<ttype>2); } | |
8d08fdba | 3449 | | DO |
ad321293 | 3450 | { $<ttype>$ = begin_do_stmt (); } |
8d08fdba | 3451 | implicitly_scoped_stmt WHILE |
5566b478 | 3452 | { |
ad321293 MM |
3453 | finish_do_body ($<ttype>2); |
3454 | cond_stmt_keyword = "do"; | |
5566b478 | 3455 | } |
8d08fdba | 3456 | paren_expr_or_null ';' |
3e4d04a1 RH |
3457 | { $$ = $<ttype>2; |
3458 | finish_do_stmt ($6, $<ttype>2); } | |
863adfc0 | 3459 | | FOR |
ad321293 | 3460 | { $<ttype>$ = begin_for_stmt (); } |
863adfc0 | 3461 | '(' for.init.statement |
ad321293 MM |
3462 | { finish_for_init_stmt ($<ttype>2); } |
3463 | xcond ';' | |
3464 | { finish_for_cond ($6, $<ttype>2); } | |
8d08fdba | 3465 | xexpr ')' |
ad321293 | 3466 | { finish_for_expr ($9, $<ttype>2); } |
b02922a4 | 3467 | implicitly_scoped_stmt |
3e4d04a1 RH |
3468 | { $$ = $<ttype>2; |
3469 | finish_for_stmt ($<ttype>2); } | |
84d901be | 3470 | | SWITCH |
527f0080 | 3471 | { $<ttype>$ = begin_switch_stmt (); } |
ad321293 | 3472 | '(' condition ')' |
527f0080 | 3473 | { finish_switch_cond ($4, $<ttype>2); } |
8d2733ca | 3474 | implicitly_scoped_stmt |
3e4d04a1 RH |
3475 | { $$ = $<ttype>2; |
3476 | finish_switch_stmt ($<ttype>2); } | |
8d08fdba | 3477 | | CASE expr_no_commas ':' |
3e4d04a1 | 3478 | { $<ttype>$ = finish_case_label ($2, NULL_TREE); } |
8d08fdba | 3479 | stmt |
3e4d04a1 | 3480 | { $$ = $<ttype>4; } |
f0e01782 | 3481 | | CASE expr_no_commas ELLIPSIS expr_no_commas ':' |
3e4d04a1 | 3482 | { $<ttype>$ = finish_case_label ($2, $4); } |
8d08fdba | 3483 | stmt |
3e4d04a1 | 3484 | { $$ = $<ttype>6; } |
8d08fdba | 3485 | | DEFAULT ':' |
3e4d04a1 | 3486 | { $<ttype>$ = finish_case_label (NULL_TREE, NULL_TREE); } |
8d08fdba | 3487 | stmt |
3e4d04a1 | 3488 | { $$ = $<ttype>3; } |
8d08fdba | 3489 | | BREAK ';' |
3e4d04a1 | 3490 | { $$ = finish_break_stmt (); } |
8d08fdba | 3491 | | CONTINUE ';' |
3e4d04a1 | 3492 | { $$ = finish_continue_stmt (); } |
3dcaad8b | 3493 | | RETURN_KEYWORD ';' |
3e4d04a1 | 3494 | { $$ = finish_return_stmt (NULL_TREE); } |
3dcaad8b | 3495 | | RETURN_KEYWORD expr ';' |
3e4d04a1 | 3496 | { $$ = finish_return_stmt ($2); } |
b84a3874 | 3497 | | asm_keyword maybe_cv_qualifier '(' STRING ')' ';' |
3e4d04a1 | 3498 | { $$ = finish_asm_stmt ($2, $4, NULL_TREE, NULL_TREE, |
4f78b9a8 RH |
3499 | NULL_TREE); |
3500 | ASM_INPUT_P ($$) = 1; } | |
8d08fdba | 3501 | /* This is the case with just output operands. */ |
b84a3874 | 3502 | | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ')' ';' |
3e4d04a1 | 3503 | { $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); } |
8d08fdba | 3504 | /* This is the case with input operands as well. */ |
b84a3874 | 3505 | | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':' |
3e4d04a1 RH |
3506 | asm_operands ')' ';' |
3507 | { $$ = finish_asm_stmt ($2, $4, $6, $8, NULL_TREE); } | |
b84a3874 | 3508 | | asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ')' ';' |
3e4d04a1 | 3509 | { $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, NULL_TREE); } |
8d08fdba | 3510 | /* This is the case with clobbered registers as well. */ |
b84a3874 | 3511 | | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':' |
8d2733ca | 3512 | asm_operands ':' asm_clobbers ')' ';' |
3e4d04a1 | 3513 | { $$ = finish_asm_stmt ($2, $4, $6, $8, $10); } |
b84a3874 | 3514 | | asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ':' |
eca1bd08 | 3515 | asm_clobbers ')' ';' |
3e4d04a1 | 3516 | { $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, $8); } |
b84a3874 | 3517 | | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands SCOPE |
eca1bd08 | 3518 | asm_clobbers ')' ';' |
3e4d04a1 | 3519 | { $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, $8); } |
8d08fdba | 3520 | | GOTO '*' expr ';' |
84d901be | 3521 | { |
ad321293 | 3522 | if (pedantic) |
cab1f180 | 3523 | pedwarn ("ISO C++ forbids computed gotos"); |
3e4d04a1 | 3524 | $$ = finish_goto_stmt ($3); |
5566b478 | 3525 | } |
8d08fdba | 3526 | | GOTO identifier ';' |
3e4d04a1 | 3527 | { $$ = finish_goto_stmt ($2); } |
8d08fdba | 3528 | | label_colon stmt |
3e4d04a1 | 3529 | { $$ = NULL_TREE; } |
8d08fdba | 3530 | | label_colon '}' |
8251199e | 3531 | { error ("label must be followed by statement"); |
3e4d04a1 RH |
3532 | yyungetc ('}', 0); |
3533 | $$ = NULL_TREE; } | |
8d08fdba | 3534 | | ';' |
3e4d04a1 RH |
3535 | { finish_stmt (); |
3536 | $$ = NULL_TREE; } | |
8d2733ca | 3537 | | try_block |
3e4d04a1 | 3538 | { $$ = NULL_TREE; } |
26877584 | 3539 | | using_directive |
3e4d04a1 | 3540 | { $$ = NULL_TREE; } |
ea9635c7 | 3541 | | namespace_using_decl |
3e4d04a1 RH |
3542 | { do_local_using_decl ($1); |
3543 | $$ = NULL_TREE; } | |
85c6cbaf | 3544 | | namespace_alias |
3e4d04a1 | 3545 | { $$ = NULL_TREE; } |
8d08fdba MS |
3546 | ; |
3547 | ||
f30432d7 MS |
3548 | function_try_block: |
3549 | TRY | |
0dde4175 | 3550 | { $<ttype>$ = begin_function_try_block (); } |
ade3dc07 | 3551 | function_body |
0dde4175 | 3552 | { finish_function_try_block ($<ttype>2); } |
f30432d7 | 3553 | handler_seq |
ade3dc07 | 3554 | { finish_function_handler_sequence ($<ttype>2); } |
f30432d7 MS |
3555 | ; |
3556 | ||
8d2733ca | 3557 | try_block: |
863adfc0 | 3558 | TRY |
ad321293 | 3559 | { $<ttype>$ = begin_try_block (); } |
863adfc0 | 3560 | compstmt |
ad321293 | 3561 | { finish_try_block ($<ttype>2); } |
8d2733ca | 3562 | handler_seq |
ad321293 | 3563 | { finish_handler_sequence ($<ttype>2); } |
8d08fdba MS |
3564 | ; |
3565 | ||
8d2733ca | 3566 | handler_seq: |
824b9a4c MS |
3567 | handler |
3568 | | handler_seq handler | |
7437519c ZW |
3569 | | /* empty */ |
3570 | { /* Generate a fake handler block to avoid later aborts. */ | |
3571 | tree fake_handler = begin_handler (); | |
3572 | finish_handler_parms (NULL_TREE, fake_handler); | |
3573 | finish_handler (fake_handler); | |
3574 | $<ttype>$ = fake_handler; | |
3575 | ||
3576 | error ("must have at least one catch per try block"); | |
3577 | } | |
824b9a4c MS |
3578 | ; |
3579 | ||
3580 | handler: | |
3581 | CATCH | |
1a6025b4 | 3582 | { $<ttype>$ = begin_handler (); } |
ad321293 | 3583 | handler_args |
1a6025b4 | 3584 | { finish_handler_parms ($3, $<ttype>2); } |
824b9a4c | 3585 | compstmt |
1a6025b4 | 3586 | { finish_handler ($<ttype>2); } |
8d2733ca | 3587 | ; |
8d08fdba | 3588 | |
a4443a08 | 3589 | type_specifier_seq: |
c11b6f21 MS |
3590 | typed_typespecs %prec EMPTY |
3591 | | nonempty_cv_qualifiers %prec EMPTY | |
a4443a08 MS |
3592 | ; |
3593 | ||
8d2733ca MS |
3594 | handler_args: |
3595 | '(' ELLIPSIS ')' | |
b35d4555 | 3596 | { $$ = NULL_TREE; } |
a3b49ccd | 3597 | /* This doesn't allow reference parameters, the below does. |
a4443a08 | 3598 | | '(' type_specifier_seq absdcl ')' |
46b02c6d MS |
3599 | { check_for_new_type ("inside exception declarations", $2); |
3600 | expand_start_catch_block ($2.t, $3); } | |
a4443a08 | 3601 | | '(' type_specifier_seq ')' |
46b02c6d MS |
3602 | { check_for_new_type ("inside exception declarations", $2); |
3603 | expand_start_catch_block ($2.t, NULL_TREE); } | |
a4443a08 | 3604 | | '(' type_specifier_seq notype_declarator ')' |
46b02c6d MS |
3605 | { check_for_new_type ("inside exception declarations", $2); |
3606 | expand_start_catch_block ($2.t, $3); } | |
a4443a08 | 3607 | | '(' typed_typespecs after_type_declarator ')' |
46b02c6d MS |
3608 | { check_for_new_type ("inside exception declarations", $2); |
3609 | expand_start_catch_block ($2.t, $3); } | |
e92cc029 | 3610 | This allows reference parameters... */ |
a3b49ccd | 3611 | | '(' parm ')' |
84d901be | 3612 | { |
3c5c0849 | 3613 | check_for_new_type ("inside exception declarations", $2); |
b35d4555 MM |
3614 | $$ = start_handler_parms (TREE_PURPOSE ($2.t), |
3615 | TREE_VALUE ($2.t)); | |
3c5c0849 | 3616 | } |
8d2733ca | 3617 | ; |
8d08fdba | 3618 | |
8d2733ca MS |
3619 | label_colon: |
3620 | IDENTIFIER ':' | |
f01b0acb | 3621 | { finish_label_stmt ($1); } |
8d2733ca | 3622 | | PTYPENAME ':' |
f01b0acb | 3623 | { finish_label_stmt ($1); } |
84d901be | 3624 | | tTYPENAME ':' |
f01b0acb | 3625 | { finish_label_stmt ($1); } |
a80e4195 | 3626 | | SELFNAME ':' |
f01b0acb | 3627 | { finish_label_stmt ($1); } |
8d08fdba MS |
3628 | ; |
3629 | ||
863adfc0 MS |
3630 | for.init.statement: |
3631 | xexpr ';' | |
558475f0 | 3632 | { finish_expr_stmt ($1); } |
863adfc0 MS |
3633 | | decl |
3634 | | '{' compstmtend | |
72b7eeff | 3635 | { if (pedantic) |
cab1f180 | 3636 | pedwarn ("ISO C++ forbids compound statements inside for initializations"); |
72b7eeff | 3637 | } |
8d08fdba MS |
3638 | ; |
3639 | ||
3640 | /* Either a type-qualifier or nothing. First thing in an `asm' statement. */ | |
3641 | ||
c11b6f21 MS |
3642 | maybe_cv_qualifier: |
3643 | /* empty */ | |
574a0ef5 | 3644 | { $$ = NULL_TREE; } |
c11b6f21 | 3645 | | CV_QUALIFIER |
8d08fdba MS |
3646 | ; |
3647 | ||
3648 | xexpr: | |
c11b6f21 | 3649 | /* empty */ |
8d08fdba MS |
3650 | { $$ = NULL_TREE; } |
3651 | | expr | |
3652 | | error | |
3653 | { $$ = NULL_TREE; } | |
3654 | ; | |
3655 | ||
3656 | /* These are the operands other than the first string and colon | |
3657 | in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */ | |
c11b6f21 MS |
3658 | asm_operands: |
3659 | /* empty */ | |
8d08fdba MS |
3660 | { $$ = NULL_TREE; } |
3661 | | nonnull_asm_operands | |
3662 | ; | |
3663 | ||
3664 | nonnull_asm_operands: | |
3665 | asm_operand | |
3666 | | nonnull_asm_operands ',' asm_operand | |
3667 | { $$ = chainon ($$, $3); } | |
3668 | ; | |
3669 | ||
3670 | asm_operand: | |
3671 | STRING '(' expr ')' | |
84b72302 RH |
3672 | { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); } |
3673 | | '[' identifier ']' STRING '(' expr ')' | |
fc552851 RS |
3674 | { $2 = build_string (IDENTIFIER_LENGTH ($2), |
3675 | IDENTIFIER_POINTER ($2)); | |
3676 | $$ = build_tree_list (build_tree_list ($2, $4), $6); } | |
8d08fdba MS |
3677 | ; |
3678 | ||
3679 | asm_clobbers: | |
b84a3874 RH |
3680 | STRING |
3681 | { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);} | |
3682 | | asm_clobbers ',' STRING | |
3683 | { $$ = tree_cons (NULL_TREE, $3, $1); } | |
8d08fdba MS |
3684 | ; |
3685 | ||
3686 | /* This is what appears inside the parens in a function declarator. | |
3687 | Its value is represented in the format that grokdeclarator expects. | |
3688 | ||
3689 | In C++, declaring a function with no parameters | |
3690 | means that that function takes *no* parameters. */ | |
51c184be | 3691 | |
c11b6f21 MS |
3692 | parmlist: |
3693 | /* empty */ | |
8d08fdba | 3694 | { |
46b02c6d | 3695 | $$ = empty_parms(); |
8d08fdba | 3696 | } |
51c184be MS |
3697 | | complex_parmlist |
3698 | | type_id | |
ce4a0391 | 3699 | { $$ = finish_parmlist (build_tree_list (NULL_TREE, $1.t), 0); |
46b02c6d | 3700 | check_for_new_type ("inside parameter list", $1); } |
51c184be MS |
3701 | ; |
3702 | ||
3703 | /* This nonterminal does not include the common sequence '(' type_id ')', | |
3704 | as it is ambiguous and must be disambiguated elsewhere. */ | |
3705 | complex_parmlist: | |
3706 | parms | |
ce4a0391 | 3707 | { $$ = finish_parmlist ($$, 0); } |
51c184be | 3708 | | parms_comma ELLIPSIS |
ce4a0391 | 3709 | { $$ = finish_parmlist ($1, 1); } |
8d08fdba MS |
3710 | /* C++ allows an ellipsis without a separating ',' */ |
3711 | | parms ELLIPSIS | |
ce4a0391 | 3712 | { $$ = finish_parmlist ($1, 1); } |
51c184be | 3713 | | type_id ELLIPSIS |
ce4a0391 | 3714 | { $$ = finish_parmlist (build_tree_list (NULL_TREE, |
84d901be | 3715 | $1.t), 1); } |
8d08fdba | 3716 | | ELLIPSIS |
ce4a0391 | 3717 | { $$ = finish_parmlist (NULL_TREE, 1); } |
8d08fdba MS |
3718 | | parms ':' |
3719 | { | |
3720 | /* This helps us recover from really nasty | |
3721 | parse errors, for example, a missing right | |
3722 | parenthesis. */ | |
3723 | yyerror ("possibly missing ')'"); | |
ce4a0391 | 3724 | $$ = finish_parmlist ($1, 0); |
8d08fdba MS |
3725 | yyungetc (':', 0); |
3726 | yychar = ')'; | |
3727 | } | |
51c184be MS |
3728 | | type_id ':' |
3729 | { | |
3730 | /* This helps us recover from really nasty | |
3731 | parse errors, for example, a missing right | |
3732 | parenthesis. */ | |
3733 | yyerror ("possibly missing ')'"); | |
ce4a0391 | 3734 | $$ = finish_parmlist (build_tree_list (NULL_TREE, |
84d901be | 3735 | $1.t), 0); |
51c184be MS |
3736 | yyungetc (':', 0); |
3737 | yychar = ')'; | |
3738 | } | |
8d08fdba MS |
3739 | ; |
3740 | ||
42976354 BK |
3741 | /* A default argument to a */ |
3742 | defarg: | |
3743 | '=' | |
3744 | { maybe_snarf_defarg (); } | |
3745 | defarg1 | |
3746 | { $$ = $3; } | |
3747 | ; | |
3748 | ||
3749 | defarg1: | |
3750 | DEFARG | |
3751 | | init | |
3752 | ; | |
3753 | ||
8d08fdba MS |
3754 | /* A nonempty list of parameter declarations or type names. */ |
3755 | parms: | |
51c184be | 3756 | named_parm |
46b02c6d MS |
3757 | { check_for_new_type ("in a parameter list", $1); |
3758 | $$ = build_tree_list (NULL_TREE, $1.t); } | |
42976354 | 3759 | | parm defarg |
46b02c6d | 3760 | { check_for_new_type ("in a parameter list", $1); |
42976354 | 3761 | $$ = build_tree_list ($2, $1.t); } |
a292b002 | 3762 | | parms_comma full_parm |
46b02c6d MS |
3763 | { check_for_new_type ("in a parameter list", $2); |
3764 | $$ = chainon ($$, $2.t); } | |
51c184be MS |
3765 | | parms_comma bad_parm |
3766 | { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); } | |
3767 | | parms_comma bad_parm '=' init | |
3768 | { $$ = chainon ($$, build_tree_list ($4, $2)); } | |
3769 | ; | |
3770 | ||
3771 | parms_comma: | |
3772 | parms ',' | |
3773 | | type_id ',' | |
46b02c6d MS |
3774 | { check_for_new_type ("in a parameter list", $1); |
3775 | $$ = build_tree_list (NULL_TREE, $1.t); } | |
8d08fdba MS |
3776 | ; |
3777 | ||
3778 | /* A single parameter declaration or parameter type name, | |
c11b6f21 | 3779 | as found in a parmlist. */ |
51c184be | 3780 | named_parm: |
51c184be MS |
3781 | /* Here we expand typed_declspecs inline to avoid mis-parsing of |
3782 | TYPESPEC IDENTIFIER. */ | |
3783 | typed_declspecs1 declarator | |
98884b26 JM |
3784 | { $$.new_type_flag = $1.new_type_flag; |
3785 | $$.t = build_tree_list ($1.t, $2); } | |
51c184be | 3786 | | typed_typespecs declarator |
84d901be | 3787 | { $$.t = build_tree_list ($1.t, $2); |
46b02c6d | 3788 | $$.new_type_flag = $1.new_type_flag; } |
51c184be | 3789 | | typespec declarator |
1f8f4a0b | 3790 | { $$.t = build_tree_list (build_tree_list (NULL_TREE, $1.t), |
84d901be | 3791 | $2); |
46b02c6d | 3792 | $$.new_type_flag = $1.new_type_flag; } |
51c184be | 3793 | | typed_declspecs1 absdcl |
98884b26 | 3794 | { $$.t = build_tree_list ($1.t, $2); |
46b02c6d | 3795 | $$.new_type_flag = $1.new_type_flag; } |
c11b6f21 | 3796 | | typed_declspecs1 %prec EMPTY |
84d901be | 3797 | { $$.t = build_tree_list ($1.t, NULL_TREE); |
46b02c6d | 3798 | $$.new_type_flag = $1.new_type_flag; } |
51c184be | 3799 | | declmods notype_declarator |
84d901be | 3800 | { $$.t = build_tree_list ($1.t, $2); |
46b02c6d | 3801 | $$.new_type_flag = 0; } |
8d08fdba MS |
3802 | ; |
3803 | ||
a292b002 | 3804 | full_parm: |
42976354 BK |
3805 | parm |
3806 | { $$.t = build_tree_list (NULL_TREE, $1.t); | |
3807 | $$.new_type_flag = $1.new_type_flag; } | |
3808 | | parm defarg | |
46b02c6d MS |
3809 | { $$.t = build_tree_list ($2, $1.t); |
3810 | $$.new_type_flag = $1.new_type_flag; } | |
a292b002 MS |
3811 | ; |
3812 | ||
51c184be | 3813 | parm: |
c11b6f21 | 3814 | named_parm |
51c184be | 3815 | | type_id |
8d08fdba MS |
3816 | ; |
3817 | ||
c11b6f21 MS |
3818 | see_typename: |
3819 | /* empty */ %prec EMPTY | |
3820 | { see_typename (); } | |
8d08fdba MS |
3821 | ; |
3822 | ||
8d08fdba | 3823 | bad_parm: |
51c184be MS |
3824 | /* empty */ %prec EMPTY |
3825 | { | |
8251199e | 3826 | error ("type specifier omitted for parameter"); |
6060a796 | 3827 | $$ = build_tree_list (integer_type_node, NULL_TREE); |
51c184be MS |
3828 | } |
3829 | | notype_declarator | |
8d08fdba | 3830 | { |
7d8e8369 NS |
3831 | if (TREE_CODE ($$) == SCOPE_REF) |
3832 | { | |
3833 | if (TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TYPE_PARM | |
3834 | || TREE_CODE (TREE_OPERAND ($$, 0)) == BOUND_TEMPLATE_TEMPLATE_PARM) | |
3835 | error ("`%E' is not a type, use `typename %E' to make it one", $$); | |
3836 | else | |
3837 | error ("no type `%D' in `%T'", TREE_OPERAND ($$, 1), TREE_OPERAND ($$, 0)); | |
3838 | } | |
3839 | else | |
3840 | error ("type specifier omitted for parameter `%E'", $$); | |
6060a796 | 3841 | $$ = build_tree_list (integer_type_node, $$); |
8d08fdba MS |
3842 | } |
3843 | ; | |
3844 | ||
fd8b7a0e GP |
3845 | bad_decl: |
3846 | IDENTIFIER template_arg_list_ignore IDENTIFIER arg_list_ignore ';' | |
3847 | { | |
33bd39a2 | 3848 | error("'%D' is used as a type, but is not defined as a type.", $1); |
fd8b7a0e GP |
3849 | $3 = error_mark_node; |
3850 | } | |
3851 | ; | |
3852 | ||
3853 | template_arg_list_ignore: | |
3854 | '<' template_arg_list_opt template_close_bracket | |
3855 | { } | |
3856 | | /* empty */ | |
3857 | ; | |
3858 | ||
3859 | arg_list_ignore: | |
3860 | '(' nonnull_exprlist ')' | |
3861 | { } | |
3862 | | /* empty */ | |
3863 | ; | |
3864 | ||
e3417fcd | 3865 | exception_specification_opt: |
c11b6f21 | 3866 | /* empty */ %prec EMPTY |
8d08fdba | 3867 | { $$ = NULL_TREE; } |
c11b6f21 | 3868 | | THROW '(' ansi_raise_identifiers ')' %prec EMPTY |
8d08fdba | 3869 | { $$ = $3; } |
c11b6f21 | 3870 | | THROW LEFT_RIGHT %prec EMPTY |
4cc1d462 | 3871 | { $$ = empty_except_spec; } |
8d08fdba MS |
3872 | ; |
3873 | ||
8d08fdba | 3874 | ansi_raise_identifier: |
51c184be | 3875 | type_id |
4cc1d462 NS |
3876 | { |
3877 | check_for_new_type ("exception specifier", $1); | |
3878 | $$ = groktypename ($1.t); | |
3879 | } | |
7437519c ZW |
3880 | | error |
3881 | { $$ = error_mark_node; } | |
8d08fdba MS |
3882 | ; |
3883 | ||
8d08fdba MS |
3884 | ansi_raise_identifiers: |
3885 | ansi_raise_identifier | |
4cc1d462 | 3886 | { $$ = add_exception_specifier (NULL_TREE, $1, 1); } |
8d08fdba | 3887 | | ansi_raise_identifiers ',' ansi_raise_identifier |
4cc1d462 | 3888 | { $$ = add_exception_specifier ($1, $3, 1); } |
8d08fdba MS |
3889 | ; |
3890 | ||
51c184be | 3891 | conversion_declarator: |
c11b6f21 | 3892 | /* empty */ %prec EMPTY |
51c184be | 3893 | { $$ = NULL_TREE; } |
c11b6f21 | 3894 | | '*' cv_qualifiers conversion_declarator |
51c184be | 3895 | { $$ = make_pointer_declarator ($2, $3); } |
c11b6f21 | 3896 | | '&' cv_qualifiers conversion_declarator |
51c184be | 3897 | { $$ = make_reference_declarator ($2, $3); } |
c11b6f21 | 3898 | | ptr_to_mem cv_qualifiers conversion_declarator |
a28e3c7f | 3899 | { tree arg = make_pointer_declarator ($2, $3); |
718b8ea5 | 3900 | $$ = build_nt (SCOPE_REF, $1, arg); |
51c184be MS |
3901 | } |
3902 | ; | |
3903 | ||
c11b6f21 | 3904 | operator: |
f2d71db6 | 3905 | OPERATOR |
aca77bd1 JM |
3906 | { |
3907 | saved_scopes = tree_cons (got_scope, got_object, saved_scopes); | |
5361cbb7 | 3908 | TREE_LANG_FLAG_0 (saved_scopes) = looking_for_typename; |
aca77bd1 JM |
3909 | /* We look for conversion-type-id's in both the class and current |
3910 | scopes, just as for ID in 'ptr->ID::'. */ | |
5361cbb7 NS |
3911 | looking_for_typename = 1; |
3912 | got_object = got_scope; | |
aca77bd1 JM |
3913 | got_scope = NULL_TREE; |
3914 | } | |
f2d71db6 | 3915 | ; |
aca77bd1 | 3916 | |
f2d71db6 NS |
3917 | unoperator: |
3918 | { got_scope = TREE_PURPOSE (saved_scopes); | |
3919 | got_object = TREE_VALUE (saved_scopes); | |
5361cbb7 NS |
3920 | looking_for_typename = TREE_LANG_FLAG_0 (saved_scopes); |
3921 | saved_scopes = TREE_CHAIN (saved_scopes); | |
3922 | } | |
f2d71db6 | 3923 | ; |
a28e3c7f | 3924 | |
8d08fdba | 3925 | operator_name: |
f2d71db6 NS |
3926 | operator '*' unoperator |
3927 | { $$ = frob_opname (ansi_opname (MULT_EXPR)); } | |
3928 | | operator '/' unoperator | |
3929 | { $$ = frob_opname (ansi_opname (TRUNC_DIV_EXPR)); } | |
3930 | | operator '%' unoperator | |
3931 | { $$ = frob_opname (ansi_opname (TRUNC_MOD_EXPR)); } | |
3932 | | operator '+' unoperator | |
3933 | { $$ = frob_opname (ansi_opname (PLUS_EXPR)); } | |
3934 | | operator '-' unoperator | |
3935 | { $$ = frob_opname (ansi_opname (MINUS_EXPR)); } | |
3936 | | operator '&' unoperator | |
3937 | { $$ = frob_opname (ansi_opname (BIT_AND_EXPR)); } | |
3938 | | operator '|' unoperator | |
3939 | { $$ = frob_opname (ansi_opname (BIT_IOR_EXPR)); } | |
3940 | | operator '^' unoperator | |
3941 | { $$ = frob_opname (ansi_opname (BIT_XOR_EXPR)); } | |
3942 | | operator '~' unoperator | |
3943 | { $$ = frob_opname (ansi_opname (BIT_NOT_EXPR)); } | |
3944 | | operator ',' unoperator | |
3945 | { $$ = frob_opname (ansi_opname (COMPOUND_EXPR)); } | |
3946 | | operator ARITHCOMPARE unoperator | |
3947 | { $$ = frob_opname (ansi_opname ($2)); } | |
3948 | | operator '<' unoperator | |
3949 | { $$ = frob_opname (ansi_opname (LT_EXPR)); } | |
3950 | | operator '>' unoperator | |
3951 | { $$ = frob_opname (ansi_opname (GT_EXPR)); } | |
3952 | | operator EQCOMPARE unoperator | |
3953 | { $$ = frob_opname (ansi_opname ($2)); } | |
3954 | | operator ASSIGN unoperator | |
3955 | { $$ = frob_opname (ansi_assopname ($2)); } | |
3956 | | operator '=' unoperator | |
3957 | { $$ = frob_opname (ansi_assopname (NOP_EXPR)); } | |
3958 | | operator LSHIFT unoperator | |
3959 | { $$ = frob_opname (ansi_opname ($2)); } | |
3960 | | operator RSHIFT unoperator | |
3961 | { $$ = frob_opname (ansi_opname ($2)); } | |
3962 | | operator PLUSPLUS unoperator | |
3963 | { $$ = frob_opname (ansi_opname (POSTINCREMENT_EXPR)); } | |
3964 | | operator MINUSMINUS unoperator | |
3965 | { $$ = frob_opname (ansi_opname (PREDECREMENT_EXPR)); } | |
3966 | | operator ANDAND unoperator | |
3967 | { $$ = frob_opname (ansi_opname (TRUTH_ANDIF_EXPR)); } | |
3968 | | operator OROR unoperator | |
3969 | { $$ = frob_opname (ansi_opname (TRUTH_ORIF_EXPR)); } | |
3970 | | operator '!' unoperator | |
3971 | { $$ = frob_opname (ansi_opname (TRUTH_NOT_EXPR)); } | |
3972 | | operator '?' ':' unoperator | |
3973 | { $$ = frob_opname (ansi_opname (COND_EXPR)); } | |
3974 | | operator MIN_MAX unoperator | |
3975 | { $$ = frob_opname (ansi_opname ($2)); } | |
3976 | | operator POINTSAT unoperator %prec EMPTY | |
3977 | { $$ = frob_opname (ansi_opname (COMPONENT_REF)); } | |
3978 | | operator POINTSAT_STAR unoperator %prec EMPTY | |
3979 | { $$ = frob_opname (ansi_opname (MEMBER_REF)); } | |
3980 | | operator LEFT_RIGHT unoperator | |
3981 | { $$ = frob_opname (ansi_opname (CALL_EXPR)); } | |
3982 | | operator '[' ']' unoperator | |
3983 | { $$ = frob_opname (ansi_opname (ARRAY_REF)); } | |
3984 | | operator NEW unoperator %prec EMPTY | |
3985 | { $$ = frob_opname (ansi_opname (NEW_EXPR)); } | |
3986 | | operator DELETE unoperator %prec EMPTY | |
3987 | { $$ = frob_opname (ansi_opname (DELETE_EXPR)); } | |
3988 | | operator NEW '[' ']' unoperator | |
3989 | { $$ = frob_opname (ansi_opname (VEC_NEW_EXPR)); } | |
3990 | | operator DELETE '[' ']' unoperator | |
3991 | { $$ = frob_opname (ansi_opname (VEC_DELETE_EXPR)); } | |
f2d71db6 NS |
3992 | | operator type_specifier_seq conversion_declarator unoperator |
3993 | { $$ = frob_opname (grokoptypename ($2.t, $3)); } | |
3994 | | operator error unoperator | |
3995 | { $$ = frob_opname (ansi_opname (ERROR_MARK)); } | |
8d08fdba MS |
3996 | ; |
3997 | ||
3e4d04a1 RH |
3998 | /* The forced readahead in here is because we might be at the end of a |
3999 | line, and lineno won't be bumped until yylex absorbs the first token | |
4000 | on the next line. */ | |
4001 | save_lineno: | |
4002 | { if (yychar == YYEMPTY) | |
4003 | yychar = YYLEX; | |
4004 | $$ = lineno; } | |
4005 | ; | |
8d08fdba | 4006 | %% |
00595019 MS |
4007 | |
4008 | #ifdef SPEW_DEBUG | |
4009 | const char * | |
4010 | debug_yytranslate (value) | |
4011 | int value; | |
4012 | { | |
4013 | return yytname[YYTRANSLATE (value)]; | |
4014 | } | |
00595019 | 4015 | #endif |
94a50397 RH |
4016 | |
4017 | /* Free malloced parser stacks if necessary. */ | |
4018 | ||
4019 | void | |
4020 | free_parser_stacks () | |
4021 | { | |
4022 | if (malloced_yyss) | |
4023 | { | |
4024 | free (malloced_yyss); | |
4025 | free (malloced_yyvs); | |
4026 | } | |
4027 | } | |
e2500fed | 4028 | |
80b1331c MM |
4029 | /* Return the value corresponding to TOKEN in the global scope. */ |
4030 | ||
4031 | static tree | |
4032 | parse_scoped_id (token) | |
4033 | tree token; | |
4034 | { | |
4035 | tree id; | |
4036 | ||
4037 | id = make_node (CPLUS_BINDING); | |
4038 | if (!qualified_lookup_using_namespace (token, global_namespace, id, 0)) | |
4039 | id = NULL_TREE; | |
4040 | else | |
4041 | id = BINDING_VALUE (id); | |
4042 | if (yychar == YYEMPTY) | |
4043 | yychar = yylex(); | |
4044 | ||
4045 | return do_scoped_id (token, id); | |
4046 | } | |
4047 | ||
88e5899c MM |
4048 | /* AGGR may be either a type node (like class_type_node) or a |
4049 | TREE_LIST whose TREE_PURPOSE is a list of attributes and whose | |
4050 | TREE_VALUE is a type node. Set *TAG_KIND and *ATTRIBUTES to | |
4051 | represent the information encoded. */ | |
4052 | ||
4053 | static void | |
4054 | parse_split_aggr (tree aggr, enum tag_types *tag_kind, tree *attributes) | |
4055 | { | |
4056 | if (TREE_CODE (aggr) == TREE_LIST) | |
4057 | { | |
4058 | *attributes = TREE_PURPOSE (aggr); | |
4059 | aggr = TREE_VALUE (aggr); | |
4060 | } | |
4061 | else | |
4062 | *attributes = NULL_TREE; | |
4063 | *tag_kind = (enum tag_types) tree_low_cst (aggr, 1); | |
4064 | } | |
4065 | ||
4066 | /* Like xref_tag, except that the AGGR may be either a type node (like | |
4067 | class_type_node) or a TREE_LIST whose TREE_PURPOSE is a list of | |
4068 | attributes and whose TREE_VALUE is a type node. */ | |
4069 | ||
4070 | static tree | |
4071 | parse_xref_tag (tree aggr, tree name, int globalize) | |
4072 | { | |
4073 | tree attributes; | |
4074 | enum tag_types tag_kind; | |
4075 | parse_split_aggr (aggr, &tag_kind, &attributes); | |
4076 | return xref_tag (tag_kind, name, attributes, globalize); | |
4077 | } | |
4078 | ||
eb8845be | 4079 | /* Like handle_class_head, but AGGR may be as for parse_xref_tag. */ |
88e5899c MM |
4080 | |
4081 | static tree | |
4082 | parse_handle_class_head (tree aggr, tree scope, tree id, | |
4083 | int defn_p, int *new_type_p) | |
4084 | { | |
4085 | tree attributes; | |
4086 | enum tag_types tag_kind; | |
4087 | parse_split_aggr (aggr, &tag_kind, &attributes); | |
4088 | return handle_class_head (tag_kind, scope, id, attributes, | |
4089 | defn_p, new_type_p); | |
4090 | } | |
4091 | ||
eb8845be MM |
4092 | /* Like do_decl_instantiation, but the declarator has not yet been |
4093 | parsed. */ | |
4094 | ||
4095 | static void | |
4096 | parse_decl_instantiation (tree declspecs, tree declarator, tree storage) | |
4097 | { | |
4098 | tree decl = grokdeclarator (declarator, declspecs, NORMAL, 0, NULL); | |
4099 | do_decl_instantiation (decl, storage); | |
4100 | } | |
4101 | ||
15c7fb9c MM |
4102 | /* Like begin_function_definition, but SPECS_ATTRS is a combined list |
4103 | containing both a decl-specifier-seq and attributes. */ | |
4104 | ||
4105 | static int | |
4106 | parse_begin_function_definition (tree specs_attrs, tree declarator) | |
4107 | { | |
4108 | tree specs; | |
4109 | tree attrs; | |
4110 | ||
4111 | split_specs_attrs (specs_attrs, &specs, &attrs); | |
4112 | return begin_function_definition (specs, attrs, declarator); | |
4113 | } | |
4114 | ||
4ba126e4 MM |
4115 | /* Like finish_call_expr, but the name for FN has not yet been |
4116 | resolved. */ | |
4117 | ||
4118 | static tree | |
4119 | parse_finish_call_expr (tree fn, tree args, int koenig) | |
4120 | { | |
4121 | bool disallow_virtual; | |
4122 | tree template_args; | |
4123 | tree template_id; | |
4124 | tree f; | |
4125 | ||
4126 | if (TREE_CODE (fn) == OFFSET_REF) | |
4127 | return build_offset_ref_call_from_tree (fn, args); | |
4128 | ||
4129 | if (TREE_CODE (fn) == SCOPE_REF) | |
4130 | { | |
4131 | tree scope; | |
4132 | tree name; | |
4133 | ||
4134 | scope = TREE_OPERAND (fn, 0); | |
4135 | name = TREE_OPERAND (fn, 1); | |
4136 | ||
4137 | if (scope == error_mark_node || name == error_mark_node) | |
4138 | return error_mark_node; | |
4139 | if (!processing_template_decl) | |
4140 | { | |
4141 | if (TREE_CODE (scope) == NAMESPACE_DECL) | |
4142 | fn = lookup_namespace_name (scope, name); | |
4143 | else | |
4144 | { | |
e8fe46d4 GDR |
4145 | if (!COMPLETE_TYPE_P (scope) && !TYPE_BEING_DEFINED (scope)) |
4146 | { | |
4147 | error ("incomplete type '%T' cannot be used to name a scope", | |
4148 | scope); | |
4149 | return error_mark_node; | |
4150 | } | |
4151 | else if (TREE_CODE (name) == TEMPLATE_ID_EXPR) | |
4ba126e4 MM |
4152 | { |
4153 | template_id = name; | |
4154 | template_args = TREE_OPERAND (name, 1); | |
4155 | name = TREE_OPERAND (name, 0); | |
4156 | } | |
4157 | else | |
e65e6212 KG |
4158 | { |
4159 | template_id = NULL_TREE; | |
4160 | template_args = NULL_TREE; | |
4161 | } | |
4ba126e4 | 4162 | |
50ad9642 MM |
4163 | if (BASELINK_P (name)) |
4164 | fn = name; | |
4165 | else | |
4166 | { | |
4167 | if (TREE_CODE (name) == OVERLOAD) | |
4168 | name = DECL_NAME (get_first_fn (name)); | |
4169 | fn = lookup_member (scope, name, /*protect=*/1, | |
4170 | /*prefer_type=*/0); | |
7979434d NS |
4171 | if (!fn) |
4172 | { | |
4173 | error ("'%D' has no member named '%E'", scope, name); | |
4174 | return error_mark_node; | |
4175 | } | |
4176 | ||
50ad9642 MM |
4177 | if (BASELINK_P (fn) && template_id) |
4178 | BASELINK_FUNCTIONS (fn) | |
4179 | = build_nt (TEMPLATE_ID_EXPR, | |
4180 | BASELINK_FUNCTIONS (fn), | |
4181 | template_args); | |
4182 | } | |
9e259dd1 MM |
4183 | if (current_class_type) |
4184 | fn = (adjust_result_of_qualified_name_lookup | |
4185 | (fn, scope, current_class_type)); | |
4ba126e4 MM |
4186 | } |
4187 | } | |
4188 | disallow_virtual = true; | |
4189 | } | |
4190 | else | |
4191 | disallow_virtual = false; | |
4192 | ||
4193 | if (koenig && TREE_CODE (fn) == IDENTIFIER_NODE) | |
4194 | { | |
4195 | /* Do the Koenig lookup. */ | |
4196 | fn = do_identifier (fn, 2, args); | |
4197 | /* If name lookup didn't find any matching declarations, we've | |
4198 | got an unbound identifier. */ | |
4199 | if (TREE_CODE (fn) == IDENTIFIER_NODE) | |
4200 | { | |
4201 | /* For some reason, do_identifier does not resolve | |
4202 | conversion operator names if the only matches would be | |
4203 | template conversion operators. So, we do it here. */ | |
4204 | if (IDENTIFIER_TYPENAME_P (fn) && current_class_type) | |
4205 | { | |
4206 | f = lookup_member (current_class_type, fn, | |
4207 | /*protect=*/1, /*want_type=*/0); | |
4208 | if (f) | |
4209 | return finish_call_expr (f, args, | |
4210 | /*disallow_virtual=*/false); | |
4211 | } | |
4212 | /* If the name still could not be resolved, then the program | |
4213 | is ill-formed. */ | |
4214 | if (TREE_CODE (fn) == IDENTIFIER_NODE) | |
4215 | { | |
4216 | unqualified_name_lookup_error (fn); | |
4217 | return error_mark_node; | |
4218 | } | |
4219 | } | |
4220 | else if (TREE_CODE (fn) == FUNCTION_DECL | |
4221 | || DECL_FUNCTION_TEMPLATE_P (fn) | |
4222 | || TREE_CODE (fn) == OVERLOAD) | |
4223 | { | |
4224 | tree scope = DECL_CONTEXT (get_first_fn (fn)); | |
4225 | if (scope && TYPE_P (scope)) | |
4226 | { | |
4227 | tree access_scope; | |
4228 | ||
4229 | if (DERIVED_FROM_P (scope, current_class_type) | |
4230 | && current_class_ref) | |
50ad9642 MM |
4231 | { |
4232 | fn = build_baselink (lookup_base (current_class_type, | |
4233 | scope, | |
4234 | ba_any, | |
4235 | NULL), | |
4236 | TYPE_BINFO (current_class_type), | |
4237 | fn, | |
4238 | /*optype=*/NULL_TREE); | |
4239 | return finish_object_call_expr (fn, | |
4240 | current_class_ref, | |
4241 | args); | |
4242 | } | |
4243 | ||
4ba126e4 MM |
4244 | |
4245 | access_scope = current_class_type; | |
4246 | while (!DERIVED_FROM_P (scope, access_scope)) | |
4247 | { | |
4248 | access_scope = TYPE_CONTEXT (access_scope); | |
4249 | while (DECL_P (access_scope)) | |
4250 | access_scope = DECL_CONTEXT (access_scope); | |
4251 | } | |
4252 | ||
4253 | fn = build_baselink (NULL_TREE, | |
4254 | TYPE_BINFO (access_scope), | |
4255 | fn, | |
4256 | /*optype=*/NULL_TREE); | |
4257 | } | |
4258 | } | |
4259 | } | |
4260 | ||
4261 | if (TREE_CODE (fn) == COMPONENT_REF) | |
4262 | /* If the parser sees `(x->y)(bar)' we get here because the | |
4263 | parentheses confuse the parser. Treat this like | |
4264 | `x->y(bar)'. */ | |
4265 | return finish_object_call_expr (TREE_OPERAND (fn, 1), | |
4266 | TREE_OPERAND (fn, 0), | |
4267 | args); | |
4268 | ||
4269 | if (processing_template_decl) | |
4270 | return build_nt (CALL_EXPR, fn, args, NULL_TREE); | |
4271 | ||
4272 | return build_call_from_tree (fn, args, disallow_virtual); | |
4273 | } | |
4274 | ||
e2500fed | 4275 | #include "gt-cp-parse.h" |