2 % (c) The University of Glasgow, 2004
7 Simply the name of a module, represented as a Z-encoded FastString.
8 These are Uniquable, hence we can build FiniteMaps with ModuleNames as
14 Module, -- Abstract, instance of Eq, Ord, Outputable
15 , pprModule -- :: ModuleName -> SDoc
20 , moduleString -- :: ModuleName -> EncodedString
21 , moduleUserString -- :: ModuleName -> UserString
22 , moduleFS -- :: ModuleName -> EncodedFS
24 , mkModule -- :: UserString -> ModuleName
25 , mkModuleFS -- :: UserFS -> ModuleName
26 , mkSysModuleFS -- :: EncodedFS -> ModuleName
29 , elemModuleEnv, extendModuleEnv, extendModuleEnvList, plusModuleEnv_C
30 , delModuleEnvList, delModuleEnv, plusModuleEnv, lookupModuleEnv
31 , lookupWithDefaultModuleEnv, mapModuleEnv, mkModuleEnv, emptyModuleEnv
32 , moduleEnvElts, unitModuleEnv, isEmptyModuleEnv, foldModuleEnv
35 , ModuleSet, emptyModuleSet, mkModuleSet, moduleSetElts, extendModuleSet, elemModuleSet
39 #include "HsVersions.h"
42 import Unique ( Uniquable(..) )
43 import Maybes ( expectJust )
47 import StringBuffer ( StringBuffer )
51 %************************************************************************
53 \subsection{Module locations}
55 %************************************************************************
60 ml_hs_file :: Maybe FilePath,
61 -- the source file, if we have one. Package modules
62 -- probably don't have source files.
64 ml_hspp_file :: Maybe FilePath,
65 -- filename of preprocessed source, if we have
67 ml_hspp_buf :: Maybe StringBuffer,
68 -- the actual preprocessed source, maybe.
70 ml_hi_file :: FilePath,
71 -- Where the .hi file is, whether or not it exists
72 -- yet. Always of form foo.hi, even if there is an
73 -- hi-boot file (we add the -boot suffix later)
75 ml_obj_file :: FilePath
76 -- Where the .o file is, whether or not it exists yet.
77 -- (might not exist either because the module hasn't
78 -- been compiled yet, or because it is part of a
79 -- package with a .a file)
82 instance Outputable ModLocation where
85 -- Rather a gruesome function to have in Module
87 showModMsg :: Bool -> Module -> ModLocation -> String
88 showModMsg use_object mod location =
89 mod_str ++ replicate (max 0 (16 - length mod_str)) ' '
90 ++" ( " ++ expectJust "showModMsg" (ml_hs_file location) ++ ", "
92 then ml_obj_file location
95 where mod_str = moduleUserString mod
98 For a module in another package, the hs_file and obj_file
99 components of ModLocation are undefined.
101 The locations specified by a ModLocation may or may not
102 correspond to actual files yet: for example, even if the object
103 file doesn't exist, the ModLocation still contains the path to
104 where the object file will reside if/when it is created.
107 %************************************************************************
109 \subsection{The name of a module}
111 %************************************************************************
114 newtype Module = Module EncodedFS
115 -- Haskell module names can include the quote character ',
116 -- so the module names have the z-encoding applied to them
118 instance Binary Module where
119 put_ bh (Module m) = put_ bh m
120 get bh = do m <- get bh; return (Module m)
122 instance Uniquable Module where
123 getUnique (Module nm) = getUnique nm
125 instance Eq Module where
126 nm1 == nm2 = getUnique nm1 == getUnique nm2
128 -- Warning: gives an ordering relation based on the uniques of the
129 -- FastStrings which are the (encoded) module names. This is _not_
130 -- a lexicographical ordering.
131 instance Ord Module where
132 nm1 `compare` nm2 = getUnique nm1 `compare` getUnique nm2
134 instance Outputable Module where
138 pprModule :: Module -> SDoc
139 pprModule (Module nm) = pprEncodedFS nm
141 moduleFS :: Module -> EncodedFS
142 moduleFS (Module mod) = mod
144 moduleString :: Module -> EncodedString
145 moduleString (Module mod) = unpackFS mod
147 moduleUserString :: Module -> UserString
148 moduleUserString (Module mod) = decode (unpackFS mod)
150 -- used to be called mkSrcModule
151 mkModule :: UserString -> Module
152 mkModule s = Module (mkFastString (encode s))
154 -- used to be called mkSrcModuleFS
155 mkModuleFS :: UserFS -> Module
156 mkModuleFS s = Module (encodeFS s)
158 -- used to be called mkSysModuleFS
159 mkSysModuleFS :: EncodedFS -> Module
160 mkSysModuleFS s = Module s
163 %************************************************************************
165 \subsection{@ModuleEnv@s}
167 %************************************************************************
170 type ModuleEnv elt = UniqFM elt
172 emptyModuleEnv :: ModuleEnv a
173 mkModuleEnv :: [(Module, a)] -> ModuleEnv a
174 unitModuleEnv :: Module -> a -> ModuleEnv a
175 extendModuleEnv :: ModuleEnv a -> Module -> a -> ModuleEnv a
176 extendModuleEnv_C :: (a->a->a) -> ModuleEnv a -> Module -> a -> ModuleEnv a
177 plusModuleEnv :: ModuleEnv a -> ModuleEnv a -> ModuleEnv a
178 extendModuleEnvList :: ModuleEnv a -> [(Module, a)] -> ModuleEnv a
180 delModuleEnvList :: ModuleEnv a -> [Module] -> ModuleEnv a
181 delModuleEnv :: ModuleEnv a -> Module -> ModuleEnv a
182 plusModuleEnv_C :: (a -> a -> a) -> ModuleEnv a -> ModuleEnv a -> ModuleEnv a
183 mapModuleEnv :: (a -> b) -> ModuleEnv a -> ModuleEnv b
184 moduleEnvElts :: ModuleEnv a -> [a]
186 isEmptyModuleEnv :: ModuleEnv a -> Bool
187 lookupModuleEnv :: ModuleEnv a -> Module -> Maybe a
188 lookupWithDefaultModuleEnv :: ModuleEnv a -> a -> Module -> a
189 elemModuleEnv :: Module -> ModuleEnv a -> Bool
190 foldModuleEnv :: (a -> b -> b) -> b -> ModuleEnv a -> b
192 elemModuleEnv = elemUFM
193 extendModuleEnv = addToUFM
194 extendModuleEnv_C = addToUFM_C
195 extendModuleEnvList = addListToUFM
196 plusModuleEnv_C = plusUFM_C
197 delModuleEnvList = delListFromUFM
198 delModuleEnv = delFromUFM
199 plusModuleEnv = plusUFM
200 lookupModuleEnv = lookupUFM
201 lookupWithDefaultModuleEnv = lookupWithDefaultUFM
202 mapModuleEnv = mapUFM
203 mkModuleEnv = listToUFM
204 emptyModuleEnv = emptyUFM
205 moduleEnvElts = eltsUFM
206 unitModuleEnv = unitUFM
207 isEmptyModuleEnv = isNullUFM
208 foldModuleEnv = foldUFM
212 type ModuleSet = UniqSet Module
213 mkModuleSet :: [Module] -> ModuleSet
214 extendModuleSet :: ModuleSet -> Module -> ModuleSet
215 emptyModuleSet :: ModuleSet
216 moduleSetElts :: ModuleSet -> [Module]
217 elemModuleSet :: Module -> ModuleSet -> Bool
219 emptyModuleSet = emptyUniqSet
220 mkModuleSet = mkUniqSet
221 extendModuleSet = addOneToUniqSet
222 moduleSetElts = uniqSetToList
223 elemModuleSet = elementOfUniqSet