Package serp.bytecode
Class LocalTable
- java.lang.Object
-
- serp.bytecode.Attributes
-
- serp.bytecode.Attribute
-
- serp.bytecode.LocalTable
-
- All Implemented Interfaces:
BCEntity
,InstructionPtr
,VisitAcceptor
- Direct Known Subclasses:
LocalVariableTable
,LocalVariableTypeTable
public abstract class LocalTable extends Attribute implements InstructionPtr
Code blocks compiled from source have local tables mapping locals used in opcodes to their names and descriptions.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List
_locals
-
Constructor Summary
Constructors Constructor Description LocalTable(int nameIndex, Attributes owner)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Local
addLocal()
Add a local to this table.Local
addLocal(java.lang.String name, java.lang.String type)
Add a local to this table.Local
addLocal(Local local)
Import a local from another method/class.void
clear()
Clear all locals from this table.Code
getCode()
Returns the Code block that owns the Instruction(s) this InstructionPtr points to.(package private) int
getLength()
Return the length of the bytecode representation of this attribute in bytes, excluding the name index.Local
getLocal(int local)
Return the local with the given locals index, or null if none.Local
getLocal(java.lang.String name)
Return the local with the given name, or null if none.Local[]
getLocals()
Return all the locals of this method.Local[]
getLocals(java.lang.String name)
Return all locals with the given name, or empty array if none.protected abstract Local
newLocal()
Create a new element of this table.protected abstract Local[]
newLocalArray(int size)
Create a new array.(package private) void
read(java.io.DataInput in, int length)
Read the attribute bytecode from the given stream, up to length bytes, excluding the name index.(package private) void
read(Attribute other)
Copy the information from the given attribute to this one.boolean
removeLocal(int local)
Removes the local with the given locals index from the table.boolean
removeLocal(java.lang.String name)
Removes the local with the given name from this method.boolean
removeLocal(Local local)
Removes a local from this method.void
replaceTarget(Instruction oldTarget, Instruction newTarget)
Replace the given old, likely invalid, target with a new target.void
setLocals(Local[] locals)
Set the locals of this table.void
updateTargets()
Use the byte indexes read from the class file to calculate and set references to the target instruction(s) for this ptr.(package private) void
write(java.io.DataOutput out, int length)
Write the attribute bytecode to the given stream, up to length bytes, excluding the name index.-
Methods inherited from class serp.bytecode.Attribute
create, getAttributesHolder, getClassLoader, getName, getNameIndex, getOwner, getPool, getProject, invalidate, isValid
-
Methods inherited from class serp.bytecode.Attributes
addAttribute, addAttribute, clearAttributes, getAttribute, getAttributes, getAttributes, readAttributes, removeAttribute, removeAttribute, setAttributes, visitAttributes, writeAttributes
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface serp.bytecode.visitor.VisitAcceptor
acceptVisit
-
-
-
-
Constructor Detail
-
LocalTable
LocalTable(int nameIndex, Attributes owner)
-
-
Method Detail
-
getLocals
public Local[] getLocals()
Return all the locals of this method.
-
getLocal
public Local getLocal(int local)
Return the local with the given locals index, or null if none.
-
getLocal
public Local getLocal(java.lang.String name)
Return the local with the given name, or null if none. If multiple locals have the given name, which is returned is undefined.
-
getLocals
public Local[] getLocals(java.lang.String name)
Return all locals with the given name, or empty array if none.
-
setLocals
public void setLocals(Local[] locals)
Set the locals of this table. This method is useful when importing locals from another method.
-
addLocal
public Local addLocal(Local local)
Import a local from another method/class. Note that the program counter and length from the given local is copied directly, and thus will be incorrect unless this method is the same as the one the local is copied from, or the pc and length are reset.
-
addLocal
public Local addLocal()
Add a local to this table.
-
newLocal
protected abstract Local newLocal()
Create a new element of this table.
-
newLocalArray
protected abstract Local[] newLocalArray(int size)
Create a new array.
-
addLocal
public Local addLocal(java.lang.String name, java.lang.String type)
Add a local to this table.
-
clear
public void clear()
Clear all locals from this table.
-
removeLocal
public boolean removeLocal(int local)
Removes the local with the given locals index from the table.- Returns:
- true if a local was removed, false otherwise
-
removeLocal
public boolean removeLocal(java.lang.String name)
Removes the local with the given name from this method.- Returns:
- true if a local was removed, false otherwise
-
removeLocal
public boolean removeLocal(Local local)
Removes a local from this method. After this method, the local will be invalid, and the result of any operations on it is undefined.- Returns:
- true if a local was removed, false otherwise
-
updateTargets
public void updateTargets()
Description copied from interface:InstructionPtr
Use the byte indexes read from the class file to calculate and set references to the target instruction(s) for this ptr. This method will be called after the byte code has been read in for the first time and before it is written after modification.- Specified by:
updateTargets
in interfaceInstructionPtr
-
replaceTarget
public void replaceTarget(Instruction oldTarget, Instruction newTarget)
Description copied from interface:InstructionPtr
Replace the given old, likely invalid, target with a new target. The new target Instruction is guaranteed to be in the same code block as this InstructionPtr.- Specified by:
replaceTarget
in interfaceInstructionPtr
-
getCode
public Code getCode()
Description copied from interface:InstructionPtr
Returns the Code block that owns the Instruction(s) this InstructionPtr points to.- Specified by:
getCode
in interfaceInstructionPtr
-
getLength
int getLength()
Description copied from class:Attribute
Return the length of the bytecode representation of this attribute in bytes, excluding the name index.
-
read
void read(Attribute other)
Description copied from class:Attribute
Copy the information from the given attribute to this one. Does nothing by default.
-
read
void read(java.io.DataInput in, int length) throws java.io.IOException
Description copied from class:Attribute
Read the attribute bytecode from the given stream, up to length bytes, excluding the name index. Does nothing by default.
-
write
void write(java.io.DataOutput out, int length) throws java.io.IOException
Description copied from class:Attribute
Write the attribute bytecode to the given stream, up to length bytes, excluding the name index. Does nothing by default.
-
-