changeset 431:7a6bfa569a52

Fix: analyzeGraph() should work correctly now.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Thu, 04 Oct 2007 09:55:07 +0200
parents e6c759e151cd
children 3ead178e0662
files trunk/src/cmd/ImportGraph.d
diffstat 1 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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);
 }