net.janino
Class ClassFile.CodeAttribute

java.lang.Object
  |
  +--net.janino.ClassFile.AttributeInfo
        |
        +--net.janino.ClassFile.CodeAttribute
Enclosing class:
ClassFile

public class ClassFile.CodeAttribute
extends net.janino.ClassFile.AttributeInfo

A representation of a "Code" attribute. Supplies several "write()" methods, similar to an OutputStream, plus ClassFile.CodeAttribute.Offsets and ClassFile.CodeAttribute.Inserters, which allow for very flexible generation of bytecode.


Inner Class Summary
 class ClassFile.CodeAttribute.Inserter
          A class that implements an insertion point into a "Code" attribute.
 class ClassFile.CodeAttribute.Offset
          A class that represents an offset within a "Code" attribute.
 
Constructor Summary
ClassFile.CodeAttribute()
          Create an empty "Code" attribute.
 
Method Summary
(package private)  void ()
           
 void addException(ClassFile.CodeAttribute.Offset startPC, ClassFile.CodeAttribute.Offset endPC, ClassFile.CodeAttribute.Offset handlerPC, java.lang.String catchTypeFD)
           
 short allocateLocalVariable(short size)
          Allocate space for a local variable of the given size (1 or 2) on the local variable array.
 void fixUp()
           
 void flowAnalysis()
          Checks the code for consistency; updates the "maxStack" member.
 ClassFile getClassFile()
           
 ClassFile.CodeAttribute.Inserter newInserter()
          Allocate an ClassFile.CodeAttribute.Inserter, set it to the current offset, and insert it before the current offset.
 ClassFile.CodeAttribute.Offset newOffset()
           
 void popInserter()
          Replace the current ClassFile.CodeAttribute.Inserter with the remembered one (see pushInserter(ClassFile.CodeAttribute.Inserter)).
 void pushInserter(ClassFile.CodeAttribute.Inserter ins)
          Remember the current ClassFile.CodeAttribute.Inserter, then replace it with the new one.
 void relocate()
           
 void restoreLocalVariables()
          Restore the previous size of the local variables array.
 void saveLocalVariables()
          Remember the current size of the local variables array.
 void store(java.io.DataOutputStream dos)
           
protected  void storeBody(java.io.DataOutputStream dos)
           
 void write(byte[] b)
           
 void write(int b)
           
 void writeBranch(int opcode, ClassFile.CodeAttribute.Offset dst)
           
 void writeByte(int v)
           
 void writeChar(int v)
           
 void writeDouble(double v)
           
 void writeFloat(float v)
           
 void writeInt(int v)
           
 void writeLong(long v)
           
 void writeOffset(ClassFile.CodeAttribute.Offset src, ClassFile.CodeAttribute.Offset dst)
           
 void writeOpcode(int opcode)
           
 void writeShort(int v)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFile.CodeAttribute

public ClassFile.CodeAttribute()
Create an empty "Code" attribute.
Method Detail

allocateLocalVariable

public short allocateLocalVariable(short size)
Allocate space for a local variable of the given size (1 or 2) on the local variable array. As a side effect, the "max_locals" field of the "Code" attribute is updated. The only way to deallocate local variables is to saveLocalVariables() and later restoreLocalVariables().

saveLocalVariables

public void saveLocalVariables()
Remember the current size of the local variables array.

restoreLocalVariables

public void restoreLocalVariables()
Restore the previous size of the local variables array.

storeBody

protected void storeBody(java.io.DataOutputStream dos)
                  throws java.io.IOException
Overrides:
storeBody in class net.janino.ClassFile.AttributeInfo

flowAnalysis

public void flowAnalysis()
Checks the code for consistency; updates the "maxStack" member. Notice: On inconsistencies, a "RuntimeException" is thrown (KLUDGE).

fixUp

public void fixUp()

relocate

public void relocate()

write

public void write(byte[] b)

write

public void write(int b)

writeByte

public void writeByte(int v)

writeChar

public void writeChar(int v)

writeDouble

public void writeDouble(double v)

writeFloat

public void writeFloat(float v)

writeInt

public void writeInt(int v)

writeLong

public void writeLong(long v)

writeShort

public void writeShort(int v)

writeOpcode

public void writeOpcode(int opcode)

writeBranch

public void writeBranch(int opcode,
                        ClassFile.CodeAttribute.Offset dst)

writeOffset

public void writeOffset(ClassFile.CodeAttribute.Offset src,
                        ClassFile.CodeAttribute.Offset dst)

newOffset

public ClassFile.CodeAttribute.Offset newOffset()

newInserter

public ClassFile.CodeAttribute.Inserter newInserter()
Allocate an ClassFile.CodeAttribute.Inserter, set it to the current offset, and insert it before the current offset. In clear text, this means that you can continue writing to the "Code" attribute, then pushInserter(ClassFile.CodeAttribute.Inserter) the ClassFile.CodeAttribute.Inserter, then write again (which inserts bytes into the "Code" attribute at the previously remembered position), and then popInserter().

pushInserter

public void pushInserter(ClassFile.CodeAttribute.Inserter ins)
Remember the current ClassFile.CodeAttribute.Inserter, then replace it with the new one.

popInserter

public void popInserter()
Replace the current ClassFile.CodeAttribute.Inserter with the remembered one (see pushInserter(ClassFile.CodeAttribute.Inserter)).

addException

public void addException(ClassFile.CodeAttribute.Offset startPC,
                         ClassFile.CodeAttribute.Offset endPC,
                         ClassFile.CodeAttribute.Offset handlerPC,
                         java.lang.String catchTypeFD)

void ()
Overrides:
in class java.lang.Object

getClassFile

public ClassFile getClassFile()

store

public void store(java.io.DataOutputStream dos)
           throws java.io.IOException