Groovy 1.8.4

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

Authors:
Jochen Theodorou
See Also:
AsmClassGenerator


Nested Class Summary
static class CompileStack.BlockRecorder

protected static class CompileStack.LabelRange

 
Method Summary
def CompileStack(WriterController wc)

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

void applyBlockRecorder()

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

void clear()

Clears the state of the class.

boolean containsVariable(String name)

@param name the name of the variable of interest

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

creates a new named label

int defineTemporaryVariable(Variable var, boolean store)

creates a temporary variable.

int defineTemporaryVariable(String name, boolean store)

creates a temporary variable.

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

creates a temporary variable.

BytecodeVariable defineVariable(Variable v, boolean initFromStack)

Defines a new Variable using an AST variable.

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

org.objectweb.asm.Label getBreakLabel()

org.objectweb.asm.Label getContinueLabel()

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

Returns the label for the given name

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

Used for break foo inside a loop to end the execution of the marked loop.

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

Used for continue foo inside a loop to continue the execution of the marked loop.

VariableScope getScope()

BytecodeVariable getVariable(String variableName)

BytecodeVariable getVariable(String variableName, boolean mustExist)

Returns a normal variable.

boolean hasBlockRecorder()

void init(VariableScope el, Parameter[] parameters)

initializes this class for a MethodNode.

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

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

void pushImplicitThis(boolean implicitThis)

void pushInSpecialConstructorCall()

void pushLHS(boolean lhs)

void pushLoop(VariableScope el, String labelName)

Should be called when decending into a loop that defines also a scope.

void pushLoop(String labelName)

Should be called when decending into a loop that does not define a scope.

void pushState()

org.objectweb.asm.Label pushSwitch()

Creates a new break label and a element for the state stack so pop has to be called later

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 writeExceptionTable(CompileStack.BlockRecorder block, org.objectweb.asm.Label goal, String sig)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Method Detail

CompileStack

public def CompileStack(WriterController wc)


addExceptionBlock

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


applyBlockRecorder

public void applyBlockRecorder()


applyFinallyBlocks

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


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


containsVariable

public boolean containsVariable(String name)
Parameters:
name - the name of the variable of interest
Returns:
true if a variable is already defined


createLocalLabel

public org.objectweb.asm.Label createLocalLabel(String name)
creates a new named label


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


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


defineVariable

public 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.


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(String name)
Returns the label for the given name


getNamedBreakLabel

public 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

public 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.


getScope

public VariableScope getScope()


getVariable

public BytecodeVariable getVariable(String variableName)


getVariable

public BytecodeVariable getVariable(String variableName, boolean mustExist)
Returns a normal variable.

If mustExist is 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 mustExist not true)


hasBlockRecorder

public boolean hasBlockRecorder()


init

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


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()
because a boolean Expression may not be evaluated completely it is important to keep the registers clean


pushImplicitThis

public void pushImplicitThis(boolean implicitThis)


pushInSpecialConstructorCall

public void pushInSpecialConstructorCall()


pushLHS

public void pushLHS(boolean lhs)


pushLoop

public 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

public 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


pushState

public void pushState()


pushSwitch

public org.objectweb.asm.Label pushSwitch()
Creates a new break label and a element for the state stack so pop has to be called later


pushVariableScope

public 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


removeVar

public void removeVar(int tempIndex)


writeExceptionTable

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


 

Copyright © 2003-2011 The Codehaus. All rights reserved.