]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
c-decl.c (finish_function): When processing a nested function...
[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
4c571114 6 Copyright (C) 1998, 1999 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"
ad321293
MM
34
35/* There routines provide a modular interface to perform many parsing
36 operations. They may therefore be used during actual parsing, or
37 during template instantiation, which may be regarded as a
38 degenerate form of parsing. Since the current g++ parser is
39 lacking in several respects, and will be reimplemented, we are
40 attempting to move most code that is not directly related to
41 parsing into this file; that will make implementing the new parser
42 much easier since it will be able to make use of these routines. */
43
558475f0 44static void expand_stmts PROTO((tree));
f1dedc31
MM
45static void do_pushlevel PROTO((void));
46static tree do_poplevel PROTO((void));
a7e4cfa0 47static void finish_expr_stmt_real PROTO((tree, int));
527f0080 48static tree expand_cond PROTO((tree));
558475f0 49
ad321293
MM
50/* When parsing a template, LAST_TREE contains the last statement
51 parsed. These are chained together through the TREE_CHAIN field,
52 but often need to be re-organized since the parse is performed
53 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
54 STMT. */
55
56#define RECHAIN_STMTS(stmt, substmt, last) \
57 do { \
58 substmt = last; \
59 TREE_CHAIN (stmt) = NULL_TREE; \
60 last_tree = stmt; \
61 } while (0)
62
63#define RECHAIN_STMTS_FROM_LAST(stmt, substmt) \
64 RECHAIN_STMTS (stmt, substmt, last_tree)
65
66#define RECHAIN_STMTS_FROM_CHAIN(stmt, substmt) \
67 RECHAIN_STMTS (stmt, substmt, TREE_CHAIN (stmt))
68
527f0080
MM
69/* Finish processing the COND, the SUBSTMT condition for STMT. */
70
71#define FINISH_COND(cond, stmt, substmt) \
72 do { \
73 if (last_tree != stmt) \
74 RECHAIN_STMTS_FROM_LAST (stmt, substmt); \
75 else \
76 substmt = cond; \
77 } while (0)
78
a7e4cfa0 79/* T is a statement. Add it to the statement-tree. */
ad321293 80
a7e4cfa0
MM
81void
82add_tree (t)
83 tree t;
84{
85 /* Add T to the statement-tree. */
86 last_tree = TREE_CHAIN (last_tree) = t;
87
88 /* When we expand a statement-tree, we must know whether or not the
89 statements are full-expresions. We record that fact here. */
90 if (building_stmt_tree ())
91 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p;
92}
93
94/* Finish an expression-statement, whose EXPRESSION is as indicated.
95 If ASSIGNED_THIS is non-zero, then this statement just assigned to
96 the `this' pointer. */
97
98static void
99finish_expr_stmt_real (expr, assigned_this)
ad321293 100 tree expr;
a7e4cfa0 101 int assigned_this;
ad321293 102{
ce4a0391 103 if (expr != NULL_TREE)
ad321293 104 {
558475f0
MM
105 if (building_stmt_tree ())
106 add_tree (build_min_nt (EXPR_STMT, expr));
107 else
ce4a0391
MM
108 {
109 emit_line_note (input_filename, lineno);
110 /* Do default conversion if safe and possibly important,
111 in case within ({...}). */
02cac427
NS
112 if (!stmts_are_full_exprs_p &&
113 ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
114 && lvalue_p (expr))
115 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
ce4a0391 116 expr = default_conversion (expr);
f1dedc31
MM
117
118 if (stmts_are_full_exprs_p)
119 expand_start_target_temps ();
120
558475f0 121 cplus_expand_expr_stmt (expr);
558475f0 122
f1dedc31
MM
123 if (stmts_are_full_exprs_p)
124 {
125 expand_end_target_temps ();
126 clear_momentary ();
127 }
128 }
ad321293 129 }
ce4a0391 130
a7e4cfa0
MM
131 /* If this statement assigned to the `this' pointer, record that
132 fact for finish_stmt. */
133 if (assigned_this)
134 current_function_just_assigned_this = 1;
135
ad321293 136 finish_stmt ();
558475f0
MM
137
138 /* This was an expression-statement, so we save the type of the
139 expression. */
140 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
ad321293
MM
141}
142
a7e4cfa0
MM
143/* Like finish_expr_stmt_real, but ASSIGNS_THIS is always zero. */
144
145void
146finish_expr_stmt (expr)
147 tree expr;
148{
149 finish_expr_stmt_real (expr, /*assigns_this=*/0);
150}
151
ad321293
MM
152/* Begin an if-statement. Returns a newly created IF_STMT if
153 appropriate. */
154
155tree
156begin_if_stmt ()
157{
158 tree r;
159
558475f0 160 if (building_stmt_tree ())
ad321293
MM
161 {
162 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
163 add_tree (r);
164 }
165 else
166 r = NULL_TREE;
167
168 do_pushlevel ();
169
170 return r;
171}
172
173/* Process the COND of an if-statement, which may be given by
174 IF_STMT. */
175
176void
177finish_if_stmt_cond (cond, if_stmt)
178 tree cond;
179 tree if_stmt;
180{
558475f0 181 if (building_stmt_tree ())
a7e4cfa0 182 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
ad321293
MM
183 else
184 {
185 emit_line_note (input_filename, lineno);
186 expand_start_cond (condition_conversion (cond), 0);
187 }
188}
189
190/* Finish the then-clause of an if-statement, which may be given by
191 IF_STMT. */
192
193tree
194finish_then_clause (if_stmt)
195 tree if_stmt;
196{
558475f0 197 if (building_stmt_tree ())
ad321293
MM
198 {
199 RECHAIN_STMTS_FROM_CHAIN (if_stmt,
200 THEN_CLAUSE (if_stmt));
201 last_tree = if_stmt;
202 return if_stmt;
203 }
204 else
205 return NULL_TREE;
206}
207
208/* Begin the else-clause of an if-statement. */
209
210void
211begin_else_clause ()
212{
558475f0 213 if (!building_stmt_tree ())
ad321293
MM
214 expand_start_else ();
215}
216
217/* Finish the else-clause of an if-statement, which may be given by
218 IF_STMT. */
219
220void
221finish_else_clause (if_stmt)
222 tree if_stmt;
223{
558475f0 224 if (building_stmt_tree ())
ad321293
MM
225 RECHAIN_STMTS_FROM_CHAIN (if_stmt, ELSE_CLAUSE (if_stmt));
226}
227
228/* Finsh an if-statement. */
229
230void
231finish_if_stmt ()
232{
558475f0 233 if (!building_stmt_tree ())
ad321293
MM
234 expand_end_cond ();
235
236 do_poplevel ();
237 finish_stmt ();
238}
239
240/* Begin a while-statement. Returns a newly created WHILE_STMT if
241 appropriate. */
242
243tree
244begin_while_stmt ()
245{
246 tree r;
247
558475f0 248 if (building_stmt_tree ())
ad321293
MM
249 {
250 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
251 add_tree (r);
252 }
253 else
254 {
255 emit_nop ();
256 emit_line_note (input_filename, lineno);
257 expand_start_loop (1);
258 r = NULL_TREE;
259 }
260
261 do_pushlevel ();
262
263 return r;
264}
265
266/* Process the COND of an if-statement, which may be given by
267 WHILE_STMT. */
268
269void
270finish_while_stmt_cond (cond, while_stmt)
271 tree cond;
272 tree while_stmt;
273{
558475f0 274 if (building_stmt_tree ())
a7e4cfa0 275 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
ad321293
MM
276 else
277 {
278 emit_line_note (input_filename, lineno);
279 expand_exit_loop_if_false (0, condition_conversion (cond));
280 }
281
282 /* If COND wasn't a declaration, clear out the
283 block we made for it and start a new one here so the
284 optimization in expand_end_loop will work. */
285 if (getdecls () == NULL_TREE)
286 {
287 do_poplevel ();
288 do_pushlevel ();
289 }
290}
291
292/* Finish a while-statement, which may be given by WHILE_STMT. */
293
294void
295finish_while_stmt (while_stmt)
296 tree while_stmt;
297{
298 do_poplevel ();
299
558475f0 300 if (building_stmt_tree ())
ad321293
MM
301 RECHAIN_STMTS_FROM_CHAIN (while_stmt, WHILE_BODY (while_stmt));
302 else
303 expand_end_loop ();
304 finish_stmt ();
305}
306
307/* Begin a do-statement. Returns a newly created DO_STMT if
308 appropriate. */
309
310tree
311begin_do_stmt ()
312{
558475f0 313 if (building_stmt_tree ())
ad321293
MM
314 {
315 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
316 add_tree (r);
317 return r;
318 }
319 else
320 {
321 emit_nop ();
322 emit_line_note (input_filename, lineno);
323 expand_start_loop_continue_elsewhere (1);
324 return NULL_TREE;
325 }
326}
327
328/* Finish the body of a do-statement, which may be given by DO_STMT. */
329
330void
331finish_do_body (do_stmt)
332 tree do_stmt;
333{
558475f0 334 if (building_stmt_tree ())
ad321293
MM
335 RECHAIN_STMTS_FROM_CHAIN (do_stmt, DO_BODY (do_stmt));
336 else
337 expand_loop_continue_here ();
338}
339
340/* Finish a do-statement, which may be given by DO_STMT, and whose
341 COND is as indicated. */
342
343void
344finish_do_stmt (cond, do_stmt)
345 tree cond;
346 tree do_stmt;
347{
558475f0 348 if (building_stmt_tree ())
2a1e9fdd 349 DO_COND (do_stmt) = cond;
ad321293
MM
350 else
351 {
352 emit_line_note (input_filename, lineno);
353 expand_exit_loop_if_false (0, condition_conversion (cond));
354 expand_end_loop ();
355 }
356
357 clear_momentary ();
358 finish_stmt ();
359}
360
361/* Finish a return-statement. The EXPRESSION returned, if any, is as
362 indicated. */
363
364void
365finish_return_stmt (expr)
366 tree expr;
367{
558475f0
MM
368 if (building_stmt_tree ())
369 add_tree (build_min_nt (RETURN_STMT, expr));
370 else
371 {
372 emit_line_note (input_filename, lineno);
373 c_expand_return (expr);
374 }
375
ad321293
MM
376 finish_stmt ();
377}
378
379/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
380
381tree
382begin_for_stmt ()
383{
384 tree r;
385
558475f0 386 if (building_stmt_tree ())
ad321293
MM
387 {
388 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
389 NULL_TREE, NULL_TREE);
390 add_tree (r);
391 }
392 else
393 r = NULL_TREE;
394
395 if (flag_new_for_scope > 0)
396 {
397 do_pushlevel ();
398 note_level_for_for ();
399 }
400
401 return r;
402}
403
404/* Finish the for-init-statement of a for-statement, which may be
405 given by FOR_STMT. */
406
407void
408finish_for_init_stmt (for_stmt)
409 tree for_stmt;
410{
558475f0 411 if (building_stmt_tree ())
ad321293
MM
412 {
413 if (last_tree != for_stmt)
414 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_INIT_STMT (for_stmt));
415 }
416 else
417 {
418 emit_nop ();
419 emit_line_note (input_filename, lineno);
420 expand_start_loop_continue_elsewhere (1);
421 }
422
423 do_pushlevel ();
424}
425
426/* Finish the COND of a for-statement, which may be given by
427 FOR_STMT. */
428
429void
430finish_for_cond (cond, for_stmt)
431 tree cond;
432 tree for_stmt;
433{
558475f0 434 if (building_stmt_tree ())
a7e4cfa0 435 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
ad321293
MM
436 else
437 {
438 emit_line_note (input_filename, lineno);
1dcf683e
MM
439 if (cond)
440 expand_exit_loop_if_false (0, condition_conversion (cond));
ad321293
MM
441 }
442
443 /* If the cond wasn't a declaration, clear out the
444 block we made for it and start a new one here so the
445 optimization in expand_end_loop will work. */
446 if (getdecls () == NULL_TREE)
447 {
448 do_poplevel ();
449 do_pushlevel ();
450 }
451}
452
453/* Finish the increment-EXPRESSION in a for-statement, which may be
454 given by FOR_STMT. */
455
456void
457finish_for_expr (expr, for_stmt)
458 tree expr;
459 tree for_stmt;
460{
558475f0 461 if (building_stmt_tree ())
2a1e9fdd 462 FOR_EXPR (for_stmt) = expr;
ad321293
MM
463
464 /* Don't let the tree nodes for EXPR be discarded
465 by clear_momentary during the parsing of the next stmt. */
466 push_momentary ();
467}
468
469/* Finish the body of a for-statement, which may be given by
470 FOR_STMT. The increment-EXPR for the loop must be
471 provided. */
472
473void
474finish_for_stmt (expr, for_stmt)
475 tree expr;
476 tree for_stmt;
477{
478 /* Pop the scope for the body of the loop. */
479 do_poplevel ();
480
558475f0 481 if (building_stmt_tree ())
ad321293
MM
482 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_BODY (for_stmt));
483 else
484 {
485 emit_line_note (input_filename, lineno);
486 expand_loop_continue_here ();
487 if (expr)
f1dedc31 488 finish_expr_stmt (expr);
ad321293
MM
489 expand_end_loop ();
490 }
491
492 pop_momentary ();
493
494 if (flag_new_for_scope > 0)
495 do_poplevel ();
496
497 finish_stmt ();
498}
499
500/* Finish a break-statement. */
501
502void
503finish_break_stmt ()
504{
505 emit_line_note (input_filename, lineno);
558475f0 506 if (building_stmt_tree ())
ad321293
MM
507 add_tree (build_min_nt (BREAK_STMT));
508 else if ( ! expand_exit_something ())
8251199e 509 cp_error ("break statement not within loop or switch");
ad321293
MM
510}
511
512/* Finish a continue-statement. */
513
514void
515finish_continue_stmt ()
516{
517 emit_line_note (input_filename, lineno);
558475f0 518 if (building_stmt_tree ())
ad321293
MM
519 add_tree (build_min_nt (CONTINUE_STMT));
520 else if (! expand_continue_loop (0))
8251199e 521 cp_error ("continue statement not within a loop");
ad321293
MM
522}
523
527f0080
MM
524/* Begin a switch-statement. Returns a new SWITCH_STMT if
525 appropriate. */
ad321293 526
527f0080 527tree
ad321293
MM
528begin_switch_stmt ()
529{
527f0080
MM
530 tree r;
531
532 if (building_stmt_tree ())
533 {
534 r = build_min_nt (SWITCH_STMT, NULL_TREE, NULL_TREE);
535 add_tree (r);
536 }
537 else
538 r = NULL_TREE;
539
ad321293 540 do_pushlevel ();
527f0080
MM
541
542 return r;
ad321293
MM
543}
544
527f0080 545/* Finish the cond of a switch-statement. */
ad321293 546
527f0080
MM
547void
548finish_switch_cond (cond, switch_stmt)
ad321293 549 tree cond;
527f0080 550 tree switch_stmt;
ad321293 551{
558475f0 552 if (building_stmt_tree ())
527f0080 553 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
0db982be 554 else if (cond != error_mark_node)
ad321293
MM
555 {
556 emit_line_note (input_filename, lineno);
557 c_expand_start_case (cond);
ad321293 558 }
0db982be 559 else
527f0080
MM
560 /* The code is in error, but we don't want expand_end_case to
561 crash. */
562 c_expand_start_case (boolean_false_node);
0db982be 563
ad321293
MM
564 push_switch ();
565
566 /* Don't let the tree nodes for COND be discarded by
567 clear_momentary during the parsing of the next stmt. */
568 push_momentary ();
ad321293
MM
569}
570
571/* Finish the body of a switch-statement, which may be given by
572 SWITCH_STMT. The COND to switch on is indicated. */
573
574void
575finish_switch_stmt (cond, switch_stmt)
576 tree cond;
577 tree switch_stmt;
578{
558475f0 579 if (building_stmt_tree ())
ad321293
MM
580 RECHAIN_STMTS_FROM_CHAIN (switch_stmt, SWITCH_BODY (switch_stmt));
581 else
582 expand_end_case (cond);
583 pop_momentary ();
584 pop_switch ();
585 do_poplevel ();
586 finish_stmt ();
587}
588
589/* Finish a case-label. */
590
591void
592finish_case_label (low_value, high_value)
593 tree low_value;
594 tree high_value;
595{
558475f0
MM
596 if (building_stmt_tree ())
597 {
598 add_tree (build_min_nt (CASE_LABEL, low_value, high_value));
599 return;
600 }
601
ad321293
MM
602 do_case (low_value, high_value);
603}
604
ad321293
MM
605/* Finish a goto-statement. */
606
607void
608finish_goto_stmt (destination)
609 tree destination;
610{
3fa56191
MM
611 if (TREE_CODE (destination) == IDENTIFIER_NODE)
612 destination = lookup_label (destination);
613
558475f0 614 if (building_stmt_tree ())
ad321293
MM
615 add_tree (build_min_nt (GOTO_STMT, destination));
616 else
617 {
618 emit_line_note (input_filename, lineno);
619
3fa56191 620 if (TREE_CODE (destination) == LABEL_DECL)
ad321293 621 {
3fa56191
MM
622 TREE_USED (destination) = 1;
623 expand_goto (destination);
ad321293
MM
624 }
625 else
626 expand_computed_goto (destination);
627 }
628}
629
630/* Begin a try-block. Returns a newly-created TRY_BLOCK if
631 appropriate. */
632
633tree
634begin_try_block ()
635{
558475f0 636 if (building_stmt_tree ())
ad321293
MM
637 {
638 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
639 NULL_TREE);
640 add_tree (r);
641 return r;
642 }
643 else
644 {
645 emit_line_note (input_filename, lineno);
646 expand_start_try_stmts ();
647 return NULL_TREE;
648 }
649}
650
0dde4175
JM
651/* Likewise, for a function-try-block. */
652
653tree
654begin_function_try_block ()
655{
558475f0 656 if (building_stmt_tree ())
0dde4175
JM
657 {
658 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
659 NULL_TREE);
660 add_tree (r);
661 return r;
662 }
663 else
664 {
665 if (! current_function_parms_stored)
666 store_parm_decls ();
667 expand_start_early_try_stmts ();
668 return NULL_TREE;
669 }
670}
671
ad321293
MM
672/* Finish a try-block, which may be given by TRY_BLOCK. */
673
674void
675finish_try_block (try_block)
676 tree try_block;
677{
558475f0 678 if (building_stmt_tree ())
ad321293
MM
679 RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block));
680 else
558475f0 681 expand_start_all_catch ();
ad321293
MM
682}
683
f1dedc31
MM
684/* Finish an implicitly generated try-block, with a cleanup is given
685 by CLEANUP. */
686
687void
688finish_cleanup (cleanup, try_block)
689 tree cleanup;
690 tree try_block;
691{
692 if (building_stmt_tree ())
693 {
2a1e9fdd 694 TRY_HANDLERS (try_block) = cleanup;
f1dedc31
MM
695 CLEANUP_P (try_block) = 1;
696 }
697 else
698 expand_eh_region_end (protect_with_terminate (cleanup));
699}
700
0dde4175
JM
701/* Likewise, for a function-try-block. */
702
703void
704finish_function_try_block (try_block)
f1dedc31 705 tree try_block;
0dde4175 706{
558475f0 707 if (building_stmt_tree ())
0dde4175
JM
708 RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block));
709 else
710 {
711 end_protect_partials ();
712 expand_start_all_catch ();
713 in_function_try_handler = 1;
714 }
715}
716
ad321293
MM
717/* Finish a handler-sequence for a try-block, which may be given by
718 TRY_BLOCK. */
719
720void
721finish_handler_sequence (try_block)
722 tree try_block;
723{
558475f0 724 if (building_stmt_tree ())
ad321293
MM
725 RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block));
726 else
f1dedc31 727 expand_end_all_catch ();
ad321293
MM
728}
729
0dde4175
JM
730/* Likewise, for a function-try-block. */
731
732void
733finish_function_handler_sequence (try_block)
734 tree try_block;
735{
558475f0 736 if (building_stmt_tree ())
0dde4175
JM
737 RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block));
738 else
739 {
740 in_function_try_handler = 0;
741 expand_end_all_catch ();
742 }
743}
744
ad321293
MM
745/* Begin a handler. Returns a HANDLER if appropriate. */
746
747tree
748begin_handler ()
749{
750 tree r;
751
558475f0 752 if (building_stmt_tree ())
ad321293
MM
753 {
754 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
755 add_tree (r);
756 }
757 else
758 r = NULL_TREE;
759
760 do_pushlevel ();
761
762 return r;
763}
764
765/* Finish the handler-parameters for a handler, which may be given by
766 HANDLER. */
767
768void
769finish_handler_parms (handler)
770 tree handler;
771{
558475f0 772 if (building_stmt_tree ())
ad321293
MM
773 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_PARMS (handler));
774}
775
776/* Finish a handler, which may be given by HANDLER. */
777
778void
779finish_handler (handler)
780 tree handler;
781{
558475f0 782 if (building_stmt_tree ())
ad321293
MM
783 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_BODY (handler));
784 else
785 expand_end_catch_block ();
786
787 do_poplevel ();
788}
789
790/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
791 compound-statement does not define a scope. Returns a new
792 COMPOUND_STMT if appropriate. */
793
794tree
795begin_compound_stmt (has_no_scope)
796 int has_no_scope;
797{
798 tree r;
799
558475f0 800 if (building_stmt_tree ())
ad321293
MM
801 {
802 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
803 add_tree (r);
804 if (has_no_scope)
805 COMPOUND_STMT_NO_SCOPE (r) = 1;
806 }
807 else
808 r = NULL_TREE;
809
558475f0
MM
810 last_expr_type = NULL_TREE;
811
ad321293
MM
812 if (!has_no_scope)
813 do_pushlevel ();
f1dedc31
MM
814 else
815 /* Normally, we try hard to keep the BLOCK for a
816 statement-expression. But, if it's a statement-expression with
817 a scopeless block, there's nothing to keep, and we don't want
818 to accidentally keep a block *inside* the scopeless block. */
819 keep_next_level (0);
ad321293
MM
820
821 return r;
822}
823
824
825/* Finish a compound-statement, which may be given by COMPOUND_STMT.
826 If HAS_NO_SCOPE is non-zero, the compound statement does not define
827 a scope. */
828
829tree
830finish_compound_stmt (has_no_scope, compound_stmt)
831 int has_no_scope;
832 tree compound_stmt;
833{
834 tree r;
558475f0 835 tree t;
ad321293
MM
836
837 if (!has_no_scope)
838 r = do_poplevel ();
839 else
840 r = NULL_TREE;
841
558475f0 842 if (building_stmt_tree ())
ad321293
MM
843 RECHAIN_STMTS_FROM_CHAIN (compound_stmt,
844 COMPOUND_BODY (compound_stmt));
845
558475f0
MM
846 /* When we call finish_stmt we will lost LAST_EXPR_TYPE. But, since
847 the precise purpose of that variable is store the type of the
848 last expression statement within the last compound statement, we
849 preserve the value. */
850 t = last_expr_type;
ad321293 851 finish_stmt ();
558475f0 852 last_expr_type = t;
ad321293
MM
853
854 return r;
855}
856
857/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
858 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
859 CLOBBERS. */
860
861void
862finish_asm_stmt (cv_qualifier, string, output_operands,
3ebc5c52 863 input_operands, clobbers)
ad321293
MM
864 tree cv_qualifier;
865 tree string;
866 tree output_operands;
867 tree input_operands;
868 tree clobbers;
869{
870 if (TREE_CHAIN (string))
3ebc5c52 871 {
558475f0 872 if (building_stmt_tree ())
9188c363
MM
873 /* We need to build the combined string on the permanent
874 obstack so that we can use it during instantiations. */
875 push_permanent_obstack ();
3ebc5c52
MM
876
877 string = combine_strings (string);
878
558475f0 879 if (building_stmt_tree ())
3ebc5c52
MM
880 pop_obstacks ();
881 }
ad321293 882
f71f87f9
MM
883 if (cv_qualifier != NULL_TREE
884 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
885 {
886 cp_warning ("%s qualifier ignored on asm",
887 IDENTIFIER_POINTER (cv_qualifier));
888 cv_qualifier = NULL_TREE;
889 }
890
558475f0 891 if (building_stmt_tree ())
ad321293
MM
892 {
893 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
894 output_operands, input_operands,
895 clobbers);
896 add_tree (r);
897 }
898 else
899 {
900 emit_line_note (input_filename, lineno);
6e9438cf
AG
901 if (output_operands != NULL_TREE || input_operands != NULL_TREE
902 || clobbers != NULL_TREE)
903 {
7dc5bd62
MM
904 tree t;
905
7dc5bd62
MM
906 for (t = input_operands; t; t = TREE_CHAIN (t))
907 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
908
6e9438cf
AG
909 c_expand_asm_operands (string, output_operands,
910 input_operands,
911 clobbers,
f71f87f9 912 cv_qualifier != NULL_TREE,
6e9438cf
AG
913 input_filename, lineno);
914 }
915 else
f71f87f9 916 expand_asm (string);
a64c757e 917
ad321293
MM
918 finish_stmt ();
919 }
920}
b4c4a9ec 921
f01b0acb
MM
922/* Finish a label with the indicated NAME. */
923
924void
925finish_label_stmt (name)
926 tree name;
927{
3fa56191 928 tree decl = define_label (input_filename, lineno, name);
f01b0acb 929
558475f0 930 if (building_stmt_tree ())
acef433b 931 add_tree (build_min_nt (LABEL_STMT, decl));
3fa56191
MM
932 else if (decl)
933 expand_label (decl);
f01b0acb
MM
934}
935
acef433b
MM
936/* Finish a series of declarations for local labels. G++ allows users
937 to declare "local" labels, i.e., labels with scope. This extension
938 is useful when writing code involving statement-expressions. */
939
940void
941finish_label_decl (name)
942 tree name;
943{
944 tree decl = declare_local_label (name);
945 if (building_stmt_tree ())
946 add_decl_stmt (decl);
947}
948
9188c363
MM
949/* Create a declaration statement for the declaration given by the
950 DECL. */
951
952void
953add_decl_stmt (decl)
954 tree decl;
955{
956 tree decl_stmt;
957
958 /* We need the type to last until instantiation time. */
9188c363
MM
959 decl_stmt = build_min_nt (DECL_STMT, decl);
960 add_tree (decl_stmt);
961}
962
f1dedc31
MM
963/* We're in a constructor, and have just constructed a a subobject of
964 *THIS. CLEANUP is code to run if an exception is thrown before the
965 end of the current function is reached. */
966
967void
968finish_subobject (cleanup)
969 tree cleanup;
970{
971 if (building_stmt_tree ())
972 {
973 tree r = build_min_nt (SUBOBJECT, cleanup);
974 add_tree (r);
975 }
976 else
977 add_partial_entry (cleanup);
978}
979
558475f0
MM
980/* Bind a name and initialization to the return value of
981 the current function. */
982
983void
984finish_named_return_value (return_id, init)
985 tree return_id, init;
986{
987 tree decl = DECL_RESULT (current_function_decl);
988
989 if (pedantic)
990 /* Give this error as many times as there are occurrences,
991 so that users can use Emacs compilation buffers to find
992 and fix all such places. */
993 pedwarn ("ANSI C++ does not permit named return values");
994
995 if (return_id != NULL_TREE)
996 {
997 if (DECL_NAME (decl) == NULL_TREE)
998 {
999 DECL_NAME (decl) = return_id;
1000 DECL_ASSEMBLER_NAME (decl) = return_id;
1001 }
1002 else
1003 {
1004 cp_error ("return identifier `%D' already in place", return_id);
1005 return;
1006 }
1007 }
1008
1009 /* Can't let this happen for constructors. */
1010 if (DECL_CONSTRUCTOR_P (current_function_decl))
1011 {
1012 error ("can't redefine default return value for constructors");
1013 return;
1014 }
1015
1016 /* If we have a named return value, put that in our scope as well. */
1017 if (DECL_NAME (decl) != NULL_TREE)
1018 {
1019 /* Let `cp_finish_decl' know that this initializer is ok. */
1020 DECL_INITIAL (decl) = init;
1021 pushdecl (decl);
1022
1023 if (building_stmt_tree ())
2a1e9fdd 1024 add_tree (build_min_nt (RETURN_INIT, return_id, init));
558475f0
MM
1025 else
1026 {
1027 cp_finish_decl (decl, init, NULL_TREE, 0, 0);
1028 store_return_init (decl);
1029 }
1030 }
1031}
1032
1033/* Cache the value of this class's main virtual function table pointer
1034 in a register variable. This will save one indirection if a
1035 more than one virtual function call is made this function. */
1036
1037void
1038setup_vtbl_ptr ()
1039{
558475f0
MM
1040 if (base_init_expr == 0
1041 && DECL_CONSTRUCTOR_P (current_function_decl))
1042 {
1043 if (building_stmt_tree ())
1044 add_tree (build_min_nt
1045 (CTOR_INITIALIZER,
1046 current_member_init_list, current_base_init_list));
1047 else
f1dedc31 1048 emit_base_init (current_class_type);
558475f0 1049 }
f1dedc31
MM
1050
1051 /* Always keep the BLOCK node associated with the outermost pair of
1052 curley braces of a function. These are needed for correct
1053 operation of dwarfout.c. */
1054 keep_next_level (1);
558475f0
MM
1055}
1056
1057/* Begin a new scope. */
1058
f1dedc31 1059static void
558475f0
MM
1060do_pushlevel ()
1061{
1062 if (!building_stmt_tree ())
1063 {
1064 emit_line_note (input_filename, lineno);
1065 clear_last_expr ();
1066 }
558475f0 1067 push_momentary ();
f1dedc31
MM
1068 if (stmts_are_full_exprs_p)
1069 pushlevel (0);
1070 if (!building_stmt_tree () && stmts_are_full_exprs_p)
558475f0 1071 expand_start_bindings (0);
f1dedc31 1072}
558475f0
MM
1073
1074/* Finish a scope. */
1075
f1dedc31 1076static tree
558475f0
MM
1077do_poplevel ()
1078{
1079 tree t;
1080
f1dedc31 1081 if (!building_stmt_tree () && stmts_are_full_exprs_p)
558475f0 1082 expand_end_bindings (getdecls (), kept_level_p (), 0);
f1dedc31
MM
1083 if (stmts_are_full_exprs_p)
1084 t = poplevel (kept_level_p (), 1, 0);
38c7331a
MM
1085 else
1086 t = NULL_TREE;
558475f0
MM
1087 pop_momentary ();
1088 return t;
1089}
1090
b4c4a9ec
MM
1091/* Finish a parenthesized expression EXPR. */
1092
1093tree
1094finish_parenthesized_expr (expr)
1095 tree expr;
1096{
1097 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1098 /* This inhibits warnings in truthvalue_conversion. */
1099 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1100
1101 return expr;
1102}
1103
b69b1501
MM
1104/* Begin a statement-expression. The value returned must be passed to
1105 finish_stmt_expr. */
b4c4a9ec
MM
1106
1107tree
1108begin_stmt_expr ()
1109{
f1dedc31 1110 keep_next_level (1);
558475f0 1111 /* If we're building a statement tree, then the upcoming compound
b69b1501
MM
1112 statement will be chained onto the tree structure, starting at
1113 last_tree. We return last_tree so that we can later unhook the
1114 compound statement. */
558475f0 1115 return building_stmt_tree () ? last_tree : expand_start_stmt_expr();
b4c4a9ec
MM
1116}
1117
1118/* Finish a statement-expression. RTL_EXPR should be the value
1119 returned by the previous begin_stmt_expr; EXPR is the
1120 statement-expression. Returns an expression representing the
1121 statement-expression. */
1122
1123tree
1124finish_stmt_expr (rtl_expr, expr)
1125 tree rtl_expr;
1126 tree expr;
1127{
1128 tree result;
1129
558475f0 1130 if (!building_stmt_tree ())
b4c4a9ec
MM
1131 {
1132 rtl_expr = expand_end_stmt_expr (rtl_expr);
1133 /* The statements have side effects, so the group does. */
1134 TREE_SIDE_EFFECTS (rtl_expr) = 1;
1135 }
1136
558475f0 1137 if (building_stmt_tree ())
b69b1501 1138 {
f1dedc31
MM
1139 /* If the last thing in the statement-expression was not an
1140 expression-statement, then it has type `void'. */
1141 if (!last_expr_type)
1142 last_expr_type = void_type_node;
1143 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1144 TREE_SIDE_EFFECTS (result) = 1;
1145
b69b1501 1146 /* Remove the compound statement from the tree structure; it is
558475f0 1147 now saved in the STMT_EXPR. */
b69b1501
MM
1148 last_tree = rtl_expr;
1149 TREE_CHAIN (last_tree) = NULL_TREE;
1150 }
f1dedc31
MM
1151 else if (expr && TREE_CODE (expr) == BLOCK)
1152 {
1153 result = build (BIND_EXPR, TREE_TYPE (rtl_expr),
1154 NULL_TREE, rtl_expr, expr);
1155 delete_block (expr);
1156 }
1157 else
1158 result = rtl_expr;
1159
1160 if (expr && TREE_CODE (expr) == BLOCK)
1161 /* Remove the block from the tree at this point. It gets put back
1162 at the proper place when the STMT_EXPR or BIND_EXPR is
1163 expanded. */
1164 delete_block (expr);
1165
b4c4a9ec
MM
1166 return result;
1167}
1168
1169/* Finish a call to FN with ARGS. Returns a representation of the
1170 call. */
1171
1172tree
a759e627 1173finish_call_expr (fn, args, koenig)
b4c4a9ec
MM
1174 tree fn;
1175 tree args;
a759e627 1176 int koenig;
b4c4a9ec 1177{
a759e627
ML
1178 tree result;
1179
1180 if (koenig)
03d82991
JM
1181 {
1182 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1183 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1184 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
e13a4123 1185 fn = do_identifier (fn, 2, args);
03d82991 1186 }
a759e627 1187 result = build_x_function_call (fn, args, current_class_ref);
b4c4a9ec
MM
1188
1189 if (TREE_CODE (result) == CALL_EXPR
66543169
NS
1190 && (! TREE_TYPE (result)
1191 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
b4c4a9ec
MM
1192 result = require_complete_type (result);
1193
1194 return result;
1195}
1196
1197/* Finish a call to a postfix increment or decrement or EXPR. (Which
1198 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1199 POSTDECREMENT_EXPR.) */
1200
1201tree
1202finish_increment_expr (expr, code)
1203 tree expr;
1204 enum tree_code code;
1205{
1206 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1207 a COMPONENT_REF). This way if we've got, say, a reference to a
1208 static member that's being operated on, we don't end up trying to
1209 find a member operator for the class it's in. */
1210
1211 if (TREE_CODE (expr) == OFFSET_REF)
1212 expr = resolve_offset_ref (expr);
1213 return build_x_unary_op (code, expr);
1214}
1215
1216/* Finish a use of `this'. Returns an expression for `this'. */
1217
1218tree
1219finish_this_expr ()
1220{
1221 tree result;
1222
1223 if (current_class_ptr)
1224 {
1225#ifdef WARNING_ABOUT_CCD
1226 TREE_USED (current_class_ptr) = 1;
1227#endif
1228 result = current_class_ptr;
1229 }
1230 else if (current_function_decl
1231 && DECL_STATIC_FUNCTION_P (current_function_decl))
1232 {
8251199e 1233 error ("`this' is unavailable for static member functions");
b4c4a9ec
MM
1234 result = error_mark_node;
1235 }
1236 else
1237 {
1238 if (current_function_decl)
8251199e 1239 error ("invalid use of `this' in non-member function");
b4c4a9ec 1240 else
8251199e 1241 error ("invalid use of `this' at top level");
b4c4a9ec
MM
1242 result = error_mark_node;
1243 }
1244
1245 return result;
1246}
1247
1248/* Finish a member function call using OBJECT and ARGS as arguments to
1249 FN. Returns an expression for the call. */
1250
1251tree
1252finish_object_call_expr (fn, object, args)
1253 tree fn;
1254 tree object;
1255 tree args;
1256{
1257#if 0
1258 /* This is a future direction of this code, but because
1259 build_x_function_call cannot always undo what is done in
1260 build_component_ref entirely yet, we cannot do this. */
1261
1262 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1263 return finish_call_expr (real_fn, args);
1264#else
c68c56f7
MM
1265 if (TREE_CODE (fn) == TYPE_DECL)
1266 {
1267 if (processing_template_decl)
1268 /* This can happen on code like:
1269
1270 class X;
1271 template <class T> void f(T t) {
1272 t.X();
1273 }
1274
1275 We just grab the underlying IDENTIFIER. */
1276 fn = DECL_NAME (fn);
1277 else
1278 {
8251199e 1279 cp_error ("calling type `%T' like a method", fn);
c68c56f7
MM
1280 return error_mark_node;
1281 }
1282 }
1283
b4c4a9ec
MM
1284 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1285#endif
1286}
1287
1288/* Finish a qualified member function call using OBJECT and ARGS as
1289 arguments to FN. Returns an expressino for the call. */
1290
1291tree
1292finish_qualified_object_call_expr (fn, object, args)
1293 tree fn;
1294 tree object;
1295 tree args;
1296{
6eabb241
MM
1297 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1298 TREE_OPERAND (fn, 1), args);
b4c4a9ec
MM
1299}
1300
1301/* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1302 being the scope, if any, of DESTRUCTOR. Returns an expression for
1303 the call. */
1304
1305tree
1306finish_pseudo_destructor_call_expr (object, scope, destructor)
1307 tree object;
1308 tree scope;
1309 tree destructor;
1310{
40242ccf
MM
1311 if (processing_template_decl)
1312 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1313
b4c4a9ec 1314 if (scope && scope != destructor)
8251199e 1315 cp_error ("destructor specifier `%T::~%T()' must have matching names",
b4c4a9ec
MM
1316 scope, destructor);
1317
1318 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1319 && (TREE_CODE (TREE_TYPE (object)) !=
1320 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
8251199e 1321 cp_error ("`%E' is not of type `%T'", object, destructor);
b4c4a9ec
MM
1322
1323 return cp_convert (void_type_node, object);
1324}
1325
1326/* Finish a call to a globally qualified member function FN using
1327 ARGS. Returns an expression for the call. */
1328
1329tree
75d587eb 1330finish_qualified_call_expr (fn, args)
b4c4a9ec
MM
1331 tree fn;
1332 tree args;
1333{
1334 if (processing_template_decl)
2a1e9fdd 1335 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
b4c4a9ec
MM
1336 else
1337 return build_member_call (TREE_OPERAND (fn, 0),
1338 TREE_OPERAND (fn, 1),
1339 args);
1340}
1341
1342/* Finish an expression taking the address of LABEL. Returns an
1343 expression for the address. */
1344
1345tree
1346finish_label_address_expr (label)
1347 tree label;
1348{
1349 tree result;
1350
1351 label = lookup_label (label);
1352 if (label == NULL_TREE)
1353 result = null_pointer_node;
1354 else
1355 {
1356 TREE_USED (label) = 1;
1357 result = build1 (ADDR_EXPR, ptr_type_node, label);
1358 TREE_CONSTANT (result) = 1;
1359 }
1360
1361 return result;
1362}
1363
ce4a0391
MM
1364/* Finish an expression of the form CODE EXPR. */
1365
1366tree
1367finish_unary_op_expr (code, expr)
1368 enum tree_code code;
1369 tree expr;
1370{
1371 tree result = build_x_unary_op (code, expr);
1372 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST)
1373 TREE_NEGATED_INT (result) = 1;
1374 overflow_warning (result);
1375 return result;
1376}
1377
1378/* Finish an id-expression. */
1379
1380tree
1381finish_id_expr (expr)
1382 tree expr;
1383{
1384 if (TREE_CODE (expr) == IDENTIFIER_NODE)
a759e627 1385 expr = do_identifier (expr, 1, NULL_TREE);
ce4a0391
MM
1386
1387 return expr;
1388}
1389
1390/* Begin a new-placement. */
1391
1392int
1393begin_new_placement ()
1394{
1395 /* The arguments to a placement new might be passed to a
1396 deallocation function, in the event that the allocation throws an
1397 exception. Since we don't expand exception handlers until the
1398 end of a function, we must make sure the arguments stay around
1399 that long. */
1400 return suspend_momentary ();
1401}
1402
1403/* Finish a new-placement. The ARGS are the placement arguments. The
1404 COOKIE is the value returned by the previous call to
1405 begin_new_placement. */
1406
1407tree
1408finish_new_placement (args, cookie)
1409 tree args;
1410 int cookie;
1411{
1412 resume_momentary (cookie);
1413 return args;
1414}
1415
b4c4a9ec
MM
1416/* Begin a function defniition declared with DECL_SPECS and
1417 DECLARATOR. Returns non-zero if the function-declaration is
1418 legal. */
1419
1420int
1421begin_function_definition (decl_specs, declarator)
1422 tree decl_specs;
1423 tree declarator;
1424{
1425 tree specs;
1426 tree attrs;
1427 split_specs_attrs (decl_specs, &specs, &attrs);
a8f73d4b 1428 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
b4c4a9ec
MM
1429 return 0;
1430
1431 reinit_parse_for_function ();
39c01e4c
MM
1432 /* The things we're about to see are not directly qualified by any
1433 template headers we've seen thus far. */
1434 reset_specialization ();
1435
b4c4a9ec
MM
1436 return 1;
1437}
1438
1439/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1440 a SCOPE_REF. */
1441
1442tree
1443begin_constructor_declarator (scope, name)
1444 tree scope;
1445 tree name;
1446{
1447 tree result = build_parse_node (SCOPE_REF, scope, name);
830fcda8 1448 enter_scope_of (result);
b4c4a9ec
MM
1449 return result;
1450}
1451
ce4a0391
MM
1452/* Finish an init-declarator. Returns a DECL. */
1453
1454tree
1455finish_declarator (declarator, declspecs, attributes,
1456 prefix_attributes, initialized)
1457 tree declarator;
1458 tree declspecs;
1459 tree attributes;
1460 tree prefix_attributes;
1461 int initialized;
1462{
1463 return start_decl (declarator, declspecs, initialized, attributes,
1464 prefix_attributes);
1465}
1466
8014a339 1467/* Finish a translation unit. */
ce4a0391
MM
1468
1469void
1470finish_translation_unit ()
1471{
1472 /* In case there were missing closebraces,
1473 get us back to the global binding level. */
1474 while (! toplevel_bindings_p ())
1475 poplevel (0, 0, 0);
1476 while (current_namespace != global_namespace)
1477 pop_namespace ();
1478 finish_file ();
1479}
1480
b4c4a9ec
MM
1481/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1482 Returns the parameter. */
1483
1484tree
1485finish_template_type_parm (aggr, identifier)
1486 tree aggr;
1487 tree identifier;
1488{
6eabb241 1489 if (aggr != class_type_node)
b4c4a9ec 1490 {
8251199e 1491 pedwarn ("template type parameters must use the keyword `class' or `typename'");
b4c4a9ec
MM
1492 aggr = class_type_node;
1493 }
1494
1495 return build_tree_list (aggr, identifier);
1496}
1497
1498/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1499 Returns the parameter. */
1500
1501tree
1502finish_template_template_parm (aggr, identifier)
1503 tree aggr;
1504 tree identifier;
1505{
1506 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1507 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1508 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1509 DECL_TEMPLATE_RESULT (tmpl) = decl;
1510 SET_DECL_ARTIFICIAL (decl);
1511 end_template_decl ();
1512
1513 return finish_template_type_parm (aggr, tmpl);
1514}
ce4a0391
MM
1515
1516/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1517 non-zero, the parameter list was terminated by a `...'. */
1518
1519tree
1520finish_parmlist (parms, ellipsis)
1521 tree parms;
1522 int ellipsis;
1523{
1524 if (!ellipsis)
1525 chainon (parms, void_list_node);
1526 /* We mark the PARMS as a parmlist so that declarator processing can
1527 disambiguate certain constructs. */
1528 if (parms != NULL_TREE)
1529 TREE_PARMLIST (parms) = 1;
1530
1531 return parms;
1532}
1533
1534/* Begin a class definition, as indicated by T. */
1535
1536tree
1537begin_class_definition (t)
1538 tree t;
1539{
9188c363
MM
1540 push_permanent_obstack ();
1541
ce4a0391
MM
1542 if (t == error_mark_node
1543 || ! IS_AGGR_TYPE (t))
1544 {
830fcda8 1545 t = make_lang_type (RECORD_TYPE);
ce4a0391
MM
1546 pushtag (make_anon_name (), t, 0);
1547 }
830fcda8
JM
1548
1549 /* In a definition of a member class template, we will get here with an
1550 implicit typename, a TYPENAME_TYPE with a type. */
1551 if (TREE_CODE (t) == TYPENAME_TYPE)
1552 t = TREE_TYPE (t);
4c571114
MM
1553
1554 /* If we generated a partial instantiation of this type, but now
1555 we're seeing a real definition, we're actually looking at a
1556 partial specialization. Consider:
1557
1558 template <class T, class U>
1559 struct Y {};
1560
1561 template <class T>
1562 struct X {};
1563
1564 template <class T, class U>
1565 void f()
1566 {
1567 typename X<Y<T, U> >::A a;
1568 }
1569
1570 template <class T, class U>
1571 struct X<Y<T, U> >
1572 {
1573 };
1574
1575 We have to undo the effects of the previous partial
1576 instantiation. */
1577 if (PARTIAL_INSTANTIATION_P (t))
1578 {
1579 if (!pedantic)
1580 {
1581 /* Unfortunately, when we're not in pedantic mode, we
1582 attempt to actually fill in some of the fields of the
1583 partial instantiation, in order to support the implicit
1584 typename extension. Clear those fields now, in
1585 preparation for the definition here. The fields cleared
1586 here must match those set in instantiate_class_template.
1587 Look for a comment mentioning begin_class_definition
1588 there. */
1589 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1590 TYPE_FIELDS (t) = NULL_TREE;
1591 TYPE_METHODS (t) = NULL_TREE;
1592 CLASSTYPE_TAGS (t) = NULL_TREE;
1593 TYPE_SIZE (t) = NULL_TREE;
1594 }
830fcda8 1595
4c571114
MM
1596 /* This isn't a partial instantiation any more. */
1597 PARTIAL_INSTANTIATION_P (t) = 0;
1598 }
1599 /* If this type was already complete, and we see another definition,
1600 that's an error. */
1601 else if (TYPE_SIZE (t))
ce4a0391 1602 duplicate_tag_error (t);
4c571114 1603
b4f70b3d
NS
1604 /* Update the location of the decl. */
1605 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1606 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1607
4c571114 1608 if (TYPE_BEING_DEFINED (t))
ce4a0391
MM
1609 {
1610 t = make_lang_type (TREE_CODE (t));
1611 pushtag (TYPE_IDENTIFIER (t), t, 0);
ce4a0391 1612 }
ff350acd 1613 maybe_process_partial_specialization (t);
8f032717 1614 pushclass (t, 1);
ce4a0391 1615 TYPE_BEING_DEFINED (t) = 1;
ce4a0391
MM
1616 /* Reset the interface data, at the earliest possible
1617 moment, as it might have been set via a class foo;
1618 before. */
6eabb241
MM
1619 {
1620 tree name = TYPE_IDENTIFIER (t);
1621
1622 if (! ANON_AGGRNAME_P (name))
1623 {
1624 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1625 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1626 (t, interface_unknown);
1627 }
1628
1629 /* Only leave this bit clear if we know this
1630 class is part of an interface-only specification. */
1631 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1632 || ! CLASSTYPE_INTERFACE_ONLY (t))
1633 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1634 }
ce4a0391 1635#if 0
830fcda8
JM
1636 tmp = TYPE_IDENTIFIER ($<ttype>0);
1637 if (tmp && IDENTIFIER_TEMPLATE (tmp))
1638 overload_template_name (tmp, 1);
ce4a0391
MM
1639#endif
1640 reset_specialization();
1641
1642 /* In case this is a local class within a template
1643 function, we save the current tree structure so
1644 that we can get it back later. */
1645 begin_tree ();
1646
b7975aed
MM
1647 /* Make a declaration for this class in its own scope. */
1648 build_self_reference ();
1649
830fcda8 1650 return t;
ce4a0391
MM
1651}
1652
61a127b3
MM
1653/* Finish the member declaration given by DECL. */
1654
1655void
1656finish_member_declaration (decl)
1657 tree decl;
1658{
1659 if (decl == error_mark_node || decl == NULL_TREE)
1660 return;
1661
1662 if (decl == void_type_node)
1663 /* The COMPONENT was a friend, not a member, and so there's
1664 nothing for us to do. */
1665 return;
1666
1667 /* We should see only one DECL at a time. */
1668 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1669
1670 /* Set up access control for DECL. */
1671 TREE_PRIVATE (decl)
1672 = (current_access_specifier == access_private_node);
1673 TREE_PROTECTED (decl)
1674 = (current_access_specifier == access_protected_node);
1675 if (TREE_CODE (decl) == TEMPLATE_DECL)
1676 {
1677 TREE_PRIVATE (DECL_RESULT (decl)) = TREE_PRIVATE (decl);
1678 TREE_PROTECTED (DECL_RESULT (decl)) = TREE_PROTECTED (decl);
1679 }
1680
1681 /* Mark the DECL as a member of the current class. */
1682 if (TREE_CODE (decl) == FUNCTION_DECL
1683 || DECL_FUNCTION_TEMPLATE_P (decl))
1684 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1685 finish_struct. Presumably it is already set as the function is
1686 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1687 DECL_CLASS_CONTEXT (decl) = current_class_type;
61a127b3
MM
1688 else
1689 DECL_CONTEXT (decl) = current_class_type;
1690
1691 /* Put functions on the TYPE_METHODS list and everything else on the
1692 TYPE_FIELDS list. Note that these are built up in reverse order.
1693 We reverse them (to obtain declaration order) in finish_struct. */
1694 if (TREE_CODE (decl) == FUNCTION_DECL
1695 || DECL_FUNCTION_TEMPLATE_P (decl))
1696 {
1697 /* We also need to add this function to the
1698 CLASSTYPE_METHOD_VEC. */
1699 add_method (current_class_type, 0, decl);
1700
1701 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1702 TYPE_METHODS (current_class_type) = decl;
1703 }
1704 else
1705 {
1706 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1707 go at the beginning. The reason is that lookup_field_1
1708 searches the list in order, and we want a field name to
1709 override a type name so that the "struct stat hack" will
1710 work. In particular:
1711
1712 struct S { enum E { }; int E } s;
1713 s.E = 3;
1714
1715 is legal. In addition, the FIELD_DECLs must be maintained in
1716 declaration order so that class layout works as expected.
1717 However, we don't need that order until class layout, so we
1718 save a little time by putting FIELD_DECLs on in reverse order
1719 here, and then reversing them in finish_struct_1. (We could
1720 also keep a pointer to the correct insertion points in the
1721 list.) */
1722
1723 if (TREE_CODE (decl) == TYPE_DECL)
1724 TYPE_FIELDS (current_class_type)
1725 = chainon (TYPE_FIELDS (current_class_type), decl);
1726 else
1727 {
1728 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1729 TYPE_FIELDS (current_class_type) = decl;
1730 }
8f032717
MM
1731
1732 /* Enter the DECL into the scope of the class. */
1733 if (TREE_CODE (decl) != USING_DECL)
1734 pushdecl_class_level (decl);
61a127b3
MM
1735 }
1736}
1737
1738/* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1739 the definition is immediately followed by a semicolon. Returns the
1740 type. */
ce4a0391
MM
1741
1742tree
fbdd0024 1743finish_class_definition (t, attributes, semi, pop_scope_p)
ce4a0391 1744 tree t;
ce4a0391
MM
1745 tree attributes;
1746 int semi;
fbdd0024 1747 int pop_scope_p;
ce4a0391 1748{
ce4a0391
MM
1749 /* finish_struct nukes this anyway; if finish_exception does too,
1750 then it can go. */
1751 if (semi)
1752 note_got_semicolon (t);
1753
dc8263bc
JM
1754 /* If we got any attributes in class_head, xref_tag will stick them in
1755 TREE_TYPE of the type. Grab them now. */
1756 attributes = chainon (TREE_TYPE (t), attributes);
1757 TREE_TYPE (t) = NULL_TREE;
1758
ce4a0391
MM
1759 if (TREE_CODE (t) == ENUMERAL_TYPE)
1760 ;
1761 else
1762 {
9f33663b 1763 t = finish_struct (t, attributes);
ce4a0391
MM
1764 if (semi)
1765 note_got_semicolon (t);
1766 }
1767
1768 pop_obstacks ();
1769
1770 if (! semi)
1771 check_for_missing_semicolon (t);
fbdd0024
MM
1772 if (pop_scope_p)
1773 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
ce4a0391
MM
1774 if (current_scope () == current_function_decl)
1775 do_pending_defargs ();
1776
1777 return t;
1778}
1779
1780/* Finish processing the default argument expressions cached during
1781 the processing of a class definition. */
1782
1783void
51632249 1784begin_inline_definitions ()
ce4a0391
MM
1785{
1786 if (pending_inlines
1787 && current_scope () == current_function_decl)
1788 do_pending_inlines ();
1789}
1790
1791/* Finish processing the inline function definitions cached during the
1792 processing of a class definition. */
1793
1794void
51632249 1795finish_inline_definitions ()
ce4a0391
MM
1796{
1797 if (current_class_type == NULL_TREE)
1798 clear_inline_text_obstack ();
1799
1800 /* Undo the begin_tree in begin_class_definition. */
1801 end_tree ();
1802}
35acd3f2
MM
1803
1804/* Finish processing the declaration of a member class template
1805 TYPES whose template parameters are given by PARMS. */
1806
1807tree
61a127b3 1808finish_member_class_template (types)
35acd3f2
MM
1809 tree types;
1810{
36a117a5
MM
1811 tree t;
1812
1813 /* If there are declared, but undefined, partial specializations
1814 mixed in with the typespecs they will not yet have passed through
1815 maybe_process_partial_specialization, so we do that here. */
1816 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1817 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1818 maybe_process_partial_specialization (TREE_VALUE (t));
1819
35acd3f2 1820 note_list_got_semicolon (types);
61a127b3 1821 grok_x_components (types);
35acd3f2
MM
1822 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1823 /* The component was in fact a friend declaration. We avoid
1824 finish_member_template_decl performing certain checks by
1825 unsetting TYPES. */
1826 types = NULL_TREE;
61a127b3
MM
1827
1828 finish_member_template_decl (types);
1829
35acd3f2
MM
1830 /* As with other component type declarations, we do
1831 not store the new DECL on the list of
1832 component_decls. */
1833 return NULL_TREE;
1834}
36a117a5
MM
1835
1836/* Finish processsing a complete template declaration. The PARMS are
1837 the template parameters. */
1838
1839void
1840finish_template_decl (parms)
1841 tree parms;
1842{
1843 if (parms)
1844 end_template_decl ();
1845 else
1846 end_specialization ();
1847}
1848
1849/* Finish processing a a template-id (which names a type) of the form
1850 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1851 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1852 the scope of template-id indicated. */
1853
1854tree
1855finish_template_type (name, args, entering_scope)
1856 tree name;
1857 tree args;
1858 int entering_scope;
1859{
1860 tree decl;
1861
1862 decl = lookup_template_class (name, args,
1863 NULL_TREE, NULL_TREE, entering_scope);
1864 if (decl != error_mark_node)
1865 decl = TYPE_STUB_DECL (decl);
1866
1867 return decl;
1868}
648f19f6
MM
1869
1870/* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
1871 namespace scope or a class scope. */
1872
1873void
1874enter_scope_of (sr)
1875 tree sr;
1876{
1877 tree scope = TREE_OPERAND (sr, 0);
1878
1879 if (TREE_CODE (scope) == NAMESPACE_DECL)
1880 {
1881 push_decl_namespace (scope);
1882 TREE_COMPLEXITY (sr) = -1;
1883 }
1884 else if (scope != current_class_type)
1885 {
830fcda8
JM
1886 if (TREE_CODE (scope) == TYPENAME_TYPE)
1887 {
1888 /* In a declarator for a template class member, the scope will
1889 get here as an implicit typename, a TYPENAME_TYPE with a type. */
1890 scope = TREE_TYPE (scope);
1891 TREE_OPERAND (sr, 0) = scope;
1892 }
648f19f6
MM
1893 push_nested_class (scope, 3);
1894 TREE_COMPLEXITY (sr) = current_class_depth;
1895 }
1896}
ea6021e8
MM
1897
1898/* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
1899 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
1900 BASE_CLASS, or NULL_TREE if an error occurred. The
1901 ACCESSS_SPECIFIER is one of
1902 access_{default,public,protected_private}[_virtual]_node.*/
1903
1904tree
6eabb241 1905finish_base_specifier (access_specifier, base_class)
ea6021e8
MM
1906 tree access_specifier;
1907 tree base_class;
ea6021e8
MM
1908{
1909 tree type;
1910 tree result;
1911
1912 if (base_class == NULL_TREE)
1913 {
8251199e 1914 error ("invalid base class");
ea6021e8
MM
1915 type = error_mark_node;
1916 }
1917 else
1918 type = TREE_TYPE (base_class);
6eabb241 1919
ea6021e8
MM
1920 if (! is_aggr_type (type, 1))
1921 result = NULL_TREE;
ea6021e8
MM
1922 else
1923 result = build_tree_list (access_specifier, type);
1924
1925 return result;
1926}
61a127b3
MM
1927
1928/* Called when multiple declarators are processed. If that is not
1929 premitted in this context, an error is issued. */
1930
1931void
1932check_multiple_declarators ()
1933{
1934 /* [temp]
1935
1936 In a template-declaration, explicit specialization, or explicit
1937 instantiation the init-declarator-list in the declaration shall
1938 contain at most one declarator.
1939
1940 We don't just use PROCESSING_TEMPLATE_DECL for the first
1941 condition since that would disallow the perfectly legal code,
1942 like `template <class T> struct S { int i, j; };'. */
1943 tree scope = current_scope ();
1944
1945 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
1946 /* It's OK to write `template <class T> void f() { int i, j;}'. */
1947 return;
1948
1949 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
1950 || processing_explicit_instantiation
1951 || processing_specialization)
1952 cp_error ("multiple declarators in template declaration");
1953}
1954
b894fc05
JM
1955tree
1956finish_typeof (expr)
1957 tree expr;
1958{
1959 if (processing_template_decl)
1960 {
1961 tree t;
1962
9188c363 1963 push_permanent_obstack ();
b894fc05 1964 t = make_lang_type (TYPEOF_TYPE);
b894fc05 1965 TYPE_FIELDS (t) = expr;
b894fc05
JM
1966 pop_obstacks ();
1967
1968 return t;
1969 }
1970
1971 return TREE_TYPE (expr);
1972}
558475f0
MM
1973
1974/* Create an empty statement tree for FN. */
1975
1976void
1977begin_stmt_tree (fn)
1978 tree fn;
1979{
1980 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
1981 what follows. We remove the extraneous statement in
1982 finish_stmt_tree. */
1983 DECL_SAVED_TREE (fn) = build_nt (EXPR_STMT, void_zero_node);
1984 last_tree = DECL_SAVED_TREE (fn);
1985 last_expr_type = NULL_TREE;
1986}
1987
1988/* Finish the statement tree for FN. */
1989
1990void
1991finish_stmt_tree (fn)
1992 tree fn;
1993{
a7e4cfa0
MM
1994 tree stmt;
1995
1996 /* Remove the fake extra statement added in begin_stmt_tree. */
1997 stmt = TREE_CHAIN (DECL_SAVED_TREE (fn));
1998 DECL_SAVED_TREE (fn) = stmt;
1999
2000 /* The line-number recorded in the outermost statement in a function
2001 is the line number of the end of the function. */
2002 STMT_LINENO (stmt) = lineno;
2003 STMT_LINENO_FOR_FN_P (stmt) = 1;
2004}
2005
2006/* We're about to expand T, a statement. Set up appropriate context
2007 for the substitution. */
2008
2009void
2010prep_stmt (t)
2011 tree t;
2012{
2013 if (!STMT_LINENO_FOR_FN_P (t))
2014 lineno = STMT_LINENO (t);
2015 stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
558475f0
MM
2016}
2017
527f0080
MM
2018/* Some statements, like for-statements or if-statements, require a
2019 condition. This condition can be a declaration. If T is such a
2020 declaration it is processed, and an expression appropriate to use
2021 as the condition is returned. Otherwise, T itself is returned. */
2022
2023static tree
2024expand_cond (t)
2025 tree t;
2026{
2027 if (t && TREE_CODE (t) == DECL_STMT)
2028 {
2029 expand_stmt (t);
2030 return convert_from_reference (DECL_STMT_DECL (t));
2031 }
2032 else
2033 return t;
2034}
2035
558475f0
MM
2036/* Generate RTL for the chain of statements T. */
2037
2038static void
2039expand_stmts (t)
2040 tree t;
2041{
2042 while (t)
2043 {
2044 expand_stmt (t);
2045 t = TREE_CHAIN (t);
2046 }
2047}
2048
2049/* Generate RTL for the statement T, and its substatements. */
2050
2051tree
2052expand_stmt (t)
2053 tree t;
2054{
a7e4cfa0
MM
2055 int saved_stmts_are_full_exprs_p;
2056 tree rval;
2057
558475f0
MM
2058 if (t == NULL_TREE || t == error_mark_node)
2059 return NULL_TREE;
2060
a7e4cfa0
MM
2061 /* Assume we'll have nothing to return. */
2062 rval = NULL_TREE;
2063
2064 /* Set up context appropriately for handling this statement. */
2065 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p;
2066 prep_stmt (t);
2067
558475f0
MM
2068 switch (TREE_CODE (t))
2069 {
2070 case RETURN_STMT:
558475f0
MM
2071 finish_return_stmt (RETURN_EXPR (t));
2072 break;
2073
2074 case EXPR_STMT:
a7e4cfa0
MM
2075 finish_expr_stmt_real (EXPR_STMT_EXPR (t),
2076 EXPR_STMT_ASSIGNS_THIS (t));
558475f0
MM
2077 break;
2078
2079 case DECL_STMT:
2080 {
2081 tree decl;
2082 int i = suspend_momentary ();
2083
2084 lineno = STMT_LINENO (t);
2085 emit_line_note (input_filename, lineno);
2086 decl = DECL_STMT_DECL (t);
acef433b
MM
2087 if (TREE_CODE (decl) == LABEL_DECL)
2088 finish_label_decl (DECL_NAME (decl));
2089 else
2090 {
2091 /* We need to clear DECL_CONTEXT so that maybe_push_decl
2092 will push it into the current scope. */
2093 if (DECL_CONTEXT (decl) == current_function_decl)
2094 DECL_CONTEXT (decl) = NULL_TREE;
2095 /* If we marked this variable as dead when we processed it
2096 before, we must undo that now. The variable has been
2097 resuscitated. */
2098 if (TREE_CODE (decl) == VAR_DECL)
2099 DECL_DEAD_FOR_LOCAL (decl) = 0;
2100 maybe_push_decl (decl);
b7b8bcd2
MM
2101 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
2102 {
2103 maybe_inject_for_scope_var (decl);
2104 initialize_local_var (decl, DECL_INITIAL (decl), 0);
2105 }
acef433b 2106 }
558475f0
MM
2107 resume_momentary (i);
2108 }
2109 break;
2110
2111 case FOR_STMT:
2112 {
2113 tree tmp;
2114
558475f0
MM
2115 begin_for_stmt ();
2116 for (tmp = FOR_INIT_STMT (t); tmp; tmp = TREE_CHAIN (tmp))
2117 expand_stmt (tmp);
2118 finish_for_init_stmt (NULL_TREE);
527f0080 2119 finish_for_cond (expand_cond (FOR_COND (t)), NULL_TREE);
558475f0
MM
2120 tmp = FOR_EXPR (t);
2121 finish_for_expr (tmp, NULL_TREE);
2122 expand_stmt (FOR_BODY (t));
2123 finish_for_stmt (tmp, NULL_TREE);
2124 }
2125 break;
2126
2127 case WHILE_STMT:
2128 {
558475f0 2129 begin_while_stmt ();
527f0080 2130 finish_while_stmt_cond (expand_cond (WHILE_COND (t)), NULL_TREE);
558475f0
MM
2131 expand_stmt (WHILE_BODY (t));
2132 finish_while_stmt (NULL_TREE);
2133 }
2134 break;
2135
2136 case DO_STMT:
2137 {
558475f0
MM
2138 begin_do_stmt ();
2139 expand_stmt (DO_BODY (t));
2140 finish_do_body (NULL_TREE);
2141 finish_do_stmt (DO_COND (t), NULL_TREE);
2142 }
2143 break;
2144
2145 case IF_STMT:
558475f0 2146 begin_if_stmt ();
527f0080 2147 finish_if_stmt_cond (expand_cond (IF_COND (t)), NULL_TREE);
558475f0
MM
2148 if (THEN_CLAUSE (t))
2149 {
2150 expand_stmt (THEN_CLAUSE (t));
2151 finish_then_clause (NULL_TREE);
2152 }
2153 if (ELSE_CLAUSE (t))
2154 {
2155 begin_else_clause ();
2156 expand_stmt (ELSE_CLAUSE (t));
2157 finish_else_clause (NULL_TREE);
2158 }
2159 finish_if_stmt ();
2160 break;
2161
2162 case COMPOUND_STMT:
558475f0
MM
2163 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
2164 expand_stmts (COMPOUND_BODY (t));
a7e4cfa0 2165 rval = finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
558475f0 2166 NULL_TREE);
a7e4cfa0 2167 break;
558475f0
MM
2168
2169 case BREAK_STMT:
558475f0
MM
2170 finish_break_stmt ();
2171 break;
2172
2173 case CONTINUE_STMT:
558475f0
MM
2174 finish_continue_stmt ();
2175 break;
2176
2177 case SWITCH_STMT:
527f0080
MM
2178 {
2179 tree cond;
2180
527f0080
MM
2181 begin_switch_stmt ();
2182 cond = expand_cond (SWITCH_COND (t));
2183 finish_switch_cond (cond, NULL_TREE);
558475f0 2184 expand_stmt (SWITCH_BODY (t));
527f0080
MM
2185 finish_switch_stmt (cond, NULL_TREE);
2186 }
558475f0
MM
2187 break;
2188
2189 case CASE_LABEL:
2190 finish_case_label (CASE_LOW (t), CASE_HIGH (t));
2191 break;
2192
acef433b 2193 case LABEL_STMT:
acef433b 2194 finish_label_stmt (DECL_NAME (LABEL_STMT_LABEL (t)));
558475f0
MM
2195 break;
2196
2197 case GOTO_STMT:
acef433b
MM
2198 if (TREE_CODE (GOTO_DESTINATION (t)) == LABEL_DECL)
2199 finish_goto_stmt (DECL_NAME (GOTO_DESTINATION (t)));
2200 else
2201 finish_goto_stmt (GOTO_DESTINATION (t));
558475f0
MM
2202 break;
2203
2204 case ASM_STMT:
558475f0
MM
2205 finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS
2206 (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
2207 break;
2208
2209 case TRY_BLOCK:
f1dedc31
MM
2210 if (CLEANUP_P (t))
2211 {
2212 expand_eh_region_start ();
2213 expand_stmt (TRY_STMTS (t));
2214 finish_cleanup (TRY_HANDLERS (t), NULL_TREE);
2215 }
2216 else
2217 {
2218 begin_try_block ();
2219 expand_stmt (TRY_STMTS (t));
2220 finish_try_block (NULL_TREE);
2221 expand_stmts (TRY_HANDLERS (t));
2222 finish_handler_sequence (NULL_TREE);
2223 }
558475f0
MM
2224 break;
2225
2226 case HANDLER:
558475f0
MM
2227 begin_handler ();
2228 if (HANDLER_PARMS (t))
3c5c0849 2229 expand_start_catch_block (DECL_STMT_DECL (HANDLER_PARMS (t)));
558475f0 2230 else
3c5c0849 2231 expand_start_catch_block (NULL_TREE);
558475f0
MM
2232 finish_handler_parms (NULL_TREE);
2233 expand_stmt (HANDLER_BODY (t));
2234 finish_handler (NULL_TREE);
2235 break;
2236
f1dedc31 2237 case SUBOBJECT:
f1dedc31
MM
2238 finish_subobject (SUBOBJECT_CLEANUP (t));
2239 break;
2240
558475f0
MM
2241 default:
2242 my_friendly_abort (19990810);
2243 break;
2244 }
2245
a7e4cfa0
MM
2246 /* Restore saved state. */
2247 stmts_are_full_exprs_p = saved_stmts_are_full_exprs_p;
2248
2249 return rval;
558475f0
MM
2250}
2251
2252/* Generate RTL for FN. */
2253
2254void
2255expand_body (fn)
2256 tree fn;
2257{
558475f0
MM
2258 tree t;
2259 tree try_block;
2260
a8f73d4b 2261 start_function (NULL_TREE, fn, NULL_TREE, SF_PRE_PARSED | SF_EXPAND);
558475f0
MM
2262 store_parm_decls ();
2263
2264 /* There are a few things that we do not handle recursively. For
2265 example, a function try-block is handled differently from an
2266 ordinary try-block, so we must handle it here. */
2267 t = DECL_SAVED_TREE (fn);
2268 try_block = NULL_TREE;
2269 if (t && TREE_CODE (t) == TRY_BLOCK)
2270 {
2271 try_block = t;
2272 begin_function_try_block ();
2273 t = TRY_STMTS (try_block);
2274 }
2275
2276 if (t && TREE_CODE (t) == RETURN_INIT)
2277 {
2278 /* Clear this out so that finish_named_return_value can set it
2279 again. */
2280 DECL_NAME (DECL_RESULT (fn)) = NULL_TREE;
2281 finish_named_return_value (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
2282 t = TREE_CHAIN (t);
2283 }
2284
2285 if (t && TREE_CODE (t) == CTOR_INITIALIZER)
2286 {
2287 current_member_init_list = TREE_OPERAND (t, 0);
2288 current_base_init_list = TREE_OPERAND (t, 1);
2289 t = TREE_CHAIN (t);
2290 }
2291
2292 /* If this is a constructor, we need to initialize our members and
2293 base-classes. */
2294 setup_vtbl_ptr ();
2295
558475f0
MM
2296 /* Expand the body. */
2297 expand_stmt (t);
2298
2299 /* If there was a function try-block, expand the handlers. */
2300 if (try_block)
2301 {
2302 finish_function_try_block (NULL_TREE);
2303 {
2304 tree handler = TRY_HANDLERS (try_block);
2305 for (; handler; handler = TREE_CHAIN (handler))
2306 expand_stmt (handler);
2307 }
2308 finish_function_handler_sequence (NULL_TREE);
2309 }
2310
fdfcc44c 2311 finish_function (lineno, 0);
558475f0 2312}