Ejemplo n.º 1
0
            public PopTreeGraph Build(MethodDefinition method)
            {
                IControlFlowGraph cfg   = FlowGraphFactory.CreateControlFlowGraph(method);
                PopTreeGraph      graph = new PopTreeGraph(cfg);

                foreach (IInstructionBlock block in cfg.Blocks)
                {
                    PopTreeListBuilder build = new PopTreeListBuilder();

                    Instruction instruction  = block.FirstInstruction;
                    ArrayList   instructions = new ArrayList();
                    while (instruction != null)
                    {
                        instructions.Add(instruction);
                        instruction = instruction.Next;
                    }

                    PopTreeList list = build.Build(instructions);
                    if (list != null)
                    {
                        list.Block = block;
                        graph.Add(list);
                    }
                }
                return(graph);
            }
Ejemplo n.º 2
0
        public void Blah()
        {
            MemberHasAttributeMatcher matcher  = new MemberHasAttributeMatcher("CodeWeaving.Matcher.SampleCode.SuperDuperAttribute");
            AssemblyDefinition        assembly = AssemblyFactory.GetAssembly(GetType().Assembly.Location);
            MemberFinder     memberFinder      = new MemberFinder();
            FindMemberUsages findMemberUsages  = new FindMemberUsages();

            foreach (MemberReference member in memberFinder.FindMembers(assembly, matcher))
            {
                PropertyDefinition property = member as PropertyDefinition;
                if (property != null)
                {
                    Console.WriteLine("Found: {0}", property);
                    foreach (MemberUsage usage in findMemberUsages.FindUsages(assembly, property.GetMethod))
                    {
                        Console.WriteLine("Usage: {0}", usage.MethodDefinition);
                        CodeInspector codeInspector = new CodeInspector();
                        codeInspector.Inspect(usage.MethodDefinition, _mocks.DynamicMock <IInspectionVisitor>());

                        ControlFlowGraph controlFlowGraph = FlowGraphFactory.CreateControlFlowGraph(usage.MethodDefinition);
                        // ActionFlowGraph actionFlowGraph = FlowGraphFactory.CreateActionFlowGraph(controlFlowGraph);
                        StringWriter writer = new StringWriter();
                        FormatControlFlowGraph(writer, controlFlowGraph);
                        Console.WriteLine(writer.ToString());
                    }
                }
            }
        }
        protected void RunTestCase(string name)
        {
            MethodDefinition method = LoadTestCaseMethod(name);
            ControlFlowGraph cfg    = FlowGraphFactory.CreateControlFlowGraph(method);

            Assert.AreEqual(Normalize(LoadExpectedControlFlowString(name)), Normalize(ToString(cfg)));
        }
Ejemplo n.º 4
0
        private static bool IsNoSideEffectIndirectActivationInvocation(MethodInvocationExpression invocation)
        {
            MethodDefinition methodDefinition = MethodDefinitionFor(invocation);

            if (null == methodDefinition)
            {
                return(false);
            }
            ActionFlowGraph afg = FlowGraphFactory.CreateActionFlowGraph(FlowGraphFactory.CreateControlFlowGraph(methodDefinition));

            if (afg.Blocks.Count == 2 && afg.Blocks[0].ActionType == ActionType.Invoke)
            {
                InvokeActionBlock invocationBlock = (InvokeActionBlock)afg.Blocks[0];
                return(IsActivateInvocation(invocationBlock.Expression));
            }

            return(false);
        }
Ejemplo n.º 5
0
 private static ActionFlowGraph CreateActionFlowGraph(MethodDefinition method)
 {
     return(FlowGraphFactory.CreateActionFlowGraph(FlowGraphFactory.CreateControlFlowGraph(method)));
 }
Ejemplo n.º 6
0
        private static Expression GetQueryExpression(MethodDefinition method)
        {
            ActionFlowGraph afg = FlowGraphFactory.CreateActionFlowGraph(FlowGraphFactory.CreateControlFlowGraph(method));

            return(GetQueryExpression(afg));
        }
Ejemplo n.º 7
0
        ActionFlowGraph GetActionFlowGraph(string name)
        {
            MethodDefinition method = LoadTestCaseMethod(name);

            return(FlowGraphFactory.CreateActionFlowGraph(FlowGraphFactory.CreateControlFlowGraph(method)));
        }