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