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

CodeExceptionGen.java

00001 package de.fub.bytecode.generic;
00002 
00003 import de.fub.bytecode.Constants;
00004 import de.fub.bytecode.classfile.*;
00005 
00006 /** 
00007  * This class represents an exception handler, i.e. specifies the  region where
00008  * a handler is active and an instruction where the actual handling is done.
00009  * pool as parameters.
00010  *
00011  * @version $Id: CodeExceptionGen.java,v 1.1.1.1 2002/01/24 03:44:02 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  * @see     MethodGen
00014  * @see     CodeException
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    * Add an exception handler, i.e. specify region where a handler is active and an
00024    * instruction where the actual handling is done.
00025    *
00026    * @param start_pc Start of region
00027    * @param end_pc End of region
00028    * @param handler_pc Where handling is done
00029    * @param catch_type which exception is handled
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    * @return true, if ih is target of this handler
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    * Get CodeException object.
00047    *
00048    * This relies on that the instruction list has already been dumped to byte code or
00049    * or that the `setPositions' methods has been called for the instruction list.
00050    *
00051    * @param cp constant pool
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    * @param old_ih old target, either start or end
00080    * @param new_ih new target
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 }

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