kodkod.ast.NaryIntExpression Java Examples
The following examples show how to use
kodkod.ast.NaryIntExpression.
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: Simplifier.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public IntExpression visit(NaryIntExpression expr) { IntExpression ret = lookup(expr); if (ret!=null) return ret; final IntOperator op = expr.op(); final List<IntExpression> children = simplify(op, visitAll(expr)); final int size = children.size(); switch(size) { case 0 : return cache(expr, constant(0)); case 1 : return cache(expr, children.get(0)); default : ret = expr.size()==size && allSame(expr,children) ? expr : IntExpression.compose(op, children); return cache(expr,ret); } }
Example #2
Source File: AbstractReplacer.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Calls lookup(intExpr) and returns the cached value, if any. If a replacement * has not been cached, visits the intExpr's children. If nothing changes, the * argument is cached and returned, otherwise a replacement intExpr is cached * and returned. * * @return { e: IntExpression | e.op = intExpr.op && #e.children = * #intExpr.children && all i: [0..intExpr.children) | e.child(i) = * intExpr.child(i).accept(delegate) } */ @Override public IntExpression visit(NaryIntExpression intExpr) { IntExpression ret = lookup(intExpr); if (ret != null) return ret; final IntExpression[] visited = new IntExpression[intExpr.size()]; boolean allSame = true; for (int i = 0; i < visited.length; i++) { final IntExpression child = intExpr.child(i); visited[i] = child.accept(delegate); allSame = allSame && visited[i] == child; } ret = allSame ? intExpr : IntExpression.compose(intExpr.op(), visited); return cache(intExpr, ret); }
Example #3
Source File: FOL2BoolTranslator.java From kodkod with MIT License | 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, intExpr.left.accept(this) intExpr.op intExpr.right.accept(this)) */ public final Int visit(NaryIntExpression intExpr) { Int ret = lookup(intExpr); if (ret!=null) return ret; final Int first = intExpr.child(0).accept(this); final Int[] rest = new Int[intExpr.size()-1]; for(int i = 0; i < rest.length; i++) { rest[i] = intExpr.child(i+1).accept(this); } switch(intExpr.op()) { case PLUS : ret = first.plus(rest); break; case MULTIPLY : ret = first.multiply(rest); break; case AND : ret = first.and(rest); break; case OR : ret = first.or(rest); break; default : throw new IllegalArgumentException("Unknown nary operator: " + intExpr.op()); } return cache(intExpr, ret); }
Example #4
Source File: AbstractReplacer.java From kodkod with MIT License | 6 votes |
/** * Calls lookup(intExpr) and returns the cached value, if any. * If a replacement has not been cached, visits the intExpr's * children. If nothing changes, the argument is cached and * returned, otherwise a replacement intExpr is cached and returned. * @return { e: IntExpression | e.op = intExpr.op && #e.children = #intExpr.children && all i: [0..intExpr.children) | e.child(i) = intExpr.child(i).accept(this) } */ public IntExpression visit(NaryIntExpression intExpr) { IntExpression ret = lookup(intExpr); if (ret!=null) return ret; final IntExpression[] visited = new IntExpression[intExpr.size()]; boolean allSame = true; for(int i = 0 ; i < visited.length; i++) { final IntExpression child = intExpr.child(i); visited[i] = child.accept(this); allSame = allSame && visited[i]==child; } ret = allSame ? intExpr : IntExpression.compose(intExpr.op(), visited); return cache(intExpr,ret); }
Example #5
Source File: TranslateKodkodToJava.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void visit(NaryIntExpression x) { String newname = makename(x); if (newname == null) return; String[] list = new String[x.size()]; for (int i = 0; i < list.length; i++) list[i] = make(x.child(i)); file.printf("IntExpression %s=IntExpression.compose(IntOperator.", newname); switch (x.op()) { case PLUS : file.print("PLUS"); break; case MULTIPLY : file.print("MULTIPLY"); break; case AND : file.print("AND"); break; case OR : file.print("OR"); break; default : throw new RuntimeException("Unknown kodkod operator \"" + x.op() + "\" encountered"); } for (int i = 0; i < list.length; i++) file.printf(", %s", list[i]); file.printf(");%n"); }
Example #6
Source File: PrettyPrinter.java From quetzal with Eclipse Public License 2.0 | 5 votes |
/** @effects appends the tokenization of the given node to this.tokens */ public void visit(NaryIntExpression node) { if (displayed(node)) return; final boolean oldTop = notTop(); final IntOperator op = node.op(); visitChild(node.child(0), parenthesize(op, node.child(0))); for(int i = 1, size = node.size(); i < size; i++) { infix(op); visitChild(node.child(i), parenthesize(op, node.child(i))); } top = oldTop; }
Example #7
Source File: PrettyPrinter.java From quetzal with Eclipse Public License 2.0 | 5 votes |
/** @return true if the given int expression needs to be parenthesized if a * child of a binary int expression with the given operator */ private boolean parenthesize(IntOperator op, IntExpression child) { return child instanceof SumExpression || child instanceof IfIntExpression || child instanceof NaryIntExpression || (child instanceof BinaryIntExpression && (!associative(op) || ((BinaryIntExpression)child).op()!=op)); }
Example #8
Source File: PrettyPrinter.java From kodkod with MIT License | 5 votes |
/** @ensures appends the tokenization of the given node to this.tokens */ public void visit(NaryIntExpression node) { final IntOperator op = node.op(); visitChild(node.child(0), parenthesize(op, node.child(0))); for(int i = 1, size = node.size(); i < size; i++) { infix(op); visitChild(node.child(i), parenthesize(op, node.child(i))); } }
Example #9
Source File: PrettyPrinter.java From kodkod with MIT License | 5 votes |
/** @return true if the given int expression needs to be parenthesized if a * child of a binary int expression with the given operator */ private boolean parenthesize(IntOperator op, IntExpression child) { return child instanceof SumExpression || child instanceof IfIntExpression || child instanceof NaryIntExpression || (child instanceof BinaryIntExpression && (!associative(op) || ((BinaryIntExpression)child).op()!=op)); }
Example #10
Source File: AbstractDetector.java From kodkod with MIT License | 5 votes |
/** * Calls lookup(intExpr) and returns the cached value, if any. * If no cached value exists, visits each child, caches the * disjunction of the children's return values and returns it. * @return let x = lookup(intExpr) | * x != null => x, * cache(intExpr, intExpr.child(0).accept(this) || ... || intExpr.child(intExpr.size()-1).accept(this)) */ public Boolean visit(NaryIntExpression intExpr) { final Boolean ret = lookup(intExpr); if (ret!=null) return ret; for(IntExpression child : intExpr) { if (child.accept(this)) return cache(intExpr, true); } return cache(intExpr, false); }
Example #11
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 each child, caches the * union of the children's return values and returns it. * @return let x = lookup(intExpr) | * x != null => x, * cache(intExpr, intExpr.child(0).accept(this) + .. + intExpr.child(intExpr.size()-1).accept(this)) */ public Set<T> visit(NaryIntExpression intExpr) { Set<T> ret = lookup(intExpr); if (ret!=null) return ret; ret = newSet(); for(IntExpression child : intExpr) { ret.addAll(child.accept(this)); } return cache(intExpr, ret); }
Example #12
Source File: AbstractVoidVisitor.java From kodkod with MIT License | 5 votes |
/** * Visits the children if this.visited(intExpr) returns false. Otherwise does nothing. * @ensures all i: [0..#intExpr.children) | intExpr.child(i).accept(this) */ public void visit(NaryIntExpression intExpr) { if (visited(intExpr)) return; for(IntExpression child : intExpr) { child.accept(this); } }
Example #13
Source File: PrettyPrinter.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * @ensures appends the tokenization of the given node to this.tokens */ @Override public void visit(NaryIntExpression node) { final IntOperator op = node.op(); visitChild(node.child(0), parenthesize(op, node.child(0))); for (int i = 1, size = node.size(); i < size; i++) { infix(op); visitChild(node.child(i), parenthesize(op, node.child(i))); } }
Example #14
Source File: FOL2BoolTranslator.java From org.alloytools.alloy with Apache License 2.0 | 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, * intExpr.left.accept(this) intExpr.op intExpr.right.accept(this)) */ @Override public final Int visit(NaryIntExpression intExpr) { Int ret = lookup(intExpr); if (ret != null) return ret; final Int first = intExpr.child(0).accept(this); final Int[] rest = new Int[intExpr.size() - 1]; for (int i = 0; i < rest.length; i++) { rest[i] = intExpr.child(i + 1).accept(this); } switch (intExpr.op()) { case PLUS : ret = first.plus(rest); break; case MULTIPLY : ret = first.multiply(rest); break; case AND : ret = first.and(rest); break; case OR : ret = first.or(rest); break; default : throw new IllegalArgumentException("Unknown nary operator: " + intExpr.op()); } return cache(intExpr, ret); }
Example #15
Source File: AbstractDetector.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 each child, caches the disjunction of the children's * return values and returns it. * * @return let x = lookup(intExpr) | x != null => x, cache(intExpr, * intExpr.child(0).accept(this) || ... || * intExpr.child(intExpr.size()-1).accept(this)) */ @Override public Boolean visit(NaryIntExpression intExpr) { final Boolean ret = lookup(intExpr); if (ret != null) return ret; for (IntExpression child : intExpr) { if (child.accept(this)) return cache(intExpr, true); } return cache(intExpr, false); }
Example #16
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 each child, caches the union of the children's return * values and returns it. * * @return let x = lookup(intExpr) | x != null => x, cache(intExpr, * intExpr.child(0).accept(this) + .. + * intExpr.child(intExpr.size()-1).accept(this)) */ @Override public Set<T> visit(NaryIntExpression intExpr) { Set<T> ret = lookup(intExpr); if (ret != null) return ret; ret = newSet(); for (IntExpression child : intExpr) { ret.addAll(child.accept(this)); } return cache(intExpr, ret); }
Example #17
Source File: AbstractVoidVisitor.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Visits the children if this.visited(intExpr) returns false. Otherwise does * nothing. * * @ensures all i: [0..#intExpr.children) | intExpr.child(i).accept(this) */ @Override public void visit(NaryIntExpression intExpr) { if (visited(intExpr)) return; for (IntExpression child : intExpr) { child.accept(this); } }
Example #18
Source File: AnnotatedNode.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public Boolean visit(NaryIntExpression e) { return checkVisitedThenAccum(e, Boolean.FALSE, e); }
Example #19
Source File: AspectReturnVisitor.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public I visit(NaryIntExpression intExpr) { start(intExpr); return end(intExpr, visitor.visit(intExpr)); }
Example #20
Source File: PrettyPrinter.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public void visit(NaryIntExpression intExpr) { visit(intExpr, intExpr.op(), intExpr.iterator()); }
Example #21
Source File: HOLTranslator.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
@Override public IntExpression visit(NaryIntExpression intExpr) { return intExpr; }
Example #22
Source File: VoidVisitor.java From kodkod with MIT License | 2 votes |
/** * Visits the given nary int expression. **/ public void visit(NaryIntExpression intExpr);
Example #23
Source File: ReturnVisitor.java From kodkod with MIT License | 2 votes |
/** * Visits the given nary expression and returns the result. * @return the result of visiting <code>intExpr</code> **/ public I visit(NaryIntExpression intExpr);
Example #24
Source File: PrettyPrinter.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * @return true if the given int expression needs to be parenthesized if a child * of a binary int expression with the given operator */ private boolean parenthesize(IntOperator op, IntExpression child) { return child instanceof SumExpression || child instanceof IfIntExpression || child instanceof NaryIntExpression || (child instanceof BinaryIntExpression && (!associative(op) || ((BinaryIntExpression) child).op() != op)); }
Example #25
Source File: ReturnVisitor.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * Visits the given nary expression and returns the result. * * @return the result of visiting <code>intExpr</code> **/ public I visit(NaryIntExpression intExpr);
Example #26
Source File: VoidVisitor.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * Visits the given nary int expression. **/ public void visit(NaryIntExpression intExpr);
Example #27
Source File: PrettyPrinter.java From kodkod with MIT License | votes |
public void visit(NaryIntExpression intExpr) { visit(intExpr, intExpr.op(), intExpr.iterator());}