]>
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 NS |
6 | Copyright (C) 1998, 1999, 2000, 2001, 2002, |
7 | 2003 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" |
ad321293 MM |
35 | #include "except.h" |
36 | #include "lex.h" | |
12027a89 | 37 | #include "toplev.h" |
84df082b | 38 | #include "flags.h" |
d9b2d9da | 39 | #include "rtl.h" |
d6684bc8 | 40 | #include "expr.h" |
225ff119 | 41 | #include "output.h" |
ea11ca7e | 42 | #include "timevar.h" |
2b85879e | 43 | #include "debug.h" |
ad321293 MM |
44 | |
45 | /* There routines provide a modular interface to perform many parsing | |
46 | operations. They may therefore be used during actual parsing, or | |
47 | during template instantiation, which may be regarded as a | |
48 | degenerate form of parsing. Since the current g++ parser is | |
49 | lacking in several respects, and will be reimplemented, we are | |
50 | attempting to move most code that is not directly related to | |
51 | parsing into this file; that will make implementing the new parser | |
52 | much easier since it will be able to make use of these routines. */ | |
53 | ||
158991b7 KG |
54 | static tree maybe_convert_cond PARAMS ((tree)); |
55 | static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *)); | |
31f8e4f3 | 56 | static void emit_associated_thunks PARAMS ((tree)); |
54f7877c | 57 | static void genrtl_try_block PARAMS ((tree)); |
52a11cbf | 58 | static void genrtl_eh_spec_block PARAMS ((tree)); |
54f7877c | 59 | static void genrtl_handler PARAMS ((tree)); |
54f7877c | 60 | static void cp_expand_stmt PARAMS ((tree)); |
f444e36b MM |
61 | static void genrtl_start_function PARAMS ((tree)); |
62 | static void genrtl_finish_function PARAMS ((tree)); | |
b850de4f | 63 | static tree clear_decl_rtl PARAMS ((tree *, int *, void *)); |
558475f0 | 64 | |
527f0080 MM |
65 | /* Finish processing the COND, the SUBSTMT condition for STMT. */ |
66 | ||
c3af729a | 67 | #define FINISH_COND(COND, STMT, SUBSTMT) \ |
ed5511d9 | 68 | do { \ |
c3af729a | 69 | if (last_tree != (STMT)) \ |
ed5511d9 | 70 | { \ |
c3af729a GS |
71 | RECHAIN_STMTS (STMT, SUBSTMT); \ |
72 | if (!processing_template_decl) \ | |
73 | { \ | |
74 | (COND) = build_tree_list (SUBSTMT, COND); \ | |
75 | (SUBSTMT) = (COND); \ | |
76 | } \ | |
ed5511d9 MM |
77 | } \ |
78 | else \ | |
c3af729a | 79 | (SUBSTMT) = (COND); \ |
527f0080 | 80 | } while (0) |
35b1567d | 81 | |
8d241e0b KL |
82 | /* Deferred Access Checking Overview |
83 | --------------------------------- | |
84 | ||
85 | Most C++ expressions and declarations require access checking | |
86 | to be performed during parsing. However, in several cases, | |
87 | this has to be treated differently. | |
88 | ||
89 | For member declarations, access checking has to be deferred | |
90 | until more information about the declaration is known. For | |
91 | example: | |
92 | ||
93 | class A { | |
94 | typedef int X; | |
95 | public: | |
96 | X f(); | |
97 | }; | |
98 | ||
99 | A::X A::f(); | |
100 | A::X g(); | |
101 | ||
102 | When we are parsing the function return type `A::X', we don't | |
103 | really know if this is allowed until we parse the function name. | |
104 | ||
105 | Furthermore, some contexts require that access checking is | |
106 | never performed at all. These include class heads, and template | |
107 | instantiations. | |
108 | ||
109 | Typical use of access checking functions is described here: | |
110 | ||
111 | 1. When we enter a context that requires certain access checking | |
112 | mode, the function `push_deferring_access_checks' is called with | |
113 | DEFERRING argument specifying the desired mode. Access checking | |
114 | may be performed immediately (dk_no_deferred), deferred | |
115 | (dk_deferred), or not performed (dk_no_check). | |
116 | ||
117 | 2. When a declaration such as a type, or a variable, is encountered, | |
118 | the function `perform_or_defer_access_check' is called. It | |
119 | maintains a TREE_LIST of all deferred checks. | |
120 | ||
121 | 3. The global `current_class_type' or `current_function_decl' is then | |
122 | setup by the parser. `enforce_access' relies on these information | |
123 | to check access. | |
124 | ||
125 | 4. Upon exiting the context mentioned in step 1, | |
126 | `perform_deferred_access_checks' is called to check all declaration | |
127 | stored in the TREE_LIST. `pop_deferring_access_checks' is then | |
128 | called to restore the previous access checking mode. | |
129 | ||
130 | In case of parsing error, we simply call `pop_deferring_access_checks' | |
131 | without `perform_deferred_access_checks'. */ | |
132 | ||
cf22909c KL |
133 | /* Data for deferred access checking. */ |
134 | static GTY(()) deferred_access *deferred_access_stack; | |
135 | static GTY(()) deferred_access *deferred_access_free_list; | |
136 | ||
137 | /* Save the current deferred access states and start deferred | |
138 | access checking iff DEFER_P is true. */ | |
139 | ||
8d241e0b | 140 | void push_deferring_access_checks (deferring_kind deferring) |
cf22909c KL |
141 | { |
142 | deferred_access *d; | |
143 | ||
78757caa KL |
144 | /* For context like template instantiation, access checking |
145 | disabling applies to all nested context. */ | |
146 | if (deferred_access_stack | |
147 | && deferred_access_stack->deferring_access_checks_kind == dk_no_check) | |
148 | deferring = dk_no_check; | |
149 | ||
cf22909c KL |
150 | /* Recycle previously used free store if available. */ |
151 | if (deferred_access_free_list) | |
152 | { | |
153 | d = deferred_access_free_list; | |
154 | deferred_access_free_list = d->next; | |
155 | } | |
156 | else | |
157 | d = (deferred_access *) ggc_alloc (sizeof (deferred_access)); | |
158 | ||
159 | d->next = deferred_access_stack; | |
160 | d->deferred_access_checks = NULL_TREE; | |
8d241e0b | 161 | d->deferring_access_checks_kind = deferring; |
cf22909c KL |
162 | deferred_access_stack = d; |
163 | } | |
164 | ||
165 | /* Resume deferring access checks again after we stopped doing | |
166 | this previously. */ | |
167 | ||
168 | void resume_deferring_access_checks (void) | |
169 | { | |
8d241e0b KL |
170 | if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred) |
171 | deferred_access_stack->deferring_access_checks_kind = dk_deferred; | |
cf22909c KL |
172 | } |
173 | ||
174 | /* Stop deferring access checks. */ | |
175 | ||
176 | void stop_deferring_access_checks (void) | |
177 | { | |
8d241e0b KL |
178 | if (deferred_access_stack->deferring_access_checks_kind == dk_deferred) |
179 | deferred_access_stack->deferring_access_checks_kind = dk_no_deferred; | |
cf22909c KL |
180 | } |
181 | ||
182 | /* Discard the current deferred access checks and restore the | |
183 | previous states. */ | |
184 | ||
185 | void pop_deferring_access_checks (void) | |
186 | { | |
187 | deferred_access *d = deferred_access_stack; | |
188 | deferred_access_stack = d->next; | |
189 | ||
190 | /* Remove references to access checks TREE_LIST. */ | |
191 | d->deferred_access_checks = NULL_TREE; | |
192 | ||
193 | /* Store in free list for later use. */ | |
194 | d->next = deferred_access_free_list; | |
195 | deferred_access_free_list = d; | |
196 | } | |
197 | ||
198 | /* Returns a TREE_LIST representing the deferred checks. | |
199 | The TREE_PURPOSE of each node is the type through which the | |
200 | access occurred; the TREE_VALUE is the declaration named. | |
201 | */ | |
202 | ||
203 | tree get_deferred_access_checks (void) | |
204 | { | |
205 | return deferred_access_stack->deferred_access_checks; | |
206 | } | |
207 | ||
208 | /* Take current deferred checks and combine with the | |
209 | previous states if we also defer checks previously. | |
210 | Otherwise perform checks now. */ | |
211 | ||
212 | void pop_to_parent_deferring_access_checks (void) | |
213 | { | |
214 | tree deferred_check = get_deferred_access_checks (); | |
215 | deferred_access *d1 = deferred_access_stack; | |
216 | deferred_access *d2 = deferred_access_stack->next; | |
217 | deferred_access *d3 = deferred_access_stack->next->next; | |
218 | ||
219 | /* Temporary swap the order of the top two states, just to make | |
220 | sure the garbage collector will not reclaim the memory during | |
221 | processing below. */ | |
222 | deferred_access_stack = d2; | |
223 | d2->next = d1; | |
224 | d1->next = d3; | |
225 | ||
226 | for ( ; deferred_check; deferred_check = TREE_CHAIN (deferred_check)) | |
227 | /* Perform deferred check if required. */ | |
228 | perform_or_defer_access_check (TREE_PURPOSE (deferred_check), | |
229 | TREE_VALUE (deferred_check)); | |
230 | ||
231 | deferred_access_stack = d1; | |
232 | d1->next = d2; | |
233 | d2->next = d3; | |
234 | pop_deferring_access_checks (); | |
235 | } | |
236 | ||
25903d03 KL |
237 | /* Perform the deferred access checks. |
238 | ||
239 | After performing the checks, we still have to keep the list | |
240 | `deferred_access_stack->deferred_access_checks' since we may want | |
241 | to check access for them again later in a different context. | |
242 | For example: | |
243 | ||
244 | class A { | |
245 | typedef int X; | |
246 | static X a; | |
247 | }; | |
248 | A::X A::a, x; // No error for `A::a', error for `x' | |
249 | ||
250 | We have to perform deferred access of `A::X', first with `A::a', | |
251 | next with `x'. */ | |
cf22909c KL |
252 | |
253 | void perform_deferred_access_checks (void) | |
254 | { | |
255 | tree deferred_check; | |
256 | for (deferred_check = deferred_access_stack->deferred_access_checks; | |
257 | deferred_check; | |
258 | deferred_check = TREE_CHAIN (deferred_check)) | |
259 | /* Check access. */ | |
260 | enforce_access (TREE_PURPOSE (deferred_check), | |
261 | TREE_VALUE (deferred_check)); | |
cf22909c KL |
262 | } |
263 | ||
264 | /* Defer checking the accessibility of DECL, when looked up in | |
265 | CLASS_TYPE. */ | |
266 | ||
267 | void perform_or_defer_access_check (tree class_type, tree decl) | |
268 | { | |
269 | tree check; | |
270 | ||
271 | /* If we are not supposed to defer access checks, just check now. */ | |
8d241e0b | 272 | if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred) |
cf22909c KL |
273 | { |
274 | enforce_access (class_type, decl); | |
275 | return; | |
276 | } | |
8d241e0b KL |
277 | /* Exit if we are in a context that no access checking is performed. */ |
278 | else if (deferred_access_stack->deferring_access_checks_kind == dk_no_check) | |
279 | return; | |
cf22909c KL |
280 | |
281 | /* See if we are already going to perform this check. */ | |
282 | for (check = deferred_access_stack->deferred_access_checks; | |
283 | check; | |
284 | check = TREE_CHAIN (check)) | |
285 | if (TREE_VALUE (check) == decl | |
78757caa | 286 | && TYPE_P (TREE_PURPOSE (check)) |
cf22909c KL |
287 | && same_type_p (TREE_PURPOSE (check), class_type)) |
288 | return; | |
289 | /* If not, record the check. */ | |
290 | deferred_access_stack->deferred_access_checks | |
291 | = tree_cons (class_type, decl, | |
292 | deferred_access_stack->deferred_access_checks); | |
293 | } | |
294 | ||
838dfd8a | 295 | /* Returns nonzero if the current statement is a full expression, |
f2c5f623 BC |
296 | i.e. temporaries created during that statement should be destroyed |
297 | at the end of the statement. */ | |
35b1567d | 298 | |
f2c5f623 BC |
299 | int |
300 | stmts_are_full_exprs_p () | |
301 | { | |
ae499cce MM |
302 | return current_stmt_tree ()->stmts_are_full_exprs_p; |
303 | } | |
304 | ||
305 | /* Returns the stmt_tree (if any) to which statements are currently | |
306 | being added. If there is no active statement-tree, NULL is | |
307 | returned. */ | |
308 | ||
309 | stmt_tree | |
310 | current_stmt_tree () | |
311 | { | |
312 | return (cfun | |
e2500fed | 313 | ? &cfun->language->base.x_stmt_tree |
ae499cce | 314 | : &scope_chain->x_stmt_tree); |
f2c5f623 | 315 | } |
35b1567d | 316 | |
f2c5f623 BC |
317 | /* Nonzero if TYPE is an anonymous union or struct type. We have to use a |
318 | flag for this because "A union for which objects or pointers are | |
319 | declared is not an anonymous union" [class.union]. */ | |
35b1567d | 320 | |
f2c5f623 BC |
321 | int |
322 | anon_aggr_type_p (node) | |
323 | tree node; | |
35b1567d | 324 | { |
e2500fed | 325 | return ANON_AGGR_TYPE_P (node); |
35b1567d BC |
326 | } |
327 | ||
f2c5f623 | 328 | /* Finish a scope. */ |
35b1567d BC |
329 | |
330 | tree | |
f2c5f623 | 331 | do_poplevel () |
35b1567d BC |
332 | { |
333 | tree block = NULL_TREE; | |
334 | ||
f2c5f623 | 335 | if (stmts_are_full_exprs_p ()) |
35b1567d | 336 | { |
50e60bc3 | 337 | tree scope_stmts = NULL_TREE; |
f2c5f623 | 338 | |
35b1567d | 339 | block = poplevel (kept_level_p (), 1, 0); |
9f175208 | 340 | if (!processing_template_decl) |
35b1567d | 341 | { |
9f175208 JM |
342 | /* This needs to come after the poplevel so that partial scopes |
343 | are properly nested. */ | |
344 | scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); | |
345 | if (block) | |
346 | { | |
347 | SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block; | |
348 | SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block; | |
349 | } | |
35b1567d BC |
350 | } |
351 | } | |
352 | ||
353 | return block; | |
354 | } | |
355 | ||
f2c5f623 | 356 | /* Begin a new scope. */ |
35b1567d BC |
357 | |
358 | void | |
92bc1323 | 359 | do_pushlevel (scope_kind sk) |
35b1567d | 360 | { |
f2c5f623 | 361 | if (stmts_are_full_exprs_p ()) |
35b1567d | 362 | { |
f2c5f623 BC |
363 | if (!processing_template_decl) |
364 | add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0); | |
92bc1323 | 365 | begin_scope (sk); |
35b1567d BC |
366 | } |
367 | } | |
368 | ||
35b1567d BC |
369 | /* Finish a goto-statement. */ |
370 | ||
3e4d04a1 | 371 | tree |
35b1567d BC |
372 | finish_goto_stmt (destination) |
373 | tree destination; | |
374 | { | |
375 | if (TREE_CODE (destination) == IDENTIFIER_NODE) | |
376 | destination = lookup_label (destination); | |
377 | ||
378 | /* We warn about unused labels with -Wunused. That means we have to | |
379 | mark the used labels as used. */ | |
380 | if (TREE_CODE (destination) == LABEL_DECL) | |
381 | TREE_USED (destination) = 1; | |
382 | ||
383 | if (TREE_CODE (destination) != LABEL_DECL) | |
384 | /* We don't inline calls to functions with computed gotos. | |
385 | Those functions are typically up to some funny business, | |
386 | and may be depending on the labels being at particular | |
387 | addresses, or some such. */ | |
388 | DECL_UNINLINABLE (current_function_decl) = 1; | |
389 | ||
390 | check_goto (destination); | |
391 | ||
3e4d04a1 | 392 | return add_stmt (build_stmt (GOTO_STMT, destination)); |
35b1567d BC |
393 | } |
394 | ||
ed5511d9 MM |
395 | /* COND is the condition-expression for an if, while, etc., |
396 | statement. Convert it to a boolean value, if appropriate. */ | |
397 | ||
f2c5f623 | 398 | tree |
ed5511d9 MM |
399 | maybe_convert_cond (cond) |
400 | tree cond; | |
401 | { | |
402 | /* Empty conditions remain empty. */ | |
403 | if (!cond) | |
404 | return NULL_TREE; | |
405 | ||
406 | /* Wait until we instantiate templates before doing conversion. */ | |
407 | if (processing_template_decl) | |
408 | return cond; | |
409 | ||
410 | /* Do the conversion. */ | |
411 | cond = convert_from_reference (cond); | |
412 | return condition_conversion (cond); | |
413 | } | |
414 | ||
9bfadf57 | 415 | /* Finish an expression-statement, whose EXPRESSION is as indicated. */ |
a7e4cfa0 | 416 | |
3e4d04a1 | 417 | tree |
9bfadf57 | 418 | finish_expr_stmt (expr) |
ad321293 MM |
419 | tree expr; |
420 | { | |
3e4d04a1 | 421 | tree r = NULL_TREE; |
0481bc21 | 422 | tree expr_type = NULL_TREE;; |
3e4d04a1 | 423 | |
ce4a0391 | 424 | if (expr != NULL_TREE) |
ad321293 | 425 | { |
35b1567d | 426 | if (!processing_template_decl |
f2c5f623 | 427 | && !(stmts_are_full_exprs_p ()) |
35b1567d BC |
428 | && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE |
429 | && lvalue_p (expr)) | |
430 | || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)) | |
431 | expr = default_conversion (expr); | |
432 | ||
0481bc21 MM |
433 | /* Remember the type of the expression. */ |
434 | expr_type = TREE_TYPE (expr); | |
435 | ||
f2c5f623 | 436 | if (stmts_are_full_exprs_p ()) |
35b1567d BC |
437 | expr = convert_to_void (expr, "statement"); |
438 | ||
3e4d04a1 | 439 | r = add_stmt (build_stmt (EXPR_STMT, expr)); |
35b1567d | 440 | } |
364460b6 | 441 | |
35b1567d | 442 | finish_stmt (); |
558475f0 | 443 | |
35b1567d BC |
444 | /* This was an expression-statement, so we save the type of the |
445 | expression. */ | |
0481bc21 | 446 | last_expr_type = expr_type; |
3e4d04a1 RH |
447 | |
448 | return r; | |
35b1567d BC |
449 | } |
450 | ||
35b1567d | 451 | |
ad321293 MM |
452 | /* Begin an if-statement. Returns a newly created IF_STMT if |
453 | appropriate. */ | |
454 | ||
455 | tree | |
456 | begin_if_stmt () | |
457 | { | |
458 | tree r; | |
92bc1323 | 459 | do_pushlevel (sk_block); |
0dfdeca6 | 460 | r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE); |
ae499cce | 461 | add_stmt (r); |
ad321293 MM |
462 | return r; |
463 | } | |
464 | ||
465 | /* Process the COND of an if-statement, which may be given by | |
466 | IF_STMT. */ | |
467 | ||
468 | void | |
469 | finish_if_stmt_cond (cond, if_stmt) | |
470 | tree cond; | |
471 | tree if_stmt; | |
472 | { | |
ed5511d9 | 473 | cond = maybe_convert_cond (cond); |
35b1567d | 474 | FINISH_COND (cond, if_stmt, IF_COND (if_stmt)); |
ad321293 MM |
475 | } |
476 | ||
477 | /* Finish the then-clause of an if-statement, which may be given by | |
478 | IF_STMT. */ | |
479 | ||
480 | tree | |
481 | finish_then_clause (if_stmt) | |
482 | tree if_stmt; | |
483 | { | |
35b1567d | 484 | RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt)); |
35b1567d | 485 | return if_stmt; |
ad321293 MM |
486 | } |
487 | ||
488 | /* Begin the else-clause of an if-statement. */ | |
489 | ||
490 | void | |
491 | begin_else_clause () | |
492 | { | |
ad321293 MM |
493 | } |
494 | ||
495 | /* Finish the else-clause of an if-statement, which may be given by | |
496 | IF_STMT. */ | |
497 | ||
498 | void | |
499 | finish_else_clause (if_stmt) | |
500 | tree if_stmt; | |
501 | { | |
35b1567d | 502 | RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt)); |
ad321293 MM |
503 | } |
504 | ||
dfbb4f34 | 505 | /* Finish an if-statement. */ |
ad321293 MM |
506 | |
507 | void | |
508 | finish_if_stmt () | |
509 | { | |
ad321293 | 510 | finish_stmt (); |
5d764395 | 511 | do_poplevel (); |
35b1567d BC |
512 | } |
513 | ||
ad321293 MM |
514 | /* Begin a while-statement. Returns a newly created WHILE_STMT if |
515 | appropriate. */ | |
516 | ||
517 | tree | |
518 | begin_while_stmt () | |
519 | { | |
520 | tree r; | |
0dfdeca6 | 521 | r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE); |
ae499cce | 522 | add_stmt (r); |
92bc1323 | 523 | do_pushlevel (sk_block); |
ad321293 MM |
524 | return r; |
525 | } | |
526 | ||
27d26ee7 | 527 | /* Process the COND of a while-statement, which may be given by |
ad321293 MM |
528 | WHILE_STMT. */ |
529 | ||
530 | void | |
531 | finish_while_stmt_cond (cond, while_stmt) | |
532 | tree cond; | |
533 | tree while_stmt; | |
534 | { | |
ed5511d9 | 535 | cond = maybe_convert_cond (cond); |
5275f2bf JM |
536 | if (processing_template_decl) |
537 | /* Don't mess with condition decls in a template. */ | |
538 | FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt)); | |
539 | else if (getdecls () == NULL_TREE) | |
5d764395 JM |
540 | /* It was a simple condition; install it. */ |
541 | WHILE_COND (while_stmt) = cond; | |
542 | else | |
543 | { | |
544 | /* If there was a declaration in the condition, we can't leave it | |
545 | there; transform | |
546 | while (A x = 42) { } | |
547 | to | |
548 | while (true) { A x = 42; if (!x) break; } */ | |
549 | tree if_stmt; | |
550 | WHILE_COND (while_stmt) = boolean_true_node; | |
551 | ||
552 | if_stmt = begin_if_stmt (); | |
553 | cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0); | |
554 | finish_if_stmt_cond (cond, if_stmt); | |
555 | finish_break_stmt (); | |
556 | finish_then_clause (if_stmt); | |
557 | finish_if_stmt (); | |
558 | } | |
ad321293 MM |
559 | } |
560 | ||
561 | /* Finish a while-statement, which may be given by WHILE_STMT. */ | |
562 | ||
563 | void | |
564 | finish_while_stmt (while_stmt) | |
565 | tree while_stmt; | |
566 | { | |
567 | do_poplevel (); | |
35b1567d | 568 | RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt)); |
ad321293 MM |
569 | finish_stmt (); |
570 | } | |
571 | ||
572 | /* Begin a do-statement. Returns a newly created DO_STMT if | |
573 | appropriate. */ | |
574 | ||
575 | tree | |
576 | begin_do_stmt () | |
577 | { | |
0dfdeca6 | 578 | tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE); |
ae499cce | 579 | add_stmt (r); |
35b1567d | 580 | return r; |
ad321293 MM |
581 | } |
582 | ||
583 | /* Finish the body of a do-statement, which may be given by DO_STMT. */ | |
584 | ||
585 | void | |
586 | finish_do_body (do_stmt) | |
587 | tree do_stmt; | |
588 | { | |
35b1567d | 589 | RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt)); |
ad321293 MM |
590 | } |
591 | ||
592 | /* Finish a do-statement, which may be given by DO_STMT, and whose | |
593 | COND is as indicated. */ | |
594 | ||
595 | void | |
596 | finish_do_stmt (cond, do_stmt) | |
597 | tree cond; | |
598 | tree do_stmt; | |
599 | { | |
ed5511d9 | 600 | cond = maybe_convert_cond (cond); |
35b1567d BC |
601 | DO_COND (do_stmt) = cond; |
602 | finish_stmt (); | |
603 | } | |
ed5511d9 | 604 | |
ad321293 MM |
605 | /* Finish a return-statement. The EXPRESSION returned, if any, is as |
606 | indicated. */ | |
607 | ||
3e4d04a1 | 608 | tree |
ad321293 MM |
609 | finish_return_stmt (expr) |
610 | tree expr; | |
611 | { | |
3e4d04a1 RH |
612 | tree r; |
613 | ||
efc7052d | 614 | expr = check_return_expr (expr); |
35b1567d | 615 | if (!processing_template_decl) |
efee38a9 | 616 | { |
a0de9d20 | 617 | if (DECL_DESTRUCTOR_P (current_function_decl)) |
efee38a9 MM |
618 | { |
619 | /* Similarly, all destructors must run destructors for | |
620 | base-classes before returning. So, all returns in a | |
dfbb4f34 | 621 | destructor get sent to the DTOR_LABEL; finish_function emits |
efee38a9 | 622 | code to return a value there. */ |
3e4d04a1 | 623 | return finish_goto_stmt (dtor_label); |
efee38a9 MM |
624 | } |
625 | } | |
3e4d04a1 | 626 | r = add_stmt (build_stmt (RETURN_STMT, expr)); |
35b1567d | 627 | finish_stmt (); |
3e4d04a1 RH |
628 | |
629 | return r; | |
35b1567d | 630 | } |
efee38a9 | 631 | |
ad321293 MM |
632 | /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */ |
633 | ||
634 | tree | |
635 | begin_for_stmt () | |
636 | { | |
637 | tree r; | |
638 | ||
0dfdeca6 BC |
639 | r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE, |
640 | NULL_TREE, NULL_TREE); | |
f2c5f623 | 641 | NEW_FOR_SCOPE_P (r) = flag_new_for_scope > 0; |
f2c5f623 | 642 | if (NEW_FOR_SCOPE_P (r)) |
92bc1323 | 643 | do_pushlevel (sk_for); |
18ba380b | 644 | add_stmt (r); |
ad321293 MM |
645 | |
646 | return r; | |
647 | } | |
648 | ||
649 | /* Finish the for-init-statement of a for-statement, which may be | |
650 | given by FOR_STMT. */ | |
651 | ||
652 | void | |
653 | finish_for_init_stmt (for_stmt) | |
654 | tree for_stmt; | |
655 | { | |
35b1567d BC |
656 | if (last_tree != for_stmt) |
657 | RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt)); | |
92bc1323 | 658 | do_pushlevel (sk_block); |
ad321293 MM |
659 | } |
660 | ||
661 | /* Finish the COND of a for-statement, which may be given by | |
662 | FOR_STMT. */ | |
663 | ||
664 | void | |
665 | finish_for_cond (cond, for_stmt) | |
666 | tree cond; | |
667 | tree for_stmt; | |
668 | { | |
ed5511d9 | 669 | cond = maybe_convert_cond (cond); |
5275f2bf JM |
670 | if (processing_template_decl) |
671 | /* Don't mess with condition decls in a template. */ | |
672 | FINISH_COND (cond, for_stmt, FOR_COND (for_stmt)); | |
673 | else if (getdecls () == NULL_TREE) | |
5d764395 JM |
674 | /* It was a simple condition; install it. */ |
675 | FOR_COND (for_stmt) = cond; | |
676 | else | |
677 | { | |
678 | /* If there was a declaration in the condition, we can't leave it | |
679 | there; transform | |
680 | for (; A x = 42;) { } | |
681 | to | |
682 | for (;;) { A x = 42; if (!x) break; } */ | |
683 | tree if_stmt; | |
684 | FOR_COND (for_stmt) = NULL_TREE; | |
685 | ||
686 | if_stmt = begin_if_stmt (); | |
687 | cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0); | |
688 | finish_if_stmt_cond (cond, if_stmt); | |
689 | finish_break_stmt (); | |
690 | finish_then_clause (if_stmt); | |
691 | finish_if_stmt (); | |
692 | } | |
ad321293 MM |
693 | } |
694 | ||
695 | /* Finish the increment-EXPRESSION in a for-statement, which may be | |
696 | given by FOR_STMT. */ | |
697 | ||
698 | void | |
699 | finish_for_expr (expr, for_stmt) | |
700 | tree expr; | |
701 | tree for_stmt; | |
702 | { | |
35b1567d | 703 | FOR_EXPR (for_stmt) = expr; |
ad321293 MM |
704 | } |
705 | ||
706 | /* Finish the body of a for-statement, which may be given by | |
707 | FOR_STMT. The increment-EXPR for the loop must be | |
708 | provided. */ | |
709 | ||
710 | void | |
35b1567d | 711 | finish_for_stmt (for_stmt) |
ad321293 MM |
712 | tree for_stmt; |
713 | { | |
714 | /* Pop the scope for the body of the loop. */ | |
715 | do_poplevel (); | |
35b1567d | 716 | RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt)); |
f2c5f623 | 717 | if (NEW_FOR_SCOPE_P (for_stmt)) |
ad321293 | 718 | do_poplevel (); |
ad321293 MM |
719 | finish_stmt (); |
720 | } | |
721 | ||
722 | /* Finish a break-statement. */ | |
723 | ||
3e4d04a1 | 724 | tree |
ad321293 MM |
725 | finish_break_stmt () |
726 | { | |
3e4d04a1 | 727 | return add_stmt (build_break_stmt ()); |
35b1567d BC |
728 | } |
729 | ||
ad321293 MM |
730 | /* Finish a continue-statement. */ |
731 | ||
3e4d04a1 | 732 | tree |
ad321293 MM |
733 | finish_continue_stmt () |
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 | |
742 | begin_switch_stmt () | |
743 | { | |
744 | tree r; | |
92bc1323 | 745 | do_pushlevel (sk_block); |
6f9fdf4d | 746 | r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE); |
ae499cce | 747 | add_stmt (r); |
527f0080 | 748 | return r; |
ad321293 MM |
749 | } |
750 | ||
527f0080 | 751 | /* Finish the cond of a switch-statement. */ |
ad321293 | 752 | |
527f0080 MM |
753 | void |
754 | finish_switch_cond (cond, switch_stmt) | |
ad321293 | 755 | tree cond; |
527f0080 | 756 | tree switch_stmt; |
ad321293 | 757 | { |
6f9fdf4d | 758 | tree orig_type = NULL; |
35b1567d | 759 | if (!processing_template_decl) |
373eb3b3 | 760 | { |
56cb9733 MM |
761 | tree index; |
762 | ||
35b1567d | 763 | /* Convert the condition to an integer or enumeration type. */ |
b746c5dc | 764 | cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true); |
35b1567d | 765 | if (cond == NULL_TREE) |
373eb3b3 | 766 | { |
35b1567d BC |
767 | error ("switch quantity not an integer"); |
768 | cond = error_mark_node; | |
769 | } | |
6f9fdf4d | 770 | orig_type = TREE_TYPE (cond); |
35b1567d BC |
771 | if (cond != error_mark_node) |
772 | { | |
35b1567d | 773 | cond = default_conversion (cond); |
2bb5d995 | 774 | cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond)); |
373eb3b3 | 775 | } |
56cb9733 | 776 | |
25c8b645 JJ |
777 | if (cond != error_mark_node) |
778 | { | |
779 | index = get_unwidened (cond, NULL_TREE); | |
780 | /* We can't strip a conversion from a signed type to an unsigned, | |
781 | because if we did, int_fits_type_p would do the wrong thing | |
782 | when checking case values for being in range, | |
783 | and it's too hard to do the right thing. */ | |
784 | if (TREE_UNSIGNED (TREE_TYPE (cond)) | |
785 | == TREE_UNSIGNED (TREE_TYPE (index))) | |
786 | cond = index; | |
787 | } | |
ad321293 | 788 | } |
35b1567d | 789 | FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt)); |
6f9fdf4d | 790 | SWITCH_TYPE (switch_stmt) = orig_type; |
56cb9733 | 791 | push_switch (switch_stmt); |
ad321293 MM |
792 | } |
793 | ||
794 | /* Finish the body of a switch-statement, which may be given by | |
795 | SWITCH_STMT. The COND to switch on is indicated. */ | |
796 | ||
797 | void | |
35b1567d | 798 | finish_switch_stmt (switch_stmt) |
ad321293 MM |
799 | tree switch_stmt; |
800 | { | |
35b1567d | 801 | RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt)); |
ad321293 | 802 | pop_switch (); |
ad321293 | 803 | finish_stmt (); |
5d764395 | 804 | do_poplevel (); |
ad321293 MM |
805 | } |
806 | ||
c6002625 | 807 | /* Generate the RTL for T, which is a TRY_BLOCK. */ |
6625cdb5 | 808 | |
54f7877c MM |
809 | static void |
810 | genrtl_try_block (t) | |
35b1567d BC |
811 | tree t; |
812 | { | |
813 | if (CLEANUP_P (t)) | |
814 | { | |
815 | expand_eh_region_start (); | |
816 | expand_stmt (TRY_STMTS (t)); | |
52a11cbf | 817 | expand_eh_region_end_cleanup (TRY_HANDLERS (t)); |
46e8c075 | 818 | } |
ad321293 MM |
819 | else |
820 | { | |
f444e36b | 821 | if (!FN_TRY_BLOCK_P (t)) |
d479d37f | 822 | emit_line_note (input_filename, input_line); |
35b1567d | 823 | |
52a11cbf | 824 | expand_eh_region_start (); |
35b1567d | 825 | expand_stmt (TRY_STMTS (t)); |
ad321293 | 826 | |
35b1567d | 827 | if (FN_TRY_BLOCK_P (t)) |
ad321293 | 828 | { |
35b1567d BC |
829 | expand_start_all_catch (); |
830 | in_function_try_handler = 1; | |
831 | expand_stmt (TRY_HANDLERS (t)); | |
832 | in_function_try_handler = 0; | |
833 | expand_end_all_catch (); | |
834 | } | |
835 | else | |
836 | { | |
837 | expand_start_all_catch (); | |
838 | expand_stmt (TRY_HANDLERS (t)); | |
839 | expand_end_all_catch (); | |
ad321293 | 840 | } |
ad321293 MM |
841 | } |
842 | } | |
843 | ||
c6002625 | 844 | /* Generate the RTL for T, which is an EH_SPEC_BLOCK. */ |
52a11cbf RH |
845 | |
846 | static void | |
847 | genrtl_eh_spec_block (t) | |
848 | tree t; | |
849 | { | |
850 | expand_eh_region_start (); | |
851 | expand_stmt (EH_SPEC_STMTS (t)); | |
852 | expand_eh_region_end_allowed (EH_SPEC_RAISES (t), | |
853 | build_call (call_unexpected_node, | |
854 | tree_cons (NULL_TREE, | |
855 | build_exc_ptr (), | |
856 | NULL_TREE))); | |
857 | } | |
858 | ||
ad321293 MM |
859 | /* Begin a try-block. Returns a newly-created TRY_BLOCK if |
860 | appropriate. */ | |
861 | ||
862 | tree | |
863 | begin_try_block () | |
864 | { | |
0dfdeca6 | 865 | tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE); |
ae499cce | 866 | add_stmt (r); |
35b1567d | 867 | return r; |
ad321293 MM |
868 | } |
869 | ||
0dde4175 JM |
870 | /* Likewise, for a function-try-block. */ |
871 | ||
872 | tree | |
873 | begin_function_try_block () | |
874 | { | |
0dfdeca6 | 875 | tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE); |
35b1567d | 876 | FN_TRY_BLOCK_P (r) = 1; |
ae499cce | 877 | add_stmt (r); |
35b1567d | 878 | return r; |
0dde4175 JM |
879 | } |
880 | ||
ad321293 MM |
881 | /* Finish a try-block, which may be given by TRY_BLOCK. */ |
882 | ||
883 | void | |
884 | finish_try_block (try_block) | |
885 | tree try_block; | |
886 | { | |
35b1567d | 887 | RECHAIN_STMTS (try_block, TRY_STMTS (try_block)); |
ad321293 MM |
888 | } |
889 | ||
efa8eda3 MM |
890 | /* Finish the body of a cleanup try-block, which may be given by |
891 | TRY_BLOCK. */ | |
892 | ||
62409b39 MM |
893 | void |
894 | finish_cleanup_try_block (try_block) | |
895 | tree try_block; | |
896 | { | |
35b1567d | 897 | RECHAIN_STMTS (try_block, TRY_STMTS (try_block)); |
62409b39 MM |
898 | } |
899 | ||
f1dedc31 MM |
900 | /* Finish an implicitly generated try-block, with a cleanup is given |
901 | by CLEANUP. */ | |
902 | ||
903 | void | |
904 | finish_cleanup (cleanup, try_block) | |
905 | tree cleanup; | |
906 | tree try_block; | |
907 | { | |
35b1567d BC |
908 | TRY_HANDLERS (try_block) = cleanup; |
909 | CLEANUP_P (try_block) = 1; | |
f1dedc31 MM |
910 | } |
911 | ||
0dde4175 JM |
912 | /* Likewise, for a function-try-block. */ |
913 | ||
914 | void | |
915 | finish_function_try_block (try_block) | |
a0de9d20 | 916 | tree try_block; |
0dde4175 | 917 | { |
35b1567d BC |
918 | if (TREE_CHAIN (try_block) |
919 | && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER) | |
62409b39 | 920 | { |
35b1567d BC |
921 | /* Chain the compound statement after the CTOR_INITIALIZER. */ |
922 | TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree; | |
923 | /* And make the CTOR_INITIALIZER the body of the try-block. */ | |
924 | RECHAIN_STMTS (try_block, TRY_STMTS (try_block)); | |
62409b39 | 925 | } |
0dde4175 | 926 | else |
35b1567d | 927 | RECHAIN_STMTS (try_block, TRY_STMTS (try_block)); |
b35d4555 | 928 | in_function_try_handler = 1; |
0dde4175 JM |
929 | } |
930 | ||
ad321293 MM |
931 | /* Finish a handler-sequence for a try-block, which may be given by |
932 | TRY_BLOCK. */ | |
933 | ||
934 | void | |
935 | finish_handler_sequence (try_block) | |
936 | tree try_block; | |
937 | { | |
35b1567d BC |
938 | RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block)); |
939 | check_handlers (TRY_HANDLERS (try_block)); | |
ad321293 MM |
940 | } |
941 | ||
0dde4175 JM |
942 | /* Likewise, for a function-try-block. */ |
943 | ||
944 | void | |
945 | finish_function_handler_sequence (try_block) | |
946 | tree try_block; | |
947 | { | |
b35d4555 | 948 | in_function_try_handler = 0; |
35b1567d BC |
949 | RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block)); |
950 | check_handlers (TRY_HANDLERS (try_block)); | |
951 | } | |
952 | ||
c6002625 | 953 | /* Generate the RTL for T, which is a HANDLER. */ |
b35d4555 | 954 | |
54f7877c | 955 | static void |
35b1567d BC |
956 | genrtl_handler (t) |
957 | tree t; | |
958 | { | |
959 | genrtl_do_pushlevel (); | |
1a6025b4 JM |
960 | if (!processing_template_decl) |
961 | expand_start_catch (HANDLER_TYPE (t)); | |
35b1567d BC |
962 | expand_stmt (HANDLER_BODY (t)); |
963 | if (!processing_template_decl) | |
52a11cbf | 964 | expand_end_catch (); |
0dde4175 JM |
965 | } |
966 | ||
ad321293 MM |
967 | /* Begin a handler. Returns a HANDLER if appropriate. */ |
968 | ||
969 | tree | |
970 | begin_handler () | |
971 | { | |
972 | tree r; | |
0dfdeca6 | 973 | r = build_stmt (HANDLER, NULL_TREE, NULL_TREE); |
ae499cce | 974 | add_stmt (r); |
1a6025b4 JM |
975 | /* Create a binding level for the eh_info and the exception object |
976 | cleanup. */ | |
92bc1323 | 977 | do_pushlevel (sk_catch); |
ad321293 MM |
978 | return r; |
979 | } | |
980 | ||
981 | /* Finish the handler-parameters for a handler, which may be given by | |
b35d4555 MM |
982 | HANDLER. DECL is the declaration for the catch parameter, or NULL |
983 | if this is a `catch (...)' clause. */ | |
ad321293 | 984 | |
1a6025b4 | 985 | void |
b35d4555 MM |
986 | finish_handler_parms (decl, handler) |
987 | tree decl; | |
ad321293 | 988 | tree handler; |
b35d4555 | 989 | { |
1a6025b4 | 990 | tree type = NULL_TREE; |
b35d4555 MM |
991 | if (processing_template_decl) |
992 | { | |
993 | if (decl) | |
994 | { | |
995 | decl = pushdecl (decl); | |
996 | decl = push_template_decl (decl); | |
997 | add_decl_stmt (decl); | |
998 | RECHAIN_STMTS (handler, HANDLER_PARMS (handler)); | |
1a6025b4 | 999 | type = TREE_TYPE (decl); |
b35d4555 MM |
1000 | } |
1001 | } | |
35b1567d | 1002 | else |
1a6025b4 | 1003 | type = expand_start_catch_block (decl); |
35b1567d | 1004 | |
1a6025b4 | 1005 | HANDLER_TYPE (handler) = type; |
35b1567d BC |
1006 | } |
1007 | ||
1008 | /* Finish a handler, which may be given by HANDLER. The BLOCKs are | |
1009 | the return value from the matching call to finish_handler_parms. */ | |
1010 | ||
1011 | void | |
1a6025b4 | 1012 | finish_handler (handler) |
35b1567d BC |
1013 | tree handler; |
1014 | { | |
1015 | if (!processing_template_decl) | |
1a6025b4 | 1016 | expand_end_catch_block (); |
35b1567d BC |
1017 | do_poplevel (); |
1018 | RECHAIN_STMTS (handler, HANDLER_BODY (handler)); | |
1019 | } | |
1020 | ||
838dfd8a | 1021 | /* Begin a compound-statement. If HAS_NO_SCOPE is nonzero, the |
ad321293 MM |
1022 | compound-statement does not define a scope. Returns a new |
1023 | COMPOUND_STMT if appropriate. */ | |
1024 | ||
1025 | tree | |
1026 | begin_compound_stmt (has_no_scope) | |
1027 | int has_no_scope; | |
1028 | { | |
1029 | tree r; | |
6625cdb5 | 1030 | int is_try = 0; |
ad321293 | 1031 | |
0dfdeca6 | 1032 | r = build_stmt (COMPOUND_STMT, NULL_TREE); |
35b1567d BC |
1033 | |
1034 | if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK) | |
1035 | is_try = 1; | |
1036 | ||
ae499cce | 1037 | add_stmt (r); |
35b1567d BC |
1038 | if (has_no_scope) |
1039 | COMPOUND_STMT_NO_SCOPE (r) = 1; | |
ad321293 | 1040 | |
558475f0 MM |
1041 | last_expr_type = NULL_TREE; |
1042 | ||
ad321293 | 1043 | if (!has_no_scope) |
92bc1323 | 1044 | do_pushlevel (is_try ? sk_try : sk_block); |
f1dedc31 MM |
1045 | else |
1046 | /* Normally, we try hard to keep the BLOCK for a | |
1047 | statement-expression. But, if it's a statement-expression with | |
1048 | a scopeless block, there's nothing to keep, and we don't want | |
1049 | to accidentally keep a block *inside* the scopeless block. */ | |
1050 | keep_next_level (0); | |
ad321293 MM |
1051 | |
1052 | return r; | |
1053 | } | |
1054 | ||
ad321293 | 1055 | /* Finish a compound-statement, which may be given by COMPOUND_STMT. |
838dfd8a | 1056 | If HAS_NO_SCOPE is nonzero, the compound statement does not define |
ad321293 MM |
1057 | a scope. */ |
1058 | ||
1059 | tree | |
1060 | finish_compound_stmt (has_no_scope, compound_stmt) | |
1061 | int has_no_scope; | |
1062 | tree compound_stmt; | |
1063 | { | |
1064 | tree r; | |
558475f0 | 1065 | tree t; |
ad321293 MM |
1066 | |
1067 | if (!has_no_scope) | |
1068 | r = do_poplevel (); | |
1069 | else | |
1070 | r = NULL_TREE; | |
1071 | ||
35b1567d | 1072 | RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt)); |
ad321293 | 1073 | |
cb39191d | 1074 | /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since |
558475f0 MM |
1075 | the precise purpose of that variable is store the type of the |
1076 | last expression statement within the last compound statement, we | |
1077 | preserve the value. */ | |
1078 | t = last_expr_type; | |
ad321293 | 1079 | finish_stmt (); |
558475f0 | 1080 | last_expr_type = t; |
ad321293 MM |
1081 | |
1082 | return r; | |
1083 | } | |
1084 | ||
35b1567d BC |
1085 | /* Finish an asm-statement, whose components are a CV_QUALIFIER, a |
1086 | STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some | |
1087 | CLOBBERS. */ | |
7dc5bd62 | 1088 | |
3e4d04a1 | 1089 | tree |
35b1567d BC |
1090 | finish_asm_stmt (cv_qualifier, string, output_operands, |
1091 | input_operands, clobbers) | |
1092 | tree cv_qualifier; | |
1093 | tree string; | |
1094 | tree output_operands; | |
1095 | tree input_operands; | |
1096 | tree clobbers; | |
1097 | { | |
1098 | tree r; | |
abfc8a36 MM |
1099 | tree t; |
1100 | ||
35b1567d BC |
1101 | if (cv_qualifier != NULL_TREE |
1102 | && cv_qualifier != ridpointers[(int) RID_VOLATILE]) | |
1103 | { | |
33bd39a2 | 1104 | warning ("%s qualifier ignored on asm", |
35b1567d BC |
1105 | IDENTIFIER_POINTER (cv_qualifier)); |
1106 | cv_qualifier = NULL_TREE; | |
ad321293 | 1107 | } |
35b1567d | 1108 | |
abfc8a36 | 1109 | if (!processing_template_decl) |
40b18c0a MM |
1110 | { |
1111 | int i; | |
1112 | int ninputs; | |
1113 | int noutputs; | |
1114 | ||
1115 | for (t = input_operands; t; t = TREE_CHAIN (t)) | |
1116 | { | |
1117 | tree converted_operand | |
1118 | = decay_conversion (TREE_VALUE (t)); | |
1119 | ||
1120 | /* If the type of the operand hasn't been determined (e.g., | |
1121 | because it involves an overloaded function), then issue | |
1122 | an error message. There's no context available to | |
1123 | resolve the overloading. */ | |
1124 | if (TREE_TYPE (converted_operand) == unknown_type_node) | |
1125 | { | |
33bd39a2 | 1126 | error ("type of asm operand `%E' could not be determined", |
40b18c0a MM |
1127 | TREE_VALUE (t)); |
1128 | converted_operand = error_mark_node; | |
1129 | } | |
1130 | TREE_VALUE (t) = converted_operand; | |
1131 | } | |
1132 | ||
1133 | ninputs = list_length (input_operands); | |
1134 | noutputs = list_length (output_operands); | |
1135 | ||
1136 | for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i) | |
1137 | { | |
1138 | bool allows_mem; | |
1139 | bool allows_reg; | |
1140 | bool is_inout; | |
1141 | const char *constraint; | |
1142 | tree operand; | |
1143 | ||
84b72302 | 1144 | constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); |
28c56d25 | 1145 | operand = TREE_VALUE (t); |
40b18c0a MM |
1146 | |
1147 | if (!parse_output_constraint (&constraint, | |
1148 | i, ninputs, noutputs, | |
1149 | &allows_mem, | |
1150 | &allows_reg, | |
1151 | &is_inout)) | |
1152 | { | |
a723baf1 MM |
1153 | /* By marking this operand as erroneous, we will not try |
1154 | to process this operand again in expand_asm_operands. */ | |
1155 | TREE_VALUE (t) = error_mark_node; | |
40b18c0a MM |
1156 | continue; |
1157 | } | |
1158 | ||
1159 | /* If the operand is a DECL that is going to end up in | |
1160 | memory, assume it is addressable. This is a bit more | |
1161 | conservative than it would ideally be; the exact test is | |
1162 | buried deep in expand_asm_operands and depends on the | |
1163 | DECL_RTL for the OPERAND -- which we don't have at this | |
1164 | point. */ | |
1165 | if (!allows_reg && DECL_P (operand)) | |
dffd7eb6 | 1166 | cxx_mark_addressable (operand); |
40b18c0a MM |
1167 | } |
1168 | } | |
abfc8a36 | 1169 | |
0dfdeca6 BC |
1170 | r = build_stmt (ASM_STMT, cv_qualifier, string, |
1171 | output_operands, input_operands, | |
1172 | clobbers); | |
3e4d04a1 | 1173 | return add_stmt (r); |
ad321293 | 1174 | } |
b4c4a9ec | 1175 | |
f01b0acb MM |
1176 | /* Finish a label with the indicated NAME. */ |
1177 | ||
a723baf1 | 1178 | tree |
f01b0acb MM |
1179 | finish_label_stmt (name) |
1180 | tree name; | |
1181 | { | |
d479d37f | 1182 | tree decl = define_label (input_filename, input_line, name); |
a723baf1 | 1183 | return add_stmt (build_stmt (LABEL_STMT, decl)); |
f01b0acb MM |
1184 | } |
1185 | ||
acef433b MM |
1186 | /* Finish a series of declarations for local labels. G++ allows users |
1187 | to declare "local" labels, i.e., labels with scope. This extension | |
1188 | is useful when writing code involving statement-expressions. */ | |
1189 | ||
1190 | void | |
1191 | finish_label_decl (name) | |
1192 | tree name; | |
1193 | { | |
1194 | tree decl = declare_local_label (name); | |
35b1567d | 1195 | add_decl_stmt (decl); |
acef433b MM |
1196 | } |
1197 | ||
659e5a7a | 1198 | /* When DECL goes out of scope, make sure that CLEANUP is executed. */ |
f1dedc31 MM |
1199 | |
1200 | void | |
659e5a7a JM |
1201 | finish_decl_cleanup (decl, cleanup) |
1202 | tree decl; | |
f1dedc31 MM |
1203 | tree cleanup; |
1204 | { | |
659e5a7a | 1205 | add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup)); |
35b1567d BC |
1206 | } |
1207 | ||
659e5a7a | 1208 | /* If the current scope exits with an exception, run CLEANUP. */ |
24bef158 | 1209 | |
659e5a7a JM |
1210 | void |
1211 | finish_eh_cleanup (cleanup) | |
24bef158 MM |
1212 | tree cleanup; |
1213 | { | |
659e5a7a JM |
1214 | tree r = build_stmt (CLEANUP_STMT, NULL_TREE, cleanup); |
1215 | CLEANUP_EH_ONLY (r) = 1; | |
1216 | add_stmt (r); | |
35b1567d BC |
1217 | } |
1218 | ||
2282d28d MM |
1219 | /* The MEM_INITS is a list of mem-initializers, in reverse of the |
1220 | order they were written by the user. Each node is as for | |
1221 | emit_mem_initializers. */ | |
bf3428d0 MM |
1222 | |
1223 | void | |
2282d28d | 1224 | finish_mem_initializers (tree mem_inits) |
bf3428d0 | 1225 | { |
2282d28d MM |
1226 | /* Reorder the MEM_INITS so that they are in the order they appeared |
1227 | in the source program. */ | |
1228 | mem_inits = nreverse (mem_inits); | |
bf3428d0 | 1229 | |
a0de9d20 | 1230 | if (processing_template_decl) |
2282d28d | 1231 | add_stmt (build_min_nt (CTOR_INITIALIZER, mem_inits)); |
cdd2559c | 1232 | else |
2282d28d | 1233 | emit_mem_initializers (mem_inits); |
558475f0 MM |
1234 | } |
1235 | ||
8f17b5c5 | 1236 | /* Returns the stack of SCOPE_STMTs for the current function. */ |
35b1567d | 1237 | |
8f17b5c5 MM |
1238 | tree * |
1239 | current_scope_stmt_stack () | |
8f471b0d | 1240 | { |
e2500fed | 1241 | return &cfun->language->base.x_scope_stmt_stack; |
8f471b0d MM |
1242 | } |
1243 | ||
b4c4a9ec MM |
1244 | /* Finish a parenthesized expression EXPR. */ |
1245 | ||
1246 | tree | |
1247 | finish_parenthesized_expr (expr) | |
1248 | tree expr; | |
1249 | { | |
1250 | if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr)))) | |
78ef5b89 | 1251 | /* This inhibits warnings in c_common_truthvalue_conversion. */ |
b4c4a9ec MM |
1252 | C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK); |
1253 | ||
19420d00 NS |
1254 | if (TREE_CODE (expr) == OFFSET_REF) |
1255 | /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be | |
1256 | enclosed in parentheses. */ | |
1257 | PTRMEM_OK_P (expr) = 0; | |
b4c4a9ec MM |
1258 | return expr; |
1259 | } | |
1260 | ||
a723baf1 MM |
1261 | /* Finish a reference to a non-static data member (DECL) that is not |
1262 | preceded by `.' or `->'. */ | |
1263 | ||
1264 | tree | |
1265 | finish_non_static_data_member (tree decl, tree qualifying_scope) | |
1266 | { | |
1267 | my_friendly_assert (TREE_CODE (decl) == FIELD_DECL, 20020909); | |
1268 | ||
1269 | if (current_class_ptr == NULL_TREE) | |
1270 | { | |
1271 | if (current_function_decl | |
1272 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
1273 | cp_error_at ("invalid use of member `%D' in static member function", | |
1274 | decl); | |
1275 | else | |
1276 | cp_error_at ("invalid use of non-static data member `%D'", decl); | |
1277 | error ("from this location"); | |
1278 | ||
1279 | return error_mark_node; | |
1280 | } | |
1281 | TREE_USED (current_class_ptr) = 1; | |
1282 | if (processing_template_decl) | |
bbaab916 NS |
1283 | return build_min (COMPONENT_REF, TREE_TYPE (decl), |
1284 | current_class_ref, DECL_NAME (decl)); | |
a723baf1 MM |
1285 | else |
1286 | { | |
1287 | tree access_type = current_class_type; | |
1288 | tree object = current_class_ref; | |
1289 | ||
9f01ded6 KL |
1290 | while (access_type |
1291 | && !DERIVED_FROM_P (context_for_name_lookup (decl), access_type)) | |
a723baf1 MM |
1292 | { |
1293 | access_type = TYPE_CONTEXT (access_type); | |
9f01ded6 | 1294 | while (access_type && DECL_P (access_type)) |
a723baf1 MM |
1295 | access_type = DECL_CONTEXT (access_type); |
1296 | } | |
1297 | ||
9f01ded6 KL |
1298 | if (!access_type) |
1299 | { | |
1300 | cp_error_at ("object missing in reference to `%D'", | |
1301 | decl); | |
1302 | error ("from this location"); | |
1303 | return error_mark_node; | |
1304 | } | |
1305 | ||
78757caa | 1306 | perform_or_defer_access_check (access_type, decl); |
a723baf1 MM |
1307 | |
1308 | /* If the data member was named `C::M', convert `*this' to `C' | |
1309 | first. */ | |
1310 | if (qualifying_scope) | |
1311 | { | |
1312 | tree binfo = NULL_TREE; | |
1313 | object = build_scoped_ref (object, qualifying_scope, | |
1314 | &binfo); | |
1315 | } | |
1316 | ||
1317 | return build_class_member_access_expr (object, decl, | |
1318 | /*access_path=*/NULL_TREE, | |
1319 | /*preserve_reference=*/false); | |
1320 | } | |
1321 | } | |
1322 | ||
b69b1501 MM |
1323 | /* Begin a statement-expression. The value returned must be passed to |
1324 | finish_stmt_expr. */ | |
b4c4a9ec MM |
1325 | |
1326 | tree | |
1327 | begin_stmt_expr () | |
1328 | { | |
6f80451c MM |
1329 | /* If we're outside a function, we won't have a statement-tree to |
1330 | work with. But, if we see a statement-expression we need to | |
1331 | create one. */ | |
01d939e8 | 1332 | if (! cfun && !last_tree) |
6f80451c MM |
1333 | begin_stmt_tree (&scope_chain->x_saved_tree); |
1334 | ||
f1dedc31 | 1335 | keep_next_level (1); |
558475f0 | 1336 | /* If we're building a statement tree, then the upcoming compound |
b69b1501 MM |
1337 | statement will be chained onto the tree structure, starting at |
1338 | last_tree. We return last_tree so that we can later unhook the | |
1339 | compound statement. */ | |
35b1567d BC |
1340 | return last_tree; |
1341 | } | |
1342 | ||
596fd31c MM |
1343 | /* Used when beginning a statement-expression outside function scope. |
1344 | For example, when handling a file-scope initializer, we use this | |
1345 | function. */ | |
35b1567d | 1346 | |
596fd31c MM |
1347 | tree |
1348 | begin_global_stmt_expr () | |
35b1567d | 1349 | { |
596fd31c MM |
1350 | if (! cfun && !last_tree) |
1351 | begin_stmt_tree (&scope_chain->x_saved_tree); | |
35b1567d | 1352 | |
596fd31c MM |
1353 | keep_next_level (1); |
1354 | ||
b2123dc0 | 1355 | return last_tree ? last_tree : expand_start_stmt_expr(/*has_scope=*/1); |
596fd31c MM |
1356 | } |
1357 | ||
1358 | /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */ | |
1359 | ||
1360 | tree | |
1361 | finish_global_stmt_expr (stmt_expr) | |
1362 | tree stmt_expr; | |
1363 | { | |
1364 | stmt_expr = expand_end_stmt_expr (stmt_expr); | |
35b1567d BC |
1365 | |
1366 | if (! cfun | |
1367 | && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE) | |
1368 | finish_stmt_tree (&scope_chain->x_saved_tree); | |
1369 | ||
596fd31c | 1370 | return stmt_expr; |
b4c4a9ec MM |
1371 | } |
1372 | ||
1373 | /* Finish a statement-expression. RTL_EXPR should be the value | |
1374 | returned by the previous begin_stmt_expr; EXPR is the | |
1375 | statement-expression. Returns an expression representing the | |
1376 | statement-expression. */ | |
1377 | ||
1378 | tree | |
5ba57b55 | 1379 | finish_stmt_expr (rtl_expr) |
b4c4a9ec | 1380 | tree rtl_expr; |
b4c4a9ec MM |
1381 | { |
1382 | tree result; | |
1383 | ||
35b1567d BC |
1384 | /* If the last thing in the statement-expression was not an |
1385 | expression-statement, then it has type `void'. */ | |
1386 | if (!last_expr_type) | |
1387 | last_expr_type = void_type_node; | |
1388 | result = build_min (STMT_EXPR, last_expr_type, last_tree); | |
1389 | TREE_SIDE_EFFECTS (result) = 1; | |
1390 | ||
1391 | /* Remove the compound statement from the tree structure; it is | |
1392 | now saved in the STMT_EXPR. */ | |
ae499cce | 1393 | last_tree = rtl_expr; |
35b1567d | 1394 | TREE_CHAIN (last_tree) = NULL_TREE; |
f1dedc31 | 1395 | |
6f80451c MM |
1396 | /* If we created a statement-tree for this statement-expression, |
1397 | remove it now. */ | |
01d939e8 | 1398 | if (! cfun |
6f80451c MM |
1399 | && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE) |
1400 | finish_stmt_tree (&scope_chain->x_saved_tree); | |
1401 | ||
b4c4a9ec MM |
1402 | return result; |
1403 | } | |
1404 | ||
4ba126e4 MM |
1405 | /* Generate an expression for `FN (ARGS)'. |
1406 | ||
1407 | If DISALLOW_VIRTUAL is true, the call to FN will be not generated | |
1408 | as a virtual call, even if FN is virtual. (This flag is set when | |
1409 | encountering an expression where the function name is explicitly | |
1410 | qualified. For example a call to `X::f' never generates a virtual | |
1411 | call.) | |
1412 | ||
1413 | Returns code for the call. */ | |
b4c4a9ec MM |
1414 | |
1415 | tree | |
4ba126e4 | 1416 | finish_call_expr (tree fn, tree args, bool disallow_virtual) |
b4c4a9ec | 1417 | { |
4ba126e4 MM |
1418 | if (fn == error_mark_node || args == error_mark_node) |
1419 | return error_mark_node; | |
1420 | ||
1421 | if (processing_template_decl) | |
1422 | return build_nt (CALL_EXPR, fn, args, NULL_TREE); | |
1423 | ||
1424 | /* ARGS should be a list of arguments. */ | |
1425 | my_friendly_assert (!args || TREE_CODE (args) == TREE_LIST, | |
1426 | 20020712); | |
a759e627 | 1427 | |
a723baf1 MM |
1428 | /* A reference to a member function will appear as an overloaded |
1429 | function (rather than a BASELINK) if an unqualified name was used | |
1430 | to refer to it. */ | |
1431 | if (!BASELINK_P (fn) && is_overloaded_fn (fn)) | |
1432 | { | |
1433 | tree f; | |
1434 | ||
1435 | if (TREE_CODE (fn) == TEMPLATE_ID_EXPR) | |
1436 | f = get_first_fn (TREE_OPERAND (fn, 0)); | |
1437 | else | |
1438 | f = get_first_fn (fn); | |
1439 | if (DECL_FUNCTION_MEMBER_P (f)) | |
1440 | { | |
1441 | tree type = currently_open_derived_class (DECL_CONTEXT (f)); | |
1442 | fn = build_baselink (TYPE_BINFO (type), | |
1443 | TYPE_BINFO (type), | |
1444 | fn, /*optype=*/NULL_TREE); | |
1445 | } | |
1446 | } | |
1447 | ||
4ba126e4 | 1448 | if (BASELINK_P (fn)) |
03d82991 | 1449 | { |
4ba126e4 MM |
1450 | tree object; |
1451 | ||
1452 | /* A call to a member function. From [over.call.func]: | |
1453 | ||
1454 | If the keyword this is in scope and refers to the class of | |
1455 | that member function, or a derived class thereof, then the | |
1456 | function call is transformed into a qualified function call | |
1457 | using (*this) as the postfix-expression to the left of the | |
1458 | . operator.... [Otherwise] a contrived object of type T | |
1459 | becomes the implied object argument. | |
1460 | ||
1461 | This paragraph is unclear about this situation: | |
1462 | ||
1463 | struct A { void f(); }; | |
1464 | struct B : public A {}; | |
1465 | struct C : public A { void g() { B::f(); }}; | |
1466 | ||
1467 | In particular, for `B::f', this paragraph does not make clear | |
1468 | whether "the class of that member function" refers to `A' or | |
1469 | to `B'. We believe it refers to `B'. */ | |
1470 | if (current_class_type | |
1471 | && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), | |
1472 | current_class_type) | |
1473 | && current_class_ref) | |
1474 | object = current_class_ref; | |
1475 | else | |
1476 | { | |
1477 | tree representative_fn; | |
b4c4a9ec | 1478 | |
4ba126e4 MM |
1479 | representative_fn = BASELINK_FUNCTIONS (fn); |
1480 | if (TREE_CODE (representative_fn) == TEMPLATE_ID_EXPR) | |
1481 | representative_fn = TREE_OPERAND (representative_fn, 0); | |
1482 | representative_fn = get_first_fn (representative_fn); | |
1483 | object = build_dummy_object (DECL_CONTEXT (representative_fn)); | |
1484 | } | |
b4c4a9ec | 1485 | |
4ba126e4 MM |
1486 | return build_new_method_call (object, fn, args, NULL_TREE, |
1487 | (disallow_virtual | |
1488 | ? LOOKUP_NONVIRTUAL : 0)); | |
1489 | } | |
1490 | else if (is_overloaded_fn (fn)) | |
1491 | /* A call to a namespace-scope function. */ | |
1492 | return build_new_function_call (fn, args); | |
a723baf1 MM |
1493 | else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR) |
1494 | { | |
1495 | tree result; | |
1496 | ||
1497 | if (args) | |
1498 | error ("arguments to destructor are not allowed"); | |
1499 | /* Mark the pseudo-destructor call as having side-effects so | |
1500 | that we do not issue warnings about its use. */ | |
1501 | result = build1 (NOP_EXPR, | |
1502 | void_type_node, | |
1503 | TREE_OPERAND (fn, 0)); | |
1504 | TREE_SIDE_EFFECTS (result) = 1; | |
1505 | return result; | |
1506 | } | |
4ba126e4 MM |
1507 | else if (CLASS_TYPE_P (TREE_TYPE (fn))) |
1508 | { | |
1509 | /* If the "function" is really an object of class type, it might | |
1510 | have an overloaded `operator ()'. */ | |
1511 | tree result; | |
14d22dd6 | 1512 | result = build_new_op (CALL_EXPR, LOOKUP_NORMAL, fn, args, NULL_TREE); |
4ba126e4 MM |
1513 | if (result) |
1514 | return result; | |
1515 | } | |
1516 | ||
1517 | /* A call where the function is unknown. */ | |
1518 | return build_function_call (fn, args); | |
b4c4a9ec MM |
1519 | } |
1520 | ||
1521 | /* Finish a call to a postfix increment or decrement or EXPR. (Which | |
1522 | is indicated by CODE, which should be POSTINCREMENT_EXPR or | |
1523 | POSTDECREMENT_EXPR.) */ | |
1524 | ||
1525 | tree | |
1526 | finish_increment_expr (expr, code) | |
1527 | tree expr; | |
1528 | enum tree_code code; | |
1529 | { | |
1530 | /* If we get an OFFSET_REF, turn it into what it really means (e.g., | |
1531 | a COMPONENT_REF). This way if we've got, say, a reference to a | |
1532 | static member that's being operated on, we don't end up trying to | |
1533 | find a member operator for the class it's in. */ | |
1534 | ||
1535 | if (TREE_CODE (expr) == OFFSET_REF) | |
1536 | expr = resolve_offset_ref (expr); | |
1537 | return build_x_unary_op (code, expr); | |
1538 | } | |
1539 | ||
1540 | /* Finish a use of `this'. Returns an expression for `this'. */ | |
1541 | ||
1542 | tree | |
1543 | finish_this_expr () | |
1544 | { | |
1545 | tree result; | |
1546 | ||
1547 | if (current_class_ptr) | |
1548 | { | |
b4c4a9ec MM |
1549 | result = current_class_ptr; |
1550 | } | |
1551 | else if (current_function_decl | |
1552 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
1553 | { | |
8251199e | 1554 | error ("`this' is unavailable for static member functions"); |
b4c4a9ec MM |
1555 | result = error_mark_node; |
1556 | } | |
1557 | else | |
1558 | { | |
1559 | if (current_function_decl) | |
8251199e | 1560 | error ("invalid use of `this' in non-member function"); |
b4c4a9ec | 1561 | else |
8251199e | 1562 | error ("invalid use of `this' at top level"); |
b4c4a9ec MM |
1563 | result = error_mark_node; |
1564 | } | |
1565 | ||
1566 | return result; | |
1567 | } | |
1568 | ||
1569 | /* Finish a member function call using OBJECT and ARGS as arguments to | |
1570 | FN. Returns an expression for the call. */ | |
1571 | ||
1572 | tree | |
1573 | finish_object_call_expr (fn, object, args) | |
1574 | tree fn; | |
1575 | tree object; | |
1576 | tree args; | |
1577 | { | |
c219b878 | 1578 | if (DECL_DECLARES_TYPE_P (fn)) |
c68c56f7 MM |
1579 | { |
1580 | if (processing_template_decl) | |
1581 | /* This can happen on code like: | |
1582 | ||
1583 | class X; | |
1584 | template <class T> void f(T t) { | |
1585 | t.X(); | |
1586 | } | |
1587 | ||
1588 | We just grab the underlying IDENTIFIER. */ | |
1589 | fn = DECL_NAME (fn); | |
1590 | else | |
1591 | { | |
33bd39a2 | 1592 | error ("calling type `%T' like a method", fn); |
c68c56f7 MM |
1593 | return error_mark_node; |
1594 | } | |
1595 | } | |
4ba126e4 | 1596 | |
a723baf1 MM |
1597 | if (processing_template_decl) |
1598 | return build_nt (CALL_EXPR, | |
1599 | build_nt (COMPONENT_REF, object, fn), | |
1600 | args); | |
1601 | ||
50ad9642 MM |
1602 | if (name_p (fn)) |
1603 | return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL); | |
1604 | else | |
1605 | return build_new_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL); | |
b4c4a9ec MM |
1606 | } |
1607 | ||
1608 | /* Finish a qualified member function call using OBJECT and ARGS as | |
509fc277 | 1609 | arguments to FN. Returns an expression for the call. */ |
b4c4a9ec MM |
1610 | |
1611 | tree | |
1612 | finish_qualified_object_call_expr (fn, object, args) | |
1613 | tree fn; | |
1614 | tree object; | |
1615 | tree args; | |
1616 | { | |
6eabb241 MM |
1617 | return build_scoped_method_call (object, TREE_OPERAND (fn, 0), |
1618 | TREE_OPERAND (fn, 1), args); | |
b4c4a9ec MM |
1619 | } |
1620 | ||
a723baf1 MM |
1621 | /* Finish a pseudo-destructor expression. If SCOPE is NULL, the |
1622 | expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is | |
1623 | the TYPE for the type given. If SCOPE is non-NULL, the expression | |
1624 | was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */ | |
b4c4a9ec MM |
1625 | |
1626 | tree | |
a723baf1 | 1627 | finish_pseudo_destructor_expr (object, scope, destructor) |
b4c4a9ec MM |
1628 | tree object; |
1629 | tree scope; | |
1630 | tree destructor; | |
1631 | { | |
a723baf1 MM |
1632 | if (destructor == error_mark_node) |
1633 | return error_mark_node; | |
40242ccf | 1634 | |
a723baf1 | 1635 | my_friendly_assert (TYPE_P (destructor), 20010905); |
b4c4a9ec | 1636 | |
a723baf1 MM |
1637 | if (!processing_template_decl) |
1638 | { | |
1639 | if (scope == error_mark_node) | |
1640 | { | |
1641 | error ("invalid qualifying scope in pseudo-destructor name"); | |
1642 | return error_mark_node; | |
1643 | } | |
1644 | ||
1645 | if (!same_type_p (TREE_TYPE (object), destructor)) | |
1646 | { | |
1647 | error ("`%E' is not of type `%T'", object, destructor); | |
1648 | return error_mark_node; | |
1649 | } | |
1650 | } | |
b4c4a9ec | 1651 | |
a723baf1 | 1652 | return build (PSEUDO_DTOR_EXPR, void_type_node, object, scope, destructor); |
b4c4a9ec MM |
1653 | } |
1654 | ||
ce4a0391 MM |
1655 | /* Finish an expression of the form CODE EXPR. */ |
1656 | ||
1657 | tree | |
1658 | finish_unary_op_expr (code, expr) | |
1659 | enum tree_code code; | |
1660 | tree expr; | |
1661 | { | |
1662 | tree result = build_x_unary_op (code, expr); | |
7c355bca ML |
1663 | /* Inside a template, build_x_unary_op does not fold the |
1664 | expression. So check whether the result is folded before | |
1665 | setting TREE_NEGATED_INT. */ | |
1666 | if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST | |
88b4335f NS |
1667 | && TREE_CODE (result) == INTEGER_CST |
1668 | && !TREE_UNSIGNED (TREE_TYPE (result)) | |
1669 | && INT_CST_LT (result, integer_zero_node)) | |
ce4a0391 MM |
1670 | TREE_NEGATED_INT (result) = 1; |
1671 | overflow_warning (result); | |
1672 | return result; | |
1673 | } | |
1674 | ||
a723baf1 MM |
1675 | /* Finish a compound-literal expression. TYPE is the type to which |
1676 | the INITIALIZER_LIST is being cast. */ | |
1677 | ||
1678 | tree | |
1679 | finish_compound_literal (type, initializer_list) | |
1680 | tree type; | |
1681 | tree initializer_list; | |
1682 | { | |
1683 | tree compound_literal; | |
1684 | ||
1685 | /* Build a CONSTRUCTOR for the INITIALIZER_LIST. */ | |
dcf92453 | 1686 | compound_literal = build_constructor (NULL_TREE, initializer_list); |
a723baf1 MM |
1687 | /* Mark it as a compound-literal. */ |
1688 | TREE_HAS_CONSTRUCTOR (compound_literal) = 1; | |
1689 | if (processing_template_decl) | |
1690 | TREE_TYPE (compound_literal) = type; | |
1691 | else | |
1692 | { | |
1693 | /* Check the initialization. */ | |
1694 | compound_literal = digest_init (type, compound_literal, NULL); | |
1695 | /* If the TYPE was an array type with an unknown bound, then we can | |
1696 | figure out the dimension now. For example, something like: | |
1697 | ||
1698 | `(int []) { 2, 3 }' | |
1699 | ||
1700 | implies that the array has two elements. */ | |
1701 | if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) | |
1702 | complete_array_type (type, compound_literal, 1); | |
1703 | } | |
1704 | ||
1705 | return compound_literal; | |
1706 | } | |
1707 | ||
5f261ba9 MM |
1708 | /* Return the declaration for the function-name variable indicated by |
1709 | ID. */ | |
1710 | ||
1711 | tree | |
1712 | finish_fname (tree id) | |
1713 | { | |
1714 | tree decl; | |
1715 | ||
1716 | decl = fname_decl (C_RID_CODE (id), id); | |
1717 | if (processing_template_decl) | |
1718 | decl = build_min_nt (LOOKUP_EXPR, DECL_NAME (decl)); | |
1719 | return decl; | |
1720 | } | |
1721 | ||
15c7fb9c | 1722 | /* Begin a function definition declared with DECL_SPECS, ATTRIBUTES, |
838dfd8a | 1723 | and DECLARATOR. Returns nonzero if the function-declaration is |
0e339752 | 1724 | valid. */ |
b4c4a9ec MM |
1725 | |
1726 | int | |
15c7fb9c | 1727 | begin_function_definition (decl_specs, attributes, declarator) |
b4c4a9ec | 1728 | tree decl_specs; |
15c7fb9c | 1729 | tree attributes; |
b4c4a9ec MM |
1730 | tree declarator; |
1731 | { | |
15c7fb9c | 1732 | if (!start_function (decl_specs, declarator, attributes, SF_DEFAULT)) |
b4c4a9ec | 1733 | return 0; |
1f51a992 | 1734 | |
39c01e4c MM |
1735 | /* The things we're about to see are not directly qualified by any |
1736 | template headers we've seen thus far. */ | |
1737 | reset_specialization (); | |
1738 | ||
b4c4a9ec MM |
1739 | return 1; |
1740 | } | |
1741 | ||
8014a339 | 1742 | /* Finish a translation unit. */ |
ce4a0391 MM |
1743 | |
1744 | void | |
1745 | finish_translation_unit () | |
1746 | { | |
1747 | /* In case there were missing closebraces, | |
1748 | get us back to the global binding level. */ | |
273a708f | 1749 | pop_everything (); |
ce4a0391 MM |
1750 | while (current_namespace != global_namespace) |
1751 | pop_namespace (); | |
0ba8a114 | 1752 | |
c6002625 | 1753 | /* Do file scope __FUNCTION__ et al. */ |
0ba8a114 | 1754 | finish_fname_decls (); |
ce4a0391 MM |
1755 | } |
1756 | ||
b4c4a9ec MM |
1757 | /* Finish a template type parameter, specified as AGGR IDENTIFIER. |
1758 | Returns the parameter. */ | |
1759 | ||
1760 | tree | |
1761 | finish_template_type_parm (aggr, identifier) | |
1762 | tree aggr; | |
1763 | tree identifier; | |
1764 | { | |
6eabb241 | 1765 | if (aggr != class_type_node) |
b4c4a9ec | 1766 | { |
8251199e | 1767 | pedwarn ("template type parameters must use the keyword `class' or `typename'"); |
b4c4a9ec MM |
1768 | aggr = class_type_node; |
1769 | } | |
1770 | ||
1771 | return build_tree_list (aggr, identifier); | |
1772 | } | |
1773 | ||
1774 | /* Finish a template template parameter, specified as AGGR IDENTIFIER. | |
1775 | Returns the parameter. */ | |
1776 | ||
1777 | tree | |
1778 | finish_template_template_parm (aggr, identifier) | |
1779 | tree aggr; | |
1780 | tree identifier; | |
1781 | { | |
1782 | tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE); | |
1783 | tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); | |
1784 | DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; | |
1785 | DECL_TEMPLATE_RESULT (tmpl) = decl; | |
c727aa5e | 1786 | DECL_ARTIFICIAL (decl) = 1; |
b4c4a9ec MM |
1787 | end_template_decl (); |
1788 | ||
b37bf5bd NS |
1789 | my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110); |
1790 | ||
b4c4a9ec MM |
1791 | return finish_template_type_parm (aggr, tmpl); |
1792 | } | |
ce4a0391 | 1793 | |
8ba658ee MM |
1794 | /* ARGUMENT is the default-argument value for a template template |
1795 | parameter. If ARGUMENT is invalid, issue error messages and return | |
1796 | the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */ | |
1797 | ||
1798 | tree | |
1799 | check_template_template_default_arg (tree argument) | |
1800 | { | |
1801 | if (TREE_CODE (argument) != TEMPLATE_DECL | |
1802 | && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM | |
1803 | && TREE_CODE (argument) != TYPE_DECL | |
1804 | && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) | |
1805 | { | |
1806 | error ("invalid default template argument"); | |
1807 | return error_mark_node; | |
1808 | } | |
1809 | ||
1810 | return argument; | |
1811 | } | |
1812 | ||
ce4a0391 | 1813 | /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is |
838dfd8a | 1814 | nonzero, the parameter list was terminated by a `...'. */ |
ce4a0391 MM |
1815 | |
1816 | tree | |
1817 | finish_parmlist (parms, ellipsis) | |
1818 | tree parms; | |
1819 | int ellipsis; | |
1820 | { | |
5cce22b6 NS |
1821 | if (parms) |
1822 | { | |
1823 | /* We mark the PARMS as a parmlist so that declarator processing can | |
1824 | disambiguate certain constructs. */ | |
1825 | TREE_PARMLIST (parms) = 1; | |
1826 | /* We do not append void_list_node here, but leave it to grokparms | |
1827 | to do that. */ | |
1828 | PARMLIST_ELLIPSIS_P (parms) = ellipsis; | |
1829 | } | |
ce4a0391 MM |
1830 | return parms; |
1831 | } | |
1832 | ||
1833 | /* Begin a class definition, as indicated by T. */ | |
1834 | ||
1835 | tree | |
1836 | begin_class_definition (t) | |
1837 | tree t; | |
1838 | { | |
7437519c ZW |
1839 | if (t == error_mark_node) |
1840 | return error_mark_node; | |
1841 | ||
522d6614 NS |
1842 | if (processing_template_parmlist) |
1843 | { | |
33bd39a2 | 1844 | error ("definition of `%#T' inside template parameter list", t); |
522d6614 NS |
1845 | return error_mark_node; |
1846 | } | |
47ee8904 MM |
1847 | /* A non-implicit typename comes from code like: |
1848 | ||
1849 | template <typename T> struct A { | |
1850 | template <typename U> struct A<T>::B ... | |
1851 | ||
1852 | This is erroneous. */ | |
1853 | else if (TREE_CODE (t) == TYPENAME_TYPE) | |
1854 | { | |
33bd39a2 | 1855 | error ("invalid definition of qualified type `%T'", t); |
47ee8904 MM |
1856 | t = error_mark_node; |
1857 | } | |
1858 | ||
1859 | if (t == error_mark_node || ! IS_AGGR_TYPE (t)) | |
ce4a0391 | 1860 | { |
33848bb0 | 1861 | t = make_aggr_type (RECORD_TYPE); |
ce4a0391 MM |
1862 | pushtag (make_anon_name (), t, 0); |
1863 | } | |
830fcda8 | 1864 | |
4c571114 MM |
1865 | /* If this type was already complete, and we see another definition, |
1866 | that's an error. */ | |
8fbc5ae7 | 1867 | if (COMPLETE_TYPE_P (t)) |
4223f82f MM |
1868 | { |
1869 | error ("redefinition of `%#T'", t); | |
1870 | cp_error_at ("previous definition of `%#T'", t); | |
1871 | return error_mark_node; | |
1872 | } | |
4c571114 | 1873 | |
b4f70b3d | 1874 | /* Update the location of the decl. */ |
82a98427 | 1875 | DECL_SOURCE_LOCATION (TYPE_NAME (t)) = input_location; |
b4f70b3d | 1876 | |
4c571114 | 1877 | if (TYPE_BEING_DEFINED (t)) |
ce4a0391 | 1878 | { |
33848bb0 | 1879 | t = make_aggr_type (TREE_CODE (t)); |
ce4a0391 | 1880 | pushtag (TYPE_IDENTIFIER (t), t, 0); |
ce4a0391 | 1881 | } |
ff350acd | 1882 | maybe_process_partial_specialization (t); |
14d22dd6 | 1883 | pushclass (t, true); |
ce4a0391 | 1884 | TYPE_BEING_DEFINED (t) = 1; |
55760a0c | 1885 | TYPE_PACKED (t) = flag_pack_struct; |
ce4a0391 MM |
1886 | /* Reset the interface data, at the earliest possible |
1887 | moment, as it might have been set via a class foo; | |
1888 | before. */ | |
1951a1b6 JM |
1889 | if (! TYPE_ANONYMOUS_P (t)) |
1890 | { | |
1891 | CLASSTYPE_INTERFACE_ONLY (t) = interface_only; | |
1892 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X | |
1893 | (t, interface_unknown); | |
1894 | } | |
ce4a0391 MM |
1895 | reset_specialization(); |
1896 | ||
b7975aed MM |
1897 | /* Make a declaration for this class in its own scope. */ |
1898 | build_self_reference (); | |
1899 | ||
830fcda8 | 1900 | return t; |
ce4a0391 MM |
1901 | } |
1902 | ||
61a127b3 MM |
1903 | /* Finish the member declaration given by DECL. */ |
1904 | ||
1905 | void | |
1906 | finish_member_declaration (decl) | |
1907 | tree decl; | |
1908 | { | |
1909 | if (decl == error_mark_node || decl == NULL_TREE) | |
1910 | return; | |
1911 | ||
1912 | if (decl == void_type_node) | |
1913 | /* The COMPONENT was a friend, not a member, and so there's | |
1914 | nothing for us to do. */ | |
1915 | return; | |
1916 | ||
1917 | /* We should see only one DECL at a time. */ | |
1918 | my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0); | |
1919 | ||
1920 | /* Set up access control for DECL. */ | |
1921 | TREE_PRIVATE (decl) | |
1922 | = (current_access_specifier == access_private_node); | |
1923 | TREE_PROTECTED (decl) | |
1924 | = (current_access_specifier == access_protected_node); | |
1925 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
1926 | { | |
17aec3eb RK |
1927 | TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl); |
1928 | TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl); | |
61a127b3 MM |
1929 | } |
1930 | ||
1931 | /* Mark the DECL as a member of the current class. */ | |
4f1c5b7d | 1932 | DECL_CONTEXT (decl) = current_class_type; |
61a127b3 | 1933 | |
421844e7 MM |
1934 | /* [dcl.link] |
1935 | ||
1936 | A C language linkage is ignored for the names of class members | |
1937 | and the member function type of class member functions. */ | |
1938 | if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c) | |
5d2ed28c | 1939 | SET_DECL_LANGUAGE (decl, lang_cplusplus); |
421844e7 | 1940 | |
7088fca9 KL |
1941 | maybe_add_class_template_decl_list (current_class_type, decl, /*friend_p=*/0); |
1942 | ||
61a127b3 MM |
1943 | /* Put functions on the TYPE_METHODS list and everything else on the |
1944 | TYPE_FIELDS list. Note that these are built up in reverse order. | |
1945 | We reverse them (to obtain declaration order) in finish_struct. */ | |
1946 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1947 | || DECL_FUNCTION_TEMPLATE_P (decl)) | |
1948 | { | |
1949 | /* We also need to add this function to the | |
1950 | CLASSTYPE_METHOD_VEC. */ | |
452a394b | 1951 | add_method (current_class_type, decl, /*error_p=*/0); |
61a127b3 MM |
1952 | |
1953 | TREE_CHAIN (decl) = TYPE_METHODS (current_class_type); | |
1954 | TYPE_METHODS (current_class_type) = decl; | |
1955 | } | |
1956 | else | |
1957 | { | |
1958 | /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields | |
1959 | go at the beginning. The reason is that lookup_field_1 | |
1960 | searches the list in order, and we want a field name to | |
1961 | override a type name so that the "struct stat hack" will | |
1962 | work. In particular: | |
1963 | ||
1964 | struct S { enum E { }; int E } s; | |
1965 | s.E = 3; | |
1966 | ||
0e339752 | 1967 | is valid. In addition, the FIELD_DECLs must be maintained in |
61a127b3 MM |
1968 | declaration order so that class layout works as expected. |
1969 | However, we don't need that order until class layout, so we | |
1970 | save a little time by putting FIELD_DECLs on in reverse order | |
1971 | here, and then reversing them in finish_struct_1. (We could | |
1972 | also keep a pointer to the correct insertion points in the | |
1973 | list.) */ | |
1974 | ||
1975 | if (TREE_CODE (decl) == TYPE_DECL) | |
1976 | TYPE_FIELDS (current_class_type) | |
1977 | = chainon (TYPE_FIELDS (current_class_type), decl); | |
1978 | else | |
1979 | { | |
1980 | TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type); | |
1981 | TYPE_FIELDS (current_class_type) = decl; | |
1982 | } | |
8f032717 MM |
1983 | |
1984 | /* Enter the DECL into the scope of the class. */ | |
1985 | if (TREE_CODE (decl) != USING_DECL) | |
1986 | pushdecl_class_level (decl); | |
61a127b3 MM |
1987 | } |
1988 | } | |
1989 | ||
1990 | /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI, | |
1991 | the definition is immediately followed by a semicolon. Returns the | |
1992 | type. */ | |
ce4a0391 MM |
1993 | |
1994 | tree | |
fbdd0024 | 1995 | finish_class_definition (t, attributes, semi, pop_scope_p) |
ce4a0391 | 1996 | tree t; |
ce4a0391 MM |
1997 | tree attributes; |
1998 | int semi; | |
fbdd0024 | 1999 | int pop_scope_p; |
ce4a0391 | 2000 | { |
7437519c ZW |
2001 | if (t == error_mark_node) |
2002 | return error_mark_node; | |
2003 | ||
ce4a0391 MM |
2004 | /* finish_struct nukes this anyway; if finish_exception does too, |
2005 | then it can go. */ | |
2006 | if (semi) | |
2007 | note_got_semicolon (t); | |
2008 | ||
dc8263bc JM |
2009 | /* If we got any attributes in class_head, xref_tag will stick them in |
2010 | TREE_TYPE of the type. Grab them now. */ | |
a588fe25 JM |
2011 | attributes = chainon (TYPE_ATTRIBUTES (t), attributes); |
2012 | TYPE_ATTRIBUTES (t) = NULL_TREE; | |
dc8263bc | 2013 | |
ce4a0391 MM |
2014 | if (TREE_CODE (t) == ENUMERAL_TYPE) |
2015 | ; | |
2016 | else | |
2017 | { | |
9f33663b | 2018 | t = finish_struct (t, attributes); |
ce4a0391 MM |
2019 | if (semi) |
2020 | note_got_semicolon (t); | |
2021 | } | |
2022 | ||
fbdd0024 MM |
2023 | if (pop_scope_p) |
2024 | pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t))); | |
ce4a0391 MM |
2025 | |
2026 | return t; | |
2027 | } | |
2028 | ||
35acd3f2 MM |
2029 | /* Finish processing the declaration of a member class template |
2030 | TYPES whose template parameters are given by PARMS. */ | |
2031 | ||
2032 | tree | |
61a127b3 | 2033 | finish_member_class_template (types) |
35acd3f2 MM |
2034 | tree types; |
2035 | { | |
36a117a5 MM |
2036 | tree t; |
2037 | ||
2038 | /* If there are declared, but undefined, partial specializations | |
2039 | mixed in with the typespecs they will not yet have passed through | |
2040 | maybe_process_partial_specialization, so we do that here. */ | |
2041 | for (t = types; t != NULL_TREE; t = TREE_CHAIN (t)) | |
2042 | if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t)))) | |
2043 | maybe_process_partial_specialization (TREE_VALUE (t)); | |
2044 | ||
35acd3f2 | 2045 | note_list_got_semicolon (types); |
61a127b3 | 2046 | grok_x_components (types); |
35acd3f2 MM |
2047 | if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type) |
2048 | /* The component was in fact a friend declaration. We avoid | |
2049 | finish_member_template_decl performing certain checks by | |
2050 | unsetting TYPES. */ | |
2051 | types = NULL_TREE; | |
61a127b3 MM |
2052 | |
2053 | finish_member_template_decl (types); | |
2054 | ||
35acd3f2 MM |
2055 | /* As with other component type declarations, we do |
2056 | not store the new DECL on the list of | |
2057 | component_decls. */ | |
2058 | return NULL_TREE; | |
2059 | } | |
36a117a5 | 2060 | |
306ef644 | 2061 | /* Finish processing a complete template declaration. The PARMS are |
36a117a5 MM |
2062 | the template parameters. */ |
2063 | ||
2064 | void | |
2065 | finish_template_decl (parms) | |
2066 | tree parms; | |
2067 | { | |
2068 | if (parms) | |
2069 | end_template_decl (); | |
2070 | else | |
2071 | end_specialization (); | |
2072 | } | |
2073 | ||
509fc277 | 2074 | /* Finish processing a template-id (which names a type) of the form |
36a117a5 | 2075 | NAME < ARGS >. Return the TYPE_DECL for the type named by the |
838dfd8a | 2076 | template-id. If ENTERING_SCOPE is nonzero we are about to enter |
36a117a5 MM |
2077 | the scope of template-id indicated. */ |
2078 | ||
2079 | tree | |
2080 | finish_template_type (name, args, entering_scope) | |
2081 | tree name; | |
2082 | tree args; | |
2083 | int entering_scope; | |
2084 | { | |
2085 | tree decl; | |
2086 | ||
2087 | decl = lookup_template_class (name, args, | |
f9c244b8 NS |
2088 | NULL_TREE, NULL_TREE, |
2089 | entering_scope, /*complain=*/1); | |
36a117a5 MM |
2090 | if (decl != error_mark_node) |
2091 | decl = TYPE_STUB_DECL (decl); | |
2092 | ||
2093 | return decl; | |
2094 | } | |
648f19f6 | 2095 | |
ea6021e8 MM |
2096 | /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. |
2097 | Return a TREE_LIST containing the ACCESS_SPECIFIER and the | |
2098 | BASE_CLASS, or NULL_TREE if an error occurred. The | |
aba649ba | 2099 | ACCESS_SPECIFIER is one of |
ea6021e8 MM |
2100 | access_{default,public,protected_private}[_virtual]_node.*/ |
2101 | ||
2102 | tree | |
dbbf88d1 | 2103 | finish_base_specifier (tree base, tree access, bool virtual_p) |
ea6021e8 | 2104 | { |
ea6021e8 MM |
2105 | tree result; |
2106 | ||
dbbf88d1 | 2107 | if (base == error_mark_node) |
acb044ee GDR |
2108 | { |
2109 | error ("invalid base-class specification"); | |
2110 | result = NULL_TREE; | |
2111 | } | |
dbbf88d1 | 2112 | else if (! is_aggr_type (base, 1)) |
ea6021e8 | 2113 | result = NULL_TREE; |
ea6021e8 | 2114 | else |
bb92901d | 2115 | { |
dbbf88d1 | 2116 | if (cp_type_quals (base) != 0) |
bb92901d | 2117 | { |
dbbf88d1 NS |
2118 | error ("base class `%T' has cv qualifiers", base); |
2119 | base = TYPE_MAIN_VARIANT (base); | |
bb92901d | 2120 | } |
dbbf88d1 NS |
2121 | result = build_tree_list (access, base); |
2122 | TREE_VIA_VIRTUAL (result) = virtual_p; | |
bb92901d | 2123 | } |
ea6021e8 MM |
2124 | |
2125 | return result; | |
2126 | } | |
61a127b3 MM |
2127 | |
2128 | /* Called when multiple declarators are processed. If that is not | |
2129 | premitted in this context, an error is issued. */ | |
2130 | ||
2131 | void | |
2132 | check_multiple_declarators () | |
2133 | { | |
2134 | /* [temp] | |
2135 | ||
2136 | In a template-declaration, explicit specialization, or explicit | |
2137 | instantiation the init-declarator-list in the declaration shall | |
2138 | contain at most one declarator. | |
2139 | ||
2140 | We don't just use PROCESSING_TEMPLATE_DECL for the first | |
0e339752 | 2141 | condition since that would disallow the perfectly valid code, |
61a127b3 | 2142 | like `template <class T> struct S { int i, j; };'. */ |
5f261ba9 | 2143 | if (at_function_scope_p ()) |
61a127b3 MM |
2144 | /* It's OK to write `template <class T> void f() { int i, j;}'. */ |
2145 | return; | |
2146 | ||
2147 | if (PROCESSING_REAL_TEMPLATE_DECL_P () | |
2148 | || processing_explicit_instantiation | |
2149 | || processing_specialization) | |
33bd39a2 | 2150 | error ("multiple declarators in template declaration"); |
61a127b3 MM |
2151 | } |
2152 | ||
0213a355 JM |
2153 | /* Implement the __typeof keyword: Return the type of EXPR, suitable for |
2154 | use as a type-specifier. */ | |
2155 | ||
b894fc05 JM |
2156 | tree |
2157 | finish_typeof (expr) | |
2158 | tree expr; | |
2159 | { | |
65a5559b MM |
2160 | tree type; |
2161 | ||
dffbbe80 | 2162 | if (type_dependent_expression_p (expr)) |
b894fc05 | 2163 | { |
65a5559b MM |
2164 | type = make_aggr_type (TYPEOF_TYPE); |
2165 | TYPE_FIELDS (type) = expr; | |
b894fc05 | 2166 | |
65a5559b | 2167 | return type; |
b894fc05 JM |
2168 | } |
2169 | ||
12fa82db MM |
2170 | if (TREE_CODE (expr) == OFFSET_REF) |
2171 | expr = resolve_offset_ref (expr); | |
2172 | ||
65a5559b MM |
2173 | type = TREE_TYPE (expr); |
2174 | ||
2175 | if (!type || type == unknown_type_node) | |
2176 | { | |
2177 | error ("type of `%E' is unknown", expr); | |
2178 | return error_mark_node; | |
2179 | } | |
2180 | ||
2181 | return type; | |
b894fc05 | 2182 | } |
558475f0 | 2183 | |
0213a355 JM |
2184 | /* Compute the value of the `sizeof' operator. */ |
2185 | ||
2186 | tree | |
2187 | finish_sizeof (t) | |
2188 | tree t; | |
2189 | { | |
fa72b064 | 2190 | return TYPE_P (t) ? cxx_sizeof (t) : expr_sizeof (t); |
0213a355 JM |
2191 | } |
2192 | ||
2193 | /* Implement the __alignof keyword: Return the minimum required | |
2194 | alignment of T, measured in bytes. */ | |
2195 | ||
2196 | tree | |
2197 | finish_alignof (t) | |
2198 | tree t; | |
2199 | { | |
2200 | if (processing_template_decl) | |
a723baf1 | 2201 | return build_min (ALIGNOF_EXPR, size_type_node, t); |
0213a355 | 2202 | |
fa72b064 | 2203 | return TYPE_P (t) ? cxx_alignof (t) : c_alignof_expr (t); |
0213a355 JM |
2204 | } |
2205 | ||
62409b39 MM |
2206 | /* Generate RTL for the statement T, and its substatements, and any |
2207 | other statements at its nesting level. */ | |
558475f0 | 2208 | |
54f7877c MM |
2209 | static void |
2210 | cp_expand_stmt (t) | |
558475f0 MM |
2211 | tree t; |
2212 | { | |
54f7877c | 2213 | switch (TREE_CODE (t)) |
62409b39 | 2214 | { |
54f7877c MM |
2215 | case TRY_BLOCK: |
2216 | genrtl_try_block (t); | |
2217 | break; | |
558475f0 | 2218 | |
52a11cbf RH |
2219 | case EH_SPEC_BLOCK: |
2220 | genrtl_eh_spec_block (t); | |
2221 | break; | |
2222 | ||
54f7877c MM |
2223 | case HANDLER: |
2224 | genrtl_handler (t); | |
2225 | break; | |
558475f0 | 2226 | |
9da99f7d NS |
2227 | case USING_STMT: |
2228 | break; | |
2229 | ||
54f7877c | 2230 | default: |
a98facb0 | 2231 | abort (); |
54f7877c MM |
2232 | break; |
2233 | } | |
558475f0 MM |
2234 | } |
2235 | ||
3eb24f73 MM |
2236 | /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs |
2237 | will equivalent CALL_EXPRs. */ | |
2238 | ||
2239 | static tree | |
2240 | simplify_aggr_init_exprs_r (tp, walk_subtrees, data) | |
2241 | tree *tp; | |
2242 | int *walk_subtrees ATTRIBUTE_UNUSED; | |
2243 | void *data ATTRIBUTE_UNUSED; | |
2244 | { | |
2245 | tree aggr_init_expr; | |
2246 | tree call_expr; | |
2247 | tree fn; | |
2248 | tree args; | |
2249 | tree slot; | |
2250 | tree type; | |
4977bab6 | 2251 | enum style_t { ctor, arg, pcc } style; |
3eb24f73 | 2252 | |
3eb24f73 | 2253 | aggr_init_expr = *tp; |
22e92ac3 MM |
2254 | /* We don't need to walk into types; there's nothing in a type that |
2255 | needs simplification. (And, furthermore, there are places we | |
2256 | actively don't want to go. For example, we don't want to wander | |
2257 | into the default arguments for a FUNCTION_DECL that appears in a | |
2258 | CALL_EXPR.) */ | |
2259 | if (TYPE_P (aggr_init_expr)) | |
2260 | { | |
2261 | *walk_subtrees = 0; | |
2262 | return NULL_TREE; | |
2263 | } | |
2264 | /* Only AGGR_INIT_EXPRs are interesting. */ | |
2265 | else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR) | |
3eb24f73 MM |
2266 | return NULL_TREE; |
2267 | ||
2268 | /* Form an appropriate CALL_EXPR. */ | |
2269 | fn = TREE_OPERAND (aggr_init_expr, 0); | |
2270 | args = TREE_OPERAND (aggr_init_expr, 1); | |
2271 | slot = TREE_OPERAND (aggr_init_expr, 2); | |
2272 | type = TREE_TYPE (aggr_init_expr); | |
4977bab6 | 2273 | |
3eb24f73 | 2274 | if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr)) |
4977bab6 ZW |
2275 | style = ctor; |
2276 | #ifdef PCC_STATIC_STRUCT_RETURN | |
2277 | else if (1) | |
2278 | style = pcc; | |
2279 | #endif | |
2280 | else if (TREE_ADDRESSABLE (type)) | |
2281 | style = arg; | |
2282 | else | |
2283 | /* We shouldn't build an AGGR_INIT_EXPR if we don't need any special | |
2284 | handling. See build_cplus_new. */ | |
2285 | abort (); | |
2286 | ||
2287 | if (style == ctor || style == arg) | |
3eb24f73 | 2288 | { |
4977bab6 ZW |
2289 | /* Pass the address of the slot. If this is a constructor, we |
2290 | replace the first argument; otherwise, we tack on a new one. */ | |
2291 | if (style == ctor) | |
2292 | args = TREE_CHAIN (args); | |
2293 | ||
dffd7eb6 | 2294 | cxx_mark_addressable (slot); |
b850de4f MM |
2295 | args = tree_cons (NULL_TREE, |
2296 | build1 (ADDR_EXPR, | |
2297 | build_pointer_type (TREE_TYPE (slot)), | |
2298 | slot), | |
4977bab6 | 2299 | args); |
3eb24f73 | 2300 | } |
4977bab6 | 2301 | |
b850de4f MM |
2302 | call_expr = build (CALL_EXPR, |
2303 | TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), | |
2304 | fn, args, NULL_TREE); | |
3eb24f73 MM |
2305 | TREE_SIDE_EFFECTS (call_expr) = 1; |
2306 | ||
4977bab6 | 2307 | if (style == arg) |
89ea02fb JM |
2308 | /* Tell the backend that we've added our return slot to the argument |
2309 | list. */ | |
2310 | CALL_EXPR_HAS_RETURN_SLOT_ADDR (call_expr) = 1; | |
4977bab6 | 2311 | else if (style == pcc) |
3eb24f73 | 2312 | { |
4977bab6 ZW |
2313 | /* If we're using the non-reentrant PCC calling convention, then we |
2314 | need to copy the returned value out of the static buffer into the | |
2315 | SLOT. */ | |
78757caa | 2316 | push_deferring_access_checks (dk_no_check); |
46af705a JDA |
2317 | call_expr = build_aggr_init (slot, call_expr, |
2318 | DIRECT_BIND | LOOKUP_ONLYCONVERTING); | |
78757caa | 2319 | pop_deferring_access_checks (); |
3eb24f73 | 2320 | } |
3eb24f73 | 2321 | |
4977bab6 ZW |
2322 | /* We want to use the value of the initialized location as the |
2323 | result. */ | |
2324 | call_expr = build (COMPOUND_EXPR, type, | |
2325 | call_expr, slot); | |
3eb24f73 MM |
2326 | |
2327 | /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */ | |
2328 | TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr); | |
2329 | *tp = call_expr; | |
2330 | ||
2331 | /* Keep iterating. */ | |
2332 | return NULL_TREE; | |
2333 | } | |
2334 | ||
31f8e4f3 MM |
2335 | /* Emit all thunks to FN that should be emitted when FN is emitted. */ |
2336 | ||
2337 | static void | |
2338 | emit_associated_thunks (fn) | |
2339 | tree fn; | |
2340 | { | |
2341 | /* When we use vcall offsets, we emit thunks with the virtual | |
2342 | functions to which they thunk. The whole point of vcall offsets | |
2343 | is so that you can know statically the entire set of thunks that | |
2344 | will ever be needed for a given virtual function, thereby | |
2345 | enabling you to output all the thunks with the function itself. */ | |
3461fba7 | 2346 | if (DECL_VIRTUAL_P (fn)) |
31f8e4f3 | 2347 | { |
bb5e8a7f | 2348 | tree thunk; |
4977bab6 | 2349 | |
bb5e8a7f | 2350 | for (thunk = DECL_THUNKS (fn); thunk; thunk = TREE_CHAIN (thunk)) |
4977bab6 ZW |
2351 | { |
2352 | use_thunk (thunk, /*emit_p=*/1); | |
2353 | if (DECL_RESULT_THUNK_P (thunk)) | |
2354 | { | |
2355 | tree probe; | |
2356 | ||
2357 | for (probe = DECL_THUNKS (thunk); | |
2358 | probe; probe = TREE_CHAIN (probe)) | |
2359 | use_thunk (probe, /*emit_p=*/1); | |
2360 | } | |
2361 | } | |
31f8e4f3 MM |
2362 | } |
2363 | } | |
2364 | ||
558475f0 MM |
2365 | /* Generate RTL for FN. */ |
2366 | ||
2367 | void | |
2368 | expand_body (fn) | |
2369 | tree fn; | |
2370 | { | |
82a98427 | 2371 | location_t saved_loc; |
367aa585 | 2372 | tree saved_function; |
558475f0 | 2373 | |
62409b39 MM |
2374 | /* When the parser calls us after finishing the body of a template |
2375 | function, we don't really want to expand the body. When we're | |
2376 | processing an in-class definition of an inline function, | |
2377 | PROCESSING_TEMPLATE_DECL will no longer be set here, so we have | |
2378 | to look at the function itself. */ | |
2379 | if (processing_template_decl | |
2380 | || (DECL_LANG_SPECIFIC (fn) | |
2381 | && DECL_TEMPLATE_INFO (fn) | |
2382 | && uses_template_parms (DECL_TI_ARGS (fn)))) | |
d658cd4c MM |
2383 | { |
2384 | /* Normally, collection only occurs in rest_of_compilation. So, | |
2385 | if we don't collect here, we never collect junk generated | |
2386 | during the processing of templates until we hit a | |
2387 | non-template function. */ | |
2388 | ggc_collect (); | |
2389 | return; | |
2390 | } | |
62409b39 | 2391 | |
3eb24f73 | 2392 | /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */ |
ee94fce6 MM |
2393 | walk_tree_without_duplicates (&DECL_SAVED_TREE (fn), |
2394 | simplify_aggr_init_exprs_r, | |
2395 | NULL); | |
3eb24f73 | 2396 | |
3461fba7 NS |
2397 | /* If this is a constructor or destructor body, we have to clone |
2398 | it. */ | |
db9b2174 MM |
2399 | if (maybe_clone_body (fn)) |
2400 | { | |
2401 | /* We don't want to process FN again, so pretend we've written | |
2402 | it out, even though we haven't. */ | |
2403 | TREE_ASM_WRITTEN (fn) = 1; | |
2404 | return; | |
2405 | } | |
2406 | ||
84df082b MM |
2407 | /* There's no reason to do any of the work here if we're only doing |
2408 | semantic analysis; this code just generates RTL. */ | |
2409 | if (flag_syntax_only) | |
2410 | return; | |
2411 | ||
21b0c6dc MM |
2412 | /* If possible, avoid generating RTL for this function. Instead, |
2413 | just record it as an inline function, and wait until end-of-file | |
2414 | to decide whether to write it out or not. */ | |
56e770bf MM |
2415 | if (/* We have to generate RTL if it's not an inline function. */ |
2416 | (DECL_INLINE (fn) || DECL_COMDAT (fn)) | |
4f8e1232 | 2417 | /* Or if we have to emit code for inline functions anyhow. */ |
21b0c6dc MM |
2418 | && !flag_keep_inline_functions |
2419 | /* Or if we actually have a reference to the function. */ | |
4f8e1232 | 2420 | && !DECL_NEEDED_P (fn)) |
21b0c6dc | 2421 | { |
21b0c6dc MM |
2422 | /* Set DECL_EXTERNAL so that assemble_external will be called as |
2423 | necessary. We'll clear it again in finish_file. */ | |
2424 | if (!DECL_EXTERNAL (fn)) | |
2425 | { | |
2426 | DECL_NOT_REALLY_EXTERN (fn) = 1; | |
2427 | DECL_EXTERNAL (fn) = 1; | |
2428 | } | |
2429 | /* Remember this function. In finish_file we'll decide if | |
2430 | we actually need to write this function out. */ | |
56e770bf | 2431 | defer_fn (fn); |
aba649ba | 2432 | /* Let the back-end know that this function exists. */ |
2b85879e | 2433 | (*debug_hooks->deferred_inline_function) (fn); |
21b0c6dc MM |
2434 | return; |
2435 | } | |
2436 | ||
92788413 MM |
2437 | /* Compute the appropriate object-file linkage for inline |
2438 | functions. */ | |
79065db2 | 2439 | if (DECL_DECLARED_INLINE_P (fn)) |
92788413 MM |
2440 | import_export_decl (fn); |
2441 | ||
4f8e1232 MM |
2442 | /* If FN is external, then there's no point in generating RTL for |
2443 | it. This situation can arise with an inline function under | |
83662e2b | 2444 | `-fexternal-templates'; we instantiate the function, even though |
4f8e1232 MM |
2445 | we're not planning on emitting it, in case we get a chance to |
2446 | inline it. */ | |
2447 | if (DECL_EXTERNAL (fn)) | |
2448 | return; | |
2449 | ||
62409b39 | 2450 | /* Save the current file name and line number. When we expand the |
82a98427 | 2451 | body of the function, we'll set INPUT_LOCATION so that |
62409b39 | 2452 | error-mesages come out in the right places. */ |
82a98427 | 2453 | saved_loc = input_location; |
367aa585 | 2454 | saved_function = current_function_decl; |
82a98427 | 2455 | input_location = DECL_SOURCE_LOCATION (fn); |
367aa585 JM |
2456 | current_function_decl = fn; |
2457 | ||
2458 | timevar_push (TV_INTEGRATION); | |
2459 | ||
2460 | /* Optimize the body of the function before expanding it. */ | |
2461 | optimize_function (fn); | |
2462 | ||
2463 | timevar_pop (TV_INTEGRATION); | |
2464 | timevar_push (TV_EXPAND); | |
62409b39 | 2465 | |
f444e36b | 2466 | genrtl_start_function (fn); |
6462c441 | 2467 | current_function_is_thunk = DECL_THUNK_P (fn); |
558475f0 | 2468 | |
558475f0 | 2469 | /* Expand the body. */ |
b35d4555 | 2470 | expand_stmt (DECL_SAVED_TREE (fn)); |
558475f0 | 2471 | |
62409b39 MM |
2472 | /* Statements should always be full-expressions at the outermost set |
2473 | of curly braces for a function. */ | |
f2c5f623 | 2474 | my_friendly_assert (stmts_are_full_exprs_p (), 19990831); |
62409b39 MM |
2475 | |
2476 | /* The outermost statement for a function contains the line number | |
2477 | recorded when we finished processing the function. */ | |
d479d37f | 2478 | input_line = STMT_LINENO (DECL_SAVED_TREE (fn)); |
62409b39 MM |
2479 | |
2480 | /* Generate code for the function. */ | |
f444e36b | 2481 | genrtl_finish_function (fn); |
62409b39 | 2482 | |
46e8c075 MM |
2483 | /* If possible, obliterate the body of the function so that it can |
2484 | be garbage collected. */ | |
b7442fb5 | 2485 | if (dump_enabled_p (TDI_all)) |
46e8c075 MM |
2486 | /* Keep the body; we're going to dump it. */ |
2487 | ; | |
2488 | else if (DECL_INLINE (fn) && flag_inline_trees) | |
2489 | /* We might need the body of this function so that we can expand | |
2490 | it inline somewhere else. */ | |
2491 | ; | |
2492 | else | |
2493 | /* We don't need the body; blow it away. */ | |
d658cd4c MM |
2494 | DECL_SAVED_TREE (fn) = NULL_TREE; |
2495 | ||
62409b39 | 2496 | /* And restore the current source position. */ |
367aa585 | 2497 | current_function_decl = saved_function; |
82a98427 | 2498 | input_location = saved_loc; |
f12eef58 | 2499 | extract_interface_info (); |
ea11ca7e JM |
2500 | |
2501 | timevar_pop (TV_EXPAND); | |
14691f8d RH |
2502 | |
2503 | /* Emit any thunks that should be emitted at the same time as FN. */ | |
2504 | emit_associated_thunks (fn); | |
558475f0 | 2505 | } |
54f7877c | 2506 | |
07b2f2fd JM |
2507 | /* Helper function for walk_tree, used by finish_function to override all |
2508 | the RETURN_STMTs and pertinent CLEANUP_STMTs for the named return | |
2509 | value optimization. */ | |
0d97bf4c | 2510 | |
07b2f2fd | 2511 | tree |
0d97bf4c JM |
2512 | nullify_returns_r (tp, walk_subtrees, data) |
2513 | tree *tp; | |
2514 | int *walk_subtrees; | |
07b2f2fd | 2515 | void *data; |
0d97bf4c | 2516 | { |
07b2f2fd JM |
2517 | tree nrv = (tree) data; |
2518 | ||
2519 | /* No need to walk into types. There wouldn't be any need to walk into | |
2520 | non-statements, except that we have to consider STMT_EXPRs. */ | |
0d97bf4c JM |
2521 | if (TYPE_P (*tp)) |
2522 | *walk_subtrees = 0; | |
2523 | else if (TREE_CODE (*tp) == RETURN_STMT) | |
d65b1d77 | 2524 | RETURN_STMT_EXPR (*tp) = NULL_TREE; |
07b2f2fd JM |
2525 | else if (TREE_CODE (*tp) == CLEANUP_STMT |
2526 | && CLEANUP_DECL (*tp) == nrv) | |
659e5a7a | 2527 | CLEANUP_EH_ONLY (*tp) = 1; |
0d97bf4c JM |
2528 | |
2529 | /* Keep iterating. */ | |
2530 | return NULL_TREE; | |
2531 | } | |
2532 | ||
f444e36b MM |
2533 | /* Start generating the RTL for FN. */ |
2534 | ||
2535 | static void | |
2536 | genrtl_start_function (fn) | |
2537 | tree fn; | |
2538 | { | |
f444e36b MM |
2539 | /* Tell everybody what function we're processing. */ |
2540 | current_function_decl = fn; | |
2541 | /* Get the RTL machinery going for this function. */ | |
ee6b0296 | 2542 | init_function_start (fn); |
f444e36b MM |
2543 | /* Let everybody know that we're expanding this function, not doing |
2544 | semantic analysis. */ | |
2545 | expanding_p = 1; | |
2546 | ||
2547 | /* Even though we're inside a function body, we still don't want to | |
2548 | call expand_expr to calculate the size of a variable-sized array. | |
2549 | We haven't necessarily assigned RTL to all variables yet, so it's | |
2550 | not safe to try to expand expressions involving them. */ | |
2551 | immediate_size_expand = 0; | |
2552 | cfun->x_dont_save_pending_sizes_p = 1; | |
2553 | ||
2554 | /* Let the user know we're compiling this function. */ | |
2555 | announce_function (fn); | |
2556 | ||
2557 | /* Initialize the per-function data. */ | |
2558 | my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911); | |
2559 | if (DECL_SAVED_FUNCTION_DATA (fn)) | |
2560 | { | |
2561 | /* If we already parsed this function, and we're just expanding it | |
2562 | now, restore saved state. */ | |
2563 | *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn); | |
2564 | ||
2565 | /* This function is being processed in whole-function mode; we | |
2566 | already did semantic analysis. */ | |
2567 | cfun->x_whole_function_mode_p = 1; | |
2568 | ||
2569 | /* If we decided that we didn't want to inline this function, | |
2570 | make sure the back-end knows that. */ | |
2571 | if (!current_function_cannot_inline) | |
2572 | current_function_cannot_inline = cp_function_chain->cannot_inline; | |
2573 | ||
edf5cd1d JM |
2574 | /* We don't need the saved data anymore. Unless this is an inline |
2575 | function; we need the named return value info for | |
2576 | cp_copy_res_decl_for_inlining. */ | |
2577 | if (! DECL_INLINE (fn)) | |
e2500fed | 2578 | DECL_SAVED_FUNCTION_DATA (fn) = NULL; |
f444e36b MM |
2579 | } |
2580 | ||
f444e36b MM |
2581 | /* Keep track of how many functions we're presently expanding. */ |
2582 | ++function_depth; | |
2583 | ||
2584 | /* Create a binding level for the parameters. */ | |
a0de9d20 | 2585 | expand_function_start (fn, /*parms_have_cleanups=*/0); |
f444e36b MM |
2586 | /* If this function is `main'. */ |
2587 | if (DECL_MAIN_P (fn)) | |
2588 | expand_main_function (); | |
0d97bf4c | 2589 | |
07b2f2fd JM |
2590 | /* Give our named return value the same RTL as our RESULT_DECL. */ |
2591 | if (current_function_return_value) | |
2592 | COPY_DECL_RTL (DECL_RESULT (fn), current_function_return_value); | |
f444e36b MM |
2593 | } |
2594 | ||
2595 | /* Finish generating the RTL for FN. */ | |
2596 | ||
2597 | static void | |
2598 | genrtl_finish_function (fn) | |
2599 | tree fn; | |
2600 | { | |
4f8e1232 | 2601 | tree t; |
f444e36b MM |
2602 | |
2603 | #if 0 | |
2604 | if (write_symbols != NO_DEBUG) | |
2605 | { | |
2606 | /* Keep this code around in case we later want to control debug info | |
2607 | based on whether a type is "used". (jason 1999-11-11) */ | |
2608 | ||
2609 | tree ttype = target_type (fntype); | |
2610 | tree parmdecl; | |
2611 | ||
2612 | if (IS_AGGR_TYPE (ttype)) | |
2613 | /* Let debugger know it should output info for this type. */ | |
2614 | note_debug_info_needed (ttype); | |
2615 | ||
2616 | for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) | |
2617 | { | |
2618 | ttype = target_type (TREE_TYPE (parmdecl)); | |
2619 | if (IS_AGGR_TYPE (ttype)) | |
2620 | /* Let debugger know it should output info for this type. */ | |
2621 | note_debug_info_needed (ttype); | |
2622 | } | |
2623 | } | |
2624 | #endif | |
2625 | ||
2626 | /* Clean house because we will need to reorder insns here. */ | |
2627 | do_pending_stack_adjust (); | |
2628 | ||
a0de9d20 JM |
2629 | /* If we have a named return value, we need to force a return so that |
2630 | the return register is USEd. */ | |
2631 | if (DECL_NAME (DECL_RESULT (fn))) | |
e6fe680d | 2632 | emit_jump (return_label); |
f444e36b MM |
2633 | |
2634 | /* We hard-wired immediate_size_expand to zero in start_function. | |
2635 | Expand_function_end will decrement this variable. So, we set the | |
2636 | variable to one here, so that after the decrement it will remain | |
2637 | zero. */ | |
2638 | immediate_size_expand = 1; | |
2639 | ||
2640 | /* Generate rtl for function exit. */ | |
d479d37f | 2641 | expand_function_end (input_filename, input_line, 0); |
f444e36b | 2642 | |
f444e36b MM |
2643 | /* If this is a nested function (like a template instantiation that |
2644 | we're compiling in the midst of compiling something else), push a | |
2645 | new GC context. That will keep local variables on the stack from | |
2646 | being collected while we're doing the compilation of this | |
2647 | function. */ | |
2648 | if (function_depth > 1) | |
2649 | ggc_push_context (); | |
2650 | ||
b850de4f MM |
2651 | /* There's no need to defer outputting this function any more; we |
2652 | know we want to output it. */ | |
2653 | DECL_DEFER_OUTPUT (fn) = 0; | |
2654 | ||
f444e36b MM |
2655 | /* Run the optimizers and output the assembler code for this |
2656 | function. */ | |
2657 | rest_of_compilation (fn); | |
2658 | ||
2659 | /* Undo the call to ggc_push_context above. */ | |
2660 | if (function_depth > 1) | |
2661 | ggc_pop_context (); | |
2662 | ||
f444e36b MM |
2663 | #if 0 |
2664 | /* Keep this code around in case we later want to control debug info | |
2665 | based on whether a type is "used". (jason 1999-11-11) */ | |
2666 | ||
2667 | if (ctype && TREE_ASM_WRITTEN (fn)) | |
2668 | note_debug_info_needed (ctype); | |
2669 | #endif | |
2670 | ||
2671 | /* If this function is marked with the constructor attribute, add it | |
2672 | to the list of functions to be called along with constructors | |
2673 | from static duration objects. */ | |
2674 | if (DECL_STATIC_CONSTRUCTOR (fn)) | |
2675 | static_ctors = tree_cons (NULL_TREE, fn, static_ctors); | |
2676 | ||
2677 | /* If this function is marked with the destructor attribute, add it | |
2678 | to the list of functions to be called along with destructors from | |
2679 | static duration objects. */ | |
2680 | if (DECL_STATIC_DESTRUCTOR (fn)) | |
2681 | static_dtors = tree_cons (NULL_TREE, fn, static_dtors); | |
2682 | ||
f444e36b MM |
2683 | --function_depth; |
2684 | ||
4f8e1232 MM |
2685 | /* In C++, we should never be saving RTL for the function. */ |
2686 | my_friendly_assert (!DECL_SAVED_INSNS (fn), 20010903); | |
b850de4f | 2687 | |
4f8e1232 MM |
2688 | /* Since we don't need the RTL for this function anymore, stop |
2689 | pointing to it. That's especially important for LABEL_DECLs, | |
2690 | since you can reach all the instructions in the function from the | |
2691 | CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. Walk the | |
2692 | BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and non-static | |
2693 | local variables. */ | |
2694 | walk_tree_without_duplicates (&DECL_SAVED_TREE (fn), | |
2695 | clear_decl_rtl, | |
2696 | NULL); | |
f444e36b | 2697 | |
4f8e1232 MM |
2698 | /* Clear out the RTL for the arguments. */ |
2699 | for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t)) | |
2700 | { | |
2701 | SET_DECL_RTL (t, NULL_RTX); | |
2702 | DECL_INCOMING_RTL (t) = NULL_RTX; | |
b850de4f | 2703 | } |
4f8e1232 MM |
2704 | |
2705 | if (!(flag_inline_trees && DECL_INLINE (fn))) | |
2706 | /* DECL_INITIAL must remain nonzero so we know this was an | |
2707 | actual function definition. */ | |
2708 | DECL_INITIAL (fn) = error_mark_node; | |
b850de4f | 2709 | |
f444e36b MM |
2710 | /* Let the error reporting routines know that we're outside a |
2711 | function. For a nested function, this value is used in | |
2712 | pop_cp_function_context and then reset via pop_function_context. */ | |
2713 | current_function_decl = NULL_TREE; | |
2714 | } | |
2715 | ||
b850de4f MM |
2716 | /* Clear out the DECL_RTL for the non-static variables in BLOCK and |
2717 | its sub-blocks. */ | |
2718 | ||
2719 | static tree | |
2720 | clear_decl_rtl (tp, walk_subtrees, data) | |
2721 | tree *tp; | |
2722 | int *walk_subtrees ATTRIBUTE_UNUSED; | |
2723 | void *data ATTRIBUTE_UNUSED; | |
2724 | { | |
2725 | if (nonstatic_local_decl_p (*tp)) | |
2726 | SET_DECL_RTL (*tp, NULL_RTX); | |
2727 | ||
2728 | return NULL_TREE; | |
2729 | } | |
2730 | ||
54f7877c MM |
2731 | /* Perform initialization related to this module. */ |
2732 | ||
2733 | void | |
2734 | init_cp_semantics () | |
2735 | { | |
2736 | lang_expand_stmt = cp_expand_stmt; | |
2737 | } | |
cf22909c KL |
2738 | |
2739 | #include "gt-cp-semantics.h" |