# HG changeset patch # User Aziz K?ksal # Date 1191484507 -7200 # Node ID 7a6bfa569a5264563fdff8e3a4d599807f971b9a # Parent e6c759e151cdf9797b481779674cc1843e38a439 Fix: analyzeGraph() should work correctly now. diff -r e6c759e151cd -r 7a6bfa569a52 trunk/src/cmd/ImportGraph.d --- a/trunk/src/cmd/ImportGraph.d Wed Oct 03 23:00:46 2007 +0200 +++ b/trunk/src/cmd/ImportGraph.d Thu Oct 04 09:55:07 2007 +0200 @@ -162,6 +162,15 @@ } // Finished loading modules. + // Check that every module has at least one incoming or outgoing edge. + assert( + delegate { + foreach (mod; loadedModulesList) + if (mod.incoming.length == 0 && mod.outgoing.length == 0) + throw new Exception("module "~mod.getFQN()~" has no edges in the graph."); + return true; + }() == true + ); if (options & (IGraphOption.PrintList | IGraphOption.PrintPaths)) { @@ -236,9 +245,9 @@ Stdout("}\n"); } -void analyzeGraph(Vertex[] vertices, Edge[] edges) +void analyzeGraph(Vertex[] vertices_init, Edge[] edges) { - void recursive(Vertex[] modules) + void recursive(Vertex[] vertices) { foreach (idx, vertex; vertices) { @@ -264,10 +273,17 @@ edges[j++] = edges[i]; edges.length = j; vertices = vertices[0..idx] ~ vertices[idx+1..$]; - return recursive(modules); + recursive(vertices); + return; } else - assert(0, "orphaned module: "~vertex.getFQN()~" (has no edges in graph)"); // orphaned vertex (module) in graph + { + // Edges to this vertex were removed previously. + // Only remove vertex now. + vertices = vertices[0..idx] ~ vertices[idx+1..$]; + recursive(vertices); + return; + } } else if (incoming == 0) { @@ -280,11 +296,13 @@ edges[j++] = edges[i]; edges.length = j; vertices = vertices[0..idx] ~ vertices[idx+1..$]; - return recursive(modules); + recursive(vertices); + return; } // else // { // // source && sink +// // continue loop. // } } @@ -295,5 +313,5 @@ if (edge) edge.isCyclic = true; } - recursive(vertices); + recursive(vertices_init); }