Java Code Examples for kodkod.ast.BinaryExpression#left()

The following examples show how to use kodkod.ast.BinaryExpression#left() . 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(BinaryExpression node) {
	if (displayed(node)) return;
	final boolean oldTop = notTop();
	final ExprOperator op = node.op();
	final Expression left = node.left(), right = node.right();
	if (op==ExprOperator.JOIN && left.arity()==1 && right.arity()==2 && right instanceof Relation) { 
		append(right);
		append("[");
		visitChild(left, false);
		append("]");
	} else {
		visitChild(left, parenthesize(op, left));
		infix(op);
		visitChild(right, parenthesize(op, right));
	}
	top = oldTop;
}
 
Example 2
Source File: AbstractReplacer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls lookup(binExpr) 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 { b: BinaryExpression | b.left = binExpr.left.accept(delegate) &&
 *         b.right = binExpr.right.accept(delegate) && b.op = binExpr.op }
 */
@Override
public Expression visit(BinaryExpression binExpr) {
    Expression ret = lookup(binExpr);
    if (ret != null)
        return ret;

    final Expression left = binExpr.left().accept(delegate);
    final Expression right = binExpr.right().accept(delegate);
    ret = (left == binExpr.left() && right == binExpr.right()) ? binExpr : left.compose(binExpr.op(), right);
    return cache(binExpr, ret);
}
 
Example 3
Source File: AbstractReplacer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(binExpr) 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 { b: BinaryExpression | b.left = binExpr.left.accept(this) &&
 *                                 b.right = binExpr.right.accept(this) && b.op = binExpr.op }
 */
public Expression visit(BinaryExpression binExpr) {
	Expression ret = lookup(binExpr);
	if (ret!=null) return ret;
	
	final Expression left  = binExpr.left().accept(this);
	final Expression right = binExpr.right().accept(this);
	ret = (left==binExpr.left() && right==binExpr.right()) ?
		  binExpr : left.compose(binExpr.op(), right);
	return cache(binExpr,ret);
}
 
Example 4
Source File: PartialCannonicalizer.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Expression visit(BinaryExpression expr) { 
	Expression ret = lookup(expr);
	if (ret!=null) return ret;
	final ExprOperator op = expr.op();
	final Expression left = expr.left().accept(this);
	final Expression right = expr.right().accept(this);
	
	ret = simplify(op, left, right);
	
	if (ret==null) {
	
		final int hash = hash(op, left, right);
		for(Iterator<PartialCannonicalizer.Holder<Expression>> itr = exprs.get(hash); itr.hasNext(); ) {
			final Expression next = itr.next().obj;
			if (next instanceof BinaryExpression) { 
				final BinaryExpression hit = (BinaryExpression) next;
				if (hit.op()==op && hit.left()==left && hit.right()==right) { 
					return cache(expr, hit);
				}
			}
		}

		ret = left==expr.left()&&right==expr.right() ? expr : left.compose(op, right);
		exprs.add(new PartialCannonicalizer.Holder<Expression>(ret, hash));
	}
	
	return cache(expr,ret);
}
 
Example 5
Source File: Simplifier.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Expression visit(BinaryExpression expr) { 
	Expression ret = lookup(expr);
	if (ret!=null) return ret;
	final ExprOperator op = expr.op();
	final Expression left = expr.left().accept(this);
	final Expression right = expr.right().accept(this);
	
	ret = simplify(op, left, right);
	
	if (ret==null) {
		ret = left==expr.left()&&right==expr.right() ? expr : left.compose(op, right);
	}
	
	return cache(expr,ret);
}