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 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
37 /* There routines provide a modular interface to perform many parsing
38 operations. They may therefore be used during actual parsing, or
39 during template instantiation, which may be regarded as a
40 degenerate form of parsing. Since the current g++ parser is
41 lacking in several respects, and will be reimplemented, we are
42 attempting to move most code that is not directly related to
43 parsing into this file; that will make implementing the new parser
44 much easier since it will be able to make use of these routines. */
46 static tree expand_cond
PROTO((tree
));
47 static tree maybe_convert_cond
PROTO((tree
));
49 /* Record the fact that STMT was the last statement added to the
52 #define SET_LAST_STMT(stmt) \
53 (current_stmt_tree->x_last_stmt = (stmt))
55 /* When parsing a template, LAST_TREE contains the last statement
56 parsed. These are chained together through the TREE_CHAIN field,
57 but often need to be re-organized since the parse is performed
58 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
61 #define RECHAIN_STMTS(stmt, substmt) \
63 substmt = TREE_CHAIN (stmt); \
64 TREE_CHAIN (stmt) = NULL_TREE; \
65 SET_LAST_STMT (stmt); \
68 /* Finish processing the COND, the SUBSTMT condition for STMT. */
70 #define FINISH_COND(cond, stmt, substmt) \
72 if (last_tree != stmt) \
74 RECHAIN_STMTS (stmt, substmt); \
75 if (!processing_template_decl) \
77 cond = build_tree_list (substmt, cond); \
85 /* T is a statement. Add it to the statement-tree. */
91 /* Add T to the statement-tree. */
92 TREE_CHAIN (last_tree
) = t
;
95 /* When we expand a statement-tree, we must know whether or not the
96 statements are full-expresions. We record that fact here. */
97 if (building_stmt_tree ())
98 STMT_IS_FULL_EXPR_P (last_tree
) = stmts_are_full_exprs_p
;
101 /* COND is the condition-expression for an if, while, etc.,
102 statement. Convert it to a boolean value, if appropriate. */
105 maybe_convert_cond (cond
)
108 /* Empty conditions remain empty. */
112 /* Wait until we instantiate templates before doing conversion. */
113 if (processing_template_decl
)
116 /* Do the conversion. */
117 cond
= convert_from_reference (cond
);
118 return condition_conversion (cond
);
121 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
124 finish_expr_stmt (expr
)
127 if (expr
!= NULL_TREE
)
129 if (building_stmt_tree ())
131 /* Do default conversion if safe and possibly important,
132 in case within ({...}). */
133 if (!processing_template_decl
134 && !stmts_are_full_exprs_p
135 && ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
137 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
138 expr
= default_conversion (expr
);
140 if (!processing_template_decl
)
141 expr
= break_out_cleanups (expr
);
143 add_tree (build_min_nt (EXPR_STMT
, expr
));
147 emit_line_note (input_filename
, lineno
);
149 if (stmts_are_full_exprs_p
)
150 expand_start_target_temps ();
152 cplus_expand_expr_stmt (expr
);
154 if (stmts_are_full_exprs_p
)
155 expand_end_target_temps ();
161 /* This was an expression-statement, so we save the type of the
163 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
166 /* Begin an if-statement. Returns a newly created IF_STMT if
176 if (building_stmt_tree ())
178 r
= build_min_nt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
187 /* Process the COND of an if-statement, which may be given by
191 finish_if_stmt_cond (cond
, if_stmt
)
195 cond
= maybe_convert_cond (cond
);
197 if (building_stmt_tree ())
198 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
201 emit_line_note (input_filename
, lineno
);
202 expand_start_cond (cond
, 0);
206 /* Finish the then-clause of an if-statement, which may be given by
210 finish_then_clause (if_stmt
)
213 if (building_stmt_tree ())
215 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
216 SET_LAST_STMT (if_stmt
);
223 /* Begin the else-clause of an if-statement. */
228 if (!building_stmt_tree ())
229 expand_start_else ();
232 /* Finish the else-clause of an if-statement, which may be given by
236 finish_else_clause (if_stmt
)
239 if (building_stmt_tree ())
240 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
243 /* Finsh an if-statement. */
248 if (!building_stmt_tree ())
255 /* Begin a while-statement. Returns a newly created WHILE_STMT if
263 if (building_stmt_tree ())
265 r
= build_min_nt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
271 emit_line_note (input_filename
, lineno
);
272 expand_start_loop (1);
281 /* Process the COND of an if-statement, which may be given by
285 finish_while_stmt_cond (cond
, while_stmt
)
289 cond
= maybe_convert_cond (cond
);
291 if (building_stmt_tree ())
292 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
295 emit_line_note (input_filename
, lineno
);
296 expand_exit_loop_if_false (0, cond
);
299 /* If COND wasn't a declaration, clear out the
300 block we made for it and start a new one here so the
301 optimization in expand_end_loop will work. */
302 if (getdecls () == NULL_TREE
)
309 /* Finish a while-statement, which may be given by WHILE_STMT. */
312 finish_while_stmt (while_stmt
)
317 if (building_stmt_tree ())
318 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
324 /* Begin a do-statement. Returns a newly created DO_STMT if
330 if (building_stmt_tree ())
332 tree r
= build_min_nt (DO_STMT
, NULL_TREE
, NULL_TREE
);
339 emit_line_note (input_filename
, lineno
);
340 expand_start_loop_continue_elsewhere (1);
345 /* Finish the body of a do-statement, which may be given by DO_STMT. */
348 finish_do_body (do_stmt
)
351 if (building_stmt_tree ())
352 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
354 expand_loop_continue_here ();
357 /* Finish a do-statement, which may be given by DO_STMT, and whose
358 COND is as indicated. */
361 finish_do_stmt (cond
, do_stmt
)
365 cond
= maybe_convert_cond (cond
);
367 if (building_stmt_tree ())
368 DO_COND (do_stmt
) = cond
;
371 emit_line_note (input_filename
, lineno
);
372 expand_exit_loop_if_false (0, cond
);
379 /* Finish a return-statement. The EXPRESSION returned, if any, is as
383 finish_return_stmt (expr
)
386 if (doing_semantic_analysis_p () && !processing_template_decl
)
387 expr
= check_return_expr (expr
);
389 if (doing_semantic_analysis_p () && !processing_template_decl
)
391 if (DECL_CONSTRUCTOR_P (current_function_decl
) && ctor_label
)
393 /* Even returns without a value in a constructor must return
394 `this'. We accomplish this by sending all returns in a
395 constructor to the CTOR_LABEL; finish_function emits code to
396 return a value there. When we finally generate the real
397 return statement, CTOR_LABEL is no longer set, and we fall
398 through into the normal return-processing code below. */
399 finish_goto_stmt (ctor_label
);
402 else if (DECL_DESTRUCTOR_P (current_function_decl
))
404 /* Similarly, all destructors must run destructors for
405 base-classes before returning. So, all returns in a
406 destructor get sent to the DTOR_LABEL; finsh_function emits
407 code to return a value there. */
408 finish_goto_stmt (dtor_label
);
413 if (building_stmt_tree ())
414 add_tree (build_min_nt (RETURN_STMT
, expr
));
417 emit_line_note (input_filename
, lineno
);
418 c_expand_return (expr
);
424 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
431 if (building_stmt_tree ())
433 r
= build_min_nt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
434 NULL_TREE
, NULL_TREE
);
440 if (flag_new_for_scope
> 0)
443 note_level_for_for ();
449 /* Finish the for-init-statement of a for-statement, which may be
450 given by FOR_STMT. */
453 finish_for_init_stmt (for_stmt
)
456 if (building_stmt_tree ())
458 if (last_tree
!= for_stmt
)
459 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
464 emit_line_note (input_filename
, lineno
);
465 expand_start_loop_continue_elsewhere (1);
471 /* Finish the COND of a for-statement, which may be given by
475 finish_for_cond (cond
, for_stmt
)
479 cond
= maybe_convert_cond (cond
);
481 if (building_stmt_tree ())
482 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
485 emit_line_note (input_filename
, lineno
);
487 expand_exit_loop_if_false (0, cond
);
490 /* If the cond wasn't a declaration, clear out the
491 block we made for it and start a new one here so the
492 optimization in expand_end_loop will work. */
493 if (getdecls () == NULL_TREE
)
500 /* Finish the increment-EXPRESSION in a for-statement, which may be
501 given by FOR_STMT. */
504 finish_for_expr (expr
, for_stmt
)
508 if (building_stmt_tree ())
509 FOR_EXPR (for_stmt
) = expr
;
512 /* Finish the body of a for-statement, which may be given by
513 FOR_STMT. The increment-EXPR for the loop must be
517 finish_for_stmt (expr
, for_stmt
)
521 /* Pop the scope for the body of the loop. */
524 if (building_stmt_tree ())
525 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
528 emit_line_note (input_filename
, lineno
);
529 expand_loop_continue_here ();
531 finish_expr_stmt (expr
);
535 if (flag_new_for_scope
> 0)
541 /* Finish a break-statement. */
546 emit_line_note (input_filename
, lineno
);
547 if (building_stmt_tree ())
548 add_tree (build_min_nt (BREAK_STMT
));
549 else if ( ! expand_exit_something ())
550 cp_error ("break statement not within loop or switch");
553 /* Finish a continue-statement. */
556 finish_continue_stmt ()
558 emit_line_note (input_filename
, lineno
);
559 if (building_stmt_tree ())
560 add_tree (build_min_nt (CONTINUE_STMT
));
561 else if (! expand_continue_loop (0))
562 cp_error ("continue statement not within a loop");
565 /* Begin a switch-statement. Returns a new SWITCH_STMT if
573 if (building_stmt_tree ())
575 r
= build_min_nt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
586 /* Finish the cond of a switch-statement. */
589 finish_switch_cond (cond
, switch_stmt
)
593 if (building_stmt_tree ())
594 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
595 else if (cond
!= error_mark_node
)
597 emit_line_note (input_filename
, lineno
);
598 c_expand_start_case (cond
);
601 /* The code is in error, but we don't want expand_end_case to
603 c_expand_start_case (boolean_false_node
);
608 /* Finish the body of a switch-statement, which may be given by
609 SWITCH_STMT. The COND to switch on is indicated. */
612 finish_switch_stmt (cond
, switch_stmt
)
616 if (building_stmt_tree ())
617 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
619 expand_end_case (cond
);
625 /* Finish a case-label. */
628 finish_case_label (low_value
, high_value
)
632 if (building_stmt_tree ())
634 /* Add a representation for the case label to the statement
636 add_tree (build_min_nt (CASE_LABEL
, low_value
, high_value
));
637 /* And warn about crossing initializations, etc. */
638 if (!processing_template_decl
)
639 define_case_label ();
643 do_case (low_value
, high_value
);
646 /* Finish a goto-statement. */
649 finish_goto_stmt (destination
)
652 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
653 destination
= lookup_label (destination
);
655 /* We warn about unused labels with -Wunused. That means we have to
656 mark the used labels as used. */
657 if (TREE_CODE (destination
) == LABEL_DECL
)
658 TREE_USED (destination
) = 1;
660 if (building_stmt_tree ())
661 add_tree (build_min_nt (GOTO_STMT
, destination
));
664 emit_line_note (input_filename
, lineno
);
666 if (TREE_CODE (destination
) == LABEL_DECL
)
668 label_rtx (destination
);
669 expand_goto (destination
);
672 expand_computed_goto (destination
);
676 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
682 if (building_stmt_tree ())
684 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
691 emit_line_note (input_filename
, lineno
);
692 expand_start_try_stmts ();
697 /* Likewise, for a function-try-block. */
700 begin_function_try_block ()
702 if (building_stmt_tree ())
704 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
706 FN_TRY_BLOCK_P (r
) = 1;
712 if (! current_function_parms_stored
)
714 expand_start_early_try_stmts ();
719 /* Finish a try-block, which may be given by TRY_BLOCK. */
722 finish_try_block (try_block
)
725 if (building_stmt_tree ())
726 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
728 expand_start_all_catch ();
731 /* Finish the body of a cleanup try-block, which may be given by
735 finish_cleanup_try_block (try_block
)
738 if (building_stmt_tree ())
739 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
742 /* Finish an implicitly generated try-block, with a cleanup is given
746 finish_cleanup (cleanup
, try_block
)
750 if (building_stmt_tree ())
752 TRY_HANDLERS (try_block
) = cleanup
;
753 CLEANUP_P (try_block
) = 1;
756 expand_eh_region_end (protect_with_terminate (cleanup
));
759 /* Likewise, for a function-try-block. */
762 finish_function_try_block (try_block
)
765 if (building_stmt_tree ())
767 if (TREE_CHAIN (try_block
)
768 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
770 /* Chain the compound statement after the CTOR_INITIALIZER. */
771 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
772 /* And make the CTOR_INITIALIZER the body of the try-block. */
773 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
776 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
780 end_protect_partials ();
781 expand_start_all_catch ();
784 in_function_try_handler
= 1;
787 /* Finish a handler-sequence for a try-block, which may be given by
791 finish_handler_sequence (try_block
)
794 if (building_stmt_tree ())
795 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
797 expand_end_all_catch ();
800 /* Likewise, for a function-try-block. */
803 finish_function_handler_sequence (try_block
)
806 in_function_try_handler
= 0;
808 if (building_stmt_tree ())
809 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
811 expand_end_all_catch ();
814 /* Begin a handler. Returns a HANDLER if appropriate. */
821 if (building_stmt_tree ())
823 r
= build_min_nt (HANDLER
, NULL_TREE
, NULL_TREE
);
834 /* Finish the handler-parameters for a handler, which may be given by
835 HANDLER. DECL is the declaration for the catch parameter, or NULL
836 if this is a `catch (...)' clause. */
839 finish_handler_parms (decl
, handler
)
843 tree blocks
= NULL_TREE
;
845 if (processing_template_decl
)
849 decl
= pushdecl (decl
);
850 decl
= push_template_decl (decl
);
851 add_decl_stmt (decl
);
852 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
855 else if (building_stmt_tree ())
856 blocks
= expand_start_catch_block (decl
);
861 /* Note the beginning of a handler for TYPE. This function is called
862 at the point to which control should be transferred when an
863 appropriately-typed exception is thrown. */
866 begin_catch_block (type
)
869 if (building_stmt_tree ())
870 add_tree (build (START_CATCH_STMT
, type
));
872 start_catch_handler (type
);
875 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
876 the return value from the matching call to finish_handler_parms. */
879 finish_handler (blocks
, handler
)
883 if (!processing_template_decl
)
885 if (building_stmt_tree ())
886 expand_end_catch_block (blocks
);
888 if (!building_stmt_tree ())
890 /* Fall to outside the try statement when done executing
891 handler and we fall off end of handler. This is jump
892 Lresume in the documentation. */
893 expand_goto (top_label_entry (&caught_return_label_stack
));
894 end_catch_handler ();
900 if (building_stmt_tree ())
901 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
904 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
905 compound-statement does not define a scope. Returns a new
906 COMPOUND_STMT if appropriate. */
909 begin_compound_stmt (has_no_scope
)
914 if (building_stmt_tree ())
916 r
= build_min_nt (COMPOUND_STMT
, NULL_TREE
);
919 COMPOUND_STMT_NO_SCOPE (r
) = 1;
924 last_expr_type
= NULL_TREE
;
929 /* Normally, we try hard to keep the BLOCK for a
930 statement-expression. But, if it's a statement-expression with
931 a scopeless block, there's nothing to keep, and we don't want
932 to accidentally keep a block *inside* the scopeless block. */
935 /* If this is the outermost block of the function, declare the
936 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
938 && !current_function_name_declared
939 && !processing_template_decl
942 declare_function_name ();
943 current_function_name_declared
= 1;
950 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
951 If HAS_NO_SCOPE is non-zero, the compound statement does not define
955 finish_compound_stmt (has_no_scope
, compound_stmt
)
967 if (building_stmt_tree ())
968 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
970 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
971 the precise purpose of that variable is store the type of the
972 last expression statement within the last compound statement, we
973 preserve the value. */
981 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
982 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
986 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
987 input_operands
, clobbers
)
990 tree output_operands
;
994 if (TREE_CHAIN (string
))
995 string
= combine_strings (string
);
997 if (cv_qualifier
!= NULL_TREE
998 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
1000 cp_warning ("%s qualifier ignored on asm",
1001 IDENTIFIER_POINTER (cv_qualifier
));
1002 cv_qualifier
= NULL_TREE
;
1005 if (building_stmt_tree ())
1007 tree r
= build_min_nt (ASM_STMT
, cv_qualifier
, string
,
1008 output_operands
, input_operands
,
1014 emit_line_note (input_filename
, lineno
);
1015 if (output_operands
!= NULL_TREE
|| input_operands
!= NULL_TREE
1016 || clobbers
!= NULL_TREE
)
1020 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
1021 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
1023 c_expand_asm_operands (string
, output_operands
,
1026 cv_qualifier
!= NULL_TREE
,
1027 input_filename
, lineno
);
1030 expand_asm (string
);
1036 /* Finish a label with the indicated NAME. */
1039 finish_label_stmt (name
)
1042 tree decl
= define_label (input_filename
, lineno
, name
);
1044 if (building_stmt_tree ())
1045 add_tree (build_min_nt (LABEL_STMT
, decl
));
1047 expand_label (decl
);
1050 /* Finish a series of declarations for local labels. G++ allows users
1051 to declare "local" labels, i.e., labels with scope. This extension
1052 is useful when writing code involving statement-expressions. */
1055 finish_label_decl (name
)
1058 tree decl
= declare_local_label (name
);
1059 if (building_stmt_tree ())
1060 add_decl_stmt (decl
);
1063 /* Create a declaration statement for the declaration given by the
1067 add_decl_stmt (decl
)
1072 /* We need the type to last until instantiation time. */
1073 decl_stmt
= build_min_nt (DECL_STMT
, decl
);
1074 add_tree (decl_stmt
);
1077 /* We're in a constructor, and have just constructed a a subobject of
1078 *THIS. CLEANUP is code to run if an exception is thrown before the
1079 end of the current function is reached. */
1082 finish_subobject (cleanup
)
1085 if (building_stmt_tree ())
1087 tree r
= build_min_nt (SUBOBJECT
, cleanup
);
1091 add_partial_entry (cleanup
);
1094 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1097 finish_decl_cleanup (decl
, cleanup
)
1101 if (building_stmt_tree ())
1102 add_tree (build_min_nt (CLEANUP_STMT
, decl
, cleanup
));
1104 || (DECL_SIZE (decl
) && TREE_TYPE (decl
) != error_mark_node
))
1105 expand_decl_cleanup (decl
, cleanup
);
1108 /* Bind a name and initialization to the return value of
1109 the current function. */
1112 finish_named_return_value (return_id
, init
)
1113 tree return_id
, init
;
1115 tree decl
= DECL_RESULT (current_function_decl
);
1118 /* Give this error as many times as there are occurrences,
1119 so that users can use Emacs compilation buffers to find
1120 and fix all such places. */
1121 pedwarn ("ANSI C++ does not permit named return values");
1123 if (return_id
!= NULL_TREE
)
1125 if (DECL_NAME (decl
) == NULL_TREE
)
1127 DECL_NAME (decl
) = return_id
;
1128 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1132 cp_error ("return identifier `%D' already in place", return_id
);
1137 /* Can't let this happen for constructors. */
1138 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1140 error ("can't redefine default return value for constructors");
1144 /* If we have a named return value, put that in our scope as well. */
1145 if (DECL_NAME (decl
) != NULL_TREE
)
1147 /* Let `cp_finish_decl' know that this initializer is ok. */
1148 DECL_INITIAL (decl
) = init
;
1149 if (doing_semantic_analysis_p ())
1152 if (building_stmt_tree ())
1153 add_tree (build_min_nt (RETURN_INIT
, return_id
, init
));
1156 cp_finish_decl (decl
, init
, NULL_TREE
, 0);
1157 store_return_init (decl
);
1162 /* Cache the value of this class's main virtual function table pointer
1163 in a register variable. This will save one indirection if a
1164 more than one virtual function call is made this function. */
1169 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1171 /* If we've already done this, there's no need to do it again. */
1175 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1177 if (processing_template_decl
)
1178 add_tree (build_min_nt
1180 current_member_init_list
, current_base_init_list
));
1182 finish_expr_stmt (emit_base_init (current_class_type
));
1184 else if (DECL_DESTRUCTOR_P (current_function_decl
)
1185 && !processing_template_decl
)
1187 tree binfo
= TYPE_BINFO (current_class_type
);
1191 /* If the dtor is empty, and we know there is not possible way we
1192 could use any vtable entries, before they are possibly set by
1193 a base class dtor, we don't have to setup the vtables, as we
1194 know that any base class dtoring will set up any vtables it
1195 needs. We avoid MI, because one base class dtor can do a
1196 virtual dispatch to an overridden function that would need to
1197 have a non-related vtable set up, we cannot avoid setting up
1198 vtables in that case. We could change this to see if there is
1200 if_stmt
= begin_if_stmt ();
1202 /* If it is not safe to avoid setting up the vtables, then
1203 someone will change the condition to be boolean_true_node.
1204 (Actually, for now, we do not have code to set the condition
1205 appropriate, so we just assume that we always need to
1206 initialize the vtables.) */
1207 finish_if_stmt_cond (boolean_true_node
, if_stmt
);
1208 current_vcalls_possible_p
= &IF_COND (if_stmt
);
1209 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
1211 /* Make all virtual function table pointers in non-virtual base
1212 classes point to CURRENT_CLASS_TYPE's virtual function
1214 expand_direct_vtbls_init (binfo
, binfo
, 1, 0, current_class_ptr
);
1216 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
1217 expand_indirect_vtbls_init (binfo
, current_class_ref
,
1220 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
1221 finish_then_clause (if_stmt
);
1225 /* Always keep the BLOCK node associated with the outermost pair of
1226 curly braces of a function. These are needed for correct
1227 operation of dwarfout.c. */
1228 keep_next_level (1);
1230 /* The virtual function tables are set up now. */
1234 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
1235 whether this statements opens or closes a scope. PARTIAL_P is true
1236 for a partial scope, i.e, the scope that begins after a label when
1237 an object that needs a cleanup is created. */
1240 add_scope_stmt (begin_p
, partial_p
)
1246 /* Build the statement. */
1247 ss
= build_min_nt (SCOPE_STMT
);
1248 SCOPE_BEGIN_P (ss
) = begin_p
;
1249 SCOPE_PARTIAL_P (ss
) = partial_p
;
1251 /* If we're finishing a scope, figure out whether the scope was
1252 really necessary. */
1255 SCOPE_NULLIFIED_P (ss
) = !kept_level_p ();
1256 SCOPE_NULLIFIED_P (TREE_VALUE (current_scope_stmt_stack
))
1257 = SCOPE_NULLIFIED_P (ss
);
1260 /* Keep the scope stack up to date. */
1262 current_scope_stmt_stack
1263 = tree_cons (NULL_TREE
, ss
, current_scope_stmt_stack
);
1265 current_scope_stmt_stack
= TREE_CHAIN (current_scope_stmt_stack
);
1267 /* Add the new statement to the statement-tree. */
1271 /* Begin a new scope. */
1276 if (!building_stmt_tree ())
1278 emit_line_note (input_filename
, lineno
);
1281 if (stmts_are_full_exprs_p
)
1284 if (!building_stmt_tree ()
1285 && !current_function
->x_whole_function_mode_p
)
1286 expand_start_bindings (0);
1287 else if (building_stmt_tree () && !processing_template_decl
)
1288 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
1292 /* Finish a scope. */
1299 if (stmts_are_full_exprs_p
)
1301 if (!building_stmt_tree ()
1302 && !current_function
->x_whole_function_mode_p
)
1303 expand_end_bindings (getdecls (), kept_level_p (), 0);
1304 else if (building_stmt_tree () && !processing_template_decl
)
1306 add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
1308 /* When not in function-at-a-time mode, expand_end_bindings
1309 will warn about unused variables. But, in
1310 function-at-a-time mode expand_end_bindings is not passed
1311 the list of variables in the current scope, and therefore
1312 no warning is emitted. So, we explicitly warn here. */
1313 warn_about_unused_variables (getdecls ());
1316 t
= poplevel (kept_level_p (), 1, 0);
1321 /* Finish a parenthesized expression EXPR. */
1324 finish_parenthesized_expr (expr
)
1327 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1328 /* This inhibits warnings in truthvalue_conversion. */
1329 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1334 /* Begin a statement-expression. The value returned must be passed to
1335 finish_stmt_expr. */
1340 /* If we're outside a function, we won't have a statement-tree to
1341 work with. But, if we see a statement-expression we need to
1343 if (!current_function
&& !last_tree
)
1344 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1346 keep_next_level (1);
1347 /* If we're building a statement tree, then the upcoming compound
1348 statement will be chained onto the tree structure, starting at
1349 last_tree. We return last_tree so that we can later unhook the
1350 compound statement. */
1351 return building_stmt_tree () ? last_tree
: expand_start_stmt_expr();
1354 /* Finish a statement-expression. RTL_EXPR should be the value
1355 returned by the previous begin_stmt_expr; EXPR is the
1356 statement-expression. Returns an expression representing the
1357 statement-expression. */
1360 finish_stmt_expr (rtl_expr
)
1365 if (!building_stmt_tree ())
1366 rtl_expr
= expand_end_stmt_expr (rtl_expr
);
1368 if (building_stmt_tree ())
1370 /* If the last thing in the statement-expression was not an
1371 expression-statement, then it has type `void'. */
1372 if (!last_expr_type
)
1373 last_expr_type
= void_type_node
;
1374 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1375 TREE_SIDE_EFFECTS (result
) = 1;
1377 /* Remove the compound statement from the tree structure; it is
1378 now saved in the STMT_EXPR. */
1379 SET_LAST_STMT (rtl_expr
);
1380 TREE_CHAIN (last_tree
) = NULL_TREE
;
1385 /* If we created a statement-tree for this statement-expression,
1387 if (!current_function
1388 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1389 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1394 /* Finish a call to FN with ARGS. Returns a representation of the
1398 finish_call_expr (fn
, args
, koenig
)
1407 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1408 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1409 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1410 fn
= do_identifier (fn
, 2, args
);
1412 result
= build_x_function_call (fn
, args
, current_class_ref
);
1414 if (TREE_CODE (result
) == CALL_EXPR
1415 && (! TREE_TYPE (result
)
1416 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1417 result
= require_complete_type (result
);
1422 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1423 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1424 POSTDECREMENT_EXPR.) */
1427 finish_increment_expr (expr
, code
)
1429 enum tree_code code
;
1431 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1432 a COMPONENT_REF). This way if we've got, say, a reference to a
1433 static member that's being operated on, we don't end up trying to
1434 find a member operator for the class it's in. */
1436 if (TREE_CODE (expr
) == OFFSET_REF
)
1437 expr
= resolve_offset_ref (expr
);
1438 return build_x_unary_op (code
, expr
);
1441 /* Finish a use of `this'. Returns an expression for `this'. */
1448 if (current_class_ptr
)
1450 #ifdef WARNING_ABOUT_CCD
1451 TREE_USED (current_class_ptr
) = 1;
1453 result
= current_class_ptr
;
1455 else if (current_function_decl
1456 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1458 error ("`this' is unavailable for static member functions");
1459 result
= error_mark_node
;
1463 if (current_function_decl
)
1464 error ("invalid use of `this' in non-member function");
1466 error ("invalid use of `this' at top level");
1467 result
= error_mark_node
;
1473 /* Finish a member function call using OBJECT and ARGS as arguments to
1474 FN. Returns an expression for the call. */
1477 finish_object_call_expr (fn
, object
, args
)
1483 /* This is a future direction of this code, but because
1484 build_x_function_call cannot always undo what is done in
1485 build_component_ref entirely yet, we cannot do this. */
1487 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1488 return finish_call_expr (real_fn
, args
);
1490 if (DECL_DECLARES_TYPE_P (fn
))
1492 if (processing_template_decl
)
1493 /* This can happen on code like:
1496 template <class T> void f(T t) {
1500 We just grab the underlying IDENTIFIER. */
1501 fn
= DECL_NAME (fn
);
1504 cp_error ("calling type `%T' like a method", fn
);
1505 return error_mark_node
;
1509 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1513 /* Finish a qualified member function call using OBJECT and ARGS as
1514 arguments to FN. Returns an expressino for the call. */
1517 finish_qualified_object_call_expr (fn
, object
, args
)
1522 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1523 TREE_OPERAND (fn
, 1), args
);
1526 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1527 being the scope, if any, of DESTRUCTOR. Returns an expression for
1531 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1536 if (processing_template_decl
)
1537 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1539 if (scope
&& scope
!= destructor
)
1540 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1543 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1544 && (TREE_CODE (TREE_TYPE (object
)) !=
1545 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1546 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1548 return cp_convert (void_type_node
, object
);
1551 /* Finish a call to a globally qualified member function FN using
1552 ARGS. Returns an expression for the call. */
1555 finish_qualified_call_expr (fn
, args
)
1559 if (processing_template_decl
)
1560 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1562 return build_member_call (TREE_OPERAND (fn
, 0),
1563 TREE_OPERAND (fn
, 1),
1567 /* Finish an expression taking the address of LABEL. Returns an
1568 expression for the address. */
1571 finish_label_address_expr (label
)
1576 label
= lookup_label (label
);
1577 if (label
== NULL_TREE
)
1578 result
= null_pointer_node
;
1581 TREE_USED (label
) = 1;
1582 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1583 TREE_CONSTANT (result
) = 1;
1589 /* Finish an expression of the form CODE EXPR. */
1592 finish_unary_op_expr (code
, expr
)
1593 enum tree_code code
;
1596 tree result
= build_x_unary_op (code
, expr
);
1597 /* Inside a template, build_x_unary_op does not fold the
1598 expression. So check whether the result is folded before
1599 setting TREE_NEGATED_INT. */
1600 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1601 && TREE_CODE (result
) == INTEGER_CST
)
1602 TREE_NEGATED_INT (result
) = 1;
1603 overflow_warning (result
);
1607 /* Finish an id-expression. */
1610 finish_id_expr (expr
)
1613 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1614 expr
= do_identifier (expr
, 1, NULL_TREE
);
1619 /* Begin a function defniition declared with DECL_SPECS and
1620 DECLARATOR. Returns non-zero if the function-declaration is
1624 begin_function_definition (decl_specs
, declarator
)
1630 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1631 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1634 reinit_parse_for_function ();
1635 /* The things we're about to see are not directly qualified by any
1636 template headers we've seen thus far. */
1637 reset_specialization ();
1642 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1646 begin_constructor_declarator (scope
, name
)
1650 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1651 enter_scope_of (result
);
1655 /* Finish an init-declarator. Returns a DECL. */
1658 finish_declarator (declarator
, declspecs
, attributes
,
1659 prefix_attributes
, initialized
)
1663 tree prefix_attributes
;
1666 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1670 /* Finish a translation unit. */
1673 finish_translation_unit ()
1675 /* In case there were missing closebraces,
1676 get us back to the global binding level. */
1678 while (current_namespace
!= global_namespace
)
1683 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1684 Returns the parameter. */
1687 finish_template_type_parm (aggr
, identifier
)
1691 if (aggr
!= class_type_node
)
1693 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1694 aggr
= class_type_node
;
1697 return build_tree_list (aggr
, identifier
);
1700 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1701 Returns the parameter. */
1704 finish_template_template_parm (aggr
, identifier
)
1708 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1709 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1710 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1711 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1712 SET_DECL_ARTIFICIAL (decl
);
1713 end_template_decl ();
1715 return finish_template_type_parm (aggr
, tmpl
);
1718 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1719 non-zero, the parameter list was terminated by a `...'. */
1722 finish_parmlist (parms
, ellipsis
)
1727 chainon (parms
, void_list_node
);
1728 /* We mark the PARMS as a parmlist so that declarator processing can
1729 disambiguate certain constructs. */
1730 if (parms
!= NULL_TREE
)
1731 TREE_PARMLIST (parms
) = 1;
1736 /* Begin a class definition, as indicated by T. */
1739 begin_class_definition (t
)
1742 if (t
== error_mark_node
1743 || ! IS_AGGR_TYPE (t
))
1745 t
= make_lang_type (RECORD_TYPE
);
1746 pushtag (make_anon_name (), t
, 0);
1749 /* In a definition of a member class template, we will get here with an
1750 implicit typename, a TYPENAME_TYPE with a type. */
1751 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1754 /* If we generated a partial instantiation of this type, but now
1755 we're seeing a real definition, we're actually looking at a
1756 partial specialization. Consider:
1758 template <class T, class U>
1764 template <class T, class U>
1767 typename X<Y<T, U> >::A a;
1770 template <class T, class U>
1775 We have to undo the effects of the previous partial
1777 if (PARTIAL_INSTANTIATION_P (t
))
1781 /* Unfortunately, when we're not in pedantic mode, we
1782 attempt to actually fill in some of the fields of the
1783 partial instantiation, in order to support the implicit
1784 typename extension. Clear those fields now, in
1785 preparation for the definition here. The fields cleared
1786 here must match those set in instantiate_class_template.
1787 Look for a comment mentioning begin_class_definition
1789 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1790 TYPE_FIELDS (t
) = NULL_TREE
;
1791 TYPE_METHODS (t
) = NULL_TREE
;
1792 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1793 TYPE_SIZE (t
) = NULL_TREE
;
1796 /* This isn't a partial instantiation any more. */
1797 PARTIAL_INSTANTIATION_P (t
) = 0;
1799 /* If this type was already complete, and we see another definition,
1801 else if (TYPE_SIZE (t
))
1802 duplicate_tag_error (t
);
1804 /* Update the location of the decl. */
1805 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1806 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1808 if (TYPE_BEING_DEFINED (t
))
1810 t
= make_lang_type (TREE_CODE (t
));
1811 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1813 maybe_process_partial_specialization (t
);
1815 TYPE_BEING_DEFINED (t
) = 1;
1816 /* Reset the interface data, at the earliest possible
1817 moment, as it might have been set via a class foo;
1820 tree name
= TYPE_IDENTIFIER (t
);
1822 if (! ANON_AGGRNAME_P (name
))
1824 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1825 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1826 (t
, interface_unknown
);
1829 /* Only leave this bit clear if we know this
1830 class is part of an interface-only specification. */
1831 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1832 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1833 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1836 tmp
= TYPE_IDENTIFIER ($
<ttype
>0);
1837 if (tmp
&& IDENTIFIER_TEMPLATE (tmp
))
1838 overload_template_name (tmp
, 1);
1840 reset_specialization();
1842 /* Make a declaration for this class in its own scope. */
1843 build_self_reference ();
1848 /* Finish the member declaration given by DECL. */
1851 finish_member_declaration (decl
)
1854 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1857 if (decl
== void_type_node
)
1858 /* The COMPONENT was a friend, not a member, and so there's
1859 nothing for us to do. */
1862 /* We should see only one DECL at a time. */
1863 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1865 /* Set up access control for DECL. */
1867 = (current_access_specifier
== access_private_node
);
1868 TREE_PROTECTED (decl
)
1869 = (current_access_specifier
== access_protected_node
);
1870 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1872 TREE_PRIVATE (DECL_RESULT (decl
)) = TREE_PRIVATE (decl
);
1873 TREE_PROTECTED (DECL_RESULT (decl
)) = TREE_PROTECTED (decl
);
1876 /* Mark the DECL as a member of the current class. */
1877 if (TREE_CODE (decl
) == FUNCTION_DECL
1878 || DECL_FUNCTION_TEMPLATE_P (decl
))
1879 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1880 finish_struct. Presumably it is already set as the function is
1881 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1882 DECL_CLASS_CONTEXT (decl
) = current_class_type
;
1884 DECL_CONTEXT (decl
) = current_class_type
;
1886 /* Put functions on the TYPE_METHODS list and everything else on the
1887 TYPE_FIELDS list. Note that these are built up in reverse order.
1888 We reverse them (to obtain declaration order) in finish_struct. */
1889 if (TREE_CODE (decl
) == FUNCTION_DECL
1890 || DECL_FUNCTION_TEMPLATE_P (decl
))
1892 /* We also need to add this function to the
1893 CLASSTYPE_METHOD_VEC. */
1894 add_method (current_class_type
, 0, decl
);
1896 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1897 TYPE_METHODS (current_class_type
) = decl
;
1901 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1902 go at the beginning. The reason is that lookup_field_1
1903 searches the list in order, and we want a field name to
1904 override a type name so that the "struct stat hack" will
1905 work. In particular:
1907 struct S { enum E { }; int E } s;
1910 is legal. In addition, the FIELD_DECLs must be maintained in
1911 declaration order so that class layout works as expected.
1912 However, we don't need that order until class layout, so we
1913 save a little time by putting FIELD_DECLs on in reverse order
1914 here, and then reversing them in finish_struct_1. (We could
1915 also keep a pointer to the correct insertion points in the
1918 if (TREE_CODE (decl
) == TYPE_DECL
)
1919 TYPE_FIELDS (current_class_type
)
1920 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1923 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1924 TYPE_FIELDS (current_class_type
) = decl
;
1927 /* Enter the DECL into the scope of the class. */
1928 if (TREE_CODE (decl
) != USING_DECL
)
1929 pushdecl_class_level (decl
);
1933 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1934 the definition is immediately followed by a semicolon. Returns the
1938 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
1944 /* finish_struct nukes this anyway; if finish_exception does too,
1947 note_got_semicolon (t
);
1949 /* If we got any attributes in class_head, xref_tag will stick them in
1950 TREE_TYPE of the type. Grab them now. */
1951 attributes
= chainon (TREE_TYPE (t
), attributes
);
1952 TREE_TYPE (t
) = NULL_TREE
;
1954 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1958 t
= finish_struct (t
, attributes
);
1960 note_got_semicolon (t
);
1964 check_for_missing_semicolon (t
);
1966 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
1967 if (current_scope () == current_function_decl
)
1968 do_pending_defargs ();
1973 /* Finish processing the default argument expressions cached during
1974 the processing of a class definition. */
1977 begin_inline_definitions ()
1980 && current_scope () == current_function_decl
)
1981 do_pending_inlines ();
1984 /* Finish processing the inline function definitions cached during the
1985 processing of a class definition. */
1988 finish_inline_definitions ()
1990 if (current_class_type
== NULL_TREE
)
1991 clear_inline_text_obstack ();
1994 /* Finish processing the declaration of a member class template
1995 TYPES whose template parameters are given by PARMS. */
1998 finish_member_class_template (types
)
2003 /* If there are declared, but undefined, partial specializations
2004 mixed in with the typespecs they will not yet have passed through
2005 maybe_process_partial_specialization, so we do that here. */
2006 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
2007 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
2008 maybe_process_partial_specialization (TREE_VALUE (t
));
2010 note_list_got_semicolon (types
);
2011 grok_x_components (types
);
2012 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
2013 /* The component was in fact a friend declaration. We avoid
2014 finish_member_template_decl performing certain checks by
2018 finish_member_template_decl (types
);
2020 /* As with other component type declarations, we do
2021 not store the new DECL on the list of
2026 /* Finish processsing a complete template declaration. The PARMS are
2027 the template parameters. */
2030 finish_template_decl (parms
)
2034 end_template_decl ();
2036 end_specialization ();
2039 /* Finish processing a a template-id (which names a type) of the form
2040 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2041 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2042 the scope of template-id indicated. */
2045 finish_template_type (name
, args
, entering_scope
)
2052 decl
= lookup_template_class (name
, args
,
2053 NULL_TREE
, NULL_TREE
, entering_scope
);
2054 if (decl
!= error_mark_node
)
2055 decl
= TYPE_STUB_DECL (decl
);
2060 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2061 namespace scope or a class scope. */
2067 tree scope
= TREE_OPERAND (sr
, 0);
2069 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2071 push_decl_namespace (scope
);
2072 TREE_COMPLEXITY (sr
) = -1;
2074 else if (scope
!= current_class_type
)
2076 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2078 /* In a declarator for a template class member, the scope will
2079 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2080 scope
= TREE_TYPE (scope
);
2081 TREE_OPERAND (sr
, 0) = scope
;
2083 push_nested_class (scope
, 3);
2084 TREE_COMPLEXITY (sr
) = current_class_depth
;
2088 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2089 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2090 BASE_CLASS, or NULL_TREE if an error occurred. The
2091 ACCESSS_SPECIFIER is one of
2092 access_{default,public,protected_private}[_virtual]_node.*/
2095 finish_base_specifier (access_specifier
, base_class
)
2096 tree access_specifier
;
2102 if (base_class
== NULL_TREE
)
2104 error ("invalid base class");
2105 type
= error_mark_node
;
2108 type
= TREE_TYPE (base_class
);
2110 if (! is_aggr_type (type
, 1))
2113 result
= build_tree_list (access_specifier
, type
);
2118 /* Called when multiple declarators are processed. If that is not
2119 premitted in this context, an error is issued. */
2122 check_multiple_declarators ()
2126 In a template-declaration, explicit specialization, or explicit
2127 instantiation the init-declarator-list in the declaration shall
2128 contain at most one declarator.
2130 We don't just use PROCESSING_TEMPLATE_DECL for the first
2131 condition since that would disallow the perfectly legal code,
2132 like `template <class T> struct S { int i, j; };'. */
2133 tree scope
= current_scope ();
2135 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2136 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2139 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2140 || processing_explicit_instantiation
2141 || processing_specialization
)
2142 cp_error ("multiple declarators in template declaration");
2146 finish_typeof (expr
)
2149 if (processing_template_decl
)
2153 t
= make_lang_type (TYPEOF_TYPE
);
2154 TYPE_FIELDS (t
) = expr
;
2159 return TREE_TYPE (expr
);
2162 /* Create an empty statement tree rooted at T. */
2168 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2169 what follows. We remove the extraneous statement in
2170 finish_stmt_tree. */
2171 *t
= build_nt (EXPR_STMT
, void_zero_node
);
2173 last_expr_type
= NULL_TREE
;
2176 /* Finish the statement tree rooted at T. */
2179 finish_stmt_tree (t
)
2184 /* Remove the fake extra statement added in begin_stmt_tree. */
2185 stmt
= TREE_CHAIN (*t
);
2187 SET_LAST_STMT (NULL_TREE
);
2189 if (current_function
)
2191 /* The line-number recorded in the outermost statement in a function
2192 is the line number of the end of the function. */
2193 STMT_LINENO (stmt
) = lineno
;
2194 STMT_LINENO_FOR_FN_P (stmt
) = 1;
2198 /* We're about to expand T, a statement. Set up appropriate context
2199 for the substitution. */
2205 if (!STMT_LINENO_FOR_FN_P (t
))
2206 lineno
= STMT_LINENO (t
);
2207 stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2210 /* Some statements, like for-statements or if-statements, require a
2211 condition. This condition can be a declaration. If T is such a
2212 declaration it is processed, and an expression appropriate to use
2213 as the condition is returned. Otherwise, T itself is returned. */
2219 if (t
&& TREE_CODE (t
) == TREE_LIST
)
2221 expand_stmt (TREE_PURPOSE (t
));
2222 return TREE_VALUE (t
);
2228 /* Generate RTL for the statement T, and its substatements, and any
2229 other statements at its nesting level. */
2235 tree rval
= NULL_TREE
;
2237 while (t
&& t
!= error_mark_node
)
2239 int saved_stmts_are_full_exprs_p
;
2241 /* Assume we'll have nothing to return. */
2244 /* Set up context appropriately for handling this statement. */
2245 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p
;
2248 switch (TREE_CODE (t
))
2251 finish_return_stmt (RETURN_EXPR (t
));
2255 finish_expr_stmt (EXPR_STMT_EXPR (t
));
2262 emit_line_note (input_filename
, lineno
);
2263 decl
= DECL_STMT_DECL (t
);
2264 /* If this is a declaration for an automatic local
2265 variable, initialize it. Note that we might also see a
2266 declaration for a namespace-scope object (declared with
2267 `extern'). We don't have to handle the initialization
2268 of those objects here; they can only be declarations,
2269 rather than definitions. */
2270 if (TREE_CODE (decl
) == VAR_DECL
2271 && !TREE_STATIC (decl
)
2272 && !DECL_EXTERNAL (decl
))
2274 /* Let the back-end know about this variable. */
2275 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl
)))
2276 emit_local_var (decl
);
2278 expand_anon_union_decl (decl
, NULL_TREE
,
2279 DECL_ANON_UNION_ELEMS (decl
));
2281 else if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
2282 make_rtl_for_local_static (decl
);
2287 finish_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2290 case START_CATCH_STMT
:
2291 begin_catch_block (TREE_TYPE (t
));
2299 expand_stmt (FOR_INIT_STMT (t
));
2300 finish_for_init_stmt (NULL_TREE
);
2301 finish_for_cond (expand_cond (FOR_COND (t
)), NULL_TREE
);
2303 finish_for_expr (tmp
, NULL_TREE
);
2304 expand_stmt (FOR_BODY (t
));
2305 finish_for_stmt (tmp
, NULL_TREE
);
2311 begin_while_stmt ();
2312 finish_while_stmt_cond (expand_cond (WHILE_COND (t
)), NULL_TREE
);
2313 expand_stmt (WHILE_BODY (t
));
2314 finish_while_stmt (NULL_TREE
);
2321 expand_stmt (DO_BODY (t
));
2322 finish_do_body (NULL_TREE
);
2323 finish_do_stmt (DO_COND (t
), NULL_TREE
);
2329 finish_if_stmt_cond (expand_cond (IF_COND (t
)), NULL_TREE
);
2330 if (THEN_CLAUSE (t
))
2332 expand_stmt (THEN_CLAUSE (t
));
2333 finish_then_clause (NULL_TREE
);
2335 if (ELSE_CLAUSE (t
))
2337 begin_else_clause ();
2338 expand_stmt (ELSE_CLAUSE (t
));
2339 finish_else_clause (NULL_TREE
);
2345 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
));
2346 expand_stmt (COMPOUND_BODY (t
));
2347 rval
= finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
),
2352 finish_break_stmt ();
2356 finish_continue_stmt ();
2363 begin_switch_stmt ();
2364 cond
= expand_cond (SWITCH_COND (t
));
2365 finish_switch_cond (cond
, NULL_TREE
);
2366 expand_stmt (SWITCH_BODY (t
));
2367 finish_switch_stmt (cond
, NULL_TREE
);
2372 finish_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2376 expand_label (LABEL_STMT_LABEL (t
));
2380 finish_goto_stmt (GOTO_DESTINATION (t
));
2384 finish_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
), ASM_OUTPUTS
2385 (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2391 expand_eh_region_start ();
2392 expand_stmt (TRY_STMTS (t
));
2393 finish_cleanup_try_block (NULL_TREE
);
2394 finish_cleanup (TRY_HANDLERS (t
), NULL_TREE
);
2398 if (FN_TRY_BLOCK_P (t
))
2399 begin_function_try_block ();
2403 expand_stmt (TRY_STMTS (t
));
2405 if (FN_TRY_BLOCK_P (t
))
2407 finish_function_try_block (NULL_TREE
);
2408 expand_stmt (TRY_HANDLERS (t
));
2409 finish_function_handler_sequence (NULL_TREE
);
2413 finish_try_block (NULL_TREE
);
2414 expand_stmt (TRY_HANDLERS (t
));
2415 finish_handler_sequence (NULL_TREE
);
2422 expand_stmt (HANDLER_BODY (t
));
2423 finish_handler (NULL_TREE
, NULL_TREE
);
2427 finish_subobject (SUBOBJECT_CLEANUP (t
));
2431 if (SCOPE_BEGIN_P (t
))
2432 expand_start_bindings (2 * SCOPE_NULLIFIED_P (t
));
2433 else if (SCOPE_END_P (t
))
2434 expand_end_bindings (NULL_TREE
, !SCOPE_NULLIFIED_P (t
),
2435 SCOPE_PARTIAL_P (t
));
2439 /* Clear this out so that finish_named_return_value can set it
2441 DECL_NAME (DECL_RESULT (current_function_decl
)) = NULL_TREE
;
2442 finish_named_return_value (TREE_OPERAND (t
, 0),
2443 TREE_OPERAND (t
, 1));
2447 my_friendly_abort (19990810);
2451 /* Restore saved state. */
2452 stmts_are_full_exprs_p
= saved_stmts_are_full_exprs_p
;
2454 /* Go on to the next statement in this scope. */
2461 /* Generate RTL for FN. */
2468 char *saved_input_filename
;
2470 /* When the parser calls us after finishing the body of a template
2471 function, we don't really want to expand the body. When we're
2472 processing an in-class definition of an inline function,
2473 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2474 to look at the function itself. */
2475 if (processing_template_decl
2476 || (DECL_LANG_SPECIFIC (fn
)
2477 && DECL_TEMPLATE_INFO (fn
)
2478 && uses_template_parms (DECL_TI_ARGS (fn
))))
2480 /* Normally, collection only occurs in rest_of_compilation. So,
2481 if we don't collect here, we never collect junk generated
2482 during the processing of templates until we hit a
2483 non-template function. */
2488 /* There's no reason to do any of the work here if we're only doing
2489 semantic analysis; this code just generates RTL. */
2490 if (flag_syntax_only
)
2493 /* Save the current file name and line number. When we expand the
2494 body of the function, we'll set LINENO and INPUT_FILENAME so that
2495 error-mesages come out in the right places. */
2496 saved_lineno
= lineno
;
2497 saved_input_filename
= input_filename
;
2498 lineno
= DECL_SOURCE_LINE (fn
);
2499 input_filename
= DECL_SOURCE_FILE (fn
);
2501 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2502 store_parm_decls ();
2504 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2505 any of the other magic variables we set up when starting a
2507 current_function_name_declared
= 1;
2509 /* Expand the body. */
2510 expand_stmt (DECL_SAVED_TREE (fn
));
2512 /* Statements should always be full-expressions at the outermost set
2513 of curly braces for a function. */
2514 my_friendly_assert (stmts_are_full_exprs_p
, 19990831);
2516 /* The outermost statement for a function contains the line number
2517 recorded when we finished processing the function. */
2518 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2520 /* Generate code for the function. */
2521 finish_function (lineno
, 0);
2523 /* We don't need the body any more. Allow it to be garbage
2524 collected. We can't do this if we're going to dump everything. */
2525 if (!flag_dump_translation_unit
)
2526 DECL_SAVED_TREE (fn
) = NULL_TREE
;
2528 /* And restore the current source position. */
2529 lineno
= saved_lineno
;
2530 input_filename
= saved_input_filename
;