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
));
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 tree genrtl_do_poplevel
PARAMS ((void));
59 static void genrtl_named_return_value
PARAMS ((void));
60 static void cp_expand_stmt
PARAMS ((tree
));
62 /* When parsing a template, LAST_TREE contains the last statement
63 parsed. These are chained together through the TREE_CHAIN field,
64 but often need to be re-organized since the parse is performed
65 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
68 #define RECHAIN_STMTS(stmt, substmt) \
70 substmt = TREE_CHAIN (stmt); \
71 TREE_CHAIN (stmt) = NULL_TREE; \
75 /* Finish processing the COND, the SUBSTMT condition for STMT. */
77 #define FINISH_COND(cond, stmt, substmt) \
79 if (last_tree != stmt) \
81 RECHAIN_STMTS (stmt, substmt); \
82 if (!processing_template_decl) \
84 cond = build_tree_list (substmt, cond); \
92 /* Wrapper since C and C++ expand_expr_stmt are different. */
94 expand_expr_stmt_fn lang_expand_expr_stmt
= cplus_expand_expr_stmt
;
96 /* Wrapper function instead of #define for use with c-common code. */
99 set_current_function_name_declared (i
)
102 cp_function_chain
->name_declared
= i
;
105 /* Returns non-zero if the current statement is a full expression,
106 i.e. temporaries created during that statement should be destroyed
107 at the end of the statement. */
110 stmts_are_full_exprs_p ()
112 return current_stmt_tree ()->stmts_are_full_exprs_p
;
115 /* Returns the stmt_tree (if any) to which statements are currently
116 being added. If there is no active statement-tree, NULL is
123 ? &cfun
->language
->x_stmt_tree
124 : &scope_chain
->x_stmt_tree
);
127 /* One if we have already declared __FUNCTION__ (and related
128 variables) in the current function. Two if we are in the process
132 current_function_name_declared ()
134 return cp_function_chain
->name_declared
;
137 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
138 flag for this because "A union for which objects or pointers are
139 declared is not an anonymous union" [class.union]. */
142 anon_aggr_type_p (node
)
145 return (CLASS_TYPE_P (node
) && TYPE_LANG_SPECIFIC(node
)->anon_aggr
);
148 /* Finish a scope. */
153 tree block
= NULL_TREE
;
155 if (stmts_are_full_exprs_p ())
157 tree scope_stmts
= NULL_TREE
;
159 if (!processing_template_decl
)
160 scope_stmts
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
162 block
= poplevel (kept_level_p (), 1, 0);
163 if (block
&& !processing_template_decl
)
165 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts
)) = block
;
166 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts
)) = block
;
173 /* Begin a new scope. */
178 if (stmts_are_full_exprs_p ())
181 if (!processing_template_decl
)
182 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
186 /* Finish a goto-statement. */
189 finish_goto_stmt (destination
)
192 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
193 destination
= lookup_label (destination
);
195 /* We warn about unused labels with -Wunused. That means we have to
196 mark the used labels as used. */
197 if (TREE_CODE (destination
) == LABEL_DECL
)
198 TREE_USED (destination
) = 1;
200 if (TREE_CODE (destination
) != LABEL_DECL
)
201 /* We don't inline calls to functions with computed gotos.
202 Those functions are typically up to some funny business,
203 and may be depending on the labels being at particular
204 addresses, or some such. */
205 DECL_UNINLINABLE (current_function_decl
) = 1;
207 check_goto (destination
);
209 add_stmt (build_stmt (GOTO_STMT
, destination
));
212 /* COND is the condition-expression for an if, while, etc.,
213 statement. Convert it to a boolean value, if appropriate. */
216 maybe_convert_cond (cond
)
219 /* Empty conditions remain empty. */
223 /* Wait until we instantiate templates before doing conversion. */
224 if (processing_template_decl
)
227 /* Do the conversion. */
228 cond
= convert_from_reference (cond
);
229 return condition_conversion (cond
);
232 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
235 finish_expr_stmt (expr
)
238 if (expr
!= NULL_TREE
)
240 if (!processing_template_decl
241 && !(stmts_are_full_exprs_p ())
242 && ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
244 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
245 expr
= default_conversion (expr
);
247 if (stmts_are_full_exprs_p ())
248 expr
= convert_to_void (expr
, "statement");
250 if (!processing_template_decl
)
251 expr
= break_out_cleanups (expr
);
253 add_stmt (build_stmt (EXPR_STMT
, expr
));
258 /* This was an expression-statement, so we save the type of the
260 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
264 /* Begin an if-statement. Returns a newly created IF_STMT if
272 r
= build_stmt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
277 /* Process the COND of an if-statement, which may be given by
281 finish_if_stmt_cond (cond
, if_stmt
)
285 cond
= maybe_convert_cond (cond
);
286 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
289 /* Finish the then-clause of an if-statement, which may be given by
293 finish_then_clause (if_stmt
)
296 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
301 /* Begin the else-clause of an if-statement. */
308 /* Finish the else-clause of an if-statement, which may be given by
312 finish_else_clause (if_stmt
)
315 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
318 /* Finsh an if-statement. */
330 /* If COND wasn't a declaration, clear out the
331 block we made for it and start a new one here so the
332 optimization in expand_end_loop will work. */
333 if (getdecls () == NULL_TREE
)
340 /* Begin a while-statement. Returns a newly created WHILE_STMT if
347 r
= build_stmt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
353 /* Process the COND of a while-statement, which may be given by
357 finish_while_stmt_cond (cond
, while_stmt
)
361 cond
= maybe_convert_cond (cond
);
362 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
366 /* Finish a while-statement, which may be given by WHILE_STMT. */
369 finish_while_stmt (while_stmt
)
373 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
377 /* Begin a do-statement. Returns a newly created DO_STMT if
383 tree r
= build_stmt (DO_STMT
, NULL_TREE
, NULL_TREE
);
388 /* Finish the body of a do-statement, which may be given by DO_STMT. */
391 finish_do_body (do_stmt
)
394 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
397 /* Finish a do-statement, which may be given by DO_STMT, and whose
398 COND is as indicated. */
401 finish_do_stmt (cond
, do_stmt
)
405 cond
= maybe_convert_cond (cond
);
406 DO_COND (do_stmt
) = cond
;
410 /* Finish a return-statement. The EXPRESSION returned, if any, is as
414 finish_return_stmt (expr
)
417 if (!processing_template_decl
)
418 expr
= check_return_expr (expr
);
419 if (!processing_template_decl
)
421 if (DECL_CONSTRUCTOR_P (current_function_decl
) && ctor_label
)
423 /* Even returns without a value in a constructor must return
424 `this'. We accomplish this by sending all returns in a
425 constructor to the CTOR_LABEL; finish_function emits code to
426 return a value there. When we finally generate the real
427 return statement, CTOR_LABEL is no longer set, and we fall
428 through into the normal return-processing code below. */
429 finish_goto_stmt (ctor_label
);
432 else if (DECL_DESTRUCTOR_P (current_function_decl
))
434 /* Similarly, all destructors must run destructors for
435 base-classes before returning. So, all returns in a
436 destructor get sent to the DTOR_LABEL; finsh_function emits
437 code to return a value there. */
438 finish_goto_stmt (dtor_label
);
442 add_stmt (build_stmt (RETURN_STMT
, expr
));
446 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
453 r
= build_stmt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
454 NULL_TREE
, NULL_TREE
);
455 NEW_FOR_SCOPE_P (r
) = flag_new_for_scope
> 0;
457 if (NEW_FOR_SCOPE_P (r
))
460 note_level_for_for ();
466 /* Finish the for-init-statement of a for-statement, which may be
467 given by FOR_STMT. */
470 finish_for_init_stmt (for_stmt
)
473 if (last_tree
!= for_stmt
)
474 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
478 /* Finish the COND of a for-statement, which may be given by
482 finish_for_cond (cond
, for_stmt
)
486 cond
= maybe_convert_cond (cond
);
487 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
491 /* Finish the increment-EXPRESSION in a for-statement, which may be
492 given by FOR_STMT. */
495 finish_for_expr (expr
, for_stmt
)
499 FOR_EXPR (for_stmt
) = expr
;
502 /* Finish the body of a for-statement, which may be given by
503 FOR_STMT. The increment-EXPR for the loop must be
507 finish_for_stmt (for_stmt
)
510 /* Pop the scope for the body of the loop. */
512 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
513 if (NEW_FOR_SCOPE_P (for_stmt
))
518 /* Finish a break-statement. */
523 add_stmt (build_stmt (BREAK_STMT
));
526 /* Finish a continue-statement. */
529 finish_continue_stmt ()
531 add_stmt (build_stmt (CONTINUE_STMT
));
534 /* Begin a switch-statement. Returns a new SWITCH_STMT if
541 r
= build_stmt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
547 /* Finish the cond of a switch-statement. */
550 finish_switch_cond (cond
, switch_stmt
)
554 if (!processing_template_decl
)
556 /* Convert the condition to an integer or enumeration type. */
557 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, 1);
558 if (cond
== NULL_TREE
)
560 error ("switch quantity not an integer");
561 cond
= error_mark_node
;
563 if (cond
!= error_mark_node
)
565 cond
= default_conversion (cond
);
566 cond
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (cond
), cond
));
569 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
573 /* Finish the body of a switch-statement, which may be given by
574 SWITCH_STMT. The COND to switch on is indicated. */
577 finish_switch_stmt (switch_stmt
)
580 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
586 /* Finish a case-label. */
589 finish_case_label (low_value
, high_value
)
593 /* Add a representation for the case label to the statement
595 add_stmt (build_stmt (CASE_LABEL
, low_value
, high_value
));
596 /* And warn about crossing initializations, etc. */
597 if (!processing_template_decl
)
598 define_case_label ();
601 /* Generate the RTL for T, which is a TRY_BLOCK. */
609 expand_eh_region_start ();
610 expand_stmt (TRY_STMTS (t
));
611 expand_eh_region_end (protect_with_terminate (TRY_HANDLERS (t
)));
615 if (FN_TRY_BLOCK_P (t
))
617 if (! current_function_parms_stored
)
619 expand_start_early_try_stmts ();
623 emit_line_note (input_filename
, lineno
);
624 expand_start_try_stmts ();
627 expand_stmt (TRY_STMTS (t
));
629 if (FN_TRY_BLOCK_P (t
))
631 end_protect_partials ();
632 expand_start_all_catch ();
633 in_function_try_handler
= 1;
634 expand_stmt (TRY_HANDLERS (t
));
635 in_function_try_handler
= 0;
636 expand_end_all_catch ();
640 expand_start_all_catch ();
641 expand_stmt (TRY_HANDLERS (t
));
642 expand_end_all_catch ();
647 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
653 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
658 /* Likewise, for a function-try-block. */
661 begin_function_try_block ()
663 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
664 FN_TRY_BLOCK_P (r
) = 1;
669 /* Finish a try-block, which may be given by TRY_BLOCK. */
672 finish_try_block (try_block
)
675 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
678 /* Finish the body of a cleanup try-block, which may be given by
682 finish_cleanup_try_block (try_block
)
685 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
688 /* Finish an implicitly generated try-block, with a cleanup is given
692 finish_cleanup (cleanup
, try_block
)
696 TRY_HANDLERS (try_block
) = cleanup
;
697 CLEANUP_P (try_block
) = 1;
700 /* Likewise, for a function-try-block. */
703 finish_function_try_block (try_block
)
706 if (TREE_CHAIN (try_block
)
707 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
709 /* Chain the compound statement after the CTOR_INITIALIZER. */
710 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
711 /* And make the CTOR_INITIALIZER the body of the try-block. */
712 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
715 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
716 in_function_try_handler
= 1;
719 /* Finish a handler-sequence for a try-block, which may be given by
723 finish_handler_sequence (try_block
)
726 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
727 check_handlers (TRY_HANDLERS (try_block
));
730 /* Likewise, for a function-try-block. */
733 finish_function_handler_sequence (try_block
)
736 in_function_try_handler
= 0;
737 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
738 check_handlers (TRY_HANDLERS (try_block
));
741 /* Generate the RTL for T, which is a HANDLER. */
747 genrtl_do_pushlevel ();
748 expand_stmt (HANDLER_BODY (t
));
749 if (!processing_template_decl
)
751 /* Fall to outside the try statement when done executing
752 handler and we fall off end of handler. This is jump
753 Lresume in the documentation. */
754 expand_goto (top_label_entry (&caught_return_label_stack
));
755 end_catch_handler ();
759 /* Begin a handler. Returns a HANDLER if appropriate. */
765 r
= build_stmt (HANDLER
, NULL_TREE
, NULL_TREE
);
771 /* Finish the handler-parameters for a handler, which may be given by
772 HANDLER. DECL is the declaration for the catch parameter, or NULL
773 if this is a `catch (...)' clause. */
776 finish_handler_parms (decl
, handler
)
780 tree blocks
= NULL_TREE
;
782 if (processing_template_decl
)
786 decl
= pushdecl (decl
);
787 decl
= push_template_decl (decl
);
788 add_decl_stmt (decl
);
789 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
793 blocks
= expand_start_catch_block (decl
);
796 TREE_TYPE (handler
) = TREE_TYPE (decl
);
801 /* Generate the RTL for a CATCH_BLOCK. */
804 genrtl_catch_block (type
)
807 start_catch_handler (type
);
810 /* Note the beginning of a handler for TYPE. This function is called
811 at the point to which control should be transferred when an
812 appropriately-typed exception is thrown. */
815 begin_catch_block (type
)
818 add_stmt (build (START_CATCH_STMT
, type
));
821 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
822 the return value from the matching call to finish_handler_parms. */
825 finish_handler (blocks
, handler
)
829 if (!processing_template_decl
)
830 expand_end_catch_block (blocks
);
832 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
835 /* Generate the RTL for T, which is a CTOR_STMT. */
841 if (CTOR_BEGIN_P (t
))
842 begin_protect_partials ();
844 /* After this point, any exceptions will cause the
845 destructor to be executed, so we no longer need to worry
846 about destroying the various subobjects ourselves. */
847 end_protect_partials ();
850 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
851 compound-statement does not define a scope. Returns a new
852 COMPOUND_STMT if appropriate. */
855 begin_compound_stmt (has_no_scope
)
861 r
= build_stmt (COMPOUND_STMT
, NULL_TREE
);
863 if (last_tree
&& TREE_CODE (last_tree
) == TRY_BLOCK
)
868 COMPOUND_STMT_NO_SCOPE (r
) = 1;
870 last_expr_type
= NULL_TREE
;
876 note_level_for_eh ();
879 /* Normally, we try hard to keep the BLOCK for a
880 statement-expression. But, if it's a statement-expression with
881 a scopeless block, there's nothing to keep, and we don't want
882 to accidentally keep a block *inside* the scopeless block. */
885 /* If this is the outermost block of the function, declare the
886 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
888 && !(current_function_name_declared () )
891 cp_function_chain
->name_declared
= 1;
892 declare_function_name ();
898 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
899 If HAS_NO_SCOPE is non-zero, the compound statement does not define
903 finish_compound_stmt (has_no_scope
, compound_stmt
)
915 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
917 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
918 the precise purpose of that variable is store the type of the
919 last expression statement within the last compound statement, we
920 preserve the value. */
928 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
929 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
933 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
934 input_operands
, clobbers
)
937 tree output_operands
;
944 if (TREE_CHAIN (string
))
945 string
= combine_strings (string
);
947 if (cv_qualifier
!= NULL_TREE
948 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
950 cp_warning ("%s qualifier ignored on asm",
951 IDENTIFIER_POINTER (cv_qualifier
));
952 cv_qualifier
= NULL_TREE
;
955 if (!processing_template_decl
)
956 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
957 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
959 r
= build_stmt (ASM_STMT
, cv_qualifier
, string
,
960 output_operands
, input_operands
,
965 /* Finish a label with the indicated NAME. */
968 finish_label_stmt (name
)
971 tree decl
= define_label (input_filename
, lineno
, name
);
972 add_stmt (build_stmt (LABEL_STMT
, decl
));
975 /* Finish a series of declarations for local labels. G++ allows users
976 to declare "local" labels, i.e., labels with scope. This extension
977 is useful when writing code involving statement-expressions. */
980 finish_label_decl (name
)
983 tree decl
= declare_local_label (name
);
984 add_decl_stmt (decl
);
987 /* Create a declaration statement for the declaration given by the
996 /* We need the type to last until instantiation time. */
997 decl_stmt
= build_stmt (DECL_STMT
, decl
);
998 add_stmt (decl_stmt
);
1001 /* Generate the RTL for a SUBOBJECT. */
1004 genrtl_subobject (cleanup
)
1007 add_partial_entry (cleanup
);
1010 /* We're in a constructor, and have just constructed a a subobject of
1011 *THIS. CLEANUP is code to run if an exception is thrown before the
1012 end of the current function is reached. */
1015 finish_subobject (cleanup
)
1018 tree r
= build_stmt (SUBOBJECT
, cleanup
);
1022 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1025 finish_decl_cleanup (decl
, cleanup
)
1029 add_stmt (build_stmt (CLEANUP_STMT
, decl
, cleanup
));
1032 /* Generate the RTL for a RETURN_INIT. */
1035 genrtl_named_return_value ()
1039 decl
= DECL_RESULT (current_function_decl
);
1041 emit_local_var (decl
);
1043 /* If this named return value comes in a register, put it in a
1045 if (DECL_REGISTER (decl
))
1047 original_result_rtx
= DECL_RTL (decl
);
1048 /* Note that the mode of the old DECL_RTL may be wider than the
1049 mode of DECL_RESULT, depending on the calling conventions for
1050 the processor. For example, on the Alpha, a 32-bit integer
1051 is returned in a DImode register -- the DECL_RESULT has
1052 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
1053 here, we use the mode the back-end has already assigned for
1054 the return value. */
1055 DECL_RTL (decl
) = gen_reg_rtx (GET_MODE (original_result_rtx
));
1056 if (TREE_ADDRESSABLE (decl
))
1057 put_var_into_stack (decl
);
1061 /* Bind a name and initialization to the return value of
1062 the current function. */
1065 finish_named_return_value (return_id
, init
)
1066 tree return_id
, init
;
1068 tree decl
= DECL_RESULT (current_function_decl
);
1070 /* Give this error as many times as there are occurrences, so that
1071 users can use Emacs compilation buffers to find and fix all such
1074 pedwarn ("ISO C++ does not permit named return values");
1075 cp_deprecated ("the named return value extension");
1077 if (return_id
!= NULL_TREE
)
1079 if (DECL_NAME (decl
) == NULL_TREE
)
1081 DECL_NAME (decl
) = return_id
;
1082 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1086 cp_error ("return identifier `%D' already in place", return_id
);
1091 /* Can't let this happen for constructors. */
1092 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1094 error ("can't redefine default return value for constructors");
1098 /* If we have a named return value, put that in our scope as well. */
1099 if (DECL_NAME (decl
) != NULL_TREE
)
1101 /* Let `cp_finish_decl' know that this initializer is ok. */
1102 DECL_INITIAL (decl
) = init
;
1103 if (doing_semantic_analysis_p ())
1105 if (!processing_template_decl
)
1107 cp_finish_decl (decl
, init
, NULL_TREE
, 0);
1108 add_stmt (build_stmt (RETURN_INIT
, NULL_TREE
, NULL_TREE
));
1111 add_stmt (build_stmt (RETURN_INIT
, return_id
, init
));
1114 /* Don't use tree-inlining for functions with named return values.
1115 That doesn't work properly because we don't do any translation of
1116 the RETURN_INITs when they are copied. */
1117 DECL_UNINLINABLE (current_function_decl
) = 1;
1120 /* The INIT_LIST is a list of mem-initializers, in the order they were
1121 written by the user. The TREE_VALUE of each node is a list of
1122 initializers for a particular subobject. The TREE_PURPOSE is a
1123 FIELD_DECL is the initializer is for a non-static data member, and
1124 a class type if the initializer is for a base class. */
1127 finish_mem_initializers (init_list
)
1130 tree member_init_list
;
1131 tree base_init_list
;
1132 tree last_base_warned_about
;
1136 member_init_list
= NULL_TREE
;
1137 base_init_list
= NULL_TREE
;
1138 last_base_warned_about
= NULL_TREE
;
1140 for (init
= init_list
; init
; init
= next
)
1142 next
= TREE_CHAIN (init
);
1143 if (TREE_CODE (TREE_PURPOSE (init
)) == FIELD_DECL
)
1145 TREE_CHAIN (init
) = member_init_list
;
1146 member_init_list
= init
;
1148 /* We're running through the initializers from right to left
1149 as we process them here. So, if we see a data member
1150 initializer after we see a base initializer, that
1151 actually means that the base initializer preceeded the
1152 data member initializer. */
1153 if (warn_reorder
&& last_base_warned_about
!= base_init_list
)
1157 for (base
= base_init_list
;
1158 base
!= last_base_warned_about
;
1159 base
= TREE_CHAIN (base
))
1161 cp_warning ("base initializer for `%T'",
1162 TREE_PURPOSE (base
));
1163 warning (" will be re-ordered to precede member initializations");
1166 last_base_warned_about
= base_init_list
;
1171 TREE_CHAIN (init
) = base_init_list
;
1172 base_init_list
= init
;
1176 setup_vtbl_ptr (member_init_list
, base_init_list
);
1179 /* Cache the value of this class's main virtual function table pointer
1180 in a register variable. This will save one indirection if a
1181 more than one virtual function call is made this function. */
1184 setup_vtbl_ptr (member_init_list
, base_init_list
)
1185 tree member_init_list
;
1186 tree base_init_list
;
1188 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1190 /* If we've already done this, there's no need to do it again. */
1194 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1196 if (processing_template_decl
)
1197 add_stmt (build_min_nt
1199 member_init_list
, base_init_list
));
1204 /* Mark the beginning of the constructor. */
1205 ctor_stmt
= build_stmt (CTOR_STMT
);
1206 CTOR_BEGIN_P (ctor_stmt
) = 1;
1207 add_stmt (ctor_stmt
);
1209 /* And actually initialize the base-classes and members. */
1210 emit_base_init (member_init_list
, base_init_list
);
1213 else if (DECL_DESTRUCTOR_P (current_function_decl
)
1214 && !processing_template_decl
)
1220 /* If the dtor is empty, and we know there is not any possible
1221 way we could use any vtable entries, before they are possibly
1222 set by a base class dtor, we don't have to setup the vtables,
1223 as we know that any base class dtor will set up any vtables
1224 it needs. We avoid MI, because one base class dtor can do a
1225 virtual dispatch to an overridden function that would need to
1226 have a non-related vtable set up, we cannot avoid setting up
1227 vtables in that case. We could change this to see if there
1228 is just one vtable. */
1229 if_stmt
= begin_if_stmt ();
1231 /* If it is not safe to avoid setting up the vtables, then
1232 someone will change the condition to be boolean_true_node.
1233 (Actually, for now, we do not have code to set the condition
1234 appropriately, so we just assume that we always need to
1235 initialize the vtables.) */
1236 finish_if_stmt_cond (boolean_true_node
, if_stmt
);
1237 current_vcalls_possible_p
= &IF_COND (if_stmt
);
1239 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1240 open the block for the if-body. */
1241 saved_cfnd
= current_function_name_declared ();
1242 cp_function_chain
->name_declared
= 1;
1243 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
1244 cp_function_chain
->name_declared
= saved_cfnd
;
1246 /* Make all virtual function table pointers in non-virtual base
1247 classes point to CURRENT_CLASS_TYPE's virtual function
1249 initialize_vtbl_ptrs (current_class_ptr
);
1251 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
1252 finish_then_clause (if_stmt
);
1256 /* Always keep the BLOCK node associated with the outermost pair of
1257 curly braces of a function. These are needed for correct
1258 operation of dwarfout.c. */
1259 keep_next_level (1);
1261 /* The virtual function tables are set up now. */
1266 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
1267 whether this statements opens or closes a scope. PARTIAL_P is true
1268 for a partial scope, i.e, the scope that begins after a label when
1269 an object that needs a cleanup is created. If BEGIN_P is nonzero,
1270 returns a new TREE_LIST representing the top of the SCOPE_STMT
1271 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
1272 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
1273 and whose TREE_PURPOSE is the matching SCOPE_STMT iwth
1274 SCOPE_BEGIN_P set. */
1277 add_scope_stmt (begin_p
, partial_p
)
1284 /* Build the statement. */
1285 ss
= build_stmt (SCOPE_STMT
, NULL_TREE
);
1286 SCOPE_BEGIN_P (ss
) = begin_p
;
1287 SCOPE_PARTIAL_P (ss
) = partial_p
;
1289 /* Keep the scope stack up to date. */
1292 current_scope_stmt_stack
1293 = tree_cons (ss
, NULL_TREE
, current_scope_stmt_stack
);
1294 top
= current_scope_stmt_stack
;
1298 top
= current_scope_stmt_stack
;
1299 TREE_VALUE (top
) = ss
;
1300 current_scope_stmt_stack
= TREE_CHAIN (top
);
1303 /* Add the new statement to the statement-tree. */
1309 /* Finish a parenthesized expression EXPR. */
1312 finish_parenthesized_expr (expr
)
1315 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1316 /* This inhibits warnings in truthvalue_conversion. */
1317 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1319 if (TREE_CODE (expr
) == OFFSET_REF
)
1320 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1321 enclosed in parentheses. */
1322 PTRMEM_OK_P (expr
) = 0;
1326 /* Begin a statement-expression. The value returned must be passed to
1327 finish_stmt_expr. */
1332 /* If we're outside a function, we won't have a statement-tree to
1333 work with. But, if we see a statement-expression we need to
1335 if (! cfun
&& !last_tree
)
1336 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1338 keep_next_level (1);
1339 /* If we're building a statement tree, then the upcoming compound
1340 statement will be chained onto the tree structure, starting at
1341 last_tree. We return last_tree so that we can later unhook the
1342 compound statement. */
1346 /* Used when beginning a statement-expression outside function scope.
1347 For example, when handling a file-scope initializer, we use this
1351 begin_global_stmt_expr ()
1353 if (! cfun
&& !last_tree
)
1354 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1356 keep_next_level (1);
1358 return (last_tree
!= NULL_TREE
) ? last_tree
: expand_start_stmt_expr();
1361 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1364 finish_global_stmt_expr (stmt_expr
)
1367 stmt_expr
= expand_end_stmt_expr (stmt_expr
);
1370 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1371 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1376 /* Finish a statement-expression. RTL_EXPR should be the value
1377 returned by the previous begin_stmt_expr; EXPR is the
1378 statement-expression. Returns an expression representing the
1379 statement-expression. */
1382 finish_stmt_expr (rtl_expr
)
1387 /* If the last thing in the statement-expression was not an
1388 expression-statement, then it has type `void'. */
1389 if (!last_expr_type
)
1390 last_expr_type
= void_type_node
;
1391 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1392 TREE_SIDE_EFFECTS (result
) = 1;
1394 /* Remove the compound statement from the tree structure; it is
1395 now saved in the STMT_EXPR. */
1396 last_tree
= rtl_expr
;
1397 TREE_CHAIN (last_tree
) = NULL_TREE
;
1399 /* If we created a statement-tree for this statement-expression,
1402 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1403 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1408 /* Finish a call to FN with ARGS. Returns a representation of the
1412 finish_call_expr (fn
, args
, koenig
)
1421 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1422 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1423 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1424 fn
= do_identifier (fn
, 2, args
);
1426 result
= build_x_function_call (fn
, args
, current_class_ref
);
1428 if (TREE_CODE (result
) == CALL_EXPR
1429 && (! TREE_TYPE (result
)
1430 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1431 result
= require_complete_type (result
);
1436 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1437 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1438 POSTDECREMENT_EXPR.) */
1441 finish_increment_expr (expr
, code
)
1443 enum tree_code code
;
1445 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1446 a COMPONENT_REF). This way if we've got, say, a reference to a
1447 static member that's being operated on, we don't end up trying to
1448 find a member operator for the class it's in. */
1450 if (TREE_CODE (expr
) == OFFSET_REF
)
1451 expr
= resolve_offset_ref (expr
);
1452 return build_x_unary_op (code
, expr
);
1455 /* Finish a use of `this'. Returns an expression for `this'. */
1462 if (current_class_ptr
)
1464 #ifdef WARNING_ABOUT_CCD
1465 TREE_USED (current_class_ptr
) = 1;
1467 result
= current_class_ptr
;
1469 else if (current_function_decl
1470 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1472 error ("`this' is unavailable for static member functions");
1473 result
= error_mark_node
;
1477 if (current_function_decl
)
1478 error ("invalid use of `this' in non-member function");
1480 error ("invalid use of `this' at top level");
1481 result
= error_mark_node
;
1487 /* Finish a member function call using OBJECT and ARGS as arguments to
1488 FN. Returns an expression for the call. */
1491 finish_object_call_expr (fn
, object
, args
)
1497 /* This is a future direction of this code, but because
1498 build_x_function_call cannot always undo what is done in
1499 build_component_ref entirely yet, we cannot do this. */
1501 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1502 return finish_call_expr (real_fn
, args
);
1504 if (DECL_DECLARES_TYPE_P (fn
))
1506 if (processing_template_decl
)
1507 /* This can happen on code like:
1510 template <class T> void f(T t) {
1514 We just grab the underlying IDENTIFIER. */
1515 fn
= DECL_NAME (fn
);
1518 cp_error ("calling type `%T' like a method", fn
);
1519 return error_mark_node
;
1523 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1527 /* Finish a qualified member function call using OBJECT and ARGS as
1528 arguments to FN. Returns an expressino for the call. */
1531 finish_qualified_object_call_expr (fn
, object
, args
)
1536 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1537 TREE_OPERAND (fn
, 1), args
);
1540 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1541 being the scope, if any, of DESTRUCTOR. Returns an expression for
1545 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1550 if (processing_template_decl
)
1551 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1553 if (scope
&& scope
!= destructor
)
1554 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1557 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1558 && (TREE_CODE (TREE_TYPE (object
)) !=
1559 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1560 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1562 return cp_convert (void_type_node
, object
);
1565 /* Finish a call to a globally qualified member function FN using
1566 ARGS. Returns an expression for the call. */
1569 finish_qualified_call_expr (fn
, args
)
1573 if (processing_template_decl
)
1574 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1576 return build_member_call (TREE_OPERAND (fn
, 0),
1577 TREE_OPERAND (fn
, 1),
1581 /* Finish an expression taking the address of LABEL. Returns an
1582 expression for the address. */
1585 finish_label_address_expr (label
)
1590 label
= lookup_label (label
);
1591 if (label
== NULL_TREE
)
1592 result
= null_pointer_node
;
1595 TREE_USED (label
) = 1;
1596 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1597 TREE_CONSTANT (result
) = 1;
1598 /* This function cannot be inlined. All jumps to the addressed
1599 label should wind up at the same point. */
1600 DECL_UNINLINABLE (current_function_decl
) = 1;
1606 /* Finish an expression of the form CODE EXPR. */
1609 finish_unary_op_expr (code
, expr
)
1610 enum tree_code code
;
1613 tree result
= build_x_unary_op (code
, expr
);
1614 /* Inside a template, build_x_unary_op does not fold the
1615 expression. So check whether the result is folded before
1616 setting TREE_NEGATED_INT. */
1617 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1618 && TREE_CODE (result
) == INTEGER_CST
1619 && !TREE_UNSIGNED (TREE_TYPE (result
))
1620 && INT_CST_LT (result
, integer_zero_node
))
1621 TREE_NEGATED_INT (result
) = 1;
1622 overflow_warning (result
);
1626 /* Finish an id-expression. */
1629 finish_id_expr (expr
)
1632 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1633 expr
= do_identifier (expr
, 1, NULL_TREE
);
1638 static tree current_type_lookups
;
1640 /* Perform deferred access control for types used in the type of a
1644 deferred_type_access_control ()
1646 tree lookup
= type_lookups
;
1648 if (lookup
== error_mark_node
)
1651 for (; lookup
; lookup
= TREE_CHAIN (lookup
))
1652 enforce_access (TREE_PURPOSE (lookup
), TREE_VALUE (lookup
));
1656 decl_type_access_control (decl
)
1661 if (type_lookups
== error_mark_node
)
1664 save_fn
= current_function_decl
;
1666 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
1667 current_function_decl
= decl
;
1669 deferred_type_access_control ();
1671 current_function_decl
= save_fn
;
1673 /* Now strip away the checks for the current declarator; they were
1674 added to type_lookups after typed_declspecs saved the copy that
1675 ended up in current_type_lookups. */
1676 type_lookups
= current_type_lookups
;
1680 save_type_access_control (lookups
)
1683 current_type_lookups
= lookups
;
1686 /* Begin a function definition declared with DECL_SPECS and
1687 DECLARATOR. Returns non-zero if the function-declaration is
1691 begin_function_definition (decl_specs
, declarator
)
1698 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1699 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1702 deferred_type_access_control ();
1703 type_lookups
= error_mark_node
;
1705 /* The things we're about to see are not directly qualified by any
1706 template headers we've seen thus far. */
1707 reset_specialization ();
1712 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1716 begin_constructor_declarator (scope
, name
)
1720 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1721 enter_scope_of (result
);
1725 /* Finish an init-declarator. Returns a DECL. */
1728 finish_declarator (declarator
, declspecs
, attributes
,
1729 prefix_attributes
, initialized
)
1733 tree prefix_attributes
;
1736 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1740 /* Finish a translation unit. */
1743 finish_translation_unit ()
1745 /* In case there were missing closebraces,
1746 get us back to the global binding level. */
1748 while (current_namespace
!= global_namespace
)
1753 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1754 Returns the parameter. */
1757 finish_template_type_parm (aggr
, identifier
)
1761 if (aggr
!= class_type_node
)
1763 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1764 aggr
= class_type_node
;
1767 return build_tree_list (aggr
, identifier
);
1770 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1771 Returns the parameter. */
1774 finish_template_template_parm (aggr
, identifier
)
1778 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1779 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1780 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1781 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1782 DECL_ARTIFICIAL (decl
) = 1;
1783 end_template_decl ();
1785 return finish_template_type_parm (aggr
, tmpl
);
1788 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1789 non-zero, the parameter list was terminated by a `...'. */
1792 finish_parmlist (parms
, ellipsis
)
1797 chainon (parms
, void_list_node
);
1798 /* We mark the PARMS as a parmlist so that declarator processing can
1799 disambiguate certain constructs. */
1800 if (parms
!= NULL_TREE
)
1801 TREE_PARMLIST (parms
) = 1;
1806 /* Begin a class definition, as indicated by T. */
1809 begin_class_definition (t
)
1812 if (t
== error_mark_node
1813 || ! IS_AGGR_TYPE (t
))
1815 t
= make_aggr_type (RECORD_TYPE
);
1816 pushtag (make_anon_name (), t
, 0);
1819 /* In a definition of a member class template, we will get here with an
1820 implicit typename, a TYPENAME_TYPE with a type. */
1821 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1824 /* If we generated a partial instantiation of this type, but now
1825 we're seeing a real definition, we're actually looking at a
1826 partial specialization. Consider:
1828 template <class T, class U>
1834 template <class T, class U>
1837 typename X<Y<T, U> >::A a;
1840 template <class T, class U>
1845 We have to undo the effects of the previous partial
1847 if (PARTIAL_INSTANTIATION_P (t
))
1851 /* Unfortunately, when we're not in pedantic mode, we
1852 attempt to actually fill in some of the fields of the
1853 partial instantiation, in order to support the implicit
1854 typename extension. Clear those fields now, in
1855 preparation for the definition here. The fields cleared
1856 here must match those set in instantiate_class_template.
1857 Look for a comment mentioning begin_class_definition
1859 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1860 TYPE_FIELDS (t
) = NULL_TREE
;
1861 TYPE_METHODS (t
) = NULL_TREE
;
1862 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1863 CLASSTYPE_VBASECLASSES (t
) = NULL_TREE
;
1864 TYPE_SIZE (t
) = NULL_TREE
;
1867 /* This isn't a partial instantiation any more. */
1868 PARTIAL_INSTANTIATION_P (t
) = 0;
1870 /* If this type was already complete, and we see another definition,
1872 else if (COMPLETE_TYPE_P (t
))
1873 duplicate_tag_error (t
);
1875 /* Update the location of the decl. */
1876 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1877 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1879 if (TYPE_BEING_DEFINED (t
))
1881 t
= make_aggr_type (TREE_CODE (t
));
1882 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1884 maybe_process_partial_specialization (t
);
1886 TYPE_BEING_DEFINED (t
) = 1;
1887 TYPE_PACKED (t
) = flag_pack_struct
;
1888 /* Reset the interface data, at the earliest possible
1889 moment, as it might have been set via a class foo;
1892 tree name
= TYPE_IDENTIFIER (t
);
1894 if (! ANON_AGGRNAME_P (name
))
1896 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1897 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1898 (t
, interface_unknown
);
1901 /* Only leave this bit clear if we know this
1902 class is part of an interface-only specification. */
1903 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1904 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1905 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1907 reset_specialization();
1909 /* Make a declaration for this class in its own scope. */
1910 build_self_reference ();
1915 /* Finish the member declaration given by DECL. */
1918 finish_member_declaration (decl
)
1921 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1924 if (decl
== void_type_node
)
1925 /* The COMPONENT was a friend, not a member, and so there's
1926 nothing for us to do. */
1929 /* We should see only one DECL at a time. */
1930 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1932 /* Set up access control for DECL. */
1934 = (current_access_specifier
== access_private_node
);
1935 TREE_PROTECTED (decl
)
1936 = (current_access_specifier
== access_protected_node
);
1937 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1939 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
1940 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
1943 /* Mark the DECL as a member of the current class. */
1944 DECL_CONTEXT (decl
) = current_class_type
;
1948 A C language linkage is ignored for the names of class members
1949 and the member function type of class member functions. */
1950 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
1951 DECL_LANGUAGE (decl
) = lang_cplusplus
;
1953 /* Put functions on the TYPE_METHODS list and everything else on the
1954 TYPE_FIELDS list. Note that these are built up in reverse order.
1955 We reverse them (to obtain declaration order) in finish_struct. */
1956 if (TREE_CODE (decl
) == FUNCTION_DECL
1957 || DECL_FUNCTION_TEMPLATE_P (decl
))
1959 /* We also need to add this function to the
1960 CLASSTYPE_METHOD_VEC. */
1961 add_method (current_class_type
, decl
, /*error_p=*/0);
1963 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1964 TYPE_METHODS (current_class_type
) = decl
;
1968 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1969 go at the beginning. The reason is that lookup_field_1
1970 searches the list in order, and we want a field name to
1971 override a type name so that the "struct stat hack" will
1972 work. In particular:
1974 struct S { enum E { }; int E } s;
1977 is legal. In addition, the FIELD_DECLs must be maintained in
1978 declaration order so that class layout works as expected.
1979 However, we don't need that order until class layout, so we
1980 save a little time by putting FIELD_DECLs on in reverse order
1981 here, and then reversing them in finish_struct_1. (We could
1982 also keep a pointer to the correct insertion points in the
1985 if (TREE_CODE (decl
) == TYPE_DECL
)
1986 TYPE_FIELDS (current_class_type
)
1987 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1990 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1991 TYPE_FIELDS (current_class_type
) = decl
;
1994 /* Enter the DECL into the scope of the class. */
1995 if (TREE_CODE (decl
) != USING_DECL
)
1996 pushdecl_class_level (decl
);
2000 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
2001 the definition is immediately followed by a semicolon. Returns the
2005 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
2011 /* finish_struct nukes this anyway; if finish_exception does too,
2014 note_got_semicolon (t
);
2016 /* If we got any attributes in class_head, xref_tag will stick them in
2017 TREE_TYPE of the type. Grab them now. */
2018 attributes
= chainon (TREE_TYPE (t
), attributes
);
2019 TREE_TYPE (t
) = NULL_TREE
;
2021 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
2025 t
= finish_struct (t
, attributes
);
2027 note_got_semicolon (t
);
2031 check_for_missing_semicolon (t
);
2033 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
2034 if (current_scope () == current_function_decl
)
2035 do_pending_defargs ();
2040 /* Finish processing the default argument expressions cached during
2041 the processing of a class definition. */
2044 begin_inline_definitions ()
2046 if (current_scope () == current_function_decl
)
2047 do_pending_inlines ();
2050 /* Finish processing the inline function definitions cached during the
2051 processing of a class definition. */
2054 finish_inline_definitions ()
2056 if (current_class_type
== NULL_TREE
)
2057 clear_inline_text_obstack ();
2060 /* Finish processing the declaration of a member class template
2061 TYPES whose template parameters are given by PARMS. */
2064 finish_member_class_template (types
)
2069 /* If there are declared, but undefined, partial specializations
2070 mixed in with the typespecs they will not yet have passed through
2071 maybe_process_partial_specialization, so we do that here. */
2072 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
2073 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
2074 maybe_process_partial_specialization (TREE_VALUE (t
));
2076 note_list_got_semicolon (types
);
2077 grok_x_components (types
);
2078 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
2079 /* The component was in fact a friend declaration. We avoid
2080 finish_member_template_decl performing certain checks by
2084 finish_member_template_decl (types
);
2086 /* As with other component type declarations, we do
2087 not store the new DECL on the list of
2092 /* Finish processsing a complete template declaration. The PARMS are
2093 the template parameters. */
2096 finish_template_decl (parms
)
2100 end_template_decl ();
2102 end_specialization ();
2105 /* Finish processing a a template-id (which names a type) of the form
2106 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2107 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2108 the scope of template-id indicated. */
2111 finish_template_type (name
, args
, entering_scope
)
2118 decl
= lookup_template_class (name
, args
,
2119 NULL_TREE
, NULL_TREE
, entering_scope
);
2120 if (decl
!= error_mark_node
)
2121 decl
= TYPE_STUB_DECL (decl
);
2126 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2127 namespace scope or a class scope. */
2133 tree scope
= TREE_OPERAND (sr
, 0);
2135 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2137 push_decl_namespace (scope
);
2138 TREE_COMPLEXITY (sr
) = -1;
2140 else if (scope
!= current_class_type
)
2142 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2144 /* In a declarator for a template class member, the scope will
2145 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2146 scope
= TREE_TYPE (scope
);
2147 TREE_OPERAND (sr
, 0) = scope
;
2149 push_nested_class (scope
, 3);
2150 TREE_COMPLEXITY (sr
) = current_class_depth
;
2154 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2155 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2156 BASE_CLASS, or NULL_TREE if an error occurred. The
2157 ACCESSS_SPECIFIER is one of
2158 access_{default,public,protected_private}[_virtual]_node.*/
2161 finish_base_specifier (access_specifier
, base_class
)
2162 tree access_specifier
;
2168 if (base_class
== NULL_TREE
)
2170 error ("invalid base class");
2171 type
= error_mark_node
;
2174 type
= TREE_TYPE (base_class
);
2176 if (! is_aggr_type (type
, 1))
2179 result
= build_tree_list (access_specifier
, type
);
2184 /* Called when multiple declarators are processed. If that is not
2185 premitted in this context, an error is issued. */
2188 check_multiple_declarators ()
2192 In a template-declaration, explicit specialization, or explicit
2193 instantiation the init-declarator-list in the declaration shall
2194 contain at most one declarator.
2196 We don't just use PROCESSING_TEMPLATE_DECL for the first
2197 condition since that would disallow the perfectly legal code,
2198 like `template <class T> struct S { int i, j; };'. */
2199 tree scope
= current_scope ();
2201 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2202 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2205 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2206 || processing_explicit_instantiation
2207 || processing_specialization
)
2208 cp_error ("multiple declarators in template declaration");
2212 finish_typeof (expr
)
2215 if (processing_template_decl
)
2219 t
= make_aggr_type (TYPEOF_TYPE
);
2220 TYPE_FIELDS (t
) = expr
;
2225 return TREE_TYPE (expr
);
2228 /* Generate RTL for the statement T, and its substatements, and any
2229 other statements at its nesting level. */
2235 switch (TREE_CODE (t
))
2238 genrtl_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2241 case START_CATCH_STMT
:
2242 genrtl_catch_block (TREE_TYPE (t
));
2246 genrtl_ctor_stmt (t
);
2250 genrtl_try_block (t
);
2258 genrtl_subobject (SUBOBJECT_CLEANUP (t
));
2262 genrtl_scope_stmt (t
);
2266 genrtl_named_return_value ();
2270 my_friendly_abort (19990810);
2275 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2276 will equivalent CALL_EXPRs. */
2279 simplify_aggr_init_exprs_r (tp
, walk_subtrees
, data
)
2281 int *walk_subtrees ATTRIBUTE_UNUSED
;
2282 void *data ATTRIBUTE_UNUSED
;
2284 tree aggr_init_expr
;
2291 int copy_from_buffer_p
;
2293 aggr_init_expr
= *tp
;
2294 /* We don't need to walk into types; there's nothing in a type that
2295 needs simplification. (And, furthermore, there are places we
2296 actively don't want to go. For example, we don't want to wander
2297 into the default arguments for a FUNCTION_DECL that appears in a
2299 if (TYPE_P (aggr_init_expr
))
2304 /* Only AGGR_INIT_EXPRs are interesting. */
2305 else if (TREE_CODE (aggr_init_expr
) != AGGR_INIT_EXPR
)
2308 /* Form an appropriate CALL_EXPR. */
2309 fn
= TREE_OPERAND (aggr_init_expr
, 0);
2310 args
= TREE_OPERAND (aggr_init_expr
, 1);
2311 slot
= TREE_OPERAND (aggr_init_expr
, 2);
2312 type
= TREE_TYPE (aggr_init_expr
);
2314 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
2316 /* Replace the first argument with the address of the third
2317 argument to the AGGR_INIT_EXPR. */
2318 call_type
= build_pointer_type (type
);
2319 mark_addressable (slot
);
2320 args
= tree_cons (NULL_TREE
, build1 (ADDR_EXPR
, call_type
, slot
),
2323 call_expr
= build (CALL_EXPR
, call_type
, fn
, args
, NULL_TREE
);
2324 TREE_SIDE_EFFECTS (call_expr
) = 1;
2326 /* If we're using the non-reentrant PCC calling convention, then we
2327 need to copy the returned value out of the static buffer into the
2329 copy_from_buffer_p
= 0;
2330 #ifdef PCC_STATIC_STRUCT_RETURN
2331 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) && aggregate_value_p (type
))
2335 flag_access_control
= 0;
2336 call_expr
= build_aggr_init (slot
, call_expr
, LOOKUP_ONLYCONVERTING
);
2337 flag_access_control
= old_ac
;
2338 copy_from_buffer_p
= 1;
2342 /* If this AGGR_INIT_EXPR indicates the value returned by a
2343 function, then we want to use the value of the initialized
2344 location as the result. */
2345 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) || copy_from_buffer_p
)
2347 call_expr
= build (COMPOUND_EXPR
, type
,
2349 TREE_SIDE_EFFECTS (call_expr
) = 1;
2352 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2353 TREE_CHAIN (call_expr
) = TREE_CHAIN (aggr_init_expr
);
2356 /* Keep iterating. */
2360 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2363 emit_associated_thunks (fn
)
2366 /* When we use vcall offsets, we emit thunks with the virtual
2367 functions to which they thunk. The whole point of vcall offsets
2368 is so that you can know statically the entire set of thunks that
2369 will ever be needed for a given virtual function, thereby
2370 enabling you to output all the thunks with the function itself. */
2371 if (vcall_offsets_in_vtable_p () && DECL_VIRTUAL_P (fn
))
2376 for (binfo
= TYPE_BINFO (DECL_CONTEXT (fn
));
2378 binfo
= TREE_CHAIN (binfo
))
2379 for (v
= BINFO_VIRTUALS (binfo
); v
; v
= TREE_CHAIN (v
))
2381 && (!integer_zerop (BV_DELTA (v
))
2382 || BV_VCALL_INDEX (v
)))
2387 if (BV_USE_VCALL_INDEX_P (v
))
2389 vcall_index
= BV_VCALL_INDEX (v
);
2390 my_friendly_assert (vcall_index
!= NULL_TREE
, 20000621);
2393 vcall_index
= NULL_TREE
;
2395 thunk
= make_thunk (build1 (ADDR_EXPR
,
2396 vfunc_ptr_type_node
,
2400 /*generate_with_vtable_p=*/0);
2401 use_thunk (thunk
, /*emit_p=*/1);
2407 /* Generate RTL for FN. */
2414 const char *saved_input_filename
;
2416 /* When the parser calls us after finishing the body of a template
2417 function, we don't really want to expand the body. When we're
2418 processing an in-class definition of an inline function,
2419 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2420 to look at the function itself. */
2421 if (processing_template_decl
2422 || (DECL_LANG_SPECIFIC (fn
)
2423 && DECL_TEMPLATE_INFO (fn
)
2424 && uses_template_parms (DECL_TI_ARGS (fn
))))
2426 /* Normally, collection only occurs in rest_of_compilation. So,
2427 if we don't collect here, we never collect junk generated
2428 during the processing of templates until we hit a
2429 non-template function. */
2434 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2435 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn
),
2436 simplify_aggr_init_exprs_r
,
2439 /* If this is a constructor or destructor body, we have to clone it
2440 under the new ABI. */
2441 if (maybe_clone_body (fn
))
2443 /* We don't want to process FN again, so pretend we've written
2444 it out, even though we haven't. */
2445 TREE_ASM_WRITTEN (fn
) = 1;
2449 /* There's no reason to do any of the work here if we're only doing
2450 semantic analysis; this code just generates RTL. */
2451 if (flag_syntax_only
)
2454 /* If possible, avoid generating RTL for this function. Instead,
2455 just record it as an inline function, and wait until end-of-file
2456 to decide whether to write it out or not. */
2457 if (/* We have to generate RTL if it's not an inline function. */
2458 (DECL_INLINE (fn
) || DECL_COMDAT (fn
))
2459 /* Or if we have to keep all inline functions anyhow. */
2460 && !flag_keep_inline_functions
2461 /* Or if we actually have a reference to the function. */
2462 && !DECL_NEEDED_P (fn
)
2463 /* Or if this is a nested function. */
2464 && !decl_function_context (fn
))
2466 /* Give the function RTL now so that we can assign it to a
2467 function pointer, etc. */
2468 make_function_rtl (fn
);
2469 /* Set DECL_EXTERNAL so that assemble_external will be called as
2470 necessary. We'll clear it again in finish_file. */
2471 if (!DECL_EXTERNAL (fn
))
2473 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2474 DECL_EXTERNAL (fn
) = 1;
2476 /* Remember this function. In finish_file we'll decide if
2477 we actually need to write this function out. */
2479 /* Let the back-end know that this funtion exists. */
2480 note_deferral_of_defined_inline_function (fn
);
2484 /* Emit any thunks that should be emitted at the same time as FN. */
2485 emit_associated_thunks (fn
);
2487 timevar_push (TV_INTEGRATION
);
2489 /* Optimize the body of the function before expanding it. */
2490 optimize_function (fn
);
2492 timevar_pop (TV_INTEGRATION
);
2493 timevar_push (TV_EXPAND
);
2495 /* Save the current file name and line number. When we expand the
2496 body of the function, we'll set LINENO and INPUT_FILENAME so that
2497 error-mesages come out in the right places. */
2498 saved_lineno
= lineno
;
2499 saved_input_filename
= input_filename
;
2500 lineno
= DECL_SOURCE_LINE (fn
);
2501 input_filename
= DECL_SOURCE_FILE (fn
);
2503 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2504 store_parm_decls ();
2505 current_function_is_thunk
= DECL_THUNK_P (fn
);
2507 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2508 any of the other magic variables we set up when starting a
2510 cp_function_chain
->name_declared
= 1;
2512 /* Expand the body. */
2513 expand_stmt (DECL_SAVED_TREE (fn
));
2515 /* Statements should always be full-expressions at the outermost set
2516 of curly braces for a function. */
2517 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2519 /* The outermost statement for a function contains the line number
2520 recorded when we finished processing the function. */
2521 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2523 /* Generate code for the function. */
2524 finish_function (0);
2526 /* If possible, obliterate the body of the function so that it can
2527 be garbage collected. */
2528 if (flag_dump_translation_unit
)
2529 /* Keep the body; we're going to dump it. */
2531 else if (DECL_INLINE (fn
) && flag_inline_trees
)
2532 /* We might need the body of this function so that we can expand
2533 it inline somewhere else. */
2536 /* We don't need the body; blow it away. */
2537 DECL_SAVED_TREE (fn
) = NULL_TREE
;
2539 /* And restore the current source position. */
2540 lineno
= saved_lineno
;
2541 input_filename
= saved_input_filename
;
2542 extract_interface_info ();
2544 timevar_pop (TV_EXPAND
);
2547 /* Perform initialization related to this module. */
2550 init_cp_semantics ()
2552 lang_expand_stmt
= cp_expand_stmt
;