kodkod.ast.IfIntExpression Java Examples

The following examples show how to use kodkod.ast.IfIntExpression. 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: PrettyPrinter.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
/** @effects appends the tokenization of the given node to this.tokens */
		public void visit(IfIntExpression node) {
			if (displayed(node)) return;
			final boolean oldTop = notTop();
			append("if");
			space();
			visitChild(node.condition(), parenthesize(node.condition()));
			infix("then");
//			indent++;
//			newline();
			visitChild(node.thenExpr(), parenthesize(node.thenExpr()));
			infix("else");
//			newline();
			visitChild(node.elseExpr(), parenthesize(node.elseExpr()));
//			indent--;
			top = oldTop;
		}
 
Example #2
Source File: PartialCannonicalizer.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public IntExpression visit(IfIntExpression expr) { 
	IntExpression ret = lookup(expr);
	if (ret!=null) return ret;
	
	final Formula cond = expr.condition().accept(this);
	final IntExpression thenExpr = expr.thenExpr().accept(this);
	final IntExpression elseExpr = expr.elseExpr().accept(this);
	
	ret = simplify(cond,thenExpr,elseExpr);
	
	if (ret==null) { 
		final int hash = hash(IfIntExpression.class, cond, thenExpr, elseExpr);
		for(Iterator<PartialCannonicalizer.Holder<IntExpression>> itr = intExprs.get(hash); itr.hasNext(); ) {
			final IntExpression next = itr.next().obj;
			if (next.getClass()==IfIntExpression.class) { 
				final IfIntExpression hit = (IfIntExpression) 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);
		intExprs.add(new PartialCannonicalizer.Holder<IntExpression>(ret, hash));
	}
	return cache(expr,ret);
}
 
Example #3
Source File: Simplifier.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public IntExpression visit(IfIntExpression expr) { 
	IntExpression ret = lookup(expr);
	if (ret!=null) return ret;
	
	final Formula cond = expr.condition().accept(this);
	final IntExpression thenExpr = expr.thenExpr().accept(this);
	final IntExpression 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);
}
 
Example #4
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
/** @ensures appends the tokenization of the given node to this.tokens */
public void visit(IfIntExpression node) {
	visitChild(node.condition(), parenthesize(node.condition()));
	infix("=>");
	indent++;
	newline();
	visitChild(node.thenExpr(), parenthesize(node.thenExpr()));
	infix("else");
	newline();
	visitChild(node.elseExpr(), parenthesize(node.elseExpr()));
	indent--;
}
 
Example #5
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
/** @return true if the given int expression needs to be parenthesized if a 
 * child of a binary int expression with the given operator */
private boolean parenthesize(IntOperator op, IntExpression child) { 
	return child instanceof SumExpression ||
		   child instanceof IfIntExpression || 
		   child instanceof NaryIntExpression ||
	       (child instanceof BinaryIntExpression && 
	        (!associative(op) || ((BinaryIntExpression)child).op()!=op));
}
 
Example #6
Source File: FOL2BoolTranslator.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Calls lookup(intExpr) and returns the cached value, if any.  
 * If a translation has not been cached, translates the expression,
 * calls cache(...) on it and returns it.
 * @return let t = lookup(intExpr) | some t => t, 
 * 			cache(intExpr, intExpr.condition.accept(this).choice(intExpr.then.accept(this), intExpr.else.accept(this)))
 */
public final Int visit(IfIntExpression intExpr) { 
	Int ret = lookup(intExpr);
	if (ret!=null) return ret;

	final BooleanValue condition = intExpr.condition().accept(this);
	final Int thenExpr = intExpr.thenExpr().accept(this);
	final Int elseExpr = intExpr.elseExpr().accept(this);
	ret = thenExpr.choice(condition, elseExpr);

	return cache(intExpr, ret);
}
 
Example #7
Source File: AbstractCollector.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(intExpr) 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(intExpr) | 
 *          x != null => x,  
 *          cache(intExpr, intExpr.condition.accept(this) + intExpr.thenExpr.accept(this) + intExpr.elseExpr.accept(this)) 
 */
public Set<T> visit(IfIntExpression intExpr) {
	Set<T> ret = lookup(intExpr);
	if (ret!=null) return ret;
	ret = newSet();
	ret.addAll(intExpr.condition().accept(this));
	ret.addAll(intExpr.thenExpr().accept(this));
	ret.addAll(intExpr.elseExpr().accept(this));
	return cache(intExpr, ret);
}
 
Example #8
Source File: AbstractVoidVisitor.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Visits the if-condition, the then-expression, and the else-expression  if
 * this.visited(intExpr) returns false.  Otherwise does nothing.
 * @ensures intExpr.condition.accept(this) && intExpr.thenExpr.accept(this) &&
 *          intExpr.elseExpr.accept(this)
 */
public void visit(IfIntExpression intExpr) {
	if (visited(intExpr)) return;
	intExpr.condition().accept(this);
	intExpr.thenExpr().accept(this);
	intExpr.elseExpr().accept(this);
}
 
Example #9
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 
 * children.  If nothing changes, the argument is cached and
 * returned, otherwise a replacement expression is cached and returned.
 * @return { i: IfIntExpression | i.condition = intExpr.condition.accept(this) &&
 *                             i.thenExpr = intExpr.thenExpr.accept(this) &&
 *                             i.elseExpr = intExpr.elseExpr.accept(this) }
 */
public IntExpression visit(IfIntExpression intExpr) {
	IntExpression ret = lookup(intExpr);
	if (ret!=null) return ret;

	final Formula condition = intExpr.condition().accept(this);
	final IntExpression thenExpr = intExpr.thenExpr().accept(this);
	final IntExpression elseExpr = intExpr.elseExpr().accept(this);
	ret = (condition==intExpr.condition() && thenExpr==intExpr.thenExpr() &&
		   elseExpr==intExpr.elseExpr()) ? 
	      intExpr : condition.thenElse(thenExpr, elseExpr);
	return cache(intExpr,ret);
}
 
Example #10
Source File: TranslateKodkodToJava.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visit(IfIntExpression x) {
    String newname = makename(x);
    if (newname == null)
        return;
    String a = make(x.condition());
    String b = make(x.thenExpr());
    String c = make(x.elseExpr());
    file.printf("IntExpression %s=%s.thenElse(%s,%s);%n", newname, a, b, c);
}
 
Example #11
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * @ensures appends the tokenization of the given node to this.tokens
 */
@Override
public void visit(IfIntExpression node) {
    visitChild(node.condition(), parenthesize(node.condition()));
    infix("=>");
    indent++;
    newline();
    visitChild(node.thenExpr(), parenthesize(node.thenExpr()));
    infix("else");
    newline();
    visitChild(node.elseExpr(), parenthesize(node.elseExpr()));
    indent--;
}
 
Example #12
Source File: FOL2BoolTranslator.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 translation
 * has not been cached, translates the expression, calls cache(...) on it and
 * returns it.
 *
 * @return let t = lookup(intExpr) | some t => t, cache(intExpr,
 *         intExpr.condition.accept(this).choice(intExpr.then.accept(this),
 *         intExpr.else.accept(this)))
 */
@Override
public final Int visit(IfIntExpression intExpr) {
    Int ret = lookup(intExpr);
    if (ret != null)
        return ret;

    final BooleanValue condition = intExpr.condition().accept(this);
    final Int thenExpr = intExpr.thenExpr().accept(this);
    final Int elseExpr = intExpr.elseExpr().accept(this);
    ret = thenExpr.choice(condition, elseExpr);
    return cache(intExpr, ret);
}
 
Example #13
Source File: PrettyPrinter.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/** @return true if the given int expression needs to be parenthesized if a 
 * child of a binary int expression with the given operator */
private boolean parenthesize(IntOperator op, IntExpression child) { 
	return child instanceof SumExpression ||
		   child instanceof IfIntExpression || 
		   child instanceof NaryIntExpression ||
	       (child instanceof BinaryIntExpression && 
	        (!associative(op) || ((BinaryIntExpression)child).op()!=op));
}
 
Example #14
Source File: AbstractCollector.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 no cached
 * value exists, visits each child, caches the union of the children's return
 * values and returns it.
 *
 * @return let x = lookup(intExpr) | x != null => x, cache(intExpr,
 *         intExpr.condition.accept(this) + intExpr.thenExpr.accept(this) +
 *         intExpr.elseExpr.accept(this))
 */
@Override
public Set<T> visit(IfIntExpression intExpr) {
    Set<T> ret = lookup(intExpr);
    if (ret != null)
        return ret;
    ret = newSet();
    ret.addAll(intExpr.condition().accept(this));
    ret.addAll(intExpr.thenExpr().accept(this));
    ret.addAll(intExpr.elseExpr().accept(this));
    return cache(intExpr, ret);
}
 
Example #15
Source File: AbstractVoidVisitor.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Visits the if-condition, the then-expression, and the else-expression if
 * this.visited(intExpr) returns false. Otherwise does nothing.
 *
 * @ensures intExpr.condition.accept(this) && intExpr.thenExpr.accept(this) &&
 *          intExpr.elseExpr.accept(this)
 */
@Override
public void visit(IfIntExpression intExpr) {
    if (visited(intExpr))
        return;
    intExpr.condition().accept(this);
    intExpr.thenExpr().accept(this);
    intExpr.elseExpr().accept(this);
}
 
Example #16
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 children. If nothing changes,
 * the argument is cached and returned, otherwise a replacement expression is
 * cached and returned.
 *
 * @return { i: IfIntExpression | i.condition =
 *         intExpr.condition.accept(delegate) && i.thenExpr =
 *         intExpr.thenExpr.accept(delegate) && i.elseExpr =
 *         intExpr.elseExpr.accept(delegate) }
 */
@Override
public IntExpression visit(IfIntExpression intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret != null)
        return ret;

    final Formula condition = intExpr.condition().accept(delegate);
    final IntExpression thenExpr = intExpr.thenExpr().accept(delegate);
    final IntExpression elseExpr = intExpr.elseExpr().accept(delegate);
    ret = (condition == intExpr.condition() && thenExpr == intExpr.thenExpr() && elseExpr == intExpr.elseExpr()) ? intExpr : condition.thenElse(thenExpr, elseExpr);
    return cache(intExpr, ret);
}
 
Example #17
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(IfIntExpression intExpr) {
    visit(intExpr, "ite", intExpr.condition(), intExpr.thenExpr(), intExpr.elseExpr());
}
 
Example #18
Source File: AnnotatedNode.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * Calls visited(ifexpr); ifexpr's children are not top-level formulas so they
 * are not visited.
 */
@Override
public void visit(IfIntExpression ifexpr) {
    visited(ifexpr);
}
 
Example #19
Source File: AnnotatedNode.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean visit(IfIntExpression e) {
    return checkVisitedThenAccumA(e, Boolean.FALSE, e.condition(), e.thenExpr(), e.elseExpr());
}
 
Example #20
Source File: HOLTranslator.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public IntExpression visit(IfIntExpression intExpr) {
    return intExpr;
}
 
Example #21
Source File: AspectReturnVisitor.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public I visit(IfIntExpression intExpr) {
    start(intExpr);
    return end(intExpr, visitor.visit(intExpr));
}
 
Example #22
Source File: PrettyPrinter.java    From kodkod with MIT License 4 votes vote down vote up
public void visit(IfIntExpression intExpr) {
	visit(intExpr, "ite", intExpr.condition(), intExpr.thenExpr(), intExpr.elseExpr());
}
 
Example #23
Source File: AnnotatedNode.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Calls visited(ifexpr); ifexpr's children are not top-level formulas
 * so they are not visited.
 */
public void visit(IfIntExpression ifexpr) {
	visited(ifexpr);
}
 
Example #24
Source File: VoidVisitor.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Visits the given if-int-expression.
 */
public void visit(IfIntExpression intExpr);
 
Example #25
Source File: AbstractDetector.java    From kodkod with MIT License 2 votes vote down vote up
/** 
 * Calls lookup(intExpr) 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(intExpr) | 
 *          x != null => x,  
 *          cache(intExpr, intExpr.condition.accept(this) || intExpr.thenExpr.accept(this) || intExpr.elseExpr.accept(this)) 
 */
public Boolean visit(IfIntExpression intExpr) {
	final Boolean ret = lookup(intExpr);
	return (ret!=null) ? ret :  cache(intExpr, intExpr.condition().accept(this) || intExpr.thenExpr().accept(this) || intExpr.elseExpr().accept(this));
}
 
Example #26
Source File: ReturnVisitor.java    From kodkod with MIT License 2 votes vote down vote up
/**
   * Visits the given if-int-expression and returns the result.
* @return the result of visiting <code>intExpr</code> 
   */
  public I visit(IfIntExpression intExpr);
 
Example #27
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * @return true if the given int expression needs to be parenthesized if a child
 *         of a binary int expression with the given operator
 */
private boolean parenthesize(IntOperator op, IntExpression child) {
    return child instanceof SumExpression || child instanceof IfIntExpression || child instanceof NaryIntExpression || (child instanceof BinaryIntExpression && (!associative(op) || ((BinaryIntExpression) child).op() != op));
}
 
Example #28
Source File: AbstractDetector.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Calls lookup(intExpr) 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(intExpr) | x != null => x, cache(intExpr,
 *         intExpr.condition.accept(this) || intExpr.thenExpr.accept(this) ||
 *         intExpr.elseExpr.accept(this))
 */
@Override
public Boolean visit(IfIntExpression intExpr) {
    final Boolean ret = lookup(intExpr);
    return (ret != null) ? ret : cache(intExpr, intExpr.condition().accept(this) || intExpr.thenExpr().accept(this) || intExpr.elseExpr().accept(this));
}
 
Example #29
Source File: ReturnVisitor.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Visits the given if-int-expression and returns the result.
 *
 * @return the result of visiting <code>intExpr</code>
 */
public I visit(IfIntExpression intExpr);
 
Example #30
Source File: VoidVisitor.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Visits the given if-int-expression.
 */
public void visit(IfIntExpression intExpr);