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

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


         old2appendedfacts = new LinkedHashMap<Sig, Expr>();
         sig2module        = new HashMap<Sig, CompModule>();
         allModules        = new ArrayList<CompModule>();
         exactSigs         = new LinkedHashSet<Sig>();
         globals           = new LinkedHashMap<String,Expr>();
         metaSig           = new PrimSig("this/sig$", Attr.ABSTRACT, Attr.META);
         metaField         = new PrimSig("this/field$", Attr.ABSTRACT, Attr.META);
      } else {
         this.world        = world;
         new2old           = world.new2old;
         old2fields        = world.old2fields;
         old2appendedfacts = world.old2appendedfacts;
View Full Code Here


      }
      attributes = Util.append(attributes, exact ? Attr.EXACT : null);
      if (subset!=null) {
         attributes = Util.append(attributes, SUBSET.makenull(subset));
         List<Sig> newParents = new ArrayList<Sig>(parents==null ? 0 : parents.size());
         if (parents!=null) for(ExprVar p: parents) newParents.add(new PrimSig(p.label, WHERE.make(p.pos)));
         obj = new SubsetSig(full, newParents, attributes);
      } else {
         attributes = Util.append(attributes, SUBSIG.makenull(subsig));
         PrimSig newParent = (parents!=null && parents.size()>0) ? (new PrimSig(parents.get(0).label, WHERE.make(parents.get(0).pos))) : UNIV;
         obj = new PrimSig(full, newParent, attributes);
      }
      sigs.put(name, obj);
      old2fields.put(obj, fields);
      old2appendedfacts.put(obj, fact);
      return obj;
View Full Code Here

         Sig parentAST = u.getRawSIG(sup.pos, sup.label);
         if (parentAST==null) throw new ErrorSyntax(sup.pos, "The sig \""+sup.label+"\" cannot be found.");
         Sig parent = resolveSig(res, topo, parentAST);
         if (!(parent instanceof PrimSig)) throw new ErrorSyntax(sup.pos, "Cannot extend the subset signature \"" + parent
               + "\".\n" + "A signature can only extend a toplevel signature or a subsignature.");
         PrimSig p = (PrimSig)parent;
         realSig = new PrimSig(fullname, p, oldS.attributes.toArray(new Attr[0]));
      }
      res.new2old.put(realSig, oldS);
      res.sig2module.put(realSig, u);
      for(CompModule m: res.allModules) {
         for(Map.Entry<String,Sig> e: m.sigs.entrySet()) if (e.getValue()==oldS) e.setValue(realSig);
View Full Code Here

      Map<Field,PrimSig> field2meta = new LinkedHashMap<Field,PrimSig>();
      boolean hasMetaSig = false, hasMetaField = false;
      root.new2old.put(root.metaSig, root.metaSig);     root.sigs.put(base(root.metaSig), root.metaSig);
      root.new2old.put(root.metaField, root.metaField); root.sigs.put(base(root.metaField), root.metaField);
      for(CompModule m: root.allModules) for(Sig s: new ArrayList<Sig>(m.sigs.values())) if (m!=root || (s!=root.metaSig && s!=root.metaField)) {
         PrimSig ka = new PrimSig(s.label+"$", root.metaSig, Attr.ONE, PRIVATE.makenull(s.isPrivate), Attr.META);
         sig2meta.put(s, ka);
         ka.addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "value", s);
         m.new2old.put(ka, ka);
         m.sigs.put(base(ka), ka);
         hasMetaSig = true;
         Expr allfields = ExprConstant.EMPTYNESS;
         for(Field field: s.getFields()) {
            Pos priv = field.isPrivate; if (priv==null) priv = s.isPrivate;
            PrimSig kb = new PrimSig(s.label+"$"+field.label, root.metaField, Attr.ONE, PRIVATE.makenull(priv), Attr.META);
            field2meta.put(field, kb);
            m.new2old.put(kb, kb);
            m.sigs.put(base(kb), kb);
            hasMetaField = true;
            kb.addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "value", field);
            if (allfields==ExprConstant.EMPTYNESS) allfields = kb; else allfields = allfields.plus(kb);
         }
         ka.addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "fields", allfields);
      }
      for(Map.Entry<Sig,PrimSig> e: sig2meta.entrySet()) {
         Expr expr = null;
         if ((e.getKey()) instanceof PrimSig) {
            PrimSig a = (PrimSig)(e.getKey());
            if (a.parent!=null && a.parent!=UNIV) expr = sig2meta.get(a.parent);
         }
         e.getValue().addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "parent", (expr==null ? ExprConstant.EMPTYNESS : expr));
      }
      for(Map.Entry<Sig,PrimSig> e: sig2meta.entrySet()) {
         Sig s = e.getKey();
         PrimSig s2 = e.getValue();
         Expr allfields = ExprConstant.EMPTYNESS;
         for(Field f: s.getFields()) {
            PrimSig metaF = field2meta.get(f);
            if (allfields==ExprConstant.EMPTYNESS) allfields = metaF; else allfields = allfields.plus(metaF);
         }
         if (s instanceof PrimSig) for(Sig c: (((PrimSig)s).descendents())) for(Field f: c.getFields()) {
            PrimSig metaF = field2meta.get(f);
            if (allfields==ExprConstant.EMPTYNESS) allfields = metaF; else allfields = allfields.plus(metaF);
         }
         s2.addDefinedField(Pos.UNKNOWN, null, Pos.UNKNOWN, "subfields", allfields);
      }
      if (hasMetaSig==false) root.facts.add(new Pair<String,Expr>("sig$fact", root.metaSig.no().and(root.metaField.no())));
View Full Code Here

              ExprList list = (ExprList)fact;
              if (list.op!=ExprList.Op.TOTALORDER || list.args.size()!=3) break;
              if (((ExprUnary)b1).op!=ExprUnary.Op.SETOF) break; else b1 = ((ExprUnary)b1).sub.deNOP();
              if (((ExprBinary)b2).op!=ExprBinary.Op.ARROW) break; else { b3 = ((ExprBinary)b2).right.deNOP(); b2 = ((ExprBinary)b2).left.deNOP(); }
              if (!(b1 instanceof PrimSig) || b1!=b2 || b1!=b3) break;
              PrimSig sub = (PrimSig)b1;
              Field f1 = s.getFields().get(0), f2 = s.getFields().get(1);
              if (sub.isEnum==null || !list.args.get(0).isSame(sub) || !list.args.get(1).isSame(s.join(f1)) || !list.args.get(2).isSame(s.join(f2))) break;
              // Now, we've confirmed it is a total ordering on an enum. Let's pre-bind the relations
              TupleSet me = sol.query(true, sol.a2k(s), false), firstTS = factory.noneOf(2), lastTS = null, nextTS = factory.noneOf(3);
              if (me.size()!=1 || me.arity()!=1) break;
              int n = sub.children().size();
              for(PrimSig c: sub.children()) {
                 TupleSet TS = sol.query(true, sol.a2k(c), false);
                 if (TS.size()!=1 || TS.arity()!=1) { firstTS=factory.noneOf(2); nextTS=factory.noneOf(3); break; }
                 if (lastTS==null) { firstTS=me.product(TS); lastTS=TS; continue; }
                 nextTS.addAll(me.product(lastTS).product(TS));
                 lastTS=TS;
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.