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 tree prune_unused_decls
PARAMS ((tree
*, int *, void *));
52 static void deferred_type_access_control
PARAMS ((void));
53 static void emit_associated_thunks
PARAMS ((tree
));
55 /* Record the fact that STMT was the last statement added to the
58 #define SET_LAST_STMT(stmt) \
59 (current_stmt_tree->x_last_stmt = (stmt))
61 /* When parsing a template, LAST_TREE contains the last statement
62 parsed. These are chained together through the TREE_CHAIN field,
63 but often need to be re-organized since the parse is performed
64 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
67 #define RECHAIN_STMTS(stmt, substmt) \
69 substmt = TREE_CHAIN (stmt); \
70 TREE_CHAIN (stmt) = NULL_TREE; \
71 SET_LAST_STMT (stmt); \
74 /* Finish processing the COND, the SUBSTMT condition for STMT. */
76 #define FINISH_COND(cond, stmt, substmt) \
78 if (last_tree != stmt) \
80 RECHAIN_STMTS (stmt, substmt); \
81 if (!processing_template_decl) \
83 cond = build_tree_list (substmt, cond); \
91 /* Wrapper since C and C++ expand_expr_stmt are different. */
93 expand_expr_stmt_fn lang_expand_expr_stmt
= cplus_expand_expr_stmt
;
95 /* Wrapper function instead of #define for use with c-common code. */
98 set_current_function_name_declared (i
)
101 cp_function_chain
->name_declared
= i
;
104 /* Returns non-zero if the current statement is a full expression,
105 i.e. temporaries created during that statement should be destroyed
106 at the end of the statement. */
109 stmts_are_full_exprs_p ()
111 return current_stmt_tree
->stmts_are_full_exprs_p
;
114 /* One if we have already declared __FUNCTION__ (and related
115 variables) in the current function. Two if we are in the process
119 current_function_name_declared ()
121 return cp_function_chain
->name_declared
;
124 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
125 flag for this because "A union for which objects or pointers are
126 declared is not an anonymous union" [class.union]. */
129 anon_aggr_type_p (node
)
132 return (CLASS_TYPE_P (node
) && TYPE_LANG_SPECIFIC(node
)->anon_aggr
);
135 /* Finish a scope. */
140 tree block
= NULL_TREE
;
142 if (stmts_are_full_exprs_p ())
144 tree scope_stmts
= NULL_TREE
;
146 if (!processing_template_decl
)
147 scope_stmts
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
149 block
= poplevel (kept_level_p (), 1, 0);
150 if (block
&& !processing_template_decl
)
152 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts
)) = block
;
153 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts
)) = block
;
160 /* Begin a new scope. */
165 if (stmts_are_full_exprs_p ())
168 if (!processing_template_decl
)
169 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
173 /* T is a statement. Add it to the statement-tree. */
179 /* Add T to the statement-tree. */
180 TREE_CHAIN (last_tree
) = t
;
182 /* When we expand a statement-tree, we must know whether or not the
183 statements are full-expresions. We record that fact here. */
184 STMT_IS_FULL_EXPR_P (last_tree
) = stmts_are_full_exprs_p ();
187 /* Finish a goto-statement. */
190 finish_goto_stmt (destination
)
193 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
194 destination
= lookup_label (destination
);
196 /* We warn about unused labels with -Wunused. That means we have to
197 mark the used labels as used. */
198 if (TREE_CODE (destination
) == LABEL_DECL
)
199 TREE_USED (destination
) = 1;
201 if (TREE_CODE (destination
) != LABEL_DECL
)
202 /* We don't inline calls to functions with computed gotos.
203 Those functions are typically up to some funny business,
204 and may be depending on the labels being at particular
205 addresses, or some such. */
206 DECL_UNINLINABLE (current_function_decl
) = 1;
208 check_goto (destination
);
210 add_tree (build_stmt (GOTO_STMT
, destination
));
213 /* COND is the condition-expression for an if, while, etc.,
214 statement. Convert it to a boolean value, if appropriate. */
217 maybe_convert_cond (cond
)
220 /* Empty conditions remain empty. */
224 /* Wait until we instantiate templates before doing conversion. */
225 if (processing_template_decl
)
228 /* Do the conversion. */
229 cond
= convert_from_reference (cond
);
230 return condition_conversion (cond
);
233 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
236 finish_expr_stmt (expr
)
239 if (expr
!= NULL_TREE
)
241 if (!processing_template_decl
242 && !(stmts_are_full_exprs_p ())
243 && ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
245 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
246 expr
= default_conversion (expr
);
248 if (stmts_are_full_exprs_p ())
249 expr
= convert_to_void (expr
, "statement");
251 if (!processing_template_decl
)
252 expr
= break_out_cleanups (expr
);
254 add_tree (build_stmt (EXPR_STMT
, expr
));
259 /* This was an expression-statement, so we save the type of the
261 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
265 /* Begin an if-statement. Returns a newly created IF_STMT if
273 r
= build_stmt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
278 /* Process the COND of an if-statement, which may be given by
282 finish_if_stmt_cond (cond
, if_stmt
)
286 cond
= maybe_convert_cond (cond
);
287 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
290 /* Finish the then-clause of an if-statement, which may be given by
294 finish_then_clause (if_stmt
)
297 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
298 SET_LAST_STMT (if_stmt
);
302 /* Begin the else-clause of an if-statement. */
309 /* Finish the else-clause of an if-statement, which may be given by
313 finish_else_clause (if_stmt
)
316 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
319 /* Finsh an if-statement. */
331 /* If COND wasn't a declaration, clear out the
332 block we made for it and start a new one here so the
333 optimization in expand_end_loop will work. */
334 if (getdecls () == NULL_TREE
)
341 /* Begin a while-statement. Returns a newly created WHILE_STMT if
348 r
= build_stmt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
354 /* Process the COND of a while-statement, which may be given by
358 finish_while_stmt_cond (cond
, while_stmt
)
362 cond
= maybe_convert_cond (cond
);
363 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
367 /* Finish a while-statement, which may be given by WHILE_STMT. */
370 finish_while_stmt (while_stmt
)
374 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
378 /* Begin a do-statement. Returns a newly created DO_STMT if
384 tree r
= build_stmt (DO_STMT
, NULL_TREE
, NULL_TREE
);
389 /* Finish the body of a do-statement, which may be given by DO_STMT. */
392 finish_do_body (do_stmt
)
395 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
398 /* Finish a do-statement, which may be given by DO_STMT, and whose
399 COND is as indicated. */
402 finish_do_stmt (cond
, do_stmt
)
406 cond
= maybe_convert_cond (cond
);
407 DO_COND (do_stmt
) = cond
;
411 /* Finish a return-statement. The EXPRESSION returned, if any, is as
415 finish_return_stmt (expr
)
418 if (!processing_template_decl
)
419 expr
= check_return_expr (expr
);
420 if (!processing_template_decl
)
422 if (DECL_CONSTRUCTOR_P (current_function_decl
) && ctor_label
)
424 /* Even returns without a value in a constructor must return
425 `this'. We accomplish this by sending all returns in a
426 constructor to the CTOR_LABEL; finish_function emits code to
427 return a value there. When we finally generate the real
428 return statement, CTOR_LABEL is no longer set, and we fall
429 through into the normal return-processing code below. */
430 finish_goto_stmt (ctor_label
);
433 else if (DECL_DESTRUCTOR_P (current_function_decl
))
435 /* Similarly, all destructors must run destructors for
436 base-classes before returning. So, all returns in a
437 destructor get sent to the DTOR_LABEL; finsh_function emits
438 code to return a value there. */
439 finish_goto_stmt (dtor_label
);
443 add_tree (build_stmt (RETURN_STMT
, expr
));
447 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
454 r
= build_stmt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
455 NULL_TREE
, NULL_TREE
);
456 NEW_FOR_SCOPE_P (r
) = flag_new_for_scope
> 0;
458 if (NEW_FOR_SCOPE_P (r
))
461 note_level_for_for ();
467 /* Finish the for-init-statement of a for-statement, which may be
468 given by FOR_STMT. */
471 finish_for_init_stmt (for_stmt
)
474 if (last_tree
!= for_stmt
)
475 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
479 /* Finish the COND of a for-statement, which may be given by
483 finish_for_cond (cond
, for_stmt
)
487 cond
= maybe_convert_cond (cond
);
488 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
492 /* Finish the increment-EXPRESSION in a for-statement, which may be
493 given by FOR_STMT. */
496 finish_for_expr (expr
, for_stmt
)
500 FOR_EXPR (for_stmt
) = expr
;
503 /* Finish the body of a for-statement, which may be given by
504 FOR_STMT. The increment-EXPR for the loop must be
508 finish_for_stmt (for_stmt
)
511 /* Pop the scope for the body of the loop. */
513 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
514 if (NEW_FOR_SCOPE_P (for_stmt
))
519 /* Finish a break-statement. */
524 add_tree (build_stmt (BREAK_STMT
));
527 /* Finish a continue-statement. */
530 finish_continue_stmt ()
532 add_tree (build_stmt (CONTINUE_STMT
));
535 /* Begin a switch-statement. Returns a new SWITCH_STMT if
542 r
= build_stmt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
548 /* Finish the cond of a switch-statement. */
551 finish_switch_cond (cond
, switch_stmt
)
555 if (!processing_template_decl
)
557 /* Convert the condition to an integer or enumeration type. */
558 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, 1);
559 if (cond
== NULL_TREE
)
561 error ("switch quantity not an integer");
562 cond
= error_mark_node
;
564 if (cond
!= error_mark_node
)
566 cond
= default_conversion (cond
);
567 cond
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (cond
), cond
));
570 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
574 /* Finish the body of a switch-statement, which may be given by
575 SWITCH_STMT. The COND to switch on is indicated. */
578 finish_switch_stmt (switch_stmt
)
581 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
587 /* Finish a case-label. */
590 finish_case_label (low_value
, high_value
)
594 /* Add a representation for the case label to the statement
596 add_tree (build_stmt (CASE_LABEL
, low_value
, high_value
));
597 /* And warn about crossing initializations, etc. */
598 if (!processing_template_decl
)
599 define_case_label ();
602 /* Generate the RTL for T, which is a TRY_BLOCK. */
604 void genrtl_try_block (t
)
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
)) {
616 if (! current_function_parms_stored
)
618 expand_start_early_try_stmts ();
621 emit_line_note (input_filename
, lineno
);
622 expand_start_try_stmts ();
625 expand_stmt (TRY_STMTS (t
));
627 if (FN_TRY_BLOCK_P (t
))
629 end_protect_partials ();
630 expand_start_all_catch ();
631 in_function_try_handler
= 1;
632 expand_stmt (TRY_HANDLERS (t
));
633 in_function_try_handler
= 0;
634 expand_end_all_catch ();
638 expand_start_all_catch ();
639 expand_stmt (TRY_HANDLERS (t
));
640 expand_end_all_catch ();
645 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
651 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
656 /* Likewise, for a function-try-block. */
659 begin_function_try_block ()
661 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
662 FN_TRY_BLOCK_P (r
) = 1;
667 /* Finish a try-block, which may be given by TRY_BLOCK. */
670 finish_try_block (try_block
)
673 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
676 /* Finish the body of a cleanup try-block, which may be given by
680 finish_cleanup_try_block (try_block
)
683 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
686 /* Finish an implicitly generated try-block, with a cleanup is given
690 finish_cleanup (cleanup
, try_block
)
694 TRY_HANDLERS (try_block
) = cleanup
;
695 CLEANUP_P (try_block
) = 1;
698 /* Likewise, for a function-try-block. */
701 finish_function_try_block (try_block
)
704 if (TREE_CHAIN (try_block
)
705 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
707 /* Chain the compound statement after the CTOR_INITIALIZER. */
708 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
709 /* And make the CTOR_INITIALIZER the body of the try-block. */
710 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
713 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
714 in_function_try_handler
= 1;
717 /* Finish a handler-sequence for a try-block, which may be given by
721 finish_handler_sequence (try_block
)
724 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
725 check_handlers (TRY_HANDLERS (try_block
));
728 /* Likewise, for a function-try-block. */
731 finish_function_handler_sequence (try_block
)
734 in_function_try_handler
= 0;
735 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
736 check_handlers (TRY_HANDLERS (try_block
));
739 /* Generate the RTL for T, which is a HANDLER. */
745 genrtl_do_pushlevel ();
746 expand_stmt (HANDLER_BODY (t
));
747 if (!processing_template_decl
)
749 /* Fall to outside the try statement when done executing
750 handler and we fall off end of handler. This is jump
751 Lresume in the documentation. */
752 expand_goto (top_label_entry (&caught_return_label_stack
));
753 end_catch_handler ();
757 /* Begin a handler. Returns a HANDLER if appropriate. */
763 r
= build_stmt (HANDLER
, NULL_TREE
, NULL_TREE
);
769 /* Finish the handler-parameters for a handler, which may be given by
770 HANDLER. DECL is the declaration for the catch parameter, or NULL
771 if this is a `catch (...)' clause. */
774 finish_handler_parms (decl
, handler
)
778 tree blocks
= NULL_TREE
;
780 if (processing_template_decl
)
784 decl
= pushdecl (decl
);
785 decl
= push_template_decl (decl
);
786 add_decl_stmt (decl
);
787 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
791 blocks
= expand_start_catch_block (decl
);
794 TREE_TYPE (handler
) = TREE_TYPE (decl
);
799 /* Generate the RTL for a CATCH_BLOCK. */
802 genrtl_catch_block (type
)
805 start_catch_handler (type
);
808 /* Note the beginning of a handler for TYPE. This function is called
809 at the point to which control should be transferred when an
810 appropriately-typed exception is thrown. */
813 begin_catch_block (type
)
816 add_tree (build (START_CATCH_STMT
, type
));
819 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
820 the return value from the matching call to finish_handler_parms. */
823 finish_handler (blocks
, handler
)
827 if (!processing_template_decl
)
828 expand_end_catch_block (blocks
);
830 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
833 /* Generate the RTL for T, which is a CTOR_STMT. */
839 if (CTOR_BEGIN_P (t
))
840 begin_protect_partials ();
842 /* After this point, any exceptions will cause the
843 destructor to be executed, so we no longer need to worry
844 about destroying the various subobjects ourselves. */
845 end_protect_partials ();
848 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
849 compound-statement does not define a scope. Returns a new
850 COMPOUND_STMT if appropriate. */
853 begin_compound_stmt (has_no_scope
)
859 r
= build_stmt (COMPOUND_STMT
, NULL_TREE
);
861 if (last_tree
&& TREE_CODE (last_tree
) == TRY_BLOCK
)
866 COMPOUND_STMT_NO_SCOPE (r
) = 1;
868 last_expr_type
= NULL_TREE
;
874 note_level_for_eh ();
877 /* Normally, we try hard to keep the BLOCK for a
878 statement-expression. But, if it's a statement-expression with
879 a scopeless block, there's nothing to keep, and we don't want
880 to accidentally keep a block *inside* the scopeless block. */
883 /* If this is the outermost block of the function, declare the
884 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
886 && !(current_function_name_declared () )
889 cp_function_chain
->name_declared
= 1;
890 declare_function_name ();
896 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
897 If HAS_NO_SCOPE is non-zero, the compound statement does not define
901 finish_compound_stmt (has_no_scope
, compound_stmt
)
913 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
915 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
916 the precise purpose of that variable is store the type of the
917 last expression statement within the last compound statement, we
918 preserve the value. */
926 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
927 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
931 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
932 input_operands
, clobbers
)
935 tree output_operands
;
942 if (TREE_CHAIN (string
))
943 string
= combine_strings (string
);
945 if (cv_qualifier
!= NULL_TREE
946 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
948 cp_warning ("%s qualifier ignored on asm",
949 IDENTIFIER_POINTER (cv_qualifier
));
950 cv_qualifier
= NULL_TREE
;
953 if (!processing_template_decl
)
954 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
955 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
957 r
= build_stmt (ASM_STMT
, cv_qualifier
, string
,
958 output_operands
, input_operands
,
963 /* Finish a label with the indicated NAME. */
966 finish_label_stmt (name
)
969 tree decl
= define_label (input_filename
, lineno
, name
);
970 add_tree (build_stmt (LABEL_STMT
, decl
));
973 /* Finish a series of declarations for local labels. G++ allows users
974 to declare "local" labels, i.e., labels with scope. This extension
975 is useful when writing code involving statement-expressions. */
978 finish_label_decl (name
)
981 tree decl
= declare_local_label (name
);
982 add_decl_stmt (decl
);
985 /* Create a declaration statement for the declaration given by the
994 /* We need the type to last until instantiation time. */
995 decl_stmt
= build_stmt (DECL_STMT
, decl
);
996 add_tree (decl_stmt
);
999 /* Generate the RTL for a SUBOBJECT. */
1002 genrtl_subobject (cleanup
)
1005 add_partial_entry (cleanup
);
1008 /* We're in a constructor, and have just constructed a a subobject of
1009 *THIS. CLEANUP is code to run if an exception is thrown before the
1010 end of the current function is reached. */
1013 finish_subobject (cleanup
)
1016 tree r
= build_stmt (SUBOBJECT
, cleanup
);
1020 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1023 finish_decl_cleanup (decl
, cleanup
)
1027 add_tree (build_stmt (CLEANUP_STMT
, decl
, cleanup
));
1030 /* Generate the RTL for a RETURN_INIT. */
1033 genrtl_named_return_value ()
1037 decl
= DECL_RESULT (current_function_decl
);
1039 emit_local_var (decl
);
1041 /* If this named return value comes in a register, put it in a
1043 if (DECL_REGISTER (decl
))
1045 original_result_rtx
= DECL_RTL (decl
);
1046 /* Note that the mode of the old DECL_RTL may be wider than the
1047 mode of DECL_RESULT, depending on the calling conventions for
1048 the processor. For example, on the Alpha, a 32-bit integer
1049 is returned in a DImode register -- the DECL_RESULT has
1050 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
1051 here, we use the mode the back-end has already assigned for
1052 the return value. */
1053 DECL_RTL (decl
) = gen_reg_rtx (GET_MODE (original_result_rtx
));
1054 if (TREE_ADDRESSABLE (decl
))
1055 put_var_into_stack (decl
);
1059 /* Bind a name and initialization to the return value of
1060 the current function. */
1063 finish_named_return_value (return_id
, init
)
1064 tree return_id
, init
;
1066 tree decl
= DECL_RESULT (current_function_decl
);
1068 /* Give this error as many times as there are occurrences, so that
1069 users can use Emacs compilation buffers to find and fix all such
1072 pedwarn ("ISO C++ does not permit named return values");
1073 cp_deprecated ("the named return value extension");
1075 if (return_id
!= NULL_TREE
)
1077 if (DECL_NAME (decl
) == NULL_TREE
)
1079 DECL_NAME (decl
) = return_id
;
1080 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1084 cp_error ("return identifier `%D' already in place", return_id
);
1089 /* Can't let this happen for constructors. */
1090 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1092 error ("can't redefine default return value for constructors");
1096 /* If we have a named return value, put that in our scope as well. */
1097 if (DECL_NAME (decl
) != NULL_TREE
)
1099 /* Let `cp_finish_decl' know that this initializer is ok. */
1100 DECL_INITIAL (decl
) = init
;
1101 if (doing_semantic_analysis_p ())
1103 if (!processing_template_decl
)
1105 cp_finish_decl (decl
, init
, NULL_TREE
, 0);
1106 add_tree (build_stmt (RETURN_INIT
, NULL_TREE
, NULL_TREE
));
1109 add_tree (build_stmt (RETURN_INIT
, return_id
, init
));
1112 /* Don't use tree-inlining for functions with named return values.
1113 That doesn't work properly because we don't do any translation of
1114 the RETURN_INITs when they are copied. */
1115 DECL_UNINLINABLE (current_function_decl
) = 1;
1118 /* The INIT_LIST is a list of mem-initializers, in the order they were
1119 written by the user. The TREE_VALUE of each node is a list of
1120 initializers for a particular subobject. The TREE_PURPOSE is a
1121 FIELD_DECL is the initializer is for a non-static data member, and
1122 a class type if the initializer is for a base class. */
1125 finish_mem_initializers (init_list
)
1128 tree member_init_list
;
1129 tree base_init_list
;
1130 tree last_base_warned_about
;
1134 member_init_list
= NULL_TREE
;
1135 base_init_list
= NULL_TREE
;
1136 last_base_warned_about
= NULL_TREE
;
1138 for (init
= init_list
; init
; init
= next
)
1140 next
= TREE_CHAIN (init
);
1141 if (TREE_CODE (TREE_PURPOSE (init
)) == FIELD_DECL
)
1143 TREE_CHAIN (init
) = member_init_list
;
1144 member_init_list
= init
;
1146 /* We're running through the initializers from right to left
1147 as we process them here. So, if we see a data member
1148 initializer after we see a base initializer, that
1149 actually means that the base initializer preceeded the
1150 data member initializer. */
1151 if (warn_reorder
&& last_base_warned_about
!= base_init_list
)
1155 for (base
= base_init_list
;
1156 base
!= last_base_warned_about
;
1157 base
= TREE_CHAIN (base
))
1159 cp_warning ("base initializer for `%T'",
1160 TREE_PURPOSE (base
));
1161 warning (" will be re-ordered to precede member initializations");
1164 last_base_warned_about
= base_init_list
;
1169 TREE_CHAIN (init
) = base_init_list
;
1170 base_init_list
= init
;
1174 setup_vtbl_ptr (member_init_list
, base_init_list
);
1177 /* Cache the value of this class's main virtual function table pointer
1178 in a register variable. This will save one indirection if a
1179 more than one virtual function call is made this function. */
1182 setup_vtbl_ptr (member_init_list
, base_init_list
)
1183 tree member_init_list
;
1184 tree base_init_list
;
1186 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1188 /* If we've already done this, there's no need to do it again. */
1192 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1194 if (processing_template_decl
)
1195 add_tree (build_min_nt
1197 member_init_list
, base_init_list
));
1202 /* Mark the beginning of the constructor. */
1203 ctor_stmt
= build_stmt (CTOR_STMT
);
1204 CTOR_BEGIN_P (ctor_stmt
) = 1;
1205 add_tree (ctor_stmt
);
1207 /* And actually initialize the base-classes and members. */
1208 emit_base_init (member_init_list
, base_init_list
);
1211 else if (DECL_DESTRUCTOR_P (current_function_decl
)
1212 && !processing_template_decl
)
1218 /* If the dtor is empty, and we know there is not any possible
1219 way we could use any vtable entries, before they are possibly
1220 set by a base class dtor, we don't have to setup the vtables,
1221 as we know that any base class dtor will set up any vtables
1222 it needs. We avoid MI, because one base class dtor can do a
1223 virtual dispatch to an overridden function that would need to
1224 have a non-related vtable set up, we cannot avoid setting up
1225 vtables in that case. We could change this to see if there
1226 is just one vtable. */
1227 if_stmt
= begin_if_stmt ();
1229 /* If it is not safe to avoid setting up the vtables, then
1230 someone will change the condition to be boolean_true_node.
1231 (Actually, for now, we do not have code to set the condition
1232 appropriately, so we just assume that we always need to
1233 initialize the vtables.) */
1234 finish_if_stmt_cond (boolean_true_node
, if_stmt
);
1235 current_vcalls_possible_p
= &IF_COND (if_stmt
);
1237 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1238 open the block for the if-body. */
1239 saved_cfnd
= current_function_name_declared ();
1240 cp_function_chain
->name_declared
= 1;
1241 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
1242 cp_function_chain
->name_declared
= saved_cfnd
;
1244 /* Make all virtual function table pointers in non-virtual base
1245 classes point to CURRENT_CLASS_TYPE's virtual function
1247 initialize_vtbl_ptrs (current_class_ptr
);
1249 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
1250 finish_then_clause (if_stmt
);
1254 /* Always keep the BLOCK node associated with the outermost pair of
1255 curly braces of a function. These are needed for correct
1256 operation of dwarfout.c. */
1257 keep_next_level (1);
1259 /* The virtual function tables are set up now. */
1264 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
1265 whether this statements opens or closes a scope. PARTIAL_P is true
1266 for a partial scope, i.e, the scope that begins after a label when
1267 an object that needs a cleanup is created. If BEGIN_P is nonzero,
1268 returns a new TREE_LIST representing the top of the SCOPE_STMT
1269 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
1270 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
1271 and whose TREE_PURPOSE is the matching SCOPE_STMT iwth
1272 SCOPE_BEGIN_P set. */
1275 add_scope_stmt (begin_p
, partial_p
)
1282 /* Build the statement. */
1283 ss
= build_stmt (SCOPE_STMT
, NULL_TREE
);
1284 SCOPE_BEGIN_P (ss
) = begin_p
;
1285 SCOPE_PARTIAL_P (ss
) = partial_p
;
1287 /* Keep the scope stack up to date. */
1290 current_scope_stmt_stack
1291 = tree_cons (ss
, NULL_TREE
, current_scope_stmt_stack
);
1292 top
= current_scope_stmt_stack
;
1296 top
= current_scope_stmt_stack
;
1297 TREE_VALUE (top
) = ss
;
1298 current_scope_stmt_stack
= TREE_CHAIN (top
);
1301 /* Add the new statement to the statement-tree. */
1307 /* Finish a parenthesized expression EXPR. */
1310 finish_parenthesized_expr (expr
)
1313 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1314 /* This inhibits warnings in truthvalue_conversion. */
1315 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1317 if (TREE_CODE (expr
) == OFFSET_REF
)
1318 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1319 enclosed in parentheses. */
1320 PTRMEM_OK_P (expr
) = 0;
1324 /* Begin a statement-expression. The value returned must be passed to
1325 finish_stmt_expr. */
1330 /* If we're outside a function, we won't have a statement-tree to
1331 work with. But, if we see a statement-expression we need to
1333 if (! cfun
&& !last_tree
)
1334 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1336 keep_next_level (1);
1337 /* If we're building a statement tree, then the upcoming compound
1338 statement will be chained onto the tree structure, starting at
1339 last_tree. We return last_tree so that we can later unhook the
1340 compound statement. */
1344 /* Used when beginning a statement-expression outside function scope.
1345 For example, when handling a file-scope initializer, we use this
1349 begin_global_stmt_expr ()
1351 if (! cfun
&& !last_tree
)
1352 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1354 keep_next_level (1);
1356 return (last_tree
!= NULL_TREE
) ? last_tree
: expand_start_stmt_expr();
1359 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1362 finish_global_stmt_expr (stmt_expr
)
1365 stmt_expr
= expand_end_stmt_expr (stmt_expr
);
1368 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1369 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1374 /* Finish a statement-expression. RTL_EXPR should be the value
1375 returned by the previous begin_stmt_expr; EXPR is the
1376 statement-expression. Returns an expression representing the
1377 statement-expression. */
1380 finish_stmt_expr (rtl_expr
)
1385 /* If the last thing in the statement-expression was not an
1386 expression-statement, then it has type `void'. */
1387 if (!last_expr_type
)
1388 last_expr_type
= void_type_node
;
1389 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1390 TREE_SIDE_EFFECTS (result
) = 1;
1392 /* Remove the compound statement from the tree structure; it is
1393 now saved in the STMT_EXPR. */
1394 SET_LAST_STMT (rtl_expr
);
1395 TREE_CHAIN (last_tree
) = NULL_TREE
;
1397 /* If we created a statement-tree for this statement-expression,
1400 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1401 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1406 /* Finish a call to FN with ARGS. Returns a representation of the
1410 finish_call_expr (fn
, args
, koenig
)
1419 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1420 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1421 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1422 fn
= do_identifier (fn
, 2, args
);
1424 result
= build_x_function_call (fn
, args
, current_class_ref
);
1426 if (TREE_CODE (result
) == CALL_EXPR
1427 && (! TREE_TYPE (result
)
1428 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1429 result
= require_complete_type (result
);
1434 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1435 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1436 POSTDECREMENT_EXPR.) */
1439 finish_increment_expr (expr
, code
)
1441 enum tree_code code
;
1443 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1444 a COMPONENT_REF). This way if we've got, say, a reference to a
1445 static member that's being operated on, we don't end up trying to
1446 find a member operator for the class it's in. */
1448 if (TREE_CODE (expr
) == OFFSET_REF
)
1449 expr
= resolve_offset_ref (expr
);
1450 return build_x_unary_op (code
, expr
);
1453 /* Finish a use of `this'. Returns an expression for `this'. */
1460 if (current_class_ptr
)
1462 #ifdef WARNING_ABOUT_CCD
1463 TREE_USED (current_class_ptr
) = 1;
1465 result
= current_class_ptr
;
1467 else if (current_function_decl
1468 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1470 error ("`this' is unavailable for static member functions");
1471 result
= error_mark_node
;
1475 if (current_function_decl
)
1476 error ("invalid use of `this' in non-member function");
1478 error ("invalid use of `this' at top level");
1479 result
= error_mark_node
;
1485 /* Finish a member function call using OBJECT and ARGS as arguments to
1486 FN. Returns an expression for the call. */
1489 finish_object_call_expr (fn
, object
, args
)
1495 /* This is a future direction of this code, but because
1496 build_x_function_call cannot always undo what is done in
1497 build_component_ref entirely yet, we cannot do this. */
1499 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1500 return finish_call_expr (real_fn
, args
);
1502 if (DECL_DECLARES_TYPE_P (fn
))
1504 if (processing_template_decl
)
1505 /* This can happen on code like:
1508 template <class T> void f(T t) {
1512 We just grab the underlying IDENTIFIER. */
1513 fn
= DECL_NAME (fn
);
1516 cp_error ("calling type `%T' like a method", fn
);
1517 return error_mark_node
;
1521 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1525 /* Finish a qualified member function call using OBJECT and ARGS as
1526 arguments to FN. Returns an expressino for the call. */
1529 finish_qualified_object_call_expr (fn
, object
, args
)
1534 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1535 TREE_OPERAND (fn
, 1), args
);
1538 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1539 being the scope, if any, of DESTRUCTOR. Returns an expression for
1543 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1548 if (processing_template_decl
)
1549 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1551 if (scope
&& scope
!= destructor
)
1552 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1555 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1556 && (TREE_CODE (TREE_TYPE (object
)) !=
1557 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1558 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1560 return cp_convert (void_type_node
, object
);
1563 /* Finish a call to a globally qualified member function FN using
1564 ARGS. Returns an expression for the call. */
1567 finish_qualified_call_expr (fn
, args
)
1571 if (processing_template_decl
)
1572 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1574 return build_member_call (TREE_OPERAND (fn
, 0),
1575 TREE_OPERAND (fn
, 1),
1579 /* Finish an expression taking the address of LABEL. Returns an
1580 expression for the address. */
1583 finish_label_address_expr (label
)
1588 label
= lookup_label (label
);
1589 if (label
== NULL_TREE
)
1590 result
= null_pointer_node
;
1593 TREE_USED (label
) = 1;
1594 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1595 TREE_CONSTANT (result
) = 1;
1596 /* This function cannot be inlined. All jumps to the addressed
1597 label should wind up at the same point. */
1598 DECL_UNINLINABLE (current_function_decl
) = 1;
1604 /* Finish an expression of the form CODE EXPR. */
1607 finish_unary_op_expr (code
, expr
)
1608 enum tree_code code
;
1611 tree result
= build_x_unary_op (code
, expr
);
1612 /* Inside a template, build_x_unary_op does not fold the
1613 expression. So check whether the result is folded before
1614 setting TREE_NEGATED_INT. */
1615 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1616 && TREE_CODE (result
) == INTEGER_CST
1617 && !TREE_UNSIGNED (TREE_TYPE (result
))
1618 && INT_CST_LT (result
, integer_zero_node
))
1619 TREE_NEGATED_INT (result
) = 1;
1620 overflow_warning (result
);
1624 /* Finish an id-expression. */
1627 finish_id_expr (expr
)
1630 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1631 expr
= do_identifier (expr
, 1, NULL_TREE
);
1636 static tree current_type_lookups
;
1638 /* Perform deferred access control for types used in the type of a
1642 deferred_type_access_control ()
1644 tree lookup
= type_lookups
;
1646 if (lookup
== error_mark_node
)
1649 for (; lookup
; lookup
= TREE_CHAIN (lookup
))
1650 enforce_access (TREE_PURPOSE (lookup
), TREE_VALUE (lookup
));
1654 decl_type_access_control (decl
)
1659 if (type_lookups
== error_mark_node
)
1662 save_fn
= current_function_decl
;
1664 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
1665 current_function_decl
= decl
;
1667 deferred_type_access_control ();
1669 current_function_decl
= save_fn
;
1671 /* Now strip away the checks for the current declarator; they were
1672 added to type_lookups after typed_declspecs saved the copy that
1673 ended up in current_type_lookups. */
1674 type_lookups
= current_type_lookups
;
1678 save_type_access_control (lookups
)
1681 current_type_lookups
= lookups
;
1684 /* Begin a function definition declared with DECL_SPECS and
1685 DECLARATOR. Returns non-zero if the function-declaration is
1689 begin_function_definition (decl_specs
, declarator
)
1696 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1697 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1700 deferred_type_access_control ();
1701 type_lookups
= error_mark_node
;
1703 /* The things we're about to see are not directly qualified by any
1704 template headers we've seen thus far. */
1705 reset_specialization ();
1710 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1714 begin_constructor_declarator (scope
, name
)
1718 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1719 enter_scope_of (result
);
1723 /* Finish an init-declarator. Returns a DECL. */
1726 finish_declarator (declarator
, declspecs
, attributes
,
1727 prefix_attributes
, initialized
)
1731 tree prefix_attributes
;
1734 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1738 /* Finish a translation unit. */
1741 finish_translation_unit ()
1743 /* In case there were missing closebraces,
1744 get us back to the global binding level. */
1746 while (current_namespace
!= global_namespace
)
1751 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1752 Returns the parameter. */
1755 finish_template_type_parm (aggr
, identifier
)
1759 if (aggr
!= class_type_node
)
1761 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1762 aggr
= class_type_node
;
1765 return build_tree_list (aggr
, identifier
);
1768 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1769 Returns the parameter. */
1772 finish_template_template_parm (aggr
, identifier
)
1776 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1777 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1778 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1779 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1780 DECL_ARTIFICIAL (decl
) = 1;
1781 end_template_decl ();
1783 return finish_template_type_parm (aggr
, tmpl
);
1786 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1787 non-zero, the parameter list was terminated by a `...'. */
1790 finish_parmlist (parms
, ellipsis
)
1795 chainon (parms
, void_list_node
);
1796 /* We mark the PARMS as a parmlist so that declarator processing can
1797 disambiguate certain constructs. */
1798 if (parms
!= NULL_TREE
)
1799 TREE_PARMLIST (parms
) = 1;
1804 /* Begin a class definition, as indicated by T. */
1807 begin_class_definition (t
)
1810 if (t
== error_mark_node
1811 || ! IS_AGGR_TYPE (t
))
1813 t
= make_aggr_type (RECORD_TYPE
);
1814 pushtag (make_anon_name (), t
, 0);
1817 /* In a definition of a member class template, we will get here with an
1818 implicit typename, a TYPENAME_TYPE with a type. */
1819 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1822 /* If we generated a partial instantiation of this type, but now
1823 we're seeing a real definition, we're actually looking at a
1824 partial specialization. Consider:
1826 template <class T, class U>
1832 template <class T, class U>
1835 typename X<Y<T, U> >::A a;
1838 template <class T, class U>
1843 We have to undo the effects of the previous partial
1845 if (PARTIAL_INSTANTIATION_P (t
))
1849 /* Unfortunately, when we're not in pedantic mode, we
1850 attempt to actually fill in some of the fields of the
1851 partial instantiation, in order to support the implicit
1852 typename extension. Clear those fields now, in
1853 preparation for the definition here. The fields cleared
1854 here must match those set in instantiate_class_template.
1855 Look for a comment mentioning begin_class_definition
1857 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1858 TYPE_FIELDS (t
) = NULL_TREE
;
1859 TYPE_METHODS (t
) = NULL_TREE
;
1860 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1861 CLASSTYPE_VBASECLASSES (t
) = NULL_TREE
;
1862 TYPE_SIZE (t
) = NULL_TREE
;
1865 /* This isn't a partial instantiation any more. */
1866 PARTIAL_INSTANTIATION_P (t
) = 0;
1868 /* If this type was already complete, and we see another definition,
1870 else if (COMPLETE_TYPE_P (t
))
1871 duplicate_tag_error (t
);
1873 /* Update the location of the decl. */
1874 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1875 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1877 if (TYPE_BEING_DEFINED (t
))
1879 t
= make_aggr_type (TREE_CODE (t
));
1880 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1882 maybe_process_partial_specialization (t
);
1884 TYPE_BEING_DEFINED (t
) = 1;
1885 TYPE_PACKED (t
) = flag_pack_struct
;
1886 /* Reset the interface data, at the earliest possible
1887 moment, as it might have been set via a class foo;
1890 tree name
= TYPE_IDENTIFIER (t
);
1892 if (! ANON_AGGRNAME_P (name
))
1894 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1895 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1896 (t
, interface_unknown
);
1899 /* Only leave this bit clear if we know this
1900 class is part of an interface-only specification. */
1901 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1902 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1903 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1905 reset_specialization();
1907 /* Make a declaration for this class in its own scope. */
1908 build_self_reference ();
1913 /* Finish the member declaration given by DECL. */
1916 finish_member_declaration (decl
)
1919 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1922 if (decl
== void_type_node
)
1923 /* The COMPONENT was a friend, not a member, and so there's
1924 nothing for us to do. */
1927 /* We should see only one DECL at a time. */
1928 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1930 /* Set up access control for DECL. */
1932 = (current_access_specifier
== access_private_node
);
1933 TREE_PROTECTED (decl
)
1934 = (current_access_specifier
== access_protected_node
);
1935 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1937 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
1938 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
1941 /* Mark the DECL as a member of the current class. */
1942 DECL_CONTEXT (decl
) = current_class_type
;
1946 A C language linkage is ignored for the names of class members
1947 and the member function type of class member functions. */
1948 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
1949 DECL_LANGUAGE (decl
) = lang_cplusplus
;
1951 /* Put functions on the TYPE_METHODS list and everything else on the
1952 TYPE_FIELDS list. Note that these are built up in reverse order.
1953 We reverse them (to obtain declaration order) in finish_struct. */
1954 if (TREE_CODE (decl
) == FUNCTION_DECL
1955 || DECL_FUNCTION_TEMPLATE_P (decl
))
1957 /* We also need to add this function to the
1958 CLASSTYPE_METHOD_VEC. */
1959 add_method (current_class_type
, decl
, /*error_p=*/0);
1961 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1962 TYPE_METHODS (current_class_type
) = decl
;
1966 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1967 go at the beginning. The reason is that lookup_field_1
1968 searches the list in order, and we want a field name to
1969 override a type name so that the "struct stat hack" will
1970 work. In particular:
1972 struct S { enum E { }; int E } s;
1975 is legal. In addition, the FIELD_DECLs must be maintained in
1976 declaration order so that class layout works as expected.
1977 However, we don't need that order until class layout, so we
1978 save a little time by putting FIELD_DECLs on in reverse order
1979 here, and then reversing them in finish_struct_1. (We could
1980 also keep a pointer to the correct insertion points in the
1983 if (TREE_CODE (decl
) == TYPE_DECL
)
1984 TYPE_FIELDS (current_class_type
)
1985 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1988 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1989 TYPE_FIELDS (current_class_type
) = decl
;
1992 /* Enter the DECL into the scope of the class. */
1993 if (TREE_CODE (decl
) != USING_DECL
)
1994 pushdecl_class_level (decl
);
1998 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1999 the definition is immediately followed by a semicolon. Returns the
2003 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
2009 /* finish_struct nukes this anyway; if finish_exception does too,
2012 note_got_semicolon (t
);
2014 /* If we got any attributes in class_head, xref_tag will stick them in
2015 TREE_TYPE of the type. Grab them now. */
2016 attributes
= chainon (TREE_TYPE (t
), attributes
);
2017 TREE_TYPE (t
) = NULL_TREE
;
2019 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
2023 t
= finish_struct (t
, attributes
);
2025 note_got_semicolon (t
);
2029 check_for_missing_semicolon (t
);
2031 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
2032 if (current_scope () == current_function_decl
)
2033 do_pending_defargs ();
2038 /* Finish processing the default argument expressions cached during
2039 the processing of a class definition. */
2042 begin_inline_definitions ()
2044 if (current_scope () == current_function_decl
)
2045 do_pending_inlines ();
2048 /* Finish processing the inline function definitions cached during the
2049 processing of a class definition. */
2052 finish_inline_definitions ()
2054 if (current_class_type
== NULL_TREE
)
2055 clear_inline_text_obstack ();
2058 /* Finish processing the declaration of a member class template
2059 TYPES whose template parameters are given by PARMS. */
2062 finish_member_class_template (types
)
2067 /* If there are declared, but undefined, partial specializations
2068 mixed in with the typespecs they will not yet have passed through
2069 maybe_process_partial_specialization, so we do that here. */
2070 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
2071 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
2072 maybe_process_partial_specialization (TREE_VALUE (t
));
2074 note_list_got_semicolon (types
);
2075 grok_x_components (types
);
2076 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
2077 /* The component was in fact a friend declaration. We avoid
2078 finish_member_template_decl performing certain checks by
2082 finish_member_template_decl (types
);
2084 /* As with other component type declarations, we do
2085 not store the new DECL on the list of
2090 /* Finish processsing a complete template declaration. The PARMS are
2091 the template parameters. */
2094 finish_template_decl (parms
)
2098 end_template_decl ();
2100 end_specialization ();
2103 /* Finish processing a a template-id (which names a type) of the form
2104 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2105 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2106 the scope of template-id indicated. */
2109 finish_template_type (name
, args
, entering_scope
)
2116 decl
= lookup_template_class (name
, args
,
2117 NULL_TREE
, NULL_TREE
, entering_scope
);
2118 if (decl
!= error_mark_node
)
2119 decl
= TYPE_STUB_DECL (decl
);
2124 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2125 namespace scope or a class scope. */
2131 tree scope
= TREE_OPERAND (sr
, 0);
2133 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2135 push_decl_namespace (scope
);
2136 TREE_COMPLEXITY (sr
) = -1;
2138 else if (scope
!= current_class_type
)
2140 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2142 /* In a declarator for a template class member, the scope will
2143 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2144 scope
= TREE_TYPE (scope
);
2145 TREE_OPERAND (sr
, 0) = scope
;
2147 push_nested_class (scope
, 3);
2148 TREE_COMPLEXITY (sr
) = current_class_depth
;
2152 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2153 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2154 BASE_CLASS, or NULL_TREE if an error occurred. The
2155 ACCESSS_SPECIFIER is one of
2156 access_{default,public,protected_private}[_virtual]_node.*/
2159 finish_base_specifier (access_specifier
, base_class
)
2160 tree access_specifier
;
2166 if (base_class
== NULL_TREE
)
2168 error ("invalid base class");
2169 type
= error_mark_node
;
2172 type
= TREE_TYPE (base_class
);
2174 if (! is_aggr_type (type
, 1))
2177 result
= build_tree_list (access_specifier
, type
);
2182 /* Called when multiple declarators are processed. If that is not
2183 premitted in this context, an error is issued. */
2186 check_multiple_declarators ()
2190 In a template-declaration, explicit specialization, or explicit
2191 instantiation the init-declarator-list in the declaration shall
2192 contain at most one declarator.
2194 We don't just use PROCESSING_TEMPLATE_DECL for the first
2195 condition since that would disallow the perfectly legal code,
2196 like `template <class T> struct S { int i, j; };'. */
2197 tree scope
= current_scope ();
2199 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2200 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2203 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2204 || processing_explicit_instantiation
2205 || processing_specialization
)
2206 cp_error ("multiple declarators in template declaration");
2210 finish_typeof (expr
)
2213 if (processing_template_decl
)
2217 t
= make_aggr_type (TYPEOF_TYPE
);
2218 TYPE_FIELDS (t
) = expr
;
2223 return TREE_TYPE (expr
);
2226 /* Remove declarations of internal variables that are not used from a
2227 stmt tree. To qualify, the variable must have a name and must have
2228 a zero DECL_SOURCE_LINE. We tried to remove all variables for
2229 which TREE_USED was false, but it turns out that there's tons of
2230 variables for which TREE_USED is false but that are still in fact
2234 prune_unused_decls (tp
, walk_subtrees
, data
)
2236 int *walk_subtrees ATTRIBUTE_UNUSED
;
2237 void *data ATTRIBUTE_UNUSED
;
2247 if (TREE_CODE (t
) == DECL_STMT
)
2249 tree d
= DECL_STMT_DECL (t
);
2250 if (!TREE_USED (d
) && DECL_NAME (d
) && DECL_SOURCE_LINE (d
) == 0)
2252 *tp
= TREE_CHAIN (t
);
2253 /* Recurse on the new value of tp, otherwise we will skip
2254 the next statement. */
2255 return prune_unused_decls (tp
, walk_subtrees
, data
);
2258 else if (TREE_CODE (t
) == SCOPE_STMT
)
2260 /* Remove all unused decls from the BLOCK of this SCOPE_STMT. */
2261 tree block
= SCOPE_STMT_BLOCK (t
);
2267 for (vp
= &BLOCK_VARS (block
); *vp
; )
2270 if (! TREE_USED (v
) && DECL_NAME (v
) && DECL_SOURCE_LINE (v
) == 0)
2271 *vp
= TREE_CHAIN (v
); /* drop */
2273 vp
= &TREE_CHAIN (v
); /* advance */
2275 /* If there are now no variables, the entire BLOCK can be dropped.
2276 (This causes SCOPE_NULLIFIED_P (t) to be true.) */
2277 if (BLOCK_VARS (block
) == NULL_TREE
)
2278 SCOPE_STMT_BLOCK (t
) = NULL_TREE
;
2284 /* Create an empty statement tree rooted at T. */
2290 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2291 what follows. We remove the extraneous statement in
2292 finish_stmt_tree. */
2293 *t
= build_nt (EXPR_STMT
, void_zero_node
);
2295 last_expr_type
= NULL_TREE
;
2298 /* Finish the statement tree rooted at T. */
2301 finish_stmt_tree (t
)
2306 /* Remove the fake extra statement added in begin_stmt_tree. */
2307 stmt
= TREE_CHAIN (*t
);
2309 SET_LAST_STMT (NULL_TREE
);
2311 /* Remove unused decls from the stmt tree. */
2312 walk_stmt_tree (t
, prune_unused_decls
, NULL
);
2316 /* The line-number recorded in the outermost statement in a function
2317 is the line number of the end of the function. */
2318 STMT_LINENO (stmt
) = lineno
;
2319 STMT_LINENO_FOR_FN_P (stmt
) = 1;
2323 /* We're about to expand T, a statement. Set up appropriate context
2324 for the substitution. */
2330 if (!STMT_LINENO_FOR_FN_P (t
))
2331 lineno
= STMT_LINENO (t
);
2332 current_stmt_tree
->stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2335 /* Generate RTL for the statement T, and its substatements, and any
2336 other statements at its nesting level. */
2339 lang_expand_stmt (t
)
2342 tree rval
= NULL_TREE
;
2344 while (t
&& t
!= error_mark_node
)
2346 int saved_stmts_are_full_exprs_p
;
2348 /* Assume we'll have nothing to return. */
2351 /* Set up context appropriately for handling this statement. */
2352 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p ();
2355 switch (TREE_CODE (t
))
2358 genrtl_return_stmt (RETURN_EXPR (t
));
2362 genrtl_expr_stmt (EXPR_STMT_EXPR (t
));
2366 genrtl_decl_stmt (t
);
2370 genrtl_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2373 case START_CATCH_STMT
:
2374 genrtl_catch_block (TREE_TYPE (t
));
2378 genrtl_ctor_stmt (t
);
2382 genrtl_for_stmt (t
);
2386 genrtl_while_stmt (t
);
2398 genrtl_compound_stmt (t
);
2402 genrtl_break_stmt ();
2406 genrtl_continue_stmt ();
2410 genrtl_switch_stmt (t
);
2414 genrtl_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2418 expand_label (LABEL_STMT_LABEL (t
));
2422 genrtl_goto_stmt (GOTO_DESTINATION (t
));
2426 genrtl_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
),
2427 ASM_OUTPUTS (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2431 genrtl_try_block (t
);
2439 genrtl_subobject (SUBOBJECT_CLEANUP (t
));
2443 genrtl_scope_stmt (t
);
2447 genrtl_named_return_value ();
2451 my_friendly_abort (19990810);
2455 /* Restore saved state. */
2456 current_stmt_tree
->stmts_are_full_exprs_p
= saved_stmts_are_full_exprs_p
;
2458 /* Go on to the next statement in this scope. */
2465 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2466 will equivalent CALL_EXPRs. */
2469 simplify_aggr_init_exprs_r (tp
, walk_subtrees
, data
)
2471 int *walk_subtrees ATTRIBUTE_UNUSED
;
2472 void *data ATTRIBUTE_UNUSED
;
2474 tree aggr_init_expr
;
2481 int copy_from_buffer_p
;
2483 aggr_init_expr
= *tp
;
2484 /* We don't need to walk into types; there's nothing in a type that
2485 needs simplification. (And, furthermore, there are places we
2486 actively don't want to go. For example, we don't want to wander
2487 into the default arguments for a FUNCTION_DECL that appears in a
2489 if (TYPE_P (aggr_init_expr
))
2494 /* Only AGGR_INIT_EXPRs are interesting. */
2495 else if (TREE_CODE (aggr_init_expr
) != AGGR_INIT_EXPR
)
2498 /* Form an appropriate CALL_EXPR. */
2499 fn
= TREE_OPERAND (aggr_init_expr
, 0);
2500 args
= TREE_OPERAND (aggr_init_expr
, 1);
2501 slot
= TREE_OPERAND (aggr_init_expr
, 2);
2502 type
= TREE_TYPE (aggr_init_expr
);
2504 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
2506 /* Replace the first argument with the address of the third
2507 argument to the AGGR_INIT_EXPR. */
2508 call_type
= build_pointer_type (type
);
2509 mark_addressable (slot
);
2510 args
= tree_cons (NULL_TREE
, build1 (ADDR_EXPR
, call_type
, slot
),
2513 call_expr
= build (CALL_EXPR
, call_type
, fn
, args
, NULL_TREE
);
2514 TREE_SIDE_EFFECTS (call_expr
) = 1;
2516 /* If we're using the non-reentrant PCC calling convention, then we
2517 need to copy the returned value out of the static buffer into the
2519 copy_from_buffer_p
= 0;
2520 #ifdef PCC_STATIC_STRUCT_RETURN
2521 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) && aggregate_value_p (type
))
2525 flag_access_control
= 0;
2526 call_expr
= build_aggr_init (slot
, call_expr
, LOOKUP_ONLYCONVERTING
);
2527 flag_access_control
= old_ac
;
2528 copy_from_buffer_p
= 1;
2532 /* If this AGGR_INIT_EXPR indicates the value returned by a
2533 function, then we want to use the value of the initialized
2534 location as the result. */
2535 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) || copy_from_buffer_p
)
2537 call_expr
= build (COMPOUND_EXPR
, type
,
2539 TREE_SIDE_EFFECTS (call_expr
) = 1;
2542 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2543 TREE_CHAIN (call_expr
) = TREE_CHAIN (aggr_init_expr
);
2546 /* Keep iterating. */
2550 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2553 emit_associated_thunks (fn
)
2556 /* When we use vcall offsets, we emit thunks with the virtual
2557 functions to which they thunk. The whole point of vcall offsets
2558 is so that you can know statically the entire set of thunks that
2559 will ever be needed for a given virtual function, thereby
2560 enabling you to output all the thunks with the function itself. */
2561 if (vcall_offsets_in_vtable_p () && DECL_VIRTUAL_P (fn
))
2566 for (binfo
= TYPE_BINFO (DECL_CONTEXT (fn
));
2568 binfo
= TREE_CHAIN (binfo
))
2569 for (v
= BINFO_VIRTUALS (binfo
); v
; v
= TREE_CHAIN (v
))
2571 && (!integer_zerop (BV_DELTA (v
))
2572 || BV_VCALL_INDEX (v
)))
2577 if (BV_USE_VCALL_INDEX_P (v
))
2579 vcall_index
= BV_VCALL_INDEX (v
);
2580 my_friendly_assert (vcall_index
!= NULL_TREE
, 20000621);
2583 vcall_index
= NULL_TREE
;
2585 thunk
= make_thunk (build1 (ADDR_EXPR
,
2586 vfunc_ptr_type_node
,
2590 /*generate_with_vtable_p=*/0);
2591 use_thunk (thunk
, /*emit_p=*/1);
2597 /* Generate RTL for FN. */
2604 const char *saved_input_filename
;
2606 /* When the parser calls us after finishing the body of a template
2607 function, we don't really want to expand the body. When we're
2608 processing an in-class definition of an inline function,
2609 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2610 to look at the function itself. */
2611 if (processing_template_decl
2612 || (DECL_LANG_SPECIFIC (fn
)
2613 && DECL_TEMPLATE_INFO (fn
)
2614 && uses_template_parms (DECL_TI_ARGS (fn
))))
2616 /* Normally, collection only occurs in rest_of_compilation. So,
2617 if we don't collect here, we never collect junk generated
2618 during the processing of templates until we hit a
2619 non-template function. */
2624 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2625 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn
),
2626 simplify_aggr_init_exprs_r
,
2629 /* If this is a constructor or destructor body, we have to clone it
2630 under the new ABI. */
2631 if (maybe_clone_body (fn
))
2633 /* We don't want to process FN again, so pretend we've written
2634 it out, even though we haven't. */
2635 TREE_ASM_WRITTEN (fn
) = 1;
2639 /* There's no reason to do any of the work here if we're only doing
2640 semantic analysis; this code just generates RTL. */
2641 if (flag_syntax_only
)
2644 /* If possible, avoid generating RTL for this function. Instead,
2645 just record it as an inline function, and wait until end-of-file
2646 to decide whether to write it out or not. */
2647 if (/* We have to generate RTL if it's not an inline function. */
2648 (DECL_INLINE (fn
) || DECL_COMDAT (fn
))
2649 /* Or if we have to keep all inline functions anyhow. */
2650 && !flag_keep_inline_functions
2651 /* Or if we actually have a reference to the function. */
2652 && !DECL_NEEDED_P (fn
)
2653 /* Or if this is a nested function. */
2654 && !decl_function_context (fn
))
2656 /* Give the function RTL now so that we can assign it to a
2657 function pointer, etc. */
2658 make_function_rtl (fn
);
2659 /* Set DECL_EXTERNAL so that assemble_external will be called as
2660 necessary. We'll clear it again in finish_file. */
2661 if (!DECL_EXTERNAL (fn
))
2663 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2664 DECL_EXTERNAL (fn
) = 1;
2666 /* Remember this function. In finish_file we'll decide if
2667 we actually need to write this function out. */
2669 /* Let the back-end know that this funtion exists. */
2670 note_deferral_of_defined_inline_function (fn
);
2674 /* Emit any thunks that should be emitted at the same time as FN. */
2675 emit_associated_thunks (fn
);
2677 timevar_push (TV_INTEGRATION
);
2679 /* Optimize the body of the function before expanding it. */
2680 optimize_function (fn
);
2682 timevar_pop (TV_INTEGRATION
);
2683 timevar_push (TV_EXPAND
);
2685 /* Save the current file name and line number. When we expand the
2686 body of the function, we'll set LINENO and INPUT_FILENAME so that
2687 error-mesages come out in the right places. */
2688 saved_lineno
= lineno
;
2689 saved_input_filename
= input_filename
;
2690 lineno
= DECL_SOURCE_LINE (fn
);
2691 input_filename
= DECL_SOURCE_FILE (fn
);
2693 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2694 store_parm_decls ();
2695 current_function_is_thunk
= DECL_THUNK_P (fn
);
2697 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2698 any of the other magic variables we set up when starting a
2700 cp_function_chain
->name_declared
= 1;
2702 /* Expand the body. */
2703 expand_stmt (DECL_SAVED_TREE (fn
));
2705 /* Statements should always be full-expressions at the outermost set
2706 of curly braces for a function. */
2707 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2709 /* The outermost statement for a function contains the line number
2710 recorded when we finished processing the function. */
2711 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2713 /* Generate code for the function. */
2714 finish_function (0);
2716 /* If possible, obliterate the body of the function so that it can
2717 be garbage collected. */
2718 if (flag_dump_translation_unit
)
2719 /* Keep the body; we're going to dump it. */
2721 else if (DECL_INLINE (fn
) && flag_inline_trees
)
2722 /* We might need the body of this function so that we can expand
2723 it inline somewhere else. */
2726 /* We don't need the body; blow it away. */
2727 DECL_SAVED_TREE (fn
) = NULL_TREE
;
2729 /* And restore the current source position. */
2730 lineno
= saved_lineno
;
2731 input_filename
= saved_input_filename
;
2732 extract_interface_info ();
2734 timevar_pop (TV_EXPAND
);