use of kodkod.engine.bool.Operator in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(formula) 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(formula) | some t => t, cache(formula,
* formula.op(formula.left.accept(this), formula.right.accept(this))
*/
@Override
public final BooleanValue visit(NaryFormula formula) {
final BooleanValue ret = lookup(formula);
if (ret != null)
return ret;
final FormulaOperator op = formula.op();
final Operator.Nary boolOp;
switch(op) {
case AND:
boolOp = Operator.AND;
break;
case OR:
boolOp = Operator.OR;
break;
default:
throw new IllegalArgumentException("Unknown nary operator: " + op);
}
final BooleanAccumulator acc = BooleanAccumulator.treeGate(boolOp);
final BooleanValue shortCircuit = boolOp.shortCircuit();
for (Formula child : formula) {
if (acc.add(child.accept(this)) == shortCircuit)
break;
}
return cache(formula, interpreter.factory().accumulate(acc));
}
Aggregations