A program which finds a cycles in units dependencies
authorunC0Rr
Wed, 17 Nov 2010 16:31:30 +0300
changeset 4355 4554c4df9f1a
parent 4353 671d66ba3af6
child 4357 a1fcfc341a52
A program which finds a cycles in units dependencies to run: unitCycles `ls *.pas`
tools/unitCycles.hs
--- a/tools/unitCycles.hs	Wed Nov 17 16:19:28 2010 +0300
+++ b/tools/unitCycles.hs	Wed Nov 17 16:31:30 2010 +0300
@@ -5,6 +5,7 @@
 import Control.Monad
 import Data.Either
 import Data.List
+import Data.Graph
 
 unident :: Identificator -> String
 unident (Identificator s) = s
@@ -13,7 +14,15 @@
 extractUnits (Program (Identificator name) (Implementation (Uses idents) _ _) _) = ("program " ++ name, map unident idents)
 extractUnits (Unit (Identificator name) (Interface (Uses idents1) _) (Implementation (Uses idents2) _ _) _ _) = (name, map unident $ idents1 ++ idents2)
 
+-- stronglyConnComp :: Ord key => [(node, key, [key])] -> [SCC node]
+
+f :: [(String, [String])] -> String
+f = unlines . map showSCC . stronglyConnComp . map (\(a, b) -> (a, a, b))
+    where
+    showSCC (AcyclicSCC v) = v
+    showSCC (CyclicSCC vs) = intercalate ", " vs
+
 main = do
     fileNames <- getArgs
     files <- mapM readFile fileNames
-    mapM_ (putStrLn . show . extractUnits) . rights . map parsePascalUnit $ files
+    putStrLn . f . map extractUnits . rights . map parsePascalUnit $ files