public static void TestCallGraph(string xmlArchive, List<Tuple<string,string,bool>> testData) { CallGraph callGraph; var dbName = SrcMLDataContext.MakeDBName(xmlArchive); SrcMLDataContext.DropUserInstanceDatabase(dbName); var sw = Stopwatch.StartNew(); using (var db = SrcMLDataContext.CreateDatabaseConnection(dbName)) { callGraph = new CallGraph(xmlArchive, db); } sw.Stop(); Assert.IsNotNull(callGraph); Console.WriteLine("{0} to build the call graph", sw.Elapsed); List<bool> statuses = new List<bool>(); foreach (var test in testData) { var caller = test.Item1; var callee = test.Item2; var expected = test.Item3; var should = test.Item3 ? "should" : "shouldn't"; Console.Write("{0} {1} call {2}: ", caller, should, callee); var status = (expected == callGraph.ContainsRelationship(caller, callee)); statuses.Add(status); Console.WriteLine(status ? "PASS" : "FAIL"); Console.Write("{0} {1} be in the caller list for {2}: ", callee, should, callee); status = (expected == callGraph.GetCallers(callee).Any(c => (c.CallerDefinition as MethodDefinition).MethodSignature == caller)); statuses.Add(status); Console.WriteLine(status ? "PASS" : "FAIL"); Console.Write("{0} {1} be in the callee list for {2}: ", callee, should, caller); status = (expected == callGraph.GetCallees(caller).Any(c => (c.CalleeDefinition as MethodDefinition).MethodSignature == callee)); statuses.Add(status); Console.WriteLine(status ? "PASS" : "FAIL"); Console.WriteLine(); } Assert.IsTrue(statuses.All(s => s)); }
internal static SyntaxNode GenerateCode(CallGraph<string,int> callgraph) { List<MethodDeclarationSyntax> methods = new List<MethodDeclarationSyntax>(); foreach (var vertex in callgraph.GetNodes()) { methods.Add(GetMethod(vertex, callgraph.GetCallees(vertex))); } //methods.Add(GetMain(callgraph.GetNodes())); return SyntaxFactory.CompilationUnit() .WithMembers( SyntaxFactory.SingletonList<MemberDeclarationSyntax>( SyntaxFactory.ClassDeclaration( @"C") .WithMembers( SyntaxFactory.List<MemberDeclarationSyntax>(methods) ))) .NormalizeWhitespace(); }
internal bool IsCalled(MethodDescriptor methodDescriptor, MethodDescriptor calleeDescriptor, CallGraph<MethodDescriptor, LocationDescriptor> callgraph) { return callgraph.GetCallees(methodDescriptor).Contains(calleeDescriptor); }
internal bool IsCalled(MethodDescriptor methodDescriptor, MethodDescriptor calleeDescriptor, CallGraph <MethodDescriptor, LocationDescriptor> callgraph) { return(callgraph.GetCallees(methodDescriptor).Contains(calleeDescriptor)); }