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

TABLESWITCH.java

00001 package de.fub.bytecode.generic;
00002 
00003 import java.io.*;
00004 import de.fub.bytecode.util.ByteSequence;
00005 
00006 /** 
00007  * TABLESWITCH - Switch within given range of values, i.e., low..high
00008  *
00009  * @version $Id: TABLESWITCH.java,v 1.1.1.1 2002/01/24 03:41:42 pserver Exp $
00010  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00011  * @see SWITCH
00012  */
00013 public class TABLESWITCH extends Select {
00014   /**
00015    * Empty constructor needed for the Class.newInstance() statement in
00016    * Instruction.readInstruction(). Not to be used otherwise.
00017    */
00018   TABLESWITCH() {}  
00019   /**
00020    * @param match sorted array of match values, match[0] must be low value, 
00021    * match[match_length - 1] high value
00022    * @param targets where to branch for matched values
00023    * @param target default branch
00024    */
00025   public TABLESWITCH(int[] match, InstructionHandle[] targets,
00026              InstructionHandle target) {
00027     super(de.fub.bytecode.Constants.TABLESWITCH, match, targets, target);
00028     
00029     length = (short)(13 + match_length * 4); /* Alignment remainder assumed
00030                           * 0 here, until dump time */
00031     fixed_length = length;
00032   }  
00033   /**
00034    * Call corresponding visitor method(s). The order is:
00035    * Call visitor methods of implemented interfaces first, then
00036    * call methods according to the class hierarchy in descending order,
00037    * i.e., the most specific visitXXX() call comes last.
00038    *
00039    * @param v Visitor object
00040    */
00041   public void accept(Visitor v) {
00042     v.visitVariableLengthInstruction(this);
00043     v.visitStackProducer(this);
00044     v.visitInstructionTargeter(this);
00045     v.visitBranchInstruction(this);
00046     v.visitSelect(this);
00047     v.visitTABLESWITCH(this);
00048   }  
00049   /**
00050    * Dump instruction as byte code to stream out.
00051    * @param out Output stream
00052    */
00053   public void dump(DataOutputStream out) throws IOException {
00054     super.dump(out);
00055 
00056     out.writeInt(match[0]);                 // low
00057     out.writeInt(match[match_length - 1]);  // high
00058 
00059     for(int i=0; i < match_length; i++)     // jump offsets
00060       out.writeInt(indices[i] = getTargetOffset(targets[i]));
00061   }  
00062   /**
00063    * Read needed data (e.g. index) from file.
00064    */
00065   protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
00066   {
00067     super.initFromFile(bytes, wide);
00068 
00069     int low    = bytes.readInt();
00070     int high   = bytes.readInt();
00071 
00072     match_length = high - low + 1;
00073     fixed_length = (short)(13 + match_length * 4);
00074     length       = (short)(fixed_length + padding);
00075 
00076     match   = new int[match_length];
00077     indices = new int[match_length];
00078     targets = new InstructionHandle[match_length];
00079 
00080     for(int i=low; i <= high; i++)
00081       match[i - low] = i;
00082 
00083     for(int i=0; i < match_length; i++) {
00084       indices[i] = bytes.readInt();
00085     }
00086   }  
00087 }

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