Search in sources :

Example 11 with TypeList

use of com.android.dx.rop.type.TypeList in project buck by facebook.

the class StdAttributeFactory method exceptions.

/**
     * Parses an {@code Exceptions} attribute.
     */
private Attribute exceptions(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }
    ByteArray bytes = cf.getBytes();
    // number_of_exceptions
    int count = bytes.getUnsignedShort(offset);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "number_of_exceptions: " + Hex.u2(count));
    }
    offset += 2;
    length -= 2;
    if (length != (count * 2)) {
        throwBadLength((count * 2) + 2);
    }
    TypeList list = cf.makeTypeList(offset, count);
    return new AttExceptions(list);
}
Also used : AttExceptions(com.android.dx.cf.attrib.AttExceptions) ByteArray(com.android.dx.util.ByteArray) TypeList(com.android.dx.rop.type.TypeList)

Example 12 with TypeList

use of com.android.dx.rop.type.TypeList in project buck by facebook.

the class StdCatchBuilder method hasAnyCatches.

/** {@inheritDoc} */
public boolean hasAnyCatches() {
    BasicBlockList blocks = method.getBlocks();
    int size = blocks.size();
    for (int i = 0; i < size; i++) {
        BasicBlock block = blocks.get(i);
        TypeList catches = block.getLastInsn().getCatches();
        if (catches.size() != 0) {
            return true;
        }
    }
    return false;
}
Also used : BasicBlock(com.android.dx.rop.code.BasicBlock) BasicBlockList(com.android.dx.rop.code.BasicBlockList) TypeList(com.android.dx.rop.type.TypeList)

Example 13 with TypeList

use of com.android.dx.rop.type.TypeList in project buck by facebook.

the class StdCatchBuilder method handlersFor.

/**
     * Makes the {@link CatchHandlerList} for the given basic block.
     *
     * @param block {@code non-null;} block to get entries for
     * @param addresses {@code non-null;} address objects for each block
     * @return {@code non-null;} array of entries
     */
private static CatchHandlerList handlersFor(BasicBlock block, BlockAddresses addresses) {
    IntList successors = block.getSuccessors();
    int succSize = successors.size();
    int primary = block.getPrimarySuccessor();
    TypeList catches = block.getLastInsn().getCatches();
    int catchSize = catches.size();
    if (catchSize == 0) {
        return CatchHandlerList.EMPTY;
    }
    if (((primary == -1) && (succSize != catchSize)) || ((primary != -1) && ((succSize != (catchSize + 1)) || (primary != successors.get(catchSize))))) {
        /*
             * Blocks that throw are supposed to list their primary
             * successor -- if any -- last in the successors list, but
             * that constraint appears to be violated here.
             */
        throw new RuntimeException("shouldn't happen: weird successors list");
    }
    /*
         * Reduce the effective catchSize if we spot a catch-all that
         * isn't at the end.
         */
    for (int i = 0; i < catchSize; i++) {
        Type type = catches.getType(i);
        if (type.equals(Type.OBJECT)) {
            catchSize = i + 1;
            break;
        }
    }
    CatchHandlerList result = new CatchHandlerList(catchSize);
    for (int i = 0; i < catchSize; i++) {
        CstType oneType = new CstType(catches.getType(i));
        CodeAddress oneHandler = addresses.getStart(successors.get(i));
        result.set(i, oneType, oneHandler.getAddress());
    }
    result.setImmutable();
    return result;
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) CstType(com.android.dx.rop.cst.CstType) TypeList(com.android.dx.rop.type.TypeList) IntList(com.android.dx.util.IntList)

Example 14 with TypeList

use of com.android.dx.rop.type.TypeList in project buck by facebook.

the class StdCatchBuilder method getCatchTypes.

/** {@inheritDoc} */
public HashSet<Type> getCatchTypes() {
    HashSet<Type> result = new HashSet<Type>(20);
    BasicBlockList blocks = method.getBlocks();
    int size = blocks.size();
    for (int i = 0; i < size; i++) {
        BasicBlock block = blocks.get(i);
        TypeList catches = block.getLastInsn().getCatches();
        int catchSize = catches.size();
        for (int j = 0; j < catchSize; j++) {
            result.add(catches.getType(j));
        }
    }
    return result;
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) BasicBlock(com.android.dx.rop.code.BasicBlock) BasicBlockList(com.android.dx.rop.code.BasicBlockList) TypeList(com.android.dx.rop.type.TypeList) HashSet(java.util.HashSet)

Aggregations

TypeList (com.android.dx.rop.type.TypeList)14 StdTypeList (com.android.dx.rop.type.StdTypeList)8 CstType (com.android.dx.rop.cst.CstType)7 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)3 BasicBlock (com.android.dx.rop.code.BasicBlock)3 Type (com.android.dx.rop.type.Type)3 FileNotFoundException (java.io.FileNotFoundException)3 Annotations (com.android.dx.rop.annotation.Annotations)2 BasicBlockList (com.android.dx.rop.code.BasicBlockList)2 IntList (com.android.dx.util.IntList)2 AttExceptions (com.android.dx.cf.attrib.AttExceptions)1 AttRuntimeInvisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations)1 AttRuntimeInvisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations)1 AttRuntimeVisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations)1 AttRuntimeVisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations)1 ConcreteMethod (com.android.dx.cf.code.ConcreteMethod)1 Method (com.android.dx.cf.iface.Method)1 MethodList (com.android.dx.cf.iface.MethodList)1 DalvCode (com.android.dx.dex.code.DalvCode)1 EncodedMethod (com.android.dx.dex.file.EncodedMethod)1