Exemplo n.º 1
0
        private MemberDecl InterpretAndUnfoldTactic(MemberDecl target, Resolver r)
        {
            Contract.Requires(Tcce.NonNull(target));
            // initialize new stack for variables
            var frame = new Stack <Dictionary <IVariable, Type> >();

            var method = target as Method;

            if (method != null)
            {
                _state.SetTopLevelClass(method.EnclosingClass?.Name);
                _state.TargetMethod = target;
                var dict = method.Ins.Concat(method.Outs)
                           .ToDictionary <IVariable, IVariable, Type>(item => item, item => item.Type);

                frame.Push(dict);
                var preRes = GetResultList().Keys.Copy();

                InterpertBlockStmt(method.Body, frame);
                GenerateResultCode();
                // sanity check
                Contract.Assert(frame.Count == 0);

                var newRets =
                    GetResultList().Where(kvp => !preRes.Contains(kvp.Key)).ToDictionary(i => i.Key, i => i.Value);

                Contract.Assert(newRets.Count != 0);
                var body = Util.InsertCode(_state, newRets);
                method.Body.Body.Clear();
                if (newRets.Count != 0 && body != null)
                {
                    method.Body.Body.AddRange(body.Body);
                }

                // use the original resolver of the resoved program, as it contains all the necessary type info
                method.CallsTactic = 0;
                // set the current class in the resolver, so that it can refer to the memberdecl correctly
                r.SetCurClass(method.EnclosingClass as ClassDecl);
                //asssume the defualt module is the current module, this needs to be improved.
                r.ResolveMethodBody(method, _state.GetDafnyProgram().DefaultModuleDef.Name);
                //Console.WriteLine("Errors: " + _program.reporter.Count(ErrorLevel.Error));
            }
            return(method);
        }