コード例 #1
0
        public void Test(string methodName, PotentialType expectedType)
        {
            var method = typeof (TestTarget.IL.CallParameterTypesRecorderTarget).GetMethod(methodName);

            var instructions = method.GetInstructions();

            var recorder = new CallParameterTypesRecorder();

            recorder.Initialize(method);

            var takeWhile = instructions.TakeWhile(x => x.OpCode != OpCodes.Nop);
            var state = recorder.Visit(TypeAnalysisState.Empty,  takeWhile);

            Assert.That(state.StackTop, Is.EqualTo(expectedType));
        }
コード例 #2
0
        public void Walk(MethodInfo method, ControlFlowGraph graph)
        {
            this.recorder = new CallParameterTypesRecorder();

            this.recorder.Initialize(method);

            var variables = method.GetMethodBody().LocalVariables.ToDictionary(x => x.LocalIndex, x => PotentialType.FromType(x.LocalType));
            var parameters = method.GetParameters().ToDictionary(x => x.Position, x => PotentialType.FromType(x.ParameterType));
            var initialState = new TypeAnalysisState(variables, parameters);

            var walker = new ControlFlowGraphWalker<TypeAnalysisState>
            {
                InitialState = initialState,
                VisitingBlock = (state, block) => this.recorder.Visit(state, block.Instructions)
            };

            walker.WalkCore(method, graph);
        }