OSDN Git Service

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