Beispiel #1
0
    public TypeApply Compile_Method(Method method, Dictionary <TypeParameter, Type> typeArgs, List <TypeParameter> extraTypeParams = null)
    {
        Dictionary <string, TypeParameter> substArgs = new Dictionary <string, TypeParameter>();
        var fullTypeArgs = method.TypeArgs.Concat(extraTypeParams ?? new List <TypeParameter>()).ToList();

        fullTypeArgs.ForEach(t => substArgs.Add(t.Name, t));
        typeArgs = typeArgs.ToDictionary(p => substArgs[p.Key.Name], p => p.Value);
        TypeApply apply = new TypeApply(this, DafnySpec.SanitizedName(method), fullTypeArgs, typeArgs);

        //Console.Error.WriteLine("Compile_Method: " + method + " :: " + method.GetType() + " " + String.Join(",", typeArgs));
        if (!compileMethods.ContainsKey(apply))
        {
            //Console.Error.WriteLine("Compile_Method# " + method + " :: " + method.GetType() + " " + String.Join(",", typeArgs));
            compileMethods.Add(apply, apply);
            var tok     = method.tok;
            var writers = ChooseWriter(tok, method.Name, apply);
            CompileMethodGhost compile = NewCompileMethod(this, method, apply,
                                                          writers.Item1, writers.Item2, writers.Item3, writers.Item4);
            if (writers.Item3 == "Seq" && typeArgs.Count == 1)
            {
                compile.visibleElementType = new List <Type>(apply.typeArgs.Values)[0];
            }
            compile.minVerify = minVerify;
            try
            {
                compile.Compile();
            }
            catch (Exception e)
            {
                throw new Exception("while compiling method " + method.Name, e);
            }
        }
        return(apply);
    }
Beispiel #2
0
    public TypeApply Compile_Function(Function function, Dictionary <TypeParameter, Type> typeArgs)
    {
        Dictionary <string, TypeParameter> substArgs = new Dictionary <string, TypeParameter>();

        function.TypeArgs.ForEach(t => substArgs.Add(t.Name, t));
        typeArgs = typeArgs.ToDictionary(p => substArgs[p.Key.Name], p => p.Value);
        TypeApply apply = new TypeApply(this, DafnySpec.SanitizedName(function), function.TypeArgs, typeArgs);

        if (!compileFunctions.ContainsKey(apply))
        {
            compileFunctions.Add(apply, apply);
            var tok = function.tok;
            //Console.Error.WriteLine("function: " + function + " :: " + function.GetType());
            //Console.Error.WriteLine("    " + function.Body);
            //Console.Error.WriteLine("    " + function.IsRecursive + " " + function.IsGhost);
            var writers = ChooseWriter(tok, function.Name, apply);
            if (!Attributes.Contains(function.Attributes, "imported"))
            {
                try
                {
                    var compile = new CompileFunction(this, function, apply, writers.Item1, writers.Item2,
                                                      writers.Item3, writers.Item4);
                    if (writers.Item3 == "Seq" && typeArgs.Count == 1)
                    {
                        compile.visibleElementType = new List <Type>(apply.typeArgs.Values)[0];
                    }
                    compile.minVerify = minVerify;
                    compile.Compile();
                }
                catch (Exception e)
                {
                    throw new Exception("while compiling function " + function.Name, e);
                }
            }
            else
            {
                // imported
                if (function.Ens.Count > 0)
                {
                    string name = FunName(SimpleName(apply.AppName()));
                    AddLemma(new LemmaCall(writers.Item3, (Type)null,
                                           "call lemma_fun_ensures_" + name + "();", false));
                }
            }
            bool hidden = Attributes.Contains(function.Attributes, "opaque");
            bool isFull = function.Name.Contains("#") && function.Name.EndsWith("_FULL");
            if (!function.IsGhost && !isFull && !IsSpecFile(function.tok.filename))
            {
                Compile_FunctionAsMethod(function, typeArgs, substArgs);
            }
        }
        return(apply);
    }