Search in sources :

Example 1 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

the class ClassReferenceListBuilder method addDependencies.

private void addDependencies(ConstantPool pool) {
    for (Constant constant : pool.getEntries()) {
        if (constant instanceof CstType) {
            Type type = ((CstType) constant).getClassType();
            String descriptor = type.getDescriptor();
            if (descriptor.endsWith(";")) {
                int lastBrace = descriptor.lastIndexOf('[');
                if (lastBrace < 0) {
                    addClassWithHierachy(descriptor.substring(1, descriptor.length() - 1));
                } else {
                    assert descriptor.length() > lastBrace + 3 && descriptor.charAt(lastBrace + 1) == 'L';
                    addClassWithHierachy(descriptor.substring(lastBrace + 2, descriptor.length() - 1));
                }
            }
        }
    }
}
Also used : CstType(com.taobao.android.dx.rop.cst.CstType) Type(com.taobao.android.dx.rop.type.Type) Constant(com.taobao.android.dx.rop.cst.Constant) CstType(com.taobao.android.dx.rop.cst.CstType)

Example 2 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

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 : CstType(com.taobao.android.dx.rop.cst.CstType) Type(com.taobao.android.dx.rop.type.Type) CstType(com.taobao.android.dx.rop.cst.CstType)

Example 3 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

the class TypeListItem method writeTo0.

/**
 * {@inheritDoc}
 */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    TypeIdsSection typeIds = file.getTypeIds();
    int sz = list.size();
    if (out.annotates()) {
        out.annotate(0, offsetString() + " type_list");
        out.annotate(HEADER_SIZE, "  size: " + Hex.u4(sz));
        for (int i = 0; i < sz; i++) {
            Type one = list.getType(i);
            int idx = typeIds.indexOf(one);
            out.annotate(ELEMENT_SIZE, "  " + Hex.u2(idx) + " // " + one.toHuman());
        }
    }
    out.writeInt(sz);
    for (int i = 0; i < sz; i++) {
        out.writeShort(typeIds.indexOf(list.getType(i)));
    }
}
Also used : Type(com.taobao.android.dx.rop.type.Type)

Example 4 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

the class RegisterSpec method intersect.

/**
 * Returns an instance that is the intersection between this instance
 * and the given one, if any. The intersection is defined as follows:
 *
 * <ul>
 *   <li>If {@code other} is {@code null}, then the result
 *     is {@code null}.
 *   <li>If the register numbers don't match, then the intersection
 *     is {@code null}. Otherwise, the register number of the
 *     intersection is the same as the one in the two instances.</li>
 *   <li>If the types returned by {@code getType()} are not
 *     {@code equals()}, then the intersection is null.</li>
 *   <li>If the type bearers returned by {@code getTypeBearer()}
 *     are {@code equals()}, then the intersection's type bearer
 *     is the one from this instance. Otherwise, the intersection's
 *     type bearer is the {@code getType()} of this instance.</li>
 *   <li>If the locals are {@code equals()}, then the local info
 *     of the intersection is the local info of this instance. Otherwise,
 *     the local info of the intersection is {@code null}.</li>
 * </ul>
 *
 * @param other {@code null-ok;} instance to intersect with (or {@code null})
 * @param localPrimary whether local variables are primary to the
 * intersection; if {@code true}, then the only non-null
 * results occur when registers being intersected have equal local
 * infos (or both have {@code null} local infos)
 * @return {@code null-ok;} the intersection
 */
public RegisterSpec intersect(RegisterSpec other, boolean localPrimary) {
    if (this == other) {
        // Easy out.
        return this;
    }
    if ((other == null) || (reg != other.getReg())) {
        return null;
    }
    LocalItem resultLocal = ((local == null) || !local.equals(other.getLocalItem())) ? null : local;
    boolean sameName = (resultLocal == local);
    if (localPrimary && !sameName) {
        return null;
    }
    Type thisType = getType();
    Type otherType = other.getType();
    // Note: Types are always interned.
    if (thisType != otherType) {
        return null;
    }
    TypeBearer resultTypeBearer = type.equals(other.getTypeBearer()) ? type : thisType;
    if ((resultTypeBearer == type) && sameName) {
        // It turns out that the intersection is "this" after all.
        return this;
    }
    return (resultLocal == null) ? make(reg, resultTypeBearer) : make(reg, resultTypeBearer, resultLocal);
}
Also used : Type(com.taobao.android.dx.rop.type.Type) TypeBearer(com.taobao.android.dx.rop.type.TypeBearer)

Example 5 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

the class RegisterSpec method toString0.

/**
 * Helper for {@link #toString} and {@link #toHuman}.
 *
 * @param human whether to be human-oriented
 * @return {@code non-null;} the string form
 */
private String toString0(boolean human) {
    StringBuffer sb = new StringBuffer(40);
    sb.append(regString());
    sb.append(":");
    if (local != null) {
        sb.append(local.toString());
    }
    Type justType = type.getType();
    sb.append(justType);
    if (justType != type) {
        sb.append("=");
        if (human && (type instanceof CstString)) {
            sb.append(((CstString) type).toQuoted());
        } else if (human && (type instanceof Constant)) {
            sb.append(type.toHuman());
        } else {
            sb.append(type);
        }
    }
    return sb.toString();
}
Also used : Type(com.taobao.android.dx.rop.type.Type) Constant(com.taobao.android.dx.rop.cst.Constant) CstString(com.taobao.android.dx.rop.cst.CstString)

Aggregations

Type (com.taobao.android.dx.rop.type.Type)32 CstType (com.taobao.android.dx.rop.cst.CstType)19 Constant (com.taobao.android.dx.rop.cst.Constant)5 StdTypeList (com.taobao.android.dx.rop.type.StdTypeList)5 TypeBearer (com.taobao.android.dx.rop.type.TypeBearer)5 CstString (com.taobao.android.dx.rop.cst.CstString)4 RegisterSpec (com.taobao.android.dx.rop.code.RegisterSpec)3 TypeList (com.taobao.android.dx.rop.type.TypeList)3 BasicBlock (com.taobao.android.dx.rop.code.BasicBlock)2 Insn (com.taobao.android.dx.rop.code.Insn)2 PlainCstInsn (com.taobao.android.dx.rop.code.PlainCstInsn)2 PlainInsn (com.taobao.android.dx.rop.code.PlainInsn)2 SourcePosition (com.taobao.android.dx.rop.code.SourcePosition)2 ThrowingCstInsn (com.taobao.android.dx.rop.code.ThrowingCstInsn)2 ThrowingInsn (com.taobao.android.dx.rop.code.ThrowingInsn)2 CstInteger (com.taobao.android.dx.rop.cst.CstInteger)2 ByteArrayByteInput (com.taobao.android.dex.util.ByteArrayByteInput)1 ByteInput (com.taobao.android.dex.util.ByteInput)1 AttInnerClasses (com.taobao.android.dx.cf.attrib.AttInnerClasses)1 AttRuntimeInvisibleAnnotations (com.taobao.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations)1