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