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