2002-02-19 Philip Blundell <philb@gnu.org>
[official-gcc.git] / gcc / cp / semantics.c
blobc344a3016efacea864050672ba0c249073c55cc1
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.
6 Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GNU CC.
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.
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.
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. */
27 #include "config.h"
28 #include "system.h"
29 #include "tree.h"
30 #include "cp-tree.h"
31 #include "tree-inline.h"
32 #include "except.h"
33 #include "lex.h"
34 #include "toplev.h"
35 #include "flags.h"
36 #include "ggc.h"
37 #include "rtl.h"
38 #include "expr.h"
39 #include "output.h"
40 #include "timevar.h"
41 #include "debug.h"
43 /* There routines provide a modular interface to perform many parsing
44 operations. They may therefore be used during actual parsing, or
45 during template instantiation, which may be regarded as a
46 degenerate form of parsing. Since the current g++ parser is
47 lacking in several respects, and will be reimplemented, we are
48 attempting to move most code that is not directly related to
49 parsing into this file; that will make implementing the new parser
50 much easier since it will be able to make use of these routines. */
52 static tree maybe_convert_cond PARAMS ((tree));
53 static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
54 static void deferred_type_access_control PARAMS ((void));
55 static void emit_associated_thunks PARAMS ((tree));
56 static void genrtl_try_block PARAMS ((tree));
57 static void genrtl_eh_spec_block PARAMS ((tree));
58 static void genrtl_handler PARAMS ((tree));
59 static void genrtl_ctor_stmt PARAMS ((tree));
60 static void genrtl_subobject PARAMS ((tree));
61 static void genrtl_named_return_value PARAMS ((void));
62 static void cp_expand_stmt PARAMS ((tree));
63 static void genrtl_start_function PARAMS ((tree));
64 static void genrtl_finish_function PARAMS ((tree));
65 static tree clear_decl_rtl PARAMS ((tree *, int *, void *));
67 /* Finish processing the COND, the SUBSTMT condition for STMT. */
69 #define FINISH_COND(COND, STMT, SUBSTMT) \
70 do { \
71 if (last_tree != (STMT)) \
72 { \
73 RECHAIN_STMTS (STMT, SUBSTMT); \
74 if (!processing_template_decl) \
75 { \
76 (COND) = build_tree_list (SUBSTMT, COND); \
77 (SUBSTMT) = (COND); \
78 } \
79 } \
80 else \
81 (SUBSTMT) = (COND); \
82 } while (0)
84 /* Returns non-zero if the current statement is a full expression,
85 i.e. temporaries created during that statement should be destroyed
86 at the end of the statement. */
88 int
89 stmts_are_full_exprs_p ()
91 return current_stmt_tree ()->stmts_are_full_exprs_p;
94 /* Returns the stmt_tree (if any) to which statements are currently
95 being added. If there is no active statement-tree, NULL is
96 returned. */
98 stmt_tree
99 current_stmt_tree ()
101 return (cfun
102 ? &cfun->language->x_stmt_tree
103 : &scope_chain->x_stmt_tree);
106 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
107 flag for this because "A union for which objects or pointers are
108 declared is not an anonymous union" [class.union]. */
111 anon_aggr_type_p (node)
112 tree node;
114 return (CLASS_TYPE_P (node) && TYPE_LANG_SPECIFIC(node)->anon_aggr);
117 /* Finish a scope. */
119 tree
120 do_poplevel ()
122 tree block = NULL_TREE;
124 if (stmts_are_full_exprs_p ())
126 tree scope_stmts = NULL_TREE;
128 if (!processing_template_decl)
129 scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
131 block = poplevel (kept_level_p (), 1, 0);
132 if (block && !processing_template_decl)
134 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
135 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
139 return block;
142 /* Begin a new scope. */
144 void
145 do_pushlevel ()
147 if (stmts_are_full_exprs_p ())
149 pushlevel (0);
150 if (!processing_template_decl)
151 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
155 /* Finish a goto-statement. */
157 tree
158 finish_goto_stmt (destination)
159 tree destination;
161 if (TREE_CODE (destination) == IDENTIFIER_NODE)
162 destination = lookup_label (destination);
164 /* We warn about unused labels with -Wunused. That means we have to
165 mark the used labels as used. */
166 if (TREE_CODE (destination) == LABEL_DECL)
167 TREE_USED (destination) = 1;
169 if (TREE_CODE (destination) != LABEL_DECL)
170 /* We don't inline calls to functions with computed gotos.
171 Those functions are typically up to some funny business,
172 and may be depending on the labels being at particular
173 addresses, or some such. */
174 DECL_UNINLINABLE (current_function_decl) = 1;
176 check_goto (destination);
178 return add_stmt (build_stmt (GOTO_STMT, destination));
181 /* COND is the condition-expression for an if, while, etc.,
182 statement. Convert it to a boolean value, if appropriate. */
184 tree
185 maybe_convert_cond (cond)
186 tree cond;
188 /* Empty conditions remain empty. */
189 if (!cond)
190 return NULL_TREE;
192 /* Wait until we instantiate templates before doing conversion. */
193 if (processing_template_decl)
194 return cond;
196 /* Do the conversion. */
197 cond = convert_from_reference (cond);
198 return condition_conversion (cond);
201 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
203 tree
204 finish_expr_stmt (expr)
205 tree expr;
207 tree r = NULL_TREE;
209 if (expr != NULL_TREE)
211 if (!processing_template_decl
212 && !(stmts_are_full_exprs_p ())
213 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
214 && lvalue_p (expr))
215 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
216 expr = default_conversion (expr);
218 if (stmts_are_full_exprs_p ())
219 expr = convert_to_void (expr, "statement");
221 r = add_stmt (build_stmt (EXPR_STMT, expr));
224 finish_stmt ();
226 /* This was an expression-statement, so we save the type of the
227 expression. */
228 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
230 return r;
234 /* Begin an if-statement. Returns a newly created IF_STMT if
235 appropriate. */
237 tree
238 begin_if_stmt ()
240 tree r;
241 do_pushlevel ();
242 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
243 add_stmt (r);
244 return r;
247 /* Process the COND of an if-statement, which may be given by
248 IF_STMT. */
250 void
251 finish_if_stmt_cond (cond, if_stmt)
252 tree cond;
253 tree if_stmt;
255 cond = maybe_convert_cond (cond);
256 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
259 /* Finish the then-clause of an if-statement, which may be given by
260 IF_STMT. */
262 tree
263 finish_then_clause (if_stmt)
264 tree if_stmt;
266 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
267 last_tree = if_stmt;
268 return if_stmt;
271 /* Begin the else-clause of an if-statement. */
273 void
274 begin_else_clause ()
278 /* Finish the else-clause of an if-statement, which may be given by
279 IF_STMT. */
281 void
282 finish_else_clause (if_stmt)
283 tree if_stmt;
285 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
288 /* Finish an if-statement. */
290 void
291 finish_if_stmt ()
293 do_poplevel ();
294 finish_stmt ();
297 void
298 clear_out_block ()
300 /* If COND wasn't a declaration, clear out the
301 block we made for it and start a new one here so the
302 optimization in expand_end_loop will work. */
303 if (getdecls () == NULL_TREE)
305 do_poplevel ();
306 do_pushlevel ();
310 /* Begin a while-statement. Returns a newly created WHILE_STMT if
311 appropriate. */
313 tree
314 begin_while_stmt ()
316 tree r;
317 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
318 add_stmt (r);
319 do_pushlevel ();
320 return r;
323 /* Process the COND of a while-statement, which may be given by
324 WHILE_STMT. */
326 void
327 finish_while_stmt_cond (cond, while_stmt)
328 tree cond;
329 tree while_stmt;
331 cond = maybe_convert_cond (cond);
332 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
333 clear_out_block ();
336 /* Finish a while-statement, which may be given by WHILE_STMT. */
338 void
339 finish_while_stmt (while_stmt)
340 tree while_stmt;
342 do_poplevel ();
343 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
344 finish_stmt ();
347 /* Begin a do-statement. Returns a newly created DO_STMT if
348 appropriate. */
350 tree
351 begin_do_stmt ()
353 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
354 add_stmt (r);
355 return r;
358 /* Finish the body of a do-statement, which may be given by DO_STMT. */
360 void
361 finish_do_body (do_stmt)
362 tree do_stmt;
364 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
367 /* Finish a do-statement, which may be given by DO_STMT, and whose
368 COND is as indicated. */
370 void
371 finish_do_stmt (cond, do_stmt)
372 tree cond;
373 tree do_stmt;
375 cond = maybe_convert_cond (cond);
376 DO_COND (do_stmt) = cond;
377 finish_stmt ();
380 /* Finish a return-statement. The EXPRESSION returned, if any, is as
381 indicated. */
383 tree
384 finish_return_stmt (expr)
385 tree expr;
387 tree r;
389 if (!processing_template_decl)
390 expr = check_return_expr (expr);
391 if (!processing_template_decl)
393 if (DECL_DESTRUCTOR_P (current_function_decl))
395 /* Similarly, all destructors must run destructors for
396 base-classes before returning. So, all returns in a
397 destructor get sent to the DTOR_LABEL; finish_function emits
398 code to return a value there. */
399 return finish_goto_stmt (dtor_label);
402 r = add_stmt (build_stmt (RETURN_STMT, expr));
403 finish_stmt ();
405 return r;
408 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
410 tree
411 begin_for_stmt ()
413 tree r;
415 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
416 NULL_TREE, NULL_TREE);
417 NEW_FOR_SCOPE_P (r) = flag_new_for_scope > 0;
418 add_stmt (r);
419 if (NEW_FOR_SCOPE_P (r))
421 do_pushlevel ();
422 note_level_for_for ();
425 return r;
428 /* Finish the for-init-statement of a for-statement, which may be
429 given by FOR_STMT. */
431 void
432 finish_for_init_stmt (for_stmt)
433 tree for_stmt;
435 if (last_tree != for_stmt)
436 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
437 do_pushlevel ();
440 /* Finish the COND of a for-statement, which may be given by
441 FOR_STMT. */
443 void
444 finish_for_cond (cond, for_stmt)
445 tree cond;
446 tree for_stmt;
448 cond = maybe_convert_cond (cond);
449 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
450 clear_out_block ();
453 /* Finish the increment-EXPRESSION in a for-statement, which may be
454 given by FOR_STMT. */
456 void
457 finish_for_expr (expr, for_stmt)
458 tree expr;
459 tree for_stmt;
461 FOR_EXPR (for_stmt) = expr;
464 /* Finish the body of a for-statement, which may be given by
465 FOR_STMT. The increment-EXPR for the loop must be
466 provided. */
468 void
469 finish_for_stmt (for_stmt)
470 tree for_stmt;
472 /* Pop the scope for the body of the loop. */
473 do_poplevel ();
474 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
475 if (NEW_FOR_SCOPE_P (for_stmt))
476 do_poplevel ();
477 finish_stmt ();
480 /* Finish a break-statement. */
482 tree
483 finish_break_stmt ()
485 return add_stmt (build_break_stmt ());
488 /* Finish a continue-statement. */
490 tree
491 finish_continue_stmt ()
493 return add_stmt (build_continue_stmt ());
496 /* Begin a switch-statement. Returns a new SWITCH_STMT if
497 appropriate. */
499 tree
500 begin_switch_stmt ()
502 tree r;
503 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
504 add_stmt (r);
505 do_pushlevel ();
506 return r;
509 /* Finish the cond of a switch-statement. */
511 void
512 finish_switch_cond (cond, switch_stmt)
513 tree cond;
514 tree switch_stmt;
516 tree orig_type = NULL;
517 if (!processing_template_decl)
519 tree type;
520 tree index;
522 /* Convert the condition to an integer or enumeration type. */
523 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
524 if (cond == NULL_TREE)
526 error ("switch quantity not an integer");
527 cond = error_mark_node;
529 orig_type = TREE_TYPE (cond);
530 if (cond != error_mark_node)
532 cond = default_conversion (cond);
533 cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
536 type = TREE_TYPE (cond);
537 index = get_unwidened (cond, NULL_TREE);
538 /* We can't strip a conversion from a signed type to an unsigned,
539 because if we did, int_fits_type_p would do the wrong thing
540 when checking case values for being in range,
541 and it's too hard to do the right thing. */
542 if (TREE_UNSIGNED (TREE_TYPE (cond))
543 == TREE_UNSIGNED (TREE_TYPE (index)))
544 cond = index;
546 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
547 SWITCH_TYPE (switch_stmt) = orig_type;
548 push_switch (switch_stmt);
551 /* Finish the body of a switch-statement, which may be given by
552 SWITCH_STMT. The COND to switch on is indicated. */
554 void
555 finish_switch_stmt (switch_stmt)
556 tree switch_stmt;
558 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
559 pop_switch ();
560 do_poplevel ();
561 finish_stmt ();
564 /* Generate the RTL for T, which is a TRY_BLOCK. */
566 static void
567 genrtl_try_block (t)
568 tree t;
570 if (CLEANUP_P (t))
572 expand_eh_region_start ();
573 expand_stmt (TRY_STMTS (t));
574 expand_eh_region_end_cleanup (TRY_HANDLERS (t));
576 else
578 if (!FN_TRY_BLOCK_P (t))
579 emit_line_note (input_filename, lineno);
581 expand_eh_region_start ();
582 expand_stmt (TRY_STMTS (t));
584 if (FN_TRY_BLOCK_P (t))
586 expand_start_all_catch ();
587 in_function_try_handler = 1;
588 expand_stmt (TRY_HANDLERS (t));
589 in_function_try_handler = 0;
590 expand_end_all_catch ();
592 else
594 expand_start_all_catch ();
595 expand_stmt (TRY_HANDLERS (t));
596 expand_end_all_catch ();
601 /* Generate the RTL for T, which is an EH_SPEC_BLOCK. */
603 static void
604 genrtl_eh_spec_block (t)
605 tree t;
607 expand_eh_region_start ();
608 expand_stmt (EH_SPEC_STMTS (t));
609 expand_eh_region_end_allowed (EH_SPEC_RAISES (t),
610 build_call (call_unexpected_node,
611 tree_cons (NULL_TREE,
612 build_exc_ptr (),
613 NULL_TREE)));
616 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
617 appropriate. */
619 tree
620 begin_try_block ()
622 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
623 add_stmt (r);
624 return r;
627 /* Likewise, for a function-try-block. */
629 tree
630 begin_function_try_block ()
632 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
633 FN_TRY_BLOCK_P (r) = 1;
634 add_stmt (r);
635 return r;
638 /* Finish a try-block, which may be given by TRY_BLOCK. */
640 void
641 finish_try_block (try_block)
642 tree try_block;
644 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
647 /* Finish the body of a cleanup try-block, which may be given by
648 TRY_BLOCK. */
650 void
651 finish_cleanup_try_block (try_block)
652 tree try_block;
654 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
657 /* Finish an implicitly generated try-block, with a cleanup is given
658 by CLEANUP. */
660 void
661 finish_cleanup (cleanup, try_block)
662 tree cleanup;
663 tree try_block;
665 TRY_HANDLERS (try_block) = cleanup;
666 CLEANUP_P (try_block) = 1;
669 /* Likewise, for a function-try-block. */
671 void
672 finish_function_try_block (try_block)
673 tree try_block;
675 if (TREE_CHAIN (try_block)
676 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
678 /* Chain the compound statement after the CTOR_INITIALIZER. */
679 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
680 /* And make the CTOR_INITIALIZER the body of the try-block. */
681 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
683 else
684 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
685 in_function_try_handler = 1;
688 /* Finish a handler-sequence for a try-block, which may be given by
689 TRY_BLOCK. */
691 void
692 finish_handler_sequence (try_block)
693 tree try_block;
695 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
696 check_handlers (TRY_HANDLERS (try_block));
699 /* Likewise, for a function-try-block. */
701 void
702 finish_function_handler_sequence (try_block)
703 tree try_block;
705 in_function_try_handler = 0;
706 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
707 check_handlers (TRY_HANDLERS (try_block));
710 /* Generate the RTL for T, which is a HANDLER. */
712 static void
713 genrtl_handler (t)
714 tree t;
716 genrtl_do_pushlevel ();
717 if (!processing_template_decl)
718 expand_start_catch (HANDLER_TYPE (t));
719 expand_stmt (HANDLER_BODY (t));
720 if (!processing_template_decl)
721 expand_end_catch ();
724 /* Begin a handler. Returns a HANDLER if appropriate. */
726 tree
727 begin_handler ()
729 tree r;
730 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
731 add_stmt (r);
732 /* Create a binding level for the eh_info and the exception object
733 cleanup. */
734 do_pushlevel ();
735 note_level_for_catch ();
736 return r;
739 /* Finish the handler-parameters for a handler, which may be given by
740 HANDLER. DECL is the declaration for the catch parameter, or NULL
741 if this is a `catch (...)' clause. */
743 void
744 finish_handler_parms (decl, handler)
745 tree decl;
746 tree handler;
748 tree type = NULL_TREE;
749 if (processing_template_decl)
751 if (decl)
753 decl = pushdecl (decl);
754 decl = push_template_decl (decl);
755 add_decl_stmt (decl);
756 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
757 type = TREE_TYPE (decl);
760 else
761 type = expand_start_catch_block (decl);
763 HANDLER_TYPE (handler) = type;
766 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
767 the return value from the matching call to finish_handler_parms. */
769 void
770 finish_handler (handler)
771 tree handler;
773 if (!processing_template_decl)
774 expand_end_catch_block ();
775 do_poplevel ();
776 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
779 /* Generate the RTL for T, which is a CTOR_STMT. */
781 static void
782 genrtl_ctor_stmt (t)
783 tree t;
785 if (CTOR_BEGIN_P (t))
786 begin_protect_partials ();
787 else
788 /* After this point, any exceptions will cause the
789 destructor to be executed, so we no longer need to worry
790 about destroying the various subobjects ourselves. */
791 end_protect_partials ();
794 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
795 compound-statement does not define a scope. Returns a new
796 COMPOUND_STMT if appropriate. */
798 tree
799 begin_compound_stmt (has_no_scope)
800 int has_no_scope;
802 tree r;
803 int is_try = 0;
805 r = build_stmt (COMPOUND_STMT, NULL_TREE);
807 if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK)
808 is_try = 1;
810 add_stmt (r);
811 if (has_no_scope)
812 COMPOUND_STMT_NO_SCOPE (r) = 1;
814 last_expr_type = NULL_TREE;
816 if (!has_no_scope)
818 do_pushlevel ();
819 if (is_try)
820 note_level_for_try ();
822 else
823 /* Normally, we try hard to keep the BLOCK for a
824 statement-expression. But, if it's a statement-expression with
825 a scopeless block, there's nothing to keep, and we don't want
826 to accidentally keep a block *inside* the scopeless block. */
827 keep_next_level (0);
829 return r;
832 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
833 If HAS_NO_SCOPE is non-zero, the compound statement does not define
834 a scope. */
836 tree
837 finish_compound_stmt (has_no_scope, compound_stmt)
838 int has_no_scope;
839 tree compound_stmt;
841 tree r;
842 tree t;
844 if (!has_no_scope)
845 r = do_poplevel ();
846 else
847 r = NULL_TREE;
849 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
851 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
852 the precise purpose of that variable is store the type of the
853 last expression statement within the last compound statement, we
854 preserve the value. */
855 t = last_expr_type;
856 finish_stmt ();
857 last_expr_type = t;
859 return r;
862 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
863 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
864 CLOBBERS. */
866 tree
867 finish_asm_stmt (cv_qualifier, string, output_operands,
868 input_operands, clobbers)
869 tree cv_qualifier;
870 tree string;
871 tree output_operands;
872 tree input_operands;
873 tree clobbers;
875 tree r;
876 tree t;
878 if (TREE_CHAIN (string))
879 string = combine_strings (string);
881 if (cv_qualifier != NULL_TREE
882 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
884 warning ("%s qualifier ignored on asm",
885 IDENTIFIER_POINTER (cv_qualifier));
886 cv_qualifier = NULL_TREE;
889 if (!processing_template_decl)
891 int i;
892 int ninputs;
893 int noutputs;
895 for (t = input_operands; t; t = TREE_CHAIN (t))
897 tree converted_operand
898 = decay_conversion (TREE_VALUE (t));
900 /* If the type of the operand hasn't been determined (e.g.,
901 because it involves an overloaded function), then issue
902 an error message. There's no context available to
903 resolve the overloading. */
904 if (TREE_TYPE (converted_operand) == unknown_type_node)
906 error ("type of asm operand `%E' could not be determined",
907 TREE_VALUE (t));
908 converted_operand = error_mark_node;
910 TREE_VALUE (t) = converted_operand;
913 ninputs = list_length (input_operands);
914 noutputs = list_length (output_operands);
916 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
918 bool allows_mem;
919 bool allows_reg;
920 bool is_inout;
921 const char *constraint;
922 tree operand;
924 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
925 operand = TREE_VALUE (output_operands);
927 if (!parse_output_constraint (&constraint,
928 i, ninputs, noutputs,
929 &allows_mem,
930 &allows_reg,
931 &is_inout))
933 /* By marking the type as erroneous, we will not try to
934 process this operand again in expand_asm_operands. */
935 TREE_TYPE (operand) = error_mark_node;
936 continue;
939 /* If the operand is a DECL that is going to end up in
940 memory, assume it is addressable. This is a bit more
941 conservative than it would ideally be; the exact test is
942 buried deep in expand_asm_operands and depends on the
943 DECL_RTL for the OPERAND -- which we don't have at this
944 point. */
945 if (!allows_reg && DECL_P (operand))
946 mark_addressable (operand);
950 r = build_stmt (ASM_STMT, cv_qualifier, string,
951 output_operands, input_operands,
952 clobbers);
953 return add_stmt (r);
956 /* Finish a label with the indicated NAME. */
958 void
959 finish_label_stmt (name)
960 tree name;
962 tree decl = define_label (input_filename, lineno, name);
963 add_stmt (build_stmt (LABEL_STMT, decl));
966 /* Finish a series of declarations for local labels. G++ allows users
967 to declare "local" labels, i.e., labels with scope. This extension
968 is useful when writing code involving statement-expressions. */
970 void
971 finish_label_decl (name)
972 tree name;
974 tree decl = declare_local_label (name);
975 add_decl_stmt (decl);
978 /* Generate the RTL for a SUBOBJECT. */
980 static void
981 genrtl_subobject (cleanup)
982 tree cleanup;
984 add_partial_entry (cleanup);
987 /* We're in a constructor, and have just constructed a a subobject of
988 *THIS. CLEANUP is code to run if an exception is thrown before the
989 end of the current function is reached. */
991 void
992 finish_subobject (cleanup)
993 tree cleanup;
995 tree r = build_stmt (SUBOBJECT, cleanup);
996 add_stmt (r);
999 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1001 void
1002 finish_decl_cleanup (decl, cleanup)
1003 tree decl;
1004 tree cleanup;
1006 add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup));
1009 /* Generate the RTL for a RETURN_INIT. */
1011 static void
1012 genrtl_named_return_value ()
1014 tree decl = DECL_RESULT (current_function_decl);
1016 /* If this named return value comes in a register, put it in a
1017 pseudo-register. */
1018 if (DECL_REGISTER (decl))
1020 /* Note that the mode of the old DECL_RTL may be wider than the
1021 mode of DECL_RESULT, depending on the calling conventions for
1022 the processor. For example, on the Alpha, a 32-bit integer
1023 is returned in a DImode register -- the DECL_RESULT has
1024 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
1025 here, we use the mode the back-end has already assigned for
1026 the return value. */
1027 SET_DECL_RTL (decl, gen_reg_rtx (GET_MODE (DECL_RTL (decl))));
1028 if (TREE_ADDRESSABLE (decl))
1029 put_var_into_stack (decl);
1032 emit_local_var (decl);
1035 /* Bind a name and initialization to the return value of
1036 the current function. */
1038 void
1039 finish_named_return_value (return_id, init)
1040 tree return_id, init;
1042 tree decl = DECL_RESULT (current_function_decl);
1044 /* Give this error as many times as there are occurrences, so that
1045 users can use Emacs compilation buffers to find and fix all such
1046 places. */
1047 if (pedantic)
1048 pedwarn ("ISO C++ does not permit named return values");
1049 cp_deprecated ("the named return value extension");
1051 if (return_id != NULL_TREE)
1053 if (DECL_NAME (decl) == NULL_TREE)
1054 DECL_NAME (decl) = return_id;
1055 else
1057 error ("return identifier `%D' already in place", return_id);
1058 return;
1062 /* Can't let this happen for constructors. */
1063 if (DECL_CONSTRUCTOR_P (current_function_decl))
1065 error ("can't redefine default return value for constructors");
1066 return;
1069 /* If we have a named return value, put that in our scope as well. */
1070 if (DECL_NAME (decl) != NULL_TREE)
1072 /* Let `cp_finish_decl' know that this initializer is ok. */
1073 DECL_INITIAL (decl) = init;
1074 if (doing_semantic_analysis_p ())
1075 pushdecl (decl);
1076 if (!processing_template_decl)
1078 cp_finish_decl (decl, init, NULL_TREE, 0);
1079 add_stmt (build_stmt (RETURN_INIT, NULL_TREE, NULL_TREE));
1081 else
1082 add_stmt (build_stmt (RETURN_INIT, return_id, init));
1085 /* Don't use tree-inlining for functions with named return values.
1086 That doesn't work properly because we don't do any translation of
1087 the RETURN_INITs when they are copied. */
1088 DECL_UNINLINABLE (current_function_decl) = 1;
1091 /* The INIT_LIST is a list of mem-initializers, in the order they were
1092 written by the user. The TREE_VALUE of each node is a list of
1093 initializers for a particular subobject. The TREE_PURPOSE is a
1094 FIELD_DECL is the initializer is for a non-static data member, and
1095 a class type if the initializer is for a base class. */
1097 void
1098 finish_mem_initializers (init_list)
1099 tree init_list;
1101 tree member_init_list;
1102 tree base_init_list;
1103 tree last_base_warned_about;
1104 tree next;
1105 tree init;
1107 member_init_list = NULL_TREE;
1108 base_init_list = NULL_TREE;
1109 last_base_warned_about = NULL_TREE;
1111 for (init = init_list; init; init = next)
1113 next = TREE_CHAIN (init);
1114 if (TREE_CODE (TREE_PURPOSE (init)) == FIELD_DECL)
1116 TREE_CHAIN (init) = member_init_list;
1117 member_init_list = init;
1119 /* We're running through the initializers from right to left
1120 as we process them here. So, if we see a data member
1121 initializer after we see a base initializer, that
1122 actually means that the base initializer preceded the
1123 data member initializer. */
1124 if (warn_reorder && last_base_warned_about != base_init_list)
1126 tree base;
1128 for (base = base_init_list;
1129 base != last_base_warned_about;
1130 base = TREE_CHAIN (base))
1132 warning ("base initializer for `%T'",
1133 TREE_PURPOSE (base));
1134 warning (" will be re-ordered to precede member initializations");
1137 last_base_warned_about = base_init_list;
1140 else
1142 TREE_CHAIN (init) = base_init_list;
1143 base_init_list = init;
1147 if (processing_template_decl)
1148 add_stmt (build_min_nt (CTOR_INITIALIZER,
1149 member_init_list, base_init_list));
1150 else
1151 emit_base_init (member_init_list, base_init_list);
1154 /* Returns the stack of SCOPE_STMTs for the current function. */
1156 tree *
1157 current_scope_stmt_stack ()
1159 return &cfun->language->x_scope_stmt_stack;
1162 /* Finish a parenthesized expression EXPR. */
1164 tree
1165 finish_parenthesized_expr (expr)
1166 tree expr;
1168 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1169 /* This inhibits warnings in truthvalue_conversion. */
1170 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1172 if (TREE_CODE (expr) == OFFSET_REF)
1173 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1174 enclosed in parentheses. */
1175 PTRMEM_OK_P (expr) = 0;
1176 return expr;
1179 /* Begin a statement-expression. The value returned must be passed to
1180 finish_stmt_expr. */
1182 tree
1183 begin_stmt_expr ()
1185 /* If we're outside a function, we won't have a statement-tree to
1186 work with. But, if we see a statement-expression we need to
1187 create one. */
1188 if (! cfun && !last_tree)
1189 begin_stmt_tree (&scope_chain->x_saved_tree);
1191 keep_next_level (1);
1192 /* If we're building a statement tree, then the upcoming compound
1193 statement will be chained onto the tree structure, starting at
1194 last_tree. We return last_tree so that we can later unhook the
1195 compound statement. */
1196 return last_tree;
1199 /* Used when beginning a statement-expression outside function scope.
1200 For example, when handling a file-scope initializer, we use this
1201 function. */
1203 tree
1204 begin_global_stmt_expr ()
1206 if (! cfun && !last_tree)
1207 begin_stmt_tree (&scope_chain->x_saved_tree);
1209 keep_next_level (1);
1211 return (last_tree != NULL_TREE) ? last_tree : expand_start_stmt_expr();
1214 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1216 tree
1217 finish_global_stmt_expr (stmt_expr)
1218 tree stmt_expr;
1220 stmt_expr = expand_end_stmt_expr (stmt_expr);
1222 if (! cfun
1223 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1224 finish_stmt_tree (&scope_chain->x_saved_tree);
1226 return stmt_expr;
1229 /* Finish a statement-expression. RTL_EXPR should be the value
1230 returned by the previous begin_stmt_expr; EXPR is the
1231 statement-expression. Returns an expression representing the
1232 statement-expression. */
1234 tree
1235 finish_stmt_expr (rtl_expr)
1236 tree rtl_expr;
1238 tree result;
1240 /* If the last thing in the statement-expression was not an
1241 expression-statement, then it has type `void'. */
1242 if (!last_expr_type)
1243 last_expr_type = void_type_node;
1244 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1245 TREE_SIDE_EFFECTS (result) = 1;
1247 /* Remove the compound statement from the tree structure; it is
1248 now saved in the STMT_EXPR. */
1249 last_tree = rtl_expr;
1250 TREE_CHAIN (last_tree) = NULL_TREE;
1252 /* If we created a statement-tree for this statement-expression,
1253 remove it now. */
1254 if (! cfun
1255 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1256 finish_stmt_tree (&scope_chain->x_saved_tree);
1258 return result;
1261 /* Finish a call to FN with ARGS. Returns a representation of the
1262 call. */
1264 tree
1265 finish_call_expr (fn, args, koenig)
1266 tree fn;
1267 tree args;
1268 int koenig;
1270 tree result;
1272 if (koenig)
1274 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1275 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1276 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
1277 fn = do_identifier (fn, 2, args);
1279 result = build_x_function_call (fn, args, current_class_ref);
1281 if (TREE_CODE (result) == CALL_EXPR
1282 && (! TREE_TYPE (result)
1283 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
1284 result = require_complete_type (result);
1286 return result;
1289 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1290 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1291 POSTDECREMENT_EXPR.) */
1293 tree
1294 finish_increment_expr (expr, code)
1295 tree expr;
1296 enum tree_code code;
1298 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1299 a COMPONENT_REF). This way if we've got, say, a reference to a
1300 static member that's being operated on, we don't end up trying to
1301 find a member operator for the class it's in. */
1303 if (TREE_CODE (expr) == OFFSET_REF)
1304 expr = resolve_offset_ref (expr);
1305 return build_x_unary_op (code, expr);
1308 /* Finish a use of `this'. Returns an expression for `this'. */
1310 tree
1311 finish_this_expr ()
1313 tree result;
1315 if (current_class_ptr)
1317 result = current_class_ptr;
1319 else if (current_function_decl
1320 && DECL_STATIC_FUNCTION_P (current_function_decl))
1322 error ("`this' is unavailable for static member functions");
1323 result = error_mark_node;
1325 else
1327 if (current_function_decl)
1328 error ("invalid use of `this' in non-member function");
1329 else
1330 error ("invalid use of `this' at top level");
1331 result = error_mark_node;
1334 return result;
1337 /* Finish a member function call using OBJECT and ARGS as arguments to
1338 FN. Returns an expression for the call. */
1340 tree
1341 finish_object_call_expr (fn, object, args)
1342 tree fn;
1343 tree object;
1344 tree args;
1346 #if 0
1347 /* This is a future direction of this code, but because
1348 build_x_function_call cannot always undo what is done in
1349 build_component_ref entirely yet, we cannot do this. */
1351 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1352 return finish_call_expr (real_fn, args);
1353 #else
1354 if (DECL_DECLARES_TYPE_P (fn))
1356 if (processing_template_decl)
1357 /* This can happen on code like:
1359 class X;
1360 template <class T> void f(T t) {
1361 t.X();
1364 We just grab the underlying IDENTIFIER. */
1365 fn = DECL_NAME (fn);
1366 else
1368 error ("calling type `%T' like a method", fn);
1369 return error_mark_node;
1373 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1374 #endif
1377 /* Finish a qualified member function call using OBJECT and ARGS as
1378 arguments to FN. Returns an expression for the call. */
1380 tree
1381 finish_qualified_object_call_expr (fn, object, args)
1382 tree fn;
1383 tree object;
1384 tree args;
1386 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1387 TREE_OPERAND (fn, 1), args);
1390 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1391 being the scope, if any, of DESTRUCTOR. Returns an expression for
1392 the call. */
1394 tree
1395 finish_pseudo_destructor_call_expr (object, scope, destructor)
1396 tree object;
1397 tree scope;
1398 tree destructor;
1400 if (processing_template_decl)
1401 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1403 if (scope && scope != destructor)
1404 error ("destructor specifier `%T::~%T()' must have matching names",
1405 scope, destructor);
1407 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1408 && (TREE_CODE (TREE_TYPE (object)) !=
1409 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1410 error ("`%E' is not of type `%T'", object, destructor);
1412 return cp_convert (void_type_node, object);
1415 /* Finish a call to a globally qualified member function FN using
1416 ARGS. Returns an expression for the call. */
1418 tree
1419 finish_qualified_call_expr (fn, args)
1420 tree fn;
1421 tree args;
1423 if (processing_template_decl)
1424 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
1425 else
1426 return build_member_call (TREE_OPERAND (fn, 0),
1427 TREE_OPERAND (fn, 1),
1428 args);
1431 /* Finish an expression of the form CODE EXPR. */
1433 tree
1434 finish_unary_op_expr (code, expr)
1435 enum tree_code code;
1436 tree expr;
1438 tree result = build_x_unary_op (code, expr);
1439 /* Inside a template, build_x_unary_op does not fold the
1440 expression. So check whether the result is folded before
1441 setting TREE_NEGATED_INT. */
1442 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
1443 && TREE_CODE (result) == INTEGER_CST
1444 && !TREE_UNSIGNED (TREE_TYPE (result))
1445 && INT_CST_LT (result, integer_zero_node))
1446 TREE_NEGATED_INT (result) = 1;
1447 overflow_warning (result);
1448 return result;
1451 /* Finish an id-expression. */
1453 tree
1454 finish_id_expr (expr)
1455 tree expr;
1457 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1458 expr = do_identifier (expr, 1, NULL_TREE);
1460 if (TREE_TYPE (expr) == error_mark_node)
1461 expr = error_mark_node;
1462 return expr;
1465 static tree current_type_lookups;
1467 /* Perform deferred access control for types used in the type of a
1468 declaration. */
1470 static void
1471 deferred_type_access_control ()
1473 tree lookup = type_lookups;
1475 if (lookup == error_mark_node)
1476 return;
1478 for (; lookup; lookup = TREE_CHAIN (lookup))
1479 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1482 void
1483 decl_type_access_control (decl)
1484 tree decl;
1486 tree save_fn;
1488 if (type_lookups == error_mark_node)
1489 return;
1491 save_fn = current_function_decl;
1493 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1494 current_function_decl = decl;
1496 deferred_type_access_control ();
1498 current_function_decl = save_fn;
1500 /* Now strip away the checks for the current declarator; they were
1501 added to type_lookups after typed_declspecs saved the copy that
1502 ended up in current_type_lookups. */
1503 type_lookups = current_type_lookups;
1505 current_type_lookups = NULL_TREE;
1508 /* Record the lookups, if we're doing deferred access control. */
1510 void
1511 save_type_access_control (lookups)
1512 tree lookups;
1514 if (type_lookups != error_mark_node)
1516 my_friendly_assert (!current_type_lookups, 20010301);
1517 current_type_lookups = lookups;
1519 else
1520 my_friendly_assert (!lookups || lookups == error_mark_node, 20010301);
1523 /* Set things up so that the next deferred access control will succeed.
1524 This is needed for friend declarations see grokdeclarator for details. */
1526 void
1527 skip_type_access_control ()
1529 type_lookups = NULL_TREE;
1532 /* Reset the deferred access control. */
1534 void
1535 reset_type_access_control ()
1537 type_lookups = NULL_TREE;
1538 current_type_lookups = NULL_TREE;
1541 /* Begin a function definition declared with DECL_SPECS and
1542 DECLARATOR. Returns non-zero if the function-declaration is
1543 legal. */
1546 begin_function_definition (decl_specs, declarator)
1547 tree decl_specs;
1548 tree declarator;
1550 tree specs;
1551 tree attrs;
1553 split_specs_attrs (decl_specs, &specs, &attrs);
1554 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
1555 return 0;
1557 deferred_type_access_control ();
1558 type_lookups = error_mark_node;
1560 /* The things we're about to see are not directly qualified by any
1561 template headers we've seen thus far. */
1562 reset_specialization ();
1564 return 1;
1567 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1568 a SCOPE_REF. */
1570 tree
1571 begin_constructor_declarator (scope, name)
1572 tree scope;
1573 tree name;
1575 tree result = build_nt (SCOPE_REF, scope, name);
1576 enter_scope_of (result);
1577 return result;
1580 /* Finish an init-declarator. Returns a DECL. */
1582 tree
1583 finish_declarator (declarator, declspecs, attributes,
1584 prefix_attributes, initialized)
1585 tree declarator;
1586 tree declspecs;
1587 tree attributes;
1588 tree prefix_attributes;
1589 int initialized;
1591 return start_decl (declarator, declspecs, initialized, attributes,
1592 prefix_attributes);
1595 /* Finish a translation unit. */
1597 void
1598 finish_translation_unit ()
1600 /* In case there were missing closebraces,
1601 get us back to the global binding level. */
1602 pop_everything ();
1603 while (current_namespace != global_namespace)
1604 pop_namespace ();
1606 /* Do file scope __FUNCTION__ et al. */
1607 finish_fname_decls ();
1609 finish_file ();
1612 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1613 Returns the parameter. */
1615 tree
1616 finish_template_type_parm (aggr, identifier)
1617 tree aggr;
1618 tree identifier;
1620 if (aggr != class_type_node)
1622 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1623 aggr = class_type_node;
1626 return build_tree_list (aggr, identifier);
1629 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1630 Returns the parameter. */
1632 tree
1633 finish_template_template_parm (aggr, identifier)
1634 tree aggr;
1635 tree identifier;
1637 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1638 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1639 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1640 DECL_TEMPLATE_RESULT (tmpl) = decl;
1641 DECL_ARTIFICIAL (decl) = 1;
1642 end_template_decl ();
1644 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110);
1646 return finish_template_type_parm (aggr, tmpl);
1649 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1650 non-zero, the parameter list was terminated by a `...'. */
1652 tree
1653 finish_parmlist (parms, ellipsis)
1654 tree parms;
1655 int ellipsis;
1657 if (parms)
1659 /* We mark the PARMS as a parmlist so that declarator processing can
1660 disambiguate certain constructs. */
1661 TREE_PARMLIST (parms) = 1;
1662 /* We do not append void_list_node here, but leave it to grokparms
1663 to do that. */
1664 PARMLIST_ELLIPSIS_P (parms) = ellipsis;
1666 return parms;
1669 /* Begin a class definition, as indicated by T. */
1671 tree
1672 begin_class_definition (t)
1673 tree t;
1675 if (t == error_mark_node)
1676 return error_mark_node;
1678 /* Check the bases are accessible. */
1679 decl_type_access_control (TYPE_NAME (t));
1680 reset_type_access_control ();
1682 if (processing_template_parmlist)
1684 error ("definition of `%#T' inside template parameter list", t);
1685 return error_mark_node;
1688 /* In a definition of a member class template, we will get here with
1689 an implicit typename. */
1690 if (IMPLICIT_TYPENAME_P (t))
1691 t = TREE_TYPE (t);
1692 /* A non-implicit typename comes from code like:
1694 template <typename T> struct A {
1695 template <typename U> struct A<T>::B ...
1697 This is erroneous. */
1698 else if (TREE_CODE (t) == TYPENAME_TYPE)
1700 error ("invalid definition of qualified type `%T'", t);
1701 t = error_mark_node;
1704 if (t == error_mark_node || ! IS_AGGR_TYPE (t))
1706 t = make_aggr_type (RECORD_TYPE);
1707 pushtag (make_anon_name (), t, 0);
1710 /* If we generated a partial instantiation of this type, but now
1711 we're seeing a real definition, we're actually looking at a
1712 partial specialization. Consider:
1714 template <class T, class U>
1715 struct Y {};
1717 template <class T>
1718 struct X {};
1720 template <class T, class U>
1721 void f()
1723 typename X<Y<T, U> >::A a;
1726 template <class T, class U>
1727 struct X<Y<T, U> >
1731 We have to undo the effects of the previous partial
1732 instantiation. */
1733 if (PARTIAL_INSTANTIATION_P (t))
1735 if (!pedantic)
1737 /* Unfortunately, when we're not in pedantic mode, we
1738 attempt to actually fill in some of the fields of the
1739 partial instantiation, in order to support the implicit
1740 typename extension. Clear those fields now, in
1741 preparation for the definition here. The fields cleared
1742 here must match those set in instantiate_class_template.
1743 Look for a comment mentioning begin_class_definition
1744 there. */
1745 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1746 TYPE_FIELDS (t) = NULL_TREE;
1747 TYPE_METHODS (t) = NULL_TREE;
1748 CLASSTYPE_TAGS (t) = NULL_TREE;
1749 CLASSTYPE_VBASECLASSES (t) = NULL_TREE;
1750 TYPE_SIZE (t) = NULL_TREE;
1753 /* This isn't a partial instantiation any more. */
1754 PARTIAL_INSTANTIATION_P (t) = 0;
1756 /* If this type was already complete, and we see another definition,
1757 that's an error. */
1758 else if (COMPLETE_TYPE_P (t))
1759 duplicate_tag_error (t);
1761 /* Update the location of the decl. */
1762 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1763 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1765 if (TYPE_BEING_DEFINED (t))
1767 t = make_aggr_type (TREE_CODE (t));
1768 pushtag (TYPE_IDENTIFIER (t), t, 0);
1770 maybe_process_partial_specialization (t);
1771 pushclass (t, 1);
1772 TYPE_BEING_DEFINED (t) = 1;
1773 TYPE_PACKED (t) = flag_pack_struct;
1774 /* Reset the interface data, at the earliest possible
1775 moment, as it might have been set via a class foo;
1776 before. */
1777 if (! TYPE_ANONYMOUS_P (t))
1779 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1780 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1781 (t, interface_unknown);
1783 reset_specialization();
1785 /* Make a declaration for this class in its own scope. */
1786 build_self_reference ();
1788 return t;
1791 /* Finish the member declaration given by DECL. */
1793 void
1794 finish_member_declaration (decl)
1795 tree decl;
1797 if (decl == error_mark_node || decl == NULL_TREE)
1798 return;
1800 if (decl == void_type_node)
1801 /* The COMPONENT was a friend, not a member, and so there's
1802 nothing for us to do. */
1803 return;
1805 /* We should see only one DECL at a time. */
1806 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1808 /* Set up access control for DECL. */
1809 TREE_PRIVATE (decl)
1810 = (current_access_specifier == access_private_node);
1811 TREE_PROTECTED (decl)
1812 = (current_access_specifier == access_protected_node);
1813 if (TREE_CODE (decl) == TEMPLATE_DECL)
1815 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
1816 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
1819 /* Mark the DECL as a member of the current class. */
1820 DECL_CONTEXT (decl) = current_class_type;
1822 /* [dcl.link]
1824 A C language linkage is ignored for the names of class members
1825 and the member function type of class member functions. */
1826 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
1827 SET_DECL_LANGUAGE (decl, lang_cplusplus);
1829 /* Put functions on the TYPE_METHODS list and everything else on the
1830 TYPE_FIELDS list. Note that these are built up in reverse order.
1831 We reverse them (to obtain declaration order) in finish_struct. */
1832 if (TREE_CODE (decl) == FUNCTION_DECL
1833 || DECL_FUNCTION_TEMPLATE_P (decl))
1835 /* We also need to add this function to the
1836 CLASSTYPE_METHOD_VEC. */
1837 add_method (current_class_type, decl, /*error_p=*/0);
1839 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1840 TYPE_METHODS (current_class_type) = decl;
1842 else
1844 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1845 go at the beginning. The reason is that lookup_field_1
1846 searches the list in order, and we want a field name to
1847 override a type name so that the "struct stat hack" will
1848 work. In particular:
1850 struct S { enum E { }; int E } s;
1851 s.E = 3;
1853 is legal. In addition, the FIELD_DECLs must be maintained in
1854 declaration order so that class layout works as expected.
1855 However, we don't need that order until class layout, so we
1856 save a little time by putting FIELD_DECLs on in reverse order
1857 here, and then reversing them in finish_struct_1. (We could
1858 also keep a pointer to the correct insertion points in the
1859 list.) */
1861 if (TREE_CODE (decl) == TYPE_DECL)
1862 TYPE_FIELDS (current_class_type)
1863 = chainon (TYPE_FIELDS (current_class_type), decl);
1864 else
1866 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1867 TYPE_FIELDS (current_class_type) = decl;
1870 /* Enter the DECL into the scope of the class. */
1871 if (TREE_CODE (decl) != USING_DECL)
1872 pushdecl_class_level (decl);
1876 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1877 the definition is immediately followed by a semicolon. Returns the
1878 type. */
1880 tree
1881 finish_class_definition (t, attributes, semi, pop_scope_p)
1882 tree t;
1883 tree attributes;
1884 int semi;
1885 int pop_scope_p;
1887 if (t == error_mark_node)
1888 return error_mark_node;
1890 /* finish_struct nukes this anyway; if finish_exception does too,
1891 then it can go. */
1892 if (semi)
1893 note_got_semicolon (t);
1895 /* If we got any attributes in class_head, xref_tag will stick them in
1896 TREE_TYPE of the type. Grab them now. */
1897 attributes = chainon (TYPE_ATTRIBUTES (t), attributes);
1898 TYPE_ATTRIBUTES (t) = NULL_TREE;
1900 if (TREE_CODE (t) == ENUMERAL_TYPE)
1902 else
1904 t = finish_struct (t, attributes);
1905 if (semi)
1906 note_got_semicolon (t);
1909 if (! semi)
1910 check_for_missing_semicolon (t);
1911 if (pop_scope_p)
1912 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
1913 if (current_function_decl)
1914 type_lookups = error_mark_node;
1915 if (current_scope () == current_function_decl)
1916 do_pending_defargs ();
1918 return t;
1921 /* Finish processing the default argument expressions cached during
1922 the processing of a class definition. */
1924 void
1925 begin_inline_definitions ()
1927 if (current_scope () == current_function_decl)
1928 do_pending_inlines ();
1931 /* Finish processing the inline function definitions cached during the
1932 processing of a class definition. */
1934 void
1935 finish_inline_definitions ()
1937 if (current_class_type == NULL_TREE)
1938 clear_inline_text_obstack ();
1941 /* Finish processing the declaration of a member class template
1942 TYPES whose template parameters are given by PARMS. */
1944 tree
1945 finish_member_class_template (types)
1946 tree types;
1948 tree t;
1950 /* If there are declared, but undefined, partial specializations
1951 mixed in with the typespecs they will not yet have passed through
1952 maybe_process_partial_specialization, so we do that here. */
1953 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1954 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1955 maybe_process_partial_specialization (TREE_VALUE (t));
1957 note_list_got_semicolon (types);
1958 grok_x_components (types);
1959 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1960 /* The component was in fact a friend declaration. We avoid
1961 finish_member_template_decl performing certain checks by
1962 unsetting TYPES. */
1963 types = NULL_TREE;
1965 finish_member_template_decl (types);
1967 /* As with other component type declarations, we do
1968 not store the new DECL on the list of
1969 component_decls. */
1970 return NULL_TREE;
1973 /* Finish processing a complete template declaration. The PARMS are
1974 the template parameters. */
1976 void
1977 finish_template_decl (parms)
1978 tree parms;
1980 if (parms)
1981 end_template_decl ();
1982 else
1983 end_specialization ();
1986 /* Finish processing a template-id (which names a type) of the form
1987 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1988 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1989 the scope of template-id indicated. */
1991 tree
1992 finish_template_type (name, args, entering_scope)
1993 tree name;
1994 tree args;
1995 int entering_scope;
1997 tree decl;
1999 decl = lookup_template_class (name, args,
2000 NULL_TREE, NULL_TREE,
2001 entering_scope, /*complain=*/1);
2002 if (decl != error_mark_node)
2003 decl = TYPE_STUB_DECL (decl);
2005 return decl;
2008 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2009 namespace scope or a class scope. */
2011 void
2012 enter_scope_of (sr)
2013 tree sr;
2015 tree scope = TREE_OPERAND (sr, 0);
2017 if (TREE_CODE (scope) == NAMESPACE_DECL)
2019 push_decl_namespace (scope);
2020 TREE_COMPLEXITY (sr) = -1;
2022 else if (scope != current_class_type)
2024 if (TREE_CODE (scope) == TYPENAME_TYPE)
2026 /* In a declarator for a template class member, the scope will
2027 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2028 scope = TREE_TYPE (scope);
2029 TREE_OPERAND (sr, 0) = scope;
2031 push_nested_class (scope, 3);
2032 TREE_COMPLEXITY (sr) = current_class_depth;
2036 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2037 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2038 BASE_CLASS, or NULL_TREE if an error occurred. The
2039 ACCESS_SPECIFIER is one of
2040 access_{default,public,protected_private}[_virtual]_node.*/
2042 tree
2043 finish_base_specifier (access_specifier, base_class)
2044 tree access_specifier;
2045 tree base_class;
2047 tree result;
2049 if (! is_aggr_type (base_class, 1))
2050 result = NULL_TREE;
2051 else
2053 if (cp_type_quals (base_class) != 0)
2055 error ("base class `%T' has cv qualifiers", base_class);
2056 base_class = TYPE_MAIN_VARIANT (base_class);
2058 result = build_tree_list (access_specifier, base_class);
2061 return result;
2064 /* Called when multiple declarators are processed. If that is not
2065 premitted in this context, an error is issued. */
2067 void
2068 check_multiple_declarators ()
2070 /* [temp]
2072 In a template-declaration, explicit specialization, or explicit
2073 instantiation the init-declarator-list in the declaration shall
2074 contain at most one declarator.
2076 We don't just use PROCESSING_TEMPLATE_DECL for the first
2077 condition since that would disallow the perfectly legal code,
2078 like `template <class T> struct S { int i, j; };'. */
2079 tree scope = current_scope ();
2081 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2082 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2083 return;
2085 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2086 || processing_explicit_instantiation
2087 || processing_specialization)
2088 error ("multiple declarators in template declaration");
2091 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
2092 use as a type-specifier. */
2094 tree
2095 finish_typeof (expr)
2096 tree expr;
2098 if (processing_template_decl)
2100 tree t;
2102 t = make_aggr_type (TYPEOF_TYPE);
2103 TYPE_FIELDS (t) = expr;
2105 return t;
2108 if (TREE_CODE (expr) == OFFSET_REF)
2109 expr = resolve_offset_ref (expr);
2111 return TREE_TYPE (expr);
2114 /* Compute the value of the `sizeof' operator. */
2116 tree
2117 finish_sizeof (t)
2118 tree t;
2120 if (processing_template_decl)
2121 return build_min_nt (SIZEOF_EXPR, t);
2123 return TYPE_P (t) ? c_sizeof (t) : expr_sizeof (t);
2126 /* Implement the __alignof keyword: Return the minimum required
2127 alignment of T, measured in bytes. */
2129 tree
2130 finish_alignof (t)
2131 tree t;
2133 if (processing_template_decl)
2134 return build_min_nt (ALIGNOF_EXPR, t);
2136 return TYPE_P (t) ? c_alignof (t) : c_alignof_expr (t);
2139 /* Generate RTL for the statement T, and its substatements, and any
2140 other statements at its nesting level. */
2142 static void
2143 cp_expand_stmt (t)
2144 tree t;
2146 switch (TREE_CODE (t))
2148 case CLEANUP_STMT:
2149 genrtl_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2150 break;
2152 case CTOR_STMT:
2153 genrtl_ctor_stmt (t);
2154 break;
2156 case TRY_BLOCK:
2157 genrtl_try_block (t);
2158 break;
2160 case EH_SPEC_BLOCK:
2161 genrtl_eh_spec_block (t);
2162 break;
2164 case HANDLER:
2165 genrtl_handler (t);
2166 break;
2168 case SUBOBJECT:
2169 genrtl_subobject (SUBOBJECT_CLEANUP (t));
2170 break;
2172 case RETURN_INIT:
2173 genrtl_named_return_value ();
2174 break;
2176 case USING_STMT:
2177 break;
2179 default:
2180 abort ();
2181 break;
2185 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2186 will equivalent CALL_EXPRs. */
2188 static tree
2189 simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2190 tree *tp;
2191 int *walk_subtrees ATTRIBUTE_UNUSED;
2192 void *data ATTRIBUTE_UNUSED;
2194 tree aggr_init_expr;
2195 tree call_expr;
2196 tree fn;
2197 tree args;
2198 tree slot;
2199 tree type;
2200 int copy_from_buffer_p;
2202 aggr_init_expr = *tp;
2203 /* We don't need to walk into types; there's nothing in a type that
2204 needs simplification. (And, furthermore, there are places we
2205 actively don't want to go. For example, we don't want to wander
2206 into the default arguments for a FUNCTION_DECL that appears in a
2207 CALL_EXPR.) */
2208 if (TYPE_P (aggr_init_expr))
2210 *walk_subtrees = 0;
2211 return NULL_TREE;
2213 /* Only AGGR_INIT_EXPRs are interesting. */
2214 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
2215 return NULL_TREE;
2217 /* Form an appropriate CALL_EXPR. */
2218 fn = TREE_OPERAND (aggr_init_expr, 0);
2219 args = TREE_OPERAND (aggr_init_expr, 1);
2220 slot = TREE_OPERAND (aggr_init_expr, 2);
2221 type = TREE_TYPE (aggr_init_expr);
2222 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2224 /* Replace the first argument with the address of the third
2225 argument to the AGGR_INIT_EXPR. */
2226 mark_addressable (slot);
2227 args = tree_cons (NULL_TREE,
2228 build1 (ADDR_EXPR,
2229 build_pointer_type (TREE_TYPE (slot)),
2230 slot),
2231 TREE_CHAIN (args));
2233 call_expr = build (CALL_EXPR,
2234 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
2235 fn, args, NULL_TREE);
2236 TREE_SIDE_EFFECTS (call_expr) = 1;
2238 /* If we're using the non-reentrant PCC calling convention, then we
2239 need to copy the returned value out of the static buffer into the
2240 SLOT. */
2241 copy_from_buffer_p = 0;
2242 #ifdef PCC_STATIC_STRUCT_RETURN
2243 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2245 int old_ac = flag_access_control;
2247 flag_access_control = 0;
2248 call_expr = build_aggr_init (slot, call_expr,
2249 DIRECT_BIND | LOOKUP_ONLYCONVERTING);
2250 flag_access_control = old_ac;
2251 copy_from_buffer_p = 1;
2253 #endif
2255 /* If this AGGR_INIT_EXPR indicates the value returned by a
2256 function, then we want to use the value of the initialized
2257 location as the result. */
2258 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2260 call_expr = build (COMPOUND_EXPR, type,
2261 call_expr, slot);
2262 TREE_SIDE_EFFECTS (call_expr) = 1;
2265 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2266 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2267 *tp = call_expr;
2269 /* Keep iterating. */
2270 return NULL_TREE;
2273 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2275 static void
2276 emit_associated_thunks (fn)
2277 tree fn;
2279 /* When we use vcall offsets, we emit thunks with the virtual
2280 functions to which they thunk. The whole point of vcall offsets
2281 is so that you can know statically the entire set of thunks that
2282 will ever be needed for a given virtual function, thereby
2283 enabling you to output all the thunks with the function itself. */
2284 if (DECL_VIRTUAL_P (fn))
2286 tree binfo;
2287 tree v;
2289 for (binfo = TYPE_BINFO (DECL_CONTEXT (fn));
2290 binfo;
2291 binfo = TREE_CHAIN (binfo))
2292 for (v = BINFO_VIRTUALS (binfo); v; v = TREE_CHAIN (v))
2293 if (BV_FN (v) == fn
2294 && (!integer_zerop (BV_DELTA (v))
2295 || BV_USE_VCALL_INDEX_P (v)))
2297 tree thunk;
2298 tree vcall_index;
2300 if (BV_USE_VCALL_INDEX_P (v))
2302 vcall_index = BV_VCALL_INDEX (v);
2303 my_friendly_assert (vcall_index != NULL_TREE, 20000621);
2305 else
2306 vcall_index = NULL_TREE;
2308 thunk = make_thunk (build1 (ADDR_EXPR,
2309 vfunc_ptr_type_node,
2310 fn),
2311 BV_DELTA (v),
2312 vcall_index);
2313 use_thunk (thunk, /*emit_p=*/1);
2318 /* Generate RTL for FN. */
2320 void
2321 expand_body (fn)
2322 tree fn;
2324 int saved_lineno;
2325 const char *saved_input_filename;
2327 /* When the parser calls us after finishing the body of a template
2328 function, we don't really want to expand the body. When we're
2329 processing an in-class definition of an inline function,
2330 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2331 to look at the function itself. */
2332 if (processing_template_decl
2333 || (DECL_LANG_SPECIFIC (fn)
2334 && DECL_TEMPLATE_INFO (fn)
2335 && uses_template_parms (DECL_TI_ARGS (fn))))
2337 /* Normally, collection only occurs in rest_of_compilation. So,
2338 if we don't collect here, we never collect junk generated
2339 during the processing of templates until we hit a
2340 non-template function. */
2341 ggc_collect ();
2342 return;
2345 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2346 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2347 simplify_aggr_init_exprs_r,
2348 NULL);
2350 /* If this is a constructor or destructor body, we have to clone
2351 it. */
2352 if (maybe_clone_body (fn))
2354 /* We don't want to process FN again, so pretend we've written
2355 it out, even though we haven't. */
2356 TREE_ASM_WRITTEN (fn) = 1;
2357 return;
2360 /* There's no reason to do any of the work here if we're only doing
2361 semantic analysis; this code just generates RTL. */
2362 if (flag_syntax_only)
2363 return;
2365 /* If possible, avoid generating RTL for this function. Instead,
2366 just record it as an inline function, and wait until end-of-file
2367 to decide whether to write it out or not. */
2368 if (/* We have to generate RTL if it's not an inline function. */
2369 (DECL_INLINE (fn) || DECL_COMDAT (fn))
2370 /* Or if we have to emit code for inline functions anyhow. */
2371 && !flag_keep_inline_functions
2372 /* Or if we actually have a reference to the function. */
2373 && !DECL_NEEDED_P (fn))
2375 /* Set DECL_EXTERNAL so that assemble_external will be called as
2376 necessary. We'll clear it again in finish_file. */
2377 if (!DECL_EXTERNAL (fn))
2379 DECL_NOT_REALLY_EXTERN (fn) = 1;
2380 DECL_EXTERNAL (fn) = 1;
2382 /* Remember this function. In finish_file we'll decide if
2383 we actually need to write this function out. */
2384 defer_fn (fn);
2385 /* Let the back-end know that this function exists. */
2386 (*debug_hooks->deferred_inline_function) (fn);
2387 return;
2390 /* Compute the appropriate object-file linkage for inline
2391 functions. */
2392 if (DECL_DECLARED_INLINE_P (fn))
2393 import_export_decl (fn);
2395 /* If FN is external, then there's no point in generating RTL for
2396 it. This situation can arise with an inline function under
2397 `-fexternal-templates'; we instantiate the function, even though
2398 we're not planning on emitting it, in case we get a chance to
2399 inline it. */
2400 if (DECL_EXTERNAL (fn))
2401 return;
2403 timevar_push (TV_INTEGRATION);
2405 /* Optimize the body of the function before expanding it. */
2406 optimize_function (fn);
2408 timevar_pop (TV_INTEGRATION);
2409 timevar_push (TV_EXPAND);
2411 /* Save the current file name and line number. When we expand the
2412 body of the function, we'll set LINENO and INPUT_FILENAME so that
2413 error-mesages come out in the right places. */
2414 saved_lineno = lineno;
2415 saved_input_filename = input_filename;
2416 lineno = DECL_SOURCE_LINE (fn);
2417 input_filename = DECL_SOURCE_FILE (fn);
2419 genrtl_start_function (fn);
2420 current_function_is_thunk = DECL_THUNK_P (fn);
2422 /* Expand the body. */
2423 expand_stmt (DECL_SAVED_TREE (fn));
2425 /* Statements should always be full-expressions at the outermost set
2426 of curly braces for a function. */
2427 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2429 /* The outermost statement for a function contains the line number
2430 recorded when we finished processing the function. */
2431 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2433 /* Generate code for the function. */
2434 genrtl_finish_function (fn);
2436 /* If possible, obliterate the body of the function so that it can
2437 be garbage collected. */
2438 if (dump_enabled_p (TDI_all))
2439 /* Keep the body; we're going to dump it. */
2441 else if (DECL_INLINE (fn) && flag_inline_trees)
2442 /* We might need the body of this function so that we can expand
2443 it inline somewhere else. */
2445 else
2446 /* We don't need the body; blow it away. */
2447 DECL_SAVED_TREE (fn) = NULL_TREE;
2449 /* And restore the current source position. */
2450 lineno = saved_lineno;
2451 input_filename = saved_input_filename;
2452 extract_interface_info ();
2454 timevar_pop (TV_EXPAND);
2456 /* Emit any thunks that should be emitted at the same time as FN. */
2457 emit_associated_thunks (fn);
2460 /* Helper function for walk_tree, used by finish_function to override all
2461 the RETURN_STMTs and pertinent CLEANUP_STMTs for the named return
2462 value optimization. */
2464 tree
2465 nullify_returns_r (tp, walk_subtrees, data)
2466 tree *tp;
2467 int *walk_subtrees;
2468 void *data;
2470 tree nrv = (tree) data;
2472 /* No need to walk into types. There wouldn't be any need to walk into
2473 non-statements, except that we have to consider STMT_EXPRs. */
2474 if (TYPE_P (*tp))
2475 *walk_subtrees = 0;
2476 else if (TREE_CODE (*tp) == RETURN_STMT)
2477 RETURN_EXPR (*tp) = NULL_TREE;
2478 else if (TREE_CODE (*tp) == CLEANUP_STMT
2479 && CLEANUP_DECL (*tp) == nrv)
2480 CLEANUP_EXPR (*tp) = NULL_TREE;
2482 /* Keep iterating. */
2483 return NULL_TREE;
2486 /* Start generating the RTL for FN. */
2488 static void
2489 genrtl_start_function (fn)
2490 tree fn;
2492 /* Tell everybody what function we're processing. */
2493 current_function_decl = fn;
2494 /* Get the RTL machinery going for this function. */
2495 init_function_start (fn, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
2496 /* Let everybody know that we're expanding this function, not doing
2497 semantic analysis. */
2498 expanding_p = 1;
2500 /* Even though we're inside a function body, we still don't want to
2501 call expand_expr to calculate the size of a variable-sized array.
2502 We haven't necessarily assigned RTL to all variables yet, so it's
2503 not safe to try to expand expressions involving them. */
2504 immediate_size_expand = 0;
2505 cfun->x_dont_save_pending_sizes_p = 1;
2507 /* Let the user know we're compiling this function. */
2508 announce_function (fn);
2510 /* Initialize the per-function data. */
2511 my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911);
2512 if (DECL_SAVED_FUNCTION_DATA (fn))
2514 /* If we already parsed this function, and we're just expanding it
2515 now, restore saved state. */
2516 *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn);
2518 /* This function is being processed in whole-function mode; we
2519 already did semantic analysis. */
2520 cfun->x_whole_function_mode_p = 1;
2522 /* If we decided that we didn't want to inline this function,
2523 make sure the back-end knows that. */
2524 if (!current_function_cannot_inline)
2525 current_function_cannot_inline = cp_function_chain->cannot_inline;
2527 /* We don't need the saved data anymore. */
2528 free (DECL_SAVED_FUNCTION_DATA (fn));
2529 DECL_SAVED_FUNCTION_DATA (fn) = NULL;
2532 /* Keep track of how many functions we're presently expanding. */
2533 ++function_depth;
2535 /* Create a binding level for the parameters. */
2536 expand_function_start (fn, /*parms_have_cleanups=*/0);
2537 /* If this function is `main'. */
2538 if (DECL_MAIN_P (fn))
2539 expand_main_function ();
2541 /* Give our named return value the same RTL as our RESULT_DECL. */
2542 if (current_function_return_value)
2543 COPY_DECL_RTL (DECL_RESULT (fn), current_function_return_value);
2546 /* Finish generating the RTL for FN. */
2548 static void
2549 genrtl_finish_function (fn)
2550 tree fn;
2552 tree t;
2554 #if 0
2555 if (write_symbols != NO_DEBUG)
2557 /* Keep this code around in case we later want to control debug info
2558 based on whether a type is "used". (jason 1999-11-11) */
2560 tree ttype = target_type (fntype);
2561 tree parmdecl;
2563 if (IS_AGGR_TYPE (ttype))
2564 /* Let debugger know it should output info for this type. */
2565 note_debug_info_needed (ttype);
2567 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
2569 ttype = target_type (TREE_TYPE (parmdecl));
2570 if (IS_AGGR_TYPE (ttype))
2571 /* Let debugger know it should output info for this type. */
2572 note_debug_info_needed (ttype);
2575 #endif
2577 /* Clean house because we will need to reorder insns here. */
2578 do_pending_stack_adjust ();
2580 /* If we have a named return value, we need to force a return so that
2581 the return register is USEd. */
2582 if (DECL_NAME (DECL_RESULT (fn)))
2583 emit_jump (return_label);
2585 /* We hard-wired immediate_size_expand to zero in start_function.
2586 Expand_function_end will decrement this variable. So, we set the
2587 variable to one here, so that after the decrement it will remain
2588 zero. */
2589 immediate_size_expand = 1;
2591 /* Generate rtl for function exit. */
2592 expand_function_end (input_filename, lineno, 0);
2594 /* If this is a nested function (like a template instantiation that
2595 we're compiling in the midst of compiling something else), push a
2596 new GC context. That will keep local variables on the stack from
2597 being collected while we're doing the compilation of this
2598 function. */
2599 if (function_depth > 1)
2600 ggc_push_context ();
2602 /* There's no need to defer outputting this function any more; we
2603 know we want to output it. */
2604 DECL_DEFER_OUTPUT (fn) = 0;
2606 /* Run the optimizers and output the assembler code for this
2607 function. */
2608 rest_of_compilation (fn);
2610 /* Undo the call to ggc_push_context above. */
2611 if (function_depth > 1)
2612 ggc_pop_context ();
2614 #if 0
2615 /* Keep this code around in case we later want to control debug info
2616 based on whether a type is "used". (jason 1999-11-11) */
2618 if (ctype && TREE_ASM_WRITTEN (fn))
2619 note_debug_info_needed (ctype);
2620 #endif
2622 /* If this function is marked with the constructor attribute, add it
2623 to the list of functions to be called along with constructors
2624 from static duration objects. */
2625 if (DECL_STATIC_CONSTRUCTOR (fn))
2626 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
2628 /* If this function is marked with the destructor attribute, add it
2629 to the list of functions to be called along with destructors from
2630 static duration objects. */
2631 if (DECL_STATIC_DESTRUCTOR (fn))
2632 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
2634 --function_depth;
2636 /* In C++, we should never be saving RTL for the function. */
2637 my_friendly_assert (!DECL_SAVED_INSNS (fn), 20010903);
2639 /* Since we don't need the RTL for this function anymore, stop
2640 pointing to it. That's especially important for LABEL_DECLs,
2641 since you can reach all the instructions in the function from the
2642 CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. Walk the
2643 BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and non-static
2644 local variables. */
2645 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2646 clear_decl_rtl,
2647 NULL);
2649 /* Clear out the RTL for the arguments. */
2650 for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t))
2652 SET_DECL_RTL (t, NULL_RTX);
2653 DECL_INCOMING_RTL (t) = NULL_RTX;
2656 if (!(flag_inline_trees && DECL_INLINE (fn)))
2657 /* DECL_INITIAL must remain nonzero so we know this was an
2658 actual function definition. */
2659 DECL_INITIAL (fn) = error_mark_node;
2661 /* Let the error reporting routines know that we're outside a
2662 function. For a nested function, this value is used in
2663 pop_cp_function_context and then reset via pop_function_context. */
2664 current_function_decl = NULL_TREE;
2667 /* Clear out the DECL_RTL for the non-static variables in BLOCK and
2668 its sub-blocks. */
2670 static tree
2671 clear_decl_rtl (tp, walk_subtrees, data)
2672 tree *tp;
2673 int *walk_subtrees ATTRIBUTE_UNUSED;
2674 void *data ATTRIBUTE_UNUSED;
2676 if (nonstatic_local_decl_p (*tp))
2677 SET_DECL_RTL (*tp, NULL_RTX);
2679 return NULL_TREE;
2682 /* Perform initialization related to this module. */
2684 void
2685 init_cp_semantics ()
2687 lang_expand_stmt = cp_expand_stmt;