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;
}
if (this.equals(other.reg, other.type, other.local)) {
return this;
}
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 Rop method toString.
/** {@inheritDoc} */
@Override
public String toString() {
StringBuffer sb = new StringBuffer(40);
sb.append("Rop{");
sb.append(RegOps.opName(opcode));
if (result != Type.VOID) {
sb.append(" ");
sb.append(result);
} else {
sb.append(" .");
}
sb.append(" <-");
int sz = sources.size();
if (sz == 0) {
sb.append(" .");
} else {
for (int i = 0; i < sz; i++) {
sb.append(' ');
sb.append(sources.getType(i));
}
}
if (isCallLike) {
sb.append(" call");
}
sz = exceptions.size();
if (sz != 0) {
sb.append(" throws");
for (int i = 0; i < sz; i++) {
sb.append(' ');
Type one = exceptions.getType(i);
if (one == Type.THROWABLE) {
sb.append("<any>");
} else {
sb.append(exceptions.getType(i));
}
}
} else {
switch(branchingness) {
case BRANCH_NONE:
sb.append(" flows");
break;
case BRANCH_RETURN:
sb.append(" returns");
break;
case BRANCH_GOTO:
sb.append(" gotos");
break;
case BRANCH_IF:
sb.append(" ifs");
break;
case BRANCH_SWITCH:
sb.append(" switches");
break;
default:
sb.append(" " + Hex.u1(branchingness));
break;
}
}
sb.append('}');
return sb.toString();
}
use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.
the class Rops method opFilledNewArray.
/**
* Returns the appropriate {@code filled-new-array} rop for the given
* type. The result may be a shared instance.
*
* @param arrayType {@code non-null;} type of array being created
* @param count {@code >= 0;} number of elements that the array should have
* @return {@code non-null;} an appropriate instance
*/
public static Rop opFilledNewArray(TypeBearer arrayType, int count) {
Type type = arrayType.getType();
Type elementType = type.getComponentType();
if (elementType.isCategory2()) {
return throwBadType(arrayType);
}
if (count < 0) {
throw new IllegalArgumentException("count < 0");
}
StdTypeList sourceTypes = new StdTypeList(count);
for (int i = 0; i < count; i++) {
sourceTypes.set(i, elementType);
}
// Note: The resulting rop is considered call-like.
return new Rop(RegOps.FILLED_NEW_ARRAY, sourceTypes, Exceptions.LIST_Error);
}
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)));
}
}
Aggregations