Package serp.bytecode
Class LineNumberTable
- java.lang.Object
-
- serp.bytecode.Attributes
-
- serp.bytecode.Attribute
-
- serp.bytecode.LineNumberTable
-
- All Implemented Interfaces:
BCEntity,InstructionPtr,VisitAcceptor
public class LineNumberTable extends Attribute implements InstructionPtr
Code blocks compiled from source have line number tables mapping opcodes to source lines. This table automatically maintains line numbers in ascending order by their start program counter position at all times.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List_lineNumbers
-
Constructor Summary
Constructors Constructor Description LineNumberTable(int nameIndex, Attributes owner)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacceptVisit(BCVisitor visit)Accept a visit from aBCVisitor, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.LineNumberaddLineNumber()Add a new line number to this table.LineNumberaddLineNumber(int startPc, int line)Add a new line number to this table.LineNumberaddLineNumber(Instruction start, int line)Add a new line number to this table.LineNumberaddLineNumber(LineNumber ln)Import a line number from another method.voidclear()Clear the line numbers.CodegetCode()Returns the Code block that owns the Instruction(s) this InstructionPtr points to.(package private) intgetLength()Return the length of the bytecode representation of this attribute in bytes, excluding the name index.LineNumbergetLineNumber(int pc)Return the line number for the given program counter, or null if none.LineNumbergetLineNumber(Instruction ins)Return the line number for the given instruction, or null if none.LineNumber[]getLineNumbers()Return the line numbers held in this table.(package private) voidread(java.io.DataInput in, int length)Read the attribute bytecode from the given stream, up to length bytes, excluding the name index.(package private) voidread(Attribute other)Copy the information from the given attribute to this one.booleanremoveLineNumber(int pc)Remove the line number for the given program counter.booleanremoveLineNumber(Instruction ins)Remove the line number for the given instruction.booleanremoveLineNumber(LineNumber ln)Remove the given line.voidreplaceTarget(Instruction oldTarget, Instruction newTarget)Replace the given old, likely invalid, target with a new target.voidsetLineNumbers(LineNumber[] lines)Set the line numbers for the table.voidupdateTargets()Use the byte indexes read from the class file to calculate and set references to the target instruction(s) for this ptr.(package private) voidwrite(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
-
-
-
-
Constructor Detail
-
LineNumberTable
LineNumberTable(int nameIndex, Attributes owner)
-
-
Method Detail
-
getLineNumbers
public LineNumber[] getLineNumbers()
Return the line numbers held in this table.
-
getLineNumber
public LineNumber getLineNumber(int pc)
Return the line number for the given program counter, or null if none.
-
getLineNumber
public LineNumber getLineNumber(Instruction ins)
Return the line number for the given instruction, or null if none.
-
setLineNumbers
public void setLineNumbers(LineNumber[] lines)
Set the line numbers for the table. This method is useful when importing line numbers from another method.
-
addLineNumber
public LineNumber addLineNumber(LineNumber ln)
Import a line number from another method.- Returns:
- the newly added line number
-
addLineNumber
public LineNumber addLineNumber()
Add a new line number to this table.
-
addLineNumber
public LineNumber addLineNumber(int startPc, int line)
Add a new line number to this table.
-
addLineNumber
public LineNumber addLineNumber(Instruction start, int line)
Add a new line number to this table.
-
clear
public void clear()
Clear the line numbers.
-
removeLineNumber
public boolean removeLineNumber(LineNumber ln)
Remove the given line.- Returns:
- true if the line was removed, false otherwise
-
removeLineNumber
public boolean removeLineNumber(int pc)
Remove the line number for the given program counter.- Returns:
- true if the line was removed, false otherwise
-
removeLineNumber
public boolean removeLineNumber(Instruction ins)
Remove the line number for the given instruction.- Returns:
- true if the line was removed, false otherwise
-
updateTargets
public void updateTargets()
Description copied from interface:InstructionPtrUse 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:
updateTargetsin interfaceInstructionPtr
-
replaceTarget
public void replaceTarget(Instruction oldTarget, Instruction newTarget)
Description copied from interface:InstructionPtrReplace 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:
replaceTargetin interfaceInstructionPtr
-
acceptVisit
public void acceptVisit(BCVisitor visit)
Description copied from interface:VisitAcceptorAccept a visit from aBCVisitor, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.- Specified by:
acceptVisitin interfaceVisitAcceptor
-
getLength
int getLength()
Description copied from class:AttributeReturn the length of the bytecode representation of this attribute in bytes, excluding the name index.
-
read
void read(Attribute other)
Description copied from class:AttributeCopy 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.IOExceptionDescription copied from class:AttributeRead 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.IOExceptionDescription copied from class:AttributeWrite the attribute bytecode to the given stream, up to length bytes, excluding the name index. Does nothing by default.
-
getCode
public Code getCode()
Description copied from interface:InstructionPtrReturns the Code block that owns the Instruction(s) this InstructionPtr points to.- Specified by:
getCodein interfaceInstructionPtr
-
-