Package serp.bytecode
Class ConstantInstruction
- java.lang.Object
-
- serp.bytecode.Instruction
-
- serp.bytecode.TypedInstruction
-
- serp.bytecode.ConstantInstruction
-
- All Implemented Interfaces:
BCEntity,VisitAcceptor
public class ConstantInstruction extends TypedInstruction
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 beiconst5; if later incremented to 6, the opcode will be changed tobipush(6).- Author:
- Abe White
-
-
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.booleanequalsInstruction(Instruction other)ConstantInstructions are equal if the const they reference is the same, or if the const of either is unset.java.lang.StringgetClassNameValue()Return the class value of this constant, or null if not set.doublegetDoubleValue()Return the double value of this constant, or 0 if not set.floatgetFloatValue()Return the float value of this constant, or 0 if not set.intgetIntValue()Return the int value of this constant, or 0 if not set.intgetLogicalStackChange()Return the logical number of stack positions changed by this instruction.longgetLongValue()Return the long value of this constant, or 0 if not set.intgetStackChange()Return the number of stack positions this instruction pushes or pops during its execution.java.lang.StringgetStringValue()Return the string value of this constant, or null if not set.java.lang.StringgetTypeName()Return the type name for this instruction.java.lang.ObjectgetValue()Return the value of the constant as its wrapper type, or null if not set.ConstantInstructionsetNull()Set this constant to null.TypedInstructionsetType(java.lang.String type)Set the type of this instruction.ConstantInstructionsetValue(boolean value)Set the value of this constant; note that this type is converted to int.ConstantInstructionsetValue(char value)Set the value of this constant; note that this type is converted to int.ConstantInstructionsetValue(double value)Set the value of this constant.ConstantInstructionsetValue(float value)Set the value of this constant.ConstantInstructionsetValue(int value)Set the value of this constant.ConstantInstructionsetValue(long value)Set the value of this constant.ConstantInstructionsetValue(short value)Set the value of this constant; note that this type is converted to int.ConstantInstructionsetValue(java.lang.Class value)Set the value of this constant.ConstantInstructionsetValue(java.lang.Object value)Set the constant to the given value.ConstantInstructionsetValue(java.lang.String value)Set the value of this constant.ConstantInstructionsetValue(java.lang.String value, boolean clsName)ConstantInstructionsetValue(BCClass value)Set the value of this constant.-
Methods inherited from class serp.bytecode.TypedInstruction
getType, getTypeBC, setType, setType
-
Methods inherited from class serp.bytecode.Instruction
getByteIndex, getClassLoader, getCode, getLineNumber, getName, getOpcode, getPool, getProject, isValid
-
-
-
-
Method Detail
-
getStackChange
public int getStackChange()
Description copied from class:InstructionReturn the number of stack positions this instruction pushes or pops during its execution.- Overrides:
getStackChangein 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:InstructionReturn the logical number of stack positions changed by this instruction. In other words, ignore weirdness with longs and doubles taking two stack positions.- Overrides:
getLogicalStackChangein classInstruction
-
getTypeName
public java.lang.String getTypeName()
Description copied from class:TypedInstructionReturn the type name for this instruction. If the type has not been set, this method will return null.- Specified by:
getTypeNamein classTypedInstruction
-
setType
public TypedInstruction setType(java.lang.String type)
Description copied from class:TypedInstructionSet the type of this instruction. Types that have no direct support will be converted accordingly.- Specified by:
setTypein classTypedInstruction- Returns:
- this instruction, for method chaining
-
getValue
public java.lang.Object getValue()
Return the value of the constant as its wrapper type, or null if not set. Returns class values as the class name.
-
setValue
public ConstantInstruction setValue(java.lang.Object value)
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
public java.lang.String 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
public java.lang.String getClassNameValue()
Return the class value of this constant, or null if not set.
-
setNull
public ConstantInstruction setNull()
Set this constant to null.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(java.lang.String value)
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(java.lang.String value, boolean clsName)
-
setValue
public ConstantInstruction setValue(java.lang.Class value)
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(BCClass value)
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(int value)
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(long value)
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(float value)
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(double value)
Set the value of this constant.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(boolean value)
Set the value of this constant; note that this type is converted to int.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(short value)
Set the value of this constant; note that this type is converted to int.- Returns:
- this instruction, for method chaining
-
setValue
public ConstantInstruction setValue(char value)
Set the value of this constant; note that this type is converted to int.- Returns:
- this instruction, for method chaining
-
equalsInstruction
public boolean equalsInstruction(Instruction other)
ConstantInstructions are equal if the const they reference is the same, or if the const of either is unset.- Overrides:
equalsInstructionin classInstruction
-
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- Overrides:
acceptVisitin classInstruction
-
-