00001 package de.fub.bytecode.generic;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 public final class BranchHandle extends InstructionHandle {
00016 private BranchInstruction bi;
00017
00018
00019
00020 private static BranchHandle bh_list = null;
00021
00022 private BranchHandle(BranchInstruction i) {
00023 super(i);
00024 bi = i;
00025 }
00026
00027
00028 protected void addHandle() {
00029 next = bh_list;
00030 bh_list = this;
00031 }
00032 static final BranchHandle getBranchHandle(BranchInstruction i) {
00033 if(bh_list == null)
00034 return new BranchHandle(i);
00035 else {
00036 BranchHandle bh = bh_list;
00037 bh_list = (BranchHandle)bh.next;
00038
00039 bh.setInstruction(i);
00040
00041 return bh;
00042 }
00043 }
00044
00045
00046
00047
00048
00049
00050 public int getPosition() { return bi.position; }
00051
00052
00053
00054 public InstructionHandle getTarget() {
00055 return bi.getTarget();
00056 }
00057
00058
00059
00060 public void setInstruction(Instruction i) {
00061 super.setInstruction(i);
00062
00063 if(!(i instanceof BranchInstruction))
00064 throw new ClassGenException("Assigning " + i +
00065 " to branch handle which is not a branch instruction");
00066
00067 bi = (BranchInstruction)i;
00068 }
00069
00070
00071 void setPosition(int pos) {
00072 i_position = bi.position = pos;
00073 }
00074
00075
00076
00077 public void setTarget(InstructionHandle ih) {
00078 bi.setTarget(ih);
00079 }
00080 protected int updatePosition(int offset, int max_offset) {
00081 int x = bi.updatePosition(offset, max_offset);
00082 i_position = bi.position;
00083 return x;
00084 }
00085
00086
00087
00088 public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
00089 bi.updateTarget(old_ih, new_ih);
00090 }
00091 }