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