async internal static Task<MethodEntity> FindProviderAndCreateMethodEntityAsync(MethodDescriptor methodDescriptor) { MethodEntity methodEntity = null; var pair = await ProjectCodeProvider.GetProjectProviderAndSyntaxAsync(methodDescriptor); if (pair != null) { var provider = pair.Item1; var tree = pair.Item2; var model = provider.Compilation.GetSemanticModel(tree); var methodEntityGenerator = new MethodSyntaxProcessor(model, provider, tree, methodDescriptor); methodEntity = methodEntityGenerator.ParseMethod(); } else { var libraryMethodVisitor = new LibraryMethodProcessor(methodDescriptor); methodEntity = libraryMethodVisitor.ParseLibraryMethod(); } return methodEntity; }
/// <summary> /// Try to get the roslyn methods on the fly /// Currently works with one project. /// </summary> public async Task AnalyzeOnDemandAsync(AnalysisStrategy strategy) { Contract.Assert(this.Dispatcher != null); var cancellationSource = new CancellationTokenSource(); var triple = await ProjectCodeProvider.GetProviderContainingEntryPointAsync(this.Solution, cancellationSource.Token); if (triple != null) { // cancel out outstanding processing tasks //cancellationSource.Cancel(); var provider = triple.Item1; var mainSymbol = triple.Item2; var tree = triple.Item3; var model = provider.Compilation.GetSemanticModel(tree); var methodVisitor = new MethodSyntaxProcessor(model, tree, mainSymbol); //var mainMethodEntity = methodVisitor.ParseMethod(); var mainMethodDescriptor = Utils.CreateMethodDescriptor(mainSymbol); var mainMethodEntityDescriptor = EntityFactory.Create(mainMethodDescriptor, this.Dispatcher); IEntityProcessor mainMethodEntityProcessor = null; switch(strategy) { case AnalysisStrategy.ONDEMAND_ORLEANS: var methodEntityGrain = await OrleansDispatcher.CreateMethodEntityGrain((OrleansEntityDescriptor)mainMethodEntityDescriptor); // Option 1: Direcly using the Grain await methodEntityGrain.DoAnalysisAsync(); // Option 2: Using the processor (requires making the processor serializable) //mainMethodEntityProcessor = await methodEntityGrain.GetEntityWithProcessorAsync(); //await mainMethodEntityProcessor.DoAnalysisAsync(); break; case AnalysisStrategy.ONDEMAND_ASYNC: mainMethodEntityProcessor = await this.Dispatcher.GetEntityWithProcessorAsync(mainMethodEntityDescriptor); var mainMethodEntity = ((MethodEntityProcessor)mainMethodEntityProcessor).MethodEntity; this.Dispatcher.RegisterEntity(mainMethodEntity.EntityDescriptor, mainMethodEntity); await mainMethodEntityProcessor.DoAnalysisAsync(); break; } //await Task.WhenAll(mainMethodEntityProcessor.DoAnalysisAsync()); //Thread.Sleep(1000); Logger.Instance.Log("SolutionAnalyzer", "AnalyzeOnDemandAsync", "--- Done with propagation ---"); } }
/// <summary> /// Try to get the roslyn methods on the fly /// Currently works with one project. /// </summary> public void AnalyzeOnDemand() { Contract.Assert(this.Dispatcher != null); var cancellationToken = new CancellationTokenSource(); var projectIDs = this.Solution.GetProjectDependencyGraph().GetTopologicallySortedProjects(cancellationToken.Token); foreach (var projectId in projectIDs) { var project = this.Solution.GetProject(projectId); var compilation = project.GetCompilationAsync().Result; var triple = ProjectCodeProvider.GetProviderContainingEntryPointAsync(project, cancellationToken.Token).Result; var provider = triple.Item1; IMethodSymbol mainSymbol = triple.Item2; var tree = triple.Item3; if (provider != null) { var model = provider.Compilation.GetSemanticModel(tree); cancellationToken.Cancel(); // cancel out outstanding processing tasks var methodVisitor = new MethodSyntaxProcessor(model, tree, mainSymbol); var mainMethodEntity = methodVisitor.ParseMethod(); this.Dispatcher.RegisterEntity(mainMethodEntity.EntityDescriptor, mainMethodEntity); var mainEntityProcessor = new MethodEntityProcessor((MethodEntity)mainMethodEntity, this.Dispatcher); //var mainMethodDescriptor = new MethodDescriptor(mainSymbol); //var mainMethodEntityDescriptor = EntityFactory.Create(mainMethodDescriptor); //var mainEntityProcessor = this.Dispatcher.GetEntityWithProcessorAsync(mainMethodEntityDescriptor).Result ; // Just a test //mainEntityProcessor.MethodEntity.CurrentContext = new CallConext<AMethod, ANode>(mainEntityProcessor.MethodEntity.Method, null, null); mainEntityProcessor.DoAnalysis(); Logger.Instance.Log("SolutionAnalyzer", "AnalyzeOnDemand", "--- Done with propagation ---"); } } if (this.Dispatcher is QueueingDispatcher) { var qd = (QueueingDispatcher)this.Dispatcher; while (!qd.IsDoneProcessing) { Logger.Instance.Log("SolutionAnalyzer", "AnalyzeOnDemand", "Waiting for the queue to empty up..."); Thread.Sleep(1000); } } }
async internal Task<MethodEntity> CreateMethodEntityAsync(MethodDescriptor methodDescriptor) { MethodEntity methodEntity = null; var tree = await this.GetSyntaxAsync(methodDescriptor); if(tree==null) { } var model = this.Compilation.GetSemanticModel(tree); var methodEntityGenerator = new MethodSyntaxProcessor(model, this, tree, methodDescriptor); methodEntity = methodEntityGenerator.ParseMethod(); return methodEntity; }