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