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));
}
}
}
}
}
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;
}
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)));
}
}
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);
}
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();
}
Aggregations