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
35 /* There routines provide a modular interface to perform many parsing
36 operations. They may therefore be used during actual parsing, or
37 during template instantiation, which may be regarded as a
38 degenerate form of parsing. Since the current g++ parser is
39 lacking in several respects, and will be reimplemented, we are
40 attempting to move most code that is not directly related to
41 parsing into this file; that will make implementing the new parser
42 much easier since it will be able to make use of these routines. */
44 static void do_pushlevel
PROTO((void));
45 static tree do_poplevel
PROTO((void));
46 static void finish_expr_stmt_real
PROTO((tree
, int));
47 static tree expand_cond
PROTO((tree
));
48 static tree maybe_convert_cond
PROTO((tree
));
50 /* When parsing a template, LAST_TREE contains the last statement
51 parsed. These are chained together through the TREE_CHAIN field,
52 but often need to be re-organized since the parse is performed
53 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
56 #define RECHAIN_STMTS(stmt, substmt) \
58 substmt = TREE_CHAIN (stmt); \
59 TREE_CHAIN (stmt) = NULL_TREE; \
63 /* Finish processing the COND, the SUBSTMT condition for STMT. */
65 #define FINISH_COND(cond, stmt, substmt) \
67 if (last_tree != stmt) \
69 RECHAIN_STMTS (stmt, substmt); \
70 if (!processing_template_decl) \
72 cond = build_tree_list (substmt, cond); \
80 /* T is a statement. Add it to the statement-tree. */
86 /* Add T to the statement-tree. */
87 last_tree
= TREE_CHAIN (last_tree
) = t
;
89 /* When we expand a statement-tree, we must know whether or not the
90 statements are full-expresions. We record that fact here. */
91 if (building_stmt_tree ())
92 STMT_IS_FULL_EXPR_P (last_tree
) = stmts_are_full_exprs_p
;
95 /* COND is the condition-expression for an if, while, etc.,
96 statement. Convert it to a boolean value, if appropriate. */
99 maybe_convert_cond (cond
)
102 /* Empty conditions remain empty. */
106 /* Wait until we instantiate templates before doing conversion. */
107 if (processing_template_decl
)
110 /* Do the conversion. */
111 cond
= convert_from_reference (cond
);
112 return condition_conversion (cond
);
115 /* Finish an expression-statement, whose EXPRESSION is as indicated.
116 If ASSIGNED_THIS is non-zero, then this statement just assigned to
117 the `this' pointer. */
120 finish_expr_stmt_real (expr
, assigned_this
)
124 if (expr
!= NULL_TREE
)
126 if (building_stmt_tree ())
127 add_tree (build_min_nt (EXPR_STMT
, expr
));
130 emit_line_note (input_filename
, lineno
);
131 /* Do default conversion if safe and possibly important,
132 in case within ({...}). */
133 if (!stmts_are_full_exprs_p
&&
134 ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
136 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
137 expr
= default_conversion (expr
);
139 if (stmts_are_full_exprs_p
)
140 expand_start_target_temps ();
142 cplus_expand_expr_stmt (expr
);
144 if (stmts_are_full_exprs_p
)
146 expand_end_target_temps ();
152 /* If this statement assigned to the `this' pointer, record that
153 fact for finish_stmt. */
155 current_function_just_assigned_this
= 1;
159 /* This was an expression-statement, so we save the type of the
161 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
164 /* Like finish_expr_stmt_real, but ASSIGNS_THIS is always zero. */
167 finish_expr_stmt (expr
)
170 finish_expr_stmt_real (expr
, /*assigns_this=*/0);
173 /* Begin an if-statement. Returns a newly created IF_STMT if
181 if (building_stmt_tree ())
183 r
= build_min_nt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
194 /* Process the COND of an if-statement, which may be given by
198 finish_if_stmt_cond (cond
, if_stmt
)
202 cond
= maybe_convert_cond (cond
);
204 if (building_stmt_tree ())
205 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
208 emit_line_note (input_filename
, lineno
);
209 expand_start_cond (cond
, 0);
213 /* Finish the then-clause of an if-statement, which may be given by
217 finish_then_clause (if_stmt
)
220 if (building_stmt_tree ())
222 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
230 /* Begin the else-clause of an if-statement. */
235 if (!building_stmt_tree ())
236 expand_start_else ();
239 /* Finish the else-clause of an if-statement, which may be given by
243 finish_else_clause (if_stmt
)
246 if (building_stmt_tree ())
247 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
250 /* Finsh an if-statement. */
255 if (!building_stmt_tree ())
262 /* Begin a while-statement. Returns a newly created WHILE_STMT if
270 if (building_stmt_tree ())
272 r
= build_min_nt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
278 emit_line_note (input_filename
, lineno
);
279 expand_start_loop (1);
288 /* Process the COND of an if-statement, which may be given by
292 finish_while_stmt_cond (cond
, while_stmt
)
296 cond
= maybe_convert_cond (cond
);
298 if (building_stmt_tree ())
299 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
302 emit_line_note (input_filename
, lineno
);
303 expand_exit_loop_if_false (0, cond
);
306 /* If COND wasn't a declaration, clear out the
307 block we made for it and start a new one here so the
308 optimization in expand_end_loop will work. */
309 if (getdecls () == NULL_TREE
)
316 /* Finish a while-statement, which may be given by WHILE_STMT. */
319 finish_while_stmt (while_stmt
)
324 if (building_stmt_tree ())
325 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
331 /* Begin a do-statement. Returns a newly created DO_STMT if
337 if (building_stmt_tree ())
339 tree r
= build_min_nt (DO_STMT
, NULL_TREE
, NULL_TREE
);
346 emit_line_note (input_filename
, lineno
);
347 expand_start_loop_continue_elsewhere (1);
352 /* Finish the body of a do-statement, which may be given by DO_STMT. */
355 finish_do_body (do_stmt
)
358 if (building_stmt_tree ())
359 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
361 expand_loop_continue_here ();
364 /* Finish a do-statement, which may be given by DO_STMT, and whose
365 COND is as indicated. */
368 finish_do_stmt (cond
, do_stmt
)
372 cond
= maybe_convert_cond (cond
);
374 if (building_stmt_tree ())
375 DO_COND (do_stmt
) = cond
;
378 emit_line_note (input_filename
, lineno
);
379 expand_exit_loop_if_false (0, cond
);
387 /* Finish a return-statement. The EXPRESSION returned, if any, is as
391 finish_return_stmt (expr
)
394 if (building_stmt_tree ())
395 add_tree (build_min_nt (RETURN_STMT
, expr
));
398 emit_line_note (input_filename
, lineno
);
399 c_expand_return (expr
);
405 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
412 if (building_stmt_tree ())
414 r
= build_min_nt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
415 NULL_TREE
, NULL_TREE
);
421 if (flag_new_for_scope
> 0)
424 note_level_for_for ();
430 /* Finish the for-init-statement of a for-statement, which may be
431 given by FOR_STMT. */
434 finish_for_init_stmt (for_stmt
)
437 if (building_stmt_tree ())
439 if (last_tree
!= for_stmt
)
440 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
445 emit_line_note (input_filename
, lineno
);
446 expand_start_loop_continue_elsewhere (1);
452 /* Finish the COND of a for-statement, which may be given by
456 finish_for_cond (cond
, for_stmt
)
460 cond
= maybe_convert_cond (cond
);
462 if (building_stmt_tree ())
463 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
466 emit_line_note (input_filename
, lineno
);
468 expand_exit_loop_if_false (0, cond
);
471 /* If the cond wasn't a declaration, clear out the
472 block we made for it and start a new one here so the
473 optimization in expand_end_loop will work. */
474 if (getdecls () == NULL_TREE
)
481 /* Finish the increment-EXPRESSION in a for-statement, which may be
482 given by FOR_STMT. */
485 finish_for_expr (expr
, for_stmt
)
489 if (building_stmt_tree ())
490 FOR_EXPR (for_stmt
) = expr
;
492 /* Don't let the tree nodes for EXPR be discarded
493 by clear_momentary during the parsing of the next stmt. */
497 /* Finish the body of a for-statement, which may be given by
498 FOR_STMT. The increment-EXPR for the loop must be
502 finish_for_stmt (expr
, for_stmt
)
506 /* Pop the scope for the body of the loop. */
509 if (building_stmt_tree ())
510 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
513 emit_line_note (input_filename
, lineno
);
514 expand_loop_continue_here ();
516 finish_expr_stmt (expr
);
522 if (flag_new_for_scope
> 0)
528 /* Finish a break-statement. */
533 emit_line_note (input_filename
, lineno
);
534 if (building_stmt_tree ())
535 add_tree (build_min_nt (BREAK_STMT
));
536 else if ( ! expand_exit_something ())
537 cp_error ("break statement not within loop or switch");
540 /* Finish a continue-statement. */
543 finish_continue_stmt ()
545 emit_line_note (input_filename
, lineno
);
546 if (building_stmt_tree ())
547 add_tree (build_min_nt (CONTINUE_STMT
));
548 else if (! expand_continue_loop (0))
549 cp_error ("continue statement not within a loop");
552 /* Begin a switch-statement. Returns a new SWITCH_STMT if
560 if (building_stmt_tree ())
562 r
= build_min_nt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
573 /* Finish the cond of a switch-statement. */
576 finish_switch_cond (cond
, switch_stmt
)
580 if (building_stmt_tree ())
581 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
582 else if (cond
!= error_mark_node
)
584 emit_line_note (input_filename
, lineno
);
585 c_expand_start_case (cond
);
588 /* The code is in error, but we don't want expand_end_case to
590 c_expand_start_case (boolean_false_node
);
594 /* Don't let the tree nodes for COND be discarded by
595 clear_momentary during the parsing of the next stmt. */
599 /* Finish the body of a switch-statement, which may be given by
600 SWITCH_STMT. The COND to switch on is indicated. */
603 finish_switch_stmt (cond
, switch_stmt
)
607 if (building_stmt_tree ())
608 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
610 expand_end_case (cond
);
617 /* Finish a case-label. */
620 finish_case_label (low_value
, high_value
)
624 if (building_stmt_tree ())
626 add_tree (build_min_nt (CASE_LABEL
, low_value
, high_value
));
630 do_case (low_value
, high_value
);
633 /* Finish a goto-statement. */
636 finish_goto_stmt (destination
)
639 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
640 destination
= lookup_label (destination
);
642 if (building_stmt_tree ())
643 add_tree (build_min_nt (GOTO_STMT
, destination
));
646 emit_line_note (input_filename
, lineno
);
648 if (TREE_CODE (destination
) == LABEL_DECL
)
650 TREE_USED (destination
) = 1;
651 expand_goto (destination
);
654 expand_computed_goto (destination
);
658 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
664 if (building_stmt_tree ())
666 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
673 emit_line_note (input_filename
, lineno
);
674 expand_start_try_stmts ();
679 /* Likewise, for a function-try-block. */
682 begin_function_try_block ()
684 if (building_stmt_tree ())
686 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
688 FN_TRY_BLOCK_P (r
) = 1;
694 if (! current_function_parms_stored
)
696 expand_start_early_try_stmts ();
701 /* Finish a try-block, which may be given by TRY_BLOCK. */
704 finish_try_block (try_block
)
707 if (building_stmt_tree ())
708 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
710 expand_start_all_catch ();
713 /* Finish the body of a cleanup try-block, which may be given by
717 finish_cleanup_try_block (try_block
)
720 if (building_stmt_tree ())
721 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
724 /* Finish an implicitly generated try-block, with a cleanup is given
728 finish_cleanup (cleanup
, try_block
)
732 if (building_stmt_tree ())
734 TRY_HANDLERS (try_block
) = cleanup
;
735 CLEANUP_P (try_block
) = 1;
738 expand_eh_region_end (protect_with_terminate (cleanup
));
741 /* Likewise, for a function-try-block. */
744 finish_function_try_block (try_block
)
747 if (building_stmt_tree ())
749 if (TREE_CHAIN (try_block
)
750 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
752 /* Chain the compound statement after the CTOR_INITIALIZER. */
753 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
754 /* And make the CTOR_INITIALIZER the body of the try-block. */
755 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
758 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
762 end_protect_partials ();
763 expand_start_all_catch ();
764 in_function_try_handler
= 1;
768 /* Finish a handler-sequence for a try-block, which may be given by
772 finish_handler_sequence (try_block
)
775 if (building_stmt_tree ())
776 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
778 expand_end_all_catch ();
781 /* Likewise, for a function-try-block. */
784 finish_function_handler_sequence (try_block
)
787 if (building_stmt_tree ())
788 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
791 in_function_try_handler
= 0;
792 expand_end_all_catch ();
796 /* Begin a handler. Returns a HANDLER if appropriate. */
803 if (building_stmt_tree ())
805 r
= build_min_nt (HANDLER
, NULL_TREE
, NULL_TREE
);
816 /* Finish the handler-parameters for a handler, which may be given by
820 finish_handler_parms (handler
)
823 if (building_stmt_tree ())
824 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
827 /* Finish a handler, which may be given by HANDLER. */
830 finish_handler (handler
)
833 if (building_stmt_tree ())
834 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
836 expand_end_catch_block ();
841 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
842 compound-statement does not define a scope. Returns a new
843 COMPOUND_STMT if appropriate. */
846 begin_compound_stmt (has_no_scope
)
851 if (building_stmt_tree ())
853 r
= build_min_nt (COMPOUND_STMT
, NULL_TREE
);
856 COMPOUND_STMT_NO_SCOPE (r
) = 1;
861 last_expr_type
= NULL_TREE
;
866 /* Normally, we try hard to keep the BLOCK for a
867 statement-expression. But, if it's a statement-expression with
868 a scopeless block, there's nothing to keep, and we don't want
869 to accidentally keep a block *inside* the scopeless block. */
872 /* If this is the outermost block of the function, declare the
873 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
874 if (!current_function_name_declared
&& !processing_template_decl
)
876 declare_function_name ();
877 current_function_name_declared
= 1;
884 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
885 If HAS_NO_SCOPE is non-zero, the compound statement does not define
889 finish_compound_stmt (has_no_scope
, compound_stmt
)
901 if (building_stmt_tree ())
902 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
904 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
905 the precise purpose of that variable is store the type of the
906 last expression statement within the last compound statement, we
907 preserve the value. */
915 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
916 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
920 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
921 input_operands
, clobbers
)
924 tree output_operands
;
928 if (TREE_CHAIN (string
))
930 if (building_stmt_tree ())
931 /* We need to build the combined string on the permanent
932 obstack so that we can use it during instantiations. */
933 push_permanent_obstack ();
935 string
= combine_strings (string
);
937 if (building_stmt_tree ())
941 if (cv_qualifier
!= NULL_TREE
942 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
944 cp_warning ("%s qualifier ignored on asm",
945 IDENTIFIER_POINTER (cv_qualifier
));
946 cv_qualifier
= NULL_TREE
;
949 if (building_stmt_tree ())
951 tree r
= build_min_nt (ASM_STMT
, cv_qualifier
, string
,
952 output_operands
, input_operands
,
958 emit_line_note (input_filename
, lineno
);
959 if (output_operands
!= NULL_TREE
|| input_operands
!= NULL_TREE
960 || clobbers
!= NULL_TREE
)
964 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
965 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
967 c_expand_asm_operands (string
, output_operands
,
970 cv_qualifier
!= NULL_TREE
,
971 input_filename
, lineno
);
980 /* Finish a label with the indicated NAME. */
983 finish_label_stmt (name
)
986 tree decl
= define_label (input_filename
, lineno
, name
);
988 if (building_stmt_tree ())
989 add_tree (build_min_nt (LABEL_STMT
, decl
));
994 /* Finish a series of declarations for local labels. G++ allows users
995 to declare "local" labels, i.e., labels with scope. This extension
996 is useful when writing code involving statement-expressions. */
999 finish_label_decl (name
)
1002 tree decl
= declare_local_label (name
);
1003 if (building_stmt_tree ())
1004 add_decl_stmt (decl
);
1007 /* Create a declaration statement for the declaration given by the
1011 add_decl_stmt (decl
)
1016 /* We need the type to last until instantiation time. */
1017 decl_stmt
= build_min_nt (DECL_STMT
, decl
);
1018 add_tree (decl_stmt
);
1021 /* We're in a constructor, and have just constructed a a subobject of
1022 *THIS. CLEANUP is code to run if an exception is thrown before the
1023 end of the current function is reached. */
1026 finish_subobject (cleanup
)
1029 if (building_stmt_tree ())
1031 tree r
= build_min_nt (SUBOBJECT
, cleanup
);
1035 add_partial_entry (cleanup
);
1038 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1041 finish_decl_cleanup (decl
, cleanup
)
1045 if (building_stmt_tree ())
1046 add_tree (build_min_nt (CLEANUP_STMT
, decl
, cleanup
));
1047 else if (DECL_SIZE (decl
) && TREE_TYPE (decl
) != error_mark_node
)
1048 expand_decl_cleanup (decl
, cleanup
);
1051 /* Bind a name and initialization to the return value of
1052 the current function. */
1055 finish_named_return_value (return_id
, init
)
1056 tree return_id
, init
;
1058 tree decl
= DECL_RESULT (current_function_decl
);
1061 /* Give this error as many times as there are occurrences,
1062 so that users can use Emacs compilation buffers to find
1063 and fix all such places. */
1064 pedwarn ("ANSI C++ does not permit named return values");
1066 if (return_id
!= NULL_TREE
)
1068 if (DECL_NAME (decl
) == NULL_TREE
)
1070 DECL_NAME (decl
) = return_id
;
1071 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1075 cp_error ("return identifier `%D' already in place", return_id
);
1080 /* Can't let this happen for constructors. */
1081 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1083 error ("can't redefine default return value for constructors");
1087 /* If we have a named return value, put that in our scope as well. */
1088 if (DECL_NAME (decl
) != NULL_TREE
)
1090 /* Let `cp_finish_decl' know that this initializer is ok. */
1091 DECL_INITIAL (decl
) = init
;
1094 if (building_stmt_tree ())
1095 add_tree (build_min_nt (RETURN_INIT
, return_id
, init
));
1098 cp_finish_decl (decl
, init
, NULL_TREE
, 0, 0);
1099 store_return_init (decl
);
1104 /* Cache the value of this class's main virtual function table pointer
1105 in a register variable. This will save one indirection if a
1106 more than one virtual function call is made this function. */
1111 if (base_init_expr
== 0
1112 && DECL_CONSTRUCTOR_P (current_function_decl
))
1114 if (building_stmt_tree ())
1115 add_tree (build_min_nt
1117 current_member_init_list
, current_base_init_list
));
1119 emit_base_init (current_class_type
);
1122 /* Always keep the BLOCK node associated with the outermost pair of
1123 curley braces of a function. These are needed for correct
1124 operation of dwarfout.c. */
1125 keep_next_level (1);
1128 /* Begin a new scope. */
1133 if (!building_stmt_tree ())
1135 emit_line_note (input_filename
, lineno
);
1139 if (stmts_are_full_exprs_p
)
1141 if (!building_stmt_tree () && stmts_are_full_exprs_p
)
1142 expand_start_bindings (0);
1145 /* Finish a scope. */
1152 if (!building_stmt_tree () && stmts_are_full_exprs_p
)
1153 expand_end_bindings (getdecls (), kept_level_p (), 0);
1154 if (stmts_are_full_exprs_p
)
1155 t
= poplevel (kept_level_p (), 1, 0);
1162 /* Finish a parenthesized expression EXPR. */
1165 finish_parenthesized_expr (expr
)
1168 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1169 /* This inhibits warnings in truthvalue_conversion. */
1170 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1175 /* Begin a statement-expression. The value returned must be passed to
1176 finish_stmt_expr. */
1181 keep_next_level (1);
1182 /* If we're building a statement tree, then the upcoming compound
1183 statement will be chained onto the tree structure, starting at
1184 last_tree. We return last_tree so that we can later unhook the
1185 compound statement. */
1186 return building_stmt_tree () ? last_tree
: expand_start_stmt_expr();
1189 /* Finish a statement-expression. RTL_EXPR should be the value
1190 returned by the previous begin_stmt_expr; EXPR is the
1191 statement-expression. Returns an expression representing the
1192 statement-expression. */
1195 finish_stmt_expr (rtl_expr
, expr
)
1201 if (!building_stmt_tree ())
1203 rtl_expr
= expand_end_stmt_expr (rtl_expr
);
1204 /* The statements have side effects, so the group does. */
1205 TREE_SIDE_EFFECTS (rtl_expr
) = 1;
1208 if (building_stmt_tree ())
1210 /* If the last thing in the statement-expression was not an
1211 expression-statement, then it has type `void'. */
1212 if (!last_expr_type
)
1213 last_expr_type
= void_type_node
;
1214 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1215 TREE_SIDE_EFFECTS (result
) = 1;
1217 /* Remove the compound statement from the tree structure; it is
1218 now saved in the STMT_EXPR. */
1219 last_tree
= rtl_expr
;
1220 TREE_CHAIN (last_tree
) = NULL_TREE
;
1222 else if (expr
&& TREE_CODE (expr
) == BLOCK
)
1224 result
= build (BIND_EXPR
, TREE_TYPE (rtl_expr
),
1225 NULL_TREE
, rtl_expr
, expr
);
1226 delete_block (expr
);
1231 if (expr
&& TREE_CODE (expr
) == BLOCK
)
1232 /* Remove the block from the tree at this point. It gets put back
1233 at the proper place when the STMT_EXPR or BIND_EXPR is
1235 delete_block (expr
);
1240 /* Finish a call to FN with ARGS. Returns a representation of the
1244 finish_call_expr (fn
, args
, koenig
)
1253 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1254 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1255 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1256 fn
= do_identifier (fn
, 2, args
);
1258 result
= build_x_function_call (fn
, args
, current_class_ref
);
1260 if (TREE_CODE (result
) == CALL_EXPR
1261 && (! TREE_TYPE (result
)
1262 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1263 result
= require_complete_type (result
);
1268 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1269 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1270 POSTDECREMENT_EXPR.) */
1273 finish_increment_expr (expr
, code
)
1275 enum tree_code code
;
1277 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1278 a COMPONENT_REF). This way if we've got, say, a reference to a
1279 static member that's being operated on, we don't end up trying to
1280 find a member operator for the class it's in. */
1282 if (TREE_CODE (expr
) == OFFSET_REF
)
1283 expr
= resolve_offset_ref (expr
);
1284 return build_x_unary_op (code
, expr
);
1287 /* Finish a use of `this'. Returns an expression for `this'. */
1294 if (current_class_ptr
)
1296 #ifdef WARNING_ABOUT_CCD
1297 TREE_USED (current_class_ptr
) = 1;
1299 result
= current_class_ptr
;
1301 else if (current_function_decl
1302 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1304 error ("`this' is unavailable for static member functions");
1305 result
= error_mark_node
;
1309 if (current_function_decl
)
1310 error ("invalid use of `this' in non-member function");
1312 error ("invalid use of `this' at top level");
1313 result
= error_mark_node
;
1319 /* Finish a member function call using OBJECT and ARGS as arguments to
1320 FN. Returns an expression for the call. */
1323 finish_object_call_expr (fn
, object
, args
)
1329 /* This is a future direction of this code, but because
1330 build_x_function_call cannot always undo what is done in
1331 build_component_ref entirely yet, we cannot do this. */
1333 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1334 return finish_call_expr (real_fn
, args
);
1336 if (TREE_CODE (fn
) == TYPE_DECL
)
1338 if (processing_template_decl
)
1339 /* This can happen on code like:
1342 template <class T> void f(T t) {
1346 We just grab the underlying IDENTIFIER. */
1347 fn
= DECL_NAME (fn
);
1350 cp_error ("calling type `%T' like a method", fn
);
1351 return error_mark_node
;
1355 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1359 /* Finish a qualified member function call using OBJECT and ARGS as
1360 arguments to FN. Returns an expressino for the call. */
1363 finish_qualified_object_call_expr (fn
, object
, args
)
1368 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1369 TREE_OPERAND (fn
, 1), args
);
1372 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1373 being the scope, if any, of DESTRUCTOR. Returns an expression for
1377 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1382 if (processing_template_decl
)
1383 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1385 if (scope
&& scope
!= destructor
)
1386 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1389 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1390 && (TREE_CODE (TREE_TYPE (object
)) !=
1391 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1392 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1394 return cp_convert (void_type_node
, object
);
1397 /* Finish a call to a globally qualified member function FN using
1398 ARGS. Returns an expression for the call. */
1401 finish_qualified_call_expr (fn
, args
)
1405 if (processing_template_decl
)
1406 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1408 return build_member_call (TREE_OPERAND (fn
, 0),
1409 TREE_OPERAND (fn
, 1),
1413 /* Finish an expression taking the address of LABEL. Returns an
1414 expression for the address. */
1417 finish_label_address_expr (label
)
1422 label
= lookup_label (label
);
1423 if (label
== NULL_TREE
)
1424 result
= null_pointer_node
;
1427 TREE_USED (label
) = 1;
1428 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1429 TREE_CONSTANT (result
) = 1;
1435 /* Finish an expression of the form CODE EXPR. */
1438 finish_unary_op_expr (code
, expr
)
1439 enum tree_code code
;
1442 tree result
= build_x_unary_op (code
, expr
);
1443 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
)
1444 TREE_NEGATED_INT (result
) = 1;
1445 overflow_warning (result
);
1449 /* Finish an id-expression. */
1452 finish_id_expr (expr
)
1455 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1456 expr
= do_identifier (expr
, 1, NULL_TREE
);
1461 /* Begin a new-placement. */
1464 begin_new_placement ()
1466 /* The arguments to a placement new might be passed to a
1467 deallocation function, in the event that the allocation throws an
1468 exception. Since we don't expand exception handlers until the
1469 end of a function, we must make sure the arguments stay around
1471 return suspend_momentary ();
1474 /* Finish a new-placement. The ARGS are the placement arguments. The
1475 COOKIE is the value returned by the previous call to
1476 begin_new_placement. */
1479 finish_new_placement (args
, cookie
)
1483 resume_momentary (cookie
);
1487 /* Begin a function defniition declared with DECL_SPECS and
1488 DECLARATOR. Returns non-zero if the function-declaration is
1492 begin_function_definition (decl_specs
, declarator
)
1498 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1499 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1502 reinit_parse_for_function ();
1503 /* The things we're about to see are not directly qualified by any
1504 template headers we've seen thus far. */
1505 reset_specialization ();
1510 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1514 begin_constructor_declarator (scope
, name
)
1518 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1519 enter_scope_of (result
);
1523 /* Finish an init-declarator. Returns a DECL. */
1526 finish_declarator (declarator
, declspecs
, attributes
,
1527 prefix_attributes
, initialized
)
1531 tree prefix_attributes
;
1534 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1538 /* Finish a translation unit. */
1541 finish_translation_unit ()
1543 /* In case there were missing closebraces,
1544 get us back to the global binding level. */
1546 while (current_namespace
!= global_namespace
)
1551 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1552 Returns the parameter. */
1555 finish_template_type_parm (aggr
, identifier
)
1559 if (aggr
!= class_type_node
)
1561 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1562 aggr
= class_type_node
;
1565 return build_tree_list (aggr
, identifier
);
1568 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1569 Returns the parameter. */
1572 finish_template_template_parm (aggr
, identifier
)
1576 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1577 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1578 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1579 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1580 SET_DECL_ARTIFICIAL (decl
);
1581 end_template_decl ();
1583 return finish_template_type_parm (aggr
, tmpl
);
1586 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1587 non-zero, the parameter list was terminated by a `...'. */
1590 finish_parmlist (parms
, ellipsis
)
1595 chainon (parms
, void_list_node
);
1596 /* We mark the PARMS as a parmlist so that declarator processing can
1597 disambiguate certain constructs. */
1598 if (parms
!= NULL_TREE
)
1599 TREE_PARMLIST (parms
) = 1;
1604 /* Begin a class definition, as indicated by T. */
1607 begin_class_definition (t
)
1610 push_permanent_obstack ();
1612 if (t
== error_mark_node
1613 || ! IS_AGGR_TYPE (t
))
1615 t
= make_lang_type (RECORD_TYPE
);
1616 pushtag (make_anon_name (), t
, 0);
1619 /* In a definition of a member class template, we will get here with an
1620 implicit typename, a TYPENAME_TYPE with a type. */
1621 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1624 /* If we generated a partial instantiation of this type, but now
1625 we're seeing a real definition, we're actually looking at a
1626 partial specialization. Consider:
1628 template <class T, class U>
1634 template <class T, class U>
1637 typename X<Y<T, U> >::A a;
1640 template <class T, class U>
1645 We have to undo the effects of the previous partial
1647 if (PARTIAL_INSTANTIATION_P (t
))
1651 /* Unfortunately, when we're not in pedantic mode, we
1652 attempt to actually fill in some of the fields of the
1653 partial instantiation, in order to support the implicit
1654 typename extension. Clear those fields now, in
1655 preparation for the definition here. The fields cleared
1656 here must match those set in instantiate_class_template.
1657 Look for a comment mentioning begin_class_definition
1659 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1660 TYPE_FIELDS (t
) = NULL_TREE
;
1661 TYPE_METHODS (t
) = NULL_TREE
;
1662 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1663 TYPE_SIZE (t
) = NULL_TREE
;
1666 /* This isn't a partial instantiation any more. */
1667 PARTIAL_INSTANTIATION_P (t
) = 0;
1669 /* If this type was already complete, and we see another definition,
1671 else if (TYPE_SIZE (t
))
1672 duplicate_tag_error (t
);
1674 /* Update the location of the decl. */
1675 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1676 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1678 if (TYPE_BEING_DEFINED (t
))
1680 t
= make_lang_type (TREE_CODE (t
));
1681 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1683 maybe_process_partial_specialization (t
);
1685 TYPE_BEING_DEFINED (t
) = 1;
1686 /* Reset the interface data, at the earliest possible
1687 moment, as it might have been set via a class foo;
1690 tree name
= TYPE_IDENTIFIER (t
);
1692 if (! ANON_AGGRNAME_P (name
))
1694 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1695 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1696 (t
, interface_unknown
);
1699 /* Only leave this bit clear if we know this
1700 class is part of an interface-only specification. */
1701 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1702 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1703 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1706 tmp
= TYPE_IDENTIFIER ($
<ttype
>0);
1707 if (tmp
&& IDENTIFIER_TEMPLATE (tmp
))
1708 overload_template_name (tmp
, 1);
1710 reset_specialization();
1712 /* In case this is a local class within a template
1713 function, we save the current tree structure so
1714 that we can get it back later. */
1717 /* Make a declaration for this class in its own scope. */
1718 build_self_reference ();
1723 /* Finish the member declaration given by DECL. */
1726 finish_member_declaration (decl
)
1729 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1732 if (decl
== void_type_node
)
1733 /* The COMPONENT was a friend, not a member, and so there's
1734 nothing for us to do. */
1737 /* We should see only one DECL at a time. */
1738 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1740 /* Set up access control for DECL. */
1742 = (current_access_specifier
== access_private_node
);
1743 TREE_PROTECTED (decl
)
1744 = (current_access_specifier
== access_protected_node
);
1745 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1747 TREE_PRIVATE (DECL_RESULT (decl
)) = TREE_PRIVATE (decl
);
1748 TREE_PROTECTED (DECL_RESULT (decl
)) = TREE_PROTECTED (decl
);
1751 /* Mark the DECL as a member of the current class. */
1752 if (TREE_CODE (decl
) == FUNCTION_DECL
1753 || DECL_FUNCTION_TEMPLATE_P (decl
))
1754 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1755 finish_struct. Presumably it is already set as the function is
1756 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1757 DECL_CLASS_CONTEXT (decl
) = current_class_type
;
1759 DECL_CONTEXT (decl
) = current_class_type
;
1761 /* Put functions on the TYPE_METHODS list and everything else on the
1762 TYPE_FIELDS list. Note that these are built up in reverse order.
1763 We reverse them (to obtain declaration order) in finish_struct. */
1764 if (TREE_CODE (decl
) == FUNCTION_DECL
1765 || DECL_FUNCTION_TEMPLATE_P (decl
))
1767 /* We also need to add this function to the
1768 CLASSTYPE_METHOD_VEC. */
1769 add_method (current_class_type
, 0, decl
);
1771 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1772 TYPE_METHODS (current_class_type
) = decl
;
1776 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1777 go at the beginning. The reason is that lookup_field_1
1778 searches the list in order, and we want a field name to
1779 override a type name so that the "struct stat hack" will
1780 work. In particular:
1782 struct S { enum E { }; int E } s;
1785 is legal. In addition, the FIELD_DECLs must be maintained in
1786 declaration order so that class layout works as expected.
1787 However, we don't need that order until class layout, so we
1788 save a little time by putting FIELD_DECLs on in reverse order
1789 here, and then reversing them in finish_struct_1. (We could
1790 also keep a pointer to the correct insertion points in the
1793 if (TREE_CODE (decl
) == TYPE_DECL
)
1794 TYPE_FIELDS (current_class_type
)
1795 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1798 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1799 TYPE_FIELDS (current_class_type
) = decl
;
1802 /* Enter the DECL into the scope of the class. */
1803 if (TREE_CODE (decl
) != USING_DECL
)
1804 pushdecl_class_level (decl
);
1808 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1809 the definition is immediately followed by a semicolon. Returns the
1813 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
1819 /* finish_struct nukes this anyway; if finish_exception does too,
1822 note_got_semicolon (t
);
1824 /* If we got any attributes in class_head, xref_tag will stick them in
1825 TREE_TYPE of the type. Grab them now. */
1826 attributes
= chainon (TREE_TYPE (t
), attributes
);
1827 TREE_TYPE (t
) = NULL_TREE
;
1829 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1833 t
= finish_struct (t
, attributes
);
1835 note_got_semicolon (t
);
1841 check_for_missing_semicolon (t
);
1843 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
1844 if (current_scope () == current_function_decl
)
1845 do_pending_defargs ();
1850 /* Finish processing the default argument expressions cached during
1851 the processing of a class definition. */
1854 begin_inline_definitions ()
1857 && current_scope () == current_function_decl
)
1858 do_pending_inlines ();
1861 /* Finish processing the inline function definitions cached during the
1862 processing of a class definition. */
1865 finish_inline_definitions ()
1867 if (current_class_type
== NULL_TREE
)
1868 clear_inline_text_obstack ();
1870 /* Undo the begin_tree in begin_class_definition. */
1874 /* Finish processing the declaration of a member class template
1875 TYPES whose template parameters are given by PARMS. */
1878 finish_member_class_template (types
)
1883 /* If there are declared, but undefined, partial specializations
1884 mixed in with the typespecs they will not yet have passed through
1885 maybe_process_partial_specialization, so we do that here. */
1886 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
1887 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
1888 maybe_process_partial_specialization (TREE_VALUE (t
));
1890 note_list_got_semicolon (types
);
1891 grok_x_components (types
);
1892 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
1893 /* The component was in fact a friend declaration. We avoid
1894 finish_member_template_decl performing certain checks by
1898 finish_member_template_decl (types
);
1900 /* As with other component type declarations, we do
1901 not store the new DECL on the list of
1906 /* Finish processsing a complete template declaration. The PARMS are
1907 the template parameters. */
1910 finish_template_decl (parms
)
1914 end_template_decl ();
1916 end_specialization ();
1919 /* Finish processing a a template-id (which names a type) of the form
1920 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1921 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1922 the scope of template-id indicated. */
1925 finish_template_type (name
, args
, entering_scope
)
1932 decl
= lookup_template_class (name
, args
,
1933 NULL_TREE
, NULL_TREE
, entering_scope
);
1934 if (decl
!= error_mark_node
)
1935 decl
= TYPE_STUB_DECL (decl
);
1940 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
1941 namespace scope or a class scope. */
1947 tree scope
= TREE_OPERAND (sr
, 0);
1949 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
1951 push_decl_namespace (scope
);
1952 TREE_COMPLEXITY (sr
) = -1;
1954 else if (scope
!= current_class_type
)
1956 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
1958 /* In a declarator for a template class member, the scope will
1959 get here as an implicit typename, a TYPENAME_TYPE with a type. */
1960 scope
= TREE_TYPE (scope
);
1961 TREE_OPERAND (sr
, 0) = scope
;
1963 push_nested_class (scope
, 3);
1964 TREE_COMPLEXITY (sr
) = current_class_depth
;
1968 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
1969 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
1970 BASE_CLASS, or NULL_TREE if an error occurred. The
1971 ACCESSS_SPECIFIER is one of
1972 access_{default,public,protected_private}[_virtual]_node.*/
1975 finish_base_specifier (access_specifier
, base_class
)
1976 tree access_specifier
;
1982 if (base_class
== NULL_TREE
)
1984 error ("invalid base class");
1985 type
= error_mark_node
;
1988 type
= TREE_TYPE (base_class
);
1990 if (! is_aggr_type (type
, 1))
1993 result
= build_tree_list (access_specifier
, type
);
1998 /* Called when multiple declarators are processed. If that is not
1999 premitted in this context, an error is issued. */
2002 check_multiple_declarators ()
2006 In a template-declaration, explicit specialization, or explicit
2007 instantiation the init-declarator-list in the declaration shall
2008 contain at most one declarator.
2010 We don't just use PROCESSING_TEMPLATE_DECL for the first
2011 condition since that would disallow the perfectly legal code,
2012 like `template <class T> struct S { int i, j; };'. */
2013 tree scope
= current_scope ();
2015 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2016 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2019 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2020 || processing_explicit_instantiation
2021 || processing_specialization
)
2022 cp_error ("multiple declarators in template declaration");
2026 finish_typeof (expr
)
2029 if (processing_template_decl
)
2033 push_permanent_obstack ();
2034 t
= make_lang_type (TYPEOF_TYPE
);
2035 TYPE_FIELDS (t
) = expr
;
2041 return TREE_TYPE (expr
);
2044 /* Create an empty statement tree for FN. */
2047 begin_stmt_tree (fn
)
2050 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2051 what follows. We remove the extraneous statement in
2052 finish_stmt_tree. */
2053 DECL_SAVED_TREE (fn
) = build_nt (EXPR_STMT
, void_zero_node
);
2054 last_tree
= DECL_SAVED_TREE (fn
);
2055 last_expr_type
= NULL_TREE
;
2058 /* Finish the statement tree for FN. */
2061 finish_stmt_tree (fn
)
2066 /* Remove the fake extra statement added in begin_stmt_tree. */
2067 stmt
= TREE_CHAIN (DECL_SAVED_TREE (fn
));
2068 DECL_SAVED_TREE (fn
) = stmt
;
2070 /* The line-number recorded in the outermost statement in a function
2071 is the line number of the end of the function. */
2072 STMT_LINENO (stmt
) = lineno
;
2073 STMT_LINENO_FOR_FN_P (stmt
) = 1;
2076 /* We're about to expand T, a statement. Set up appropriate context
2077 for the substitution. */
2083 if (!STMT_LINENO_FOR_FN_P (t
))
2084 lineno
= STMT_LINENO (t
);
2085 stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2088 /* Some statements, like for-statements or if-statements, require a
2089 condition. This condition can be a declaration. If T is such a
2090 declaration it is processed, and an expression appropriate to use
2091 as the condition is returned. Otherwise, T itself is returned. */
2097 if (t
&& TREE_CODE (t
) == TREE_LIST
)
2099 expand_stmt (TREE_PURPOSE (t
));
2100 return TREE_VALUE (t
);
2106 /* Generate RTL for the statement T, and its substatements, and any
2107 other statements at its nesting level. */
2115 while (t
&& t
!= error_mark_node
)
2117 int saved_stmts_are_full_exprs_p
;
2119 /* Assume we'll have nothing to return. */
2122 /* Set up context appropriately for handling this statement. */
2123 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p
;
2126 switch (TREE_CODE (t
))
2129 finish_return_stmt (RETURN_EXPR (t
));
2133 finish_expr_stmt_real (EXPR_STMT_EXPR (t
),
2134 EXPR_STMT_ASSIGNS_THIS (t
));
2140 int i
= suspend_momentary ();
2142 emit_line_note (input_filename
, lineno
);
2143 decl
= DECL_STMT_DECL (t
);
2144 if (TREE_CODE (decl
) == LABEL_DECL
)
2145 finish_label_decl (DECL_NAME (decl
));
2148 /* If we marked this variable as dead when we processed it
2149 before, we must undo that now. The variable has been
2151 if (TREE_CODE (decl
) == VAR_DECL
)
2152 DECL_DEAD_FOR_LOCAL (decl
) = 0;
2153 /* We need to clear DECL_CONTEXT so that maybe_push_decl
2154 will push it into the current scope. */
2155 if (DECL_CONTEXT (decl
) == current_function_decl
)
2157 DECL_CONTEXT (decl
) = NULL_TREE
;
2158 maybe_push_decl (decl
);
2160 /* If this is a declaration for an automatic local
2161 variable, initialize it. Note that we might also see a
2162 declaration for a namespace-scope object (declared with
2163 `extern') or an object with static storage duration
2164 (declared with `static'). We don't have to handle the
2165 initialization of those objects here; the former can
2166 never be a definition (only a declaration), and the
2167 latter is handled in finish_file. */
2168 if (TREE_CODE (decl
) == VAR_DECL
2169 && !TREE_STATIC (decl
)
2170 && !DECL_EXTERNAL (decl
))
2172 /* Support the old for-scope rules for backwards
2174 maybe_inject_for_scope_var (decl
);
2175 /* Let the back-end know about this variable. */
2176 emit_local_var (decl
);
2179 resume_momentary (i
);
2184 finish_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2192 expand_stmt (FOR_INIT_STMT (t
));
2193 finish_for_init_stmt (NULL_TREE
);
2194 finish_for_cond (expand_cond (FOR_COND (t
)), NULL_TREE
);
2196 finish_for_expr (tmp
, NULL_TREE
);
2197 expand_stmt (FOR_BODY (t
));
2198 finish_for_stmt (tmp
, NULL_TREE
);
2204 begin_while_stmt ();
2205 finish_while_stmt_cond (expand_cond (WHILE_COND (t
)), NULL_TREE
);
2206 expand_stmt (WHILE_BODY (t
));
2207 finish_while_stmt (NULL_TREE
);
2214 expand_stmt (DO_BODY (t
));
2215 finish_do_body (NULL_TREE
);
2216 finish_do_stmt (DO_COND (t
), NULL_TREE
);
2222 finish_if_stmt_cond (expand_cond (IF_COND (t
)), NULL_TREE
);
2223 if (THEN_CLAUSE (t
))
2225 expand_stmt (THEN_CLAUSE (t
));
2226 finish_then_clause (NULL_TREE
);
2228 if (ELSE_CLAUSE (t
))
2230 begin_else_clause ();
2231 expand_stmt (ELSE_CLAUSE (t
));
2232 finish_else_clause (NULL_TREE
);
2238 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
));
2239 expand_stmt (COMPOUND_BODY (t
));
2240 rval
= finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
),
2245 finish_break_stmt ();
2249 finish_continue_stmt ();
2256 begin_switch_stmt ();
2257 cond
= expand_cond (SWITCH_COND (t
));
2258 finish_switch_cond (cond
, NULL_TREE
);
2259 expand_stmt (SWITCH_BODY (t
));
2260 finish_switch_stmt (cond
, NULL_TREE
);
2265 finish_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2269 finish_label_stmt (DECL_NAME (LABEL_STMT_LABEL (t
)));
2273 if (TREE_CODE (GOTO_DESTINATION (t
)) == LABEL_DECL
)
2274 finish_goto_stmt (DECL_NAME (GOTO_DESTINATION (t
)));
2276 finish_goto_stmt (GOTO_DESTINATION (t
));
2280 finish_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
), ASM_OUTPUTS
2281 (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2287 expand_eh_region_start ();
2288 expand_stmt (TRY_STMTS (t
));
2289 finish_cleanup_try_block (NULL_TREE
);
2290 finish_cleanup (TRY_HANDLERS (t
), NULL_TREE
);
2295 expand_stmt (TRY_STMTS (t
));
2296 finish_try_block (NULL_TREE
);
2297 expand_stmt (TRY_HANDLERS (t
));
2298 finish_handler_sequence (NULL_TREE
);
2304 if (HANDLER_PARMS (t
))
2305 expand_start_catch_block (DECL_STMT_DECL (HANDLER_PARMS (t
)));
2307 expand_start_catch_block (NULL_TREE
);
2308 finish_handler_parms (NULL_TREE
);
2309 expand_stmt (HANDLER_BODY (t
));
2310 finish_handler (NULL_TREE
);
2314 finish_subobject (SUBOBJECT_CLEANUP (t
));
2318 my_friendly_abort (19990810);
2322 /* Restore saved state. */
2323 stmts_are_full_exprs_p
= saved_stmts_are_full_exprs_p
;
2325 /* Go on to the next statement in this scope. */
2332 /* Generate RTL for FN. */
2339 char *saved_input_filename
;
2343 /* When the parser calls us after finishing the body of a template
2344 function, we don't really want to expand the body. When we're
2345 processing an in-class definition of an inline function,
2346 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2347 to look at the function itself. */
2348 if (processing_template_decl
2349 || (DECL_LANG_SPECIFIC (fn
)
2350 && DECL_TEMPLATE_INFO (fn
)
2351 && uses_template_parms (DECL_TI_ARGS (fn
))))
2354 /* Save the current file name and line number. When we expand the
2355 body of the funciton, we'll set LINENO and INPUT_FILENAME so that
2356 error-mesages come out in the right places. */
2357 saved_lineno
= lineno
;
2358 saved_input_filename
= input_filename
;
2359 lineno
= DECL_SOURCE_LINE (fn
);
2360 input_filename
= DECL_SOURCE_FILE (fn
);
2362 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2363 store_parm_decls ();
2365 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2366 any of the other magic variables we set up when starting a
2368 current_function_name_declared
= 1;
2370 /* There are a few things that we do not handle recursively. For
2371 example, a function try-block is handled differently from an
2372 ordinary try-block, so we must handle it here. */
2373 t
= DECL_SAVED_TREE (fn
);
2374 try_block
= NULL_TREE
;
2375 if (t
&& TREE_CODE (t
) == TRY_BLOCK
)
2378 begin_function_try_block ();
2379 t
= TRY_STMTS (try_block
);
2382 if (t
&& TREE_CODE (t
) == RETURN_INIT
)
2384 /* Clear this out so that finish_named_return_value can set it
2386 DECL_NAME (DECL_RESULT (fn
)) = NULL_TREE
;
2387 finish_named_return_value (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
2391 if (t
&& TREE_CODE (t
) == CTOR_INITIALIZER
)
2393 current_member_init_list
= TREE_OPERAND (t
, 0);
2394 current_base_init_list
= TREE_OPERAND (t
, 1);
2398 /* If this is a constructor, we need to initialize our members and
2402 /* Expand the body. */
2405 /* If there was a function try-block, expand the handlers. */
2408 finish_function_try_block (NULL_TREE
);
2409 expand_stmt (TRY_HANDLERS (try_block
));
2410 finish_function_handler_sequence (NULL_TREE
);
2413 /* Statements should always be full-expressions at the outermost set
2414 of curly braces for a function. */
2415 my_friendly_assert (stmts_are_full_exprs_p
, 19990831);
2417 /* The outermost statement for a function contains the line number
2418 recorded when we finished processing the function. */
2419 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2421 /* Generate code for the function. */
2422 finish_function (lineno
, 0);
2424 /* And restore the current source position. */
2425 lineno
= saved_lineno
;
2426 input_filename
= saved_input_filename
;