Search in sources :

Example 56 with Type

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

the class ClassDefsSection method orderItems0.

/**
 * Helper for {@link #orderItems}, which recursively assigns indices
 * to classes.
 *
 * @param type {@code null-ok;} type ref to assign, if any
 * @param idx {@code >= 0;} the next index to assign
 * @param maxDepth maximum recursion depth; if negative, this will
 * throw an exception indicating class definition circularity
 * @return {@code >= 0;} the next index to assign
 */
private int orderItems0(Type type, int idx, int maxDepth) {
    ClassDefItem c = classDefs.get(type);
    if ((c == null) || (c.hasIndex())) {
        return idx;
    }
    if (maxDepth < 0) {
        throw new RuntimeException("class circularity with " + type);
    }
    maxDepth--;
    CstType superclassCst = c.getSuperclass();
    if (superclassCst != null) {
        Type superclass = superclassCst.getClassType();
        idx = orderItems0(superclass, idx, maxDepth);
    }
    TypeList interfaces = c.getInterfaces();
    int sz = interfaces.size();
    for (int i = 0; i < sz; i++) {
        idx = orderItems0(interfaces.getType(i), idx, maxDepth);
    }
    c.setIndex(idx);
    orderedDefs.add(c);
    return idx + 1;
}
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)

Example 57 with Type

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

the class ClassDefsSection method add.

/**
 * Adds an element to this instance. It is illegal to attempt to add more
 * than one class with the same name.
 *
 * @param clazz {@code non-null;} the class def to add
 */
public void add(ClassDefItem clazz) {
    Type type;
    try {
        type = clazz.getThisClass().getClassType();
    } catch (NullPointerException ex) {
        // Elucidate the exception.
        throw new NullPointerException("clazz == null");
    }
    throwIfPrepared();
    if (classDefs.get(type) != null) {
        throw new IllegalArgumentException("already added: " + type);
    }
    classDefs.put(type, clazz);
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType)

Example 58 with Type

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

the class DebugInfoDecoder method decode0.

private void decode0() throws IOException {
    ByteInput bs = new ByteArrayByteInput(encoded);
    line = Leb128.readUnsignedLeb128(bs);
    int szParams = Leb128.readUnsignedLeb128(bs);
    StdTypeList params = desc.getParameterTypes();
    int curReg = getParamBase();
    if (szParams != params.size()) {
        throw new RuntimeException("Mismatch between parameters_size and prototype");
    }
    if (!isStatic) {
        // Start off with implicit 'this' entry
        LocalEntry thisEntry = new LocalEntry(0, true, curReg, thisStringIdx, 0, 0);
        locals.add(thisEntry);
        lastEntryForReg[curReg] = thisEntry;
        curReg++;
    }
    for (int i = 0; i < szParams; i++) {
        Type paramType = params.getType(i);
        LocalEntry le;
        int nameIdx = readStringIndex(bs);
        if (nameIdx == -1) {
            /*
                 * Unnamed parameter; often but not always filled in by an
                 * extended start op after the prologue
                 */
            le = new LocalEntry(0, true, curReg, -1, 0, 0);
        } else {
            // TODO: Final 0 should be idx of paramType.getDescriptor().
            le = new LocalEntry(0, true, curReg, nameIdx, 0, 0);
        }
        locals.add(le);
        lastEntryForReg[curReg] = le;
        curReg += paramType.getCategory();
    }
    for (; ; ) {
        int opcode = bs.readByte() & 0xff;
        switch(opcode) {
            case DBG_START_LOCAL:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    int nameIdx = readStringIndex(bs);
                    int typeIdx = readStringIndex(bs);
                    LocalEntry le = new LocalEntry(address, true, reg, nameIdx, typeIdx, 0);
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_START_LOCAL_EXTENDED:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    int nameIdx = readStringIndex(bs);
                    int typeIdx = readStringIndex(bs);
                    int sigIdx = readStringIndex(bs);
                    LocalEntry le = new LocalEntry(address, true, reg, nameIdx, typeIdx, sigIdx);
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_RESTART_LOCAL:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    LocalEntry prevle;
                    LocalEntry le;
                    try {
                        prevle = lastEntryForReg[reg];
                        if (prevle.isStart) {
                            throw new RuntimeException("nonsensical " + "RESTART_LOCAL on live register v" + reg);
                        }
                        le = new LocalEntry(address, true, reg, prevle.nameIndex, prevle.typeIndex, 0);
                    } catch (NullPointerException ex) {
                        throw new RuntimeException("Encountered RESTART_LOCAL on new v" + reg);
                    }
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_END_LOCAL:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    LocalEntry prevle;
                    LocalEntry le;
                    try {
                        prevle = lastEntryForReg[reg];
                        if (!prevle.isStart) {
                            throw new RuntimeException("nonsensical " + "END_LOCAL on dead register v" + reg);
                        }
                        le = new LocalEntry(address, false, reg, prevle.nameIndex, prevle.typeIndex, prevle.signatureIndex);
                    } catch (NullPointerException ex) {
                        throw new RuntimeException("Encountered END_LOCAL on new v" + reg);
                    }
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_END_SEQUENCE:
                // all done
                return;
            case DBG_ADVANCE_PC:
                address += Leb128.readUnsignedLeb128(bs);
                break;
            case DBG_ADVANCE_LINE:
                line += Leb128.readSignedLeb128(bs);
                break;
            case DBG_SET_PROLOGUE_END:
                // TODO do something with this.
                break;
            case DBG_SET_EPILOGUE_BEGIN:
                // TODO do something with this.
                break;
            case DBG_SET_FILE:
                // TODO do something with this.
                break;
            default:
                if (opcode < DBG_FIRST_SPECIAL) {
                    throw new RuntimeException("Invalid extended opcode encountered " + opcode);
                }
                int adjopcode = opcode - DBG_FIRST_SPECIAL;
                address += adjopcode / DBG_LINE_RANGE;
                line += DBG_LINE_BASE + (adjopcode % DBG_LINE_RANGE);
                positions.add(new PositionEntry(address, line));
                break;
        }
    }
}
Also used : Type(com.android.dx.rop.type.Type) StdTypeList(com.android.dx.rop.type.StdTypeList) ByteArrayByteInput(com.android.dex.util.ByteArrayByteInput) ByteInput(com.android.dex.util.ByteInput) ByteArrayByteInput(com.android.dex.util.ByteArrayByteInput)

Example 59 with Type

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

the class TypeIdsSection method intern.

/**
 * Interns an element into this instance.
 *
 * @param type {@code non-null;} the type to intern
 * @return {@code non-null;} the interned reference
 */
public synchronized TypeIdItem intern(CstType type) {
    if (type == null) {
        throw new NullPointerException("type == null");
    }
    throwIfPrepared();
    Type typePerSe = type.getClassType();
    TypeIdItem result = typeIds.get(typePerSe);
    if (result == null) {
        result = new TypeIdItem(type);
        typeIds.put(typePerSe, result);
    }
    return result;
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType)

Example 60 with Type

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

the class TypeIdsSection 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 = typeIds.get(type);
    if (result == null) {
        throw new IllegalArgumentException("not found: " + cst);
    }
    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)

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