Ejemplo n.º 1
0
        public override void Typecheck(TypecheckingContext tc)
        {
            //Contract.Requires(tc != null);
            foreach (var e in Rhss)
            {
                e.Typecheck(tc);
            }

            Contract.Assert(Dummies.Count == Rhss.Count); // enforced by resolution
            for (var i = 0; i < Dummies.Count; i++)
            {
                var lhs = Dummies[i];
                var rhs = Rhss[i];
                lhs.TypedIdent.Type = rhs.Type;
            }

            for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next)
            {
                kv.Typecheck(tc);
            }

            Body.Typecheck(tc);
            Contract.Assert(Body.Type != null); // follows from postcondition of Expr.Typecheck
            this.Type = Body.Type;
        }
Ejemplo n.º 2
0
        public override void Typecheck(TypecheckingContext tc)
        {
            //Contract.Requires(tc != null);
            foreach (object p in Params)
            {
                var expr = p as Expr;
                if (expr != null)
                {
                    expr.Typecheck(tc);
                }

                if ((Key == "minimize" || Key == "maximize") &&
                    (expr == null || !(expr.Type.IsInt || expr.Type.IsReal || expr.Type.IsBv)))
                {
                    tc.Error(this, "attributes :minimize and :maximize accept only one argument of type int, real or bv");
                    break;
                }

                if (Key == "verified_under" && (expr == null || !expr.Type.IsBool))
                {
                    tc.Error(this, "attribute :verified_under accepts only one argument of type bool");
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public override void Typecheck(TypecheckingContext tc)
        {
            //Contract.Requires(tc != null);
            for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next)
            {
                kv.Typecheck(tc);
            }
            Body.Typecheck(tc);
            Contract.Assert(Body.Type != null); // follows from postcondition of Expr.Typecheck

            List <Type> /*!*/ argTypes = new List <Type>();

            foreach (Variable /*!*/ v in Dummies)
            {
                Contract.Assert(v != null);
                argTypes.Add(v.TypedIdent.Type);
            }
            this.Type = new MapType(this.tok, this.TypeParameters, argTypes, Body.Type);

            // Check that type parameters occur in the types of the
            // dummies, or otherwise in the triggers. This can only be
            // done after typechecking
            List <TypeVariable> /*!*/ unmentionedParameters = GetUnmentionedTypeParameters();

            Contract.Assert(unmentionedParameters != null);

            if (unmentionedParameters.Count > 0)
            {
                tc.Error(this, "the type variable {0} does not occur in types of the lambda parameters", unmentionedParameters[0]);
            }
        }
Ejemplo n.º 4
0
        public override void Typecheck(TypecheckingContext tc)
        {
            //Contract.Requires(tc != null);
            for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next)
            {
                kv.Typecheck(tc);
            }

            for (Trigger tr = this.Triggers; tr != null; tr = tr.Next)
            {
                tr.Typecheck(tc);
            }

            Body.Typecheck(tc);
            Contract.Assert(Body.Type != null); // follows from postcondition of Expr.Typecheck
            if (!Body.Type.Unify(Type.Bool))
            {
                tc.Error(this, "quantifier body must be of type bool");
            }

            this.Type = Type.Bool;

            // Check that type parameters occur in the types of the
            // dummies, or otherwise in the triggers. This can only be
            // done after typechecking
            List <TypeVariable> /*!*/
            unmentionedParameters = GetUnmentionedTypeParameters();

            Contract.Assert(unmentionedParameters != null);

            if (unmentionedParameters.Count > 0)
            {
                // all the type parameters that do not occur in dummy types
                // have to occur in triggers

                for (Trigger tr = this.Triggers; tr != null; tr = tr.Next)
                {
                    // for positive triggers, make sure all bound variables are mentioned
                    if (tr.Pos)
                    {
                        Set /*Variable*/
                            freeVars = new Set/*Variable*/ ();
                        tr.ComputeFreeVariables(freeVars);
                        foreach (TypeVariable /*!*/ v in unmentionedParameters)
                        {
                            Contract.Assert(v != null);
                            if (!freeVars[v])
                            {
                                tc.Error(tr,
                                         "trigger does not mention {0}, which does not occur in variables types either",
                                         v);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public override void Typecheck(TypecheckingContext tc)
 {
     //Contract.Requires(tc != null);
     foreach (Expr /*!*/ e in this.Tr)
     {
         Contract.Assert(e != null);
         e.Typecheck(tc);
     }
 }
Ejemplo n.º 6
0
 public override void Typecheck(TypecheckingContext tc)
 {
     //Contract.Requires(tc != null);
     foreach (object p in Params)
     {
         if (p is Expr)
         {
             ((Expr)p).Typecheck(tc);
         }
     }
 }
Ejemplo n.º 7
0
        public static int ResolveAndTypecheck(Absy absy)
        {
            var rc = new ResolutionContext(null);

            absy.Resolve(rc);
            if (rc.ErrorCount != 0)
            {
                return(rc.ErrorCount);
            }
            var tc = new TypecheckingContext(null);

            absy.Typecheck(tc);
            return(tc.ErrorCount);
        }
Ejemplo n.º 8
0
    protected void ResolveImpl(Implementation impl) {
      Contract.Requires(impl != null);
      Contract.Ensures(impl.Proc != null);
      ResolutionContext rc = new ResolutionContext(new DummyErrorSink());

      foreach (var decl in program.TopLevelDeclarations) {
        decl.Register(rc);
      }

      impl.Proc = null; // to force Resolve() redo the operation
      impl.Resolve(rc);

      TypecheckingContext tc = new TypecheckingContext(new DummyErrorSink());

      impl.Typecheck(tc);
    }
Ejemplo n.º 9
0
        public void FunctionCall()
        {
            var fc = CreateFunctionCall("bv8slt", Microsoft.Boogie.Type.Bool, new List<Microsoft.Boogie.Type>() {
                BasicType.GetBvType(8),
                BasicType.GetBvType(8)
            });

            var constantBv = new LiteralExpr(Token.NoToken, BigNum.FromInt(0) , 8);
            var nary = new NAryExpr(Token.NoToken,fc, new List<Expr>() { constantBv, constantBv} );

            // Get shallow type (this was broken when this test was written)
            Assert.AreEqual(BasicType.Bool, nary.ShallowType);

            // Deep type check (this was not broken before writing this test)
            Assert.IsNull(nary.Type);

            var tc = new TypecheckingContext(this);
            nary.Typecheck(tc);

            Assert.AreEqual(BasicType.Bool, nary.Type);
        }
Ejemplo n.º 10
0
 public override void Typecheck(TypecheckingContext tc)
 {
     //Contract.Requires(tc != null);
       foreach (object p in Params) {
     if (p is Expr) {
       ((Expr)p).Typecheck(tc);
     }
       }
 }
Ejemplo n.º 11
0
 public void CheckAssignments(TypecheckingContext tc)
 {
     Contract.Requires(tc != null);
     List<Variable>/*!*/ vars = new List<Variable>();
     this.AddAssignedVariables(vars);
     foreach (Variable/*!*/ v in vars)
     {
     Contract.Assert(v != null);
     if (!v.IsMutable)
     {
         tc.Error(this, "command assigns to an immutable variable: {0}", v.Name);
     }
     else if (!CommandLineOptions.Clo.DoModSetAnalysis && v is GlobalVariable && !tc.InFrame(v))
     {
         tc.Error(this, "command assigns to a global variable that is not in the enclosing procedure's modifies clause: {0}", v.Name);
     }
     }
 }
Ejemplo n.º 12
0
 protected void TypecheckAttributes(TypecheckingContext rc) {
   Contract.Requires(rc != null);
   for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next) {
     kv.Typecheck(rc);
   }
 }
Ejemplo n.º 13
0
 public override void Typecheck(TypecheckingContext tc) {
   //Contract.Requires(tc != null);
   return;
 }
Ejemplo n.º 14
0
    public override void Typecheck(TypecheckingContext tc) {
      //Contract.Requires(tc != null);
      for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next) {
        kv.Typecheck(tc);
      }
      Body.Typecheck(tc);
      Contract.Assert(Body.Type != null);  // follows from postcondition of Expr.Typecheck

      List<Type>/*!*/ argTypes = new List<Type>();
      foreach (Variable/*!*/ v in Dummies) {
        Contract.Assert(v != null);
        argTypes.Add(v.TypedIdent.Type);
      }
      this.Type = new MapType(this.tok, this.TypeParameters, argTypes, Body.Type);

      // Check that type parameters occur in the types of the
      // dummies, or otherwise in the triggers. This can only be
      // done after typechecking
      List<TypeVariable>/*!*/ unmentionedParameters = GetUnmentionedTypeParameters();
      Contract.Assert(unmentionedParameters != null);

      if (unmentionedParameters.Count > 0) {
        tc.Error(this, "the type variable {0} does not occur in types of the lambda parameters", unmentionedParameters[0]);
      }
    }
Ejemplo n.º 15
0
 public override void Typecheck(TypecheckingContext tc)
 {
     TypecheckAttributes(Attributes, tc);
       if (!CommandLineOptions.Clo.DoModSetAnalysis)
       {
       if (!tc.Yields)
       {
           tc.Error(this, "enclosing procedure of a parallel call must yield");
       }
       foreach (CallCmd callCmd in CallCmds)
       {
           if (!QKeyValue.FindBoolAttribute(callCmd.Proc.Attributes, "yields"))
           {
               tc.Error(callCmd, "target procedure of a parallel call must yield");
           }
           if (!QKeyValue.FindBoolAttribute(callCmd.Proc.Attributes, "stable"))
           {
               tc.Error(callCmd, "target procedure of a parallel call must be stable");
           }
       }
       }
       foreach (CallCmd callCmd in CallCmds)
       {
       callCmd.Typecheck(tc);
       }
 }
Ejemplo n.º 16
0
 public override void Typecheck(TypecheckingContext tc)
 {
     //Contract.Requires(tc != null);
       Expr.Typecheck(tc);
       Contract.Assert(Expr.Type != null);  // follows from Expr.Typecheck postcondition
       if (!Expr.Type.Unify(Type.Bool)) {
     tc.Error(this, "an assumed expression must be of type bool (got: {0})", Expr.Type);
       }
 }
Ejemplo n.º 17
0
 public override void Typecheck(TypecheckingContext tc) {
   //Contract.Requires(tc != null);
   foreach (Expr/*!*/ e in this.Tr) {
     Contract.Assert(e != null);
     e.Typecheck(tc);
   }
 }
Ejemplo n.º 18
0
 public override void Typecheck(TypecheckingContext tc)
 {
     if (!CommandLineOptions.Clo.DoModSetAnalysis && !tc.Yields)
       {
       tc.Error(this, "enclosing procedure of a yield command must yield");
       }
 }
Ejemplo n.º 19
0
        public override void Typecheck(TypecheckingContext tc)
        {
            foreach (AssignLhs/*!*/ e in Lhss) {
            Contract.Assert(e != null);
            e.Typecheck(tc);
              }
              foreach (Expr/*!*/ e in Rhss) {
            Contract.Assert(e != null);
            e.Typecheck(tc);
              }

              this.CheckAssignments(tc);

              for (int i = 0; i < Lhss.Count; ++i) {
            Type ltype = Lhss[i].Type;
            Type rtype = Rhss[i].Type;
            if (ltype != null && rtype != null) {
              // otherwise, there has already been an error when
              // typechecking the lhs or rhs
              if (!ltype.Unify(rtype))
            tc.Error(Lhss[i],
                     "mismatched types in assignment command (cannot assign {0} to {1})",
                     rtype, ltype);
            }
              }
        }
Ejemplo n.º 20
0
 public override void Typecheck(TypecheckingContext tc)
 {
     //Contract.Requires(tc != null);
       // nothing to typecheck
 }
Ejemplo n.º 21
0
 public override void Typecheck(TypecheckingContext tc)
 {
     //Contract.Requires(tc != null);
       foreach (Cmd/*!*/ cmd in Cmds) {
     Contract.Assert(cmd != null);
     cmd.Typecheck(tc);
       }
 }
Ejemplo n.º 22
0
 public override void Typecheck(TypecheckingContext tc)
 {
     AssignedVariable.Typecheck(tc);
 }
Ejemplo n.º 23
0
       /*
                   #region _TESTING_NEW_STUFF_
            CommandLineOptions.Clo.vcVariety = CommandLineOptions.VCVariety.Block;
            //VCExpr wp = Wlp.Block(block, SuccCorrect, context); // Computes wp.S.true
            
            CommandLineOptions.Clo.vcVariety = CommandLineOptions.VCVariety.Doomed;
            #endregion

       */

        VCExpr GenerateEVC(Implementation impl, out Dictionary<int, Absy> label2absy, Checker ch, out int assertionCount) {
          Contract.Requires(impl != null);
          Contract.Requires(ch != null);
          Contract.Ensures(Contract.Result<VCExpr>() != null);

          TypecheckingContext tc = new TypecheckingContext(null);
          impl.Typecheck(tc);
          label2absy = new Dictionary<int, Absy>();
          VCExpr vc;
          switch (CommandLineOptions.Clo.vcVariety) {
            case CommandLineOptions.VCVariety.Doomed:
              vc = LetVC(cce.NonNull(impl.Blocks[0]), label2absy, ch.TheoremProver.Context, out assertionCount);
              break;

            default:
              Contract.Assert(false); throw new cce.UnreachableException();  // unexpected enumeration value
          }
          return vc;
        }
Ejemplo n.º 24
0
 public override void Typecheck(TypecheckingContext tc)
 {
     //Contract.Requires(tc != null);
       foreach (IdentifierExpr ie in Vars)
       {
       ie.Typecheck(tc);
       }
       this.CheckAssignments(tc);
 }
Ejemplo n.º 25
0
 public override void Typecheck(TypecheckingContext tc) {
   //Contract.Requires(tc != null);
   foreach (object p in Params) {
     var expr = p as Expr;
     if (expr != null) {
       expr.Typecheck(tc);
     }
     if ((Key == "minimize" || Key == "maximize")
         && (expr == null || !(expr.Type.IsInt || expr.Type.IsReal || expr.Type.IsBv)))
     {
       tc.Error(this, "attributes :minimize and :maximize accept only one argument of type int, real or bv");
       break;
     }
     if (Key == "verified_under" && (expr == null || !expr.Type.IsBool))
     {
       tc.Error(this, "attribute :verified_under accepts only one argument of type bool");
       break;
     }
   }
 }
Ejemplo n.º 26
0
 public override void Typecheck(TypecheckingContext tc)
 {
 }
Ejemplo n.º 27
0
    public override void Typecheck(TypecheckingContext tc) {
      //Contract.Requires(tc != null);
      for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next) {
        kv.Typecheck(tc);
      }
      for (Trigger tr = this.Triggers; tr != null; tr = tr.Next) {
        tr.Typecheck(tc);
      }
      Body.Typecheck(tc);
      Contract.Assert(Body.Type != null);  // follows from postcondition of Expr.Typecheck
      if (!Body.Type.Unify(Type.Bool)) {
        tc.Error(this, "quantifier body must be of type bool");
      }
      this.Type = Type.Bool;

      // Check that type parameters occur in the types of the
      // dummies, or otherwise in the triggers. This can only be
      // done after typechecking
      List<TypeVariable>/*!*/ unmentionedParameters = GetUnmentionedTypeParameters();
      Contract.Assert(unmentionedParameters != null);

      if (unmentionedParameters.Count > 0) {
        // all the type parameters that do not occur in dummy types
        // have to occur in triggers

        for (Trigger tr = this.Triggers; tr != null; tr = tr.Next) {
          // for positive triggers, make sure all bound variables are mentioned
          if (tr.Pos) {
            Set /*Variable*/ freeVars = new Set /*Variable*/ ();
            tr.ComputeFreeVariables(freeVars);
            foreach (TypeVariable/*!*/ v in unmentionedParameters) {
              Contract.Assert(v != null);
              if (!freeVars[v])
                tc.Error(tr,
                         "trigger does not mention {0}, which does not occur in variables types either",
                         v);
            }
          }
        }
      }
    }
Ejemplo n.º 28
0
 public static void TypecheckAttributes(QKeyValue attributes, TypecheckingContext tc)
 {
     Contract.Requires(tc != null);
       for (QKeyValue kv = attributes; kv != null; kv = kv.Next) {
     kv.Typecheck(tc);
       }
 }
Ejemplo n.º 29
0
 public TypeAmbiguitySeeker(TypecheckingContext tc)
 {
     Contract.Requires(tc != null);
     TC = tc;
 }
Ejemplo n.º 30
0
        public override void Typecheck(TypecheckingContext tc)
        {
            Map.Typecheck(tc);
              foreach (Expr/*!*/ e in Indexes) {
            Contract.Assert(e != null);
            e.Typecheck(tc);
              }

              // we use the same typechecking code as in MapSelect
              List<Expr>/*!*/ selectArgs = new List<Expr>();
              foreach (Expr/*!*/ e in Indexes) {
            Contract.Assert(e != null);
            selectArgs.Add(e);
              }
              TypeParamInstantiation/*!*/ tpInsts;
              TypeAttr =
            MapSelect.Typecheck(cce.NonNull(Map.Type), Map,
                            selectArgs, out tpInsts, tc, tok, "map assignment");
              TypeParameters = tpInsts;
        }
Ejemplo n.º 31
0
        public void ProtectedExprChangeTypeFail()
        {
            var e = GetUnTypedImmutableNAry();

            // Now Typecheck
            // Even though it's immutable we allow the TypeCheck field to be set if the Expr has never been type checked
            var TC = new TypecheckingContext(this);
            e.Typecheck(TC);
            Assert.IsNotNull(e.Type);
            Assert.IsTrue(e.Type.IsBool);

            // Trying to modify the Type to a different Type now should fail
            e.Type = BasicType.Int;
        }
Ejemplo n.º 32
0
 public override void Typecheck(TypecheckingContext tc) {
   //Contract.Requires(tc != null);
   //   type variables can occur when working with polymorphic functions/procedures
   //      if (!this.Type.IsClosed)
   //        tc.Error(this, "free variables in type of an identifier: {0}",
   //                 this.Type.FreeVariables);
   if (this.WhereExpr != null) {
     this.WhereExpr.Typecheck(tc);
     Contract.Assert(this.WhereExpr.Type != null);  // follows from postcondition of Expr.Typecheck
     if (!this.WhereExpr.Type.Unify(Type.Bool)) {
       tc.Error(this, "where clauses must be of type bool");
     }
   }
 }
Ejemplo n.º 33
0
 public override void Typecheck(TypecheckingContext tc)
 {
     foreach (Cmd/*!*/ c in Cmds) {
     Contract.Assert(c != null);
     c.Typecheck(tc);
       }
       Contract.Assume(this.TransferCmd != null);
       TransferCmd.Typecheck(tc);
 }
Ejemplo n.º 34
0
        public override void Typecheck(TypecheckingContext tc)
        {
            //Contract.Requires(tc != null);
            Contract.Assume(this.Proc != null);  // we assume the CallCmd has been successfully resolved before calling this Typecheck method

            TypecheckAttributes(Attributes, tc);

            // typecheck in-parameters
            foreach (Expr e in Ins)
            if (e != null)
                e.Typecheck(tc);
            foreach (Expr e in Outs)
            if (e != null)
                e.Typecheck(tc);
            this.CheckAssignments(tc);

            List<Type>/*!*/ formalInTypes = new List<Type>();
            List<Type>/*!*/ formalOutTypes = new List<Type>();
            List<Expr>/*!*/ actualIns = new List<Expr>();
            List<IdentifierExpr>/*!*/ actualOuts = new List<IdentifierExpr>();
            for (int i = 0; i < Ins.Count; ++i)
            {
            if (Ins[i] != null)
            {
                formalInTypes.Add(cce.NonNull(Proc.InParams[i]).TypedIdent.Type);
                actualIns.Add(Ins[i]);
            }
            }
            for (int i = 0; i < Outs.Count; ++i)
            {
            if (Outs[i] != null)
            {
                formalOutTypes.Add(cce.NonNull(Proc.OutParams[i]).TypedIdent.Type);
                actualOuts.Add(Outs[i]);
            }
            }

            // match actuals with formals
            List<Type/*!*/>/*!*/ actualTypeParams;
            Type.CheckArgumentTypes(Proc.TypeParameters,
                                out actualTypeParams,
                                formalInTypes, actualIns,
                                formalOutTypes, actualOuts,
                                this.tok,
                                "call to " + callee,
                                tc);
            Contract.Assert(cce.NonNullElements(actualTypeParams));
            TypeParameters = SimpleTypeParamInstantiation.From(Proc.TypeParameters,
                                                           actualTypeParams);

            if (!CommandLineOptions.Clo.DoModSetAnalysis && IsAsync)
            {
            if (!tc.Yields)
            {
                tc.Error(this, "enclosing procedure of an async call must yield");
            }
            if (!QKeyValue.FindBoolAttribute(Proc.Attributes, "yields"))
            {
                tc.Error(this, "target procedure of an async call must yield");
            }
            if (!QKeyValue.FindBoolAttribute(Proc.Attributes, "stable"))
            {
                tc.Error(this, "target procedure of an async call must be stable");
            }
            }
        }
Ejemplo n.º 35
0
        public void ProtectedExprType()
        {
            var e = GetUnTypedImmutableNAry();

            // Now Typecheck
            // Even though it's immutable we allow the TypeCheck field to be set if the Expr has never been type checked
            var TC = new TypecheckingContext(this);
            e.Typecheck(TC);
            Assert.IsNotNull(e.Type);
            Assert.IsTrue(e.Type.IsBool);
        }
Ejemplo n.º 36
0
 public TypeAmbiguitySeeker(TypecheckingContext tc) {
   Contract.Requires(tc != null);
   TC = tc;
 }
Ejemplo n.º 37
0
        public void ProtectedExprTypeChangeTypeSucceed()
        {
            var e = GetUnTypedImmutableNAry();

            // Now Typecheck
            // Even though it's immutable we allow the TypeCheck field to be set if the Expr has never been type checked
            var TC = new TypecheckingContext(this);
            e.Typecheck(TC);
            Assert.IsNotNull(e.Type);
            Assert.IsTrue(e.Type.IsBool);

            // Trying to assign the same Type should succeed
            e.Type = BasicType.Bool;
        }
Ejemplo n.º 38
0
    public override void Typecheck(TypecheckingContext tc) {
      //Contract.Requires(tc != null);
      Helpers.ExtraTraceInformation("Starting typechecking");

      int oldErrorCount = tc.ErrorCount;
      foreach (Declaration d in TopLevelDeclarations) {
        d.Typecheck(tc);
      }

      if (oldErrorCount == tc.ErrorCount) {
        // check whether any type proxies have remained uninstantiated
        TypeAmbiguitySeeker/*!*/ seeker = new TypeAmbiguitySeeker(tc);
        foreach (Declaration d in TopLevelDeclarations) {
          seeker.Visit(d);
        }
      }
    }