kodkod.ast.ComparisonFormula Java Examples

The following examples show how to use kodkod.ast.ComparisonFormula. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PartialCannonicalizer.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public Formula visit(ComparisonFormula formula) { 
	Formula ret = lookup(formula);
	if (ret!=null) return ret;
	
	final ExprCompOperator op = formula.op();
	final Expression left = formula.left().accept(this);
	final Expression right = formula.right().accept(this);
	
	if (left==right) return cache(formula,Formula.TRUE);
	
	final int hash = hash(op, left, right);
	for(Iterator<PartialCannonicalizer.Holder<Formula>> itr = formulas.get(hash); itr.hasNext(); ) {
		final Formula next = itr.next().obj;
		if (next instanceof ComparisonFormula) { 
			final ComparisonFormula hit = (ComparisonFormula) next;
			if (hit.op()==op && hit.left()==left && hit.right()==right) { 
				return cache(formula, hit);
			}
		}
	}

	ret = left==formula.left()&&right==formula.right() ? formula : left.compare(op, right);
	formulas.add(new PartialCannonicalizer.Holder<Formula>(ret, hash));
	return cache(formula,ret);
}
 
Example #2
Source File: FOL2BoolTranslator.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Calls lookup(compFormula) and returns the cached value, if any.  
 * If a translation has not been cached, translates the formula,
 * calls cache(...) on it and returns it.
 * @return let t = lookup(compFormula) | some t => t, 
 *      let op = (binExpr.op).(SUBSET->subset + EQUALS->eq) | 
 *       cache(compFormula, op(compFormula.left.accept(this), compFormula.right.accept(this)))
 */
public final BooleanValue visit(ComparisonFormula compFormula) {
	BooleanValue ret = lookup(compFormula);
	if (ret!=null) return ret;

	final BooleanMatrix left = compFormula.left().accept(this);
	final BooleanMatrix right = compFormula.right().accept(this);
	final ExprCompOperator op = compFormula.op();

	switch(op) {
	case SUBSET	: ret = left.subset(right); break;
	case EQUALS	: ret = left.eq(right); break;
	default : 
		throw new IllegalArgumentException("Unknown operator: " + compFormula.op());
	}
	return cache(compFormula,ret);
}
 
Example #3
Source File: TranslateKodkodToJava.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visit(ComparisonFormula x) {
    String newname = makename(x);
    if (newname == null)
        return;
    String left = make(x.left());
    String right = make(x.right());
    switch (x.op()) {
        case EQUALS :
            file.printf("Formula %s=%s.eq(%s);%n", newname, left, right);
            break;
        case SUBSET :
            file.printf("Formula %s=%s.in(%s);%n", newname, left, right);
            break;
        default :
            throw new RuntimeException("Unknown kodkod operator \"" + x.op() + "\" encountered");
    }
}
 
Example #4
Source File: FOL2BoolTranslator.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Calls lookup(compFormula) and returns the cached value, if any. If a
 * translation has not been cached, translates the formula, calls cache(...) on
 * it and returns it.
 *
 * @return let t = lookup(compFormula) | some t => t, let op =
 *         (binExpr.op).(SUBSET->subset + EQUALS->eq) | cache(compFormula,
 *         op(compFormula.left.accept(this), compFormula.right.accept(this)))
 */
@Override
public final BooleanValue visit(ComparisonFormula compFormula) {
    BooleanValue ret = lookup(compFormula);
    if (ret != null)
        return ret;

    final BooleanMatrix left = compFormula.left().accept(this);
    final BooleanMatrix right = compFormula.right().accept(this);
    final ExprCompOperator op = compFormula.op();

    switch (op) {
        case SUBSET :
            ret = left.subset(right, env);
            break;
        case EQUALS :
            ret = left.eq(right, env);
            break;
        default :
            throw new IllegalArgumentException("Unknown operator: " + compFormula.op());
    }
    return cache(compFormula, ret);
}
 
Example #5
Source File: Simplifier.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Formula visit(ComparisonFormula formula) { 
	Formula ret = lookup(formula);
	if (ret!=null) return ret;
	
	final ExprCompOperator op = formula.op();
	final Expression left = formula.left().accept(this);
	final Expression right = formula.right().accept(this);
	
	if (left==right) return cache(formula,Formula.TRUE);
	
	ret = left==formula.left()&&right==formula.right() ? formula : left.compare(op, right);
	return cache(formula,ret);
}
 
Example #6
Source File: PrettyPrinter.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/** @effects this.tokens' = concat[ this.tokens, tokenize[node.left], node.op, tokenize[node.right] */
public void visit(ComparisonFormula node) {
	if (displayed(node)) return;
	final boolean oldTop = notTop();
	visitChild(node.left(), parenthesize(node.left()));
	infix(node.op());
	visitChild(node.right(), parenthesize(node.right()));
	top = oldTop;
}
 
Example #7
Source File: Skolemizer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls super.visit(cf) after disabling skolemization and returns the result. 
 * @return super.visit(cf) 
 **/
public final Formula visit(ComparisonFormula cf) {
	final int oldDepth = skolemDepth;
	skolemDepth = -1; // cannot skolemize inside a comparison formula
	final Formula ret = super.visit(cf);
	skolemDepth = oldDepth;
	return source(ret,cf);
}
 
Example #8
Source File: AbstractCollector.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(compFormula) 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(compFormula) | 
 *          x != null => x,  
 *          cache(compFormula,compFormula.left.accept(this) + compFormula.right.accept(this)) 
 */
public Set<T> visit(ComparisonFormula compFormula) {
	Set<T> ret = lookup(compFormula);
	if (ret!=null) return ret;		
	ret = newSet();
	ret.addAll(compFormula.left().accept(this));
	ret.addAll(compFormula.right().accept(this));
	return cache(compFormula, ret);
}
 
Example #9
Source File: AbstractReplacer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * 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(this) &&
 *                                  c.right = compFormula.right.accept(this) &&
 *                                  c.op = compFormula.op }
 */
public Formula visit(ComparisonFormula compFormula) {
	Formula ret = lookup(compFormula);
	if (ret!=null) return ret;
		
	final Expression left  = compFormula.left().accept(this);
	final Expression right = compFormula.right().accept(this);
	ret =  (left==compFormula.left() && right==compFormula.right()) ? 
		   compFormula : left.compare(compFormula.op(), right);	
	return cache(compFormula,ret);
}
 
Example #10
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * @ensures this.tokens' = concat[ this.tokens, tokenize[node.left], node.op,
 *          tokenize[node.right]
 */
@Override
public void visit(ComparisonFormula node) {
    visitChild(node.left(), parenthesize(node.left()));
    infix(node.op());
    visitChild(node.right(), parenthesize(node.right()));
}
 
Example #11
Source File: Skolemizer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls super.visit(cf) after disabling skolemization and returns the result.
 *
 * @return super.visit(cf)
 **/
@Override
public final Formula visit(ComparisonFormula cf) {
    final int oldDepth = skolemDepth;
    skolemDepth = -1; // cannot skolemize inside a comparison formula
    final Formula ret = super.visit(cf);
    skolemDepth = oldDepth;
    return source(ret, cf);
}
 
Example #12
Source File: AbstractReplacer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #13
Source File: AbstractVoidVisitor.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Visits the left and right children if this.visited(compFormula) returns
 * false. Otherwise does nothing.
 *
 * @ensures compFormula.left.accept(this) && compFormula.right.accept(this)
 */
@Override
public void visit(ComparisonFormula compFormula) {
    if (visited(compFormula))
        return;
    compFormula.left().accept(this);
    compFormula.right().accept(this);
}
 
Example #14
Source File: AbstractCollector.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls lookup(compFormula) 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(compFormula) | x != null => x,
 *         cache(compFormula,compFormula.left.accept(this) +
 *         compFormula.right.accept(this))
 */
@Override
public Set<T> visit(ComparisonFormula compFormula) {
    Set<T> ret = lookup(compFormula);
    if (ret != null)
        return ret;
    ret = newSet();
    ret.addAll(compFormula.left().accept(this));
    ret.addAll(compFormula.right().accept(this));
    return cache(compFormula, ret);
}
 
Example #15
Source File: AspectReturnVisitor.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public F visit(ComparisonFormula compFormula) {
    start(compFormula);
    return end(compFormula, visitor.visit(compFormula));
}
 
Example #16
Source File: PrettyPrinter.java    From kodkod with MIT License 4 votes vote down vote up
/** @ensures this.tokens' = concat[ this.tokens, tokenize[node.left], node.op, tokenize[node.right] */
public void visit(ComparisonFormula node) {
	visitChild(node.left(), parenthesize(node.left()));
	infix(node.op());
	visitChild(node.right(), parenthesize(node.right()));
}
 
Example #17
Source File: FormulaFlattener.java    From kodkod with MIT License 4 votes vote down vote up
/** @see #visitFormula(Formula) */
public final void visit(ComparisonFormula cf) 		{ visitFormula(cf); }
 
Example #18
Source File: TrivialProof.java    From kodkod with MIT License 4 votes vote down vote up
public void visit(ComparisonFormula compFormula) { 
	if (visited(compFormula)) return;
	relevant.add(compFormula); 	
}
 
Example #19
Source File: AbstractVoidVisitor.java    From kodkod with MIT License 4 votes vote down vote up
/**
 * Visits the left and right children  if
 * this.visited(compFormula) returns false.  Otherwise does nothing.
 * @ensures compFormula.left.accept(this) && compFormula.right.accept(this)
 */
public void visit(ComparisonFormula compFormula) {
	if (visited(compFormula)) return;
	compFormula.left().accept(this);
	compFormula.right().accept(this);
}
 
Example #20
Source File: TrivialProof.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(ComparisonFormula compFormula) {
    if (visited(compFormula))
        return;
    relevant.add(compFormula);
}
 
Example #21
Source File: AnnotatedNode.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean visit(ComparisonFormula f) {
    return checkVisitedThenAccumA(f, Boolean.FALSE, f.left(), f.right());
}
 
Example #22
Source File: AnnotatedNode.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * Calls visited(compFormula); compFormula's children are not top-level formulas
 * so they are not visited.
 */
@Override
public void visit(ComparisonFormula compFormula) {
    visited(compFormula);
}
 
Example #23
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(ComparisonFormula compFormula) {
    visit(compFormula, compFormula.op(), compFormula.left(), compFormula.right());
}
 
Example #24
Source File: FullNegationPropagator.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/** @see #visitFormula(Formula) */
@Override
public final void visit(ComparisonFormula cf) {
    visitFormula(cf);
}
 
Example #25
Source File: HOLTranslator.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public Proc visit(ComparisonFormula cf) {
    return new Proc.FOL(bounds, cf);
}
 
Example #26
Source File: FormulaFlattener.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/** @see #visitFormula(Formula) */
@Override
public final void visit(ComparisonFormula cf) {
    visitFormula(cf);
}
 
Example #27
Source File: AbstractDetector.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Calls lookup(exprComp) and returns the cached value, if any. If no cached
 * value exists, visits each child, caches the disjunction of the children's
 * return values and returns it.
 *
 * @return let x = lookup(exprComp) | x != null => x,
 *         cache(exprComp,exprComp.left.accept(this) ||
 *         exprComp.right.accept(this))
 */
@Override
public Boolean visit(ComparisonFormula exprComp) {
    final Boolean ret = lookup(exprComp);
    return (ret != null) ? ret : cache(exprComp, exprComp.left().accept(this) || exprComp.right().accept(this));
}
 
Example #28
Source File: VoidVisitor.java    From kodkod with MIT License 2 votes vote down vote up
/** 
* Visits the given comparison formula.
**/
  public void visit(ComparisonFormula compFormula);
 
Example #29
Source File: ReturnVisitor.java    From kodkod with MIT License 2 votes vote down vote up
/** 
* Visits the given comparison formula and returns the result.
* @return the result of visiting <code>compFormula</code> 
**/
  public F visit(ComparisonFormula compFormula);
 
Example #30
Source File: AbstractDetector.java    From kodkod with MIT License 2 votes vote down vote up
/** 
 * Calls lookup(exprComp) and returns the cached value, if any.  
 * If no cached value exists, visits each child, caches the
 * disjunction of the children's return values and returns it. 
 * @return let x = lookup(exprComp) | 
 *          x != null => x,  
 *          cache(exprComp,exprComp.left.accept(this) || exprComp.right.accept(this)) 
 */
public Boolean visit(ComparisonFormula exprComp) {
	final Boolean ret = lookup(exprComp);
	return (ret!=null) ? ret :  cache(exprComp, exprComp.left().accept(this) || exprComp.right().accept(this));
}