Java Code Examples for kodkod.ast.IntExpression#apply()

The following examples show how to use kodkod.ast.IntExpression#apply() . 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 IntExpression visit(UnaryIntExpression expr) { 
	IntExpression ret = lookup(expr);
	if (ret!=null) return ret;
	
	final IntOperator op = expr.op();
	final IntExpression child = expr.intExpr().accept(this);
	
	ret = simplify(op, child);
	if (ret==null) {
		final int hash = hash(op, child);
		for(Iterator<PartialCannonicalizer.Holder<IntExpression>> itr = intExprs.get(hash); itr.hasNext(); ) {
			final IntExpression next = itr.next().obj;
			if (next.getClass()==UnaryIntExpression.class) { 
				if (((UnaryIntExpression)next).intExpr()==child)
					return cache(expr, next);
			}
		}
		ret = child==expr.intExpr() ? expr : child.apply(op);
		intExprs.add(new PartialCannonicalizer.Holder<IntExpression>(ret, hash));
	}
	return cache(expr,ret);
}
 
Example 2
Source File: AbstractReplacer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 *
 * @return { u: UnaryIntExpression | u.expression =
 *         intExpr.expression.accept(delegate) && u.op = intExpr.op }
 */
@Override
public IntExpression visit(UnaryIntExpression intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret != null)
        return ret;

    final IntExpression child = intExpr.intExpr().accept(delegate);
    ret = (child == intExpr.intExpr()) ? intExpr : child.apply(intExpr.op());
    return cache(intExpr, ret);
}
 
Example 3
Source File: IntTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private final void testUnOp(IntOperator op, IntExpression ei, int i, int result, int mask) {
    final IntExpression e = ei.apply(op);
    final Formula f = ei.eq(constant(i)).and(e.eq(constant(result)));
    final Solution s = solve(f);
    if (overflows(ei, i, result)) {
        assertNull(f.toString(), s.instance());
    } else {
        assertNotNull(f.toString(), s.instance());
        final Evaluator eval = new Evaluator(s.instance(), solver.options());
        assertEquals(result & mask, eval.evaluate(e) & mask);
    }
}
 
Example 4
Source File: AbstractReplacer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * 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.
 * @return { u: UnaryIntExpression | u.expression = intExpr.expression.accept(this) && u.op = intExpr.op }
 */
public IntExpression visit(UnaryIntExpression intExpr) {
	IntExpression ret = lookup(intExpr);
	if (ret!=null) return ret;

	final IntExpression child = intExpr.intExpr().accept(this);
	ret = (child==intExpr.intExpr()) ?  intExpr : child.apply(intExpr.op());
	return cache(intExpr,ret);
}
 
Example 5
Source File: IntTest.java    From kodkod with MIT License 5 votes vote down vote up
private final void testUnOp(IntOperator op, IntExpression ei, int i, int result, int mask) {
	final IntExpression e = ei.apply(op);
	final Formula f = ei.eq(constant(i)).and(e.eq(constant(result)));
	final Solution s = solve(f);

	assertNotNull(s.instance());
	final Evaluator eval = new Evaluator(s.instance(), solver.options());
	assertEquals(result & mask, eval.evaluate(e) & mask);
	
}
 
Example 6
Source File: Simplifier.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public IntExpression visit(UnaryIntExpression expr) { 
	IntExpression ret = lookup(expr);
	if (ret!=null) return ret;
	
	final IntOperator op = expr.op();
	final IntExpression child = expr.intExpr().accept(this);
	
	ret = simplify(op, child);
	if (ret==null) {
		ret = child==expr.intExpr() ? expr : child.apply(op);
	}
	return cache(expr,ret);
}