Exemplo n.º 1
0
        private VCExpr GenFunctionAxiom(UntypedFunction fun, Function originalFun)
        {
            Contract.Requires(originalFun != null);
              Contract.Ensures(Contract.Result<VCExpr>() != null);
              List<Type/*!*/>/*!*/ originalInTypes = new List<Type/*!*/>(originalFun.InParams.Count);
              foreach (Formal/*!*/ f in originalFun.InParams)
            originalInTypes.Add(f.TypedIdent.Type);

              return GenFunctionAxiom(fun.Fun, fun.ImplicitTypeParams, fun.ExplicitTypeParams,
                              originalInTypes,
                              cce.NonNull(originalFun.OutParams[0]).TypedIdent.Type);
        }
Exemplo n.º 2
0
        internal UntypedFunction Typed2Untyped(Function fun)
        {
            Contract.Requires(fun != null);
              UntypedFunction res;
              if (!Typed2UntypedFunctions.TryGetValue(fun, out res)) {
            Contract.Assert(fun.OutParams.Count == 1);

            // if all of the parameters are int or bool, the function does
            // not have to be changed
            if (fun.InParams.All(param => UnchangedType(cce.NonNull(param).TypedIdent.Type)) &&
            UnchangedType(cce.NonNull(fun.OutParams[0]).TypedIdent.Type) &&
            fun.TypeParameters.Count == 0) {
              res = new UntypedFunction(fun, new List<TypeVariable/*!*/>(), new List<TypeVariable/*!*/>());
            } else {
              List<Type/*!*/>/*!*/ argTypes = new List<Type/*!*/>();
              foreach (Variable/*!*/ v in fun.InParams) {
            Contract.Assert(v != null);
            argTypes.Add(v.TypedIdent.Type);
              }

              List<TypeVariable/*!*/>/*!*/ implicitParams, explicitParams;
              SeparateTypeParams(argTypes, fun.TypeParameters, out implicitParams, out explicitParams);

              Type[]/*!*/ types = new Type[explicitParams.Count + fun.InParams.Count + 1];
              int i = 0;
              for (int j = 0; j < explicitParams.Count; ++j) {
            types[i] = T;
            i = i + 1;
              }
              for (int j = 0; j < fun.InParams.Count; ++i, ++j)
            types[i] = TypeAfterErasure(cce.NonNull(fun.InParams[j]).TypedIdent.Type);
              types[types.Length - 1] = TypeAfterErasure(cce.NonNull(fun.OutParams[0]).TypedIdent.Type);

              Function/*!*/ untypedFun = HelperFuns.BoogieFunction(fun.Name, types);
              Contract.Assert(untypedFun != null);
              untypedFun.Attributes = fun.Attributes;
              res = new UntypedFunction(untypedFun, implicitParams, explicitParams);
              if (U.Equals(types[types.Length - 1]))
            AddTypeAxiom(GenFunctionAxiom(res, fun));
            }

            Typed2UntypedFunctions.Add(fun, res);
              }
              return res;
        }