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:41:38 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 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    * 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   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    * @return true, if ih is target of this handler
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    * Get CodeException object.
00055    *
00056    * This relies on that the instruction list has already been dumped to byte code or
00057    * or that the `setPositions' methods has been called for the instruction list.
00058    *
00059    * @param cp constant pool
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    * @param old_ih old target, either start or end
00088    * @param new_ih new target
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 }

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