コード例 #1
0
        public async Task <CallGraph <MethodDescriptor, LocationDescriptor> > GenerateCallGraphAsync()
        {
            Logger.LogS("SolutionAnalyzer", "GenerateCallGraphAsync", "Start building CG");
            var callgraph = new CallGraph <MethodDescriptor, LocationDescriptor>();
            var roots     = await this.SolutionManager.GetRootsAsync(this.RootKind);

            var worklist = new Queue <MethodDescriptor>(roots);
            var visited  = new HashSet <MethodDescriptor>();

            callgraph.AddRootMethods(roots);

            while (worklist.Count > 0)
            {
                var currentMethodDescriptor = worklist.Dequeue();
                visited.Add(currentMethodDescriptor);
                Logger.LogS("SolutionAnalyzer", "GenerateCallGraphAsync", "Proccesing  {0}", currentMethodDescriptor);

                var methodEntity = await this.SolutionManager.GetMethodEntityAsync(currentMethodDescriptor);

                var calleesInfoForMethod = await methodEntity.GetCalleesInfoAsync();

                foreach (var entry in calleesInfoForMethod)
                {
                    var analysisNode = entry.Key;
                    var callees      = entry.Value;

                    foreach (var calleeDescriptor in callees)
                    {
                        Logger.LogS("SolutionAnalyzer", "GenerateCallGraphAsync", "Adding {0}-{1} to CG", currentMethodDescriptor, calleeDescriptor);
                        callgraph.AddCallAtLocation(analysisNode.LocationDescriptor, currentMethodDescriptor, calleeDescriptor);

                        if (!visited.Contains(calleeDescriptor) && !worklist.Contains(calleeDescriptor))
                        {
                            worklist.Enqueue(calleeDescriptor);
                        }
                    }
                }
            }

            return(callgraph);
        }
コード例 #2
0
        public CallGraph<MethodDescriptor, LocationDescriptor> GenerateCallGraph()
        {
            var roots = ProjectCodeProvider.GetMainMethods(this.Solution);
            Contract.Assert(this.Dispatcher != null);
            //Contract.Assert(this.Dispatcher.GetAllEntites() != null);

            var callgraph = new CallGraph<MethodDescriptor, LocationDescriptor>();
            callgraph.AddRootMethods(roots);
            // var allEntities = new HashSet<IEntity>(this.Dispatcher.GetAllEntites());
			var allEntityDescriptors =this.Dispatcher.GetAllEntitiesDescriptors();
            foreach (var entityDesc in allEntityDescriptors)
            {
                //  entity.GetEntityProcessor(this.Dispatcher);
                //var entityProcessor = new MethodEntityProcessor((MethodEntity)entity, this.Dispatcher); 
                var entityProcessor = this.Dispatcher.GetEntityWithProcessor(entityDesc);
                
                // Updates the callGraph
                UpdateCallGraph(entityProcessor, callgraph,this.Solution);
                MethodEntity methodEntity = (MethodEntity) entityProcessor.Entity;
                
                methodEntity.Save(Path.Combine(Path.GetTempPath(), 
                    methodEntity.MethodDescriptor.ClassName + "_" + methodEntity.MethodDescriptor.Name + ".dot"));
            }
            //callgraph.Save("cg.dot");

            return callgraph;
        }