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 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
));
54 /* When parsing a template, LAST_TREE contains the last statement
55 parsed. These are chained together through the TREE_CHAIN field,
56 but often need to be re-organized since the parse is performed
57 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
60 #define RECHAIN_STMTS(stmt, substmt) \
62 substmt = TREE_CHAIN (stmt); \
63 TREE_CHAIN (stmt) = NULL_TREE; \
67 /* Finish processing the COND, the SUBSTMT condition for STMT. */
69 #define FINISH_COND(cond, stmt, substmt) \
71 if (last_tree != stmt) \
73 RECHAIN_STMTS (stmt, substmt); \
74 if (!processing_template_decl) \
76 cond = build_tree_list (substmt, cond); \
84 /* Wrapper since C and C++ expand_expr_stmt are different. */
86 expand_expr_stmt_fn lang_expand_expr_stmt
= cplus_expand_expr_stmt
;
88 /* Wrapper function instead of #define for use with c-common code. */
91 set_current_function_name_declared (i
)
94 cp_function_chain
->name_declared
= i
;
97 /* Returns non-zero if the current statement is a full expression,
98 i.e. temporaries created during that statement should be destroyed
99 at the end of the statement. */
102 stmts_are_full_exprs_p ()
104 return current_stmt_tree ()->stmts_are_full_exprs_p
;
107 /* Returns the stmt_tree (if any) to which statements are currently
108 being added. If there is no active statement-tree, NULL is
115 ? &cfun
->language
->x_stmt_tree
116 : &scope_chain
->x_stmt_tree
);
119 /* One if we have already declared __FUNCTION__ (and related
120 variables) in the current function. Two if we are in the process
124 current_function_name_declared ()
126 return cp_function_chain
->name_declared
;
129 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
130 flag for this because "A union for which objects or pointers are
131 declared is not an anonymous union" [class.union]. */
134 anon_aggr_type_p (node
)
137 return (CLASS_TYPE_P (node
) && TYPE_LANG_SPECIFIC(node
)->anon_aggr
);
140 /* Finish a scope. */
145 tree block
= NULL_TREE
;
147 if (stmts_are_full_exprs_p ())
149 tree scope_stmts
= NULL_TREE
;
151 if (!processing_template_decl
)
152 scope_stmts
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
154 block
= poplevel (kept_level_p (), 1, 0);
155 if (block
&& !processing_template_decl
)
157 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts
)) = block
;
158 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts
)) = block
;
165 /* Begin a new scope. */
170 if (stmts_are_full_exprs_p ())
173 if (!processing_template_decl
)
174 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
178 /* Finish a goto-statement. */
181 finish_goto_stmt (destination
)
184 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
185 destination
= lookup_label (destination
);
187 /* We warn about unused labels with -Wunused. That means we have to
188 mark the used labels as used. */
189 if (TREE_CODE (destination
) == LABEL_DECL
)
190 TREE_USED (destination
) = 1;
192 if (TREE_CODE (destination
) != LABEL_DECL
)
193 /* We don't inline calls to functions with computed gotos.
194 Those functions are typically up to some funny business,
195 and may be depending on the labels being at particular
196 addresses, or some such. */
197 DECL_UNINLINABLE (current_function_decl
) = 1;
199 check_goto (destination
);
201 add_stmt (build_stmt (GOTO_STMT
, destination
));
204 /* COND is the condition-expression for an if, while, etc.,
205 statement. Convert it to a boolean value, if appropriate. */
208 maybe_convert_cond (cond
)
211 /* Empty conditions remain empty. */
215 /* Wait until we instantiate templates before doing conversion. */
216 if (processing_template_decl
)
219 /* Do the conversion. */
220 cond
= convert_from_reference (cond
);
221 return condition_conversion (cond
);
224 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
227 finish_expr_stmt (expr
)
230 if (expr
!= NULL_TREE
)
232 if (!processing_template_decl
233 && !(stmts_are_full_exprs_p ())
234 && ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
236 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
237 expr
= default_conversion (expr
);
239 if (stmts_are_full_exprs_p ())
240 expr
= convert_to_void (expr
, "statement");
242 if (!processing_template_decl
)
243 expr
= break_out_cleanups (expr
);
245 add_stmt (build_stmt (EXPR_STMT
, expr
));
250 /* This was an expression-statement, so we save the type of the
252 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
256 /* Begin an if-statement. Returns a newly created IF_STMT if
264 r
= build_stmt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
269 /* Process the COND of an if-statement, which may be given by
273 finish_if_stmt_cond (cond
, if_stmt
)
277 cond
= maybe_convert_cond (cond
);
278 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
281 /* Finish the then-clause of an if-statement, which may be given by
285 finish_then_clause (if_stmt
)
288 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
293 /* Begin the else-clause of an if-statement. */
300 /* Finish the else-clause of an if-statement, which may be given by
304 finish_else_clause (if_stmt
)
307 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
310 /* Finsh an if-statement. */
322 /* If COND wasn't a declaration, clear out the
323 block we made for it and start a new one here so the
324 optimization in expand_end_loop will work. */
325 if (getdecls () == NULL_TREE
)
332 /* Begin a while-statement. Returns a newly created WHILE_STMT if
339 r
= build_stmt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
345 /* Process the COND of a while-statement, which may be given by
349 finish_while_stmt_cond (cond
, while_stmt
)
353 cond
= maybe_convert_cond (cond
);
354 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
358 /* Finish a while-statement, which may be given by WHILE_STMT. */
361 finish_while_stmt (while_stmt
)
365 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
369 /* Begin a do-statement. Returns a newly created DO_STMT if
375 tree r
= build_stmt (DO_STMT
, NULL_TREE
, NULL_TREE
);
380 /* Finish the body of a do-statement, which may be given by DO_STMT. */
383 finish_do_body (do_stmt
)
386 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
389 /* Finish a do-statement, which may be given by DO_STMT, and whose
390 COND is as indicated. */
393 finish_do_stmt (cond
, do_stmt
)
397 cond
= maybe_convert_cond (cond
);
398 DO_COND (do_stmt
) = cond
;
402 /* Finish a return-statement. The EXPRESSION returned, if any, is as
406 finish_return_stmt (expr
)
409 if (!processing_template_decl
)
410 expr
= check_return_expr (expr
);
411 if (!processing_template_decl
)
413 if (DECL_CONSTRUCTOR_P (current_function_decl
) && ctor_label
)
415 /* Even returns without a value in a constructor must return
416 `this'. We accomplish this by sending all returns in a
417 constructor to the CTOR_LABEL; finish_function emits code to
418 return a value there. When we finally generate the real
419 return statement, CTOR_LABEL is no longer set, and we fall
420 through into the normal return-processing code below. */
421 finish_goto_stmt (ctor_label
);
424 else if (DECL_DESTRUCTOR_P (current_function_decl
))
426 /* Similarly, all destructors must run destructors for
427 base-classes before returning. So, all returns in a
428 destructor get sent to the DTOR_LABEL; finsh_function emits
429 code to return a value there. */
430 finish_goto_stmt (dtor_label
);
434 add_stmt (build_stmt (RETURN_STMT
, expr
));
438 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
445 r
= build_stmt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
446 NULL_TREE
, NULL_TREE
);
447 NEW_FOR_SCOPE_P (r
) = flag_new_for_scope
> 0;
449 if (NEW_FOR_SCOPE_P (r
))
452 note_level_for_for ();
458 /* Finish the for-init-statement of a for-statement, which may be
459 given by FOR_STMT. */
462 finish_for_init_stmt (for_stmt
)
465 if (last_tree
!= for_stmt
)
466 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
470 /* Finish the COND of a for-statement, which may be given by
474 finish_for_cond (cond
, for_stmt
)
478 cond
= maybe_convert_cond (cond
);
479 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
483 /* Finish the increment-EXPRESSION in a for-statement, which may be
484 given by FOR_STMT. */
487 finish_for_expr (expr
, for_stmt
)
491 FOR_EXPR (for_stmt
) = expr
;
494 /* Finish the body of a for-statement, which may be given by
495 FOR_STMT. The increment-EXPR for the loop must be
499 finish_for_stmt (for_stmt
)
502 /* Pop the scope for the body of the loop. */
504 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
505 if (NEW_FOR_SCOPE_P (for_stmt
))
510 /* Finish a break-statement. */
515 add_stmt (build_stmt (BREAK_STMT
));
518 /* Finish a continue-statement. */
521 finish_continue_stmt ()
523 add_stmt (build_stmt (CONTINUE_STMT
));
526 /* Begin a switch-statement. Returns a new SWITCH_STMT if
533 r
= build_stmt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
539 /* Finish the cond of a switch-statement. */
542 finish_switch_cond (cond
, switch_stmt
)
546 if (!processing_template_decl
)
548 /* Convert the condition to an integer or enumeration type. */
549 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, 1);
550 if (cond
== NULL_TREE
)
552 error ("switch quantity not an integer");
553 cond
= error_mark_node
;
555 if (cond
!= error_mark_node
)
557 cond
= default_conversion (cond
);
558 cond
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (cond
), cond
));
561 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
565 /* Finish the body of a switch-statement, which may be given by
566 SWITCH_STMT. The COND to switch on is indicated. */
569 finish_switch_stmt (switch_stmt
)
572 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
578 /* Finish a case-label. */
581 finish_case_label (low_value
, high_value
)
585 /* Add a representation for the case label to the statement
587 add_stmt (build_stmt (CASE_LABEL
, low_value
, high_value
));
588 /* And warn about crossing initializations, etc. */
589 if (!processing_template_decl
)
590 define_case_label ();
593 /* Generate the RTL for T, which is a TRY_BLOCK. */
595 void genrtl_try_block (t
)
600 expand_eh_region_start ();
601 expand_stmt (TRY_STMTS (t
));
602 expand_eh_region_end (protect_with_terminate (TRY_HANDLERS (t
)));
606 if (FN_TRY_BLOCK_P (t
))
608 if (! current_function_parms_stored
)
610 expand_start_early_try_stmts ();
614 emit_line_note (input_filename
, lineno
);
615 expand_start_try_stmts ();
618 expand_stmt (TRY_STMTS (t
));
620 if (FN_TRY_BLOCK_P (t
))
622 end_protect_partials ();
623 expand_start_all_catch ();
624 in_function_try_handler
= 1;
625 expand_stmt (TRY_HANDLERS (t
));
626 in_function_try_handler
= 0;
627 expand_end_all_catch ();
631 expand_start_all_catch ();
632 expand_stmt (TRY_HANDLERS (t
));
633 expand_end_all_catch ();
638 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
644 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
649 /* Likewise, for a function-try-block. */
652 begin_function_try_block ()
654 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
655 FN_TRY_BLOCK_P (r
) = 1;
660 /* Finish a try-block, which may be given by TRY_BLOCK. */
663 finish_try_block (try_block
)
666 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
669 /* Finish the body of a cleanup try-block, which may be given by
673 finish_cleanup_try_block (try_block
)
676 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
679 /* Finish an implicitly generated try-block, with a cleanup is given
683 finish_cleanup (cleanup
, try_block
)
687 TRY_HANDLERS (try_block
) = cleanup
;
688 CLEANUP_P (try_block
) = 1;
691 /* Likewise, for a function-try-block. */
694 finish_function_try_block (try_block
)
697 if (TREE_CHAIN (try_block
)
698 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
700 /* Chain the compound statement after the CTOR_INITIALIZER. */
701 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
702 /* And make the CTOR_INITIALIZER the body of the try-block. */
703 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
706 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
707 in_function_try_handler
= 1;
710 /* Finish a handler-sequence for a try-block, which may be given by
714 finish_handler_sequence (try_block
)
717 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
718 check_handlers (TRY_HANDLERS (try_block
));
721 /* Likewise, for a function-try-block. */
724 finish_function_handler_sequence (try_block
)
727 in_function_try_handler
= 0;
728 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
729 check_handlers (TRY_HANDLERS (try_block
));
732 /* Generate the RTL for T, which is a HANDLER. */
738 genrtl_do_pushlevel ();
739 expand_stmt (HANDLER_BODY (t
));
740 if (!processing_template_decl
)
742 /* Fall to outside the try statement when done executing
743 handler and we fall off end of handler. This is jump
744 Lresume in the documentation. */
745 expand_goto (top_label_entry (&caught_return_label_stack
));
746 end_catch_handler ();
750 /* Begin a handler. Returns a HANDLER if appropriate. */
756 r
= build_stmt (HANDLER
, NULL_TREE
, NULL_TREE
);
762 /* Finish the handler-parameters for a handler, which may be given by
763 HANDLER. DECL is the declaration for the catch parameter, or NULL
764 if this is a `catch (...)' clause. */
767 finish_handler_parms (decl
, handler
)
771 tree blocks
= NULL_TREE
;
773 if (processing_template_decl
)
777 decl
= pushdecl (decl
);
778 decl
= push_template_decl (decl
);
779 add_decl_stmt (decl
);
780 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
784 blocks
= expand_start_catch_block (decl
);
787 TREE_TYPE (handler
) = TREE_TYPE (decl
);
792 /* Generate the RTL for a CATCH_BLOCK. */
795 genrtl_catch_block (type
)
798 start_catch_handler (type
);
801 /* Note the beginning of a handler for TYPE. This function is called
802 at the point to which control should be transferred when an
803 appropriately-typed exception is thrown. */
806 begin_catch_block (type
)
809 add_stmt (build (START_CATCH_STMT
, type
));
812 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
813 the return value from the matching call to finish_handler_parms. */
816 finish_handler (blocks
, handler
)
820 if (!processing_template_decl
)
821 expand_end_catch_block (blocks
);
823 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
826 /* Generate the RTL for T, which is a CTOR_STMT. */
832 if (CTOR_BEGIN_P (t
))
833 begin_protect_partials ();
835 /* After this point, any exceptions will cause the
836 destructor to be executed, so we no longer need to worry
837 about destroying the various subobjects ourselves. */
838 end_protect_partials ();
841 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
842 compound-statement does not define a scope. Returns a new
843 COMPOUND_STMT if appropriate. */
846 begin_compound_stmt (has_no_scope
)
852 r
= build_stmt (COMPOUND_STMT
, NULL_TREE
);
854 if (last_tree
&& TREE_CODE (last_tree
) == TRY_BLOCK
)
859 COMPOUND_STMT_NO_SCOPE (r
) = 1;
861 last_expr_type
= NULL_TREE
;
867 note_level_for_eh ();
870 /* Normally, we try hard to keep the BLOCK for a
871 statement-expression. But, if it's a statement-expression with
872 a scopeless block, there's nothing to keep, and we don't want
873 to accidentally keep a block *inside* the scopeless block. */
876 /* If this is the outermost block of the function, declare the
877 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
879 && !(current_function_name_declared () )
882 cp_function_chain
->name_declared
= 1;
883 declare_function_name ();
889 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
890 If HAS_NO_SCOPE is non-zero, the compound statement does not define
894 finish_compound_stmt (has_no_scope
, compound_stmt
)
906 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
908 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
909 the precise purpose of that variable is store the type of the
910 last expression statement within the last compound statement, we
911 preserve the value. */
919 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
920 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
924 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
925 input_operands
, clobbers
)
928 tree output_operands
;
935 if (TREE_CHAIN (string
))
936 string
= combine_strings (string
);
938 if (cv_qualifier
!= NULL_TREE
939 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
941 cp_warning ("%s qualifier ignored on asm",
942 IDENTIFIER_POINTER (cv_qualifier
));
943 cv_qualifier
= NULL_TREE
;
946 if (!processing_template_decl
)
947 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
948 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
950 r
= build_stmt (ASM_STMT
, cv_qualifier
, string
,
951 output_operands
, input_operands
,
956 /* Finish a label with the indicated NAME. */
959 finish_label_stmt (name
)
962 tree decl
= define_label (input_filename
, lineno
, name
);
963 add_stmt (build_stmt (LABEL_STMT
, decl
));
966 /* Finish a series of declarations for local labels. G++ allows users
967 to declare "local" labels, i.e., labels with scope. This extension
968 is useful when writing code involving statement-expressions. */
971 finish_label_decl (name
)
974 tree decl
= declare_local_label (name
);
975 add_decl_stmt (decl
);
978 /* Create a declaration statement for the declaration given by the
987 /* We need the type to last until instantiation time. */
988 decl_stmt
= build_stmt (DECL_STMT
, decl
);
989 add_stmt (decl_stmt
);
992 /* Generate the RTL for a SUBOBJECT. */
995 genrtl_subobject (cleanup
)
998 add_partial_entry (cleanup
);
1001 /* We're in a constructor, and have just constructed a a subobject of
1002 *THIS. CLEANUP is code to run if an exception is thrown before the
1003 end of the current function is reached. */
1006 finish_subobject (cleanup
)
1009 tree r
= build_stmt (SUBOBJECT
, cleanup
);
1013 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1016 finish_decl_cleanup (decl
, cleanup
)
1020 add_stmt (build_stmt (CLEANUP_STMT
, decl
, cleanup
));
1023 /* Generate the RTL for a RETURN_INIT. */
1026 genrtl_named_return_value ()
1030 decl
= DECL_RESULT (current_function_decl
);
1032 emit_local_var (decl
);
1034 /* If this named return value comes in a register, put it in a
1036 if (DECL_REGISTER (decl
))
1038 original_result_rtx
= DECL_RTL (decl
);
1039 /* Note that the mode of the old DECL_RTL may be wider than the
1040 mode of DECL_RESULT, depending on the calling conventions for
1041 the processor. For example, on the Alpha, a 32-bit integer
1042 is returned in a DImode register -- the DECL_RESULT has
1043 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
1044 here, we use the mode the back-end has already assigned for
1045 the return value. */
1046 DECL_RTL (decl
) = gen_reg_rtx (GET_MODE (original_result_rtx
));
1047 if (TREE_ADDRESSABLE (decl
))
1048 put_var_into_stack (decl
);
1052 /* Bind a name and initialization to the return value of
1053 the current function. */
1056 finish_named_return_value (return_id
, init
)
1057 tree return_id
, init
;
1059 tree decl
= DECL_RESULT (current_function_decl
);
1061 /* Give this error as many times as there are occurrences, so that
1062 users can use Emacs compilation buffers to find and fix all such
1065 pedwarn ("ISO C++ does not permit named return values");
1066 cp_deprecated ("the named return value extension");
1068 if (return_id
!= NULL_TREE
)
1070 if (DECL_NAME (decl
) == NULL_TREE
)
1072 DECL_NAME (decl
) = return_id
;
1073 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1077 cp_error ("return identifier `%D' already in place", return_id
);
1082 /* Can't let this happen for constructors. */
1083 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1085 error ("can't redefine default return value for constructors");
1089 /* If we have a named return value, put that in our scope as well. */
1090 if (DECL_NAME (decl
) != NULL_TREE
)
1092 /* Let `cp_finish_decl' know that this initializer is ok. */
1093 DECL_INITIAL (decl
) = init
;
1094 if (doing_semantic_analysis_p ())
1096 if (!processing_template_decl
)
1098 cp_finish_decl (decl
, init
, NULL_TREE
, 0);
1099 add_stmt (build_stmt (RETURN_INIT
, NULL_TREE
, NULL_TREE
));
1102 add_stmt (build_stmt (RETURN_INIT
, return_id
, init
));
1105 /* Don't use tree-inlining for functions with named return values.
1106 That doesn't work properly because we don't do any translation of
1107 the RETURN_INITs when they are copied. */
1108 DECL_UNINLINABLE (current_function_decl
) = 1;
1111 /* The INIT_LIST is a list of mem-initializers, in the order they were
1112 written by the user. The TREE_VALUE of each node is a list of
1113 initializers for a particular subobject. The TREE_PURPOSE is a
1114 FIELD_DECL is the initializer is for a non-static data member, and
1115 a class type if the initializer is for a base class. */
1118 finish_mem_initializers (init_list
)
1121 tree member_init_list
;
1122 tree base_init_list
;
1123 tree last_base_warned_about
;
1127 member_init_list
= NULL_TREE
;
1128 base_init_list
= NULL_TREE
;
1129 last_base_warned_about
= NULL_TREE
;
1131 for (init
= init_list
; init
; init
= next
)
1133 next
= TREE_CHAIN (init
);
1134 if (TREE_CODE (TREE_PURPOSE (init
)) == FIELD_DECL
)
1136 TREE_CHAIN (init
) = member_init_list
;
1137 member_init_list
= init
;
1139 /* We're running through the initializers from right to left
1140 as we process them here. So, if we see a data member
1141 initializer after we see a base initializer, that
1142 actually means that the base initializer preceeded the
1143 data member initializer. */
1144 if (warn_reorder
&& last_base_warned_about
!= base_init_list
)
1148 for (base
= base_init_list
;
1149 base
!= last_base_warned_about
;
1150 base
= TREE_CHAIN (base
))
1152 cp_warning ("base initializer for `%T'",
1153 TREE_PURPOSE (base
));
1154 warning (" will be re-ordered to precede member initializations");
1157 last_base_warned_about
= base_init_list
;
1162 TREE_CHAIN (init
) = base_init_list
;
1163 base_init_list
= init
;
1167 setup_vtbl_ptr (member_init_list
, base_init_list
);
1170 /* Cache the value of this class's main virtual function table pointer
1171 in a register variable. This will save one indirection if a
1172 more than one virtual function call is made this function. */
1175 setup_vtbl_ptr (member_init_list
, base_init_list
)
1176 tree member_init_list
;
1177 tree base_init_list
;
1179 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1181 /* If we've already done this, there's no need to do it again. */
1185 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1187 if (processing_template_decl
)
1188 add_stmt (build_min_nt
1190 member_init_list
, base_init_list
));
1195 /* Mark the beginning of the constructor. */
1196 ctor_stmt
= build_stmt (CTOR_STMT
);
1197 CTOR_BEGIN_P (ctor_stmt
) = 1;
1198 add_stmt (ctor_stmt
);
1200 /* And actually initialize the base-classes and members. */
1201 emit_base_init (member_init_list
, base_init_list
);
1204 else if (DECL_DESTRUCTOR_P (current_function_decl
)
1205 && !processing_template_decl
)
1211 /* If the dtor is empty, and we know there is not any possible
1212 way we could use any vtable entries, before they are possibly
1213 set by a base class dtor, we don't have to setup the vtables,
1214 as we know that any base class dtor will set up any vtables
1215 it needs. We avoid MI, because one base class dtor can do a
1216 virtual dispatch to an overridden function that would need to
1217 have a non-related vtable set up, we cannot avoid setting up
1218 vtables in that case. We could change this to see if there
1219 is just one vtable. */
1220 if_stmt
= begin_if_stmt ();
1222 /* If it is not safe to avoid setting up the vtables, then
1223 someone will change the condition to be boolean_true_node.
1224 (Actually, for now, we do not have code to set the condition
1225 appropriately, so we just assume that we always need to
1226 initialize the vtables.) */
1227 finish_if_stmt_cond (boolean_true_node
, if_stmt
);
1228 current_vcalls_possible_p
= &IF_COND (if_stmt
);
1230 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1231 open the block for the if-body. */
1232 saved_cfnd
= current_function_name_declared ();
1233 cp_function_chain
->name_declared
= 1;
1234 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
1235 cp_function_chain
->name_declared
= saved_cfnd
;
1237 /* Make all virtual function table pointers in non-virtual base
1238 classes point to CURRENT_CLASS_TYPE's virtual function
1240 initialize_vtbl_ptrs (current_class_ptr
);
1242 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
1243 finish_then_clause (if_stmt
);
1247 /* Always keep the BLOCK node associated with the outermost pair of
1248 curly braces of a function. These are needed for correct
1249 operation of dwarfout.c. */
1250 keep_next_level (1);
1252 /* The virtual function tables are set up now. */
1257 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
1258 whether this statements opens or closes a scope. PARTIAL_P is true
1259 for a partial scope, i.e, the scope that begins after a label when
1260 an object that needs a cleanup is created. If BEGIN_P is nonzero,
1261 returns a new TREE_LIST representing the top of the SCOPE_STMT
1262 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
1263 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
1264 and whose TREE_PURPOSE is the matching SCOPE_STMT iwth
1265 SCOPE_BEGIN_P set. */
1268 add_scope_stmt (begin_p
, partial_p
)
1275 /* Build the statement. */
1276 ss
= build_stmt (SCOPE_STMT
, NULL_TREE
);
1277 SCOPE_BEGIN_P (ss
) = begin_p
;
1278 SCOPE_PARTIAL_P (ss
) = partial_p
;
1280 /* Keep the scope stack up to date. */
1283 current_scope_stmt_stack
1284 = tree_cons (ss
, NULL_TREE
, current_scope_stmt_stack
);
1285 top
= current_scope_stmt_stack
;
1289 top
= current_scope_stmt_stack
;
1290 TREE_VALUE (top
) = ss
;
1291 current_scope_stmt_stack
= TREE_CHAIN (top
);
1294 /* Add the new statement to the statement-tree. */
1300 /* Finish a parenthesized expression EXPR. */
1303 finish_parenthesized_expr (expr
)
1306 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1307 /* This inhibits warnings in truthvalue_conversion. */
1308 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1310 if (TREE_CODE (expr
) == OFFSET_REF
)
1311 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1312 enclosed in parentheses. */
1313 PTRMEM_OK_P (expr
) = 0;
1317 /* Begin a statement-expression. The value returned must be passed to
1318 finish_stmt_expr. */
1323 /* If we're outside a function, we won't have a statement-tree to
1324 work with. But, if we see a statement-expression we need to
1326 if (! cfun
&& !last_tree
)
1327 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1329 keep_next_level (1);
1330 /* If we're building a statement tree, then the upcoming compound
1331 statement will be chained onto the tree structure, starting at
1332 last_tree. We return last_tree so that we can later unhook the
1333 compound statement. */
1337 /* Used when beginning a statement-expression outside function scope.
1338 For example, when handling a file-scope initializer, we use this
1342 begin_global_stmt_expr ()
1344 if (! cfun
&& !last_tree
)
1345 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1347 keep_next_level (1);
1349 return (last_tree
!= NULL_TREE
) ? last_tree
: expand_start_stmt_expr();
1352 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1355 finish_global_stmt_expr (stmt_expr
)
1358 stmt_expr
= expand_end_stmt_expr (stmt_expr
);
1361 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1362 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1367 /* Finish a statement-expression. RTL_EXPR should be the value
1368 returned by the previous begin_stmt_expr; EXPR is the
1369 statement-expression. Returns an expression representing the
1370 statement-expression. */
1373 finish_stmt_expr (rtl_expr
)
1378 /* If the last thing in the statement-expression was not an
1379 expression-statement, then it has type `void'. */
1380 if (!last_expr_type
)
1381 last_expr_type
= void_type_node
;
1382 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1383 TREE_SIDE_EFFECTS (result
) = 1;
1385 /* Remove the compound statement from the tree structure; it is
1386 now saved in the STMT_EXPR. */
1387 last_tree
= rtl_expr
;
1388 TREE_CHAIN (last_tree
) = NULL_TREE
;
1390 /* If we created a statement-tree for this statement-expression,
1393 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1394 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1399 /* Finish a call to FN with ARGS. Returns a representation of the
1403 finish_call_expr (fn
, args
, koenig
)
1412 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1413 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1414 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1415 fn
= do_identifier (fn
, 2, args
);
1417 result
= build_x_function_call (fn
, args
, current_class_ref
);
1419 if (TREE_CODE (result
) == CALL_EXPR
1420 && (! TREE_TYPE (result
)
1421 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1422 result
= require_complete_type (result
);
1427 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1428 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1429 POSTDECREMENT_EXPR.) */
1432 finish_increment_expr (expr
, code
)
1434 enum tree_code code
;
1436 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1437 a COMPONENT_REF). This way if we've got, say, a reference to a
1438 static member that's being operated on, we don't end up trying to
1439 find a member operator for the class it's in. */
1441 if (TREE_CODE (expr
) == OFFSET_REF
)
1442 expr
= resolve_offset_ref (expr
);
1443 return build_x_unary_op (code
, expr
);
1446 /* Finish a use of `this'. Returns an expression for `this'. */
1453 if (current_class_ptr
)
1455 #ifdef WARNING_ABOUT_CCD
1456 TREE_USED (current_class_ptr
) = 1;
1458 result
= current_class_ptr
;
1460 else if (current_function_decl
1461 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1463 error ("`this' is unavailable for static member functions");
1464 result
= error_mark_node
;
1468 if (current_function_decl
)
1469 error ("invalid use of `this' in non-member function");
1471 error ("invalid use of `this' at top level");
1472 result
= error_mark_node
;
1478 /* Finish a member function call using OBJECT and ARGS as arguments to
1479 FN. Returns an expression for the call. */
1482 finish_object_call_expr (fn
, object
, args
)
1488 /* This is a future direction of this code, but because
1489 build_x_function_call cannot always undo what is done in
1490 build_component_ref entirely yet, we cannot do this. */
1492 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1493 return finish_call_expr (real_fn
, args
);
1495 if (DECL_DECLARES_TYPE_P (fn
))
1497 if (processing_template_decl
)
1498 /* This can happen on code like:
1501 template <class T> void f(T t) {
1505 We just grab the underlying IDENTIFIER. */
1506 fn
= DECL_NAME (fn
);
1509 cp_error ("calling type `%T' like a method", fn
);
1510 return error_mark_node
;
1514 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1518 /* Finish a qualified member function call using OBJECT and ARGS as
1519 arguments to FN. Returns an expressino for the call. */
1522 finish_qualified_object_call_expr (fn
, object
, args
)
1527 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1528 TREE_OPERAND (fn
, 1), args
);
1531 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1532 being the scope, if any, of DESTRUCTOR. Returns an expression for
1536 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1541 if (processing_template_decl
)
1542 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1544 if (scope
&& scope
!= destructor
)
1545 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1548 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1549 && (TREE_CODE (TREE_TYPE (object
)) !=
1550 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1551 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1553 return cp_convert (void_type_node
, object
);
1556 /* Finish a call to a globally qualified member function FN using
1557 ARGS. Returns an expression for the call. */
1560 finish_qualified_call_expr (fn
, args
)
1564 if (processing_template_decl
)
1565 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1567 return build_member_call (TREE_OPERAND (fn
, 0),
1568 TREE_OPERAND (fn
, 1),
1572 /* Finish an expression taking the address of LABEL. Returns an
1573 expression for the address. */
1576 finish_label_address_expr (label
)
1581 label
= lookup_label (label
);
1582 if (label
== NULL_TREE
)
1583 result
= null_pointer_node
;
1586 TREE_USED (label
) = 1;
1587 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1588 TREE_CONSTANT (result
) = 1;
1589 /* This function cannot be inlined. All jumps to the addressed
1590 label should wind up at the same point. */
1591 DECL_UNINLINABLE (current_function_decl
) = 1;
1597 /* Finish an expression of the form CODE EXPR. */
1600 finish_unary_op_expr (code
, expr
)
1601 enum tree_code code
;
1604 tree result
= build_x_unary_op (code
, expr
);
1605 /* Inside a template, build_x_unary_op does not fold the
1606 expression. So check whether the result is folded before
1607 setting TREE_NEGATED_INT. */
1608 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1609 && TREE_CODE (result
) == INTEGER_CST
1610 && !TREE_UNSIGNED (TREE_TYPE (result
))
1611 && INT_CST_LT (result
, integer_zero_node
))
1612 TREE_NEGATED_INT (result
) = 1;
1613 overflow_warning (result
);
1617 /* Finish an id-expression. */
1620 finish_id_expr (expr
)
1623 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1624 expr
= do_identifier (expr
, 1, NULL_TREE
);
1629 static tree current_type_lookups
;
1631 /* Perform deferred access control for types used in the type of a
1635 deferred_type_access_control ()
1637 tree lookup
= type_lookups
;
1639 if (lookup
== error_mark_node
)
1642 for (; lookup
; lookup
= TREE_CHAIN (lookup
))
1643 enforce_access (TREE_PURPOSE (lookup
), TREE_VALUE (lookup
));
1647 decl_type_access_control (decl
)
1652 if (type_lookups
== error_mark_node
)
1655 save_fn
= current_function_decl
;
1657 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
1658 current_function_decl
= decl
;
1660 deferred_type_access_control ();
1662 current_function_decl
= save_fn
;
1664 /* Now strip away the checks for the current declarator; they were
1665 added to type_lookups after typed_declspecs saved the copy that
1666 ended up in current_type_lookups. */
1667 type_lookups
= current_type_lookups
;
1671 save_type_access_control (lookups
)
1674 current_type_lookups
= lookups
;
1677 /* Begin a function definition declared with DECL_SPECS and
1678 DECLARATOR. Returns non-zero if the function-declaration is
1682 begin_function_definition (decl_specs
, declarator
)
1689 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1690 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1693 deferred_type_access_control ();
1694 type_lookups
= error_mark_node
;
1696 /* The things we're about to see are not directly qualified by any
1697 template headers we've seen thus far. */
1698 reset_specialization ();
1703 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1707 begin_constructor_declarator (scope
, name
)
1711 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1712 enter_scope_of (result
);
1716 /* Finish an init-declarator. Returns a DECL. */
1719 finish_declarator (declarator
, declspecs
, attributes
,
1720 prefix_attributes
, initialized
)
1724 tree prefix_attributes
;
1727 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1731 /* Finish a translation unit. */
1734 finish_translation_unit ()
1736 /* In case there were missing closebraces,
1737 get us back to the global binding level. */
1739 while (current_namespace
!= global_namespace
)
1744 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1745 Returns the parameter. */
1748 finish_template_type_parm (aggr
, identifier
)
1752 if (aggr
!= class_type_node
)
1754 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1755 aggr
= class_type_node
;
1758 return build_tree_list (aggr
, identifier
);
1761 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1762 Returns the parameter. */
1765 finish_template_template_parm (aggr
, identifier
)
1769 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1770 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1771 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1772 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1773 DECL_ARTIFICIAL (decl
) = 1;
1774 end_template_decl ();
1776 return finish_template_type_parm (aggr
, tmpl
);
1779 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1780 non-zero, the parameter list was terminated by a `...'. */
1783 finish_parmlist (parms
, ellipsis
)
1788 chainon (parms
, void_list_node
);
1789 /* We mark the PARMS as a parmlist so that declarator processing can
1790 disambiguate certain constructs. */
1791 if (parms
!= NULL_TREE
)
1792 TREE_PARMLIST (parms
) = 1;
1797 /* Begin a class definition, as indicated by T. */
1800 begin_class_definition (t
)
1803 if (t
== error_mark_node
1804 || ! IS_AGGR_TYPE (t
))
1806 t
= make_aggr_type (RECORD_TYPE
);
1807 pushtag (make_anon_name (), t
, 0);
1810 /* In a definition of a member class template, we will get here with an
1811 implicit typename, a TYPENAME_TYPE with a type. */
1812 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1815 /* If we generated a partial instantiation of this type, but now
1816 we're seeing a real definition, we're actually looking at a
1817 partial specialization. Consider:
1819 template <class T, class U>
1825 template <class T, class U>
1828 typename X<Y<T, U> >::A a;
1831 template <class T, class U>
1836 We have to undo the effects of the previous partial
1838 if (PARTIAL_INSTANTIATION_P (t
))
1842 /* Unfortunately, when we're not in pedantic mode, we
1843 attempt to actually fill in some of the fields of the
1844 partial instantiation, in order to support the implicit
1845 typename extension. Clear those fields now, in
1846 preparation for the definition here. The fields cleared
1847 here must match those set in instantiate_class_template.
1848 Look for a comment mentioning begin_class_definition
1850 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1851 TYPE_FIELDS (t
) = NULL_TREE
;
1852 TYPE_METHODS (t
) = NULL_TREE
;
1853 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1854 CLASSTYPE_VBASECLASSES (t
) = NULL_TREE
;
1855 TYPE_SIZE (t
) = NULL_TREE
;
1858 /* This isn't a partial instantiation any more. */
1859 PARTIAL_INSTANTIATION_P (t
) = 0;
1861 /* If this type was already complete, and we see another definition,
1863 else if (COMPLETE_TYPE_P (t
))
1864 duplicate_tag_error (t
);
1866 /* Update the location of the decl. */
1867 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1868 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1870 if (TYPE_BEING_DEFINED (t
))
1872 t
= make_aggr_type (TREE_CODE (t
));
1873 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1875 maybe_process_partial_specialization (t
);
1877 TYPE_BEING_DEFINED (t
) = 1;
1878 TYPE_PACKED (t
) = flag_pack_struct
;
1879 /* Reset the interface data, at the earliest possible
1880 moment, as it might have been set via a class foo;
1883 tree name
= TYPE_IDENTIFIER (t
);
1885 if (! ANON_AGGRNAME_P (name
))
1887 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1888 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1889 (t
, interface_unknown
);
1892 /* Only leave this bit clear if we know this
1893 class is part of an interface-only specification. */
1894 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1895 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1896 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1898 reset_specialization();
1900 /* Make a declaration for this class in its own scope. */
1901 build_self_reference ();
1906 /* Finish the member declaration given by DECL. */
1909 finish_member_declaration (decl
)
1912 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1915 if (decl
== void_type_node
)
1916 /* The COMPONENT was a friend, not a member, and so there's
1917 nothing for us to do. */
1920 /* We should see only one DECL at a time. */
1921 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1923 /* Set up access control for DECL. */
1925 = (current_access_specifier
== access_private_node
);
1926 TREE_PROTECTED (decl
)
1927 = (current_access_specifier
== access_protected_node
);
1928 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1930 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
1931 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
1934 /* Mark the DECL as a member of the current class. */
1935 DECL_CONTEXT (decl
) = current_class_type
;
1939 A C language linkage is ignored for the names of class members
1940 and the member function type of class member functions. */
1941 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
1942 DECL_LANGUAGE (decl
) = lang_cplusplus
;
1944 /* Put functions on the TYPE_METHODS list and everything else on the
1945 TYPE_FIELDS list. Note that these are built up in reverse order.
1946 We reverse them (to obtain declaration order) in finish_struct. */
1947 if (TREE_CODE (decl
) == FUNCTION_DECL
1948 || DECL_FUNCTION_TEMPLATE_P (decl
))
1950 /* We also need to add this function to the
1951 CLASSTYPE_METHOD_VEC. */
1952 add_method (current_class_type
, decl
, /*error_p=*/0);
1954 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1955 TYPE_METHODS (current_class_type
) = decl
;
1959 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1960 go at the beginning. The reason is that lookup_field_1
1961 searches the list in order, and we want a field name to
1962 override a type name so that the "struct stat hack" will
1963 work. In particular:
1965 struct S { enum E { }; int E } s;
1968 is legal. In addition, the FIELD_DECLs must be maintained in
1969 declaration order so that class layout works as expected.
1970 However, we don't need that order until class layout, so we
1971 save a little time by putting FIELD_DECLs on in reverse order
1972 here, and then reversing them in finish_struct_1. (We could
1973 also keep a pointer to the correct insertion points in the
1976 if (TREE_CODE (decl
) == TYPE_DECL
)
1977 TYPE_FIELDS (current_class_type
)
1978 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1981 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1982 TYPE_FIELDS (current_class_type
) = decl
;
1985 /* Enter the DECL into the scope of the class. */
1986 if (TREE_CODE (decl
) != USING_DECL
)
1987 pushdecl_class_level (decl
);
1991 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1992 the definition is immediately followed by a semicolon. Returns the
1996 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
2002 /* finish_struct nukes this anyway; if finish_exception does too,
2005 note_got_semicolon (t
);
2007 /* If we got any attributes in class_head, xref_tag will stick them in
2008 TREE_TYPE of the type. Grab them now. */
2009 attributes
= chainon (TREE_TYPE (t
), attributes
);
2010 TREE_TYPE (t
) = NULL_TREE
;
2012 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
2016 t
= finish_struct (t
, attributes
);
2018 note_got_semicolon (t
);
2022 check_for_missing_semicolon (t
);
2024 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
2025 if (current_scope () == current_function_decl
)
2026 do_pending_defargs ();
2031 /* Finish processing the default argument expressions cached during
2032 the processing of a class definition. */
2035 begin_inline_definitions ()
2037 if (current_scope () == current_function_decl
)
2038 do_pending_inlines ();
2041 /* Finish processing the inline function definitions cached during the
2042 processing of a class definition. */
2045 finish_inline_definitions ()
2047 if (current_class_type
== NULL_TREE
)
2048 clear_inline_text_obstack ();
2051 /* Finish processing the declaration of a member class template
2052 TYPES whose template parameters are given by PARMS. */
2055 finish_member_class_template (types
)
2060 /* If there are declared, but undefined, partial specializations
2061 mixed in with the typespecs they will not yet have passed through
2062 maybe_process_partial_specialization, so we do that here. */
2063 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
2064 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
2065 maybe_process_partial_specialization (TREE_VALUE (t
));
2067 note_list_got_semicolon (types
);
2068 grok_x_components (types
);
2069 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
2070 /* The component was in fact a friend declaration. We avoid
2071 finish_member_template_decl performing certain checks by
2075 finish_member_template_decl (types
);
2077 /* As with other component type declarations, we do
2078 not store the new DECL on the list of
2083 /* Finish processsing a complete template declaration. The PARMS are
2084 the template parameters. */
2087 finish_template_decl (parms
)
2091 end_template_decl ();
2093 end_specialization ();
2096 /* Finish processing a a template-id (which names a type) of the form
2097 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2098 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2099 the scope of template-id indicated. */
2102 finish_template_type (name
, args
, entering_scope
)
2109 decl
= lookup_template_class (name
, args
,
2110 NULL_TREE
, NULL_TREE
, entering_scope
);
2111 if (decl
!= error_mark_node
)
2112 decl
= TYPE_STUB_DECL (decl
);
2117 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2118 namespace scope or a class scope. */
2124 tree scope
= TREE_OPERAND (sr
, 0);
2126 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2128 push_decl_namespace (scope
);
2129 TREE_COMPLEXITY (sr
) = -1;
2131 else if (scope
!= current_class_type
)
2133 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2135 /* In a declarator for a template class member, the scope will
2136 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2137 scope
= TREE_TYPE (scope
);
2138 TREE_OPERAND (sr
, 0) = scope
;
2140 push_nested_class (scope
, 3);
2141 TREE_COMPLEXITY (sr
) = current_class_depth
;
2145 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2146 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2147 BASE_CLASS, or NULL_TREE if an error occurred. The
2148 ACCESSS_SPECIFIER is one of
2149 access_{default,public,protected_private}[_virtual]_node.*/
2152 finish_base_specifier (access_specifier
, base_class
)
2153 tree access_specifier
;
2159 if (base_class
== NULL_TREE
)
2161 error ("invalid base class");
2162 type
= error_mark_node
;
2165 type
= TREE_TYPE (base_class
);
2167 if (! is_aggr_type (type
, 1))
2170 result
= build_tree_list (access_specifier
, type
);
2175 /* Called when multiple declarators are processed. If that is not
2176 premitted in this context, an error is issued. */
2179 check_multiple_declarators ()
2183 In a template-declaration, explicit specialization, or explicit
2184 instantiation the init-declarator-list in the declaration shall
2185 contain at most one declarator.
2187 We don't just use PROCESSING_TEMPLATE_DECL for the first
2188 condition since that would disallow the perfectly legal code,
2189 like `template <class T> struct S { int i, j; };'. */
2190 tree scope
= current_scope ();
2192 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2193 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2196 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2197 || processing_explicit_instantiation
2198 || processing_specialization
)
2199 cp_error ("multiple declarators in template declaration");
2203 finish_typeof (expr
)
2206 if (processing_template_decl
)
2210 t
= make_aggr_type (TYPEOF_TYPE
);
2211 TYPE_FIELDS (t
) = expr
;
2216 return TREE_TYPE (expr
);
2219 /* We're about to expand T, a statement. Set up appropriate context
2220 for the substitution. */
2226 if (!STMT_LINENO_FOR_FN_P (t
))
2227 lineno
= STMT_LINENO (t
);
2228 current_stmt_tree ()->stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2231 /* Generate RTL for the statement T, and its substatements, and any
2232 other statements at its nesting level. */
2235 lang_expand_stmt (t
)
2238 tree rval
= NULL_TREE
;
2240 while (t
&& t
!= error_mark_node
)
2242 int saved_stmts_are_full_exprs_p
;
2244 /* Assume we'll have nothing to return. */
2247 /* Set up context appropriately for handling this statement. */
2248 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p ();
2251 switch (TREE_CODE (t
))
2254 genrtl_return_stmt (RETURN_EXPR (t
));
2258 genrtl_expr_stmt (EXPR_STMT_EXPR (t
));
2262 genrtl_decl_stmt (t
);
2266 genrtl_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2269 case START_CATCH_STMT
:
2270 genrtl_catch_block (TREE_TYPE (t
));
2274 genrtl_ctor_stmt (t
);
2278 genrtl_for_stmt (t
);
2282 genrtl_while_stmt (t
);
2294 genrtl_compound_stmt (t
);
2298 genrtl_break_stmt ();
2302 genrtl_continue_stmt ();
2306 genrtl_switch_stmt (t
);
2310 genrtl_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2314 expand_label (LABEL_STMT_LABEL (t
));
2318 genrtl_goto_stmt (GOTO_DESTINATION (t
));
2322 genrtl_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
),
2323 ASM_OUTPUTS (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2327 genrtl_try_block (t
);
2335 genrtl_subobject (SUBOBJECT_CLEANUP (t
));
2339 genrtl_scope_stmt (t
);
2343 genrtl_named_return_value ();
2347 my_friendly_abort (19990810);
2351 /* Restore saved state. */
2352 current_stmt_tree ()->stmts_are_full_exprs_p
=
2353 saved_stmts_are_full_exprs_p
;
2355 /* Go on to the next statement in this scope. */
2362 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2363 will equivalent CALL_EXPRs. */
2366 simplify_aggr_init_exprs_r (tp
, walk_subtrees
, data
)
2368 int *walk_subtrees ATTRIBUTE_UNUSED
;
2369 void *data ATTRIBUTE_UNUSED
;
2371 tree aggr_init_expr
;
2378 int copy_from_buffer_p
;
2380 aggr_init_expr
= *tp
;
2381 /* We don't need to walk into types; there's nothing in a type that
2382 needs simplification. (And, furthermore, there are places we
2383 actively don't want to go. For example, we don't want to wander
2384 into the default arguments for a FUNCTION_DECL that appears in a
2386 if (TYPE_P (aggr_init_expr
))
2391 /* Only AGGR_INIT_EXPRs are interesting. */
2392 else if (TREE_CODE (aggr_init_expr
) != AGGR_INIT_EXPR
)
2395 /* Form an appropriate CALL_EXPR. */
2396 fn
= TREE_OPERAND (aggr_init_expr
, 0);
2397 args
= TREE_OPERAND (aggr_init_expr
, 1);
2398 slot
= TREE_OPERAND (aggr_init_expr
, 2);
2399 type
= TREE_TYPE (aggr_init_expr
);
2401 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
2403 /* Replace the first argument with the address of the third
2404 argument to the AGGR_INIT_EXPR. */
2405 call_type
= build_pointer_type (type
);
2406 mark_addressable (slot
);
2407 args
= tree_cons (NULL_TREE
, build1 (ADDR_EXPR
, call_type
, slot
),
2410 call_expr
= build (CALL_EXPR
, call_type
, fn
, args
, NULL_TREE
);
2411 TREE_SIDE_EFFECTS (call_expr
) = 1;
2413 /* If we're using the non-reentrant PCC calling convention, then we
2414 need to copy the returned value out of the static buffer into the
2416 copy_from_buffer_p
= 0;
2417 #ifdef PCC_STATIC_STRUCT_RETURN
2418 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) && aggregate_value_p (type
))
2422 flag_access_control
= 0;
2423 call_expr
= build_aggr_init (slot
, call_expr
, LOOKUP_ONLYCONVERTING
);
2424 flag_access_control
= old_ac
;
2425 copy_from_buffer_p
= 1;
2429 /* If this AGGR_INIT_EXPR indicates the value returned by a
2430 function, then we want to use the value of the initialized
2431 location as the result. */
2432 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) || copy_from_buffer_p
)
2434 call_expr
= build (COMPOUND_EXPR
, type
,
2436 TREE_SIDE_EFFECTS (call_expr
) = 1;
2439 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2440 TREE_CHAIN (call_expr
) = TREE_CHAIN (aggr_init_expr
);
2443 /* Keep iterating. */
2447 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2450 emit_associated_thunks (fn
)
2453 /* When we use vcall offsets, we emit thunks with the virtual
2454 functions to which they thunk. The whole point of vcall offsets
2455 is so that you can know statically the entire set of thunks that
2456 will ever be needed for a given virtual function, thereby
2457 enabling you to output all the thunks with the function itself. */
2458 if (vcall_offsets_in_vtable_p () && DECL_VIRTUAL_P (fn
))
2463 for (binfo
= TYPE_BINFO (DECL_CONTEXT (fn
));
2465 binfo
= TREE_CHAIN (binfo
))
2466 for (v
= BINFO_VIRTUALS (binfo
); v
; v
= TREE_CHAIN (v
))
2468 && (!integer_zerop (BV_DELTA (v
))
2469 || BV_VCALL_INDEX (v
)))
2474 if (BV_USE_VCALL_INDEX_P (v
))
2476 vcall_index
= BV_VCALL_INDEX (v
);
2477 my_friendly_assert (vcall_index
!= NULL_TREE
, 20000621);
2480 vcall_index
= NULL_TREE
;
2482 thunk
= make_thunk (build1 (ADDR_EXPR
,
2483 vfunc_ptr_type_node
,
2487 /*generate_with_vtable_p=*/0);
2488 use_thunk (thunk
, /*emit_p=*/1);
2494 /* Generate RTL for FN. */
2501 const char *saved_input_filename
;
2503 /* When the parser calls us after finishing the body of a template
2504 function, we don't really want to expand the body. When we're
2505 processing an in-class definition of an inline function,
2506 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2507 to look at the function itself. */
2508 if (processing_template_decl
2509 || (DECL_LANG_SPECIFIC (fn
)
2510 && DECL_TEMPLATE_INFO (fn
)
2511 && uses_template_parms (DECL_TI_ARGS (fn
))))
2513 /* Normally, collection only occurs in rest_of_compilation. So,
2514 if we don't collect here, we never collect junk generated
2515 during the processing of templates until we hit a
2516 non-template function. */
2521 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2522 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn
),
2523 simplify_aggr_init_exprs_r
,
2526 /* If this is a constructor or destructor body, we have to clone it
2527 under the new ABI. */
2528 if (maybe_clone_body (fn
))
2530 /* We don't want to process FN again, so pretend we've written
2531 it out, even though we haven't. */
2532 TREE_ASM_WRITTEN (fn
) = 1;
2536 /* There's no reason to do any of the work here if we're only doing
2537 semantic analysis; this code just generates RTL. */
2538 if (flag_syntax_only
)
2541 /* If possible, avoid generating RTL for this function. Instead,
2542 just record it as an inline function, and wait until end-of-file
2543 to decide whether to write it out or not. */
2544 if (/* We have to generate RTL if it's not an inline function. */
2545 (DECL_INLINE (fn
) || DECL_COMDAT (fn
))
2546 /* Or if we have to keep all inline functions anyhow. */
2547 && !flag_keep_inline_functions
2548 /* Or if we actually have a reference to the function. */
2549 && !DECL_NEEDED_P (fn
)
2550 /* Or if this is a nested function. */
2551 && !decl_function_context (fn
))
2553 /* Give the function RTL now so that we can assign it to a
2554 function pointer, etc. */
2555 make_function_rtl (fn
);
2556 /* Set DECL_EXTERNAL so that assemble_external will be called as
2557 necessary. We'll clear it again in finish_file. */
2558 if (!DECL_EXTERNAL (fn
))
2560 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2561 DECL_EXTERNAL (fn
) = 1;
2563 /* Remember this function. In finish_file we'll decide if
2564 we actually need to write this function out. */
2566 /* Let the back-end know that this funtion exists. */
2567 note_deferral_of_defined_inline_function (fn
);
2571 /* Emit any thunks that should be emitted at the same time as FN. */
2572 emit_associated_thunks (fn
);
2574 timevar_push (TV_INTEGRATION
);
2576 /* Optimize the body of the function before expanding it. */
2577 optimize_function (fn
);
2579 timevar_pop (TV_INTEGRATION
);
2580 timevar_push (TV_EXPAND
);
2582 /* Save the current file name and line number. When we expand the
2583 body of the function, we'll set LINENO and INPUT_FILENAME so that
2584 error-mesages come out in the right places. */
2585 saved_lineno
= lineno
;
2586 saved_input_filename
= input_filename
;
2587 lineno
= DECL_SOURCE_LINE (fn
);
2588 input_filename
= DECL_SOURCE_FILE (fn
);
2590 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2591 store_parm_decls ();
2592 current_function_is_thunk
= DECL_THUNK_P (fn
);
2594 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2595 any of the other magic variables we set up when starting a
2597 cp_function_chain
->name_declared
= 1;
2599 /* Expand the body. */
2600 expand_stmt (DECL_SAVED_TREE (fn
));
2602 /* Statements should always be full-expressions at the outermost set
2603 of curly braces for a function. */
2604 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2606 /* The outermost statement for a function contains the line number
2607 recorded when we finished processing the function. */
2608 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2610 /* Generate code for the function. */
2611 finish_function (0);
2613 /* If possible, obliterate the body of the function so that it can
2614 be garbage collected. */
2615 if (flag_dump_translation_unit
)
2616 /* Keep the body; we're going to dump it. */
2618 else if (DECL_INLINE (fn
) && flag_inline_trees
)
2619 /* We might need the body of this function so that we can expand
2620 it inline somewhere else. */
2623 /* We don't need the body; blow it away. */
2624 DECL_SAVED_TREE (fn
) = NULL_TREE
;
2626 /* And restore the current source position. */
2627 lineno
= saved_lineno
;
2628 input_filename
= saved_input_filename
;
2629 extract_interface_info ();
2631 timevar_pop (TV_EXPAND
);