Search in sources :

Example 1 with XMLNode

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

the class A4SolutionReader method parseType.

/**
 * Parse type.
 */
private Expr parseType(XMLNode node) throws IOException, Err {
    Expr expr = null;
    if (!node.is("types"))
        throw new IOException("<types>...</type> expected");
    for (XMLNode n : node) if (n.is("type")) {
        Sig sig = parseSig(n.getAttribute("ID"), 0);
        if (expr == null)
            expr = sig;
        else
            expr = expr.product(sig);
    }
    if (expr == null)
        throw new IOException("<type ID=../> expected");
    return expr;
}
Also used : PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) SubsetSig(edu.mit.csail.sdg.ast.Sig.SubsetSig) Sig(edu.mit.csail.sdg.ast.Sig) Expr(edu.mit.csail.sdg.ast.Expr) XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) IOException(java.io.IOException)

Example 2 with XMLNode

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

the class A4SolutionReader method parseSkolem.

/**
 * Parse skolem.
 */
private ExprVar parseSkolem(String id) throws IOException, Err {
    final XMLNode node = nmap.get(id);
    if (node == null)
        throw new IOException("Unknown ID " + id + " encountered.");
    if (!node.is("skolem"))
        throw new IOException("ID " + id + " is not a skolem.");
    String label = label(node);
    Expr type = null;
    for (XMLNode sub : node) if (sub.is("types")) {
        Expr t = parseType(sub);
        if (type == null)
            type = t;
        else
            type = type.plus(t);
    }
    int arity;
    if (type == null || (arity = type.type().arity()) < 1)
        throw new IOException("Skolem " + label + " is maltyped.");
    ExprVar var = ExprVar.make(Pos.UNKNOWN, label, type.type());
    TupleSet ts = parseTuples(node, arity);
    expr2ts.put(var, ts);
    return var;
}
Also used : ExprVar(edu.mit.csail.sdg.ast.ExprVar) TupleSet(kodkod.instance.TupleSet) XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) Expr(edu.mit.csail.sdg.ast.Expr) IOException(java.io.IOException)

Example 3 with XMLNode

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

the class A4SolutionReader method parseTuple.

/**
 * Parse tuple.
 */
private Tuple parseTuple(XMLNode tuple, int arity) throws Err {
    Tuple ans = null;
    try {
        for (XMLNode sub : tuple) if (sub.is("atom")) {
            Tuple x = factory.tuple(sub.getAttribute("label"));
            if (ans == null)
                ans = x;
            else
                ans = ans.product(x);
        }
        if (ans == null)
            throw new ErrorFatal("Expecting: <tuple> <atom label=\"..\"/> .. </tuple>");
        if (ans.arity() != arity)
            throw new ErrorFatal("Expecting: tuple of arity " + arity + " but got tuple of arity " + ans.arity());
        return ans;
    } catch (Throwable ex) {
        throw new ErrorFatal("Expecting: <tuple> <atom label=\"..\"/> .. </tuple>", ex);
    }
}
Also used : ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) Tuple(kodkod.instance.Tuple)

Example 4 with XMLNode

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

the class A4SolutionReader method parseField.

/**
 * Parse field.
 */
private Field parseField(String id) throws IOException, Err {
    final XMLNode node = nmap.get(id);
    if (node == null)
        throw new IOException("Unknown FieldID " + id + " encountered.");
    if (!node.is("field"))
        throw new IOException("ID " + id + " is not a field.");
    String label = label(node);
    Pos isPrivate = yes(node, "private") ? Pos.UNKNOWN : null;
    Pos isMeta = yes(node, "meta") ? Pos.UNKNOWN : null;
    Expr type = null;
    for (XMLNode sub : node) if (sub.is("types")) {
        Expr t = parseType(sub);
        if (type == null)
            type = t;
        else
            type = type.plus(t);
    }
    int arity;
    if (type == null || (arity = type.type().arity()) < 2)
        throw new IOException("Field " + label + " is maltyped.");
    String parentID = node.getAttribute("parentID");
    Sig parent = id2sig.get(parentID);
    if (parent == null)
        throw new IOException("ID " + parentID + " is not a sig.");
    Field field = null;
    for (Field f : parent.getFields()) if (f.label.equals(label) && f.type().arity() == arity && choices.contains(f)) {
        field = f;
        choices.remove(f);
        break;
    }
    if (field == null)
        field = parent.addTrickyField(Pos.UNKNOWN, isPrivate, null, null, isMeta, new String[] { label }, UNIV.join(type))[0];
    TupleSet ts = parseTuples(node, arity);
    expr2ts.put(field, ts);
    return field;
}
Also used : PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) SubsetSig(edu.mit.csail.sdg.ast.Sig.SubsetSig) Sig(edu.mit.csail.sdg.ast.Sig) Field(edu.mit.csail.sdg.ast.Sig.Field) TupleSet(kodkod.instance.TupleSet) XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) Expr(edu.mit.csail.sdg.ast.Expr) Pos(edu.mit.csail.sdg.alloy4.Pos) IOException(java.io.IOException)

Example 5 with XMLNode

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

the class InternalTest method test3.

public void test3() throws Exception {
    XMLNode xml = new XMLNode(new StringReader("<alloy builddate='unknown'>" + "<instance bitwidth='2' maxseq='1' command='Run Deadlock' filename='dijkstra.als'>" + "<sig label='univ' ID='0' builtin='yes'> <atom label='-2'/> <atom label='-1'/> <atom label='0'/> <atom label='1'/> <atom label='State$0'/> <atom label='State$1'/> <atom label='State$2'/> </sig>" + "<sig label='Int' ID='1' parentID='0' builtin='yes'> <atom label='-2'/> <atom label='-1'/> <atom label='0'/> <atom label='1'/> </sig>" + "<sig label='seq/Int' ID='2' parentID='1' builtin='yes'> <atom label='0'/> </sig>" + "<sig label='State' ID='5' parentID='6'> <atom label='State$0'/> </sig>" + "<sig label='Mutex' ID='6' parentID='5'> <atom label='Mutex$0'/> </sig>" + "</instance>" + "</alloy>"));
    String err = "";
    try {
        A4SolutionReader.read(null, xml);
    } catch (Throwable ex) {
        err = ex.toString();
    }
    check(err.contains("cyclic inheritance"));
}
Also used : XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) StringReader(java.io.StringReader)

Aggregations

XMLNode (edu.mit.csail.sdg.alloy4.XMLNode)13 Expr (edu.mit.csail.sdg.ast.Expr)6 Sig (edu.mit.csail.sdg.ast.Sig)6 StringReader (java.io.StringReader)5 A4Solution (edu.mit.csail.sdg.translator.A4Solution)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ExprVar (edu.mit.csail.sdg.ast.ExprVar)3 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)3 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)3 TupleSet (kodkod.instance.TupleSet)3 SafeList (edu.mit.csail.sdg.alloy4.SafeList)2 Command (edu.mit.csail.sdg.ast.Command)2 Module (edu.mit.csail.sdg.ast.Module)2 Field (edu.mit.csail.sdg.ast.Sig.Field)2 A4Options (edu.mit.csail.sdg.translator.A4Options)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)1