00001 package de.fub.bytecode.generic;
00002
00003 import de.fub.bytecode.Constants;
00004 import de.fub.bytecode.classfile.*;
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 public final class CodeExceptionGen implements Constants, InstructionTargeter {
00017 private InstructionHandle start_pc;
00018 private InstructionHandle end_pc;
00019 private InstructionHandle handler_pc;
00020 private ObjectType catch_type;
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 public CodeExceptionGen(InstructionHandle start_pc, InstructionHandle end_pc,
00032 InstructionHandle handler_pc, ObjectType catch_type) {
00033 setStartPC(start_pc);
00034 setEndPC(end_pc);
00035 setHandlerPC(handler_pc);
00036 this.catch_type = catch_type;
00037 }
00038
00039
00040
00041 public boolean containsTarget(InstructionHandle ih) {
00042 return (start_pc == ih) || (end_pc == ih) || (handler_pc == ih);
00043 }
00044 public ObjectType getCatchType() { return catch_type; }
00045
00046
00047
00048
00049
00050
00051
00052
00053 public CodeException getCodeException(ConstantPoolGen cp) {
00054 return new CodeException(start_pc.getPosition(),
00055 end_pc.getPosition(),
00056 handler_pc.getPosition(),
00057 (catch_type == null)? 0 : cp.addClass(catch_type));
00058 }
00059 public InstructionHandle getEndPC() { return end_pc; }
00060 public InstructionHandle getHandlerPC() { return handler_pc; }
00061 public InstructionHandle getStartPC() { return start_pc; }
00062 public void setCatchType(ObjectType catch_type) { this.catch_type = catch_type; }
00063 public void setEndPC(InstructionHandle end_pc) {
00064 BranchInstruction.notifyTarget(this.end_pc, end_pc, this);
00065 this.end_pc = end_pc;
00066 }
00067 public void setHandlerPC(InstructionHandle handler_pc) {
00068 BranchInstruction.notifyTarget(this.handler_pc, handler_pc, this);
00069 this.handler_pc = handler_pc;
00070 }
00071 public void setStartPC(InstructionHandle start_pc) {
00072 BranchInstruction.notifyTarget(this.start_pc, start_pc, this);
00073 this.start_pc = start_pc;
00074 }
00075 public String toString() {
00076 return "CodeExceptionGen(" + start_pc + ", " + end_pc + ", " + handler_pc + ")";
00077 }
00078
00079
00080
00081
00082 public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
00083 boolean targeted = false;
00084
00085 if(start_pc == old_ih) {
00086 targeted = true;
00087 setStartPC(new_ih);
00088 }
00089
00090 if(end_pc == old_ih) {
00091 targeted = true;
00092 setEndPC(new_ih);
00093 }
00094
00095 if(handler_pc == old_ih) {
00096 targeted = true;
00097 setHandlerPC(new_ih);
00098 }
00099
00100 if(!targeted)
00101 throw new ClassGenException("Not targeting " + old_ih + ", but {" + start_pc + ", " +
00102 end_pc + ", " + handler_pc + "}");
00103 }
00104 }