]>
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; | |
a5bcc582 NS |
1377 | |
1378 | if (expr) | |
1379 | { | |
a5bcc582 NS |
1380 | if (!processing_template_decl && !VOID_TYPE_P (TREE_TYPE (expr))) |
1381 | { | |
2692eb7d JM |
1382 | tree type = TREE_TYPE (expr); |
1383 | ||
a5bcc582 NS |
1384 | if (TREE_CODE (type) == ARRAY_TYPE |
1385 | || TREE_CODE (type) == FUNCTION_TYPE) | |
1386 | expr = decay_conversion (expr); | |
1387 | ||
1388 | expr = convert_from_reference (expr); | |
1389 | expr = require_complete_type (expr); | |
1390 | ||
2692eb7d JM |
1391 | type = TREE_TYPE (expr); |
1392 | ||
a5bcc582 NS |
1393 | /* Build a TARGET_EXPR for this aggregate. finish_stmt_expr |
1394 | will then pull it apart so the lifetime of the target is | |
cd0be382 | 1395 | within the scope of the expression containing this statement |
a5bcc582 NS |
1396 | expression. */ |
1397 | if (TREE_CODE (expr) == TARGET_EXPR) | |
1398 | ; | |
1399 | else if (!IS_AGGR_TYPE (type) || TYPE_HAS_TRIVIAL_INIT_REF (type)) | |
1400 | expr = build_target_expr_with_type (expr, type); | |
1401 | else | |
1402 | { | |
1403 | /* Copy construct. */ | |
1404 | expr = build_special_member_call | |
1405 | (NULL_TREE, complete_ctor_identifier, | |
1406 | build_tree_list (NULL_TREE, expr), | |
1407 | TYPE_BINFO (type), LOOKUP_NORMAL); | |
1408 | expr = build_cplus_new (type, expr); | |
1409 | my_friendly_assert (TREE_CODE (expr) == TARGET_EXPR, 20030729); | |
1410 | } | |
1411 | } | |
1412 | ||
1413 | if (expr != error_mark_node) | |
1414 | { | |
1415 | result = build_stmt (EXPR_STMT, expr); | |
325c3691 | 1416 | EXPR_STMT_STMT_EXPR_RESULT (result) = 1; |
a5bcc582 NS |
1417 | add_stmt (result); |
1418 | } | |
1419 | } | |
1420 | ||
1421 | finish_stmt (); | |
1422 | ||
325c3691 RH |
1423 | /* Remember the last expression so that finish_stmt_expr |
1424 | can pull it apart. */ | |
1425 | TREE_TYPE (stmt_expr) = result; | |
a5bcc582 NS |
1426 | |
1427 | return result; | |
1428 | } | |
1429 | ||
303b7406 NS |
1430 | /* Finish a statement-expression. EXPR should be the value returned |
1431 | by the previous begin_stmt_expr. Returns an expression | |
1432 | representing the statement-expression. */ | |
b4c4a9ec MM |
1433 | |
1434 | tree | |
325c3691 | 1435 | finish_stmt_expr (tree stmt_expr, bool has_no_scope) |
b4c4a9ec | 1436 | { |
325c3691 RH |
1437 | tree result, result_stmt, type; |
1438 | tree *result_stmt_p = NULL; | |
1439 | ||
1440 | result_stmt = TREE_TYPE (stmt_expr); | |
1441 | TREE_TYPE (stmt_expr) = void_type_node; | |
1442 | result = pop_stmt_list (stmt_expr); | |
1443 | ||
1444 | if (!result_stmt || VOID_TYPE_P (result_stmt)) | |
a5bcc582 NS |
1445 | type = void_type_node; |
1446 | else | |
1447 | { | |
325c3691 RH |
1448 | /* We need to search the statement expression for the result_stmt, |
1449 | since we'll need to replace it entirely. */ | |
1450 | tree t; | |
1451 | result_stmt_p = &result; | |
1452 | while (1) | |
a5bcc582 | 1453 | { |
325c3691 RH |
1454 | t = *result_stmt_p; |
1455 | if (t == result_stmt) | |
1456 | break; | |
1457 | ||
1458 | switch (TREE_CODE (t)) | |
1459 | { | |
1460 | case STATEMENT_LIST: | |
1461 | { | |
1462 | tree_stmt_iterator i = tsi_last (t); | |
1463 | result_stmt_p = tsi_stmt_ptr (i); | |
1464 | break; | |
1465 | } | |
1466 | case BIND_EXPR: | |
1467 | result_stmt_p = &BIND_EXPR_BODY (t); | |
1468 | break; | |
325c3691 RH |
1469 | case TRY_FINALLY_EXPR: |
1470 | case TRY_CATCH_EXPR: | |
1471 | case CLEANUP_STMT: | |
1472 | result_stmt_p = &TREE_OPERAND (t, 0); | |
1473 | break; | |
1474 | default: | |
1475 | abort (); | |
1476 | } | |
a5bcc582 | 1477 | } |
325c3691 | 1478 | type = TREE_TYPE (EXPR_STMT_EXPR (result_stmt)); |
a5bcc582 | 1479 | } |
6f80451c | 1480 | |
a5bcc582 | 1481 | if (processing_template_decl) |
325c3691 RH |
1482 | { |
1483 | result = build_min (STMT_EXPR, type, result); | |
1484 | TREE_SIDE_EFFECTS (result) = 1; | |
1485 | STMT_EXPR_NO_SCOPE (result) = has_no_scope; | |
1486 | } | |
1487 | else if (!VOID_TYPE_P (type)) | |
a5bcc582 NS |
1488 | { |
1489 | /* Pull out the TARGET_EXPR that is the final expression. Put | |
1490 | the target's init_expr as the final expression and then put | |
1491 | the statement expression itself as the target's init | |
1492 | expr. Finally, return the target expression. */ | |
2692eb7d JM |
1493 | tree init, target_expr = EXPR_STMT_EXPR (result_stmt); |
1494 | my_friendly_assert (TREE_CODE (target_expr) == TARGET_EXPR, 20030729); | |
1495 | ||
1496 | /* The initializer will be void if the initialization is done by | |
1497 | AGGR_INIT_EXPR; propagate that out to the statement-expression as | |
1498 | a whole. */ | |
1499 | init = TREE_OPERAND (target_expr, 1); | |
1500 | type = TREE_TYPE (init); | |
1501 | ||
1502 | if (stmts_are_full_exprs_p ()) | |
1503 | init = fold (build1 (CLEANUP_POINT_EXPR, type, init)); | |
1504 | *result_stmt_p = init; | |
1505 | ||
1506 | if (VOID_TYPE_P (type)) | |
1507 | /* No frobbing needed. */; | |
1508 | else if (TREE_CODE (result) == BIND_EXPR) | |
325c3691 | 1509 | { |
2692eb7d JM |
1510 | /* The BIND_EXPR created in finish_compound_stmt is void; if we're |
1511 | returning a value directly, give it the appropriate type. */ | |
325c3691 | 1512 | if (VOID_TYPE_P (TREE_TYPE (result))) |
2692eb7d JM |
1513 | TREE_TYPE (result) = type; |
1514 | else if (same_type_p (TREE_TYPE (result), type)) | |
325c3691 RH |
1515 | ; |
1516 | else | |
1517 | abort (); | |
1518 | } | |
1519 | else if (TREE_CODE (result) == STATEMENT_LIST) | |
2692eb7d JM |
1520 | /* We need to wrap a STATEMENT_LIST in a BIND_EXPR so it can have a |
1521 | type other than void. FIXME why can't we just return a value | |
1522 | from STATEMENT_LIST? */ | |
1523 | result = build3 (BIND_EXPR, type, NULL, result, NULL); | |
325c3691 | 1524 | |
2692eb7d JM |
1525 | TREE_OPERAND (target_expr, 1) = result; |
1526 | result = target_expr; | |
a5bcc582 | 1527 | } |
325c3691 | 1528 | |
b4c4a9ec MM |
1529 | return result; |
1530 | } | |
1531 | ||
b3445994 | 1532 | /* Perform Koenig lookup. FN is the postfix-expression representing |
fa531100 MM |
1533 | the function (or functions) to call; ARGS are the arguments to the |
1534 | call. Returns the functions to be considered by overload | |
1535 | resolution. */ | |
b3445994 MM |
1536 | |
1537 | tree | |
1538 | perform_koenig_lookup (tree fn, tree args) | |
1539 | { | |
1540 | tree identifier = NULL_TREE; | |
1541 | tree functions = NULL_TREE; | |
1542 | ||
1543 | /* Find the name of the overloaded function. */ | |
1544 | if (TREE_CODE (fn) == IDENTIFIER_NODE) | |
1545 | identifier = fn; | |
1546 | else if (is_overloaded_fn (fn)) | |
1547 | { | |
1548 | functions = fn; | |
1549 | identifier = DECL_NAME (get_first_fn (functions)); | |
1550 | } | |
1551 | else if (DECL_P (fn)) | |
1552 | { | |
1553 | functions = fn; | |
1554 | identifier = DECL_NAME (fn); | |
1555 | } | |
1556 | ||
1557 | /* A call to a namespace-scope function using an unqualified name. | |
1558 | ||
1559 | Do Koenig lookup -- unless any of the arguments are | |
1560 | type-dependent. */ | |
1561 | if (!any_type_dependent_arguments_p (args)) | |
1562 | { | |
1563 | fn = lookup_arg_dependent (identifier, functions, args); | |
1564 | if (!fn) | |
1565 | /* The unqualified name could not be resolved. */ | |
1566 | fn = unqualified_fn_lookup_error (identifier); | |
1567 | } | |
1568 | else | |
10b1d5e7 | 1569 | fn = identifier; |
b3445994 MM |
1570 | |
1571 | return fn; | |
1572 | } | |
1573 | ||
4ba126e4 MM |
1574 | /* Generate an expression for `FN (ARGS)'. |
1575 | ||
1576 | If DISALLOW_VIRTUAL is true, the call to FN will be not generated | |
1577 | as a virtual call, even if FN is virtual. (This flag is set when | |
1578 | encountering an expression where the function name is explicitly | |
1579 | qualified. For example a call to `X::f' never generates a virtual | |
1580 | call.) | |
1581 | ||
1582 | Returns code for the call. */ | |
b4c4a9ec MM |
1583 | |
1584 | tree | |
6d80c4b9 | 1585 | finish_call_expr (tree fn, tree args, bool disallow_virtual, bool koenig_p) |
b4c4a9ec | 1586 | { |
d17811fd MM |
1587 | tree result; |
1588 | tree orig_fn; | |
1589 | tree orig_args; | |
1590 | ||
4ba126e4 MM |
1591 | if (fn == error_mark_node || args == error_mark_node) |
1592 | return error_mark_node; | |
1593 | ||
4ba126e4 MM |
1594 | /* ARGS should be a list of arguments. */ |
1595 | my_friendly_assert (!args || TREE_CODE (args) == TREE_LIST, | |
1596 | 20020712); | |
a759e627 | 1597 | |
d17811fd MM |
1598 | orig_fn = fn; |
1599 | orig_args = args; | |
1600 | ||
1601 | if (processing_template_decl) | |
1602 | { | |
1603 | if (type_dependent_expression_p (fn) | |
1604 | || any_type_dependent_arguments_p (args)) | |
6d80c4b9 | 1605 | { |
6de9cd9a | 1606 | result = build_nt (CALL_EXPR, fn, args, NULL_TREE); |
6d80c4b9 MM |
1607 | KOENIG_LOOKUP_P (result) = koenig_p; |
1608 | return result; | |
1609 | } | |
d17811fd MM |
1610 | if (!BASELINK_P (fn) |
1611 | && TREE_CODE (fn) != PSEUDO_DTOR_EXPR | |
1612 | && TREE_TYPE (fn) != unknown_type_node) | |
1613 | fn = build_non_dependent_expr (fn); | |
1614 | args = build_non_dependent_args (orig_args); | |
1615 | } | |
1616 | ||
a723baf1 MM |
1617 | /* A reference to a member function will appear as an overloaded |
1618 | function (rather than a BASELINK) if an unqualified name was used | |
1619 | to refer to it. */ | |
1620 | if (!BASELINK_P (fn) && is_overloaded_fn (fn)) | |
1621 | { | |
12483c9f | 1622 | tree f = fn; |
a723baf1 | 1623 | |
12483c9f NS |
1624 | if (TREE_CODE (f) == TEMPLATE_ID_EXPR) |
1625 | f = TREE_OPERAND (f, 0); | |
1626 | f = get_first_fn (f); | |
a723baf1 MM |
1627 | if (DECL_FUNCTION_MEMBER_P (f)) |
1628 | { | |
1629 | tree type = currently_open_derived_class (DECL_CONTEXT (f)); | |
c44e68a5 KL |
1630 | if (!type) |
1631 | type = DECL_CONTEXT (f); | |
a723baf1 MM |
1632 | fn = build_baselink (TYPE_BINFO (type), |
1633 | TYPE_BINFO (type), | |
1634 | fn, /*optype=*/NULL_TREE); | |
1635 | } | |
1636 | } | |
1637 | ||
d17811fd | 1638 | result = NULL_TREE; |
4ba126e4 | 1639 | if (BASELINK_P (fn)) |
03d82991 | 1640 | { |
4ba126e4 MM |
1641 | tree object; |
1642 | ||
1643 | /* A call to a member function. From [over.call.func]: | |
1644 | ||
1645 | If the keyword this is in scope and refers to the class of | |
1646 | that member function, or a derived class thereof, then the | |
1647 | function call is transformed into a qualified function call | |
1648 | using (*this) as the postfix-expression to the left of the | |
1649 | . operator.... [Otherwise] a contrived object of type T | |
1650 | becomes the implied object argument. | |
1651 | ||
1652 | This paragraph is unclear about this situation: | |
1653 | ||
1654 | struct A { void f(); }; | |
1655 | struct B : public A {}; | |
1656 | struct C : public A { void g() { B::f(); }}; | |
1657 | ||
1658 | In particular, for `B::f', this paragraph does not make clear | |
1659 | whether "the class of that member function" refers to `A' or | |
1660 | to `B'. We believe it refers to `B'. */ | |
1661 | if (current_class_type | |
1662 | && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), | |
1663 | current_class_type) | |
1664 | && current_class_ref) | |
127b8136 MM |
1665 | object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), |
1666 | NULL); | |
4ba126e4 MM |
1667 | else |
1668 | { | |
1669 | tree representative_fn; | |
b4c4a9ec | 1670 | |
4ba126e4 MM |
1671 | representative_fn = BASELINK_FUNCTIONS (fn); |
1672 | if (TREE_CODE (representative_fn) == TEMPLATE_ID_EXPR) | |
1673 | representative_fn = TREE_OPERAND (representative_fn, 0); | |
1674 | representative_fn = get_first_fn (representative_fn); | |
1675 | object = build_dummy_object (DECL_CONTEXT (representative_fn)); | |
1676 | } | |
b4c4a9ec | 1677 | |
d17811fd MM |
1678 | if (processing_template_decl) |
1679 | { | |
1680 | if (type_dependent_expression_p (object)) | |
6de9cd9a | 1681 | return build_nt (CALL_EXPR, orig_fn, orig_args, NULL_TREE); |
d17811fd MM |
1682 | object = build_non_dependent_expr (object); |
1683 | } | |
1684 | ||
1685 | result = build_new_method_call (object, fn, args, NULL_TREE, | |
1686 | (disallow_virtual | |
1687 | ? LOOKUP_NONVIRTUAL : 0)); | |
4ba126e4 MM |
1688 | } |
1689 | else if (is_overloaded_fn (fn)) | |
1690 | /* A call to a namespace-scope function. */ | |
d17811fd | 1691 | result = build_new_function_call (fn, args); |
a723baf1 MM |
1692 | else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR) |
1693 | { | |
a723baf1 MM |
1694 | if (args) |
1695 | error ("arguments to destructor are not allowed"); | |
1696 | /* Mark the pseudo-destructor call as having side-effects so | |
1697 | that we do not issue warnings about its use. */ | |
1698 | result = build1 (NOP_EXPR, | |
1699 | void_type_node, | |
1700 | TREE_OPERAND (fn, 0)); | |
1701 | TREE_SIDE_EFFECTS (result) = 1; | |
a723baf1 | 1702 | } |
4ba126e4 | 1703 | else if (CLASS_TYPE_P (TREE_TYPE (fn))) |
d17811fd MM |
1704 | /* If the "function" is really an object of class type, it might |
1705 | have an overloaded `operator ()'. */ | |
ec835fb2 MM |
1706 | result = build_new_op (CALL_EXPR, LOOKUP_NORMAL, fn, args, NULL_TREE, |
1707 | /*overloaded_p=*/NULL); | |
d17811fd MM |
1708 | if (!result) |
1709 | /* A call where the function is unknown. */ | |
1710 | result = build_function_call (fn, args); | |
4ba126e4 | 1711 | |
d17811fd | 1712 | if (processing_template_decl) |
6d80c4b9 | 1713 | { |
6de9cd9a DN |
1714 | result = build (CALL_EXPR, TREE_TYPE (result), orig_fn, |
1715 | orig_args, NULL_TREE); | |
6d80c4b9 MM |
1716 | KOENIG_LOOKUP_P (result) = koenig_p; |
1717 | } | |
d17811fd | 1718 | return result; |
b4c4a9ec MM |
1719 | } |
1720 | ||
1721 | /* Finish a call to a postfix increment or decrement or EXPR. (Which | |
1722 | is indicated by CODE, which should be POSTINCREMENT_EXPR or | |
1723 | POSTDECREMENT_EXPR.) */ | |
1724 | ||
1725 | tree | |
3a978d72 | 1726 | finish_increment_expr (tree expr, enum tree_code code) |
b4c4a9ec | 1727 | { |
b4c4a9ec MM |
1728 | return build_x_unary_op (code, expr); |
1729 | } | |
1730 | ||
1731 | /* Finish a use of `this'. Returns an expression for `this'. */ | |
1732 | ||
1733 | tree | |
3a978d72 | 1734 | finish_this_expr (void) |
b4c4a9ec MM |
1735 | { |
1736 | tree result; | |
1737 | ||
1738 | if (current_class_ptr) | |
1739 | { | |
b4c4a9ec MM |
1740 | result = current_class_ptr; |
1741 | } | |
1742 | else if (current_function_decl | |
1743 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
1744 | { | |
8251199e | 1745 | error ("`this' is unavailable for static member functions"); |
b4c4a9ec MM |
1746 | result = error_mark_node; |
1747 | } | |
1748 | else | |
1749 | { | |
1750 | if (current_function_decl) | |
8251199e | 1751 | error ("invalid use of `this' in non-member function"); |
b4c4a9ec | 1752 | else |
8251199e | 1753 | error ("invalid use of `this' at top level"); |
b4c4a9ec MM |
1754 | result = error_mark_node; |
1755 | } | |
1756 | ||
1757 | return result; | |
1758 | } | |
1759 | ||
a723baf1 MM |
1760 | /* Finish a pseudo-destructor expression. If SCOPE is NULL, the |
1761 | expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is | |
1762 | the TYPE for the type given. If SCOPE is non-NULL, the expression | |
1763 | was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */ | |
b4c4a9ec MM |
1764 | |
1765 | tree | |
3a978d72 | 1766 | finish_pseudo_destructor_expr (tree object, tree scope, tree destructor) |
b4c4a9ec | 1767 | { |
a723baf1 MM |
1768 | if (destructor == error_mark_node) |
1769 | return error_mark_node; | |
40242ccf | 1770 | |
a723baf1 | 1771 | my_friendly_assert (TYPE_P (destructor), 20010905); |
b4c4a9ec | 1772 | |
a723baf1 MM |
1773 | if (!processing_template_decl) |
1774 | { | |
1775 | if (scope == error_mark_node) | |
1776 | { | |
1777 | error ("invalid qualifying scope in pseudo-destructor name"); | |
1778 | return error_mark_node; | |
1779 | } | |
1780 | ||
26bcf8fc MM |
1781 | /* [expr.pseudo] says both: |
1782 | ||
1783 | The type designated by the pseudo-destructor-name shall be | |
1784 | the same as the object type. | |
1785 | ||
1786 | and: | |
1787 | ||
1788 | The cv-unqualified versions of the object type and of the | |
1789 | type designated by the pseudo-destructor-name shall be the | |
1790 | same type. | |
1791 | ||
1792 | We implement the more generous second sentence, since that is | |
1793 | what most other compilers do. */ | |
1794 | if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object), | |
1795 | destructor)) | |
a723baf1 MM |
1796 | { |
1797 | error ("`%E' is not of type `%T'", object, destructor); | |
1798 | return error_mark_node; | |
1799 | } | |
1800 | } | |
b4c4a9ec | 1801 | |
a723baf1 | 1802 | return build (PSEUDO_DTOR_EXPR, void_type_node, object, scope, destructor); |
b4c4a9ec MM |
1803 | } |
1804 | ||
ce4a0391 MM |
1805 | /* Finish an expression of the form CODE EXPR. */ |
1806 | ||
1807 | tree | |
3a978d72 | 1808 | finish_unary_op_expr (enum tree_code code, tree expr) |
ce4a0391 MM |
1809 | { |
1810 | tree result = build_x_unary_op (code, expr); | |
7c355bca ML |
1811 | /* Inside a template, build_x_unary_op does not fold the |
1812 | expression. So check whether the result is folded before | |
1813 | setting TREE_NEGATED_INT. */ | |
1814 | if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST | |
88b4335f | 1815 | && TREE_CODE (result) == INTEGER_CST |
8df83eae | 1816 | && !TYPE_UNSIGNED (TREE_TYPE (result)) |
88b4335f | 1817 | && INT_CST_LT (result, integer_zero_node)) |
ce4a0391 MM |
1818 | TREE_NEGATED_INT (result) = 1; |
1819 | overflow_warning (result); | |
1820 | return result; | |
1821 | } | |
1822 | ||
a723baf1 MM |
1823 | /* Finish a compound-literal expression. TYPE is the type to which |
1824 | the INITIALIZER_LIST is being cast. */ | |
1825 | ||
1826 | tree | |
3a978d72 | 1827 | finish_compound_literal (tree type, tree initializer_list) |
a723baf1 MM |
1828 | { |
1829 | tree compound_literal; | |
1830 | ||
1831 | /* Build a CONSTRUCTOR for the INITIALIZER_LIST. */ | |
dcf92453 | 1832 | compound_literal = build_constructor (NULL_TREE, initializer_list); |
a723baf1 MM |
1833 | /* Mark it as a compound-literal. */ |
1834 | TREE_HAS_CONSTRUCTOR (compound_literal) = 1; | |
1835 | if (processing_template_decl) | |
1836 | TREE_TYPE (compound_literal) = type; | |
1837 | else | |
1838 | { | |
1839 | /* Check the initialization. */ | |
1840 | compound_literal = digest_init (type, compound_literal, NULL); | |
1841 | /* If the TYPE was an array type with an unknown bound, then we can | |
1842 | figure out the dimension now. For example, something like: | |
1843 | ||
1844 | `(int []) { 2, 3 }' | |
1845 | ||
1846 | implies that the array has two elements. */ | |
1847 | if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) | |
1848 | complete_array_type (type, compound_literal, 1); | |
1849 | } | |
1850 | ||
1851 | return compound_literal; | |
1852 | } | |
1853 | ||
5f261ba9 MM |
1854 | /* Return the declaration for the function-name variable indicated by |
1855 | ID. */ | |
1856 | ||
1857 | tree | |
1858 | finish_fname (tree id) | |
1859 | { | |
1860 | tree decl; | |
1861 | ||
1862 | decl = fname_decl (C_RID_CODE (id), id); | |
1863 | if (processing_template_decl) | |
10b1d5e7 | 1864 | decl = DECL_NAME (decl); |
5f261ba9 MM |
1865 | return decl; |
1866 | } | |
1867 | ||
15c7fb9c | 1868 | /* Begin a function definition declared with DECL_SPECS, ATTRIBUTES, |
838dfd8a | 1869 | and DECLARATOR. Returns nonzero if the function-declaration is |
0e339752 | 1870 | valid. */ |
b4c4a9ec MM |
1871 | |
1872 | int | |
3a978d72 | 1873 | begin_function_definition (tree decl_specs, tree attributes, tree declarator) |
b4c4a9ec | 1874 | { |
15c7fb9c | 1875 | if (!start_function (decl_specs, declarator, attributes, SF_DEFAULT)) |
b4c4a9ec | 1876 | return 0; |
1f51a992 | 1877 | |
39c01e4c MM |
1878 | /* The things we're about to see are not directly qualified by any |
1879 | template headers we've seen thus far. */ | |
1880 | reset_specialization (); | |
1881 | ||
b4c4a9ec MM |
1882 | return 1; |
1883 | } | |
1884 | ||
8014a339 | 1885 | /* Finish a translation unit. */ |
ce4a0391 MM |
1886 | |
1887 | void | |
3a978d72 | 1888 | finish_translation_unit (void) |
ce4a0391 MM |
1889 | { |
1890 | /* In case there were missing closebraces, | |
1891 | get us back to the global binding level. */ | |
273a708f | 1892 | pop_everything (); |
ce4a0391 MM |
1893 | while (current_namespace != global_namespace) |
1894 | pop_namespace (); | |
0ba8a114 | 1895 | |
c6002625 | 1896 | /* Do file scope __FUNCTION__ et al. */ |
0ba8a114 | 1897 | finish_fname_decls (); |
ce4a0391 MM |
1898 | } |
1899 | ||
b4c4a9ec MM |
1900 | /* Finish a template type parameter, specified as AGGR IDENTIFIER. |
1901 | Returns the parameter. */ | |
1902 | ||
1903 | tree | |
3a978d72 | 1904 | finish_template_type_parm (tree aggr, tree identifier) |
b4c4a9ec | 1905 | { |
6eabb241 | 1906 | if (aggr != class_type_node) |
b4c4a9ec | 1907 | { |
8251199e | 1908 | pedwarn ("template type parameters must use the keyword `class' or `typename'"); |
b4c4a9ec MM |
1909 | aggr = class_type_node; |
1910 | } | |
1911 | ||
1912 | return build_tree_list (aggr, identifier); | |
1913 | } | |
1914 | ||
1915 | /* Finish a template template parameter, specified as AGGR IDENTIFIER. | |
1916 | Returns the parameter. */ | |
1917 | ||
1918 | tree | |
3a978d72 | 1919 | finish_template_template_parm (tree aggr, tree identifier) |
b4c4a9ec MM |
1920 | { |
1921 | tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE); | |
1922 | tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); | |
1923 | DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; | |
1924 | DECL_TEMPLATE_RESULT (tmpl) = decl; | |
c727aa5e | 1925 | DECL_ARTIFICIAL (decl) = 1; |
b4c4a9ec MM |
1926 | end_template_decl (); |
1927 | ||
b37bf5bd NS |
1928 | my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110); |
1929 | ||
b4c4a9ec MM |
1930 | return finish_template_type_parm (aggr, tmpl); |
1931 | } | |
ce4a0391 | 1932 | |
8ba658ee MM |
1933 | /* ARGUMENT is the default-argument value for a template template |
1934 | parameter. If ARGUMENT is invalid, issue error messages and return | |
1935 | the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */ | |
1936 | ||
1937 | tree | |
1938 | check_template_template_default_arg (tree argument) | |
1939 | { | |
1940 | if (TREE_CODE (argument) != TEMPLATE_DECL | |
1941 | && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM | |
8ba658ee MM |
1942 | && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) |
1943 | { | |
a3a503a5 GB |
1944 | if (TREE_CODE (argument) == TYPE_DECL) |
1945 | { | |
1946 | tree t = TREE_TYPE (argument); | |
1947 | ||
1948 | /* Try to emit a slightly smarter error message if we detect | |
1949 | that the user is using a template instantiation. */ | |
1950 | if (CLASSTYPE_TEMPLATE_INFO (t) | |
1951 | && CLASSTYPE_TEMPLATE_INSTANTIATION (t)) | |
1952 | error ("invalid use of type `%T' as a default value for a " | |
1953 | "template template-parameter", t); | |
1954 | else | |
1955 | error ("invalid use of `%D' as a default value for a template " | |
1956 | "template-parameter", argument); | |
1957 | } | |
1958 | else | |
1959 | error ("invalid default argument for a template template parameter"); | |
8ba658ee MM |
1960 | return error_mark_node; |
1961 | } | |
1962 | ||
1963 | return argument; | |
1964 | } | |
1965 | ||
ce4a0391 | 1966 | /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is |
838dfd8a | 1967 | nonzero, the parameter list was terminated by a `...'. */ |
ce4a0391 MM |
1968 | |
1969 | tree | |
3a978d72 | 1970 | finish_parmlist (tree parms, int ellipsis) |
ce4a0391 | 1971 | { |
5cce22b6 NS |
1972 | if (parms) |
1973 | { | |
1974 | /* We mark the PARMS as a parmlist so that declarator processing can | |
1975 | disambiguate certain constructs. */ | |
1976 | TREE_PARMLIST (parms) = 1; | |
1977 | /* We do not append void_list_node here, but leave it to grokparms | |
1978 | to do that. */ | |
1979 | PARMLIST_ELLIPSIS_P (parms) = ellipsis; | |
1980 | } | |
ce4a0391 MM |
1981 | return parms; |
1982 | } | |
1983 | ||
1984 | /* Begin a class definition, as indicated by T. */ | |
1985 | ||
1986 | tree | |
3a978d72 | 1987 | begin_class_definition (tree t) |
ce4a0391 | 1988 | { |
7437519c ZW |
1989 | if (t == error_mark_node) |
1990 | return error_mark_node; | |
1991 | ||
522d6614 NS |
1992 | if (processing_template_parmlist) |
1993 | { | |
33bd39a2 | 1994 | error ("definition of `%#T' inside template parameter list", t); |
522d6614 NS |
1995 | return error_mark_node; |
1996 | } | |
47ee8904 MM |
1997 | /* A non-implicit typename comes from code like: |
1998 | ||
1999 | template <typename T> struct A { | |
2000 | template <typename U> struct A<T>::B ... | |
2001 | ||
2002 | This is erroneous. */ | |
2003 | else if (TREE_CODE (t) == TYPENAME_TYPE) | |
2004 | { | |
33bd39a2 | 2005 | error ("invalid definition of qualified type `%T'", t); |
47ee8904 MM |
2006 | t = error_mark_node; |
2007 | } | |
2008 | ||
2009 | if (t == error_mark_node || ! IS_AGGR_TYPE (t)) | |
ce4a0391 | 2010 | { |
33848bb0 | 2011 | t = make_aggr_type (RECORD_TYPE); |
ce4a0391 MM |
2012 | pushtag (make_anon_name (), t, 0); |
2013 | } | |
830fcda8 | 2014 | |
4c571114 MM |
2015 | /* If this type was already complete, and we see another definition, |
2016 | that's an error. */ | |
8fbc5ae7 | 2017 | if (COMPLETE_TYPE_P (t)) |
4223f82f MM |
2018 | { |
2019 | error ("redefinition of `%#T'", t); | |
2020 | cp_error_at ("previous definition of `%#T'", t); | |
2021 | return error_mark_node; | |
2022 | } | |
4c571114 | 2023 | |
b4f70b3d | 2024 | /* Update the location of the decl. */ |
f31686a3 | 2025 | DECL_SOURCE_LOCATION (TYPE_NAME (t)) = input_location; |
b4f70b3d | 2026 | |
4c571114 | 2027 | if (TYPE_BEING_DEFINED (t)) |
ce4a0391 | 2028 | { |
33848bb0 | 2029 | t = make_aggr_type (TREE_CODE (t)); |
ce4a0391 | 2030 | pushtag (TYPE_IDENTIFIER (t), t, 0); |
ce4a0391 | 2031 | } |
ff350acd | 2032 | maybe_process_partial_specialization (t); |
29370796 | 2033 | pushclass (t); |
ce4a0391 | 2034 | TYPE_BEING_DEFINED (t) = 1; |
c0694c4b MM |
2035 | if (flag_pack_struct) |
2036 | { | |
2037 | tree v; | |
2038 | TYPE_PACKED (t) = 1; | |
2039 | /* Even though the type is being defined for the first time | |
2040 | here, there might have been a forward declaration, so there | |
2041 | might be cv-qualified variants of T. */ | |
2042 | for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v)) | |
2043 | TYPE_PACKED (v) = 1; | |
2044 | } | |
ce4a0391 MM |
2045 | /* Reset the interface data, at the earliest possible |
2046 | moment, as it might have been set via a class foo; | |
2047 | before. */ | |
1951a1b6 JM |
2048 | if (! TYPE_ANONYMOUS_P (t)) |
2049 | { | |
2050 | CLASSTYPE_INTERFACE_ONLY (t) = interface_only; | |
2051 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X | |
2052 | (t, interface_unknown); | |
2053 | } | |
ce4a0391 MM |
2054 | reset_specialization(); |
2055 | ||
b7975aed MM |
2056 | /* Make a declaration for this class in its own scope. */ |
2057 | build_self_reference (); | |
2058 | ||
830fcda8 | 2059 | return t; |
ce4a0391 MM |
2060 | } |
2061 | ||
61a127b3 MM |
2062 | /* Finish the member declaration given by DECL. */ |
2063 | ||
2064 | void | |
3a978d72 | 2065 | finish_member_declaration (tree decl) |
61a127b3 MM |
2066 | { |
2067 | if (decl == error_mark_node || decl == NULL_TREE) | |
2068 | return; | |
2069 | ||
2070 | if (decl == void_type_node) | |
2071 | /* The COMPONENT was a friend, not a member, and so there's | |
2072 | nothing for us to do. */ | |
2073 | return; | |
2074 | ||
2075 | /* We should see only one DECL at a time. */ | |
2076 | my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0); | |
2077 | ||
2078 | /* Set up access control for DECL. */ | |
2079 | TREE_PRIVATE (decl) | |
2080 | = (current_access_specifier == access_private_node); | |
2081 | TREE_PROTECTED (decl) | |
2082 | = (current_access_specifier == access_protected_node); | |
2083 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
2084 | { | |
17aec3eb RK |
2085 | TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl); |
2086 | TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl); | |
61a127b3 MM |
2087 | } |
2088 | ||
2089 | /* Mark the DECL as a member of the current class. */ | |
4f1c5b7d | 2090 | DECL_CONTEXT (decl) = current_class_type; |
61a127b3 | 2091 | |
421844e7 MM |
2092 | /* [dcl.link] |
2093 | ||
2094 | A C language linkage is ignored for the names of class members | |
2095 | and the member function type of class member functions. */ | |
2096 | if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c) | |
5d2ed28c | 2097 | SET_DECL_LANGUAGE (decl, lang_cplusplus); |
421844e7 | 2098 | |
61a127b3 MM |
2099 | /* Put functions on the TYPE_METHODS list and everything else on the |
2100 | TYPE_FIELDS list. Note that these are built up in reverse order. | |
2101 | We reverse them (to obtain declaration order) in finish_struct. */ | |
2102 | if (TREE_CODE (decl) == FUNCTION_DECL | |
2103 | || DECL_FUNCTION_TEMPLATE_P (decl)) | |
2104 | { | |
2105 | /* We also need to add this function to the | |
2106 | CLASSTYPE_METHOD_VEC. */ | |
452a394b | 2107 | add_method (current_class_type, decl, /*error_p=*/0); |
61a127b3 MM |
2108 | |
2109 | TREE_CHAIN (decl) = TYPE_METHODS (current_class_type); | |
2110 | TYPE_METHODS (current_class_type) = decl; | |
f139561c MM |
2111 | |
2112 | maybe_add_class_template_decl_list (current_class_type, decl, | |
2113 | /*friend_p=*/0); | |
61a127b3 | 2114 | } |
f139561c | 2115 | /* Enter the DECL into the scope of the class. */ |
fd9aef9d | 2116 | else if ((TREE_CODE (decl) == USING_DECL && TREE_TYPE (decl)) |
399dedb9 | 2117 | || pushdecl_class_level (decl)) |
61a127b3 MM |
2118 | { |
2119 | /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields | |
2120 | go at the beginning. The reason is that lookup_field_1 | |
2121 | searches the list in order, and we want a field name to | |
2122 | override a type name so that the "struct stat hack" will | |
2123 | work. In particular: | |
2124 | ||
2125 | struct S { enum E { }; int E } s; | |
2126 | s.E = 3; | |
2127 | ||
0e339752 | 2128 | is valid. In addition, the FIELD_DECLs must be maintained in |
61a127b3 MM |
2129 | declaration order so that class layout works as expected. |
2130 | However, we don't need that order until class layout, so we | |
2131 | save a little time by putting FIELD_DECLs on in reverse order | |
2132 | here, and then reversing them in finish_struct_1. (We could | |
2133 | also keep a pointer to the correct insertion points in the | |
2134 | list.) */ | |
2135 | ||
2136 | if (TREE_CODE (decl) == TYPE_DECL) | |
2137 | TYPE_FIELDS (current_class_type) | |
2138 | = chainon (TYPE_FIELDS (current_class_type), decl); | |
2139 | else | |
2140 | { | |
2141 | TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type); | |
2142 | TYPE_FIELDS (current_class_type) = decl; | |
2143 | } | |
8f032717 | 2144 | |
f139561c MM |
2145 | maybe_add_class_template_decl_list (current_class_type, decl, |
2146 | /*friend_p=*/0); | |
61a127b3 MM |
2147 | } |
2148 | } | |
2149 | ||
35acd3f2 MM |
2150 | /* Finish processing the declaration of a member class template |
2151 | TYPES whose template parameters are given by PARMS. */ | |
2152 | ||
2153 | tree | |
3a978d72 | 2154 | finish_member_class_template (tree types) |
35acd3f2 | 2155 | { |
36a117a5 MM |
2156 | tree t; |
2157 | ||
2158 | /* If there are declared, but undefined, partial specializations | |
2159 | mixed in with the typespecs they will not yet have passed through | |
2160 | maybe_process_partial_specialization, so we do that here. */ | |
2161 | for (t = types; t != NULL_TREE; t = TREE_CHAIN (t)) | |
2162 | if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t)))) | |
2163 | maybe_process_partial_specialization (TREE_VALUE (t)); | |
2164 | ||
61a127b3 | 2165 | grok_x_components (types); |
35acd3f2 MM |
2166 | if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type) |
2167 | /* The component was in fact a friend declaration. We avoid | |
2168 | finish_member_template_decl performing certain checks by | |
2169 | unsetting TYPES. */ | |
2170 | types = NULL_TREE; | |
61a127b3 MM |
2171 | |
2172 | finish_member_template_decl (types); | |
2173 | ||
35acd3f2 MM |
2174 | /* As with other component type declarations, we do |
2175 | not store the new DECL on the list of | |
2176 | component_decls. */ | |
2177 | return NULL_TREE; | |
2178 | } | |
36a117a5 | 2179 | |
306ef644 | 2180 | /* Finish processing a complete template declaration. The PARMS are |
36a117a5 MM |
2181 | the template parameters. */ |
2182 | ||
2183 | void | |
3a978d72 | 2184 | finish_template_decl (tree parms) |
36a117a5 MM |
2185 | { |
2186 | if (parms) | |
2187 | end_template_decl (); | |
2188 | else | |
2189 | end_specialization (); | |
2190 | } | |
2191 | ||
509fc277 | 2192 | /* Finish processing a template-id (which names a type) of the form |
36a117a5 | 2193 | NAME < ARGS >. Return the TYPE_DECL for the type named by the |
838dfd8a | 2194 | template-id. If ENTERING_SCOPE is nonzero we are about to enter |
36a117a5 MM |
2195 | the scope of template-id indicated. */ |
2196 | ||
2197 | tree | |
3a978d72 | 2198 | finish_template_type (tree name, tree args, int entering_scope) |
36a117a5 MM |
2199 | { |
2200 | tree decl; | |
2201 | ||
2202 | decl = lookup_template_class (name, args, | |
42eaed49 NS |
2203 | NULL_TREE, NULL_TREE, entering_scope, |
2204 | tf_error | tf_warning | tf_user); | |
36a117a5 MM |
2205 | if (decl != error_mark_node) |
2206 | decl = TYPE_STUB_DECL (decl); | |
2207 | ||
2208 | return decl; | |
2209 | } | |
648f19f6 | 2210 | |
ea6021e8 MM |
2211 | /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. |
2212 | Return a TREE_LIST containing the ACCESS_SPECIFIER and the | |
2213 | BASE_CLASS, or NULL_TREE if an error occurred. The | |
aba649ba | 2214 | ACCESS_SPECIFIER is one of |
ea6021e8 MM |
2215 | access_{default,public,protected_private}[_virtual]_node.*/ |
2216 | ||
2217 | tree | |
dbbf88d1 | 2218 | finish_base_specifier (tree base, tree access, bool virtual_p) |
ea6021e8 | 2219 | { |
ea6021e8 MM |
2220 | tree result; |
2221 | ||
dbbf88d1 | 2222 | if (base == error_mark_node) |
acb044ee GDR |
2223 | { |
2224 | error ("invalid base-class specification"); | |
2225 | result = NULL_TREE; | |
2226 | } | |
dbbf88d1 | 2227 | else if (! is_aggr_type (base, 1)) |
ea6021e8 | 2228 | result = NULL_TREE; |
ea6021e8 | 2229 | else |
bb92901d | 2230 | { |
dbbf88d1 | 2231 | if (cp_type_quals (base) != 0) |
bb92901d | 2232 | { |
dbbf88d1 NS |
2233 | error ("base class `%T' has cv qualifiers", base); |
2234 | base = TYPE_MAIN_VARIANT (base); | |
bb92901d | 2235 | } |
dbbf88d1 NS |
2236 | result = build_tree_list (access, base); |
2237 | TREE_VIA_VIRTUAL (result) = virtual_p; | |
bb92901d | 2238 | } |
ea6021e8 MM |
2239 | |
2240 | return result; | |
2241 | } | |
61a127b3 MM |
2242 | |
2243 | /* Called when multiple declarators are processed. If that is not | |
cd0be382 | 2244 | permitted in this context, an error is issued. */ |
61a127b3 MM |
2245 | |
2246 | void | |
3a978d72 | 2247 | check_multiple_declarators (void) |
61a127b3 MM |
2248 | { |
2249 | /* [temp] | |
2250 | ||
2251 | In a template-declaration, explicit specialization, or explicit | |
2252 | instantiation the init-declarator-list in the declaration shall | |
2253 | contain at most one declarator. | |
2254 | ||
2255 | We don't just use PROCESSING_TEMPLATE_DECL for the first | |
0e339752 | 2256 | condition since that would disallow the perfectly valid code, |
61a127b3 | 2257 | like `template <class T> struct S { int i, j; };'. */ |
5f261ba9 | 2258 | if (at_function_scope_p ()) |
61a127b3 MM |
2259 | /* It's OK to write `template <class T> void f() { int i, j;}'. */ |
2260 | return; | |
2261 | ||
2262 | if (PROCESSING_REAL_TEMPLATE_DECL_P () | |
2263 | || processing_explicit_instantiation | |
2264 | || processing_specialization) | |
33bd39a2 | 2265 | error ("multiple declarators in template declaration"); |
61a127b3 MM |
2266 | } |
2267 | ||
22038b2c NS |
2268 | /* Issue a diagnostic that NAME cannot be found in SCOPE. */ |
2269 | ||
2270 | void | |
2271 | qualified_name_lookup_error (tree scope, tree name) | |
2272 | { | |
2273 | if (TYPE_P (scope)) | |
2274 | { | |
2275 | if (!COMPLETE_TYPE_P (scope)) | |
2276 | error ("incomplete type `%T' used in nested name specifier", scope); | |
2277 | else | |
2278 | error ("`%D' is not a member of `%T'", name, scope); | |
2279 | } | |
2280 | else if (scope != global_namespace) | |
2281 | error ("`%D' is not a member of `%D'", name, scope); | |
2282 | else | |
2283 | error ("`::%D' has not been declared", name); | |
2284 | } | |
2285 | ||
b3445994 MM |
2286 | /* ID_EXPRESSION is a representation of parsed, but unprocessed, |
2287 | id-expression. (See cp_parser_id_expression for details.) SCOPE, | |
2288 | if non-NULL, is the type or namespace used to explicitly qualify | |
2289 | ID_EXPRESSION. DECL is the entity to which that name has been | |
2290 | resolved. | |
2291 | ||
2292 | *CONSTANT_EXPRESSION_P is true if we are presently parsing a | |
2293 | constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will | |
2294 | be set to true if this expression isn't permitted in a | |
2295 | constant-expression, but it is otherwise not set by this function. | |
2296 | *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a | |
2297 | constant-expression, but a non-constant expression is also | |
2298 | permissible. | |
2299 | ||
2300 | If an error occurs, and it is the kind of error that might cause | |
2301 | the parser to abort a tentative parse, *ERROR_MSG is filled in. It | |
2302 | is the caller's responsibility to issue the message. *ERROR_MSG | |
2303 | will be a string with static storage duration, so the caller need | |
2304 | not "free" it. | |
2305 | ||
2306 | Return an expression for the entity, after issuing appropriate | |
2307 | diagnostics. This function is also responsible for transforming a | |
2308 | reference to a non-static member into a COMPONENT_REF that makes | |
2309 | the use of "this" explicit. | |
2310 | ||
2311 | Upon return, *IDK will be filled in appropriately. */ | |
2312 | ||
2313 | tree | |
2314 | finish_id_expression (tree id_expression, | |
2315 | tree decl, | |
2316 | tree scope, | |
2317 | cp_id_kind *idk, | |
2318 | tree *qualifying_class, | |
67c03833 JM |
2319 | bool integral_constant_expression_p, |
2320 | bool allow_non_integral_constant_expression_p, | |
2321 | bool *non_integral_constant_expression_p, | |
b3445994 MM |
2322 | const char **error_msg) |
2323 | { | |
2324 | /* Initialize the output parameters. */ | |
2325 | *idk = CP_ID_KIND_NONE; | |
2326 | *error_msg = NULL; | |
2327 | ||
2328 | if (id_expression == error_mark_node) | |
2329 | return error_mark_node; | |
2330 | /* If we have a template-id, then no further lookup is | |
2331 | required. If the template-id was for a template-class, we | |
2332 | will sometimes have a TYPE_DECL at this point. */ | |
2333 | else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
ee935db4 | 2334 | || TREE_CODE (decl) == TYPE_DECL) |
b3445994 MM |
2335 | ; |
2336 | /* Look up the name. */ | |
2337 | else | |
2338 | { | |
2339 | if (decl == error_mark_node) | |
2340 | { | |
2341 | /* Name lookup failed. */ | |
4546865e MM |
2342 | if (scope |
2343 | && (!TYPE_P (scope) | |
2344 | || (!dependent_type_p (scope) | |
2345 | && !(TREE_CODE (id_expression) == IDENTIFIER_NODE | |
2346 | && IDENTIFIER_TYPENAME_P (id_expression) | |
2347 | && dependent_type_p (TREE_TYPE (id_expression)))))) | |
b3445994 | 2348 | { |
4546865e MM |
2349 | /* If the qualifying type is non-dependent (and the name |
2350 | does not name a conversion operator to a dependent | |
2351 | type), issue an error. */ | |
22038b2c | 2352 | qualified_name_lookup_error (scope, id_expression); |
b3445994 MM |
2353 | return error_mark_node; |
2354 | } | |
2355 | else if (!scope) | |
2356 | { | |
2357 | /* It may be resolved via Koenig lookup. */ | |
2358 | *idk = CP_ID_KIND_UNQUALIFIED; | |
2359 | return id_expression; | |
2360 | } | |
4546865e MM |
2361 | else |
2362 | decl = id_expression; | |
b3445994 MM |
2363 | } |
2364 | /* If DECL is a variable that would be out of scope under | |
2365 | ANSI/ISO rules, but in scope in the ARM, name lookup | |
2366 | will succeed. Issue a diagnostic here. */ | |
2367 | else | |
2368 | decl = check_for_out_of_scope_variable (decl); | |
2369 | ||
2370 | /* Remember that the name was used in the definition of | |
2371 | the current class so that we can check later to see if | |
2372 | the meaning would have been different after the class | |
2373 | was entirely defined. */ | |
2374 | if (!scope && decl != error_mark_node) | |
2375 | maybe_note_name_used_in_class (id_expression, decl); | |
2376 | } | |
2377 | ||
2378 | /* If we didn't find anything, or what we found was a type, | |
2379 | then this wasn't really an id-expression. */ | |
2380 | if (TREE_CODE (decl) == TEMPLATE_DECL | |
2381 | && !DECL_FUNCTION_TEMPLATE_P (decl)) | |
2382 | { | |
2383 | *error_msg = "missing template arguments"; | |
2384 | return error_mark_node; | |
2385 | } | |
2386 | else if (TREE_CODE (decl) == TYPE_DECL | |
2387 | || TREE_CODE (decl) == NAMESPACE_DECL) | |
2388 | { | |
2389 | *error_msg = "expected primary-expression"; | |
2390 | return error_mark_node; | |
2391 | } | |
2392 | ||
2393 | /* If the name resolved to a template parameter, there is no | |
931a9c05 GB |
2394 | need to look it up again later. */ |
2395 | if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl)) | |
2396 | || TREE_CODE (decl) == TEMPLATE_PARM_INDEX) | |
b3445994 MM |
2397 | { |
2398 | *idk = CP_ID_KIND_NONE; | |
931a9c05 GB |
2399 | if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX) |
2400 | decl = TEMPLATE_PARM_DECL (decl); | |
67c03833 | 2401 | if (integral_constant_expression_p |
68deab91 | 2402 | && !dependent_type_p (TREE_TYPE (decl)) |
931a9c05 GB |
2403 | && !INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl))) |
2404 | { | |
67c03833 | 2405 | if (!allow_non_integral_constant_expression_p) |
931a9c05 GB |
2406 | error ("template parameter `%D' of type `%T' is not allowed in " |
2407 | "an integral constant expression because it is not of " | |
2408 | "integral or enumeration type", decl, TREE_TYPE (decl)); | |
67c03833 | 2409 | *non_integral_constant_expression_p = true; |
931a9c05 GB |
2410 | } |
2411 | return DECL_INITIAL (decl); | |
2412 | } | |
2413 | /* Similarly, we resolve enumeration constants to their | |
2414 | underlying values. */ | |
2415 | else if (TREE_CODE (decl) == CONST_DECL) | |
2416 | { | |
2417 | *idk = CP_ID_KIND_NONE; | |
2418 | if (!processing_template_decl) | |
b3445994 MM |
2419 | return DECL_INITIAL (decl); |
2420 | return decl; | |
2421 | } | |
2422 | else | |
2423 | { | |
2424 | bool dependent_p; | |
2425 | ||
2426 | /* If the declaration was explicitly qualified indicate | |
2427 | that. The semantics of `A::f(3)' are different than | |
2428 | `f(3)' if `f' is virtual. */ | |
2429 | *idk = (scope | |
2430 | ? CP_ID_KIND_QUALIFIED | |
2431 | : (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
2432 | ? CP_ID_KIND_TEMPLATE_ID | |
2433 | : CP_ID_KIND_UNQUALIFIED)); | |
2434 | ||
2435 | ||
2436 | /* [temp.dep.expr] | |
2437 | ||
2438 | An id-expression is type-dependent if it contains an | |
2439 | identifier that was declared with a dependent type. | |
2440 | ||
b3445994 MM |
2441 | The standard is not very specific about an id-expression that |
2442 | names a set of overloaded functions. What if some of them | |
2443 | have dependent types and some of them do not? Presumably, | |
2444 | such a name should be treated as a dependent name. */ | |
2445 | /* Assume the name is not dependent. */ | |
2446 | dependent_p = false; | |
2447 | if (!processing_template_decl) | |
2448 | /* No names are dependent outside a template. */ | |
2449 | ; | |
2450 | /* A template-id where the name of the template was not resolved | |
2451 | is definitely dependent. */ | |
2452 | else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
2453 | && (TREE_CODE (TREE_OPERAND (decl, 0)) | |
2454 | == IDENTIFIER_NODE)) | |
2455 | dependent_p = true; | |
2456 | /* For anything except an overloaded function, just check its | |
2457 | type. */ | |
2458 | else if (!is_overloaded_fn (decl)) | |
2459 | dependent_p | |
2460 | = dependent_type_p (TREE_TYPE (decl)); | |
2461 | /* For a set of overloaded functions, check each of the | |
2462 | functions. */ | |
2463 | else | |
2464 | { | |
2465 | tree fns = decl; | |
2466 | ||
2467 | if (BASELINK_P (fns)) | |
2468 | fns = BASELINK_FUNCTIONS (fns); | |
2469 | ||
2470 | /* For a template-id, check to see if the template | |
2471 | arguments are dependent. */ | |
2472 | if (TREE_CODE (fns) == TEMPLATE_ID_EXPR) | |
2473 | { | |
2474 | tree args = TREE_OPERAND (fns, 1); | |
2475 | dependent_p = any_dependent_template_arguments_p (args); | |
2476 | /* The functions are those referred to by the | |
2477 | template-id. */ | |
2478 | fns = TREE_OPERAND (fns, 0); | |
2479 | } | |
2480 | ||
2481 | /* If there are no dependent template arguments, go through | |
cd0be382 | 2482 | the overloaded functions. */ |
b3445994 MM |
2483 | while (fns && !dependent_p) |
2484 | { | |
2485 | tree fn = OVL_CURRENT (fns); | |
2486 | ||
2487 | /* Member functions of dependent classes are | |
2488 | dependent. */ | |
2489 | if (TREE_CODE (fn) == FUNCTION_DECL | |
2490 | && type_dependent_expression_p (fn)) | |
2491 | dependent_p = true; | |
2492 | else if (TREE_CODE (fn) == TEMPLATE_DECL | |
2493 | && dependent_template_p (fn)) | |
2494 | dependent_p = true; | |
2495 | ||
2496 | fns = OVL_NEXT (fns); | |
2497 | } | |
2498 | } | |
2499 | ||
2500 | /* If the name was dependent on a template parameter, we will | |
2501 | resolve the name at instantiation time. */ | |
2502 | if (dependent_p) | |
2503 | { | |
2504 | /* Create a SCOPE_REF for qualified names, if the scope is | |
2505 | dependent. */ | |
2506 | if (scope) | |
2507 | { | |
2508 | if (TYPE_P (scope)) | |
2509 | *qualifying_class = scope; | |
2510 | /* Since this name was dependent, the expression isn't | |
2511 | constant -- yet. No error is issued because it might | |
2512 | be constant when things are instantiated. */ | |
67c03833 JM |
2513 | if (integral_constant_expression_p) |
2514 | *non_integral_constant_expression_p = true; | |
b3445994 MM |
2515 | if (TYPE_P (scope) && dependent_type_p (scope)) |
2516 | return build_nt (SCOPE_REF, scope, id_expression); | |
2517 | else if (TYPE_P (scope) && DECL_P (decl)) | |
2518 | return build (SCOPE_REF, TREE_TYPE (decl), scope, | |
2519 | id_expression); | |
2520 | else | |
2521 | return decl; | |
2522 | } | |
2523 | /* A TEMPLATE_ID already contains all the information we | |
2524 | need. */ | |
2525 | if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR) | |
2526 | return id_expression; | |
2527 | /* Since this name was dependent, the expression isn't | |
2528 | constant -- yet. No error is issued because it might be | |
2529 | constant when things are instantiated. */ | |
67c03833 JM |
2530 | if (integral_constant_expression_p) |
2531 | *non_integral_constant_expression_p = true; | |
10b1d5e7 | 2532 | *idk = CP_ID_KIND_UNQUALIFIED_DEPENDENT; |
5a98fa7b MM |
2533 | /* If we found a variable, then name lookup during the |
2534 | instantiation will always resolve to the same VAR_DECL | |
2535 | (or an instantiation thereof). */ | |
3c398f34 MM |
2536 | if (TREE_CODE (decl) == VAR_DECL |
2537 | || TREE_CODE (decl) == PARM_DECL) | |
5a98fa7b | 2538 | return decl; |
10b1d5e7 | 2539 | return id_expression; |
b3445994 MM |
2540 | } |
2541 | ||
2542 | /* Only certain kinds of names are allowed in constant | |
931a9c05 GB |
2543 | expression. Enumerators and template parameters |
2544 | have already been handled above. */ | |
67c03833 | 2545 | if (integral_constant_expression_p) |
b3445994 | 2546 | { |
931a9c05 GB |
2547 | /* Const variables or static data members of integral or |
2548 | enumeration types initialized with constant expressions | |
2549 | are OK. */ | |
2550 | if (TREE_CODE (decl) == VAR_DECL | |
2551 | && CP_TYPE_CONST_P (TREE_TYPE (decl)) | |
2552 | && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)) | |
2553 | && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)) | |
b3445994 MM |
2554 | ; |
2555 | else | |
2556 | { | |
67c03833 | 2557 | if (!allow_non_integral_constant_expression_p) |
b3445994 MM |
2558 | { |
2559 | error ("`%D' cannot appear in a constant-expression", decl); | |
2560 | return error_mark_node; | |
2561 | } | |
67c03833 | 2562 | *non_integral_constant_expression_p = true; |
b3445994 MM |
2563 | } |
2564 | } | |
415d4636 MM |
2565 | |
2566 | if (TREE_CODE (decl) == NAMESPACE_DECL) | |
9e95d15f NS |
2567 | { |
2568 | error ("use of namespace `%D' as expression", decl); | |
2569 | return error_mark_node; | |
2570 | } | |
2571 | else if (DECL_CLASS_TEMPLATE_P (decl)) | |
2572 | { | |
2573 | error ("use of class template `%T' as expression", decl); | |
2574 | return error_mark_node; | |
2575 | } | |
2576 | else if (TREE_CODE (decl) == TREE_LIST) | |
2577 | { | |
2578 | /* Ambiguous reference to base members. */ | |
2579 | error ("request for member `%D' is ambiguous in " | |
2580 | "multiple inheritance lattice", id_expression); | |
2581 | print_candidates (decl); | |
2582 | return error_mark_node; | |
2583 | } | |
415d4636 MM |
2584 | |
2585 | /* Mark variable-like entities as used. Functions are similarly | |
2586 | marked either below or after overload resolution. */ | |
2587 | if (TREE_CODE (decl) == VAR_DECL | |
2588 | || TREE_CODE (decl) == PARM_DECL | |
2589 | || TREE_CODE (decl) == RESULT_DECL) | |
2590 | mark_used (decl); | |
2591 | ||
2592 | if (scope) | |
2593 | { | |
2594 | decl = (adjust_result_of_qualified_name_lookup | |
2595 | (decl, scope, current_class_type)); | |
e20bcc5e JH |
2596 | |
2597 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
2598 | mark_used (decl); | |
2599 | ||
415d4636 MM |
2600 | if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl)) |
2601 | *qualifying_class = scope; | |
2602 | else if (!processing_template_decl) | |
2603 | decl = convert_from_reference (decl); | |
2604 | else if (TYPE_P (scope)) | |
2605 | decl = build (SCOPE_REF, TREE_TYPE (decl), scope, decl); | |
2606 | } | |
9e95d15f NS |
2607 | else if (TREE_CODE (decl) == FIELD_DECL) |
2608 | decl = finish_non_static_data_member (decl, current_class_ref, | |
2609 | /*qualifying_scope=*/NULL_TREE); | |
2610 | else if (is_overloaded_fn (decl)) | |
2611 | { | |
2612 | tree first_fn = OVL_CURRENT (decl); | |
b3445994 | 2613 | |
9e95d15f NS |
2614 | if (TREE_CODE (first_fn) == TEMPLATE_DECL) |
2615 | first_fn = DECL_TEMPLATE_RESULT (first_fn); | |
415d4636 MM |
2616 | |
2617 | if (!really_overloaded_fn (decl)) | |
2618 | mark_used (first_fn); | |
2619 | ||
9e95d15f NS |
2620 | if (TREE_CODE (first_fn) == FUNCTION_DECL |
2621 | && DECL_FUNCTION_MEMBER_P (first_fn)) | |
2622 | { | |
2623 | /* A set of member functions. */ | |
2624 | decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0); | |
2625 | return finish_class_member_access_expr (decl, id_expression); | |
2626 | } | |
9e95d15f NS |
2627 | } |
2628 | else | |
2629 | { | |
2630 | if (TREE_CODE (decl) == VAR_DECL | |
2631 | || TREE_CODE (decl) == PARM_DECL | |
2632 | || TREE_CODE (decl) == RESULT_DECL) | |
2633 | { | |
2634 | tree context = decl_function_context (decl); | |
2635 | ||
2636 | if (context != NULL_TREE && context != current_function_decl | |
2637 | && ! TREE_STATIC (decl)) | |
2638 | { | |
2639 | error ("use of %s from containing function", | |
2640 | (TREE_CODE (decl) == VAR_DECL | |
2641 | ? "`auto' variable" : "parameter")); | |
2642 | cp_error_at (" `%#D' declared here", decl); | |
2643 | return error_mark_node; | |
2644 | } | |
2645 | } | |
2646 | ||
2647 | if (DECL_P (decl) && DECL_NONLOCAL (decl) | |
2648 | && DECL_CLASS_SCOPE_P (decl) | |
2649 | && DECL_CONTEXT (decl) != current_class_type) | |
2650 | { | |
2651 | tree path; | |
2652 | ||
2653 | path = currently_open_derived_class (DECL_CONTEXT (decl)); | |
2654 | perform_or_defer_access_check (TYPE_BINFO (path), decl); | |
2655 | } | |
2656 | ||
9e95d15f NS |
2657 | if (! processing_template_decl) |
2658 | decl = convert_from_reference (decl); | |
2659 | } | |
2660 | ||
b3445994 MM |
2661 | /* Resolve references to variables of anonymous unions |
2662 | into COMPONENT_REFs. */ | |
2663 | if (TREE_CODE (decl) == ALIAS_DECL) | |
6de9cd9a | 2664 | decl = unshare_expr (DECL_INITIAL (decl)); |
b3445994 MM |
2665 | } |
2666 | ||
2667 | if (TREE_DEPRECATED (decl)) | |
2668 | warn_deprecated_use (decl); | |
2669 | ||
2670 | return decl; | |
2671 | } | |
2672 | ||
0213a355 JM |
2673 | /* Implement the __typeof keyword: Return the type of EXPR, suitable for |
2674 | use as a type-specifier. */ | |
2675 | ||
b894fc05 | 2676 | tree |
3a978d72 | 2677 | finish_typeof (tree expr) |
b894fc05 | 2678 | { |
65a5559b MM |
2679 | tree type; |
2680 | ||
dffbbe80 | 2681 | if (type_dependent_expression_p (expr)) |
b894fc05 | 2682 | { |
65a5559b | 2683 | type = make_aggr_type (TYPEOF_TYPE); |
eb34af89 | 2684 | TYPEOF_TYPE_EXPR (type) = expr; |
b894fc05 | 2685 | |
65a5559b | 2686 | return type; |
b894fc05 JM |
2687 | } |
2688 | ||
65a5559b MM |
2689 | type = TREE_TYPE (expr); |
2690 | ||
2691 | if (!type || type == unknown_type_node) | |
2692 | { | |
2693 | error ("type of `%E' is unknown", expr); | |
2694 | return error_mark_node; | |
2695 | } | |
2696 | ||
2697 | return type; | |
b894fc05 | 2698 | } |
558475f0 | 2699 | |
3eb24f73 | 2700 | /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs |
6de9cd9a | 2701 | with equivalent CALL_EXPRs. */ |
3eb24f73 MM |
2702 | |
2703 | static tree | |
3a978d72 | 2704 | simplify_aggr_init_exprs_r (tree* tp, |
9eeb200f JM |
2705 | int* walk_subtrees, |
2706 | void* data ATTRIBUTE_UNUSED) | |
3eb24f73 | 2707 | { |
22e92ac3 MM |
2708 | /* We don't need to walk into types; there's nothing in a type that |
2709 | needs simplification. (And, furthermore, there are places we | |
2710 | actively don't want to go. For example, we don't want to wander | |
2711 | into the default arguments for a FUNCTION_DECL that appears in a | |
2712 | CALL_EXPR.) */ | |
9eeb200f | 2713 | if (TYPE_P (*tp)) |
22e92ac3 MM |
2714 | { |
2715 | *walk_subtrees = 0; | |
2716 | return NULL_TREE; | |
2717 | } | |
2718 | /* Only AGGR_INIT_EXPRs are interesting. */ | |
9eeb200f | 2719 | else if (TREE_CODE (*tp) != AGGR_INIT_EXPR) |
3eb24f73 MM |
2720 | return NULL_TREE; |
2721 | ||
9eeb200f JM |
2722 | simplify_aggr_init_expr (tp); |
2723 | ||
2724 | /* Keep iterating. */ | |
2725 | return NULL_TREE; | |
2726 | } | |
2727 | ||
2728 | /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This | |
2729 | function is broken out from the above for the benefit of the tree-ssa | |
2730 | project. */ | |
2731 | ||
2732 | void | |
2733 | simplify_aggr_init_expr (tree *tp) | |
2734 | { | |
2735 | tree aggr_init_expr = *tp; | |
2736 | ||
3eb24f73 | 2737 | /* Form an appropriate CALL_EXPR. */ |
9eeb200f JM |
2738 | tree fn = TREE_OPERAND (aggr_init_expr, 0); |
2739 | tree args = TREE_OPERAND (aggr_init_expr, 1); | |
2740 | tree slot = TREE_OPERAND (aggr_init_expr, 2); | |
2692eb7d | 2741 | tree type = TREE_TYPE (slot); |
9eeb200f JM |
2742 | |
2743 | tree call_expr; | |
2744 | enum style_t { ctor, arg, pcc } style; | |
4977bab6 | 2745 | |
3eb24f73 | 2746 | if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr)) |
4977bab6 ZW |
2747 | style = ctor; |
2748 | #ifdef PCC_STATIC_STRUCT_RETURN | |
2749 | else if (1) | |
2750 | style = pcc; | |
2751 | #endif | |
2752 | else if (TREE_ADDRESSABLE (type)) | |
2753 | style = arg; | |
2754 | else | |
2755 | /* We shouldn't build an AGGR_INIT_EXPR if we don't need any special | |
2756 | handling. See build_cplus_new. */ | |
2757 | abort (); | |
2758 | ||
2759 | if (style == ctor || style == arg) | |
3eb24f73 | 2760 | { |
4977bab6 ZW |
2761 | /* Pass the address of the slot. If this is a constructor, we |
2762 | replace the first argument; otherwise, we tack on a new one. */ | |
9eeb200f JM |
2763 | tree addr; |
2764 | ||
4977bab6 ZW |
2765 | if (style == ctor) |
2766 | args = TREE_CHAIN (args); | |
2767 | ||
dffd7eb6 | 2768 | cxx_mark_addressable (slot); |
2692eb7d | 2769 | addr = build1 (ADDR_EXPR, build_pointer_type (type), slot); |
9eeb200f JM |
2770 | if (style == arg) |
2771 | { | |
2772 | /* The return type might have different cv-quals from the slot. */ | |
2773 | tree fntype = TREE_TYPE (TREE_TYPE (fn)); | |
2774 | #ifdef ENABLE_CHECKING | |
2775 | if (TREE_CODE (fntype) != FUNCTION_TYPE | |
2776 | && TREE_CODE (fntype) != METHOD_TYPE) | |
2777 | abort (); | |
2778 | #endif | |
2779 | addr = convert (build_pointer_type (TREE_TYPE (fntype)), addr); | |
2780 | } | |
2781 | ||
2782 | args = tree_cons (NULL_TREE, addr, args); | |
3eb24f73 | 2783 | } |
4977bab6 | 2784 | |
b850de4f MM |
2785 | call_expr = build (CALL_EXPR, |
2786 | TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), | |
2787 | fn, args, NULL_TREE); | |
3eb24f73 | 2788 | |
4977bab6 | 2789 | if (style == arg) |
89ea02fb JM |
2790 | /* Tell the backend that we've added our return slot to the argument |
2791 | list. */ | |
2792 | CALL_EXPR_HAS_RETURN_SLOT_ADDR (call_expr) = 1; | |
4977bab6 | 2793 | else if (style == pcc) |
3eb24f73 | 2794 | { |
4977bab6 ZW |
2795 | /* If we're using the non-reentrant PCC calling convention, then we |
2796 | need to copy the returned value out of the static buffer into the | |
2797 | SLOT. */ | |
78757caa | 2798 | push_deferring_access_checks (dk_no_check); |
46af705a JDA |
2799 | call_expr = build_aggr_init (slot, call_expr, |
2800 | DIRECT_BIND | LOOKUP_ONLYCONVERTING); | |
78757caa | 2801 | pop_deferring_access_checks (); |
3eb24f73 | 2802 | } |
3eb24f73 | 2803 | |
3eb24f73 | 2804 | *tp = call_expr; |
3eb24f73 MM |
2805 | } |
2806 | ||
31f8e4f3 MM |
2807 | /* Emit all thunks to FN that should be emitted when FN is emitted. */ |
2808 | ||
2809 | static void | |
3a978d72 | 2810 | emit_associated_thunks (tree fn) |
31f8e4f3 MM |
2811 | { |
2812 | /* When we use vcall offsets, we emit thunks with the virtual | |
2813 | functions to which they thunk. The whole point of vcall offsets | |
2814 | is so that you can know statically the entire set of thunks that | |
2815 | will ever be needed for a given virtual function, thereby | |
2816 | enabling you to output all the thunks with the function itself. */ | |
3461fba7 | 2817 | if (DECL_VIRTUAL_P (fn)) |
31f8e4f3 | 2818 | { |
bb5e8a7f | 2819 | tree thunk; |
4977bab6 | 2820 | |
bb5e8a7f | 2821 | for (thunk = DECL_THUNKS (fn); thunk; thunk = TREE_CHAIN (thunk)) |
4977bab6 | 2822 | { |
e00853fd | 2823 | if (!THUNK_ALIAS (thunk)) |
4977bab6 | 2824 | { |
bb885938 NS |
2825 | use_thunk (thunk, /*emit_p=*/1); |
2826 | if (DECL_RESULT_THUNK_P (thunk)) | |
2827 | { | |
2828 | tree probe; | |
2829 | ||
2830 | for (probe = DECL_THUNKS (thunk); | |
2831 | probe; probe = TREE_CHAIN (probe)) | |
2832 | use_thunk (probe, /*emit_p=*/1); | |
2833 | } | |
4977bab6 | 2834 | } |
bb885938 NS |
2835 | else |
2836 | my_friendly_assert (!DECL_THUNKS (thunk), 20031023); | |
4977bab6 | 2837 | } |
31f8e4f3 MM |
2838 | } |
2839 | } | |
2840 | ||
558475f0 MM |
2841 | /* Generate RTL for FN. */ |
2842 | ||
2843 | void | |
3a978d72 | 2844 | expand_body (tree fn) |
558475f0 | 2845 | { |
367aa585 | 2846 | tree saved_function; |
6de9cd9a | 2847 | |
92788413 MM |
2848 | /* Compute the appropriate object-file linkage for inline |
2849 | functions. */ | |
79065db2 | 2850 | if (DECL_DECLARED_INLINE_P (fn)) |
92788413 MM |
2851 | import_export_decl (fn); |
2852 | ||
4f8e1232 MM |
2853 | /* If FN is external, then there's no point in generating RTL for |
2854 | it. This situation can arise with an inline function under | |
83662e2b | 2855 | `-fexternal-templates'; we instantiate the function, even though |
4f8e1232 MM |
2856 | we're not planning on emitting it, in case we get a chance to |
2857 | inline it. */ | |
2858 | if (DECL_EXTERNAL (fn)) | |
2859 | return; | |
2860 | ||
4985cde3 | 2861 | /* ??? When is this needed? */ |
367aa585 | 2862 | saved_function = current_function_decl; |
367aa585 | 2863 | |
de81ffd4 JH |
2864 | /* Emit any thunks that should be emitted at the same time as FN. */ |
2865 | emit_associated_thunks (fn); | |
2866 | ||
c1f927e8 | 2867 | tree_rest_of_compilation (fn, function_depth > 1); |
d658cd4c | 2868 | |
367aa585 | 2869 | current_function_decl = saved_function; |
ea11ca7e | 2870 | |
4985cde3 | 2871 | extract_interface_info (); |
14691f8d | 2872 | |
4985cde3 RH |
2873 | /* If this function is marked with the constructor attribute, add it |
2874 | to the list of functions to be called along with constructors | |
2875 | from static duration objects. */ | |
2876 | if (DECL_STATIC_CONSTRUCTOR (fn)) | |
2877 | static_ctors = tree_cons (NULL_TREE, fn, static_ctors); | |
2878 | ||
2879 | /* If this function is marked with the destructor attribute, add it | |
2880 | to the list of functions to be called along with destructors from | |
2881 | static duration objects. */ | |
2882 | if (DECL_STATIC_DESTRUCTOR (fn)) | |
2883 | static_dtors = tree_cons (NULL_TREE, fn, static_dtors); | |
85b22f78 NS |
2884 | |
2885 | if (DECL_CLONED_FUNCTION_P (fn)) | |
2886 | { | |
2887 | /* If this is a clone, go through the other clones now and mark | |
2888 | their parameters used. We have to do that here, as we don't | |
2889 | know whether any particular clone will be expanded, and | |
2890 | therefore cannot pick one arbitrarily. */ | |
2891 | tree probe; | |
2892 | ||
2893 | for (probe = TREE_CHAIN (DECL_CLONED_FUNCTION (fn)); | |
2894 | probe && DECL_CLONED_FUNCTION_P (probe); | |
2895 | probe = TREE_CHAIN (probe)) | |
2896 | { | |
2897 | tree parms; | |
2898 | ||
2899 | for (parms = DECL_ARGUMENTS (probe); | |
2900 | parms; parms = TREE_CHAIN (parms)) | |
2901 | TREE_USED (parms) = 1; | |
2902 | } | |
2903 | } | |
558475f0 | 2904 | } |
54f7877c | 2905 | |
8cd2462c JH |
2906 | /* Generate RTL for FN. */ |
2907 | ||
2908 | void | |
5671bf27 | 2909 | expand_or_defer_fn (tree fn) |
8cd2462c JH |
2910 | { |
2911 | /* When the parser calls us after finishing the body of a template | |
c353b8e3 MM |
2912 | function, we don't really want to expand the body. */ |
2913 | if (processing_template_decl) | |
8cd2462c JH |
2914 | { |
2915 | /* Normally, collection only occurs in rest_of_compilation. So, | |
2916 | if we don't collect here, we never collect junk generated | |
2917 | during the processing of templates until we hit a | |
2918 | non-template function. */ | |
2919 | ggc_collect (); | |
2920 | return; | |
2921 | } | |
2922 | ||
2923 | /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */ | |
2924 | walk_tree_without_duplicates (&DECL_SAVED_TREE (fn), | |
2925 | simplify_aggr_init_exprs_r, | |
2926 | NULL); | |
2927 | ||
2928 | /* If this is a constructor or destructor body, we have to clone | |
2929 | it. */ | |
2930 | if (maybe_clone_body (fn)) | |
2931 | { | |
2932 | /* We don't want to process FN again, so pretend we've written | |
2933 | it out, even though we haven't. */ | |
2934 | TREE_ASM_WRITTEN (fn) = 1; | |
2935 | return; | |
2936 | } | |
2937 | ||
2938 | /* There's no reason to do any of the work here if we're only doing | |
2939 | semantic analysis; this code just generates RTL. */ | |
2940 | if (flag_syntax_only) | |
2941 | return; | |
2942 | ||
e4d91027 RH |
2943 | /* Compute the appropriate object-file linkage for inline functions. */ |
2944 | if (DECL_DECLARED_INLINE_P (fn)) | |
2945 | import_export_decl (fn); | |
8cd2462c | 2946 | |
99edd65d RH |
2947 | function_depth++; |
2948 | ||
e4d91027 | 2949 | /* Expand or defer, at the whim of the compilation unit manager. */ |
6b00c969 | 2950 | cgraph_finalize_function (fn, function_depth > 1); |
99edd65d RH |
2951 | |
2952 | function_depth--; | |
8cd2462c JH |
2953 | } |
2954 | ||
6de9cd9a DN |
2955 | struct nrv_data |
2956 | { | |
2957 | tree var; | |
2958 | tree result; | |
2959 | htab_t visited; | |
2960 | }; | |
0d97bf4c | 2961 | |
6de9cd9a DN |
2962 | /* Helper function for walk_tree, used by finalize_nrv below. */ |
2963 | ||
2964 | static tree | |
2965 | finalize_nrv_r (tree* tp, int* walk_subtrees, void* data) | |
0d97bf4c | 2966 | { |
6de9cd9a DN |
2967 | struct nrv_data *dp = (struct nrv_data *)data; |
2968 | void **slot; | |
07b2f2fd JM |
2969 | |
2970 | /* No need to walk into types. There wouldn't be any need to walk into | |
2971 | non-statements, except that we have to consider STMT_EXPRs. */ | |
0d97bf4c JM |
2972 | if (TYPE_P (*tp)) |
2973 | *walk_subtrees = 0; | |
6de9cd9a DN |
2974 | /* Change all returns to just refer to the RESULT_DECL; this is a nop, |
2975 | but differs from using NULL_TREE in that it indicates that we care | |
2976 | about the value of the RESULT_DECL. */ | |
0d97bf4c | 2977 | else if (TREE_CODE (*tp) == RETURN_STMT) |
6de9cd9a DN |
2978 | RETURN_STMT_EXPR (*tp) = dp->result; |
2979 | /* Change all cleanups for the NRV to only run when an exception is | |
2980 | thrown. */ | |
07b2f2fd | 2981 | else if (TREE_CODE (*tp) == CLEANUP_STMT |
6de9cd9a | 2982 | && CLEANUP_DECL (*tp) == dp->var) |
659e5a7a | 2983 | CLEANUP_EH_ONLY (*tp) = 1; |
6de9cd9a DN |
2984 | /* Replace the DECL_STMT for the NRV with an initialization of the |
2985 | RESULT_DECL, if needed. */ | |
2986 | else if (TREE_CODE (*tp) == DECL_STMT | |
2987 | && DECL_STMT_DECL (*tp) == dp->var) | |
2988 | { | |
2989 | tree init; | |
2990 | if (DECL_INITIAL (dp->var) | |
2991 | && DECL_INITIAL (dp->var) != error_mark_node) | |
2992 | { | |
2993 | init = build (INIT_EXPR, void_type_node, dp->result, | |
2994 | DECL_INITIAL (dp->var)); | |
2995 | DECL_INITIAL (dp->var) = error_mark_node; | |
2996 | } | |
2997 | else | |
2998 | init = NULL_TREE; | |
2999 | init = build_stmt (EXPR_STMT, init); | |
3000 | SET_EXPR_LOCUS (init, EXPR_LOCUS (*tp)); | |
3001 | TREE_CHAIN (init) = TREE_CHAIN (*tp); | |
3002 | *tp = init; | |
3003 | } | |
3004 | /* And replace all uses of the NRV with the RESULT_DECL. */ | |
3005 | else if (*tp == dp->var) | |
3006 | *tp = dp->result; | |
3007 | ||
3008 | /* Avoid walking into the same tree more than once. Unfortunately, we | |
3009 | can't just use walk_tree_without duplicates because it would only call | |
3010 | us for the first occurrence of dp->var in the function body. */ | |
3011 | slot = htab_find_slot (dp->visited, *tp, INSERT); | |
3012 | if (*slot) | |
3013 | *walk_subtrees = 0; | |
3014 | else | |
3015 | *slot = *tp; | |
0d97bf4c JM |
3016 | |
3017 | /* Keep iterating. */ | |
3018 | return NULL_TREE; | |
3019 | } | |
3020 | ||
6de9cd9a DN |
3021 | /* Called from finish_function to implement the named return value |
3022 | optimization by overriding all the RETURN_STMTs and pertinent | |
3023 | CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the | |
3024 | RESULT_DECL for the function. */ | |
f444e36b | 3025 | |
4985cde3 | 3026 | void |
6de9cd9a | 3027 | finalize_nrv (tree *tp, tree var, tree result) |
f444e36b | 3028 | { |
6de9cd9a DN |
3029 | struct nrv_data data; |
3030 | ||
3031 | /* Copy debugging information from VAR to RESULT. */ | |
3032 | DECL_NAME (result) = DECL_NAME (var); | |
3033 | DECL_SOURCE_LOCATION (result) = DECL_SOURCE_LOCATION (var); | |
3034 | DECL_ABSTRACT_ORIGIN (result) = DECL_ABSTRACT_ORIGIN (var); | |
3035 | /* Don't forget that we take its address. */ | |
3036 | TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var); | |
3037 | ||
3038 | data.var = var; | |
3039 | data.result = result; | |
3040 | data.visited = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL); | |
3041 | walk_tree (tp, finalize_nrv_r, &data, 0); | |
3042 | htab_delete (data.visited); | |
b850de4f MM |
3043 | } |
3044 | ||
54f7877c MM |
3045 | /* Perform initialization related to this module. */ |
3046 | ||
3047 | void | |
3a978d72 | 3048 | init_cp_semantics (void) |
54f7877c | 3049 | { |
54f7877c | 3050 | } |
cf22909c KL |
3051 | |
3052 | #include "gt-cp-semantics.h" |