Search in sources :

Example 21 with Type

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

the class OneLocalsArray method makeInitialized.

/**
 * {@inheritDoc}
 */
public void makeInitialized(Type type) {
    int len = locals.length;
    if (len == 0) {
        // We have to check for this before checking for immutability.
        return;
    }
    throwIfImmutable();
    Type initializedType = type.getInitializedType();
    for (int i = 0; i < len; i++) {
        if (locals[i] == type) {
            locals[i] = initializedType;
        }
    }
}
Also used : Type(com.android.dx.rop.type.Type)

Example 22 with Type

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

the class Ropper method addSetupBlocks.

/**
 * Constructs and adds the blocks that perform setup for the rest of
 * the method. This includes a first block which merely contains
 * assignments from parameters to the same-numbered registers and
 * a possible second block which deals with synchronization.
 */
private void addSetupBlocks() {
    LocalVariableList localVariables = method.getLocalVariables();
    SourcePosition pos = method.makeSourcePosistion(0);
    Prototype desc = method.getEffectiveDescriptor();
    StdTypeList params = desc.getParameterTypes();
    int sz = params.size();
    InsnList insns = new InsnList(sz + 1);
    int at = 0;
    for (int i = 0; i < sz; i++) {
        Type one = params.get(i);
        LocalVariableList.Item local = localVariables.pcAndIndexToLocal(0, at);
        RegisterSpec result = (local == null) ? RegisterSpec.make(at, one) : RegisterSpec.makeLocalOptional(at, one, local.getLocalItem());
        Insn insn = new PlainCstInsn(Rops.opMoveParam(one), pos, result, RegisterSpecList.EMPTY, CstInteger.make(at));
        insns.set(i, insn);
        at += one.getCategory();
    }
    insns.set(sz, new PlainInsn(Rops.GOTO, pos, null, RegisterSpecList.EMPTY));
    insns.setImmutable();
    boolean synch = isSynchronized();
    int label = synch ? getSpecialLabel(SYNCH_SETUP_1) : 0;
    BasicBlock bb = new BasicBlock(getSpecialLabel(PARAM_ASSIGNMENT), insns, IntList.makeImmutable(label), label);
    addBlock(bb, IntList.EMPTY);
    if (synch) {
        RegisterSpec synchReg = getSynchReg();
        Insn insn;
        if (isStatic()) {
            insn = new ThrowingCstInsn(Rops.CONST_OBJECT, pos, RegisterSpecList.EMPTY, StdTypeList.EMPTY, method.getDefiningClass());
            insns = new InsnList(1);
            insns.set(0, insn);
        } else {
            insns = new InsnList(2);
            insn = new PlainCstInsn(Rops.MOVE_PARAM_OBJECT, pos, synchReg, RegisterSpecList.EMPTY, CstInteger.VALUE_0);
            insns.set(0, insn);
            insns.set(1, new PlainInsn(Rops.GOTO, pos, null, RegisterSpecList.EMPTY));
        }
        int label2 = getSpecialLabel(SYNCH_SETUP_2);
        insns.setImmutable();
        bb = new BasicBlock(label, insns, IntList.makeImmutable(label2), label2);
        addBlock(bb, IntList.EMPTY);
        insns = new InsnList(isStatic() ? 2 : 1);
        if (isStatic()) {
            insns.set(0, new PlainInsn(Rops.opMoveResultPseudo(synchReg), pos, synchReg, RegisterSpecList.EMPTY));
        }
        insn = new ThrowingInsn(Rops.MONITOR_ENTER, pos, RegisterSpecList.make(synchReg), StdTypeList.EMPTY);
        insns.set(isStatic() ? 1 : 0, insn);
        insns.setImmutable();
        bb = new BasicBlock(label2, insns, IntList.makeImmutable(0), 0);
        addBlock(bb, IntList.EMPTY);
    }
}
Also used : ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn) ThrowingInsn(com.android.dx.rop.code.ThrowingInsn) PlainInsn(com.android.dx.rop.code.PlainInsn) Insn(com.android.dx.rop.code.Insn) PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) Prototype(com.android.dx.rop.type.Prototype) ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn) BasicBlock(com.android.dx.rop.code.BasicBlock) InsnList(com.android.dx.rop.code.InsnList) ThrowingInsn(com.android.dx.rop.code.ThrowingInsn) PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) PlainInsn(com.android.dx.rop.code.PlainInsn) Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) StdTypeList(com.android.dx.rop.type.StdTypeList) SourcePosition(com.android.dx.rop.code.SourcePosition) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 23 with Type

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

the class AttributeTranslator method translateInnerClasses.

/**
 * Gets the {@code InnerClasses} attribute out of a given
 * {@link AttributeList}, if any, translating it to one or more of an
 * {@code InnerClass}, {@code EnclosingClass}, or
 * {@code MemberClasses} annotation.
 *
 * @param thisClass {@code non-null;} type representing the class being
 * processed
 * @param attribs {@code non-null;} the attributes list to search in
 * @param needEnclosingClass whether to include an
 * {@code EnclosingClass} annotation
 * @return {@code null-ok;} the converted list of annotations, if there
 * was an attribute to translate
 */
private static Annotations translateInnerClasses(CstType thisClass, AttributeList attribs, boolean needEnclosingClass) {
    AttInnerClasses innerClasses = (AttInnerClasses) attribs.findFirst(AttInnerClasses.ATTRIBUTE_NAME);
    if (innerClasses == null) {
        return null;
    }
    /*
         * Search the list for the element representing the current class
         * as well as for any named member classes.
         */
    InnerClassList list = innerClasses.getInnerClasses();
    int size = list.size();
    InnerClassList.Item foundThisClass = null;
    ArrayList<Type> membersList = new ArrayList<Type>();
    for (int i = 0; i < size; i++) {
        InnerClassList.Item item = list.get(i);
        CstType innerClass = item.getInnerClass();
        if (innerClass.equals(thisClass)) {
            foundThisClass = item;
        } else if (thisClass.equals(item.getOuterClass())) {
            membersList.add(innerClass.getClassType());
        }
    }
    int membersSize = membersList.size();
    if ((foundThisClass == null) && (membersSize == 0)) {
        return null;
    }
    Annotations result = new Annotations();
    if (foundThisClass != null) {
        result.add(AnnotationUtils.makeInnerClass(foundThisClass.getInnerName(), foundThisClass.getAccessFlags()));
        if (needEnclosingClass) {
            CstType outer = foundThisClass.getOuterClass();
            if (outer == null) {
                throw new Warning("Ignoring InnerClasses attribute for an " + "anonymous inner class\n" + "(" + thisClass.toHuman() + ") that doesn't come with an\n" + "associated EnclosingMethod attribute. " + "This class was probably produced by a\n" + "compiler that did not target the modern " + ".class file format. The recommended\n" + "solution is to recompile the class from " + "source, using an up-to-date compiler\n" + "and without specifying any \"-target\" type " + "options. The consequence of ignoring\n" + "this warning is that reflective operations " + "on this class will incorrectly\n" + "indicate that it is *not* an inner class.");
            }
            result.add(AnnotationUtils.makeEnclosingClass(foundThisClass.getOuterClass()));
        }
    }
    if (membersSize != 0) {
        StdTypeList typeList = new StdTypeList(membersSize);
        for (int i = 0; i < membersSize; i++) {
            typeList.set(i, membersList.get(i));
        }
        typeList.setImmutable();
        result.add(AnnotationUtils.makeMemberClasses(typeList));
    }
    result.setImmutable();
    return result;
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) Warning(com.android.dx.util.Warning) AttRuntimeVisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations) AttRuntimeVisibleParameterAnnotations(com.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations) Annotations(com.android.dx.rop.annotation.Annotations) AttRuntimeInvisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations) AttRuntimeInvisibleParameterAnnotations(com.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations) StdTypeList(com.android.dx.rop.type.StdTypeList) CstType(com.android.dx.rop.cst.CstType) ArrayList(java.util.ArrayList) InnerClassList(com.android.dx.cf.attrib.InnerClassList) AttInnerClasses(com.android.dx.cf.attrib.AttInnerClasses)

Example 24 with Type

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

the class OutputFinisher method addConstants.

/**
 * Helper for {@link #getAllConstants} which adds all the info for
 * a single {@code RegisterSpec}.
 *
 * @param result {@code non-null;} result set to add to
 * @param spec {@code null-ok;} register spec to add
 */
private static void addConstants(HashSet<Constant> result, RegisterSpec spec) {
    if (spec == null) {
        return;
    }
    LocalItem local = spec.getLocalItem();
    CstString name = local.getName();
    CstString signature = local.getSignature();
    Type type = spec.getType();
    if (type != Type.KNOWN_NULL) {
        result.add(CstType.intern(type));
    } else {
        /* If this a "known null", let's use "Object" because that's going to be the
             * resulting type in {@link LocalList.MakeState#filterSpec} */
        result.add(CstType.intern(Type.OBJECT));
    }
    if (name != null) {
        result.add(name);
    }
    if (signature != null) {
        result.add(signature);
    }
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) CstString(com.android.dx.rop.cst.CstString) LocalItem(com.android.dx.rop.code.LocalItem)

Example 25 with Type

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

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

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