+2004-06-29 Andrew Haley <aph@redhat.com>
+
+ * except.c (expand_start_java_handler): Push a new binding level.
+ Don't build a TRY_CATCH_EXPR now, we'll do it later. Call
+ register_exception_range() to register where we'll do it.
+ (expand_end_java_handler): Remove old bogus code. Replace with
+ new logic that simply builds TRY_CATCH_EXPRs and inserts them at
+ the top of the expression we're curently building.
+ (maybe_end_try): Delete.
+ * decl.c (binding_level.exception_range): New field.
+ (clear_binding_level): Add field exception_range. Reformat.
+ (poplevel): Call expand_end_java_handler().
+ (poplevel): Call java_add_stmt only if functionbody is false.
+ (maybe_poplevels): Don't call maybe_end_try() from here.
+ (end_java_method): Clear no longer used trees in function decl.
+ (register_exception_range): New function.
+ * java-tree.h (register_exception_range, struct eh_range): Declare.
+
2004-06-28 Bryce McKinlay <mckinlay@redhat.com>
* jcf-write.c (get_classfile_modifiers): Formatting fixes.
/* The statements in this binding level. */
tree stmts;
+ /* An exception range associated with this binding level. */
+ struct eh_range * GTY((skip (""))) exception_range;
+
/* Binding depth at which this level began. Used only for debugging. */
unsigned binding_depth;
};
/* Binding level structures are initialized by copying this one. */
static const struct binding_level clear_binding_level
- = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
- NULL_BINDING_LEVEL, LARGEST_PC, 0, NULL_TREE, 0};
+= {
+ NULL_TREE, /* names */
+ NULL_TREE, /* shadowed */
+ NULL_TREE, /* blocks */
+ NULL_TREE, /* this_lock */
+ NULL_BINDING_LEVEL, /* level_chain */
+ LARGEST_PC, /* end_pc */
+ 0, /* start_pc */
+ NULL, /* stmts */
+ NULL, /* exception_range */
+ 0, /* binding_depth */
+ };
#if 0
/* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
TREE_TYPE (block) = void_type_node;
}
+ if (current_binding_level->exception_range)
+ expand_end_java_handler (current_binding_level->exception_range);
+
if (block != 0)
{
/* If any statements have been generated at this level, create a
bind = build (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block),
BLOCK_EXPR_BODY (block), block);
-
BIND_EXPR_BODY (bind) = current_binding_level->stmts;
if (BIND_EXPR_BODY (bind)
DECL_INITIAL (current_function_decl) = block;
DECL_SAVED_TREE (current_function_decl) = bind;
}
- else if (block)
+ else
{
- if (!block_previously_created)
- current_binding_level->blocks
- = chainon (current_binding_level->blocks, block);
+ if (block)
+ {
+ if (!block_previously_created)
+ current_binding_level->blocks
+ = chainon (current_binding_level->blocks, block);
+ }
+ /* If we did not make a block for the level just exited,
+ any blocks made for inner levels
+ (since they cannot be recorded as subblocks in that level)
+ must be carried forward so they will later become subblocks
+ of something else. */
+ else if (subblocks)
+ current_binding_level->blocks
+ = chainon (current_binding_level->blocks, subblocks);
+
+ if (bind)
+ java_add_stmt (bind);
}
- /* If we did not make a block for the level just exited,
- any blocks made for inner levels
- (since they cannot be recorded as subblocks in that level)
- must be carried forward so they will later become subblocks
- of something else. */
- else if (subblocks)
- current_binding_level->blocks
- = chainon (current_binding_level->blocks, subblocks);
-
- if (bind)
- java_add_stmt (bind);
-
+
if (block)
TREE_USED (block) = 1;
return block;
#endif
while (current_binding_level->end_pc <= pc)
- {
- maybe_end_try (current_binding_level->start_pc, pc);
- poplevel (1, 0, 0);
- }
- maybe_end_try (0, pc);
+ poplevel (1, 0, 0);
}
/* Terminate any binding which began during the range beginning at
flag_unit_at_a_time = 0;
finish_method (fndecl);
+ if (! flag_unit_at_a_time)
+ {
+ /* Nulling these fields when we no longer need them saves
+ memory. */
+ DECL_SAVED_TREE (fndecl) = NULL;
+ DECL_STRUCT_FUNCTION (fndecl) = NULL;
+ DECL_INITIAL (fndecl) = NULL_TREE;
+ }
current_function_decl = NULL_TREE;
}
return ¤t_binding_level->stmts;
}
+/* Register an exception range as belonging to the current binding
+ level. There may only be one: if there are more, we'll create more
+ binding levels. However, each range can have multiple handlers,
+ and these are expanded when we call expand_end_java_handler(). */
+
+void
+register_exception_range (struct eh_range *range, int pc, int end_pc)
+{
+ if (current_binding_level->exception_range)
+ abort ();
+ current_binding_level->exception_range = range;
+ current_binding_level->end_pc = end_pc;
+ current_binding_level->start_pc = pc;
+}
#include "gt-java-decl.h"
#include "toplev.h"
static void expand_start_java_handler (struct eh_range *);
-static void expand_end_java_handler (struct eh_range *);
static struct eh_range *find_handler_in_range (int, struct eh_range *,
struct eh_range *);
static void link_handler (struct eh_range *, struct eh_range *);
fprintf (stderr, "expand start handler pc %d --> %d\n",
current_pc, range->end_pc);
#endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
- {
- tree new = build (TRY_CATCH_EXPR, void_type_node, NULL, NULL);
- TREE_SIDE_EFFECTS (new) = 1;
- java_add_stmt (build_java_empty_stmt ());
- range->stmt = java_add_stmt (new);
- }
-
+ pushlevel (0);
+ register_exception_range (range, range->start_pc, range->end_pc);
range->expanded = 1;
}
/* If there are any handlers for this range, isssue end of range,
and then all handler blocks */
-static void
+void
expand_end_java_handler (struct eh_range *range)
{
tree handler = range->handlers;
- tree compound = NULL;
- force_poplevels (range->start_pc);
for ( ; handler != NULL_TREE; handler = TREE_CHAIN (handler))
{
/* For bytecode we treat exceptions a little unusually. A
extra (and difficult) work to get this to look like a
gcc-style finally clause. */
tree type = TREE_PURPOSE (handler);
-
if (type == NULL)
type = throwable_type_node;
-
type = prepare_eh_table_type (type);
- if (compound)
- {
- /* If we already have a COMPOUND there is more than one
- catch handler for this try block. Wrap the
- TRY_CATCH_EXPR in operand 1 of COMPOUND with another
- TRY_CATCH_EXPR. */
- tree inner_try_expr = TREE_OPERAND (compound, 1);
- tree catch_expr
- = build (CATCH_EXPR, void_type_node, type,
- build (GOTO_EXPR, void_type_node, TREE_VALUE (handler)));
- tree try_expr
- = build (TRY_CATCH_EXPR, void_type_node,
- inner_try_expr, catch_expr);
- TREE_OPERAND (compound, 1) = try_expr;
- }
- else
- {
- tree *stmts = get_stmts ();
- tree outer;
- tree try_expr;
- compound = range->stmt;
- outer = TREE_OPERAND (compound, 0);
- try_expr = TREE_OPERAND (compound, 1);
- /* On the left of COMPOUND is the expresion to be evaluated
- before the try handler is entered; on the right is a
- TRY_FINALLY_EXPR with no operands as yet. In the current
- statement list is an expression that we're going to move
- inside the try handler. We'll create a new COMPOUND_EXPR
- with the outer context on the left and the TRY_FINALLY_EXPR
- on the right, then nullify both operands of COMPOUND, which
- becomes the final expression in OUTER. This new compound
- expression replaces the current statement list. */
- TREE_OPERAND (try_expr, 0) = *stmts;
- TREE_OPERAND (try_expr, 1)
- = build (CATCH_EXPR, void_type_node, type,
- build (GOTO_EXPR, void_type_node, TREE_VALUE (handler)));
- TREE_SIDE_EFFECTS (try_expr) = 1;
- TREE_OPERAND (compound, 0) = build_java_empty_stmt ();
- TREE_OPERAND (compound, 1) = build_java_empty_stmt ();
- compound
- = build (COMPOUND_EXPR, TREE_TYPE (try_expr), outer, try_expr);
- *stmts = compound;
- }
+ {
+ tree catch_expr
+ = build (CATCH_EXPR, void_type_node, type,
+ build (GOTO_EXPR, void_type_node, TREE_VALUE (handler)));
+ tree try_catch_expr = build (TRY_CATCH_EXPR, void_type_node,
+ *get_stmts (), catch_expr);
+ *get_stmts () = try_catch_expr;
+ }
}
#if defined(DEBUG_JAVA_BINDING_LEVELS)
indent ();
check_start_handlers (range, start_pc);
}
-/* Emit any end-of-try-range ending at end_pc and starting before
- start_pc. */
-
-void
-maybe_end_try (int start_pc, int end_pc)
-{
- if (! doing_eh (1))
- return;
-
- while (current_range != NULL_EH_RANGE && current_range->end_pc <= end_pc
- && current_range->start_pc >= start_pc)
- {
- expand_end_java_handler (current_range);
- current_range = current_range->outer;
- }
-}
extern void add_handler (int, int, tree, tree);
extern void handle_nested_ranges (void);
extern void expand_resume_after_catch (void);
+extern void expand_end_java_handler (struct eh_range *);
#define SEARCH_SUPER 2
#define SEARCH_VISIBLE 4
+/* Defined in java-except.h */
+struct eh_range;
+
extern void java_parse_file (int);
extern bool java_mark_addressable (tree);
extern tree java_type_for_mode (enum machine_mode, int);
extern tree java_add_stmt (tree);
extern tree java_add_local_var (tree decl);
extern tree *get_stmts (void);
+extern void register_exception_range(struct eh_range *, int, int);
extern void finish_method (tree);
extern void java_expand_body (tree);