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;
}
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;
}
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);
}
}
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;
}
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"));
}
Aggregations