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

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


     */
    static Type make(List<PrimSig> list, int start, int end) {
        if (start<0 || end<0 || start>=end || end>list.size()) return EMPTY;
        PrimSig[] newlist = new PrimSig[end-start];
        for(int i=start, j=0; i<end; i++, j++) {
            PrimSig x=list.get(i);
            if (x==NONE) {
                for(i=0; i<newlist.length; i++) newlist[i]=x;
                break;
            }
            newlist[j]=x;
View Full Code Here


     * <br>   we change nothing, and simply return null
     *
     * <p><b>Precondition:</b> a[i] is not NONE, and a[i].parent is abstract, and a[i].parent!=UNIV
     */
    private static List<PrimSig> fold(ArrayList<List<PrimSig>> entries, List<PrimSig> a, int i) {
        PrimSig parent = a.get(i).parent;
        SafeList<PrimSig> children;
        try { children=parent.children(); } catch(Err ex) { return null; } // Exception only occurs if a[i].parent==UNIV
        List<PrimSig> subs = children.makeCopy();
        ArrayList<List<PrimSig>> toDelete = new ArrayList<List<PrimSig>>();
        for(int bi=entries.size()-1; bi>=0; bi--) {
            List<PrimSig> b=entries.get(bi);
            if (b.size() == a.size()) {
                for(int j=0; ;j++) {
                    if (j>=b.size()) {toDelete.add(b); subs.remove(b.get(i)); break;}
                    PrimSig bt1=a.get(j), bt2=b.get(j);
                    if (i==j && bt2.parent!=parent) break;
                    if (i!=j && bt2!=bt1) break;
                }
            }
        }
View Full Code Here

            List<PrimSig> x = Arrays.asList(xx.types);
            while(true) {
                int n = x.size();
                boolean changed = false;
                for(int i=0; i<n; i++) {
                    PrimSig bt = x.get(i);
                    if (bt.parent!=null && bt.parent!=UNIV && bt.parent.isAbstract!=null) {
                        List<PrimSig> folded = fold(e, x, i);
                        if (folded!=null) {x=folded; changed=true; i--;}
                    }
                }
View Full Code Here

            if (isEmpty()) return this;
            if (that.isEmpty()) return that;
            final int n = types.length;
            final PrimSig[] ans = new PrimSig[n];
            for(int i=0; i<n; i++) {
                PrimSig c = this.types[i].intersect(that.types[i]);
                if (c==NONE) { for(i=0; i<n; i++) { ans[i]=c; } break; }
                ans[i]=c;
            }
            return new ProductType(ans);
        }
View Full Code Here

         */
        ProductType join(ProductType that) {
            int left=types.length, right=that.types.length, n=left+right-2;
            if (left<=1 && right<=1) return zero; // We try to do the best we can, in the face of precondition violation
            if (n<0) throw new OutOfMemoryError(); // This means the addition overflowed!
            final PrimSig a=types[left-1], b=that.types[0], c=a.intersect(b);
            if (c==NONE) return new ProductType(n, c);
            final PrimSig[] types = new PrimSig[n];
            int j=0;
            for(int i=0; i<left-1; i++, j++) { types[j]=this.types[i]; }
            for(int i=1; i<right; i++, j++)  { types[j]=that.types[i]; }
View Full Code Here

    public static Map<String,PrimSig> atom2sig(A4Solution solution) throws Err {
       Map<String,PrimSig> map = new HashMap<String,PrimSig>();
       for(Sig s: solution.getAllReachableSigs()) if (s instanceof PrimSig) for(A4Tuple t: (A4TupleSet) solution.eval(s)) {
          // We skip over SubsetSig and only care about PrimSig
          String atom = t.atom(0);
          PrimSig old = map.get(atom);
          if (old==null || ((PrimSig)s).isSameOrDescendentOf(old)) { map.put(atom, (PrimSig)s); }
       }
       return map;
    }
View Full Code Here

    /** Returns the short unique name corresponding to the given atom if the problem is solved and is satisfiable; else returns atom.toString(). */
    String atom2name(Object atom) { String ans=atom2name.get(atom); return ans==null ? atom.toString() : ans; }

    /** Returns the most specific sig corresponding to the given atom if the problem is solved and is satisfiable; else returns UNIV. */
    PrimSig atom2sig(Object atom) { PrimSig sig=atom2sig.get(atom); return sig==null ? UNIV : sig; }
View Full Code Here

          case 44: // Typescope ::= TypeNumber STRING
            {
              CommandScope RESULT =null;
        CommandScope a = (CommandScope)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.elementAt(CUP$CompParser$top-1)).value;
        Pos b = (Pos)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;
         RESULT = new CommandScope(a.pos.merge(b), new PrimSig("String", AttrType.WHERE.make(a.pos.merge(b))), a.isExact, a.startingScope, a.endingScope, a.increment);
              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Typescope",71, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 43: // Typescope ::= TypeNumber UNIV
            {
              CommandScope RESULT =null;
        CommandScope e = (CommandScope)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.elementAt(CUP$CompParser$top-1)).value;
        Pos f = (Pos)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;
         if (1==1) throw new ErrorSyntax(e.pos.merge(f), "You cannot set a scope on univ.");
              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Typescope",71, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 42: // Typescope ::= TypeNumber SEQ
            {
              CommandScope RESULT =null;
        CommandScope a = (CommandScope)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.elementAt(CUP$CompParser$top-1)).value;
        Pos b = (Pos)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;

   Pos p = a.pos.merge(b);
   if (a.endingScope>a.startingScope) throw new ErrorSyntax(p, "Cannot specify a growing scope for \"seq\"");
   if (a.isExact) throw new ErrorSyntax(p, "The exactly keyword is redundant here since the number of sequence index has to be exact.");
   RESULT = new CommandScope(p, new PrimSig("seq", AttrType.WHERE.make(p)), a.isExact, a.startingScope, a.startingScope, 1);

              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Typescope",71, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 41: // Typescope ::= TypeNumber INT
            {
              CommandScope RESULT =null;
        CommandScope a = (CommandScope)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.elementAt(CUP$CompParser$top-1)).value;
        Pos b = (Pos)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;

   Pos p = a.pos.merge(b);
   if (a.endingScope>a.startingScope) throw new ErrorSyntax(p, "Cannot specify a growing scope for \"int\"");
   if (a.isExact) throw new ErrorSyntax(p, "The exactly keyword is redundant here since the integer bitwidth must be exact.");
   RESULT = new CommandScope(p, new PrimSig("int", AttrType.WHERE.make(p)), a.isExact, a.startingScope, a.startingScope, 1);

              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Typescope",71, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 40: // Typescope ::= TypeNumber Name
            {
              CommandScope RESULT =null;
        CommandScope a = (CommandScope)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.elementAt(CUP$CompParser$top-1)).value;
        ExprVar b = (ExprVar)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;

   nod(b);
   RESULT = new CommandScope(a.pos.merge(b.pos), new PrimSig(b.label, AttrType.WHERE.make(a.pos.merge(b.pos))), a.isExact, a.startingScope, a.endingScope, a.increment);

              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Typescope",71, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 39: // Typescopes ::= Typescopes COMMA Typescope
            {
              List<CommandScope> RESULT =null;
        List<CommandScope> a = (List<CommandScope>)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.elementAt(CUP$CompParser$top-2)).value;
        CommandScope b = (CommandScope)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;
         RESULT=a; a.add(b);
              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Typescopes",72, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 38: // Typescopes ::= Typescope
            {
              List<CommandScope> RESULT =null;
        CommandScope a = (CommandScope)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;
         RESULT=new ArrayList<CommandScope>(); RESULT.add(a);
              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Typescopes",72, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 37: // Scope ::=
            {
              List<CommandScope> RESULT =null;
         RESULT=new ArrayList<CommandScope>();
              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Scope",59, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 36: // Scope ::= FOR Typescopes
            {
              List<CommandScope> RESULT =null;
        List<CommandScope> b = (List<CommandScope>)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;
         RESULT=b;
              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Scope",59, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 35: // Scope ::= FOR NUMBER BUT Typescopes
            {
              List<CommandScope> RESULT =null;
        ExprConstant a = (ExprConstant)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.elementAt(CUP$CompParser$top-2)).value;
        List<CommandScope> b = (List<CommandScope>)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;
         RESULT=b;                                  b.add(new CommandScope(a.pos, new PrimSig("univ", AttrType.WHERE.make(a.pos)), true, a.num, a.num, 1));
              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Scope",59, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
          case 34: // Scope ::= FOR NUMBER
            {
              List<CommandScope> RESULT =null;
        ExprConstant a = (ExprConstant)((java_cup_11a.runtime.Symbol) CUP$CompParser$stack.peek()).value;
         RESULT=new ArrayList<CommandScope>(); RESULT.add(new CommandScope(a.pos, new PrimSig("univ", AttrType.WHERE.make(a.pos)), true, a.num, a.num, 1));
              CUP$CompParser$result = parser.getSymbolFactory().newSymbol("Scope",59, RESULT);
            }
          return CUP$CompParser$result;

          /*. . . . . . . . . . . . . . . . . . . .*/
 
View Full Code Here

    /** If A is not toplevel, and we haven't been able to derive its scope yet, then give it its parent's scope. */
    private boolean derive_scope_from_parent (Iterable<Sig> sigs) throws Err {
        boolean changed=false;
        Sig trouble=null;
        for(Sig s:sigs) if (!s.builtin && !s.isTopLevel() && sig2scope(s)<0 && (s instanceof PrimSig)) {
           PrimSig p = ((PrimSig)s).parent;
           int pb = sig2scope(p);
           if (pb>=0) {sig2scope(s,pb); changed=true;} else {trouble=s;}
        }
        if (changed) return true;
        if (trouble==null) return false;
View Full Code Here

   /** Construct an AlloySet or AlloyRelation corresponding to the given expression. */
   private void setOrRel(A4Solution sol, String label, Expr expr, boolean isPrivate, boolean isMeta) throws Err {
      for(List<PrimSig> ps:expr.type().fold()) {
         if (ps.size()==1) {
            PrimSig t = ps.get(0);
            AlloySet set = makeSet(label, isPrivate, isMeta, sig(t));
            sets.add(set);
            for(A4Tuple tp: (A4TupleSet)(sol.eval(expr.intersect(t)))) {
               atom2sets.get(string2atom.get(tp.atom(0))).add(set);
            }
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.