Package serp.bytecode
Class ConstantInstruction
java.lang.Object
serp.bytecode.CodeEntry
serp.bytecode.Instruction
serp.bytecode.TypedInstruction
serp.bytecode.ConstantInstruction
- All Implemented Interfaces:
BCEntity
,VisitAcceptor
An instruction that that loads a constant onto the stack.
The opcode represented by this instruction may change depending on the
type and value of the constant set. For example, if the constant value
is initially set to 5, the opcode will be
iconst5
; if later
incremented to 6, the opcode will be changed to bipush(6)
.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptVisit
(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.private void
calculateOpcode
(Object value, boolean clsName, boolean wide) private void
When adding class entries, make sure the bytecode spec supports them.boolean
equalsInstruction
(Instruction other) ConstantInstructions are equal if the const they reference is the same, or if the const of either is unset.Return the class value of this constant, or null if not set.double
Return the double value of this constant, or 0 if not set.float
Return the float value of this constant, or 0 if not set.int
Return the int value of this constant, or 0 if not set.(package private) int
Return the length in bytes of this opcode, including all arguments.int
Return the logical number of stack positions changed by this instruction.long
Return the long value of this constant, or 0 if not set.int
Return the number of stack positions this instruction pushes or pops during its execution.Return the string value of this constant, or null if not set.Return the type name for this instruction.getValue()
Return the value of the constant as its wrapper type, or null if not set.(package private) void
Read the arguments for this opcode from the given stream.(package private) void
read
(Instruction orig) Copy the given instruction data.setNull()
Set this constant to null.Set the type of this instruction.setValue
(boolean value) Set the value of this constant; note that this type is converted to int.setValue
(char value) Set the value of this constant; note that this type is converted to int.setValue
(double value) Set the value of this constant.setValue
(float value) Set the value of this constant.setValue
(int value) Set the value of this constant.setValue
(long value) Set the value of this constant.setValue
(short value) Set the value of this constant; note that this type is converted to int.Set the value of this constant.Set the constant to the given value.Set the value of this constant.Set the value of this constant.(package private) void
write
(DataOutput out) Write the arguments for this opcode to the given stream.Methods inherited from class serp.bytecode.TypedInstruction
getType, getTypeBC, mapType, setType, setType
Methods inherited from class serp.bytecode.Instruction
getByteIndex, getClassLoader, getCode, getLineNumber, getName, getOpcode, getPool, getProject, invalidate, invalidateByteIndexes, isValid, setOpcode
-
Field Details
-
_arg
private int _arg
-
-
Constructor Details
-
Method Details
-
getLength
int getLength()Description copied from class:Instruction
Return the length in bytes of this opcode, including all arguments. For many opcodes this method relies on an up-to-date byte index.- Overrides:
getLength
in classInstruction
-
getStackChange
public int getStackChange()Description copied from class:Instruction
Return the number of stack positions this instruction pushes or pops during its execution.- Overrides:
getStackChange
in classInstruction
- Returns:
- 0 if the stack is not affected by this instruction, a positive number if it pushes onto the stack, and a negative number if it pops from the stack
-
getLogicalStackChange
public int getLogicalStackChange()Description copied from class:Instruction
Return the logical number of stack positions changed by this instruction. In other words, ignore weirdness with longs and doubles taking two stack positions.- Overrides:
getLogicalStackChange
in classInstruction
-
getTypeName
Description copied from class:TypedInstruction
Return the type name for this instruction. If the type has not been set, this method will return null.- Specified by:
getTypeName
in classTypedInstruction
-
setType
Description copied from class:TypedInstruction
Set the type of this instruction. Types that have no direct support will be converted accordingly.- Specified by:
setType
in classTypedInstruction
- Returns:
- this instruction, for method chaining
-
getValue
Return the value of the constant as its wrapper type, or null if not set. Returns class values as the class name. -
setValue
Set the constant to the given value. The value should be an instance of String, Integer, Long, Double, Float, Class, BCClass, or null depending on the constant type. If the given value is not supported directly, it will be converted accordingly.- Returns:
- this instruction, for method chaining
-
getStringValue
Return the string value of this constant, or null if not set. -
getIntValue
public int getIntValue()Return the int value of this constant, or 0 if not set. -
getLongValue
public long getLongValue()Return the long value of this constant, or 0 if not set. -
getFloatValue
public float getFloatValue()Return the float value of this constant, or 0 if not set. -
getDoubleValue
public double getDoubleValue()Return the double value of this constant, or 0 if not set. -
getClassNameValue
Return the class value of this constant, or null if not set. -
setNull
Set this constant to null.- Returns:
- this instruction, for method chaining
-
setValue
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
-
setValue
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
Set the value of this constant; note that this type is converted to int.- Returns:
- this instruction, for method chaining
-
setValue
Set the value of this constant; note that this type is converted to int.- Returns:
- this instruction, for method chaining
-
setValue
Set the value of this constant; note that this type is converted to int.- Returns:
- this instruction, for method chaining
-
equalsInstruction
ConstantInstructions are equal if the const they reference is the same, or if the const of either is unset.- Overrides:
equalsInstruction
in classInstruction
-
acceptVisit
Description copied from interface:VisitAcceptor
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.- Specified by:
acceptVisit
in interfaceVisitAcceptor
- Overrides:
acceptVisit
in classInstruction
-
read
Description copied from class:Instruction
Copy the given instruction data.- Overrides:
read
in classInstruction
-
read
Description copied from class:Instruction
Read the arguments for this opcode from the given stream. This method should be overridden by opcodes that take arguments.- Overrides:
read
in classInstruction
- Throws:
IOException
-
write
Description copied from class:Instruction
Write the arguments for this opcode to the given stream. This method should be overridden by opcodes that take arguments.- Overrides:
write
in classInstruction
- Throws:
IOException
-
calculateOpcode
-
ensureBytecodeVersion
private void ensureBytecodeVersion()When adding class entries, make sure the bytecode spec supports them.
-