OSDN Git Service

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