Beispiel #1
0
        public Expr DisjointnessExpr(string domainName, HashSet <Variable> scope)
        {
            LinearDomain  domain    = linearDomains[domainName];
            BoundVariable partition = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("partition_{0}", domainName), new MapType(Token.NoToken, new List <TypeVariable>(), new List <Type> {
                domain.elementType
            }, Microsoft.Boogie.Type.Int)));
            Expr disjointExpr = Expr.True;
            int  count        = 0;

            foreach (Variable v in scope)
            {
                IdentifierExpr ie = new IdentifierExpr(Token.NoToken, v);
                Expr           e  = new NAryExpr(Token.NoToken, new FunctionCall(domain.mapConstInt), new List <Expr> {
                    new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(count++))
                });
                e = new NAryExpr(Token.NoToken, new FunctionCall(domain.mapEqInt), new List <Expr> {
                    new IdentifierExpr(Token.NoToken, partition), e
                });
                e = new NAryExpr(Token.NoToken, new FunctionCall(domain.mapImpBool), new List <Expr> {
                    v.TypedIdent.Type is MapType ? ie : Singleton(ie, domainName), e
                });
                e = Expr.Binary(BinaryOperator.Opcode.Eq, e, new NAryExpr(Token.NoToken, new FunctionCall(domain.mapConstBool), new List <Expr> {
                    Expr.True
                }));
                disjointExpr = Expr.Binary(BinaryOperator.Opcode.And, e, disjointExpr);
            }
            var expr = new ExistsExpr(Token.NoToken, new List <Variable> {
                partition
            }, disjointExpr);

            expr.Resolve(new ResolutionContext(null));
            expr.Typecheck(new TypecheckingContext(null));
            return(expr);
        }
Beispiel #2
0
 private static Expr OutPermsSubsetInPerms(LinearDomain domain, IEnumerable<Expr> ins, IEnumerable<Expr> outs)
 {
   Expr inMultiset = ExprHelper.Old(PermissionMultiset(domain, ins));
   Expr outMultiset = PermissionMultiset(domain, outs);
   Expr subsetExpr = ExprHelper.FunctionCall(domain.mapLe, outMultiset, inMultiset);
   return Expr.Eq(subsetExpr, ExprHelper.FunctionCall(domain.mapConstBool, Expr.True));
 }
Beispiel #3
0
 private Expr SubsetExpr(LinearDomain domain, Expr ie, Variable partition, int partitionCount)
 {
   Expr e = ExprHelper.FunctionCall(domain.mapConstInt, Expr.Literal(partitionCount));
   e = ExprHelper.FunctionCall(domain.mapEqInt, Expr.Ident(partition), e);
   e = ExprHelper.FunctionCall(domain.mapImp, ie, e);
   e = Expr.Eq(e, ExprHelper.FunctionCall(domain.mapConstBool, Expr.True));
   return e;
 }
Beispiel #4
0
    private static Expr PermissionMultiset(LinearDomain domain, IEnumerable<Expr> exprs)
    {
      var terms = exprs.Select(x =>
        ExprHelper.FunctionCall(domain.mapIteInt,
          ExprHelper.FunctionCall(domain.collectors[x.Type], x),
          domain.MapConstInt(1),
          domain.MapConstInt(0))).ToList<Expr>();

      if (terms.Count == 0)
        return domain.MapConstInt(0);
      return terms.Aggregate((x, y) => ExprHelper.FunctionCall(domain.mapAdd, x, y));
    }
Beispiel #5
0
    public Expr DisjointnessExprForPermissions(string domainName, IEnumerable<Expr> permissionsExprs)
    {
      Expr expr = Expr.True;
      if (permissionsExprs.Count() > 1)
      {
        int count = 0;
        List<Expr> subsetExprs = new List<Expr>();
        LinearDomain domain = linearDomains[domainName];
        BoundVariable partition = new BoundVariable(Token.NoToken,
          new TypedIdent(Token.NoToken, $"partition_{domainName}", domain.mapTypeInt));
        foreach (Expr e in permissionsExprs)
        {
          subsetExprs.Add(SubsetExpr(domain, e, partition, count));
          count++;
        }

        expr = new ExistsExpr(Token.NoToken, new List<Variable> {partition}, Expr.And(subsetExprs));
      }

      expr.Resolve(new ResolutionContext(null));
      expr.Typecheck(new TypecheckingContext(null));
      return expr;
    }
Beispiel #6
0
 private Expr SubsetExprs(LinearDomain domain, HashSet<Variable> scope, Variable partition, int count, Expr expr)
 {
     foreach (Variable v in scope)
     {
         if (!domain.collectors.ContainsKey(v.TypedIdent.Type)) continue;
         Expr ie = new NAryExpr(Token.NoToken, new FunctionCall(domain.collectors[v.TypedIdent.Type]), new List<Expr> { Expr.Ident(v) });
         expr = Expr.And(SubsetExpr(domain, ie, partition, count), expr);
         count++;
     }
     expr = new ExistsExpr(Token.NoToken, new List<Variable> { partition }, expr);
     expr.Resolve(new ResolutionContext(null));
     expr.Typecheck(new TypecheckingContext(null));
     return expr;
 }
Beispiel #7
0
 private Expr SubsetExpr(LinearDomain domain, Expr ie, Variable partition, int partitionCount)
 {
     Expr e = new NAryExpr(Token.NoToken, new FunctionCall(domain.mapConstInt), new List<Expr> { new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(partitionCount)) });
     e = new NAryExpr(Token.NoToken, new FunctionCall(domain.mapEqInt), new List<Expr> { Expr.Ident(partition), e });
     e = new NAryExpr(Token.NoToken, new FunctionCall(domain.mapImpBool), new List<Expr> { ie, e });
     e = Expr.Eq(e, new NAryExpr(Token.NoToken, new FunctionCall(domain.mapConstBool), new List<Expr> { Expr.True }));
     return e;
 }
Beispiel #8
0
    private static List<Expr> PendingAsyncLinearParams(LinearTypeChecker linearTypeChecker, LinearDomain domain, AtomicAction pendingAsync, IdentifierExpr pa)
    {
      var pendingAsyncLinearParams = new List<Expr>();

      for (int i = 0; i < pendingAsync.proc.InParams.Count; i++)
      {
        var inParam = pendingAsync.proc.InParams[i];
        if (linearTypeChecker.FindDomainName(inParam) == domain.domainName && InKinds.Contains(linearTypeChecker.FindLinearKind(inParam)))
        {
          var pendingAsyncParam = ExprHelper.FunctionCall(pendingAsync.pendingAsyncCtor.selectors[i], pa);
          pendingAsyncLinearParams.Add(pendingAsyncParam);
        }
      }

      return pendingAsyncLinearParams;
    }