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));
49 /* When parsing a template, LAST_TREE contains the last statement
50 parsed. These are chained together through the TREE_CHAIN field,
51 but often need to be re-organized since the parse is performed
52 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
55 #define RECHAIN_STMTS(stmt, substmt) \
57 substmt = TREE_CHAIN (stmt); \
58 TREE_CHAIN (stmt) = NULL_TREE; \
62 /* Finish processing the COND, the SUBSTMT condition for STMT. */
64 #define FINISH_COND(cond, stmt, substmt) \
66 if (last_tree != stmt) \
67 RECHAIN_STMTS (stmt, substmt); \
72 /* T is a statement. Add it to the statement-tree. */
78 /* Add T to the statement-tree. */
79 last_tree = TREE_CHAIN (last_tree) = t;
81 /* When we expand a statement-tree, we must know whether or not the
82 statements are full-expresions. We record that fact here. */
83 if (building_stmt_tree ())
84 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p;
87 /* Finish an expression-statement, whose EXPRESSION is as indicated.
88 If ASSIGNED_THIS is non-zero, then this statement just assigned to
89 the `this' pointer. */
92 finish_expr_stmt_real (expr, assigned_this)
96 if (expr != NULL_TREE)
98 if (building_stmt_tree ())
99 add_tree (build_min_nt (EXPR_STMT, expr));
102 emit_line_note (input_filename, lineno);
103 /* Do default conversion if safe and possibly important,
104 in case within ({...}). */
105 if (!stmts_are_full_exprs_p &&
106 ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
108 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
109 expr = default_conversion (expr);
111 if (stmts_are_full_exprs_p)
112 expand_start_target_temps ();
114 cplus_expand_expr_stmt (expr);
116 if (stmts_are_full_exprs_p)
118 expand_end_target_temps ();
124 /* If this statement assigned to the `this' pointer, record that
125 fact for finish_stmt. */
127 current_function_just_assigned_this = 1;
131 /* This was an expression-statement, so we save the type of the
133 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
136 /* Like finish_expr_stmt_real, but ASSIGNS_THIS is always zero. */
139 finish_expr_stmt (expr)
142 finish_expr_stmt_real (expr, /*assigns_this=*/0);
145 /* Begin an if-statement. Returns a newly created IF_STMT if
153 if (building_stmt_tree ())
155 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
166 /* Process the COND of an if-statement, which may be given by
170 finish_if_stmt_cond (cond, if_stmt)
174 if (building_stmt_tree ())
175 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
178 emit_line_note (input_filename, lineno);
179 expand_start_cond (condition_conversion (cond), 0);
183 /* Finish the then-clause of an if-statement, which may be given by
187 finish_then_clause (if_stmt)
190 if (building_stmt_tree ())
192 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
200 /* Begin the else-clause of an if-statement. */
205 if (!building_stmt_tree ())
206 expand_start_else ();
209 /* Finish the else-clause of an if-statement, which may be given by
213 finish_else_clause (if_stmt)
216 if (building_stmt_tree ())
217 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
220 /* Finsh an if-statement. */
225 if (!building_stmt_tree ())
232 /* Begin a while-statement. Returns a newly created WHILE_STMT if
240 if (building_stmt_tree ())
242 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
248 emit_line_note (input_filename, lineno);
249 expand_start_loop (1);
258 /* Process the COND of an if-statement, which may be given by
262 finish_while_stmt_cond (cond, while_stmt)
266 if (building_stmt_tree ())
267 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
270 emit_line_note (input_filename, lineno);
271 expand_exit_loop_if_false (0, condition_conversion (cond));
274 /* If COND wasn't a declaration, clear out the
275 block we made for it and start a new one here so the
276 optimization in expand_end_loop will work. */
277 if (getdecls () == NULL_TREE)
284 /* Finish a while-statement, which may be given by WHILE_STMT. */
287 finish_while_stmt (while_stmt)
292 if (building_stmt_tree ())
293 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
299 /* Begin a do-statement. Returns a newly created DO_STMT if
305 if (building_stmt_tree ())
307 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
314 emit_line_note (input_filename, lineno);
315 expand_start_loop_continue_elsewhere (1);
320 /* Finish the body of a do-statement, which may be given by DO_STMT. */
323 finish_do_body (do_stmt)
326 if (building_stmt_tree ())
327 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
329 expand_loop_continue_here ();
332 /* Finish a do-statement, which may be given by DO_STMT, and whose
333 COND is as indicated. */
336 finish_do_stmt (cond, do_stmt)
340 if (building_stmt_tree ())
341 DO_COND (do_stmt) = cond;
344 emit_line_note (input_filename, lineno);
345 expand_exit_loop_if_false (0, condition_conversion (cond));
353 /* Finish a return-statement. The EXPRESSION returned, if any, is as
357 finish_return_stmt (expr)
360 if (building_stmt_tree ())
361 add_tree (build_min_nt (RETURN_STMT, expr));
364 emit_line_note (input_filename, lineno);
365 c_expand_return (expr);
371 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
378 if (building_stmt_tree ())
380 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
381 NULL_TREE, NULL_TREE);
387 if (flag_new_for_scope > 0)
390 note_level_for_for ();
396 /* Finish the for-init-statement of a for-statement, which may be
397 given by FOR_STMT. */
400 finish_for_init_stmt (for_stmt)
403 if (building_stmt_tree ())
405 if (last_tree != for_stmt)
406 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
411 emit_line_note (input_filename, lineno);
412 expand_start_loop_continue_elsewhere (1);
418 /* Finish the COND of a for-statement, which may be given by
422 finish_for_cond (cond, for_stmt)
426 if (building_stmt_tree ())
427 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
430 emit_line_note (input_filename, lineno);
432 expand_exit_loop_if_false (0, condition_conversion (cond));
435 /* If the cond wasn't a declaration, clear out the
436 block we made for it and start a new one here so the
437 optimization in expand_end_loop will work. */
438 if (getdecls () == NULL_TREE)
445 /* Finish the increment-EXPRESSION in a for-statement, which may be
446 given by FOR_STMT. */
449 finish_for_expr (expr, for_stmt)
453 if (building_stmt_tree ())
454 FOR_EXPR (for_stmt) = expr;
456 /* Don't let the tree nodes for EXPR be discarded
457 by clear_momentary during the parsing of the next stmt. */
461 /* Finish the body of a for-statement, which may be given by
462 FOR_STMT. The increment-EXPR for the loop must be
466 finish_for_stmt (expr, for_stmt)
470 /* Pop the scope for the body of the loop. */
473 if (building_stmt_tree ())
474 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
477 emit_line_note (input_filename, lineno);
478 expand_loop_continue_here ();
480 finish_expr_stmt (expr);
486 if (flag_new_for_scope > 0)
492 /* Finish a break-statement. */
497 emit_line_note (input_filename, lineno);
498 if (building_stmt_tree ())
499 add_tree (build_min_nt (BREAK_STMT));
500 else if ( ! expand_exit_something ())
501 cp_error ("break statement not within loop or switch");
504 /* Finish a continue-statement. */
507 finish_continue_stmt ()
509 emit_line_note (input_filename, lineno);
510 if (building_stmt_tree ())
511 add_tree (build_min_nt (CONTINUE_STMT));
512 else if (! expand_continue_loop (0))
513 cp_error ("continue statement not within a loop");
516 /* Begin a switch-statement. Returns a new SWITCH_STMT if
524 if (building_stmt_tree ())
526 r = build_min_nt (SWITCH_STMT, NULL_TREE, NULL_TREE);
537 /* Finish the cond of a switch-statement. */
540 finish_switch_cond (cond, switch_stmt)
544 if (building_stmt_tree ())
545 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
546 else if (cond != error_mark_node)
548 emit_line_note (input_filename, lineno);
549 c_expand_start_case (cond);
552 /* The code is in error, but we don't want expand_end_case to
554 c_expand_start_case (boolean_false_node);
558 /* Don't let the tree nodes for COND be discarded by
559 clear_momentary during the parsing of the next stmt. */
563 /* Finish the body of a switch-statement, which may be given by
564 SWITCH_STMT. The COND to switch on is indicated. */
567 finish_switch_stmt (cond, switch_stmt)
571 if (building_stmt_tree ())
572 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
574 expand_end_case (cond);
581 /* Finish a case-label. */
584 finish_case_label (low_value, high_value)
588 if (building_stmt_tree ())
590 add_tree (build_min_nt (CASE_LABEL, low_value, high_value));
594 do_case (low_value, high_value);
597 /* Finish a goto-statement. */
600 finish_goto_stmt (destination)
603 if (TREE_CODE (destination) == IDENTIFIER_NODE)
604 destination = lookup_label (destination);
606 if (building_stmt_tree ())
607 add_tree (build_min_nt (GOTO_STMT, destination));
610 emit_line_note (input_filename, lineno);
612 if (TREE_CODE (destination) == LABEL_DECL)
614 TREE_USED (destination) = 1;
615 expand_goto (destination);
618 expand_computed_goto (destination);
622 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
628 if (building_stmt_tree ())
630 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
637 emit_line_note (input_filename, lineno);
638 expand_start_try_stmts ();
643 /* Likewise, for a function-try-block. */
646 begin_function_try_block ()
648 if (building_stmt_tree ())
650 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
652 FN_TRY_BLOCK_P (r) = 1;
658 if (! current_function_parms_stored)
660 expand_start_early_try_stmts ();
665 /* Finish a try-block, which may be given by TRY_BLOCK. */
668 finish_try_block (try_block)
671 if (building_stmt_tree ())
672 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
674 expand_start_all_catch ();
678 finish_cleanup_try_block (try_block)
681 if (building_stmt_tree ())
682 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
685 /* Finish an implicitly generated try-block, with a cleanup is given
689 finish_cleanup (cleanup, try_block)
693 if (building_stmt_tree ())
695 TRY_HANDLERS (try_block) = cleanup;
696 CLEANUP_P (try_block) = 1;
699 expand_eh_region_end (protect_with_terminate (cleanup));
702 /* Likewise, for a function-try-block. */
705 finish_function_try_block (try_block)
708 if (building_stmt_tree ())
710 if (TREE_CHAIN (try_block)
711 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
713 /* Chain the compound statement after the CTOR_INITIALIZER. */
714 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
715 /* And make the CTOR_INITIALIZER the body of the try-block. */
716 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
719 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
723 end_protect_partials ();
724 expand_start_all_catch ();
725 in_function_try_handler = 1;
729 /* Finish a handler-sequence for a try-block, which may be given by
733 finish_handler_sequence (try_block)
736 if (building_stmt_tree ())
737 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
739 expand_end_all_catch ();
742 /* Likewise, for a function-try-block. */
745 finish_function_handler_sequence (try_block)
748 if (building_stmt_tree ())
749 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
752 in_function_try_handler = 0;
753 expand_end_all_catch ();
757 /* Begin a handler. Returns a HANDLER if appropriate. */
764 if (building_stmt_tree ())
766 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
777 /* Finish the handler-parameters for a handler, which may be given by
781 finish_handler_parms (handler)
784 if (building_stmt_tree ())
785 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
788 /* Finish a handler, which may be given by HANDLER. */
791 finish_handler (handler)
794 if (building_stmt_tree ())
795 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
797 expand_end_catch_block ();
802 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
803 compound-statement does not define a scope. Returns a new
804 COMPOUND_STMT if appropriate. */
807 begin_compound_stmt (has_no_scope)
812 if (building_stmt_tree ())
814 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
817 COMPOUND_STMT_NO_SCOPE (r) = 1;
822 last_expr_type = NULL_TREE;
827 /* Normally, we try hard to keep the BLOCK for a
828 statement-expression. But, if it's a statement-expression with
829 a scopeless block, there's nothing to keep, and we don't want
830 to accidentally keep a block *inside* the scopeless block. */
837 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
838 If HAS_NO_SCOPE is non-zero, the compound statement does not define
842 finish_compound_stmt (has_no_scope, compound_stmt)
854 if (building_stmt_tree ())
855 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
857 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
858 the precise purpose of that variable is store the type of the
859 last expression statement within the last compound statement, we
860 preserve the value. */
868 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
869 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
873 finish_asm_stmt (cv_qualifier, string, output_operands,
874 input_operands, clobbers)
877 tree output_operands;
881 if (TREE_CHAIN (string))
883 if (building_stmt_tree ())
884 /* We need to build the combined string on the permanent
885 obstack so that we can use it during instantiations. */
886 push_permanent_obstack ();
888 string = combine_strings (string);
890 if (building_stmt_tree ())
894 if (cv_qualifier != NULL_TREE
895 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
897 cp_warning ("%s qualifier ignored on asm",
898 IDENTIFIER_POINTER (cv_qualifier));
899 cv_qualifier = NULL_TREE;
902 if (building_stmt_tree ())
904 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
905 output_operands, input_operands,
911 emit_line_note (input_filename, lineno);
912 if (output_operands != NULL_TREE || input_operands != NULL_TREE
913 || clobbers != NULL_TREE)
917 for (t = input_operands; t; t = TREE_CHAIN (t))
918 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
920 c_expand_asm_operands (string, output_operands,
923 cv_qualifier != NULL_TREE,
924 input_filename, lineno);
933 /* Finish a label with the indicated NAME. */
936 finish_label_stmt (name)
939 tree decl = define_label (input_filename, lineno, name);
941 if (building_stmt_tree ())
942 add_tree (build_min_nt (LABEL_STMT, decl));
947 /* Finish a series of declarations for local labels. G++ allows users
948 to declare "local" labels, i.e., labels with scope. This extension
949 is useful when writing code involving statement-expressions. */
952 finish_label_decl (name)
955 tree decl = declare_local_label (name);
956 if (building_stmt_tree ())
957 add_decl_stmt (decl);
960 /* Create a declaration statement for the declaration given by the
969 /* We need the type to last until instantiation time. */
970 decl_stmt = build_min_nt (DECL_STMT, decl);
971 add_tree (decl_stmt);
974 /* We're in a constructor, and have just constructed a a subobject of
975 *THIS. CLEANUP is code to run if an exception is thrown before the
976 end of the current function is reached. */
979 finish_subobject (cleanup)
982 if (building_stmt_tree ())
984 tree r = build_min_nt (SUBOBJECT, cleanup);
988 add_partial_entry (cleanup);
991 /* Bind a name and initialization to the return value of
992 the current function. */
995 finish_named_return_value (return_id, init)
996 tree return_id, init;
998 tree decl = DECL_RESULT (current_function_decl);
1001 /* Give this error as many times as there are occurrences,
1002 so that users can use Emacs compilation buffers to find
1003 and fix all such places. */
1004 pedwarn ("ANSI C++ does not permit named return values");
1006 if (return_id != NULL_TREE)
1008 if (DECL_NAME (decl) == NULL_TREE)
1010 DECL_NAME (decl) = return_id;
1011 DECL_ASSEMBLER_NAME (decl) = return_id;
1015 cp_error ("return identifier `%D' already in place", return_id);
1020 /* Can't let this happen for constructors. */
1021 if (DECL_CONSTRUCTOR_P (current_function_decl))
1023 error ("can't redefine default return value for constructors");
1027 /* If we have a named return value, put that in our scope as well. */
1028 if (DECL_NAME (decl) != NULL_TREE)
1030 /* Let `cp_finish_decl' know that this initializer is ok. */
1031 DECL_INITIAL (decl) = init;
1034 if (building_stmt_tree ())
1035 add_tree (build_min_nt (RETURN_INIT, return_id, init));
1038 cp_finish_decl (decl, init, NULL_TREE, 0, 0);
1039 store_return_init (decl);
1044 /* Cache the value of this class's main virtual function table pointer
1045 in a register variable. This will save one indirection if a
1046 more than one virtual function call is made this function. */
1051 if (base_init_expr == 0
1052 && DECL_CONSTRUCTOR_P (current_function_decl))
1054 if (building_stmt_tree ())
1055 add_tree (build_min_nt
1057 current_member_init_list, current_base_init_list));
1059 emit_base_init (current_class_type);
1062 /* Always keep the BLOCK node associated with the outermost pair of
1063 curley braces of a function. These are needed for correct
1064 operation of dwarfout.c. */
1065 keep_next_level (1);
1068 /* Begin a new scope. */
1073 if (!building_stmt_tree ())
1075 emit_line_note (input_filename, lineno);
1079 if (stmts_are_full_exprs_p)
1081 if (!building_stmt_tree () && stmts_are_full_exprs_p)
1082 expand_start_bindings (0);
1085 /* Finish a scope. */
1092 if (!building_stmt_tree () && stmts_are_full_exprs_p)
1093 expand_end_bindings (getdecls (), kept_level_p (), 0);
1094 if (stmts_are_full_exprs_p)
1095 t = poplevel (kept_level_p (), 1, 0);
1102 /* Finish a parenthesized expression EXPR. */
1105 finish_parenthesized_expr (expr)
1108 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1109 /* This inhibits warnings in truthvalue_conversion. */
1110 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1115 /* Begin a statement-expression. The value returned must be passed to
1116 finish_stmt_expr. */
1121 keep_next_level (1);
1122 /* If we're building a statement tree, then the upcoming compound
1123 statement will be chained onto the tree structure, starting at
1124 last_tree. We return last_tree so that we can later unhook the
1125 compound statement. */
1126 return building_stmt_tree () ? last_tree : expand_start_stmt_expr();
1129 /* Finish a statement-expression. RTL_EXPR should be the value
1130 returned by the previous begin_stmt_expr; EXPR is the
1131 statement-expression. Returns an expression representing the
1132 statement-expression. */
1135 finish_stmt_expr (rtl_expr, expr)
1141 if (!building_stmt_tree ())
1143 rtl_expr = expand_end_stmt_expr (rtl_expr);
1144 /* The statements have side effects, so the group does. */
1145 TREE_SIDE_EFFECTS (rtl_expr) = 1;
1148 if (building_stmt_tree ())
1150 /* If the last thing in the statement-expression was not an
1151 expression-statement, then it has type `void'. */
1152 if (!last_expr_type)
1153 last_expr_type = void_type_node;
1154 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1155 TREE_SIDE_EFFECTS (result) = 1;
1157 /* Remove the compound statement from the tree structure; it is
1158 now saved in the STMT_EXPR. */
1159 last_tree = rtl_expr;
1160 TREE_CHAIN (last_tree) = NULL_TREE;
1162 else if (expr && TREE_CODE (expr) == BLOCK)
1164 result = build (BIND_EXPR, TREE_TYPE (rtl_expr),
1165 NULL_TREE, rtl_expr, expr);
1166 delete_block (expr);
1171 if (expr && TREE_CODE (expr) == BLOCK)
1172 /* Remove the block from the tree at this point. It gets put back
1173 at the proper place when the STMT_EXPR or BIND_EXPR is
1175 delete_block (expr);
1180 /* Finish a call to FN with ARGS. Returns a representation of the
1184 finish_call_expr (fn, args, koenig)
1193 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1194 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1195 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
1196 fn = do_identifier (fn, 2, args);
1198 result = build_x_function_call (fn, args, current_class_ref);
1200 if (TREE_CODE (result) == CALL_EXPR
1201 && (! TREE_TYPE (result)
1202 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
1203 result = require_complete_type (result);
1208 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1209 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1210 POSTDECREMENT_EXPR.) */
1213 finish_increment_expr (expr, code)
1215 enum tree_code code;
1217 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1218 a COMPONENT_REF). This way if we've got, say, a reference to a
1219 static member that's being operated on, we don't end up trying to
1220 find a member operator for the class it's in. */
1222 if (TREE_CODE (expr) == OFFSET_REF)
1223 expr = resolve_offset_ref (expr);
1224 return build_x_unary_op (code, expr);
1227 /* Finish a use of `this'. Returns an expression for `this'. */
1234 if (current_class_ptr)
1236 #ifdef WARNING_ABOUT_CCD
1237 TREE_USED (current_class_ptr) = 1;
1239 result = current_class_ptr;
1241 else if (current_function_decl
1242 && DECL_STATIC_FUNCTION_P (current_function_decl))
1244 error ("`this' is unavailable for static member functions");
1245 result = error_mark_node;
1249 if (current_function_decl)
1250 error ("invalid use of `this' in non-member function");
1252 error ("invalid use of `this' at top level");
1253 result = error_mark_node;
1259 /* Finish a member function call using OBJECT and ARGS as arguments to
1260 FN. Returns an expression for the call. */
1263 finish_object_call_expr (fn, object, args)
1269 /* This is a future direction of this code, but because
1270 build_x_function_call cannot always undo what is done in
1271 build_component_ref entirely yet, we cannot do this. */
1273 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1274 return finish_call_expr (real_fn, args);
1276 if (TREE_CODE (fn) == TYPE_DECL)
1278 if (processing_template_decl)
1279 /* This can happen on code like:
1282 template <class T> void f(T t) {
1286 We just grab the underlying IDENTIFIER. */
1287 fn = DECL_NAME (fn);
1290 cp_error ("calling type `%T' like a method", fn);
1291 return error_mark_node;
1295 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1299 /* Finish a qualified member function call using OBJECT and ARGS as
1300 arguments to FN. Returns an expressino for the call. */
1303 finish_qualified_object_call_expr (fn, object, args)
1308 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1309 TREE_OPERAND (fn, 1), args);
1312 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1313 being the scope, if any, of DESTRUCTOR. Returns an expression for
1317 finish_pseudo_destructor_call_expr (object, scope, destructor)
1322 if (processing_template_decl)
1323 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1325 if (scope && scope != destructor)
1326 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1329 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1330 && (TREE_CODE (TREE_TYPE (object)) !=
1331 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1332 cp_error ("`%E' is not of type `%T'", object, destructor);
1334 return cp_convert (void_type_node, object);
1337 /* Finish a call to a globally qualified member function FN using
1338 ARGS. Returns an expression for the call. */
1341 finish_qualified_call_expr (fn, args)
1345 if (processing_template_decl)
1346 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
1348 return build_member_call (TREE_OPERAND (fn, 0),
1349 TREE_OPERAND (fn, 1),
1353 /* Finish an expression taking the address of LABEL. Returns an
1354 expression for the address. */
1357 finish_label_address_expr (label)
1362 label = lookup_label (label);
1363 if (label == NULL_TREE)
1364 result = null_pointer_node;
1367 TREE_USED (label) = 1;
1368 result = build1 (ADDR_EXPR, ptr_type_node, label);
1369 TREE_CONSTANT (result) = 1;
1375 /* Finish an expression of the form CODE EXPR. */
1378 finish_unary_op_expr (code, expr)
1379 enum tree_code code;
1382 tree result = build_x_unary_op (code, expr);
1383 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST)
1384 TREE_NEGATED_INT (result) = 1;
1385 overflow_warning (result);
1389 /* Finish an id-expression. */
1392 finish_id_expr (expr)
1395 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1396 expr = do_identifier (expr, 1, NULL_TREE);
1401 /* Begin a new-placement. */
1404 begin_new_placement ()
1406 /* The arguments to a placement new might be passed to a
1407 deallocation function, in the event that the allocation throws an
1408 exception. Since we don't expand exception handlers until the
1409 end of a function, we must make sure the arguments stay around
1411 return suspend_momentary ();
1414 /* Finish a new-placement. The ARGS are the placement arguments. The
1415 COOKIE is the value returned by the previous call to
1416 begin_new_placement. */
1419 finish_new_placement (args, cookie)
1423 resume_momentary (cookie);
1427 /* Begin a function defniition declared with DECL_SPECS and
1428 DECLARATOR. Returns non-zero if the function-declaration is
1432 begin_function_definition (decl_specs, declarator)
1438 split_specs_attrs (decl_specs, &specs, &attrs);
1439 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
1442 reinit_parse_for_function ();
1443 /* The things we're about to see are not directly qualified by any
1444 template headers we've seen thus far. */
1445 reset_specialization ();
1450 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1454 begin_constructor_declarator (scope, name)
1458 tree result = build_parse_node (SCOPE_REF, scope, name);
1459 enter_scope_of (result);
1463 /* Finish an init-declarator. Returns a DECL. */
1466 finish_declarator (declarator, declspecs, attributes,
1467 prefix_attributes, initialized)
1471 tree prefix_attributes;
1474 return start_decl (declarator, declspecs, initialized, attributes,
1478 /* Finish a translation unit. */
1481 finish_translation_unit ()
1483 /* In case there were missing closebraces,
1484 get us back to the global binding level. */
1485 while (! toplevel_bindings_p ())
1487 while (current_namespace != global_namespace)
1492 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1493 Returns the parameter. */
1496 finish_template_type_parm (aggr, identifier)
1500 if (aggr != class_type_node)
1502 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1503 aggr = class_type_node;
1506 return build_tree_list (aggr, identifier);
1509 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1510 Returns the parameter. */
1513 finish_template_template_parm (aggr, identifier)
1517 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1518 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1519 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1520 DECL_TEMPLATE_RESULT (tmpl) = decl;
1521 SET_DECL_ARTIFICIAL (decl);
1522 end_template_decl ();
1524 return finish_template_type_parm (aggr, tmpl);
1527 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1528 non-zero, the parameter list was terminated by a `...'. */
1531 finish_parmlist (parms, ellipsis)
1536 chainon (parms, void_list_node);
1537 /* We mark the PARMS as a parmlist so that declarator processing can
1538 disambiguate certain constructs. */
1539 if (parms != NULL_TREE)
1540 TREE_PARMLIST (parms) = 1;
1545 /* Begin a class definition, as indicated by T. */
1548 begin_class_definition (t)
1551 push_permanent_obstack ();
1553 if (t == error_mark_node
1554 || ! IS_AGGR_TYPE (t))
1556 t = make_lang_type (RECORD_TYPE);
1557 pushtag (make_anon_name (), t, 0);
1560 /* In a definition of a member class template, we will get here with an
1561 implicit typename, a TYPENAME_TYPE with a type. */
1562 if (TREE_CODE (t) == TYPENAME_TYPE)
1565 /* If we generated a partial instantiation of this type, but now
1566 we're seeing a real definition, we're actually looking at a
1567 partial specialization. Consider:
1569 template <class T, class U>
1575 template <class T, class U>
1578 typename X<Y<T, U> >::A a;
1581 template <class T, class U>
1586 We have to undo the effects of the previous partial
1588 if (PARTIAL_INSTANTIATION_P (t))
1592 /* Unfortunately, when we're not in pedantic mode, we
1593 attempt to actually fill in some of the fields of the
1594 partial instantiation, in order to support the implicit
1595 typename extension. Clear those fields now, in
1596 preparation for the definition here. The fields cleared
1597 here must match those set in instantiate_class_template.
1598 Look for a comment mentioning begin_class_definition
1600 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1601 TYPE_FIELDS (t) = NULL_TREE;
1602 TYPE_METHODS (t) = NULL_TREE;
1603 CLASSTYPE_TAGS (t) = NULL_TREE;
1604 TYPE_SIZE (t) = NULL_TREE;
1607 /* This isn't a partial instantiation any more. */
1608 PARTIAL_INSTANTIATION_P (t) = 0;
1610 /* If this type was already complete, and we see another definition,
1612 else if (TYPE_SIZE (t))
1613 duplicate_tag_error (t);
1615 /* Update the location of the decl. */
1616 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1617 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1619 if (TYPE_BEING_DEFINED (t))
1621 t = make_lang_type (TREE_CODE (t));
1622 pushtag (TYPE_IDENTIFIER (t), t, 0);
1624 maybe_process_partial_specialization (t);
1626 TYPE_BEING_DEFINED (t) = 1;
1627 /* Reset the interface data, at the earliest possible
1628 moment, as it might have been set via a class foo;
1631 tree name = TYPE_IDENTIFIER (t);
1633 if (! ANON_AGGRNAME_P (name))
1635 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1636 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1637 (t, interface_unknown);
1640 /* Only leave this bit clear if we know this
1641 class is part of an interface-only specification. */
1642 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1643 || ! CLASSTYPE_INTERFACE_ONLY (t))
1644 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1647 tmp = TYPE_IDENTIFIER ($<ttype>0);
1648 if (tmp && IDENTIFIER_TEMPLATE (tmp))
1649 overload_template_name (tmp, 1);
1651 reset_specialization();
1653 /* In case this is a local class within a template
1654 function, we save the current tree structure so
1655 that we can get it back later. */
1658 /* Make a declaration for this class in its own scope. */
1659 build_self_reference ();
1664 /* Finish the member declaration given by DECL. */
1667 finish_member_declaration (decl)
1670 if (decl == error_mark_node || decl == NULL_TREE)
1673 if (decl == void_type_node)
1674 /* The COMPONENT was a friend, not a member, and so there's
1675 nothing for us to do. */
1678 /* We should see only one DECL at a time. */
1679 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1681 /* Set up access control for DECL. */
1683 = (current_access_specifier == access_private_node);
1684 TREE_PROTECTED (decl)
1685 = (current_access_specifier == access_protected_node);
1686 if (TREE_CODE (decl) == TEMPLATE_DECL)
1688 TREE_PRIVATE (DECL_RESULT (decl)) = TREE_PRIVATE (decl);
1689 TREE_PROTECTED (DECL_RESULT (decl)) = TREE_PROTECTED (decl);
1692 /* Mark the DECL as a member of the current class. */
1693 if (TREE_CODE (decl) == FUNCTION_DECL
1694 || DECL_FUNCTION_TEMPLATE_P (decl))
1695 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1696 finish_struct. Presumably it is already set as the function is
1697 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1698 DECL_CLASS_CONTEXT (decl) = current_class_type;
1700 DECL_CONTEXT (decl) = current_class_type;
1702 /* Put functions on the TYPE_METHODS list and everything else on the
1703 TYPE_FIELDS list. Note that these are built up in reverse order.
1704 We reverse them (to obtain declaration order) in finish_struct. */
1705 if (TREE_CODE (decl) == FUNCTION_DECL
1706 || DECL_FUNCTION_TEMPLATE_P (decl))
1708 /* We also need to add this function to the
1709 CLASSTYPE_METHOD_VEC. */
1710 add_method (current_class_type, 0, decl);
1712 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1713 TYPE_METHODS (current_class_type) = decl;
1717 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1718 go at the beginning. The reason is that lookup_field_1
1719 searches the list in order, and we want a field name to
1720 override a type name so that the "struct stat hack" will
1721 work. In particular:
1723 struct S { enum E { }; int E } s;
1726 is legal. In addition, the FIELD_DECLs must be maintained in
1727 declaration order so that class layout works as expected.
1728 However, we don't need that order until class layout, so we
1729 save a little time by putting FIELD_DECLs on in reverse order
1730 here, and then reversing them in finish_struct_1. (We could
1731 also keep a pointer to the correct insertion points in the
1734 if (TREE_CODE (decl) == TYPE_DECL)
1735 TYPE_FIELDS (current_class_type)
1736 = chainon (TYPE_FIELDS (current_class_type), decl);
1739 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1740 TYPE_FIELDS (current_class_type) = decl;
1743 /* Enter the DECL into the scope of the class. */
1744 if (TREE_CODE (decl) != USING_DECL)
1745 pushdecl_class_level (decl);
1749 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1750 the definition is immediately followed by a semicolon. Returns the
1754 finish_class_definition (t, attributes, semi, pop_scope_p)
1760 /* finish_struct nukes this anyway; if finish_exception does too,
1763 note_got_semicolon (t);
1765 /* If we got any attributes in class_head, xref_tag will stick them in
1766 TREE_TYPE of the type. Grab them now. */
1767 attributes = chainon (TREE_TYPE (t), attributes);
1768 TREE_TYPE (t) = NULL_TREE;
1770 if (TREE_CODE (t) == ENUMERAL_TYPE)
1774 t = finish_struct (t, attributes);
1776 note_got_semicolon (t);
1782 check_for_missing_semicolon (t);
1784 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
1785 if (current_scope () == current_function_decl)
1786 do_pending_defargs ();
1791 /* Finish processing the default argument expressions cached during
1792 the processing of a class definition. */
1795 begin_inline_definitions ()
1798 && current_scope () == current_function_decl)
1799 do_pending_inlines ();
1802 /* Finish processing the inline function definitions cached during the
1803 processing of a class definition. */
1806 finish_inline_definitions ()
1808 if (current_class_type == NULL_TREE)
1809 clear_inline_text_obstack ();
1811 /* Undo the begin_tree in begin_class_definition. */
1815 /* Finish processing the declaration of a member class template
1816 TYPES whose template parameters are given by PARMS. */
1819 finish_member_class_template (types)
1824 /* If there are declared, but undefined, partial specializations
1825 mixed in with the typespecs they will not yet have passed through
1826 maybe_process_partial_specialization, so we do that here. */
1827 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1828 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1829 maybe_process_partial_specialization (TREE_VALUE (t));
1831 note_list_got_semicolon (types);
1832 grok_x_components (types);
1833 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1834 /* The component was in fact a friend declaration. We avoid
1835 finish_member_template_decl performing certain checks by
1839 finish_member_template_decl (types);
1841 /* As with other component type declarations, we do
1842 not store the new DECL on the list of
1847 /* Finish processsing a complete template declaration. The PARMS are
1848 the template parameters. */
1851 finish_template_decl (parms)
1855 end_template_decl ();
1857 end_specialization ();
1860 /* Finish processing a a template-id (which names a type) of the form
1861 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1862 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1863 the scope of template-id indicated. */
1866 finish_template_type (name, args, entering_scope)
1873 decl = lookup_template_class (name, args,
1874 NULL_TREE, NULL_TREE, entering_scope);
1875 if (decl != error_mark_node)
1876 decl = TYPE_STUB_DECL (decl);
1881 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
1882 namespace scope or a class scope. */
1888 tree scope = TREE_OPERAND (sr, 0);
1890 if (TREE_CODE (scope) == NAMESPACE_DECL)
1892 push_decl_namespace (scope);
1893 TREE_COMPLEXITY (sr) = -1;
1895 else if (scope != current_class_type)
1897 if (TREE_CODE (scope) == TYPENAME_TYPE)
1899 /* In a declarator for a template class member, the scope will
1900 get here as an implicit typename, a TYPENAME_TYPE with a type. */
1901 scope = TREE_TYPE (scope);
1902 TREE_OPERAND (sr, 0) = scope;
1904 push_nested_class (scope, 3);
1905 TREE_COMPLEXITY (sr) = current_class_depth;
1909 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
1910 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
1911 BASE_CLASS, or NULL_TREE if an error occurred. The
1912 ACCESSS_SPECIFIER is one of
1913 access_{default,public,protected_private}[_virtual]_node.*/
1916 finish_base_specifier (access_specifier, base_class)
1917 tree access_specifier;
1923 if (base_class == NULL_TREE)
1925 error ("invalid base class");
1926 type = error_mark_node;
1929 type = TREE_TYPE (base_class);
1931 if (! is_aggr_type (type, 1))
1934 result = build_tree_list (access_specifier, type);
1939 /* Called when multiple declarators are processed. If that is not
1940 premitted in this context, an error is issued. */
1943 check_multiple_declarators ()
1947 In a template-declaration, explicit specialization, or explicit
1948 instantiation the init-declarator-list in the declaration shall
1949 contain at most one declarator.
1951 We don't just use PROCESSING_TEMPLATE_DECL for the first
1952 condition since that would disallow the perfectly legal code,
1953 like `template <class T> struct S { int i, j; };'. */
1954 tree scope = current_scope ();
1956 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
1957 /* It's OK to write `template <class T> void f() { int i, j;}'. */
1960 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
1961 || processing_explicit_instantiation
1962 || processing_specialization)
1963 cp_error ("multiple declarators in template declaration");
1967 finish_typeof (expr)
1970 if (processing_template_decl)
1974 push_permanent_obstack ();
1975 t = make_lang_type (TYPEOF_TYPE);
1976 TYPE_FIELDS (t) = expr;
1982 return TREE_TYPE (expr);
1985 /* Create an empty statement tree for FN. */
1988 begin_stmt_tree (fn)
1991 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
1992 what follows. We remove the extraneous statement in
1993 finish_stmt_tree. */
1994 DECL_SAVED_TREE (fn) = build_nt (EXPR_STMT, void_zero_node);
1995 last_tree = DECL_SAVED_TREE (fn);
1996 last_expr_type = NULL_TREE;
1999 /* Finish the statement tree for FN. */
2002 finish_stmt_tree (fn)
2007 /* Remove the fake extra statement added in begin_stmt_tree. */
2008 stmt = TREE_CHAIN (DECL_SAVED_TREE (fn));
2009 DECL_SAVED_TREE (fn) = stmt;
2011 /* The line-number recorded in the outermost statement in a function
2012 is the line number of the end of the function. */
2013 STMT_LINENO (stmt) = lineno;
2014 STMT_LINENO_FOR_FN_P (stmt) = 1;
2017 /* We're about to expand T, a statement. Set up appropriate context
2018 for the substitution. */
2024 if (!STMT_LINENO_FOR_FN_P (t))
2025 lineno = STMT_LINENO (t);
2026 stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
2029 /* Some statements, like for-statements or if-statements, require a
2030 condition. This condition can be a declaration. If T is such a
2031 declaration it is processed, and an expression appropriate to use
2032 as the condition is returned. Otherwise, T itself is returned. */
2038 if (t && TREE_CODE (t) == DECL_STMT)
2041 return convert_from_reference (DECL_STMT_DECL (t));
2047 /* Generate RTL for the statement T, and its substatements, and any
2048 other statements at its nesting level. */
2056 while (t && t != error_mark_node)
2058 int saved_stmts_are_full_exprs_p;
2060 /* Assume we'll have nothing to return. */
2063 /* Set up context appropriately for handling this statement. */
2064 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p;
2067 switch (TREE_CODE (t))
2070 finish_return_stmt (RETURN_EXPR (t));
2074 finish_expr_stmt_real (EXPR_STMT_EXPR (t),
2075 EXPR_STMT_ASSIGNS_THIS (t));
2081 int i = suspend_momentary ();
2083 emit_line_note (input_filename, lineno);
2084 decl = DECL_STMT_DECL (t);
2085 if (TREE_CODE (decl) == LABEL_DECL)
2086 finish_label_decl (DECL_NAME (decl));
2089 /* If we marked this variable as dead when we processed it
2090 before, we must undo that now. The variable has been
2092 if (TREE_CODE (decl) == VAR_DECL)
2093 DECL_DEAD_FOR_LOCAL (decl) = 0;
2094 /* We need to clear DECL_CONTEXT so that maybe_push_decl
2095 will push it into the current scope. */
2096 if (DECL_CONTEXT (decl) == current_function_decl)
2098 DECL_CONTEXT (decl) = NULL_TREE;
2099 maybe_push_decl (decl);
2101 /* If this is a declaration for an automatic local
2102 variable, initialize it. Note that we might also see a
2103 declaration for a namespace-scope object (declared with
2104 `extern') or an object with static storage duration
2105 (declared with `static'). We don't have to handle the
2106 initialization of those objects here; the former can
2107 never be a definition (only a declaration), and the
2108 latter is handled in finish_file. */
2109 if (TREE_CODE (decl) == VAR_DECL
2110 && !TREE_STATIC (decl)
2111 && !DECL_EXTERNAL (decl))
2113 /* Support the old for-scope rules for backwards
2115 maybe_inject_for_scope_var (decl);
2116 /* Let the back-end know about this variable. */
2117 initialize_local_var (decl, DECL_INITIAL (decl), 0);
2120 resume_momentary (i);
2129 expand_stmt (FOR_INIT_STMT (t));
2130 finish_for_init_stmt (NULL_TREE);
2131 finish_for_cond (expand_cond (FOR_COND (t)), NULL_TREE);
2133 finish_for_expr (tmp, NULL_TREE);
2134 expand_stmt (FOR_BODY (t));
2135 finish_for_stmt (tmp, NULL_TREE);
2141 begin_while_stmt ();
2142 finish_while_stmt_cond (expand_cond (WHILE_COND (t)), NULL_TREE);
2143 expand_stmt (WHILE_BODY (t));
2144 finish_while_stmt (NULL_TREE);
2151 expand_stmt (DO_BODY (t));
2152 finish_do_body (NULL_TREE);
2153 finish_do_stmt (DO_COND (t), NULL_TREE);
2159 finish_if_stmt_cond (expand_cond (IF_COND (t)), NULL_TREE);
2160 if (THEN_CLAUSE (t))
2162 expand_stmt (THEN_CLAUSE (t));
2163 finish_then_clause (NULL_TREE);
2165 if (ELSE_CLAUSE (t))
2167 begin_else_clause ();
2168 expand_stmt (ELSE_CLAUSE (t));
2169 finish_else_clause (NULL_TREE);
2175 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
2176 expand_stmt (COMPOUND_BODY (t));
2177 rval = finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
2182 finish_break_stmt ();
2186 finish_continue_stmt ();
2193 begin_switch_stmt ();
2194 cond = expand_cond (SWITCH_COND (t));
2195 finish_switch_cond (cond, NULL_TREE);
2196 expand_stmt (SWITCH_BODY (t));
2197 finish_switch_stmt (cond, NULL_TREE);
2202 finish_case_label (CASE_LOW (t), CASE_HIGH (t));
2206 finish_label_stmt (DECL_NAME (LABEL_STMT_LABEL (t)));
2210 if (TREE_CODE (GOTO_DESTINATION (t)) == LABEL_DECL)
2211 finish_goto_stmt (DECL_NAME (GOTO_DESTINATION (t)));
2213 finish_goto_stmt (GOTO_DESTINATION (t));
2217 finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS
2218 (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
2224 expand_eh_region_start ();
2225 expand_stmt (TRY_STMTS (t));
2226 finish_cleanup_try_block (NULL_TREE);
2227 finish_cleanup (TRY_HANDLERS (t), NULL_TREE);
2232 expand_stmt (TRY_STMTS (t));
2233 finish_try_block (NULL_TREE);
2234 expand_stmt (TRY_HANDLERS (t));
2235 finish_handler_sequence (NULL_TREE);
2241 if (HANDLER_PARMS (t))
2242 expand_start_catch_block (DECL_STMT_DECL (HANDLER_PARMS (t)));
2244 expand_start_catch_block (NULL_TREE);
2245 finish_handler_parms (NULL_TREE);
2246 expand_stmt (HANDLER_BODY (t));
2247 finish_handler (NULL_TREE);
2251 finish_subobject (SUBOBJECT_CLEANUP (t));
2255 my_friendly_abort (19990810);
2259 /* Restore saved state. */
2260 stmts_are_full_exprs_p = saved_stmts_are_full_exprs_p;
2262 /* Go on to the next statement in this scope. */
2269 /* Generate RTL for FN. */
2276 char *saved_input_filename;
2280 /* When the parser calls us after finishing the body of a template
2281 function, we don't really want to expand the body. When we're
2282 processing an in-class definition of an inline function,
2283 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2284 to look at the function itself. */
2285 if (processing_template_decl
2286 || (DECL_LANG_SPECIFIC (fn)
2287 && DECL_TEMPLATE_INFO (fn)
2288 && uses_template_parms (DECL_TI_ARGS (fn))))
2291 /* Save the current file name and line number. When we expand the
2292 body of the funciton, we'll set LINENO and INPUT_FILENAME so that
2293 error-mesages come out in the right places. */
2294 saved_lineno = lineno;
2295 saved_input_filename = input_filename;
2296 lineno = DECL_SOURCE_LINE (fn);
2297 input_filename = DECL_SOURCE_FILE (fn);
2299 start_function (NULL_TREE, fn, NULL_TREE, SF_PRE_PARSED | SF_EXPAND);
2300 store_parm_decls ();
2302 /* There are a few things that we do not handle recursively. For
2303 example, a function try-block is handled differently from an
2304 ordinary try-block, so we must handle it here. */
2305 t = DECL_SAVED_TREE (fn);
2306 try_block = NULL_TREE;
2307 if (t && TREE_CODE (t) == TRY_BLOCK)
2310 begin_function_try_block ();
2311 t = TRY_STMTS (try_block);
2314 if (t && TREE_CODE (t) == RETURN_INIT)
2316 /* Clear this out so that finish_named_return_value can set it
2318 DECL_NAME (DECL_RESULT (fn)) = NULL_TREE;
2319 finish_named_return_value (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
2323 if (t && TREE_CODE (t) == CTOR_INITIALIZER)
2325 current_member_init_list = TREE_OPERAND (t, 0);
2326 current_base_init_list = TREE_OPERAND (t, 1);
2330 /* If this is a constructor, we need to initialize our members and
2334 /* Expand the body. */
2337 /* If there was a function try-block, expand the handlers. */
2340 finish_function_try_block (NULL_TREE);
2341 expand_stmt (TRY_HANDLERS (try_block));
2342 finish_function_handler_sequence (NULL_TREE);
2345 /* Statements should always be full-expressions at the outermost set
2346 of curly braces for a function. */
2347 my_friendly_assert (stmts_are_full_exprs_p, 19990831);
2349 /* The outermost statement for a function contains the line number
2350 recorded when we finished processing the function. */
2351 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2353 /* Generate code for the function. */
2354 finish_function (lineno, 0);
2356 /* And restore the current source position. */
2357 lineno = saved_lineno;
2358 input_filename = saved_input_filename;