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