Examples of Sig


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

    /** Parse type. */
    private Expr parseType(XMLNode node) throws IOException, Err {
        Expr expr = null;
        if (!node.is("types")) throw new IOException("<types>...</type> expected");
        for(XMLNode n:node) if (n.is("type")) {
            Sig sig=parseSig(n.getAttribute("ID"), 0);
            if (expr==null) expr=sig; else expr=expr.product(sig);
        }
        if (expr==null) throw new IOException("<type ID=../> expected");
        return expr;
    }
View Full Code Here

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

       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))
              { field=f; choices.remove(f); break; }
       if (field==null) field = parent.addTrickyField(Pos.UNKNOWN, isPrivate, null, null, isMeta, new String[] {label}, UNIV.join(type)) [0];
       TupleSet ts = parseTuples(node, arity);
       expr2ts.put(field, ts);
       return field;
    }
View Full Code Here

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

    private void c(boolean follow, ExprVar o, ExprVar x, ExprVar n, Expr e, List<CommandScope> s, ExprConstant c) throws Err {
        if (n!=null) nod(n);
        int bitwidth=(-1), maxseq=(-1), overall=(-1), expects=(c==null ? -1 : c.num);
        Pos p = o.pos.merge(n!=null ? n.span() : e.span());
        for(int i=s.size()-1; i>=0; i--) {
          Sig j=s.get(i).sig;  int k=s.get(i).startingScope;
          p=p.merge(j.pos);
          if (j.label.equals("univ")) { overall=k; s.remove(i); continue; }
          if (j.label.equals("int"))  { if (bitwidth>=0) throw new ErrorSyntax(j.pos, "The bitwidth cannot be specified more than once."); bitwidth=k; s.remove(i); continue; }
          if (j.label.equals("seq"))  { if (maxseq>=0) throw new ErrorSyntax(j.pos, "The maximum sequence length cannot be specified more than once."); maxseq=k; s.remove(i); continue; }
        }
View Full Code Here

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

       boolean changed=false;
       again:
       for(Sig s:sigs) if (!s.builtin && (s instanceof PrimSig) && s.isAbstract!=null) {
          SafeList<PrimSig> subs = ((PrimSig)s).children();
          if (subs.size()==0) continue;
          Sig missing=null;
          int sum=0;
          for(Sig c:subs) {
             int cn = sig2scope(c);
             if (cn<0) { if (missing==null) { missing=c; continue; } else { continue again; } }
             sum=sum+cn;
View Full Code Here

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

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

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

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

    private ScopeComputer(A4Reporter rep, Iterable<Sig> sigs, Command cmd) throws Err {
        this.rep = rep;
        this.cmd = cmd;
        // Process each sig listed in the command
        for(CommandScope entry:cmd.scope) {
            Sig s = entry.sig;
            int scope = entry.startingScope;
            boolean exact = entry.isExact;
            if (s==UNIV) throw new ErrorSyntax(cmd.pos, "You cannot set a scope on \"univ\".");
            if (s==SIGINT) throw new ErrorSyntax(cmd.pos,
                    "You can no longer set a scope on \"Int\". "
                    +"The number of atoms in Int is always exactly equal to 2^(integer bitwidth).\n");
            if (s==SEQIDX) throw new ErrorSyntax(cmd.pos,
                    "You cannot set a scope on \"seq/Int\". "
                    +"To set the maximum allowed sequence length, use the seq keyword.\n");
            if (s==STRING) {
               if (maxstring>=0) throw new ErrorSyntax(cmd.pos, "Sig \"String\" already has a scope of "+maxstring+", so we cannot set it to be "+scope);
               if (!exact) throw new ErrorSyntax(cmd.pos, "Sig \"String\" must have an exact scope.");
               maxstring = scope;
               continue;
            }
            if (s==NONE) throw new ErrorSyntax(cmd.pos, "You cannot set a scope on \"none\".");
            if (s.isEnum!=null) throw new ErrorSyntax(cmd.pos, "You cannot set a scope on the enum \""+s.label+"\"");
            if (s.isOne!=null && scope!=1) throw new ErrorSyntax(cmd.pos,
                "Sig \""+s+"\" has the multiplicity of \"one\", so its scope must be 1, and cannot be "+scope);
            if (s.isLone!=null && scope>1) throw new ErrorSyntax(cmd.pos,
                "Sig \""+s+"\" has the multiplicity of \"lone\", so its scope must 0 or 1, and cannot be "+scope);
            if (s.isSome!=null && scope<1) throw new ErrorSyntax(cmd.pos,
                "Sig \""+s+"\" has the multiplicity of \"some\", so its scope must 1 or above, and cannot be "+scope);
            sig2scope(s, scope);
            if (exact) makeExact(cmd.pos, s);
        }
        // Force "one" sigs to be exactly one, and "lone" to be at most one
        for(Sig s:sigs) if (s instanceof PrimSig) {
            if (s.isOne!=null) { makeExact(cmd.pos, s); sig2scope(s,1); } else if (s.isLone!=null && sig2scope(s)!=0) sig2scope(s,1);
        }
        // Derive the implicit scopes
        while(true) {
            if (derive_abstract_scope(sigs))    { do {} while(derive_abstract_scope(sigs));     continue; }
            if (derive_overall_scope(sigs))     { do {} while(derive_overall_scope(sigs));      continue; }
            if (derive_scope_from_parent(sigs)) { do {} while(derive_scope_from_parent(sigs))continue; }
            break;
        }
        // Set the initial scope on "int" and "Int" and "seq"
        int maxseq=cmd.maxseq, bitwidth=cmd.bitwidth;
        if (bitwidth<0) bitwidth=4;
        setBitwidth(cmd.pos, bitwidth);
        if (maxseq<0) {
            if (cmd.overall>=0) maxseq=cmd.overall; else maxseq=4;
            int max = (1<<(bitwidth-1))-1;
            if (maxseq > max) maxseq = max;
        }
        setMaxSeq(cmd.pos, maxseq);
        // Generate the atoms and the universe
        for(Sig s:sigs) if (s.isTopLevel()) computeLowerBound((PrimSig)s);
        for(int max=max(), i=min(); i<=max; i++) atoms.add(""+i);
    }
View Full Code Here

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

      msg.append("\" is ambiguous.\n" + "There are ").append(objs.size()).append(" choices:");
      for(int i=0; i<objs.size(); i++) {
         msg.append("\n\n#").append(i+1).append(": ");
         Object x=objs.get(i);
         if (x instanceof Sig) {
            Sig y = (Sig)x; msg.append("sig ").append(y.label).append("\n"+"at ").append(y.pos.toShortString());
         }
         else if (x instanceof Func) {
            Func y = (Func)x;
            msg.append(y.isPred?"pred ":"fun ")
            .append(y.label).append("\n"+"at ").append(y.pos.toShortString());
View Full Code Here

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

   /** Lookup non-fully-qualified Sig/Func/Assertion from the current module; it skips PARAMs. */
   private List<Object> getRawNQS (CompModule start, final int r, String name) {
      // (r&1)!=0 => Sig,   (r&2) != 0 => assertion,   (r&4)!=0 => Func
      List<Object> ans=new ArrayList<Object>();
      for(CompModule m:getAllNameableModules()) {
         if ((r&1)!=0) { Sig x=m.sigs.get(name); if (x!=null) if (m==start || x.isPrivate==null) ans.add(x); }
         if ((r&2)!=0) { Expr x=m.asserts.get(name); if (x!=null) ans.add(x); }
         if ((r&4)!=0) { ArrayList<Func> x=m.funcs.get(name); if (x!=null) for(Func y:x) if (m==start || y.isPrivate==null) ans.add(y); }
      }
      return ans;
   }
View Full Code Here

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

      CompModule u=this;
      if (name.startsWith("this/")) name=name.substring(5);
      for(int level=0; ;level++) {
         int i=name.indexOf('/');
         if (i<0) {
            if ((r&1)!=0) { Sig x=u.sigs.get(name); if (x!=null) if (level==0 || x.isPrivate==null) ans.add(x); }
            if ((r&2)!=0) { Expr x=u.asserts.get(name); if (x!=null) ans.add(x); }
            if ((r&4)!=0) { ArrayList<Func> x=u.funcs.get(name); if (x!=null) for(Func y:x) if (level==0 || y.isPrivate==null) ans.add(y); }
            if (ans.size()==0) return u.getRawNQS(this,r,name); // If nothing at this module, then do a non-qualified search from this module
            return ans;
         }
View Full Code Here

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

   }

   /** Lookup a Sig from the current module (and it will also search this.params) */
   private Sig getRawSIG (Pos pos, String name) throws Err {
      List<Object> s;
      Sig s2=null;
      if (name.equals("sig$") || name.equals("field$")) if (world!=null) {
         s2 = world.sigs.get(name);
         if (s2!=null) return s2;
      }
      if (name.equals("univ"))       return UNIV;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.