Package edu.mit.csail.sdg.alloy4

Examples of edu.mit.csail.sdg.alloy4.A4Reporter


    @Override public List<? extends Browsable> getSubnodes() {
        if (args.size()==0) {
            Expr b = fun.getBody();
            return Util.asList(make(b.pos(), b.span(), b.getDescription(), b.getSubnodes()));
        }
        Pos p = pos;
        if (p == Pos.UNKNOWN) p = span();
        Browsable f = make(p, p, (fun.isPred ? "<b>pred</b> " : "<b>fun</b> ")+fun.label , fun.getSubnodes());
        Browsable a = make(span(), span(), "<b>" + args.size() + " argument" + (args.size()==1 ? "</b>" : "s</b>"), args);
        return Util.asList(f, a);
    }
View Full Code Here


    //============================================================================================================//

    /** {@inheritDoc} */
    @Override public Pos span() {
        Pos p=span;
        if (p==null) {
            p=pos.merge(closingBracket);
            for(Expr a:args) p=p.merge(a.span());
            span=p;
        }
        return p;
    }
View Full Code Here

    /** Caches the span() result. */
    private Pos span = null;

    /** {@inheritDoc} */
    @Override public Pos span() {
        Pos p = span;
        if (p==null) span = (p = cond.span().merge(right.span()).merge(left.span()));
        return p;
    }
View Full Code Here

        try { throw new Exception(); } catch(Exception ex) { name = ex.getStackTrace()[1].getMethodName(); }
        Method[] methods = getClass().getDeclaredMethods();
        Method m=null;
        for(int i=0; i<methods.length; i++) if (methods[i].getName().equals(name)) { m=methods[i]; break; }
        final Method method=m;
        return new Runner() {
            private static final long serialVersionUID = 0;
            public void run() {
                try {
                    method.setAccessible(true);
                    method.invoke(SimpleGUI.this, new Object[]{});
View Full Code Here

        try { throw new Exception(); } catch(Exception ex) { name = ex.getStackTrace()[1].getMethodName(); }
        Method[] methods = getClass().getDeclaredMethods();
        Method m=null;
        for(int i=0; i<methods.length; i++) if (methods[i].getName().equals(name)) { m=methods[i]; break; }
        final Method method=m;
        return new Runner() {
            private static final long serialVersionUID = 0;
            public void run(Object arg) {
                try {
                    method.setAccessible(true);
                    method.invoke(SimpleGUI.this, new Object[]{arg});
View Full Code Here

    /** Parse sig/set. */
    private Sig parseSig(String id, int depth) throws IOException, Err {
        Sig ans = id2sig.get(id);
        if (ans!=null) return ans;
        XMLNode node = nmap.get(id);
        if (node==null) throw new IOException("Unknown SigID "+id+" encountered.");
        if (!node.is("sig")) throw new IOException("ID "+id+" is not a sig.");
        String label   = label(node);
        Attr isAbstract = yes(node,"abstract") ? Attr.ABSTRACT : null;
        Attr isOne      = yes(node,"one")      ? Attr.ONE      : null;
        Attr isLone     = yes(node,"lone")     ? Attr.LONE     : null;
        Attr isSome     = yes(node,"some")     ? Attr.SOME     : null;
        Attr isPrivate  = yes(node,"private"? Attr.PRIVATE  : null;
        Attr isMeta     = yes(node,"meta")     ? Attr.META     : null;
        Attr isEnum     = yes(node,"enum")     ? Attr.ENUM     : null;
        Attr isExact    = yes(node,"exact")    ? Attr.EXACT    : null;
        if (yes(node,"builtin")) {
           if (label.equals(UNIV.label))   { id2sig.put(id, UNIV);   return UNIV;   }
           if (label.equals(SIGINT.label)) { id2sig.put(id, SIGINT); return SIGINT; }
           if (label.equals(SEQIDX.label)) { id2sig.put(id, SEQIDX); return SEQIDX; }
           if (label.equals(STRING.label)) { id2sig.put(id, STRING); return STRING; }
           throw new IOException("Unknown builtin sig: "+label+" (id="+id+")");
        }
        if (depth > nmap.size()) throw new IOException("Sig "+label+" (id="+id+") is in a cyclic inheritance relationship.");
        List<Sig> parents = null;
        TupleSet ts = factory.noneOf(1);
        for(XMLNode sub:node) {
           if (sub.is("atom")) { ts.add(factory.tuple(sub.getAttribute("label"))); continue; }
           if (!sub.is("type")) continue;
           Sig parent = parseSig(sub.getAttribute("ID"), depth+1);
           if (parents==null) parents = new ArrayList<Sig>();
           parents.add(parent);
        }
        if (parents==null) {
           String parentID = node.getAttribute("parentID");
           Sig parent = parseSig(parentID, depth+1);
           if (!(parent instanceof PrimSig)) throw new IOException("Parent of sig "+label+" (id="+id+") must not be a subset sig.");
           for(Expr choice: choices)
              if (choice instanceof PrimSig && parent==((PrimSig)choice).parent && ((Sig)choice).label.equals(label))
                 { ans=(Sig)choice; choices.remove(choice); break; }
View Full Code Here

        return expr;
    }

    /** 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))
View Full Code Here

       return field;
    }

    /** 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.");
View Full Code Here

           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());
View Full Code Here

        }
    }

    /** Validate the given filename to see if it is a valid Alloy XML instance file. */
    private static void validate(String filename) throws Exception {
        A4SolutionReader.read(new ArrayList<Sig>(), new XMLNode(new File(filename))).toString();
        StaticInstanceReader.parseInstance(new File(filename));
    }
View Full Code Here

TOP

Related Classes of edu.mit.csail.sdg.alloy4.A4Reporter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.