more simplification logic

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1537 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-07-23 16:40:26 +00:00
parent 3355b6207e
commit 0852fb888d
14 changed files with 54 additions and 19 deletions

View File

@ -31,6 +31,10 @@ public abstract class AbstractConstant implements IConstant {
public Collection<? extends IConstant> getConstants() {
return Collections.singleton(this);
}
public Collection<? extends ITerm> getAllTerms() {
return Collections.singleton(this);
}
@Override

View File

@ -103,10 +103,10 @@ public class BinaryFormula extends AbstractBinaryFormula {
return result;
}
public Collection<? extends ITerm> getTerms() {
public Collection<? extends ITerm> getAllTerms() {
Collection<ITerm> result = HashSetFactory.make();
result.addAll(f1.getTerms());
result.addAll(f2.getTerms());
result.addAll(f1.getAllTerms());
result.addAll(f2.getAllTerms());
return result;
}

View File

@ -11,7 +11,6 @@
package com.ibm.wala.logic;
public class BooleanConstant extends AbstractConstant {
public static final BooleanConstant TRUE = new BooleanConstant(true);
@ -38,5 +37,5 @@ public class BooleanConstant extends AbstractConstant {
public int hashCode() {
return val ? 11 : 13;
}
}

View File

@ -62,4 +62,8 @@ public class BooleanConstantFormula implements IMaxTerm {
return 163 * c.hashCode();
}
public Collection<? extends ITerm> getAllTerms() {
return Collections.singleton(c);
}
}

View File

@ -48,10 +48,10 @@ public class CNFFormula extends AbstractBinaryFormula implements ICNFFormula {
return result;
}
public Collection<? extends ITerm> getTerms() {
public Collection<? extends ITerm> getAllTerms() {
Collection<ITerm> result = HashSetFactory.make();
for (IFormula f : maxTerms) {
result.addAll(f.getTerms());
result.addAll(f.getAllTerms());
}
return result;
}

View File

@ -39,10 +39,10 @@ public class Disjunction extends AbstractBinaryFormula implements IMaxTerm {
return result;
}
public Collection<? extends ITerm> getTerms() {
public Collection<? extends ITerm> getAllTerms() {
Collection<ITerm> result = HashSetFactory.make();
for (IFormula f : clauses) {
result.addAll(f.getTerms());
result.addAll(f.getAllTerms());
}
return result;
}

View File

@ -143,4 +143,13 @@ public class FunctionTerm extends AbstractTerm {
return false;
return true;
}
public Collection<? extends ITerm> getAllTerms() {
Collection<ITerm> result = HashSetFactory.make();
result.add(this);
for (ITerm t : parameters) {
result.addAll(t.getAllTerms());
}
return result;
}
}

View File

@ -41,9 +41,9 @@ public interface IFormula {
public Collection<? extends IConstant> getConstants();
/**
* @return the terms that appear in this formula
* @return all terms that appear in this formula, including recursive descent on on-atomic terms
*/
public Collection<? extends ITerm> getTerms();
public Collection<? extends ITerm> getAllTerms();
public String prettyPrint(ILogicDecorator d);

View File

@ -32,4 +32,9 @@ public interface ITerm {
public String prettyPrint(ILogicDecorator d);
public Collection<? extends IConstant> getConstants();
/**
* Collect all terms that appear in this term, including subterms if this is a function term
*/
public Collection<? extends ITerm> getAllTerms();
}

View File

@ -83,8 +83,8 @@ public class NotFormula implements IFormula {
return f.getConstants();
}
public Collection<? extends ITerm> getTerms() {
return f.getTerms();
public Collection<? extends ITerm> getAllTerms() {
return f.getAllTerms();
}
@Override

View File

@ -108,8 +108,8 @@ public class QuantifiedFormula implements IMaxTerm {
return f.getConstants();
}
public Collection<? extends ITerm> getTerms() {
return f.getTerms();
public Collection<? extends ITerm> getAllTerms() {
return f.getAllTerms();
}
@Override

View File

@ -34,6 +34,15 @@ public class RelationFormula implements IMaxTerm {
public List<ITerm> getTerms() {
return terms;
}
public Collection<? extends ITerm> getAllTerms() {
Collection<ITerm> result = HashSetFactory.make();
for (ITerm t: terms) {
result.addAll(t.getAllTerms());
}
return result;
}
private RelationFormula(final IRelation R, final List<ITerm> terms) throws IllegalArgumentException {
super();
@ -171,4 +180,5 @@ public class RelationFormula implements IMaxTerm {
result.append(terms.get(1).prettyPrint(d));
return result.toString();
}
}

View File

@ -275,16 +275,16 @@ public class Simplifier {
Variable bound = q.getBoundVar();
IFormula body = q.getFormula();
// this could be inefficient. find a better algorithm.
for (Variable free : f.getFreeVariables()) {
if (q.getFreeVariables().contains(free)) {
for (ITerm t : f.getAllTerms()) {
if (q.getFreeVariables().contains(t)) {
Variable fresh = makeFresh(q, f);
IFormula testBody = substitute(body, bound, fresh);
IFormula testF = substitute(f, free, fresh);
IFormula testF = substitute(f, t, fresh);
if (implies(testBody,testF)) {
return true;
}
} else {
IFormula testBody = substitute(body, bound, free);
IFormula testBody = substitute(body, bound, t);
if (implies(testBody, f)) {
return true;
}

View File

@ -93,4 +93,8 @@ public class Variable extends AbstractTerm implements Comparable<Variable> {
public int compareTo(Variable o) throws NullPointerException {
return this.getNumber() - o.getNumber();
}
public Collection<? extends ITerm> getAllTerms() {
return Collections.singleton(this);
}
}