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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations