Search in sources :

Example 21 with Expression

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

the class AbstractCollector method visit.

/**
 * Calls lookup(expr) and returns the cached value, if any. If no cached value
 * exists, visits each child, caches the union of the children's return values
 * and returns it.
 *
 * @return let x = lookup(expr) | x != null => x, cache(expr,
 *         expr.child(0).accept(this) + .. +
 *         expr.child(expr.size()-1).accept(this))
 */
@Override
public Set<T> visit(NaryExpression expr) {
    Set<T> ret = lookup(expr);
    if (ret != null)
        return ret;
    ret = newSet();
    for (Expression child : expr) {
        ret.addAll(child.accept(this));
    }
    return cache(expr, 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)

Example 22 with Expression

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

the class AbstractReplacer method visit.

/**
 * Calls lookup(decl) and returns the cached value, if any. If a replacement has
 * not been cached, visits the declaration's variable and expression. If nothing
 * changes, the argument is cached and returned, otherwise a replacement Decl
 * object is cached and returned.
 *
 * @return { d: Declaration | d.variable = declaration.variable.accept(delegate)
 *         && d.multiplicity = decl.multiplicity && d.expression =
 *         declaration.expression.accept(delegate)
 */
@Override
public Decl visit(Decl decl) {
    Decl ret = lookup(decl);
    if (ret != null)
        return ret;
    final Variable variable = (Variable) decl.variable().accept(delegate);
    final Expression expression = decl.expression().accept(delegate);
    ret = (variable == decl.variable() && expression == decl.expression()) ? decl : variable.declare(decl.multiplicity(), expression);
    return cache(decl, ret);
}
Also used : Variable(kodkod.ast.Variable) 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) Decl(kodkod.ast.Decl)

Example 23 with Expression

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

the class AbstractReplacer method visit.

/**
 * Calls lookup(decls) and returns the cached value, if any. If a replacement
 * has not been cached, visits each of the children's variable and expression.
 * If nothing changes, the argument is cached and returned, otherwise a
 * replacement Decls object is cached and returned.
 *
 * @return { d: Decls | d.size = decls.size && all i: [0..d.size) |
 *         d.declarations[i] = decls.declarations[i].accept(delegate) }
 */
@Override
public Expression visit(ProjectExpression project) {
    Expression ret = lookup(project);
    if (ret != null)
        return ret;
    final Expression expr = project.expression().accept(delegate);
    final IntExpression[] cols = new IntExpression[project.arity()];
    boolean allSame = expr == project.expression();
    for (int i = 0, arity = project.arity(); i < arity; i++) {
        cols[i] = project.column(i).accept(delegate);
        allSame = allSame && (cols[i] == project.column(i));
    }
    ret = allSame ? project : expr.project(cols);
    return cache(project, 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 24 with Expression

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

the class AbstractReplacer method visit.

/**
 * Calls lookup(compFormula) and returns the cached value, if any. If a
 * replacement has not been cached, visits the formula's children. If nothing
 * changes, the argument is cached and returned, otherwise a replacement formula
 * is cached and returned.
 *
 * @return { c: ComparisonFormula | c.left = compFormula.left.accept(delegate)
 *         && c.right = compFormula.right.accept(delegate) && c.op =
 *         compFormula.op }
 */
@Override
public Formula visit(ComparisonFormula compFormula) {
    Formula ret = lookup(compFormula);
    if (ret != null)
        return ret;
    final Expression left = compFormula.left().accept(delegate);
    final Expression right = compFormula.right().accept(delegate);
    ret = (left == compFormula.left() && right == compFormula.right()) ? compFormula : left.compare(compFormula.op(), right);
    return cache(compFormula, 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) 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)

Example 25 with Expression

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

the class AbstractReplacer method visit.

/**
 * Calls lookup(comprehension) 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: Comprehension | c.declarations =
 *         comprehension.declarations.accept(delegate) && c.formula =
 *         comprehension.formula.accept(delegate) }
 */
@Override
public Expression visit(Comprehension comprehension) {
    Expression ret = lookup(comprehension);
    if (ret != null)
        return ret;
    final Decls decls = comprehension.decls().accept(delegate);
    final Formula formula = comprehension.formula().accept(delegate);
    ret = (decls == comprehension.decls() && formula == comprehension.formula()) ? comprehension : formula.comprehension(decls);
    return cache(comprehension, 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) Decls(kodkod.ast.Decls) 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)

Aggregations

Expression (kodkod.ast.Expression)127 Formula (kodkod.ast.Formula)95 Variable (kodkod.ast.Variable)80 IntExpression (kodkod.ast.IntExpression)49 Relation (kodkod.ast.Relation)26 BinaryExpression (kodkod.ast.BinaryExpression)22 Decls (kodkod.ast.Decls)22 Bounds (kodkod.instance.Bounds)21 TupleSet (kodkod.instance.TupleSet)20 Universe (kodkod.instance.Universe)20 SumExpression (kodkod.ast.SumExpression)19 TupleFactory (kodkod.instance.TupleFactory)19 Solution (kodkod.engine.Solution)17 QuantifiedFormula (kodkod.ast.QuantifiedFormula)14 Solver (kodkod.engine.Solver)14 BinaryIntExpression (kodkod.ast.BinaryIntExpression)13 ConstantExpression (kodkod.ast.ConstantExpression)13 IfExpression (kodkod.ast.IfExpression)13 IfIntExpression (kodkod.ast.IfIntExpression)13 NaryExpression (kodkod.ast.NaryExpression)13