com.android.dx.rop.type.StdTypeList Java Examples

The following examples show how to use com.android.dx.rop.type.StdTypeList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ByteCatchList.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a rop-style catches list equivalent to this one.
 *
 * @return {@code non-null;} the converted instance
 */
public TypeList toRopCatchList() {
    int sz = size();
    if (sz == 0) {
        return StdTypeList.EMPTY;
    }

    StdTypeList result = new StdTypeList(sz);

    for (int i = 0; i < sz; i++) {
        result.set(i, get(i).getExceptionClass().getClassType());
    }

    result.setImmutable();
    return result;
}
 
Example #2
Source File: ByteCatchList.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a rop-style catches list equivalent to this one.
 *
 * @return {@code non-null;} the converted instance
 */
public TypeList toRopCatchList() {
    int sz = size();
    if (sz == 0) {
        return StdTypeList.EMPTY;
    }

    StdTypeList result = new StdTypeList(sz);

    for (int i = 0; i < sz; i++) {
        result.set(i, get(i).getExceptionClass().getClassType());
    }

    result.setImmutable();
    return result;
}
 
Example #3
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code filled-new-array} rop for the given
 * type. The result may be a shared instance.
 *
 * @param arrayType {@code non-null;} type of array being created
 * @param count {@code count >= 0;} number of elements that the array should have
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opFilledNewArray(TypeBearer arrayType, int count) {
    Type type = arrayType.getType();
    Type elementType = type.getComponentType();

    if (elementType.isCategory2()) {
        return throwBadType(arrayType);
    }

    if (count < 0) {
        throw new IllegalArgumentException("count < 0");
    }

    StdTypeList sourceTypes = new StdTypeList(count);

    for (int i = 0; i < count; i++) {
        sourceTypes.set(i, elementType);
    }

    // Note: The resulting rop is considered call-like.
    return new Rop(RegOps.FILLED_NEW_ARRAY,
                   sourceTypes,
                   Exceptions.LIST_Error);
}
 
Example #4
Source File: ByteCatchList.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a rop-style catches list equivalent to this one.
 *
 * @return {@code non-null;} the converted instance
 */
public TypeList toRopCatchList() {
    int sz = size();
    if (sz == 0) {
        return StdTypeList.EMPTY;
    }

    StdTypeList result = new StdTypeList(sz);

    for (int i = 0; i < sz; i++) {
        result.set(i, get(i).getExceptionClass().getClassType());
    }

    result.setImmutable();
    return result;
}
 
Example #5
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code new-array} rop for the given
 * type. The result is a shared instance.
 *
 * @param arrayType {@code non-null;} array type of array being created
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opNewArray(TypeBearer arrayType) {
    Type type = arrayType.getType();
    Type elementType = type.getComponentType();

    switch (elementType.getBasicType()) {
        case Type.BT_INT:     return NEW_ARRAY_INT;
        case Type.BT_LONG:    return NEW_ARRAY_LONG;
        case Type.BT_FLOAT:   return NEW_ARRAY_FLOAT;
        case Type.BT_DOUBLE:  return NEW_ARRAY_DOUBLE;
        case Type.BT_BOOLEAN: return NEW_ARRAY_BOOLEAN;
        case Type.BT_BYTE:    return NEW_ARRAY_BYTE;
        case Type.BT_CHAR:    return NEW_ARRAY_CHAR;
        case Type.BT_SHORT:   return NEW_ARRAY_SHORT;
        case Type.BT_OBJECT: {
            return new Rop(RegOps.NEW_ARRAY, type, StdTypeList.INT,
                    Exceptions.LIST_Error_NegativeArraySizeException,
                    "new-array-object");
        }
    }

    return throwBadType(type);
}
 
Example #6
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code new-array} rop for the given
 * type. The result is a shared instance.
 *
 * @param arrayType {@code non-null;} array type of array being created
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opNewArray(TypeBearer arrayType) {
    Type type = arrayType.getType();
    Type elementType = type.getComponentType();

    switch (elementType.getBasicType()) {
        case Type.BT_INT:     return NEW_ARRAY_INT;
        case Type.BT_LONG:    return NEW_ARRAY_LONG;
        case Type.BT_FLOAT:   return NEW_ARRAY_FLOAT;
        case Type.BT_DOUBLE:  return NEW_ARRAY_DOUBLE;
        case Type.BT_BOOLEAN: return NEW_ARRAY_BOOLEAN;
        case Type.BT_BYTE:    return NEW_ARRAY_BYTE;
        case Type.BT_CHAR:    return NEW_ARRAY_CHAR;
        case Type.BT_SHORT:   return NEW_ARRAY_SHORT;
        case Type.BT_OBJECT: {
            return new Rop(RegOps.NEW_ARRAY, type, StdTypeList.INT,
                    Exceptions.LIST_Error_NegativeArraySizeException,
                    "new-array-object");
        }
    }

    return throwBadType(type);
}
 
Example #7
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code new-array} rop for the given
 * type. The result is a shared instance.
 *
 * @param arrayType {@code non-null;} array type of array being created
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opNewArray(TypeBearer arrayType) {
    Type type = arrayType.getType();
    Type elementType = type.getComponentType();

    switch (elementType.getBasicType()) {
        case Type.BT_INT:     return NEW_ARRAY_INT;
        case Type.BT_LONG:    return NEW_ARRAY_LONG;
        case Type.BT_FLOAT:   return NEW_ARRAY_FLOAT;
        case Type.BT_DOUBLE:  return NEW_ARRAY_DOUBLE;
        case Type.BT_BOOLEAN: return NEW_ARRAY_BOOLEAN;
        case Type.BT_BYTE:    return NEW_ARRAY_BYTE;
        case Type.BT_CHAR:    return NEW_ARRAY_CHAR;
        case Type.BT_SHORT:   return NEW_ARRAY_SHORT;
        case Type.BT_OBJECT: {
            return new Rop(RegOps.NEW_ARRAY, type, StdTypeList.INT,
                    Exceptions.LIST_Error_NegativeArraySizeException,
                    "new-array-object");
        }
    }

    return throwBadType(type);
}
 
Example #8
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code filled-new-array} rop for the given
 * type. The result may be a shared instance.
 *
 * @param arrayType {@code non-null;} type of array being created
 * @param count {@code count >= 0;} number of elements that the array should have
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opFilledNewArray(TypeBearer arrayType, int count) {
    Type type = arrayType.getType();
    Type elementType = type.getComponentType();

    if (elementType.isCategory2()) {
        return throwBadType(arrayType);
    }

    if (count < 0) {
        throw new IllegalArgumentException("count < 0");
    }

    StdTypeList sourceTypes = new StdTypeList(count);

    for (int i = 0; i < count; i++) {
        sourceTypes.set(i, elementType);
    }

    // Note: The resulting rop is considered call-like.
    return new Rop(RegOps.FILLED_NEW_ARRAY,
                   sourceTypes,
                   Exceptions.LIST_Error);
}
 
Example #9
Source File: BaseMachine.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void popArgs(Frame frame, Prototype prototype) {
    StdTypeList types = prototype.getParameterTypes();
    int size = types.size();

    // Use the above method to do the actual popping...
    popArgs(frame, size);

    // ...and then verify the popped types.

    for (int i = 0; i < size; i++) {
        if (! Merger.isPossiblyAssignableFrom(types.getType(i), args[i])) {
            throw new SimException("at stack depth " + (size - 1 - i) +
                    ", expected type " + types.getType(i).toHuman() +
                    " but found " + args[i].getType().toHuman());
        }
    }
}
 
Example #10
Source File: ClassDefItem.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the list of interfaces implemented.
 *
 * @return {@code non-null;} the interfaces list
 */
public TypeList getInterfaces() {
    if (interfaces == null) {
        return StdTypeList.EMPTY;
    }

    return interfaces.getList();
}
 
Example #11
Source File: ProtoIdItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the short-form of the given prototype.
 *
 * @param prototype {@code non-null;} the prototype
 * @return {@code non-null;} the short form
 */
private static CstString makeShortForm(Prototype prototype) {
    StdTypeList parameters = prototype.getParameterTypes();
    int size = parameters.size();
    StringBuilder sb = new StringBuilder(size + 1);

    sb.append(shortFormCharFor(prototype.getReturnType()));

    for (int i = 0; i < size; i++) {
        sb.append(shortFormCharFor(parameters.getType(i)));
    }

    return new CstString(sb.toString());
}
 
Example #12
Source File: TypeListItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected int compareTo0(OffsettedItem other) {
    TypeList thisList = this.list;
    TypeList otherList = ((TypeListItem) other).list;

    return StdTypeList.compareContents(thisList, otherList);
}
 
Example #13
Source File: ProtoIdItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    int shortyIdx = file.getStringIds().indexOf(shortForm);
    int returnIdx = file.getTypeIds().indexOf(prototype.getReturnType());
    int paramsOff = OffsettedItem.getAbsoluteOffsetOr0(parameterTypes);

    if (out.annotates()) {
        StringBuilder sb = new StringBuilder();
        sb.append(prototype.getReturnType().toHuman());
        sb.append(" proto(");

        StdTypeList params = prototype.getParameterTypes();
        int size = params.size();

        for (int i = 0; i < size; i++) {
            if (i != 0) {
                sb.append(", ");
            }
            sb.append(params.getType(i).toHuman());
        }

        sb.append(")");
        out.annotate(0, indexString() + ' ' + sb.toString());
        out.annotate(4, "  shorty_idx:      " + Hex.u4(shortyIdx) +
                " // " + shortForm.toQuoted());
        out.annotate(4, "  return_type_idx: " + Hex.u4(returnIdx) +
                " // " + prototype.getReturnType().toHuman());
        out.annotate(4, "  parameters_off:  " + Hex.u4(paramsOff));
    }

    out.writeInt(shortyIdx);
    out.writeInt(returnIdx);
    out.writeInt(paramsOff);
}
 
Example #14
Source File: ProtoIdItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param prototype {@code non-null;} the constant for the prototype
 */
public ProtoIdItem(Prototype prototype) {
    if (prototype == null) {
        throw new NullPointerException("prototype == null");
    }

    this.prototype = prototype;
    this.shortForm = makeShortForm(prototype);

    StdTypeList parameters = prototype.getParameterTypes();
    this.parameterTypes = (parameters.size() == 0) ? null
        : new TypeListItem(parameters);
}
 
Example #15
Source File: Frame.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize this frame with the method's parameters. Used for the first
 * frame.
 *
 * @param params Type list of method parameters.
 */
public void initializeWithParameters(StdTypeList params) {
    int at = 0;
    int sz = params.size();

    for (int i = 0; i < sz; i++) {
         Type one = params.get(i);
         locals.set(at, one);
         at += one.getCategory();
    }
}
 
Example #16
Source File: ClassDefItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the list of interfaces implemented.
 *
 * @return {@code non-null;} the interfaces list
 */
public TypeList getInterfaces() {
    if (interfaces == null) {
        return StdTypeList.EMPTY;
    }

    return interfaces.getList();
}
 
Example #17
Source File: Frame.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize this frame with the method's parameters. Used for the first
 * frame.
 *
 * @param params Type list of method parameters.
 */
public void initializeWithParameters(StdTypeList params) {
    int at = 0;
    int sz = params.size();

    for (int i = 0; i < sz; i++) {
         Type one = params.get(i);
         locals.set(at, one);
         at += one.getCategory();
    }
}
 
Example #18
Source File: Insn.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
public boolean contentEquals(Insn b) {
    return opcode == b.getOpcode()
            && position.equals(b.getPosition())
            && (getClass() == b.getClass())
            && equalsHandleNulls(result, b.getResult())
            && equalsHandleNulls(sources, b.getSources())
            && StdTypeList.equalContents(getCatches(), b.getCatches());
}
 
Example #19
Source File: Code.java    From dexmaker with Apache License 2.0 5 votes vote down vote up
/**
 * Compare ints or references. If the comparison is true, execution jumps to
 * {@code trueLabel}. If it is false, execution continues to the next
 * instruction.
 */
public <T> void compare(Comparison comparison, Label trueLabel, Local<T> a, Local<T> b) {
    adopt(trueLabel);
    Rop rop = comparison.rop(StdTypeList.make(a.type.ropType, b.type.ropType));
    addInstruction(new PlainInsn(rop, sourcePosition, null,
            RegisterSpecList.make(a.spec(), b.spec())), trueLabel);
}
 
Example #20
Source File: ProtoIdItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param prototype {@code non-null;} the constant for the prototype
 */
public ProtoIdItem(Prototype prototype) {
    if (prototype == null) {
        throw new NullPointerException("prototype == null");
    }

    this.prototype = prototype;
    this.shortForm = makeShortForm(prototype);

    StdTypeList parameters = prototype.getParameterTypes();
    this.parameterTypes = (parameters.size() == 0) ? null
        : new TypeListItem(parameters);
}
 
Example #21
Source File: ProtoIdItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the short-form of the given prototype.
 *
 * @param prototype {@code non-null;} the prototype
 * @return {@code non-null;} the short form
 */
private static CstString makeShortForm(Prototype prototype) {
    StdTypeList parameters = prototype.getParameterTypes();
    int size = parameters.size();
    StringBuilder sb = new StringBuilder(size + 1);

    sb.append(shortFormCharFor(prototype.getReturnType()));

    for (int i = 0; i < size; i++) {
        sb.append(shortFormCharFor(parameters.getType(i)));
    }

    return new CstString(sb.toString());
}
 
Example #22
Source File: ProtoIdItem.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    int shortyIdx = file.getStringIds().indexOf(shortForm);
    int returnIdx = file.getTypeIds().indexOf(prototype.getReturnType());
    int paramsOff = OffsettedItem.getAbsoluteOffsetOr0(parameterTypes);

    if (out.annotates()) {
        StringBuilder sb = new StringBuilder();
        sb.append(prototype.getReturnType().toHuman());
        sb.append(" proto(");

        StdTypeList params = prototype.getParameterTypes();
        int size = params.size();

        for (int i = 0; i < size; i++) {
            if (i != 0) {
                sb.append(", ");
            }
            sb.append(params.getType(i).toHuman());
        }

        sb.append(")");
        out.annotate(0, indexString() + ' ' + sb.toString());
        out.annotate(4, "  shorty_idx:      " + Hex.u4(shortyIdx) +
                " // " + shortForm.toQuoted());
        out.annotate(4, "  return_type_idx: " + Hex.u4(returnIdx) +
                " // " + prototype.getReturnType().toHuman());
        out.annotate(4, "  parameters_off:  " + Hex.u4(paramsOff));
    }

    out.writeInt(shortyIdx);
    out.writeInt(returnIdx);
    out.writeInt(paramsOff);
}
 
Example #23
Source File: Frame.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize this frame with the method's parameters. Used for the first
 * frame.
 *
 * @param params Type list of method parameters.
 */
public void initializeWithParameters(StdTypeList params) {
    int at = 0;
    int sz = params.size();

    for (int i = 0; i < sz; i++) {
         Type one = params.get(i);
         locals.set(at, one);
         at += one.getCategory();
    }
}
 
Example #24
Source File: ProtoIdItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the short-form of the given prototype.
 *
 * @param prototype {@code non-null;} the prototype
 * @return {@code non-null;} the short form
 */
private static CstString makeShortForm(Prototype prototype) {
    StdTypeList parameters = prototype.getParameterTypes();
    int size = parameters.size();
    StringBuilder sb = new StringBuilder(size + 1);

    sb.append(shortFormCharFor(prototype.getReturnType()));

    for (int i = 0; i < size; i++) {
        sb.append(shortFormCharFor(parameters.getType(i)));
    }

    return new CstString(sb.toString());
}
 
Example #25
Source File: Insn.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
public boolean contentEquals(Insn b) {
    return opcode == b.getOpcode()
            && position.equals(b.getPosition())
            && (getClass() == b.getClass())
            && equalsHandleNulls(result, b.getResult())
            && equalsHandleNulls(sources, b.getSources())
            && StdTypeList.equalContents(getCatches(), b.getCatches());
}
 
Example #26
Source File: ClassDefItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the list of interfaces implemented.
 *
 * @return {@code non-null;} the interfaces list
 */
public TypeList getInterfaces() {
    if (interfaces == null) {
        return StdTypeList.EMPTY;
    }

    return interfaces.getList();
}
 
Example #27
Source File: DexMaker.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
EncodedMethod toEncodedMethod(DexOptions dexOptions) {
    if (code != null) {
        RopMethod ropMethod = new RopMethod(code.toBasicBlocks(), 0);
        LocalVariableInfo locals = null;
        DalvCode dalvCode = RopTranslator.translate(
                ropMethod, PositionList.NONE, locals, code.paramSize(), dexOptions);
        return new EncodedMethod(method.constant, flags, dalvCode, StdTypeList.EMPTY);
    } else return new EncodedMethod(method.constant, flags, null, StdTypeList.EMPTY);

}
 
Example #28
Source File: Frame.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize this frame with the method's parameters. Used for the first
 * frame.
 *
 * @param params Type list of method parameters.
 */
public void initializeWithParameters(StdTypeList params) {
    int at = 0;
    int sz = params.size();

    for (int i = 0; i < sz; i++) {
         Type one = params.get(i);
         locals.set(at, one);
         at += one.getCategory();
    }
}
 
Example #29
Source File: Code.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Compare ints or references. If the comparison is true, execution jumps to
 * {@code trueLabel}. If it is false, execution continues to the next
 * instruction.
 */
public <T> void compare(Comparison comparison, Label trueLabel, Local<T> a, Local<T> b) {
    adopt(trueLabel);
    Rop rop = comparison.rop(StdTypeList.make(a.type.ropType, b.type.ropType));
    addInstruction(new PlainInsn(rop, sourcePosition, null,
            RegisterSpecList.make(a.spec(), b.spec())), trueLabel);
}
 
Example #30
Source File: AttributeTranslator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the list of thrown exceptions for a given method.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the list of thrown exceptions
 */
public static TypeList getExceptions(Method method) {
    AttributeList attribs = method.getAttributes();
    AttExceptions exceptions = (AttExceptions)
        attribs.findFirst(AttExceptions.ATTRIBUTE_NAME);

    if (exceptions == null) {
        return StdTypeList.EMPTY;
    }

    return exceptions.getExceptions();
}