Java Code Examples for kodkod.ast.ProjectExpression#expression()

The following examples show how to use kodkod.ast.ProjectExpression#expression() . 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: 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 2
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);
}