kodkod.ast.ProjectExpression Java Examples

The following examples show how to use kodkod.ast.ProjectExpression. 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: PrettyPrinter.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
/** @effects appends the tokenization of the given node to this.tokens */
public void visit(ProjectExpression node) {
	if (displayed(node)) return;
	final boolean oldTop = notTop();
	append("project");
	append("[");
	node.expression().accept(this);
	comma();
	append("<");
	final Iterator<IntExpression> cols = node.columns();
	cols.next().accept(this);
	while(cols.hasNext()) { 
		comma();
		cols.next().accept(this);
	}
	append(">");
	append("]");
	top = oldTop;
}
 
Example #2
Source File: AbstractReplacer.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Calls lookup(decls) and returns the cached value, if any. If a replacement
 * has not been cached, visits each of the children's variable and expression.
 * If nothing changes, the argument is cached and returned, otherwise a
 * replacement Decls object is cached and returned.
 *
 * @return { d: Decls | d.size = decls.size && all i: [0..d.size) |
 *         d.declarations[i] = decls.declarations[i].accept(delegate) }
 */
@Override
public Expression visit(ProjectExpression project) {
    Expression ret = lookup(project);
    if (ret != null)
        return ret;

    final Expression expr = project.expression().accept(delegate);
    final IntExpression[] cols = new IntExpression[project.arity()];
    boolean allSame = expr == project.expression();
    for (int i = 0, arity = project.arity(); i < arity; i++) {
        cols[i] = project.column(i).accept(delegate);
        allSame = allSame && (cols[i] == project.column(i));
    }
    ret = allSame ? project : expr.project(cols);
    return cache(project, ret);
}
 
Example #3
Source File: PrettyPrinter.java    From kodkod with MIT License 6 votes vote down vote up
/** @ensures appends the tokenization of the given node to this.tokens */
public void visit(ProjectExpression node) {
	append("project");
	append("[");
	node.expression().accept(this);
	comma();
	append("<");
	final Iterator<IntExpression> cols = node.columns();
	cols.next().accept(this);
	while(cols.hasNext()) { 
		comma();
		cols.next().accept(this);
	}
	append(">");
	append("]");
}
 
Example #4
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * @ensures appends the tokenization of the given node to this.tokens
 */
@Override
public void visit(ProjectExpression node) {
    append("project");
    append("[");
    node.expression().accept(this);
    comma();
    append("<");
    final Iterator<IntExpression> cols = node.columns();
    cols.next().accept(this);
    while (cols.hasNext()) {
        comma();
        cols.next().accept(this);
    }
    append(">");
    append("]");
}
 
Example #5
Source File: TranslateKodkodToJava.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visit(ProjectExpression x) {
    String newname = makename(x);
    if (newname == null)
        return;
    String expr = make(x.expression());
    List<String> names = new ArrayList<String>();
    for (Iterator<IntExpression> i = x.columns(); i.hasNext();) {
        names.add(make(i.next()));
    }
    for (int i = 0; i < names.size(); i++) {
        if (i == 0)
            file.printf("Expression %s=%s.project(", newname, expr);
        else
            file.printf(",");
        file.printf("%s", names.get(i));
    }
    file.printf(");%n");
}
 
Example #6
Source File: AnnotatedNode.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean visit(ProjectExpression project) {
    Boolean ans = get(project);
    if (ans != null)
        return ans;
    List<IntExpression> cols = new ArrayList<IntExpression>(project.arity());
    for (int i = 0, arity = project.arity(); i < arity; i++) {
        cols.add(project.column(i));
    }
    return accum(project, project.expression().accept(this), cols);
}
 
Example #7
Source File: FOL2BoolTranslator.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Calls lookup(project) 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(project) | some t => t, 
 * 			cache(project, project.expression.accept(this).project(translate(project.columns))
 */
public final BooleanMatrix visit(ProjectExpression project) {
	BooleanMatrix ret = lookup(project);
	if (ret!=null) return ret;

	final Int[] cols = new Int[project.arity()];
	for(int i = 0, arity = project.arity(); i < arity; i++) {
		cols[i] = project.column(i).accept(this);
	}

	return cache(project, project.expression().accept(this).project(cols));
}
 
Example #8
Source File: AbstractDetector.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Calls lookup(project) 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(project) | 
 *          x != null => x,  
 *          cache(project, project.expression.accept(this) || project.columns[int].accept(this)) 
 */
public Boolean visit(ProjectExpression project) {
	final Boolean ret = lookup(project);
	if (ret!=null) return ret;
	if (project.expression().accept(this))
		return cache(project, true);
	for(int i = 0, arity = project.arity(); i < arity; i++) {
		if (project.column(i).accept(this))
			return cache(project, true);
	}
	return cache(project, false);
}
 
Example #9
Source File: AbstractCollector.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Calls lookup(project) 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(project) | 
 *          x != null => x,  
 *          cache(project, project.expression.accept(this) + project.columns[int].accept(this)) 
 */
public Set<T> visit(ProjectExpression project) {
	Set<T> ret = lookup(project);
	if (ret!=null) return ret;
	ret = newSet();
	ret.addAll(project.expression().accept(this));
	for(int i = 0, arity = project.arity(); i < arity; i++) {
		ret.addAll(project.column(i).accept(this));
	}
	return cache(project,ret);
}
 
Example #10
Source File: AbstractVoidVisitor.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Visits project.expression and project.columns if this.visited(project) returns false.
 * Otherwise does nothing.
 * @ensures project.expression.accept(this) && all i: project.arity | project.columns[i].accept(this)
 */
public void visit(ProjectExpression project) {
	if (visited(project)) return;
	project.expression().accept(this);
	for(int i = 0, arity = project.arity(); i < arity; i++) {
		project.column(i).accept(this);
	}
}
 
Example #11
Source File: AbstractReplacer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(decls) and returns the cached value, if any.  
 * If a replacement has not been cached, visits each of the children's 
 * variable and expression.  If nothing changes, the argument is cached and
 * returned, otherwise a replacement Decls object is cached and returned.
 * @return { d: Decls | d.size = decls.size && 
 *                      all i: [0..d.size) | d.declarations[i] = decls.declarations[i].accept(this) } 
 */
public Expression visit(ProjectExpression project) { 
	Expression ret = lookup(project);
	if (ret!=null) return ret;

	final Expression expr = project.expression().accept(this);
	final IntExpression[] cols = new IntExpression[project.arity()];
	boolean allSame = expr==project.expression();
	for(int i = 0, arity = project.arity(); i < arity; i++) {
		cols[i] = project.column(i).accept(this);
		allSame = allSame && (cols[i]==project.column(i));
	}
	ret = allSame ? project : expr.project(cols);
	return cache(project, ret);
}
 
Example #12
Source File: FOL2BoolTranslator.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls lookup(project) 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(project) | some t => t, cache(project,
 *         project.expression.accept(this).project(translate(project.columns))
 */
@Override
public final BooleanMatrix visit(ProjectExpression project) {
    BooleanMatrix ret = lookup(project);
    if (ret != null)
        return ret;

    final Int[] cols = new Int[project.arity()];
    for (int i = 0, arity = project.arity(); i < arity; i++) {
        cols[i] = project.column(i).accept(this);
    }

    return cache(project, project.expression().accept(this).project(cols));
}
 
Example #13
Source File: AbstractDetector.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls lookup(project) 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(project) | x != null => x, cache(project,
 *         project.expression.accept(this) || project.columns[int].accept(this))
 */
@Override
public Boolean visit(ProjectExpression project) {
    final Boolean ret = lookup(project);
    if (ret != null)
        return ret;
    if (project.expression().accept(this))
        return cache(project, true);
    for (int i = 0, arity = project.arity(); i < arity; i++) {
        if (project.column(i).accept(this))
            return cache(project, true);
    }
    return cache(project, false);
}
 
Example #14
Source File: AbstractCollector.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls lookup(project) 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(project) | x != null => x, cache(project,
 *         project.expression.accept(this) + project.columns[int].accept(this))
 */
@Override
public Set<T> visit(ProjectExpression project) {
    Set<T> ret = lookup(project);
    if (ret != null)
        return ret;
    ret = newSet();
    ret.addAll(project.expression().accept(this));
    for (int i = 0, arity = project.arity(); i < arity; i++) {
        ret.addAll(project.column(i).accept(this));
    }
    return cache(project, ret);
}
 
Example #15
Source File: AbstractVoidVisitor.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Visits project.expression and project.columns if this.visited(project)
 * returns false. Otherwise does nothing.
 *
 * @ensures project.expression.accept(this) && all i: project.arity |
 *          project.columns[i].accept(this)
 */
@Override
public void visit(ProjectExpression project) {
    if (visited(project))
        return;
    project.expression().accept(this);
    for (int i = 0, arity = project.arity(); i < arity; i++) {
        project.column(i).accept(this);
    }
}
 
Example #16
Source File: AspectReturnVisitor.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public E visit(ProjectExpression project) {
    start(project);
    return end(project, visitor.visit(project));
}
 
Example #17
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(ProjectExpression project) {
    visit(project, "proj", project.expression(), project.columns());
}
 
Example #18
Source File: HOLTranslator.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
@Override
public Expression visit(ProjectExpression project) {
    return project;
}
 
Example #19
Source File: PrettyPrinter.java    From kodkod with MIT License 4 votes vote down vote up
public void visit(ProjectExpression project) {
	visit(project, "proj", project.expression(), project.columns());
}
 
Example #20
Source File: VoidVisitor.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Visits the given projection expression.
 */
public void visit(ProjectExpression project);
 
Example #21
Source File: ReturnVisitor.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Visits the given projection expression and returns the result.
 * @return the result of visiting <code>project</code>
 */
public E visit(ProjectExpression project);
 
Example #22
Source File: ReturnVisitor.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Visits the given projection expression and returns the result.
 *
 * @return the result of visiting <code>project</code>
 */
public E visit(ProjectExpression project);
 
Example #23
Source File: VoidVisitor.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Visits the given projection expression.
 */
public void visit(ProjectExpression project);