Search in sources :

Example 21 with IntExpression

use of kodkod.ast.IntExpression in project org.alloytools.alloy by AlloyTools.

the class AbstractReplacer method visit.

/**
 * Calls lookup(intExpr) and returns the cached value, if any. If a replacement
 * has not been cached, visits the expression's children. If nothing changes,
 * the argument is cached and returned, otherwise a replacement expression is
 * cached and returned.
 *
 * @return { i: IfIntExpression | i.condition =
 *         intExpr.condition.accept(delegate) && i.thenExpr =
 *         intExpr.thenExpr.accept(delegate) && i.elseExpr =
 *         intExpr.elseExpr.accept(delegate) }
 */
@Override
public IntExpression visit(IfIntExpression intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret != null)
        return ret;
    final Formula condition = intExpr.condition().accept(delegate);
    final IntExpression thenExpr = intExpr.thenExpr().accept(delegate);
    final IntExpression elseExpr = intExpr.elseExpr().accept(delegate);
    ret = (condition == intExpr.condition() && thenExpr == intExpr.thenExpr() && elseExpr == intExpr.elseExpr()) ? intExpr : condition.thenElse(thenExpr, elseExpr);
    return cache(intExpr, ret);
}
Also used : BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) ConstantFormula(kodkod.ast.ConstantFormula) NotFormula(kodkod.ast.NotFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) Formula(kodkod.ast.Formula) FixFormula(kodkod.ast.FixFormula) IntComparisonFormula(kodkod.ast.IntComparisonFormula) BinaryIntExpression(kodkod.ast.BinaryIntExpression) IfIntExpression(kodkod.ast.IfIntExpression) UnaryIntExpression(kodkod.ast.UnaryIntExpression) NaryIntExpression(kodkod.ast.NaryIntExpression) IntExpression(kodkod.ast.IntExpression)

Example 22 with IntExpression

use of kodkod.ast.IntExpression in project org.alloytools.alloy by AlloyTools.

the class AbstractReplacer method visit.

/**
 * Calls lookup(intExpr) and returns the cached value, if any. If a replacement
 * has not been cached, visits the expression's child. If nothing changes, the
 * argument is cached and returned, otherwise a replacement expression is cached
 * and returned.
 *
 * @return { i: ExprToIntCast | i.expression =
 *         intExpr.expression.accept(delegate) && i.op = intExpr.op}
 */
@Override
public IntExpression visit(ExprToIntCast intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret != null)
        return ret;
    final Expression expr = intExpr.expression().accept(delegate);
    ret = expr == intExpr.expression() ? intExpr : expr.apply(intExpr.op());
    return cache(intExpr, ret);
}
Also used : ProjectExpression(kodkod.ast.ProjectExpression) BinaryIntExpression(kodkod.ast.BinaryIntExpression) SumExpression(kodkod.ast.SumExpression) IfIntExpression(kodkod.ast.IfIntExpression) BinaryExpression(kodkod.ast.BinaryExpression) ConstantExpression(kodkod.ast.ConstantExpression) UnaryIntExpression(kodkod.ast.UnaryIntExpression) NaryIntExpression(kodkod.ast.NaryIntExpression) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) UnaryExpression(kodkod.ast.UnaryExpression) NaryExpression(kodkod.ast.NaryExpression) IfExpression(kodkod.ast.IfExpression) BinaryIntExpression(kodkod.ast.BinaryIntExpression) IfIntExpression(kodkod.ast.IfIntExpression) UnaryIntExpression(kodkod.ast.UnaryIntExpression) NaryIntExpression(kodkod.ast.NaryIntExpression) IntExpression(kodkod.ast.IntExpression)

Example 23 with IntExpression

use of kodkod.ast.IntExpression in project org.alloytools.alloy by AlloyTools.

the class AbstractReplacer method visit.

/**
 * Calls lookup(intExpr) and returns the cached value, if any. If a replacement
 * has not been cached, visits the expression's children. If nothing changes,
 * the argument is cached and returned, otherwise a replacement expression is
 * cached and returned.
 *
 * @return { c: IntExpression | [[c]] = intExpr.left.accept(delegate) op
 *         intExpr.right.accept(delegate) }
 */
@Override
public IntExpression visit(BinaryIntExpression intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret != null)
        return ret;
    final IntExpression left = intExpr.left().accept(delegate);
    final IntExpression right = intExpr.right().accept(delegate);
    ret = (left == intExpr.left() && right == intExpr.right()) ? intExpr : left.compose(intExpr.op(), right);
    return cache(intExpr, ret);
}
Also used : BinaryIntExpression(kodkod.ast.BinaryIntExpression) IfIntExpression(kodkod.ast.IfIntExpression) UnaryIntExpression(kodkod.ast.UnaryIntExpression) NaryIntExpression(kodkod.ast.NaryIntExpression) IntExpression(kodkod.ast.IntExpression)

Example 24 with IntExpression

use of kodkod.ast.IntExpression in project org.alloytools.alloy by AlloyTools.

the class AbstractReplacer method visit.

/**
 * Calls lookup(intExpr) and returns the cached value, if any. If a replacement
 * has not been cached, visits the intExpr's children. If nothing changes, the
 * argument is cached and returned, otherwise a replacement intExpr is cached
 * and returned.
 *
 * @return { e: IntExpression | e.op = intExpr.op && #e.children =
 *         #intExpr.children && all i: [0..intExpr.children) | e.child(i) =
 *         intExpr.child(i).accept(delegate) }
 */
@Override
public IntExpression visit(NaryIntExpression intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret != null)
        return ret;
    final IntExpression[] visited = new IntExpression[intExpr.size()];
    boolean allSame = true;
    for (int i = 0; i < visited.length; i++) {
        final IntExpression child = intExpr.child(i);
        visited[i] = child.accept(delegate);
        allSame = allSame && visited[i] == child;
    }
    ret = allSame ? intExpr : IntExpression.compose(intExpr.op(), visited);
    return cache(intExpr, ret);
}
Also used : BinaryIntExpression(kodkod.ast.BinaryIntExpression) IfIntExpression(kodkod.ast.IfIntExpression) UnaryIntExpression(kodkod.ast.UnaryIntExpression) NaryIntExpression(kodkod.ast.NaryIntExpression) IntExpression(kodkod.ast.IntExpression)

Example 25 with IntExpression

use of kodkod.ast.IntExpression in project org.alloytools.alloy by AlloyTools.

the class AbstractReplacer method visit.

/**
 * Calls lookup(intExpr) and returns the cached value, if any. If a replacement
 * has not been cached, visits the expression's children. If nothing changes,
 * the argument is cached and returned, otherwise a replacement expression is
 * cached and returned.
 *
 * @return { c: IntExpression | [[c]] = sum intExpr.decls.accept(delegate) |
 *         intExpr.intExpr.accept(delegate) }
 */
@Override
public IntExpression visit(SumExpression intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret != null)
        return ret;
    final Decls decls = intExpr.decls().accept(delegate);
    final IntExpression expr = intExpr.intExpr().accept(delegate);
    ret = (decls == intExpr.decls() && expr == intExpr.intExpr()) ? intExpr : expr.sum(decls);
    return cache(intExpr, ret);
}
Also used : Decls(kodkod.ast.Decls) BinaryIntExpression(kodkod.ast.BinaryIntExpression) IfIntExpression(kodkod.ast.IfIntExpression) UnaryIntExpression(kodkod.ast.UnaryIntExpression) NaryIntExpression(kodkod.ast.NaryIntExpression) IntExpression(kodkod.ast.IntExpression)

Aggregations

IntExpression (kodkod.ast.IntExpression)32 Formula (kodkod.ast.Formula)16 Expression (kodkod.ast.Expression)13 BinaryIntExpression (kodkod.ast.BinaryIntExpression)11 IfIntExpression (kodkod.ast.IfIntExpression)11 NaryIntExpression (kodkod.ast.NaryIntExpression)11 UnaryIntExpression (kodkod.ast.UnaryIntExpression)11 Decls (kodkod.ast.Decls)10 BinaryExpression (kodkod.ast.BinaryExpression)8 Variable (kodkod.ast.Variable)8 Solution (kodkod.engine.Solution)8 QuantifiedFormula (kodkod.ast.QuantifiedFormula)7 Relation (kodkod.ast.Relation)7 TupleFactory (kodkod.instance.TupleFactory)6 TupleSet (kodkod.instance.TupleSet)6 SumExpression (kodkod.ast.SumExpression)5 Solver (kodkod.engine.Solver)5 Bounds (kodkod.instance.Bounds)5 Universe (kodkod.instance.Universe)5 ConstantExpression (kodkod.ast.ConstantExpression)4