use of kodkod.ast.operator.FormulaOperator 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.operator.FormulaOperator in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(binFormula) and returns the cached value, if any. If a
* translation has not been cached, translates the formula, calls cache(...) on
* it and returns it.
*
* @return let t = lookup(binFormula) | some t => t, cache(binFormula,
* binFormula.op(binFormula.left.accept(this),
* binFormula.right.accept(this))
*/
@Override
public final BooleanValue visit(BinaryFormula binFormula) {
BooleanValue ret = lookup(binFormula);
if (ret != null)
return ret;
final BooleanValue left = binFormula.left().accept(this);
final BooleanValue right = binFormula.right().accept(this);
final FormulaOperator op = binFormula.op();
final BooleanFactory f = interpreter.factory();
switch(op) {
case AND:
ret = f.and(left, right);
break;
case OR:
ret = f.or(left, right);
break;
case IMPLIES:
ret = f.implies(left, right);
break;
case IFF:
ret = f.iff(left, right);
break;
default:
throw new IllegalArgumentException("Unknown operator: " + op);
}
return cache(binFormula, ret);
}
Aggregations