Exemple #1
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;
                }
            }
        }
Exemple #2
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);
                            }
                        }
                    }
                }
            }
        }
Exemple #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]);
            }
        }
Exemple #4
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");
     }
   }
 }
Exemple #5
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);
       }
 }
Exemple #6
0
 public override void Typecheck(TypecheckingContext tc) {
   //Contract.Requires(tc != null);
   // PR: why was the base call left out previously?
   base.Typecheck(tc);
   // TypecheckAttributes(tc);
   if (Body != null) {
     Body.Typecheck(tc);
     if (!cce.NonNull(Body.Type).Unify(cce.NonNull(OutParams[0]).TypedIdent.Type))
       tc.Error(Body,
                "function body with invalid type: {0} (expected: {1})",
                Body.Type, cce.NonNull(OutParams[0]).TypedIdent.Type);
   }
 }
Exemple #7
0
 public override void Typecheck(TypecheckingContext tc)
 {
     if (!CommandLineOptions.Clo.DoModSetAnalysis && !tc.Yields)
       {
       tc.Error(this, "enclosing procedure of a yield command must yield");
       }
 }
Exemple #8
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);
            }
              }
        }
Exemple #9
0
 public override void Typecheck(TypecheckingContext tc) {
   CtorType outputType = this.OutParams[0].TypedIdent.Type as CtorType;
   if (outputType == null || !outputType.IsDatatype()) {
     tc.Error(tok, "The output type of a constructor must be a datatype");
   }
   base.Typecheck(tc);
 }
Exemple #10
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);
       }
 }
Exemple #11
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;
     }
   }
 }
Exemple #12
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]);
      }
    }
Exemple #13
0
    void MatchFormals(List<Variable>/*!*/ implFormals, List<Variable>/*!*/ procFormals, string/*!*/ inout, TypecheckingContext/*!*/ tc) {
      Contract.Requires(implFormals != null);
      Contract.Requires(procFormals != null);
      Contract.Requires(inout != null);
      Contract.Requires(tc != null);
      if (implFormals.Count != procFormals.Count) {
        tc.Error(this, "mismatched number of {0}-parameters in procedure implementation: {1}",
                 inout, this.Name);
      } else {
        // unify the type parameters so that types can be compared
        Contract.Assert(Proc != null);
        Contract.Assert(this.TypeParameters.Count == Proc.TypeParameters.Count);

        IDictionary<TypeVariable/*!*/, Type/*!*/>/*!*/ subst1 =
          new Dictionary<TypeVariable/*!*/, Type/*!*/>();
        IDictionary<TypeVariable/*!*/, Type/*!*/>/*!*/ subst2 =
          new Dictionary<TypeVariable/*!*/, Type/*!*/>();

        for (int i = 0; i < this.TypeParameters.Count; ++i) {
          TypeVariable/*!*/ newVar =
            new TypeVariable(Token.NoToken, Proc.TypeParameters[i].Name);
          Contract.Assert(newVar != null);
          subst1.Add(Proc.TypeParameters[i], newVar);
          subst2.Add(this.TypeParameters[i], newVar);
        }

        for (int i = 0; i < implFormals.Count; i++) {
          // the names of the formals are allowed to change from the proc to the impl

          // but types must be identical
          Type t = cce.NonNull((Variable)implFormals[i]).TypedIdent.Type.Substitute(subst2);
          Type u = cce.NonNull((Variable)procFormals[i]).TypedIdent.Type.Substitute(subst1);
          if (!t.Equals(u)) {
            string/*!*/ a = cce.NonNull((Variable)implFormals[i]).Name;
            Contract.Assert(a != null);
            string/*!*/ b = cce.NonNull((Variable)procFormals[i]).Name;
            Contract.Assert(b != null);
            string/*!*/ c;
            if (a == b) {
              c = a;
            } else {
              c = String.Format("{0} (named {1} in implementation)", b, a);
            }
            tc.Error(this, "mismatched type of {0}-parameter in implementation {1}: {2}", inout, this.Name, c);
          }
        }
      }
    }
Exemple #14
0
    public override void Typecheck(TypecheckingContext tc) {
      //Contract.Requires(tc != null);
      base.Typecheck(tc);

      Contract.Assume(this.Proc != null);

      if (this.TypeParameters.Count != Proc.TypeParameters.Count) {
        tc.Error(this, "mismatched number of type parameters in procedure implementation: {0}",
                 this.Name);
      } else {
        // if the numbers of type parameters are different, it is
        // difficult to compare the argument types
        MatchFormals(this.InParams, Proc.InParams, "in", tc);
        MatchFormals(this.OutParams, Proc.OutParams, "out", tc);
      }

      foreach (Variable/*!*/ v in LocVars) {
        Contract.Assert(v != null);
        v.Typecheck(tc);
      }
      List<IdentifierExpr> oldFrame = tc.Frame;
      bool oldYields = tc.Yields;
      tc.Frame = Proc.Modifies;
      tc.Yields = QKeyValue.FindBoolAttribute(Proc.Attributes, "yields");
      foreach (Block b in Blocks) {
        b.Typecheck(tc);
      }
      Contract.Assert(tc.Frame == Proc.Modifies);
      tc.Frame = oldFrame;
      tc.Yields = oldYields;
    }
Exemple #15
0
 public override void Typecheck(TypecheckingContext tc) {
   //Contract.Requires(tc != null);
   base.Typecheck(tc);
   foreach (IdentifierExpr/*!*/ ide in Modifies) {
     Contract.Assert(ide != null);
     Contract.Assume(ide.Decl != null);
     if (!ide.Decl.IsMutable) {
       tc.Error(this, "modifies list contains constant: {0}", ide.Name);
     }
     ide.Typecheck(tc);
   }
   foreach (Requires/*!*/ e in Requires) {
     Contract.Assert(e != null);
     e.Typecheck(tc);
   }
   bool oldYields = tc.Yields;
   tc.Yields = QKeyValue.FindBoolAttribute(Attributes, "yields");
   foreach (Ensures/*!*/ e in Ensures) {
     Contract.Assert(e != null);
     e.Typecheck(tc);
   }
   tc.Yields = oldYields;
 }
Exemple #16
0
 public override void Typecheck(TypecheckingContext tc) {
   //Contract.Requires(tc != null);
     
   if (IsAtomicSpecification && !tc.Yields)
   {
       tc.Error(this, "atomic specification allowed only in a yielding procedure");
       return;
   }
   this.Condition.Typecheck(tc);
   Contract.Assert(this.Condition.Type != null);  // follows from postcondition of Expr.Typecheck
   if (!this.Condition.Type.Unify(Type.Bool)) {
     tc.Error(this, "postconditions must be of type bool");
   }
 }
Exemple #17
0
 public override void Typecheck(TypecheckingContext tc) {
   //Contract.Requires(tc != null);
   this.Condition.Typecheck(tc);
   Contract.Assert(this.Condition.Type != null);  // follows from postcondition of Expr.Typecheck
   if (!this.Condition.Type.Unify(Type.Bool)) {
     tc.Error(this, "preconditions must be of type bool");
   }
 }
Exemple #18
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);
            }
          }
        }
      }
    }
Exemple #19
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");
            }
            }
        }
Exemple #20
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);
     }
     }
 }
Exemple #21
0
    public override void Typecheck(TypecheckingContext tc) {
      //Contract.Requires(tc != null);
      base.Typecheck(tc);

      if (Parents != null) {
        foreach (ConstantParent/*!*/ p in Parents) {
          Contract.Assert(p != null);
          p.Parent.Typecheck(tc);
          if (!cce.NonNull(p.Parent.Decl).TypedIdent.Type.Unify(this.TypedIdent.Type))
            tc.Error(p.Parent,
                     "parent of constant has incompatible type ({0} instead of {1})",
                     p.Parent.Decl.TypedIdent.Type, this.TypedIdent.Type);
        }
      }
    }