| java.lang.Object org.codehaus.groovy.classgen.CompileStack
CompileStack | public class CompileStack implements Opcodes(Code) | | 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.
See Also: org.codehaus.groovy.classgen.AsmClassGenerator author: Jochen Theodorou |
Method Summary | |
public void | applyFinallyBlocks(Label label, boolean isBreakLabel) | public void | applyFinallyBlocks() | public void | clear() Clears the state of the class. | public boolean | containsVariable(String name) | public Label | createLocalLabel(String name) | public int | defineTemporaryVariable(org.codehaus.groovy.ast.Variable var, boolean store) creates a temporary variable. | public int | defineTemporaryVariable(String name, boolean store) creates a temporary variable. | public int | defineTemporaryVariable(String name, ClassNode node, boolean store) creates a temporary variable. | public Variable | defineVariable(org.codehaus.groovy.ast.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 initilizethe new variable. | public Label | getBreakLabel() | public Label | getContinueLabel() | public int | getCurrentClassIndex() | public int | getCurrentMetaClassIndex() | public Label | getLabel(String name) | protected Label | getNamedBreakLabel(String name) Used for break foo inside a loop to end the
execution of the marked loop. | protected Label | getNamedContinueLabel(String name) Used for continue foo inside a loop to continue
the execution of the marked loop. | public VariableScope | getScope() | public Variable | getVariable(String variableName) | public Variable | getVariable(String variableName, boolean mustExist) | public boolean | hasFinallyBlocks() | protected void | init(VariableScope el, Parameter[] parameters, MethodVisitor mv, ClassNode cn) initializes this class for a MethodNode. | public void | pop() | public void | popFinallyBlock() | protected void | pushBooleanExpression() | public void | pushFinallyBlock(Runnable block) | protected void | pushLoop(VariableScope el, String labelName) Should be called when decending into a loop that defines
also a scope. | protected void | pushLoop(String labelName) Should be called when decending into a loop that does
not define a scope. | protected Label | pushSwitch() | protected void | pushVariableScope(VariableScope el) Causes the statestack to add an element and sets
the given scope as new current variable scope. | public void | removeVar(int tempIndex) | public void | setCurrentClassIndex(int index) | public void | setCurrentMetaClassIndex(int index) |
applyFinallyBlocks | public void applyFinallyBlocks(Label label, boolean isBreakLabel)(Code) | | |
applyFinallyBlocks | public void applyFinallyBlocks()(Code) | | |
clear | public void clear()(Code) | | 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)(Code) | | Returns true if a varibale is already defined
|
createLocalLabel | public Label createLocalLabel(String name)(Code) | | creates a new named label
|
defineTemporaryVariable | public int defineTemporaryVariable(org.codehaus.groovy.ast.Variable var, boolean store)(Code) | | creates a temporary variable.
Parameters: var - defines type and name Parameters: store - defines if the toplevel argument of the stack should be stored the index used for this temporary variable |
defineTemporaryVariable | public int defineTemporaryVariable(String name, boolean store)(Code) | | creates a temporary variable.
Parameters: name - defines type and name Parameters: store - defines if the toplevel argument of the stack should be stored the index used for this temporary variable |
defineTemporaryVariable | public int defineTemporaryVariable(String name, ClassNode node, boolean store)(Code) | | creates a temporary variable.
Parameters: name - defines the name Parameters: node - defines the node Parameters: store - defines if the toplevel argument of the stack should be stored the index used for this temporary variable |
defineVariable | public Variable defineVariable(org.codehaus.groovy.ast.Variable v, boolean initFromStack)(Code) | | Defines a new Variable using an AST variable.
Parameters: initFromStack - if true the last element of the stack will be used to initilizethe new variable. If false nullwill be used. |
getBreakLabel | public Label getBreakLabel()(Code) | | |
getContinueLabel | public Label getContinueLabel()(Code) | | |
getCurrentClassIndex | public int getCurrentClassIndex()(Code) | | |
getCurrentMetaClassIndex | public int getCurrentMetaClassIndex()(Code) | | |
getLabel | public Label getLabel(String name)(Code) | | Returns the label for the given name
|
getNamedBreakLabel | protected Label getNamedBreakLabel(String name)(Code) | | 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 Label getNamedContinueLabel(String name)(Code) | | 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.
|
hasFinallyBlocks | public boolean hasFinallyBlocks()(Code) | | |
init | protected void init(VariableScope el, Parameter[] parameters, MethodVisitor mv, ClassNode cn)(Code) | | 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
|
popFinallyBlock | public void popFinallyBlock()(Code) | | |
pushBooleanExpression | protected void pushBooleanExpression()(Code) | | because a boolean Expression may not be evaluated completly
it is important to keep the registers clean
|
pushLoop | protected void pushLoop(VariableScope el, String labelName)(Code) | | 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)(Code) | | 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
|
pushSwitch | protected Label pushSwitch()(Code) | | Creates a new break label and a element for the state stack
so pop has to be called later
|
pushVariableScope | protected void pushVariableScope(VariableScope el)(Code) | | 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)(Code) | | |
setCurrentClassIndex | public void setCurrentClassIndex(int index)(Code) | | |
setCurrentMetaClassIndex | public void setCurrentMetaClassIndex(int index)(Code) | | |
|
|