kodkod.ast.UnaryIntExpression Java Examples

The following examples show how to use kodkod.ast.UnaryIntExpression. 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: TranslateKodkodToJava.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visit(UnaryIntExpression x) {
    String newname = makename(x);
    if (newname == null)
        return;
    String sub = make(x.intExpr());
    switch (x.op()) {
        case MINUS :
            file.printf("IntExpression %s=%s.negate();%n", newname, sub);
            break;
        case NOT :
            file.printf("IntExpression %s=%s.not();%n", newname, sub);
            break;
        case ABS :
            file.printf("IntExpression %s=%s.abs();%n", newname, sub);
            break;
        case SGN :
            file.printf("IntExpression %s=%s.signum();%n", newname, sub);
            break;
        default :
            throw new RuntimeException("Unknown kodkod operator \"" + x.op() + "\" encountered");
    }
}
 
Example #2
Source File: PartialCannonicalizer.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public IntExpression visit(UnaryIntExpression expr) { 
	IntExpression ret = lookup(expr);
	if (ret!=null) return ret;
	
	final IntOperator op = expr.op();
	final IntExpression child = expr.intExpr().accept(this);
	
	ret = simplify(op, child);
	if (ret==null) {
		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()==UnaryIntExpression.class) { 
				if (((UnaryIntExpression)next).intExpr()==child)
					return cache(expr, next);
			}
		}
		ret = child==expr.intExpr() ? expr : child.apply(op);
		intExprs.add(new PartialCannonicalizer.Holder<IntExpression>(ret, hash));
	}
	return cache(expr,ret);
}
 
Example #3
Source File: FOL2BoolTranslator.java    From org.alloytools.alloy with Apache License 2.0 6 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.op(intExpr.expression.accept(this)))
 */
@Override
public final Int visit(UnaryIntExpression intExpr) {
    Int ret = lookup(intExpr);
    if (ret != null)
        return ret;
    final Int child = intExpr.intExpr().accept(this);
    switch (intExpr.op()) {
        case NEG :
            ret = child.negate();
            break;
        case NOT :
            ret = child.not();
            break;
        case ABS :
            ret = child.abs();
            break;
        case SGN :
            ret = child.sgn();
            break;
        default :
            throw new IllegalArgumentException("Unknown operator: " + intExpr.op());
    }
    return cache(intExpr, ret);
}
 
Example #4
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * @ensures appends the given op and child to this.tokens; the child is
 *          parenthesized if it's not an instance of unary int expression or int
 *          constant.
 **/
@Override
public void visit(UnaryIntExpression node) {
    final IntExpression child = node.intExpr();
    final IntOperator op = node.op();
    final boolean parens = (op == IntOperator.ABS) || (op == IntOperator.SGN) || parenthesize(child);
    append(node.op());
    visitChild(child, parens);
}
 
Example #5
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.op(intExpr.expression.accept(this)))
 */
public final Int visit(UnaryIntExpression intExpr) {
	Int ret = lookup(intExpr);
	if (ret!=null) return ret;
	final Int child = intExpr.intExpr().accept(this);
	switch(intExpr.op()) {
	case NEG 	: ret = child.negate(); break;
	case NOT 	: ret = child.not(); break;
	case ABS 	: ret = child.abs(); break;
	case SGN 	: ret = child.sgn(); break;
	default : 
		throw new IllegalArgumentException("Unknown operator: " + intExpr.op());
	}
	return cache(intExpr, ret);
}
 
Example #6
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 the child, caches its return value and returns it. 
 * @return let x = lookup(intExpr) | 
 *          x != null => x,  
 *          cache(intExpr, intExpr.expression.accept(this)) 
 */
public Set<T> visit(UnaryIntExpression intExpr) {
	Set<T> ret = lookup(intExpr);
	if (ret!=null) return ret;
	ret = newSet();
	ret.addAll(intExpr.intExpr().accept(this));
	return cache(intExpr,ret);
}
 
Example #7
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
/** @ensures appends the given op and child to this.tokens; the child is 
 * parenthesized if it's not an instance of unary int expression or int constant. **/
public void visit(UnaryIntExpression node)  { 
	final IntExpression child = node.intExpr();
	final IntOperator op = node.op();
	final boolean parens = 
		(op==IntOperator.ABS) || (op==IntOperator.SGN) || 
		parenthesize(child);
	append(node.op());
	visitChild(child, parens);
}
 
Example #8
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 { u: UnaryIntExpression | u.expression = intExpr.expression.accept(this) && u.op = intExpr.op }
 */
public IntExpression visit(UnaryIntExpression intExpr) {
	IntExpression ret = lookup(intExpr);
	if (ret!=null) return ret;

	final IntExpression child = intExpr.intExpr().accept(this);
	ret = (child==intExpr.intExpr()) ?  intExpr : child.apply(intExpr.op());
	return cache(intExpr,ret);
}
 
Example #9
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 the child, caches its return value and returns it.
 *
 * @return let x = lookup(intExpr) | x != null => x, cache(intExpr,
 *         intExpr.expression.accept(this))
 */
@Override
public Set<T> visit(UnaryIntExpression intExpr) {
    Set<T> ret = lookup(intExpr);
    if (ret != null)
        return ret;
    ret = newSet();
    ret.addAll(intExpr.intExpr().accept(this));
    return cache(intExpr, ret);
}
 
Example #10
Source File: PrettyPrinter.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/** @effects appends the given op and child to this.tokens; the child is 
 * parenthesized if it's not an instance of unary int expression or int constant. **/
public void visit(UnaryIntExpression node)  { 
	if (displayed(node)) return;
	final boolean oldTop = notTop();
	final IntExpression child = node.intExpr();
	final IntOperator op = node.op();
	final boolean parens = 
		(op==IntOperator.ABS) || (op==IntOperator.SGN) || 
		parenthesize(child);
	append(node.op());
	visitChild(child, parens);
	top = oldTop;
}
 
Example #11
Source File: AbstractVoidVisitor.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Visits the subexpression if this.visited(intExpr) returns false. Otherwise
 * does nothing.
 *
 * @ensures unaryExpr.expression.accept(this)
 */
@Override
public void visit(UnaryIntExpression intExpr) {
    if (visited(intExpr))
        return;
    intExpr.intExpr().accept(this);
}
 
Example #12
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 { u: UnaryIntExpression | u.expression =
 *         intExpr.expression.accept(delegate) && u.op = intExpr.op }
 */
@Override
public IntExpression visit(UnaryIntExpression intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret != null)
        return ret;

    final IntExpression child = intExpr.intExpr().accept(delegate);
    ret = (child == intExpr.intExpr()) ? intExpr : child.apply(intExpr.op());
    return cache(intExpr, ret);
}
 
Example #13
Source File: Simplifier.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public IntExpression visit(UnaryIntExpression expr) { 
	IntExpression ret = lookup(expr);
	if (ret!=null) return ret;
	
	final IntOperator op = expr.op();
	final IntExpression child = expr.intExpr().accept(this);
	
	ret = simplify(op, child);
	if (ret==null) {
		ret = child==expr.intExpr() ? expr : child.apply(op);
	}
	return cache(expr,ret);
}
 
Example #14
Source File: HOLTranslator.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public IntExpression visit(UnaryIntExpression intExpr) {
    return intExpr;
}
 
Example #15
Source File: PrettyPrinter.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
/** @return true if the given expression should be parenthesized when a 
 * child of a compound parent */
private boolean parenthesize(IntExpression child) { 
	return !(child instanceof UnaryIntExpression || 
			 child instanceof IntConstant || 
			 child instanceof ExprToIntCast); 
}
 
Example #16
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(UnaryIntExpression intExpr) {
    visit(intExpr, intExpr.op(), intExpr.intExpr());
}
 
Example #17
Source File: AnnotatedNode.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean visit(UnaryIntExpression e) {
    return checkVisitedThenAccumA(e, Boolean.FALSE, e.intExpr());
}
 
Example #18
Source File: AspectReturnVisitor.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public I visit(UnaryIntExpression intExpr) {
    start(intExpr);
    return end(intExpr, visitor.visit(intExpr));
}
 
Example #19
Source File: PrettyPrinter.java    From kodkod with MIT License 4 votes vote down vote up
/** @return true if the given expression should be parenthesized when a 
 * child of a compound parent */
private boolean parenthesize(IntExpression child) { 
	return !(child instanceof UnaryIntExpression || 
			 child instanceof IntConstant || 
			 child instanceof ExprToIntCast); 
}
 
Example #20
Source File: VoidVisitor.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Visits the given unary integer expression.
 */
public void visit(UnaryIntExpression intExpr);
 
Example #21
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 the child, caches its return value and returns it. 
 * @return let x = lookup(intExpr) | 
 *          x != null => x,  
 *          cache(intExpr, intExpr.expression.accept(this)) 
 */
public Boolean visit(UnaryIntExpression intExpr) {
	final Boolean ret = lookup(intExpr);
	return (ret!=null) ? ret : cache(intExpr, intExpr.intExpr().accept(this));
}
 
Example #22
Source File: ReturnVisitor.java    From kodkod with MIT License 2 votes vote down vote up
/**
   * Visits the given unary integer expression and returns the result.
* @return the result of visiting <code>intExpr</code> 
   */
  public I visit(UnaryIntExpression intExpr);
 
Example #23
Source File: AbstractVoidVisitor.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Visits the subexpression  if
 * this.visited(intExpr) returns false.  Otherwise does nothing.
 * @ensures unaryExpr.expression.accept(this)
 */
public void visit(UnaryIntExpression intExpr) {
	if (visited(intExpr)) return;
	intExpr.intExpr().accept(this);
}
 
Example #24
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * @return true if the given expression should be parenthesized when a child of
 *         a compound parent
 */
private boolean parenthesize(IntExpression child) {
    return !(child instanceof UnaryIntExpression || child instanceof IntConstant || child instanceof ExprToIntCast);
}
 
Example #25
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 the child, caches its return value and returns it.
 *
 * @return let x = lookup(intExpr) | x != null => x, cache(intExpr,
 *         intExpr.expression.accept(this))
 */
@Override
public Boolean visit(UnaryIntExpression intExpr) {
    final Boolean ret = lookup(intExpr);
    return (ret != null) ? ret : cache(intExpr, intExpr.intExpr().accept(this));
}
 
Example #26
Source File: ReturnVisitor.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Visits the given unary integer expression and returns the result.
 *
 * @return the result of visiting <code>intExpr</code>
 */
public I visit(UnaryIntExpression intExpr);
 
Example #27
Source File: VoidVisitor.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Visits the given unary integer expression.
 */
public void visit(UnaryIntExpression intExpr);
 
Example #28
Source File: PrettyPrinter.java    From kodkod with MIT License votes vote down vote up
public void visit(UnaryIntExpression intExpr) { visit(intExpr, intExpr.op(), intExpr.intExpr());}