Skip to content

Commit

Permalink
remove duplicates after processing to a list
Browse files Browse the repository at this point in the history
  • Loading branch information
dorchard committed Sep 2, 2024
1 parent d1a4004 commit 921f8f7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Language/Fortran/Analysis/ModGraph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ genModGraph mversion includeDirs cppOpts paths = do
pf <- parserF path contents
mapM_ (perModule path) (childrenBi pf :: [ProgramUnit ()])
pure ()
execStateT (mapM_ iter (removeDuplicates paths)) modGraph0
execStateT (mapM_ iter paths) modGraph0

-- Remove duplicates from a list preserving the left most occurrence.
removeDuplicates :: Eq a => [a] -> [a]
Expand All @@ -122,12 +122,14 @@ modGraphToDOT ModGraph { mgGraph = gr } = unlines dot

-- Provides a topological sort of the graph, giving a list of filenames
modGraphToList :: ModGraph -> [String]
modGraphToList mg
| nxt <- takeNextMods mg
, not (null nxt) =
let mg' = delModNodes (map fst nxt) mg
in [ fn | (_, Just (MOFile fn)) <- nxt ] ++ modGraphToList mg'
modGraphToList _ = []
modGraphToList m = removeDuplicates $ modGraphToList' m
where
modGraphToList' mg
| nxt <- takeNextMods mg
, not (null nxt) =
let mg' = delModNodes (map fst nxt) mg
in [ fn | (_, Just (MOFile fn)) <- nxt ] ++ modGraphToList' mg'
modGraphToList' _ = []


takeNextMods :: ModGraph -> [(Node, Maybe ModOrigin)]
Expand Down

0 comments on commit 921f8f7

Please sign in to comment.