choices.add(s);
for(Field f:s.getFields()) choices.add(f);
}
// find <instance>..</instance>
if (!xml.is("alloy")) throw new ErrorSyntax("The XML file's root node must be <alloy> or <instance>.");
XMLNode inst = null;
for(XMLNode sub: xml) if (sub.is("instance")) { inst=sub; break; }
if (inst==null) throw new ErrorSyntax("The XML file must contain an <instance> element.");
// set up the basic values of the A4Solution object
final int bitwidth = Integer.parseInt(inst.getAttribute("bitwidth"));
final int maxseq = Integer.parseInt(inst.getAttribute("maxseq"));
final int max = (1<<(bitwidth-1))-1, min = 0-(1<<(bitwidth-1));
if (bitwidth>=1 && bitwidth<=30) for(int i=min; i<=max; i++) { atoms.add(Integer.toString(i)); }
for(XMLNode x:inst) {
String id=x.getAttribute("ID");
if (id.length()>0 && (x.is("field") || x.is("skolem") || x.is("sig"))) {
if (nmap.put(id, x)!=null) throw new IOException("ID "+id+" is repeated.");
if (x.is("sig")) {
boolean isString = STRING.label.equals(label(x)) && yes(x, "builtin");
for(XMLNode y:x) if (y.is("atom")) {
String attr = y.getAttribute("label");
atoms.add(attr);
if (isString) strings.add(attr);
}
}
}
}
// create the A4Solution object
A4Options opt = new A4Options();
opt.originalFilename = inst.getAttribute("filename");
sol = new A4Solution(inst.getAttribute("command"), bitwidth, maxseq, strings, atoms, null, opt, 1);
factory = sol.getFactory();
// parse all the sigs, fields, and skolems
for(Map.Entry<String,XMLNode> e:nmap.entrySet()) if (e.getValue().is("sig")) parseSig(e.getKey(), 0);
for(Map.Entry<String,XMLNode> e:nmap.entrySet()) if (e.getValue().is("field")) parseField(e.getKey());
for(Map.Entry<String,XMLNode> e:nmap.entrySet()) if (e.getValue().is("skolem")) parseSkolem(e.getKey());