1 // Copyright (c) 1997 Per M.A. Bothner. 2 // This is free software; for terms and warranty disclaimer see ./COPYING. 3 4 package gnu.bytecode; 5 6 /** The state of a try statement. */ 7 8 public class TryState { 9 /** The surrounding TryState, if any. */ 10 TryState previous; 11 12 /** The label for the code following the entire try-statement. 13 * Allocated lazily: If null, the following code is unreachable. 14 */ 15 Label end_label; 16 17 /** If this "try" has a "finally", the Label of the "finally" sub-routine. */ 18 Label finally_subr; 19 20 /** Used for the return address of the finally subroutine (if any). */ 21 Variable finally_ret_addr; 22 23 /** Non-null if we need a temporary to save the result. */ 24 Variable saved_result; 25 26 /** If the {@code SP > 0} when we entered the try, the stack is saved here. */ 27 Variable[] savedStack; 28 29 Label start_try; 30 Label end_try; 31 32 /** If we are inside a try, the type of variable matched. */ 33 ClassType try_type; 34 35 /** Only used in emitWithCleanupStart mode. */ 36 Type[] savedTypes; 37 38 ExitableBlock exitCases; 39 40 Variable exception; 41 42 boolean tryClauseDone; 43 TryState(CodeAttr code)44 public TryState (CodeAttr code) 45 { 46 previous = code.try_stack; 47 code.try_stack = this; 48 start_try = code.getLabel(); 49 } 50 51 /* Skip TryStates without finally blocks, or if we're no longer in 52 * the try-clause. */ outerHandler(TryState innerTry, TryState outerTry)53 static TryState outerHandler (TryState innerTry, TryState outerTry) 54 { 55 while (innerTry != outerTry 56 && (innerTry.finally_subr == null || innerTry.tryClauseDone)) 57 innerTry = innerTry.previous; 58 return innerTry; 59 } 60 61 /* DEBUGGING: 62 static int counter; int id=++counter; 63 public String toString() { return "TryState#"+id; } 64 */ 65 } 66