kodkod.ast
Class Variable

java.lang.Object
  extended by kodkod.ast.Expression
      extended by kodkod.ast.LeafExpression
          extended by kodkod.ast.Variable
All Implemented Interfaces:
Node

public final class Variable
extends LeafExpression

Represents a variable in a quantified formula, a comprehension expression, or a sum expression. Two variables are the same if and only if they refer to the same object. That is, v1.eauls(v2) <=> v1 == v2. Each variable has a name, which is basically a comment for the purpose of printing, viewing, etc. The name has no meaning otherwise. The arity of a variable specifies the arity of expressions over which the variable can range.

Author:
Emina Torlak
invariant:
no children
specfield:
name: String
arity: int

Field Summary
 
Fields inherited from class kodkod.ast.Expression
IDEN, INTS, NONE, UNIV
 
Method Summary
<E,F,D,I> E
accept(ReturnVisitor<E,F,D,I> visitor)
          Returns true of o is a BinaryFormula with the same tree structure as this.
 void accept(VoidVisitor visitor)
          Accepts the given visitor.
 Decl declare(Multiplicity mult, Expression expr)
          Returns the declaration that constrains this variable to be bound to the specified number of the elements in the given expression: 'this: mult expr'.
 Decl loneOf(Expression expr)
          Returns the declaration that constrains this variable to be bound to at most one element of the given expression: 'this: lone expr'.
static Variable nary(java.lang.String name, int arity)
          Returns a new variable with the specified name and arity.
 Decl oneOf(Expression expr)
          Returns the declaration that constrains this variable to be bound to exactly one element of the given expression: 'this: one expr'.
 Decl setOf(Expression expr)
          Returns the declaration that constrains this variable to be bound to a subset of the elements in the given expression: 'this: set expr'.
 Decl someOf(Expression expr)
          Returns the declaration that constrains this variable to be bound to at least one element of the given expression: 'this: some expr'.
static Variable unary(java.lang.String name)
          Returns a new variable with the specified name and arity 1.
 
Methods inherited from class kodkod.ast.LeafExpression
arity, name, toString
 
Methods inherited from class kodkod.ast.Expression
apply, apply, apply, closure, compose, compose, count, difference, eq, in, intersection, join, lone, no, one, override, product, project, reflexiveClosure, some, sum, transpose, union
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

unary

public static Variable unary(java.lang.String name)
Returns a new variable with the specified name and arity 1.

effects:
this.name' = name && this.arity' = 1

nary

public static Variable nary(java.lang.String name,
                            int arity)
Returns a new variable with the specified name and arity.

Throws:
java.lang.IllegalArgumentException - - arity < 1
effects:
this.name' = name && this.arity' = arity

loneOf

public Decl loneOf(Expression expr)
Returns the declaration that constrains this variable to be bound to at most one element of the given expression: 'this: lone expr'.

Returns:
{d: Decl | d.variable = this && d.multiplicity = LONE && d.expression = expr }
Throws:
java.lang.NullPointerException - - expr = null
java.lang.IllegalArgumentException - - this.arity != expr.arity || expr.arity != 1

oneOf

public Decl oneOf(Expression expr)
Returns the declaration that constrains this variable to be bound to exactly one element of the given expression: 'this: one expr'.

Returns:
{d: Decl | d.variable = this && d.multiplicity = ONE && d.expression = expr }
Throws:
java.lang.NullPointerException - - expr = null
java.lang.IllegalArgumentException - - this.arity != expr.arity || expr.arity != 1

someOf

public Decl someOf(Expression expr)
Returns the declaration that constrains this variable to be bound to at least one element of the given expression: 'this: some expr'.

Returns:
{d: Decl | d.variable = this && d.multiplicity = SOME && d.expression = expr }
Throws:
java.lang.NullPointerException - - expr = null
java.lang.IllegalArgumentException - - this.arity != expr.arity || expr.arity != 1

setOf

public Decl setOf(Expression expr)
Returns the declaration that constrains this variable to be bound to a subset of the elements in the given expression: 'this: set expr'.

Returns:
{d: Decl | d.variable = this && d.multiplicity = SET && d.expression = expr }
Throws:
java.lang.NullPointerException - - expr = null
java.lang.IllegalArgumentException - - this.arity != expr.arity

declare

public Decl declare(Multiplicity mult,
                    Expression expr)
Returns the declaration that constrains this variable to be bound to the specified number of the elements in the given expression: 'this: mult expr'.

Returns:
{d: Decl | d.variable = this && d.multiplicity = mult && d.expression = expr }
Throws:
java.lang.NullPointerException - - expression = null || mult = null
java.lang.IllegalArgumentException - - mult = NO
java.lang.IllegalArgumentException - - mult in ONE + LONE + SOME && expr.arity != 1
java.lang.IllegalArgumentException - - this.arity != expr.arity

accept

public <E,F,D,I> E accept(ReturnVisitor<E,F,D,I> visitor)
Returns true of o is a BinaryFormula with the same tree structure as this.

Specified by:
accept in interface Node
Specified by:
accept in class Expression
Returns:
o.op.equals(this.op) && o.left.equals(this.left) && o.right.equals(this.right)
See Also:
Node.accept(kodkod.ast.visitor.ReturnVisitor)

accept

public void accept(VoidVisitor visitor)
Accepts the given visitor.

See Also:
Node.accept(kodkod.ast.visitor.VoidVisitor)