Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.classgen
Class CompileStack

    java.lang.Object
      org.codehaus.groovy.classgen.CompileStack

All Implemented Interfaces:
  org.objectweb.asm.Opcodes

    public class CompileStack

extends Object
implements org.objectweb.asm.Opcodes

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:

- 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!

Author:
  Jochen Theodorou
See Also:
  `AsmClassGenerator`

Field Summary

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)`
`void` | `clear()` Clears the state of the class.
`boolean` | `containsVariable(String name)`
`org.objectweb.asm.Label` | `createLocalLabel(String name)` creates a new named label
`int` | `defineTemporaryVariable(String name, boolean store)` creates a temporary variable.
`int` | `defineTemporaryVariable(String name, ClassNode node, boolean store)` creates a temporary variable.
`int` | `defineTemporaryVariable(Variable var, boolean store)` creates a temporary variable.
`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(String name)` Returns the label for the given name
`protected org.objectweb.asm.Label` | `getNamedBreakLabel(String name)` Used for `break foo` inside a loop to end the execution of the marked loop.
`protected org.objectweb.asm.Label` | `getNamedContinueLabel(String name)` Used for `continue foo` inside a loop to continue the execution of the marked loop.
`VariableScope` | `getScope()`
`Variable` | `getVariable(String variableName)`
`Variable` | `getVariable(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.
`void` | `pop()`
`void` | `popFinallyBlock()`
`void` | `popFinallyBlockVisit(Runnable block)`
`protected void` | `pushBooleanExpression()` because a boolean Expression may not be evaluated completly it is important to keep the registers clean
`void` | `pushFinallyBlock(Runnable block)`
`void` | `pushFinallyBlockVisit(Runnable block)`
`protected void` | `pushLoop(String labelName)` Should be called when decending into a loop that does not define a scope.
`protected void` | `pushLoop(VariableScope el, String labelName)` Should be called when decending into a loop that defines also a scope.
`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)`
`void` | `setCurrentClassIndex(int index)`
`void` | `setCurrentMetaClassIndex(int index)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CompileStack

    public CompileStack()

Method Detail

### getContinueLabel

    public org.objectweb.asm.Label getContinueLabel()

### getBreakLabel

    public org.objectweb.asm.Label getBreakLabel()

### removeVar

    public void removeVar(int tempIndex)

### pop

    public void pop()

### getScope

    public VariableScope getScope()

### defineTemporaryVariable

    public 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

### getVariable

    public Variable getVariable(String variableName)

### getVariable

    public Variable getVariable(String variableName,
                                boolean mustExist)

  returns a normal variable, that was defined before. If mustExist is to false, then this method will throw a GroovyBugError. It is no the intention of this method to let this happen! And the exception should never be used for flow control. If the exception is thrown then it is a bug in the class using CompileStack. This mehod 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 `mustExist` not true)

### defineTemporaryVariable

    public int defineTemporaryVariable(String name,
                                       boolean store)

  creates a temporary variable.

  Parameters:
    `name` - defines type and name
    `store` - defines if the toplevel argument of the stack should be stored
  Returns:
    the index used for this temporary variable

### defineTemporaryVariable

    public int defineTemporaryVariable(String name,
                                       ClassNode node,
                                       boolean store)

  creates a temporary variable.

  Parameters:
    `name` - defines the name
    `node` - defines the node
    `store` - defines if the toplevel argument of the stack should be stored
  Returns:
    the index used for this temporary variable

### clear

    public 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

### init

    protected void init(VariableScope el,
                        Parameter[] parameters,
                        org.objectweb.asm.MethodVisitor mv,
                        ClassNode cn)

  initializes this class for a MethodNode. This method will automatically define varibales for the method parameters and will create references if needed. the created variables can be get by getVariable

### pushVariableScope

    protected void pushVariableScope(VariableScope el)

  Causes the statestack 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

### pushLoop

    protected void pushLoop(VariableScope el,
                            String labelName)

  Should be called when decending 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

### pushLoop

    protected void pushLoop(String labelName)

  Should be called when decending into a loop that does not define a scope. Creates a element for the state stack so pop has to be called later

### getNamedBreakLabel

    protected org.objectweb.asm.Label getNamedBreakLabel(String name)

  Used for `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.

### getNamedContinueLabel

    protected org.objectweb.asm.Label getNamedContinueLabel(String name)

  Used for `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.

### pushSwitch

    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

### pushBooleanExpression

    protected void pushBooleanExpression()

  because a boolean Expression may not be evaluated completly it is important to keep the registers clean

### defineVariable

    public Variable 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 initilize the new variable. If false null will be used.

### containsVariable

    public boolean containsVariable(String name)

  Parameters:
    `name` - the name of the variable of interest
  Returns:
    true if a variable is already defined

### getLabel

    public org.objectweb.asm.Label getLabel(String name)

  Returns the label for the given name

### createLocalLabel

    public org.objectweb.asm.Label createLocalLabel(String name)

  creates a new named label

### getCurrentClassIndex

    public int getCurrentClassIndex()

### setCurrentClassIndex

    public void setCurrentClassIndex(int index)

### getCurrentMetaClassIndex

    public int getCurrentMetaClassIndex()

### setCurrentMetaClassIndex

    public void setCurrentMetaClassIndex(int index)

### applyFinallyBlocks

    public void applyFinallyBlocks(org.objectweb.asm.Label label,
                                   boolean isBreakLabel)

### applyFinallyBlocks

    public void applyFinallyBlocks()

### hasFinallyBlocks

    public boolean hasFinallyBlocks()

### pushFinallyBlock

    public void pushFinallyBlock(Runnable block)

### popFinallyBlock

    public void popFinallyBlock()

### pushFinallyBlockVisit

    public void pushFinallyBlockVisit(Runnable block)

### popFinallyBlockVisit

    public void popFinallyBlockVisit(Runnable block)

Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright © 2003-2008 The Codehaus. All rights reserved.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD