Search in sources :

Example 1 with ExprQt

use of edu.mit.csail.sdg.ast.ExprQt in project org.alloytools.alloy by AlloyTools.

the class TranslateAlloyToKodkod method visit.

/**
 * {@inheritDoc}
 */
@Override
public Object visit(ExprQt x) throws Err {
    Expr xx = x.desugar();
    if (xx instanceof ExprQt)
        x = (ExprQt) xx;
    else
        return visitThis(xx);
    Object ans = visit_qt(x.op, x.decls, x.sub);
    if (ans instanceof Formula)
        k2pos((Formula) ans, x);
    return ans;
}
Also used : QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) Expr(edu.mit.csail.sdg.ast.Expr) ExprQt(edu.mit.csail.sdg.ast.ExprQt)

Example 2 with ExprQt

use of edu.mit.csail.sdg.ast.ExprQt in project org.alloytools.alloy by AlloyTools.

the class SimInstance method visit.

/**
 * {@inheritDoc}
 */
@Override
public Object visit(ExprQt x) throws Err {
    Expr xx = x.desugar();
    if (xx instanceof ExprQt)
        x = (ExprQt) xx;
    else
        return visitThis(xx);
    if (x.op == ExprQt.Op.COMPREHENSION) {
        TempList<SimTuple> ans = new TempList<SimTuple>();
        enumerate(ans, 0, x, x.sub, 0);
        return SimTupleset.make(ans.makeConst());
    }
    if (x.op == ExprQt.Op.ALL)
        return enumerate(null, 0, x, x.sub.not(), 0) == 0;
    if (x.op == ExprQt.Op.NO)
        return enumerate(null, 0, x, x.sub, 0) == 0;
    if (x.op == ExprQt.Op.SOME)
        return enumerate(null, 0, x, x.sub, 0) >= 1;
    if (x.op == ExprQt.Op.LONE)
        return enumerate(null, 0, x, x.sub, 0) <= 1;
    if (x.op == ExprQt.Op.ONE)
        return enumerate(null, 0, x, x.sub, 0) == 1;
    if (x.op == ExprQt.Op.SUM)
        return trunc(enumerate(null, 0, x, x.sub, 0));
    throw new ErrorFatal(x.pos, "Unsupported operator (" + x.op + ") encountered during ExprQt.accept()");
}
Also used : ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) Expr(edu.mit.csail.sdg.ast.Expr) TempList(edu.mit.csail.sdg.alloy4.ConstList.TempList) ExprQt(edu.mit.csail.sdg.ast.ExprQt)

Aggregations

Expr (edu.mit.csail.sdg.ast.Expr)2 ExprQt (edu.mit.csail.sdg.ast.ExprQt)2 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)1 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)1 Formula (kodkod.ast.Formula)1 QuantifiedFormula (kodkod.ast.QuantifiedFormula)1