use of kodkod.ast.NaryFormula in project org.alloytools.alloy by AlloyTools.
the class AbstractCollector method visit.
/**
* Calls lookup(formula) and returns the cached value, if any. If no cached
* value exists, visits each child, caches the union of the children's return
* values and returns it.
*
* @return let x = lookup(formula) | x != null => x, cache(formula,
* formula.child(0).accept(this) + .. +
* formula.child(formula.size()-1).accept(this))
*/
@Override
public Set<T> visit(NaryFormula formula) {
Set<T> ret = lookup(formula);
if (ret != null)
return ret;
ret = newSet();
for (Formula child : formula) {
ret.addAll(child.accept(this));
}
return cache(formula, ret);
}
use of kodkod.ast.NaryFormula in project org.alloytools.alloy by AlloyTools.
the class Nodes method allConjuncts.
public static List<Formula> allConjuncts(Formula formula, List<Formula> acc) {
List<Formula> ans = acc != null ? acc : new ArrayList<Formula>();
if (formula instanceof BinaryFormula) {
final BinaryFormula bin = (BinaryFormula) formula;
if (bin.op() == FormulaOperator.AND) {
allConjuncts(bin.left(), ans);
allConjuncts(bin.right(), ans);
return ans;
}
}
if (formula instanceof NaryFormula) {
final NaryFormula nf = (NaryFormula) formula;
if (nf.op() == FormulaOperator.AND) {
for (Formula child : nf) {
allConjuncts(child, ans);
}
return ans;
}
}
ans.add(formula);
return ans;
}
use of kodkod.ast.NaryFormula in project org.alloytools.alloy by AlloyTools.
the class FullNegationPropagator method visit.
/**
* Visits the formula's children with appropriate settings for the negated flag
* if bf has not been visited before.
*
* @see kodkod.ast.visitor.AbstractVoidVisitor#visit(kodkod.ast.NaryFormula)
*/
@Override
public final void visit(NaryFormula nf) {
if (visited(nf))
return;
final FormulaOperator op = nf.op();
if (negated && op == AND) {
List<Formula> formulas = new LinkedList<Formula>();
for (Formula f : nf) {
FullNegationPropagator fne = new FullNegationPropagator(shared, annotations);
f.not().accept(fne);
formulas.add(Formula.and(fne.conjuncts));
}
addConjunct(Formula.or(formulas), false, nf);
hasChanged = true;
} else if (!negated && op == OR) {
List<Formula> formulas = new LinkedList<Formula>();
boolean changed = false;
for (Formula f : nf) {
FullNegationPropagator fne = new FullNegationPropagator(shared, annotations);
f.accept(fne);
changed = changed || fne.hasChanged;
formulas.add(Formula.and(fne.conjuncts));
}
if (changed) {
addConjunct(Formula.or(formulas), false, nf);
hasChanged = true;
} else {
addConjunct(nf);
}
} else {
for (Formula f : nf) {
f.accept(this);
}
hasChanged = negated;
}
}
use of kodkod.ast.NaryFormula in project org.alloytools.alloy by AlloyTools.
the class PrenexNFConverter method visit.
@Override
public Formula visit(NaryFormula formula) {
final ArrayList<Formula> children = new ArrayList<Formula>(formula.size());
boolean allSame = true;
boolean noQuant = true;
for (Formula ch : formula) {
Formula ch2 = ch.accept(this);
allSame = allSame && ch == ch2;
noQuant = noQuant && !(ch2 instanceof QuantifiedFormula);
children.add(ch2);
}
Formula ans;
if (allSame && noQuant) {
ans = formula;
} else {
ans = children.get(0);
for (int i = 1; i < children.size(); i++) ans = new Pair(ans, children.get(i)).compose(formula.op());
}
return saveMapping(ans, formula);
}
use of kodkod.ast.NaryFormula in project org.alloytools.alloy by AlloyTools.
the class HOLTranslator method visit.
@Override
public Proc visit(NaryFormula formula) {
if (annotated.isFOLNode(formula))
return new Proc.FOL(bounds, formula);
Proc ans = null;
for (Formula f : formula) {
Proc p = formula.op() == FormulaOperator.OR ? toProc(f) : f.accept(this);
ans = ans == null ? p : ans.compose(formula.op(), p);
}
return ans;
}
Aggregations