Search in sources :

Example 1 with ExprCall

use of edu.mit.csail.sdg.ast.ExprCall in project org.alloytools.alloy by AlloyTools.

the class CompUtil method areIntsUsed.

// =============================================================================================================//
/**
 * Whether or not Int appears in the relation types found in these sigs
 */
public static boolean areIntsUsed(Iterable<Sig> sigs, Command cmd) {
    /* check for Int-typed relations */
    for (Sig s : sigs) {
        for (Field f : s.getFields()) {
            for (ProductType pt : f.type()) {
                for (int k = 0; k < pt.arity(); k++) {
                    if (pt.get(k) == SIGINT || pt.get(k) == SEQIDX)
                        return true;
                }
            }
        }
    }
    if (cmd == null)
        return false;
    /* check expressions; look for CAST2SIGING (Int[]) */
    try {
        Object intTriggerNode;
        intTriggerNode = cmd.formula.accept(new VisitQueryOnce<Object>() {

            @Override
            public Object visit(ExprCall x) throws Err {
                // Int[]
                if (x.fun.label.startsWith("integer/"))
                    return null;
                return super.visit(x);
            }

            @Override
            public Object visit(ExprUnary x) throws Err {
                if (x.op == Op.CAST2SIGINT)
                    return x;
                return super.visit(x);
            }
        });
        if (intTriggerNode != null)
            return true;
    } catch (Err e) {
    }
    return false;
}
Also used : Sig(edu.mit.csail.sdg.ast.Sig) VisitQueryOnce(edu.mit.csail.sdg.ast.VisitQueryOnce) Field(edu.mit.csail.sdg.ast.Sig.Field) ExprCall(edu.mit.csail.sdg.ast.ExprCall) Err(edu.mit.csail.sdg.alloy4.Err) ProductType(edu.mit.csail.sdg.ast.Type.ProductType) ExprUnary(edu.mit.csail.sdg.ast.ExprUnary)

Aggregations

Err (edu.mit.csail.sdg.alloy4.Err)1 ExprCall (edu.mit.csail.sdg.ast.ExprCall)1 ExprUnary (edu.mit.csail.sdg.ast.ExprUnary)1 Sig (edu.mit.csail.sdg.ast.Sig)1 Field (edu.mit.csail.sdg.ast.Sig.Field)1 ProductType (edu.mit.csail.sdg.ast.Type.ProductType)1 VisitQueryOnce (edu.mit.csail.sdg.ast.VisitQueryOnce)1