FileDocCategorySizeDatePackage
Insn.javaAPI DocAndroid 5.1 API13555Thu Mar 12 22:18:30 GMT 2015com.android.dx.rop.code

Insn

public abstract class Insn extends Object implements com.android.dx.util.ToHuman
A register-based instruction. An instruction is the combination of an opcode (which specifies operation and source/result types), a list of actual sources and result registers/values, and additional information.

Fields Summary
private final Rop
opcode
{@code non-null;} opcode
private final SourcePosition
position
{@code non-null;} source position
private final RegisterSpec
result
{@code null-ok;} spec for the result of this instruction, if any
private final RegisterSpecList
sources
{@code non-null;} specs for all the sources of this instruction
Constructors Summary
public Insn(Rop opcode, SourcePosition position, RegisterSpec result, RegisterSpecList sources)
Constructs an instance.

param
opcode {@code non-null;} the opcode
param
position {@code non-null;} source position
param
result {@code null-ok;} spec for the result, if any
param
sources {@code non-null;} specs for all the sources

        if (opcode == null) {
            throw new NullPointerException("opcode == null");
        }

        if (position == null) {
            throw new NullPointerException("position == null");
        }

        if (sources == null) {
            throw new NullPointerException("sources == null");
        }

        this.opcode = opcode;
        this.position = position;
        this.result = result;
        this.sources = sources;
    
Methods Summary
public abstract voidaccept(com.android.dx.rop.code.Insn$Visitor visitor)
Calls the appropriate method on the given visitor, depending on the class of this instance. Subclasses must override this.

param
visitor {@code non-null;} the visitor to call on

public final booleancanThrow()
Gets whether this instruction can possibly throw an exception. This is just a convenient wrapper for {@code getOpcode().canThrow()}.

return
{@code true} iff this instruction can possibly throw

        return opcode.canThrow();
    
public booleancontentEquals(com.android.dx.rop.code.Insn b)
Compares Insn contents, since {@code Insn.equals()} is defined to be an identity compare. Insn's are {@code contentEquals()} if they have the same opcode, registers, source position, and other metadata.

return
true in the case described above

        return opcode == b.getOpcode()
                && position.equals(b.getPosition())
                && (getClass() == b.getClass())
                && equalsHandleNulls(result, b.getResult())
                && equalsHandleNulls(sources, b.getSources())
                && StdTypeList.equalContents(getCatches(), b.getCatches());
    
public com.android.dx.rop.code.Insncopy()
Returns an exact copy of this Insn

return
{@code non-null;} an appropriately-constructed instance

        return withRegisterOffset(0);
    
public final booleanequals(java.lang.Object other)
{@inheritDoc} Instances of this class compare by identity. That is, {@code x.equals(y)} is only true if {@code x == y}.

        return (this == other);
    
private static booleanequalsHandleNulls(java.lang.Object a, java.lang.Object b)
Compares, handling nulls safely

param
a first object
param
b second object
return
true if they're equal or both null.

        return (a == b) || ((a != null) && a.equals(b));
    
public abstract com.android.dx.rop.type.TypeListgetCatches()
Gets the list of possibly-caught exceptions. This returns {@link StdTypeList#EMPTY} if this instruction has no handlers, which can be either if this instruction can't possibly throw or if it merely doesn't handle any of its possible exceptions. To determine whether this instruction can throw, use {@link #canThrow}.

return
{@code non-null;} the catches list

public java.lang.StringgetInlineString()
Gets an "inline" string portion for toHuman(), if available. This is the portion that appears after the Rop opcode

return
{@code null-ok;} if non-null, the inline text for toHuman()

        return null;
    
public final RegisterSpecgetLocalAssignment()
Gets the spec of a local variable assignment that occurs at this instruction, or null if no local variable assignment occurs. This may be the result register, or for {@code mark-local} insns it may be the source.

return
{@code null-ok;} a named register spec or null

        RegisterSpec assignment;
        if (opcode.getOpcode() == RegOps.MARK_LOCAL) {
            assignment = sources.get(0);
        } else {
            assignment = result;
        }

        if (assignment == null) {
            return null;
        }

        LocalItem localItem = assignment.getLocalItem();

        if (localItem == null) {
            return null;
        }

        return assignment;
    
public final RopgetOpcode()
Gets the opcode.

return
{@code non-null;} the opcode

        return opcode;
    
public final SourcePositiongetPosition()
Gets the source position.

return
{@code non-null;} the source position

        return position;
    
public final RegisterSpecgetResult()
Gets the result spec, if any. A return value of {@code null} means this instruction returns nothing.

return
{@code null-ok;} the result spec, if any

        return result;
    
public final RegisterSpecListgetSources()
Gets the source specs.

return
{@code non-null;} the source specs

        return sources;
    
public final inthashCode()
{@inheritDoc} This implementation returns the identity hashcode of this instance. This is proper, since instances of this class compare by identity (see {@link #equals}).

        return System.identityHashCode(this);
    
public java.lang.StringtoHuman()
Gets a human-oriented (and slightly lossy) string for this instance.

return
{@code non-null;} the human string form

        return toHumanWithInline(getInlineString());
    
protected final java.lang.StringtoHumanWithInline(java.lang.String extra)
Returns the human string form of this instance, with the given bit added in the standard location for an inline argument.

param
extra {@code null-ok;} the inline argument string
return
{@code non-null;} the human string form

        StringBuffer sb = new StringBuffer(80);

        sb.append(position);
        sb.append(": ");
        sb.append(opcode.getNickname());

        if (extra != null) {
            sb.append("(");
            sb.append(extra);
            sb.append(")");
        }

        if (result == null) {
            sb.append(" .");
        } else {
            sb.append(" ");
            sb.append(result.toHuman());
        }

        sb.append(" <-");

        int sz = sources.size();
        if (sz == 0) {
            sb.append(" .");
        } else {
            for (int i = 0; i < sz; i++) {
                sb.append(" ");
                sb.append(sources.get(i).toHuman());
            }
        }

        return sb.toString();
    
public java.lang.StringtoString()
{@inheritDoc}

        return toStringWithInline(getInlineString());
    
protected final java.lang.StringtoStringWithInline(java.lang.String extra)
Returns the string form of this instance, with the given bit added in the standard location for an inline argument.

param
extra {@code null-ok;} the inline argument string
return
{@code non-null;} the string form

        StringBuffer sb = new StringBuffer(80);

        sb.append("Insn{");
        sb.append(position);
        sb.append(' ");
        sb.append(opcode);

        if (extra != null) {
            sb.append(' ");
            sb.append(extra);
        }

        sb.append(" :: ");

        if (result != null) {
            sb.append(result);
            sb.append(" <- ");
        }

        sb.append(sources);
        sb.append('}");

        return sb.toString();
    
public abstract com.android.dx.rop.code.InsnwithAddedCatch(com.android.dx.rop.type.Type type)
Returns an instance that is just like this one, except that it has a catch list with the given item appended to the end. This method throws an exception if this instance can't possibly throw. To determine whether this instruction can throw, use {@link #canThrow}.

param
type {@code non-null;} type to append to the catch list
return
{@code non-null;} an appropriately-constructed instance

public abstract com.android.dx.rop.code.InsnwithNewRegisters(RegisterSpec result, RegisterSpecList sources)
Returns an instance that is just like this one, except with new result and source registers.

param
result {@code null-ok;} new result register
param
sources {@code non-null;} new sources registers
return
{@code non-null;} an appropriately-constructed instance

public abstract com.android.dx.rop.code.InsnwithRegisterOffset(int delta)
Returns an instance that is just like this one, except that all register references have been offset by the given delta.

param
delta the amount to offset register references by
return
{@code non-null;} an appropriately-constructed instance

public com.android.dx.rop.code.InsnwithSourceLiteral()
Returns an instance that is just like this one, except that, if possible, the insn is converted into a version in which a source (if it is a constant) is represented directly rather than as a register reference. {@code this} is returned in cases where the translation is not possible.

return
{@code non-null;} an appropriately-constructed instance

        return this;