Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.classgen.asm
[Java] 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

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!

Authors:
  Jochen Theodorou

See Also:
  AsmClassGenerator

Nested Class Summary
`static class` | `CompileStack.BlockRecorder`
`protected static class` | `CompileStack.LabelRange`

Method Summary
`java.lang.Object` | `CompileStack(WriterController wc)`
`void` | `addExceptionBlock(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label goal, java.lang.String sig)` initializes this class for a MethodNode.
`void` | `applyBlockRecorder()`
`void` | `applyFinallyBlocks(org.objectweb.asm.Label label, boolean isBreakLabel)`
`void` | `clear()`
`boolean` | `containsVariable(java.lang.String name)` Returns the label for the given name
`org.objectweb.asm.Label` | `createLocalLabel(java.lang.String name)`
`int` | `defineTemporaryVariable(Variable var, boolean store)`
`int` | `defineTemporaryVariable(java.lang.String name, boolean store)`
`int` | `defineTemporaryVariable(java.lang.String name, ClassNode node, boolean store)` Clears the state of the class.
`BytecodeVariable` | `defineVariable(Variable v, boolean initFromStack)` @param name the name of the variable of interest
`BytecodeVariable` | `defineVariable(Variable v, ClassNode variableType, boolean initFromStack)`
`org.objectweb.asm.Label` | `getBreakLabel()`
`org.objectweb.asm.Label` | `getContinueLabel()`
`org.objectweb.asm.Label` | `getLabel(java.lang.String name)`
`org.objectweb.asm.Label` | `getNamedBreakLabel(java.lang.String name)`
`org.objectweb.asm.Label` | `getNamedContinueLabel(java.lang.String name)`
`VariableScope` | `getScope()`
`BytecodeVariable` | `getVariable(java.lang.String variableName)`
`BytecodeVariable` | `getVariable(java.lang.String variableName, boolean mustExist)` creates a temporary variable.
`boolean` | `hasBlockRecorder()`
`void` | `init(VariableScope el, Parameter[] parameters)` Causes the statestack to add an element and sets the given scope as new current variable scope.
`boolean` | `isImplicitThis()`
`boolean` | `isInSpecialConstructorCall()`
`boolean` | `isLHS()`
`void` | `pop()`
`void` | `popBlockRecorderVisit(CompileStack.BlockRecorder finallyBlock)`
`void` | `popImplicitThis()`
`void` | `popLHS()`
`void` | `pushBlockRecorder(CompileStack.BlockRecorder recorder)`
`void` | `pushBlockRecorderVisit(CompileStack.BlockRecorder finallyBlock)`
`void` | `pushBooleanExpression()`
`void` | `pushImplicitThis(boolean implicitThis)`
`void` | `pushInSpecialConstructorCall()`
`void` | `pushLHS(boolean lhs)`
`void` | `pushLoop(VariableScope el, java.lang.String labelName)` Used for `break foo` inside a loop to end the execution of the marked loop.
`void` | `pushLoop(java.lang.String labelName)`
`void` | `pushState()`
`org.objectweb.asm.Label` | `pushSwitch()`
`void` | `pushVariableScope(VariableScope el)` Should be called when decending into a loop that does not define a scope.
`void` | `removeVar(int tempIndex)`
`void` | `writeExceptionTable(CompileStack.BlockRecorder block, org.objectweb.asm.Label goal, java.lang.String sig)`

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Method Detail

### CompileStack

    public java.lang.Object CompileStack(WriterController wc)

### addExceptionBlock

    public void addExceptionBlock(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label goal, java.lang.String sig)

  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().

### applyBlockRecorder

    public void applyBlockRecorder()

### applyFinallyBlocks

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

### clear

    public void clear()

### containsVariable

    public boolean containsVariable(java.lang.String name)

  Returns the label for the given name

### createLocalLabel

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

### defineTemporaryVariable

    public int defineTemporaryVariable(Variable var, boolean store)

### defineTemporaryVariable

    public int defineTemporaryVariable(java.lang.String name, boolean store)

### defineTemporaryVariable

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

  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

### defineVariable

    public BytecodeVariable defineVariable(Variable v, boolean initFromStack)

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

### defineVariable

    public BytecodeVariable defineVariable(Variable v, ClassNode variableType, boolean initFromStack)

### getBreakLabel

    public org.objectweb.asm.Label getBreakLabel()

### getContinueLabel

    public org.objectweb.asm.Label getContinueLabel()

### getLabel

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

### getNamedBreakLabel

    public org.objectweb.asm.Label getNamedBreakLabel(java.lang.String name)

### getNamedContinueLabel

    public org.objectweb.asm.Label getNamedContinueLabel(java.lang.String name)

### getScope

    public VariableScope getScope()

### getVariable

    public BytecodeVariable getVariable(java.lang.String variableName)

### getVariable

    public BytecodeVariable getVariable(java.lang.String variableName, boolean mustExist)

  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

### hasBlockRecorder

    public boolean hasBlockRecorder()

### init

    public void init(VariableScope el, Parameter[] parameters)

  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

### isImplicitThis

    public boolean isImplicitThis()

### isInSpecialConstructorCall

    public boolean isInSpecialConstructorCall()

### isLHS

    public boolean isLHS()

### pop

    public void pop()

### popBlockRecorderVisit

    public void popBlockRecorderVisit(CompileStack.BlockRecorder finallyBlock)

### popImplicitThis

    public void popImplicitThis()

### popLHS

    public void popLHS()

### pushBlockRecorder

    public void pushBlockRecorder(CompileStack.BlockRecorder recorder)

### pushBlockRecorderVisit

    public void pushBlockRecorderVisit(CompileStack.BlockRecorder finallyBlock)

### pushBooleanExpression

    public void pushBooleanExpression()

### pushImplicitThis

    public void pushImplicitThis(boolean implicitThis)

### pushInSpecialConstructorCall

    public void pushInSpecialConstructorCall()

### pushLHS

    public void pushLHS(boolean lhs)

### pushLoop

    public void pushLoop(VariableScope el, java.lang.String labelName)

  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.

### pushLoop

    public void pushLoop(java.lang.String labelName)

### pushState

    public void pushState()

### pushSwitch

    public org.objectweb.asm.Label pushSwitch()

### pushVariableScope

    public void pushVariableScope(VariableScope el)

  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

### removeVar

    public void removeVar(int tempIndex)

### writeExceptionTable

    public void writeExceptionTable(CompileStack.BlockRecorder block, org.objectweb.asm.Label goal, java.lang.String sig)

Groovy Documentation