TryState.java 1.7 KB

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