|
janino.net | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.janino.CodeContext
public class CodeContext
The context of the compilation of a function (constructor or method). Manages generation of byte code, the exception table, generation of line number tables, allocation of local variables, determining of stack size and local variable table size and flow analysis.
Nested Class Summary | |
---|---|
static interface |
CodeContext.FixUp
A throw-in interface that marks CodeContext.Offset s
as "fix-ups": During the execution of
fixUp() , all "fix-ups" are invoked and
can do last touches to the code attribute. |
class |
CodeContext.Inserter
A class that implements an insertion point into a "Code" attribute. |
class |
CodeContext.LineNumberOffset
|
class |
CodeContext.Offset
A class that represents an offset within a "Code" attribute. |
Constructor Summary | |
---|---|
CodeContext(ClassFile classFile)
Create an empty "Code" attribute. |
Method Summary | |
---|---|
void |
addExceptionTableEntry(CodeContext.Offset startPC,
CodeContext.Offset endPC,
CodeContext.Offset handlerPC,
java.lang.String catchTypeFD)
Add another entry to the "exception_table" of this code attribute (see JVMS 4.7.3). |
short |
allocateLocalVariable(short size)
Allocate space for a local variable of the given size (1 or 2) on the local variable array. |
Java.LocalVariableSlot |
allocateLocalVariable(short size,
java.lang.String name,
IClass type)
Allocate space for a local variable of the given size (1 or 2) on the local variable array. |
CodeContext.Inserter |
currentInserter()
|
void |
fixUpAndRelocate()
fixUp() all of the offsets and relocate() all relocatables |
void |
flowAnalysis(java.lang.String functionName)
Checks the code for consistency; updates the "maxStack" member. |
java.util.List |
getAllLocalVars()
|
ClassFile |
getClassFile()
|
void |
makeSpace(short lineNumber,
int size)
Add space for size bytes at current offset. |
CodeContext.Inserter |
newInserter()
Allocate an CodeContext.Inserter , set it to the current offset, and
insert it before the current offset. |
CodeContext.Offset |
newOffset()
|
void |
popInserter()
Replace the current CodeContext.Inserter with the remembered one (see
pushInserter(CodeContext.Inserter) ). |
void |
pushInserter(CodeContext.Inserter ins)
Remember the current CodeContext.Inserter , then replace it with the
new one. |
void |
restoreLocalVariables()
Restore the previous size of the local variables array. |
java.util.List |
saveLocalVariables()
Remember the current size of the local variables array. |
protected void |
storeCodeAttributeBody(java.io.DataOutputStream dos,
short lineNumberTableAttributeNameIndex,
short localVariableTableAttributeNameIndex)
|
protected ClassFile.AttributeInfo |
storeLocalVariableTable(java.io.DataOutputStream dos,
short localVariableTableAttributeNameIndex)
|
void |
write(short lineNumber,
byte b1)
Inserts a byte at the current insertion position. |
void |
write(short lineNumber,
byte[] b)
Inserts a sequence of bytes at the current insertion position. |
void |
write(short lineNumber,
byte b1,
byte b2)
Inserts bytes at the current insertion position. |
void |
write(short lineNumber,
byte b1,
byte b2,
byte b3)
Inserts bytes at the current insertion position. |
void |
write(short lineNumber,
byte b1,
byte b2,
byte b3,
byte b4)
Inserts bytes at the current insertion position. |
void |
writeBranch(short lineNumber,
int opcode,
CodeContext.Offset dst)
|
void |
writeOffset(short lineNumber,
CodeContext.Offset src,
CodeContext.Offset dst)
|
void |
writeShort(short lineNumber,
int v)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CodeContext(ClassFile classFile)
Method Detail |
---|
public ClassFile getClassFile()
public short allocateLocalVariable(short size)
saveLocalVariables()
and later restoreLocalVariables()
.
size
- The number of slots to allocate (1 or 2)
public Java.LocalVariableSlot allocateLocalVariable(short size, java.lang.String name, IClass type)
saveLocalVariables()
and later restoreLocalVariables()
.
size
- Number of slots to use (1 or 2)name
- The variable name, if it's null, the variable won't be written to the localvariabletabletype
- The variable type. if the name isn't null, the type is needed to write to the localvariabletablepublic java.util.List saveLocalVariables()
public void restoreLocalVariables()
protected void storeCodeAttributeBody(java.io.DataOutputStream dos, short lineNumberTableAttributeNameIndex, short localVariableTableAttributeNameIndex) throws java.io.IOException
dos
- lineNumberTableAttributeNameIndex
- 0 == don't generate a "LineNumberTable" attribute
java.io.IOException
protected ClassFile.AttributeInfo storeLocalVariableTable(java.io.DataOutputStream dos, short localVariableTableAttributeNameIndex)
public void flowAnalysis(java.lang.String functionName)
public void fixUpAndRelocate()
public void write(short lineNumber, byte[] b)
CodeContext.LineNumberOffset
s as necessary.
lineNumber
- The line number that corresponds to the byte code, or -1b
- public void write(short lineNumber, byte b1)
CodeContext.LineNumberOffset
s as necessary.
This method is an optimization to avoid allocating small byte[] and ease GC load.
lineNumber
- The line number that corresponds to the byte code, or -1b1
- public void write(short lineNumber, byte b1, byte b2)
CodeContext.LineNumberOffset
s as necessary.
This method is an optimization to avoid allocating small byte[] and ease GC load.
lineNumber
- The line number that corresponds to the byte code, or -1b1
- b2
- public void write(short lineNumber, byte b1, byte b2, byte b3)
CodeContext.LineNumberOffset
s as necessary.
This method is an optimization to avoid allocating small byte[] and ease GC load.
lineNumber
- The line number that corresponds to the byte code, or -1b1
- b2
- b3
- public void write(short lineNumber, byte b1, byte b2, byte b3, byte b4)
CodeContext.LineNumberOffset
s as necessary.
This method is an optimization to avoid allocating small byte[] and ease GC load.
lineNumber
- The line number that corresponds to the byte code, or -1b1
- b2
- b3
- b4
- public void makeSpace(short lineNumber, int size)
CodeContext.LineNumberOffset
s as necessary.
lineNumber
- The line number that corresponds to the byte code, or -1size
- The size in bytes to injectpublic void writeShort(short lineNumber, int v)
lineNumber
- The line number that corresponds to the byte code, or -1public void writeBranch(short lineNumber, int opcode, CodeContext.Offset dst)
lineNumber
- The line number that corresponds to the byte code, or -1public void writeOffset(short lineNumber, CodeContext.Offset src, CodeContext.Offset dst)
public CodeContext.Offset newOffset()
public CodeContext.Inserter newInserter()
CodeContext.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(CodeContext.Inserter)
the
CodeContext.Inserter
, then write again (which inserts bytes into the
"Code" attribute at the previously remembered position), and then
popInserter()
.
public CodeContext.Inserter currentInserter()
public void pushInserter(CodeContext.Inserter ins)
CodeContext.Inserter
, then replace it with the
new one.
public void popInserter()
CodeContext.Inserter
with the remembered one (see
pushInserter(CodeContext.Inserter)
).
public void addExceptionTableEntry(CodeContext.Offset startPC, CodeContext.Offset endPC, CodeContext.Offset handlerPC, java.lang.String catchTypeFD)
startPC
- endPC
- handlerPC
- catchTypeFD
- public java.util.List getAllLocalVars()
|
janino.net | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |