]>
Commit | Line | Data |
---|---|---|
ad321293 MM |
1 | /* Perform the semantic phase of parsing, i.e., the process of |
2 | building tree structure, checking semantic consistency, and | |
3 | building RTL. These routines are used both during actual parsing | |
4 | and during the instantiation of template functions. | |
5 | ||
5088b058 RH |
6 | Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
7 | Free Software Foundation, Inc. | |
ad321293 MM |
8 | Written by Mark Mitchell (mmitchell@usa.net) based on code found |
9 | formerly in parse.y and pt.c. | |
10 | ||
f5adbb8d | 11 | This file is part of GCC. |
ad321293 | 12 | |
f5adbb8d | 13 | GCC is free software; you can redistribute it and/or modify it |
ad321293 MM |
14 | under the terms of the GNU General Public License as published by |
15 | the Free Software Foundation; either version 2, or (at your option) | |
16 | any later version. | |
17 | ||
f5adbb8d | 18 | GCC is distributed in the hope that it will be useful, but |
ad321293 MM |
19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | General Public License for more details. | |
22 | ||
23 | You should have received a copy of the GNU General Public License | |
f5adbb8d | 24 | along with GCC; see the file COPYING. If not, write to the Free |
ad321293 MM |
25 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
26 | 02111-1307, USA. */ | |
27 | ||
28 | #include "config.h" | |
8d052bc7 | 29 | #include "system.h" |
4977bab6 ZW |
30 | #include "coretypes.h" |
31 | #include "tm.h" | |
ad321293 MM |
32 | #include "tree.h" |
33 | #include "cp-tree.h" | |
25af8512 | 34 | #include "tree-inline.h" |
6de9cd9a | 35 | #include "tree-mudflap.h" |
ad321293 | 36 | #include "except.h" |
12027a89 | 37 | #include "toplev.h" |
84df082b | 38 | #include "flags.h" |
d9b2d9da | 39 | #include "rtl.h" |
d6684bc8 | 40 | #include "expr.h" |
225ff119 | 41 | #include "output.h" |
ea11ca7e | 42 | #include "timevar.h" |
2b85879e | 43 | #include "debug.h" |
6de9cd9a | 44 | #include "diagnostic.h" |
8cd2462c | 45 | #include "cgraph.h" |
325c3691 | 46 | #include "tree-iterator.h" |
ad321293 MM |
47 | |
48 | /* There routines provide a modular interface to perform many parsing | |
49 | operations. They may therefore be used during actual parsing, or | |
50 | during template instantiation, which may be regarded as a | |
51 | degenerate form of parsing. Since the current g++ parser is | |
52 | lacking in several respects, and will be reimplemented, we are | |
53 | attempting to move most code that is not directly related to | |
54 | parsing into this file; that will make implementing the new parser | |
55 | much easier since it will be able to make use of these routines. */ | |
56 | ||
3a978d72 NN |
57 | static tree maybe_convert_cond (tree); |
58 | static tree simplify_aggr_init_exprs_r (tree *, int *, void *); | |
59 | static void emit_associated_thunks (tree); | |
6de9cd9a | 60 | static tree finalize_nrv_r (tree *, int *, void *); |
4985cde3 | 61 | |
558475f0 | 62 | |
8d241e0b KL |
63 | /* Deferred Access Checking Overview |
64 | --------------------------------- | |
65 | ||
66 | Most C++ expressions and declarations require access checking | |
67 | to be performed during parsing. However, in several cases, | |
68 | this has to be treated differently. | |
69 | ||
70 | For member declarations, access checking has to be deferred | |
71 | until more information about the declaration is known. For | |
72 | example: | |
73 | ||
74 | class A { | |
75 | typedef int X; | |
76 | public: | |
77 | X f(); | |
78 | }; | |
79 | ||
80 | A::X A::f(); | |
81 | A::X g(); | |
82 | ||
83 | When we are parsing the function return type `A::X', we don't | |
84 | really know if this is allowed until we parse the function name. | |
85 | ||
86 | Furthermore, some contexts require that access checking is | |
87 | never performed at all. These include class heads, and template | |
88 | instantiations. | |
89 | ||
90 | Typical use of access checking functions is described here: | |
91 | ||
92 | 1. When we enter a context that requires certain access checking | |
93 | mode, the function `push_deferring_access_checks' is called with | |
94 | DEFERRING argument specifying the desired mode. Access checking | |
95 | may be performed immediately (dk_no_deferred), deferred | |
96 | (dk_deferred), or not performed (dk_no_check). | |
97 | ||
98 | 2. When a declaration such as a type, or a variable, is encountered, | |
99 | the function `perform_or_defer_access_check' is called. It | |
100 | maintains a TREE_LIST of all deferred checks. | |
101 | ||
102 | 3. The global `current_class_type' or `current_function_decl' is then | |
103 | setup by the parser. `enforce_access' relies on these information | |
104 | to check access. | |
105 | ||
106 | 4. Upon exiting the context mentioned in step 1, | |
107 | `perform_deferred_access_checks' is called to check all declaration | |
108 | stored in the TREE_LIST. `pop_deferring_access_checks' is then | |
109 | called to restore the previous access checking mode. | |
110 | ||
111 | In case of parsing error, we simply call `pop_deferring_access_checks' | |
112 | without `perform_deferred_access_checks'. */ | |
113 | ||
cf22909c KL |
114 | /* Data for deferred access checking. */ |
115 | static GTY(()) deferred_access *deferred_access_stack; | |
116 | static GTY(()) deferred_access *deferred_access_free_list; | |
117 | ||
118 | /* Save the current deferred access states and start deferred | |
119 | access checking iff DEFER_P is true. */ | |
120 | ||
572c2b17 AP |
121 | void |
122 | push_deferring_access_checks (deferring_kind deferring) | |
cf22909c KL |
123 | { |
124 | deferred_access *d; | |
125 | ||
78757caa KL |
126 | /* For context like template instantiation, access checking |
127 | disabling applies to all nested context. */ | |
128 | if (deferred_access_stack | |
129 | && deferred_access_stack->deferring_access_checks_kind == dk_no_check) | |
130 | deferring = dk_no_check; | |
131 | ||
cf22909c KL |
132 | /* Recycle previously used free store if available. */ |
133 | if (deferred_access_free_list) | |
134 | { | |
135 | d = deferred_access_free_list; | |
136 | deferred_access_free_list = d->next; | |
137 | } | |
138 | else | |
c68b0a84 | 139 | d = ggc_alloc (sizeof (deferred_access)); |
cf22909c KL |
140 | |
141 | d->next = deferred_access_stack; | |
142 | d->deferred_access_checks = NULL_TREE; | |
8d241e0b | 143 | d->deferring_access_checks_kind = deferring; |
cf22909c KL |
144 | deferred_access_stack = d; |
145 | } | |
146 | ||
147 | /* Resume deferring access checks again after we stopped doing | |
148 | this previously. */ | |
149 | ||
572c2b17 AP |
150 | void |
151 | resume_deferring_access_checks (void) | |
cf22909c | 152 | { |
8d241e0b KL |
153 | if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred) |
154 | deferred_access_stack->deferring_access_checks_kind = dk_deferred; | |
cf22909c KL |
155 | } |
156 | ||
157 | /* Stop deferring access checks. */ | |
158 | ||
572c2b17 AP |
159 | void |
160 | stop_deferring_access_checks (void) | |
cf22909c | 161 | { |
8d241e0b KL |
162 | if (deferred_access_stack->deferring_access_checks_kind == dk_deferred) |
163 | deferred_access_stack->deferring_access_checks_kind = dk_no_deferred; | |
cf22909c KL |
164 | } |
165 | ||
166 | /* Discard the current deferred access checks and restore the | |
167 | previous states. */ | |
168 | ||
572c2b17 AP |
169 | void |
170 | pop_deferring_access_checks (void) | |
cf22909c KL |
171 | { |
172 | deferred_access *d = deferred_access_stack; | |
173 | deferred_access_stack = d->next; | |
174 | ||
175 | /* Remove references to access checks TREE_LIST. */ | |
176 | d->deferred_access_checks = NULL_TREE; | |
177 | ||
178 | /* Store in free list for later use. */ | |
179 | d->next = deferred_access_free_list; | |
180 | deferred_access_free_list = d; | |
181 | } | |
182 | ||
183 | /* Returns a TREE_LIST representing the deferred checks. | |
184 | The TREE_PURPOSE of each node is the type through which the | |
185 | access occurred; the TREE_VALUE is the declaration named. | |
186 | */ | |
187 | ||
572c2b17 AP |
188 | tree |
189 | get_deferred_access_checks (void) | |
cf22909c KL |
190 | { |
191 | return deferred_access_stack->deferred_access_checks; | |
192 | } | |
193 | ||
194 | /* Take current deferred checks and combine with the | |
195 | previous states if we also defer checks previously. | |
196 | Otherwise perform checks now. */ | |
197 | ||
572c2b17 AP |
198 | void |
199 | pop_to_parent_deferring_access_checks (void) | |
cf22909c KL |
200 | { |
201 | tree deferred_check = get_deferred_access_checks (); | |
202 | deferred_access *d1 = deferred_access_stack; | |
203 | deferred_access *d2 = deferred_access_stack->next; | |
204 | deferred_access *d3 = deferred_access_stack->next->next; | |
205 | ||
206 | /* Temporary swap the order of the top two states, just to make | |
207 | sure the garbage collector will not reclaim the memory during | |
208 | processing below. */ | |
209 | deferred_access_stack = d2; | |
210 | d2->next = d1; | |
211 | d1->next = d3; | |
212 | ||
213 | for ( ; deferred_check; deferred_check = TREE_CHAIN (deferred_check)) | |
214 | /* Perform deferred check if required. */ | |
215 | perform_or_defer_access_check (TREE_PURPOSE (deferred_check), | |
216 | TREE_VALUE (deferred_check)); | |
217 | ||
218 | deferred_access_stack = d1; | |
219 | d1->next = d2; | |
220 | d2->next = d3; | |
221 | pop_deferring_access_checks (); | |
222 | } | |
223 | ||
25903d03 KL |
224 | /* Perform the deferred access checks. |
225 | ||
226 | After performing the checks, we still have to keep the list | |
227 | `deferred_access_stack->deferred_access_checks' since we may want | |
228 | to check access for them again later in a different context. | |
229 | For example: | |
230 | ||
231 | class A { | |
232 | typedef int X; | |
233 | static X a; | |
234 | }; | |
235 | A::X A::a, x; // No error for `A::a', error for `x' | |
236 | ||
237 | We have to perform deferred access of `A::X', first with `A::a', | |
238 | next with `x'. */ | |
cf22909c | 239 | |
572c2b17 AP |
240 | void |
241 | perform_deferred_access_checks (void) | |
cf22909c KL |
242 | { |
243 | tree deferred_check; | |
244 | for (deferred_check = deferred_access_stack->deferred_access_checks; | |
245 | deferred_check; | |
246 | deferred_check = TREE_CHAIN (deferred_check)) | |
247 | /* Check access. */ | |
248 | enforce_access (TREE_PURPOSE (deferred_check), | |
249 | TREE_VALUE (deferred_check)); | |
cf22909c KL |
250 | } |
251 | ||
252 | /* Defer checking the accessibility of DECL, when looked up in | |
6df5158a | 253 | BINFO. */ |
cf22909c | 254 | |
572c2b17 AP |
255 | void |
256 | perform_or_defer_access_check (tree binfo, tree decl) | |
cf22909c KL |
257 | { |
258 | tree check; | |
259 | ||
0f2a66c9 NS |
260 | /* Exit if we are in a context that no access checking is performed. */ |
261 | if (deferred_access_stack->deferring_access_checks_kind == dk_no_check) | |
262 | return; | |
6df5158a | 263 | |
0f2a66c9 NS |
264 | my_friendly_assert (TREE_CODE (binfo) == TREE_VEC, 20030623); |
265 | ||
cf22909c | 266 | /* If we are not supposed to defer access checks, just check now. */ |
8d241e0b | 267 | if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred) |
cf22909c | 268 | { |
6df5158a | 269 | enforce_access (binfo, decl); |
cf22909c KL |
270 | return; |
271 | } | |
0f2a66c9 | 272 | |
cf22909c KL |
273 | /* See if we are already going to perform this check. */ |
274 | for (check = deferred_access_stack->deferred_access_checks; | |
275 | check; | |
276 | check = TREE_CHAIN (check)) | |
6df5158a | 277 | if (TREE_VALUE (check) == decl && TREE_PURPOSE (check) == binfo) |
cf22909c KL |
278 | return; |
279 | /* If not, record the check. */ | |
280 | deferred_access_stack->deferred_access_checks | |
6df5158a | 281 | = tree_cons (binfo, decl, |
cf22909c KL |
282 | deferred_access_stack->deferred_access_checks); |
283 | } | |
284 | ||
838dfd8a | 285 | /* Returns nonzero if the current statement is a full expression, |
f2c5f623 BC |
286 | i.e. temporaries created during that statement should be destroyed |
287 | at the end of the statement. */ | |
35b1567d | 288 | |
f2c5f623 | 289 | int |
3a978d72 | 290 | stmts_are_full_exprs_p (void) |
f2c5f623 | 291 | { |
ae499cce MM |
292 | return current_stmt_tree ()->stmts_are_full_exprs_p; |
293 | } | |
294 | ||
295 | /* Returns the stmt_tree (if any) to which statements are currently | |
296 | being added. If there is no active statement-tree, NULL is | |
297 | returned. */ | |
298 | ||
299 | stmt_tree | |
3a978d72 | 300 | current_stmt_tree (void) |
ae499cce MM |
301 | { |
302 | return (cfun | |
e2500fed | 303 | ? &cfun->language->base.x_stmt_tree |
ae499cce | 304 | : &scope_chain->x_stmt_tree); |
f2c5f623 | 305 | } |
35b1567d | 306 | |
543a0daa RH |
307 | /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */ |
308 | ||
309 | static tree | |
310 | maybe_cleanup_point_expr (tree expr) | |
311 | { | |
312 | if (!processing_template_decl && stmts_are_full_exprs_p ()) | |
313 | expr = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (expr), expr)); | |
314 | return expr; | |
315 | } | |
316 | ||
317 | /* Create a declaration statement for the declaration given by the DECL. */ | |
318 | ||
319 | void | |
350fae66 | 320 | add_decl_expr (tree decl) |
543a0daa | 321 | { |
350fae66 | 322 | tree r = build_stmt (DECL_EXPR, decl); |
543a0daa RH |
323 | if (DECL_INITIAL (decl)) |
324 | r = maybe_cleanup_point_expr (r); | |
325 | add_stmt (r); | |
326 | } | |
327 | ||
f2c5f623 BC |
328 | /* Nonzero if TYPE is an anonymous union or struct type. We have to use a |
329 | flag for this because "A union for which objects or pointers are | |
330 | declared is not an anonymous union" [class.union]. */ | |
35b1567d | 331 | |
f2c5f623 | 332 | int |
3a978d72 | 333 | anon_aggr_type_p (tree node) |
35b1567d | 334 | { |
e2500fed | 335 | return ANON_AGGR_TYPE_P (node); |
35b1567d BC |
336 | } |
337 | ||
f2c5f623 | 338 | /* Finish a scope. */ |
35b1567d | 339 | |
325c3691 RH |
340 | static tree |
341 | do_poplevel (tree stmt_list) | |
35b1567d | 342 | { |
325c3691 | 343 | tree block = NULL; |
35b1567d | 344 | |
f2c5f623 | 345 | if (stmts_are_full_exprs_p ()) |
325c3691 | 346 | block = poplevel (kept_level_p (), 1, 0); |
f2c5f623 | 347 | |
325c3691 RH |
348 | stmt_list = pop_stmt_list (stmt_list); |
349 | ||
350 | if (!processing_template_decl) | |
351 | { | |
352 | stmt_list = c_build_bind_expr (block, stmt_list); | |
353 | /* ??? See c_end_compound_stmt re statement expressions. */ | |
35b1567d BC |
354 | } |
355 | ||
325c3691 | 356 | return stmt_list; |
35b1567d BC |
357 | } |
358 | ||
f2c5f623 | 359 | /* Begin a new scope. */ |
35b1567d | 360 | |
325c3691 | 361 | static tree |
92bc1323 | 362 | do_pushlevel (scope_kind sk) |
35b1567d | 363 | { |
325c3691 | 364 | tree ret = push_stmt_list (); |
f2c5f623 | 365 | if (stmts_are_full_exprs_p ()) |
325c3691 RH |
366 | begin_scope (sk, NULL); |
367 | return ret; | |
368 | } | |
5a508662 RH |
369 | |
370 | /* Queue a cleanup. CLEANUP is an expression/statement to be executed | |
371 | when the current scope is exited. EH_ONLY is true when this is not | |
372 | meant to apply to normal control flow transfer. */ | |
373 | ||
374 | void | |
375 | push_cleanup (tree decl, tree cleanup, bool eh_only) | |
376 | { | |
377 | tree stmt = build_stmt (CLEANUP_STMT, NULL, cleanup, decl); | |
378 | CLEANUP_EH_ONLY (stmt) = eh_only; | |
379 | add_stmt (stmt); | |
380 | CLEANUP_BODY (stmt) = push_stmt_list (); | |
381 | } | |
325c3691 | 382 | |
caf2523d RH |
383 | /* Begin a conditional that might contain a declaration. When generating |
384 | normal code, we want the declaration to appear before the statement | |
385 | containing the conditional. When generating template code, we want the | |
350fae66 | 386 | conditional to be rendered as the raw DECL_EXPR. */ |
325c3691 RH |
387 | |
388 | static void | |
caf2523d | 389 | begin_cond (tree *cond_p) |
325c3691 | 390 | { |
caf2523d RH |
391 | if (processing_template_decl) |
392 | *cond_p = push_stmt_list (); | |
393 | } | |
394 | ||
395 | /* Finish such a conditional. */ | |
396 | ||
397 | static void | |
398 | finish_cond (tree *cond_p, tree expr) | |
399 | { | |
400 | if (processing_template_decl) | |
35b1567d | 401 | { |
caf2523d | 402 | tree cond = pop_stmt_list (*cond_p); |
350fae66 | 403 | if (TREE_CODE (cond) == DECL_EXPR) |
caf2523d | 404 | expr = cond; |
35b1567d | 405 | } |
caf2523d | 406 | *cond_p = expr; |
35b1567d BC |
407 | } |
408 | ||
325c3691 RH |
409 | /* If *COND_P specifies a conditional with a declaration, transform the |
410 | loop such that | |
caf2523d RH |
411 | while (A x = 42) { } |
412 | for (; A x = 42;) { } | |
325c3691 | 413 | becomes |
caf2523d RH |
414 | while (true) { A x = 42; if (!x) break; } |
415 | for (;;) { A x = 42; if (!x) break; } | |
416 | The statement list for BODY will be empty if the conditional did | |
417 | not declare anything. */ | |
418 | ||
325c3691 | 419 | static void |
caf2523d | 420 | simplify_loop_decl_cond (tree *cond_p, tree body) |
325c3691 | 421 | { |
caf2523d | 422 | tree cond, if_stmt; |
325c3691 | 423 | |
caf2523d RH |
424 | if (!TREE_SIDE_EFFECTS (body)) |
425 | return; | |
325c3691 | 426 | |
caf2523d RH |
427 | cond = *cond_p; |
428 | *cond_p = boolean_true_node; | |
429 | ||
430 | if_stmt = begin_if_stmt (); | |
431 | cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0); | |
432 | finish_if_stmt_cond (cond, if_stmt); | |
433 | finish_break_stmt (); | |
434 | finish_then_clause (if_stmt); | |
435 | finish_if_stmt (if_stmt); | |
436 | } | |
325c3691 | 437 | |
35b1567d BC |
438 | /* Finish a goto-statement. */ |
439 | ||
3e4d04a1 | 440 | tree |
3a978d72 | 441 | finish_goto_stmt (tree destination) |
35b1567d BC |
442 | { |
443 | if (TREE_CODE (destination) == IDENTIFIER_NODE) | |
444 | destination = lookup_label (destination); | |
445 | ||
446 | /* We warn about unused labels with -Wunused. That means we have to | |
447 | mark the used labels as used. */ | |
448 | if (TREE_CODE (destination) == LABEL_DECL) | |
449 | TREE_USED (destination) = 1; | |
fc2b8477 MM |
450 | else |
451 | { | |
452 | /* The DESTINATION is being used as an rvalue. */ | |
453 | if (!processing_template_decl) | |
454 | destination = decay_conversion (destination); | |
455 | /* We don't inline calls to functions with computed gotos. | |
456 | Those functions are typically up to some funny business, | |
457 | and may be depending on the labels being at particular | |
458 | addresses, or some such. */ | |
459 | DECL_UNINLINABLE (current_function_decl) = 1; | |
460 | } | |
35b1567d BC |
461 | |
462 | check_goto (destination); | |
463 | ||
9e14e18f | 464 | return add_stmt (build_stmt (GOTO_EXPR, destination)); |
35b1567d BC |
465 | } |
466 | ||
ed5511d9 MM |
467 | /* COND is the condition-expression for an if, while, etc., |
468 | statement. Convert it to a boolean value, if appropriate. */ | |
469 | ||
8ce33230 | 470 | static tree |
3a978d72 | 471 | maybe_convert_cond (tree cond) |
ed5511d9 MM |
472 | { |
473 | /* Empty conditions remain empty. */ | |
474 | if (!cond) | |
475 | return NULL_TREE; | |
476 | ||
477 | /* Wait until we instantiate templates before doing conversion. */ | |
478 | if (processing_template_decl) | |
479 | return cond; | |
480 | ||
481 | /* Do the conversion. */ | |
482 | cond = convert_from_reference (cond); | |
483 | return condition_conversion (cond); | |
484 | } | |
485 | ||
9bfadf57 | 486 | /* Finish an expression-statement, whose EXPRESSION is as indicated. */ |
a7e4cfa0 | 487 | |
3e4d04a1 | 488 | tree |
3a978d72 | 489 | finish_expr_stmt (tree expr) |
ad321293 | 490 | { |
3e4d04a1 RH |
491 | tree r = NULL_TREE; |
492 | ||
ce4a0391 | 493 | if (expr != NULL_TREE) |
ad321293 | 494 | { |
a5bcc582 | 495 | if (!processing_template_decl) |
3a5b9284 RH |
496 | { |
497 | if (warn_sequence_point) | |
498 | verify_sequence_points (expr); | |
499 | expr = convert_to_void (expr, "statement"); | |
500 | } | |
47d4c811 NS |
501 | else if (!type_dependent_expression_p (expr)) |
502 | convert_to_void (build_non_dependent_expr (expr), "statement"); | |
325c3691 RH |
503 | |
504 | /* Simplification of inner statement expressions, compound exprs, | |
505 | etc can result in the us already having an EXPR_STMT. */ | |
543a0daa RH |
506 | if (TREE_CODE (expr) != CLEANUP_POINT_EXPR) |
507 | { | |
508 | if (TREE_CODE (expr) != EXPR_STMT) | |
509 | expr = build_stmt (EXPR_STMT, expr); | |
510 | expr = maybe_cleanup_point_expr (expr); | |
511 | } | |
512 | ||
325c3691 | 513 | r = add_stmt (expr); |
35b1567d | 514 | } |
364460b6 | 515 | |
35b1567d | 516 | finish_stmt (); |
558475f0 | 517 | |
3e4d04a1 | 518 | return r; |
35b1567d BC |
519 | } |
520 | ||
35b1567d | 521 | |
ad321293 MM |
522 | /* Begin an if-statement. Returns a newly created IF_STMT if |
523 | appropriate. */ | |
524 | ||
525 | tree | |
3a978d72 | 526 | begin_if_stmt (void) |
ad321293 | 527 | { |
325c3691 RH |
528 | tree r, scope; |
529 | scope = do_pushlevel (sk_block); | |
0dfdeca6 | 530 | r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE); |
325c3691 | 531 | TREE_CHAIN (r) = scope; |
caf2523d | 532 | begin_cond (&IF_COND (r)); |
ad321293 MM |
533 | return r; |
534 | } | |
535 | ||
536 | /* Process the COND of an if-statement, which may be given by | |
537 | IF_STMT. */ | |
538 | ||
539 | void | |
3a978d72 | 540 | finish_if_stmt_cond (tree cond, tree if_stmt) |
ad321293 | 541 | { |
caf2523d RH |
542 | finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond)); |
543 | add_stmt (if_stmt); | |
325c3691 | 544 | THEN_CLAUSE (if_stmt) = push_stmt_list (); |
ad321293 MM |
545 | } |
546 | ||
547 | /* Finish the then-clause of an if-statement, which may be given by | |
548 | IF_STMT. */ | |
549 | ||
550 | tree | |
3a978d72 | 551 | finish_then_clause (tree if_stmt) |
ad321293 | 552 | { |
325c3691 | 553 | THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt)); |
35b1567d | 554 | return if_stmt; |
ad321293 MM |
555 | } |
556 | ||
557 | /* Begin the else-clause of an if-statement. */ | |
558 | ||
325c3691 RH |
559 | void |
560 | begin_else_clause (tree if_stmt) | |
ad321293 | 561 | { |
325c3691 | 562 | ELSE_CLAUSE (if_stmt) = push_stmt_list (); |
ad321293 MM |
563 | } |
564 | ||
565 | /* Finish the else-clause of an if-statement, which may be given by | |
566 | IF_STMT. */ | |
567 | ||
568 | void | |
3a978d72 | 569 | finish_else_clause (tree if_stmt) |
ad321293 | 570 | { |
325c3691 | 571 | ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt)); |
ad321293 MM |
572 | } |
573 | ||
dfbb4f34 | 574 | /* Finish an if-statement. */ |
ad321293 MM |
575 | |
576 | void | |
325c3691 | 577 | finish_if_stmt (tree if_stmt) |
ad321293 | 578 | { |
325c3691 RH |
579 | tree scope = TREE_CHAIN (if_stmt); |
580 | TREE_CHAIN (if_stmt) = NULL; | |
581 | add_stmt (do_poplevel (scope)); | |
ad321293 | 582 | finish_stmt (); |
35b1567d BC |
583 | } |
584 | ||
ad321293 MM |
585 | /* Begin a while-statement. Returns a newly created WHILE_STMT if |
586 | appropriate. */ | |
587 | ||
588 | tree | |
3a978d72 | 589 | begin_while_stmt (void) |
ad321293 MM |
590 | { |
591 | tree r; | |
0dfdeca6 | 592 | r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE); |
ae499cce | 593 | add_stmt (r); |
325c3691 | 594 | WHILE_BODY (r) = do_pushlevel (sk_block); |
caf2523d | 595 | begin_cond (&WHILE_COND (r)); |
ad321293 MM |
596 | return r; |
597 | } | |
598 | ||
27d26ee7 | 599 | /* Process the COND of a while-statement, which may be given by |
ad321293 MM |
600 | WHILE_STMT. */ |
601 | ||
602 | void | |
3a978d72 | 603 | finish_while_stmt_cond (tree cond, tree while_stmt) |
ad321293 | 604 | { |
caf2523d RH |
605 | finish_cond (&WHILE_COND (while_stmt), maybe_convert_cond (cond)); |
606 | simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt)); | |
ad321293 MM |
607 | } |
608 | ||
609 | /* Finish a while-statement, which may be given by WHILE_STMT. */ | |
610 | ||
611 | void | |
3a978d72 | 612 | finish_while_stmt (tree while_stmt) |
ad321293 | 613 | { |
325c3691 | 614 | WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt)); |
ad321293 MM |
615 | finish_stmt (); |
616 | } | |
617 | ||
618 | /* Begin a do-statement. Returns a newly created DO_STMT if | |
619 | appropriate. */ | |
620 | ||
621 | tree | |
3a978d72 | 622 | begin_do_stmt (void) |
ad321293 | 623 | { |
0dfdeca6 | 624 | tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE); |
ae499cce | 625 | add_stmt (r); |
325c3691 | 626 | DO_BODY (r) = push_stmt_list (); |
35b1567d | 627 | return r; |
ad321293 MM |
628 | } |
629 | ||
630 | /* Finish the body of a do-statement, which may be given by DO_STMT. */ | |
631 | ||
632 | void | |
3a978d72 | 633 | finish_do_body (tree do_stmt) |
ad321293 | 634 | { |
325c3691 | 635 | DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt)); |
ad321293 MM |
636 | } |
637 | ||
638 | /* Finish a do-statement, which may be given by DO_STMT, and whose | |
639 | COND is as indicated. */ | |
640 | ||
641 | void | |
3a978d72 | 642 | finish_do_stmt (tree cond, tree do_stmt) |
ad321293 | 643 | { |
ed5511d9 | 644 | cond = maybe_convert_cond (cond); |
35b1567d BC |
645 | DO_COND (do_stmt) = cond; |
646 | finish_stmt (); | |
647 | } | |
ed5511d9 | 648 | |
ad321293 MM |
649 | /* Finish a return-statement. The EXPRESSION returned, if any, is as |
650 | indicated. */ | |
651 | ||
3e4d04a1 | 652 | tree |
3a978d72 | 653 | finish_return_stmt (tree expr) |
ad321293 | 654 | { |
3e4d04a1 RH |
655 | tree r; |
656 | ||
efc7052d | 657 | expr = check_return_expr (expr); |
35b1567d | 658 | if (!processing_template_decl) |
efee38a9 | 659 | { |
a0de9d20 | 660 | if (DECL_DESTRUCTOR_P (current_function_decl)) |
efee38a9 MM |
661 | { |
662 | /* Similarly, all destructors must run destructors for | |
663 | base-classes before returning. So, all returns in a | |
dfbb4f34 | 664 | destructor get sent to the DTOR_LABEL; finish_function emits |
efee38a9 | 665 | code to return a value there. */ |
3e4d04a1 | 666 | return finish_goto_stmt (dtor_label); |
efee38a9 MM |
667 | } |
668 | } | |
543a0daa | 669 | |
5088b058 | 670 | r = build_stmt (RETURN_EXPR, expr); |
543a0daa RH |
671 | r = maybe_cleanup_point_expr (r); |
672 | r = add_stmt (r); | |
35b1567d | 673 | finish_stmt (); |
3e4d04a1 RH |
674 | |
675 | return r; | |
35b1567d | 676 | } |
efee38a9 | 677 | |
ad321293 MM |
678 | /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */ |
679 | ||
680 | tree | |
3a978d72 | 681 | begin_for_stmt (void) |
ad321293 MM |
682 | { |
683 | tree r; | |
684 | ||
0dfdeca6 BC |
685 | r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE, |
686 | NULL_TREE, NULL_TREE); | |
325c3691 RH |
687 | |
688 | if (flag_new_for_scope > 0) | |
689 | TREE_CHAIN (r) = do_pushlevel (sk_for); | |
ad321293 | 690 | |
894ca2c9 RH |
691 | if (processing_template_decl) |
692 | FOR_INIT_STMT (r) = push_stmt_list (); | |
693 | ||
ad321293 MM |
694 | return r; |
695 | } | |
696 | ||
697 | /* Finish the for-init-statement of a for-statement, which may be | |
698 | given by FOR_STMT. */ | |
699 | ||
700 | void | |
3a978d72 | 701 | finish_for_init_stmt (tree for_stmt) |
ad321293 | 702 | { |
894ca2c9 RH |
703 | if (processing_template_decl) |
704 | FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt)); | |
325c3691 RH |
705 | add_stmt (for_stmt); |
706 | FOR_BODY (for_stmt) = do_pushlevel (sk_block); | |
caf2523d | 707 | begin_cond (&FOR_COND (for_stmt)); |
ad321293 MM |
708 | } |
709 | ||
710 | /* Finish the COND of a for-statement, which may be given by | |
711 | FOR_STMT. */ | |
712 | ||
713 | void | |
3a978d72 | 714 | finish_for_cond (tree cond, tree for_stmt) |
ad321293 | 715 | { |
caf2523d RH |
716 | finish_cond (&FOR_COND (for_stmt), maybe_convert_cond (cond)); |
717 | simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt)); | |
ad321293 MM |
718 | } |
719 | ||
720 | /* Finish the increment-EXPRESSION in a for-statement, which may be | |
721 | given by FOR_STMT. */ | |
722 | ||
723 | void | |
3a978d72 | 724 | finish_for_expr (tree expr, tree for_stmt) |
ad321293 | 725 | { |
543a0daa RH |
726 | if (!expr) |
727 | return; | |
6f69173e MM |
728 | /* If EXPR is an overloaded function, issue an error; there is no |
729 | context available to use to perform overload resolution. */ | |
543a0daa | 730 | if (type_unknown_p (expr)) |
6f69173e MM |
731 | { |
732 | cxx_incomplete_type_error (expr, TREE_TYPE (expr)); | |
733 | expr = error_mark_node; | |
734 | } | |
543a0daa | 735 | expr = maybe_cleanup_point_expr (expr); |
35b1567d | 736 | FOR_EXPR (for_stmt) = expr; |
ad321293 MM |
737 | } |
738 | ||
739 | /* Finish the body of a for-statement, which may be given by | |
740 | FOR_STMT. The increment-EXPR for the loop must be | |
741 | provided. */ | |
742 | ||
743 | void | |
3a978d72 | 744 | finish_for_stmt (tree for_stmt) |
ad321293 | 745 | { |
325c3691 RH |
746 | FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt)); |
747 | ||
ad321293 | 748 | /* Pop the scope for the body of the loop. */ |
325c3691 RH |
749 | if (flag_new_for_scope > 0) |
750 | { | |
751 | tree scope = TREE_CHAIN (for_stmt); | |
752 | TREE_CHAIN (for_stmt) = NULL; | |
753 | add_stmt (do_poplevel (scope)); | |
754 | } | |
755 | ||
ad321293 MM |
756 | finish_stmt (); |
757 | } | |
758 | ||
759 | /* Finish a break-statement. */ | |
760 | ||
3e4d04a1 | 761 | tree |
3a978d72 | 762 | finish_break_stmt (void) |
ad321293 | 763 | { |
3e4d04a1 | 764 | return add_stmt (build_break_stmt ()); |
35b1567d BC |
765 | } |
766 | ||
ad321293 MM |
767 | /* Finish a continue-statement. */ |
768 | ||
3e4d04a1 | 769 | tree |
3a978d72 | 770 | finish_continue_stmt (void) |
ad321293 | 771 | { |
3e4d04a1 | 772 | return add_stmt (build_continue_stmt ()); |
ad321293 MM |
773 | } |
774 | ||
35b1567d BC |
775 | /* Begin a switch-statement. Returns a new SWITCH_STMT if |
776 | appropriate. */ | |
777 | ||
778 | tree | |
3a978d72 | 779 | begin_switch_stmt (void) |
35b1567d | 780 | { |
325c3691 RH |
781 | tree r, scope; |
782 | ||
6f9fdf4d | 783 | r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE); |
325c3691 RH |
784 | |
785 | scope = do_pushlevel (sk_block); | |
786 | TREE_CHAIN (r) = scope; | |
caf2523d | 787 | begin_cond (&SWITCH_COND (r)); |
325c3691 | 788 | |
527f0080 | 789 | return r; |
ad321293 MM |
790 | } |
791 | ||
527f0080 | 792 | /* Finish the cond of a switch-statement. */ |
ad321293 | 793 | |
527f0080 | 794 | void |
3a978d72 | 795 | finish_switch_cond (tree cond, tree switch_stmt) |
ad321293 | 796 | { |
6f9fdf4d | 797 | tree orig_type = NULL; |
35b1567d | 798 | if (!processing_template_decl) |
373eb3b3 | 799 | { |
56cb9733 MM |
800 | tree index; |
801 | ||
35b1567d | 802 | /* Convert the condition to an integer or enumeration type. */ |
b746c5dc | 803 | cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true); |
35b1567d | 804 | if (cond == NULL_TREE) |
373eb3b3 | 805 | { |
35b1567d BC |
806 | error ("switch quantity not an integer"); |
807 | cond = error_mark_node; | |
808 | } | |
6f9fdf4d | 809 | orig_type = TREE_TYPE (cond); |
35b1567d BC |
810 | if (cond != error_mark_node) |
811 | { | |
0a72704b MM |
812 | /* [stmt.switch] |
813 | ||
814 | Integral promotions are performed. */ | |
815 | cond = perform_integral_promotions (cond); | |
543a0daa | 816 | cond = maybe_cleanup_point_expr (cond); |
373eb3b3 | 817 | } |
56cb9733 | 818 | |
25c8b645 JJ |
819 | if (cond != error_mark_node) |
820 | { | |
821 | index = get_unwidened (cond, NULL_TREE); | |
822 | /* We can't strip a conversion from a signed type to an unsigned, | |
823 | because if we did, int_fits_type_p would do the wrong thing | |
824 | when checking case values for being in range, | |
825 | and it's too hard to do the right thing. */ | |
8df83eae RK |
826 | if (TYPE_UNSIGNED (TREE_TYPE (cond)) |
827 | == TYPE_UNSIGNED (TREE_TYPE (index))) | |
25c8b645 JJ |
828 | cond = index; |
829 | } | |
ad321293 | 830 | } |
caf2523d | 831 | finish_cond (&SWITCH_COND (switch_stmt), cond); |
6f9fdf4d | 832 | SWITCH_TYPE (switch_stmt) = orig_type; |
caf2523d | 833 | add_stmt (switch_stmt); |
56cb9733 | 834 | push_switch (switch_stmt); |
325c3691 | 835 | SWITCH_BODY (switch_stmt) = push_stmt_list (); |
ad321293 MM |
836 | } |
837 | ||
838 | /* Finish the body of a switch-statement, which may be given by | |
839 | SWITCH_STMT. The COND to switch on is indicated. */ | |
840 | ||
841 | void | |
3a978d72 | 842 | finish_switch_stmt (tree switch_stmt) |
ad321293 | 843 | { |
325c3691 RH |
844 | tree scope; |
845 | ||
846 | SWITCH_BODY (switch_stmt) = pop_stmt_list (SWITCH_BODY (switch_stmt)); | |
ad321293 | 847 | pop_switch (); |
ad321293 | 848 | finish_stmt (); |
325c3691 RH |
849 | |
850 | scope = TREE_CHAIN (switch_stmt); | |
851 | TREE_CHAIN (switch_stmt) = NULL; | |
852 | add_stmt (do_poplevel (scope)); | |
ad321293 MM |
853 | } |
854 | ||
ad321293 MM |
855 | /* Begin a try-block. Returns a newly-created TRY_BLOCK if |
856 | appropriate. */ | |
857 | ||
858 | tree | |
3a978d72 | 859 | begin_try_block (void) |
ad321293 | 860 | { |
0dfdeca6 | 861 | tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE); |
ae499cce | 862 | add_stmt (r); |
325c3691 | 863 | TRY_STMTS (r) = push_stmt_list (); |
35b1567d | 864 | return r; |
ad321293 MM |
865 | } |
866 | ||
0dde4175 JM |
867 | /* Likewise, for a function-try-block. */ |
868 | ||
869 | tree | |
3a978d72 | 870 | begin_function_try_block (void) |
0dde4175 | 871 | { |
325c3691 | 872 | tree r = begin_try_block (); |
35b1567d | 873 | FN_TRY_BLOCK_P (r) = 1; |
35b1567d | 874 | return r; |
0dde4175 JM |
875 | } |
876 | ||
ad321293 MM |
877 | /* Finish a try-block, which may be given by TRY_BLOCK. */ |
878 | ||
879 | void | |
3a978d72 | 880 | finish_try_block (tree try_block) |
ad321293 | 881 | { |
325c3691 RH |
882 | TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); |
883 | TRY_HANDLERS (try_block) = push_stmt_list (); | |
ad321293 MM |
884 | } |
885 | ||
efa8eda3 MM |
886 | /* Finish the body of a cleanup try-block, which may be given by |
887 | TRY_BLOCK. */ | |
888 | ||
62409b39 | 889 | void |
3a978d72 | 890 | finish_cleanup_try_block (tree try_block) |
62409b39 | 891 | { |
325c3691 | 892 | TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); |
62409b39 MM |
893 | } |
894 | ||
f1dedc31 MM |
895 | /* Finish an implicitly generated try-block, with a cleanup is given |
896 | by CLEANUP. */ | |
897 | ||
898 | void | |
3a978d72 | 899 | finish_cleanup (tree cleanup, tree try_block) |
f1dedc31 | 900 | { |
35b1567d BC |
901 | TRY_HANDLERS (try_block) = cleanup; |
902 | CLEANUP_P (try_block) = 1; | |
f1dedc31 MM |
903 | } |
904 | ||
0dde4175 JM |
905 | /* Likewise, for a function-try-block. */ |
906 | ||
907 | void | |
3a978d72 | 908 | finish_function_try_block (tree try_block) |
0dde4175 | 909 | { |
325c3691 RH |
910 | finish_try_block (try_block); |
911 | /* FIXME : something queer about CTOR_INITIALIZER somehow following | |
912 | the try block, but moving it inside. */ | |
b35d4555 | 913 | in_function_try_handler = 1; |
0dde4175 JM |
914 | } |
915 | ||
ad321293 MM |
916 | /* Finish a handler-sequence for a try-block, which may be given by |
917 | TRY_BLOCK. */ | |
918 | ||
919 | void | |
3a978d72 | 920 | finish_handler_sequence (tree try_block) |
ad321293 | 921 | { |
325c3691 | 922 | TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block)); |
35b1567d | 923 | check_handlers (TRY_HANDLERS (try_block)); |
ad321293 MM |
924 | } |
925 | ||
0dde4175 JM |
926 | /* Likewise, for a function-try-block. */ |
927 | ||
928 | void | |
3a978d72 | 929 | finish_function_handler_sequence (tree try_block) |
0dde4175 | 930 | { |
b35d4555 | 931 | in_function_try_handler = 0; |
325c3691 | 932 | finish_handler_sequence (try_block); |
35b1567d BC |
933 | } |
934 | ||
ad321293 MM |
935 | /* Begin a handler. Returns a HANDLER if appropriate. */ |
936 | ||
937 | tree | |
3a978d72 | 938 | begin_handler (void) |
ad321293 MM |
939 | { |
940 | tree r; | |
325c3691 | 941 | |
0dfdeca6 | 942 | r = build_stmt (HANDLER, NULL_TREE, NULL_TREE); |
ae499cce | 943 | add_stmt (r); |
325c3691 | 944 | |
1a6025b4 JM |
945 | /* Create a binding level for the eh_info and the exception object |
946 | cleanup. */ | |
325c3691 RH |
947 | HANDLER_BODY (r) = do_pushlevel (sk_catch); |
948 | ||
ad321293 MM |
949 | return r; |
950 | } | |
951 | ||
952 | /* Finish the handler-parameters for a handler, which may be given by | |
b35d4555 MM |
953 | HANDLER. DECL is the declaration for the catch parameter, or NULL |
954 | if this is a `catch (...)' clause. */ | |
ad321293 | 955 | |
1a6025b4 | 956 | void |
3a978d72 | 957 | finish_handler_parms (tree decl, tree handler) |
b35d4555 | 958 | { |
1a6025b4 | 959 | tree type = NULL_TREE; |
b35d4555 MM |
960 | if (processing_template_decl) |
961 | { | |
962 | if (decl) | |
963 | { | |
964 | decl = pushdecl (decl); | |
965 | decl = push_template_decl (decl); | |
325c3691 | 966 | HANDLER_PARMS (handler) = decl; |
1a6025b4 | 967 | type = TREE_TYPE (decl); |
b35d4555 MM |
968 | } |
969 | } | |
35b1567d | 970 | else |
1a6025b4 | 971 | type = expand_start_catch_block (decl); |
35b1567d | 972 | |
1a6025b4 | 973 | HANDLER_TYPE (handler) = type; |
b80cfdcd | 974 | if (!processing_template_decl && type) |
6cad4e17 | 975 | mark_used (eh_type_info (type)); |
35b1567d BC |
976 | } |
977 | ||
978 | /* Finish a handler, which may be given by HANDLER. The BLOCKs are | |
979 | the return value from the matching call to finish_handler_parms. */ | |
980 | ||
981 | void | |
3a978d72 | 982 | finish_handler (tree handler) |
35b1567d BC |
983 | { |
984 | if (!processing_template_decl) | |
1a6025b4 | 985 | expand_end_catch_block (); |
325c3691 | 986 | HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler)); |
35b1567d BC |
987 | } |
988 | ||
5882f0f3 RH |
989 | /* Begin a compound statement. FLAGS contains some bits that control the |
990 | behaviour and context. If BCS_NO_SCOPE is set, the compound statement | |
991 | does not define a scope. If BCS_FN_BODY is set, this is the outermost | |
992 | block of a function. If BCS_TRY_BLOCK is set, this is the block | |
993 | created on behalf of a TRY statement. Returns a token to be passed to | |
994 | finish_compound_stmt. */ | |
ad321293 MM |
995 | |
996 | tree | |
325c3691 | 997 | begin_compound_stmt (unsigned int flags) |
ad321293 | 998 | { |
325c3691 | 999 | tree r; |
558475f0 | 1000 | |
325c3691 RH |
1001 | if (flags & BCS_NO_SCOPE) |
1002 | { | |
1003 | r = push_stmt_list (); | |
1004 | STATEMENT_LIST_NO_SCOPE (r) = 1; | |
1005 | ||
1006 | /* Normally, we try hard to keep the BLOCK for a statement-expression. | |
1007 | But, if it's a statement-expression with a scopeless block, there's | |
1008 | nothing to keep, and we don't want to accidentally keep a block | |
1009 | *inside* the scopeless block. */ | |
1010 | keep_next_level (false); | |
1011 | } | |
f1dedc31 | 1012 | else |
325c3691 RH |
1013 | r = do_pushlevel (flags & BCS_TRY_BLOCK ? sk_try : sk_block); |
1014 | ||
5882f0f3 RH |
1015 | /* When processing a template, we need to remember where the braces were, |
1016 | so that we can set up identical scopes when instantiating the template | |
1017 | later. BIND_EXPR is a handy candidate for this. | |
1018 | Note that do_poplevel won't create a BIND_EXPR itself here (and thus | |
1019 | result in nested BIND_EXPRs), since we don't build BLOCK nodes when | |
1020 | processing templates. */ | |
1021 | if (processing_template_decl) | |
325c3691 | 1022 | { |
5882f0f3 RH |
1023 | r = build (BIND_EXPR, NULL, NULL, r, NULL); |
1024 | BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0; | |
1025 | BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0; | |
325c3691 RH |
1026 | TREE_SIDE_EFFECTS (r) = 1; |
1027 | } | |
ad321293 MM |
1028 | |
1029 | return r; | |
1030 | } | |
1031 | ||
5882f0f3 | 1032 | /* Finish a compound-statement, which is given by STMT. */ |
ad321293 | 1033 | |
325c3691 RH |
1034 | void |
1035 | finish_compound_stmt (tree stmt) | |
ad321293 | 1036 | { |
5882f0f3 RH |
1037 | if (TREE_CODE (stmt) == BIND_EXPR) |
1038 | BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt)); | |
325c3691 RH |
1039 | else if (STATEMENT_LIST_NO_SCOPE (stmt)) |
1040 | stmt = pop_stmt_list (stmt); | |
7a3397c7 | 1041 | else |
325c3691 | 1042 | stmt = do_poplevel (stmt); |
ad321293 | 1043 | |
325c3691 RH |
1044 | /* ??? See c_end_compound_stmt wrt statement expressions. */ |
1045 | add_stmt (stmt); | |
ad321293 | 1046 | finish_stmt (); |
ad321293 MM |
1047 | } |
1048 | ||
6de9cd9a DN |
1049 | /* Finish an asm-statement, whose components are a STRING, some |
1050 | OUTPUT_OPERANDS, some INPUT_OPERANDS, and some CLOBBERS. Also note | |
1051 | whether the asm-statement should be considered volatile. */ | |
7dc5bd62 | 1052 | |
3e4d04a1 | 1053 | tree |
6de9cd9a DN |
1054 | finish_asm_stmt (int volatile_p, tree string, tree output_operands, |
1055 | tree input_operands, tree clobbers) | |
35b1567d BC |
1056 | { |
1057 | tree r; | |
abfc8a36 MM |
1058 | tree t; |
1059 | ||
abfc8a36 | 1060 | if (!processing_template_decl) |
40b18c0a MM |
1061 | { |
1062 | int i; | |
1063 | int ninputs; | |
1064 | int noutputs; | |
1065 | ||
1066 | for (t = input_operands; t; t = TREE_CHAIN (t)) | |
1067 | { | |
1068 | tree converted_operand | |
1069 | = decay_conversion (TREE_VALUE (t)); | |
1070 | ||
1071 | /* If the type of the operand hasn't been determined (e.g., | |
1072 | because it involves an overloaded function), then issue | |
1073 | an error message. There's no context available to | |
1074 | resolve the overloading. */ | |
1075 | if (TREE_TYPE (converted_operand) == unknown_type_node) | |
1076 | { | |
33bd39a2 | 1077 | error ("type of asm operand `%E' could not be determined", |
40b18c0a MM |
1078 | TREE_VALUE (t)); |
1079 | converted_operand = error_mark_node; | |
1080 | } | |
1081 | TREE_VALUE (t) = converted_operand; | |
1082 | } | |
1083 | ||
1084 | ninputs = list_length (input_operands); | |
1085 | noutputs = list_length (output_operands); | |
1086 | ||
1087 | for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i) | |
1088 | { | |
1089 | bool allows_mem; | |
1090 | bool allows_reg; | |
1091 | bool is_inout; | |
1092 | const char *constraint; | |
1093 | tree operand; | |
1094 | ||
84b72302 | 1095 | constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); |
28c56d25 | 1096 | operand = TREE_VALUE (t); |
40b18c0a MM |
1097 | |
1098 | if (!parse_output_constraint (&constraint, | |
1099 | i, ninputs, noutputs, | |
1100 | &allows_mem, | |
1101 | &allows_reg, | |
1102 | &is_inout)) | |
1103 | { | |
a723baf1 MM |
1104 | /* By marking this operand as erroneous, we will not try |
1105 | to process this operand again in expand_asm_operands. */ | |
1106 | TREE_VALUE (t) = error_mark_node; | |
40b18c0a MM |
1107 | continue; |
1108 | } | |
1109 | ||
1110 | /* If the operand is a DECL that is going to end up in | |
1111 | memory, assume it is addressable. This is a bit more | |
1112 | conservative than it would ideally be; the exact test is | |
1113 | buried deep in expand_asm_operands and depends on the | |
1114 | DECL_RTL for the OPERAND -- which we don't have at this | |
1115 | point. */ | |
1116 | if (!allows_reg && DECL_P (operand)) | |
dffd7eb6 | 1117 | cxx_mark_addressable (operand); |
40b18c0a MM |
1118 | } |
1119 | } | |
abfc8a36 | 1120 | |
e130a54b | 1121 | r = build_stmt (ASM_EXPR, string, |
0dfdeca6 BC |
1122 | output_operands, input_operands, |
1123 | clobbers); | |
6de9cd9a | 1124 | ASM_VOLATILE_P (r) = volatile_p; |
3e4d04a1 | 1125 | return add_stmt (r); |
ad321293 | 1126 | } |
b4c4a9ec | 1127 | |
f01b0acb MM |
1128 | /* Finish a label with the indicated NAME. */ |
1129 | ||
a723baf1 | 1130 | tree |
3a978d72 | 1131 | finish_label_stmt (tree name) |
f01b0acb | 1132 | { |
5b030314 | 1133 | tree decl = define_label (input_location, name); |
9e14e18f | 1134 | return add_stmt (build_stmt (LABEL_EXPR, decl)); |
f01b0acb MM |
1135 | } |
1136 | ||
acef433b MM |
1137 | /* Finish a series of declarations for local labels. G++ allows users |
1138 | to declare "local" labels, i.e., labels with scope. This extension | |
1139 | is useful when writing code involving statement-expressions. */ | |
1140 | ||
1141 | void | |
3a978d72 | 1142 | finish_label_decl (tree name) |
acef433b MM |
1143 | { |
1144 | tree decl = declare_local_label (name); | |
350fae66 | 1145 | add_decl_expr (decl); |
acef433b MM |
1146 | } |
1147 | ||
659e5a7a | 1148 | /* When DECL goes out of scope, make sure that CLEANUP is executed. */ |
f1dedc31 MM |
1149 | |
1150 | void | |
3a978d72 | 1151 | finish_decl_cleanup (tree decl, tree cleanup) |
f1dedc31 | 1152 | { |
325c3691 | 1153 | push_cleanup (decl, cleanup, false); |
35b1567d BC |
1154 | } |
1155 | ||
659e5a7a | 1156 | /* If the current scope exits with an exception, run CLEANUP. */ |
24bef158 | 1157 | |
659e5a7a | 1158 | void |
3a978d72 | 1159 | finish_eh_cleanup (tree cleanup) |
24bef158 | 1160 | { |
325c3691 | 1161 | push_cleanup (NULL, cleanup, true); |
35b1567d BC |
1162 | } |
1163 | ||
2282d28d MM |
1164 | /* The MEM_INITS is a list of mem-initializers, in reverse of the |
1165 | order they were written by the user. Each node is as for | |
1166 | emit_mem_initializers. */ | |
bf3428d0 MM |
1167 | |
1168 | void | |
2282d28d | 1169 | finish_mem_initializers (tree mem_inits) |
bf3428d0 | 1170 | { |
2282d28d MM |
1171 | /* Reorder the MEM_INITS so that they are in the order they appeared |
1172 | in the source program. */ | |
1173 | mem_inits = nreverse (mem_inits); | |
bf3428d0 | 1174 | |
a0de9d20 | 1175 | if (processing_template_decl) |
2282d28d | 1176 | add_stmt (build_min_nt (CTOR_INITIALIZER, mem_inits)); |
cdd2559c | 1177 | else |
2282d28d | 1178 | emit_mem_initializers (mem_inits); |
558475f0 MM |
1179 | } |
1180 | ||
b4c4a9ec MM |
1181 | /* Finish a parenthesized expression EXPR. */ |
1182 | ||
1183 | tree | |
3a978d72 | 1184 | finish_parenthesized_expr (tree expr) |
b4c4a9ec MM |
1185 | { |
1186 | if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr)))) | |
78ef5b89 | 1187 | /* This inhibits warnings in c_common_truthvalue_conversion. */ |
b4c4a9ec MM |
1188 | C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK); |
1189 | ||
19420d00 NS |
1190 | if (TREE_CODE (expr) == OFFSET_REF) |
1191 | /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be | |
1192 | enclosed in parentheses. */ | |
1193 | PTRMEM_OK_P (expr) = 0; | |
b4c4a9ec MM |
1194 | return expr; |
1195 | } | |
1196 | ||
a723baf1 MM |
1197 | /* Finish a reference to a non-static data member (DECL) that is not |
1198 | preceded by `.' or `->'. */ | |
1199 | ||
1200 | tree | |
a3f10e50 | 1201 | finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) |
a723baf1 MM |
1202 | { |
1203 | my_friendly_assert (TREE_CODE (decl) == FIELD_DECL, 20020909); | |
1204 | ||
a3f10e50 | 1205 | if (!object) |
a723baf1 MM |
1206 | { |
1207 | if (current_function_decl | |
1208 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
1209 | cp_error_at ("invalid use of member `%D' in static member function", | |
1210 | decl); | |
1211 | else | |
1212 | cp_error_at ("invalid use of non-static data member `%D'", decl); | |
1213 | error ("from this location"); | |
1214 | ||
1215 | return error_mark_node; | |
1216 | } | |
1217 | TREE_USED (current_class_ptr) = 1; | |
58e1d54c | 1218 | if (processing_template_decl && !qualifying_scope) |
a723baf1 | 1219 | { |
a3f10e50 | 1220 | tree type = TREE_TYPE (decl); |
a723baf1 | 1221 | |
a3f10e50 NS |
1222 | if (TREE_CODE (type) == REFERENCE_TYPE) |
1223 | type = TREE_TYPE (type); | |
1224 | else | |
1225 | { | |
f4f206f4 | 1226 | /* Set the cv qualifiers. */ |
a3f10e50 NS |
1227 | int quals = cp_type_quals (TREE_TYPE (current_class_ref)); |
1228 | ||
1229 | if (DECL_MUTABLE_P (decl)) | |
1230 | quals &= ~TYPE_QUAL_CONST; | |
9e95d15f | 1231 | |
a3f10e50 NS |
1232 | quals |= cp_type_quals (TREE_TYPE (decl)); |
1233 | type = cp_build_qualified_type (type, quals); | |
1234 | } | |
9e95d15f | 1235 | |
44de5aeb | 1236 | return build_min (COMPONENT_REF, type, object, decl, NULL_TREE); |
a3f10e50 NS |
1237 | } |
1238 | else | |
1239 | { | |
1240 | tree access_type = TREE_TYPE (object); | |
1241 | tree lookup_context = context_for_name_lookup (decl); | |
1242 | ||
1243 | while (!DERIVED_FROM_P (lookup_context, access_type)) | |
a723baf1 MM |
1244 | { |
1245 | access_type = TYPE_CONTEXT (access_type); | |
9f01ded6 | 1246 | while (access_type && DECL_P (access_type)) |
a723baf1 | 1247 | access_type = DECL_CONTEXT (access_type); |
a723baf1 | 1248 | |
a3f10e50 NS |
1249 | if (!access_type) |
1250 | { | |
1251 | cp_error_at ("object missing in reference to `%D'", decl); | |
1252 | error ("from this location"); | |
1253 | return error_mark_node; | |
1254 | } | |
9f01ded6 KL |
1255 | } |
1256 | ||
5c425df5 | 1257 | /* If PROCESSING_TEMPLATE_DECL is nonzero here, then |
58e1d54c KL |
1258 | QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF |
1259 | for now. */ | |
1260 | if (processing_template_decl) | |
1261 | return build_min (SCOPE_REF, TREE_TYPE (decl), | |
1262 | qualifying_scope, DECL_NAME (decl)); | |
1263 | ||
6df5158a | 1264 | perform_or_defer_access_check (TYPE_BINFO (access_type), decl); |
a723baf1 MM |
1265 | |
1266 | /* If the data member was named `C::M', convert `*this' to `C' | |
1267 | first. */ | |
1268 | if (qualifying_scope) | |
1269 | { | |
1270 | tree binfo = NULL_TREE; | |
1271 | object = build_scoped_ref (object, qualifying_scope, | |
1272 | &binfo); | |
1273 | } | |
1274 | ||
1275 | return build_class_member_access_expr (object, decl, | |
1276 | /*access_path=*/NULL_TREE, | |
1277 | /*preserve_reference=*/false); | |
1278 | } | |
1279 | } | |
1280 | ||
ee76b931 MM |
1281 | /* DECL was the declaration to which a qualified-id resolved. Issue |
1282 | an error message if it is not accessible. If OBJECT_TYPE is | |
1283 | non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the | |
1284 | type of `*x', or `x', respectively. If the DECL was named as | |
1285 | `A::B' then NESTED_NAME_SPECIFIER is `A'. */ | |
1286 | ||
1287 | void | |
1288 | check_accessibility_of_qualified_id (tree decl, | |
1289 | tree object_type, | |
1290 | tree nested_name_specifier) | |
1291 | { | |
1292 | tree scope; | |
1293 | tree qualifying_type = NULL_TREE; | |
1294 | ||
1295 | /* Determine the SCOPE of DECL. */ | |
1296 | scope = context_for_name_lookup (decl); | |
1297 | /* If the SCOPE is not a type, then DECL is not a member. */ | |
1298 | if (!TYPE_P (scope)) | |
1299 | return; | |
1300 | /* Compute the scope through which DECL is being accessed. */ | |
1301 | if (object_type | |
1302 | /* OBJECT_TYPE might not be a class type; consider: | |
1303 | ||
1304 | class A { typedef int I; }; | |
1305 | I *p; | |
1306 | p->A::I::~I(); | |
1307 | ||
1308 | In this case, we will have "A::I" as the DECL, but "I" as the | |
1309 | OBJECT_TYPE. */ | |
1310 | && CLASS_TYPE_P (object_type) | |
1311 | && DERIVED_FROM_P (scope, object_type)) | |
1312 | /* If we are processing a `->' or `.' expression, use the type of the | |
1313 | left-hand side. */ | |
1314 | qualifying_type = object_type; | |
1315 | else if (nested_name_specifier) | |
1316 | { | |
1317 | /* If the reference is to a non-static member of the | |
1318 | current class, treat it as if it were referenced through | |
1319 | `this'. */ | |
1320 | if (DECL_NONSTATIC_MEMBER_P (decl) | |
1321 | && current_class_ptr | |
1322 | && DERIVED_FROM_P (scope, current_class_type)) | |
1323 | qualifying_type = current_class_type; | |
1324 | /* Otherwise, use the type indicated by the | |
1325 | nested-name-specifier. */ | |
1326 | else | |
1327 | qualifying_type = nested_name_specifier; | |
1328 | } | |
1329 | else | |
1330 | /* Otherwise, the name must be from the current class or one of | |
1331 | its bases. */ | |
1332 | qualifying_type = currently_open_derived_class (scope); | |
1333 | ||
1334 | if (qualifying_type) | |
1335 | perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl); | |
1336 | } | |
1337 | ||
1338 | /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the | |
1339 | class named to the left of the "::" operator. DONE is true if this | |
1340 | expression is a complete postfix-expression; it is false if this | |
1341 | expression is followed by '->', '[', '(', etc. ADDRESS_P is true | |
1342 | iff this expression is the operand of '&'. */ | |
1343 | ||
1344 | tree | |
1345 | finish_qualified_id_expr (tree qualifying_class, tree expr, bool done, | |
1346 | bool address_p) | |
1347 | { | |
5e08432e MM |
1348 | if (error_operand_p (expr)) |
1349 | return error_mark_node; | |
1350 | ||
ee76b931 MM |
1351 | /* If EXPR occurs as the operand of '&', use special handling that |
1352 | permits a pointer-to-member. */ | |
1353 | if (address_p && done) | |
1354 | { | |
1355 | if (TREE_CODE (expr) == SCOPE_REF) | |
1356 | expr = TREE_OPERAND (expr, 1); | |
a5ac359a MM |
1357 | expr = build_offset_ref (qualifying_class, expr, |
1358 | /*address_p=*/true); | |
ee76b931 MM |
1359 | return expr; |
1360 | } | |
1361 | ||
1362 | if (TREE_CODE (expr) == FIELD_DECL) | |
a3f10e50 NS |
1363 | expr = finish_non_static_data_member (expr, current_class_ref, |
1364 | qualifying_class); | |
ee76b931 MM |
1365 | else if (BASELINK_P (expr) && !processing_template_decl) |
1366 | { | |
1367 | tree fn; | |
1368 | tree fns; | |
1369 | ||
1370 | /* See if any of the functions are non-static members. */ | |
1371 | fns = BASELINK_FUNCTIONS (expr); | |
1372 | if (TREE_CODE (fns) == TEMPLATE_ID_EXPR) | |
1373 | fns = TREE_OPERAND (fns, 0); | |
1374 | for (fn = fns; fn; fn = OVL_NEXT (fn)) | |
1375 | if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)) | |
1376 | break; | |
1377 | /* If so, the expression may be relative to the current | |
1378 | class. */ | |
1379 | if (fn && current_class_type | |
1380 | && DERIVED_FROM_P (qualifying_class, current_class_type)) | |
1381 | expr = (build_class_member_access_expr | |
1382 | (maybe_dummy_object (qualifying_class, NULL), | |
1383 | expr, | |
1384 | BASELINK_ACCESS_BINFO (expr), | |
1385 | /*preserve_reference=*/false)); | |
1386 | else if (done) | |
a5ac359a MM |
1387 | /* The expression is a qualified name whose address is not |
1388 | being taken. */ | |
1389 | expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false); | |
ee76b931 MM |
1390 | } |
1391 | ||
1392 | return expr; | |
1393 | } | |
1394 | ||
b69b1501 MM |
1395 | /* Begin a statement-expression. The value returned must be passed to |
1396 | finish_stmt_expr. */ | |
b4c4a9ec MM |
1397 | |
1398 | tree | |
3a978d72 | 1399 | begin_stmt_expr (void) |
b4c4a9ec | 1400 | { |
325c3691 | 1401 | return push_stmt_list (); |
35b1567d BC |
1402 | } |
1403 | ||
a5bcc582 NS |
1404 | /* Process the final expression of a statement expression. EXPR can be |
1405 | NULL, if the final expression is empty. Build up a TARGET_EXPR so | |
1406 | that the result value can be safely returned to the enclosing | |
1407 | expression. */ | |
1408 | ||
1409 | tree | |
325c3691 | 1410 | finish_stmt_expr_expr (tree expr, tree stmt_expr) |
a5bcc582 NS |
1411 | { |
1412 | tree result = NULL_TREE; | |
a5bcc582 NS |
1413 | |
1414 | if (expr) | |
1415 | { | |
a5bcc582 NS |
1416 | if (!processing_template_decl && !VOID_TYPE_P (TREE_TYPE (expr))) |
1417 | { | |
2692eb7d JM |
1418 | tree type = TREE_TYPE (expr); |
1419 | ||
a5bcc582 NS |
1420 | if (TREE_CODE (type) == ARRAY_TYPE |
1421 | || TREE_CODE (type) == FUNCTION_TYPE) | |
1422 | expr = decay_conversion (expr); | |
1423 | ||
1424 | expr = convert_from_reference (expr); | |
1425 | expr = require_complete_type (expr); | |
1426 | ||
2692eb7d JM |
1427 | type = TREE_TYPE (expr); |
1428 | ||
a5bcc582 NS |
1429 | /* Build a TARGET_EXPR for this aggregate. finish_stmt_expr |
1430 | will then pull it apart so the lifetime of the target is | |
cd0be382 | 1431 | within the scope of the expression containing this statement |
a5bcc582 NS |
1432 | expression. */ |
1433 | if (TREE_CODE (expr) == TARGET_EXPR) | |
1434 | ; | |
1435 | else if (!IS_AGGR_TYPE (type) || TYPE_HAS_TRIVIAL_INIT_REF (type)) | |
1436 | expr = build_target_expr_with_type (expr, type); | |
1437 | else | |
1438 | { | |
1439 | /* Copy construct. */ | |
1440 | expr = build_special_member_call | |
1441 | (NULL_TREE, complete_ctor_identifier, | |
1442 | build_tree_list (NULL_TREE, expr), | |
1443 | TYPE_BINFO (type), LOOKUP_NORMAL); | |
1444 | expr = build_cplus_new (type, expr); | |
1445 | my_friendly_assert (TREE_CODE (expr) == TARGET_EXPR, 20030729); | |
1446 | } | |
1447 | } | |
1448 | ||
1449 | if (expr != error_mark_node) | |
1450 | { | |
1451 | result = build_stmt (EXPR_STMT, expr); | |
325c3691 | 1452 | EXPR_STMT_STMT_EXPR_RESULT (result) = 1; |
a5bcc582 NS |
1453 | add_stmt (result); |
1454 | } | |
1455 | } | |
1456 | ||
1457 | finish_stmt (); | |
1458 | ||
325c3691 RH |
1459 | /* Remember the last expression so that finish_stmt_expr |
1460 | can pull it apart. */ | |
1461 | TREE_TYPE (stmt_expr) = result; | |
a5bcc582 NS |
1462 | |
1463 | return result; | |
1464 | } | |
1465 | ||
303b7406 NS |
1466 | /* Finish a statement-expression. EXPR should be the value returned |
1467 | by the previous begin_stmt_expr. Returns an expression | |
1468 | representing the statement-expression. */ | |
b4c4a9ec MM |
1469 | |
1470 | tree | |
325c3691 | 1471 | finish_stmt_expr (tree stmt_expr, bool has_no_scope) |
b4c4a9ec | 1472 | { |
325c3691 RH |
1473 | tree result, result_stmt, type; |
1474 | tree *result_stmt_p = NULL; | |
1475 | ||
1476 | result_stmt = TREE_TYPE (stmt_expr); | |
1477 | TREE_TYPE (stmt_expr) = void_type_node; | |
1478 | result = pop_stmt_list (stmt_expr); | |
1479 | ||
1480 | if (!result_stmt || VOID_TYPE_P (result_stmt)) | |
a5bcc582 NS |
1481 | type = void_type_node; |
1482 | else | |
1483 | { | |
325c3691 RH |
1484 | /* We need to search the statement expression for the result_stmt, |
1485 | since we'll need to replace it entirely. */ | |
1486 | tree t; | |
1487 | result_stmt_p = &result; | |
1488 | while (1) | |
a5bcc582 | 1489 | { |
325c3691 RH |
1490 | t = *result_stmt_p; |
1491 | if (t == result_stmt) | |
1492 | break; | |
1493 | ||
1494 | switch (TREE_CODE (t)) | |
1495 | { | |
1496 | case STATEMENT_LIST: | |
1497 | { | |
1498 | tree_stmt_iterator i = tsi_last (t); | |
1499 | result_stmt_p = tsi_stmt_ptr (i); | |
1500 | break; | |
1501 | } | |
1502 | case BIND_EXPR: | |
1503 | result_stmt_p = &BIND_EXPR_BODY (t); | |
1504 | break; | |
325c3691 RH |
1505 | case TRY_FINALLY_EXPR: |
1506 | case TRY_CATCH_EXPR: | |
1507 | case CLEANUP_STMT: | |
1508 | result_stmt_p = &TREE_OPERAND (t, 0); | |
1509 | break; | |
1510 | default: | |
1511 | abort (); | |
1512 | } | |
a5bcc582 | 1513 | } |
325c3691 | 1514 | type = TREE_TYPE (EXPR_STMT_EXPR (result_stmt)); |
a5bcc582 | 1515 | } |
6f80451c | 1516 | |
a5bcc582 | 1517 | if (processing_template_decl) |
325c3691 RH |
1518 | { |
1519 | result = build_min (STMT_EXPR, type, result); | |
1520 | TREE_SIDE_EFFECTS (result) = 1; | |
1521 | STMT_EXPR_NO_SCOPE (result) = has_no_scope; | |
1522 | } | |
1523 | else if (!VOID_TYPE_P (type)) | |
a5bcc582 NS |
1524 | { |
1525 | /* Pull out the TARGET_EXPR that is the final expression. Put | |
1526 | the target's init_expr as the final expression and then put | |
1527 | the statement expression itself as the target's init | |
1528 | expr. Finally, return the target expression. */ | |
2692eb7d JM |
1529 | tree init, target_expr = EXPR_STMT_EXPR (result_stmt); |
1530 | my_friendly_assert (TREE_CODE (target_expr) == TARGET_EXPR, 20030729); | |
1531 | ||
1532 | /* The initializer will be void if the initialization is done by | |
1533 | AGGR_INIT_EXPR; propagate that out to the statement-expression as | |
1534 | a whole. */ | |
1535 | init = TREE_OPERAND (target_expr, 1); | |
1536 | type = TREE_TYPE (init); | |
1537 | ||
543a0daa | 1538 | init = maybe_cleanup_point_expr (init); |
2692eb7d JM |
1539 | *result_stmt_p = init; |
1540 | ||
1541 | if (VOID_TYPE_P (type)) | |
1542 | /* No frobbing needed. */; | |
1543 | else if (TREE_CODE (result) == BIND_EXPR) | |
325c3691 | 1544 | { |
2692eb7d JM |
1545 | /* The BIND_EXPR created in finish_compound_stmt is void; if we're |
1546 | returning a value directly, give it the appropriate type. */ | |
325c3691 | 1547 | if (VOID_TYPE_P (TREE_TYPE (result))) |
2692eb7d JM |
1548 | TREE_TYPE (result) = type; |
1549 | else if (same_type_p (TREE_TYPE (result), type)) | |
325c3691 RH |
1550 | ; |
1551 | else | |
1552 | abort (); | |
1553 | } | |
1554 | else if (TREE_CODE (result) == STATEMENT_LIST) | |
2692eb7d JM |
1555 | /* We need to wrap a STATEMENT_LIST in a BIND_EXPR so it can have a |
1556 | type other than void. FIXME why can't we just return a value | |
1557 | from STATEMENT_LIST? */ | |
1558 | result = build3 (BIND_EXPR, type, NULL, result, NULL); | |
325c3691 | 1559 | |
2692eb7d JM |
1560 | TREE_OPERAND (target_expr, 1) = result; |
1561 | result = target_expr; | |
a5bcc582 | 1562 | } |
325c3691 | 1563 | |
b4c4a9ec MM |
1564 | return result; |
1565 | } | |
1566 | ||
b3445994 | 1567 | /* Perform Koenig lookup. FN is the postfix-expression representing |
fa531100 MM |
1568 | the function (or functions) to call; ARGS are the arguments to the |
1569 | call. Returns the functions to be considered by overload | |
1570 | resolution. */ | |
b3445994 MM |
1571 | |
1572 | tree | |
1573 | perform_koenig_lookup (tree fn, tree args) | |
1574 | { | |
1575 | tree identifier = NULL_TREE; | |
1576 | tree functions = NULL_TREE; | |
1577 | ||
1578 | /* Find the name of the overloaded function. */ | |
1579 | if (TREE_CODE (fn) == IDENTIFIER_NODE) | |
1580 | identifier = fn; | |
1581 | else if (is_overloaded_fn (fn)) | |
1582 | { | |
1583 | functions = fn; | |
1584 | identifier = DECL_NAME (get_first_fn (functions)); | |
1585 | } | |
1586 | else if (DECL_P (fn)) | |
1587 | { | |
1588 | functions = fn; | |
1589 | identifier = DECL_NAME (fn); | |
1590 | } | |
1591 | ||
1592 | /* A call to a namespace-scope function using an unqualified name. | |
1593 | ||
1594 | Do Koenig lookup -- unless any of the arguments are | |
1595 | type-dependent. */ | |
1596 | if (!any_type_dependent_arguments_p (args)) | |
1597 | { | |
1598 | fn = lookup_arg_dependent (identifier, functions, args); | |
1599 | if (!fn) | |
1600 | /* The unqualified name could not be resolved. */ | |
1601 | fn = unqualified_fn_lookup_error (identifier); | |
1602 | } | |
1603 | else | |
10b1d5e7 | 1604 | fn = identifier; |
b3445994 MM |
1605 | |
1606 | return fn; | |
1607 | } | |
1608 | ||
4ba126e4 MM |
1609 | /* Generate an expression for `FN (ARGS)'. |
1610 | ||
1611 | If DISALLOW_VIRTUAL is true, the call to FN will be not generated | |
1612 | as a virtual call, even if FN is virtual. (This flag is set when | |
1613 | encountering an expression where the function name is explicitly | |
1614 | qualified. For example a call to `X::f' never generates a virtual | |
1615 | call.) | |
1616 | ||
1617 | Returns code for the call. */ | |
b4c4a9ec MM |
1618 | |
1619 | tree | |
6d80c4b9 | 1620 | finish_call_expr (tree fn, tree args, bool disallow_virtual, bool koenig_p) |
b4c4a9ec | 1621 | { |
d17811fd MM |
1622 | tree result; |
1623 | tree orig_fn; | |
1624 | tree orig_args; | |
1625 | ||
4ba126e4 MM |
1626 | if (fn == error_mark_node || args == error_mark_node) |
1627 | return error_mark_node; | |
1628 | ||
4ba126e4 MM |
1629 | /* ARGS should be a list of arguments. */ |
1630 | my_friendly_assert (!args || TREE_CODE (args) == TREE_LIST, | |
1631 | 20020712); | |
a759e627 | 1632 | |
d17811fd MM |
1633 | orig_fn = fn; |
1634 | orig_args = args; | |
1635 | ||
1636 | if (processing_template_decl) | |
1637 | { | |
1638 | if (type_dependent_expression_p (fn) | |
1639 | || any_type_dependent_arguments_p (args)) | |
6d80c4b9 | 1640 | { |
6de9cd9a | 1641 | result = build_nt (CALL_EXPR, fn, args, NULL_TREE); |
6d80c4b9 MM |
1642 | KOENIG_LOOKUP_P (result) = koenig_p; |
1643 | return result; | |
1644 | } | |
d17811fd MM |
1645 | if (!BASELINK_P (fn) |
1646 | && TREE_CODE (fn) != PSEUDO_DTOR_EXPR | |
1647 | && TREE_TYPE (fn) != unknown_type_node) | |
1648 | fn = build_non_dependent_expr (fn); | |
1649 | args = build_non_dependent_args (orig_args); | |
1650 | } | |
1651 | ||
a723baf1 MM |
1652 | /* A reference to a member function will appear as an overloaded |
1653 | function (rather than a BASELINK) if an unqualified name was used | |
1654 | to refer to it. */ | |
1655 | if (!BASELINK_P (fn) && is_overloaded_fn (fn)) | |
1656 | { | |
12483c9f | 1657 | tree f = fn; |
a723baf1 | 1658 | |
12483c9f NS |
1659 | if (TREE_CODE (f) == TEMPLATE_ID_EXPR) |
1660 | f = TREE_OPERAND (f, 0); | |
1661 | f = get_first_fn (f); | |
a723baf1 MM |
1662 | if (DECL_FUNCTION_MEMBER_P (f)) |
1663 | { | |
1664 | tree type = currently_open_derived_class (DECL_CONTEXT (f)); | |
c44e68a5 KL |
1665 | if (!type) |
1666 | type = DECL_CONTEXT (f); | |
a723baf1 MM |
1667 | fn = build_baselink (TYPE_BINFO (type), |
1668 | TYPE_BINFO (type), | |
1669 | fn, /*optype=*/NULL_TREE); | |
1670 | } | |
1671 | } | |
1672 | ||
d17811fd | 1673 | result = NULL_TREE; |
4ba126e4 | 1674 | if (BASELINK_P (fn)) |
03d82991 | 1675 | { |
4ba126e4 MM |
1676 | tree object; |
1677 | ||
1678 | /* A call to a member function. From [over.call.func]: | |
1679 | ||
1680 | If the keyword this is in scope and refers to the class of | |
1681 | that member function, or a derived class thereof, then the | |
1682 | function call is transformed into a qualified function call | |
1683 | using (*this) as the postfix-expression to the left of the | |
1684 | . operator.... [Otherwise] a contrived object of type T | |
1685 | becomes the implied object argument. | |
1686 | ||
1687 | This paragraph is unclear about this situation: | |
1688 | ||
1689 | struct A { void f(); }; | |
1690 | struct B : public A {}; | |
1691 | struct C : public A { void g() { B::f(); }}; | |
1692 | ||
1693 | In particular, for `B::f', this paragraph does not make clear | |
1694 | whether "the class of that member function" refers to `A' or | |
1695 | to `B'. We believe it refers to `B'. */ | |
1696 | if (current_class_type | |
1697 | && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), | |
1698 | current_class_type) | |
1699 | && current_class_ref) | |
127b8136 MM |
1700 | object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), |
1701 | NULL); | |
4ba126e4 MM |
1702 | else |
1703 | { | |
1704 | tree representative_fn; | |
b4c4a9ec | 1705 | |
4ba126e4 MM |
1706 | representative_fn = BASELINK_FUNCTIONS (fn); |
1707 | if (TREE_CODE (representative_fn) == TEMPLATE_ID_EXPR) | |
1708 | representative_fn = TREE_OPERAND (representative_fn, 0); | |
1709 | representative_fn = get_first_fn (representative_fn); | |
1710 | object = build_dummy_object (DECL_CONTEXT (representative_fn)); | |
1711 | } | |
b4c4a9ec | 1712 | |
d17811fd MM |
1713 | if (processing_template_decl) |
1714 | { | |
1715 | if (type_dependent_expression_p (object)) | |
6de9cd9a | 1716 | return build_nt (CALL_EXPR, orig_fn, orig_args, NULL_TREE); |
d17811fd MM |
1717 | object = build_non_dependent_expr (object); |
1718 | } | |
1719 | ||
1720 | result = build_new_method_call (object, fn, args, NULL_TREE, | |
1721 | (disallow_virtual | |
1722 | ? LOOKUP_NONVIRTUAL : 0)); | |
4ba126e4 MM |
1723 | } |
1724 | else if (is_overloaded_fn (fn)) | |
1725 | /* A call to a namespace-scope function. */ | |
d17811fd | 1726 | result = build_new_function_call (fn, args); |
a723baf1 MM |
1727 | else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR) |
1728 | { | |
a723baf1 MM |
1729 | if (args) |
1730 | error ("arguments to destructor are not allowed"); | |
1731 | /* Mark the pseudo-destructor call as having side-effects so | |
1732 | that we do not issue warnings about its use. */ | |
1733 | result = build1 (NOP_EXPR, | |
1734 | void_type_node, | |
1735 | TREE_OPERAND (fn, 0)); | |
1736 | TREE_SIDE_EFFECTS (result) = 1; | |
a723baf1 | 1737 | } |
4ba126e4 | 1738 | else if (CLASS_TYPE_P (TREE_TYPE (fn))) |
d17811fd MM |
1739 | /* If the "function" is really an object of class type, it might |
1740 | have an overloaded `operator ()'. */ | |
ec835fb2 MM |
1741 | result = build_new_op (CALL_EXPR, LOOKUP_NORMAL, fn, args, NULL_TREE, |
1742 | /*overloaded_p=*/NULL); | |
d17811fd MM |
1743 | if (!result) |
1744 | /* A call where the function is unknown. */ | |
1745 | result = build_function_call (fn, args); | |
4ba126e4 | 1746 | |
d17811fd | 1747 | if (processing_template_decl) |
6d80c4b9 | 1748 | { |
6de9cd9a DN |
1749 | result = build (CALL_EXPR, TREE_TYPE (result), orig_fn, |
1750 | orig_args, NULL_TREE); | |
6d80c4b9 MM |
1751 | KOENIG_LOOKUP_P (result) = koenig_p; |
1752 | } | |
d17811fd | 1753 | return result; |
b4c4a9ec MM |
1754 | } |
1755 | ||
1756 | /* Finish a call to a postfix increment or decrement or EXPR. (Which | |
1757 | is indicated by CODE, which should be POSTINCREMENT_EXPR or | |
1758 | POSTDECREMENT_EXPR.) */ | |
1759 | ||
1760 | tree | |
3a978d72 | 1761 | finish_increment_expr (tree expr, enum tree_code code) |
b4c4a9ec | 1762 | { |
b4c4a9ec MM |
1763 | return build_x_unary_op (code, expr); |
1764 | } | |
1765 | ||
1766 | /* Finish a use of `this'. Returns an expression for `this'. */ | |
1767 | ||
1768 | tree | |
3a978d72 | 1769 | finish_this_expr (void) |
b4c4a9ec MM |
1770 | { |
1771 | tree result; | |
1772 | ||
1773 | if (current_class_ptr) | |
1774 | { | |
b4c4a9ec MM |
1775 | result = current_class_ptr; |
1776 | } | |
1777 | else if (current_function_decl | |
1778 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
1779 | { | |
8251199e | 1780 | error ("`this' is unavailable for static member functions"); |
b4c4a9ec MM |
1781 | result = error_mark_node; |
1782 | } | |
1783 | else | |
1784 | { | |
1785 | if (current_function_decl) | |
8251199e | 1786 | error ("invalid use of `this' in non-member function"); |
b4c4a9ec | 1787 | else |
8251199e | 1788 | error ("invalid use of `this' at top level"); |
b4c4a9ec MM |
1789 | result = error_mark_node; |
1790 | } | |
1791 | ||
1792 | return result; | |
1793 | } | |
1794 | ||
a723baf1 MM |
1795 | /* Finish a pseudo-destructor expression. If SCOPE is NULL, the |
1796 | expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is | |
1797 | the TYPE for the type given. If SCOPE is non-NULL, the expression | |
1798 | was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */ | |
b4c4a9ec MM |
1799 | |
1800 | tree | |
3a978d72 | 1801 | finish_pseudo_destructor_expr (tree object, tree scope, tree destructor) |
b4c4a9ec | 1802 | { |
a723baf1 MM |
1803 | if (destructor == error_mark_node) |
1804 | return error_mark_node; | |
40242ccf | 1805 | |
a723baf1 | 1806 | my_friendly_assert (TYPE_P (destructor), 20010905); |
b4c4a9ec | 1807 | |
a723baf1 MM |
1808 | if (!processing_template_decl) |
1809 | { | |
1810 | if (scope == error_mark_node) | |
1811 | { | |
1812 | error ("invalid qualifying scope in pseudo-destructor name"); | |
1813 | return error_mark_node; | |
1814 | } | |
1815 | ||
26bcf8fc MM |
1816 | /* [expr.pseudo] says both: |
1817 | ||
1818 | The type designated by the pseudo-destructor-name shall be | |
1819 | the same as the object type. | |
1820 | ||
1821 | and: | |
1822 | ||
1823 | The cv-unqualified versions of the object type and of the | |
1824 | type designated by the pseudo-destructor-name shall be the | |
1825 | same type. | |
1826 | ||
1827 | We implement the more generous second sentence, since that is | |
1828 | what most other compilers do. */ | |
1829 | if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object), | |
1830 | destructor)) | |
a723baf1 MM |
1831 | { |
1832 | error ("`%E' is not of type `%T'", object, destructor); | |
1833 | return error_mark_node; | |
1834 | } | |
1835 | } | |
b4c4a9ec | 1836 | |
a723baf1 | 1837 | return build (PSEUDO_DTOR_EXPR, void_type_node, object, scope, destructor); |
b4c4a9ec MM |
1838 | } |
1839 | ||
ce4a0391 MM |
1840 | /* Finish an expression of the form CODE EXPR. */ |
1841 | ||
1842 | tree | |
3a978d72 | 1843 | finish_unary_op_expr (enum tree_code code, tree expr) |
ce4a0391 MM |
1844 | { |
1845 | tree result = build_x_unary_op (code, expr); | |
7c355bca ML |
1846 | /* Inside a template, build_x_unary_op does not fold the |
1847 | expression. So check whether the result is folded before | |
1848 | setting TREE_NEGATED_INT. */ | |
1849 | if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST | |
88b4335f | 1850 | && TREE_CODE (result) == INTEGER_CST |
8df83eae | 1851 | && !TYPE_UNSIGNED (TREE_TYPE (result)) |
88b4335f | 1852 | && INT_CST_LT (result, integer_zero_node)) |
ce4a0391 MM |
1853 | TREE_NEGATED_INT (result) = 1; |
1854 | overflow_warning (result); | |
1855 | return result; | |
1856 | } | |
1857 | ||
a723baf1 MM |
1858 | /* Finish a compound-literal expression. TYPE is the type to which |
1859 | the INITIALIZER_LIST is being cast. */ | |
1860 | ||
1861 | tree | |
3a978d72 | 1862 | finish_compound_literal (tree type, tree initializer_list) |
a723baf1 MM |
1863 | { |
1864 | tree compound_literal; | |
1865 | ||
1866 | /* Build a CONSTRUCTOR for the INITIALIZER_LIST. */ | |
dcf92453 | 1867 | compound_literal = build_constructor (NULL_TREE, initializer_list); |
a723baf1 MM |
1868 | /* Mark it as a compound-literal. */ |
1869 | TREE_HAS_CONSTRUCTOR (compound_literal) = 1; | |
1870 | if (processing_template_decl) | |
1871 | TREE_TYPE (compound_literal) = type; | |
1872 | else | |
1873 | { | |
1874 | /* Check the initialization. */ | |
1875 | compound_literal = digest_init (type, compound_literal, NULL); | |
1876 | /* If the TYPE was an array type with an unknown bound, then we can | |
1877 | figure out the dimension now. For example, something like: | |
1878 | ||
1879 | `(int []) { 2, 3 }' | |
1880 | ||
1881 | implies that the array has two elements. */ | |
1882 | if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) | |
1883 | complete_array_type (type, compound_literal, 1); | |
1884 | } | |
1885 | ||
1886 | return compound_literal; | |
1887 | } | |
1888 | ||
5f261ba9 MM |
1889 | /* Return the declaration for the function-name variable indicated by |
1890 | ID. */ | |
1891 | ||
1892 | tree | |
1893 | finish_fname (tree id) | |
1894 | { | |
1895 | tree decl; | |
1896 | ||
1897 | decl = fname_decl (C_RID_CODE (id), id); | |
1898 | if (processing_template_decl) | |
10b1d5e7 | 1899 | decl = DECL_NAME (decl); |
5f261ba9 MM |
1900 | return decl; |
1901 | } | |
1902 | ||
8014a339 | 1903 | /* Finish a translation unit. */ |
ce4a0391 MM |
1904 | |
1905 | void | |
3a978d72 | 1906 | finish_translation_unit (void) |
ce4a0391 MM |
1907 | { |
1908 | /* In case there were missing closebraces, | |
1909 | get us back to the global binding level. */ | |
273a708f | 1910 | pop_everything (); |
ce4a0391 MM |
1911 | while (current_namespace != global_namespace) |
1912 | pop_namespace (); | |
0ba8a114 | 1913 | |
c6002625 | 1914 | /* Do file scope __FUNCTION__ et al. */ |
0ba8a114 | 1915 | finish_fname_decls (); |
ce4a0391 MM |
1916 | } |
1917 | ||
b4c4a9ec MM |
1918 | /* Finish a template type parameter, specified as AGGR IDENTIFIER. |
1919 | Returns the parameter. */ | |
1920 | ||
1921 | tree | |
3a978d72 | 1922 | finish_template_type_parm (tree aggr, tree identifier) |
b4c4a9ec | 1923 | { |
6eabb241 | 1924 | if (aggr != class_type_node) |
b4c4a9ec | 1925 | { |
8251199e | 1926 | pedwarn ("template type parameters must use the keyword `class' or `typename'"); |
b4c4a9ec MM |
1927 | aggr = class_type_node; |
1928 | } | |
1929 | ||
1930 | return build_tree_list (aggr, identifier); | |
1931 | } | |
1932 | ||
1933 | /* Finish a template template parameter, specified as AGGR IDENTIFIER. | |
1934 | Returns the parameter. */ | |
1935 | ||
1936 | tree | |
3a978d72 | 1937 | finish_template_template_parm (tree aggr, tree identifier) |
b4c4a9ec MM |
1938 | { |
1939 | tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE); | |
1940 | tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); | |
1941 | DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; | |
1942 | DECL_TEMPLATE_RESULT (tmpl) = decl; | |
c727aa5e | 1943 | DECL_ARTIFICIAL (decl) = 1; |
b4c4a9ec MM |
1944 | end_template_decl (); |
1945 | ||
b37bf5bd NS |
1946 | my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110); |
1947 | ||
b4c4a9ec MM |
1948 | return finish_template_type_parm (aggr, tmpl); |
1949 | } | |
ce4a0391 | 1950 | |
8ba658ee MM |
1951 | /* ARGUMENT is the default-argument value for a template template |
1952 | parameter. If ARGUMENT is invalid, issue error messages and return | |
1953 | the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */ | |
1954 | ||
1955 | tree | |
1956 | check_template_template_default_arg (tree argument) | |
1957 | { | |
1958 | if (TREE_CODE (argument) != TEMPLATE_DECL | |
1959 | && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM | |
8ba658ee MM |
1960 | && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) |
1961 | { | |
a3a503a5 GB |
1962 | if (TREE_CODE (argument) == TYPE_DECL) |
1963 | { | |
1964 | tree t = TREE_TYPE (argument); | |
1965 | ||
1966 | /* Try to emit a slightly smarter error message if we detect | |
1967 | that the user is using a template instantiation. */ | |
1968 | if (CLASSTYPE_TEMPLATE_INFO (t) | |
1969 | && CLASSTYPE_TEMPLATE_INSTANTIATION (t)) | |
1970 | error ("invalid use of type `%T' as a default value for a " | |
1971 | "template template-parameter", t); | |
1972 | else | |
1973 | error ("invalid use of `%D' as a default value for a template " | |
1974 | "template-parameter", argument); | |
1975 | } | |
1976 | else | |
1977 | error ("invalid default argument for a template template parameter"); | |
8ba658ee MM |
1978 | return error_mark_node; |
1979 | } | |
1980 | ||
1981 | return argument; | |
1982 | } | |
1983 | ||
ce4a0391 MM |
1984 | /* Begin a class definition, as indicated by T. */ |
1985 | ||
1986 | tree | |
3a978d72 | 1987 | begin_class_definition (tree t) |
ce4a0391 | 1988 | { |
7437519c ZW |
1989 | if (t == error_mark_node) |
1990 | return error_mark_node; | |
1991 | ||
522d6614 NS |
1992 | if (processing_template_parmlist) |
1993 | { | |
33bd39a2 | 1994 | error ("definition of `%#T' inside template parameter list", t); |
522d6614 NS |
1995 | return error_mark_node; |
1996 | } | |
47ee8904 MM |
1997 | /* A non-implicit typename comes from code like: |
1998 | ||
1999 | template <typename T> struct A { | |
2000 | template <typename U> struct A<T>::B ... | |
2001 | ||
2002 | This is erroneous. */ | |
2003 | else if (TREE_CODE (t) == TYPENAME_TYPE) | |
2004 | { | |
33bd39a2 | 2005 | error ("invalid definition of qualified type `%T'", t); |
47ee8904 MM |
2006 | t = error_mark_node; |
2007 | } | |
2008 | ||
2009 | if (t == error_mark_node || ! IS_AGGR_TYPE (t)) | |
ce4a0391 | 2010 | { |
33848bb0 | 2011 | t = make_aggr_type (RECORD_TYPE); |
ce4a0391 MM |
2012 | pushtag (make_anon_name (), t, 0); |
2013 | } | |
830fcda8 | 2014 | |
4c571114 MM |
2015 | /* If this type was already complete, and we see another definition, |
2016 | that's an error. */ | |
8fbc5ae7 | 2017 | if (COMPLETE_TYPE_P (t)) |
4223f82f MM |
2018 | { |
2019 | error ("redefinition of `%#T'", t); | |
2020 | cp_error_at ("previous definition of `%#T'", t); | |
2021 | return error_mark_node; | |
2022 | } | |
4c571114 | 2023 | |
b4f70b3d | 2024 | /* Update the location of the decl. */ |
f31686a3 | 2025 | DECL_SOURCE_LOCATION (TYPE_NAME (t)) = input_location; |
b4f70b3d | 2026 | |
4c571114 | 2027 | if (TYPE_BEING_DEFINED (t)) |
ce4a0391 | 2028 | { |
33848bb0 | 2029 | t = make_aggr_type (TREE_CODE (t)); |
ce4a0391 | 2030 | pushtag (TYPE_IDENTIFIER (t), t, 0); |
ce4a0391 | 2031 | } |
ff350acd | 2032 | maybe_process_partial_specialization (t); |
29370796 | 2033 | pushclass (t); |
ce4a0391 | 2034 | TYPE_BEING_DEFINED (t) = 1; |
c0694c4b MM |
2035 | if (flag_pack_struct) |
2036 | { | |
2037 | tree v; | |
2038 | TYPE_PACKED (t) = 1; | |
2039 | /* Even though the type is being defined for the first time | |
2040 | here, there might have been a forward declaration, so there | |
2041 | might be cv-qualified variants of T. */ | |
2042 | for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v)) | |
2043 | TYPE_PACKED (v) = 1; | |
2044 | } | |
ce4a0391 MM |
2045 | /* Reset the interface data, at the earliest possible |
2046 | moment, as it might have been set via a class foo; | |
2047 | before. */ | |
1951a1b6 JM |
2048 | if (! TYPE_ANONYMOUS_P (t)) |
2049 | { | |
2050 | CLASSTYPE_INTERFACE_ONLY (t) = interface_only; | |
2051 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X | |
2052 | (t, interface_unknown); | |
2053 | } | |
ce4a0391 MM |
2054 | reset_specialization(); |
2055 | ||
b7975aed MM |
2056 | /* Make a declaration for this class in its own scope. */ |
2057 | build_self_reference (); | |
2058 | ||
830fcda8 | 2059 | return t; |
ce4a0391 MM |
2060 | } |
2061 | ||
61a127b3 MM |
2062 | /* Finish the member declaration given by DECL. */ |
2063 | ||
2064 | void | |
3a978d72 | 2065 | finish_member_declaration (tree decl) |
61a127b3 MM |
2066 | { |
2067 | if (decl == error_mark_node || decl == NULL_TREE) | |
2068 | return; | |
2069 | ||
2070 | if (decl == void_type_node) | |
2071 | /* The COMPONENT was a friend, not a member, and so there's | |
2072 | nothing for us to do. */ | |
2073 | return; | |
2074 | ||
2075 | /* We should see only one DECL at a time. */ | |
2076 | my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0); | |
2077 | ||
2078 | /* Set up access control for DECL. */ | |
2079 | TREE_PRIVATE (decl) | |
2080 | = (current_access_specifier == access_private_node); | |
2081 | TREE_PROTECTED (decl) | |
2082 | = (current_access_specifier == access_protected_node); | |
2083 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
2084 | { | |
17aec3eb RK |
2085 | TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl); |
2086 | TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl); | |
61a127b3 MM |
2087 | } |
2088 | ||
2089 | /* Mark the DECL as a member of the current class. */ | |
4f1c5b7d | 2090 | DECL_CONTEXT (decl) = current_class_type; |
61a127b3 | 2091 | |
421844e7 MM |
2092 | /* [dcl.link] |
2093 | ||
2094 | A C language linkage is ignored for the names of class members | |
2095 | and the member function type of class member functions. */ | |
2096 | if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c) | |
5d2ed28c | 2097 | SET_DECL_LANGUAGE (decl, lang_cplusplus); |
421844e7 | 2098 | |
61a127b3 MM |
2099 | /* Put functions on the TYPE_METHODS list and everything else on the |
2100 | TYPE_FIELDS list. Note that these are built up in reverse order. | |
2101 | We reverse them (to obtain declaration order) in finish_struct. */ | |
2102 | if (TREE_CODE (decl) == FUNCTION_DECL | |
2103 | || DECL_FUNCTION_TEMPLATE_P (decl)) | |
2104 | { | |
2105 | /* We also need to add this function to the | |
2106 | CLASSTYPE_METHOD_VEC. */ | |
452a394b | 2107 | add_method (current_class_type, decl, /*error_p=*/0); |
61a127b3 MM |
2108 | |
2109 | TREE_CHAIN (decl) = TYPE_METHODS (current_class_type); | |
2110 | TYPE_METHODS (current_class_type) = decl; | |
f139561c MM |
2111 | |
2112 | maybe_add_class_template_decl_list (current_class_type, decl, | |
2113 | /*friend_p=*/0); | |
61a127b3 | 2114 | } |
f139561c | 2115 | /* Enter the DECL into the scope of the class. */ |
fd9aef9d | 2116 | else if ((TREE_CODE (decl) == USING_DECL && TREE_TYPE (decl)) |
399dedb9 | 2117 | || pushdecl_class_level (decl)) |
61a127b3 MM |
2118 | { |
2119 | /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields | |
2120 | go at the beginning. The reason is that lookup_field_1 | |
2121 | searches the list in order, and we want a field name to | |
2122 | override a type name so that the "struct stat hack" will | |
2123 | work. In particular: | |
2124 | ||
2125 | struct S { enum E { }; int E } s; | |
2126 | s.E = 3; | |
2127 | ||
0e339752 | 2128 | is valid. In addition, the FIELD_DECLs must be maintained in |
61a127b3 MM |
2129 | declaration order so that class layout works as expected. |
2130 | However, we don't need that order until class layout, so we | |
2131 | save a little time by putting FIELD_DECLs on in reverse order | |
2132 | here, and then reversing them in finish_struct_1. (We could | |
2133 | also keep a pointer to the correct insertion points in the | |
2134 | list.) */ | |
2135 | ||
2136 | if (TREE_CODE (decl) == TYPE_DECL) | |
2137 | TYPE_FIELDS (current_class_type) | |
2138 | = chainon (TYPE_FIELDS (current_class_type), decl); | |
2139 | else | |
2140 | { | |
2141 | TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type); | |
2142 | TYPE_FIELDS (current_class_type) = decl; | |
2143 | } | |
8f032717 | 2144 | |
f139561c MM |
2145 | maybe_add_class_template_decl_list (current_class_type, decl, |
2146 | /*friend_p=*/0); | |
61a127b3 MM |
2147 | } |
2148 | } | |
2149 | ||
306ef644 | 2150 | /* Finish processing a complete template declaration. The PARMS are |
36a117a5 MM |
2151 | the template parameters. */ |
2152 | ||
2153 | void | |
3a978d72 | 2154 | finish_template_decl (tree parms) |
36a117a5 MM |
2155 | { |
2156 | if (parms) | |
2157 | end_template_decl (); | |
2158 | else | |
2159 | end_specialization (); | |
2160 | } | |
2161 | ||
509fc277 | 2162 | /* Finish processing a template-id (which names a type) of the form |
36a117a5 | 2163 | NAME < ARGS >. Return the TYPE_DECL for the type named by the |
838dfd8a | 2164 | template-id. If ENTERING_SCOPE is nonzero we are about to enter |
36a117a5 MM |
2165 | the scope of template-id indicated. */ |
2166 | ||
2167 | tree | |
3a978d72 | 2168 | finish_template_type (tree name, tree args, int entering_scope) |
36a117a5 MM |
2169 | { |
2170 | tree decl; | |
2171 | ||
2172 | decl = lookup_template_class (name, args, | |
42eaed49 NS |
2173 | NULL_TREE, NULL_TREE, entering_scope, |
2174 | tf_error | tf_warning | tf_user); | |
36a117a5 MM |
2175 | if (decl != error_mark_node) |
2176 | decl = TYPE_STUB_DECL (decl); | |
2177 | ||
2178 | return decl; | |
2179 | } | |
648f19f6 | 2180 | |
ea6021e8 MM |
2181 | /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. |
2182 | Return a TREE_LIST containing the ACCESS_SPECIFIER and the | |
2183 | BASE_CLASS, or NULL_TREE if an error occurred. The | |
aba649ba | 2184 | ACCESS_SPECIFIER is one of |
ea6021e8 MM |
2185 | access_{default,public,protected_private}[_virtual]_node.*/ |
2186 | ||
2187 | tree | |
dbbf88d1 | 2188 | finish_base_specifier (tree base, tree access, bool virtual_p) |
ea6021e8 | 2189 | { |
ea6021e8 MM |
2190 | tree result; |
2191 | ||
dbbf88d1 | 2192 | if (base == error_mark_node) |
acb044ee GDR |
2193 | { |
2194 | error ("invalid base-class specification"); | |
2195 | result = NULL_TREE; | |
2196 | } | |
dbbf88d1 | 2197 | else if (! is_aggr_type (base, 1)) |
ea6021e8 | 2198 | result = NULL_TREE; |
ea6021e8 | 2199 | else |
bb92901d | 2200 | { |
dbbf88d1 | 2201 | if (cp_type_quals (base) != 0) |
bb92901d | 2202 | { |
dbbf88d1 NS |
2203 | error ("base class `%T' has cv qualifiers", base); |
2204 | base = TYPE_MAIN_VARIANT (base); | |
bb92901d | 2205 | } |
dbbf88d1 NS |
2206 | result = build_tree_list (access, base); |
2207 | TREE_VIA_VIRTUAL (result) = virtual_p; | |
bb92901d | 2208 | } |
ea6021e8 MM |
2209 | |
2210 | return result; | |
2211 | } | |
61a127b3 MM |
2212 | |
2213 | /* Called when multiple declarators are processed. If that is not | |
cd0be382 | 2214 | permitted in this context, an error is issued. */ |
61a127b3 MM |
2215 | |
2216 | void | |
3a978d72 | 2217 | check_multiple_declarators (void) |
61a127b3 MM |
2218 | { |
2219 | /* [temp] | |
2220 | ||
2221 | In a template-declaration, explicit specialization, or explicit | |
2222 | instantiation the init-declarator-list in the declaration shall | |
2223 | contain at most one declarator. | |
2224 | ||
2225 | We don't just use PROCESSING_TEMPLATE_DECL for the first | |
0e339752 | 2226 | condition since that would disallow the perfectly valid code, |
61a127b3 | 2227 | like `template <class T> struct S { int i, j; };'. */ |
5f261ba9 | 2228 | if (at_function_scope_p ()) |
61a127b3 MM |
2229 | /* It's OK to write `template <class T> void f() { int i, j;}'. */ |
2230 | return; | |
2231 | ||
2232 | if (PROCESSING_REAL_TEMPLATE_DECL_P () | |
2233 | || processing_explicit_instantiation | |
2234 | || processing_specialization) | |
33bd39a2 | 2235 | error ("multiple declarators in template declaration"); |
61a127b3 MM |
2236 | } |
2237 | ||
22038b2c NS |
2238 | /* Issue a diagnostic that NAME cannot be found in SCOPE. */ |
2239 | ||
2240 | void | |
2241 | qualified_name_lookup_error (tree scope, tree name) | |
2242 | { | |
2243 | if (TYPE_P (scope)) | |
2244 | { | |
2245 | if (!COMPLETE_TYPE_P (scope)) | |
2246 | error ("incomplete type `%T' used in nested name specifier", scope); | |
2247 | else | |
2248 | error ("`%D' is not a member of `%T'", name, scope); | |
2249 | } | |
2250 | else if (scope != global_namespace) | |
2251 | error ("`%D' is not a member of `%D'", name, scope); | |
2252 | else | |
2253 | error ("`::%D' has not been declared", name); | |
2254 | } | |
2255 | ||
b3445994 MM |
2256 | /* ID_EXPRESSION is a representation of parsed, but unprocessed, |
2257 | id-expression. (See cp_parser_id_expression for details.) SCOPE, | |
2258 | if non-NULL, is the type or namespace used to explicitly qualify | |
2259 | ID_EXPRESSION. DECL is the entity to which that name has been | |
2260 | resolved. | |
2261 | ||
2262 | *CONSTANT_EXPRESSION_P is true if we are presently parsing a | |
2263 | constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will | |
2264 | be set to true if this expression isn't permitted in a | |
2265 | constant-expression, but it is otherwise not set by this function. | |
2266 | *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a | |
2267 | constant-expression, but a non-constant expression is also | |
2268 | permissible. | |
2269 | ||
2270 | If an error occurs, and it is the kind of error that might cause | |
2271 | the parser to abort a tentative parse, *ERROR_MSG is filled in. It | |
2272 | is the caller's responsibility to issue the message. *ERROR_MSG | |
2273 | will be a string with static storage duration, so the caller need | |
2274 | not "free" it. | |
2275 | ||
2276 | Return an expression for the entity, after issuing appropriate | |
2277 | diagnostics. This function is also responsible for transforming a | |
2278 | reference to a non-static member into a COMPONENT_REF that makes | |
2279 | the use of "this" explicit. | |
2280 | ||
2281 | Upon return, *IDK will be filled in appropriately. */ | |
2282 | ||
2283 | tree | |
2284 | finish_id_expression (tree id_expression, | |
2285 | tree decl, | |
2286 | tree scope, | |
2287 | cp_id_kind *idk, | |
2288 | tree *qualifying_class, | |
67c03833 JM |
2289 | bool integral_constant_expression_p, |
2290 | bool allow_non_integral_constant_expression_p, | |
2291 | bool *non_integral_constant_expression_p, | |
b3445994 MM |
2292 | const char **error_msg) |
2293 | { | |
2294 | /* Initialize the output parameters. */ | |
2295 | *idk = CP_ID_KIND_NONE; | |
2296 | *error_msg = NULL; | |
2297 | ||
2298 | if (id_expression == error_mark_node) | |
2299 | return error_mark_node; | |
2300 | /* If we have a template-id, then no further lookup is | |
2301 | required. If the template-id was for a template-class, we | |
2302 | will sometimes have a TYPE_DECL at this point. */ | |
2303 | else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
ee935db4 | 2304 | || TREE_CODE (decl) == TYPE_DECL) |
b3445994 MM |
2305 | ; |
2306 | /* Look up the name. */ | |
2307 | else | |
2308 | { | |
2309 | if (decl == error_mark_node) | |
2310 | { | |
2311 | /* Name lookup failed. */ | |
4546865e MM |
2312 | if (scope |
2313 | && (!TYPE_P (scope) | |
2314 | || (!dependent_type_p (scope) | |
2315 | && !(TREE_CODE (id_expression) == IDENTIFIER_NODE | |
2316 | && IDENTIFIER_TYPENAME_P (id_expression) | |
2317 | && dependent_type_p (TREE_TYPE (id_expression)))))) | |
b3445994 | 2318 | { |
4546865e MM |
2319 | /* If the qualifying type is non-dependent (and the name |
2320 | does not name a conversion operator to a dependent | |
2321 | type), issue an error. */ | |
22038b2c | 2322 | qualified_name_lookup_error (scope, id_expression); |
b3445994 MM |
2323 | return error_mark_node; |
2324 | } | |
2325 | else if (!scope) | |
2326 | { | |
2327 | /* It may be resolved via Koenig lookup. */ | |
2328 | *idk = CP_ID_KIND_UNQUALIFIED; | |
2329 | return id_expression; | |
2330 | } | |
4546865e MM |
2331 | else |
2332 | decl = id_expression; | |
b3445994 MM |
2333 | } |
2334 | /* If DECL is a variable that would be out of scope under | |
2335 | ANSI/ISO rules, but in scope in the ARM, name lookup | |
2336 | will succeed. Issue a diagnostic here. */ | |
2337 | else | |
2338 | decl = check_for_out_of_scope_variable (decl); | |
2339 | ||
2340 | /* Remember that the name was used in the definition of | |
2341 | the current class so that we can check later to see if | |
2342 | the meaning would have been different after the class | |
2343 | was entirely defined. */ | |
2344 | if (!scope && decl != error_mark_node) | |
2345 | maybe_note_name_used_in_class (id_expression, decl); | |
2346 | } | |
2347 | ||
2348 | /* If we didn't find anything, or what we found was a type, | |
2349 | then this wasn't really an id-expression. */ | |
2350 | if (TREE_CODE (decl) == TEMPLATE_DECL | |
2351 | && !DECL_FUNCTION_TEMPLATE_P (decl)) | |
2352 | { | |
2353 | *error_msg = "missing template arguments"; | |
2354 | return error_mark_node; | |
2355 | } | |
2356 | else if (TREE_CODE (decl) == TYPE_DECL | |
2357 | || TREE_CODE (decl) == NAMESPACE_DECL) | |
2358 | { | |
2359 | *error_msg = "expected primary-expression"; | |
2360 | return error_mark_node; | |
2361 | } | |
2362 | ||
2363 | /* If the name resolved to a template parameter, there is no | |
931a9c05 GB |
2364 | need to look it up again later. */ |
2365 | if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl)) | |
2366 | || TREE_CODE (decl) == TEMPLATE_PARM_INDEX) | |
b3445994 MM |
2367 | { |
2368 | *idk = CP_ID_KIND_NONE; | |
931a9c05 GB |
2369 | if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX) |
2370 | decl = TEMPLATE_PARM_DECL (decl); | |
67c03833 | 2371 | if (integral_constant_expression_p |
68deab91 | 2372 | && !dependent_type_p (TREE_TYPE (decl)) |
931a9c05 GB |
2373 | && !INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl))) |
2374 | { | |
67c03833 | 2375 | if (!allow_non_integral_constant_expression_p) |
931a9c05 GB |
2376 | error ("template parameter `%D' of type `%T' is not allowed in " |
2377 | "an integral constant expression because it is not of " | |
2378 | "integral or enumeration type", decl, TREE_TYPE (decl)); | |
67c03833 | 2379 | *non_integral_constant_expression_p = true; |
931a9c05 GB |
2380 | } |
2381 | return DECL_INITIAL (decl); | |
2382 | } | |
2383 | /* Similarly, we resolve enumeration constants to their | |
2384 | underlying values. */ | |
2385 | else if (TREE_CODE (decl) == CONST_DECL) | |
2386 | { | |
2387 | *idk = CP_ID_KIND_NONE; | |
2388 | if (!processing_template_decl) | |
b3445994 MM |
2389 | return DECL_INITIAL (decl); |
2390 | return decl; | |
2391 | } | |
2392 | else | |
2393 | { | |
2394 | bool dependent_p; | |
2395 | ||
2396 | /* If the declaration was explicitly qualified indicate | |
2397 | that. The semantics of `A::f(3)' are different than | |
2398 | `f(3)' if `f' is virtual. */ | |
2399 | *idk = (scope | |
2400 | ? CP_ID_KIND_QUALIFIED | |
2401 | : (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
2402 | ? CP_ID_KIND_TEMPLATE_ID | |
2403 | : CP_ID_KIND_UNQUALIFIED)); | |
2404 | ||
2405 | ||
2406 | /* [temp.dep.expr] | |
2407 | ||
2408 | An id-expression is type-dependent if it contains an | |
2409 | identifier that was declared with a dependent type. | |
2410 | ||
b3445994 MM |
2411 | The standard is not very specific about an id-expression that |
2412 | names a set of overloaded functions. What if some of them | |
2413 | have dependent types and some of them do not? Presumably, | |
2414 | such a name should be treated as a dependent name. */ | |
2415 | /* Assume the name is not dependent. */ | |
2416 | dependent_p = false; | |
2417 | if (!processing_template_decl) | |
2418 | /* No names are dependent outside a template. */ | |
2419 | ; | |
2420 | /* A template-id where the name of the template was not resolved | |
2421 | is definitely dependent. */ | |
2422 | else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
2423 | && (TREE_CODE (TREE_OPERAND (decl, 0)) | |
2424 | == IDENTIFIER_NODE)) | |
2425 | dependent_p = true; | |
2426 | /* For anything except an overloaded function, just check its | |
2427 | type. */ | |
2428 | else if (!is_overloaded_fn (decl)) | |
2429 | dependent_p | |
2430 | = dependent_type_p (TREE_TYPE (decl)); | |
2431 | /* For a set of overloaded functions, check each of the | |
2432 | functions. */ | |
2433 | else | |
2434 | { | |
2435 | tree fns = decl; | |
2436 | ||
2437 | if (BASELINK_P (fns)) | |
2438 | fns = BASELINK_FUNCTIONS (fns); | |
2439 | ||
2440 | /* For a template-id, check to see if the template | |
2441 | arguments are dependent. */ | |
2442 | if (TREE_CODE (fns) == TEMPLATE_ID_EXPR) | |
2443 | { | |
2444 | tree args = TREE_OPERAND (fns, 1); | |
2445 | dependent_p = any_dependent_template_arguments_p (args); | |
2446 | /* The functions are those referred to by the | |
2447 | template-id. */ | |
2448 | fns = TREE_OPERAND (fns, 0); | |
2449 | } | |
2450 | ||
2451 | /* If there are no dependent template arguments, go through | |
cd0be382 | 2452 | the overloaded functions. */ |
b3445994 MM |
2453 | while (fns && !dependent_p) |
2454 | { | |
2455 | tree fn = OVL_CURRENT (fns); | |
2456 | ||
2457 | /* Member functions of dependent classes are | |
2458 | dependent. */ | |
2459 | if (TREE_CODE (fn) == FUNCTION_DECL | |
2460 | && type_dependent_expression_p (fn)) | |
2461 | dependent_p = true; | |
2462 | else if (TREE_CODE (fn) == TEMPLATE_DECL | |
2463 | && dependent_template_p (fn)) | |
2464 | dependent_p = true; | |
2465 | ||
2466 | fns = OVL_NEXT (fns); | |
2467 | } | |
2468 | } | |
2469 | ||
2470 | /* If the name was dependent on a template parameter, we will | |
2471 | resolve the name at instantiation time. */ | |
2472 | if (dependent_p) | |
2473 | { | |
2474 | /* Create a SCOPE_REF for qualified names, if the scope is | |
2475 | dependent. */ | |
2476 | if (scope) | |
2477 | { | |
2478 | if (TYPE_P (scope)) | |
2479 | *qualifying_class = scope; | |
2480 | /* Since this name was dependent, the expression isn't | |
2481 | constant -- yet. No error is issued because it might | |
2482 | be constant when things are instantiated. */ | |
67c03833 JM |
2483 | if (integral_constant_expression_p) |
2484 | *non_integral_constant_expression_p = true; | |
b3445994 MM |
2485 | if (TYPE_P (scope) && dependent_type_p (scope)) |
2486 | return build_nt (SCOPE_REF, scope, id_expression); | |
2487 | else if (TYPE_P (scope) && DECL_P (decl)) | |
2488 | return build (SCOPE_REF, TREE_TYPE (decl), scope, | |
2489 | id_expression); | |
2490 | else | |
2491 | return decl; | |
2492 | } | |
2493 | /* A TEMPLATE_ID already contains all the information we | |
2494 | need. */ | |
2495 | if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR) | |
2496 | return id_expression; | |
2497 | /* Since this name was dependent, the expression isn't | |
2498 | constant -- yet. No error is issued because it might be | |
2499 | constant when things are instantiated. */ | |
67c03833 JM |
2500 | if (integral_constant_expression_p) |
2501 | *non_integral_constant_expression_p = true; | |
10b1d5e7 | 2502 | *idk = CP_ID_KIND_UNQUALIFIED_DEPENDENT; |
5a98fa7b MM |
2503 | /* If we found a variable, then name lookup during the |
2504 | instantiation will always resolve to the same VAR_DECL | |
2505 | (or an instantiation thereof). */ | |
3c398f34 MM |
2506 | if (TREE_CODE (decl) == VAR_DECL |
2507 | || TREE_CODE (decl) == PARM_DECL) | |
5a98fa7b | 2508 | return decl; |
10b1d5e7 | 2509 | return id_expression; |
b3445994 MM |
2510 | } |
2511 | ||
2512 | /* Only certain kinds of names are allowed in constant | |
931a9c05 GB |
2513 | expression. Enumerators and template parameters |
2514 | have already been handled above. */ | |
67c03833 | 2515 | if (integral_constant_expression_p) |
b3445994 | 2516 | { |
931a9c05 GB |
2517 | /* Const variables or static data members of integral or |
2518 | enumeration types initialized with constant expressions | |
2519 | are OK. */ | |
2520 | if (TREE_CODE (decl) == VAR_DECL | |
2521 | && CP_TYPE_CONST_P (TREE_TYPE (decl)) | |
2522 | && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)) | |
2523 | && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)) | |
b3445994 MM |
2524 | ; |
2525 | else | |
2526 | { | |
67c03833 | 2527 | if (!allow_non_integral_constant_expression_p) |
b3445994 MM |
2528 | { |
2529 | error ("`%D' cannot appear in a constant-expression", decl); | |
2530 | return error_mark_node; | |
2531 | } | |
67c03833 | 2532 | *non_integral_constant_expression_p = true; |
b3445994 MM |
2533 | } |
2534 | } | |
415d4636 MM |
2535 | |
2536 | if (TREE_CODE (decl) == NAMESPACE_DECL) | |
9e95d15f NS |
2537 | { |
2538 | error ("use of namespace `%D' as expression", decl); | |
2539 | return error_mark_node; | |
2540 | } | |
2541 | else if (DECL_CLASS_TEMPLATE_P (decl)) | |
2542 | { | |
2543 | error ("use of class template `%T' as expression", decl); | |
2544 | return error_mark_node; | |
2545 | } | |
2546 | else if (TREE_CODE (decl) == TREE_LIST) | |
2547 | { | |
2548 | /* Ambiguous reference to base members. */ | |
2549 | error ("request for member `%D' is ambiguous in " | |
2550 | "multiple inheritance lattice", id_expression); | |
2551 | print_candidates (decl); | |
2552 | return error_mark_node; | |
2553 | } | |
415d4636 MM |
2554 | |
2555 | /* Mark variable-like entities as used. Functions are similarly | |
2556 | marked either below or after overload resolution. */ | |
2557 | if (TREE_CODE (decl) == VAR_DECL | |
2558 | || TREE_CODE (decl) == PARM_DECL | |
2559 | || TREE_CODE (decl) == RESULT_DECL) | |
2560 | mark_used (decl); | |
2561 | ||
2562 | if (scope) | |
2563 | { | |
2564 | decl = (adjust_result_of_qualified_name_lookup | |
2565 | (decl, scope, current_class_type)); | |
e20bcc5e JH |
2566 | |
2567 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
2568 | mark_used (decl); | |
2569 | ||
415d4636 MM |
2570 | if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl)) |
2571 | *qualifying_class = scope; | |
2572 | else if (!processing_template_decl) | |
2573 | decl = convert_from_reference (decl); | |
2574 | else if (TYPE_P (scope)) | |
2575 | decl = build (SCOPE_REF, TREE_TYPE (decl), scope, decl); | |
2576 | } | |
9e95d15f NS |
2577 | else if (TREE_CODE (decl) == FIELD_DECL) |
2578 | decl = finish_non_static_data_member (decl, current_class_ref, | |
2579 | /*qualifying_scope=*/NULL_TREE); | |
2580 | else if (is_overloaded_fn (decl)) | |
2581 | { | |
2582 | tree first_fn = OVL_CURRENT (decl); | |
b3445994 | 2583 | |
9e95d15f NS |
2584 | if (TREE_CODE (first_fn) == TEMPLATE_DECL) |
2585 | first_fn = DECL_TEMPLATE_RESULT (first_fn); | |
415d4636 MM |
2586 | |
2587 | if (!really_overloaded_fn (decl)) | |
2588 | mark_used (first_fn); | |
2589 | ||
9e95d15f NS |
2590 | if (TREE_CODE (first_fn) == FUNCTION_DECL |
2591 | && DECL_FUNCTION_MEMBER_P (first_fn)) | |
2592 | { | |
2593 | /* A set of member functions. */ | |
2594 | decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0); | |
2595 | return finish_class_member_access_expr (decl, id_expression); | |
2596 | } | |
9e95d15f NS |
2597 | } |
2598 | else | |
2599 | { | |
2600 | if (TREE_CODE (decl) == VAR_DECL | |
2601 | || TREE_CODE (decl) == PARM_DECL | |
2602 | || TREE_CODE (decl) == RESULT_DECL) | |
2603 | { | |
2604 | tree context = decl_function_context (decl); | |
2605 | ||
2606 | if (context != NULL_TREE && context != current_function_decl | |
2607 | && ! TREE_STATIC (decl)) | |
2608 | { | |
2609 | error ("use of %s from containing function", | |
2610 | (TREE_CODE (decl) == VAR_DECL | |
2611 | ? "`auto' variable" : "parameter")); | |
2612 | cp_error_at (" `%#D' declared here", decl); | |
2613 | return error_mark_node; | |
2614 | } | |
2615 | } | |
2616 | ||
2617 | if (DECL_P (decl) && DECL_NONLOCAL (decl) | |
2618 | && DECL_CLASS_SCOPE_P (decl) | |
2619 | && DECL_CONTEXT (decl) != current_class_type) | |
2620 | { | |
2621 | tree path; | |
2622 | ||
2623 | path = currently_open_derived_class (DECL_CONTEXT (decl)); | |
2624 | perform_or_defer_access_check (TYPE_BINFO (path), decl); | |
2625 | } | |
2626 | ||
9e95d15f NS |
2627 | if (! processing_template_decl) |
2628 | decl = convert_from_reference (decl); | |
2629 | } | |
2630 | ||
b3445994 MM |
2631 | /* Resolve references to variables of anonymous unions |
2632 | into COMPONENT_REFs. */ | |
2633 | if (TREE_CODE (decl) == ALIAS_DECL) | |
6de9cd9a | 2634 | decl = unshare_expr (DECL_INITIAL (decl)); |
b3445994 MM |
2635 | } |
2636 | ||
2637 | if (TREE_DEPRECATED (decl)) | |
2638 | warn_deprecated_use (decl); | |
2639 | ||
2640 | return decl; | |
2641 | } | |
2642 | ||
0213a355 JM |
2643 | /* Implement the __typeof keyword: Return the type of EXPR, suitable for |
2644 | use as a type-specifier. */ | |
2645 | ||
b894fc05 | 2646 | tree |
3a978d72 | 2647 | finish_typeof (tree expr) |
b894fc05 | 2648 | { |
65a5559b MM |
2649 | tree type; |
2650 | ||
dffbbe80 | 2651 | if (type_dependent_expression_p (expr)) |
b894fc05 | 2652 | { |
65a5559b | 2653 | type = make_aggr_type (TYPEOF_TYPE); |
eb34af89 | 2654 | TYPEOF_TYPE_EXPR (type) = expr; |
b894fc05 | 2655 | |
65a5559b | 2656 | return type; |
b894fc05 JM |
2657 | } |
2658 | ||
65a5559b MM |
2659 | type = TREE_TYPE (expr); |
2660 | ||
2661 | if (!type || type == unknown_type_node) | |
2662 | { | |
2663 | error ("type of `%E' is unknown", expr); | |
2664 | return error_mark_node; | |
2665 | } | |
2666 | ||
2667 | return type; | |
b894fc05 | 2668 | } |
558475f0 | 2669 | |
3eb24f73 | 2670 | /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs |
6de9cd9a | 2671 | with equivalent CALL_EXPRs. */ |
3eb24f73 MM |
2672 | |
2673 | static tree | |
3a978d72 | 2674 | simplify_aggr_init_exprs_r (tree* tp, |
9eeb200f JM |
2675 | int* walk_subtrees, |
2676 | void* data ATTRIBUTE_UNUSED) | |
3eb24f73 | 2677 | { |
22e92ac3 MM |
2678 | /* We don't need to walk into types; there's nothing in a type that |
2679 | needs simplification. (And, furthermore, there are places we | |
2680 | actively don't want to go. For example, we don't want to wander | |
2681 | into the default arguments for a FUNCTION_DECL that appears in a | |
2682 | CALL_EXPR.) */ | |
9eeb200f | 2683 | if (TYPE_P (*tp)) |
22e92ac3 MM |
2684 | { |
2685 | *walk_subtrees = 0; | |
2686 | return NULL_TREE; | |
2687 | } | |
2688 | /* Only AGGR_INIT_EXPRs are interesting. */ | |
9eeb200f | 2689 | else if (TREE_CODE (*tp) != AGGR_INIT_EXPR) |
3eb24f73 MM |
2690 | return NULL_TREE; |
2691 | ||
9eeb200f JM |
2692 | simplify_aggr_init_expr (tp); |
2693 | ||
2694 | /* Keep iterating. */ | |
2695 | return NULL_TREE; | |
2696 | } | |
2697 | ||
2698 | /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This | |
2699 | function is broken out from the above for the benefit of the tree-ssa | |
2700 | project. */ | |
2701 | ||
2702 | void | |
2703 | simplify_aggr_init_expr (tree *tp) | |
2704 | { | |
2705 | tree aggr_init_expr = *tp; | |
2706 | ||
3eb24f73 | 2707 | /* Form an appropriate CALL_EXPR. */ |
9eeb200f JM |
2708 | tree fn = TREE_OPERAND (aggr_init_expr, 0); |
2709 | tree args = TREE_OPERAND (aggr_init_expr, 1); | |
2710 | tree slot = TREE_OPERAND (aggr_init_expr, 2); | |
2692eb7d | 2711 | tree type = TREE_TYPE (slot); |
9eeb200f JM |
2712 | |
2713 | tree call_expr; | |
2714 | enum style_t { ctor, arg, pcc } style; | |
4977bab6 | 2715 | |
3eb24f73 | 2716 | if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr)) |
4977bab6 ZW |
2717 | style = ctor; |
2718 | #ifdef PCC_STATIC_STRUCT_RETURN | |
2719 | else if (1) | |
2720 | style = pcc; | |
2721 | #endif | |
2722 | else if (TREE_ADDRESSABLE (type)) | |
2723 | style = arg; | |
2724 | else | |
2725 | /* We shouldn't build an AGGR_INIT_EXPR if we don't need any special | |
2726 | handling. See build_cplus_new. */ | |
2727 | abort (); | |
2728 | ||
2729 | if (style == ctor || style == arg) | |
3eb24f73 | 2730 | { |
4977bab6 ZW |
2731 | /* Pass the address of the slot. If this is a constructor, we |
2732 | replace the first argument; otherwise, we tack on a new one. */ | |
9eeb200f JM |
2733 | tree addr; |
2734 | ||
4977bab6 ZW |
2735 | if (style == ctor) |
2736 | args = TREE_CHAIN (args); | |
2737 | ||
dffd7eb6 | 2738 | cxx_mark_addressable (slot); |
2692eb7d | 2739 | addr = build1 (ADDR_EXPR, build_pointer_type (type), slot); |
9eeb200f JM |
2740 | if (style == arg) |
2741 | { | |
2742 | /* The return type might have different cv-quals from the slot. */ | |
2743 | tree fntype = TREE_TYPE (TREE_TYPE (fn)); | |
2744 | #ifdef ENABLE_CHECKING | |
2745 | if (TREE_CODE (fntype) != FUNCTION_TYPE | |
2746 | && TREE_CODE (fntype) != METHOD_TYPE) | |
2747 | abort (); | |
2748 | #endif | |
2749 | addr = convert (build_pointer_type (TREE_TYPE (fntype)), addr); | |
2750 | } | |
2751 | ||
2752 | args = tree_cons (NULL_TREE, addr, args); | |
3eb24f73 | 2753 | } |
4977bab6 | 2754 | |
b850de4f MM |
2755 | call_expr = build (CALL_EXPR, |
2756 | TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), | |
2757 | fn, args, NULL_TREE); | |
3eb24f73 | 2758 | |
4977bab6 | 2759 | if (style == arg) |
89ea02fb JM |
2760 | /* Tell the backend that we've added our return slot to the argument |
2761 | list. */ | |
2762 | CALL_EXPR_HAS_RETURN_SLOT_ADDR (call_expr) = 1; | |
4977bab6 | 2763 | else if (style == pcc) |
3eb24f73 | 2764 | { |
4977bab6 ZW |
2765 | /* If we're using the non-reentrant PCC calling convention, then we |
2766 | need to copy the returned value out of the static buffer into the | |
2767 | SLOT. */ | |
78757caa | 2768 | push_deferring_access_checks (dk_no_check); |
46af705a JDA |
2769 | call_expr = build_aggr_init (slot, call_expr, |
2770 | DIRECT_BIND | LOOKUP_ONLYCONVERTING); | |
78757caa | 2771 | pop_deferring_access_checks (); |
3eb24f73 | 2772 | } |
3eb24f73 | 2773 | |
3eb24f73 | 2774 | *tp = call_expr; |
3eb24f73 MM |
2775 | } |
2776 | ||
31f8e4f3 MM |
2777 | /* Emit all thunks to FN that should be emitted when FN is emitted. */ |
2778 | ||
2779 | static void | |
3a978d72 | 2780 | emit_associated_thunks (tree fn) |
31f8e4f3 MM |
2781 | { |
2782 | /* When we use vcall offsets, we emit thunks with the virtual | |
2783 | functions to which they thunk. The whole point of vcall offsets | |
2784 | is so that you can know statically the entire set of thunks that | |
2785 | will ever be needed for a given virtual function, thereby | |
2786 | enabling you to output all the thunks with the function itself. */ | |
3461fba7 | 2787 | if (DECL_VIRTUAL_P (fn)) |
31f8e4f3 | 2788 | { |
bb5e8a7f | 2789 | tree thunk; |
4977bab6 | 2790 | |
bb5e8a7f | 2791 | for (thunk = DECL_THUNKS (fn); thunk; thunk = TREE_CHAIN (thunk)) |
4977bab6 | 2792 | { |
e00853fd | 2793 | if (!THUNK_ALIAS (thunk)) |
4977bab6 | 2794 | { |
bb885938 NS |
2795 | use_thunk (thunk, /*emit_p=*/1); |
2796 | if (DECL_RESULT_THUNK_P (thunk)) | |
2797 | { | |
2798 | tree probe; | |
2799 | ||
2800 | for (probe = DECL_THUNKS (thunk); | |
2801 | probe; probe = TREE_CHAIN (probe)) | |
2802 | use_thunk (probe, /*emit_p=*/1); | |
2803 | } | |
4977bab6 | 2804 | } |
bb885938 NS |
2805 | else |
2806 | my_friendly_assert (!DECL_THUNKS (thunk), 20031023); | |
4977bab6 | 2807 | } |
31f8e4f3 MM |
2808 | } |
2809 | } | |
2810 | ||
558475f0 MM |
2811 | /* Generate RTL for FN. */ |
2812 | ||
2813 | void | |
3a978d72 | 2814 | expand_body (tree fn) |
558475f0 | 2815 | { |
367aa585 | 2816 | tree saved_function; |
6de9cd9a | 2817 | |
92788413 MM |
2818 | /* Compute the appropriate object-file linkage for inline |
2819 | functions. */ | |
79065db2 | 2820 | if (DECL_DECLARED_INLINE_P (fn)) |
92788413 MM |
2821 | import_export_decl (fn); |
2822 | ||
4f8e1232 MM |
2823 | /* If FN is external, then there's no point in generating RTL for |
2824 | it. This situation can arise with an inline function under | |
83662e2b | 2825 | `-fexternal-templates'; we instantiate the function, even though |
4f8e1232 MM |
2826 | we're not planning on emitting it, in case we get a chance to |
2827 | inline it. */ | |
2828 | if (DECL_EXTERNAL (fn)) | |
2829 | return; | |
2830 | ||
4985cde3 | 2831 | /* ??? When is this needed? */ |
367aa585 | 2832 | saved_function = current_function_decl; |
367aa585 | 2833 | |
de81ffd4 JH |
2834 | /* Emit any thunks that should be emitted at the same time as FN. */ |
2835 | emit_associated_thunks (fn); | |
2836 | ||
c1f927e8 | 2837 | tree_rest_of_compilation (fn, function_depth > 1); |
d658cd4c | 2838 | |
367aa585 | 2839 | current_function_decl = saved_function; |
ea11ca7e | 2840 | |
4985cde3 | 2841 | extract_interface_info (); |
14691f8d | 2842 | |
4985cde3 RH |
2843 | /* If this function is marked with the constructor attribute, add it |
2844 | to the list of functions to be called along with constructors | |
2845 | from static duration objects. */ | |
2846 | if (DECL_STATIC_CONSTRUCTOR (fn)) | |
2847 | static_ctors = tree_cons (NULL_TREE, fn, static_ctors); | |
2848 | ||
2849 | /* If this function is marked with the destructor attribute, add it | |
2850 | to the list of functions to be called along with destructors from | |
2851 | static duration objects. */ | |
2852 | if (DECL_STATIC_DESTRUCTOR (fn)) | |
2853 | static_dtors = tree_cons (NULL_TREE, fn, static_dtors); | |
85b22f78 NS |
2854 | |
2855 | if (DECL_CLONED_FUNCTION_P (fn)) | |
2856 | { | |
2857 | /* If this is a clone, go through the other clones now and mark | |
2858 | their parameters used. We have to do that here, as we don't | |
2859 | know whether any particular clone will be expanded, and | |
2860 | therefore cannot pick one arbitrarily. */ | |
2861 | tree probe; | |
2862 | ||
2863 | for (probe = TREE_CHAIN (DECL_CLONED_FUNCTION (fn)); | |
2864 | probe && DECL_CLONED_FUNCTION_P (probe); | |
2865 | probe = TREE_CHAIN (probe)) | |
2866 | { | |
2867 | tree parms; | |
2868 | ||
2869 | for (parms = DECL_ARGUMENTS (probe); | |
2870 | parms; parms = TREE_CHAIN (parms)) | |
2871 | TREE_USED (parms) = 1; | |
2872 | } | |
2873 | } | |
558475f0 | 2874 | } |
54f7877c | 2875 | |
8cd2462c JH |
2876 | /* Generate RTL for FN. */ |
2877 | ||
2878 | void | |
5671bf27 | 2879 | expand_or_defer_fn (tree fn) |
8cd2462c JH |
2880 | { |
2881 | /* When the parser calls us after finishing the body of a template | |
c353b8e3 MM |
2882 | function, we don't really want to expand the body. */ |
2883 | if (processing_template_decl) | |
8cd2462c JH |
2884 | { |
2885 | /* Normally, collection only occurs in rest_of_compilation. So, | |
2886 | if we don't collect here, we never collect junk generated | |
2887 | during the processing of templates until we hit a | |
2888 | non-template function. */ | |
2889 | ggc_collect (); | |
2890 | return; | |
2891 | } | |
2892 | ||
2893 | /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */ | |
2894 | walk_tree_without_duplicates (&DECL_SAVED_TREE (fn), | |
2895 | simplify_aggr_init_exprs_r, | |
2896 | NULL); | |
2897 | ||
2898 | /* If this is a constructor or destructor body, we have to clone | |
2899 | it. */ | |
2900 | if (maybe_clone_body (fn)) | |
2901 | { | |
2902 | /* We don't want to process FN again, so pretend we've written | |
2903 | it out, even though we haven't. */ | |
2904 | TREE_ASM_WRITTEN (fn) = 1; | |
2905 | return; | |
2906 | } | |
2907 | ||
2908 | /* There's no reason to do any of the work here if we're only doing | |
2909 | semantic analysis; this code just generates RTL. */ | |
2910 | if (flag_syntax_only) | |
2911 | return; | |
2912 | ||
e4d91027 RH |
2913 | /* Compute the appropriate object-file linkage for inline functions. */ |
2914 | if (DECL_DECLARED_INLINE_P (fn)) | |
2915 | import_export_decl (fn); | |
8cd2462c | 2916 | |
99edd65d RH |
2917 | function_depth++; |
2918 | ||
e4d91027 | 2919 | /* Expand or defer, at the whim of the compilation unit manager. */ |
6b00c969 | 2920 | cgraph_finalize_function (fn, function_depth > 1); |
99edd65d RH |
2921 | |
2922 | function_depth--; | |
8cd2462c JH |
2923 | } |
2924 | ||
6de9cd9a DN |
2925 | struct nrv_data |
2926 | { | |
2927 | tree var; | |
2928 | tree result; | |
2929 | htab_t visited; | |
2930 | }; | |
0d97bf4c | 2931 | |
6de9cd9a DN |
2932 | /* Helper function for walk_tree, used by finalize_nrv below. */ |
2933 | ||
2934 | static tree | |
2935 | finalize_nrv_r (tree* tp, int* walk_subtrees, void* data) | |
0d97bf4c | 2936 | { |
6de9cd9a DN |
2937 | struct nrv_data *dp = (struct nrv_data *)data; |
2938 | void **slot; | |
07b2f2fd JM |
2939 | |
2940 | /* No need to walk into types. There wouldn't be any need to walk into | |
2941 | non-statements, except that we have to consider STMT_EXPRs. */ | |
0d97bf4c JM |
2942 | if (TYPE_P (*tp)) |
2943 | *walk_subtrees = 0; | |
6de9cd9a DN |
2944 | /* Change all returns to just refer to the RESULT_DECL; this is a nop, |
2945 | but differs from using NULL_TREE in that it indicates that we care | |
2946 | about the value of the RESULT_DECL. */ | |
5088b058 RH |
2947 | else if (TREE_CODE (*tp) == RETURN_EXPR) |
2948 | TREE_OPERAND (*tp, 0) = dp->result; | |
6de9cd9a DN |
2949 | /* Change all cleanups for the NRV to only run when an exception is |
2950 | thrown. */ | |
07b2f2fd | 2951 | else if (TREE_CODE (*tp) == CLEANUP_STMT |
6de9cd9a | 2952 | && CLEANUP_DECL (*tp) == dp->var) |
659e5a7a | 2953 | CLEANUP_EH_ONLY (*tp) = 1; |
350fae66 | 2954 | /* Replace the DECL_EXPR for the NRV with an initialization of the |
6de9cd9a | 2955 | RESULT_DECL, if needed. */ |
350fae66 RK |
2956 | else if (TREE_CODE (*tp) == DECL_EXPR |
2957 | && DECL_EXPR_DECL (*tp) == dp->var) | |
6de9cd9a DN |
2958 | { |
2959 | tree init; | |
2960 | if (DECL_INITIAL (dp->var) | |
2961 | && DECL_INITIAL (dp->var) != error_mark_node) | |
2962 | { | |
2963 | init = build (INIT_EXPR, void_type_node, dp->result, | |
2964 | DECL_INITIAL (dp->var)); | |
2965 | DECL_INITIAL (dp->var) = error_mark_node; | |
2966 | } | |
2967 | else | |
543a0daa | 2968 | init = build_empty_stmt (); |
6de9cd9a | 2969 | SET_EXPR_LOCUS (init, EXPR_LOCUS (*tp)); |
6de9cd9a DN |
2970 | *tp = init; |
2971 | } | |
2972 | /* And replace all uses of the NRV with the RESULT_DECL. */ | |
2973 | else if (*tp == dp->var) | |
2974 | *tp = dp->result; | |
2975 | ||
2976 | /* Avoid walking into the same tree more than once. Unfortunately, we | |
2977 | can't just use walk_tree_without duplicates because it would only call | |
2978 | us for the first occurrence of dp->var in the function body. */ | |
2979 | slot = htab_find_slot (dp->visited, *tp, INSERT); | |
2980 | if (*slot) | |
2981 | *walk_subtrees = 0; | |
2982 | else | |
2983 | *slot = *tp; | |
0d97bf4c JM |
2984 | |
2985 | /* Keep iterating. */ | |
2986 | return NULL_TREE; | |
2987 | } | |
2988 | ||
6de9cd9a | 2989 | /* Called from finish_function to implement the named return value |
5088b058 | 2990 | optimization by overriding all the RETURN_EXPRs and pertinent |
6de9cd9a DN |
2991 | CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the |
2992 | RESULT_DECL for the function. */ | |
f444e36b | 2993 | |
4985cde3 | 2994 | void |
6de9cd9a | 2995 | finalize_nrv (tree *tp, tree var, tree result) |
f444e36b | 2996 | { |
6de9cd9a DN |
2997 | struct nrv_data data; |
2998 | ||
2999 | /* Copy debugging information from VAR to RESULT. */ | |
3000 | DECL_NAME (result) = DECL_NAME (var); | |
3001 | DECL_SOURCE_LOCATION (result) = DECL_SOURCE_LOCATION (var); | |
3002 | DECL_ABSTRACT_ORIGIN (result) = DECL_ABSTRACT_ORIGIN (var); | |
3003 | /* Don't forget that we take its address. */ | |
3004 | TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var); | |
3005 | ||
3006 | data.var = var; | |
3007 | data.result = result; | |
3008 | data.visited = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL); | |
3009 | walk_tree (tp, finalize_nrv_r, &data, 0); | |
3010 | htab_delete (data.visited); | |
b850de4f MM |
3011 | } |
3012 | ||
54f7877c MM |
3013 | /* Perform initialization related to this module. */ |
3014 | ||
3015 | void | |
3a978d72 | 3016 | init_cp_semantics (void) |
54f7877c | 3017 | { |
54f7877c | 3018 | } |
cf22909c KL |
3019 | |
3020 | #include "gt-cp-semantics.h" |