protected class MethodGenerator.LocalVariableRegistry extends Object
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.
Modifier and Type | Field and Description |
---|---|
protected HashMap |
_nameToLVGMap
Maps a name to a
LocalVariableGen |
protected ArrayList |
_variables
A
java.lang.ArrayList of all
LocalVariableGen s created for this method, indexed by the
slot number of the local variable. |
Modifier | Constructor and Description |
---|---|
protected |
LocalVariableRegistry() |
Modifier and Type | Method and Description |
---|---|
protected org.apache.bcel.generic.LocalVariableGen[] |
getLocals(boolean includeRemoved)
Gets all
LocalVariableGen objects for this method. |
protected org.apache.bcel.generic.LocalVariableGen |
lookUpByName(String name)
Given the name of a variable, finds a
LocalVariableGen
corresponding to it. |
protected org.apache.bcel.generic.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(org.apache.bcel.generic.LocalVariableGen lvg)
Set up a mapping of the name of the specified
LocalVariableGen object to the LocalVariableGen
itself. |
protected void |
registerLocalVariable(org.apache.bcel.generic.LocalVariableGen lvg)
Registers a
LocalVariableGen
for this method. |
protected void |
removeByNameTracking(org.apache.bcel.generic.LocalVariableGen lvg)
Remove the mapping from the name of the specified
LocalVariableGen to itself. |
protected ArrayList _variables
A java.lang.ArrayList
of all
LocalVariableGen
s 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 LocalVariableGen
s
registered for the same slot; and if none occurs, the entry will be
null
.
protected HashMap _nameToLVGMap
LocalVariableGen
protected void registerLocalVariable(org.apache.bcel.generic.LocalVariableGen lvg)
LocalVariableGen
for this method.
Preconditions:
lvg
does not
overlap with the range of instructions for any
LocalVariableGen
with the same slot index previously
registered for this method. (Unchecked.)lvg
- The variable to be registeredprotected org.apache.bcel.generic.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:
InstructionList.setPositions()
has been called for
the InstructionList
associated with this
MethodGenerator
.slot
- the JVM local stack frame slot numberoffset
- the position in the byte codeLocalVariableGen
for the local variable
stored in the relevant slot at the relevant offset; null
if there is none.protected void registerByName(org.apache.bcel.generic.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)
lvg
- a LocalVariableGen
protected void removeByNameTracking(org.apache.bcel.generic.LocalVariableGen lvg)
LocalVariableGen
to itself.
See also registerByName(LocalVariableGen)
and
lookUpByName(String)
lvg
- a LocalVariableGen
protected org.apache.bcel.generic.LocalVariableGen lookUpByName(String name)
Given the name of a variable, finds a LocalVariableGen
corresponding to it.
See also registerByName(LocalVariableGen)
and
removeByNameTracking(LocalVariableGen)
name
- protected org.apache.bcel.generic.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.
includeRemoved
- Specifies whether all local variables ever
declared should be returned (true
) or only those not
removed (false
)LocalVariableGen
containing all the
local variablesCopyright © 2018 JBoss by Red Hat. All rights reserved.