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,
7 2003 Free Software Foundation, Inc.
8 Written by Mark Mitchell (mmitchell@usa.net) based on code found
9 formerly in parse.y and pt.c.
11 This file is part of GCC.
13 GCC is free software; you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
18 GCC is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GCC; see the file COPYING. If not, write to the Free
25 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 #include "coretypes.h"
34 #include "tree-inline.h"
46 /* There routines provide a modular interface to perform many parsing
47 operations. They may therefore be used during actual parsing, or
48 during template instantiation, which may be regarded as a
49 degenerate form of parsing. Since the current g++ parser is
50 lacking in several respects, and will be reimplemented, we are
51 attempting to move most code that is not directly related to
52 parsing into this file; that will make implementing the new parser
53 much easier since it will be able to make use of these routines. */
55 static tree
maybe_convert_cond (tree
);
56 static tree
simplify_aggr_init_exprs_r (tree
*, int *, void *);
57 static void emit_associated_thunks (tree
);
58 static void genrtl_try_block (tree
);
59 static void genrtl_eh_spec_block (tree
);
60 static void genrtl_handler (tree
);
61 static void cp_expand_stmt (tree
);
62 static void genrtl_start_function (tree
);
63 static void genrtl_finish_function (tree
);
64 static tree
clear_decl_rtl (tree
*, int *, void *);
66 /* Finish processing the COND, the SUBSTMT condition for STMT. */
68 #define FINISH_COND(COND, STMT, SUBSTMT) \
70 if (last_tree != (STMT)) \
72 RECHAIN_STMTS (STMT, SUBSTMT); \
73 if (!processing_template_decl) \
75 (COND) = build_tree_list (SUBSTMT, COND); \
83 /* Deferred Access Checking Overview
84 ---------------------------------
86 Most C++ expressions and declarations require access checking
87 to be performed during parsing. However, in several cases,
88 this has to be treated differently.
90 For member declarations, access checking has to be deferred
91 until more information about the declaration is known. For
103 When we are parsing the function return type `A::X', we don't
104 really know if this is allowed until we parse the function name.
106 Furthermore, some contexts require that access checking is
107 never performed at all. These include class heads, and template
110 Typical use of access checking functions is described here:
112 1. When we enter a context that requires certain access checking
113 mode, the function `push_deferring_access_checks' is called with
114 DEFERRING argument specifying the desired mode. Access checking
115 may be performed immediately (dk_no_deferred), deferred
116 (dk_deferred), or not performed (dk_no_check).
118 2. When a declaration such as a type, or a variable, is encountered,
119 the function `perform_or_defer_access_check' is called. It
120 maintains a TREE_LIST of all deferred checks.
122 3. The global `current_class_type' or `current_function_decl' is then
123 setup by the parser. `enforce_access' relies on these information
126 4. Upon exiting the context mentioned in step 1,
127 `perform_deferred_access_checks' is called to check all declaration
128 stored in the TREE_LIST. `pop_deferring_access_checks' is then
129 called to restore the previous access checking mode.
131 In case of parsing error, we simply call `pop_deferring_access_checks'
132 without `perform_deferred_access_checks'. */
134 /* Data for deferred access checking. */
135 static GTY(()) deferred_access
*deferred_access_stack
;
136 static GTY(()) deferred_access
*deferred_access_free_list
;
138 /* Save the current deferred access states and start deferred
139 access checking iff DEFER_P is true. */
141 void push_deferring_access_checks (deferring_kind deferring
)
145 /* For context like template instantiation, access checking
146 disabling applies to all nested context. */
147 if (deferred_access_stack
148 && deferred_access_stack
->deferring_access_checks_kind
== dk_no_check
)
149 deferring
= dk_no_check
;
151 /* Recycle previously used free store if available. */
152 if (deferred_access_free_list
)
154 d
= deferred_access_free_list
;
155 deferred_access_free_list
= d
->next
;
158 d
= (deferred_access
*) ggc_alloc (sizeof (deferred_access
));
160 d
->next
= deferred_access_stack
;
161 d
->deferred_access_checks
= NULL_TREE
;
162 d
->deferring_access_checks_kind
= deferring
;
163 deferred_access_stack
= d
;
166 /* Resume deferring access checks again after we stopped doing
169 void resume_deferring_access_checks (void)
171 if (deferred_access_stack
->deferring_access_checks_kind
== dk_no_deferred
)
172 deferred_access_stack
->deferring_access_checks_kind
= dk_deferred
;
175 /* Stop deferring access checks. */
177 void stop_deferring_access_checks (void)
179 if (deferred_access_stack
->deferring_access_checks_kind
== dk_deferred
)
180 deferred_access_stack
->deferring_access_checks_kind
= dk_no_deferred
;
183 /* Discard the current deferred access checks and restore the
186 void pop_deferring_access_checks (void)
188 deferred_access
*d
= deferred_access_stack
;
189 deferred_access_stack
= d
->next
;
191 /* Remove references to access checks TREE_LIST. */
192 d
->deferred_access_checks
= NULL_TREE
;
194 /* Store in free list for later use. */
195 d
->next
= deferred_access_free_list
;
196 deferred_access_free_list
= d
;
199 /* Returns a TREE_LIST representing the deferred checks.
200 The TREE_PURPOSE of each node is the type through which the
201 access occurred; the TREE_VALUE is the declaration named.
204 tree
get_deferred_access_checks (void)
206 return deferred_access_stack
->deferred_access_checks
;
209 /* Take current deferred checks and combine with the
210 previous states if we also defer checks previously.
211 Otherwise perform checks now. */
213 void pop_to_parent_deferring_access_checks (void)
215 tree deferred_check
= get_deferred_access_checks ();
216 deferred_access
*d1
= deferred_access_stack
;
217 deferred_access
*d2
= deferred_access_stack
->next
;
218 deferred_access
*d3
= deferred_access_stack
->next
->next
;
220 /* Temporary swap the order of the top two states, just to make
221 sure the garbage collector will not reclaim the memory during
223 deferred_access_stack
= d2
;
227 for ( ; deferred_check
; deferred_check
= TREE_CHAIN (deferred_check
))
228 /* Perform deferred check if required. */
229 perform_or_defer_access_check (TREE_PURPOSE (deferred_check
),
230 TREE_VALUE (deferred_check
));
232 deferred_access_stack
= d1
;
235 pop_deferring_access_checks ();
238 /* Perform the deferred access checks.
240 After performing the checks, we still have to keep the list
241 `deferred_access_stack->deferred_access_checks' since we may want
242 to check access for them again later in a different context.
249 A::X A::a, x; // No error for `A::a', error for `x'
251 We have to perform deferred access of `A::X', first with `A::a',
254 void perform_deferred_access_checks (void)
257 for (deferred_check
= deferred_access_stack
->deferred_access_checks
;
259 deferred_check
= TREE_CHAIN (deferred_check
))
261 enforce_access (TREE_PURPOSE (deferred_check
),
262 TREE_VALUE (deferred_check
));
265 /* Defer checking the accessibility of DECL, when looked up in
268 void perform_or_defer_access_check (tree binfo
, tree decl
)
272 my_friendly_assert (TREE_CODE (binfo
) == TREE_VEC
, 20030623);
274 /* If we are not supposed to defer access checks, just check now. */
275 if (deferred_access_stack
->deferring_access_checks_kind
== dk_no_deferred
)
277 enforce_access (binfo
, decl
);
280 /* Exit if we are in a context that no access checking is performed. */
281 else if (deferred_access_stack
->deferring_access_checks_kind
== dk_no_check
)
284 /* See if we are already going to perform this check. */
285 for (check
= deferred_access_stack
->deferred_access_checks
;
287 check
= TREE_CHAIN (check
))
288 if (TREE_VALUE (check
) == decl
&& TREE_PURPOSE (check
) == binfo
)
290 /* If not, record the check. */
291 deferred_access_stack
->deferred_access_checks
292 = tree_cons (binfo
, decl
,
293 deferred_access_stack
->deferred_access_checks
);
296 /* Returns nonzero if the current statement is a full expression,
297 i.e. temporaries created during that statement should be destroyed
298 at the end of the statement. */
301 stmts_are_full_exprs_p (void)
303 return current_stmt_tree ()->stmts_are_full_exprs_p
;
306 /* Returns the stmt_tree (if any) to which statements are currently
307 being added. If there is no active statement-tree, NULL is
311 current_stmt_tree (void)
314 ? &cfun
->language
->base
.x_stmt_tree
315 : &scope_chain
->x_stmt_tree
);
318 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
319 flag for this because "A union for which objects or pointers are
320 declared is not an anonymous union" [class.union]. */
323 anon_aggr_type_p (tree node
)
325 return ANON_AGGR_TYPE_P (node
);
328 /* Finish a scope. */
333 tree block
= NULL_TREE
;
335 if (stmts_are_full_exprs_p ())
337 tree scope_stmts
= NULL_TREE
;
339 block
= poplevel (kept_level_p (), 1, 0);
340 if (!processing_template_decl
)
342 /* This needs to come after the poplevel so that partial scopes
343 are properly nested. */
344 scope_stmts
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
347 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts
)) = block
;
348 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts
)) = block
;
356 /* Begin a new scope. */
359 do_pushlevel (scope_kind sk
)
361 if (stmts_are_full_exprs_p ())
363 if (!processing_template_decl
)
364 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
369 /* Finish a goto-statement. */
372 finish_goto_stmt (tree destination
)
374 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
375 destination
= lookup_label (destination
);
377 /* We warn about unused labels with -Wunused. That means we have to
378 mark the used labels as used. */
379 if (TREE_CODE (destination
) == LABEL_DECL
)
380 TREE_USED (destination
) = 1;
382 if (TREE_CODE (destination
) != LABEL_DECL
)
383 /* We don't inline calls to functions with computed gotos.
384 Those functions are typically up to some funny business,
385 and may be depending on the labels being at particular
386 addresses, or some such. */
387 DECL_UNINLINABLE (current_function_decl
) = 1;
389 check_goto (destination
);
391 return add_stmt (build_stmt (GOTO_STMT
, destination
));
394 /* COND is the condition-expression for an if, while, etc.,
395 statement. Convert it to a boolean value, if appropriate. */
398 maybe_convert_cond (tree cond
)
400 /* Empty conditions remain empty. */
404 /* Wait until we instantiate templates before doing conversion. */
405 if (processing_template_decl
)
408 /* Do the conversion. */
409 cond
= convert_from_reference (cond
);
410 return condition_conversion (cond
);
413 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
416 finish_expr_stmt (tree expr
)
419 tree expr_type
= NULL_TREE
;;
421 if (expr
!= NULL_TREE
)
423 if (!processing_template_decl
424 && !(stmts_are_full_exprs_p ())
425 && ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
427 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
428 expr
= default_conversion (expr
);
430 /* Remember the type of the expression. */
431 expr_type
= TREE_TYPE (expr
);
433 if (stmts_are_full_exprs_p ())
434 expr
= convert_to_void (expr
, "statement");
436 r
= add_stmt (build_stmt (EXPR_STMT
, expr
));
441 /* This was an expression-statement, so we save the type of the
443 last_expr_type
= expr_type
;
449 /* Begin an if-statement. Returns a newly created IF_STMT if
456 do_pushlevel (sk_block
);
457 r
= build_stmt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
462 /* Process the COND of an if-statement, which may be given by
466 finish_if_stmt_cond (tree cond
, tree if_stmt
)
468 cond
= maybe_convert_cond (cond
);
469 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
472 /* Finish the then-clause of an if-statement, which may be given by
476 finish_then_clause (tree if_stmt
)
478 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
482 /* Begin the else-clause of an if-statement. */
485 begin_else_clause (void)
489 /* Finish the else-clause of an if-statement, which may be given by
493 finish_else_clause (tree if_stmt
)
495 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
498 /* Finish an if-statement. */
501 finish_if_stmt (void)
507 /* Begin a while-statement. Returns a newly created WHILE_STMT if
511 begin_while_stmt (void)
514 r
= build_stmt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
516 do_pushlevel (sk_block
);
520 /* Process the COND of a while-statement, which may be given by
524 finish_while_stmt_cond (tree cond
, tree while_stmt
)
526 cond
= maybe_convert_cond (cond
);
527 if (processing_template_decl
)
528 /* Don't mess with condition decls in a template. */
529 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
530 else if (getdecls () == NULL_TREE
)
531 /* It was a simple condition; install it. */
532 WHILE_COND (while_stmt
) = cond
;
535 /* If there was a declaration in the condition, we can't leave it
539 while (true) { A x = 42; if (!x) break; } */
541 WHILE_COND (while_stmt
) = boolean_true_node
;
543 if_stmt
= begin_if_stmt ();
544 cond
= build_unary_op (TRUTH_NOT_EXPR
, cond
, 0);
545 finish_if_stmt_cond (cond
, if_stmt
);
546 finish_break_stmt ();
547 finish_then_clause (if_stmt
);
552 /* Finish a while-statement, which may be given by WHILE_STMT. */
555 finish_while_stmt (tree while_stmt
)
558 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
562 /* Begin a do-statement. Returns a newly created DO_STMT if
568 tree r
= build_stmt (DO_STMT
, NULL_TREE
, NULL_TREE
);
573 /* Finish the body of a do-statement, which may be given by DO_STMT. */
576 finish_do_body (tree do_stmt
)
578 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
581 /* Finish a do-statement, which may be given by DO_STMT, and whose
582 COND is as indicated. */
585 finish_do_stmt (tree cond
, tree do_stmt
)
587 cond
= maybe_convert_cond (cond
);
588 DO_COND (do_stmt
) = cond
;
592 /* Finish a return-statement. The EXPRESSION returned, if any, is as
596 finish_return_stmt (tree expr
)
600 expr
= check_return_expr (expr
);
601 if (!processing_template_decl
)
603 if (DECL_DESTRUCTOR_P (current_function_decl
))
605 /* Similarly, all destructors must run destructors for
606 base-classes before returning. So, all returns in a
607 destructor get sent to the DTOR_LABEL; finish_function emits
608 code to return a value there. */
609 return finish_goto_stmt (dtor_label
);
612 r
= add_stmt (build_stmt (RETURN_STMT
, expr
));
618 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
621 begin_for_stmt (void)
625 r
= build_stmt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
626 NULL_TREE
, NULL_TREE
);
627 NEW_FOR_SCOPE_P (r
) = flag_new_for_scope
> 0;
628 if (NEW_FOR_SCOPE_P (r
))
629 do_pushlevel (sk_for
);
635 /* Finish the for-init-statement of a for-statement, which may be
636 given by FOR_STMT. */
639 finish_for_init_stmt (tree for_stmt
)
641 if (last_tree
!= for_stmt
)
642 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
643 do_pushlevel (sk_block
);
646 /* Finish the COND of a for-statement, which may be given by
650 finish_for_cond (tree cond
, tree for_stmt
)
652 cond
= maybe_convert_cond (cond
);
653 if (processing_template_decl
)
654 /* Don't mess with condition decls in a template. */
655 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
656 else if (getdecls () == NULL_TREE
)
657 /* It was a simple condition; install it. */
658 FOR_COND (for_stmt
) = cond
;
661 /* If there was a declaration in the condition, we can't leave it
663 for (; A x = 42;) { }
665 for (;;) { A x = 42; if (!x) break; } */
667 FOR_COND (for_stmt
) = NULL_TREE
;
669 if_stmt
= begin_if_stmt ();
670 cond
= build_unary_op (TRUTH_NOT_EXPR
, cond
, 0);
671 finish_if_stmt_cond (cond
, if_stmt
);
672 finish_break_stmt ();
673 finish_then_clause (if_stmt
);
678 /* Finish the increment-EXPRESSION in a for-statement, which may be
679 given by FOR_STMT. */
682 finish_for_expr (tree expr
, tree for_stmt
)
684 FOR_EXPR (for_stmt
) = expr
;
687 /* Finish the body of a for-statement, which may be given by
688 FOR_STMT. The increment-EXPR for the loop must be
692 finish_for_stmt (tree for_stmt
)
694 /* Pop the scope for the body of the loop. */
696 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
697 if (NEW_FOR_SCOPE_P (for_stmt
))
702 /* Finish a break-statement. */
705 finish_break_stmt (void)
707 return add_stmt (build_break_stmt ());
710 /* Finish a continue-statement. */
713 finish_continue_stmt (void)
715 return add_stmt (build_continue_stmt ());
718 /* Begin a switch-statement. Returns a new SWITCH_STMT if
722 begin_switch_stmt (void)
725 do_pushlevel (sk_block
);
726 r
= build_stmt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
731 /* Finish the cond of a switch-statement. */
734 finish_switch_cond (tree cond
, tree switch_stmt
)
736 tree orig_type
= NULL
;
737 if (!processing_template_decl
)
741 /* Convert the condition to an integer or enumeration type. */
742 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
743 if (cond
== NULL_TREE
)
745 error ("switch quantity not an integer");
746 cond
= error_mark_node
;
748 orig_type
= TREE_TYPE (cond
);
749 if (cond
!= error_mark_node
)
751 cond
= default_conversion (cond
);
752 cond
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (cond
), cond
));
755 if (cond
!= error_mark_node
)
757 index
= get_unwidened (cond
, NULL_TREE
);
758 /* We can't strip a conversion from a signed type to an unsigned,
759 because if we did, int_fits_type_p would do the wrong thing
760 when checking case values for being in range,
761 and it's too hard to do the right thing. */
762 if (TREE_UNSIGNED (TREE_TYPE (cond
))
763 == TREE_UNSIGNED (TREE_TYPE (index
)))
767 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
768 SWITCH_TYPE (switch_stmt
) = orig_type
;
769 push_switch (switch_stmt
);
772 /* Finish the body of a switch-statement, which may be given by
773 SWITCH_STMT. The COND to switch on is indicated. */
776 finish_switch_stmt (tree switch_stmt
)
778 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
784 /* Generate the RTL for T, which is a TRY_BLOCK. */
787 genrtl_try_block (tree t
)
791 expand_eh_region_start ();
792 expand_stmt (TRY_STMTS (t
));
793 expand_eh_region_end_cleanup (TRY_HANDLERS (t
));
797 if (!FN_TRY_BLOCK_P (t
))
798 emit_line_note (input_filename
, input_line
);
800 expand_eh_region_start ();
801 expand_stmt (TRY_STMTS (t
));
803 if (FN_TRY_BLOCK_P (t
))
805 expand_start_all_catch ();
806 in_function_try_handler
= 1;
807 expand_stmt (TRY_HANDLERS (t
));
808 in_function_try_handler
= 0;
809 expand_end_all_catch ();
813 expand_start_all_catch ();
814 expand_stmt (TRY_HANDLERS (t
));
815 expand_end_all_catch ();
820 /* Generate the RTL for T, which is an EH_SPEC_BLOCK. */
823 genrtl_eh_spec_block (tree t
)
825 expand_eh_region_start ();
826 expand_stmt (EH_SPEC_STMTS (t
));
827 expand_eh_region_end_allowed (EH_SPEC_RAISES (t
),
828 build_call (call_unexpected_node
,
829 tree_cons (NULL_TREE
,
834 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
838 begin_try_block (void)
840 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
845 /* Likewise, for a function-try-block. */
848 begin_function_try_block (void)
850 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
851 FN_TRY_BLOCK_P (r
) = 1;
856 /* Finish a try-block, which may be given by TRY_BLOCK. */
859 finish_try_block (tree try_block
)
861 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
864 /* Finish the body of a cleanup try-block, which may be given by
868 finish_cleanup_try_block (tree try_block
)
870 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
873 /* Finish an implicitly generated try-block, with a cleanup is given
877 finish_cleanup (tree cleanup
, tree try_block
)
879 TRY_HANDLERS (try_block
) = cleanup
;
880 CLEANUP_P (try_block
) = 1;
883 /* Likewise, for a function-try-block. */
886 finish_function_try_block (tree try_block
)
888 if (TREE_CHAIN (try_block
)
889 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
891 /* Chain the compound statement after the CTOR_INITIALIZER. */
892 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
893 /* And make the CTOR_INITIALIZER the body of the try-block. */
894 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
897 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
898 in_function_try_handler
= 1;
901 /* Finish a handler-sequence for a try-block, which may be given by
905 finish_handler_sequence (tree try_block
)
907 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
908 check_handlers (TRY_HANDLERS (try_block
));
911 /* Likewise, for a function-try-block. */
914 finish_function_handler_sequence (tree try_block
)
916 in_function_try_handler
= 0;
917 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
918 check_handlers (TRY_HANDLERS (try_block
));
921 /* Generate the RTL for T, which is a HANDLER. */
924 genrtl_handler (tree t
)
926 genrtl_do_pushlevel ();
927 if (!processing_template_decl
)
928 expand_start_catch (HANDLER_TYPE (t
));
929 expand_stmt (HANDLER_BODY (t
));
930 if (!processing_template_decl
)
934 /* Begin a handler. Returns a HANDLER if appropriate. */
940 r
= build_stmt (HANDLER
, NULL_TREE
, NULL_TREE
);
942 /* Create a binding level for the eh_info and the exception object
944 do_pushlevel (sk_catch
);
948 /* Finish the handler-parameters for a handler, which may be given by
949 HANDLER. DECL is the declaration for the catch parameter, or NULL
950 if this is a `catch (...)' clause. */
953 finish_handler_parms (tree decl
, tree handler
)
955 tree type
= NULL_TREE
;
956 if (processing_template_decl
)
960 decl
= pushdecl (decl
);
961 decl
= push_template_decl (decl
);
962 add_decl_stmt (decl
);
963 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
964 type
= TREE_TYPE (decl
);
968 type
= expand_start_catch_block (decl
);
970 HANDLER_TYPE (handler
) = type
;
973 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
974 the return value from the matching call to finish_handler_parms. */
977 finish_handler (tree handler
)
979 if (!processing_template_decl
)
980 expand_end_catch_block ();
982 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
985 /* Begin a compound-statement. If HAS_NO_SCOPE is nonzero, the
986 compound-statement does not define a scope. Returns a new
987 COMPOUND_STMT if appropriate. */
990 begin_compound_stmt (int has_no_scope
)
995 r
= build_stmt (COMPOUND_STMT
, NULL_TREE
);
997 if (last_tree
&& TREE_CODE (last_tree
) == TRY_BLOCK
)
1002 COMPOUND_STMT_NO_SCOPE (r
) = 1;
1004 last_expr_type
= NULL_TREE
;
1007 do_pushlevel (is_try
? sk_try
: sk_block
);
1009 /* Normally, we try hard to keep the BLOCK for a
1010 statement-expression. But, if it's a statement-expression with
1011 a scopeless block, there's nothing to keep, and we don't want
1012 to accidentally keep a block *inside* the scopeless block. */
1013 keep_next_level (0);
1018 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
1019 If HAS_NO_SCOPE is nonzero, the compound statement does not define
1023 finish_compound_stmt (int has_no_scope
, tree compound_stmt
)
1033 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
1035 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
1036 the precise purpose of that variable is store the type of the
1037 last expression statement within the last compound statement, we
1038 preserve the value. */
1046 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
1047 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
1051 finish_asm_stmt (tree cv_qualifier
,
1053 tree output_operands
,
1054 tree input_operands
,
1060 if (cv_qualifier
!= NULL_TREE
1061 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
1063 warning ("%s qualifier ignored on asm",
1064 IDENTIFIER_POINTER (cv_qualifier
));
1065 cv_qualifier
= NULL_TREE
;
1068 if (!processing_template_decl
)
1074 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
1076 tree converted_operand
1077 = decay_conversion (TREE_VALUE (t
));
1079 /* If the type of the operand hasn't been determined (e.g.,
1080 because it involves an overloaded function), then issue
1081 an error message. There's no context available to
1082 resolve the overloading. */
1083 if (TREE_TYPE (converted_operand
) == unknown_type_node
)
1085 error ("type of asm operand `%E' could not be determined",
1087 converted_operand
= error_mark_node
;
1089 TREE_VALUE (t
) = converted_operand
;
1092 ninputs
= list_length (input_operands
);
1093 noutputs
= list_length (output_operands
);
1095 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1100 const char *constraint
;
1103 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1104 operand
= TREE_VALUE (t
);
1106 if (!parse_output_constraint (&constraint
,
1107 i
, ninputs
, noutputs
,
1112 /* By marking this operand as erroneous, we will not try
1113 to process this operand again in expand_asm_operands. */
1114 TREE_VALUE (t
) = error_mark_node
;
1118 /* If the operand is a DECL that is going to end up in
1119 memory, assume it is addressable. This is a bit more
1120 conservative than it would ideally be; the exact test is
1121 buried deep in expand_asm_operands and depends on the
1122 DECL_RTL for the OPERAND -- which we don't have at this
1124 if (!allows_reg
&& DECL_P (operand
))
1125 cxx_mark_addressable (operand
);
1129 r
= build_stmt (ASM_STMT
, cv_qualifier
, string
,
1130 output_operands
, input_operands
,
1132 return add_stmt (r
);
1135 /* Finish a label with the indicated NAME. */
1138 finish_label_stmt (tree name
)
1140 tree decl
= define_label (input_location
, name
);
1141 return add_stmt (build_stmt (LABEL_STMT
, decl
));
1144 /* Finish a series of declarations for local labels. G++ allows users
1145 to declare "local" labels, i.e., labels with scope. This extension
1146 is useful when writing code involving statement-expressions. */
1149 finish_label_decl (tree name
)
1151 tree decl
= declare_local_label (name
);
1152 add_decl_stmt (decl
);
1155 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1158 finish_decl_cleanup (tree decl
, tree cleanup
)
1160 add_stmt (build_stmt (CLEANUP_STMT
, decl
, cleanup
));
1163 /* If the current scope exits with an exception, run CLEANUP. */
1166 finish_eh_cleanup (tree cleanup
)
1168 tree r
= build_stmt (CLEANUP_STMT
, NULL_TREE
, cleanup
);
1169 CLEANUP_EH_ONLY (r
) = 1;
1173 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1174 order they were written by the user. Each node is as for
1175 emit_mem_initializers. */
1178 finish_mem_initializers (tree mem_inits
)
1180 /* Reorder the MEM_INITS so that they are in the order they appeared
1181 in the source program. */
1182 mem_inits
= nreverse (mem_inits
);
1184 if (processing_template_decl
)
1185 add_stmt (build_min_nt (CTOR_INITIALIZER
, mem_inits
));
1187 emit_mem_initializers (mem_inits
);
1190 /* Returns the stack of SCOPE_STMTs for the current function. */
1193 current_scope_stmt_stack (void)
1195 return &cfun
->language
->base
.x_scope_stmt_stack
;
1198 /* Finish a parenthesized expression EXPR. */
1201 finish_parenthesized_expr (tree expr
)
1203 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1204 /* This inhibits warnings in c_common_truthvalue_conversion. */
1205 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1207 if (TREE_CODE (expr
) == OFFSET_REF
)
1208 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1209 enclosed in parentheses. */
1210 PTRMEM_OK_P (expr
) = 0;
1214 /* Finish a reference to a non-static data member (DECL) that is not
1215 preceded by `.' or `->'. */
1218 finish_non_static_data_member (tree decl
, tree qualifying_scope
)
1220 my_friendly_assert (TREE_CODE (decl
) == FIELD_DECL
, 20020909);
1222 if (current_class_ptr
== NULL_TREE
)
1224 if (current_function_decl
1225 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1226 cp_error_at ("invalid use of member `%D' in static member function",
1229 cp_error_at ("invalid use of non-static data member `%D'", decl
);
1230 error ("from this location");
1232 return error_mark_node
;
1234 TREE_USED (current_class_ptr
) = 1;
1235 if (processing_template_decl
)
1236 return build_min (COMPONENT_REF
, TREE_TYPE (decl
),
1237 current_class_ref
, DECL_NAME (decl
));
1240 tree access_type
= current_class_type
;
1241 tree object
= current_class_ref
;
1244 && !DERIVED_FROM_P (context_for_name_lookup (decl
), access_type
))
1246 access_type
= TYPE_CONTEXT (access_type
);
1247 while (access_type
&& DECL_P (access_type
))
1248 access_type
= DECL_CONTEXT (access_type
);
1253 cp_error_at ("object missing in reference to `%D'",
1255 error ("from this location");
1256 return error_mark_node
;
1259 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
);
1261 /* If the data member was named `C::M', convert `*this' to `C'
1263 if (qualifying_scope
)
1265 tree binfo
= NULL_TREE
;
1266 object
= build_scoped_ref (object
, qualifying_scope
,
1270 return build_class_member_access_expr (object
, decl
,
1271 /*access_path=*/NULL_TREE
,
1272 /*preserve_reference=*/false);
1276 /* Begin a statement-expression. The value returned must be passed to
1277 finish_stmt_expr. */
1280 begin_stmt_expr (void)
1282 /* If we're outside a function, we won't have a statement-tree to
1283 work with. But, if we see a statement-expression we need to
1285 if (! cfun
&& !last_tree
)
1286 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1288 keep_next_level (1);
1289 /* If we're building a statement tree, then the upcoming compound
1290 statement will be chained onto the tree structure, starting at
1291 last_tree. We return last_tree so that we can later unhook the
1292 compound statement. */
1296 /* Used when beginning a statement-expression outside function scope.
1297 For example, when handling a file-scope initializer, we use this
1301 begin_global_stmt_expr (void)
1303 if (! cfun
&& !last_tree
)
1304 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1306 keep_next_level (1);
1308 return last_tree
? last_tree
: expand_start_stmt_expr(/*has_scope=*/1);
1311 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1314 finish_global_stmt_expr (tree stmt_expr
)
1316 stmt_expr
= expand_end_stmt_expr (stmt_expr
);
1319 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1320 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1325 /* Finish a statement-expression. RTL_EXPR should be the value
1326 returned by the previous begin_stmt_expr; EXPR is the
1327 statement-expression. Returns an expression representing the
1328 statement-expression. */
1331 finish_stmt_expr (tree rtl_expr
)
1335 /* If the last thing in the statement-expression was not an
1336 expression-statement, then it has type `void'. */
1337 if (!last_expr_type
)
1338 last_expr_type
= void_type_node
;
1339 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1340 TREE_SIDE_EFFECTS (result
) = 1;
1342 /* Remove the compound statement from the tree structure; it is
1343 now saved in the STMT_EXPR. */
1344 last_tree
= rtl_expr
;
1345 TREE_CHAIN (last_tree
) = NULL_TREE
;
1347 /* If we created a statement-tree for this statement-expression,
1350 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1351 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1356 /* Generate an expression for `FN (ARGS)'.
1358 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
1359 as a virtual call, even if FN is virtual. (This flag is set when
1360 encountering an expression where the function name is explicitly
1361 qualified. For example a call to `X::f' never generates a virtual
1364 Returns code for the call. */
1367 finish_call_expr (tree fn
, tree args
, bool disallow_virtual
)
1369 if (fn
== error_mark_node
|| args
== error_mark_node
)
1370 return error_mark_node
;
1372 if (processing_template_decl
)
1373 return build_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1375 /* ARGS should be a list of arguments. */
1376 my_friendly_assert (!args
|| TREE_CODE (args
) == TREE_LIST
,
1379 /* A reference to a member function will appear as an overloaded
1380 function (rather than a BASELINK) if an unqualified name was used
1382 if (!BASELINK_P (fn
) && is_overloaded_fn (fn
))
1386 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
1387 f
= get_first_fn (TREE_OPERAND (fn
, 0));
1389 f
= get_first_fn (fn
);
1390 if (DECL_FUNCTION_MEMBER_P (f
))
1392 tree type
= currently_open_derived_class (DECL_CONTEXT (f
));
1393 fn
= build_baselink (TYPE_BINFO (type
),
1395 fn
, /*optype=*/NULL_TREE
);
1399 if (BASELINK_P (fn
))
1403 /* A call to a member function. From [over.call.func]:
1405 If the keyword this is in scope and refers to the class of
1406 that member function, or a derived class thereof, then the
1407 function call is transformed into a qualified function call
1408 using (*this) as the postfix-expression to the left of the
1409 . operator.... [Otherwise] a contrived object of type T
1410 becomes the implied object argument.
1412 This paragraph is unclear about this situation:
1414 struct A { void f(); };
1415 struct B : public A {};
1416 struct C : public A { void g() { B::f(); }};
1418 In particular, for `B::f', this paragraph does not make clear
1419 whether "the class of that member function" refers to `A' or
1420 to `B'. We believe it refers to `B'. */
1421 if (current_class_type
1422 && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
1424 && current_class_ref
)
1425 object
= current_class_ref
;
1428 tree representative_fn
;
1430 representative_fn
= BASELINK_FUNCTIONS (fn
);
1431 if (TREE_CODE (representative_fn
) == TEMPLATE_ID_EXPR
)
1432 representative_fn
= TREE_OPERAND (representative_fn
, 0);
1433 representative_fn
= get_first_fn (representative_fn
);
1434 object
= build_dummy_object (DECL_CONTEXT (representative_fn
));
1437 return build_new_method_call (object
, fn
, args
, NULL_TREE
,
1439 ? LOOKUP_NONVIRTUAL
: 0));
1441 else if (is_overloaded_fn (fn
))
1442 /* A call to a namespace-scope function. */
1443 return build_new_function_call (fn
, args
);
1444 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
1449 error ("arguments to destructor are not allowed");
1450 /* Mark the pseudo-destructor call as having side-effects so
1451 that we do not issue warnings about its use. */
1452 result
= build1 (NOP_EXPR
,
1454 TREE_OPERAND (fn
, 0));
1455 TREE_SIDE_EFFECTS (result
) = 1;
1458 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
1460 /* If the "function" is really an object of class type, it might
1461 have an overloaded `operator ()'. */
1463 result
= build_new_op (CALL_EXPR
, LOOKUP_NORMAL
, fn
, args
, NULL_TREE
);
1468 /* A call where the function is unknown. */
1469 return build_function_call (fn
, args
);
1472 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1473 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1474 POSTDECREMENT_EXPR.) */
1477 finish_increment_expr (tree expr
, enum tree_code code
)
1479 return build_x_unary_op (code
, expr
);
1482 /* Finish a use of `this'. Returns an expression for `this'. */
1485 finish_this_expr (void)
1489 if (current_class_ptr
)
1491 result
= current_class_ptr
;
1493 else if (current_function_decl
1494 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1496 error ("`this' is unavailable for static member functions");
1497 result
= error_mark_node
;
1501 if (current_function_decl
)
1502 error ("invalid use of `this' in non-member function");
1504 error ("invalid use of `this' at top level");
1505 result
= error_mark_node
;
1511 /* Finish a member function call using OBJECT and ARGS as arguments to
1512 FN. Returns an expression for the call. */
1515 finish_object_call_expr (tree fn
, tree object
, tree args
)
1517 if (DECL_DECLARES_TYPE_P (fn
))
1519 if (processing_template_decl
)
1520 /* This can happen on code like:
1523 template <class T> void f(T t) {
1527 We just grab the underlying IDENTIFIER. */
1528 fn
= DECL_NAME (fn
);
1531 error ("calling type `%T' like a method", fn
);
1532 return error_mark_node
;
1536 if (processing_template_decl
)
1537 return build_nt (CALL_EXPR
,
1538 build_nt (COMPONENT_REF
, object
, fn
),
1542 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1544 return build_new_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1547 /* Finish a qualified member function call using OBJECT and ARGS as
1548 arguments to FN. Returns an expression for the call. */
1551 finish_qualified_object_call_expr (tree fn
, tree object
, tree args
)
1553 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1554 TREE_OPERAND (fn
, 1), args
);
1557 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
1558 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
1559 the TYPE for the type given. If SCOPE is non-NULL, the expression
1560 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
1563 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
)
1565 if (destructor
== error_mark_node
)
1566 return error_mark_node
;
1568 my_friendly_assert (TYPE_P (destructor
), 20010905);
1570 if (!processing_template_decl
)
1572 if (scope
== error_mark_node
)
1574 error ("invalid qualifying scope in pseudo-destructor name");
1575 return error_mark_node
;
1578 if (!same_type_p (TREE_TYPE (object
), destructor
))
1580 error ("`%E' is not of type `%T'", object
, destructor
);
1581 return error_mark_node
;
1585 return build (PSEUDO_DTOR_EXPR
, void_type_node
, object
, scope
, destructor
);
1588 /* Finish an expression of the form CODE EXPR. */
1591 finish_unary_op_expr (enum tree_code code
, tree expr
)
1593 tree result
= build_x_unary_op (code
, expr
);
1594 /* Inside a template, build_x_unary_op does not fold the
1595 expression. So check whether the result is folded before
1596 setting TREE_NEGATED_INT. */
1597 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1598 && TREE_CODE (result
) == INTEGER_CST
1599 && !TREE_UNSIGNED (TREE_TYPE (result
))
1600 && INT_CST_LT (result
, integer_zero_node
))
1601 TREE_NEGATED_INT (result
) = 1;
1602 overflow_warning (result
);
1606 /* Finish a compound-literal expression. TYPE is the type to which
1607 the INITIALIZER_LIST is being cast. */
1610 finish_compound_literal (tree type
, tree initializer_list
)
1612 tree compound_literal
;
1614 /* Build a CONSTRUCTOR for the INITIALIZER_LIST. */
1615 compound_literal
= build_constructor (NULL_TREE
, initializer_list
);
1616 /* Mark it as a compound-literal. */
1617 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
1618 if (processing_template_decl
)
1619 TREE_TYPE (compound_literal
) = type
;
1622 /* Check the initialization. */
1623 compound_literal
= digest_init (type
, compound_literal
, NULL
);
1624 /* If the TYPE was an array type with an unknown bound, then we can
1625 figure out the dimension now. For example, something like:
1629 implies that the array has two elements. */
1630 if (TREE_CODE (type
) == ARRAY_TYPE
&& !COMPLETE_TYPE_P (type
))
1631 complete_array_type (type
, compound_literal
, 1);
1634 return compound_literal
;
1637 /* Return the declaration for the function-name variable indicated by
1641 finish_fname (tree id
)
1645 decl
= fname_decl (C_RID_CODE (id
), id
);
1646 if (processing_template_decl
)
1647 decl
= build_min_nt (LOOKUP_EXPR
, DECL_NAME (decl
));
1651 /* Begin a function definition declared with DECL_SPECS, ATTRIBUTES,
1652 and DECLARATOR. Returns nonzero if the function-declaration is
1656 begin_function_definition (tree decl_specs
, tree attributes
, tree declarator
)
1658 if (!start_function (decl_specs
, declarator
, attributes
, SF_DEFAULT
))
1661 /* The things we're about to see are not directly qualified by any
1662 template headers we've seen thus far. */
1663 reset_specialization ();
1668 /* Finish a translation unit. */
1671 finish_translation_unit (void)
1673 /* In case there were missing closebraces,
1674 get us back to the global binding level. */
1676 while (current_namespace
!= global_namespace
)
1679 /* Do file scope __FUNCTION__ et al. */
1680 finish_fname_decls ();
1683 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1684 Returns the parameter. */
1687 finish_template_type_parm (tree aggr
, tree identifier
)
1689 if (aggr
!= class_type_node
)
1691 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1692 aggr
= class_type_node
;
1695 return build_tree_list (aggr
, identifier
);
1698 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1699 Returns the parameter. */
1702 finish_template_template_parm (tree aggr
, tree identifier
)
1704 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1705 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1706 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1707 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1708 DECL_ARTIFICIAL (decl
) = 1;
1709 end_template_decl ();
1711 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl
), 20010110);
1713 return finish_template_type_parm (aggr
, tmpl
);
1716 /* ARGUMENT is the default-argument value for a template template
1717 parameter. If ARGUMENT is invalid, issue error messages and return
1718 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
1721 check_template_template_default_arg (tree argument
)
1723 if (TREE_CODE (argument
) != TEMPLATE_DECL
1724 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
1725 && TREE_CODE (argument
) != TYPE_DECL
1726 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
1728 error ("invalid default template argument");
1729 return error_mark_node
;
1735 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1736 nonzero, the parameter list was terminated by a `...'. */
1739 finish_parmlist (tree parms
, int ellipsis
)
1743 /* We mark the PARMS as a parmlist so that declarator processing can
1744 disambiguate certain constructs. */
1745 TREE_PARMLIST (parms
) = 1;
1746 /* We do not append void_list_node here, but leave it to grokparms
1748 PARMLIST_ELLIPSIS_P (parms
) = ellipsis
;
1753 /* Begin a class definition, as indicated by T. */
1756 begin_class_definition (tree t
)
1758 if (t
== error_mark_node
)
1759 return error_mark_node
;
1761 if (processing_template_parmlist
)
1763 error ("definition of `%#T' inside template parameter list", t
);
1764 return error_mark_node
;
1766 /* A non-implicit typename comes from code like:
1768 template <typename T> struct A {
1769 template <typename U> struct A<T>::B ...
1771 This is erroneous. */
1772 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
1774 error ("invalid definition of qualified type `%T'", t
);
1775 t
= error_mark_node
;
1778 if (t
== error_mark_node
|| ! IS_AGGR_TYPE (t
))
1780 t
= make_aggr_type (RECORD_TYPE
);
1781 pushtag (make_anon_name (), t
, 0);
1784 /* If this type was already complete, and we see another definition,
1786 if (COMPLETE_TYPE_P (t
))
1788 error ("redefinition of `%#T'", t
);
1789 cp_error_at ("previous definition of `%#T'", t
);
1790 return error_mark_node
;
1793 /* Update the location of the decl. */
1794 DECL_SOURCE_LOCATION (TYPE_NAME (t
)) = input_location
;
1796 if (TYPE_BEING_DEFINED (t
))
1798 t
= make_aggr_type (TREE_CODE (t
));
1799 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1801 maybe_process_partial_specialization (t
);
1802 pushclass (t
, true);
1803 TYPE_BEING_DEFINED (t
) = 1;
1804 TYPE_PACKED (t
) = flag_pack_struct
;
1805 /* Reset the interface data, at the earliest possible
1806 moment, as it might have been set via a class foo;
1808 if (! TYPE_ANONYMOUS_P (t
))
1810 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1811 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1812 (t
, interface_unknown
);
1814 reset_specialization();
1816 /* Make a declaration for this class in its own scope. */
1817 build_self_reference ();
1822 /* Finish the member declaration given by DECL. */
1825 finish_member_declaration (tree decl
)
1827 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1830 if (decl
== void_type_node
)
1831 /* The COMPONENT was a friend, not a member, and so there's
1832 nothing for us to do. */
1835 /* We should see only one DECL at a time. */
1836 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1838 /* Set up access control for DECL. */
1840 = (current_access_specifier
== access_private_node
);
1841 TREE_PROTECTED (decl
)
1842 = (current_access_specifier
== access_protected_node
);
1843 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1845 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
1846 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
1849 /* Mark the DECL as a member of the current class. */
1850 DECL_CONTEXT (decl
) = current_class_type
;
1854 A C language linkage is ignored for the names of class members
1855 and the member function type of class member functions. */
1856 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
1857 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
1859 /* Put functions on the TYPE_METHODS list and everything else on the
1860 TYPE_FIELDS list. Note that these are built up in reverse order.
1861 We reverse them (to obtain declaration order) in finish_struct. */
1862 if (TREE_CODE (decl
) == FUNCTION_DECL
1863 || DECL_FUNCTION_TEMPLATE_P (decl
))
1865 /* We also need to add this function to the
1866 CLASSTYPE_METHOD_VEC. */
1867 add_method (current_class_type
, decl
, /*error_p=*/0);
1869 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1870 TYPE_METHODS (current_class_type
) = decl
;
1872 maybe_add_class_template_decl_list (current_class_type
, decl
,
1875 /* Enter the DECL into the scope of the class. */
1876 else if (TREE_CODE (decl
) == USING_DECL
|| pushdecl_class_level (decl
))
1878 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1879 go at the beginning. The reason is that lookup_field_1
1880 searches the list in order, and we want a field name to
1881 override a type name so that the "struct stat hack" will
1882 work. In particular:
1884 struct S { enum E { }; int E } s;
1887 is valid. In addition, the FIELD_DECLs must be maintained in
1888 declaration order so that class layout works as expected.
1889 However, we don't need that order until class layout, so we
1890 save a little time by putting FIELD_DECLs on in reverse order
1891 here, and then reversing them in finish_struct_1. (We could
1892 also keep a pointer to the correct insertion points in the
1895 if (TREE_CODE (decl
) == TYPE_DECL
)
1896 TYPE_FIELDS (current_class_type
)
1897 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1900 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1901 TYPE_FIELDS (current_class_type
) = decl
;
1904 maybe_add_class_template_decl_list (current_class_type
, decl
,
1909 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1910 the definition is immediately followed by a semicolon. Returns the
1914 finish_class_definition (tree t
, tree attributes
, int semi
, int pop_scope_p
)
1916 if (t
== error_mark_node
)
1917 return error_mark_node
;
1919 /* finish_struct nukes this anyway; if finish_exception does too,
1922 note_got_semicolon (t
);
1924 /* If we got any attributes in class_head, xref_tag will stick them in
1925 TREE_TYPE of the type. Grab them now. */
1926 attributes
= chainon (TYPE_ATTRIBUTES (t
), attributes
);
1927 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
1929 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1933 t
= finish_struct (t
, attributes
);
1935 note_got_semicolon (t
);
1939 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
1944 /* Finish processing the declaration of a member class template
1945 TYPES whose template parameters are given by PARMS. */
1948 finish_member_class_template (tree types
)
1952 /* If there are declared, but undefined, partial specializations
1953 mixed in with the typespecs they will not yet have passed through
1954 maybe_process_partial_specialization, so we do that here. */
1955 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
1956 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
1957 maybe_process_partial_specialization (TREE_VALUE (t
));
1959 note_list_got_semicolon (types
);
1960 grok_x_components (types
);
1961 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
1962 /* The component was in fact a friend declaration. We avoid
1963 finish_member_template_decl performing certain checks by
1967 finish_member_template_decl (types
);
1969 /* As with other component type declarations, we do
1970 not store the new DECL on the list of
1975 /* Finish processing a complete template declaration. The PARMS are
1976 the template parameters. */
1979 finish_template_decl (tree parms
)
1982 end_template_decl ();
1984 end_specialization ();
1987 /* Finish processing a template-id (which names a type) of the form
1988 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1989 template-id. If ENTERING_SCOPE is nonzero we are about to enter
1990 the scope of template-id indicated. */
1993 finish_template_type (tree name
, tree args
, int entering_scope
)
1997 decl
= lookup_template_class (name
, args
,
1998 NULL_TREE
, NULL_TREE
,
1999 entering_scope
, /*complain=*/1);
2000 if (decl
!= error_mark_node
)
2001 decl
= TYPE_STUB_DECL (decl
);
2006 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2007 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2008 BASE_CLASS, or NULL_TREE if an error occurred. The
2009 ACCESS_SPECIFIER is one of
2010 access_{default,public,protected_private}[_virtual]_node.*/
2013 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
2017 if (base
== error_mark_node
)
2019 error ("invalid base-class specification");
2022 else if (! is_aggr_type (base
, 1))
2026 if (cp_type_quals (base
) != 0)
2028 error ("base class `%T' has cv qualifiers", base
);
2029 base
= TYPE_MAIN_VARIANT (base
);
2031 result
= build_tree_list (access
, base
);
2032 TREE_VIA_VIRTUAL (result
) = virtual_p
;
2038 /* Called when multiple declarators are processed. If that is not
2039 premitted in this context, an error is issued. */
2042 check_multiple_declarators (void)
2046 In a template-declaration, explicit specialization, or explicit
2047 instantiation the init-declarator-list in the declaration shall
2048 contain at most one declarator.
2050 We don't just use PROCESSING_TEMPLATE_DECL for the first
2051 condition since that would disallow the perfectly valid code,
2052 like `template <class T> struct S { int i, j; };'. */
2053 if (at_function_scope_p ())
2054 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2057 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2058 || processing_explicit_instantiation
2059 || processing_specialization
)
2060 error ("multiple declarators in template declaration");
2063 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
2064 use as a type-specifier. */
2067 finish_typeof (tree expr
)
2071 if (type_dependent_expression_p (expr
))
2073 type
= make_aggr_type (TYPEOF_TYPE
);
2074 TYPE_FIELDS (type
) = expr
;
2079 type
= TREE_TYPE (expr
);
2081 if (!type
|| type
== unknown_type_node
)
2083 error ("type of `%E' is unknown", expr
);
2084 return error_mark_node
;
2090 /* Compute the value of the `sizeof' operator. */
2093 finish_sizeof (tree t
)
2095 return TYPE_P (t
) ? cxx_sizeof (t
) : expr_sizeof (t
);
2098 /* Implement the __alignof keyword: Return the minimum required
2099 alignment of T, measured in bytes. */
2102 finish_alignof (tree t
)
2104 if (processing_template_decl
)
2105 return build_min (ALIGNOF_EXPR
, size_type_node
, t
);
2107 return TYPE_P (t
) ? cxx_alignof (t
) : c_alignof_expr (t
);
2110 /* Generate RTL for the statement T, and its substatements, and any
2111 other statements at its nesting level. */
2114 cp_expand_stmt (tree t
)
2116 switch (TREE_CODE (t
))
2119 genrtl_try_block (t
);
2123 genrtl_eh_spec_block (t
);
2139 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2140 will equivalent CALL_EXPRs. */
2143 simplify_aggr_init_exprs_r (tree
* tp
,
2144 int* walk_subtrees ATTRIBUTE_UNUSED
,
2145 void* data ATTRIBUTE_UNUSED
)
2147 tree aggr_init_expr
;
2153 enum style_t
{ ctor
, arg
, pcc
} style
;
2155 aggr_init_expr
= *tp
;
2156 /* We don't need to walk into types; there's nothing in a type that
2157 needs simplification. (And, furthermore, there are places we
2158 actively don't want to go. For example, we don't want to wander
2159 into the default arguments for a FUNCTION_DECL that appears in a
2161 if (TYPE_P (aggr_init_expr
))
2166 /* Only AGGR_INIT_EXPRs are interesting. */
2167 else if (TREE_CODE (aggr_init_expr
) != AGGR_INIT_EXPR
)
2170 /* Form an appropriate CALL_EXPR. */
2171 fn
= TREE_OPERAND (aggr_init_expr
, 0);
2172 args
= TREE_OPERAND (aggr_init_expr
, 1);
2173 slot
= TREE_OPERAND (aggr_init_expr
, 2);
2174 type
= TREE_TYPE (aggr_init_expr
);
2176 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
2178 #ifdef PCC_STATIC_STRUCT_RETURN
2182 else if (TREE_ADDRESSABLE (type
))
2185 /* We shouldn't build an AGGR_INIT_EXPR if we don't need any special
2186 handling. See build_cplus_new. */
2189 if (style
== ctor
|| style
== arg
)
2191 /* Pass the address of the slot. If this is a constructor, we
2192 replace the first argument; otherwise, we tack on a new one. */
2194 args
= TREE_CHAIN (args
);
2196 cxx_mark_addressable (slot
);
2197 args
= tree_cons (NULL_TREE
,
2199 build_pointer_type (TREE_TYPE (slot
)),
2204 call_expr
= build (CALL_EXPR
,
2205 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
2206 fn
, args
, NULL_TREE
);
2207 TREE_SIDE_EFFECTS (call_expr
) = 1;
2210 /* Tell the backend that we've added our return slot to the argument
2212 CALL_EXPR_HAS_RETURN_SLOT_ADDR (call_expr
) = 1;
2213 else if (style
== pcc
)
2215 /* If we're using the non-reentrant PCC calling convention, then we
2216 need to copy the returned value out of the static buffer into the
2218 push_deferring_access_checks (dk_no_check
);
2219 call_expr
= build_aggr_init (slot
, call_expr
,
2220 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
);
2221 pop_deferring_access_checks ();
2224 /* We want to use the value of the initialized location as the
2226 call_expr
= build (COMPOUND_EXPR
, type
,
2229 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2230 TREE_CHAIN (call_expr
) = TREE_CHAIN (aggr_init_expr
);
2233 /* Keep iterating. */
2237 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2240 emit_associated_thunks (tree fn
)
2242 /* When we use vcall offsets, we emit thunks with the virtual
2243 functions to which they thunk. The whole point of vcall offsets
2244 is so that you can know statically the entire set of thunks that
2245 will ever be needed for a given virtual function, thereby
2246 enabling you to output all the thunks with the function itself. */
2247 if (DECL_VIRTUAL_P (fn
))
2251 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= TREE_CHAIN (thunk
))
2253 use_thunk (thunk
, /*emit_p=*/1);
2254 if (DECL_RESULT_THUNK_P (thunk
))
2258 for (probe
= DECL_THUNKS (thunk
);
2259 probe
; probe
= TREE_CHAIN (probe
))
2260 use_thunk (probe
, /*emit_p=*/1);
2266 /* Generate RTL for FN. */
2269 expand_body (tree fn
)
2271 location_t saved_loc
;
2272 tree saved_function
;
2274 if (flag_unit_at_a_time
&& !cgraph_global_info_ready
)
2277 /* Compute the appropriate object-file linkage for inline
2279 if (DECL_DECLARED_INLINE_P (fn
))
2280 import_export_decl (fn
);
2282 /* If FN is external, then there's no point in generating RTL for
2283 it. This situation can arise with an inline function under
2284 `-fexternal-templates'; we instantiate the function, even though
2285 we're not planning on emitting it, in case we get a chance to
2287 if (DECL_EXTERNAL (fn
))
2290 /* Save the current file name and line number. When we expand the
2291 body of the function, we'll set INPUT_LOCATION so that
2292 error-messages come out in the right places. */
2293 saved_loc
= input_location
;
2294 saved_function
= current_function_decl
;
2295 input_location
= DECL_SOURCE_LOCATION (fn
);
2296 current_function_decl
= fn
;
2298 timevar_push (TV_INTEGRATION
);
2300 /* Optimize the body of the function before expanding it. */
2301 optimize_function (fn
);
2303 timevar_pop (TV_INTEGRATION
);
2304 timevar_push (TV_EXPAND
);
2306 genrtl_start_function (fn
);
2307 current_function_is_thunk
= DECL_THUNK_P (fn
);
2309 /* Expand the body. */
2310 expand_stmt (DECL_SAVED_TREE (fn
));
2312 /* Statements should always be full-expressions at the outermost set
2313 of curly braces for a function. */
2314 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2316 /* The outermost statement for a function contains the line number
2317 recorded when we finished processing the function. */
2318 input_line
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2320 /* Generate code for the function. */
2321 genrtl_finish_function (fn
);
2323 /* If possible, obliterate the body of the function so that it can
2324 be garbage collected. */
2325 if (dump_enabled_p (TDI_all
))
2326 /* Keep the body; we're going to dump it. */
2328 else if (DECL_INLINE (fn
) && flag_inline_trees
)
2329 /* We might need the body of this function so that we can expand
2330 it inline somewhere else. */
2333 /* We don't need the body; blow it away. */
2334 DECL_SAVED_TREE (fn
) = NULL_TREE
;
2336 /* And restore the current source position. */
2337 current_function_decl
= saved_function
;
2338 input_location
= saved_loc
;
2339 extract_interface_info ();
2341 timevar_pop (TV_EXPAND
);
2343 /* Emit any thunks that should be emitted at the same time as FN. */
2344 emit_associated_thunks (fn
);
2347 /* Generate RTL for FN. */
2350 expand_or_defer_fn (fn
)
2353 /* When the parser calls us after finishing the body of a template
2354 function, we don't really want to expand the body. When we're
2355 processing an in-class definition of an inline function,
2356 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2357 to look at the function itself. */
2358 if (processing_template_decl
2359 || (DECL_LANG_SPECIFIC (fn
)
2360 && DECL_TEMPLATE_INFO (fn
)
2361 && uses_template_parms (DECL_TI_ARGS (fn
))))
2363 /* Normally, collection only occurs in rest_of_compilation. So,
2364 if we don't collect here, we never collect junk generated
2365 during the processing of templates until we hit a
2366 non-template function. */
2371 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2372 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn
),
2373 simplify_aggr_init_exprs_r
,
2376 /* If this is a constructor or destructor body, we have to clone
2378 if (maybe_clone_body (fn
))
2380 /* We don't want to process FN again, so pretend we've written
2381 it out, even though we haven't. */
2382 TREE_ASM_WRITTEN (fn
) = 1;
2386 /* There's no reason to do any of the work here if we're only doing
2387 semantic analysis; this code just generates RTL. */
2388 if (flag_syntax_only
)
2391 if (flag_unit_at_a_time
&& cgraph_global_info_ready
)
2394 if (flag_unit_at_a_time
&& !cgraph_global_info_ready
)
2398 /* Compute the appropriate object-file linkage for inline
2400 if (DECL_DECLARED_INLINE_P (fn
))
2401 import_export_decl (fn
);
2402 cgraph_finalize_function (fn
, DECL_SAVED_TREE (fn
));
2406 if (!DECL_EXTERNAL (fn
))
2408 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2409 DECL_EXTERNAL (fn
) = 1;
2411 /* Remember this function. In finish_file we'll decide if
2412 we actually need to write this function out. */
2414 /* Let the back-end know that this function exists. */
2415 (*debug_hooks
->deferred_inline_function
) (fn
);
2421 /* If possible, avoid generating RTL for this function. Instead,
2422 just record it as an inline function, and wait until end-of-file
2423 to decide whether to write it out or not. */
2424 if (/* We have to generate RTL if it's not an inline function. */
2425 (DECL_INLINE (fn
) || DECL_COMDAT (fn
))
2426 /* Or if we have to emit code for inline functions anyhow. */
2427 && !flag_keep_inline_functions
2428 /* Or if we actually have a reference to the function. */
2429 && !DECL_NEEDED_P (fn
))
2431 /* Set DECL_EXTERNAL so that assemble_external will be called as
2432 necessary. We'll clear it again in finish_file. */
2433 if (!DECL_EXTERNAL (fn
))
2435 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2436 DECL_EXTERNAL (fn
) = 1;
2438 /* Remember this function. In finish_file we'll decide if
2439 we actually need to write this function out. */
2441 /* Let the back-end know that this function exists. */
2442 (*debug_hooks
->deferred_inline_function
) (fn
);
2449 /* Helper function for walk_tree, used by finish_function to override all
2450 the RETURN_STMTs and pertinent CLEANUP_STMTs for the named return
2451 value optimization. */
2454 nullify_returns_r (tree
* tp
, int* walk_subtrees
, void* data
)
2456 tree nrv
= (tree
) data
;
2458 /* No need to walk into types. There wouldn't be any need to walk into
2459 non-statements, except that we have to consider STMT_EXPRs. */
2462 else if (TREE_CODE (*tp
) == RETURN_STMT
)
2463 RETURN_STMT_EXPR (*tp
) = NULL_TREE
;
2464 else if (TREE_CODE (*tp
) == CLEANUP_STMT
2465 && CLEANUP_DECL (*tp
) == nrv
)
2466 CLEANUP_EH_ONLY (*tp
) = 1;
2468 /* Keep iterating. */
2472 /* Start generating the RTL for FN. */
2475 genrtl_start_function (tree fn
)
2477 /* Tell everybody what function we're processing. */
2478 current_function_decl
= fn
;
2479 /* Get the RTL machinery going for this function. */
2480 init_function_start (fn
);
2481 /* Let everybody know that we're expanding this function, not doing
2482 semantic analysis. */
2485 /* Even though we're inside a function body, we still don't want to
2486 call expand_expr to calculate the size of a variable-sized array.
2487 We haven't necessarily assigned RTL to all variables yet, so it's
2488 not safe to try to expand expressions involving them. */
2489 immediate_size_expand
= 0;
2490 cfun
->x_dont_save_pending_sizes_p
= 1;
2492 /* Let the user know we're compiling this function. */
2493 announce_function (fn
);
2495 /* Initialize the per-function data. */
2496 my_friendly_assert (!DECL_PENDING_INLINE_P (fn
), 20000911);
2497 if (DECL_SAVED_FUNCTION_DATA (fn
))
2499 /* If we already parsed this function, and we're just expanding it
2500 now, restore saved state. */
2501 *cp_function_chain
= *DECL_SAVED_FUNCTION_DATA (fn
);
2503 /* This function is being processed in whole-function mode; we
2504 already did semantic analysis. */
2505 cfun
->x_whole_function_mode_p
= 1;
2507 /* If we decided that we didn't want to inline this function,
2508 make sure the back-end knows that. */
2509 if (!current_function_cannot_inline
)
2510 current_function_cannot_inline
= cp_function_chain
->cannot_inline
;
2512 /* We don't need the saved data anymore. Unless this is an inline
2513 function; we need the named return value info for
2514 cp_copy_res_decl_for_inlining. */
2515 if (! DECL_INLINE (fn
))
2516 DECL_SAVED_FUNCTION_DATA (fn
) = NULL
;
2519 /* Keep track of how many functions we're presently expanding. */
2522 /* Create a binding level for the parameters. */
2523 expand_function_start (fn
, /*parms_have_cleanups=*/0);
2524 /* If this function is `main'. */
2525 if (DECL_MAIN_P (fn
))
2526 expand_main_function ();
2528 /* Give our named return value the same RTL as our RESULT_DECL. */
2529 if (current_function_return_value
)
2530 COPY_DECL_RTL (DECL_RESULT (fn
), current_function_return_value
);
2533 /* Finish generating the RTL for FN. */
2536 genrtl_finish_function (tree fn
)
2541 if (write_symbols
!= NO_DEBUG
)
2543 /* Keep this code around in case we later want to control debug info
2544 based on whether a type is "used". (jason 1999-11-11) */
2546 tree ttype
= target_type (fntype
);
2549 if (IS_AGGR_TYPE (ttype
))
2550 /* Let debugger know it should output info for this type. */
2551 note_debug_info_needed (ttype
);
2553 for (parmdecl
= DECL_ARGUMENTS (fndecl
); parmdecl
; parmdecl
= TREE_CHAIN (parmdecl
))
2555 ttype
= target_type (TREE_TYPE (parmdecl
));
2556 if (IS_AGGR_TYPE (ttype
))
2557 /* Let debugger know it should output info for this type. */
2558 note_debug_info_needed (ttype
);
2563 /* Clean house because we will need to reorder insns here. */
2564 do_pending_stack_adjust ();
2566 /* If we have a named return value, we need to force a return so that
2567 the return register is USEd. */
2568 if (DECL_NAME (DECL_RESULT (fn
)))
2569 emit_jump (return_label
);
2571 /* We hard-wired immediate_size_expand to zero in start_function.
2572 Expand_function_end will decrement this variable. So, we set the
2573 variable to one here, so that after the decrement it will remain
2575 immediate_size_expand
= 1;
2577 /* Generate rtl for function exit. */
2578 expand_function_end ();
2580 /* If this is a nested function (like a template instantiation that
2581 we're compiling in the midst of compiling something else), push a
2582 new GC context. That will keep local variables on the stack from
2583 being collected while we're doing the compilation of this
2585 if (function_depth
> 1)
2586 ggc_push_context ();
2588 /* There's no need to defer outputting this function any more; we
2589 know we want to output it. */
2590 DECL_DEFER_OUTPUT (fn
) = 0;
2592 /* Run the optimizers and output the assembler code for this
2594 rest_of_compilation (fn
);
2596 /* Undo the call to ggc_push_context above. */
2597 if (function_depth
> 1)
2601 /* Keep this code around in case we later want to control debug info
2602 based on whether a type is "used". (jason 1999-11-11) */
2604 if (ctype
&& TREE_ASM_WRITTEN (fn
))
2605 note_debug_info_needed (ctype
);
2608 /* If this function is marked with the constructor attribute, add it
2609 to the list of functions to be called along with constructors
2610 from static duration objects. */
2611 if (DECL_STATIC_CONSTRUCTOR (fn
))
2612 static_ctors
= tree_cons (NULL_TREE
, fn
, static_ctors
);
2614 /* If this function is marked with the destructor attribute, add it
2615 to the list of functions to be called along with destructors from
2616 static duration objects. */
2617 if (DECL_STATIC_DESTRUCTOR (fn
))
2618 static_dtors
= tree_cons (NULL_TREE
, fn
, static_dtors
);
2622 /* In C++, we should never be saving RTL for the function. */
2623 my_friendly_assert (!DECL_SAVED_INSNS (fn
), 20010903);
2625 /* Since we don't need the RTL for this function anymore, stop
2626 pointing to it. That's especially important for LABEL_DECLs,
2627 since you can reach all the instructions in the function from the
2628 CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. Walk the
2629 BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and non-static
2631 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn
),
2635 /* Clear out the RTL for the arguments. */
2636 for (t
= DECL_ARGUMENTS (fn
); t
; t
= TREE_CHAIN (t
))
2638 SET_DECL_RTL (t
, NULL_RTX
);
2639 DECL_INCOMING_RTL (t
) = NULL_RTX
;
2642 if (!(flag_inline_trees
&& DECL_INLINE (fn
)))
2643 /* DECL_INITIAL must remain nonzero so we know this was an
2644 actual function definition. */
2645 DECL_INITIAL (fn
) = error_mark_node
;
2647 /* Let the error reporting routines know that we're outside a
2648 function. For a nested function, this value is used in
2649 pop_cp_function_context and then reset via pop_function_context. */
2650 current_function_decl
= NULL_TREE
;
2653 /* Clear out the DECL_RTL for the non-static variables in BLOCK and
2657 clear_decl_rtl (tree
* tp
,
2658 int* walk_subtrees ATTRIBUTE_UNUSED
,
2659 void* data ATTRIBUTE_UNUSED
)
2661 if (nonstatic_local_decl_p (*tp
))
2662 SET_DECL_RTL (*tp
, NULL_RTX
);
2667 /* Perform initialization related to this module. */
2670 init_cp_semantics (void)
2672 lang_expand_stmt
= cp_expand_stmt
;
2675 #include "gt-cp-semantics.h"