kodkod.ast.IntToExprCast Java Examples
The following examples show how to use
kodkod.ast.IntToExprCast.
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 |
public Expression visit(IntToExprCast expr) { Expression ret = lookup(expr); if (ret!=null) return ret; final IntCastOperator op = expr.op(); final IntExpression child = expr.intExpr().accept(this); 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()==IntToExprCast.class) { if (((IntToExprCast)next).intExpr()==child) return cache(expr, next); } } ret = child==expr.intExpr() ? expr : child.cast(op); exprs.add(new PartialCannonicalizer.Holder<Expression>(ret, hash)); return cache(expr,ret); }
Example #2
Source File: TranslateAlloyToKodkod.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
private IntExpression toInt(Expr x, Object y) throws Err, ErrorFatal { // simplify: if y is int[Int[sth]] then return sth if (y instanceof ExprToIntCast) { ExprToIntCast y2 = (ExprToIntCast) y; if (y2.expression() instanceof IntToExprCast) return ((IntToExprCast) y2.expression()).intExpr(); } // simplify: if y is Int[sth], then return sth if (y instanceof IntToExprCast) return ((IntToExprCast) y).intExpr(); if (y instanceof IntExpression) return (IntExpression) y; // [AM]: maybe this conversion should be removed if (y instanceof Expression) return ((Expression) y).sum(); throw new ErrorFatal(x.span(), "This should have been an integer expression.\nInstead it is " + y); }
Example #3
Source File: TranslateKodkodToJava.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void visit(IntToExprCast x) { String newname = makename(x); if (newname == null) return; String sub = make(x.intExpr()); switch (x.op()) { case INTCAST : file.printf("Expression %s=%s.toExpression();%n", newname, sub); break; case BITSETCAST : file.printf("Expression %s=%s.toBitset();%n", newname, sub); break; default : throw new RuntimeException("Unknown kodkod operator \"" + x.op() + "\" encountered"); } }
Example #4
Source File: PrettyPrinter.java From quetzal with Eclipse Public License 2.0 | 5 votes |
/** @effects this.tokens' = concat[ this.tokens, "Int","[", * tokenize[node.intExpr], "]" ] **/ public void visit(IntToExprCast node) { if (displayed(node)) return; final boolean oldTop = notTop(); append(node.op()==IntCastOperator.INTCAST ? "Int" : "Bits"); append("["); node.intExpr().accept(this); append("]"); top = oldTop; }
Example #5
Source File: PrettyPrinter.java From kodkod with MIT License | 5 votes |
/** @ensures this.tokens' = concat[ this.tokens, "Int","[", * tokenize[node.intExpr], "]" ] **/ public void visit(IntToExprCast node) { append("Int"); append("["); node.intExpr().accept(this); append("]"); }
Example #6
Source File: FOL2BoolTranslator.java From kodkod with MIT License | 5 votes |
/** * Calls lookup(castExpr) 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(castExpr) | some t => t, * cache(castExpr, translate(castExpr)) */ public BooleanMatrix visit(IntToExprCast castExpr) { BooleanMatrix ret = lookup(castExpr); if (ret!=null) return ret; final Int child = castExpr.intExpr().accept(this); final BooleanFactory factory = interpreter.factory(); final IntSet ints = interpreter.ints(); ret = factory.matrix(Dimensions.square(interpreter.universe().size(), 1)); switch(castExpr.op()) { case INTCAST : for(IntIterator iter = ints.iterator(); iter.hasNext(); ) { int i = iter.next(); int atomIndex = interpreter.interpret(i); ret.set(atomIndex, factory.or(ret.get(atomIndex), child.eq(factory.integer(i)))); } break; case BITSETCAST : final List<BooleanValue> twosComplement = child.twosComplementBits(); final int msb = twosComplement.size()-1; // handle all bits but the sign bit for(int i = 0; i < msb; i++) { int pow2 = 1<<i; if (ints.contains(pow2)) { ret.set(interpreter.interpret(pow2), twosComplement.get(i)); } } // handle the sign bit if (ints.contains(-1<<msb)) { ret.set(interpreter.interpret(-1<<msb), twosComplement.get(msb)); } break; default : throw new IllegalArgumentException("Unknown cast operator: " + castExpr.op()); } return cache(castExpr, ret); }
Example #7
Source File: AbstractCollector.java From kodkod with MIT License | 5 votes |
/** * Calls lookup(castExpr) 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(castExpr) | * x != null => x, * cache(intExpr, castExpr.intExpr.accept(this)) */ public Set<T> visit(IntToExprCast castExpr) { Set<T> ret = lookup(castExpr); if (ret!=null) return ret; ret = newSet(); ret.addAll(castExpr.intExpr().accept(this)); return cache(castExpr,ret); }
Example #8
Source File: AbstractReplacer.java From kodkod with MIT License | 5 votes |
/** * Calls lookup(castExpr) 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 { e: Expression | e = castExpr.intExpr.accept(this).toExpression() } */ public Expression visit(IntToExprCast castExpr) { Expression ret = lookup(castExpr); if (ret!=null) return ret; final IntExpression intExpr = castExpr.intExpr().accept(this); ret = (intExpr==castExpr.intExpr()) ? castExpr : intExpr.cast(castExpr.op()); return cache(castExpr, ret); }
Example #9
Source File: TranslateAlloyToKodkod.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Performs int[x]; contains an efficiency shortcut that simplifies int[Int[x]] * to x. */ private IntExpression sum(Expression x) { if (x instanceof IntToExprCast) return ((IntToExprCast) x).intExpr(); else return x.sum(); }
Example #10
Source File: PrettyPrinter.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * @ensures this.tokens' = concat[ this.tokens, "Int","[", * tokenize[node.intExpr], "]" ] **/ @Override public void visit(IntToExprCast node) { append("Int"); append("["); node.intExpr().accept(this); append("]"); }
Example #11
Source File: AbstractReplacer.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Calls lookup(castExpr) 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 { e: Expression | e = * castExpr.intExpr.accept(delegate).toExpression() } */ @Override public Expression visit(IntToExprCast castExpr) { Expression ret = lookup(castExpr); if (ret != null) return ret; final IntExpression intExpr = castExpr.intExpr().accept(delegate); ret = (intExpr == castExpr.intExpr()) ? castExpr : intExpr.cast(castExpr.op()); return cache(castExpr, ret); }
Example #12
Source File: AbstractVoidVisitor.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Visits castExpr.intExpr if this.visited(castExpr) returns false. Otherwise * does nothing. * * @ensures castExpr.expression.accept(this) */ @Override public void visit(IntToExprCast castExpr) { if (visited(castExpr)) return; castExpr.intExpr().accept(this); }
Example #13
Source File: AbstractCollector.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Calls lookup(castExpr) 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(castExpr) | x != null => x, cache(intExpr, * castExpr.intExpr.accept(this)) */ @Override public Set<T> visit(IntToExprCast castExpr) { Set<T> ret = lookup(castExpr); if (ret != null) return ret; ret = newSet(); ret.addAll(castExpr.intExpr().accept(this)); return cache(castExpr, ret); }
Example #14
Source File: PrettyPrinter.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public void visit(IntToExprCast castExpr) { visit(castExpr, castExpr.op(), castExpr.intExpr()); }
Example #15
Source File: AspectReturnVisitor.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public E visit(IntToExprCast castExpr) { start(castExpr); return end(castExpr, visitor.visit(castExpr)); }
Example #16
Source File: FOL2BoolTranslator.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
/** * Calls lookup(castExpr) 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(castExpr) | some t => t, cache(castExpr, * translate(castExpr)) */ @Override public BooleanMatrix visit(IntToExprCast castExpr) { BooleanMatrix ret = lookup(castExpr); if (ret != null) return ret; final Int child = castExpr.intExpr().accept(this); final BooleanFactory factory = interpreter.factory(); final IntSet ints = interpreter.ints(); ret = factory.matrix(Dimensions.square(interpreter.universe().size(), 1)); switch (castExpr.op()) { case INTCAST : for (IntIterator iter = ints.iterator(); iter.hasNext();) { int i = iter.next(); int atomIndex = interpreter.interpret(i); ret.set(atomIndex, factory.or(ret.get(atomIndex), child.eq(factory.integer(i)))); } ret.setDefCond(child.defCond()); break; case BITSETCAST : final List<BooleanValue> twosComplement = child.twosComplementBits(); final int msb = twosComplement.size() - 1; // handle all bits but the sign bit for (int i = 0; i < msb; i++) { int pow2 = 1 << i; if (ints.contains(pow2)) { ret.set(interpreter.interpret(pow2), twosComplement.get(i)); } } // handle the sign bit if (ints.contains(-1 << msb)) { ret.set(interpreter.interpret(-1 << msb), twosComplement.get(msb)); } break; default : throw new IllegalArgumentException("Unknown cast operator: " + castExpr.op()); } return cache(castExpr, ret); }
Example #17
Source File: HOLTranslator.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public Expression visit(IntToExprCast castExpr) { return castExpr; }
Example #18
Source File: AnnotatedNode.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public Boolean visit(IntToExprCast castExpr) { return checkVisitedThenAccumA(castExpr, Boolean.FALSE, castExpr.intExpr()); }
Example #19
Source File: VoidVisitor.java From kodkod with MIT License | 2 votes |
/** * Visits the given integer cast expression. */ public void visit(IntToExprCast castExpr);
Example #20
Source File: AbstractDetector.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * Calls lookup(castExpr) 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(castExpr) | x != null => x, cache(intExpr, * castExpr.intExpr.accept(this)) */ @Override public Boolean visit(IntToExprCast castExpr) { final Boolean ret = lookup(castExpr); return (ret != null) ? ret : cache(castExpr, castExpr.intExpr().accept(this)); }
Example #21
Source File: AbstractVoidVisitor.java From kodkod with MIT License | 2 votes |
/** * Visits castExpr.intExpr if * this.visited(castExpr) returns false. Otherwise does nothing. * @ensures castExpr.expression.accept(this) */ public void visit(IntToExprCast castExpr) { if (visited(castExpr)) return; castExpr.intExpr().accept(this); }
Example #22
Source File: ReturnVisitor.java From kodkod with MIT License | 2 votes |
/** * Visits the given cast expression expression and returns the result. * @return the result of visiting <code>castExpr</code> **/ public E visit(IntToExprCast castExpr);
Example #23
Source File: ReturnVisitor.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * Visits the given cast expression expression and returns the result. * * @return the result of visiting <code>castExpr</code> **/ public E visit(IntToExprCast castExpr);
Example #24
Source File: AbstractDetector.java From kodkod with MIT License | 2 votes |
/** * Calls lookup(castExpr) 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(castExpr) | * x != null => x, * cache(intExpr, castExpr.intExpr.accept(this)) */ public Boolean visit(IntToExprCast castExpr) { final Boolean ret = lookup(castExpr); return (ret!=null) ? ret : cache(castExpr, castExpr.intExpr().accept(this)); }
Example #25
Source File: VoidVisitor.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * Visits the given integer cast expression. */ public void visit(IntToExprCast castExpr);
Example #26
Source File: PrettyPrinter.java From kodkod with MIT License | votes |
public void visit(IntToExprCast castExpr) { visit(castExpr, castExpr.op(), castExpr.intExpr()); }