コード例 #1
0
        public void CheckStackLength(Type type)
        {
            IEnumerable<MethodInfo> methods = type.GetMethods()
                .Where(x => x.GetMethodBody() != null)
                .Where(x => x.DeclaringType == type);

            foreach (var method in methods)
            {
                var graph = ControlFlowGraphFactory.BuildForMethod(method);

                var walker = new ControlFlowGraphWalker<int>()
                {
                    InitialState = 0,
                    VisitingBlock = (stack, block) => stack + block.StackDiff
                };

                try
                {
                    var result = walker.WalkCore(method, graph);
                    Assert.That(result.Single(), Is.EqualTo(0), string.Format("Stack not 0 for method (static:{1}) {0}", method, method.IsStatic));
                }
                catch (Exception e)
                {
                    Assert.Fail("Type: {0} Method:{1} {2}", method, method.DeclaringType, e);
                }
            }
        }
コード例 #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);
        }