OSDN Git Service

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