OSDN Git Service

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