@Override public byte evaluate(TypeVariable lhs, TypeVariable[] rhs) { TypeAbstraction lhsType = lhs.getType(); TypeAbstraction meet = TypeAbstraction.TOP; for (TypeVariable r : rhs) { if (r != null && r.getType() != null) { meet = meet.meet(r.getType()); } } if (lhsType.equals(meet)) { return NOT_CHANGED; } else { lhs.setType(meet); return CHANGED; } }
private static SSAInstruction[] makeStatements(Context context) { ArrayList<SSAInstruction> statements = new ArrayList<>(); int nextLocal = 2; int retValue = nextLocal++; TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference(); SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory(); if (tr != null) { SSALoadMetadataInstruction l = insts.LoadMetadataInstruction(statements.size(), retValue, TypeReference.JavaLangClass, tr); statements.add(l); SSAReturnInstruction R = insts.ReturnInstruction(statements.size(), retValue, false); statements.add(R); } SSAInstruction[] result = new SSAInstruction[statements.size()]; Iterator<SSAInstruction> it = statements.iterator(); for (int i = 0; i < result.length; i++) { result[i] = it.next(); } return result; }
@Override public int hashCode() { return 6367 * type.hashCode(); }
@Override public TypeReference getTypeReference() { Iterator ti = types.iterator(); TypeAbstraction T = (TypeAbstraction) ti.next(); while (ti.hasNext()) { T = T.meet((TypeAbstraction) ti.next()); } return T.getTypeReference(); }
public boolean isUndefined(int valueNumber) { // TODO: Julian, you seem to be using BOTTOM in the European style. // Steve's code assumes American style (god forbid), so what you're getting // here // is not undefined, but java.lang.Object [NR/EY] if (getVariable(valueNumber) == null) { return true; } TypeAbstraction ta = getVariable(valueNumber).getType(); return ta == BOTTOM || ta.getType() == null; }
@Override public boolean equals(Object o) { if (o instanceof DeclaredTypeOperator) { DeclaredTypeOperator d = (DeclaredTypeOperator) o; return type.equals(d.type); } else { return false; } } }
private TypeAbstraction meetDeclaredExceptionTypes(SSAGetCaughtExceptionInstruction s) { ExceptionHandlerBasicBlock bb = (ExceptionHandlerBasicBlock) ir.getControlFlowGraph().getNode(s.getBasicBlockNumber()); Iterator<TypeReference> it = bb.getCaughtExceptionTypes(); TypeReference t = it.next(); IClass klass = cha.lookupClass(t); TypeAbstraction result = null; if (klass == null) { // a type that cannot be loaded. // be pessimistic result = BOTTOM; } else { result = new ConeType(klass); } while (it.hasNext()) { t = it.next(); IClass tClass = cha.lookupClass(t); if (tClass == null) { result = BOTTOM; } else { result = result.meet(new ConeType(tClass)); } } return result; }
TypeAbstraction ta = r.getType(); if (ta instanceof PointType) { if (ta.getType().equals(getStringClass())) { meet = new PointType(ta.getType()); break; if (ta.getType().equals(getStringClass())) { meet = new PointType(ta.getType()); break; TypeAbstraction lhsType = L.getType(); if (lhsType.equals(meet)) { return NOT_CHANGED; } else {
private static boolean containsNonPrimitiveAndZero(DalvikTypeVariable[] types) { boolean containsNonPrimitive = false; boolean containsZero = false; for (int i = 0; i < types.length; i++) { if (types[i] != null) { if (types[i].getType() != null && types[i].getType().getTypeReference() != null && !types[i].getType().getTypeReference().isPrimitiveType()) { containsNonPrimitive = true; } if (types[i].isIntZeroConstant()) { containsZero = true; } } } return containsNonPrimitive && containsZero; }
public boolean isUndefined(int valueNumber) { // TODO: Julian, you seem to be using BOTTOM in the European style. // Steve's code assumes American style (god forbid), so what you're getting // here // is not undefined, but java.lang.Object [NR/EY] if (getVariable(valueNumber) == null) { return true; } TypeAbstraction ta = getVariable(valueNumber).getType(); return ta == BOTTOM || ta.getType() == null; }
@Override public boolean equals(Object o) { if (o instanceof DeclaredTypeOperator) { DeclaredTypeOperator d = (DeclaredTypeOperator) o; return type.equals(d.type); } else { return false; } } }
private TypeAbstraction meetDeclaredExceptionTypes(SSAGetCaughtExceptionInstruction s) { ExceptionHandlerBasicBlock bb = (ExceptionHandlerBasicBlock) ir.getControlFlowGraph().getNode(s.getBasicBlockNumber()); Iterator<TypeReference> it = bb.getCaughtExceptionTypes(); TypeReference t = it.next(); IClass klass = cha.lookupClass(t); TypeAbstraction result = null; if (klass == null) { // a type that cannot be loaded. // be pessimistic result = BOTTOM; } else { result = new ConeType(klass); } while (it.hasNext()) { t = it.next(); IClass tClass = cha.lookupClass(t); if (tClass == null) { result = BOTTOM; } else { result = result.meet(new ConeType(tClass)); } } return result; }
TypeAbstraction ta = r.getType(); if (ta instanceof PointType) { if (ta.getType().equals(getStringClass())) { meet = new PointType(ta.getType()); break; if (ta.getType().equals(getStringClass())) { meet = new PointType(ta.getType()); break; TypeAbstraction lhsType = L.getType(); if (lhsType.equals(meet)) { return NOT_CHANGED; } else {
private static boolean containsNonPrimitiveAndZero(DalvikTypeVariable[] types) { boolean containsNonPrimitive = false; boolean containsZero = false; for (int i = 0; i < types.length; i++) { if (types[i] != null) { if (types[i].getType() != null && types[i].getType().getTypeReference() != null && !types[i].getType().getTypeReference().isPrimitiveType()) { containsNonPrimitive = true; } if (types[i].isIntZeroConstant()) { containsZero = true; } } } return containsNonPrimitive && containsZero; }
@Override public TypeReference getTypeReference() { Iterator ti = types.iterator(); TypeAbstraction T = (TypeAbstraction) ti.next(); while (ti.hasNext()) { T = T.meet((TypeAbstraction) ti.next()); } return T.getTypeReference(); }
@Override public byte evaluate(TypeVariable lhs, TypeVariable[] rhs) { TypeAbstraction lhsType = lhs.getType(); TypeAbstraction meet = TypeAbstraction.TOP; for (TypeVariable r : rhs) { if (r != null && r.getType() != null) { meet = meet.meet(r.getType()); } } if (lhsType.equals(meet)) { return NOT_CHANGED; } else { lhs.setType(meet); return CHANGED; } }
ArrayList<SSAInstruction> statements = new ArrayList<>(); int nextLocal = ref.getNumberOfParameters() + 2; IClass cls = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType(); SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory(); if (cls != null) { for (IMethod m : returnValues) {
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass().equals(obj.getClass())) { JavaTypeContext other = (JavaTypeContext) obj; return type.equals(other.type); } else { return false; } }
private static SSAInstruction[] makeStatements(Context context) { ArrayList<SSAInstruction> statements = new ArrayList<>(); int nextLocal = 2; int retValue = nextLocal++; TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference(); SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory(); if (tr != null) { SSALoadMetadataInstruction l = insts.LoadMetadataInstruction(statements.size(), retValue, TypeReference.JavaLangClass, tr); statements.add(l); SSAReturnInstruction R = insts.ReturnInstruction(statements.size(), retValue, false); statements.add(R); } SSAInstruction[] result = new SSAInstruction[statements.size()]; Iterator<SSAInstruction> it = statements.iterator(); for (int i = 0; i < result.length; i++) { result[i] = it.next(); } return result; }
@Override public TypeAbstraction meet(TypeAbstraction rhs) { if (rhs == TOP) { return this; } else if (rhs instanceof ConeType) { ConeType other = (ConeType) rhs; if (type.equals(other.type)) { return this; } else if (type.isArrayClass() || other.type.isArrayClass()) { // give up on arrays. We don't care anyway. return new ConeType(type.getClassHierarchy().getRootClass()); } else { return new ConeType(type.getClassHierarchy().getLeastCommonSuperclass(this.type, other.type)); } } else if (rhs instanceof PointType) { return rhs.meet(this); } else if (rhs instanceof PrimitiveType) { return TOP; } else { Assertions.UNREACHABLE("unexpected type " + rhs.getClass()); return null; } }