org.apache.xalan.xsltc.compiler.util
Class MethodGenerator.LocalVariableRegistry

java.lang.Object
  extended by org.apache.xalan.xsltc.compiler.util.MethodGenerator.LocalVariableRegistry
Enclosing class:
MethodGenerator

protected class MethodGenerator.LocalVariableRegistry
extends java.lang.Object

Keeps track of all local variables used in the method.

The MethodGen#addLocalVariable(String,Type,InstructionHandle,InstructionHandle) and MethodGen#addLocalVariable(String,Type,int,InstructionHandle,InstructionHandle) methods of MethodGen will only keep track of LocalVariableGen object until it'ss removed by a call to MethodGen#removeLocalVariable(LocalVariableGen).

In order to support efficient copying of local variables to outlined methods by MethodGenerator.outline(InstructionHandle,InstructionHandle,String,ClassGenerator), this class keeps track of all local variables defined by the method.


Field Summary
protected  java.util.HashMap _nameToLVGMap
          Maps a name to a LocalVariableGen
protected  java.util.ArrayList _variables
          A java.lang.ArrayList of all LocalVariableGens created for this method, indexed by the slot number of the local variable.
 
Constructor Summary
protected MethodGenerator.LocalVariableRegistry()
           
 
Method Summary
protected  LocalVariableGen[] getLocals(boolean includeRemoved)
          Gets all LocalVariableGen objects for this method.
protected  LocalVariableGen lookUpByName(java.lang.String name)
          Given the name of a variable, finds a LocalVariableGen corresponding to it.
protected  LocalVariableGen lookupRegisteredLocalVariable(int slot, int offset)
          Find which LocalVariableGen, if any, is registered for a particular JVM local stack frame slot at a particular position in the byte code for the method.
protected  void registerByName(LocalVariableGen lvg)
          Set up a mapping of the name of the specified LocalVariableGen object to the LocalVariableGen itself.
protected  void registerLocalVariable(LocalVariableGen lvg)
          Registers a org.apache.bcel.generic.LocalVariableGen for this method.
protected  void removeByNameTracking(LocalVariableGen lvg)
          Remove the mapping from the name of the specified LocalVariableGen to itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_variables

protected java.util.ArrayList _variables

A java.lang.ArrayList of all LocalVariableGens created for this method, indexed by the slot number of the local variable. The JVM stack frame of local variables is divided into "slots". A single slot can be used to store more than one variable in a method, without regard to type, so long as the byte code keeps the ranges of the two disjoint.

If only one registration of use of a particular slot occurs, the corresponding entry of _variables contains the LocalVariableGen; if more than one occurs, the corresponding entry contains all such LocalVariableGens registered for the same slot; and if none occurs, the entry will be null.


_nameToLVGMap

protected java.util.HashMap _nameToLVGMap
Maps a name to a LocalVariableGen

Constructor Detail

MethodGenerator.LocalVariableRegistry

protected MethodGenerator.LocalVariableRegistry()
Method Detail

registerLocalVariable

protected void registerLocalVariable(LocalVariableGen lvg)
Registers a org.apache.bcel.generic.LocalVariableGen for this method.

Preconditions:

Parameters:
lvg - The variable to be registered

lookupRegisteredLocalVariable

protected LocalVariableGen lookupRegisteredLocalVariable(int slot,
                                                         int offset)

Find which LocalVariableGen, if any, is registered for a particular JVM local stack frame slot at a particular position in the byte code for the method.

Preconditions:

Parameters:
slot - the JVM local stack frame slot number
offset - the position in the byte code
Returns:
the LocalVariableGen for the local variable stored in the relevant slot at the relevant offset; null if there is none.

registerByName

protected void registerByName(LocalVariableGen lvg)

Set up a mapping of the name of the specified LocalVariableGen object to the LocalVariableGen itself.

This is a bit of a hack. XSLTC is relying on the fact that the name that is being looked up won't be duplicated, which isn't guaranteed. It replaces code which used to call MethodGen#getLocalVariables() and looped through the LocalVariableGen objects it contained to find the one with the specified name. However, getLocalVariables() has the side effect of setting the start and end for any LocalVariableGen which did not already have them set, which causes problems for outlining..

See also lookUpByName(String) and removeByNameTracking(LocalVariableGen)

Parameters:
lvg - a LocalVariableGen

removeByNameTracking

protected void removeByNameTracking(LocalVariableGen lvg)
Remove the mapping from the name of the specified LocalVariableGen to itself. See also registerByName(LocalVariableGen) and lookUpByName(String)

Parameters:
lvg - a LocalVariableGen

lookUpByName

protected LocalVariableGen lookUpByName(java.lang.String name)

Given the name of a variable, finds a LocalVariableGen corresponding to it.

See also registerByName(LocalVariableGen) and removeByNameTracking(LocalVariableGen)

Parameters:
name -
Returns:

getLocals

protected LocalVariableGen[] getLocals(boolean includeRemoved)

Gets all LocalVariableGen objects for this method.

When the includeRemoved argument has the value false, this method replaces uses of MethodGen#getLocalVariables() which has a side-effect of setting the start and end range for any LocalVariableGen if either was null. That side-effect causes problems for outlining of code in XSLTC.

Parameters:
includeRemoved - Specifies whether all local variables ever declared should be returned (true) or only those not removed (false)
Returns:
an array of LocalVariableGen containing all the local variables