FileDocCategorySizeDatePackage
LocalVariableInstruction.javaAPI DocJava SE 6 API7800Tue Jun 10 00:22:22 BST 2008com.sun.org.apache.bcel.internal.generic

LocalVariableInstruction

public abstract class LocalVariableInstruction extends Instruction implements TypedInstruction, IndexedInstruction
Abstract super class for instructions dealing with local variables.
version
$Id: LocalVariableInstruction.java,v 1.1.2.1 2005/07/31 23:45:45 jeffsuttor Exp $
author
M. Dahm

Fields Summary
protected int
n
private short
c_tag
private short
canon_tag
Constructors Summary
LocalVariableInstruction(short canon_tag, short c_tag)
Empty constructor needed for the Class.newInstance() statement in Instruction.readInstruction(). Not to be used otherwise. tag and length are defined in readInstruction and initFromFile, respectively.

    super();
    this.canon_tag = canon_tag;
    this.c_tag     = c_tag;
  
LocalVariableInstruction()
Empty constructor needed for the Class.newInstance() statement in Instruction.readInstruction(). Also used by IINC()!

  
protected LocalVariableInstruction(short opcode, short c_tag, int n)

param
opcode Instruction opcode
param
c_tag Instruction number for compact version, ALOAD_0, e.g.
param
n local variable index (unsigned short)

    super(opcode, (short)2);

    this.c_tag = c_tag;
    canon_tag  = opcode;

    setIndex(n);
  
Methods Summary
public voiddump(java.io.DataOutputStream out)
Dump instruction as byte code to stream out.

param
out Output stream

    if(wide()) // Need WIDE prefix ?
      out.writeByte(Constants.WIDE);

    out.writeByte(opcode);

    if(length > 1) { // Otherwise ILOAD_n, instruction, e.g.
      if(wide())
	out.writeShort(n);
      else
	out.writeByte(n);
    }
  
public shortgetCanonicalTag()

return
canonical tag for instruction, e.g., ALOAD for ALOAD_0

    return canon_tag;
  
public final intgetIndex()

return
local variable index referred by this instruction.

 return n; 
public com.sun.org.apache.bcel.internal.generic.TypegetType(com.sun.org.apache.bcel.internal.generic.ConstantPoolGen cp)
Returns the type associated with the instruction - in case of ALOAD or ASTORE Type.OBJECT is returned. This is just a bit incorrect, because ALOAD and ASTORE may work on every ReferenceType (including Type.NULL) and ASTORE may even work on a ReturnaddressType .

return
type associated with the instruction

    switch(canon_tag) {
    case Constants.ILOAD: case Constants.ISTORE: 
      return Type.INT;
    case Constants.LLOAD: case Constants.LSTORE: 
      return Type.LONG;
    case Constants.DLOAD: case Constants.DSTORE: 
      return Type.DOUBLE;
    case Constants.FLOAD: case Constants.FSTORE: 
      return Type.FLOAT;
    case Constants.ALOAD: case Constants.ASTORE:
      return Type.OBJECT;

    default: throw new ClassGenException("Oops: unknown case in switch" + canon_tag);
    }
  
protected voidinitFromFile(com.sun.org.apache.bcel.internal.util.ByteSequence bytes, boolean wide)
Read needed data (e.g. index) from file. PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3)

    if(wide) {
      n         = bytes.readUnsignedShort();
      length    = 4;
    } else if(((opcode >= Constants.ILOAD) &&
	       (opcode <= Constants.ALOAD)) ||
	      ((opcode >= Constants.ISTORE) &&
	       (opcode <= Constants.ASTORE))) {
      n      = bytes.readUnsignedByte();
      length = 2;
    } else if(opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2
      n      = (opcode - Constants.ILOAD_0) % 4;
      length = 1;
    } else { // Assert ISTORE_0 <= tag <= ASTORE_3
      n      = (opcode - Constants.ISTORE_0) % 4;
      length = 1;
    }
 
public voidsetIndex(int n)
Set the local variable index

 
    if((n < 0) || (n > Constants.MAX_SHORT))
      throw new ClassGenException("Illegal value: " + n);

    this.n = n;

    if(n >= 0 && n <= 3) { // Use more compact instruction xLOAD_n
      opcode = (short)(c_tag + n);
      length = 1;
    } else {
      opcode = canon_tag;
      
      if(wide()) // Need WIDE prefix ?
	length = 4;
      else
	length = 2;
    }
  
public java.lang.StringtoString(boolean verbose)
Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"< local variable index>">"

param
verbose long/short format switch
return
mnemonic for instruction

    if(((opcode >= Constants.ILOAD_0) &&
	(opcode <= Constants.ALOAD_3)) ||
       ((opcode >= Constants.ISTORE_0) &&
	(opcode <= Constants.ASTORE_3)))
      return super.toString(verbose);
    else
      return super.toString(verbose) + " " + n;
  
private final booleanwide()

 // canonical tag such as ILOAD

       return n > Constants.MAX_BYTE;