Search in sources :

Example 26 with Type

use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.

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 27 with Type

use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.

the class ClassDefsSection method orderItems.

/**
 * {@inheritDoc}
 */
@Override
protected void orderItems() {
    int sz = classDefs.size();
    int idx = 0;
    orderedDefs = new ArrayList<ClassDefItem>(sz);
    /*
         * Iterate over all the classes, recursively assigning an
         * index to each, implicitly skipping the ones that have
         * already been assigned by the time this (top-level)
         * iteration reaches them.
         */
    for (Type type : classDefs.keySet()) {
        idx = orderItems0(type, idx, sz - idx);
    }
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType)

Example 28 with Type

use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.

the class ClassDefsSection method get.

/**
 * {@inheritDoc}
 */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }
    throwIfNotPrepared();
    Type type = ((CstType) cst).getClassType();
    IndexedItem result = classDefs.get(type);
    if (result == null) {
        throw new IllegalArgumentException("not found");
    }
    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)

Example 29 with Type

use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.

the class CodeItem method addContents.

/**
 * {@inheritDoc}
 */
public void addContents(DexFile file) {
    MixedItemSection byteData = file.getByteData();
    TypeIdsSection typeIds = file.getTypeIds();
    if (code.hasPositions() || code.hasLocals()) {
        debugInfo = new DebugInfoItem(code, isStatic, ref);
        byteData.add(debugInfo);
    }
    if (code.hasAnyCatches()) {
        for (Type type : code.getCatchTypes()) {
            typeIds.intern(type);
        }
        catches = new CatchStructs(code);
    }
    for (Constant c : code.getInsnConstants()) {
        file.internIfAppropriate(c);
    }
}
Also used : Type(com.android.dx.rop.type.Type) Constant(com.android.dx.rop.cst.Constant)

Example 30 with Type

use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.

the class DebugInfoEncoder method emitHeader.

/**
 * Emits the header sequence, which consists of LEB128-encoded initial
 * line number and string indicies for names of all non-"this" arguments.
 *
 * @param sortedPositions positions, sorted by ascending address
 * @param methodArgs local list entries for method argumens arguments,
 * in left-to-right order omitting "this"
 * @throws IOException
 */
private void emitHeader(ArrayList<PositionList.Entry> sortedPositions, ArrayList<LocalList.Entry> methodArgs) throws IOException {
    boolean annotate = (annotateTo != null) || (debugPrint != null);
    int mark = output.getCursor();
    // Start by initializing the line number register.
    if (sortedPositions.size() > 0) {
        PositionList.Entry entry = sortedPositions.get(0);
        line = entry.getPosition().getLine();
    }
    output.writeUleb128(line);
    if (annotate) {
        annotate(output.getCursor() - mark, "line_start: " + line);
    }
    int curParam = getParamBase();
    // paramTypes will not include 'this'
    StdTypeList paramTypes = desc.getParameterTypes();
    int szParamTypes = paramTypes.size();
    /*
         * Initialize lastEntryForReg to have an initial
         * entry for the 'this' pointer.
         */
    if (!isStatic) {
        for (LocalList.Entry arg : methodArgs) {
            if (curParam == arg.getRegister()) {
                lastEntryForReg[curParam] = arg;
                break;
            }
        }
        curParam++;
    }
    // Write out the number of parameter entries that will follow.
    mark = output.getCursor();
    output.writeUleb128(szParamTypes);
    if (annotate) {
        annotate(output.getCursor() - mark, String.format("parameters_size: %04x", szParamTypes));
    }
    /*
         * Then emit the string indicies of all the method parameters.
         * Note that 'this', if applicable, is excluded.
         */
    for (int i = 0; i < szParamTypes; i++) {
        Type pt = paramTypes.get(i);
        LocalList.Entry found = null;
        mark = output.getCursor();
        for (LocalList.Entry arg : methodArgs) {
            if (curParam == arg.getRegister()) {
                found = arg;
                if (arg.getSignature() != null) {
                    /*
                         * Parameters with signatures will be re-emitted
                         * in complete as LOCAL_START_EXTENDED's below.
                         */
                    emitStringIndex(null);
                } else {
                    emitStringIndex(arg.getName());
                }
                lastEntryForReg[curParam] = arg;
                break;
            }
        }
        if (found == null) {
            /*
                 * Emit a null symbol for "unnamed." This is common
                 * for, e.g., synthesized methods and inner-class
                 * this$0 arguments.
                 */
            emitStringIndex(null);
        }
        if (annotate) {
            String parameterName = (found == null || found.getSignature() != null) ? "<unnamed>" : found.getName().toHuman();
            annotate(output.getCursor() - mark, "parameter " + parameterName + " " + RegisterSpec.PREFIX + curParam);
        }
        curParam += pt.getCategory();
    }
    for (LocalList.Entry arg : lastEntryForReg) {
        if (arg == null) {
            continue;
        }
        CstString signature = arg.getSignature();
        if (signature != null) {
            emitLocalStartExtended(arg);
        }
    }
}
Also used : LocalList(com.android.dx.dex.code.LocalList) Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) StdTypeList(com.android.dx.rop.type.StdTypeList) PositionList(com.android.dx.dex.code.PositionList) CstString(com.android.dx.rop.cst.CstString) CstString(com.android.dx.rop.cst.CstString)

Aggregations

Type (com.android.dx.rop.type.Type)62 CstType (com.android.dx.rop.cst.CstType)36 StdTypeList (com.android.dx.rop.type.StdTypeList)10 TypeBearer (com.android.dx.rop.type.TypeBearer)10 Constant (com.android.dx.rop.cst.Constant)8 CstString (com.android.dx.rop.cst.CstString)8 RegisterSpec (com.android.dx.rop.code.RegisterSpec)6 TypeList (com.android.dx.rop.type.TypeList)6 BasicBlock (com.android.dx.rop.code.BasicBlock)4 Insn (com.android.dx.rop.code.Insn)4 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)4 PlainInsn (com.android.dx.rop.code.PlainInsn)4 SourcePosition (com.android.dx.rop.code.SourcePosition)4 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)4 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)4 CstInteger (com.android.dx.rop.cst.CstInteger)4 IntList (com.android.dx.util.IntList)4 ByteArrayByteInput (com.android.dex.util.ByteArrayByteInput)2 ByteInput (com.android.dex.util.ByteInput)2 AttInnerClasses (com.android.dx.cf.attrib.AttInnerClasses)2