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