Exemplo n.º 1
0
        private List <Statement> FindSingleTacticApplication(MemberDecl target, UpdateStmt chosenTacticCall)
        {
            Contract.Requires(tcce.NonNull(target));
            _frame = new Stack <Dictionary <IVariable, Type> >();
            var method = target as Method;

            if (method == null)
            {
                return(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);
            SearchBlockStmt(method.Body);
            _frame.Pop();
            Contract.Assert(_frame.Count == 0);
            return((from r in _resultList
                    where r.Key.Tok.pos == chosenTacticCall.Tok.pos
                    select r.Value).FirstOrDefault());
        }
Exemplo n.º 2
0
        private MemberDecl EvalTacticApplication(MemberDecl target, Resolver r)
        {
            Contract.Requires(tcce.NonNull(target));
            // initialize new stack for variables
            _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 pre_res = _resultList.Keys.Copy();

                SearchBlockStmt(method.Body);
                dict = _frame.Pop();
                // sanity check
                Contract.Assert(_frame.Count == 0);

                var new_rets = _resultList.Where(kvp => !pre_res.Contains(kvp.Key)).ToDictionary(i => i.Key, i => i.Value);
                Contract.Assert(new_rets.Count != 0);
                var body = Util.InsertCode(_state, new_rets);
                method.Body.Body.Clear();
                if (body != null)
                {
                    method.Body.Body.AddRange(body.Body);
                }

                // use the original resolver of the resoved program, as it contains all the necessary type info
                //TODO: how about pre and post ??
                method.CallsTactic = false; // set the tactic call lable to be false, no actual consequence
                // set the current class in the resolver, so that it can refer to the memberdecl correctly
                r.SetCurClass(method.EnclosingClass as ClassDecl);
                r.ResolveMethodBody(method);
                //Console.WriteLine("Errors: " + _program.reporter.Count(ErrorLevel.Error));
            }
            return(method);
        }