Java Code Examples for kodkod.ast.RelationPredicate#name()

The following examples show how to use kodkod.ast.RelationPredicate#name() . 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: AbstractVoidVisitor.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Visits the children of the predicate if this.visited(pred) returns false.
 * Otherwise does nothing.
 *
 * @ensures pred.relation.accept(this) && (pred.name = FUNCTION =>
 *          pred.domain.accept(this) && pred.range.accept(this)) && (pred.name =
 *          TOTAL_ORDERING => pred.ordered.accept(this) &&
 *          pred.first.accept(this) && pred.last.accept(this) )
 */
@Override
public void visit(RelationPredicate pred) {
    if (visited(pred))
        return;
    pred.relation().accept(this);
    if (pred.name() == RelationPredicate.Name.FUNCTION) {
        final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
        fp.domain().accept(this);
        fp.range().accept(this);
    } else if (pred.name() == RelationPredicate.Name.TOTAL_ORDERING) {
        final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
        tp.ordered().accept(this);
        tp.first().accept(this);
        tp.last().accept(this);
    }
}
 
Example 2
Source File: AbstractDetector.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Calls lookup(predicate) 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(predicate) | x != null => x, cache(predicate, some n:
 *         predicate.children | n.accept(this))
 */
@Override
public Boolean visit(RelationPredicate predicate) {
    final Boolean ret = lookup(predicate);
    if (ret != null)
        return ret;
    if (predicate.relation().accept(this))
        return cache(predicate, true);
    if (predicate.name() == RelationPredicate.Name.FUNCTION) {
        final RelationPredicate.Function fp = (RelationPredicate.Function) predicate;
        return cache(predicate, fp.domain().accept(this) || fp.range().accept(this));
    } else if (predicate.name() == RelationPredicate.Name.TOTAL_ORDERING) {
        final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) predicate;
        return cache(predicate, tp.ordered().accept(this) || tp.first().accept(this) || tp.last().accept(this));
    }
    return cache(predicate, false);
}
 
Example 3
Source File: AnnotatedNode.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean visit(RelationPredicate pred) {
    Boolean ans = get(pred);
    if (ans != null)
        return ans;
    pred.relation().accept(this);
    if (pred.name() == RelationPredicate.Name.FUNCTION) {
        final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
        fp.domain().accept(this);
        fp.range().accept(this);
    } else if (pred.name() == RelationPredicate.Name.TOTAL_ORDERING) {
        final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
        tp.ordered().accept(this);
        tp.first().accept(this);
        tp.last().accept(this);
    }
    return noHOL(pred);
}
 
Example 4
Source File: AbstractCollector.java    From kodkod with MIT License 6 votes vote down vote up
/** 
 * Calls lookup(predicate) 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(predicate) | 
 *          x != null => x,  
 *          cache(predicate, some n: predicate.children | n.accept(this)) 
 */
public Set<T> visit(RelationPredicate pred) {
	Set<T> ret = lookup(pred);
	if (ret!=null) return ret;
	ret = newSet();
	ret.addAll(pred.relation().accept(this));
	switch(pred.name()) {
	case ACYCLIC : 
		break;
	case FUNCTION :
		final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
		ret.addAll(fp.domain().accept(this));
		ret.addAll(fp.range().accept(this));
		break;
	case TOTAL_ORDERING : 
		final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
		ret.addAll(tp.ordered().accept(this));
		ret.addAll(tp.first().accept(this));
		ret.addAll(tp.last().accept(this));
		break;
	default :
		throw new IllegalArgumentException("unknown relation predicate: " + pred.name());
	}
	return cache(pred,ret);
}
 
Example 5
Source File: AbstractReplacer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls lookup(pred) and returns the cached value, if any. If a replacement has
 * not been cached, visits the formula's children. If nothing changes, the
 * argument is cached and returned, otherwise a replacement formula is cached
 * and returned.
 *
 * @return { p: RelationPredicate | p.name = pred.name && p.relation =
 *         pred.relation.accept(delegate) && p.name = FUNCTION => p.targetMult =
 *         pred.targetMult && p.domain = pred.domain.accept(delegate) && p.range
 *         = pred.range.accept(delegate), p.name = TOTAL_ORDERING => p.ordered =
 *         pred.ordered.accept(delegate) && p.first =
 *         pred.first.accept(delegate) && p.last = pred.last.accept(delegate) }
 */
@Override
public Formula visit(RelationPredicate pred) {
    Formula ret = lookup(pred);
    if (ret != null)
        return ret;

    final Relation r = (Relation) pred.relation().accept(delegate);
    switch (pred.name()) {
        case ACYCLIC :
            ret = (r == pred.relation()) ? pred : r.acyclic();
            break;
        case FUNCTION :
            final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
            final Expression domain = fp.domain().accept(delegate);
            final Expression range = fp.range().accept(delegate);
            ret = (r == fp.relation() && domain == fp.domain() && range == fp.range()) ? fp : (fp.targetMult() == Multiplicity.ONE ? r.function(domain, range) : r.partialFunction(domain, range));
            break;
        case TOTAL_ORDERING :
            final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
            final Relation ordered = (Relation) tp.ordered().accept(delegate);
            final Relation first = (Relation) tp.first().accept(delegate);
            final Relation last = (Relation) tp.last().accept(delegate);
            ret = (r == tp.relation() && ordered == tp.ordered() && first == tp.first() && last == tp.last()) ? tp : r.totalOrder(ordered, first, last);
            break;
        default :
            throw new IllegalArgumentException("unknown relation predicate: " + pred.name());
    }
    return cache(pred, ret);
}
 
Example 6
Source File: AbstractCollector.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls lookup(predicate) 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(predicate) | x != null => x, cache(predicate, some n:
 *         predicate.children | n.accept(this))
 */
@Override
public Set<T> visit(RelationPredicate pred) {
    Set<T> ret = lookup(pred);
    if (ret != null)
        return ret;
    ret = newSet();
    ret.addAll(pred.relation().accept(this));
    switch (pred.name()) {
        case ACYCLIC :
            break;
        case FUNCTION :
            final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
            ret.addAll(fp.domain().accept(this));
            ret.addAll(fp.range().accept(this));
            break;
        case TOTAL_ORDERING :
            final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
            ret.addAll(tp.ordered().accept(this));
            ret.addAll(tp.first().accept(this));
            ret.addAll(tp.last().accept(this));
            break;
        default :
            throw new IllegalArgumentException("unknown relation predicate: " + pred.name());
    }
    return cache(pred, ret);
}
 
Example 7
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * @ensures appends the tokenization of the given node to this.tokens
 */
@Override
public void visit(RelationPredicate node) {
    switch (node.name()) {
        case ACYCLIC :
            append("acyclic");
            append("[");
            node.relation().accept(this);
            append("]");
            break;
        case FUNCTION :
            RelationPredicate.Function func = (RelationPredicate.Function) node;
            append("function");
            append("[");
            func.relation().accept(this);
            colon();
            func.domain().accept(this);
            infix("->");
            keyword(func.targetMult());
            func.range().accept(this);
            append("]");
            break;
        case TOTAL_ORDERING :
            RelationPredicate.TotalOrdering ord = (RelationPredicate.TotalOrdering) node;
            append("ord");
            append("[");
            ord.relation().accept(this);
            comma();
            ord.ordered().accept(this);
            comma();
            ord.first().accept(this);
            comma();
            ord.last().accept(this);
            append("]");
            break;
        default :
            throw new AssertionError("unreachable");
    }

}
 
Example 8
Source File: PrettyPrinter.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(RelationPredicate pred) {
    if (visited(pred))
        return;

    if (pred.name() == RelationPredicate.Name.FUNCTION) {
        final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
        visit(fp, fp.name(), fp.domain(), fp.range());
    } else if (pred.name() == RelationPredicate.Name.TOTAL_ORDERING) {
        final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
        visit(tp, tp.name(), tp.ordered(), tp.first(), tp.last());
    } else {
        throw new IllegalArgumentException("Unknown predicate: " + pred);
    }
}
 
Example 9
Source File: AbstractReplacer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(pred) and returns the cached value, if any.  
 * If a replacement has not been cached, visits the formula's 
 * children.  If nothing changes, the argument is cached and
 * returned, otherwise a replacement formula is cached and returned.
 * @return { p: RelationPredicate | p.name = pred.name && p.relation = pred.relation.accept(this) &&
 *                                  p.name = FUNCTION => p.targetMult = pred.targetMult && 
 *                                                       p.domain = pred.domain.accept(this) &&
 *                                                       p.range = pred.range.accept(this),
 *                                  p.name = TOTAL_ORDERING => p.ordered = pred.ordered.accept(this) &&
 *                                                             p.first = pred.first.accept(this) &&
 *                                                             p.last = pred.last.accept(this) }
 */
public Formula visit(RelationPredicate pred) {
	Formula ret = lookup(pred);
	if (ret!=null) return ret;

	final Relation r = (Relation)pred.relation().accept(this);
	switch(pred.name()) {
	case ACYCLIC :  
		ret = (r==pred.relation()) ? pred : r.acyclic(); 
		break;
	case FUNCTION :
		final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
		final Expression domain = fp.domain().accept(this);
		final Expression range = fp.range().accept(this);
		ret = (r==fp.relation() && domain==fp.domain() && range==fp.range()) ?
				fp : 
				(fp.targetMult()==Multiplicity.ONE ? r.function(domain, range) : r.partialFunction(domain,range));
		break;
	case TOTAL_ORDERING : 
		final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
		final Relation ordered = (Relation) tp.ordered().accept(this);
		final Relation first = (Relation)tp.first().accept(this);
		final Relation last = (Relation)tp.last().accept(this);
		ret = (r==tp.relation() && ordered==tp.ordered() && first==tp.first() && last==tp.last()) ? 
				tp : r.totalOrder(ordered, first, last);
		break;
	default :
		throw new IllegalArgumentException("unknown relation predicate: " + pred.name());
	}
	return cache(pred,ret);
}
 
Example 10
Source File: AbstractVoidVisitor.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Visits the children of the predicate  if
 * this.visited(pred) returns false.  Otherwise does nothing.
 * @ensures pred.relation.accept(this) && 
 *          (pred.name = FUNCTION => pred.domain.accept(this) && pred.range.accept(this)) && 
 *          (pred.name = TOTAL_ORDERING => 
 *            pred.ordered.accept(this) && pred.first.accept(this) && pred.last.accept(this) )
 */
public void visit(RelationPredicate pred) {
	if (visited(pred)) return;
	pred.relation().accept(this);
	if (pred.name()==RelationPredicate.Name.FUNCTION) {
		final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
		fp.domain().accept(this);
		fp.range().accept(this);
	} else if (pred.name()==RelationPredicate.Name.TOTAL_ORDERING) {
		final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
		tp.ordered().accept(this);
		tp.first().accept(this);
		tp.last().accept(this);
	}
}
 
Example 11
Source File: AbstractDetector.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(predicate) 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(predicate) | 
 *          x != null => x,  
 *          cache(predicate, some n: predicate.children | n.accept(this)) 
 */
public Boolean visit(RelationPredicate predicate) {
	final Boolean ret = lookup(predicate);
	if (ret!=null) return ret;
	if (predicate.relation().accept(this)) 
		return cache(predicate, true);
	if (predicate.name()==RelationPredicate.Name.FUNCTION) {
		final RelationPredicate.Function fp = (RelationPredicate.Function) predicate;
		return cache(predicate, fp.domain().accept(this) || fp.range().accept(this));
	} else if (predicate.name()==RelationPredicate.Name.TOTAL_ORDERING) {
		final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) predicate;
		return cache(predicate, tp.ordered().accept(this) || tp.first().accept(this) || tp.last().accept(this));
	}
	return cache(predicate, false);
}
 
Example 12
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
/** @ensures appends the tokenization of the given node to this.tokens */
public void visit(RelationPredicate node) {
	switch(node.name()) { 
	case ACYCLIC : 
		append("acyclic");
		append("[");
		node.relation().accept(this);
		append("]");
		break;
	case FUNCTION : 
		RelationPredicate.Function func = (RelationPredicate.Function)node;
		append("function");
		append("[");
		func.relation().accept(this);
		colon();
		func.domain().accept(this);
		infix("->");
		keyword(func.targetMult());
		func.range().accept(this);
		append("]");
		break;
	case TOTAL_ORDERING : 
		RelationPredicate.TotalOrdering ord = (RelationPredicate.TotalOrdering)node;
		append("ord");
		append("[");
		ord.relation().accept(this);
		comma();
		ord.ordered().accept(this);
		comma();
		ord.first().accept(this);
		comma();
		ord.last().accept(this);
		append("]");
		break;
	default:
		throw new AssertionError("unreachable");
	}
	
}
 
Example 13
Source File: PrettyPrinter.java    From kodkod with MIT License 5 votes vote down vote up
public void visit(RelationPredicate pred) {
	if (visited(pred)) return;
	
	if (pred.name()==RelationPredicate.Name.FUNCTION) {
		final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
		visit(fp, fp.name(),  fp.domain(), fp.range() );
	} else if (pred.name()==RelationPredicate.Name.TOTAL_ORDERING) {
		final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
		visit(tp, tp.name(),  tp.ordered(), tp.first(), tp.last() );
	} else {
		throw new IllegalArgumentException("Unknown predicate: " + pred);
	}
}
 
Example 14
Source File: PrettyPrinter.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
/** @effects appends the tokenization of the given node to this.tokens */
public void visit(RelationPredicate node) {
	if (displayed(node)) return;
	final boolean oldTop = notTop();
	switch(node.name()) { 
	case ACYCLIC : 
		append("acyclic");
		append("[");
		node.relation().accept(this);
		append("]");
		break;
	case FUNCTION : 
		RelationPredicate.Function func = (RelationPredicate.Function)node;
		append("function");
		append("[");
		func.relation().accept(this);
		colon();
		func.domain().accept(this);
		infix("->");
		keyword(func.targetMult());
		func.range().accept(this);
		append("]");
		break;
	case TOTAL_ORDERING : 
		RelationPredicate.TotalOrdering ord = (RelationPredicate.TotalOrdering)node;
		append("ord");
		append("[");
		ord.relation().accept(this);
		comma();
		ord.ordered().accept(this);
		comma();
		ord.first().accept(this);
		comma();
		ord.last().accept(this);
		append("]");
		break;
	default:
		throw new AssertionError("unreachable");
	}
	top = oldTop;
}