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
36 /* There routines provide a modular interface to perform many parsing
37 operations. They may therefore be used during actual parsing, or
38 during template instantiation, which may be regarded as a
39 degenerate form of parsing. Since the current g++ parser is
40 lacking in several respects, and will be reimplemented, we are
41 attempting to move most code that is not directly related to
42 parsing into this file; that will make implementing the new parser
43 much easier since it will be able to make use of these routines. */
45 static tree expand_cond
PROTO((tree
));
46 static tree maybe_convert_cond
PROTO((tree
));
48 /* When parsing a template, LAST_TREE contains the last statement
49 parsed. These are chained together through the TREE_CHAIN field,
50 but often need to be re-organized since the parse is performed
51 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
54 #define RECHAIN_STMTS(stmt, substmt) \
56 substmt = TREE_CHAIN (stmt); \
57 TREE_CHAIN (stmt) = NULL_TREE; \
61 /* Finish processing the COND, the SUBSTMT condition for STMT. */
63 #define FINISH_COND(cond, stmt, substmt) \
65 if (last_tree != stmt) \
67 RECHAIN_STMTS (stmt, substmt); \
68 if (!processing_template_decl) \
70 cond = build_tree_list (substmt, cond); \
78 /* T is a statement. Add it to the statement-tree. */
84 /* Add T to the statement-tree. */
85 last_tree
= TREE_CHAIN (last_tree
) = t
;
87 /* When we expand a statement-tree, we must know whether or not the
88 statements are full-expresions. We record that fact here. */
89 if (building_stmt_tree ())
90 STMT_IS_FULL_EXPR_P (last_tree
) = stmts_are_full_exprs_p
;
93 /* COND is the condition-expression for an if, while, etc.,
94 statement. Convert it to a boolean value, if appropriate. */
97 maybe_convert_cond (cond
)
100 /* Empty conditions remain empty. */
104 /* Wait until we instantiate templates before doing conversion. */
105 if (processing_template_decl
)
108 /* Do the conversion. */
109 cond
= convert_from_reference (cond
);
110 return condition_conversion (cond
);
113 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
116 finish_expr_stmt (expr
)
119 if (expr
!= NULL_TREE
)
121 if (building_stmt_tree ())
122 add_tree (build_min_nt (EXPR_STMT
, expr
));
125 emit_line_note (input_filename
, lineno
);
126 /* Do default conversion if safe and possibly important,
127 in case within ({...}). */
128 if (!stmts_are_full_exprs_p
&&
129 ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
131 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
132 expr
= default_conversion (expr
);
134 if (stmts_are_full_exprs_p
)
135 expand_start_target_temps ();
137 cplus_expand_expr_stmt (expr
);
139 if (stmts_are_full_exprs_p
)
141 expand_end_target_temps ();
149 /* This was an expression-statement, so we save the type of the
151 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
154 /* Begin an if-statement. Returns a newly created IF_STMT if
164 if (building_stmt_tree ())
166 r
= build_min_nt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
175 /* Process the COND of an if-statement, which may be given by
179 finish_if_stmt_cond (cond
, if_stmt
)
183 cond
= maybe_convert_cond (cond
);
185 if (building_stmt_tree ())
186 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
189 emit_line_note (input_filename
, lineno
);
190 expand_start_cond (cond
, 0);
194 /* Finish the then-clause of an if-statement, which may be given by
198 finish_then_clause (if_stmt
)
201 if (building_stmt_tree ())
203 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
211 /* Begin the else-clause of an if-statement. */
216 if (!building_stmt_tree ())
217 expand_start_else ();
220 /* Finish the else-clause of an if-statement, which may be given by
224 finish_else_clause (if_stmt
)
227 if (building_stmt_tree ())
228 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
231 /* Finsh an if-statement. */
236 if (!building_stmt_tree ())
243 /* Begin a while-statement. Returns a newly created WHILE_STMT if
251 if (building_stmt_tree ())
253 r
= build_min_nt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
259 emit_line_note (input_filename
, lineno
);
260 expand_start_loop (1);
269 /* Process the COND of an if-statement, which may be given by
273 finish_while_stmt_cond (cond
, while_stmt
)
277 cond
= maybe_convert_cond (cond
);
279 if (building_stmt_tree ())
280 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
283 emit_line_note (input_filename
, lineno
);
284 expand_exit_loop_if_false (0, cond
);
287 /* If COND wasn't a declaration, clear out the
288 block we made for it and start a new one here so the
289 optimization in expand_end_loop will work. */
290 if (getdecls () == NULL_TREE
)
297 /* Finish a while-statement, which may be given by WHILE_STMT. */
300 finish_while_stmt (while_stmt
)
305 if (building_stmt_tree ())
306 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
312 /* Begin a do-statement. Returns a newly created DO_STMT if
318 if (building_stmt_tree ())
320 tree r
= build_min_nt (DO_STMT
, NULL_TREE
, NULL_TREE
);
327 emit_line_note (input_filename
, lineno
);
328 expand_start_loop_continue_elsewhere (1);
333 /* Finish the body of a do-statement, which may be given by DO_STMT. */
336 finish_do_body (do_stmt
)
339 if (building_stmt_tree ())
340 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
342 expand_loop_continue_here ();
345 /* Finish a do-statement, which may be given by DO_STMT, and whose
346 COND is as indicated. */
349 finish_do_stmt (cond
, do_stmt
)
353 cond
= maybe_convert_cond (cond
);
355 if (building_stmt_tree ())
356 DO_COND (do_stmt
) = cond
;
359 emit_line_note (input_filename
, lineno
);
360 expand_exit_loop_if_false (0, cond
);
368 /* Finish a return-statement. The EXPRESSION returned, if any, is as
372 finish_return_stmt (expr
)
375 if (doing_semantic_analysis_p () && !processing_template_decl
)
376 expr
= check_return_expr (expr
);
378 if (doing_semantic_analysis_p () && !processing_template_decl
)
380 if (DECL_CONSTRUCTOR_P (current_function_decl
) && ctor_label
)
382 /* Even returns without a value in a constructor must return
383 `this'. We accomplish this by sending all returns in a
384 constructor to the CTOR_LABEL; finish_function emits code to
385 return a value there. When we finally generate the real
386 return statement, CTOR_LABEL is no longer set, and we fall
387 through into the normal return-processing code below. */
388 finish_goto_stmt (ctor_label
);
391 else if (DECL_DESTRUCTOR_P (current_function_decl
))
393 /* Similarly, all destructors must run destructors for
394 base-classes before returning. So, all returns in a
395 destructor get sent to the DTOR_LABEL; finsh_function emits
396 code to return a value there. */
397 finish_goto_stmt (dtor_label
);
402 if (building_stmt_tree ())
403 add_tree (build_min_nt (RETURN_STMT
, expr
));
406 emit_line_note (input_filename
, lineno
);
407 c_expand_return (expr
);
413 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
420 if (building_stmt_tree ())
422 r
= build_min_nt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
423 NULL_TREE
, NULL_TREE
);
429 if (flag_new_for_scope
> 0)
432 note_level_for_for ();
438 /* Finish the for-init-statement of a for-statement, which may be
439 given by FOR_STMT. */
442 finish_for_init_stmt (for_stmt
)
445 if (building_stmt_tree ())
447 if (last_tree
!= for_stmt
)
448 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
453 emit_line_note (input_filename
, lineno
);
454 expand_start_loop_continue_elsewhere (1);
460 /* Finish the COND of a for-statement, which may be given by
464 finish_for_cond (cond
, for_stmt
)
468 cond
= maybe_convert_cond (cond
);
470 if (building_stmt_tree ())
471 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
474 emit_line_note (input_filename
, lineno
);
476 expand_exit_loop_if_false (0, cond
);
479 /* If the cond wasn't a declaration, clear out the
480 block we made for it and start a new one here so the
481 optimization in expand_end_loop will work. */
482 if (getdecls () == NULL_TREE
)
489 /* Finish the increment-EXPRESSION in a for-statement, which may be
490 given by FOR_STMT. */
493 finish_for_expr (expr
, for_stmt
)
497 if (building_stmt_tree ())
498 FOR_EXPR (for_stmt
) = expr
;
500 /* Don't let the tree nodes for EXPR be discarded
501 by clear_momentary during the parsing of the next stmt. */
505 /* Finish the body of a for-statement, which may be given by
506 FOR_STMT. The increment-EXPR for the loop must be
510 finish_for_stmt (expr
, for_stmt
)
514 /* Pop the scope for the body of the loop. */
517 if (building_stmt_tree ())
518 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
521 emit_line_note (input_filename
, lineno
);
522 expand_loop_continue_here ();
524 finish_expr_stmt (expr
);
530 if (flag_new_for_scope
> 0)
536 /* Finish a break-statement. */
541 emit_line_note (input_filename
, lineno
);
542 if (building_stmt_tree ())
543 add_tree (build_min_nt (BREAK_STMT
));
544 else if ( ! expand_exit_something ())
545 cp_error ("break statement not within loop or switch");
548 /* Finish a continue-statement. */
551 finish_continue_stmt ()
553 emit_line_note (input_filename
, lineno
);
554 if (building_stmt_tree ())
555 add_tree (build_min_nt (CONTINUE_STMT
));
556 else if (! expand_continue_loop (0))
557 cp_error ("continue statement not within a loop");
560 /* Begin a switch-statement. Returns a new SWITCH_STMT if
568 if (building_stmt_tree ())
570 r
= build_min_nt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
581 /* Finish the cond of a switch-statement. */
584 finish_switch_cond (cond
, switch_stmt
)
588 if (building_stmt_tree ())
589 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
590 else if (cond
!= error_mark_node
)
592 emit_line_note (input_filename
, lineno
);
593 c_expand_start_case (cond
);
596 /* The code is in error, but we don't want expand_end_case to
598 c_expand_start_case (boolean_false_node
);
602 /* Don't let the tree nodes for COND be discarded by
603 clear_momentary during the parsing of the next stmt. */
607 /* Finish the body of a switch-statement, which may be given by
608 SWITCH_STMT. The COND to switch on is indicated. */
611 finish_switch_stmt (cond
, switch_stmt
)
615 if (building_stmt_tree ())
616 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
618 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 ();
898 if (building_stmt_tree ())
899 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. */
937 if (!current_function_name_declared
938 && !processing_template_decl
941 declare_function_name ();
942 current_function_name_declared
= 1;
949 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
950 If HAS_NO_SCOPE is non-zero, the compound statement does not define
954 finish_compound_stmt (has_no_scope
, compound_stmt
)
966 if (building_stmt_tree ())
967 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
969 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
970 the precise purpose of that variable is store the type of the
971 last expression statement within the last compound statement, we
972 preserve the value. */
980 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
981 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
985 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
986 input_operands
, clobbers
)
989 tree output_operands
;
993 if (TREE_CHAIN (string
))
995 if (building_stmt_tree ())
996 /* We need to build the combined string on the permanent
997 obstack so that we can use it during instantiations. */
998 push_permanent_obstack ();
1000 string
= combine_strings (string
);
1002 if (building_stmt_tree ())
1006 if (cv_qualifier
!= NULL_TREE
1007 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
1009 cp_warning ("%s qualifier ignored on asm",
1010 IDENTIFIER_POINTER (cv_qualifier
));
1011 cv_qualifier
= NULL_TREE
;
1014 if (building_stmt_tree ())
1016 tree r
= build_min_nt (ASM_STMT
, cv_qualifier
, string
,
1017 output_operands
, input_operands
,
1023 emit_line_note (input_filename
, lineno
);
1024 if (output_operands
!= NULL_TREE
|| input_operands
!= NULL_TREE
1025 || clobbers
!= NULL_TREE
)
1029 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
1030 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
1032 c_expand_asm_operands (string
, output_operands
,
1035 cv_qualifier
!= NULL_TREE
,
1036 input_filename
, lineno
);
1039 expand_asm (string
);
1045 /* Finish a label with the indicated NAME. */
1048 finish_label_stmt (name
)
1051 tree decl
= define_label (input_filename
, lineno
, name
);
1053 if (building_stmt_tree ())
1054 add_tree (build_min_nt (LABEL_STMT
, decl
));
1056 expand_label (decl
);
1059 /* Finish a series of declarations for local labels. G++ allows users
1060 to declare "local" labels, i.e., labels with scope. This extension
1061 is useful when writing code involving statement-expressions. */
1064 finish_label_decl (name
)
1067 tree decl
= declare_local_label (name
);
1068 if (building_stmt_tree ())
1069 add_decl_stmt (decl
);
1072 /* Create a declaration statement for the declaration given by the
1076 add_decl_stmt (decl
)
1081 /* We need the type to last until instantiation time. */
1082 decl_stmt
= build_min_nt (DECL_STMT
, decl
);
1083 add_tree (decl_stmt
);
1086 /* We're in a constructor, and have just constructed a a subobject of
1087 *THIS. CLEANUP is code to run if an exception is thrown before the
1088 end of the current function is reached. */
1091 finish_subobject (cleanup
)
1094 if (building_stmt_tree ())
1096 tree r
= build_min_nt (SUBOBJECT
, cleanup
);
1100 add_partial_entry (cleanup
);
1103 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1106 finish_decl_cleanup (decl
, cleanup
)
1110 if (building_stmt_tree ())
1111 add_tree (build_min_nt (CLEANUP_STMT
, decl
, cleanup
));
1113 || (DECL_SIZE (decl
) && TREE_TYPE (decl
) != error_mark_node
))
1114 expand_decl_cleanup (decl
, cleanup
);
1117 /* Bind a name and initialization to the return value of
1118 the current function. */
1121 finish_named_return_value (return_id
, init
)
1122 tree return_id
, init
;
1124 tree decl
= DECL_RESULT (current_function_decl
);
1127 /* Give this error as many times as there are occurrences,
1128 so that users can use Emacs compilation buffers to find
1129 and fix all such places. */
1130 pedwarn ("ANSI C++ does not permit named return values");
1132 if (return_id
!= NULL_TREE
)
1134 if (DECL_NAME (decl
) == NULL_TREE
)
1136 DECL_NAME (decl
) = return_id
;
1137 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1141 cp_error ("return identifier `%D' already in place", return_id
);
1146 /* Can't let this happen for constructors. */
1147 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1149 error ("can't redefine default return value for constructors");
1153 /* If we have a named return value, put that in our scope as well. */
1154 if (DECL_NAME (decl
) != NULL_TREE
)
1156 /* Let `cp_finish_decl' know that this initializer is ok. */
1157 DECL_INITIAL (decl
) = init
;
1158 if (doing_semantic_analysis_p ())
1161 if (building_stmt_tree ())
1162 add_tree (build_min_nt (RETURN_INIT
, return_id
, init
));
1165 cp_finish_decl (decl
, init
, NULL_TREE
, 0, 0);
1166 store_return_init (decl
);
1171 /* Cache the value of this class's main virtual function table pointer
1172 in a register variable. This will save one indirection if a
1173 more than one virtual function call is made this function. */
1178 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1180 /* If we've already done this, there's no need to do it again. */
1184 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1186 if (processing_template_decl
)
1187 add_tree (build_min_nt
1189 current_member_init_list
, current_base_init_list
));
1191 finish_expr_stmt (emit_base_init (current_class_type
));
1193 else if (DECL_DESTRUCTOR_P (current_function_decl
)
1194 && !processing_template_decl
)
1196 tree binfo
= TYPE_BINFO (current_class_type
);
1200 /* If the dtor is empty, and we know there is not possible way we
1201 could use any vtable entries, before they are possibly set by
1202 a base class dtor, we don't have to setup the vtables, as we
1203 know that any base class dtoring will set up any vtables it
1204 needs. We avoid MI, because one base class dtor can do a
1205 virtual dispatch to an overridden function that would need to
1206 have a non-related vtable set up, we cannot avoid setting up
1207 vtables in that case. We could change this to see if there is
1209 if_stmt
= begin_if_stmt ();
1211 /* If it is not safe to avoid setting up the vtables, then
1212 someone will change the condition to be boolean_true_node.
1213 (Actually, for now, we do not have code to set the condition
1214 appropriate, so we just assume that we always need to
1215 initialize the vtables.) */
1216 finish_if_stmt_cond (boolean_true_node
, if_stmt
);
1217 current_vcalls_possible_p
= &IF_COND (if_stmt
);
1218 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
1220 /* Make all virtual function table pointers in non-virtual base
1221 classes point to CURRENT_CLASS_TYPE's virtual function
1223 expand_direct_vtbls_init (binfo
, binfo
, 1, 0, current_class_ptr
);
1225 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
1226 expand_indirect_vtbls_init (binfo
, current_class_ref
,
1229 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
1230 finish_then_clause (if_stmt
);
1234 /* Always keep the BLOCK node associated with the outermost pair of
1235 curly braces of a function. These are needed for correct
1236 operation of dwarfout.c. */
1237 keep_next_level (1);
1239 /* The virtual function tables are set up now. */
1243 /* Begin a new scope. */
1248 if (!building_stmt_tree ())
1250 emit_line_note (input_filename
, lineno
);
1254 if (stmts_are_full_exprs_p
)
1257 if (!building_stmt_tree ()
1258 && !current_function
->x_whole_function_mode_p
)
1259 expand_start_bindings (0);
1260 else if (building_stmt_tree () && !processing_template_decl
)
1262 tree ss
= build_min_nt (SCOPE_STMT
);
1263 SCOPE_BEGIN_P (ss
) = 1;
1265 current_scope_stmt_stack
1266 = tree_cons (NULL_TREE
, ss
, current_scope_stmt_stack
);
1271 /* Finish a scope. */
1278 if (stmts_are_full_exprs_p
)
1280 if (!building_stmt_tree ()
1281 && !current_function
->x_whole_function_mode_p
)
1282 expand_end_bindings (getdecls (), kept_level_p (), 0);
1283 else if (building_stmt_tree () && !processing_template_decl
)
1285 tree ss
= build_min_nt (SCOPE_STMT
);
1286 SCOPE_NULLIFIED_P (ss
) = !kept_level_p ();
1287 SCOPE_NULLIFIED_P (TREE_VALUE (current_scope_stmt_stack
))
1288 = SCOPE_NULLIFIED_P (ss
);
1290 current_scope_stmt_stack
= TREE_CHAIN (current_scope_stmt_stack
);
1292 /* When not in function-at-a-time mode, expand_end_bindings
1293 will warn about unused variables. But, in
1294 function-at-a-time mode expand_end_bindings is not passed
1295 the list of variables in the current scope, and therefore
1296 no warning is emitted. So, we explicitly warn here. */
1297 warn_about_unused_variables (getdecls ());
1300 t
= poplevel (kept_level_p (), 1, 0);
1306 /* Finish a parenthesized expression EXPR. */
1309 finish_parenthesized_expr (expr
)
1312 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1313 /* This inhibits warnings in truthvalue_conversion. */
1314 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1319 /* Begin a statement-expression. The value returned must be passed to
1320 finish_stmt_expr. */
1325 keep_next_level (1);
1326 /* If we're building a statement tree, then the upcoming compound
1327 statement will be chained onto the tree structure, starting at
1328 last_tree. We return last_tree so that we can later unhook the
1329 compound statement. */
1330 return building_stmt_tree () ? last_tree
: expand_start_stmt_expr();
1333 /* Finish a statement-expression. RTL_EXPR should be the value
1334 returned by the previous begin_stmt_expr; EXPR is the
1335 statement-expression. Returns an expression representing the
1336 statement-expression. */
1339 finish_stmt_expr (rtl_expr
)
1344 if (!building_stmt_tree ())
1346 rtl_expr
= expand_end_stmt_expr (rtl_expr
);
1347 /* The statements have side effects, so the group does too. */
1348 TREE_SIDE_EFFECTS (rtl_expr
) = 1;
1351 if (building_stmt_tree ())
1353 /* If the last thing in the statement-expression was not an
1354 expression-statement, then it has type `void'. */
1355 if (!last_expr_type
)
1356 last_expr_type
= void_type_node
;
1357 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1358 TREE_SIDE_EFFECTS (result
) = 1;
1360 /* Remove the compound statement from the tree structure; it is
1361 now saved in the STMT_EXPR. */
1362 last_tree
= rtl_expr
;
1363 TREE_CHAIN (last_tree
) = NULL_TREE
;
1371 /* Finish a call to FN with ARGS. Returns a representation of the
1375 finish_call_expr (fn
, args
, koenig
)
1384 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1385 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1386 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1387 fn
= do_identifier (fn
, 2, args
);
1389 result
= build_x_function_call (fn
, args
, current_class_ref
);
1391 if (TREE_CODE (result
) == CALL_EXPR
1392 && (! TREE_TYPE (result
)
1393 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1394 result
= require_complete_type (result
);
1399 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1400 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1401 POSTDECREMENT_EXPR.) */
1404 finish_increment_expr (expr
, code
)
1406 enum tree_code code
;
1408 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1409 a COMPONENT_REF). This way if we've got, say, a reference to a
1410 static member that's being operated on, we don't end up trying to
1411 find a member operator for the class it's in. */
1413 if (TREE_CODE (expr
) == OFFSET_REF
)
1414 expr
= resolve_offset_ref (expr
);
1415 return build_x_unary_op (code
, expr
);
1418 /* Finish a use of `this'. Returns an expression for `this'. */
1425 if (current_class_ptr
)
1427 #ifdef WARNING_ABOUT_CCD
1428 TREE_USED (current_class_ptr
) = 1;
1430 result
= current_class_ptr
;
1432 else if (current_function_decl
1433 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1435 error ("`this' is unavailable for static member functions");
1436 result
= error_mark_node
;
1440 if (current_function_decl
)
1441 error ("invalid use of `this' in non-member function");
1443 error ("invalid use of `this' at top level");
1444 result
= error_mark_node
;
1450 /* Finish a member function call using OBJECT and ARGS as arguments to
1451 FN. Returns an expression for the call. */
1454 finish_object_call_expr (fn
, object
, args
)
1460 /* This is a future direction of this code, but because
1461 build_x_function_call cannot always undo what is done in
1462 build_component_ref entirely yet, we cannot do this. */
1464 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1465 return finish_call_expr (real_fn
, args
);
1467 if (TREE_CODE (fn
) == TYPE_DECL
)
1469 if (processing_template_decl
)
1470 /* This can happen on code like:
1473 template <class T> void f(T t) {
1477 We just grab the underlying IDENTIFIER. */
1478 fn
= DECL_NAME (fn
);
1481 cp_error ("calling type `%T' like a method", fn
);
1482 return error_mark_node
;
1486 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1490 /* Finish a qualified member function call using OBJECT and ARGS as
1491 arguments to FN. Returns an expressino for the call. */
1494 finish_qualified_object_call_expr (fn
, object
, args
)
1499 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1500 TREE_OPERAND (fn
, 1), args
);
1503 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1504 being the scope, if any, of DESTRUCTOR. Returns an expression for
1508 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1513 if (processing_template_decl
)
1514 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1516 if (scope
&& scope
!= destructor
)
1517 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1520 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1521 && (TREE_CODE (TREE_TYPE (object
)) !=
1522 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1523 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1525 return cp_convert (void_type_node
, object
);
1528 /* Finish a call to a globally qualified member function FN using
1529 ARGS. Returns an expression for the call. */
1532 finish_qualified_call_expr (fn
, args
)
1536 if (processing_template_decl
)
1537 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1539 return build_member_call (TREE_OPERAND (fn
, 0),
1540 TREE_OPERAND (fn
, 1),
1544 /* Finish an expression taking the address of LABEL. Returns an
1545 expression for the address. */
1548 finish_label_address_expr (label
)
1553 label
= lookup_label (label
);
1554 if (label
== NULL_TREE
)
1555 result
= null_pointer_node
;
1558 TREE_USED (label
) = 1;
1559 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1560 TREE_CONSTANT (result
) = 1;
1566 /* Finish an expression of the form CODE EXPR. */
1569 finish_unary_op_expr (code
, expr
)
1570 enum tree_code code
;
1573 tree result
= build_x_unary_op (code
, expr
);
1574 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
)
1575 TREE_NEGATED_INT (result
) = 1;
1576 overflow_warning (result
);
1580 /* Finish an id-expression. */
1583 finish_id_expr (expr
)
1586 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1587 expr
= do_identifier (expr
, 1, NULL_TREE
);
1592 /* Begin a new-placement. */
1595 begin_new_placement ()
1597 /* The arguments to a placement new might be passed to a
1598 deallocation function, in the event that the allocation throws an
1599 exception. Since we don't expand exception handlers until the
1600 end of a function, we must make sure the arguments stay around
1602 return suspend_momentary ();
1605 /* Finish a new-placement. The ARGS are the placement arguments. The
1606 COOKIE is the value returned by the previous call to
1607 begin_new_placement. */
1610 finish_new_placement (args
, cookie
)
1614 resume_momentary (cookie
);
1618 /* Begin a function defniition declared with DECL_SPECS and
1619 DECLARATOR. Returns non-zero if the function-declaration is
1623 begin_function_definition (decl_specs
, declarator
)
1629 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1630 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1633 reinit_parse_for_function ();
1634 /* The things we're about to see are not directly qualified by any
1635 template headers we've seen thus far. */
1636 reset_specialization ();
1641 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1645 begin_constructor_declarator (scope
, name
)
1649 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1650 enter_scope_of (result
);
1654 /* Finish an init-declarator. Returns a DECL. */
1657 finish_declarator (declarator
, declspecs
, attributes
,
1658 prefix_attributes
, initialized
)
1662 tree prefix_attributes
;
1665 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1669 /* Finish a translation unit. */
1672 finish_translation_unit ()
1674 /* In case there were missing closebraces,
1675 get us back to the global binding level. */
1677 while (current_namespace
!= global_namespace
)
1682 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1683 Returns the parameter. */
1686 finish_template_type_parm (aggr
, identifier
)
1690 if (aggr
!= class_type_node
)
1692 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1693 aggr
= class_type_node
;
1696 return build_tree_list (aggr
, identifier
);
1699 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1700 Returns the parameter. */
1703 finish_template_template_parm (aggr
, identifier
)
1707 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1708 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1709 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1710 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1711 SET_DECL_ARTIFICIAL (decl
);
1712 end_template_decl ();
1714 return finish_template_type_parm (aggr
, tmpl
);
1717 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1718 non-zero, the parameter list was terminated by a `...'. */
1721 finish_parmlist (parms
, ellipsis
)
1726 chainon (parms
, void_list_node
);
1727 /* We mark the PARMS as a parmlist so that declarator processing can
1728 disambiguate certain constructs. */
1729 if (parms
!= NULL_TREE
)
1730 TREE_PARMLIST (parms
) = 1;
1735 /* Begin a class definition, as indicated by T. */
1738 begin_class_definition (t
)
1741 push_permanent_obstack ();
1743 if (t
== error_mark_node
1744 || ! IS_AGGR_TYPE (t
))
1746 t
= make_lang_type (RECORD_TYPE
);
1747 pushtag (make_anon_name (), t
, 0);
1750 /* In a definition of a member class template, we will get here with an
1751 implicit typename, a TYPENAME_TYPE with a type. */
1752 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1755 /* If we generated a partial instantiation of this type, but now
1756 we're seeing a real definition, we're actually looking at a
1757 partial specialization. Consider:
1759 template <class T, class U>
1765 template <class T, class U>
1768 typename X<Y<T, U> >::A a;
1771 template <class T, class U>
1776 We have to undo the effects of the previous partial
1778 if (PARTIAL_INSTANTIATION_P (t
))
1782 /* Unfortunately, when we're not in pedantic mode, we
1783 attempt to actually fill in some of the fields of the
1784 partial instantiation, in order to support the implicit
1785 typename extension. Clear those fields now, in
1786 preparation for the definition here. The fields cleared
1787 here must match those set in instantiate_class_template.
1788 Look for a comment mentioning begin_class_definition
1790 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1791 TYPE_FIELDS (t
) = NULL_TREE
;
1792 TYPE_METHODS (t
) = NULL_TREE
;
1793 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1794 TYPE_SIZE (t
) = NULL_TREE
;
1797 /* This isn't a partial instantiation any more. */
1798 PARTIAL_INSTANTIATION_P (t
) = 0;
1800 /* If this type was already complete, and we see another definition,
1802 else if (TYPE_SIZE (t
))
1803 duplicate_tag_error (t
);
1805 /* Update the location of the decl. */
1806 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1807 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1809 if (TYPE_BEING_DEFINED (t
))
1811 t
= make_lang_type (TREE_CODE (t
));
1812 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1814 maybe_process_partial_specialization (t
);
1816 TYPE_BEING_DEFINED (t
) = 1;
1817 /* Reset the interface data, at the earliest possible
1818 moment, as it might have been set via a class foo;
1821 tree name
= TYPE_IDENTIFIER (t
);
1823 if (! ANON_AGGRNAME_P (name
))
1825 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1826 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1827 (t
, interface_unknown
);
1830 /* Only leave this bit clear if we know this
1831 class is part of an interface-only specification. */
1832 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1833 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1834 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1837 tmp
= TYPE_IDENTIFIER ($
<ttype
>0);
1838 if (tmp
&& IDENTIFIER_TEMPLATE (tmp
))
1839 overload_template_name (tmp
, 1);
1841 reset_specialization();
1843 /* In case this is a local class within a template
1844 function, we save the current tree structure so
1845 that we can get it back later. */
1848 /* Make a declaration for this class in its own scope. */
1849 build_self_reference ();
1854 /* Finish the member declaration given by DECL. */
1857 finish_member_declaration (decl
)
1860 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1863 if (decl
== void_type_node
)
1864 /* The COMPONENT was a friend, not a member, and so there's
1865 nothing for us to do. */
1868 /* We should see only one DECL at a time. */
1869 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1871 /* Set up access control for DECL. */
1873 = (current_access_specifier
== access_private_node
);
1874 TREE_PROTECTED (decl
)
1875 = (current_access_specifier
== access_protected_node
);
1876 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1878 TREE_PRIVATE (DECL_RESULT (decl
)) = TREE_PRIVATE (decl
);
1879 TREE_PROTECTED (DECL_RESULT (decl
)) = TREE_PROTECTED (decl
);
1882 /* Mark the DECL as a member of the current class. */
1883 if (TREE_CODE (decl
) == FUNCTION_DECL
1884 || DECL_FUNCTION_TEMPLATE_P (decl
))
1885 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1886 finish_struct. Presumably it is already set as the function is
1887 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1888 DECL_CLASS_CONTEXT (decl
) = current_class_type
;
1890 DECL_CONTEXT (decl
) = current_class_type
;
1892 /* Put functions on the TYPE_METHODS list and everything else on the
1893 TYPE_FIELDS list. Note that these are built up in reverse order.
1894 We reverse them (to obtain declaration order) in finish_struct. */
1895 if (TREE_CODE (decl
) == FUNCTION_DECL
1896 || DECL_FUNCTION_TEMPLATE_P (decl
))
1898 /* We also need to add this function to the
1899 CLASSTYPE_METHOD_VEC. */
1900 add_method (current_class_type
, 0, decl
);
1902 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1903 TYPE_METHODS (current_class_type
) = decl
;
1907 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1908 go at the beginning. The reason is that lookup_field_1
1909 searches the list in order, and we want a field name to
1910 override a type name so that the "struct stat hack" will
1911 work. In particular:
1913 struct S { enum E { }; int E } s;
1916 is legal. In addition, the FIELD_DECLs must be maintained in
1917 declaration order so that class layout works as expected.
1918 However, we don't need that order until class layout, so we
1919 save a little time by putting FIELD_DECLs on in reverse order
1920 here, and then reversing them in finish_struct_1. (We could
1921 also keep a pointer to the correct insertion points in the
1924 if (TREE_CODE (decl
) == TYPE_DECL
)
1925 TYPE_FIELDS (current_class_type
)
1926 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1929 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1930 TYPE_FIELDS (current_class_type
) = decl
;
1933 /* Enter the DECL into the scope of the class. */
1934 if (TREE_CODE (decl
) != USING_DECL
)
1935 pushdecl_class_level (decl
);
1939 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1940 the definition is immediately followed by a semicolon. Returns the
1944 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
1950 /* finish_struct nukes this anyway; if finish_exception does too,
1953 note_got_semicolon (t
);
1955 /* If we got any attributes in class_head, xref_tag will stick them in
1956 TREE_TYPE of the type. Grab them now. */
1957 attributes
= chainon (TREE_TYPE (t
), attributes
);
1958 TREE_TYPE (t
) = NULL_TREE
;
1960 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1964 t
= finish_struct (t
, attributes
);
1966 note_got_semicolon (t
);
1972 check_for_missing_semicolon (t
);
1974 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
1975 if (current_scope () == current_function_decl
)
1976 do_pending_defargs ();
1981 /* Finish processing the default argument expressions cached during
1982 the processing of a class definition. */
1985 begin_inline_definitions ()
1988 && current_scope () == current_function_decl
)
1989 do_pending_inlines ();
1992 /* Finish processing the inline function definitions cached during the
1993 processing of a class definition. */
1996 finish_inline_definitions ()
1998 if (current_class_type
== NULL_TREE
)
1999 clear_inline_text_obstack ();
2001 /* Undo the begin_tree in begin_class_definition. */
2005 /* Finish processing the declaration of a member class template
2006 TYPES whose template parameters are given by PARMS. */
2009 finish_member_class_template (types
)
2014 /* If there are declared, but undefined, partial specializations
2015 mixed in with the typespecs they will not yet have passed through
2016 maybe_process_partial_specialization, so we do that here. */
2017 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
2018 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
2019 maybe_process_partial_specialization (TREE_VALUE (t
));
2021 note_list_got_semicolon (types
);
2022 grok_x_components (types
);
2023 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
2024 /* The component was in fact a friend declaration. We avoid
2025 finish_member_template_decl performing certain checks by
2029 finish_member_template_decl (types
);
2031 /* As with other component type declarations, we do
2032 not store the new DECL on the list of
2037 /* Finish processsing a complete template declaration. The PARMS are
2038 the template parameters. */
2041 finish_template_decl (parms
)
2045 end_template_decl ();
2047 end_specialization ();
2050 /* Finish processing a a template-id (which names a type) of the form
2051 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2052 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2053 the scope of template-id indicated. */
2056 finish_template_type (name
, args
, entering_scope
)
2063 decl
= lookup_template_class (name
, args
,
2064 NULL_TREE
, NULL_TREE
, entering_scope
);
2065 if (decl
!= error_mark_node
)
2066 decl
= TYPE_STUB_DECL (decl
);
2071 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2072 namespace scope or a class scope. */
2078 tree scope
= TREE_OPERAND (sr
, 0);
2080 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2082 push_decl_namespace (scope
);
2083 TREE_COMPLEXITY (sr
) = -1;
2085 else if (scope
!= current_class_type
)
2087 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2089 /* In a declarator for a template class member, the scope will
2090 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2091 scope
= TREE_TYPE (scope
);
2092 TREE_OPERAND (sr
, 0) = scope
;
2094 push_nested_class (scope
, 3);
2095 TREE_COMPLEXITY (sr
) = current_class_depth
;
2099 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2100 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2101 BASE_CLASS, or NULL_TREE if an error occurred. The
2102 ACCESSS_SPECIFIER is one of
2103 access_{default,public,protected_private}[_virtual]_node.*/
2106 finish_base_specifier (access_specifier
, base_class
)
2107 tree access_specifier
;
2113 if (base_class
== NULL_TREE
)
2115 error ("invalid base class");
2116 type
= error_mark_node
;
2119 type
= TREE_TYPE (base_class
);
2121 if (! is_aggr_type (type
, 1))
2124 result
= build_tree_list (access_specifier
, type
);
2129 /* Called when multiple declarators are processed. If that is not
2130 premitted in this context, an error is issued. */
2133 check_multiple_declarators ()
2137 In a template-declaration, explicit specialization, or explicit
2138 instantiation the init-declarator-list in the declaration shall
2139 contain at most one declarator.
2141 We don't just use PROCESSING_TEMPLATE_DECL for the first
2142 condition since that would disallow the perfectly legal code,
2143 like `template <class T> struct S { int i, j; };'. */
2144 tree scope
= current_scope ();
2146 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2147 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2150 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2151 || processing_explicit_instantiation
2152 || processing_specialization
)
2153 cp_error ("multiple declarators in template declaration");
2157 finish_typeof (expr
)
2160 if (processing_template_decl
)
2164 push_permanent_obstack ();
2165 t
= make_lang_type (TYPEOF_TYPE
);
2166 TYPE_FIELDS (t
) = expr
;
2172 return TREE_TYPE (expr
);
2175 /* Create an empty statement tree for FN. */
2178 begin_stmt_tree (fn
)
2181 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2182 what follows. We remove the extraneous statement in
2183 finish_stmt_tree. */
2184 DECL_SAVED_TREE (fn
) = build_nt (EXPR_STMT
, void_zero_node
);
2185 last_tree
= DECL_SAVED_TREE (fn
);
2186 last_expr_type
= NULL_TREE
;
2189 /* Finish the statement tree for FN. */
2192 finish_stmt_tree (fn
)
2197 /* Remove the fake extra statement added in begin_stmt_tree. */
2198 stmt
= TREE_CHAIN (DECL_SAVED_TREE (fn
));
2199 DECL_SAVED_TREE (fn
) = stmt
;
2201 /* The line-number recorded in the outermost statement in a function
2202 is the line number of the end of the function. */
2203 STMT_LINENO (stmt
) = lineno
;
2204 STMT_LINENO_FOR_FN_P (stmt
) = 1;
2207 /* We're about to expand T, a statement. Set up appropriate context
2208 for the substitution. */
2214 if (!STMT_LINENO_FOR_FN_P (t
))
2215 lineno
= STMT_LINENO (t
);
2216 stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2219 /* Some statements, like for-statements or if-statements, require a
2220 condition. This condition can be a declaration. If T is such a
2221 declaration it is processed, and an expression appropriate to use
2222 as the condition is returned. Otherwise, T itself is returned. */
2228 if (t
&& TREE_CODE (t
) == TREE_LIST
)
2230 expand_stmt (TREE_PURPOSE (t
));
2231 return TREE_VALUE (t
);
2237 /* Generate RTL for the statement T, and its substatements, and any
2238 other statements at its nesting level. */
2244 tree rval
= NULL_TREE
;
2246 while (t
&& t
!= error_mark_node
)
2248 int saved_stmts_are_full_exprs_p
;
2250 /* Assume we'll have nothing to return. */
2253 /* Set up context appropriately for handling this statement. */
2254 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p
;
2257 switch (TREE_CODE (t
))
2260 finish_return_stmt (RETURN_EXPR (t
));
2264 finish_expr_stmt (EXPR_STMT_EXPR (t
));
2270 int i
= suspend_momentary ();
2272 emit_line_note (input_filename
, lineno
);
2273 decl
= DECL_STMT_DECL (t
);
2274 /* If this is a declaration for an automatic local
2275 variable, initialize it. Note that we might also see a
2276 declaration for a namespace-scope object (declared with
2277 `extern'). We don't have to handle the initialization
2278 of those objects here; they can only be declarations,
2279 rather than definitions. */
2280 if (TREE_CODE (decl
) == VAR_DECL
2281 && !TREE_STATIC (decl
)
2282 && !DECL_EXTERNAL (decl
))
2284 /* Let the back-end know about this variable. */
2285 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl
)))
2286 emit_local_var (decl
);
2288 expand_anon_union_decl (decl
, NULL_TREE
,
2289 DECL_ANON_UNION_ELEMS (decl
));
2291 else if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
2292 rest_of_decl_compilation
2293 (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
2294 /*top_level=*/0, /*at_end=*/0);
2296 resume_momentary (i
);
2301 finish_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2304 case START_CATCH_STMT
:
2305 begin_catch_block (TREE_TYPE (t
));
2313 expand_stmt (FOR_INIT_STMT (t
));
2314 finish_for_init_stmt (NULL_TREE
);
2315 finish_for_cond (expand_cond (FOR_COND (t
)), NULL_TREE
);
2317 finish_for_expr (tmp
, NULL_TREE
);
2318 expand_stmt (FOR_BODY (t
));
2319 finish_for_stmt (tmp
, NULL_TREE
);
2325 begin_while_stmt ();
2326 finish_while_stmt_cond (expand_cond (WHILE_COND (t
)), NULL_TREE
);
2327 expand_stmt (WHILE_BODY (t
));
2328 finish_while_stmt (NULL_TREE
);
2335 expand_stmt (DO_BODY (t
));
2336 finish_do_body (NULL_TREE
);
2337 finish_do_stmt (DO_COND (t
), NULL_TREE
);
2343 finish_if_stmt_cond (expand_cond (IF_COND (t
)), NULL_TREE
);
2344 if (THEN_CLAUSE (t
))
2346 expand_stmt (THEN_CLAUSE (t
));
2347 finish_then_clause (NULL_TREE
);
2349 if (ELSE_CLAUSE (t
))
2351 begin_else_clause ();
2352 expand_stmt (ELSE_CLAUSE (t
));
2353 finish_else_clause (NULL_TREE
);
2359 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
));
2360 expand_stmt (COMPOUND_BODY (t
));
2361 rval
= finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
),
2366 finish_break_stmt ();
2370 finish_continue_stmt ();
2377 begin_switch_stmt ();
2378 cond
= expand_cond (SWITCH_COND (t
));
2379 finish_switch_cond (cond
, NULL_TREE
);
2380 expand_stmt (SWITCH_BODY (t
));
2381 finish_switch_stmt (cond
, NULL_TREE
);
2386 finish_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2390 expand_label (LABEL_STMT_LABEL (t
));
2394 finish_goto_stmt (GOTO_DESTINATION (t
));
2398 finish_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
), ASM_OUTPUTS
2399 (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2405 expand_eh_region_start ();
2406 expand_stmt (TRY_STMTS (t
));
2407 finish_cleanup_try_block (NULL_TREE
);
2408 finish_cleanup (TRY_HANDLERS (t
), NULL_TREE
);
2412 if (FN_TRY_BLOCK_P (t
))
2413 begin_function_try_block ();
2417 expand_stmt (TRY_STMTS (t
));
2419 if (FN_TRY_BLOCK_P (t
))
2421 finish_function_try_block (NULL_TREE
);
2422 expand_stmt (TRY_HANDLERS (t
));
2423 finish_function_handler_sequence (NULL_TREE
);
2427 finish_try_block (NULL_TREE
);
2428 expand_stmt (TRY_HANDLERS (t
));
2429 finish_handler_sequence (NULL_TREE
);
2436 expand_stmt (HANDLER_BODY (t
));
2437 finish_handler (NULL_TREE
, NULL_TREE
);
2441 finish_subobject (SUBOBJECT_CLEANUP (t
));
2445 if (SCOPE_BEGIN_P (t
))
2446 expand_start_bindings (2 * SCOPE_NULLIFIED_P (t
));
2447 else if (SCOPE_END_P (t
))
2448 expand_end_bindings (NULL_TREE
, !SCOPE_NULLIFIED_P (t
), 0);
2452 /* Clear this out so that finish_named_return_value can set it
2454 DECL_NAME (DECL_RESULT (current_function_decl
)) = NULL_TREE
;
2455 finish_named_return_value (TREE_OPERAND (t
, 0),
2456 TREE_OPERAND (t
, 1));
2460 my_friendly_abort (19990810);
2464 /* Restore saved state. */
2465 stmts_are_full_exprs_p
= saved_stmts_are_full_exprs_p
;
2467 /* Go on to the next statement in this scope. */
2474 /* Generate RTL for FN. */
2481 char *saved_input_filename
;
2483 /* When the parser calls us after finishing the body of a template
2484 function, we don't really want to expand the body. When we're
2485 processing an in-class definition of an inline function,
2486 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2487 to look at the function itself. */
2488 if (processing_template_decl
2489 || (DECL_LANG_SPECIFIC (fn
)
2490 && DECL_TEMPLATE_INFO (fn
)
2491 && uses_template_parms (DECL_TI_ARGS (fn
))))
2494 /* There's no reason to do any of the work here if we're only doing
2495 semantic analysis; this code just generates RTL. */
2496 if (flag_syntax_only
)
2499 /* Save the current file name and line number. When we expand the
2500 body of the function, we'll set LINENO and INPUT_FILENAME so that
2501 error-mesages come out in the right places. */
2502 saved_lineno
= lineno
;
2503 saved_input_filename
= input_filename
;
2504 lineno
= DECL_SOURCE_LINE (fn
);
2505 input_filename
= DECL_SOURCE_FILE (fn
);
2507 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2508 store_parm_decls ();
2510 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2511 any of the other magic variables we set up when starting a
2513 current_function_name_declared
= 1;
2515 /* Expand the body. */
2516 expand_stmt (DECL_SAVED_TREE (fn
));
2518 /* Statements should always be full-expressions at the outermost set
2519 of curly braces for a function. */
2520 my_friendly_assert (stmts_are_full_exprs_p
, 19990831);
2522 /* The outermost statement for a function contains the line number
2523 recorded when we finished processing the function. */
2524 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2526 /* Generate code for the function. */
2527 finish_function (lineno
, 0);
2529 /* And restore the current source position. */
2530 lineno
= saved_lineno
;
2531 input_filename
= saved_input_filename
;