Java Code Examples for kodkod.ast.IfExpression#elseExpr()

The following examples show how to use kodkod.ast.IfExpression#elseExpr() . 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 Expression visit(IfExpression expr) { 
	Expression ret = lookup(expr);
	if (ret!=null) return ret;
	
	final Formula cond = expr.condition().accept(this);
	final Expression thenExpr = expr.thenExpr().accept(this);
	final Expression elseExpr = expr.elseExpr().accept(this);
	
	ret = simplify(cond,thenExpr,elseExpr);
	
	if (ret==null) { 
		final int hash = hash(IfExpression.class, cond, thenExpr, elseExpr);
		for(Iterator<PartialCannonicalizer.Holder<Expression>> itr = exprs.get(hash); itr.hasNext(); ) {
			final Expression next = itr.next().obj;
			if (next.getClass()==IfExpression.class) { 
				final IfExpression hit = (IfExpression) next;
				if (hit.condition()==cond && hit.thenExpr()==thenExpr && hit.elseExpr()==elseExpr) { 
					return cache(expr, hit);
				}
			}
		}
		ret = cond==expr.condition()&&thenExpr==expr.thenExpr()&&elseExpr==expr.elseExpr() ? expr : cond.thenElse(thenExpr, elseExpr);
		exprs.add(new PartialCannonicalizer.Holder<Expression>(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(ifExpr) and returns the cached value, if any. If a replacement
 * has not been cached, visits the expression's children. If nothing changes,
 * the argument is cached and returned, otherwise a replacement expression is
 * cached and returned.
 *
 * @return { i: IfExpression | i.condition = ifExpr.condition.accept(delegate)
 *         && i.thenExpr = ifExpr.thenExpr.accept(delegate) && i.elseExpr =
 *         ifExpr.elseExpr.accept(delegate) }
 */
@Override
public Expression visit(IfExpression ifExpr) {
    Expression ret = lookup(ifExpr);
    if (ret != null)
        return ret;

    final Formula condition = ifExpr.condition().accept(delegate);
    final Expression thenExpr = ifExpr.thenExpr().accept(delegate);
    final Expression elseExpr = ifExpr.elseExpr().accept(delegate);
    ret = (condition == ifExpr.condition() && thenExpr == ifExpr.thenExpr() && elseExpr == ifExpr.elseExpr()) ? ifExpr : condition.thenElse(thenExpr, elseExpr);
    return cache(ifExpr, ret);
}
 
Example 3
Source File: AbstractReplacer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(ifExpr) and returns the cached value, if any.  
 * If a replacement has not been cached, visits the expression's 
 * children.  If nothing changes, the argument is cached and
 * returned, otherwise a replacement expression is cached and returned.
 * @return { i: IfExpression | i.condition = ifExpr.condition.accept(this) &&
 *                             i.thenExpr = ifExpr.thenExpr.accept(this) &&
 *                             i.elseExpr = ifExpr.elseExpr.accept(this) }
 */
public Expression visit(IfExpression ifExpr) {
	Expression ret = lookup(ifExpr);
	if (ret!=null) return ret;

	final Formula condition = ifExpr.condition().accept(this);
	final Expression thenExpr = ifExpr.thenExpr().accept(this);
	final Expression elseExpr = ifExpr.elseExpr().accept(this);
	ret = (condition==ifExpr.condition() && thenExpr==ifExpr.thenExpr() &&
		   elseExpr==ifExpr.elseExpr()) ? 
	      ifExpr : condition.thenElse(thenExpr, elseExpr);
	return cache(ifExpr,ret);
}
 
Example 4
Source File: Simplifier.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Expression visit(IfExpression expr) { 
	Expression ret = lookup(expr);
	if (ret!=null) return ret;
	
	final Formula cond = expr.condition().accept(this);
	final Expression thenExpr = expr.thenExpr().accept(this);
	final Expression elseExpr = expr.elseExpr().accept(this);
	
	ret = simplify(cond,thenExpr,elseExpr);
	
	if (ret==null) { 
		ret = cond==expr.condition()&&thenExpr==expr.thenExpr()&&elseExpr==expr.elseExpr() ? expr : cond.thenElse(thenExpr, elseExpr);
	}
	return cache(expr,ret);
}