Search in sources :

Example 71 with Err

use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.

the class CompModule method rejectNameClash.

// ============================================================================================================================//
private static void rejectNameClash(final List<CompModule> modules) throws Err {
    // The Alloy language forbids two overlapping sigs from having fields
    // with the same name.
    // In other words: if 2 fields have the same name, then their type's
    // first column must not intersect.
    final Map<String, List<Field>> fieldname2fields = new LinkedHashMap<String, List<Field>>();
    for (CompModule m : modules) {
        for (Sig sig : m.sigs.values()) {
            for (Field field : sig.getFields()) {
                List<Field> peers = fieldname2fields.get(field.label);
                if (peers == null) {
                    peers = new ArrayList<Field>();
                    fieldname2fields.put(field.label, peers);
                }
                for (Field field2 : peers) if (field.type().firstColumnOverlaps(field2.type()))
                    throw new ErrorType(field.pos, "Two overlapping signatures cannot have\n" + "two fields with the same name \"" + field.label + "\":\n\n1) one is in sig \"" + field.sig + "\"\n" + field.pos + "\n\n2) the other is in sig \"" + field2.sig + "\"\n" + field2.pos);
                peers.add(field);
            }
        }
    }
}
Also used : PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) Sig(edu.mit.csail.sdg.ast.Sig) SubsetSig(edu.mit.csail.sdg.ast.Sig.SubsetSig) Field(edu.mit.csail.sdg.ast.Sig.Field) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Util.asList(edu.mit.csail.sdg.alloy4.Util.asList) SafeList(edu.mit.csail.sdg.alloy4.SafeList) TempList(edu.mit.csail.sdg.alloy4.ConstList.TempList) List(java.util.List) ExprList(edu.mit.csail.sdg.ast.ExprList) ArrayList(java.util.ArrayList) JoinableList(edu.mit.csail.sdg.alloy4.JoinableList) ConstList(edu.mit.csail.sdg.alloy4.ConstList) LinkedHashMap(java.util.LinkedHashMap)

Example 72 with Err

use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.

the class ScopeComputer method sig2scope.

/**
 * Sets the scope for a sig; returns true iff the sig's scope is changed by this
 * call.
 */
private void sig2scope(Sig sig, int newValue) throws Err {
    if (sig.builtin)
        throw new ErrorSyntax(cmd.pos, "Cannot specify a scope for the builtin signature \"" + sig + "\"");
    if (!(sig instanceof PrimSig))
        throw new ErrorSyntax(cmd.pos, "Cannot specify a scope for a subset signature \"" + sig + "\"");
    if (newValue < 0)
        throw new ErrorSyntax(cmd.pos, "Cannot specify a negative scope for sig \"" + sig + "\"");
    int old = sig2scope(sig);
    if (old == newValue)
        return;
    if (old >= 0)
        throw new ErrorSyntax(cmd.pos, "Sig \"" + sig + "\" already has a scope of " + old + ", so we cannot set it to be " + newValue);
    sig2scope.put((PrimSig) sig, newValue);
    rep.scope("Sig " + sig + " scope <= " + newValue + "\n");
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig)

Example 73 with Err

use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.

the class ScopeComputer method derive_scope_from_parent.

// ===========================================================================================================================//
/**
 * If A is not toplevel, and we haven't been able to derive its scope yet, then
 * give it its parent's scope.
 */
private boolean derive_scope_from_parent(Iterable<Sig> sigs) throws Err {
    boolean changed = false;
    Sig trouble = null;
    for (Sig s : sigs) if (!s.builtin && !s.isTopLevel() && sig2scope(s) < 0 && (s instanceof PrimSig)) {
        PrimSig p = ((PrimSig) s).parent;
        int pb = sig2scope(p);
        if (pb >= 0) {
            sig2scope(s, pb);
            changed = true;
        } else {
            trouble = s;
        }
    }
    if (changed)
        return true;
    if (trouble == null)
        return false;
    throw new ErrorSyntax(cmd.pos, "You must specify a scope for sig \"" + trouble + "\"");
}
Also used : PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) Sig(edu.mit.csail.sdg.ast.Sig) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig)

Example 74 with Err

use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.

the class ScopeComputer method derive_overall_scope.

// ===========================================================================================================================//
/**
 * If A is toplevel, and we haven't been able to derive its scope yet, then let
 * it get the "overall" scope.
 */
private boolean derive_overall_scope(Iterable<Sig> sigs) throws Err {
    boolean changed = false;
    final int overall = (cmd.overall < 0 && cmd.scope.size() == 0) ? 3 : cmd.overall;
    for (Sig s : sigs) if (!s.builtin && s.isTopLevel() && sig2scope(s) < 0) {
        if (s.isEnum != null) {
            sig2scope(s, 0);
            continue;
        }
        // enum without children should get the empty set
        if (overall < 0)
            throw new ErrorSyntax(cmd.pos, "You must specify a scope for sig \"" + s + "\"");
        sig2scope(s, overall);
        changed = true;
    }
    return changed;
}
Also used : PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) Sig(edu.mit.csail.sdg.ast.Sig) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax)

Example 75 with Err

use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.

the class TranslateAlloyToKodkod method execute_command.

/**
 * Based on the specified "options", execute one command and return the
 * resulting A4Solution object.
 *
 * @param rep - if nonnull, we'll send compilation diagnostic messages to it
 * @param sigs - the list of sigs; this list must be complete
 * @param cmd - the Command to execute
 * @param opt - the set of options guiding the execution of the command
 * @return null if the user chose "save to FILE" as the SAT solver, and nonnull
 *         if the solver finishes the entire solving and is either satisfiable
 *         or unsatisfiable.
 *         <p>
 *         If the return value X is satisfiable, you can call X.next() to get
 *         the next satisfying solution X2; and you can call X2.next() to get
 *         the next satisfying solution X3... until you get an unsatisfying
 *         solution.
 */
public static A4Solution execute_command(A4Reporter rep, Iterable<Sig> sigs, Command cmd, A4Options opt) throws Err {
    if (rep == null)
        rep = A4Reporter.NOP;
    TranslateAlloyToKodkod tr = null;
    try {
        if (cmd.parent != null || !cmd.getGrowableSigs().isEmpty())
            return execute_greedyCommand(rep, sigs, cmd, opt);
        tr = new TranslateAlloyToKodkod(rep, opt, sigs, cmd);
        tr.makeFacts(cmd.formula);
        return tr.frame.solve(rep, cmd, new Simplifier(), false);
    } catch (UnsatisfiedLinkError ex) {
        throw new ErrorFatal("The required JNI library cannot be found: " + ex.toString().trim(), ex);
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        Pos p = tr != null ? tr.frame.kv2typepos(ex.decl().variable()).b : Pos.UNKNOWN;
        throw new ErrorType(p, "Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        else
            throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
    }
}
Also used : CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) Pos(edu.mit.csail.sdg.alloy4.Pos) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException)

Aggregations

ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)32 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)28 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)27 Err (edu.mit.csail.sdg.alloy4.Err)25 Expr (edu.mit.csail.sdg.ast.Expr)25 Sig (edu.mit.csail.sdg.ast.Sig)24 Pos (edu.mit.csail.sdg.alloy4.Pos)16 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)15 ExprVar (edu.mit.csail.sdg.ast.ExprVar)15 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)15 ArrayList (java.util.ArrayList)15 Field (edu.mit.csail.sdg.ast.Sig.Field)12 LinkedHashMap (java.util.LinkedHashMap)10 IOException (java.io.IOException)9 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)8 Func (edu.mit.csail.sdg.ast.Func)8 TupleSet (kodkod.instance.TupleSet)8 Command (edu.mit.csail.sdg.ast.Command)7 ErrorAPI (edu.mit.csail.sdg.alloy4.ErrorAPI)6 XMLNode (edu.mit.csail.sdg.alloy4.XMLNode)5