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

The following examples show how to use kodkod.ast.ProjectExpression#arity() . 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: 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 3
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 4
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 5
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 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: 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 8
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 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: 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 11
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));
}