Search in sources :

Example 11 with XMLNode

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

the class InternalTest method test1.

public void test1() 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='0'> <atom label='State$0'/> <atom label='State$1'/> <atom label='State$2'/> </sig>" + "<field label='len' parentID='5' ID='17'>" + "   <tuple> <atom label='State$1'/> <atom label='-2'/> </tuple>" + "   <tuple> <atom label='State$1'/> <atom label='-1'/> </tuple>" + "   <types> <type ID='5'/> <type ID='1'/> </types>" + "</field>" + "<skolem label='$Deadlock_s' ID='16'>" + "   <tuple> <atom label='State$0'/> </tuple>" + "   <types> <type ID='5'/> </types>" + "</skolem>" + "</instance>" + "</alloy>"));
    Sig state = new Sig.PrimSig("State");
    A4Solution sol = A4SolutionReader.read(Arrays.asList(state), xml);
    SafeList<ExprVar> skolems = new SafeList<ExprVar>(sol.getAllSkolems());
    check(skolems.size() == 1);
    check(skolems.get(0).label, "$Deadlock_s");
    check(skolems.get(0).type(), state.type());
    // 
    Sig state2 = new Sig.PrimSig("State");
    Field field2 = state2.addField("len", Sig.SIGINT);
    sol = A4SolutionReader.read(Arrays.asList(state2), xml);
    SafeList<ExprVar> skolems2 = new SafeList<ExprVar>(sol.getAllSkolems());
    check(skolems2.size() == 1);
    check(skolems2.get(0).label, "$Deadlock_s");
    check(skolems2.get(0).type(), state2.type());
    check("" + sol.eval(field2.cardinality()), "-2");
}
Also used : Sig(edu.mit.csail.sdg.ast.Sig) ExprVar(edu.mit.csail.sdg.ast.ExprVar) Field(edu.mit.csail.sdg.ast.Sig.Field) XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) SafeList(edu.mit.csail.sdg.alloy4.SafeList) StringReader(java.io.StringReader) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 12 with XMLNode

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

the class InternalTest method test2.

public void test2() throws Exception {
    test1();
    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='Act' ID='5' parentID='0'> <atom label='Act$0'/> <atom label='Act$1'/> <atom label='Act$2'/> </sig>" + "<skolem label='$x' ID='16'>" + "   <tuple> <atom label='0'/> <atom label='Act$1'/> </tuple>" + "   <types> <type ID='2'/> <type ID='5'/> </types>" + "</skolem>" + "</instance>" + "</alloy>"));
    Sig activity = new Sig.PrimSig("Act");
    A4Solution sol = A4SolutionReader.read(Arrays.asList(activity), xml);
    SafeList<ExprVar> skolems = new SafeList<ExprVar>(sol.getAllSkolems());
    check(skolems.size() == 1);
    check(skolems.get(0).label, "$x");
    check(skolems.get(0).type(), Sig.SEQIDX.type().product(activity.type()));
}
Also used : Sig(edu.mit.csail.sdg.ast.Sig) ExprVar(edu.mit.csail.sdg.ast.ExprVar) XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) SafeList(edu.mit.csail.sdg.alloy4.SafeList) StringReader(java.io.StringReader) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 13 with XMLNode

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

the class SimpleCLI method validate.

private static void validate(A4Solution sol) throws Exception {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    sol.writeXML(pw, null, null);
    pw.flush();
    sw.flush();
    String txt = sw.toString();
    A4SolutionReader.read(new ArrayList<Sig>(), new XMLNode(new StringReader(txt))).toString();
    StaticInstanceReader.parseInstance(new StringReader(txt));
}
Also used : StringWriter(java.io.StringWriter) XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) PrintWriter(java.io.PrintWriter)

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