aboutsummaryrefslogtreecommitdiff
path: root/src/Haddock
diff options
context:
space:
mode:
Diffstat (limited to 'src/Haddock')
-rw-r--r--src/Haddock/GHC/Typecheck.hs53
1 files changed, 14 insertions, 39 deletions
diff --git a/src/Haddock/GHC/Typecheck.hs b/src/Haddock/GHC/Typecheck.hs
index 52abc4ab..2a9811c9 100644
--- a/src/Haddock/GHC/Typecheck.hs
+++ b/src/Haddock/GHC/Typecheck.hs
@@ -24,28 +24,6 @@ import SrcLoc
import Data.List
-typecheckFiles :: Session -> [FilePath] -> IO [GhcModule]
-typecheckFiles session files = do
- checkedMods <- sortAndCheckModules session files
- return (map mkGhcModule checkedMods)
-
-
--- | Get the sorted graph of all loaded modules and their dependencies
-getSortedModuleGraph :: Session -> IO [(Module, FilePath)]
-getSortedModuleGraph session = do
- mbModGraph <- depanal session [] True
- moduleGraph <- case mbModGraph of
- Just mg -> return mg
- Nothing -> throwE "Failed to load all modules"
- let
- getModFile = fromJust . ml_hs_file . ms_location
- sortedGraph = topSortModuleGraph False moduleGraph Nothing
- sortedModules = concatMap flattenSCC sortedGraph
- modsAndFiles = [ (ms_mod modsum, getModFile modsum) |
- modsum <- sortedModules ]
- return modsAndFiles
-
-
type CheckedMod = (Module, FilePath, FullyCheckedMod)
@@ -56,42 +34,39 @@ type FullyCheckedMod = (ParsedSource,
-- TODO: make it handle cleanup
-sortAndCheckModules :: Session -> [FilePath] -> IO [CheckedMod]
-sortAndCheckModules session files = do
+typecheckFiles :: Session -> [FilePath] -> IO [GhcModule]
+typecheckFiles session files = do
-- load all argument files
targets <- mapM (\f -> guessTarget f Nothing) files
setTargets session targets
- -- compute the dependencies and load them as well
-
- allMods0 <- getSortedModuleGraph session
- let allMods = nub $ filter (not . ("-boot" `isSuffixOf`) . snd) allMods0
- setTargets session [Target (TargetModule $ moduleName m) Nothing
- | (m, _) <- allMods ]
-
flag <- load session LoadAllTargets
when (failed flag) $
throwE "Failed to load all needed modules"
- -- typecheck the argument modules
+ modgraph <- getModuleGraph session
- let argMods = filter ((`elem` files) . snd) allMods
+ let mods = concatMap flattenSCC $ topSortModuleGraph False modgraph Nothing
+ getModFile = fromJust . ml_hs_file . ms_location
+ mods'= [ (ms_mod modsum, ms_hspp_opts modsum, getModFile modsum) |
+ modsum <- mods ]
- checkedMods <- forM argMods $ \(mod, file) -> do
+ -- typecheck the argument modules
+
+ ghcMods <- forM mods' $ \(mod, flags, file) -> do
mbMod <- checkModule session (moduleName mod) False
case mbMod of
Just (CheckedModule a (Just b) (Just c) (Just d) _)
- -> return (mod, file, (a,b,c,d))
+ -> return $ mkGhcModule (mod, file, (a,b,c,d)) flags
_ -> throwE ("Failed to check module: " ++ moduleString mod)
- return checkedMods
-
+ return ghcMods
-- | Dig out what we want from the typechecker output
-mkGhcModule :: CheckedMod -> GhcModule
-mkGhcModule (mod, file, checkedMod) = GhcModule {
+mkGhcModule :: CheckedMod -> DynFlags -> GhcModule
+mkGhcModule (mod, file, checkedMod) dynflags = GhcModule {
ghcModule = mod,
ghcFilename = file,
ghcMbDocOpts = mbOpts,