Search in sources :

Example 1 with BitSetIterator

use of soot.util.BitSetIterator in project soot by Sable.

the class TypeResolverBV method remove_transitive_constraints.

private void remove_transitive_constraints() throws TypeException {
    refresh_solved();
    BitVector list = new BitVector();
    list.or(solved);
    list.or(unsolved);
    for (BitSetIterator varIt = list.iterator(); varIt.hasNext(); ) {
        final TypeVariableBV var = typeVariableForId(varIt.next());
        var.removeIndirectRelations();
    }
}
Also used : BitVector(soot.util.BitVector) BitSetIterator(soot.util.BitSetIterator)

Example 2 with BitSetIterator

use of soot.util.BitSetIterator in project soot by Sable.

the class TypeResolverBV method merge_primitive_types.

private void merge_primitive_types() throws TypeException {
    // merge primitive types with all parents/children
    compute_solved();
    BitSetIterator varIt = solved.iterator();
    while (varIt.hasNext()) {
        TypeVariableBV var = typeVariableForId(varIt.next());
        if (var.type().type() instanceof IntType || var.type().type() instanceof LongType || var.type().type() instanceof FloatType || var.type().type() instanceof DoubleType) {
            BitVector parents;
            BitVector children;
            boolean finished;
            do {
                finished = true;
                parents = var.parents();
                if (parents.length() != 0) {
                    finished = false;
                    for (BitSetIterator j = parents.iterator(); j.hasNext(); ) {
                        if (DEBUG) {
                            logger.debug(".");
                        }
                        TypeVariableBV parent = typeVariableForId(j.next());
                        var = var.union(parent);
                    }
                }
                children = var.children();
                if (children.length() != 0) {
                    finished = false;
                    for (BitSetIterator j = children.iterator(); j.hasNext(); ) {
                        if (DEBUG) {
                            logger.debug(".");
                        }
                        TypeVariableBV child = typeVariableForId(j.next());
                        var = var.union(child);
                    }
                }
            } while (!finished);
        }
    }
}
Also used : BitSetIterator(soot.util.BitSetIterator) BitVector(soot.util.BitVector) LongType(soot.LongType) DoubleType(soot.DoubleType) IntType(soot.IntType) FloatType(soot.FloatType)

Example 3 with BitSetIterator

use of soot.util.BitSetIterator 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);
                    }
                }
            }
        }
    }
}
Also used : BitSetIterator(soot.util.BitSetIterator) BitVector(soot.util.BitVector) LinkedList(java.util.LinkedList)

Example 4 with BitSetIterator

use of soot.util.BitSetIterator 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());
            }
        }
    }
}
Also used : BitVector(soot.util.BitVector) BitSetIterator(soot.util.BitSetIterator)

Aggregations

BitSetIterator (soot.util.BitSetIterator)4 BitVector (soot.util.BitVector)4 LinkedList (java.util.LinkedList)1 DoubleType (soot.DoubleType)1 FloatType (soot.FloatType)1 IntType (soot.IntType)1 LongType (soot.LongType)1