kodkod.ast.operator.ExprCompOperator Java Examples

The following examples show how to use kodkod.ast.operator.ExprCompOperator. 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: 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 #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: 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 #4
Source File: ComparisonFormula.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new comparison formula: left op right
 *
 * @ensures this.left' = left && this.right' = right && this.op' = op * @throws
 *          NullPointerException left = null || right = null || op = null
 * @throws IllegalArgumentException left.arity != right.arity
 */
ComparisonFormula(Expression left, ExprCompOperator op, Expression right) {
    if (left.arity() != right.arity()) {
        throw new IllegalArgumentException("Arity mismatch: " + left + "::" + left.arity() + " and " + right + "::" + right.arity());
    }
    this.left = left;
    this.right = right;
    this.op = op;
}
 
Example #5
Source File: ComparisonFormula.java    From kodkod with MIT License 5 votes vote down vote up
/**  
 * Constructs a new comparison formula: left op  right
 * 
 * @ensures this.left' = left && this.right' = right && this.op' = op
 * * @throws NullPointerException  left = null || right = null || op = null
 * @throws IllegalArgumentException  left.arity != right.arity
 */
ComparisonFormula(Expression left, ExprCompOperator op, Expression right) {
    if (left.arity()!=right.arity()) {
        throw new IllegalArgumentException(
        		"Arity mismatch: " + left + "::" + left.arity() + 
                " and " + right + "::" + right.arity());
    }
    this.left = left;
    this.right = right;
    this.op = op;
}
 
Example #6
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 #7
Source File: ComparisonFormula.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the operator of this.
 *
 * @return this.op
 */
public ExprCompOperator op() {
    return op;
}
 
Example #8
Source File: Expression.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the formula that represents the comparison of this and the given
 * expression using the given comparison operator.
 *
 * @return {f: Formula | f.left = this && f.right = expr && f.op = op}
 */
public final Formula compare(ExprCompOperator op, Expression expr) {
    return new ComparisonFormula(this, op, expr);
}
 
Example #9
Source File: ComparisonFormula.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns the operator of this.
 * @return this.op
 */
public ExprCompOperator op() {return op;}
 
Example #10
Source File: Expression.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns the formula that represents the comparison of this and the
 * given expression using the given comparison operator.
 * @return {f: Formula | f.left = this && f.right = expr  && f.op = op}
 */
public final Formula compare(ExprCompOperator op, Expression expr) {
	return new ComparisonFormula(this, op, expr);
}