|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.groovy.classgen.CompileStack
public class CompileStack
This class is a helper for AsmClassGenerator. It manages different aspects of the code of a code block like handling labels, defining variables, and scopes. After a MethodNode is visited clear should be called, for initialization the method init should be used.
Some Notes:
AsmClassGenerator
Nested Class Summary | |
---|---|
private class |
CompileStack.StateStackElement
|
Field Summary | |
---|---|
private org.objectweb.asm.Label |
breakLabel
|
private java.lang.String |
className
|
private boolean |
clear
|
private org.objectweb.asm.Label |
continueLabel
|
private java.util.Map |
currentBlockNamedLabels
|
private int |
currentClassIndex
|
private int |
currentMetaClassIndex
|
private int |
currentVariableIndex
|
private java.util.LinkedList |
finallyBlocks
|
private BytecodeHelper |
helper
|
private int |
localVariableOffset
|
private org.objectweb.asm.MethodVisitor |
mv
|
private java.util.Map |
namedLoopBreakLabel
|
private java.util.Map |
namedLoopContinueLabel
|
private int |
nextVariableIndex
|
private VariableScope |
scope
|
private java.util.Map |
stackVariables
|
private java.util.LinkedList |
stateStack
|
private java.util.Map |
superBlockNamedLabels
|
private java.util.LinkedList |
temporaryVariables
|
private org.objectweb.asm.Label |
thisEndLabel
|
private org.objectweb.asm.Label |
thisStartLabel
|
private java.util.LinkedList |
usedVariables
|
private java.util.List |
visitedBlocks
|
Fields inherited from interface org.objectweb.asm.Opcodes |
---|
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6 |
Constructor Summary | |
---|---|
CompileStack()
|
Method Summary | |
---|---|
void |
applyFinallyBlocks()
|
void |
applyFinallyBlocks(org.objectweb.asm.Label label,
boolean isBreakLabel)
|
private void |
applyFinallyBlocks(java.util.List blocks)
|
void |
clear()
Clears the state of the class. |
boolean |
containsVariable(java.lang.String name)
|
org.objectweb.asm.Label |
createLocalLabel(java.lang.String name)
creates a new named label |
private void |
createReference(Variable reference)
|
private void |
defineMethodVariables(Parameter[] paras,
boolean isInStaticContext)
|
int |
defineTemporaryVariable(java.lang.String name,
boolean store)
creates a temporary variable. |
int |
defineTemporaryVariable(java.lang.String name,
ClassNode node,
boolean store)
creates a temporary variable. |
int |
defineTemporaryVariable(Variable var,
boolean store)
creates a temporary variable. |
private Variable |
defineVar(java.lang.String name,
ClassNode type,
boolean methodParameterUsedInClosure)
|
Variable |
defineVariable(Variable v,
boolean initFromStack)
Defines a new Variable using an AST variable. |
org.objectweb.asm.Label |
getBreakLabel()
|
org.objectweb.asm.Label |
getContinueLabel()
|
int |
getCurrentClassIndex()
|
int |
getCurrentMetaClassIndex()
|
org.objectweb.asm.Label |
getLabel(java.lang.String name)
Returns the label for the given name |
protected org.objectweb.asm.Label |
getNamedBreakLabel(java.lang.String name)
Used for break foo inside a loop to end the
execution of the marked loop. |
protected org.objectweb.asm.Label |
getNamedContinueLabel(java.lang.String name)
Used for continue foo inside a loop to continue
the execution of the marked loop. |
VariableScope |
getScope()
|
Variable |
getVariable(java.lang.String variableName)
|
Variable |
getVariable(java.lang.String variableName,
boolean mustExist)
returns a normal variable, that was defined before. |
boolean |
hasFinallyBlocks()
|
protected void |
init(VariableScope el,
Parameter[] parameters,
org.objectweb.asm.MethodVisitor mv,
ClassNode cn)
initializes this class for a MethodNode. |
private void |
initLoopLabels(java.lang.String labelName)
|
private void |
makeLocalVariablesOffset(Parameter[] paras,
boolean isInStaticContext)
|
private void |
makeNextVariableID(ClassNode type)
Calculates the index of the next free register stores ir and sets the current variable index to the old value |
void |
pop()
|
void |
popFinallyBlock()
|
void |
popFinallyBlockVisit(java.lang.Runnable block)
|
private void |
popState()
|
protected void |
pushBooleanExpression()
because a boolean Expression may not be evaluated completly it is important to keep the registers clean |
void |
pushFinallyBlock(java.lang.Runnable block)
|
void |
pushFinallyBlockVisit(java.lang.Runnable block)
|
protected void |
pushLoop(java.lang.String labelName)
Should be called when decending into a loop that does not define a scope. |
protected void |
pushLoop(VariableScope el,
java.lang.String labelName)
Should be called when decending into a loop that defines also a scope. |
private void |
pushState()
|
protected org.objectweb.asm.Label |
pushSwitch()
Creates a new break label and a element for the state stack so pop has to be called later |
protected void |
pushVariableScope(VariableScope el)
Causes the statestack to add an element and sets the given scope as new current variable scope. |
void |
removeVar(int tempIndex)
|
private void |
resetVariableIndex(boolean isStatic)
|
void |
setCurrentClassIndex(int index)
|
void |
setCurrentMetaClassIndex(int index)
|
private void |
setEndLabels()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private boolean clear
private VariableScope scope
private org.objectweb.asm.Label continueLabel
private org.objectweb.asm.Label breakLabel
private java.util.Map stackVariables
private int currentVariableIndex
private int nextVariableIndex
private final java.util.LinkedList temporaryVariables
private final java.util.LinkedList usedVariables
private java.util.Map superBlockNamedLabels
private java.util.Map currentBlockNamedLabels
private java.util.LinkedList finallyBlocks
private final java.util.List visitedBlocks
private org.objectweb.asm.Label thisStartLabel
private org.objectweb.asm.Label thisEndLabel
private int currentClassIndex
private int currentMetaClassIndex
private org.objectweb.asm.MethodVisitor mv
private BytecodeHelper helper
private final java.util.LinkedList stateStack
private int localVariableOffset
private final java.util.Map namedLoopBreakLabel
private final java.util.Map namedLoopContinueLabel
private java.lang.String className
Constructor Detail |
---|
public CompileStack()
Method Detail |
---|
private void pushState()
private void popState()
public org.objectweb.asm.Label getContinueLabel()
public org.objectweb.asm.Label getBreakLabel()
public void removeVar(int tempIndex)
private void setEndLabels()
public void pop()
public VariableScope getScope()
public int defineTemporaryVariable(Variable var, boolean store)
var
- defines type and namestore
- defines if the toplevel argument of the stack should be stored
public Variable getVariable(java.lang.String variableName)
public Variable getVariable(java.lang.String variableName, boolean mustExist)
variableName
- name of the variablemustExist
- throw exception if variable does not exist
mustExist
not true)public int defineTemporaryVariable(java.lang.String name, boolean store)
name
- defines type and namestore
- defines if the toplevel argument of the stack should be stored
public int defineTemporaryVariable(java.lang.String name, ClassNode node, boolean store)
name
- defines the namenode
- defines the nodestore
- defines if the toplevel argument of the stack should be stored
private void resetVariableIndex(boolean isStatic)
public void clear()
protected void init(VariableScope el, Parameter[] parameters, org.objectweb.asm.MethodVisitor mv, ClassNode cn)
protected void pushVariableScope(VariableScope el)
protected void pushLoop(VariableScope el, java.lang.String labelName)
private void initLoopLabels(java.lang.String labelName)
protected void pushLoop(java.lang.String labelName)
protected org.objectweb.asm.Label getNamedBreakLabel(java.lang.String name)
break foo
inside a loop to end the
execution of the marked loop. This method will return the
break label of the loop if there is one found for the name.
If not, the current break label is returned.
protected org.objectweb.asm.Label getNamedContinueLabel(java.lang.String name)
continue foo
inside a loop to continue
the execution of the marked loop. This method will return
the break label of the loop if there is one found for the
name. If not, getLabel is used.
protected org.objectweb.asm.Label pushSwitch()
protected void pushBooleanExpression()
private Variable defineVar(java.lang.String name, ClassNode type, boolean methodParameterUsedInClosure)
private void makeLocalVariablesOffset(Parameter[] paras, boolean isInStaticContext)
private void defineMethodVariables(Parameter[] paras, boolean isInStaticContext)
private void createReference(Variable reference)
public Variable defineVariable(Variable v, boolean initFromStack)
initFromStack
- if true the last element of the
stack will be used to initilize
the new variable. If false null
will be used.public boolean containsVariable(java.lang.String name)
name
- the name of the variable of interest
private void makeNextVariableID(ClassNode type)
public org.objectweb.asm.Label getLabel(java.lang.String name)
public org.objectweb.asm.Label createLocalLabel(java.lang.String name)
public int getCurrentClassIndex()
public void setCurrentClassIndex(int index)
public int getCurrentMetaClassIndex()
public void setCurrentMetaClassIndex(int index)
public void applyFinallyBlocks(org.objectweb.asm.Label label, boolean isBreakLabel)
private void applyFinallyBlocks(java.util.List blocks)
public void applyFinallyBlocks()
public boolean hasFinallyBlocks()
public void pushFinallyBlock(java.lang.Runnable block)
public void popFinallyBlock()
public void pushFinallyBlockVisit(java.lang.Runnable block)
public void popFinallyBlockVisit(java.lang.Runnable block)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |