Example #1
0
        public override void Resolve(ResolutionContext rc)
        {
            //Contract.Requires(rc != null);

            if ((Key == "minimize" || Key == "maximize") && Params.Count != 1)
            {
                rc.Error(this, "attributes :minimize and :maximize accept only one argument");
            }

            if (Key == "verified_under" && Params.Count != 1)
            {
                rc.Error(this, "attribute :verified_under accepts only one argument");
            }

            foreach (object p in Params)
            {
                if (p is Expr)
                {
                    var oldCtxtState = rc.StateMode;
                    if (oldCtxtState == ResolutionContext.State.Single)
                    {
                        rc.StateMode = ResolutionContext.State.Two;
                    }

                    ((Expr)p).Resolve(rc);
                    if (oldCtxtState != rc.StateMode)
                    {
                        rc.StateMode = oldCtxtState;
                    }
                }
            }
        }
Example #2
0
 protected override void ResolveTriggers(ResolutionContext rc)
 {
     //Contract.Requires(rc != null);
     for (Trigger tr = this.Triggers; tr != null; tr = tr.Next)
     {
         int prevErrorCount = rc.ErrorCount;
         tr.Resolve(rc);
         if (prevErrorCount == rc.ErrorCount)
         {
             // for positive triggers, make sure all bound variables are mentioned
             if (tr.Pos)
             {
                 Set /*Variable*/ freeVars = new Set/*Variable*/ ();
                 tr.ComputeFreeVariables(freeVars);
                 foreach (Variable /*!*/ v in Dummies)
                 {
                     Contract.Assert(v != null);
                     if (!freeVars[v])
                     {
                         rc.Error(tr, "trigger must mention all quantified variables, but does not mention: {0}", v);
                     }
                 }
             }
         }
     }
 }
Example #3
0
        public override void Resolve(ResolutionContext rc)
        {
            //Contract.Requires(rc != null);

            if (Dummies.Count != Rhss.Count)
            {
                rc.Error(this.tok, "number of left-hand sides does not match number of right-hand sides");
            }

            foreach (var e in Rhss)
            {
                e.Resolve(rc);
            }

            rc.PushVarContext();
            foreach (var v in Dummies)
            {
                Contract.Assert(v != null);
                v.Register(rc);
                v.Resolve(rc);
            }
            for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next)
            {
                kv.Resolve(rc);
            }
            Body.Resolve(rc);
            rc.PopVarContext();
        }
Example #4
0
        public override void Resolve(ResolutionContext rc)
        {
            //Contract.Requires(rc != null);

            if ((Key == "minimize" || Key == "maximize") && Params.Count != 1)
            {
                rc.Error(this, "attributes :minimize and :maximize accept only one argument");
            }

            if (Key == "verified_under" && Params.Count != 1)
            {
                rc.Error(this, "attribute :verified_under accepts only one argument");
            }

            foreach (object p in Params)
            {
                if (p is Expr)
                {
                    ((Expr)p).Resolve(rc);
                }
            }
        }
Example #5
0
        public override void Resolve(ResolutionContext rc)
        {
            //Contract.Requires(rc != null);
            if (rc.TriggerMode)
            {
                rc.Error(this, "quantifiers are not allowed in triggers");
            }

            int previousTypeBinderState = rc.TypeBinderState;

            try
            {
                foreach (TypeVariable /*!*/ v in TypeParameters)
                {
                    Contract.Assert(v != null);
                    rc.AddTypeBinder(v);
                }

                rc.PushVarContext();
                foreach (Variable /*!*/ v in Dummies)
                {
                    Contract.Assert(v != null);
                    v.Register(rc);
                    v.Resolve(rc);
                }

                for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next)
                {
                    kv.Resolve(rc);
                }

                this.ResolveTriggers(rc);
                Body.Resolve(rc);
                rc.PopVarContext();

                // establish a canonical order of the type parameters
                this.TypeParameters = Type.SortTypeParams(TypeParameters,
                                                          new List <Type>(Dummies.Select(Item => Item.TypedIdent.Type).ToArray()), null);
            }
            finally
            {
                rc.TypeBinderState = previousTypeBinderState;
            }
        }
Example #6
0
        public override void Resolve(ResolutionContext rc)
        {
            //Contract.Requires(rc != null);
            rc.TriggerMode = true;
            foreach (Expr /*!*/ e in this.Tr)
            {
                Contract.Assert(e != null);
                e.Resolve(rc);

                // just a variable by itself is not allowed
                if (e is IdentifierExpr)
                {
                    rc.Error(e, "a matching pattern must be more than just a variable by itself: {0}", e);
                }

                // the free-variable check is performed in the surrounding quantifier expression (because that's
                // where the bound variables are known)
            }
            rc.TriggerMode = false;
        }
Example #7
0
 public override void Resolve(ResolutionContext/*!*/ rc) {
   // Contract.Requires(rc != null);
   rc.Error(this, "bitvector bounds in illegal position");
 }
Example #8
0
 protected override void ResolveTriggers(ResolutionContext rc) {
   //Contract.Requires(rc != null);
   for (Trigger tr = this.Triggers; tr != null; tr = tr.Next) {
     int prevErrorCount = rc.ErrorCount;
     tr.Resolve(rc);
     if (prevErrorCount == rc.ErrorCount) {
       // for positive triggers, make sure all bound variables are mentioned
       if (tr.Pos) {
         Set /*Variable*/ freeVars = new Set /*Variable*/ ();
         tr.ComputeFreeVariables(freeVars);
         foreach (Variable/*!*/ v in Dummies) {
           Contract.Assert(v != null);
           if (!freeVars[v]) {
             rc.Error(tr, "trigger must mention all quantified variables, but does not mention: {0}", v);
           }
         }
       }
     }
   }
 }
Example #9
0
    public override void Resolve(ResolutionContext rc) {
      //Contract.Requires(rc != null);
      rc.TriggerMode = true;
      foreach (Expr/*!*/ e in this.Tr) {
        Contract.Assert(e != null);
        e.Resolve(rc);

        // just a variable by itself is not allowed
        if (e is IdentifierExpr) {
          rc.Error(e, "a matching pattern must be more than just a variable by itself: {0}", e);
        }

        // the free-variable check is performed in the surrounding quantifier expression (because that's
        // where the bound variables are known)
      }
      rc.TriggerMode = false;
    }
Example #10
0
    public override void Resolve(ResolutionContext rc) {
      //Contract.Requires(rc != null);

      if ((Key == "minimize" || Key == "maximize") && Params.Count != 1)
      {
        rc.Error(this, "attributes :minimize and :maximize accept only one argument");
      }

      if (Key == "verified_under" && Params.Count != 1)
      {
        rc.Error(this, "attribute :verified_under accepts only one argument");
      }

      foreach (object p in Params) {
        if (p is Expr) {
          ((Expr)p).Resolve(rc);
        }
      }
    }
Example #11
0
    public override void Resolve(ResolutionContext rc) {
      //Contract.Requires(rc != null);
      if (rc.TriggerMode) {
        rc.Error(this, "quantifiers are not allowed in triggers");
      }

      int previousTypeBinderState = rc.TypeBinderState;
      try {
        foreach (TypeVariable/*!*/ v in TypeParameters) {
          Contract.Assert(v != null);
          rc.AddTypeBinder(v);
        }

        rc.PushVarContext();
        foreach (Variable/*!*/ v in Dummies) {
          Contract.Assert(v != null);
          v.Register(rc);
          v.Resolve(rc);
        }
        for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next) {
          kv.Resolve(rc);
        }
        this.ResolveTriggers(rc);
        Body.Resolve(rc);
        rc.PopVarContext();

        // establish a canonical order of the type parameters
        this.TypeParameters = Type.SortTypeParams(TypeParameters, new List<Type>(Dummies.Select(Item => Item.TypedIdent.Type).ToArray()), null);

      } finally {
        rc.TypeBinderState = previousTypeBinderState;
      }
    }
Example #12
0
    public override void Resolve(ResolutionContext rc) {
      //Contract.Requires(rc != null);
      if (Proc != null) {
        // already resolved
        return;
      }
      DeclWithFormals dwf = rc.LookUpProcedure(cce.NonNull(this.Name));
      Proc = dwf as Procedure;
      if (dwf == null) {
        rc.Error(this, "implementation given for undeclared procedure: {0}", this.Name);
      } else if (Proc == null) {
        rc.Error(this, "implementations given for function, not procedure: {0}", this.Name);
      }

      int previousTypeBinderState = rc.TypeBinderState;
      try {
        RegisterTypeParameters(rc);

        rc.PushVarContext();
        RegisterFormals(InParams, rc);
        RegisterFormals(OutParams, rc);

        foreach (Variable/*!*/ v in LocVars) {
          Contract.Assert(v != null);
          v.Register(rc);
          v.Resolve(rc);
        }
        foreach (Variable/*!*/ v in LocVars) {
          Contract.Assert(v != null);
          v.ResolveWhere(rc);
        }

        rc.PushProcedureContext();
        foreach (Block b in Blocks) {
          b.Register(rc);
        }

        ResolveAttributes(rc);

        rc.StateMode = ResolutionContext.State.Two;
        foreach (Block b in Blocks) {
          b.Resolve(rc);
        }
        rc.StateMode = ResolutionContext.State.Single;

        rc.PopProcedureContext();
        rc.PopVarContext();

        Type.CheckBoundVariableOccurrences(TypeParameters,
                                           new List<Type>(InParams.Select(Item => Item.TypedIdent.Type).ToArray()),
                                           new List<Type>(OutParams.Select(Item => Item.TypedIdent.Type).ToArray()),
                                           this.tok, "implementation arguments",
                                           rc);
      } finally {
        rc.TypeBinderState = previousTypeBinderState;
      }
      SortTypeParams();
    }
Example #13
0
    public override void Resolve(ResolutionContext rc) {
      //Contract.Requires(rc != null);
      base.Resolve(rc);
      if (Parents != null) {
        foreach (ConstantParent/*!*/ p in Parents) {
          Contract.Assert(p != null);
          p.Parent.Resolve(rc);
          if (p.Parent.Decl != null && !(p.Parent.Decl is Constant))
            rc.Error(p.Parent, "the parent of a constant has to be a constant");
          if (this.Equals(p.Parent.Decl))
            rc.Error(p.Parent, "constant cannot be its own parent");
        }
      }

      // check that no parent occurs twice
      // (could be optimised)
      if (Parents != null) {
        for (int i = 0; i < Parents.Count; ++i) {
          if (Parents[i].Parent.Decl != null) {
            for (int j = i + 1; j < Parents.Count; ++j) {
              if (Parents[j].Parent.Decl != null &&
                  cce.NonNull(Parents[i].Parent.Decl).Equals(Parents[j].Parent.Decl))
                rc.Error(Parents[j].Parent,
                         "{0} occurs more than once as parent",
                         Parents[j].Parent.Decl);
            }
          }
        }
      }
    }
Example #14
0
        public override void Resolve(ResolutionContext rc)
        {
            //Contract.Requires(rc != null);
              if (Proc != null) {
            // already resolved
            return;
              }
              ResolveAttributes(Attributes, rc);
              Proc = rc.LookUpProcedure(callee) as Procedure;
              if (Proc == null) {
            rc.Error(this, "call to undeclared procedure: {0}", callee);
              }
              foreach (Expr e in Ins) {
            if (e != null) {
              e.Resolve(rc);
            }
              }
              HashSet<Variable> actualOuts = new HashSet<Variable>();
              foreach (IdentifierExpr ide in Outs) {
            if (ide != null) {
              ide.Resolve(rc);
              if (ide.Decl != null) {
            if (actualOuts.Contains(ide.Decl)) {
              rc.Error(this, "left-hand side of call command contains variable twice: {0}", ide.Name);
            } else {
              actualOuts.Add(ide.Decl);
            }
              }
            }
              }

              if (Proc == null)
            return;

              // first make sure that the right number of parameters is given
              // (a similar check is in CheckArgumentTypes, but we are not
              // able to call this method because it cannot cope with Ins/Outs
              // that are null)
              if (Ins.Count != Proc.InParams.Count) {
            rc.Error(this.tok,
                 "wrong number of arguments in call to {0}: {1}",
                 callee, Ins.Count);
            return;
              }
              if (Outs.Count != Proc.OutParams.Count) {
            rc.Error(this.tok,
                 "wrong number of result variables in call to {0}: {1}",
                 callee, Outs.Count);
            return;
              }
              if (IsAsync) {
            if (Proc.OutParams.Count > 0) {
              rc.Error(this.tok, "a procedure called asynchronously can have no output parameters");
              return;
            }
              }

              // Check that type parameters can be determined using the given
              // actual i/o arguments. This is done already during resolution
              // because CheckBoundVariableOccurrences needs a resolution
              // context
              List<Type>/*!*/ formalInTypes = new List<Type>();
              List<Type>/*!*/ formalOutTypes = new List<Type>();
              for (int i = 0; i < Ins.Count; ++i)
            if (Ins[i] != null)
              formalInTypes.Add(cce.NonNull(Proc.InParams[i]).TypedIdent.Type);
              for (int i = 0; i < Outs.Count; ++i)
            if (Outs[i] != null)
              formalOutTypes.Add(cce.NonNull(Proc.OutParams[i]).TypedIdent.Type);

              // we need to bind the type parameters for this
              // (this is expected by CheckBoundVariableOccurrences)
              int previousTypeBinderState = rc.TypeBinderState;
              try {
            foreach (TypeVariable/*!*/ v in Proc.TypeParameters) {
              Contract.Assert(v != null);
              rc.AddTypeBinder(v);
            }
            Type.CheckBoundVariableOccurrences(Proc.TypeParameters,
                                           formalInTypes, formalOutTypes,
                                           this.tok, "types of given arguments",
                                           rc);
              } finally {
            rc.TypeBinderState = previousTypeBinderState;
              }
        }
Example #15
0
        public override void Resolve(ResolutionContext rc)
        {
            if (Lhss.Count != Rhss.Count)
            rc.Error(this,
                 "number of left-hand sides does not match number of right-hand sides");

              foreach (AssignLhs/*!*/ e in Lhss) {
            Contract.Assert(e != null);
            e.Resolve(rc);
              }
              foreach (Expr/*!*/ e in Rhss) {
            Contract.Assert(e != null);
            e.Resolve(rc);
              }

              // check for double occurrences of assigned variables
              // (could be optimised)
              for (int i = 0; i < Lhss.Count; ++i) {
            for (int j = i + 1; j < Lhss.Count; ++j) {
              if (cce.NonNull(Lhss[i].DeepAssignedVariable).Equals(
                  Lhss[j].DeepAssignedVariable))
            rc.Error(Lhss[j],
                     "variable {0} is assigned more than once in parallel assignment",
                     Lhss[j].DeepAssignedVariable);
            }
              }
        }
Example #16
0
 public override void Resolve(ResolutionContext rc)
 {
     ResolveAttributes(Attributes, rc);
       foreach (CallCmd callCmd in CallCmds)
       {
       callCmd.Resolve(rc);
       }
       HashSet<Variable> parallelCallLhss = new HashSet<Variable>();
       foreach (CallCmd callCmd in CallCmds)
       {
       foreach (IdentifierExpr ie in callCmd.Outs)
       {
           if (parallelCallLhss.Contains(ie.Decl))
           {
               rc.Error(this, "left-hand side of parallel call command contains variable twice: {0}", ie.Name);
           }
           else
           {
               parallelCallLhss.Add(ie.Decl);
           }
       }
       }
 }
Example #17
0
 public override void Resolve(ResolutionContext rc)
 {
     //Contract.Requires(rc != null);
       Contract.Ensures(labelTargets != null);
       if (labelTargets != null) {
     // already resolved
     return;
       }
       Contract.Assume(this.labelNames != null);
       labelTargets = new List<Block>();
       foreach (string/*!*/ lbl in labelNames) {
     Contract.Assert(lbl != null);
     Block b = rc.LookUpBlock(lbl);
     if (b == null) {
       rc.Error(this, "goto to unknown block: {0}", lbl);
     } else {
       labelTargets.Add(b);
     }
       }
       Debug.Assert(rc.ErrorCount > 0 || labelTargets.Count == labelNames.Count);
 }
Example #18
0
    public static void ResolveTypeSynonyms(List<TypeSynonymDecl/*!*/>/*!*/ synonymDecls, ResolutionContext/*!*/ rc) {
      Contract.Requires(cce.NonNullElements(synonymDecls));
      Contract.Requires(rc != null);
      // then discover all dependencies between type synonyms
      IDictionary<TypeSynonymDecl/*!*/, List<TypeSynonymDecl/*!*/>/*!*/>/*!*/ deps =
        new Dictionary<TypeSynonymDecl/*!*/, List<TypeSynonymDecl/*!*/>/*!*/>();
      foreach (TypeSynonymDecl/*!*/ decl in synonymDecls) {
        Contract.Assert(decl != null);
        List<TypeSynonymDecl/*!*/>/*!*/ declDeps = new List<TypeSynonymDecl/*!*/>();
        FindDependencies(decl.Body, declDeps, rc);
        deps.Add(decl, declDeps);
      }

      List<TypeSynonymDecl/*!*/>/*!*/ resolved = new List<TypeSynonymDecl/*!*/>();

      int unresolved = synonymDecls.Count - resolved.Count;
      while (unresolved > 0) {
        foreach (TypeSynonymDecl/*!*/ decl in synonymDecls) {
          Contract.Assert(decl != null);
          if (!resolved.Contains(decl) &&
              deps[decl].All(d => resolved.Contains(d))) {
            decl.Resolve(rc);
            resolved.Add(decl);
          }
        }

        int newUnresolved = synonymDecls.Count - resolved.Count;
        if (newUnresolved < unresolved) {
          // we are making progress
          unresolved = newUnresolved;
        } else {
          // there have to be cycles in the definitions
          foreach (TypeSynonymDecl/*!*/ decl in synonymDecls) {
            Contract.Assert(decl != null);
            if (!resolved.Contains(decl)) {
              rc.Error(decl,
                         "type synonym could not be resolved because of cycles: {0}" +
                         " (replacing body with \"bool\" to continue resolving)",
                         decl.Name);

              // we simply replace the bodies of all remaining type
              // synonyms with "bool" so that resolution can continue
              decl.Body = Type.Bool;
              decl.Resolve(rc);
            }
          }

          unresolved = 0;
        }
      }
    }
Example #19
0
 public override void Resolve(ResolutionContext rc) {
   HashSet<string> selectorNames = new HashSet<string>();
   foreach (DatatypeSelector selector in selectors) {
     if (selector.Name.StartsWith("#")) {
       rc.Error(selector.tok, "The selector must be a non-empty string");
     }
     else {
       if (selectorNames.Contains(selector.Name))
         rc.Error(this.tok, "The selectors for a constructor must be distinct strings");
       else
         selectorNames.Add(selector.Name);
     }
   }
   base.Resolve(rc);
 }