Package edu.mit.csail.sdg.alloy4

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax


      }
   }

   /** Add an OPEN declaration. */
   void addOpen(Pos pos, Pos isPrivate, ExprVar name, List<ExprVar> args, ExprVar alias) throws Err {
      if (status>2) throw new ErrorSyntax(pos, "The \"open\" declaration must occur before any\n" + "sig/pred/fun/fact/assert/check/run command.");
      String as = (alias==null ? "" : alias.label);
      if (name.label.length()==0) throw new ErrorSyntax(name.span(), "The filename cannot be empty.");
      if (as.indexOf('$')>=0) throw new ErrorSyntax(alias==null ? null : alias.span(), "Alias must not contain the \'$\' character");
      if (as.indexOf('@')>=0) throw new ErrorSyntax(alias==null ? null : alias.span(), "Alias must not contain the \'@\' character");
      if (as.indexOf('/')>=0) throw new ErrorSyntax(alias==null ? null : alias.span(), "Alias must not contain the \'/\' character");
      if (as.length()==0) {
         as="open$"+(1+opens.size());
         if (args==null || args.size()==0) {
            for(int i=0; ; i++) {
               if (i>=name.label.length()) { as=name.label; break; }
               char c=name.label.charAt(i);
               if ((c>='a' && c<='z') || (c>='A' && c<='Z')) continue;
               if (i==0) break;
               if (!(c>='0' && c<='9') && c!='_' && c!='\'' && c!='\"') break;
            }
         }
      }
      final TempList<String> newlist = new TempList<String>(args==null ? 0 : args.size());
      if (args!=null) for(int i=0; i<args.size(); i++) {
         ExprVar arg=args.get(i);
         if (arg.label.length()==0)      throw new ErrorSyntax(arg.span(), "Argument cannot be empty.");
         if (arg.label.indexOf('@')>=0throw new ErrorSyntax(arg.span(), "Argument cannot contain the \'@\' chracter.");
         newlist.add(arg.label);
      }
      Open x = opens.get(as);
      if (x!=null) {
         // we allow this, especially because of util/sequniv
         if (x.args.equals(newlist.makeConst()) && x.filename.equals(name.label)) return;
         throw new ErrorSyntax(pos, "You cannot import two different modules\n" + "using the same alias.");
      }
      x = new Open(pos, isPrivate!=null, as, newlist.makeConst(), name.label);
      opens.put(as, x);
   }
View Full Code Here


         Open missing=null;
         String missingName="";
         for(CompModule mod: modules) for(Open open: mod.opens.values()) {
            CompModule sub = open.realModule;
            if (open.args.size()!=sub.params.size())
               throw new ErrorSyntax(open.pos,
                     "You supplied "+open.args.size()+" arguments to the open statement, but the imported module requires "
                     +sub.params.size()+" arguments.");
            int i=0;
            for(Map.Entry<String,Sig> p: sub.params.entrySet()) {
               Sig old = p.getValue();
               String kn = p.getKey(), vn = open.args.get(i);
               i++;
               Sig vv=mod.getRawSIG(open.pos, vn);
               if (vv==null) {if (old==null) {missing=open; missingName=vn;} continue;}
               if (old==vv) continue;
               if (old!=null) throw new ErrorFatal(open.pos, "Internal error (module re-instantiated with different arguments)");
               if (vv==NONE) throw new ErrorSyntax(open.pos, "You cannot use \"none\" as an instantiating argument.");
               chg=true;
               p.setValue(vv);
               rep.parse("RESOLVE: "+(sub.path.length()==0?"this/":sub.path)+"/"+kn+" := "+vv+"\n");
            }
         }
         if (!chg && missing==null) return;
         if (!chg) throw new ErrorSyntax(missing.pos, "The signature name \""+missingName+"\" cannot be found.");
      }
   }
View Full Code Here

   /** Add an enumeration. */
   void addEnum(Pos pos, Pos priv, ExprVar name, List<ExprVar> atoms, Pos closingBracket) throws Err {
      ExprVar EXTENDS = ExprVar.make(null, "extends");
      ExprVar THIS = ExprVar.make(null, "this/"+name);
      List<ExprVar> THESE = Arrays.asList(THIS);
      if (atoms==null || atoms.size()==0) throw new ErrorSyntax(pos, "Enumeration must contain at least one name.");
      addSig(name.label, null, null, null, null, WHERE.make(name.pos), ABSTRACT.make(name.pos), PRIVATE.makenull(priv), Attr.ENUM);
      for(ExprVar a:atoms) addSig(a.label, EXTENDS, THESE, null, null, WHERE.make(a.pos), ONE.make(a.pos), PRIVATE.makenull(priv));
      int oldStatus = status;
      status = 0;
      try {
View Full Code Here

      if (!topo.add(oldS)) throw new ErrorType(pos, "Sig "+oldS+" is involved in a cyclic inheritance.");
      if (oldS instanceof SubsetSig)  {
         List<Sig> parents = new ArrayList<Sig>();
         for(Sig n: ((SubsetSig)oldS).parents) {
            Sig parentAST = u.getRawSIG(n.pos, n.label);
            if (parentAST==null) throw new ErrorSyntax(n.pos, "The sig \""+n.label+"\" cannot be found.");
            parents.add(resolveSig(res, topo, parentAST));
         }
         realSig = new SubsetSig(fullname, parents, oldS.attributes.toArray(new Attr[0]));
      } else {
         Sig sup = ((PrimSig)oldS).parent;
         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);
View Full Code Here

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

   /** Add a MACRO declaration. */
   void addMacro(Pos p, Pos isPrivate, String n, List<ExprVar> decls, Expr v) throws Err {
      if (!Version.experimental) throw new ErrorSyntax(p, "LET declaration is allowed only inside a toplevel paragraph.");
      ConstList<ExprVar> ds = ConstList.make(decls);
      status=3;
      dup(p, n, false);
      for(int i=0; i<ds.size(); i++) for(int j=i+1; j<ds.size(); j++)
         if (ds.get(i).label.equals(ds.get(j).label))
            throw new ErrorSyntax(ds.get(j).span(), "The parameter name \""+ds.get(j).label+"\" cannot appear more than once.");
      Macro ans = new Macro(p, isPrivate, this, n, ds, v);
      Macro old = macros.put(n, ans);
      if (old!=null) { macros.put(n, old); throw new ErrorSyntax(p, "You cannot declare more than one macro with the same name \""+n+"\" in the same file."); }
   }
View Full Code Here

      if (decls==null) decls=new ArrayList<Decl>(); else decls=new ArrayList<Decl>(decls);
      if (f!=null) decls.add(0, new Decl(null, null, null, Util.asList(ExprVar.make(f.span(), "this")), f));
      for(Decl d:decls) {
         if (d.isPrivate!=null) {
            ExprHasName name = d.names.get(0);
            throw new ErrorSyntax(d.isPrivate.merge(name.pos), "Function parameter \""+name.label+"\" is always private already.");
         }
         if (d.disjoint2!=null) {
            ExprHasName name = d.names.get(d.names.size()-1);
            throw new ErrorSyntax(d.disjoint2.merge(name.pos), "Function parameter \""+name.label+"\" cannot be bound to a 'disjoint' expression.");
         }
      }
      status=3;
      dup(p, n, false);
      ExprHasName dup = Decl.findDuplicateName(decls);
      if (dup!=null) throw new ErrorSyntax(dup.span(), "The parameter name \""+dup.label+"\" cannot appear more than once.");
      Func ans = new Func(p, isPrivate, n, decls, t, v);
      ArrayList<Func> list = funcs.get(n);
      if (list==null) { list = new ArrayList<Func>(); funcs.put(n, list); }
      list.add(ans);
   }
View Full Code Here

      if (name==null || name.length()==0) name="assert$"+(1+asserts.size());
      dup(pos, name, false);
      Expr old = asserts.put(name, ExprUnary.Op.NOOP.make(value.span().merge(pos), value));
      if (old!=null) {
         asserts.put(name, old);
         throw new ErrorSyntax(pos, "\""+name+"\" is already the name of an assertion in this module.");
      }
      return name;
   }
View Full Code Here

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

   /** Add a COMMAND declaration. */
   void addCommand(boolean followUp, Pos p, String n, boolean c, int o, int b, int seq, int exp, List<CommandScope> s, ExprVar label) throws Err {
      if (followUp && !Version.experimental) throw new ErrorSyntax(p, "Syntax error encountering => symbol.");
      if (label!=null) p=Pos.UNKNOWN.merge(p).merge(label.pos);
      status=3;
      if (n.length()==0) throw new ErrorSyntax(p, "Predicate/assertion name cannot be empty.");
      if (n.indexOf('@')>=0) throw new ErrorSyntax(p, "Predicate/assertion name cannot contain \'@\'");
      String labelName = (label==null || label.label.length()==0) ? n : label.label;
      Command parent = followUp ? commands.get(commands.size()-1) : null;
      Command newcommand = new Command(p, labelName, c, o, b, seq, exp, s, null, ExprVar.make(null, n), parent);
      if (parent!=null) commands.set(commands.size()-1, newcommand); else commands.add(newcommand);
   }
View Full Code Here

      if (parent!=null) commands.set(commands.size()-1, newcommand); else commands.add(newcommand);
   }

   /** Add a COMMAND declaration. */
   void addCommand(boolean followUp, Pos p, Expr e, boolean c, int o, int b, int seq, int exp, List<CommandScope> s, ExprVar label) throws Err {
      if (followUp && !Version.experimental) throw new ErrorSyntax(p, "Syntax error encountering => symbol.");
      if (label!=null) p=Pos.UNKNOWN.merge(p).merge(label.pos);
      status=3;
      String n;
      if (c) n=addAssertion(p,"check$"+(1+commands.size()),e);
      else addFunc(e.span().merge(p), Pos.UNKNOWN, n="run$"+(1+commands.size()), null, new ArrayList<Decl>(), null, e);
View Full Code Here

      Expr e;
      if (cmd.check) {
         List<Object> m = getRawQS(2, cname); // We prefer assertion in the topmost module
         if (m.size()==0 && cname.indexOf('/')<0) m=getRawNQS(this, 2, cname);
         if (m.size()>1) unique(cmd.pos, cname, m);
         if (m.size()<1) throw new ErrorSyntax(cmd.pos, "The assertion \""+cname+"\" cannot be found.");
         e = ((Expr)(m.get(0))).not();
      } else {
         List<Object> m = getRawQS(4, cname); // We prefer fun/pred in the topmost module
         if (m.size()==0 && cname.indexOf('/')<0) m=getRawNQS(this, 4, cname);
         if (m.size()>1) unique(cmd.pos, cname, m);
         if (m.size()<1) throw new ErrorSyntax(cmd.pos, "The predicate/function \""+cname+"\" cannot be found.");
         Func f = (Func) (m.get(0));
         e = f.getBody();
         if (!f.isPred) e = e.in(f.returnDecl);
         if (f.decls.size()>0) e = ExprQt.Op.SOME.make(null, null, f.decls, e);
      }
      if (e==null) e = ExprConstant.TRUE;
      TempList<CommandScope> sc=new TempList<CommandScope>(cmd.scope.size());
      for(CommandScope et: cmd.scope) {
         Sig s = getRawSIG(et.sig.pos, et.sig.label);
         if (s==null) throw new ErrorSyntax(et.sig.pos, "The sig \""+et.sig.label+"\" cannot be found.");
         sc.add(new CommandScope(null, s, et.isExact, et.startingScope, et.endingScope, et.increment));
      }
      return new Command(cmd.pos, cmd.label, cmd.check, cmd.overall, cmd.bitwidth, cmd.maxseq, cmd.expects, sc.makeConst(), exactSigs, globalFacts.and(e), parent);
   }
View Full Code Here

TOP

Related Classes of edu.mit.csail.sdg.alloy4.ErrorSyntax

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.