2 % (c) The University of Glasgow, 2004
7 Simply the name of a module, represented as a 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
18 , addBootSuffix, addBootSuffix_maybe, addBootSuffixLocn
20 , moduleString -- :: ModuleName -> String
21 , moduleFS -- :: ModuleName -> FastString
23 , mkModule -- :: String -> ModuleName
24 , mkModuleFS -- :: FastString -> ModuleName
27 , elemModuleEnv, extendModuleEnv, extendModuleEnvList, plusModuleEnv_C
28 , delModuleEnvList, delModuleEnv, plusModuleEnv, lookupModuleEnv
29 , lookupWithDefaultModuleEnv, mapModuleEnv, mkModuleEnv, emptyModuleEnv
30 , moduleEnvElts, unitModuleEnv, isEmptyModuleEnv, foldModuleEnv
31 , extendModuleEnv_C, filterModuleEnv
33 , ModuleSet, emptyModuleSet, mkModuleSet, moduleSetElts, extendModuleSet, elemModuleSet
37 #include "HsVersions.h"
39 import Unique ( Uniquable(..) )
46 %************************************************************************
48 \subsection{Module locations}
50 %************************************************************************
55 ml_hs_file :: Maybe FilePath,
56 -- The source file, if we have one. Package modules
57 -- probably don't have source files.
59 ml_hi_file :: FilePath,
60 -- Where the .hi file is, whether or not it exists
61 -- yet. Always of form foo.hi, even if there is an
62 -- hi-boot file (we add the -boot suffix later)
64 ml_obj_file :: FilePath
65 -- Where the .o file is, whether or not it exists yet.
66 -- (might not exist either because the module hasn't
67 -- been compiled yet, or because it is part of a
68 -- package with a .a file)
71 instance Outputable ModLocation where
75 For a module in another package, the hs_file and obj_file
76 components of ModLocation are undefined.
78 The locations specified by a ModLocation may or may not
79 correspond to actual files yet: for example, even if the object
80 file doesn't exist, the ModLocation still contains the path to
81 where the object file will reside if/when it is created.
84 addBootSuffix :: FilePath -> FilePath
85 -- Add the "-boot" suffix to .hs, .hi and .o files
86 addBootSuffix path = path ++ "-boot"
88 addBootSuffix_maybe :: Bool -> FilePath -> FilePath
89 addBootSuffix_maybe is_boot path
90 | is_boot = addBootSuffix path
93 addBootSuffixLocn :: ModLocation -> ModLocation
94 addBootSuffixLocn locn
95 = locn { ml_hs_file = fmap addBootSuffix (ml_hs_file locn)
96 , ml_hi_file = addBootSuffix (ml_hi_file locn)
97 , ml_obj_file = addBootSuffix (ml_obj_file locn) }
101 %************************************************************************
103 \subsection{The name of a module}
105 %************************************************************************
108 newtype Module = Module FastString
109 -- Haskell module names can include the quote character ',
110 -- so the module names have the z-encoding applied to them
112 instance Binary Module where
113 put_ bh (Module m) = put_ bh m
114 get bh = do m <- get bh; return (Module m)
116 instance Uniquable Module where
117 getUnique (Module nm) = getUnique nm
119 instance Eq Module where
120 nm1 == nm2 = getUnique nm1 == getUnique nm2
122 -- Warning: gives an ordering relation based on the uniques of the
123 -- FastStrings which are the (encoded) module names. This is _not_
124 -- a lexicographical ordering.
125 instance Ord Module where
126 nm1 `compare` nm2 = getUnique nm1 `compare` getUnique nm2
128 instance Outputable Module where
131 pprModule :: Module -> SDoc
132 pprModule (Module nm) =
133 getPprStyle $ \ sty ->
135 then ftext (zEncodeFS nm)
138 moduleFS :: Module -> FastString
139 moduleFS (Module mod) = mod
141 moduleString :: Module -> String
142 moduleString (Module mod) = unpackFS mod
144 -- used to be called mkSrcModule
145 mkModule :: String -> Module
146 mkModule s = Module (mkFastString s)
148 -- used to be called mkSrcModuleFS
149 mkModuleFS :: FastString -> Module
150 mkModuleFS s = Module s
153 %************************************************************************
155 \subsection{@ModuleEnv@s}
157 %************************************************************************
160 type ModuleEnv elt = UniqFM elt
162 emptyModuleEnv :: ModuleEnv a
163 mkModuleEnv :: [(Module, a)] -> ModuleEnv a
164 unitModuleEnv :: Module -> a -> ModuleEnv a
165 extendModuleEnv :: ModuleEnv a -> Module -> a -> ModuleEnv a
166 extendModuleEnv_C :: (a->a->a) -> ModuleEnv a -> Module -> a -> ModuleEnv a
167 plusModuleEnv :: ModuleEnv a -> ModuleEnv a -> ModuleEnv a
168 extendModuleEnvList :: ModuleEnv a -> [(Module, a)] -> ModuleEnv a
170 delModuleEnvList :: ModuleEnv a -> [Module] -> ModuleEnv a
171 delModuleEnv :: ModuleEnv a -> Module -> ModuleEnv a
172 plusModuleEnv_C :: (a -> a -> a) -> ModuleEnv a -> ModuleEnv a -> ModuleEnv a
173 mapModuleEnv :: (a -> b) -> ModuleEnv a -> ModuleEnv b
174 moduleEnvElts :: ModuleEnv a -> [a]
176 isEmptyModuleEnv :: ModuleEnv a -> Bool
177 lookupModuleEnv :: ModuleEnv a -> Module -> Maybe a
178 lookupWithDefaultModuleEnv :: ModuleEnv a -> a -> Module -> a
179 elemModuleEnv :: Module -> ModuleEnv a -> Bool
180 foldModuleEnv :: (a -> b -> b) -> b -> ModuleEnv a -> b
181 filterModuleEnv :: (a -> Bool) -> ModuleEnv a -> ModuleEnv a
183 filterModuleEnv = filterUFM
184 elemModuleEnv = elemUFM
185 extendModuleEnv = addToUFM
186 extendModuleEnv_C = addToUFM_C
187 extendModuleEnvList = addListToUFM
188 plusModuleEnv_C = plusUFM_C
189 delModuleEnvList = delListFromUFM
190 delModuleEnv = delFromUFM
191 plusModuleEnv = plusUFM
192 lookupModuleEnv = lookupUFM
193 lookupWithDefaultModuleEnv = lookupWithDefaultUFM
194 mapModuleEnv = mapUFM
195 mkModuleEnv = listToUFM
196 emptyModuleEnv = emptyUFM
197 moduleEnvElts = eltsUFM
198 unitModuleEnv = unitUFM
199 isEmptyModuleEnv = isNullUFM
200 foldModuleEnv = foldUFM
204 type ModuleSet = UniqSet Module
205 mkModuleSet :: [Module] -> ModuleSet
206 extendModuleSet :: ModuleSet -> Module -> ModuleSet
207 emptyModuleSet :: ModuleSet
208 moduleSetElts :: ModuleSet -> [Module]
209 elemModuleSet :: Module -> ModuleSet -> Bool
211 emptyModuleSet = emptyUniqSet
212 mkModuleSet = mkUniqSet
213 extendModuleSet = addOneToUniqSet
214 moduleSetElts = uniqSetToList
215 elemModuleSet = elementOfUniqSet