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

LOOKUPSWITCH.java

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

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