Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

BranchHandle.java

00001 package de.fub.bytecode.generic;
00002 
00003 /**
00004  * BranchHandle is returned by specialized InstructionList.append() whenever a
00005  * BranchInstruction is appended. This is useful when the target of this
00006  * instruction is not known at time of creation and must be set later
00007  * via setTarget().
00008  *
00009  * @see InstructionHandle
00010  * @see Instruction
00011  * @see InstructionList
00012  * @version $Id: BranchHandle.java,v 1.1.1.1 2002/01/24 03:44:02 pserver Exp $
00013  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00014  */
00015 public final class BranchHandle extends InstructionHandle {
00016   private BranchInstruction bi; // An alias in fact, but saves lots of casts
00017 
00018   /** Factory methods.
00019    */
00020   private static BranchHandle bh_list = null; // List of reusable handles
00021 
00022   private BranchHandle(BranchInstruction i) {
00023     super(i);
00024     bi = i;
00025   }  
00026   /** Handle adds itself to the list of resuable handles.
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   /* Override InstructionHandle methods: delegate to branch instruction.
00045    * Through this overriding all access to the private i_position field should
00046    * be prevented.
00047    */
00048   /* Flavio Lerda - getPoition(int) made public */
00049   /* int getPosition() { return bi.position; } */
00050   public int getPosition() { return bi.position; }  
00051   /**
00052    * @return target of instruction.
00053    */
00054   public InstructionHandle getTarget() {
00055     return bi.getTarget();
00056   }  
00057   /** 
00058    * Set new contents. Old instruction is disposed and may not be used anymore.
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   /* Flavio Lerda - getPoition(int) made public */
00070 
00071   void setPosition(int pos) {
00072     i_position = bi.position = pos;
00073   }  
00074   /**
00075    * Pass new target to instruction.
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    * Update target of instruction.
00087    */
00088   public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
00089     bi.updateTarget(old_ih, new_ih);
00090   }  
00091 }

Generated at Thu Feb 7 06:41:12 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001