Search in sources :

Example 21 with Err

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

the class A4SolutionWriter method writeSkolem.

/**
 * Write the given Skolem.
 */
private void writeSkolem(ExprVar x) throws Err {
    try {
        if (sol == null)
            // when writing a metamodel, skip the skolems
            return;
        if (x.type().hasNoTuple())
            // we do not allow "none" in the XML file's type
            return;
        // declarations
        StringBuilder sb = new StringBuilder();
        Util.encodeXMLs(sb, "\n<skolem label=\"", x.label, "\" ID=\"", map(x), "\">\n");
        if (writeExpr(sb.toString(), x)) {
            out.print("</skolem>\n");
        }
    } catch (Throwable ex) {
        throw new ErrorFatal("Error evaluating skolem " + x.label, ex);
    }
}
Also used : ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal)

Example 22 with Err

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

the class Type method toExpr.

/**
 * Convert this type into a UNION of PRODUCT of sigs.
 *
 * @throws ErrorType if it does not contain exactly one arity
 * @throws ErrorType if is_int is true
 * @throws ErrorType if is_bool is true
 */
public Expr toExpr() throws Err {
    int arity = arity();
    if (is_bool || arity < 1)
        throw new ErrorType("Cannot convert this type into a bounding expression.");
    Expr ans = null;
    for (ProductType pt : this) {
        Expr pro = null;
        for (int i = 0; i < arity; i++) if (pro == null)
            pro = pt.types[i];
        else
            pro = pro.product(pt.types[i]);
        if (ans == null)
            ans = pro;
        else
            ans = ans.plus(pro);
    }
    return ans;
}
Also used : ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 23 with Err

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

the class CompLexer method alloy_num.

private final Symbol alloy_num(String txt) throws Err {
    Pos p = alloy_here(txt);
    int n = 0;
    try {
        txt = txt.replaceAll("_", "");
        n = Integer.parseInt(txt);
    } catch (NumberFormatException ex) {
        throw new ErrorSyntax(p, "The number " + txt + " " + ex);
    }
    return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Pos(edu.mit.csail.sdg.alloy4.Pos) Symbol(java_cup.runtime.Symbol)

Example 24 with Err

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

the class CompLexer method alloy_hexnum.

private final Symbol alloy_hexnum(String txt) throws Err {
    Pos p = alloy_here(txt);
    int n = 0;
    try {
        txt = txt.substring(2).replaceAll("_", "");
        n = Integer.parseInt(txt, 16);
    } catch (NumberFormatException ex) {
        throw new ErrorSyntax(p, "The hex number " + txt + " " + ex);
    }
    return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Pos(edu.mit.csail.sdg.alloy4.Pos) Symbol(java_cup.runtime.Symbol)

Example 25 with Err

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

the class CompModule method resolveMeta.

// ============================================================================================================================//
private static void resolveMeta(final CompModule root) throws Err {
    // Now, add the meta sigs and fields if needed
    Map<Sig, PrimSig> sig2meta = new LinkedHashMap<Sig, PrimSig>();
    Map<Field, PrimSig> field2meta = new LinkedHashMap<Field, PrimSig>();
    boolean hasMetaSig = false, hasMetaField = false;
    root.new2old.put(root.metaSig, root.metaSig);
    root.sigs.put(base(root.metaSig), root.metaSig);
    root.new2old.put(root.metaField, root.metaField);
    root.sigs.put(base(root.metaField), root.metaField);
    for (CompModule m : root.allModules) for (Sig s : new ArrayList<Sig>(m.sigs.values())) if (m != root || (s != root.metaSig && s != root.metaField)) {
        PrimSig ka = new PrimSig(s.label + "$", root.metaSig, Attr.ONE, PRIVATE.makenull(s.isPrivate), Attr.META);
        sig2meta.put(s, ka);
        ka.addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "value", s);
        m.new2old.put(ka, ka);
        m.sigs.put(base(ka), ka);
        hasMetaSig = true;
        Expr allfields = ExprConstant.EMPTYNESS;
        for (Field field : s.getFields()) {
            Pos priv = field.isPrivate;
            if (priv == null)
                priv = s.isPrivate;
            PrimSig kb = new PrimSig(s.label + "$" + field.label, root.metaField, Attr.ONE, PRIVATE.makenull(priv), Attr.META);
            field2meta.put(field, kb);
            m.new2old.put(kb, kb);
            m.sigs.put(base(kb), kb);
            hasMetaField = true;
            kb.addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "value", field);
            if (allfields == ExprConstant.EMPTYNESS)
                allfields = kb;
            else
                allfields = allfields.plus(kb);
        }
        ka.addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "fields", allfields);
    }
    for (Map.Entry<Sig, PrimSig> e : sig2meta.entrySet()) {
        Expr expr = null;
        if ((e.getKey()) instanceof PrimSig) {
            PrimSig a = (PrimSig) (e.getKey());
            if (a.parent != null && a.parent != UNIV)
                expr = sig2meta.get(a.parent);
        }
        e.getValue().addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "parent", (expr == null ? ExprConstant.EMPTYNESS : expr));
    }
    for (Map.Entry<Sig, PrimSig> e : sig2meta.entrySet()) {
        Sig s = e.getKey();
        PrimSig s2 = e.getValue();
        Expr allfields = ExprConstant.EMPTYNESS;
        for (Field f : s.getFields()) {
            PrimSig metaF = field2meta.get(f);
            if (allfields == ExprConstant.EMPTYNESS)
                allfields = metaF;
            else
                allfields = allfields.plus(metaF);
        }
        if (s instanceof PrimSig)
            for (Sig c : (((PrimSig) s).descendents())) for (Field f : c.getFields()) {
                PrimSig metaF = field2meta.get(f);
                if (allfields == ExprConstant.EMPTYNESS)
                    allfields = metaF;
                else
                    allfields = allfields.plus(metaF);
            }
        s2.addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "subfields", allfields);
    }
    if (hasMetaSig == false)
        root.facts.add(new Pair<String, Expr>("sig$fact", root.metaSig.no().and(root.metaField.no())));
    else if (hasMetaField == false)
        root.facts.add(new Pair<String, Expr>("sig$fact", root.metaField.no()));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) 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) Expr(edu.mit.csail.sdg.ast.Expr) Pos(edu.mit.csail.sdg.alloy4.Pos) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) Pair(edu.mit.csail.sdg.alloy4.Pair)

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