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