Package serp.bytecode

Class LocalVariableInstruction

  • All Implemented Interfaces:
    BCEntity, VisitAcceptor
    Direct Known Subclasses:
    IIncInstruction, LoadInstruction, RetInstruction, StoreInstruction, WideInstruction

    public abstract class LocalVariableInstruction
    extends TypedInstruction
    An instruction that has an argument of an index into the local variable table of the current frame. This includes most of the load and store instructions.

    The local variable table size is fixed by the maxLocals property of the code block. Long and double types take up 2 local variable indexes.

    Parameter values to methods are loaded into the local variable table prior to the execution of the first instruction. The 0 index of the table is set to the instance of the class the method is being invoked on.

    • Field Detail

      • _index

        private int _index
    • Constructor Detail

      • LocalVariableInstruction

        LocalVariableInstruction​(Code owner)
      • LocalVariableInstruction

        LocalVariableInstruction​(Code owner,
                                 int opcode)
    • Method Detail

      • getTypeName

        public java.lang.String 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 class TypedInstruction
      • setType

        public TypedInstruction setType​(java.lang.String type)
        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 class TypedInstruction
        Returns:
        this instruction, for method chaining
      • getLocal

        public int getLocal()
        Return the index of the local variable that this instruction operates on.
      • setLocal

        public LocalVariableInstruction setLocal​(int index)
        Set the index of the local variable that this instruction operates on.
        Returns:
        this instruction, for method chaining
      • getParam

        public int getParam()
        Return the parameter that this instruction operates on, or -1 if none.
      • setParam

        public LocalVariableInstruction setParam​(int param)
        Set the method parameter that this instruction operates on. This will set both the local index and the type of the instruction based on the current method parameters.
      • setLocalVariable

        public LocalVariableInstruction setLocalVariable​(LocalVariable local)
        Set the local variable object this instruction operates on. This method will set both the type and local index of this instruction from the given local variable.
        Returns:
        this instruction, for method chaining
      • equalsInstruction

        public boolean equalsInstruction​(Instruction other)
        Two local variable instructions are equal if the local index they reference is equal or if either index is 0/unset.
        Overrides:
        equalsInstruction in class Instruction
      • calculateOpcode

        void calculateOpcode()
        Subclasses with variable opcodes can use this method to be notified that information possibly affecting the opcode has been changed.
      • calculateLocal

        void calculateLocal()
        Subclasses can use this method to calculate the locals index based on their opcode.