Package edu.mit.csail.sdg.alloy4compiler.ast.Sig

Examples of edu.mit.csail.sdg.alloy4compiler.ast.Sig.PrimSig


           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; }
           if (ans==null) {
              ans = new PrimSig(label, (PrimSig)parent, isAbstract, isLone, isOne, isSome, isPrivate, isMeta, isEnum);
              allsigs.add(ans);
           }
        } else {
           for(Expr choice:choices)
              if (choice instanceof SubsetSig && ((Sig)choice).label.equals(label) && sameset(parents, ((SubsetSig)choice).parents))
View Full Code Here


        }
        case JOIN: {
           if (warns!=null && type.hasNoTuple()) w=warn("The join operation here always yields an empty set.");
           a=(b=EMPTY);
           for (ProductType aa: left.type) for (ProductType bb: right.type) if (p.hasArity(aa.arity()+bb.arity()-2)) {
              PrimSig j = aa.get(aa.arity()-1).intersect(bb.get(0));
              if (j != Sig.NONE) for (ProductType cc:p.intersect(aa.join(bb))) if (!cc.isEmpty()) {
                 List<PrimSig> v = new ArrayList<PrimSig>(cc.arity() + 1);
                 for(int i=0; i<cc.arity(); i++) v.add(cc.get(i));
                 v.add(aa.arity()-1, j);
                 a = a.merge(Type.make(v, 0, aa.arity()));
View Full Code Here

     * @throws ErrorAPI if attempting to add an atom to an abstract sig with children, or a builtin sig, or a subset sig.
     */
    public SimAtom makeAtom(Sig sig) throws Err {
        if (sig.builtin) throw new ErrorAPI("Cannot add an atom to a builtin sig.");
        if (!(sig instanceof PrimSig)) throw new ErrorAPI("Cannot add an atom to a subset sig.");
        PrimSig s = (PrimSig)sig;
        if (s.isAbstract!=null && !s.children().isEmpty()) throw new ErrorAPI("Cannot add an atom to an abstract parent sig.");
        String label = sig.label + "$";
        if (label.startsWith("this/")) label=label.substring(5);
        for(int i=0; ;i++) {
          SimAtom atom = SimAtom.make(label + i);
          if (hasAtom(atom)) continue;
View Full Code Here

                   if (!equal(s, sum)) return "Sig "+s+" must be equal to the union of its parents "+p.parents;
                } else {
                   if (!isIn(s, sum)) return "Sig "+s+" must be equal or subset of its parents "+p.parents;
                }
             } else if (s != Sig.UNIV && s != Sig.NONE) {
                PrimSig p = (PrimSig)s;
                if (!isIn(s, p.parent)) return "Sig "+s+" must be equal or subset of its parent "+p.parent;
             }
             if (s.isAbstract!=null) {
                Expr sum = null;
                for(Sig x: ((PrimSig)s).children()) sum = x.plus(sum);
View Full Code Here

    private static Type resolveClosure (Type parent, Type child) {
        LinkedHashSet<PrimSig> nodes = new LinkedHashSet<PrimSig>();
        DirectedGraph<PrimSig> graph = new DirectedGraph<PrimSig>();
        // For each (v1->v2) in childType, add (v1->v2) into the graph.
        for (ProductType c:child) if (c.arity()==2) {
            PrimSig a=c.get(0), b=c.get(1);
            nodes.add(a);
            nodes.add(b);
            graph.addEdge(a,b);
        }
        // For each distinct v1 and v2 in the graph where v1&v2!=empty, add the edges v1->v2 and v2->v1.
        for (PrimSig a:nodes) for (PrimSig b:nodes) if (a!=b && a.intersects(b)) graph.addEdge(a,b);
        // For each a->b in ParentType:
        // 1) add a
        // 2) add b
        // 3) if a has subtypes/supertypes in the graph, connect between a and them.
        // 4) if b has subtypes/supertypes in the graph, connect between b and them.
        for (ProductType p:parent) if (p.arity()==2) {
            PrimSig a=p.get(0), b=p.get(1);
            // Add edges between a and all its subtypes and supertypes
            if (!nodes.contains(a)) {
                for (PrimSig x:nodes) if (a.intersects(x)) { graph.addEdge(a,x); graph.addEdge(x,a); }
                nodes.add(a);
            }
            // Add edges between b and all its subtypes and supertypes
            if (!nodes.contains(b)) {
                for (PrimSig x:nodes) if (b.intersects(x)) { graph.addEdge(b,x); graph.addEdge(x,b); }
                nodes.add(b);
            }
        }
        // For each c1->c2 in childType, add c1->c2 into the finalType if there exists p1->p2 in parentType
        // such that p1->..->c1->c2->..->p2 is a path in the graph.
        Type answer=Type.EMPTY;
        for (ProductType c:child) if (c.arity()==2) {
            PrimSig c1=c.get(0), c2=c.get(1);
            for (ProductType p:parent) if (p.arity()==2) {
                PrimSig p1=p.get(0), p2=p.get(1);
                if (graph.hasPath(p1,c1) && graph.hasPath(c2,p2)) { answer=answer.merge(c); break; }
            }
        }
        return answer;
    }
View Full Code Here

    /* Helper methods to simplify using the API for this example. */

    Set<Sig> sigs = new LinkedHashSet<Sig>();

    PrimSig makeSig(String name, boolean isAbstract, boolean isOne) throws Err {
        PrimSig ans = new PrimSig(name, (isAbstract ? Attr.ABSTRACT : null), (isOne ? Attr.ONE : null));
        sigs.add(ans);
        return ans;
    }
View Full Code Here

        sigs.add(ans);
        return ans;
    }

    PrimSig makeSig(PrimSig parent, String name, boolean isAbstract, boolean isOne) throws Err {
        PrimSig ans = new PrimSig(name, parent, (isAbstract ? Attr.ABSTRACT : null), (isOne ? Attr.ONE : null));
        sigs.add(ans);
        return ans;
    }
View Full Code Here

        // F1.parent = D1
        // F2.parent = D2
        // F3.parent = D2
        // D2.parent = D1
        // D1.parent = Root
        PrimSig file1 = makeSig(file, "F1", false, true);
        PrimSig file2 = makeSig(file, "F2", false, true);
        PrimSig file3 = makeSig(file, "F3", false, true);
        PrimSig dir1 = makeSig(dir, "D1", false, true);
        PrimSig dir2 = makeSig(dir, "D2", false, true);
        fact = file1.join(parent).equal(dir1).and(fact);
        fact = file2.join(parent).equal(dir2).and(fact);
        fact = file3.join(parent).equal(dir2).and(fact);
        fact = dir2.join(parent).equal(dir1).and(fact);
        fact = dir1.join(parent).equal(root).and(fact);
    }
View Full Code Here

    void makeInstance2() throws Err {
        // dir = Root, D1, D2
        // D2.parent = D1
        // D1.parent = D2
        PrimSig dir1 = makeSig(dir, "D1", false, true);
        PrimSig dir2 = makeSig(dir, "D2", false, true);
        fact = dir2.join(parent).equal(dir1).and(fact);
        fact = dir1.join(parent).equal(dir2).and(fact);
    }
View Full Code Here

        // Chooses the Alloy4 options
        A4Options opt = new A4Options();
        opt.solver = A4Options.SatSolver.SAT4J;

        // abstract sig A {}
        PrimSig A = new PrimSig("A", Attr.ABSTRACT);

        // sig B {}
        PrimSig B = new PrimSig("B");

        // one sig A1 extends A {}
        PrimSig A1 = new PrimSig("A1", A, Attr.ONE);

        // one sig A2 extends A {}
        PrimSig A2 = new PrimSig("A2", A, Attr.ONE);

        // A { f: B lone->lone B }
        Expr f = A.addField("f", B.lone_arrow_lone(B));
        // Since (B lone->lone B) is not unary,  the default is "setOf",  meaning "f:set (B lone->lone B)"
View Full Code Here

TOP

Related Classes of edu.mit.csail.sdg.alloy4compiler.ast.Sig.PrimSig

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.