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 finish_expr_stmt_real PROTO((tree, int));
45 static tree expand_cond PROTO((tree));
46 static tree maybe_convert_cond PROTO((tree));
48 /* When parsing a template, LAST_TREE contains the last statement
49 parsed. These are chained together through the TREE_CHAIN field,
50 but often need to be re-organized since the parse is performed
51 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
54 #define RECHAIN_STMTS(stmt, substmt) \
56 substmt = TREE_CHAIN (stmt); \
57 TREE_CHAIN (stmt) = NULL_TREE; \
61 /* Finish processing the COND, the SUBSTMT condition for STMT. */
63 #define FINISH_COND(cond, stmt, substmt) \
65 if (last_tree != stmt) \
67 RECHAIN_STMTS (stmt, substmt); \
68 if (!processing_template_decl) \
70 cond = build_tree_list (substmt, cond); \
78 /* T is a statement. Add it to the statement-tree. */
84 /* Add T to the statement-tree. */
85 last_tree = TREE_CHAIN (last_tree) = t;
87 /* When we expand a statement-tree, we must know whether or not the
88 statements are full-expresions. We record that fact here. */
89 if (building_stmt_tree ())
90 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p;
93 /* COND is the condition-expression for an if, while, etc.,
94 statement. Convert it to a boolean value, if appropriate. */
97 maybe_convert_cond (cond)
100 /* Empty conditions remain empty. */
104 /* Wait until we instantiate templates before doing conversion. */
105 if (processing_template_decl)
108 /* Do the conversion. */
109 cond = convert_from_reference (cond);
110 return condition_conversion (cond);
113 /* Finish an expression-statement, whose EXPRESSION is as indicated.
114 If ASSIGNED_THIS is non-zero, then this statement just assigned to
115 the `this' pointer. */
118 finish_expr_stmt_real (expr, assigned_this)
122 if (expr != NULL_TREE)
124 if (building_stmt_tree ())
125 add_tree (build_min_nt (EXPR_STMT, expr));
128 emit_line_note (input_filename, lineno);
129 /* Do default conversion if safe and possibly important,
130 in case within ({...}). */
131 if (!stmts_are_full_exprs_p &&
132 ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
134 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
135 expr = default_conversion (expr);
137 if (stmts_are_full_exprs_p)
138 expand_start_target_temps ();
140 cplus_expand_expr_stmt (expr);
142 if (stmts_are_full_exprs_p)
144 expand_end_target_temps ();
150 /* If this statement assigned to the `this' pointer, record that
151 fact for finish_stmt. */
153 current_function_just_assigned_this = 1;
157 /* This was an expression-statement, so we save the type of the
159 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
162 /* Like finish_expr_stmt_real, but ASSIGNS_THIS is always zero. */
165 finish_expr_stmt (expr)
168 finish_expr_stmt_real (expr, /*assigns_this=*/0);
171 /* Begin an if-statement. Returns a newly created IF_STMT if
179 if (building_stmt_tree ())
181 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
192 /* Process the COND of an if-statement, which may be given by
196 finish_if_stmt_cond (cond, if_stmt)
200 cond = maybe_convert_cond (cond);
202 if (building_stmt_tree ())
203 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
206 emit_line_note (input_filename, lineno);
207 expand_start_cond (cond, 0);
211 /* Finish the then-clause of an if-statement, which may be given by
215 finish_then_clause (if_stmt)
218 if (building_stmt_tree ())
220 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
228 /* Begin the else-clause of an if-statement. */
233 if (!building_stmt_tree ())
234 expand_start_else ();
237 /* Finish the else-clause of an if-statement, which may be given by
241 finish_else_clause (if_stmt)
244 if (building_stmt_tree ())
245 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
248 /* Finsh an if-statement. */
253 if (!building_stmt_tree ())
260 /* Begin a while-statement. Returns a newly created WHILE_STMT if
268 if (building_stmt_tree ())
270 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
276 emit_line_note (input_filename, lineno);
277 expand_start_loop (1);
286 /* Process the COND of an if-statement, which may be given by
290 finish_while_stmt_cond (cond, while_stmt)
294 cond = maybe_convert_cond (cond);
296 if (building_stmt_tree ())
297 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
300 emit_line_note (input_filename, lineno);
301 expand_exit_loop_if_false (0, cond);
304 /* If COND wasn't a declaration, clear out the
305 block we made for it and start a new one here so the
306 optimization in expand_end_loop will work. */
307 if (getdecls () == NULL_TREE)
314 /* Finish a while-statement, which may be given by WHILE_STMT. */
317 finish_while_stmt (while_stmt)
322 if (building_stmt_tree ())
323 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
329 /* Begin a do-statement. Returns a newly created DO_STMT if
335 if (building_stmt_tree ())
337 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
344 emit_line_note (input_filename, lineno);
345 expand_start_loop_continue_elsewhere (1);
350 /* Finish the body of a do-statement, which may be given by DO_STMT. */
353 finish_do_body (do_stmt)
356 if (building_stmt_tree ())
357 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
359 expand_loop_continue_here ();
362 /* Finish a do-statement, which may be given by DO_STMT, and whose
363 COND is as indicated. */
366 finish_do_stmt (cond, do_stmt)
370 cond = maybe_convert_cond (cond);
372 if (building_stmt_tree ())
373 DO_COND (do_stmt) = cond;
376 emit_line_note (input_filename, lineno);
377 expand_exit_loop_if_false (0, cond);
385 /* Finish a return-statement. The EXPRESSION returned, if any, is as
389 finish_return_stmt (expr)
392 if (building_stmt_tree ())
393 add_tree (build_min_nt (RETURN_STMT, expr));
396 emit_line_note (input_filename, lineno);
397 c_expand_return (expr);
403 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
410 if (building_stmt_tree ())
412 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
413 NULL_TREE, NULL_TREE);
419 if (flag_new_for_scope > 0)
422 note_level_for_for ();
428 /* Finish the for-init-statement of a for-statement, which may be
429 given by FOR_STMT. */
432 finish_for_init_stmt (for_stmt)
435 if (building_stmt_tree ())
437 if (last_tree != for_stmt)
438 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
443 emit_line_note (input_filename, lineno);
444 expand_start_loop_continue_elsewhere (1);
450 /* Finish the COND of a for-statement, which may be given by
454 finish_for_cond (cond, for_stmt)
458 cond = maybe_convert_cond (cond);
460 if (building_stmt_tree ())
461 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
464 emit_line_note (input_filename, lineno);
466 expand_exit_loop_if_false (0, cond);
469 /* If the cond wasn't a declaration, clear out the
470 block we made for it and start a new one here so the
471 optimization in expand_end_loop will work. */
472 if (getdecls () == NULL_TREE)
479 /* Finish the increment-EXPRESSION in a for-statement, which may be
480 given by FOR_STMT. */
483 finish_for_expr (expr, for_stmt)
487 if (building_stmt_tree ())
488 FOR_EXPR (for_stmt) = expr;
490 /* Don't let the tree nodes for EXPR be discarded
491 by clear_momentary during the parsing of the next stmt. */
495 /* Finish the body of a for-statement, which may be given by
496 FOR_STMT. The increment-EXPR for the loop must be
500 finish_for_stmt (expr, for_stmt)
504 /* Pop the scope for the body of the loop. */
507 if (building_stmt_tree ())
508 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
511 emit_line_note (input_filename, lineno);
512 expand_loop_continue_here ();
514 finish_expr_stmt (expr);
520 if (flag_new_for_scope > 0)
526 /* Finish a break-statement. */
531 emit_line_note (input_filename, lineno);
532 if (building_stmt_tree ())
533 add_tree (build_min_nt (BREAK_STMT));
534 else if ( ! expand_exit_something ())
535 cp_error ("break statement not within loop or switch");
538 /* Finish a continue-statement. */
541 finish_continue_stmt ()
543 emit_line_note (input_filename, lineno);
544 if (building_stmt_tree ())
545 add_tree (build_min_nt (CONTINUE_STMT));
546 else if (! expand_continue_loop (0))
547 cp_error ("continue statement not within a loop");
550 /* Begin a switch-statement. Returns a new SWITCH_STMT if
558 if (building_stmt_tree ())
560 r = build_min_nt (SWITCH_STMT, NULL_TREE, NULL_TREE);
571 /* Finish the cond of a switch-statement. */
574 finish_switch_cond (cond, switch_stmt)
578 if (building_stmt_tree ())
579 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
580 else if (cond != error_mark_node)
582 emit_line_note (input_filename, lineno);
583 c_expand_start_case (cond);
586 /* The code is in error, but we don't want expand_end_case to
588 c_expand_start_case (boolean_false_node);
592 /* Don't let the tree nodes for COND be discarded by
593 clear_momentary during the parsing of the next stmt. */
597 /* Finish the body of a switch-statement, which may be given by
598 SWITCH_STMT. The COND to switch on is indicated. */
601 finish_switch_stmt (cond, switch_stmt)
605 if (building_stmt_tree ())
606 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
608 expand_end_case (cond);
615 /* Finish a case-label. */
618 finish_case_label (low_value, high_value)
622 if (building_stmt_tree ())
624 /* Add a representation for the case label to the statement
626 add_tree (build_min_nt (CASE_LABEL, low_value, high_value));
627 /* And warn about crossing initializations, etc. */
628 if (!processing_template_decl)
629 define_case_label ();
633 do_case (low_value, high_value);
636 /* Finish a goto-statement. */
639 finish_goto_stmt (destination)
642 if (TREE_CODE (destination) == IDENTIFIER_NODE)
643 destination = lookup_label (destination);
645 if (building_stmt_tree ())
646 add_tree (build_min_nt (GOTO_STMT, destination));
649 emit_line_note (input_filename, lineno);
651 if (TREE_CODE (destination) == LABEL_DECL)
653 TREE_USED (destination) = 1;
654 label_rtx (destination);
655 expand_goto (destination);
658 expand_computed_goto (destination);
662 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
668 if (building_stmt_tree ())
670 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
677 emit_line_note (input_filename, lineno);
678 expand_start_try_stmts ();
683 /* Likewise, for a function-try-block. */
686 begin_function_try_block ()
688 if (building_stmt_tree ())
690 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
692 FN_TRY_BLOCK_P (r) = 1;
698 if (! current_function_parms_stored)
700 expand_start_early_try_stmts ();
705 /* Finish a try-block, which may be given by TRY_BLOCK. */
708 finish_try_block (try_block)
711 if (building_stmt_tree ())
712 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
714 expand_start_all_catch ();
717 /* Finish the body of a cleanup try-block, which may be given by
721 finish_cleanup_try_block (try_block)
724 if (building_stmt_tree ())
725 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
728 /* Finish an implicitly generated try-block, with a cleanup is given
732 finish_cleanup (cleanup, try_block)
736 if (building_stmt_tree ())
738 TRY_HANDLERS (try_block) = cleanup;
739 CLEANUP_P (try_block) = 1;
742 expand_eh_region_end (protect_with_terminate (cleanup));
745 /* Likewise, for a function-try-block. */
748 finish_function_try_block (try_block)
751 if (building_stmt_tree ())
753 if (TREE_CHAIN (try_block)
754 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
756 /* Chain the compound statement after the CTOR_INITIALIZER. */
757 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
758 /* And make the CTOR_INITIALIZER the body of the try-block. */
759 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
762 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
766 end_protect_partials ();
767 expand_start_all_catch ();
770 in_function_try_handler = 1;
773 /* Finish a handler-sequence for a try-block, which may be given by
777 finish_handler_sequence (try_block)
780 if (building_stmt_tree ())
781 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
783 expand_end_all_catch ();
786 /* Likewise, for a function-try-block. */
789 finish_function_handler_sequence (try_block)
792 in_function_try_handler = 0;
794 if (building_stmt_tree ())
795 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
797 expand_end_all_catch ();
800 /* Begin a handler. Returns a HANDLER if appropriate. */
807 if (building_stmt_tree ())
809 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
820 /* Finish the handler-parameters for a handler, which may be given by
821 HANDLER. DECL is the declaration for the catch parameter, or NULL
822 if this is a `catch (...)' clause. */
825 finish_handler_parms (decl, handler)
829 tree blocks = NULL_TREE;
831 if (processing_template_decl)
835 decl = pushdecl (decl);
836 decl = push_template_decl (decl);
837 add_decl_stmt (decl);
838 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
841 else if (building_stmt_tree ())
842 blocks = expand_start_catch_block (decl);
847 /* Note the beginning of a handler for TYPE. This function is called
848 at the point to which control should be transferred when an
849 appropriately-typed exception is thrown. */
852 begin_catch_block (type)
855 if (building_stmt_tree ())
856 add_tree (build (START_CATCH_STMT, type));
858 start_catch_handler (type);
861 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
862 the return value from the matching call to finish_handler_parms. */
865 finish_handler (blocks, handler)
869 if (!processing_template_decl)
871 if (building_stmt_tree ())
872 expand_end_catch_block (blocks);
874 if (!building_stmt_tree ())
876 /* Fall to outside the try statement when done executing
877 handler and we fall off end of handler. This is jump
878 Lresume in the documentation. */
879 expand_goto (top_label_entry (&caught_return_label_stack));
880 end_catch_handler ();
884 if (building_stmt_tree ())
885 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
890 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
891 compound-statement does not define a scope. Returns a new
892 COMPOUND_STMT if appropriate. */
895 begin_compound_stmt (has_no_scope)
900 if (building_stmt_tree ())
902 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
905 COMPOUND_STMT_NO_SCOPE (r) = 1;
910 last_expr_type = NULL_TREE;
915 /* Normally, we try hard to keep the BLOCK for a
916 statement-expression. But, if it's a statement-expression with
917 a scopeless block, there's nothing to keep, and we don't want
918 to accidentally keep a block *inside* the scopeless block. */
921 /* If this is the outermost block of the function, declare the
922 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
923 if (!current_function_name_declared && !processing_template_decl)
925 declare_function_name ();
926 current_function_name_declared = 1;
933 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
934 If HAS_NO_SCOPE is non-zero, the compound statement does not define
938 finish_compound_stmt (has_no_scope, compound_stmt)
950 if (building_stmt_tree ())
951 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
953 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
954 the precise purpose of that variable is store the type of the
955 last expression statement within the last compound statement, we
956 preserve the value. */
964 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
965 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
969 finish_asm_stmt (cv_qualifier, string, output_operands,
970 input_operands, clobbers)
973 tree output_operands;
977 if (TREE_CHAIN (string))
979 if (building_stmt_tree ())
980 /* We need to build the combined string on the permanent
981 obstack so that we can use it during instantiations. */
982 push_permanent_obstack ();
984 string = combine_strings (string);
986 if (building_stmt_tree ())
990 if (cv_qualifier != NULL_TREE
991 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
993 cp_warning ("%s qualifier ignored on asm",
994 IDENTIFIER_POINTER (cv_qualifier));
995 cv_qualifier = NULL_TREE;
998 if (building_stmt_tree ())
1000 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
1001 output_operands, input_operands,
1007 emit_line_note (input_filename, lineno);
1008 if (output_operands != NULL_TREE || input_operands != NULL_TREE
1009 || clobbers != NULL_TREE)
1013 for (t = input_operands; t; t = TREE_CHAIN (t))
1014 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
1016 c_expand_asm_operands (string, output_operands,
1019 cv_qualifier != NULL_TREE,
1020 input_filename, lineno);
1023 expand_asm (string);
1029 /* Finish a label with the indicated NAME. */
1032 finish_label_stmt (name)
1035 tree decl = define_label (input_filename, lineno, name);
1037 if (building_stmt_tree ())
1038 add_tree (build_min_nt (LABEL_STMT, decl));
1040 expand_label (decl);
1043 /* Finish a series of declarations for local labels. G++ allows users
1044 to declare "local" labels, i.e., labels with scope. This extension
1045 is useful when writing code involving statement-expressions. */
1048 finish_label_decl (name)
1051 tree decl = declare_local_label (name);
1052 if (building_stmt_tree ())
1053 add_decl_stmt (decl);
1056 /* Create a declaration statement for the declaration given by the
1060 add_decl_stmt (decl)
1065 /* We need the type to last until instantiation time. */
1066 decl_stmt = build_min_nt (DECL_STMT, decl);
1067 add_tree (decl_stmt);
1070 /* We're in a constructor, and have just constructed a a subobject of
1071 *THIS. CLEANUP is code to run if an exception is thrown before the
1072 end of the current function is reached. */
1075 finish_subobject (cleanup)
1078 if (building_stmt_tree ())
1080 tree r = build_min_nt (SUBOBJECT, cleanup);
1084 add_partial_entry (cleanup);
1087 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1090 finish_decl_cleanup (decl, cleanup)
1094 if (building_stmt_tree ())
1095 add_tree (build_min_nt (CLEANUP_STMT, decl, cleanup));
1097 || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
1098 expand_decl_cleanup (decl, cleanup);
1101 /* Bind a name and initialization to the return value of
1102 the current function. */
1105 finish_named_return_value (return_id, init)
1106 tree return_id, init;
1108 tree decl = DECL_RESULT (current_function_decl);
1111 /* Give this error as many times as there are occurrences,
1112 so that users can use Emacs compilation buffers to find
1113 and fix all such places. */
1114 pedwarn ("ANSI C++ does not permit named return values");
1116 if (return_id != NULL_TREE)
1118 if (DECL_NAME (decl) == NULL_TREE)
1120 DECL_NAME (decl) = return_id;
1121 DECL_ASSEMBLER_NAME (decl) = return_id;
1125 cp_error ("return identifier `%D' already in place", return_id);
1130 /* Can't let this happen for constructors. */
1131 if (DECL_CONSTRUCTOR_P (current_function_decl))
1133 error ("can't redefine default return value for constructors");
1137 /* If we have a named return value, put that in our scope as well. */
1138 if (DECL_NAME (decl) != NULL_TREE)
1140 /* Let `cp_finish_decl' know that this initializer is ok. */
1141 DECL_INITIAL (decl) = init;
1142 if (doing_semantic_analysis_p ())
1145 if (building_stmt_tree ())
1146 add_tree (build_min_nt (RETURN_INIT, return_id, init));
1149 cp_finish_decl (decl, init, NULL_TREE, 0, 0);
1150 store_return_init (decl);
1155 /* Cache the value of this class's main virtual function table pointer
1156 in a register variable. This will save one indirection if a
1157 more than one virtual function call is made this function. */
1162 if (base_init_expr == 0
1163 && DECL_CONSTRUCTOR_P (current_function_decl))
1165 if (building_stmt_tree ())
1166 add_tree (build_min_nt
1168 current_member_init_list, current_base_init_list));
1170 emit_base_init (current_class_type);
1173 /* Always keep the BLOCK node associated with the outermost pair of
1174 curley braces of a function. These are needed for correct
1175 operation of dwarfout.c. */
1176 keep_next_level (1);
1179 /* Begin a new scope. */
1184 if (!building_stmt_tree ())
1186 emit_line_note (input_filename, lineno);
1190 if (stmts_are_full_exprs_p)
1193 if (!building_stmt_tree ()
1194 && !current_function->x_whole_function_mode_p)
1195 expand_start_bindings (0);
1196 else if (building_stmt_tree () && !processing_template_decl)
1198 tree ss = build_min_nt (SCOPE_STMT);
1199 SCOPE_BEGIN_P (ss) = 1;
1201 current_scope_stmt_stack
1202 = tree_cons (NULL_TREE, ss, current_scope_stmt_stack);
1207 /* Finish a scope. */
1214 if (stmts_are_full_exprs_p)
1216 if (!building_stmt_tree ()
1217 && !current_function->x_whole_function_mode_p)
1218 expand_end_bindings (getdecls (), kept_level_p (), 0);
1219 else if (building_stmt_tree () && !processing_template_decl)
1221 tree ss = build_min_nt (SCOPE_STMT);
1222 SCOPE_NULLIFIED_P (ss) = !kept_level_p ();
1223 SCOPE_NULLIFIED_P (TREE_VALUE (current_scope_stmt_stack))
1224 = SCOPE_NULLIFIED_P (ss);
1226 current_scope_stmt_stack = TREE_CHAIN (current_scope_stmt_stack);
1228 /* When not in function-at-a-time mode, expand_end_bindings
1229 will warn about unused variables. But, in
1230 function-at-a-time mode expand_end_bindings is not passed
1231 the list of variables in the current scope, and therefore
1232 no warning is emitted. So, we explicitly warn here. */
1233 warn_about_unused_variables (getdecls ());
1236 t = poplevel (kept_level_p (), 1, 0);
1242 /* Finish a parenthesized expression EXPR. */
1245 finish_parenthesized_expr (expr)
1248 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1249 /* This inhibits warnings in truthvalue_conversion. */
1250 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1255 /* Begin a statement-expression. The value returned must be passed to
1256 finish_stmt_expr. */
1261 keep_next_level (1);
1262 /* If we're building a statement tree, then the upcoming compound
1263 statement will be chained onto the tree structure, starting at
1264 last_tree. We return last_tree so that we can later unhook the
1265 compound statement. */
1266 return building_stmt_tree () ? last_tree : expand_start_stmt_expr();
1269 /* Finish a statement-expression. RTL_EXPR should be the value
1270 returned by the previous begin_stmt_expr; EXPR is the
1271 statement-expression. Returns an expression representing the
1272 statement-expression. */
1275 finish_stmt_expr (rtl_expr, expr)
1281 if (!building_stmt_tree ())
1283 rtl_expr = expand_end_stmt_expr (rtl_expr);
1284 /* The statements have side effects, so the group does. */
1285 TREE_SIDE_EFFECTS (rtl_expr) = 1;
1288 if (building_stmt_tree ())
1290 /* If the last thing in the statement-expression was not an
1291 expression-statement, then it has type `void'. */
1292 if (!last_expr_type)
1293 last_expr_type = void_type_node;
1294 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1295 TREE_SIDE_EFFECTS (result) = 1;
1297 /* Remove the compound statement from the tree structure; it is
1298 now saved in the STMT_EXPR. */
1299 last_tree = rtl_expr;
1300 TREE_CHAIN (last_tree) = NULL_TREE;
1302 else if (expr && TREE_CODE (expr) == BLOCK)
1304 result = build (BIND_EXPR, TREE_TYPE (rtl_expr),
1305 NULL_TREE, rtl_expr, expr);
1306 delete_block (expr);
1311 if (expr && TREE_CODE (expr) == BLOCK)
1312 /* Remove the block from the tree at this point. It gets put back
1313 at the proper place when the STMT_EXPR or BIND_EXPR is
1315 delete_block (expr);
1320 /* Finish a call to FN with ARGS. Returns a representation of the
1324 finish_call_expr (fn, args, koenig)
1333 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1334 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1335 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
1336 fn = do_identifier (fn, 2, args);
1338 result = build_x_function_call (fn, args, current_class_ref);
1340 if (TREE_CODE (result) == CALL_EXPR
1341 && (! TREE_TYPE (result)
1342 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
1343 result = require_complete_type (result);
1348 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1349 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1350 POSTDECREMENT_EXPR.) */
1353 finish_increment_expr (expr, code)
1355 enum tree_code code;
1357 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1358 a COMPONENT_REF). This way if we've got, say, a reference to a
1359 static member that's being operated on, we don't end up trying to
1360 find a member operator for the class it's in. */
1362 if (TREE_CODE (expr) == OFFSET_REF)
1363 expr = resolve_offset_ref (expr);
1364 return build_x_unary_op (code, expr);
1367 /* Finish a use of `this'. Returns an expression for `this'. */
1374 if (current_class_ptr)
1376 #ifdef WARNING_ABOUT_CCD
1377 TREE_USED (current_class_ptr) = 1;
1379 result = current_class_ptr;
1381 else if (current_function_decl
1382 && DECL_STATIC_FUNCTION_P (current_function_decl))
1384 error ("`this' is unavailable for static member functions");
1385 result = error_mark_node;
1389 if (current_function_decl)
1390 error ("invalid use of `this' in non-member function");
1392 error ("invalid use of `this' at top level");
1393 result = error_mark_node;
1399 /* Finish a member function call using OBJECT and ARGS as arguments to
1400 FN. Returns an expression for the call. */
1403 finish_object_call_expr (fn, object, args)
1409 /* This is a future direction of this code, but because
1410 build_x_function_call cannot always undo what is done in
1411 build_component_ref entirely yet, we cannot do this. */
1413 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1414 return finish_call_expr (real_fn, args);
1416 if (TREE_CODE (fn) == TYPE_DECL)
1418 if (processing_template_decl)
1419 /* This can happen on code like:
1422 template <class T> void f(T t) {
1426 We just grab the underlying IDENTIFIER. */
1427 fn = DECL_NAME (fn);
1430 cp_error ("calling type `%T' like a method", fn);
1431 return error_mark_node;
1435 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1439 /* Finish a qualified member function call using OBJECT and ARGS as
1440 arguments to FN. Returns an expressino for the call. */
1443 finish_qualified_object_call_expr (fn, object, args)
1448 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1449 TREE_OPERAND (fn, 1), args);
1452 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1453 being the scope, if any, of DESTRUCTOR. Returns an expression for
1457 finish_pseudo_destructor_call_expr (object, scope, destructor)
1462 if (processing_template_decl)
1463 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1465 if (scope && scope != destructor)
1466 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1469 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1470 && (TREE_CODE (TREE_TYPE (object)) !=
1471 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1472 cp_error ("`%E' is not of type `%T'", object, destructor);
1474 return cp_convert (void_type_node, object);
1477 /* Finish a call to a globally qualified member function FN using
1478 ARGS. Returns an expression for the call. */
1481 finish_qualified_call_expr (fn, args)
1485 if (processing_template_decl)
1486 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
1488 return build_member_call (TREE_OPERAND (fn, 0),
1489 TREE_OPERAND (fn, 1),
1493 /* Finish an expression taking the address of LABEL. Returns an
1494 expression for the address. */
1497 finish_label_address_expr (label)
1502 label = lookup_label (label);
1503 if (label == NULL_TREE)
1504 result = null_pointer_node;
1507 TREE_USED (label) = 1;
1508 result = build1 (ADDR_EXPR, ptr_type_node, label);
1509 TREE_CONSTANT (result) = 1;
1515 /* Finish an expression of the form CODE EXPR. */
1518 finish_unary_op_expr (code, expr)
1519 enum tree_code code;
1522 tree result = build_x_unary_op (code, expr);
1523 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST)
1524 TREE_NEGATED_INT (result) = 1;
1525 overflow_warning (result);
1529 /* Finish an id-expression. */
1532 finish_id_expr (expr)
1535 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1536 expr = do_identifier (expr, 1, NULL_TREE);
1541 /* Begin a new-placement. */
1544 begin_new_placement ()
1546 /* The arguments to a placement new might be passed to a
1547 deallocation function, in the event that the allocation throws an
1548 exception. Since we don't expand exception handlers until the
1549 end of a function, we must make sure the arguments stay around
1551 return suspend_momentary ();
1554 /* Finish a new-placement. The ARGS are the placement arguments. The
1555 COOKIE is the value returned by the previous call to
1556 begin_new_placement. */
1559 finish_new_placement (args, cookie)
1563 resume_momentary (cookie);
1567 /* Begin a function defniition declared with DECL_SPECS and
1568 DECLARATOR. Returns non-zero if the function-declaration is
1572 begin_function_definition (decl_specs, declarator)
1578 split_specs_attrs (decl_specs, &specs, &attrs);
1579 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
1582 reinit_parse_for_function ();
1583 /* The things we're about to see are not directly qualified by any
1584 template headers we've seen thus far. */
1585 reset_specialization ();
1590 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1594 begin_constructor_declarator (scope, name)
1598 tree result = build_parse_node (SCOPE_REF, scope, name);
1599 enter_scope_of (result);
1603 /* Finish an init-declarator. Returns a DECL. */
1606 finish_declarator (declarator, declspecs, attributes,
1607 prefix_attributes, initialized)
1611 tree prefix_attributes;
1614 return start_decl (declarator, declspecs, initialized, attributes,
1618 /* Finish a translation unit. */
1621 finish_translation_unit ()
1623 /* In case there were missing closebraces,
1624 get us back to the global binding level. */
1626 while (current_namespace != global_namespace)
1631 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1632 Returns the parameter. */
1635 finish_template_type_parm (aggr, identifier)
1639 if (aggr != class_type_node)
1641 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1642 aggr = class_type_node;
1645 return build_tree_list (aggr, identifier);
1648 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1649 Returns the parameter. */
1652 finish_template_template_parm (aggr, identifier)
1656 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1657 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1658 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1659 DECL_TEMPLATE_RESULT (tmpl) = decl;
1660 SET_DECL_ARTIFICIAL (decl);
1661 end_template_decl ();
1663 return finish_template_type_parm (aggr, tmpl);
1666 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1667 non-zero, the parameter list was terminated by a `...'. */
1670 finish_parmlist (parms, ellipsis)
1675 chainon (parms, void_list_node);
1676 /* We mark the PARMS as a parmlist so that declarator processing can
1677 disambiguate certain constructs. */
1678 if (parms != NULL_TREE)
1679 TREE_PARMLIST (parms) = 1;
1684 /* Begin a class definition, as indicated by T. */
1687 begin_class_definition (t)
1690 push_permanent_obstack ();
1692 if (t == error_mark_node
1693 || ! IS_AGGR_TYPE (t))
1695 t = make_lang_type (RECORD_TYPE);
1696 pushtag (make_anon_name (), t, 0);
1699 /* In a definition of a member class template, we will get here with an
1700 implicit typename, a TYPENAME_TYPE with a type. */
1701 if (TREE_CODE (t) == TYPENAME_TYPE)
1704 /* If we generated a partial instantiation of this type, but now
1705 we're seeing a real definition, we're actually looking at a
1706 partial specialization. Consider:
1708 template <class T, class U>
1714 template <class T, class U>
1717 typename X<Y<T, U> >::A a;
1720 template <class T, class U>
1725 We have to undo the effects of the previous partial
1727 if (PARTIAL_INSTANTIATION_P (t))
1731 /* Unfortunately, when we're not in pedantic mode, we
1732 attempt to actually fill in some of the fields of the
1733 partial instantiation, in order to support the implicit
1734 typename extension. Clear those fields now, in
1735 preparation for the definition here. The fields cleared
1736 here must match those set in instantiate_class_template.
1737 Look for a comment mentioning begin_class_definition
1739 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1740 TYPE_FIELDS (t) = NULL_TREE;
1741 TYPE_METHODS (t) = NULL_TREE;
1742 CLASSTYPE_TAGS (t) = NULL_TREE;
1743 TYPE_SIZE (t) = NULL_TREE;
1746 /* This isn't a partial instantiation any more. */
1747 PARTIAL_INSTANTIATION_P (t) = 0;
1749 /* If this type was already complete, and we see another definition,
1751 else if (TYPE_SIZE (t))
1752 duplicate_tag_error (t);
1754 /* Update the location of the decl. */
1755 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1756 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1758 if (TYPE_BEING_DEFINED (t))
1760 t = make_lang_type (TREE_CODE (t));
1761 pushtag (TYPE_IDENTIFIER (t), t, 0);
1763 maybe_process_partial_specialization (t);
1765 TYPE_BEING_DEFINED (t) = 1;
1766 /* Reset the interface data, at the earliest possible
1767 moment, as it might have been set via a class foo;
1770 tree name = TYPE_IDENTIFIER (t);
1772 if (! ANON_AGGRNAME_P (name))
1774 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1775 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1776 (t, interface_unknown);
1779 /* Only leave this bit clear if we know this
1780 class is part of an interface-only specification. */
1781 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1782 || ! CLASSTYPE_INTERFACE_ONLY (t))
1783 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1786 tmp = TYPE_IDENTIFIER ($<ttype>0);
1787 if (tmp && IDENTIFIER_TEMPLATE (tmp))
1788 overload_template_name (tmp, 1);
1790 reset_specialization();
1792 /* In case this is a local class within a template
1793 function, we save the current tree structure so
1794 that we can get it back later. */
1797 /* Make a declaration for this class in its own scope. */
1798 build_self_reference ();
1803 /* Finish the member declaration given by DECL. */
1806 finish_member_declaration (decl)
1809 if (decl == error_mark_node || decl == NULL_TREE)
1812 if (decl == void_type_node)
1813 /* The COMPONENT was a friend, not a member, and so there's
1814 nothing for us to do. */
1817 /* We should see only one DECL at a time. */
1818 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1820 /* Set up access control for DECL. */
1822 = (current_access_specifier == access_private_node);
1823 TREE_PROTECTED (decl)
1824 = (current_access_specifier == access_protected_node);
1825 if (TREE_CODE (decl) == TEMPLATE_DECL)
1827 TREE_PRIVATE (DECL_RESULT (decl)) = TREE_PRIVATE (decl);
1828 TREE_PROTECTED (DECL_RESULT (decl)) = TREE_PROTECTED (decl);
1831 /* Mark the DECL as a member of the current class. */
1832 if (TREE_CODE (decl) == FUNCTION_DECL
1833 || DECL_FUNCTION_TEMPLATE_P (decl))
1834 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1835 finish_struct. Presumably it is already set as the function is
1836 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1837 DECL_CLASS_CONTEXT (decl) = current_class_type;
1839 DECL_CONTEXT (decl) = current_class_type;
1841 /* Put functions on the TYPE_METHODS list and everything else on the
1842 TYPE_FIELDS list. Note that these are built up in reverse order.
1843 We reverse them (to obtain declaration order) in finish_struct. */
1844 if (TREE_CODE (decl) == FUNCTION_DECL
1845 || DECL_FUNCTION_TEMPLATE_P (decl))
1847 /* We also need to add this function to the
1848 CLASSTYPE_METHOD_VEC. */
1849 add_method (current_class_type, 0, decl);
1851 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1852 TYPE_METHODS (current_class_type) = decl;
1856 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1857 go at the beginning. The reason is that lookup_field_1
1858 searches the list in order, and we want a field name to
1859 override a type name so that the "struct stat hack" will
1860 work. In particular:
1862 struct S { enum E { }; int E } s;
1865 is legal. In addition, the FIELD_DECLs must be maintained in
1866 declaration order so that class layout works as expected.
1867 However, we don't need that order until class layout, so we
1868 save a little time by putting FIELD_DECLs on in reverse order
1869 here, and then reversing them in finish_struct_1. (We could
1870 also keep a pointer to the correct insertion points in the
1873 if (TREE_CODE (decl) == TYPE_DECL)
1874 TYPE_FIELDS (current_class_type)
1875 = chainon (TYPE_FIELDS (current_class_type), decl);
1878 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1879 TYPE_FIELDS (current_class_type) = decl;
1882 /* Enter the DECL into the scope of the class. */
1883 if (TREE_CODE (decl) != USING_DECL)
1884 pushdecl_class_level (decl);
1888 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1889 the definition is immediately followed by a semicolon. Returns the
1893 finish_class_definition (t, attributes, semi, pop_scope_p)
1899 /* finish_struct nukes this anyway; if finish_exception does too,
1902 note_got_semicolon (t);
1904 /* If we got any attributes in class_head, xref_tag will stick them in
1905 TREE_TYPE of the type. Grab them now. */
1906 attributes = chainon (TREE_TYPE (t), attributes);
1907 TREE_TYPE (t) = NULL_TREE;
1909 if (TREE_CODE (t) == ENUMERAL_TYPE)
1913 t = finish_struct (t, attributes);
1915 note_got_semicolon (t);
1921 check_for_missing_semicolon (t);
1923 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
1924 if (current_scope () == current_function_decl)
1925 do_pending_defargs ();
1930 /* Finish processing the default argument expressions cached during
1931 the processing of a class definition. */
1934 begin_inline_definitions ()
1937 && current_scope () == current_function_decl)
1938 do_pending_inlines ();
1941 /* Finish processing the inline function definitions cached during the
1942 processing of a class definition. */
1945 finish_inline_definitions ()
1947 if (current_class_type == NULL_TREE)
1948 clear_inline_text_obstack ();
1950 /* Undo the begin_tree in begin_class_definition. */
1954 /* Finish processing the declaration of a member class template
1955 TYPES whose template parameters are given by PARMS. */
1958 finish_member_class_template (types)
1963 /* If there are declared, but undefined, partial specializations
1964 mixed in with the typespecs they will not yet have passed through
1965 maybe_process_partial_specialization, so we do that here. */
1966 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1967 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1968 maybe_process_partial_specialization (TREE_VALUE (t));
1970 note_list_got_semicolon (types);
1971 grok_x_components (types);
1972 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1973 /* The component was in fact a friend declaration. We avoid
1974 finish_member_template_decl performing certain checks by
1978 finish_member_template_decl (types);
1980 /* As with other component type declarations, we do
1981 not store the new DECL on the list of
1986 /* Finish processsing a complete template declaration. The PARMS are
1987 the template parameters. */
1990 finish_template_decl (parms)
1994 end_template_decl ();
1996 end_specialization ();
1999 /* Finish processing a a template-id (which names a type) of the form
2000 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2001 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2002 the scope of template-id indicated. */
2005 finish_template_type (name, args, entering_scope)
2012 decl = lookup_template_class (name, args,
2013 NULL_TREE, NULL_TREE, entering_scope);
2014 if (decl != error_mark_node)
2015 decl = TYPE_STUB_DECL (decl);
2020 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2021 namespace scope or a class scope. */
2027 tree scope = TREE_OPERAND (sr, 0);
2029 if (TREE_CODE (scope) == NAMESPACE_DECL)
2031 push_decl_namespace (scope);
2032 TREE_COMPLEXITY (sr) = -1;
2034 else if (scope != current_class_type)
2036 if (TREE_CODE (scope) == TYPENAME_TYPE)
2038 /* In a declarator for a template class member, the scope will
2039 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2040 scope = TREE_TYPE (scope);
2041 TREE_OPERAND (sr, 0) = scope;
2043 push_nested_class (scope, 3);
2044 TREE_COMPLEXITY (sr) = current_class_depth;
2048 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2049 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2050 BASE_CLASS, or NULL_TREE if an error occurred. The
2051 ACCESSS_SPECIFIER is one of
2052 access_{default,public,protected_private}[_virtual]_node.*/
2055 finish_base_specifier (access_specifier, base_class)
2056 tree access_specifier;
2062 if (base_class == NULL_TREE)
2064 error ("invalid base class");
2065 type = error_mark_node;
2068 type = TREE_TYPE (base_class);
2070 if (! is_aggr_type (type, 1))
2073 result = build_tree_list (access_specifier, type);
2078 /* Called when multiple declarators are processed. If that is not
2079 premitted in this context, an error is issued. */
2082 check_multiple_declarators ()
2086 In a template-declaration, explicit specialization, or explicit
2087 instantiation the init-declarator-list in the declaration shall
2088 contain at most one declarator.
2090 We don't just use PROCESSING_TEMPLATE_DECL for the first
2091 condition since that would disallow the perfectly legal code,
2092 like `template <class T> struct S { int i, j; };'. */
2093 tree scope = current_scope ();
2095 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2096 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2099 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2100 || processing_explicit_instantiation
2101 || processing_specialization)
2102 cp_error ("multiple declarators in template declaration");
2106 finish_typeof (expr)
2109 if (processing_template_decl)
2113 push_permanent_obstack ();
2114 t = make_lang_type (TYPEOF_TYPE);
2115 TYPE_FIELDS (t) = expr;
2121 return TREE_TYPE (expr);
2124 /* Create an empty statement tree for FN. */
2127 begin_stmt_tree (fn)
2130 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2131 what follows. We remove the extraneous statement in
2132 finish_stmt_tree. */
2133 DECL_SAVED_TREE (fn) = build_nt (EXPR_STMT, void_zero_node);
2134 last_tree = DECL_SAVED_TREE (fn);
2135 last_expr_type = NULL_TREE;
2138 /* Finish the statement tree for FN. */
2141 finish_stmt_tree (fn)
2146 /* Remove the fake extra statement added in begin_stmt_tree. */
2147 stmt = TREE_CHAIN (DECL_SAVED_TREE (fn));
2148 DECL_SAVED_TREE (fn) = stmt;
2150 /* The line-number recorded in the outermost statement in a function
2151 is the line number of the end of the function. */
2152 STMT_LINENO (stmt) = lineno;
2153 STMT_LINENO_FOR_FN_P (stmt) = 1;
2156 /* We're about to expand T, a statement. Set up appropriate context
2157 for the substitution. */
2163 if (!STMT_LINENO_FOR_FN_P (t))
2164 lineno = STMT_LINENO (t);
2165 stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
2168 /* Some statements, like for-statements or if-statements, require a
2169 condition. This condition can be a declaration. If T is such a
2170 declaration it is processed, and an expression appropriate to use
2171 as the condition is returned. Otherwise, T itself is returned. */
2177 if (t && TREE_CODE (t) == TREE_LIST)
2179 expand_stmt (TREE_PURPOSE (t));
2180 return TREE_VALUE (t);
2186 /* Generate RTL for the statement T, and its substatements, and any
2187 other statements at its nesting level. */
2195 while (t && t != error_mark_node)
2197 int saved_stmts_are_full_exprs_p;
2199 /* Assume we'll have nothing to return. */
2202 /* Set up context appropriately for handling this statement. */
2203 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p;
2206 switch (TREE_CODE (t))
2209 finish_return_stmt (RETURN_EXPR (t));
2213 finish_expr_stmt_real (EXPR_STMT_EXPR (t),
2214 EXPR_STMT_ASSIGNS_THIS (t));
2220 int i = suspend_momentary ();
2222 emit_line_note (input_filename, lineno);
2223 decl = DECL_STMT_DECL (t);
2224 /* If this is a declaration for an automatic local
2225 variable, initialize it. Note that we might also see a
2226 declaration for a namespace-scope object (declared with
2227 `extern') or an object with static storage duration
2228 (declared with `static'). We don't have to handle the
2229 initialization of those objects here; the former can
2230 never be a definition (only a declaration), and the
2231 latter is handled in finish_file. */
2232 if (TREE_CODE (decl) == VAR_DECL
2233 && !TREE_STATIC (decl)
2234 && !DECL_EXTERNAL (decl))
2235 /* Let the back-end know about this variable. */
2236 emit_local_var (decl);
2238 resume_momentary (i);
2243 finish_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2246 case START_CATCH_STMT:
2247 begin_catch_block (TREE_TYPE (t));
2255 expand_stmt (FOR_INIT_STMT (t));
2256 finish_for_init_stmt (NULL_TREE);
2257 finish_for_cond (expand_cond (FOR_COND (t)), NULL_TREE);
2259 finish_for_expr (tmp, NULL_TREE);
2260 expand_stmt (FOR_BODY (t));
2261 finish_for_stmt (tmp, NULL_TREE);
2267 begin_while_stmt ();
2268 finish_while_stmt_cond (expand_cond (WHILE_COND (t)), NULL_TREE);
2269 expand_stmt (WHILE_BODY (t));
2270 finish_while_stmt (NULL_TREE);
2277 expand_stmt (DO_BODY (t));
2278 finish_do_body (NULL_TREE);
2279 finish_do_stmt (DO_COND (t), NULL_TREE);
2285 finish_if_stmt_cond (expand_cond (IF_COND (t)), NULL_TREE);
2286 if (THEN_CLAUSE (t))
2288 expand_stmt (THEN_CLAUSE (t));
2289 finish_then_clause (NULL_TREE);
2291 if (ELSE_CLAUSE (t))
2293 begin_else_clause ();
2294 expand_stmt (ELSE_CLAUSE (t));
2295 finish_else_clause (NULL_TREE);
2301 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
2302 expand_stmt (COMPOUND_BODY (t));
2303 rval = finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
2308 finish_break_stmt ();
2312 finish_continue_stmt ();
2319 begin_switch_stmt ();
2320 cond = expand_cond (SWITCH_COND (t));
2321 finish_switch_cond (cond, NULL_TREE);
2322 expand_stmt (SWITCH_BODY (t));
2323 finish_switch_stmt (cond, NULL_TREE);
2328 finish_case_label (CASE_LOW (t), CASE_HIGH (t));
2332 expand_label (LABEL_STMT_LABEL (t));
2336 finish_goto_stmt (GOTO_DESTINATION (t));
2340 finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS
2341 (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
2347 expand_eh_region_start ();
2348 expand_stmt (TRY_STMTS (t));
2349 finish_cleanup_try_block (NULL_TREE);
2350 finish_cleanup (TRY_HANDLERS (t), NULL_TREE);
2354 if (FN_TRY_BLOCK_P (t))
2355 begin_function_try_block ();
2359 expand_stmt (TRY_STMTS (t));
2361 if (FN_TRY_BLOCK_P (t))
2363 finish_function_try_block (NULL_TREE);
2364 expand_stmt (TRY_HANDLERS (t));
2365 finish_function_handler_sequence (NULL_TREE);
2369 finish_try_block (NULL_TREE);
2370 expand_stmt (TRY_HANDLERS (t));
2371 finish_handler_sequence (NULL_TREE);
2378 expand_stmt (HANDLER_BODY (t));
2379 finish_handler (NULL_TREE, NULL_TREE);
2383 finish_subobject (SUBOBJECT_CLEANUP (t));
2387 if (SCOPE_BEGIN_P (t))
2388 expand_start_bindings (2 * SCOPE_NULLIFIED_P (t));
2389 else if (SCOPE_END_P (t))
2390 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t), 0);
2393 case CTOR_INITIALIZER:
2394 current_member_init_list = TREE_OPERAND (t, 0);
2395 current_base_init_list = TREE_OPERAND (t, 1);
2400 /* Clear this out so that finish_named_return_value can set it
2402 DECL_NAME (DECL_RESULT (current_function_decl)) = NULL_TREE;
2403 finish_named_return_value (TREE_OPERAND (t, 0),
2404 TREE_OPERAND (t, 1));
2408 my_friendly_abort (19990810);
2412 /* Restore saved state. */
2413 stmts_are_full_exprs_p = saved_stmts_are_full_exprs_p;
2415 /* Go on to the next statement in this scope. */
2422 /* Generate RTL for FN. */
2429 char *saved_input_filename;
2431 /* When the parser calls us after finishing the body of a template
2432 function, we don't really want to expand the body. When we're
2433 processing an in-class definition of an inline function,
2434 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2435 to look at the function itself. */
2436 if (processing_template_decl
2437 || (DECL_LANG_SPECIFIC (fn)
2438 && DECL_TEMPLATE_INFO (fn)
2439 && uses_template_parms (DECL_TI_ARGS (fn))))
2442 /* Save the current file name and line number. When we expand the
2443 body of the funciton, we'll set LINENO and INPUT_FILENAME so that
2444 error-mesages come out in the right places. */
2445 saved_lineno = lineno;
2446 saved_input_filename = input_filename;
2447 lineno = DECL_SOURCE_LINE (fn);
2448 input_filename = DECL_SOURCE_FILE (fn);
2450 start_function (NULL_TREE, fn, NULL_TREE, SF_PRE_PARSED | SF_EXPAND);
2451 store_parm_decls ();
2453 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2454 any of the other magic variables we set up when starting a
2456 current_function_name_declared = 1;
2458 /* Expand the body. */
2459 expand_stmt (DECL_SAVED_TREE (fn));
2461 /* Statements should always be full-expressions at the outermost set
2462 of curly braces for a function. */
2463 my_friendly_assert (stmts_are_full_exprs_p, 19990831);
2465 /* The outermost statement for a function contains the line number
2466 recorded when we finished processing the function. */
2467 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2469 /* Generate code for the function. */
2470 finish_function (lineno, 0);
2472 /* And restore the current source position. */
2473 lineno = saved_lineno;
2474 input_filename = saved_input_filename;