[project @ 2000-10-27 14:31:55 by simonmar]
[ghc-hetmet.git] / ghc / compiler / ghci / CmSummarise.lhs
index 00c0eec..4d03acd 100644 (file)
@@ -4,7 +4,7 @@
 \section[CmSummarise]{Module summariser for GHCI}
 
 \begin{code}
-module CmSummarise ( ModImport(..), mi_name,
+module CmSummarise ( ModImport(..), mimp_name,
                      ModSummary(..), summarise, ms_get_imports,
                     name_of_summary, deps_of_summary,
                     getImports )
@@ -14,9 +14,10 @@ where
 
 import List            ( nub )
 import Char            ( ord, isAlphaNum )
+import HscTypes                ( ModuleLocation(..) )
+import FastTypes
 
-import Module          ( Module, mod_name, mod_kind, 
-                         ModuleName, mkModuleName, ModuleKind(..) )
+import Module
 import Outputable
 \end{code}
 
@@ -32,7 +33,8 @@ import Outputable
 -- and let @compile@ read from that file on the way back up.
 data ModSummary
    = ModSummary {
-        ms_mod      :: Module,                          -- location and kind
+        ms_mod      :: Module,                          -- name, package
+       ms_location :: ModuleLocation,                  -- location
         ms_ppsource :: (Maybe (FilePath, Fingerprint)), -- preprocessed and sig if .hs
         ms_imports  :: (Maybe [ModImport])              -- imports if .hs or .hi
      }
@@ -60,14 +62,14 @@ instance Outputable ModImport where
    ppr (MISource nm) = text "{-# SOURCE #-}" <+> ppr nm
 
 
-mi_name (MINormal nm) = nm
-mi_name (MISource nm) = nm
+mimp_name (MINormal nm) = nm
+mimp_name (MISource nm) = nm
 
 name_of_summary :: ModSummary -> ModuleName
-name_of_summary = mod_name . ms_mod
+name_of_summary = moduleName . ms_mod
 
 deps_of_summary :: ModSummary -> [ModuleName]
-deps_of_summary = map mi_name . ms_get_imports
+deps_of_summary = map mimp_name . ms_get_imports
 
 ms_get_imports :: ModSummary -> [ModImport]
 ms_get_imports summ
@@ -75,33 +77,32 @@ ms_get_imports summ
 
 type Fingerprint = Int
 
-summarise :: Module -> IO ModSummary
-summarise mod
-   = case mod_kind mod of
-        InPackage path -- if in a package, investigate no further
-           -> return (ModSummary mod Nothing Nothing)
-        SourceOnly path -- source; read, cache and get imports
-           -> readFile path >>= \ modsrc ->
-              let imps = getImports modsrc
-                  fp   = fingerprint modsrc
-              in  return (ModSummary mod (Just (path,fp)) (Just imps))
-        ObjectCode oPath hiPath -- can we get away with the src summariser
-                                -- for interface files?
-           -> readFile hiPath >>= \ hisrc ->
-              let imps = getImports hisrc
-              in  return (ModSummary mod Nothing (Just imps))
-
+summarise :: Module -> ModuleLocation -> IO ModSummary
+summarise mod location
+   = if isModuleInThisPackage mod
+       then do 
+           let source_fn = hs_file location
+           -- ToDo:
+           -- ppsource_fn <- preprocess source_fn
+           modsrc <- readFile source_fn
+            let imps = getImports modsrc
+                fp   = fingerprint modsrc
+            return (ModSummary mod location (Just (source_fn,fp)) (Just imps))
+       else
+           return (ModSummary mod location Nothing Nothing)
+       
 fingerprint :: String -> Int
 fingerprint s
-   = dofp s 3# 3#
+   = dofp s (_ILIT 3) (_ILIT 3)
      where
         -- Copied from hash() in Hugs' storage.c.
-        dofp :: String -> Int# -> Int# -> Int
-        dofp []     m fp = I# fp
-        dofp (c:cs) m fp = dofp cs (m +# 1#) (iabs (fp +# m *# unbox (ord c)))
-        unbox (I# i) = i
-        iabs :: Int# -> Int#
-        iabs n = if n <# 0# then 0# -# n else n
+        dofp :: String -> FastInt -> FastInt -> Int
+        dofp []     m fp = iBox fp
+        dofp (c:cs) m fp = dofp cs (m +# _ILIT 1) 
+                               (iabs (fp +# m *# iUnbox (ord c)))
+
+        iabs :: FastInt -> FastInt
+        iabs n = if n <# _ILIT 0 then (_ILIT 0) -# n else n
 \end{code}
 
 Collect up the imports from a Haskell source module.  This is