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 InstructionTargeter, Cloneable {
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 public Object clone() {
00039 try {
00040 return super.clone();
00041 } catch(CloneNotSupportedException e) {
00042 System.err.println(e);
00043 return null;
00044 }
00045 }
00046
00047
00048
00049 public boolean containsTarget(InstructionHandle ih) {
00050 return (start_pc == ih) || (end_pc == ih) || (handler_pc == ih);
00051 }
00052 public ObjectType getCatchType() { return catch_type; }
00053
00054
00055
00056
00057
00058
00059
00060
00061 public CodeException getCodeException(ConstantPoolGen cp) {
00062 return new CodeException(start_pc.getPosition(),
00063 end_pc.getPosition(),
00064 handler_pc.getPosition(),
00065 (catch_type == null)? 0 : cp.addClass(catch_type));
00066 }
00067 public InstructionHandle getEndPC() { return end_pc; }
00068 public InstructionHandle getHandlerPC() { return handler_pc; }
00069 public InstructionHandle getStartPC() { return start_pc; }
00070 public void setCatchType(ObjectType catch_type) { this.catch_type = catch_type; }
00071 public void setEndPC(InstructionHandle end_pc) {
00072 BranchInstruction.notifyTarget(this.end_pc, end_pc, this);
00073 this.end_pc = end_pc;
00074 }
00075 public void setHandlerPC(InstructionHandle handler_pc) {
00076 BranchInstruction.notifyTarget(this.handler_pc, handler_pc, this);
00077 this.handler_pc = handler_pc;
00078 }
00079 public void setStartPC(InstructionHandle start_pc) {
00080 BranchInstruction.notifyTarget(this.start_pc, start_pc, this);
00081 this.start_pc = start_pc;
00082 }
00083 public String toString() {
00084 return "CodeExceptionGen(" + start_pc + ", " + end_pc + ", " + handler_pc + ")";
00085 }
00086
00087
00088
00089
00090 public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
00091 boolean targeted = false;
00092
00093 if(start_pc == old_ih) {
00094 targeted = true;
00095 setStartPC(new_ih);
00096 }
00097
00098 if(end_pc == old_ih) {
00099 targeted = true;
00100 setEndPC(new_ih);
00101 }
00102
00103 if(handler_pc == old_ih) {
00104 targeted = true;
00105 setHandlerPC(new_ih);
00106 }
00107
00108 if(!targeted)
00109 throw new ClassGenException("Not targeting " + old_ih + ", but {" + start_pc + ", " +
00110 end_pc + ", " + handler_pc + "}");
00111 }
00112 }