kodkod.ast.ExprToIntCast Java Examples
The following examples show how to use
kodkod.ast.ExprToIntCast.
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: 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 #2
Source File: PrettyPrinter.java From quetzal with Eclipse Public License 2.0 | 6 votes |
/** @effects this.tokens' = concat[ this.tokens, "int","[", * tokenize[node.expression], "]" ] **/ public void visit(ExprToIntCast node) { if (displayed(node)) return; final boolean oldTop = notTop(); switch(node.op()) { case SUM: append("int"); append("["); node.expression().accept(this); append("]"); break; case CARDINALITY : append("#"); append("("); node.expression().accept(this); append(")"); break; default : throw new IllegalArgumentException("unknown operator: " + node.op()); } top = oldTop; }
Example #3
Source File: PartialCannonicalizer.java From quetzal with Eclipse Public License 2.0 | 6 votes |
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 #4
Source File: PrettyPrinter.java From kodkod with MIT License | 6 votes |
/** @ensures this.tokens' = concat[ this.tokens, "int","[", * tokenize[node.expression], "]" ] **/ public void visit(ExprToIntCast node) { switch(node.op()) { case SUM: append("int"); append("["); node.expression().accept(this); append("]"); break; case CARDINALITY : append("#"); append("("); node.expression().accept(this); append(")"); break; default : throw new IllegalArgumentException("unknown operator: " + node.op()); } }
Example #5
Source File: TranslateKodkodToJava.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void visit(ExprToIntCast x) { String newname = makename(x); if (newname == null) return; String sub = make(x.expression()); switch (x.op()) { case CARDINALITY : file.printf("IntExpression %s=%s.count();%n", newname, sub); break; case SUM : file.printf("IntExpression %s=%s.sum();%n", newname, sub); break; default : throw new RuntimeException("Unknown kodkod operator \"" + x.op() + "\" encountered"); } }
Example #6
Source File: PrettyPrinter.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * @ensures this.tokens' = concat[ this.tokens, "int","[", * tokenize[node.expression], "]" ] **/ @Override public void visit(ExprToIntCast node) { switch (node.op()) { case SUM : append("int"); append("["); node.expression().accept(this); append("]"); break; case CARDINALITY : append("#"); append("("); node.expression().accept(this); append(")"); break; default : throw new IllegalArgumentException("unknown operator: " + node.op()); } }
Example #7
Source File: FOL2BoolTranslator.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * 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, * translate(intExpr)) */ @Override public final Int visit(ExprToIntCast intExpr) { Int ret = lookup(intExpr); if (ret != null) return ret; vars = vars.createNested(); BooleanMatrix expr = intExpr.expression().accept(this); switch (intExpr.op()) { case CARDINALITY : ret = expr.cardinality(); break; case SUM : final IntSet ints = interpreter.ints(); ret = sum(expr, ints.iterator(), 0, ints.size() - 1); break; default : throw new IllegalArgumentException("unknown operator: " + intExpr.op()); } for (Variable v : vars) ret.defCond().addVar(v); vars = vars.parent(); return cache(intExpr, ret); }
Example #8
Source File: AbstractCollector.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * 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(ExprToIntCast intExpr) { Set<T> ret = lookup(intExpr); if (ret != null) return ret; ret = newSet(); ret.addAll(intExpr.expression().accept(this)); return cache(intExpr, ret); }
Example #9
Source File: AbstractReplacer.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * 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 #10
Source File: AbstractReplacer.java From kodkod with MIT License | 5 votes |
/** * 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 #11
Source File: AbstractVoidVisitor.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Visits intExpr.expression if this.visited(intExpr) returns false. Otherwise * does nothing. * * @ensures intExpr.expression.accept(this) */ @Override public void visit(ExprToIntCast intExpr) { if (visited(intExpr)) return; intExpr.expression().accept(this); }
Example #12
Source File: AbstractCollector.java From kodkod with MIT License | 5 votes |
/** * 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(ExprToIntCast intExpr) { Set<T> ret = lookup(intExpr); if (ret!=null) return ret; ret = newSet(); ret.addAll(intExpr.expression().accept(this)); return cache(intExpr,ret); }
Example #13
Source File: FOL2BoolTranslator.java From kodkod with MIT License | 5 votes |
/** * 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, translate(intExpr)) */ public final Int visit(ExprToIntCast intExpr) { Int ret = lookup(intExpr); if (ret!=null) return ret; switch(intExpr.op()) { case CARDINALITY : ret = intExpr.expression().accept(this).cardinality(); break; case SUM : final IntSet ints = interpreter.ints(); ret = sum(intExpr.expression().accept(this), ints.iterator(), 0, ints.size()-1); break; default: throw new IllegalArgumentException("unknown operator: " + intExpr.op()); } return cache(intExpr, ret); }
Example #14
Source File: HOLTranslator.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public IntExpression visit(ExprToIntCast intExpr) { return intExpr; }
Example #15
Source File: PrettyPrinter.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public void visit(ExprToIntCast intExpr) { visit(intExpr, intExpr.op(), intExpr.expression()); }
Example #16
Source File: AnnotatedNode.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public Boolean visit(ExprToIntCast e) { return checkVisitedThenAccumA(e, Boolean.FALSE, e.expression()); }
Example #17
Source File: PrettyPrinter.java From quetzal with Eclipse Public License 2.0 | 4 votes |
/** @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 #18
Source File: AspectReturnVisitor.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public I visit(ExprToIntCast intExpr) { start(intExpr); return end(intExpr, visitor.visit(intExpr)); }
Example #19
Source File: PrettyPrinter.java From kodkod with MIT License | 4 votes |
/** @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 org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * Visits the given unary integer expression. */ public void visit(ExprToIntCast intExpr);
Example #21
Source File: AbstractDetector.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * 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(ExprToIntCast intExpr) { final Boolean ret = lookup(intExpr); return (ret != null) ? ret : cache(intExpr, intExpr.expression().accept(this)); }
Example #22
Source File: AbstractDetector.java From kodkod with MIT License | 2 votes |
/** * 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(ExprToIntCast intExpr) { final Boolean ret = lookup(intExpr); return (ret!=null) ? ret : cache(intExpr, intExpr.expression().accept(this)); }
Example #23
Source File: ReturnVisitor.java From kodkod with MIT License | 2 votes |
/** * Visits the given unary integer expression and returns the result. * @return the result of visiting <code>intExpr</code> */ public I visit(ExprToIntCast intExpr);
Example #24
Source File: AbstractVoidVisitor.java From kodkod with MIT License | 2 votes |
/** * Visits intExpr.expression if * this.visited(intExpr) returns false. Otherwise does nothing. * @ensures intExpr.expression.accept(this) */ public void visit(ExprToIntCast intExpr) { if (visited(intExpr)) return; intExpr.expression().accept(this); }
Example #25
Source File: VoidVisitor.java From kodkod with MIT License | 2 votes |
/** * Visits the given unary integer expression. */ public void visit(ExprToIntCast intExpr);
Example #26
Source File: ReturnVisitor.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * Visits the given unary integer expression and returns the result. * * @return the result of visiting <code>intExpr</code> */ public I visit(ExprToIntCast intExpr);
Example #27
Source File: PrettyPrinter.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * @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 #28
Source File: PrettyPrinter.java From kodkod with MIT License | votes |
public void visit(ExprToIntCast intExpr) { visit(intExpr, intExpr.op(), intExpr.expression()); }