kodkod.ast.visitor
Class AbstractReplacer

java.lang.Object
  extended by kodkod.ast.visitor.AbstractReplacer
All Implemented Interfaces:
ReturnVisitor<Expression,Formula,Decls,IntExpression>

public abstract class AbstractReplacer
extends java.lang.Object
implements ReturnVisitor<Expression,Formula,Decls,IntExpression>

A depth first replacer. The default implementation returns the tree to which it is applied. Reference equality is used to determine if two nodes are the same.

Author:
Emina Torlak
invariant:
cached in cache.Node
specfield:
cached: set Node // result of visiting these nodes will be cached
cache: Node ->lone Node

Method Summary
 Expression visit(BinaryExpression binExpr)
          Calls lookup(binExpr) and returns the cached value, if any.
 Formula visit(BinaryFormula binFormula)
          Calls lookup(binFormula) and returns the cached value, if any.
 IntExpression visit(BinaryIntExpression intExpr)
          Calls lookup(intExpr) and returns the cached value, if any.
 Formula visit(ComparisonFormula compFormula)
          Calls lookup(compFormula) and returns the cached value, if any.
 Expression visit(Comprehension comprehension)
          Calls lookup(comprehension) and returns the cached value, if any.
 Expression visit(ConstantExpression constExpr)
          Calls lookup(constExpr) and returns the cached value, if any.
 Formula visit(ConstantFormula constant)
          Calls lookup(constant) and returns the cached value, if any.
 Decl visit(Decl decl)
          Calls lookup(decl) and returns the cached value, if any.
 Decls visit(Decls decls)
          Calls lookup(decls) and returns the cached value, if any.
 IntExpression visit(ExprToIntCast intExpr)
          Calls lookup(intExpr) and returns the cached value, if any.
 Expression visit(IfExpression ifExpr)
          Calls lookup(ifExpr) and returns the cached value, if any.
 IntExpression visit(IfIntExpression intExpr)
          Calls lookup(intExpr) and returns the cached value, if any.
 Formula visit(IntComparisonFormula intComp)
          Calls lookup(intComp) and returns the cached value, if any.
 IntExpression visit(IntConstant intconst)
          Calls lookup(intconst) and returns the cached value, if any.
 Expression visit(IntToExprCast castExpr)
          Calls lookup(castExpr) and returns the cached value, if any.
 Formula visit(MultiplicityFormula multFormula)
          Calls lookup(multFormula) and returns the cached value, if any.
 Formula visit(NotFormula not)
          Calls lookup(binFormula) and returns the cached value, if any.
 Expression visit(ProjectExpression project)
          Calls lookup(decls) and returns the cached value, if any.
 Formula visit(QuantifiedFormula quantFormula)
          Calls lookup(quantFormula) and returns the cached value, if any.
 Expression visit(Relation relation)
          Calls lookup(relation) and returns the cached value, if any.
 Formula visit(RelationPredicate pred)
          Calls lookup(pred) and returns the cached value, if any.
 IntExpression visit(SumExpression intExpr)
          Calls lookup(intExpr) and returns the cached value, if any.
 Expression visit(UnaryExpression unaryExpr)
          Calls lookup(unaryExpr) and returns the cached value, if any.
 IntExpression visit(UnaryIntExpression intExpr)
          Calls lookup(intExpr) and returns the cached value, if any.
 Expression visit(Variable variable)
          Calls lookup(variable) and returns the cached value, if any.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

visit

public Decls visit(Decls decls)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ d: Decls | d.size = decls.size && all i: [0..d.size) | d.declarations[i] = decls.declarations[i].accept(this) }

visit

public Decl visit(Decl decl)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ d: Declaration | d.variable = declaration.variable.accept(this) && d.multiplicity = decl.multiplicity && d.expression = declaration.expression.accept(this)

visit

public Expression visit(Relation relation)
Calls lookup(relation) and returns the cached value, if any. If a replacement has not been cached, the relation is cached and returned.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
relation

visit

public Expression visit(Variable variable)
Calls lookup(variable) and returns the cached value, if any. If a replacement has not been cached, the variable is cached and returned.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
variable

visit

public Expression visit(ConstantExpression constExpr)
Calls lookup(constExpr) and returns the cached value, if any. If a replacement has not been cached, the constExpr is cached and returned.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
constExpr

visit

public Expression visit(BinaryExpression binExpr)
Calls lookup(binExpr) 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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ b: BinaryExpression | b.left = binExpr.left.accept(this) && b.right = binExpr.right.accept(this) && b.op = binExpr.op }

visit

public Expression visit(UnaryExpression unaryExpr)
Calls lookup(unaryExpr) 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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ u: UnaryExpression | u.left = unaryExpr.expression.accept(this) && u.op = unaryExpr.op }

visit

public Expression visit(Comprehension comprehension)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ c: Comprehension | c.declarations = comprehension.declarations.accept(this) && c.formula = comprehension.formula.accept(this) }

visit

public Expression visit(IfExpression ifExpr)
Calls lookup(ifExpr) 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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ i: IfExpression | i.condition = ifExpr.condition.accept(this) && i.thenExpr = ifExpr.thenExpr.accept(this) && i.elseExpr = ifExpr.elseExpr.accept(this) }

visit

public Expression visit(ProjectExpression project)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ d: Decls | d.size = decls.size && all i: [0..d.size) | d.declarations[i] = decls.declarations[i].accept(this) }

visit

public Expression visit(IntToExprCast castExpr)
Calls lookup(castExpr) 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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ e: Expression | e = castExpr.intExpr.accept(this).toExpression() }

visit

public IntExpression visit(IntConstant intconst)
Calls lookup(intconst) and returns the cached value, if any. If a replacement has not been cached, the constant is cached and returned.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
intconst

visit

public IntExpression visit(IfIntExpression intExpr)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ i: IfIntExpression | i.condition = intExpr.condition.accept(this) && i.thenExpr = intExpr.thenExpr.accept(this) && i.elseExpr = intExpr.elseExpr.accept(this) }

visit

public IntExpression visit(ExprToIntCast intExpr)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ i: ExprToIntCast | i.expression = intExpr.expression.accept(this) && i.op = intExpr.op}

visit

public IntExpression visit(BinaryIntExpression intExpr)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ c: IntExpression | [[c]] = intExpr.left.accept(this) op intExpr.right.accept(this) }

visit

public IntExpression visit(UnaryIntExpression intExpr)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ u: UnaryIntExpression | u.expression = intExpr.expression.accept(this) && u.op = intExpr.op }

visit

public IntExpression visit(SumExpression intExpr)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ c: IntExpression | [[c]] = sum intExpr.decls.accept(this) | intExpr.intExpr.accept(this) }

visit

public Formula visit(IntComparisonFormula intComp)
Calls lookup(intComp) 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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ c: Formula | [[c]] = intComp.left.accept(this) op intComp.right.accept(this) }

visit

public Formula visit(ConstantFormula constant)
Calls lookup(constant) and returns the cached value, if any. If a replacement has not been cached, the constant is cached and returned.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
constant

visit

public Formula visit(QuantifiedFormula quantFormula)
Calls lookup(quantFormula) 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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ q: QuantifiedFormula | q.declarations = quantFormula.declarations.accept(this) && q.formula = quantFormula.formula.accept(this) }

visit

public Formula visit(BinaryFormula binFormula)
Calls lookup(binFormula) 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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ b: BinaryFormula | b.left = binExpr.left.accept(this) && b.right = binExpr.right.accept(this) && b.op = binExpr.op }

visit

public Formula visit(NotFormula not)
Calls lookup(binFormula) and returns the cached value, if any. If a replacement has not been cached, visits the formula's child. If nothing changes, the argument is cached and returned, otherwise a replacement formula is cached and returned.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ n: NotFormula | n.child = not.child.accept(this) }

visit

public Formula visit(ComparisonFormula compFormula)
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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ c: ComparisonFormula | c.left = compFormula.left.accept(this) && c.right = compFormula.right.accept(this) && c.op = compFormula.op }

visit

public Formula visit(MultiplicityFormula multFormula)
Calls lookup(multFormula) 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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ m: MultiplicityFormula | m.multiplicity = multFormula.multiplicity && m.expression = multFormula.expression.accept(this) }

visit

public Formula visit(RelationPredicate pred)
Calls lookup(pred) 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.

Specified by:
visit in interface ReturnVisitor<Expression,Formula,Decls,IntExpression>
Returns:
{ p: RelationPredicate | p.name = pred.name && p.relation = pred.relation.accept(this) && p.name = FUNCTION => p.targetMult = pred.targetMult && p.domain = pred.domain.accept(this) && p.range = pred.range.accept(this), p.name = TOTAL_ORDERING => p.ordered = pred.ordered.accept(this) && p.first = pred.first.accept(this) && p.last = pred.last.accept(this) }