kodkod.ast.operator.ExprCastOperator Java Examples

The following examples show how to use kodkod.ast.operator.ExprCastOperator. 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(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 #2
Source File: ExpressionUtil.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
public static IntExpression intValue(Expression e) {
	return value(e).apply(ExprCastOperator.SUM);
}
 
Example #3
Source File: ExprToIntCast.java    From org.alloytools.alloy with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a new cardinality expression.
 *
 * @ensures this.expression' = expression && this.op' = op
 * @throws NullPointerException expression = null || op = null
 * @throws IllegalArgumentException op = SUM && child.arity != 1
 */
ExprToIntCast(Expression child, ExprCastOperator op) {
    if (child.arity() > 1 && op == ExprCastOperator.SUM)
        throw new IllegalArgumentException("cannot apply " + op + " to " + child);
    this.expression = child;
    this.op = op;
}
 
Example #4
Source File: ExprToIntCast.java    From kodkod with MIT License 3 votes vote down vote up
/**  
 * Constructs a new cardinality expression.
 * 
 * @ensures this.expression' = expression && this.op' = op
 * @throws NullPointerException  expression = null || op = null
 * @throws IllegalArgumentException  op = SUM && child.arity != 1
 */
ExprToIntCast(Expression child, ExprCastOperator op) {
	if (child.arity()>1 && op==ExprCastOperator.SUM) 
		throw new IllegalArgumentException("cannot apply " + op + " to " + child);
	this.expression = child;
	this.op = op;
}
 
Example #5
Source File: Expression.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the cast of this expression to an integer expression, that represents
 * either the cardinality of this expression (if op is CARDINALITY) or the sum
 * of the integer atoms it contains (if op is SUM).
 *
 * @return {e: IntExpression | e.op = op && e.expression = this}
 */
public final IntExpression apply(ExprCastOperator op) {
    return new ExprToIntCast(this, op);
}
 
Example #6
Source File: ExprToIntCast.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns this.op.
 *
 * @return this.op
 */
public ExprCastOperator op() {
    return op;
}
 
Example #7
Source File: Expression.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns the cast of this expression to an integer expression,
 * that represents either the cardinality of this expression (if op is CARDINALITY)
 * or the sum of the integer atoms it contains (if op is SUM).
 * @return {e: IntExpression | e.op = op && e.expression = this} 
 */
public final IntExpression apply(ExprCastOperator op) { 
	return new ExprToIntCast(this, op);
}
 
Example #8
Source File: ExprToIntCast.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns this.op.
 * @return this.op
 */
public ExprCastOperator op() { return op; }