Package org.codehaus.groovy.classgen.asm
Class CompileStack
- java.lang.Object
- 
- org.codehaus.groovy.classgen.asm.CompileStack
 
- 
- All Implemented Interfaces:
- org.objectweb.asm.Opcodes
 
 public class CompileStack extends java.lang.Object implements org.objectweb.asm.OpcodesManages 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: - every push method will require a later pop call
- method parameters may define a category 2 variable, so don't ignore the type stored in the variable object
- the index of the variable may not be as assumed when the variable is a parameter of a method because the parameter may be used in a closure, so don't ignore the stored variable index
- the names of temporary variables can be ignored. The names are only used for debugging and do not conflict with each other or normal variables. For accessing, the index of the variable must be used.
- never mix temporary and normal variables by changes to this class. While the name is very important for a normal variable, it is only a helper construct for temporary variables. That means for example a name for a temporary variable can be used multiple times without conflict. So mixing them both may lead to the problem that a normal or temporary variable is hidden or even removed. That must not happen!
 - See Also:
- AsmClassGenerator
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classCompileStack.BlockRecorderprotected static classCompileStack.LabelRange
 - 
Field Summary- 
Fields inherited from interface org.objectweb.asm.OpcodesAALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_MODULE, ACC_NATIVE, ACC_OPEN, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_RECORD, ACC_STATIC, ACC_STATIC_PHASE, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_TRANSITIVE, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM10_EXPERIMENTAL, ASM4, ASM5, ASM6, ASM7, ASM8, ASM9, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, 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, INTEGER, INVOKEDYNAMIC, 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, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SOURCE_DEPRECATED, SOURCE_MASK, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V_PREVIEW, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V9
 
- 
 - 
Constructor SummaryConstructors Constructor Description CompileStack(WriterController wc)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExceptionBlock(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label goal, java.lang.String sig)voidapplyBlockRecorder()voidapplyFinallyBlocks(org.objectweb.asm.Label label, boolean isBreakLabel)voidclear()Clears the state of the class.booleancontainsVariable(java.lang.String name)org.objectweb.asm.LabelcreateLocalLabel(java.lang.String name)creates a new named labelintdefineTemporaryVariable(java.lang.String name, boolean store)creates a temporary variable.intdefineTemporaryVariable(java.lang.String name, ClassNode node, boolean store)creates a temporary variable.intdefineTemporaryVariable(Variable var, boolean store)creates a temporary variable.BytecodeVariabledefineVariable(Variable v, boolean initFromStack)Defines a new Variable using an AST variable.BytecodeVariabledefineVariable(Variable v, ClassNode variableType, boolean initFromStack)org.objectweb.asm.LabelgetBreakLabel()org.objectweb.asm.LabelgetContinueLabel()org.objectweb.asm.LabelgetLabel(java.lang.String name)Returns the label for the given nameorg.objectweb.asm.LabelgetNamedBreakLabel(java.lang.String name)Used forbreak fooinside a loop to end the execution of the marked loop.org.objectweb.asm.LabelgetNamedContinueLabel(java.lang.String name)Used forcontinue fooinside a loop to continue the execution of the marked loop.VariableScopegetScope()BytecodeVariablegetVariable(java.lang.String variableName)BytecodeVariablegetVariable(java.lang.String variableName, boolean mustExist)Returns a normal variable.booleanhasBlockRecorder()voidinit(VariableScope el, Parameter[] parameters)initializes this class for a MethodNode.booleanisImplicitThis()booleanisInSpecialConstructorCall()booleanisLHS()voidpop()voidpopBlockRecorderVisit(CompileStack.BlockRecorder finallyBlock)voidpopImplicitThis()voidpopLHS()voidpushBlockRecorder(CompileStack.BlockRecorder recorder)voidpushBlockRecorderVisit(CompileStack.BlockRecorder finallyBlock)voidpushBooleanExpression()because a boolean Expression may not be evaluated completely it is important to keep the registers cleanvoidpushImplicitThis(boolean implicitThis)voidpushInSpecialConstructorCall()voidpushLHS(boolean lhs)voidpushLoop(java.lang.String labelName)Should be called when descending into a loop that does not define a scope.voidpushLoop(java.util.List<java.lang.String> labelNames)Should be called when descending into a loop that does not define a scope.voidpushLoop(VariableScope el, java.lang.String labelName)Should be called when descending into a loop that defines also a scope.voidpushLoop(VariableScope el, java.util.List<java.lang.String> labelNames)Should be called when descending into a loop that defines also a scope.voidpushState()org.objectweb.asm.LabelpushSwitch()Creates a new break label and a element for the state stack so pop has to be called latervoidpushVariableScope(VariableScope el)Causes the state-stack to add an element and sets the given scope as new current variable scope.voidremoveVar(int tempIndex)voidwriteExceptionTable(CompileStack.BlockRecorder block, org.objectweb.asm.Label goal, java.lang.String sig)
 
- 
- 
- 
Constructor Detail- 
CompileStackpublic CompileStack(WriterController wc) 
 
- 
 - 
Method Detail- 
pushStatepublic void pushState() 
 - 
getContinueLabelpublic org.objectweb.asm.Label getContinueLabel() 
 - 
getBreakLabelpublic org.objectweb.asm.Label getBreakLabel() 
 - 
removeVarpublic void removeVar(int tempIndex) 
 - 
poppublic void pop() 
 - 
getScopepublic VariableScope getScope() 
 - 
defineTemporaryVariablepublic int defineTemporaryVariable(Variable var, boolean store) creates a temporary variable.- Parameters:
- var- defines type and name
- store- defines if the toplevel argument of the stack should be stored
- Returns:
- the index used for this temporary variable
 
 - 
getVariablepublic BytecodeVariable getVariable(java.lang.String variableName) 
 - 
getVariablepublic BytecodeVariable getVariable(java.lang.String variableName, boolean mustExist) Returns a normal variable.If mustExistis true and the normal variable doesn't exist, then this method will throw a GroovyBugError. It is not the intention of this method to let this happen! And the exception should not be used for flow control - it is just acting as an assertion. If the exception is thrown then it indicates a bug in the class using CompileStack. This method can also not be used to return a temporary variable. Temporary variables are not normal variables.- Parameters:
- variableName- name of the variable
- mustExist- throw exception if variable does not exist
- Returns:
- the normal variable or null if not found (and mustExistnot true)
 
 - 
defineTemporaryVariablepublic int defineTemporaryVariable(java.lang.String name, boolean store)creates a temporary variable.- Parameters:
- name- defines type and name
- store- defines if the top-level argument of the stack should be stored
- Returns:
- the index used for this temporary variable
 
 - 
defineTemporaryVariablepublic int defineTemporaryVariable(java.lang.String name, ClassNode node, boolean store)creates a temporary variable.- Parameters:
- name- defines the name
- node- defines the node
- store- defines if the top-level argument of the stack should be stored
- Returns:
- the index used for this temporary variable
 
 - 
clearpublic void clear() Clears the state of the class. This method should be called after a MethodNode is visited. Note that a call to init will fail if clear is not called before
 - 
addExceptionBlockpublic void addExceptionBlock(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label goal, java.lang.String sig)
 - 
initpublic void init(VariableScope el, Parameter[] parameters) initializes this class for a MethodNode. This method will automatically define variables for the method parameters and will create references if needed. The created variables can be accessed by calling getVariable().
 - 
pushVariableScopepublic void pushVariableScope(VariableScope el) Causes the state-stack to add an element and sets the given scope as new current variable scope. Creates a element for the state stack so pop has to be called later
 - 
pushLooppublic void pushLoop(VariableScope el, java.lang.String labelName) Should be called when descending into a loop that defines also a scope. Calls pushVariableScope and prepares labels for a loop structure. Creates a element for the state stack so pop has to be called later, TODO: @Deprecate
 - 
pushLooppublic void pushLoop(VariableScope el, java.util.List<java.lang.String> labelNames) Should be called when descending into a loop that defines also a scope. Calls pushVariableScope and prepares labels for a loop structure. Creates a element for the state stack so pop has to be called later
 - 
pushLooppublic void pushLoop(java.lang.String labelName) Should be called when descending into a loop that does not define a scope. Creates a element for the state stack so pop has to be called later, TODO: @Deprecate
 - 
pushLooppublic void pushLoop(java.util.List<java.lang.String> labelNames) Should be called when descending into a loop that does not define a scope. Creates a element for the state stack so pop has to be called later
 - 
getNamedBreakLabelpublic org.objectweb.asm.Label getNamedBreakLabel(java.lang.String name) Used forbreak fooinside 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.
 - 
getNamedContinueLabelpublic org.objectweb.asm.Label getNamedContinueLabel(java.lang.String name) Used forcontinue fooinside 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.
 - 
pushSwitchpublic org.objectweb.asm.Label pushSwitch() Creates a new break label and a element for the state stack so pop has to be called later
 - 
pushBooleanExpressionpublic void pushBooleanExpression() because a boolean Expression may not be evaluated completely it is important to keep the registers clean
 - 
defineVariablepublic BytecodeVariable defineVariable(Variable v, boolean initFromStack) Defines a new Variable using an AST variable.- Parameters:
- initFromStack- if true the last element of the stack will be used to initialize the new variable. If false null will be used.
 
 - 
defineVariablepublic BytecodeVariable defineVariable(Variable v, ClassNode variableType, boolean initFromStack) 
 - 
containsVariablepublic boolean containsVariable(java.lang.String name) - Parameters:
- name- the name of the variable of interest
- Returns:
- true if a variable is already defined
 
 - 
getLabelpublic org.objectweb.asm.Label getLabel(java.lang.String name) Returns the label for the given name
 - 
createLocalLabelpublic org.objectweb.asm.Label createLocalLabel(java.lang.String name) creates a new named label
 - 
applyFinallyBlockspublic void applyFinallyBlocks(org.objectweb.asm.Label label, boolean isBreakLabel)
 - 
applyBlockRecorderpublic void applyBlockRecorder() 
 - 
hasBlockRecorderpublic boolean hasBlockRecorder() 
 - 
pushBlockRecorderpublic void pushBlockRecorder(CompileStack.BlockRecorder recorder) 
 - 
pushBlockRecorderVisitpublic void pushBlockRecorderVisit(CompileStack.BlockRecorder finallyBlock) 
 - 
popBlockRecorderVisitpublic void popBlockRecorderVisit(CompileStack.BlockRecorder finallyBlock) 
 - 
writeExceptionTablepublic void writeExceptionTable(CompileStack.BlockRecorder block, org.objectweb.asm.Label goal, java.lang.String sig) 
 - 
isLHSpublic boolean isLHS() 
 - 
pushLHSpublic void pushLHS(boolean lhs) 
 - 
popLHSpublic void popLHS() 
 - 
pushImplicitThispublic void pushImplicitThis(boolean implicitThis) 
 - 
isImplicitThispublic boolean isImplicitThis() 
 - 
popImplicitThispublic void popImplicitThis() 
 - 
isInSpecialConstructorCallpublic boolean isInSpecialConstructorCall() 
 - 
pushInSpecialConstructorCallpublic void pushInSpecialConstructorCall() 
 
- 
 
-