Search in sources :

Example 1 with Operator

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));
}
Also used : FormulaOperator(kodkod.ast.operator.FormulaOperator) ExprCompOperator(kodkod.ast.operator.ExprCompOperator) ExprOperator(kodkod.ast.operator.ExprOperator) Operator(kodkod.engine.bool.Operator) ConstantFormula(kodkod.ast.ConstantFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) NotFormula(kodkod.ast.NotFormula) Formula(kodkod.ast.Formula) FixFormula(kodkod.ast.FixFormula) IntComparisonFormula(kodkod.ast.IntComparisonFormula) FormulaOperator(kodkod.ast.operator.FormulaOperator) BooleanValue(kodkod.engine.bool.BooleanValue) BooleanAccumulator(kodkod.engine.bool.BooleanAccumulator)

Aggregations

BinaryFormula (kodkod.ast.BinaryFormula)1 ComparisonFormula (kodkod.ast.ComparisonFormula)1 ConstantFormula (kodkod.ast.ConstantFormula)1 FixFormula (kodkod.ast.FixFormula)1 Formula (kodkod.ast.Formula)1 IntComparisonFormula (kodkod.ast.IntComparisonFormula)1 MultiplicityFormula (kodkod.ast.MultiplicityFormula)1 NaryFormula (kodkod.ast.NaryFormula)1 NotFormula (kodkod.ast.NotFormula)1 QuantifiedFormula (kodkod.ast.QuantifiedFormula)1 ExprCompOperator (kodkod.ast.operator.ExprCompOperator)1 ExprOperator (kodkod.ast.operator.ExprOperator)1 FormulaOperator (kodkod.ast.operator.FormulaOperator)1 BooleanAccumulator (kodkod.engine.bool.BooleanAccumulator)1 BooleanValue (kodkod.engine.bool.BooleanValue)1 Operator (kodkod.engine.bool.Operator)1