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

Examples of edu.mit.csail.sdg.alloy4compiler.ast.Expr.type()


        final Func f = x.fun;
        final int n = f.count();
        final Object candidate = n==0 ? cacheForConstants.get(f) : null;
        if (candidate!=null) return candidate;
        final Expr body = f.getBody();
        if (body.type().arity()<0 || body.type().arity()!=f.returnDecl.type().arity()) throw new ErrorType(body.span(), "Function return value not fully resolved.");
        for(Func ff:current_function) if (ff==f) throw new ErrorSyntax(x.span(), ""+f+" cannot call itself recursively!");
        Env<ExprVar,Object> newenv = new Env<ExprVar,Object>();
        List<SimTupleset> list = new ArrayList<SimTupleset>(x.args.size());
        for(int i=0; i<n; i++) { SimTupleset ts = cset(x.args.get(i)); newenv.put(f.get(i), ts);  list.add(ts); }
        final SimCallback cb = callbacks.get(f);
View Full Code Here


        final Func f = x.fun;
        final int n = f.count();
        final Object candidate = n==0 ? cacheForConstants.get(f) : null;
        if (candidate!=null) return candidate;
        final Expr body = f.getBody();
        if (body.type().arity()<0 || body.type().arity()!=f.returnDecl.type().arity()) throw new ErrorType(body.span(), "Function return value not fully resolved.");
        for(Func ff:current_function) if (ff==f) throw new ErrorSyntax(x.span(), ""+f+" cannot call itself recursively!");
        Env<ExprVar,Object> newenv = new Env<ExprVar,Object>();
        List<SimTupleset> list = new ArrayList<SimTupleset>(x.args.size());
        for(int i=0; i<n; i++) { SimTupleset ts = cset(x.args.get(i)); newenv.put(f.get(i), ts);  list.add(ts); }
        final SimCallback cb = callbacks.get(f);
View Full Code Here

           if (b.isSame(Sig.SIGINT)) { Integer i = a.get(0).toInt(null); return i!=null; }
           if (b.isSame(Sig.STRING)) { String at = a.get(0).toString(); return at.length()>0 && (at.charAt(0)=='\"'); }
        }
        if (b instanceof ExprBinary && ((ExprBinary)b).op==ExprBinary.Op.ARROW) {
           Expr left = ((ExprBinary)b).left, right = ((ExprBinary)b).right;
           int ll = left.type().arity(), rr = right.type().arity();
           if (ll <= rr) return isIn(a.head(ll), left) && isIn(a.tail(rr), right);
           return isIn(a.tail(rr), right) && isIn(a.head(ll), left);
        }
        if (b instanceof ExprBinary && ((ExprBinary)b).op==ExprBinary.Op.PLUS) {
           return isIn(a, ((ExprBinary)b).left) || isIn(a, ((ExprBinary)b).right);
View Full Code Here

        }
        if (params.size() != args.size()) return this;
        Context cx2 = new Context(realModule, warnings, cx.unrolls-1);
        for(int n=params.size(), i=0; i<n; i++) {
            Expr tmp = args.get(i);
            if (!(tmp instanceof Macro)) tmp = tmp.resolve(tmp.type(), warnings);
            cx2.put(params.get(i).label, tmp);
        }
        return cx2.check(body);
    }
View Full Code Here

      }

      /** {@inheritDoc} */
      @Override public Expr visit(ExprLet x) throws Err {
         Expr right = visitThis(x.expr);
         right = right.resolve(right.type(), warns);
         ExprVar left = ExprVar.make(x.var.pos, x.var.label, right.type());
         put(left.label, left);
         Expr sub = visitThis(x.sub);
         remove(left.label);
         return ExprLet.make(x.pos, left, right, sub);
View Full Code Here

      /** {@inheritDoc} */
      @Override public Expr visit(ExprLet x) throws Err {
         Expr right = visitThis(x.expr);
         right = right.resolve(right.type(), warns);
         ExprVar left = ExprVar.make(x.var.pos, x.var.label, right.type());
         put(left.label, left);
         Expr sub = visitThis(x.sub);
         remove(left.label);
         return ExprLet.make(x.pos, left, right, sub);
      }
View Full Code Here

      @Override public Expr visit(ExprQt x) throws Err {
         TempList<Decl> decls = new TempList<Decl>(x.decls.size());
         boolean isMetaSig=false, isMetaField=false;
         for(Decl d: x.decls) {
            Expr exp = visitThis(d.expr).resolve_as_set(warns);
            if (exp.mult==0 && exp.type().arity()==1) exp = ExprUnary.Op.ONEOF.make(null, exp);
            if (exp.errors.isEmpty()) {
               if (exp.type().isSubtypeOf(rootmodule.metaSig().plus(rootmodule.metaField()).type())) {
                  isMetaSig = exp.type().intersects(rootmodule.metaSig().type());
                  isMetaField = exp.type().intersects(rootmodule.metaField().type());
               }
View Full Code Here

         boolean isMetaSig=false, isMetaField=false;
         for(Decl d: x.decls) {
            Expr exp = visitThis(d.expr).resolve_as_set(warns);
            if (exp.mult==0 && exp.type().arity()==1) exp = ExprUnary.Op.ONEOF.make(null, exp);
            if (exp.errors.isEmpty()) {
               if (exp.type().isSubtypeOf(rootmodule.metaSig().plus(rootmodule.metaField()).type())) {
                  isMetaSig = exp.type().intersects(rootmodule.metaSig().type());
                  isMetaField = exp.type().intersects(rootmodule.metaField().type());
               }
            }
            // Below is a special case to allow more fine-grained typechecking when we see "all x:field$" or "some x:field$"
View Full Code Here

         for(Decl d: x.decls) {
            Expr exp = visitThis(d.expr).resolve_as_set(warns);
            if (exp.mult==0 && exp.type().arity()==1) exp = ExprUnary.Op.ONEOF.make(null, exp);
            if (exp.errors.isEmpty()) {
               if (exp.type().isSubtypeOf(rootmodule.metaSig().plus(rootmodule.metaField()).type())) {
                  isMetaSig = exp.type().intersects(rootmodule.metaSig().type());
                  isMetaField = exp.type().intersects(rootmodule.metaField().type());
               }
            }
            // Below is a special case to allow more fine-grained typechecking when we see "all x:field$" or "some x:field$"
            boolean some = (x.op==ExprQt.Op.SOME), compre = (x.op==ExprQt.Op.COMPREHENSION);
View Full Code Here

            Expr exp = visitThis(d.expr).resolve_as_set(warns);
            if (exp.mult==0 && exp.type().arity()==1) exp = ExprUnary.Op.ONEOF.make(null, exp);
            if (exp.errors.isEmpty()) {
               if (exp.type().isSubtypeOf(rootmodule.metaSig().plus(rootmodule.metaField()).type())) {
                  isMetaSig = exp.type().intersects(rootmodule.metaSig().type());
                  isMetaField = exp.type().intersects(rootmodule.metaField().type());
               }
            }
            // Below is a special case to allow more fine-grained typechecking when we see "all x:field$" or "some x:field$"
            boolean some = (x.op==ExprQt.Op.SOME), compre = (x.op==ExprQt.Op.COMPREHENSION);
            if (x.decls.size()==1 && d.names.size()==1 && isOneOf(exp) && (x.op==ExprQt.Op.ALL || some || compre) && (isMetaSig || isMetaField)) {
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.