Search in sources :

Example 41 with CstType

use of com.android.dx.rop.cst.CstType 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 42 with CstType

use of com.android.dx.rop.cst.CstType in project buck by facebook.

the class TypeIdItem method writeTo.

/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    CstType type = getDefiningClass();
    CstString descriptor = type.getDescriptor();
    int idx = file.getStringIds().indexOf(descriptor);
    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + descriptor.toHuman());
        out.annotate(4, "  descriptor_idx: " + Hex.u4(idx));
    }
    out.writeInt(idx);
}
Also used : CstType(com.android.dx.rop.cst.CstType) CstString(com.android.dx.rop.cst.CstString)

Aggregations

CstType (com.android.dx.rop.cst.CstType)42 Constant (com.android.dx.rop.cst.Constant)15 CstString (com.android.dx.rop.cst.CstString)15 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)11 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)10 Type (com.android.dx.rop.type.Type)8 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)6 StdTypeList (com.android.dx.rop.type.StdTypeList)6 TypeList (com.android.dx.rop.type.TypeList)6 CstInsn (com.android.dx.dex.code.CstInsn)5 Annotations (com.android.dx.rop.annotation.Annotations)5 RegisterSpec (com.android.dx.rop.code.RegisterSpec)5 CstNat (com.android.dx.rop.cst.CstNat)5 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)4 Annotation (com.android.dx.rop.annotation.Annotation)4 ByteArray (com.android.dx.util.ByteArray)4 IntList (com.android.dx.util.IntList)4 FileNotFoundException (java.io.FileNotFoundException)4 AttEnclosingMethod (com.android.dx.cf.attrib.AttEnclosingMethod)3 MethodList (com.android.dx.cf.iface.MethodList)3