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 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)
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
40 /* There routines provide a modular interface to perform many parsing
41 operations. They may therefore be used during actual parsing, or
42 during template instantiation, which may be regarded as a
43 degenerate form of parsing. Since the current g++ parser is
44 lacking in several respects, and will be reimplemented, we are
45 attempting to move most code that is not directly related to
46 parsing into this file; that will make implementing the new parser
47 much easier since it will be able to make use of these routines. */
49 static tree maybe_convert_cond
PARAMS ((tree
));
50 static tree simplify_aggr_init_exprs_r
PARAMS ((tree
*, int *, void *));
51 static void deferred_type_access_control
PARAMS ((void));
52 static void emit_associated_thunks
PARAMS ((tree
));
53 static void genrtl_try_block
PARAMS ((tree
));
54 static void genrtl_handler
PARAMS ((tree
));
55 static void genrtl_catch_block
PARAMS ((tree
));
56 static void genrtl_ctor_stmt
PARAMS ((tree
));
57 static void genrtl_subobject
PARAMS ((tree
));
58 static void genrtl_named_return_value
PARAMS ((void));
59 static void cp_expand_stmt
PARAMS ((tree
));
60 static void genrtl_start_function
PARAMS ((tree
));
61 static void genrtl_finish_function
PARAMS ((tree
));
63 /* Finish processing the COND, the SUBSTMT condition for STMT. */
65 #define FINISH_COND(cond, stmt, substmt) \
67 if (last_tree != stmt) \
69 RECHAIN_STMTS (stmt, substmt); \
70 if (!processing_template_decl) \
72 cond = build_tree_list (substmt, cond); \
80 /* Returns non-zero if the current statement is a full expression,
81 i.e. temporaries created during that statement should be destroyed
82 at the end of the statement. */
85 stmts_are_full_exprs_p ()
87 return current_stmt_tree ()->stmts_are_full_exprs_p
;
90 /* Returns the stmt_tree (if any) to which statements are currently
91 being added. If there is no active statement-tree, NULL is
98 ? &cfun
->language
->x_stmt_tree
99 : &scope_chain
->x_stmt_tree
);
102 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
103 flag for this because "A union for which objects or pointers are
104 declared is not an anonymous union" [class.union]. */
107 anon_aggr_type_p (node
)
110 return (CLASS_TYPE_P (node
) && TYPE_LANG_SPECIFIC(node
)->anon_aggr
);
113 /* Finish a scope. */
118 tree block
= NULL_TREE
;
120 if (stmts_are_full_exprs_p ())
122 tree scope_stmts
= NULL_TREE
;
124 if (!processing_template_decl
)
125 scope_stmts
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
127 block
= poplevel (kept_level_p (), 1, 0);
128 if (block
&& !processing_template_decl
)
130 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts
)) = block
;
131 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts
)) = block
;
138 /* Begin a new scope. */
143 if (stmts_are_full_exprs_p ())
146 if (!processing_template_decl
)
147 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
151 /* Finish a goto-statement. */
154 finish_goto_stmt (destination
)
157 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
158 destination
= lookup_label (destination
);
160 /* We warn about unused labels with -Wunused. That means we have to
161 mark the used labels as used. */
162 if (TREE_CODE (destination
) == LABEL_DECL
)
163 TREE_USED (destination
) = 1;
165 if (TREE_CODE (destination
) != LABEL_DECL
)
166 /* We don't inline calls to functions with computed gotos.
167 Those functions are typically up to some funny business,
168 and may be depending on the labels being at particular
169 addresses, or some such. */
170 DECL_UNINLINABLE (current_function_decl
) = 1;
172 check_goto (destination
);
174 return add_stmt (build_stmt (GOTO_STMT
, destination
));
177 /* COND is the condition-expression for an if, while, etc.,
178 statement. Convert it to a boolean value, if appropriate. */
181 maybe_convert_cond (cond
)
184 /* Empty conditions remain empty. */
188 /* Wait until we instantiate templates before doing conversion. */
189 if (processing_template_decl
)
192 /* Do the conversion. */
193 cond
= convert_from_reference (cond
);
194 return condition_conversion (cond
);
197 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
200 finish_expr_stmt (expr
)
205 if (expr
!= NULL_TREE
)
207 if (!processing_template_decl
208 && !(stmts_are_full_exprs_p ())
209 && ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
211 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
212 expr
= default_conversion (expr
);
214 if (stmts_are_full_exprs_p ())
215 expr
= convert_to_void (expr
, "statement");
217 r
= add_stmt (build_stmt (EXPR_STMT
, expr
));
222 /* This was an expression-statement, so we save the type of the
224 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
230 /* Begin an if-statement. Returns a newly created IF_STMT if
238 r
= build_stmt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
243 /* Process the COND of an if-statement, which may be given by
247 finish_if_stmt_cond (cond
, if_stmt
)
251 cond
= maybe_convert_cond (cond
);
252 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
255 /* Finish the then-clause of an if-statement, which may be given by
259 finish_then_clause (if_stmt
)
262 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
267 /* Begin the else-clause of an if-statement. */
274 /* Finish the else-clause of an if-statement, which may be given by
278 finish_else_clause (if_stmt
)
281 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
284 /* Finsh an if-statement. */
296 /* If COND wasn't a declaration, clear out the
297 block we made for it and start a new one here so the
298 optimization in expand_end_loop will work. */
299 if (getdecls () == NULL_TREE
)
306 /* Begin a while-statement. Returns a newly created WHILE_STMT if
313 r
= build_stmt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
319 /* Process the COND of a while-statement, which may be given by
323 finish_while_stmt_cond (cond
, while_stmt
)
327 cond
= maybe_convert_cond (cond
);
328 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
332 /* Finish a while-statement, which may be given by WHILE_STMT. */
335 finish_while_stmt (while_stmt
)
339 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
343 /* Begin a do-statement. Returns a newly created DO_STMT if
349 tree r
= build_stmt (DO_STMT
, NULL_TREE
, NULL_TREE
);
354 /* Finish the body of a do-statement, which may be given by DO_STMT. */
357 finish_do_body (do_stmt
)
360 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
363 /* Finish a do-statement, which may be given by DO_STMT, and whose
364 COND is as indicated. */
367 finish_do_stmt (cond
, do_stmt
)
371 cond
= maybe_convert_cond (cond
);
372 DO_COND (do_stmt
) = cond
;
376 /* Finish a return-statement. The EXPRESSION returned, if any, is as
380 finish_return_stmt (expr
)
385 if (!processing_template_decl
)
386 expr
= check_return_expr (expr
);
387 if (!processing_template_decl
)
389 if (DECL_CONSTRUCTOR_P (current_function_decl
) && ctor_label
)
391 /* Even returns without a value in a constructor must return
392 `this'. We accomplish this by sending all returns in a
393 constructor to the CTOR_LABEL; finish_function emits code to
394 return a value there. When we finally generate the real
395 return statement, CTOR_LABEL is no longer set, and we fall
396 through into the normal return-processing code below. */
397 return finish_goto_stmt (ctor_label
);
399 else if (DECL_DESTRUCTOR_P (current_function_decl
))
401 /* Similarly, all destructors must run destructors for
402 base-classes before returning. So, all returns in a
403 destructor get sent to the DTOR_LABEL; finsh_function emits
404 code to return a value there. */
405 return finish_goto_stmt (dtor_label
);
408 r
= add_stmt (build_stmt (RETURN_STMT
, expr
));
414 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
421 r
= build_stmt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
422 NULL_TREE
, NULL_TREE
);
423 NEW_FOR_SCOPE_P (r
) = flag_new_for_scope
> 0;
425 if (NEW_FOR_SCOPE_P (r
))
428 note_level_for_for ();
434 /* Finish the for-init-statement of a for-statement, which may be
435 given by FOR_STMT. */
438 finish_for_init_stmt (for_stmt
)
441 if (last_tree
!= for_stmt
)
442 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
446 /* Finish the COND of a for-statement, which may be given by
450 finish_for_cond (cond
, for_stmt
)
454 cond
= maybe_convert_cond (cond
);
455 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
459 /* Finish the increment-EXPRESSION in a for-statement, which may be
460 given by FOR_STMT. */
463 finish_for_expr (expr
, for_stmt
)
467 FOR_EXPR (for_stmt
) = expr
;
470 /* Finish the body of a for-statement, which may be given by
471 FOR_STMT. The increment-EXPR for the loop must be
475 finish_for_stmt (for_stmt
)
478 /* Pop the scope for the body of the loop. */
480 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
481 if (NEW_FOR_SCOPE_P (for_stmt
))
486 /* Finish a break-statement. */
491 return add_stmt (build_break_stmt ());
494 /* Finish a continue-statement. */
497 finish_continue_stmt ()
499 return add_stmt (build_continue_stmt ());
502 /* Begin a switch-statement. Returns a new SWITCH_STMT if
509 r
= build_stmt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
515 /* Finish the cond of a switch-statement. */
518 finish_switch_cond (cond
, switch_stmt
)
522 if (!processing_template_decl
)
527 /* Convert the condition to an integer or enumeration type. */
528 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, 1);
529 if (cond
== NULL_TREE
)
531 error ("switch quantity not an integer");
532 cond
= error_mark_node
;
534 if (cond
!= error_mark_node
)
536 cond
= default_conversion (cond
);
537 cond
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (cond
), cond
));
540 type
= TREE_TYPE (cond
);
541 index
= get_unwidened (cond
, NULL_TREE
);
542 /* We can't strip a conversion from a signed type to an unsigned,
543 because if we did, int_fits_type_p would do the wrong thing
544 when checking case values for being in range,
545 and it's too hard to do the right thing. */
546 if (TREE_UNSIGNED (TREE_TYPE (cond
))
547 == TREE_UNSIGNED (TREE_TYPE (index
)))
550 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
551 push_switch (switch_stmt
);
554 /* Finish the body of a switch-statement, which may be given by
555 SWITCH_STMT. The COND to switch on is indicated. */
558 finish_switch_stmt (switch_stmt
)
561 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
567 /* Generate the RTL for T, which is a TRY_BLOCK. */
575 expand_eh_region_start ();
576 expand_stmt (TRY_STMTS (t
));
577 expand_eh_region_end (protect_with_terminate (TRY_HANDLERS (t
)));
581 if (!FN_TRY_BLOCK_P (t
))
582 emit_line_note (input_filename
, lineno
);
583 expand_start_try_stmts ();
585 expand_stmt (TRY_STMTS (t
));
587 if (FN_TRY_BLOCK_P (t
))
589 end_protect_partials ();
590 expand_start_all_catch ();
591 in_function_try_handler
= 1;
592 expand_stmt (TRY_HANDLERS (t
));
593 in_function_try_handler
= 0;
594 expand_end_all_catch ();
598 expand_start_all_catch ();
599 expand_stmt (TRY_HANDLERS (t
));
600 expand_end_all_catch ();
605 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
611 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
616 /* Likewise, for a function-try-block. */
619 begin_function_try_block ()
621 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
622 FN_TRY_BLOCK_P (r
) = 1;
627 /* Finish a try-block, which may be given by TRY_BLOCK. */
630 finish_try_block (try_block
)
633 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
636 /* Finish the body of a cleanup try-block, which may be given by
640 finish_cleanup_try_block (try_block
)
643 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
646 /* Finish an implicitly generated try-block, with a cleanup is given
650 finish_cleanup (cleanup
, try_block
)
654 TRY_HANDLERS (try_block
) = cleanup
;
655 CLEANUP_P (try_block
) = 1;
658 /* Likewise, for a function-try-block. */
661 finish_function_try_block (try_block
)
664 if (TREE_CHAIN (try_block
)
665 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
667 /* Chain the compound statement after the CTOR_INITIALIZER. */
668 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
669 /* And make the CTOR_INITIALIZER the body of the try-block. */
670 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
673 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
674 in_function_try_handler
= 1;
677 /* Finish a handler-sequence for a try-block, which may be given by
681 finish_handler_sequence (try_block
)
684 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
685 check_handlers (TRY_HANDLERS (try_block
));
688 /* Likewise, for a function-try-block. */
691 finish_function_handler_sequence (try_block
)
694 in_function_try_handler
= 0;
695 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
696 check_handlers (TRY_HANDLERS (try_block
));
699 /* Generate the RTL for T, which is a HANDLER. */
705 genrtl_do_pushlevel ();
706 expand_stmt (HANDLER_BODY (t
));
707 if (!processing_template_decl
)
709 /* Fall to outside the try statement when done executing
710 handler and we fall off end of handler. This is jump
711 Lresume in the documentation. */
712 expand_goto (top_label_entry (&caught_return_label_stack
));
713 end_catch_handler ();
717 /* Begin a handler. Returns a HANDLER if appropriate. */
723 r
= build_stmt (HANDLER
, NULL_TREE
, NULL_TREE
);
729 /* Finish the handler-parameters for a handler, which may be given by
730 HANDLER. DECL is the declaration for the catch parameter, or NULL
731 if this is a `catch (...)' clause. */
734 finish_handler_parms (decl
, handler
)
738 tree blocks
= NULL_TREE
;
740 if (processing_template_decl
)
744 decl
= pushdecl (decl
);
745 decl
= push_template_decl (decl
);
746 add_decl_stmt (decl
);
747 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
751 blocks
= expand_start_catch_block (decl
);
754 TREE_TYPE (handler
) = TREE_TYPE (decl
);
759 /* Generate the RTL for a CATCH_BLOCK. */
762 genrtl_catch_block (type
)
765 start_catch_handler (type
);
768 /* Note the beginning of a handler for TYPE. This function is called
769 at the point to which control should be transferred when an
770 appropriately-typed exception is thrown. */
773 begin_catch_block (type
)
776 add_stmt (build (START_CATCH_STMT
, type
));
779 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
780 the return value from the matching call to finish_handler_parms. */
783 finish_handler (blocks
, handler
)
787 if (!processing_template_decl
)
788 expand_end_catch_block (blocks
);
790 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
793 /* Generate the RTL for T, which is a CTOR_STMT. */
799 if (CTOR_BEGIN_P (t
))
800 begin_protect_partials ();
802 /* After this point, any exceptions will cause the
803 destructor to be executed, so we no longer need to worry
804 about destroying the various subobjects ourselves. */
805 end_protect_partials ();
808 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
809 compound-statement does not define a scope. Returns a new
810 COMPOUND_STMT if appropriate. */
813 begin_compound_stmt (has_no_scope
)
819 r
= build_stmt (COMPOUND_STMT
, NULL_TREE
);
821 if (last_tree
&& TREE_CODE (last_tree
) == TRY_BLOCK
)
826 COMPOUND_STMT_NO_SCOPE (r
) = 1;
828 last_expr_type
= NULL_TREE
;
834 note_level_for_eh ();
837 /* Normally, we try hard to keep the BLOCK for a
838 statement-expression. But, if it's a statement-expression with
839 a scopeless block, there's nothing to keep, and we don't want
840 to accidentally keep a block *inside* the scopeless block. */
843 /* If this is the outermost block of the function, declare the
844 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
846 && !function_name_declared_p
849 function_name_declared_p
= 1;
850 declare_function_name ();
856 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
857 If HAS_NO_SCOPE is non-zero, the compound statement does not define
861 finish_compound_stmt (has_no_scope
, compound_stmt
)
873 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
875 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
876 the precise purpose of that variable is store the type of the
877 last expression statement within the last compound statement, we
878 preserve the value. */
886 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
887 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
891 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
892 input_operands
, clobbers
)
895 tree output_operands
;
902 if (TREE_CHAIN (string
))
903 string
= combine_strings (string
);
905 if (cv_qualifier
!= NULL_TREE
906 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
908 cp_warning ("%s qualifier ignored on asm",
909 IDENTIFIER_POINTER (cv_qualifier
));
910 cv_qualifier
= NULL_TREE
;
913 if (!processing_template_decl
)
914 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
916 tree converted_operand
917 = decay_conversion (TREE_VALUE (t
));
919 /* If the type of the operand hasn't been determined (e.g.,
920 because it involves an overloaded function), then issue an
921 error message. There's no context available to resolve the
923 if (TREE_TYPE (converted_operand
) == unknown_type_node
)
925 cp_error ("type of asm operand `%E' could not be determined",
927 converted_operand
= error_mark_node
;
929 TREE_VALUE (t
) = converted_operand
;
932 r
= build_stmt (ASM_STMT
, cv_qualifier
, string
,
933 output_operands
, input_operands
,
938 /* Finish a label with the indicated NAME. */
941 finish_label_stmt (name
)
944 tree decl
= define_label (input_filename
, lineno
, name
);
945 add_stmt (build_stmt (LABEL_STMT
, decl
));
948 /* Finish a series of declarations for local labels. G++ allows users
949 to declare "local" labels, i.e., labels with scope. This extension
950 is useful when writing code involving statement-expressions. */
953 finish_label_decl (name
)
956 tree decl
= declare_local_label (name
);
957 add_decl_stmt (decl
);
960 /* Generate the RTL for a SUBOBJECT. */
963 genrtl_subobject (cleanup
)
966 add_partial_entry (cleanup
);
969 /* We're in a constructor, and have just constructed a a subobject of
970 *THIS. CLEANUP is code to run if an exception is thrown before the
971 end of the current function is reached. */
974 finish_subobject (cleanup
)
977 tree r
= build_stmt (SUBOBJECT
, cleanup
);
981 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
984 finish_decl_cleanup (decl
, cleanup
)
988 add_stmt (build_stmt (CLEANUP_STMT
, decl
, cleanup
));
991 /* Generate the RTL for a RETURN_INIT. */
994 genrtl_named_return_value ()
996 tree decl
= DECL_RESULT (current_function_decl
);
998 /* If this named return value comes in a register, put it in a
1000 if (DECL_REGISTER (decl
))
1002 /* Note that the mode of the old DECL_RTL may be wider than the
1003 mode of DECL_RESULT, depending on the calling conventions for
1004 the processor. For example, on the Alpha, a 32-bit integer
1005 is returned in a DImode register -- the DECL_RESULT has
1006 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
1007 here, we use the mode the back-end has already assigned for
1008 the return value. */
1009 SET_DECL_RTL (decl
, gen_reg_rtx (GET_MODE (DECL_RTL (decl
))));
1010 if (TREE_ADDRESSABLE (decl
))
1011 put_var_into_stack (decl
);
1014 emit_local_var (decl
);
1017 /* Bind a name and initialization to the return value of
1018 the current function. */
1021 finish_named_return_value (return_id
, init
)
1022 tree return_id
, init
;
1024 tree decl
= DECL_RESULT (current_function_decl
);
1026 /* Give this error as many times as there are occurrences, so that
1027 users can use Emacs compilation buffers to find and fix all such
1030 pedwarn ("ISO C++ does not permit named return values");
1031 cp_deprecated ("the named return value extension");
1033 if (return_id
!= NULL_TREE
)
1035 if (DECL_NAME (decl
) == NULL_TREE
)
1036 DECL_NAME (decl
) = return_id
;
1039 cp_error ("return identifier `%D' already in place", return_id
);
1044 /* Can't let this happen for constructors. */
1045 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1047 error ("can't redefine default return value for constructors");
1051 /* If we have a named return value, put that in our scope as well. */
1052 if (DECL_NAME (decl
) != NULL_TREE
)
1054 /* Let `cp_finish_decl' know that this initializer is ok. */
1055 DECL_INITIAL (decl
) = init
;
1056 if (doing_semantic_analysis_p ())
1058 if (!processing_template_decl
)
1060 cp_finish_decl (decl
, init
, NULL_TREE
, 0);
1061 add_stmt (build_stmt (RETURN_INIT
, NULL_TREE
, NULL_TREE
));
1064 add_stmt (build_stmt (RETURN_INIT
, return_id
, init
));
1067 /* Don't use tree-inlining for functions with named return values.
1068 That doesn't work properly because we don't do any translation of
1069 the RETURN_INITs when they are copied. */
1070 DECL_UNINLINABLE (current_function_decl
) = 1;
1073 /* The INIT_LIST is a list of mem-initializers, in the order they were
1074 written by the user. The TREE_VALUE of each node is a list of
1075 initializers for a particular subobject. The TREE_PURPOSE is a
1076 FIELD_DECL is the initializer is for a non-static data member, and
1077 a class type if the initializer is for a base class. */
1080 finish_mem_initializers (init_list
)
1083 tree member_init_list
;
1084 tree base_init_list
;
1085 tree last_base_warned_about
;
1089 member_init_list
= NULL_TREE
;
1090 base_init_list
= NULL_TREE
;
1091 last_base_warned_about
= NULL_TREE
;
1093 for (init
= init_list
; init
; init
= next
)
1095 next
= TREE_CHAIN (init
);
1096 if (TREE_CODE (TREE_PURPOSE (init
)) == FIELD_DECL
)
1098 TREE_CHAIN (init
) = member_init_list
;
1099 member_init_list
= init
;
1101 /* We're running through the initializers from right to left
1102 as we process them here. So, if we see a data member
1103 initializer after we see a base initializer, that
1104 actually means that the base initializer preceeded the
1105 data member initializer. */
1106 if (warn_reorder
&& last_base_warned_about
!= base_init_list
)
1110 for (base
= base_init_list
;
1111 base
!= last_base_warned_about
;
1112 base
= TREE_CHAIN (base
))
1114 cp_warning ("base initializer for `%T'",
1115 TREE_PURPOSE (base
));
1116 warning (" will be re-ordered to precede member initializations");
1119 last_base_warned_about
= base_init_list
;
1124 TREE_CHAIN (init
) = base_init_list
;
1125 base_init_list
= init
;
1129 setup_vtbl_ptr (member_init_list
, base_init_list
);
1132 /* Cache the value of this class's main virtual function table pointer
1133 in a register variable. This will save one indirection if a
1134 more than one virtual function call is made this function. */
1137 setup_vtbl_ptr (member_init_list
, base_init_list
)
1138 tree member_init_list
;
1139 tree base_init_list
;
1141 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1143 /* If we've already done this, there's no need to do it again. */
1147 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1149 if (processing_template_decl
)
1150 add_stmt (build_min_nt
1152 member_init_list
, base_init_list
));
1157 /* Mark the beginning of the constructor. */
1158 ctor_stmt
= build_stmt (CTOR_STMT
);
1159 CTOR_BEGIN_P (ctor_stmt
) = 1;
1160 add_stmt (ctor_stmt
);
1162 /* And actually initialize the base-classes and members. */
1163 emit_base_init (member_init_list
, base_init_list
);
1166 else if (DECL_DESTRUCTOR_P (current_function_decl
)
1167 && !processing_template_decl
)
1173 /* If the dtor is empty, and we know there is not any possible
1174 way we could use any vtable entries, before they are possibly
1175 set by a base class dtor, we don't have to setup the vtables,
1176 as we know that any base class dtor will set up any vtables
1177 it needs. We avoid MI, because one base class dtor can do a
1178 virtual dispatch to an overridden function that would need to
1179 have a non-related vtable set up, we cannot avoid setting up
1180 vtables in that case. We could change this to see if there
1181 is just one vtable. */
1182 if_stmt
= begin_if_stmt ();
1184 /* If it is not safe to avoid setting up the vtables, then
1185 someone will change the condition to be boolean_true_node.
1186 (Actually, for now, we do not have code to set the condition
1187 appropriately, so we just assume that we always need to
1188 initialize the vtables.) */
1189 finish_if_stmt_cond (boolean_true_node
, if_stmt
);
1190 current_vcalls_possible_p
= &IF_COND (if_stmt
);
1192 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1193 open the block for the if-body. */
1194 saved_cfnd
= function_name_declared_p
;
1195 function_name_declared_p
= 1;
1196 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
1197 function_name_declared_p
= saved_cfnd
;
1199 /* Make all virtual function table pointers in non-virtual base
1200 classes point to CURRENT_CLASS_TYPE's virtual function
1202 initialize_vtbl_ptrs (current_class_ptr
);
1204 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
1205 finish_then_clause (if_stmt
);
1209 /* Always keep the BLOCK node associated with the outermost pair of
1210 curly braces of a function. These are needed for correct
1211 operation of dwarfout.c. */
1212 keep_next_level (1);
1214 /* The virtual function tables are set up now. */
1218 /* Returns the stack of SCOPE_STMTs for the current function. */
1221 current_scope_stmt_stack ()
1223 return &cfun
->language
->x_scope_stmt_stack
;
1226 /* Finish a parenthesized expression EXPR. */
1229 finish_parenthesized_expr (expr
)
1232 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1233 /* This inhibits warnings in truthvalue_conversion. */
1234 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1236 if (TREE_CODE (expr
) == OFFSET_REF
)
1237 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1238 enclosed in parentheses. */
1239 PTRMEM_OK_P (expr
) = 0;
1243 /* Begin a statement-expression. The value returned must be passed to
1244 finish_stmt_expr. */
1249 /* If we're outside a function, we won't have a statement-tree to
1250 work with. But, if we see a statement-expression we need to
1252 if (! cfun
&& !last_tree
)
1253 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1255 keep_next_level (1);
1256 /* If we're building a statement tree, then the upcoming compound
1257 statement will be chained onto the tree structure, starting at
1258 last_tree. We return last_tree so that we can later unhook the
1259 compound statement. */
1263 /* Used when beginning a statement-expression outside function scope.
1264 For example, when handling a file-scope initializer, we use this
1268 begin_global_stmt_expr ()
1270 if (! cfun
&& !last_tree
)
1271 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1273 keep_next_level (1);
1275 return (last_tree
!= NULL_TREE
) ? last_tree
: expand_start_stmt_expr();
1278 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1281 finish_global_stmt_expr (stmt_expr
)
1284 stmt_expr
= expand_end_stmt_expr (stmt_expr
);
1287 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1288 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1293 /* Finish a statement-expression. RTL_EXPR should be the value
1294 returned by the previous begin_stmt_expr; EXPR is the
1295 statement-expression. Returns an expression representing the
1296 statement-expression. */
1299 finish_stmt_expr (rtl_expr
)
1304 /* If the last thing in the statement-expression was not an
1305 expression-statement, then it has type `void'. */
1306 if (!last_expr_type
)
1307 last_expr_type
= void_type_node
;
1308 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1309 TREE_SIDE_EFFECTS (result
) = 1;
1311 /* Remove the compound statement from the tree structure; it is
1312 now saved in the STMT_EXPR. */
1313 last_tree
= rtl_expr
;
1314 TREE_CHAIN (last_tree
) = NULL_TREE
;
1316 /* If we created a statement-tree for this statement-expression,
1319 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1320 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1325 /* Finish a call to FN with ARGS. Returns a representation of the
1329 finish_call_expr (fn
, args
, koenig
)
1338 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1339 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1340 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1341 fn
= do_identifier (fn
, 2, args
);
1343 result
= build_x_function_call (fn
, args
, current_class_ref
);
1345 if (TREE_CODE (result
) == CALL_EXPR
1346 && (! TREE_TYPE (result
)
1347 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1348 result
= require_complete_type (result
);
1353 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1354 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1355 POSTDECREMENT_EXPR.) */
1358 finish_increment_expr (expr
, code
)
1360 enum tree_code code
;
1362 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1363 a COMPONENT_REF). This way if we've got, say, a reference to a
1364 static member that's being operated on, we don't end up trying to
1365 find a member operator for the class it's in. */
1367 if (TREE_CODE (expr
) == OFFSET_REF
)
1368 expr
= resolve_offset_ref (expr
);
1369 return build_x_unary_op (code
, expr
);
1372 /* Finish a use of `this'. Returns an expression for `this'. */
1379 if (current_class_ptr
)
1381 #ifdef WARNING_ABOUT_CCD
1382 TREE_USED (current_class_ptr
) = 1;
1384 result
= current_class_ptr
;
1386 else if (current_function_decl
1387 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1389 error ("`this' is unavailable for static member functions");
1390 result
= error_mark_node
;
1394 if (current_function_decl
)
1395 error ("invalid use of `this' in non-member function");
1397 error ("invalid use of `this' at top level");
1398 result
= error_mark_node
;
1404 /* Finish a member function call using OBJECT and ARGS as arguments to
1405 FN. Returns an expression for the call. */
1408 finish_object_call_expr (fn
, object
, args
)
1414 /* This is a future direction of this code, but because
1415 build_x_function_call cannot always undo what is done in
1416 build_component_ref entirely yet, we cannot do this. */
1418 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1419 return finish_call_expr (real_fn
, args
);
1421 if (DECL_DECLARES_TYPE_P (fn
))
1423 if (processing_template_decl
)
1424 /* This can happen on code like:
1427 template <class T> void f(T t) {
1431 We just grab the underlying IDENTIFIER. */
1432 fn
= DECL_NAME (fn
);
1435 cp_error ("calling type `%T' like a method", fn
);
1436 return error_mark_node
;
1440 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1444 /* Finish a qualified member function call using OBJECT and ARGS as
1445 arguments to FN. Returns an expression for the call. */
1448 finish_qualified_object_call_expr (fn
, object
, args
)
1453 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1454 TREE_OPERAND (fn
, 1), args
);
1457 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1458 being the scope, if any, of DESTRUCTOR. Returns an expression for
1462 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1467 if (processing_template_decl
)
1468 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1470 if (scope
&& scope
!= destructor
)
1471 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1474 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1475 && (TREE_CODE (TREE_TYPE (object
)) !=
1476 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1477 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1479 return cp_convert (void_type_node
, object
);
1482 /* Finish a call to a globally qualified member function FN using
1483 ARGS. Returns an expression for the call. */
1486 finish_qualified_call_expr (fn
, args
)
1490 if (processing_template_decl
)
1491 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1493 return build_member_call (TREE_OPERAND (fn
, 0),
1494 TREE_OPERAND (fn
, 1),
1498 /* Finish an expression taking the address of LABEL. Returns an
1499 expression for the address. */
1502 finish_label_address_expr (label
)
1507 label
= lookup_label (label
);
1508 if (label
== NULL_TREE
)
1509 result
= null_pointer_node
;
1512 TREE_USED (label
) = 1;
1513 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1514 TREE_CONSTANT (result
) = 1;
1515 /* This function cannot be inlined. All jumps to the addressed
1516 label should wind up at the same point. */
1517 DECL_UNINLINABLE (current_function_decl
) = 1;
1523 /* Finish an expression of the form CODE EXPR. */
1526 finish_unary_op_expr (code
, expr
)
1527 enum tree_code code
;
1530 tree result
= build_x_unary_op (code
, expr
);
1531 /* Inside a template, build_x_unary_op does not fold the
1532 expression. So check whether the result is folded before
1533 setting TREE_NEGATED_INT. */
1534 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1535 && TREE_CODE (result
) == INTEGER_CST
1536 && !TREE_UNSIGNED (TREE_TYPE (result
))
1537 && INT_CST_LT (result
, integer_zero_node
))
1538 TREE_NEGATED_INT (result
) = 1;
1539 overflow_warning (result
);
1543 /* Finish an id-expression. */
1546 finish_id_expr (expr
)
1549 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1550 expr
= do_identifier (expr
, 1, NULL_TREE
);
1552 if (TREE_TYPE (expr
) == error_mark_node
)
1553 expr
= error_mark_node
;
1557 static tree current_type_lookups
;
1559 /* Perform deferred access control for types used in the type of a
1563 deferred_type_access_control ()
1565 tree lookup
= type_lookups
;
1567 if (lookup
== error_mark_node
)
1570 for (; lookup
; lookup
= TREE_CHAIN (lookup
))
1571 enforce_access (TREE_PURPOSE (lookup
), TREE_VALUE (lookup
));
1575 decl_type_access_control (decl
)
1580 if (type_lookups
== error_mark_node
)
1583 save_fn
= current_function_decl
;
1585 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
1586 current_function_decl
= decl
;
1588 deferred_type_access_control ();
1590 current_function_decl
= save_fn
;
1592 /* Now strip away the checks for the current declarator; they were
1593 added to type_lookups after typed_declspecs saved the copy that
1594 ended up in current_type_lookups. */
1595 type_lookups
= current_type_lookups
;
1599 save_type_access_control (lookups
)
1602 current_type_lookups
= lookups
;
1605 /* Begin a function definition declared with DECL_SPECS and
1606 DECLARATOR. Returns non-zero if the function-declaration is
1610 begin_function_definition (decl_specs
, declarator
)
1617 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1618 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1621 deferred_type_access_control ();
1622 type_lookups
= error_mark_node
;
1624 /* The things we're about to see are not directly qualified by any
1625 template headers we've seen thus far. */
1626 reset_specialization ();
1631 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1635 begin_constructor_declarator (scope
, name
)
1639 tree result
= build_nt (SCOPE_REF
, scope
, name
);
1640 enter_scope_of (result
);
1644 /* Finish an init-declarator. Returns a DECL. */
1647 finish_declarator (declarator
, declspecs
, attributes
,
1648 prefix_attributes
, initialized
)
1652 tree prefix_attributes
;
1655 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1659 /* Finish a translation unit. */
1662 finish_translation_unit ()
1664 /* In case there were missing closebraces,
1665 get us back to the global binding level. */
1667 while (current_namespace
!= global_namespace
)
1672 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1673 Returns the parameter. */
1676 finish_template_type_parm (aggr
, identifier
)
1680 if (aggr
!= class_type_node
)
1682 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1683 aggr
= class_type_node
;
1686 return build_tree_list (aggr
, identifier
);
1689 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1690 Returns the parameter. */
1693 finish_template_template_parm (aggr
, identifier
)
1697 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1698 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1699 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1700 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1701 DECL_ARTIFICIAL (decl
) = 1;
1702 end_template_decl ();
1704 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl
), 20010110);
1706 return finish_template_type_parm (aggr
, tmpl
);
1709 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1710 non-zero, the parameter list was terminated by a `...'. */
1713 finish_parmlist (parms
, ellipsis
)
1719 /* We mark the PARMS as a parmlist so that declarator processing can
1720 disambiguate certain constructs. */
1721 TREE_PARMLIST (parms
) = 1;
1722 /* We do not append void_list_node here, but leave it to grokparms
1724 PARMLIST_ELLIPSIS_P (parms
) = ellipsis
;
1729 /* Begin a class definition, as indicated by T. */
1732 begin_class_definition (t
)
1735 if (processing_template_parmlist
)
1737 cp_error ("definition of `%#T' inside template parameter list", t
);
1738 return error_mark_node
;
1740 if (t
== error_mark_node
1741 || ! IS_AGGR_TYPE (t
))
1743 t
= make_aggr_type (RECORD_TYPE
);
1744 pushtag (make_anon_name (), t
, 0);
1747 /* In a definition of a member class template, we will get here with an
1748 implicit typename, a TYPENAME_TYPE with a type. */
1749 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1752 /* If we generated a partial instantiation of this type, but now
1753 we're seeing a real definition, we're actually looking at a
1754 partial specialization. Consider:
1756 template <class T, class U>
1762 template <class T, class U>
1765 typename X<Y<T, U> >::A a;
1768 template <class T, class U>
1773 We have to undo the effects of the previous partial
1775 if (PARTIAL_INSTANTIATION_P (t
))
1779 /* Unfortunately, when we're not in pedantic mode, we
1780 attempt to actually fill in some of the fields of the
1781 partial instantiation, in order to support the implicit
1782 typename extension. Clear those fields now, in
1783 preparation for the definition here. The fields cleared
1784 here must match those set in instantiate_class_template.
1785 Look for a comment mentioning begin_class_definition
1787 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1788 TYPE_FIELDS (t
) = NULL_TREE
;
1789 TYPE_METHODS (t
) = NULL_TREE
;
1790 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1791 CLASSTYPE_VBASECLASSES (t
) = NULL_TREE
;
1792 TYPE_SIZE (t
) = NULL_TREE
;
1795 /* This isn't a partial instantiation any more. */
1796 PARTIAL_INSTANTIATION_P (t
) = 0;
1798 /* If this type was already complete, and we see another definition,
1800 else if (COMPLETE_TYPE_P (t
))
1801 duplicate_tag_error (t
);
1803 /* Update the location of the decl. */
1804 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1805 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1807 if (TYPE_BEING_DEFINED (t
))
1809 t
= make_aggr_type (TREE_CODE (t
));
1810 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1812 maybe_process_partial_specialization (t
);
1814 TYPE_BEING_DEFINED (t
) = 1;
1815 TYPE_PACKED (t
) = flag_pack_struct
;
1816 /* Reset the interface data, at the earliest possible
1817 moment, as it might have been set via a class foo;
1820 tree name
= TYPE_IDENTIFIER (t
);
1822 if (! ANON_AGGRNAME_P (name
))
1824 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1825 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1826 (t
, interface_unknown
);
1829 reset_specialization();
1831 /* Make a declaration for this class in its own scope. */
1832 build_self_reference ();
1837 /* Finish the member declaration given by DECL. */
1840 finish_member_declaration (decl
)
1843 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1846 if (decl
== void_type_node
)
1847 /* The COMPONENT was a friend, not a member, and so there's
1848 nothing for us to do. */
1851 /* We should see only one DECL at a time. */
1852 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1854 /* Set up access control for DECL. */
1856 = (current_access_specifier
== access_private_node
);
1857 TREE_PROTECTED (decl
)
1858 = (current_access_specifier
== access_protected_node
);
1859 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1861 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
1862 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
1865 /* Mark the DECL as a member of the current class. */
1866 DECL_CONTEXT (decl
) = current_class_type
;
1870 A C language linkage is ignored for the names of class members
1871 and the member function type of class member functions. */
1872 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
1873 DECL_LANGUAGE (decl
) = lang_cplusplus
;
1875 /* Put functions on the TYPE_METHODS list and everything else on the
1876 TYPE_FIELDS list. Note that these are built up in reverse order.
1877 We reverse them (to obtain declaration order) in finish_struct. */
1878 if (TREE_CODE (decl
) == FUNCTION_DECL
1879 || DECL_FUNCTION_TEMPLATE_P (decl
))
1881 /* We also need to add this function to the
1882 CLASSTYPE_METHOD_VEC. */
1883 add_method (current_class_type
, decl
, /*error_p=*/0);
1885 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1886 TYPE_METHODS (current_class_type
) = decl
;
1890 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1891 go at the beginning. The reason is that lookup_field_1
1892 searches the list in order, and we want a field name to
1893 override a type name so that the "struct stat hack" will
1894 work. In particular:
1896 struct S { enum E { }; int E } s;
1899 is legal. In addition, the FIELD_DECLs must be maintained in
1900 declaration order so that class layout works as expected.
1901 However, we don't need that order until class layout, so we
1902 save a little time by putting FIELD_DECLs on in reverse order
1903 here, and then reversing them in finish_struct_1. (We could
1904 also keep a pointer to the correct insertion points in the
1907 if (TREE_CODE (decl
) == TYPE_DECL
)
1908 TYPE_FIELDS (current_class_type
)
1909 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1912 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1913 TYPE_FIELDS (current_class_type
) = decl
;
1916 /* Enter the DECL into the scope of the class. */
1917 if (TREE_CODE (decl
) != USING_DECL
)
1918 pushdecl_class_level (decl
);
1922 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1923 the definition is immediately followed by a semicolon. Returns the
1927 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
1933 /* finish_struct nukes this anyway; if finish_exception does too,
1936 note_got_semicolon (t
);
1938 /* If we got any attributes in class_head, xref_tag will stick them in
1939 TREE_TYPE of the type. Grab them now. */
1940 attributes
= chainon (TREE_TYPE (t
), attributes
);
1941 TREE_TYPE (t
) = NULL_TREE
;
1943 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1947 t
= finish_struct (t
, attributes
);
1949 note_got_semicolon (t
);
1953 check_for_missing_semicolon (t
);
1955 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
1956 if (current_scope () == current_function_decl
)
1957 do_pending_defargs ();
1962 /* Finish processing the default argument expressions cached during
1963 the processing of a class definition. */
1966 begin_inline_definitions ()
1968 if (current_scope () == current_function_decl
)
1969 do_pending_inlines ();
1972 /* Finish processing the inline function definitions cached during the
1973 processing of a class definition. */
1976 finish_inline_definitions ()
1978 if (current_class_type
== NULL_TREE
)
1979 clear_inline_text_obstack ();
1982 /* Finish processing the declaration of a member class template
1983 TYPES whose template parameters are given by PARMS. */
1986 finish_member_class_template (types
)
1991 /* If there are declared, but undefined, partial specializations
1992 mixed in with the typespecs they will not yet have passed through
1993 maybe_process_partial_specialization, so we do that here. */
1994 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
1995 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
1996 maybe_process_partial_specialization (TREE_VALUE (t
));
1998 note_list_got_semicolon (types
);
1999 grok_x_components (types
);
2000 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
2001 /* The component was in fact a friend declaration. We avoid
2002 finish_member_template_decl performing certain checks by
2006 finish_member_template_decl (types
);
2008 /* As with other component type declarations, we do
2009 not store the new DECL on the list of
2014 /* Finish processsing a complete template declaration. The PARMS are
2015 the template parameters. */
2018 finish_template_decl (parms
)
2022 end_template_decl ();
2024 end_specialization ();
2027 /* Finish processing a template-id (which names a type) of the form
2028 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2029 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2030 the scope of template-id indicated. */
2033 finish_template_type (name
, args
, entering_scope
)
2040 decl
= lookup_template_class (name
, args
,
2041 NULL_TREE
, NULL_TREE
,
2042 entering_scope
, /*complain=*/1);
2043 if (decl
!= error_mark_node
)
2044 decl
= TYPE_STUB_DECL (decl
);
2049 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2050 namespace scope or a class scope. */
2056 tree scope
= TREE_OPERAND (sr
, 0);
2058 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2060 push_decl_namespace (scope
);
2061 TREE_COMPLEXITY (sr
) = -1;
2063 else if (scope
!= current_class_type
)
2065 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2067 /* In a declarator for a template class member, the scope will
2068 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2069 scope
= TREE_TYPE (scope
);
2070 TREE_OPERAND (sr
, 0) = scope
;
2072 push_nested_class (scope
, 3);
2073 TREE_COMPLEXITY (sr
) = current_class_depth
;
2077 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2078 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2079 BASE_CLASS, or NULL_TREE if an error occurred. The
2080 ACCESSS_SPECIFIER is one of
2081 access_{default,public,protected_private}[_virtual]_node.*/
2084 finish_base_specifier (access_specifier
, base_class
)
2085 tree access_specifier
;
2090 if (! is_aggr_type (base_class
, 1))
2094 if (CP_TYPE_QUALS (base_class
) != 0)
2096 cp_error ("base class `%T' has cv qualifiers", base_class
);
2097 base_class
= TYPE_MAIN_VARIANT (base_class
);
2099 result
= build_tree_list (access_specifier
, base_class
);
2105 /* Called when multiple declarators are processed. If that is not
2106 premitted in this context, an error is issued. */
2109 check_multiple_declarators ()
2113 In a template-declaration, explicit specialization, or explicit
2114 instantiation the init-declarator-list in the declaration shall
2115 contain at most one declarator.
2117 We don't just use PROCESSING_TEMPLATE_DECL for the first
2118 condition since that would disallow the perfectly legal code,
2119 like `template <class T> struct S { int i, j; };'. */
2120 tree scope
= current_scope ();
2122 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2123 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2126 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2127 || processing_explicit_instantiation
2128 || processing_specialization
)
2129 cp_error ("multiple declarators in template declaration");
2133 finish_typeof (expr
)
2136 if (processing_template_decl
)
2140 t
= make_aggr_type (TYPEOF_TYPE
);
2141 TYPE_FIELDS (t
) = expr
;
2146 if (TREE_CODE (expr
) == OFFSET_REF
)
2147 expr
= resolve_offset_ref (expr
);
2149 return TREE_TYPE (expr
);
2152 /* Generate RTL for the statement T, and its substatements, and any
2153 other statements at its nesting level. */
2159 switch (TREE_CODE (t
))
2162 genrtl_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2165 case START_CATCH_STMT
:
2166 genrtl_catch_block (TREE_TYPE (t
));
2170 genrtl_ctor_stmt (t
);
2174 genrtl_try_block (t
);
2182 genrtl_subobject (SUBOBJECT_CLEANUP (t
));
2186 genrtl_named_return_value ();
2190 my_friendly_abort (19990810);
2195 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2196 will equivalent CALL_EXPRs. */
2199 simplify_aggr_init_exprs_r (tp
, walk_subtrees
, data
)
2201 int *walk_subtrees ATTRIBUTE_UNUSED
;
2202 void *data ATTRIBUTE_UNUSED
;
2204 tree aggr_init_expr
;
2211 int copy_from_buffer_p
;
2213 aggr_init_expr
= *tp
;
2214 /* We don't need to walk into types; there's nothing in a type that
2215 needs simplification. (And, furthermore, there are places we
2216 actively don't want to go. For example, we don't want to wander
2217 into the default arguments for a FUNCTION_DECL that appears in a
2219 if (TYPE_P (aggr_init_expr
))
2224 /* Only AGGR_INIT_EXPRs are interesting. */
2225 else if (TREE_CODE (aggr_init_expr
) != AGGR_INIT_EXPR
)
2228 /* Form an appropriate CALL_EXPR. */
2229 fn
= TREE_OPERAND (aggr_init_expr
, 0);
2230 args
= TREE_OPERAND (aggr_init_expr
, 1);
2231 slot
= TREE_OPERAND (aggr_init_expr
, 2);
2232 type
= TREE_TYPE (aggr_init_expr
);
2234 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
2236 /* Replace the first argument with the address of the third
2237 argument to the AGGR_INIT_EXPR. */
2238 call_type
= build_pointer_type (type
);
2239 mark_addressable (slot
);
2240 args
= tree_cons (NULL_TREE
, build1 (ADDR_EXPR
, call_type
, slot
),
2243 call_expr
= build (CALL_EXPR
, call_type
, fn
, args
, NULL_TREE
);
2244 TREE_SIDE_EFFECTS (call_expr
) = 1;
2246 /* If we're using the non-reentrant PCC calling convention, then we
2247 need to copy the returned value out of the static buffer into the
2249 copy_from_buffer_p
= 0;
2250 #ifdef PCC_STATIC_STRUCT_RETURN
2251 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) && aggregate_value_p (type
))
2255 flag_access_control
= 0;
2256 call_expr
= build_aggr_init (slot
, call_expr
, LOOKUP_ONLYCONVERTING
);
2257 flag_access_control
= old_ac
;
2258 copy_from_buffer_p
= 1;
2262 /* If this AGGR_INIT_EXPR indicates the value returned by a
2263 function, then we want to use the value of the initialized
2264 location as the result. */
2265 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) || copy_from_buffer_p
)
2267 call_expr
= build (COMPOUND_EXPR
, type
,
2269 TREE_SIDE_EFFECTS (call_expr
) = 1;
2272 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2273 TREE_CHAIN (call_expr
) = TREE_CHAIN (aggr_init_expr
);
2276 /* Keep iterating. */
2280 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2283 emit_associated_thunks (fn
)
2286 /* When we use vcall offsets, we emit thunks with the virtual
2287 functions to which they thunk. The whole point of vcall offsets
2288 is so that you can know statically the entire set of thunks that
2289 will ever be needed for a given virtual function, thereby
2290 enabling you to output all the thunks with the function itself. */
2291 if (vcall_offsets_in_vtable_p () && DECL_VIRTUAL_P (fn
))
2296 for (binfo
= TYPE_BINFO (DECL_CONTEXT (fn
));
2298 binfo
= TREE_CHAIN (binfo
))
2299 for (v
= BINFO_VIRTUALS (binfo
); v
; v
= TREE_CHAIN (v
))
2301 && (!integer_zerop (BV_DELTA (v
))
2302 || BV_VCALL_INDEX (v
)))
2307 if (BV_USE_VCALL_INDEX_P (v
))
2309 vcall_index
= BV_VCALL_INDEX (v
);
2310 my_friendly_assert (vcall_index
!= NULL_TREE
, 20000621);
2313 vcall_index
= NULL_TREE
;
2315 thunk
= make_thunk (build1 (ADDR_EXPR
,
2316 vfunc_ptr_type_node
,
2320 /*generate_with_vtable_p=*/0);
2321 use_thunk (thunk
, /*emit_p=*/1);
2326 /* Generate RTL for FN. */
2333 const char *saved_input_filename
;
2335 /* When the parser calls us after finishing the body of a template
2336 function, we don't really want to expand the body. When we're
2337 processing an in-class definition of an inline function,
2338 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2339 to look at the function itself. */
2340 if (processing_template_decl
2341 || (DECL_LANG_SPECIFIC (fn
)
2342 && DECL_TEMPLATE_INFO (fn
)
2343 && uses_template_parms (DECL_TI_ARGS (fn
))))
2345 /* Normally, collection only occurs in rest_of_compilation. So,
2346 if we don't collect here, we never collect junk generated
2347 during the processing of templates until we hit a
2348 non-template function. */
2353 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2354 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn
),
2355 simplify_aggr_init_exprs_r
,
2358 /* If this is a constructor or destructor body, we have to clone it
2359 under the new ABI. */
2360 if (maybe_clone_body (fn
))
2362 /* We don't want to process FN again, so pretend we've written
2363 it out, even though we haven't. */
2364 TREE_ASM_WRITTEN (fn
) = 1;
2368 /* There's no reason to do any of the work here if we're only doing
2369 semantic analysis; this code just generates RTL. */
2370 if (flag_syntax_only
)
2373 /* If possible, avoid generating RTL for this function. Instead,
2374 just record it as an inline function, and wait until end-of-file
2375 to decide whether to write it out or not. */
2376 if (/* We have to generate RTL if it's not an inline function. */
2377 (DECL_INLINE (fn
) || DECL_COMDAT (fn
))
2378 /* Or if we have to keep all inline functions anyhow. */
2379 && !flag_keep_inline_functions
2380 /* Or if we actually have a reference to the function. */
2381 && !DECL_NEEDED_P (fn
)
2382 /* Or if this is a nested function. */
2383 && !decl_function_context (fn
))
2385 /* Set DECL_EXTERNAL so that assemble_external will be called as
2386 necessary. We'll clear it again in finish_file. */
2387 if (!DECL_EXTERNAL (fn
))
2389 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2390 DECL_EXTERNAL (fn
) = 1;
2392 /* Remember this function. In finish_file we'll decide if
2393 we actually need to write this function out. */
2395 /* Let the back-end know that this funtion exists. */
2396 note_deferral_of_defined_inline_function (fn
);
2400 /* Emit any thunks that should be emitted at the same time as FN. */
2401 emit_associated_thunks (fn
);
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 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2423 any of the other magic variables we set up when starting a
2425 function_name_declared_p
= 1;
2427 /* Expand the body. */
2428 expand_stmt (DECL_SAVED_TREE (fn
));
2430 /* Statements should always be full-expressions at the outermost set
2431 of curly braces for a function. */
2432 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2434 /* The outermost statement for a function contains the line number
2435 recorded when we finished processing the function. */
2436 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2438 /* Generate code for the function. */
2439 genrtl_finish_function (fn
);
2441 /* If possible, obliterate the body of the function so that it can
2442 be garbage collected. */
2443 if (flag_dump_translation_unit
)
2444 /* Keep the body; we're going to dump it. */
2446 else if (DECL_INLINE (fn
) && flag_inline_trees
)
2447 /* We might need the body of this function so that we can expand
2448 it inline somewhere else. */
2451 /* We don't need the body; blow it away. */
2452 DECL_SAVED_TREE (fn
) = NULL_TREE
;
2454 /* And restore the current source position. */
2455 lineno
= saved_lineno
;
2456 input_filename
= saved_input_filename
;
2457 extract_interface_info ();
2459 timevar_pop (TV_EXPAND
);
2462 /* Start generating the RTL for FN. */
2465 genrtl_start_function (fn
)
2470 /* Tell everybody what function we're processing. */
2471 current_function_decl
= fn
;
2472 /* Get the RTL machinery going for this function. */
2473 init_function_start (fn
, DECL_SOURCE_FILE (fn
), DECL_SOURCE_LINE (fn
));
2474 /* Let everybody know that we're expanding this function, not doing
2475 semantic analysis. */
2478 /* Even though we're inside a function body, we still don't want to
2479 call expand_expr to calculate the size of a variable-sized array.
2480 We haven't necessarily assigned RTL to all variables yet, so it's
2481 not safe to try to expand expressions involving them. */
2482 immediate_size_expand
= 0;
2483 cfun
->x_dont_save_pending_sizes_p
= 1;
2485 /* Let the user know we're compiling this function. */
2486 announce_function (fn
);
2488 /* Initialize the per-function data. */
2489 my_friendly_assert (!DECL_PENDING_INLINE_P (fn
), 20000911);
2490 if (DECL_SAVED_FUNCTION_DATA (fn
))
2492 /* If we already parsed this function, and we're just expanding it
2493 now, restore saved state. */
2494 *cp_function_chain
= *DECL_SAVED_FUNCTION_DATA (fn
);
2496 /* This function is being processed in whole-function mode; we
2497 already did semantic analysis. */
2498 cfun
->x_whole_function_mode_p
= 1;
2500 /* If we decided that we didn't want to inline this function,
2501 make sure the back-end knows that. */
2502 if (!current_function_cannot_inline
)
2503 current_function_cannot_inline
= cp_function_chain
->cannot_inline
;
2505 /* We don't need the saved data anymore. */
2506 free (DECL_SAVED_FUNCTION_DATA (fn
));
2507 DECL_SAVED_FUNCTION_DATA (fn
) = NULL
;
2510 /* Tell the cross-reference machinery that we're defining this
2512 GNU_xref_function (fn
, DECL_ARGUMENTS (fn
));
2514 /* Keep track of how many functions we're presently expanding. */
2517 /* Create a binding level for the parameters. */
2518 expand_start_bindings (2);
2519 /* Clear out any previously saved instructions for this function, in
2520 case it was defined more than once. */
2521 DECL_SAVED_INSNS (fn
) = NULL
;
2522 /* Go through the PARM_DECLs for this function to see if any need
2524 for (parm
= DECL_ARGUMENTS (fn
); parm
; parm
= TREE_CHAIN (parm
))
2525 if (TREE_TYPE (parm
) != error_mark_node
2526 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (parm
)))
2528 expand_function_start (fn
, /*parms_have_cleanups=*/1);
2532 expand_function_start (fn
, /*parms_have_cleanups=*/0);
2533 /* If this function is `main'. */
2534 if (DECL_MAIN_P (fn
))
2535 expand_main_function ();
2536 /* Create a binding contour which can be used to catch
2537 cleanup-generated temporaries. */
2538 expand_start_bindings (2);
2541 /* Finish generating the RTL for FN. */
2544 genrtl_finish_function (fn
)
2547 tree no_return_label
= NULL_TREE
;
2550 if (write_symbols
!= NO_DEBUG
)
2552 /* Keep this code around in case we later want to control debug info
2553 based on whether a type is "used". (jason 1999-11-11) */
2555 tree ttype
= target_type (fntype
);
2558 if (IS_AGGR_TYPE (ttype
))
2559 /* Let debugger know it should output info for this type. */
2560 note_debug_info_needed (ttype
);
2562 for (parmdecl
= DECL_ARGUMENTS (fndecl
); parmdecl
; parmdecl
= TREE_CHAIN (parmdecl
))
2564 ttype
= target_type (TREE_TYPE (parmdecl
));
2565 if (IS_AGGR_TYPE (ttype
))
2566 /* Let debugger know it should output info for this type. */
2567 note_debug_info_needed (ttype
);
2572 /* Clean house because we will need to reorder insns here. */
2573 do_pending_stack_adjust ();
2575 if (!dtor_label
&& !DECL_CONSTRUCTOR_P (fn
)
2576 && return_label
!= NULL_RTX
2577 && current_function_return_value
== NULL_TREE
2578 && ! DECL_NAME (DECL_RESULT (current_function_decl
)))
2579 no_return_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
2581 if (flag_exceptions
)
2582 expand_exception_blocks ();
2584 /* If this function is supposed to return a value, ensure that
2585 we do not fall into the cleanups by mistake. The end of our
2586 function will look like this:
2588 user code (may have return stmt somewhere)
2589 goto no_return_label
2594 NOTE_INSN_FUNCTION_END
2598 If the user omits a return stmt in the USER CODE section, we
2599 will have a control path which reaches NOTE_INSN_FUNCTION_END.
2600 Otherwise, we won't. */
2601 if (no_return_label
)
2603 DECL_CONTEXT (no_return_label
) = fn
;
2604 DECL_INITIAL (no_return_label
) = error_mark_node
;
2605 DECL_SOURCE_FILE (no_return_label
) = input_filename
;
2606 DECL_SOURCE_LINE (no_return_label
) = lineno
;
2607 expand_goto (no_return_label
);
2612 /* Remove the binding contour which is used to catch
2613 cleanup-generated temporaries. */
2614 expand_end_bindings (0, 0, 0);
2617 /* Emit label at beginning of cleanup code for parameters. */
2618 emit_label (cleanup_label
);
2621 /* Finish building code that will trigger warnings if users forget
2622 to make their functions return values. */
2624 emit_jump (return_label
);
2625 if (no_return_label
)
2627 /* We don't need to call `expand_*_return' here because we don't
2628 need any cleanups here--this path of code is only for error
2629 checking purposes. */
2630 expand_label (no_return_label
);
2633 /* We hard-wired immediate_size_expand to zero in start_function.
2634 Expand_function_end will decrement this variable. So, we set the
2635 variable to one here, so that after the decrement it will remain
2637 immediate_size_expand
= 1;
2639 /* Generate rtl for function exit. */
2640 expand_function_end (input_filename
, lineno
, 1);
2642 /* If this is a nested function (like a template instantiation that
2643 we're compiling in the midst of compiling something else), push a
2644 new GC context. That will keep local variables on the stack from
2645 being collected while we're doing the compilation of this
2647 if (function_depth
> 1)
2648 ggc_push_context ();
2650 /* Run the optimizers and output the assembler code for this
2652 rest_of_compilation (fn
);
2654 /* Undo the call to ggc_push_context above. */
2655 if (function_depth
> 1)
2658 if (DECL_SAVED_INSNS (fn
) && ! TREE_ASM_WRITTEN (fn
))
2660 /* Set DECL_EXTERNAL so that assemble_external will be called as
2661 necessary. We'll clear it again in finish_file. */
2662 if (! DECL_EXTERNAL (fn
))
2663 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2664 DECL_EXTERNAL (fn
) = 1;
2669 /* Keep this code around in case we later want to control debug info
2670 based on whether a type is "used". (jason 1999-11-11) */
2672 if (ctype
&& TREE_ASM_WRITTEN (fn
))
2673 note_debug_info_needed (ctype
);
2676 /* If this function is marked with the constructor attribute, add it
2677 to the list of functions to be called along with constructors
2678 from static duration objects. */
2679 if (DECL_STATIC_CONSTRUCTOR (fn
))
2680 static_ctors
= tree_cons (NULL_TREE
, fn
, static_ctors
);
2682 /* If this function is marked with the destructor attribute, add it
2683 to the list of functions to be called along with destructors from
2684 static duration objects. */
2685 if (DECL_STATIC_DESTRUCTOR (fn
))
2686 static_dtors
= tree_cons (NULL_TREE
, fn
, static_dtors
);
2690 if (!DECL_SAVED_INSNS (fn
)
2691 && !(flag_inline_trees
&& DECL_INLINE (fn
)))
2695 /* Stop pointing to the local nodes about to be freed. */
2696 /* But DECL_INITIAL must remain nonzero so we know this
2697 was an actual function definition. */
2698 DECL_INITIAL (fn
) = error_mark_node
;
2699 for (t
= DECL_ARGUMENTS (fn
); t
; t
= TREE_CHAIN (t
))
2701 SET_DECL_RTL (t
, NULL_RTX
);
2702 DECL_INCOMING_RTL (t
) = NULL_RTX
;
2706 /* Let the error reporting routines know that we're outside a
2707 function. For a nested function, this value is used in
2708 pop_cp_function_context and then reset via pop_function_context. */
2709 current_function_decl
= NULL_TREE
;
2712 /* Perform initialization related to this module. */
2715 init_cp_semantics ()
2717 lang_expand_stmt
= cp_expand_stmt
;