use of kodkod.ast.operator.ExprOperator in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(expr) and returns the cached value, if any. If a translation has
* not been cached, translates the expression, calls cache(...) on it and
* returns it.
*
* @return let t = lookup(expr) | some t => t, let op = (expr.op).(UNION->or +
* INTERSECTION->and + DIFFERENCE->difference + OVERRIDE->override +
* JOIN->dot + PRODUCT->cross) | cache(expr, op(expr.left.accept(this),
* expr.right.accept(this)))
*/
@Override
public BooleanMatrix visit(NaryExpression expr) {
BooleanMatrix ret = lookup(expr);
if (ret != null)
return ret;
final ExprOperator op = expr.op();
final BooleanMatrix first = expr.child(0).accept(this);
final BooleanMatrix[] rest = new BooleanMatrix[expr.size() - 1];
for (int i = 0; i < rest.length; i++) {
rest[i] = expr.child(i + 1).accept(this);
}
switch(op) {
case UNION:
ret = first.or(rest);
break;
case INTERSECTION:
ret = first.and(rest);
break;
case OVERRIDE:
ret = first.override(rest);
break;
case PRODUCT:
ret = first.cross(rest);
break;
default:
throw new IllegalArgumentException("Unknown associative operator: " + op);
}
return cache(expr, ret);
}
use of kodkod.ast.operator.ExprOperator in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(binExpr) and returns the cached value, if any. If a translation
* has not been cached, translates the expression, calls cache(...) on it and
* returns it.
*
* @return let t = lookup(binExpr) | some t => t, let op =
* (binExpr.op).(UNION->or + INTERSECTION->and + DIFFERENCE->difference
* + OVERRIDE->override + JOIN->dot + PRODUCT->cross) | cache(binExpr,
* op(binExpr.left.accept(this), binExpr.right.accept(this)))
*/
@Override
public BooleanMatrix visit(BinaryExpression binExpr) {
BooleanMatrix ret = lookup(binExpr);
if (ret != null)
return ret;
final BooleanMatrix left = binExpr.left().accept(this);
final BooleanMatrix right = binExpr.right().accept(this);
final ExprOperator op = binExpr.op();
switch(op) {
case UNION:
ret = left.or(right);
break;
case INTERSECTION:
ret = left.and(right);
break;
case DIFFERENCE:
ret = left.difference(right);
break;
case OVERRIDE:
ret = left.override(right);
break;
case JOIN:
ret = left.dot(right);
break;
case PRODUCT:
ret = left.cross(right);
break;
default:
throw new IllegalArgumentException("Unknown operator: " + op);
}
return cache(binExpr, ret);
}
use of kodkod.ast.operator.ExprOperator in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(unaryExpr) and returns the cached value, if any. If a
* translation has not been cached, translates the expression, calls cache(...)
* on it and returns it.
*
* @return let t = lookup(unaryExpr) | some t => t, let op =
* (unaryExpr.op).(TRANSPOSE->transpose + CLOSURE->closure +
* REFLEXIVE_CLOSURE->(lambda(m)(m.closure().or(iden))) |
* cache(unaryExpr, op(unaryExpr.child))
*/
@Override
public final BooleanMatrix visit(UnaryExpression unaryExpr) {
BooleanMatrix ret = lookup(unaryExpr);
if (ret != null)
return ret;
final BooleanMatrix child = unaryExpr.expression().accept(this);
final ExprOperator op = unaryExpr.op();
switch(op) {
case TRANSPOSE:
ret = child.transpose();
break;
case CLOSURE:
ret = child.closure();
break;
case REFLEXIVE_CLOSURE:
ret = child.closure().or(visit((ConstantExpression) Expression.IDEN));
break;
default:
throw new IllegalArgumentException("Unknown operator: " + op);
}
return cache(unaryExpr, ret);
}
Aggregations