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

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


  }

  private PackageDeclaration getPackage(String classId) {
    PackageDeclaration result = ast.newPackageDeclaration();

    Sig classSig = getSig("Class");
    SafeList<Field> cFields = classSig.getFields();
    Field packageRelations = getField("package", cFields);
    Map<String, List<String>> r = getRelations(packageRelations);

    String packageName = r.get(classId).get(0);
View Full Code Here


    return result;
  }

  private Sig getSig(String s) {
    Sig result = null;

    SafeList<Sig> sigs = ans.getAllReachableSigs();

    for (Sig sig : sigs) {
      String sigName = removeCrap(sig.toString());
View Full Code Here

      }
    };
  }
 
  protected Sig createSigByName(String name) {
    Sig result = null;
    for (Sig sig : javaMetamodel.getAllReachableSigs()) {
      String label = sig.label.replaceAll("[^/]*/", "");
      if (label.equals(name))
        result = sig;
    }
View Full Code Here

  private ConstList<CommandScope> createScopeList() throws ErrorSyntax {

    List<CommandScope> result = new ArrayList<CommandScope>();

    Sig type = createSigByName("Class");
    Sig method = createSigByName("Method");
    Sig methodId = createSigByName("MethodId");
    Sig classId = createSigByName("ClassId");
    Sig package_ = createSigByName("Package");
    Sig body = createSigByName("Body");
    Sig field = createSigByName("Field");
    Sig fieldId = createSigByName("FieldId");

    CommandScope packageScope = new CommandScope(package_,
        isExactMaxPackages, maxPackages);
    result.add(packageScope);
View Full Code Here

        return ans;
    }

    /** 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; }
           if (ans==null) {
View Full Code Here

    /** 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

       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

    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

       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

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

    /** 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

TOP

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

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.