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

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

    final Expression child = unaryExpr.expression().accept(delegate);
    ret = (child == unaryExpr.expression()) ? unaryExpr : child.apply(unaryExpr.op());
    return cache(unaryExpr, ret);
}
 
Example 4
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 { i: ExprToIntCast | i.expression =
 *         intExpr.expression.accept(delegate) && i.op = intExpr.op}
 */
@Override
public IntExpression visit(ExprToIntCast intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret != null)
        return ret;

    final Expression expr = intExpr.expression().accept(delegate);
    ret = expr == intExpr.expression() ? intExpr : expr.apply(intExpr.op());
    return cache(intExpr, ret);
}
 
Example 5
Source File: AbstractReplacer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls lookup(multFormula) and returns the cached value, if any. If a
 * replacement has not been cached, visits the formula's children. If nothing
 * changes, the argument is cached and returned, otherwise a replacement formula
 * is cached and returned.
 *
 * @return { m: MultiplicityFormula | m.multiplicity = multFormula.multiplicity
 *         && m.expression = multFormula.expression.accept(delegate) }
 */
@Override
public Formula visit(MultiplicityFormula multFormula) {
    Formula ret = lookup(multFormula);
    if (ret != null)
        return ret;

    final Expression expression = multFormula.expression().accept(delegate);
    ret = (expression == multFormula.expression()) ? multFormula : expression.apply(multFormula.multiplicity());
    return cache(multFormula, ret);
}
 
Example 6
Source File: AbstractReplacer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(unaryExpr) 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: UnaryExpression | u.left = unaryExpr.expression.accept(this) && u.op = unaryExpr.op }
 */
public Expression visit(UnaryExpression unaryExpr) {
	Expression ret = lookup(unaryExpr);
	if (ret!=null) return ret;

	final Expression child = unaryExpr.expression().accept(this);
	ret = (child==unaryExpr.expression()) ? 
		  unaryExpr : child.apply(unaryExpr.op());
	return cache(unaryExpr,ret);
}
 
Example 7
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 { i: ExprToIntCast | i.expression = intExpr.expression.accept(this) && i.op = intExpr.op}
*/
  public IntExpression visit(ExprToIntCast intExpr) {
IntExpression ret = lookup(intExpr);
if (ret!=null) return ret;
	
final Expression expr = intExpr.expression().accept(this);
ret = expr==intExpr.expression() ? intExpr : expr.apply(intExpr.op());
return cache(intExpr, ret);
  }
 
Example 8
Source File: AbstractReplacer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(multFormula) and returns the cached value, if any.  
 * If a replacement has not been cached, visits the formula's 
 * children.  If nothing changes, the argument is cached and
 * returned, otherwise a replacement formula is cached and returned.
 * @return { m: MultiplicityFormula | m.multiplicity = multFormula.multiplicity &&
 *                                    m.expression = multFormula.expression.accept(this) }
 */
public Formula visit(MultiplicityFormula multFormula) {
	Formula ret = lookup(multFormula);
	if (ret!=null) return ret;
	
	final Expression expression = multFormula.expression().accept(this);
	ret = (expression==multFormula.expression()) ? 
		  multFormula : expression.apply(multFormula.multiplicity());
	return cache(multFormula,ret);
}
 
Example 9
Source File: Simplifier.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Expression visit(UnaryExpression expr) { 
	Expression ret = lookup(expr);
	if (ret!=null) return ret;
	
	final ExprOperator op = expr.op();
	final Expression child = expr.expression().accept(this);
	
	if (isEmpty(child)) return cache(expr, child);
	ret = child==expr.expression() ? expr : child.apply(op);
	return cache(expr,ret);
}