/// <summary> /// Visit all method declaration nodes and invocation nodes. Add nodes to call graph (CodeGraph) object. /// </summary> /// <param name="syntaxTree"></param> /// <param name="semanticModel"></param> /// <returns></returns> public static CodeGraph ExtractCallGraph(SyntaxTree syntaxTree, SemanticModel semanticModel) { Console.WriteLine($"Extracting call graph from {syntaxTree.FilePath}"); var graphVisitor = new CallGraphVisitor(syntaxTree, semanticModel); graphVisitor.Visit(syntaxTree.GetRoot()); graphVisitor._callGraph.ConvertEdgesToEncodedEdges(); return(graphVisitor._callGraph); }
static void Main(string[] args) { if (args.Length != 3) { // Alternative to set default arguments here. args = new string[3]; args[0] = @""; args[1] = @""; args[2] = @""; } string baseDir = args[0]; string solutionPath = args[1]; string outputDir = args[2]; void ExploreSolution(SyntaxTree syntaxTree, SemanticModel semanticModel) { string fileName = syntaxTree.FilePath.Split('\\').Last(); string saveDir = Path.Combine(outputDir, fileName); if (!Directory.Exists(saveDir)) { Directory.CreateDirectory(saveDir); } // Extract call graph and write to file. var callGraph = CallGraphVisitor.ExtractCallGraph(syntaxTree, semanticModel); string callGraphOutputPath = Path.Combine(saveDir, "callGraph.png"); GraphWriter.GenerateDotGraph(callGraph, callGraphOutputPath); // Extract AST and write to file. var ast = ASTVisitor.ExtractAST(syntaxTree, semanticModel); string astOutputPath = Path.Combine(saveDir, "ast.png"); GraphWriter.GenerateDotGraph(ast, astOutputPath); } CSharpSolutionBuilder.BuildSolution(solutionPath, ExploreSolution); }