use of soot.util.BitVector in project soot by Sable.
the class PointsToSetInternal method getBitMask.
// Added by Adam Richard
protected BitVector getBitMask(PointsToSetInternal other, PAG pag) {
/*Prevents propogating points-to sets of inappropriate type.
*E.g. if you have in the code being analyzed:
*Shape s = (Circle)c;
*then the points-to set of s is only the elements in the points-to set
*of c that have type Circle.
*/
// Code ripped from BitPointsToSet
BitVector mask = null;
TypeManager typeManager = pag.getTypeManager();
if (!typeManager.castNeverFails(other.getType(), this.getType())) {
mask = typeManager.get(this.getType());
}
return mask;
}
use of soot.util.BitVector in project soot by Sable.
the class SharedListSet method addAll.
public boolean addAll(PointsToSetInternal other, PointsToSetInternal exclude) {
if (other == null)
return false;
if ((!(other instanceof SharedListSet)) || (exclude != null && !(exclude instanceof SharedListSet))) {
return super.addAll(other, exclude);
} else {
SharedListSet realOther = (SharedListSet) other, realExclude = (SharedListSet) exclude;
BitVector mask = getBitMask(realOther, pag);
ListNode excludeData = (realExclude == null) ? null : realExclude.data;
return addOrAddAll(data, realOther.data, excludeData, mask);
}
}
use of soot.util.BitVector in project soot by Sable.
the class TypeResolverBV method merge_single_constraints.
private void merge_single_constraints() throws TypeException {
boolean finished = false;
boolean modified = false;
while (true) {
categorize();
if (single_child_not_null.length() != 0) {
finished = false;
modified = true;
BitSetIterator i = single_child_not_null.iterator();
while (i.hasNext()) {
TypeVariableBV var = typeVariableForId(i.next());
if (single_child_not_null.get(var.id())) {
// PA: Potential difference to old algorithm - using the smallest element
// in the list rather than children().get(0);
TypeVariableBV child = typeVariableForId(var.children().iterator().next());
var = var.union(child);
}
}
}
if (finished) {
if (single_soft_parent.length() != 0) {
finished = false;
modified = true;
BitSetIterator i = single_soft_parent.iterator();
while (i.hasNext()) {
TypeVariableBV var = typeVariableForId(i.next());
if (single_soft_parent.get(var.id())) {
// PA: See above.
TypeVariableBV parent = typeVariableForId(var.parents().iterator().next());
var = var.union(parent);
}
}
}
if (single_hard_parent.length() != 0) {
finished = false;
modified = true;
BitSetIterator i = single_hard_parent.iterator();
while (i.hasNext()) {
TypeVariableBV var = typeVariableForId(i.next());
if (single_hard_parent.get(var.id())) {
// PA: See above
TypeVariableBV parent = typeVariableForId(var.parents().iterator().next());
debug_vars("union single parent\n " + var + "\n " + parent);
var = var.union(parent);
}
}
}
if (single_null_child.length() != 0) {
finished = false;
modified = true;
BitSetIterator i = single_null_child.iterator();
while (i.hasNext()) {
TypeVariableBV var = typeVariableForId(i.next());
if (single_null_child.get(var.id())) {
// PA: See above
TypeVariableBV child = typeVariableForId(var.children().iterator().next());
var = var.union(child);
}
}
}
if (finished) {
break;
}
continue;
}
if (modified) {
modified = false;
continue;
}
finished = true;
multiple_children: for (BitSetIterator varIt = multiple_children.iterator(); varIt.hasNext(); ) {
final TypeVariableBV var = typeVariableForId(varIt.next());
TypeNode lca = null;
BitVector children_to_remove = new BitVector();
for (BitSetIterator childIt = var.children().iterator(); childIt.hasNext(); ) {
final TypeVariableBV child = typeVariableForId(childIt.next());
TypeNode type = child.type();
if (type != null && type.isNull()) {
var.removeChild(child);
} else if (type != null && type.isClass()) {
children_to_remove.set(child.id());
if (lca == null) {
lca = type;
} else {
lca = lca.lcaIfUnique(type);
if (lca == null) {
if (DEBUG) {
logger.debug("==++==" + stmtBody.getMethod().getDeclaringClass().getName() + "." + stmtBody.getMethod().getName());
}
continue multiple_children;
}
}
}
}
if (lca != null) {
for (BitSetIterator childIt = children_to_remove.iterator(); childIt.hasNext(); ) {
final TypeVariableBV child = typeVariableForId(childIt.next());
var.removeChild(child);
}
var.addChild(typeVariable(lca));
}
}
for (BitSetIterator varIt = multiple_parents.iterator(); varIt.hasNext(); ) {
final TypeVariableBV var = typeVariableForId(varIt.next());
// hard parents
LinkedList<TypeVariableBV> hp = new LinkedList<TypeVariableBV>();
for (BitSetIterator parentIt = var.parents().iterator(); parentIt.hasNext(); ) {
final TypeVariableBV parent = typeVariableForId(parentIt.next());
TypeNode type = parent.type();
if (type != null) {
Iterator<TypeVariableBV> k = hp.iterator();
while (k.hasNext()) {
TypeVariableBV otherparent = k.next();
TypeNode othertype = otherparent.type();
if (type.hasDescendant(othertype)) {
var.removeParent(parent);
type = null;
break;
}
if (type.hasAncestor(othertype)) {
var.removeParent(otherparent);
k.remove();
}
}
if (type != null) {
hp.add(parent);
}
}
}
}
}
}
use of soot.util.BitVector in project soot by Sable.
the class TypeResolverBV method categorize.
private void categorize() throws TypeException {
refresh_solved();
single_soft_parent = new BitVector();
single_hard_parent = new BitVector();
multiple_parents = new BitVector();
single_child_not_null = new BitVector();
single_null_child = new BitVector();
multiple_children = new BitVector();
for (BitSetIterator i = unsolved.iterator(); i.hasNext(); ) {
TypeVariableBV var = typeVariableForId(i.next());
// parent category
{
BitVector parents = var.parents();
int size = parents.length();
if (size == 0) {
var.addParent(typeVariable(OBJECT));
single_soft_parent.set(var.id());
} else if (size == 1) {
TypeVariableBV parent = typeVariableForId(parents.iterator().next());
if (parent.type() == null) {
single_soft_parent.set(var.id());
} else {
single_hard_parent.set(var.id());
}
} else {
multiple_parents.set(var.id());
}
}
// child category
{
BitVector children = var.children();
int size = children.size();
if (size == 0) {
var.addChild(typeVariable(NULL));
single_null_child.set(var.id());
} else if (size == 1) {
TypeVariableBV child = typeVariableForId(children.iterator().next());
if (child.type() == NULL) {
single_null_child.set(var.id());
} else {
single_child_not_null.set(var.id());
}
} else {
multiple_children.set(var.id());
}
}
}
}
use of soot.util.BitVector in project soot by Sable.
the class BitVector_intersects_Test method testEmptyBitVectorsDontIntersects.
public void testEmptyBitVectorsDontIntersects() {
BitVector a = new BitVector();
BitVector b = new BitVector();
assertFalse(a.intersects(b));
assertFalse(b.intersects(a));
}
Aggregations