]>
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" |
ad321293 MM |
40 | |
41 | /* There routines provide a modular interface to perform many parsing | |
42 | operations. They may therefore be used during actual parsing, or | |
43 | during template instantiation, which may be regarded as a | |
44 | degenerate form of parsing. Since the current g++ parser is | |
45 | lacking in several respects, and will be reimplemented, we are | |
46 | attempting to move most code that is not directly related to | |
47 | parsing into this file; that will make implementing the new parser | |
48 | much easier since it will be able to make use of these routines. */ | |
49 | ||
158991b7 KG |
50 | static tree maybe_convert_cond PARAMS ((tree)); |
51 | static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *)); | |
c2e407f1 | 52 | static void deferred_type_access_control PARAMS ((void)); |
31f8e4f3 | 53 | static void emit_associated_thunks PARAMS ((tree)); |
54f7877c | 54 | static void genrtl_try_block PARAMS ((tree)); |
52a11cbf | 55 | static void genrtl_eh_spec_block PARAMS ((tree)); |
54f7877c MM |
56 | static void genrtl_handler PARAMS ((tree)); |
57 | static void genrtl_catch_block PARAMS ((tree)); | |
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 | ||
287 | /* Finsh an if-statement. */ | |
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 | |
406 | destructor get sent to the DTOR_LABEL; finsh_function emits | |
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 (); | |
724 | expand_stmt (HANDLER_BODY (t)); | |
725 | if (!processing_template_decl) | |
52a11cbf | 726 | expand_end_catch (); |
0dde4175 JM |
727 | } |
728 | ||
ad321293 MM |
729 | /* Begin a handler. Returns a HANDLER if appropriate. */ |
730 | ||
731 | tree | |
732 | begin_handler () | |
733 | { | |
734 | tree r; | |
0dfdeca6 | 735 | r = build_stmt (HANDLER, NULL_TREE, NULL_TREE); |
ae499cce | 736 | add_stmt (r); |
ad321293 | 737 | do_pushlevel (); |
ad321293 MM |
738 | return r; |
739 | } | |
740 | ||
741 | /* Finish the handler-parameters for a handler, which may be given by | |
b35d4555 MM |
742 | HANDLER. DECL is the declaration for the catch parameter, or NULL |
743 | if this is a `catch (...)' clause. */ | |
ad321293 | 744 | |
b35d4555 MM |
745 | tree |
746 | finish_handler_parms (decl, handler) | |
747 | tree decl; | |
ad321293 | 748 | tree handler; |
b35d4555 MM |
749 | { |
750 | tree blocks = NULL_TREE; | |
751 | ||
752 | if (processing_template_decl) | |
753 | { | |
754 | if (decl) | |
755 | { | |
756 | decl = pushdecl (decl); | |
757 | decl = push_template_decl (decl); | |
758 | add_decl_stmt (decl); | |
759 | RECHAIN_STMTS (handler, HANDLER_PARMS (handler)); | |
760 | } | |
761 | } | |
35b1567d | 762 | else |
b35d4555 MM |
763 | blocks = expand_start_catch_block (decl); |
764 | ||
35b1567d BC |
765 | if (decl) |
766 | TREE_TYPE (handler) = TREE_TYPE (decl); | |
767 | ||
768 | return blocks; | |
769 | } | |
770 | ||
52a11cbf | 771 | /* Generate the RTL for a START_CATCH_STMT. */ |
35b1567d | 772 | |
54f7877c | 773 | static void |
35b1567d BC |
774 | genrtl_catch_block (type) |
775 | tree type; | |
776 | { | |
52a11cbf | 777 | expand_start_catch (type); |
35b1567d BC |
778 | } |
779 | ||
780 | /* Note the beginning of a handler for TYPE. This function is called | |
781 | at the point to which control should be transferred when an | |
782 | appropriately-typed exception is thrown. */ | |
783 | ||
784 | void | |
785 | begin_catch_block (type) | |
786 | tree type; | |
787 | { | |
ae499cce | 788 | add_stmt (build (START_CATCH_STMT, type)); |
35b1567d BC |
789 | } |
790 | ||
791 | /* Finish a handler, which may be given by HANDLER. The BLOCKs are | |
792 | the return value from the matching call to finish_handler_parms. */ | |
793 | ||
794 | void | |
795 | finish_handler (blocks, handler) | |
796 | tree blocks; | |
797 | tree handler; | |
798 | { | |
799 | if (!processing_template_decl) | |
800 | expand_end_catch_block (blocks); | |
801 | do_poplevel (); | |
802 | RECHAIN_STMTS (handler, HANDLER_BODY (handler)); | |
803 | } | |
804 | ||
805 | /* Generate the RTL for T, which is a CTOR_STMT. */ | |
806 | ||
54f7877c | 807 | static void |
35b1567d BC |
808 | genrtl_ctor_stmt (t) |
809 | tree t; | |
810 | { | |
811 | if (CTOR_BEGIN_P (t)) | |
812 | begin_protect_partials (); | |
813 | else | |
814 | /* After this point, any exceptions will cause the | |
815 | destructor to be executed, so we no longer need to worry | |
816 | about destroying the various subobjects ourselves. */ | |
817 | end_protect_partials (); | |
818 | } | |
819 | ||
ad321293 MM |
820 | /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the |
821 | compound-statement does not define a scope. Returns a new | |
822 | COMPOUND_STMT if appropriate. */ | |
823 | ||
824 | tree | |
825 | begin_compound_stmt (has_no_scope) | |
826 | int has_no_scope; | |
827 | { | |
828 | tree r; | |
6625cdb5 | 829 | int is_try = 0; |
ad321293 | 830 | |
0dfdeca6 | 831 | r = build_stmt (COMPOUND_STMT, NULL_TREE); |
35b1567d BC |
832 | |
833 | if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK) | |
834 | is_try = 1; | |
835 | ||
ae499cce | 836 | add_stmt (r); |
35b1567d BC |
837 | if (has_no_scope) |
838 | COMPOUND_STMT_NO_SCOPE (r) = 1; | |
ad321293 | 839 | |
558475f0 MM |
840 | last_expr_type = NULL_TREE; |
841 | ||
ad321293 | 842 | if (!has_no_scope) |
6625cdb5 JM |
843 | { |
844 | do_pushlevel (); | |
845 | if (is_try) | |
826840d9 | 846 | note_level_for_try (); |
6625cdb5 | 847 | } |
f1dedc31 MM |
848 | else |
849 | /* Normally, we try hard to keep the BLOCK for a | |
850 | statement-expression. But, if it's a statement-expression with | |
851 | a scopeless block, there's nothing to keep, and we don't want | |
852 | to accidentally keep a block *inside* the scopeless block. */ | |
853 | keep_next_level (0); | |
ad321293 | 854 | |
24bef158 MM |
855 | /* If this is the outermost block of the function, declare the |
856 | variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */ | |
01d939e8 | 857 | if (cfun |
8f17b5c5 | 858 | && !function_name_declared_p |
9bfadf57 | 859 | && !has_no_scope) |
24bef158 | 860 | { |
8f17b5c5 | 861 | function_name_declared_p = 1; |
2ce07e2d | 862 | declare_function_name (); |
24bef158 MM |
863 | } |
864 | ||
ad321293 MM |
865 | return r; |
866 | } | |
867 | ||
ad321293 MM |
868 | /* Finish a compound-statement, which may be given by COMPOUND_STMT. |
869 | If HAS_NO_SCOPE is non-zero, the compound statement does not define | |
870 | a scope. */ | |
871 | ||
872 | tree | |
873 | finish_compound_stmt (has_no_scope, compound_stmt) | |
874 | int has_no_scope; | |
875 | tree compound_stmt; | |
876 | { | |
877 | tree r; | |
558475f0 | 878 | tree t; |
ad321293 MM |
879 | |
880 | if (!has_no_scope) | |
881 | r = do_poplevel (); | |
882 | else | |
883 | r = NULL_TREE; | |
884 | ||
35b1567d | 885 | RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt)); |
ad321293 | 886 | |
cb39191d | 887 | /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since |
558475f0 MM |
888 | the precise purpose of that variable is store the type of the |
889 | last expression statement within the last compound statement, we | |
890 | preserve the value. */ | |
891 | t = last_expr_type; | |
ad321293 | 892 | finish_stmt (); |
558475f0 | 893 | last_expr_type = t; |
ad321293 MM |
894 | |
895 | return r; | |
896 | } | |
897 | ||
35b1567d BC |
898 | /* Finish an asm-statement, whose components are a CV_QUALIFIER, a |
899 | STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some | |
900 | CLOBBERS. */ | |
7dc5bd62 | 901 | |
3e4d04a1 | 902 | tree |
35b1567d BC |
903 | finish_asm_stmt (cv_qualifier, string, output_operands, |
904 | input_operands, clobbers) | |
905 | tree cv_qualifier; | |
906 | tree string; | |
907 | tree output_operands; | |
908 | tree input_operands; | |
909 | tree clobbers; | |
910 | { | |
911 | tree r; | |
abfc8a36 MM |
912 | tree t; |
913 | ||
35b1567d BC |
914 | if (TREE_CHAIN (string)) |
915 | string = combine_strings (string); | |
916 | ||
917 | if (cv_qualifier != NULL_TREE | |
918 | && cv_qualifier != ridpointers[(int) RID_VOLATILE]) | |
919 | { | |
920 | cp_warning ("%s qualifier ignored on asm", | |
921 | IDENTIFIER_POINTER (cv_qualifier)); | |
922 | cv_qualifier = NULL_TREE; | |
ad321293 | 923 | } |
35b1567d | 924 | |
abfc8a36 MM |
925 | if (!processing_template_decl) |
926 | for (t = input_operands; t; t = TREE_CHAIN (t)) | |
8853373c MM |
927 | { |
928 | tree converted_operand | |
929 | = decay_conversion (TREE_VALUE (t)); | |
930 | ||
931 | /* If the type of the operand hasn't been determined (e.g., | |
932 | because it involves an overloaded function), then issue an | |
933 | error message. There's no context available to resolve the | |
934 | overloading. */ | |
935 | if (TREE_TYPE (converted_operand) == unknown_type_node) | |
936 | { | |
937 | cp_error ("type of asm operand `%E' could not be determined", | |
938 | TREE_VALUE (t)); | |
939 | converted_operand = error_mark_node; | |
940 | } | |
941 | TREE_VALUE (t) = converted_operand; | |
942 | } | |
abfc8a36 | 943 | |
0dfdeca6 BC |
944 | r = build_stmt (ASM_STMT, cv_qualifier, string, |
945 | output_operands, input_operands, | |
946 | clobbers); | |
3e4d04a1 | 947 | return add_stmt (r); |
ad321293 | 948 | } |
b4c4a9ec | 949 | |
f01b0acb MM |
950 | /* Finish a label with the indicated NAME. */ |
951 | ||
952 | void | |
953 | finish_label_stmt (name) | |
954 | tree name; | |
955 | { | |
3fa56191 | 956 | tree decl = define_label (input_filename, lineno, name); |
ae499cce | 957 | add_stmt (build_stmt (LABEL_STMT, decl)); |
f01b0acb MM |
958 | } |
959 | ||
acef433b MM |
960 | /* Finish a series of declarations for local labels. G++ allows users |
961 | to declare "local" labels, i.e., labels with scope. This extension | |
962 | is useful when writing code involving statement-expressions. */ | |
963 | ||
964 | void | |
965 | finish_label_decl (name) | |
966 | tree name; | |
967 | { | |
968 | tree decl = declare_local_label (name); | |
35b1567d | 969 | add_decl_stmt (decl); |
acef433b MM |
970 | } |
971 | ||
35b1567d BC |
972 | /* Generate the RTL for a SUBOBJECT. */ |
973 | ||
54f7877c | 974 | static void |
35b1567d BC |
975 | genrtl_subobject (cleanup) |
976 | tree cleanup; | |
977 | { | |
978 | add_partial_entry (cleanup); | |
9188c363 MM |
979 | } |
980 | ||
f1dedc31 MM |
981 | /* We're in a constructor, and have just constructed a a subobject of |
982 | *THIS. CLEANUP is code to run if an exception is thrown before the | |
983 | end of the current function is reached. */ | |
984 | ||
985 | void | |
986 | finish_subobject (cleanup) | |
987 | tree cleanup; | |
988 | { | |
0dfdeca6 | 989 | tree r = build_stmt (SUBOBJECT, cleanup); |
ae499cce | 990 | add_stmt (r); |
35b1567d BC |
991 | } |
992 | ||
24bef158 MM |
993 | /* When DECL goes out of scope, make sure that CLEANUP is executed. */ |
994 | ||
995 | void | |
996 | finish_decl_cleanup (decl, cleanup) | |
997 | tree decl; | |
998 | tree cleanup; | |
999 | { | |
ae499cce | 1000 | add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup)); |
35b1567d BC |
1001 | } |
1002 | ||
1003 | /* Generate the RTL for a RETURN_INIT. */ | |
1004 | ||
54f7877c | 1005 | static void |
44835fdd | 1006 | genrtl_named_return_value () |
35b1567d | 1007 | { |
156ce211 | 1008 | tree decl = DECL_RESULT (current_function_decl); |
35b1567d | 1009 | |
44835fdd MM |
1010 | /* If this named return value comes in a register, put it in a |
1011 | pseudo-register. */ | |
1012 | if (DECL_REGISTER (decl)) | |
35b1567d | 1013 | { |
44835fdd MM |
1014 | /* Note that the mode of the old DECL_RTL may be wider than the |
1015 | mode of DECL_RESULT, depending on the calling conventions for | |
1016 | the processor. For example, on the Alpha, a 32-bit integer | |
1017 | is returned in a DImode register -- the DECL_RESULT has | |
1018 | SImode but the DECL_RTL for the DECL_RESULT has DImode. So, | |
1019 | here, we use the mode the back-end has already assigned for | |
1020 | the return value. */ | |
19e7881c | 1021 | SET_DECL_RTL (decl, gen_reg_rtx (GET_MODE (DECL_RTL (decl)))); |
44835fdd MM |
1022 | if (TREE_ADDRESSABLE (decl)) |
1023 | put_var_into_stack (decl); | |
35b1567d | 1024 | } |
156ce211 RH |
1025 | |
1026 | emit_local_var (decl); | |
24bef158 MM |
1027 | } |
1028 | ||
558475f0 MM |
1029 | /* Bind a name and initialization to the return value of |
1030 | the current function. */ | |
1031 | ||
1032 | void | |
1033 | finish_named_return_value (return_id, init) | |
1034 | tree return_id, init; | |
1035 | { | |
1036 | tree decl = DECL_RESULT (current_function_decl); | |
1037 | ||
44835fdd MM |
1038 | /* Give this error as many times as there are occurrences, so that |
1039 | users can use Emacs compilation buffers to find and fix all such | |
1040 | places. */ | |
558475f0 | 1041 | if (pedantic) |
cab1f180 | 1042 | pedwarn ("ISO C++ does not permit named return values"); |
44835fdd | 1043 | cp_deprecated ("the named return value extension"); |
558475f0 MM |
1044 | |
1045 | if (return_id != NULL_TREE) | |
1046 | { | |
1047 | if (DECL_NAME (decl) == NULL_TREE) | |
92643fea | 1048 | DECL_NAME (decl) = return_id; |
558475f0 MM |
1049 | else |
1050 | { | |
1051 | cp_error ("return identifier `%D' already in place", return_id); | |
1052 | return; | |
1053 | } | |
1054 | } | |
1055 | ||
1056 | /* Can't let this happen for constructors. */ | |
1057 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
1058 | { | |
1059 | error ("can't redefine default return value for constructors"); | |
1060 | return; | |
1061 | } | |
1062 | ||
1063 | /* If we have a named return value, put that in our scope as well. */ | |
1064 | if (DECL_NAME (decl) != NULL_TREE) | |
1065 | { | |
1066 | /* Let `cp_finish_decl' know that this initializer is ok. */ | |
1067 | DECL_INITIAL (decl) = init; | |
b35d4555 MM |
1068 | if (doing_semantic_analysis_p ()) |
1069 | pushdecl (decl); | |
44835fdd MM |
1070 | if (!processing_template_decl) |
1071 | { | |
1072 | cp_finish_decl (decl, init, NULL_TREE, 0); | |
ae499cce | 1073 | add_stmt (build_stmt (RETURN_INIT, NULL_TREE, NULL_TREE)); |
44835fdd MM |
1074 | } |
1075 | else | |
ae499cce | 1076 | add_stmt (build_stmt (RETURN_INIT, return_id, init)); |
558475f0 | 1077 | } |
f0ad3f46 MM |
1078 | |
1079 | /* Don't use tree-inlining for functions with named return values. | |
1080 | That doesn't work properly because we don't do any translation of | |
1081 | the RETURN_INITs when they are copied. */ | |
1082 | DECL_UNINLINABLE (current_function_decl) = 1; | |
558475f0 MM |
1083 | } |
1084 | ||
bf3428d0 MM |
1085 | /* The INIT_LIST is a list of mem-initializers, in the order they were |
1086 | written by the user. The TREE_VALUE of each node is a list of | |
1087 | initializers for a particular subobject. The TREE_PURPOSE is a | |
1088 | FIELD_DECL is the initializer is for a non-static data member, and | |
1089 | a class type if the initializer is for a base class. */ | |
1090 | ||
1091 | void | |
1092 | finish_mem_initializers (init_list) | |
1093 | tree init_list; | |
1094 | { | |
1095 | tree member_init_list; | |
1096 | tree base_init_list; | |
1097 | tree last_base_warned_about; | |
1098 | tree next; | |
1099 | tree init; | |
1100 | ||
1101 | member_init_list = NULL_TREE; | |
1102 | base_init_list = NULL_TREE; | |
1103 | last_base_warned_about = NULL_TREE; | |
1104 | ||
1105 | for (init = init_list; init; init = next) | |
1106 | { | |
1107 | next = TREE_CHAIN (init); | |
1108 | if (TREE_CODE (TREE_PURPOSE (init)) == FIELD_DECL) | |
1109 | { | |
1110 | TREE_CHAIN (init) = member_init_list; | |
1111 | member_init_list = init; | |
1112 | ||
1113 | /* We're running through the initializers from right to left | |
1114 | as we process them here. So, if we see a data member | |
1115 | initializer after we see a base initializer, that | |
1116 | actually means that the base initializer preceeded the | |
1117 | data member initializer. */ | |
1118 | if (warn_reorder && last_base_warned_about != base_init_list) | |
1119 | { | |
1120 | tree base; | |
1121 | ||
1122 | for (base = base_init_list; | |
1123 | base != last_base_warned_about; | |
1124 | base = TREE_CHAIN (base)) | |
1125 | { | |
1126 | cp_warning ("base initializer for `%T'", | |
1127 | TREE_PURPOSE (base)); | |
1128 | warning (" will be re-ordered to precede member initializations"); | |
1129 | } | |
1130 | ||
1131 | last_base_warned_about = base_init_list; | |
1132 | } | |
1133 | } | |
1134 | else | |
1135 | { | |
1136 | TREE_CHAIN (init) = base_init_list; | |
1137 | base_init_list = init; | |
1138 | } | |
1139 | } | |
1140 | ||
1141 | setup_vtbl_ptr (member_init_list, base_init_list); | |
1142 | } | |
1143 | ||
558475f0 MM |
1144 | /* Cache the value of this class's main virtual function table pointer |
1145 | in a register variable. This will save one indirection if a | |
1146 | more than one virtual function call is made this function. */ | |
1147 | ||
1148 | void | |
fd74ca0b MM |
1149 | setup_vtbl_ptr (member_init_list, base_init_list) |
1150 | tree member_init_list; | |
1151 | tree base_init_list; | |
558475f0 | 1152 | { |
9bfadf57 MM |
1153 | my_friendly_assert (doing_semantic_analysis_p (), 19990919); |
1154 | ||
1155 | /* If we've already done this, there's no need to do it again. */ | |
1156 | if (vtbls_set_up_p) | |
1157 | return; | |
1158 | ||
1159 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
558475f0 | 1160 | { |
9bfadf57 | 1161 | if (processing_template_decl) |
ae499cce | 1162 | add_stmt (build_min_nt |
558475f0 | 1163 | (CTOR_INITIALIZER, |
fd74ca0b | 1164 | member_init_list, base_init_list)); |
558475f0 | 1165 | else |
46e8c075 MM |
1166 | { |
1167 | tree ctor_stmt; | |
1168 | ||
1169 | /* Mark the beginning of the constructor. */ | |
0dfdeca6 | 1170 | ctor_stmt = build_stmt (CTOR_STMT); |
46e8c075 | 1171 | CTOR_BEGIN_P (ctor_stmt) = 1; |
ae499cce | 1172 | add_stmt (ctor_stmt); |
46e8c075 MM |
1173 | |
1174 | /* And actually initialize the base-classes and members. */ | |
fd74ca0b | 1175 | emit_base_init (member_init_list, base_init_list); |
46e8c075 | 1176 | } |
9bfadf57 MM |
1177 | } |
1178 | else if (DECL_DESTRUCTOR_P (current_function_decl) | |
1179 | && !processing_template_decl) | |
1180 | { | |
9bfadf57 MM |
1181 | tree if_stmt; |
1182 | tree compound_stmt; | |
f9817201 | 1183 | int saved_cfnd; |
9bfadf57 | 1184 | |
3ec6bad3 MM |
1185 | /* If the dtor is empty, and we know there is not any possible |
1186 | way we could use any vtable entries, before they are possibly | |
1187 | set by a base class dtor, we don't have to setup the vtables, | |
1188 | as we know that any base class dtor will set up any vtables | |
1189 | it needs. We avoid MI, because one base class dtor can do a | |
9bfadf57 MM |
1190 | virtual dispatch to an overridden function that would need to |
1191 | have a non-related vtable set up, we cannot avoid setting up | |
3ec6bad3 MM |
1192 | vtables in that case. We could change this to see if there |
1193 | is just one vtable. */ | |
9bfadf57 MM |
1194 | if_stmt = begin_if_stmt (); |
1195 | ||
1196 | /* If it is not safe to avoid setting up the vtables, then | |
1197 | someone will change the condition to be boolean_true_node. | |
1198 | (Actually, for now, we do not have code to set the condition | |
f9817201 | 1199 | appropriately, so we just assume that we always need to |
9bfadf57 MM |
1200 | initialize the vtables.) */ |
1201 | finish_if_stmt_cond (boolean_true_node, if_stmt); | |
1202 | current_vcalls_possible_p = &IF_COND (if_stmt); | |
f9817201 MM |
1203 | |
1204 | /* Don't declare __PRETTY_FUNCTION__ and friends here when we | |
1205 | open the block for the if-body. */ | |
8f17b5c5 MM |
1206 | saved_cfnd = function_name_declared_p; |
1207 | function_name_declared_p = 1; | |
9bfadf57 | 1208 | compound_stmt = begin_compound_stmt (/*has_no_scope=*/0); |
8f17b5c5 | 1209 | function_name_declared_p = saved_cfnd; |
9bfadf57 MM |
1210 | |
1211 | /* Make all virtual function table pointers in non-virtual base | |
1212 | classes point to CURRENT_CLASS_TYPE's virtual function | |
1213 | tables. */ | |
cf2e003b | 1214 | initialize_vtbl_ptrs (current_class_ptr); |
9bfadf57 MM |
1215 | |
1216 | finish_compound_stmt (/*has_no_scope=*/0, compound_stmt); | |
1217 | finish_then_clause (if_stmt); | |
1218 | finish_if_stmt (); | |
558475f0 | 1219 | } |
f1dedc31 MM |
1220 | |
1221 | /* Always keep the BLOCK node associated with the outermost pair of | |
9bfadf57 | 1222 | curly braces of a function. These are needed for correct |
f1dedc31 MM |
1223 | operation of dwarfout.c. */ |
1224 | keep_next_level (1); | |
9bfadf57 MM |
1225 | |
1226 | /* The virtual function tables are set up now. */ | |
1227 | vtbls_set_up_p = 1; | |
558475f0 MM |
1228 | } |
1229 | ||
8f17b5c5 | 1230 | /* Returns the stack of SCOPE_STMTs for the current function. */ |
35b1567d | 1231 | |
8f17b5c5 MM |
1232 | tree * |
1233 | current_scope_stmt_stack () | |
8f471b0d | 1234 | { |
8f17b5c5 | 1235 | return &cfun->language->x_scope_stmt_stack; |
8f471b0d MM |
1236 | } |
1237 | ||
b4c4a9ec MM |
1238 | /* Finish a parenthesized expression EXPR. */ |
1239 | ||
1240 | tree | |
1241 | finish_parenthesized_expr (expr) | |
1242 | tree expr; | |
1243 | { | |
1244 | if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr)))) | |
1245 | /* This inhibits warnings in truthvalue_conversion. */ | |
1246 | C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK); | |
1247 | ||
19420d00 NS |
1248 | if (TREE_CODE (expr) == OFFSET_REF) |
1249 | /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be | |
1250 | enclosed in parentheses. */ | |
1251 | PTRMEM_OK_P (expr) = 0; | |
b4c4a9ec MM |
1252 | return expr; |
1253 | } | |
1254 | ||
b69b1501 MM |
1255 | /* Begin a statement-expression. The value returned must be passed to |
1256 | finish_stmt_expr. */ | |
b4c4a9ec MM |
1257 | |
1258 | tree | |
1259 | begin_stmt_expr () | |
1260 | { | |
6f80451c MM |
1261 | /* If we're outside a function, we won't have a statement-tree to |
1262 | work with. But, if we see a statement-expression we need to | |
1263 | create one. */ | |
01d939e8 | 1264 | if (! cfun && !last_tree) |
6f80451c MM |
1265 | begin_stmt_tree (&scope_chain->x_saved_tree); |
1266 | ||
f1dedc31 | 1267 | keep_next_level (1); |
558475f0 | 1268 | /* If we're building a statement tree, then the upcoming compound |
b69b1501 MM |
1269 | statement will be chained onto the tree structure, starting at |
1270 | last_tree. We return last_tree so that we can later unhook the | |
1271 | compound statement. */ | |
35b1567d BC |
1272 | return last_tree; |
1273 | } | |
1274 | ||
596fd31c MM |
1275 | /* Used when beginning a statement-expression outside function scope. |
1276 | For example, when handling a file-scope initializer, we use this | |
1277 | function. */ | |
35b1567d | 1278 | |
596fd31c MM |
1279 | tree |
1280 | begin_global_stmt_expr () | |
35b1567d | 1281 | { |
596fd31c MM |
1282 | if (! cfun && !last_tree) |
1283 | begin_stmt_tree (&scope_chain->x_saved_tree); | |
35b1567d | 1284 | |
596fd31c MM |
1285 | keep_next_level (1); |
1286 | ||
1287 | return (last_tree != NULL_TREE) ? last_tree : expand_start_stmt_expr(); | |
1288 | } | |
1289 | ||
1290 | /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */ | |
1291 | ||
1292 | tree | |
1293 | finish_global_stmt_expr (stmt_expr) | |
1294 | tree stmt_expr; | |
1295 | { | |
1296 | stmt_expr = expand_end_stmt_expr (stmt_expr); | |
35b1567d BC |
1297 | |
1298 | if (! cfun | |
1299 | && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE) | |
1300 | finish_stmt_tree (&scope_chain->x_saved_tree); | |
1301 | ||
596fd31c | 1302 | return stmt_expr; |
b4c4a9ec MM |
1303 | } |
1304 | ||
1305 | /* Finish a statement-expression. RTL_EXPR should be the value | |
1306 | returned by the previous begin_stmt_expr; EXPR is the | |
1307 | statement-expression. Returns an expression representing the | |
1308 | statement-expression. */ | |
1309 | ||
1310 | tree | |
5ba57b55 | 1311 | finish_stmt_expr (rtl_expr) |
b4c4a9ec | 1312 | tree rtl_expr; |
b4c4a9ec MM |
1313 | { |
1314 | tree result; | |
1315 | ||
35b1567d BC |
1316 | /* If the last thing in the statement-expression was not an |
1317 | expression-statement, then it has type `void'. */ | |
1318 | if (!last_expr_type) | |
1319 | last_expr_type = void_type_node; | |
1320 | result = build_min (STMT_EXPR, last_expr_type, last_tree); | |
1321 | TREE_SIDE_EFFECTS (result) = 1; | |
1322 | ||
1323 | /* Remove the compound statement from the tree structure; it is | |
1324 | now saved in the STMT_EXPR. */ | |
ae499cce | 1325 | last_tree = rtl_expr; |
35b1567d | 1326 | TREE_CHAIN (last_tree) = NULL_TREE; |
f1dedc31 | 1327 | |
6f80451c MM |
1328 | /* If we created a statement-tree for this statement-expression, |
1329 | remove it now. */ | |
01d939e8 | 1330 | if (! cfun |
6f80451c MM |
1331 | && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE) |
1332 | finish_stmt_tree (&scope_chain->x_saved_tree); | |
1333 | ||
b4c4a9ec MM |
1334 | return result; |
1335 | } | |
1336 | ||
1337 | /* Finish a call to FN with ARGS. Returns a representation of the | |
1338 | call. */ | |
1339 | ||
1340 | tree | |
a759e627 | 1341 | finish_call_expr (fn, args, koenig) |
b4c4a9ec MM |
1342 | tree fn; |
1343 | tree args; | |
a759e627 | 1344 | int koenig; |
b4c4a9ec | 1345 | { |
a759e627 ML |
1346 | tree result; |
1347 | ||
1348 | if (koenig) | |
03d82991 JM |
1349 | { |
1350 | if (TREE_CODE (fn) == BIT_NOT_EXPR) | |
1351 | fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0)); | |
1352 | else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR) | |
e13a4123 | 1353 | fn = do_identifier (fn, 2, args); |
03d82991 | 1354 | } |
a759e627 | 1355 | result = build_x_function_call (fn, args, current_class_ref); |
b4c4a9ec MM |
1356 | |
1357 | if (TREE_CODE (result) == CALL_EXPR | |
66543169 NS |
1358 | && (! TREE_TYPE (result) |
1359 | || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE)) | |
b4c4a9ec MM |
1360 | result = require_complete_type (result); |
1361 | ||
1362 | return result; | |
1363 | } | |
1364 | ||
1365 | /* Finish a call to a postfix increment or decrement or EXPR. (Which | |
1366 | is indicated by CODE, which should be POSTINCREMENT_EXPR or | |
1367 | POSTDECREMENT_EXPR.) */ | |
1368 | ||
1369 | tree | |
1370 | finish_increment_expr (expr, code) | |
1371 | tree expr; | |
1372 | enum tree_code code; | |
1373 | { | |
1374 | /* If we get an OFFSET_REF, turn it into what it really means (e.g., | |
1375 | a COMPONENT_REF). This way if we've got, say, a reference to a | |
1376 | static member that's being operated on, we don't end up trying to | |
1377 | find a member operator for the class it's in. */ | |
1378 | ||
1379 | if (TREE_CODE (expr) == OFFSET_REF) | |
1380 | expr = resolve_offset_ref (expr); | |
1381 | return build_x_unary_op (code, expr); | |
1382 | } | |
1383 | ||
1384 | /* Finish a use of `this'. Returns an expression for `this'. */ | |
1385 | ||
1386 | tree | |
1387 | finish_this_expr () | |
1388 | { | |
1389 | tree result; | |
1390 | ||
1391 | if (current_class_ptr) | |
1392 | { | |
1393 | #ifdef WARNING_ABOUT_CCD | |
1394 | TREE_USED (current_class_ptr) = 1; | |
1395 | #endif | |
1396 | result = current_class_ptr; | |
1397 | } | |
1398 | else if (current_function_decl | |
1399 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
1400 | { | |
8251199e | 1401 | error ("`this' is unavailable for static member functions"); |
b4c4a9ec MM |
1402 | result = error_mark_node; |
1403 | } | |
1404 | else | |
1405 | { | |
1406 | if (current_function_decl) | |
8251199e | 1407 | error ("invalid use of `this' in non-member function"); |
b4c4a9ec | 1408 | else |
8251199e | 1409 | error ("invalid use of `this' at top level"); |
b4c4a9ec MM |
1410 | result = error_mark_node; |
1411 | } | |
1412 | ||
1413 | return result; | |
1414 | } | |
1415 | ||
1416 | /* Finish a member function call using OBJECT and ARGS as arguments to | |
1417 | FN. Returns an expression for the call. */ | |
1418 | ||
1419 | tree | |
1420 | finish_object_call_expr (fn, object, args) | |
1421 | tree fn; | |
1422 | tree object; | |
1423 | tree args; | |
1424 | { | |
1425 | #if 0 | |
1426 | /* This is a future direction of this code, but because | |
1427 | build_x_function_call cannot always undo what is done in | |
1428 | build_component_ref entirely yet, we cannot do this. */ | |
1429 | ||
1430 | tree real_fn = build_component_ref (object, fn, NULL_TREE, 1); | |
1431 | return finish_call_expr (real_fn, args); | |
1432 | #else | |
c219b878 | 1433 | if (DECL_DECLARES_TYPE_P (fn)) |
c68c56f7 MM |
1434 | { |
1435 | if (processing_template_decl) | |
1436 | /* This can happen on code like: | |
1437 | ||
1438 | class X; | |
1439 | template <class T> void f(T t) { | |
1440 | t.X(); | |
1441 | } | |
1442 | ||
1443 | We just grab the underlying IDENTIFIER. */ | |
1444 | fn = DECL_NAME (fn); | |
1445 | else | |
1446 | { | |
8251199e | 1447 | cp_error ("calling type `%T' like a method", fn); |
c68c56f7 MM |
1448 | return error_mark_node; |
1449 | } | |
1450 | } | |
1451 | ||
b4c4a9ec MM |
1452 | return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL); |
1453 | #endif | |
1454 | } | |
1455 | ||
1456 | /* Finish a qualified member function call using OBJECT and ARGS as | |
509fc277 | 1457 | arguments to FN. Returns an expression for the call. */ |
b4c4a9ec MM |
1458 | |
1459 | tree | |
1460 | finish_qualified_object_call_expr (fn, object, args) | |
1461 | tree fn; | |
1462 | tree object; | |
1463 | tree args; | |
1464 | { | |
6eabb241 MM |
1465 | return build_scoped_method_call (object, TREE_OPERAND (fn, 0), |
1466 | TREE_OPERAND (fn, 1), args); | |
b4c4a9ec MM |
1467 | } |
1468 | ||
1469 | /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE | |
1470 | being the scope, if any, of DESTRUCTOR. Returns an expression for | |
1471 | the call. */ | |
1472 | ||
1473 | tree | |
1474 | finish_pseudo_destructor_call_expr (object, scope, destructor) | |
1475 | tree object; | |
1476 | tree scope; | |
1477 | tree destructor; | |
1478 | { | |
40242ccf MM |
1479 | if (processing_template_decl) |
1480 | return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor); | |
1481 | ||
b4c4a9ec | 1482 | if (scope && scope != destructor) |
8251199e | 1483 | cp_error ("destructor specifier `%T::~%T()' must have matching names", |
b4c4a9ec MM |
1484 | scope, destructor); |
1485 | ||
1486 | if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor)) | |
1487 | && (TREE_CODE (TREE_TYPE (object)) != | |
1488 | TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor))))) | |
8251199e | 1489 | cp_error ("`%E' is not of type `%T'", object, destructor); |
b4c4a9ec MM |
1490 | |
1491 | return cp_convert (void_type_node, object); | |
1492 | } | |
1493 | ||
1494 | /* Finish a call to a globally qualified member function FN using | |
1495 | ARGS. Returns an expression for the call. */ | |
1496 | ||
1497 | tree | |
75d587eb | 1498 | finish_qualified_call_expr (fn, args) |
b4c4a9ec MM |
1499 | tree fn; |
1500 | tree args; | |
1501 | { | |
1502 | if (processing_template_decl) | |
2a1e9fdd | 1503 | return build_min_nt (CALL_EXPR, fn, args, NULL_TREE); |
b4c4a9ec MM |
1504 | else |
1505 | return build_member_call (TREE_OPERAND (fn, 0), | |
1506 | TREE_OPERAND (fn, 1), | |
1507 | args); | |
1508 | } | |
1509 | ||
1510 | /* Finish an expression taking the address of LABEL. Returns an | |
1511 | expression for the address. */ | |
1512 | ||
1513 | tree | |
1514 | finish_label_address_expr (label) | |
1515 | tree label; | |
1516 | { | |
1517 | tree result; | |
1518 | ||
1519 | label = lookup_label (label); | |
1520 | if (label == NULL_TREE) | |
1521 | result = null_pointer_node; | |
1522 | else | |
1523 | { | |
1524 | TREE_USED (label) = 1; | |
1525 | result = build1 (ADDR_EXPR, ptr_type_node, label); | |
1526 | TREE_CONSTANT (result) = 1; | |
46e8c075 MM |
1527 | /* This function cannot be inlined. All jumps to the addressed |
1528 | label should wind up at the same point. */ | |
1529 | DECL_UNINLINABLE (current_function_decl) = 1; | |
b4c4a9ec MM |
1530 | } |
1531 | ||
1532 | return result; | |
1533 | } | |
1534 | ||
ce4a0391 MM |
1535 | /* Finish an expression of the form CODE EXPR. */ |
1536 | ||
1537 | tree | |
1538 | finish_unary_op_expr (code, expr) | |
1539 | enum tree_code code; | |
1540 | tree expr; | |
1541 | { | |
1542 | tree result = build_x_unary_op (code, expr); | |
7c355bca ML |
1543 | /* Inside a template, build_x_unary_op does not fold the |
1544 | expression. So check whether the result is folded before | |
1545 | setting TREE_NEGATED_INT. */ | |
1546 | if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST | |
88b4335f NS |
1547 | && TREE_CODE (result) == INTEGER_CST |
1548 | && !TREE_UNSIGNED (TREE_TYPE (result)) | |
1549 | && INT_CST_LT (result, integer_zero_node)) | |
ce4a0391 MM |
1550 | TREE_NEGATED_INT (result) = 1; |
1551 | overflow_warning (result); | |
1552 | return result; | |
1553 | } | |
1554 | ||
1555 | /* Finish an id-expression. */ | |
1556 | ||
1557 | tree | |
1558 | finish_id_expr (expr) | |
1559 | tree expr; | |
1560 | { | |
1561 | if (TREE_CODE (expr) == IDENTIFIER_NODE) | |
a759e627 | 1562 | expr = do_identifier (expr, 1, NULL_TREE); |
ce4a0391 | 1563 | |
3d7e9ba4 NS |
1564 | if (TREE_TYPE (expr) == error_mark_node) |
1565 | expr = error_mark_node; | |
ce4a0391 MM |
1566 | return expr; |
1567 | } | |
1568 | ||
70adf8a9 JM |
1569 | static tree current_type_lookups; |
1570 | ||
1571 | /* Perform deferred access control for types used in the type of a | |
1572 | declaration. */ | |
1573 | ||
1f51a992 | 1574 | static void |
70adf8a9 JM |
1575 | deferred_type_access_control () |
1576 | { | |
1f51a992 | 1577 | tree lookup = type_lookups; |
70adf8a9 JM |
1578 | |
1579 | if (lookup == error_mark_node) | |
1580 | return; | |
1581 | ||
1582 | for (; lookup; lookup = TREE_CHAIN (lookup)) | |
1583 | enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup)); | |
1584 | } | |
1585 | ||
70adf8a9 | 1586 | void |
1f51a992 JM |
1587 | decl_type_access_control (decl) |
1588 | tree decl; | |
70adf8a9 | 1589 | { |
1f51a992 | 1590 | tree save_fn; |
70adf8a9 | 1591 | |
1f51a992 JM |
1592 | if (type_lookups == error_mark_node) |
1593 | return; | |
1594 | ||
1595 | save_fn = current_function_decl; | |
1596 | ||
1597 | if (decl && TREE_CODE (decl) == FUNCTION_DECL) | |
1598 | current_function_decl = decl; | |
70adf8a9 | 1599 | |
70adf8a9 | 1600 | deferred_type_access_control (); |
1f51a992 JM |
1601 | |
1602 | current_function_decl = save_fn; | |
1603 | ||
1604 | /* Now strip away the checks for the current declarator; they were | |
1605 | added to type_lookups after typed_declspecs saved the copy that | |
1606 | ended up in current_type_lookups. */ | |
1607 | type_lookups = current_type_lookups; | |
788bf0e3 NS |
1608 | |
1609 | current_type_lookups = NULL_TREE; | |
1f51a992 JM |
1610 | } |
1611 | ||
788bf0e3 NS |
1612 | /* Record the lookups, if we're doing deferred access control. */ |
1613 | ||
1f51a992 JM |
1614 | void |
1615 | save_type_access_control (lookups) | |
1616 | tree lookups; | |
1617 | { | |
788bf0e3 NS |
1618 | if (type_lookups != error_mark_node) |
1619 | { | |
1620 | my_friendly_assert (!current_type_lookups, 20010301); | |
1621 | current_type_lookups = lookups; | |
1622 | } | |
1623 | else | |
1624 | my_friendly_assert (!lookups || lookups == error_mark_node, 20010301); | |
1625 | } | |
1626 | ||
1627 | /* Set things up so that the next deferred access control will succeed. | |
1628 | This is needed for friend declarations see grokdeclarator for details. */ | |
1629 | ||
1630 | void | |
1631 | skip_type_access_control () | |
1632 | { | |
1633 | type_lookups = NULL_TREE; | |
1634 | } | |
1635 | ||
1636 | /* Reset the deferred access control. */ | |
1637 | ||
1638 | void | |
1639 | reset_type_access_control () | |
1640 | { | |
1641 | type_lookups = NULL_TREE; | |
1642 | current_type_lookups = NULL_TREE; | |
1f51a992 | 1643 | } |
70adf8a9 JM |
1644 | |
1645 | /* Begin a function definition declared with DECL_SPECS and | |
b4c4a9ec MM |
1646 | DECLARATOR. Returns non-zero if the function-declaration is |
1647 | legal. */ | |
1648 | ||
1649 | int | |
1f51a992 | 1650 | begin_function_definition (decl_specs, declarator) |
b4c4a9ec MM |
1651 | tree decl_specs; |
1652 | tree declarator; | |
1653 | { | |
1654 | tree specs; | |
1655 | tree attrs; | |
70adf8a9 | 1656 | |
b4c4a9ec | 1657 | split_specs_attrs (decl_specs, &specs, &attrs); |
a8f73d4b | 1658 | if (!start_function (specs, declarator, attrs, SF_DEFAULT)) |
b4c4a9ec | 1659 | return 0; |
1f51a992 JM |
1660 | |
1661 | deferred_type_access_control (); | |
1662 | type_lookups = error_mark_node; | |
1663 | ||
39c01e4c MM |
1664 | /* The things we're about to see are not directly qualified by any |
1665 | template headers we've seen thus far. */ | |
1666 | reset_specialization (); | |
1667 | ||
b4c4a9ec MM |
1668 | return 1; |
1669 | } | |
1670 | ||
1671 | /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns | |
1672 | a SCOPE_REF. */ | |
1673 | ||
1674 | tree | |
1675 | begin_constructor_declarator (scope, name) | |
1676 | tree scope; | |
1677 | tree name; | |
1678 | { | |
718b8ea5 | 1679 | tree result = build_nt (SCOPE_REF, scope, name); |
830fcda8 | 1680 | enter_scope_of (result); |
b4c4a9ec MM |
1681 | return result; |
1682 | } | |
1683 | ||
ce4a0391 MM |
1684 | /* Finish an init-declarator. Returns a DECL. */ |
1685 | ||
1686 | tree | |
1687 | finish_declarator (declarator, declspecs, attributes, | |
1688 | prefix_attributes, initialized) | |
1689 | tree declarator; | |
1690 | tree declspecs; | |
1691 | tree attributes; | |
1692 | tree prefix_attributes; | |
1693 | int initialized; | |
1694 | { | |
1695 | return start_decl (declarator, declspecs, initialized, attributes, | |
1696 | prefix_attributes); | |
1697 | } | |
1698 | ||
8014a339 | 1699 | /* Finish a translation unit. */ |
ce4a0391 MM |
1700 | |
1701 | void | |
1702 | finish_translation_unit () | |
1703 | { | |
1704 | /* In case there were missing closebraces, | |
1705 | get us back to the global binding level. */ | |
273a708f | 1706 | pop_everything (); |
ce4a0391 MM |
1707 | while (current_namespace != global_namespace) |
1708 | pop_namespace (); | |
1709 | finish_file (); | |
1710 | } | |
1711 | ||
b4c4a9ec MM |
1712 | /* Finish a template type parameter, specified as AGGR IDENTIFIER. |
1713 | Returns the parameter. */ | |
1714 | ||
1715 | tree | |
1716 | finish_template_type_parm (aggr, identifier) | |
1717 | tree aggr; | |
1718 | tree identifier; | |
1719 | { | |
6eabb241 | 1720 | if (aggr != class_type_node) |
b4c4a9ec | 1721 | { |
8251199e | 1722 | pedwarn ("template type parameters must use the keyword `class' or `typename'"); |
b4c4a9ec MM |
1723 | aggr = class_type_node; |
1724 | } | |
1725 | ||
1726 | return build_tree_list (aggr, identifier); | |
1727 | } | |
1728 | ||
1729 | /* Finish a template template parameter, specified as AGGR IDENTIFIER. | |
1730 | Returns the parameter. */ | |
1731 | ||
1732 | tree | |
1733 | finish_template_template_parm (aggr, identifier) | |
1734 | tree aggr; | |
1735 | tree identifier; | |
1736 | { | |
1737 | tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE); | |
1738 | tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); | |
1739 | DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; | |
1740 | DECL_TEMPLATE_RESULT (tmpl) = decl; | |
c727aa5e | 1741 | DECL_ARTIFICIAL (decl) = 1; |
b4c4a9ec MM |
1742 | end_template_decl (); |
1743 | ||
b37bf5bd NS |
1744 | my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110); |
1745 | ||
b4c4a9ec MM |
1746 | return finish_template_type_parm (aggr, tmpl); |
1747 | } | |
ce4a0391 MM |
1748 | |
1749 | /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is | |
1750 | non-zero, the parameter list was terminated by a `...'. */ | |
1751 | ||
1752 | tree | |
1753 | finish_parmlist (parms, ellipsis) | |
1754 | tree parms; | |
1755 | int ellipsis; | |
1756 | { | |
5cce22b6 NS |
1757 | if (parms) |
1758 | { | |
1759 | /* We mark the PARMS as a parmlist so that declarator processing can | |
1760 | disambiguate certain constructs. */ | |
1761 | TREE_PARMLIST (parms) = 1; | |
1762 | /* We do not append void_list_node here, but leave it to grokparms | |
1763 | to do that. */ | |
1764 | PARMLIST_ELLIPSIS_P (parms) = ellipsis; | |
1765 | } | |
ce4a0391 MM |
1766 | return parms; |
1767 | } | |
1768 | ||
1769 | /* Begin a class definition, as indicated by T. */ | |
1770 | ||
1771 | tree | |
1772 | begin_class_definition (t) | |
1773 | tree t; | |
1774 | { | |
788bf0e3 NS |
1775 | /* Check the bases are accessible. */ |
1776 | decl_type_access_control (TYPE_NAME (t)); | |
1777 | reset_type_access_control (); | |
1778 | ||
522d6614 NS |
1779 | if (processing_template_parmlist) |
1780 | { | |
1781 | cp_error ("definition of `%#T' inside template parameter list", t); | |
1782 | return error_mark_node; | |
1783 | } | |
ce4a0391 MM |
1784 | if (t == error_mark_node |
1785 | || ! IS_AGGR_TYPE (t)) | |
1786 | { | |
33848bb0 | 1787 | t = make_aggr_type (RECORD_TYPE); |
ce4a0391 MM |
1788 | pushtag (make_anon_name (), t, 0); |
1789 | } | |
830fcda8 JM |
1790 | |
1791 | /* In a definition of a member class template, we will get here with an | |
1792 | implicit typename, a TYPENAME_TYPE with a type. */ | |
1793 | if (TREE_CODE (t) == TYPENAME_TYPE) | |
1794 | t = TREE_TYPE (t); | |
4c571114 MM |
1795 | |
1796 | /* If we generated a partial instantiation of this type, but now | |
1797 | we're seeing a real definition, we're actually looking at a | |
1798 | partial specialization. Consider: | |
1799 | ||
1800 | template <class T, class U> | |
1801 | struct Y {}; | |
1802 | ||
1803 | template <class T> | |
1804 | struct X {}; | |
1805 | ||
1806 | template <class T, class U> | |
1807 | void f() | |
1808 | { | |
1809 | typename X<Y<T, U> >::A a; | |
1810 | } | |
1811 | ||
1812 | template <class T, class U> | |
1813 | struct X<Y<T, U> > | |
1814 | { | |
1815 | }; | |
1816 | ||
1817 | We have to undo the effects of the previous partial | |
1818 | instantiation. */ | |
1819 | if (PARTIAL_INSTANTIATION_P (t)) | |
1820 | { | |
1821 | if (!pedantic) | |
1822 | { | |
1823 | /* Unfortunately, when we're not in pedantic mode, we | |
1824 | attempt to actually fill in some of the fields of the | |
1825 | partial instantiation, in order to support the implicit | |
1826 | typename extension. Clear those fields now, in | |
1827 | preparation for the definition here. The fields cleared | |
1828 | here must match those set in instantiate_class_template. | |
1829 | Look for a comment mentioning begin_class_definition | |
1830 | there. */ | |
1831 | TYPE_BINFO_BASETYPES (t) = NULL_TREE; | |
1832 | TYPE_FIELDS (t) = NULL_TREE; | |
1833 | TYPE_METHODS (t) = NULL_TREE; | |
1834 | CLASSTYPE_TAGS (t) = NULL_TREE; | |
1ddd4323 | 1835 | CLASSTYPE_VBASECLASSES (t) = NULL_TREE; |
4c571114 MM |
1836 | TYPE_SIZE (t) = NULL_TREE; |
1837 | } | |
830fcda8 | 1838 | |
4c571114 MM |
1839 | /* This isn't a partial instantiation any more. */ |
1840 | PARTIAL_INSTANTIATION_P (t) = 0; | |
1841 | } | |
1842 | /* If this type was already complete, and we see another definition, | |
1843 | that's an error. */ | |
d0f062fb | 1844 | else if (COMPLETE_TYPE_P (t)) |
ce4a0391 | 1845 | duplicate_tag_error (t); |
4c571114 | 1846 | |
b4f70b3d NS |
1847 | /* Update the location of the decl. */ |
1848 | DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename; | |
1849 | DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno; | |
1850 | ||
4c571114 | 1851 | if (TYPE_BEING_DEFINED (t)) |
ce4a0391 | 1852 | { |
33848bb0 | 1853 | t = make_aggr_type (TREE_CODE (t)); |
ce4a0391 | 1854 | pushtag (TYPE_IDENTIFIER (t), t, 0); |
ce4a0391 | 1855 | } |
ff350acd | 1856 | maybe_process_partial_specialization (t); |
8f032717 | 1857 | pushclass (t, 1); |
ce4a0391 | 1858 | TYPE_BEING_DEFINED (t) = 1; |
55760a0c | 1859 | TYPE_PACKED (t) = flag_pack_struct; |
ce4a0391 MM |
1860 | /* Reset the interface data, at the earliest possible |
1861 | moment, as it might have been set via a class foo; | |
1862 | before. */ | |
6eabb241 MM |
1863 | { |
1864 | tree name = TYPE_IDENTIFIER (t); | |
1865 | ||
1866 | if (! ANON_AGGRNAME_P (name)) | |
1867 | { | |
1868 | CLASSTYPE_INTERFACE_ONLY (t) = interface_only; | |
1869 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X | |
1870 | (t, interface_unknown); | |
1871 | } | |
6eabb241 | 1872 | } |
ce4a0391 MM |
1873 | reset_specialization(); |
1874 | ||
b7975aed MM |
1875 | /* Make a declaration for this class in its own scope. */ |
1876 | build_self_reference (); | |
1877 | ||
830fcda8 | 1878 | return t; |
ce4a0391 MM |
1879 | } |
1880 | ||
61a127b3 MM |
1881 | /* Finish the member declaration given by DECL. */ |
1882 | ||
1883 | void | |
1884 | finish_member_declaration (decl) | |
1885 | tree decl; | |
1886 | { | |
1887 | if (decl == error_mark_node || decl == NULL_TREE) | |
1888 | return; | |
1889 | ||
1890 | if (decl == void_type_node) | |
1891 | /* The COMPONENT was a friend, not a member, and so there's | |
1892 | nothing for us to do. */ | |
1893 | return; | |
1894 | ||
1895 | /* We should see only one DECL at a time. */ | |
1896 | my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0); | |
1897 | ||
1898 | /* Set up access control for DECL. */ | |
1899 | TREE_PRIVATE (decl) | |
1900 | = (current_access_specifier == access_private_node); | |
1901 | TREE_PROTECTED (decl) | |
1902 | = (current_access_specifier == access_protected_node); | |
1903 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
1904 | { | |
17aec3eb RK |
1905 | TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl); |
1906 | TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl); | |
61a127b3 MM |
1907 | } |
1908 | ||
1909 | /* Mark the DECL as a member of the current class. */ | |
4f1c5b7d | 1910 | DECL_CONTEXT (decl) = current_class_type; |
61a127b3 | 1911 | |
421844e7 MM |
1912 | /* [dcl.link] |
1913 | ||
1914 | A C language linkage is ignored for the names of class members | |
1915 | and the member function type of class member functions. */ | |
1916 | if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c) | |
1917 | DECL_LANGUAGE (decl) = lang_cplusplus; | |
1918 | ||
61a127b3 MM |
1919 | /* Put functions on the TYPE_METHODS list and everything else on the |
1920 | TYPE_FIELDS list. Note that these are built up in reverse order. | |
1921 | We reverse them (to obtain declaration order) in finish_struct. */ | |
1922 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1923 | || DECL_FUNCTION_TEMPLATE_P (decl)) | |
1924 | { | |
1925 | /* We also need to add this function to the | |
1926 | CLASSTYPE_METHOD_VEC. */ | |
452a394b | 1927 | add_method (current_class_type, decl, /*error_p=*/0); |
61a127b3 MM |
1928 | |
1929 | TREE_CHAIN (decl) = TYPE_METHODS (current_class_type); | |
1930 | TYPE_METHODS (current_class_type) = decl; | |
1931 | } | |
1932 | else | |
1933 | { | |
1934 | /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields | |
1935 | go at the beginning. The reason is that lookup_field_1 | |
1936 | searches the list in order, and we want a field name to | |
1937 | override a type name so that the "struct stat hack" will | |
1938 | work. In particular: | |
1939 | ||
1940 | struct S { enum E { }; int E } s; | |
1941 | s.E = 3; | |
1942 | ||
1943 | is legal. In addition, the FIELD_DECLs must be maintained in | |
1944 | declaration order so that class layout works as expected. | |
1945 | However, we don't need that order until class layout, so we | |
1946 | save a little time by putting FIELD_DECLs on in reverse order | |
1947 | here, and then reversing them in finish_struct_1. (We could | |
1948 | also keep a pointer to the correct insertion points in the | |
1949 | list.) */ | |
1950 | ||
1951 | if (TREE_CODE (decl) == TYPE_DECL) | |
1952 | TYPE_FIELDS (current_class_type) | |
1953 | = chainon (TYPE_FIELDS (current_class_type), decl); | |
1954 | else | |
1955 | { | |
1956 | TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type); | |
1957 | TYPE_FIELDS (current_class_type) = decl; | |
1958 | } | |
8f032717 MM |
1959 | |
1960 | /* Enter the DECL into the scope of the class. */ | |
1961 | if (TREE_CODE (decl) != USING_DECL) | |
1962 | pushdecl_class_level (decl); | |
61a127b3 MM |
1963 | } |
1964 | } | |
1965 | ||
1966 | /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI, | |
1967 | the definition is immediately followed by a semicolon. Returns the | |
1968 | type. */ | |
ce4a0391 MM |
1969 | |
1970 | tree | |
fbdd0024 | 1971 | finish_class_definition (t, attributes, semi, pop_scope_p) |
ce4a0391 | 1972 | tree t; |
ce4a0391 MM |
1973 | tree attributes; |
1974 | int semi; | |
fbdd0024 | 1975 | int pop_scope_p; |
ce4a0391 | 1976 | { |
ce4a0391 MM |
1977 | /* finish_struct nukes this anyway; if finish_exception does too, |
1978 | then it can go. */ | |
1979 | if (semi) | |
1980 | note_got_semicolon (t); | |
1981 | ||
dc8263bc JM |
1982 | /* If we got any attributes in class_head, xref_tag will stick them in |
1983 | TREE_TYPE of the type. Grab them now. */ | |
1984 | attributes = chainon (TREE_TYPE (t), attributes); | |
1985 | TREE_TYPE (t) = NULL_TREE; | |
1986 | ||
ce4a0391 MM |
1987 | if (TREE_CODE (t) == ENUMERAL_TYPE) |
1988 | ; | |
1989 | else | |
1990 | { | |
9f33663b | 1991 | t = finish_struct (t, attributes); |
ce4a0391 MM |
1992 | if (semi) |
1993 | note_got_semicolon (t); | |
1994 | } | |
1995 | ||
ce4a0391 MM |
1996 | if (! semi) |
1997 | check_for_missing_semicolon (t); | |
fbdd0024 MM |
1998 | if (pop_scope_p) |
1999 | pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t))); | |
788bf0e3 NS |
2000 | if (current_function_decl) |
2001 | type_lookups = error_mark_node; | |
ce4a0391 MM |
2002 | if (current_scope () == current_function_decl) |
2003 | do_pending_defargs (); | |
2004 | ||
2005 | return t; | |
2006 | } | |
2007 | ||
2008 | /* Finish processing the default argument expressions cached during | |
2009 | the processing of a class definition. */ | |
2010 | ||
2011 | void | |
51632249 | 2012 | begin_inline_definitions () |
ce4a0391 | 2013 | { |
0e5921e8 | 2014 | if (current_scope () == current_function_decl) |
ce4a0391 MM |
2015 | do_pending_inlines (); |
2016 | } | |
2017 | ||
2018 | /* Finish processing the inline function definitions cached during the | |
2019 | processing of a class definition. */ | |
2020 | ||
2021 | void | |
51632249 | 2022 | finish_inline_definitions () |
ce4a0391 MM |
2023 | { |
2024 | if (current_class_type == NULL_TREE) | |
2025 | clear_inline_text_obstack (); | |
ce4a0391 | 2026 | } |
35acd3f2 MM |
2027 | |
2028 | /* Finish processing the declaration of a member class template | |
2029 | TYPES whose template parameters are given by PARMS. */ | |
2030 | ||
2031 | tree | |
61a127b3 | 2032 | finish_member_class_template (types) |
35acd3f2 MM |
2033 | tree types; |
2034 | { | |
36a117a5 MM |
2035 | tree t; |
2036 | ||
2037 | /* If there are declared, but undefined, partial specializations | |
2038 | mixed in with the typespecs they will not yet have passed through | |
2039 | maybe_process_partial_specialization, so we do that here. */ | |
2040 | for (t = types; t != NULL_TREE; t = TREE_CHAIN (t)) | |
2041 | if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t)))) | |
2042 | maybe_process_partial_specialization (TREE_VALUE (t)); | |
2043 | ||
35acd3f2 | 2044 | note_list_got_semicolon (types); |
61a127b3 | 2045 | grok_x_components (types); |
35acd3f2 MM |
2046 | if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type) |
2047 | /* The component was in fact a friend declaration. We avoid | |
2048 | finish_member_template_decl performing certain checks by | |
2049 | unsetting TYPES. */ | |
2050 | types = NULL_TREE; | |
61a127b3 MM |
2051 | |
2052 | finish_member_template_decl (types); | |
2053 | ||
35acd3f2 MM |
2054 | /* As with other component type declarations, we do |
2055 | not store the new DECL on the list of | |
2056 | component_decls. */ | |
2057 | return NULL_TREE; | |
2058 | } | |
36a117a5 MM |
2059 | |
2060 | /* Finish processsing a complete template declaration. The PARMS are | |
2061 | the template parameters. */ | |
2062 | ||
2063 | void | |
2064 | finish_template_decl (parms) | |
2065 | tree parms; | |
2066 | { | |
2067 | if (parms) | |
2068 | end_template_decl (); | |
2069 | else | |
2070 | end_specialization (); | |
2071 | } | |
2072 | ||
509fc277 | 2073 | /* Finish processing a template-id (which names a type) of the form |
36a117a5 MM |
2074 | NAME < ARGS >. Return the TYPE_DECL for the type named by the |
2075 | template-id. If ENTERING_SCOPE is non-zero we are about to enter | |
2076 | the scope of template-id indicated. */ | |
2077 | ||
2078 | tree | |
2079 | finish_template_type (name, args, entering_scope) | |
2080 | tree name; | |
2081 | tree args; | |
2082 | int entering_scope; | |
2083 | { | |
2084 | tree decl; | |
2085 | ||
2086 | decl = lookup_template_class (name, args, | |
f9c244b8 NS |
2087 | NULL_TREE, NULL_TREE, |
2088 | entering_scope, /*complain=*/1); | |
36a117a5 MM |
2089 | if (decl != error_mark_node) |
2090 | decl = TYPE_STUB_DECL (decl); | |
2091 | ||
2092 | return decl; | |
2093 | } | |
648f19f6 MM |
2094 | |
2095 | /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a | |
2096 | namespace scope or a class scope. */ | |
2097 | ||
2098 | void | |
2099 | enter_scope_of (sr) | |
2100 | tree sr; | |
2101 | { | |
2102 | tree scope = TREE_OPERAND (sr, 0); | |
2103 | ||
2104 | if (TREE_CODE (scope) == NAMESPACE_DECL) | |
2105 | { | |
2106 | push_decl_namespace (scope); | |
2107 | TREE_COMPLEXITY (sr) = -1; | |
2108 | } | |
2109 | else if (scope != current_class_type) | |
2110 | { | |
830fcda8 JM |
2111 | if (TREE_CODE (scope) == TYPENAME_TYPE) |
2112 | { | |
2113 | /* In a declarator for a template class member, the scope will | |
2114 | get here as an implicit typename, a TYPENAME_TYPE with a type. */ | |
2115 | scope = TREE_TYPE (scope); | |
2116 | TREE_OPERAND (sr, 0) = scope; | |
2117 | } | |
648f19f6 MM |
2118 | push_nested_class (scope, 3); |
2119 | TREE_COMPLEXITY (sr) = current_class_depth; | |
2120 | } | |
2121 | } | |
ea6021e8 MM |
2122 | |
2123 | /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. | |
2124 | Return a TREE_LIST containing the ACCESS_SPECIFIER and the | |
2125 | BASE_CLASS, or NULL_TREE if an error occurred. The | |
2126 | ACCESSS_SPECIFIER is one of | |
2127 | access_{default,public,protected_private}[_virtual]_node.*/ | |
2128 | ||
2129 | tree | |
6eabb241 | 2130 | finish_base_specifier (access_specifier, base_class) |
ea6021e8 MM |
2131 | tree access_specifier; |
2132 | tree base_class; | |
ea6021e8 | 2133 | { |
ea6021e8 MM |
2134 | tree result; |
2135 | ||
bb92901d | 2136 | if (! is_aggr_type (base_class, 1)) |
ea6021e8 | 2137 | result = NULL_TREE; |
ea6021e8 | 2138 | else |
bb92901d NS |
2139 | { |
2140 | if (CP_TYPE_QUALS (base_class) != 0) | |
2141 | { | |
2142 | cp_error ("base class `%T' has cv qualifiers", base_class); | |
2143 | base_class = TYPE_MAIN_VARIANT (base_class); | |
2144 | } | |
2145 | result = build_tree_list (access_specifier, base_class); | |
2146 | } | |
ea6021e8 MM |
2147 | |
2148 | return result; | |
2149 | } | |
61a127b3 MM |
2150 | |
2151 | /* Called when multiple declarators are processed. If that is not | |
2152 | premitted in this context, an error is issued. */ | |
2153 | ||
2154 | void | |
2155 | check_multiple_declarators () | |
2156 | { | |
2157 | /* [temp] | |
2158 | ||
2159 | In a template-declaration, explicit specialization, or explicit | |
2160 | instantiation the init-declarator-list in the declaration shall | |
2161 | contain at most one declarator. | |
2162 | ||
2163 | We don't just use PROCESSING_TEMPLATE_DECL for the first | |
2164 | condition since that would disallow the perfectly legal code, | |
2165 | like `template <class T> struct S { int i, j; };'. */ | |
2166 | tree scope = current_scope (); | |
2167 | ||
2168 | if (scope && TREE_CODE (scope) == FUNCTION_DECL) | |
2169 | /* It's OK to write `template <class T> void f() { int i, j;}'. */ | |
2170 | return; | |
2171 | ||
2172 | if (PROCESSING_REAL_TEMPLATE_DECL_P () | |
2173 | || processing_explicit_instantiation | |
2174 | || processing_specialization) | |
2175 | cp_error ("multiple declarators in template declaration"); | |
2176 | } | |
2177 | ||
b894fc05 JM |
2178 | tree |
2179 | finish_typeof (expr) | |
2180 | tree expr; | |
2181 | { | |
2182 | if (processing_template_decl) | |
2183 | { | |
2184 | tree t; | |
2185 | ||
33848bb0 | 2186 | t = make_aggr_type (TYPEOF_TYPE); |
b894fc05 | 2187 | TYPE_FIELDS (t) = expr; |
b894fc05 JM |
2188 | |
2189 | return t; | |
2190 | } | |
2191 | ||
12fa82db MM |
2192 | if (TREE_CODE (expr) == OFFSET_REF) |
2193 | expr = resolve_offset_ref (expr); | |
2194 | ||
b894fc05 JM |
2195 | return TREE_TYPE (expr); |
2196 | } | |
558475f0 | 2197 | |
62409b39 MM |
2198 | /* Generate RTL for the statement T, and its substatements, and any |
2199 | other statements at its nesting level. */ | |
558475f0 | 2200 | |
54f7877c MM |
2201 | static void |
2202 | cp_expand_stmt (t) | |
558475f0 MM |
2203 | tree t; |
2204 | { | |
54f7877c | 2205 | switch (TREE_CODE (t)) |
62409b39 | 2206 | { |
54f7877c MM |
2207 | case CLEANUP_STMT: |
2208 | genrtl_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t)); | |
2209 | break; | |
558475f0 | 2210 | |
54f7877c MM |
2211 | case START_CATCH_STMT: |
2212 | genrtl_catch_block (TREE_TYPE (t)); | |
2213 | break; | |
a7e4cfa0 | 2214 | |
54f7877c MM |
2215 | case CTOR_STMT: |
2216 | genrtl_ctor_stmt (t); | |
2217 | break; | |
a7e4cfa0 | 2218 | |
54f7877c MM |
2219 | case TRY_BLOCK: |
2220 | genrtl_try_block (t); | |
2221 | break; | |
558475f0 | 2222 | |
52a11cbf RH |
2223 | case EH_SPEC_BLOCK: |
2224 | genrtl_eh_spec_block (t); | |
2225 | break; | |
2226 | ||
54f7877c MM |
2227 | case HANDLER: |
2228 | genrtl_handler (t); | |
2229 | break; | |
558475f0 | 2230 | |
54f7877c MM |
2231 | case SUBOBJECT: |
2232 | genrtl_subobject (SUBOBJECT_CLEANUP (t)); | |
2233 | break; | |
2234 | ||
54f7877c MM |
2235 | case RETURN_INIT: |
2236 | genrtl_named_return_value (); | |
2237 | break; | |
2238 | ||
2239 | default: | |
2240 | my_friendly_abort (19990810); | |
2241 | break; | |
2242 | } | |
558475f0 MM |
2243 | } |
2244 | ||
3eb24f73 MM |
2245 | /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs |
2246 | will equivalent CALL_EXPRs. */ | |
2247 | ||
2248 | static tree | |
2249 | simplify_aggr_init_exprs_r (tp, walk_subtrees, data) | |
2250 | tree *tp; | |
2251 | int *walk_subtrees ATTRIBUTE_UNUSED; | |
2252 | void *data ATTRIBUTE_UNUSED; | |
2253 | { | |
2254 | tree aggr_init_expr; | |
2255 | tree call_expr; | |
2256 | tree fn; | |
2257 | tree args; | |
2258 | tree slot; | |
2259 | tree type; | |
3eb24f73 MM |
2260 | int copy_from_buffer_p; |
2261 | ||
3eb24f73 | 2262 | aggr_init_expr = *tp; |
22e92ac3 MM |
2263 | /* We don't need to walk into types; there's nothing in a type that |
2264 | needs simplification. (And, furthermore, there are places we | |
2265 | actively don't want to go. For example, we don't want to wander | |
2266 | into the default arguments for a FUNCTION_DECL that appears in a | |
2267 | CALL_EXPR.) */ | |
2268 | if (TYPE_P (aggr_init_expr)) | |
2269 | { | |
2270 | *walk_subtrees = 0; | |
2271 | return NULL_TREE; | |
2272 | } | |
2273 | /* Only AGGR_INIT_EXPRs are interesting. */ | |
2274 | else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR) | |
3eb24f73 MM |
2275 | return NULL_TREE; |
2276 | ||
2277 | /* Form an appropriate CALL_EXPR. */ | |
2278 | fn = TREE_OPERAND (aggr_init_expr, 0); | |
2279 | args = TREE_OPERAND (aggr_init_expr, 1); | |
2280 | slot = TREE_OPERAND (aggr_init_expr, 2); | |
2281 | type = TREE_TYPE (aggr_init_expr); | |
3eb24f73 MM |
2282 | if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr)) |
2283 | { | |
2284 | /* Replace the first argument with the address of the third | |
2285 | argument to the AGGR_INIT_EXPR. */ | |
3eb24f73 | 2286 | mark_addressable (slot); |
b850de4f MM |
2287 | args = tree_cons (NULL_TREE, |
2288 | build1 (ADDR_EXPR, | |
2289 | build_pointer_type (TREE_TYPE (slot)), | |
2290 | slot), | |
3eb24f73 MM |
2291 | TREE_CHAIN (args)); |
2292 | } | |
b850de4f MM |
2293 | call_expr = build (CALL_EXPR, |
2294 | TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), | |
2295 | fn, args, NULL_TREE); | |
3eb24f73 MM |
2296 | TREE_SIDE_EFFECTS (call_expr) = 1; |
2297 | ||
2298 | /* If we're using the non-reentrant PCC calling convention, then we | |
2299 | need to copy the returned value out of the static buffer into the | |
2300 | SLOT. */ | |
2301 | copy_from_buffer_p = 0; | |
2302 | #ifdef PCC_STATIC_STRUCT_RETURN | |
2303 | if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type)) | |
2304 | { | |
2305 | int old_ac; | |
2306 | ||
2307 | flag_access_control = 0; | |
2308 | call_expr = build_aggr_init (slot, call_expr, LOOKUP_ONLYCONVERTING); | |
2309 | flag_access_control = old_ac; | |
2310 | copy_from_buffer_p = 1; | |
2311 | } | |
2312 | #endif | |
2313 | ||
2314 | /* If this AGGR_INIT_EXPR indicates the value returned by a | |
2315 | function, then we want to use the value of the initialized | |
2316 | location as the result. */ | |
2317 | if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p) | |
2318 | { | |
2319 | call_expr = build (COMPOUND_EXPR, type, | |
2320 | call_expr, slot); | |
2321 | TREE_SIDE_EFFECTS (call_expr) = 1; | |
2322 | } | |
2323 | ||
2324 | /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */ | |
2325 | TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr); | |
2326 | *tp = call_expr; | |
2327 | ||
2328 | /* Keep iterating. */ | |
2329 | return NULL_TREE; | |
2330 | } | |
2331 | ||
31f8e4f3 MM |
2332 | /* Emit all thunks to FN that should be emitted when FN is emitted. */ |
2333 | ||
2334 | static void | |
2335 | emit_associated_thunks (fn) | |
2336 | tree fn; | |
2337 | { | |
2338 | /* When we use vcall offsets, we emit thunks with the virtual | |
2339 | functions to which they thunk. The whole point of vcall offsets | |
2340 | is so that you can know statically the entire set of thunks that | |
2341 | will ever be needed for a given virtual function, thereby | |
2342 | enabling you to output all the thunks with the function itself. */ | |
2343 | if (vcall_offsets_in_vtable_p () && DECL_VIRTUAL_P (fn)) | |
2344 | { | |
2345 | tree binfo; | |
2346 | tree v; | |
2347 | ||
2348 | for (binfo = TYPE_BINFO (DECL_CONTEXT (fn)); | |
2349 | binfo; | |
2350 | binfo = TREE_CHAIN (binfo)) | |
2351 | for (v = BINFO_VIRTUALS (binfo); v; v = TREE_CHAIN (v)) | |
2352 | if (BV_FN (v) == fn | |
2353 | && (!integer_zerop (BV_DELTA (v)) | |
2354 | || BV_VCALL_INDEX (v))) | |
2355 | { | |
2356 | tree thunk; | |
2357 | tree vcall_index; | |
2358 | ||
2359 | if (BV_USE_VCALL_INDEX_P (v)) | |
2360 | { | |
2361 | vcall_index = BV_VCALL_INDEX (v); | |
2362 | my_friendly_assert (vcall_index != NULL_TREE, 20000621); | |
2363 | } | |
2364 | else | |
2365 | vcall_index = NULL_TREE; | |
2366 | ||
2367 | thunk = make_thunk (build1 (ADDR_EXPR, | |
2368 | vfunc_ptr_type_node, | |
2369 | fn), | |
2370 | BV_DELTA (v), | |
2371 | vcall_index, | |
2372 | /*generate_with_vtable_p=*/0); | |
2373 | use_thunk (thunk, /*emit_p=*/1); | |
2374 | } | |
2375 | } | |
2376 | } | |
2377 | ||
558475f0 MM |
2378 | /* Generate RTL for FN. */ |
2379 | ||
2380 | void | |
2381 | expand_body (fn) | |
2382 | tree fn; | |
2383 | { | |
62409b39 | 2384 | int saved_lineno; |
3b304f5b | 2385 | const char *saved_input_filename; |
558475f0 | 2386 | |
62409b39 MM |
2387 | /* When the parser calls us after finishing the body of a template |
2388 | function, we don't really want to expand the body. When we're | |
2389 | processing an in-class definition of an inline function, | |
2390 | PROCESSING_TEMPLATE_DECL will no longer be set here, so we have | |
2391 | to look at the function itself. */ | |
2392 | if (processing_template_decl | |
2393 | || (DECL_LANG_SPECIFIC (fn) | |
2394 | && DECL_TEMPLATE_INFO (fn) | |
2395 | && uses_template_parms (DECL_TI_ARGS (fn)))) | |
d658cd4c MM |
2396 | { |
2397 | /* Normally, collection only occurs in rest_of_compilation. So, | |
2398 | if we don't collect here, we never collect junk generated | |
2399 | during the processing of templates until we hit a | |
2400 | non-template function. */ | |
2401 | ggc_collect (); | |
2402 | return; | |
2403 | } | |
62409b39 | 2404 | |
3eb24f73 | 2405 | /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */ |
ee94fce6 MM |
2406 | walk_tree_without_duplicates (&DECL_SAVED_TREE (fn), |
2407 | simplify_aggr_init_exprs_r, | |
2408 | NULL); | |
3eb24f73 | 2409 | |
db9b2174 MM |
2410 | /* If this is a constructor or destructor body, we have to clone it |
2411 | under the new ABI. */ | |
2412 | if (maybe_clone_body (fn)) | |
2413 | { | |
2414 | /* We don't want to process FN again, so pretend we've written | |
2415 | it out, even though we haven't. */ | |
2416 | TREE_ASM_WRITTEN (fn) = 1; | |
2417 | return; | |
2418 | } | |
2419 | ||
84df082b MM |
2420 | /* There's no reason to do any of the work here if we're only doing |
2421 | semantic analysis; this code just generates RTL. */ | |
2422 | if (flag_syntax_only) | |
2423 | return; | |
2424 | ||
21b0c6dc MM |
2425 | /* If possible, avoid generating RTL for this function. Instead, |
2426 | just record it as an inline function, and wait until end-of-file | |
2427 | to decide whether to write it out or not. */ | |
56e770bf MM |
2428 | if (/* We have to generate RTL if it's not an inline function. */ |
2429 | (DECL_INLINE (fn) || DECL_COMDAT (fn)) | |
21b0c6dc MM |
2430 | /* Or if we have to keep all inline functions anyhow. */ |
2431 | && !flag_keep_inline_functions | |
2432 | /* Or if we actually have a reference to the function. */ | |
2433 | && !DECL_NEEDED_P (fn) | |
21b0c6dc | 2434 | /* Or if this is a nested function. */ |
4f1c5b7d | 2435 | && !decl_function_context (fn)) |
21b0c6dc | 2436 | { |
21b0c6dc MM |
2437 | /* Set DECL_EXTERNAL so that assemble_external will be called as |
2438 | necessary. We'll clear it again in finish_file. */ | |
2439 | if (!DECL_EXTERNAL (fn)) | |
2440 | { | |
2441 | DECL_NOT_REALLY_EXTERN (fn) = 1; | |
2442 | DECL_EXTERNAL (fn) = 1; | |
2443 | } | |
2444 | /* Remember this function. In finish_file we'll decide if | |
2445 | we actually need to write this function out. */ | |
56e770bf | 2446 | defer_fn (fn); |
de23a892 MM |
2447 | /* Let the back-end know that this funtion exists. */ |
2448 | note_deferral_of_defined_inline_function (fn); | |
21b0c6dc MM |
2449 | return; |
2450 | } | |
2451 | ||
92788413 MM |
2452 | /* Compute the appropriate object-file linkage for inline |
2453 | functions. */ | |
79065db2 | 2454 | if (DECL_DECLARED_INLINE_P (fn)) |
92788413 MM |
2455 | import_export_decl (fn); |
2456 | ||
31f8e4f3 MM |
2457 | /* Emit any thunks that should be emitted at the same time as FN. */ |
2458 | emit_associated_thunks (fn); | |
2459 | ||
297a5329 | 2460 | timevar_push (TV_INTEGRATION); |
ea11ca7e | 2461 | |
46e8c075 MM |
2462 | /* Optimize the body of the function before expanding it. */ |
2463 | optimize_function (fn); | |
2464 | ||
297a5329 JM |
2465 | timevar_pop (TV_INTEGRATION); |
2466 | timevar_push (TV_EXPAND); | |
2467 | ||
62409b39 | 2468 | /* Save the current file name and line number. When we expand the |
84df082b | 2469 | body of the function, we'll set LINENO and INPUT_FILENAME so that |
62409b39 MM |
2470 | error-mesages come out in the right places. */ |
2471 | saved_lineno = lineno; | |
2472 | saved_input_filename = input_filename; | |
2473 | lineno = DECL_SOURCE_LINE (fn); | |
2474 | input_filename = DECL_SOURCE_FILE (fn); | |
2475 | ||
f444e36b | 2476 | genrtl_start_function (fn); |
6462c441 | 2477 | current_function_is_thunk = DECL_THUNK_P (fn); |
558475f0 | 2478 | |
24bef158 MM |
2479 | /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or |
2480 | any of the other magic variables we set up when starting a | |
2481 | function body. */ | |
8f17b5c5 | 2482 | function_name_declared_p = 1; |
24bef158 | 2483 | |
558475f0 | 2484 | /* Expand the body. */ |
b35d4555 | 2485 | expand_stmt (DECL_SAVED_TREE (fn)); |
558475f0 | 2486 | |
62409b39 MM |
2487 | /* Statements should always be full-expressions at the outermost set |
2488 | of curly braces for a function. */ | |
f2c5f623 | 2489 | my_friendly_assert (stmts_are_full_exprs_p (), 19990831); |
62409b39 MM |
2490 | |
2491 | /* The outermost statement for a function contains the line number | |
2492 | recorded when we finished processing the function. */ | |
2493 | lineno = STMT_LINENO (DECL_SAVED_TREE (fn)); | |
2494 | ||
2495 | /* Generate code for the function. */ | |
f444e36b | 2496 | genrtl_finish_function (fn); |
62409b39 | 2497 | |
46e8c075 MM |
2498 | /* If possible, obliterate the body of the function so that it can |
2499 | be garbage collected. */ | |
2500 | if (flag_dump_translation_unit) | |
2501 | /* Keep the body; we're going to dump it. */ | |
2502 | ; | |
2503 | else if (DECL_INLINE (fn) && flag_inline_trees) | |
2504 | /* We might need the body of this function so that we can expand | |
2505 | it inline somewhere else. */ | |
2506 | ; | |
2507 | else | |
2508 | /* We don't need the body; blow it away. */ | |
d658cd4c MM |
2509 | DECL_SAVED_TREE (fn) = NULL_TREE; |
2510 | ||
62409b39 MM |
2511 | /* And restore the current source position. */ |
2512 | lineno = saved_lineno; | |
2513 | input_filename = saved_input_filename; | |
f12eef58 | 2514 | extract_interface_info (); |
ea11ca7e JM |
2515 | |
2516 | timevar_pop (TV_EXPAND); | |
558475f0 | 2517 | } |
54f7877c | 2518 | |
f444e36b MM |
2519 | /* Start generating the RTL for FN. */ |
2520 | ||
2521 | static void | |
2522 | genrtl_start_function (fn) | |
2523 | tree fn; | |
2524 | { | |
2525 | tree parm; | |
2526 | ||
2527 | /* Tell everybody what function we're processing. */ | |
2528 | current_function_decl = fn; | |
2529 | /* Get the RTL machinery going for this function. */ | |
2530 | init_function_start (fn, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn)); | |
2531 | /* Let everybody know that we're expanding this function, not doing | |
2532 | semantic analysis. */ | |
2533 | expanding_p = 1; | |
2534 | ||
2535 | /* Even though we're inside a function body, we still don't want to | |
2536 | call expand_expr to calculate the size of a variable-sized array. | |
2537 | We haven't necessarily assigned RTL to all variables yet, so it's | |
2538 | not safe to try to expand expressions involving them. */ | |
2539 | immediate_size_expand = 0; | |
2540 | cfun->x_dont_save_pending_sizes_p = 1; | |
2541 | ||
2542 | /* Let the user know we're compiling this function. */ | |
2543 | announce_function (fn); | |
2544 | ||
2545 | /* Initialize the per-function data. */ | |
2546 | my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911); | |
2547 | if (DECL_SAVED_FUNCTION_DATA (fn)) | |
2548 | { | |
2549 | /* If we already parsed this function, and we're just expanding it | |
2550 | now, restore saved state. */ | |
2551 | *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn); | |
2552 | ||
2553 | /* This function is being processed in whole-function mode; we | |
2554 | already did semantic analysis. */ | |
2555 | cfun->x_whole_function_mode_p = 1; | |
2556 | ||
2557 | /* If we decided that we didn't want to inline this function, | |
2558 | make sure the back-end knows that. */ | |
2559 | if (!current_function_cannot_inline) | |
2560 | current_function_cannot_inline = cp_function_chain->cannot_inline; | |
2561 | ||
2562 | /* We don't need the saved data anymore. */ | |
2563 | free (DECL_SAVED_FUNCTION_DATA (fn)); | |
2564 | DECL_SAVED_FUNCTION_DATA (fn) = NULL; | |
2565 | } | |
2566 | ||
2567 | /* Tell the cross-reference machinery that we're defining this | |
2568 | function. */ | |
2569 | GNU_xref_function (fn, DECL_ARGUMENTS (fn)); | |
2570 | ||
2571 | /* Keep track of how many functions we're presently expanding. */ | |
2572 | ++function_depth; | |
2573 | ||
2574 | /* Create a binding level for the parameters. */ | |
2575 | expand_start_bindings (2); | |
2576 | /* Clear out any previously saved instructions for this function, in | |
2577 | case it was defined more than once. */ | |
2578 | DECL_SAVED_INSNS (fn) = NULL; | |
2579 | /* Go through the PARM_DECLs for this function to see if any need | |
2580 | cleanups. */ | |
2581 | for (parm = DECL_ARGUMENTS (fn); parm; parm = TREE_CHAIN (parm)) | |
2582 | if (TREE_TYPE (parm) != error_mark_node | |
2583 | && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (parm))) | |
2584 | { | |
2585 | expand_function_start (fn, /*parms_have_cleanups=*/1); | |
2586 | break; | |
2587 | } | |
2588 | if (!parm) | |
2589 | expand_function_start (fn, /*parms_have_cleanups=*/0); | |
2590 | /* If this function is `main'. */ | |
2591 | if (DECL_MAIN_P (fn)) | |
2592 | expand_main_function (); | |
2593 | /* Create a binding contour which can be used to catch | |
2594 | cleanup-generated temporaries. */ | |
2595 | expand_start_bindings (2); | |
2596 | } | |
2597 | ||
2598 | /* Finish generating the RTL for FN. */ | |
2599 | ||
2600 | static void | |
2601 | genrtl_finish_function (fn) | |
2602 | tree fn; | |
2603 | { | |
f444e36b MM |
2604 | tree no_return_label = NULL_TREE; |
2605 | ||
2606 | #if 0 | |
2607 | if (write_symbols != NO_DEBUG) | |
2608 | { | |
2609 | /* Keep this code around in case we later want to control debug info | |
2610 | based on whether a type is "used". (jason 1999-11-11) */ | |
2611 | ||
2612 | tree ttype = target_type (fntype); | |
2613 | tree parmdecl; | |
2614 | ||
2615 | if (IS_AGGR_TYPE (ttype)) | |
2616 | /* Let debugger know it should output info for this type. */ | |
2617 | note_debug_info_needed (ttype); | |
2618 | ||
2619 | for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) | |
2620 | { | |
2621 | ttype = target_type (TREE_TYPE (parmdecl)); | |
2622 | if (IS_AGGR_TYPE (ttype)) | |
2623 | /* Let debugger know it should output info for this type. */ | |
2624 | note_debug_info_needed (ttype); | |
2625 | } | |
2626 | } | |
2627 | #endif | |
2628 | ||
2629 | /* Clean house because we will need to reorder insns here. */ | |
2630 | do_pending_stack_adjust (); | |
2631 | ||
2632 | if (!dtor_label && !DECL_CONSTRUCTOR_P (fn) | |
2633 | && return_label != NULL_RTX | |
2634 | && current_function_return_value == NULL_TREE | |
2635 | && ! DECL_NAME (DECL_RESULT (current_function_decl))) | |
2636 | no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); | |
2637 | ||
f444e36b MM |
2638 | /* If this function is supposed to return a value, ensure that |
2639 | we do not fall into the cleanups by mistake. The end of our | |
2640 | function will look like this: | |
2641 | ||
2642 | user code (may have return stmt somewhere) | |
2643 | goto no_return_label | |
2644 | cleanup_label: | |
2645 | cleanups | |
2646 | goto return_label | |
2647 | no_return_label: | |
2648 | NOTE_INSN_FUNCTION_END | |
2649 | return_label: | |
2650 | things for return | |
2651 | ||
2652 | If the user omits a return stmt in the USER CODE section, we | |
2653 | will have a control path which reaches NOTE_INSN_FUNCTION_END. | |
2654 | Otherwise, we won't. */ | |
2655 | if (no_return_label) | |
2656 | { | |
2657 | DECL_CONTEXT (no_return_label) = fn; | |
2658 | DECL_INITIAL (no_return_label) = error_mark_node; | |
2659 | DECL_SOURCE_FILE (no_return_label) = input_filename; | |
2660 | DECL_SOURCE_LINE (no_return_label) = lineno; | |
2661 | expand_goto (no_return_label); | |
2662 | } | |
2663 | ||
2664 | if (cleanup_label) | |
2665 | { | |
2666 | /* Remove the binding contour which is used to catch | |
2667 | cleanup-generated temporaries. */ | |
2668 | expand_end_bindings (0, 0, 0); | |
2669 | poplevel (0, 0, 0); | |
2670 | ||
2671 | /* Emit label at beginning of cleanup code for parameters. */ | |
2672 | emit_label (cleanup_label); | |
2673 | } | |
2674 | ||
f444e36b MM |
2675 | /* Finish building code that will trigger warnings if users forget |
2676 | to make their functions return values. */ | |
e6fe680d JM |
2677 | if (return_label) |
2678 | emit_jump (return_label); | |
f444e36b MM |
2679 | if (no_return_label) |
2680 | { | |
2681 | /* We don't need to call `expand_*_return' here because we don't | |
2682 | need any cleanups here--this path of code is only for error | |
2683 | checking purposes. */ | |
2684 | expand_label (no_return_label); | |
2685 | } | |
2686 | ||
2687 | /* We hard-wired immediate_size_expand to zero in start_function. | |
2688 | Expand_function_end will decrement this variable. So, we set the | |
2689 | variable to one here, so that after the decrement it will remain | |
2690 | zero. */ | |
2691 | immediate_size_expand = 1; | |
2692 | ||
2693 | /* Generate rtl for function exit. */ | |
2694 | expand_function_end (input_filename, lineno, 1); | |
2695 | ||
f444e36b MM |
2696 | /* If this is a nested function (like a template instantiation that |
2697 | we're compiling in the midst of compiling something else), push a | |
2698 | new GC context. That will keep local variables on the stack from | |
2699 | being collected while we're doing the compilation of this | |
2700 | function. */ | |
2701 | if (function_depth > 1) | |
2702 | ggc_push_context (); | |
2703 | ||
b850de4f MM |
2704 | /* There's no need to defer outputting this function any more; we |
2705 | know we want to output it. */ | |
2706 | DECL_DEFER_OUTPUT (fn) = 0; | |
2707 | ||
f444e36b MM |
2708 | /* Run the optimizers and output the assembler code for this |
2709 | function. */ | |
2710 | rest_of_compilation (fn); | |
2711 | ||
2712 | /* Undo the call to ggc_push_context above. */ | |
2713 | if (function_depth > 1) | |
2714 | ggc_pop_context (); | |
2715 | ||
2716 | if (DECL_SAVED_INSNS (fn) && ! TREE_ASM_WRITTEN (fn)) | |
2717 | { | |
2718 | /* Set DECL_EXTERNAL so that assemble_external will be called as | |
2719 | necessary. We'll clear it again in finish_file. */ | |
2720 | if (! DECL_EXTERNAL (fn)) | |
2721 | DECL_NOT_REALLY_EXTERN (fn) = 1; | |
2722 | DECL_EXTERNAL (fn) = 1; | |
2723 | defer_fn (fn); | |
2724 | } | |
2725 | ||
2726 | #if 0 | |
2727 | /* Keep this code around in case we later want to control debug info | |
2728 | based on whether a type is "used". (jason 1999-11-11) */ | |
2729 | ||
2730 | if (ctype && TREE_ASM_WRITTEN (fn)) | |
2731 | note_debug_info_needed (ctype); | |
2732 | #endif | |
2733 | ||
2734 | /* If this function is marked with the constructor attribute, add it | |
2735 | to the list of functions to be called along with constructors | |
2736 | from static duration objects. */ | |
2737 | if (DECL_STATIC_CONSTRUCTOR (fn)) | |
2738 | static_ctors = tree_cons (NULL_TREE, fn, static_ctors); | |
2739 | ||
2740 | /* If this function is marked with the destructor attribute, add it | |
2741 | to the list of functions to be called along with destructors from | |
2742 | static duration objects. */ | |
2743 | if (DECL_STATIC_DESTRUCTOR (fn)) | |
2744 | static_dtors = tree_cons (NULL_TREE, fn, static_dtors); | |
2745 | ||
f444e36b MM |
2746 | --function_depth; |
2747 | ||
b850de4f MM |
2748 | /* If we don't need the RTL for this function anymore, stop pointing |
2749 | to it. That's especially important for LABEL_DECLs, since you | |
2750 | can reach all the instructions in the function from the | |
2751 | CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. */ | |
2752 | if (!DECL_SAVED_INSNS (fn)) | |
f444e36b MM |
2753 | { |
2754 | tree t; | |
2755 | ||
b850de4f MM |
2756 | /* Walk the BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and |
2757 | non-static local variables. */ | |
2758 | walk_tree_without_duplicates (&DECL_SAVED_TREE (fn), | |
2759 | clear_decl_rtl, | |
2760 | NULL); | |
2761 | ||
2762 | /* Clear out the RTL for the arguments. */ | |
f444e36b | 2763 | for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t)) |
19e7881c MM |
2764 | { |
2765 | SET_DECL_RTL (t, NULL_RTX); | |
2766 | DECL_INCOMING_RTL (t) = NULL_RTX; | |
2767 | } | |
f444e36b | 2768 | |
b850de4f MM |
2769 | if (!(flag_inline_trees && DECL_INLINE (fn))) |
2770 | /* DECL_INITIAL must remain nonzero so we know this was an | |
2771 | actual function definition. */ | |
2772 | DECL_INITIAL (fn) = error_mark_node; | |
2773 | } | |
2774 | ||
f444e36b MM |
2775 | /* Let the error reporting routines know that we're outside a |
2776 | function. For a nested function, this value is used in | |
2777 | pop_cp_function_context and then reset via pop_function_context. */ | |
2778 | current_function_decl = NULL_TREE; | |
2779 | } | |
2780 | ||
b850de4f MM |
2781 | /* Clear out the DECL_RTL for the non-static variables in BLOCK and |
2782 | its sub-blocks. */ | |
2783 | ||
2784 | static tree | |
2785 | clear_decl_rtl (tp, walk_subtrees, data) | |
2786 | tree *tp; | |
2787 | int *walk_subtrees ATTRIBUTE_UNUSED; | |
2788 | void *data ATTRIBUTE_UNUSED; | |
2789 | { | |
2790 | if (nonstatic_local_decl_p (*tp)) | |
2791 | SET_DECL_RTL (*tp, NULL_RTX); | |
2792 | ||
2793 | return NULL_TREE; | |
2794 | } | |
2795 | ||
54f7877c MM |
2796 | /* Perform initialization related to this module. */ |
2797 | ||
2798 | void | |
2799 | init_cp_semantics () | |
2800 | { | |
2801 | lang_expand_stmt = cp_expand_stmt; | |
2802 | } |