Java Code Examples for kodkod.ast.Node#accept()

The following examples show how to use kodkod.ast.Node#accept() . 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: AnnotatedNode.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Visits the given comprehension, quantified formula, or sum expression. The
 * method returns TRUE if the creator body contains any variable not bound by
 * the decls; otherwise returns FALSE.
 */
private Boolean visit(Node creator, Decls decls, Node body) {
    Boolean ret = lookup(creator);
    if (ret != null)
        return ret;
    boolean retVal = false;
    for (Decl decl : decls) {
        retVal = decl.expression().accept(this) || retVal;
        varsInScope.push(decl.variable());
    }
    retVal = ((Boolean) body.accept(this)) || retVal;
    for (int i = decls.size(); i > 0; i--) {
        varsInScope.pop();
    }
    return cache(creator, retVal);
}
 
Example 2
Source File: AnnotatedNode.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private <E extends Node> Boolean accum(Node n, Boolean acc, Iterable<E> subs) {
    for (Node child : subs) {
        Boolean res = (Boolean) child.accept(this);
        acc = acc || res;
    }
    return place(n, acc);
}
 
Example 3
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
private void visit(Node parent, Object label, Iterator<? extends Node> children) {
	if (visited(parent)) return;
	node(parent, label.toString());
	while(children.hasNext()) {
		Node child = children.next();
		child.accept(this);
		edge(parent, child);
	}
}
 
Example 4
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
private void visit(Node parent, Object label, Node left, Node middle, Node right) {
	if (visited(parent)) return;
	node(parent, label.toString());
	left.accept(this);
	middle.accept(this);
	right.accept(this);
	edge(parent, left);	
	edge(parent, middle);	
	edge(parent, right);
}
 
Example 5
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
private void visit(Node parent, Object label, Node left, Node right) {
	if (visited(parent)) return;
	node(parent, label.toString());
	left.accept(this);
	right.accept(this);
	edge(parent, left);	
	edge(parent, right);
}
 
Example 6
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
static String apply(Node node) { 
	final Dotifier dot = new Dotifier();
	dot.graph.append("digraph {\n");
	node.accept(dot);
	dot.graph.append("}");
	return dot.graph.toString();
}
 
Example 7
Source File: Skolemizer.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Constructs a skolem replacer from the given arguments. 
 */
private Skolemizer(AnnotatedNode<Formula> annotated, Bounds bounds, Options options) {
	super(annotated.sharedNodes());

	// only cache intermediate computations for expressions with no free variables
	// and formulas with no free variables and no quantified descendants
	
	for(Node n: annotated.sharedNodes()) {
		final AbstractDetector fvdetect = annotated.freeVariableDetector();
		final AbstractDetector qdetect = annotated.quantifiedFormulaDetector();
		if (!(Boolean)n.accept(fvdetect)) {
			if (!(n instanceof Formula) || !((Boolean)n.accept(qdetect)))
				this.cache.put(n, null);
		}
	}
	this.reporter = options.reporter();
	this.bounds = bounds;
	this.interpreter = LeafInterpreter.overapproximating(bounds, options);
	this.repEnv = Environment.empty();
	this.nonSkolems = new ArrayList<DeclInfo>();
	this.nonSkolemsView = new AbstractList<Decl>() {
		public Decl get(int index) { return nonSkolems.get(index).decl;	}
		public int size() { return nonSkolems.size(); }
	};
	this.topSkolemConstraints = new ArrayList<Formula>();
	this.negated = false;
	this.skolemDepth = options.skolemDepth();
}
 
Example 8
Source File: AnnotatedNode.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Visits the given comprehension, quantified formula, or sum expression.  
 * The method returns TRUE if the creator body contains any 
 * variable not bound by the decls; otherwise returns FALSE.  
 */
private Boolean visit(Node creator, Decls decls, Node body) {
	Boolean ret = lookup(creator);
	if (ret!=null) return ret;
	boolean retVal = false;
	for(Decl decl : decls) {
		retVal = decl.expression().accept(this) || retVal;
		varsInScope.push(decl.variable());
	}
	retVal = ((Boolean)body.accept(this)) || retVal;
	for(int i = decls.size(); i > 0; i--) {
		varsInScope.pop();
	}
	return cache(creator, retVal);
}
 
Example 9
Source File: Skolemizer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a skolem replacer from the given arguments.
 */
private Skolemizer(AnnotatedNode<Formula> annotated, Bounds bounds, Options options) {
    super(annotated.sharedNodes());

    // only cache intermediate computations for expressions with no free
    // variables
    // and formulas with no free variables and no quantified descendents
    for (Node n : annotated.sharedNodes()) {
        final AbstractDetector fvdetect = annotated.freeVariableDetector();
        final AbstractDetector qdetect = annotated.quantifiedFormulaDetector();
        if (!(Boolean) n.accept(fvdetect)) {
            if (!(n instanceof Formula) || !((Boolean) n.accept(qdetect)))
                this.cache.put(n, null);
        }
    }
    this.reporter = options.reporter();
    this.bounds = bounds;
    this.interpreter = LeafInterpreter.overapproximating(bounds, options);
    this.repEnv = Environment.empty();
    this.nonSkolems = new ArrayList<DeclInfo>();
    this.nonSkolemsView = new AbstractList<Decl>() {

        @Override
        public Decl get(int index) {
            return nonSkolems.get(index).decl;
        }

        @Override
        public int size() {
            return nonSkolems.size();
        }
    };
    this.topSkolemConstraints = new ArrayList<Formula>();
    this.negated = false;
    this.skolemDepth = options.skolemDepth();
}
 
Example 10
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private void visit(Node parent, Object label, Node child, Iterator< ? extends Node> children) {
    if (visited(parent))
        return;
    node(parent, label.toString());
    child.accept(this);
    edge(parent, child);
    while (children.hasNext()) {
        Node other = children.next();
        other.accept(this);
        edge(parent, other);
    }
}
 
Example 11
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private void visit(Node parent, Object label, Iterator< ? extends Node> children) {
    if (visited(parent))
        return;
    node(parent, label.toString());
    while (children.hasNext()) {
        Node child = children.next();
        child.accept(this);
        edge(parent, child);
    }
}
 
Example 12
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private void visit(Node parent, Object label, Node left, Node middle, Node right) {
    if (visited(parent))
        return;
    node(parent, label.toString());
    left.accept(this);
    middle.accept(this);
    right.accept(this);
    edge(parent, left);
    edge(parent, middle);
    edge(parent, right);
}
 
Example 13
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private void visit(Node parent, Object label, Node left, Node right) {
    if (visited(parent))
        return;
    node(parent, label.toString());
    left.accept(this);
    right.accept(this);
    edge(parent, left);
    edge(parent, right);
}
 
Example 14
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private void visit(Node parent, Object label, Node child) {
    if (visited(parent))
        return;
    node(parent, label.toString());
    child.accept(this);
    edge(parent, child);
}
 
Example 15
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
static String apply(Node node) {
    final Dotifier dot = new Dotifier();
    dot.graph.append("digraph {\n");
    node.accept(dot);
    dot.graph.append("}");
    return dot.graph.toString();
}
 
Example 16
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
private void visit(Node parent, Object label, Node child, Iterator<? extends Node> children) {
	if (visited(parent)) return;
	node(parent, label.toString());
	child.accept(this);
	edge(parent, child);
	while(children.hasNext()) {
		Node other = children.next();
		other.accept(this);
		edge(parent, other);
	}
}
 
Example 17
Source File: PrettyPrinter.java    From kodkod with MIT License 4 votes vote down vote up
/** @ensures this.tokenize' = 
 *   (parenthesize => concat [ this.tokens, "(", tokenize[child], ")" ] else 
 *                    concat [ this.tokens, tokenize[child] ]*/
private void visitChild(Node child, boolean parenthesize) { 
	if (parenthesize) { append("("); }
	child.accept(this);
	if (parenthesize) { append(")"); }
}
 
Example 18
Source File: PrettyPrinter.java    From kodkod with MIT License 4 votes vote down vote up
private void visit(Node parent, Object label, Node child) {
	if (visited(parent)) return;
	node(parent, label.toString());
	child.accept(this);
	edge(parent, child);	
}
 
Example 19
Source File: PrettyPrinter.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns a pretty-printed string representation of the 
 * given node, with each line offset by at least the given
 * number of whitespaces.  The line parameter determines the
 * length of each pretty-printed line, including the offset.
 * @requires 0 <= offset < line
 * @return a pretty-printed string representation of the 
 * given node
 */
public static String print(Node node, int offset, int line) { 
	final Formatter formatter = new Formatter(offset,line);
	node.accept(formatter);
	return formatter.tokens.toString();
}
 
Example 20
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a pretty-printed string representation of the given node, with each
 * line offset by at least the given number of whitespaces. The line parameter
 * determines the length of each pretty-printed line, including the offset.
 *
 * @requires 0 <= offset < line
 * @return a pretty-printed string representation of the given node
 */
public static String print(Node node, int offset, int line) {
    final Formatter formatter = new Formatter(offset, line);
    node.accept(formatter);
    return formatter.tokens.toString();
}