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