com.android.dx.cf.direct
Class CodeObserver

java.lang.Object
  extended by com.android.dx.cf.direct.CodeObserver
All Implemented Interfaces:
BytecodeArray.Visitor

public class CodeObserver
extends Object
implements BytecodeArray.Visitor

Bytecode visitor to use when "observing" bytecode getting parsed.


Constructor Summary
CodeObserver(ByteArray bytes, ParseObserver observer)
          Constructs an instance.
 
Method Summary
 int getPreviousOffset()
          Get previous bytecode offset
 void setPreviousOffset(int offset)
          Set previous bytecode offset
 void visitBranch(int opcode, int offset, int length, int target)
          Visits an instruction which has a branch target argument.
 void visitConstant(int opcode, int offset, int length, Constant cst, int value)
          Visits an instruction which has a (possibly synthetic) constant argument, and possibly also an additional literal integer argument.
 void visitInvalid(int opcode, int offset, int length)
          Visits an invalid instruction.
 void visitLocal(int opcode, int offset, int length, int idx, Type type, int value)
          Visits an instruction which has a local variable index argument.
 void visitNewarray(int offset, int length, CstType cst, ArrayList<Constant> intVals)
          Visits a newarray instruction.
 void visitNoArgs(int opcode, int offset, int length, Type type)
          Visits an instruction which has no inline arguments (implicit or explicit).
 void visitSwitch(int opcode, int offset, int length, SwitchList cases, int padding)
          Visits a switch instruction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeObserver

public CodeObserver(ByteArray bytes,
                    ParseObserver observer)
Constructs an instance.

Parameters:
bytes - non-null; actual array of bytecode
observer - non-null; observer to inform of parsing
Method Detail

visitInvalid

public void visitInvalid(int opcode,
                         int offset,
                         int length)
Visits an invalid instruction.

Specified by:
visitInvalid in interface BytecodeArray.Visitor
Parameters:
opcode - the opcode
offset - offset to the instruction
length - length of the instruction, in bytes

visitNoArgs

public void visitNoArgs(int opcode,
                        int offset,
                        int length,
                        Type type)
Visits an instruction which has no inline arguments (implicit or explicit).

Specified by:
visitNoArgs in interface BytecodeArray.Visitor
Parameters:
opcode - the opcode
offset - offset to the instruction
length - length of the instruction, in bytes
type - non-null; type the instruction operates on

visitLocal

public void visitLocal(int opcode,
                       int offset,
                       int length,
                       int idx,
                       Type type,
                       int value)
Visits an instruction which has a local variable index argument.

Specified by:
visitLocal in interface BytecodeArray.Visitor
Parameters:
opcode - the opcode
offset - offset to the instruction
length - length of the instruction, in bytes
idx - the local variable index
type - non-null; the type of the accessed value
value - additional literal integer argument, if salient (i.e., for iinc)

visitConstant

public void visitConstant(int opcode,
                          int offset,
                          int length,
                          Constant cst,
                          int value)
Visits an instruction which has a (possibly synthetic) constant argument, and possibly also an additional literal integer argument. In the case of multianewarray, the argument is the count of dimensions. In the case of invokeinterface, the argument is the parameter count or'ed with the should-be-zero value left-shifted by 8. In the case of entries of type int, the value field always holds the raw value (for convenience of clients).

Note: In order to avoid giving it a barely-useful visitor all its own, newarray also uses this form, passing value as the array type code and cst as a CstType instance corresponding to the array type.

Specified by:
visitConstant in interface BytecodeArray.Visitor
Parameters:
opcode - the opcode
offset - offset to the instruction
length - length of the instruction, in bytes
cst - non-null; the constant
value - additional literal integer argument, if salient (ignore if not)

visitBranch

public void visitBranch(int opcode,
                        int offset,
                        int length,
                        int target)
Visits an instruction which has a branch target argument.

Specified by:
visitBranch in interface BytecodeArray.Visitor
Parameters:
opcode - the opcode
offset - offset to the instruction
length - length of the instruction, in bytes
target - the absolute (not relative) branch target

visitSwitch

public void visitSwitch(int opcode,
                        int offset,
                        int length,
                        SwitchList cases,
                        int padding)
Visits a switch instruction.

Specified by:
visitSwitch in interface BytecodeArray.Visitor
Parameters:
opcode - the opcode
offset - offset to the instruction
length - length of the instruction, in bytes
cases - non-null; list of (value, target) pairs, plus the default target
padding - the bytes found in the padding area (if any), packed

visitNewarray

public void visitNewarray(int offset,
                          int length,
                          CstType cst,
                          ArrayList<Constant> intVals)
Visits a newarray instruction.

Specified by:
visitNewarray in interface BytecodeArray.Visitor
Parameters:
offset - offset to the instruction
length - length of the instruction, in bytes
cst - non-null; the type of the array
intVals - non-null; list of bytecode offsets for init values

setPreviousOffset

public void setPreviousOffset(int offset)
Set previous bytecode offset

Specified by:
setPreviousOffset in interface BytecodeArray.Visitor
Parameters:
offset - offset of the previous fully parsed bytecode

getPreviousOffset

public int getPreviousOffset()
Get previous bytecode offset

Specified by:
getPreviousOffset in interface BytecodeArray.Visitor
Returns:
return the recored offset of the previous bytecode


Copyright © 2015. All rights reserved.