Package kodkod.ast

Examples of kodkod.ast.Expression


  public final Decl visit(Decl decl) {
    Decl ret = lookup(decl);
    if (ret!=null) return ret;
    final int oldDepth = skolemDepth;
    skolemDepth = -1; // can't skolemize inside a decl
    final Expression expression = decl.expression().accept(this);
    skolemDepth = oldDepth;
    ret = (expression==decl.expression()) ? decl : decl.variable().declare(decl.multiplicity(), expression);  
    return cache(decl,ret);
  }
View Full Code Here


   * @return the binding for the given variable in the current replacement environment.
   * @throws UnboundLeafException - variable not bound in teh replacement environment.
   */
  @Override
  public final Expression visit(Variable variable) {
    final Expression ret = repEnv.lookup(variable);
    if (ret==null)
      throw new UnboundLeafException("Unbound variable", variable);
    return ret;
 
View Full Code Here

  /**
   * @see kodkod.ast.visitor.AbstractReplacer#visit(kodkod.ast.Comprehension)
   */
  @Override
  public final Expression visit(Comprehension expr) {
    Expression ret = lookup(expr);
    if (ret!=null) return ret;
    final Environment<Expression> oldRepEnv = repEnv; // skolemDepth < 0 at this point
    final Decls decls = visit((Decls)expr.decls());
    final Formula formula = expr.formula().accept(this);
    ret = (decls==expr.decls() && formula==expr.formula()) ? expr : formula.comprehension(decls);
View Full Code Here

   */
  private Expression skolemExpr(Decl skolemDecl, Relation skolem) {
    final int depth = nonSkolems.size();
    final int arity = depth + skolemDecl.variable().arity();

    Expression skolemExpr = skolem;
    Environment<BooleanMatrix> skolemEnv = Environment.empty();

    for(DeclInfo info : nonSkolems) {
      if (info.upperBound==null) {
        info.upperBound = upperBound(info.decl.expression(), skolemEnv);
View Full Code Here

    Decls rangeDecls = itr.next().decl;
    while(itr.hasNext()) {
      rangeDecls = rangeDecls.and(itr.next().decl);
    }
//    System.out.println(skolemDecl.expression());
    Expression skolemDomain = skolem;
    for(int i = 0, max = skolemDecl.variable().arity(); i < max; i++) {
      skolemDomain = skolemDomain.join(Expression.UNIV);
    }
    return skolemDomain.in(Formula.TRUE.comprehension(rangeDecls))
  }
View Full Code Here

        final Decl skolemDecl = visit(decl);
       
        final Relation skolem = Relation.nary("$"+ skolemDecl.variable().name(), nonSkolems.size() + skolemDecl.variable().arity());
        reporter.skolemizing(decl, skolem, nonSkolemsView);
       
        final Expression skolemExpr = skolemExpr(skolemDecl, skolem);
       
        final Multiplicity mult = decl.multiplicity();
        rangeConstraints.add(source(skolemExpr.in(skolemDecl.expression()), decl));
        if (mult!=Multiplicity.SET) {
          rangeConstraints.add(source(skolemExpr.apply(mult), decl));
        }

        if (!nonSkolems.isEmpty())
          domConstraints.add(source(domainConstraint(skolemDecl, skolem), decl));
       
View Full Code Here

    //==============================================================================================================//

    /** Allocate relations for nonbuiltin PrimSigs bottom-up. */
    private Expression allocatePrimSig(PrimSig sig) throws Err {
        // Recursively allocate all children expressions, and form the union of them
        Expression sum = null;
        for(PrimSig child:sig.children()) {
           Expression childexpr=allocatePrimSig(child);
           if (sum==null) { sum=childexpr; continue; }
           // subsigs are disjoint
           sol.addFormula(sum.intersection(childexpr).no(), child.isSubsig);
           sum = sum.union(childexpr);
        }
View Full Code Here

    //==============================================================================================================//

    /** Allocate relations for SubsetSig top-down. */
    private Expression allocateSubsetSig(SubsetSig sig) throws Err {
        // We must not visit the same SubsetSig more than once, so if we've been here already, then return the old value right away
        Expression sum = sol.a2k(sig);
        if (sum!=null && sum!=Expression.NONE) return sum;
        // Recursively form the union of all parent expressions
        TupleSet ts = factory.noneOf(1);
        for(Sig parent:sig.parents) {
           Expression p = (parent instanceof PrimSig) ? sol.a2k(parent) : allocateSubsetSig((SubsetSig)parent);
           ts.addAll(sol.query(true, p, false));
           if (sum==null) sum=p; else sum=sum.union(p);
        }
        // If subset is exact, then just use the "sum" as is
        if (sig.exact) { sol.addSig(sig, sum); return sum; }
View Full Code Here

    //==============================================================================================================//

    /** Helper method that returns the constraint that the sig has exactly "n" elements, or at most "n" elements */
    private Formula size(Sig sig, int n, boolean exact) {
        Expression a = sol.a2k(sig);
        if (n<=0) return a.no();
        if (n==1) return exact ? a.one() : a.lone();
        Formula f = exact ? Formula.TRUE : null;
        Decls d = null;
        Expression sum = null;
        while(n>0) {
           n--;
           Variable v = Variable.unary("");
           kodkod.ast.Decl dd = v.oneOf(a);
           if (d==null) d=dd; else d=dd.and(d);
           if (sum==null) sum=v; else { if (f!=null) f=v.intersection(sum).no().and(f); sum=v.union(sum); }
        }
        if (f!=null) return sum.eq(a).and(f).forSome(d); else return a.no().or(sum.eq(a).forSome(d));
    }
View Full Code Here

           ex = u.sub;
        }
        if (ex instanceof ExprBinary) {
           ExprBinary b = (ExprBinary)ex;
           if (b.op==ExprBinary.Op.ARROW || b.op==ExprBinary.Op.PLUS || b.op==ExprBinary.Op.JOIN) {
              Expression left = sim(b.left)if (left==null) return null;
              Expression right = sim(b.right); if (right==null) return null;
              if (b.op==ExprBinary.Op.ARROW) return left.product(right);
              if (b.op==ExprBinary.Op.PLUS) return left.union(right); else return left.join(right);
           }
        }
        if (ex instanceof ExprConstant) {
View Full Code Here

TOP

Related Classes of kodkod.ast.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.