2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[Module]{The @Module@ module.}
6 Representing modules and their flavours.
11 When compiling module A, which imports module B, we need to
12 know whether B will be in the same DLL as A.
13 If it's in the same DLL, we refer to B_f_closure
14 If it isn't, we refer to _imp__B_f_closure
15 When compiling A, we record in B's Module value whether it's
16 in a different DLL, by setting the DLL flag.
24 Module -- abstract, instance of Eq, Ord, Outputable
29 , moduleNameString -- :: ModuleName -> EncodedString
30 , moduleNameUserString -- :: ModuleName -> UserString
32 , moduleString -- :: Module -> EncodedString
33 , moduleUserString -- :: Module -> UserString
34 , moduleName -- :: Module -> ModuleName
36 -- , mkVanillaModule -- :: ModuleName -> Module
37 -- , mkThisModule -- :: ModuleName -> Module
38 -- , mkPrelModule -- :: UserString -> Module
39 , mkModule -- :: ModuleName -> ModuleKind -> Module
41 -- , isLocalModule -- :: Module -> Bool
45 , mkSrcModuleFS -- :: UserFS -> ModuleName
46 , mkSysModuleFS -- :: EncodedFS -> ModuleName
48 , pprModule, pprModuleName
52 -- Where to find a .hi file
57 #include "HsVersions.h"
60 import CmdLineOpts ( opt_InPackage )
61 import FastString ( FastString, uniqueOfFS )
62 import Unique ( Uniquable(..), mkUniqueGrimily )
66 %************************************************************************
68 \subsection{Interface file flavour}
70 %************************************************************************
72 A further twist to the tale is the support for dynamically linked libraries under
73 Win32. Here, dealing with the use of global variables that's residing in a DLL
74 requires special handling at the point of use (there's an extra level of indirection,
75 i.e., (**v) to get at v's value, rather than just (*v) .) When slurping in an
76 interface file we then record whether it's coming from a .hi corresponding to a
77 module that's packaged up in a DLL or not, so that we later can emit the
80 The logic for how an interface file is marked as corresponding to a module that's
81 hiding in a DLL is explained elsewhere (ToDo: give renamer href here.)
83 @SourceOnly@ and @ObjectCode@ indicate a module from the same package
84 as the one being compiled, i.e. a home module. @InPackage@ means one
85 from a different package.
89 = SourceOnly FilePath -- .hs
90 | ObjectCode FilePath FilePath -- .o, .hi
91 | InPackage PackageName
93 isPackageKind (InPackage _) = True
94 isPackageKind _ = False
96 type PackageName = FastString -- No encoding at all
98 preludePackage :: PackageName
99 preludePackage = SLIT("std")
101 instance Outputable ModuleKind where
102 ppr (SourceOnly path_hs)
103 = text "SourceOnly" <+> text (show path_hs)
104 ppr (ObjectCode path_o path_hi)
105 = text "ObjectCode" <+> text (show path_o) <+> text (show path_hi)
106 ppr (InPackage pkgname)
107 = text "InPackage" <+> text (show pkgname)
111 %************************************************************************
113 \subsection{Where from}
115 %************************************************************************
117 The @WhereFrom@ type controls where the renamer looks for an interface file
120 data WhereFrom = ImportByUser -- Ordinary user import: look for M.hi
121 | ImportByUserSource -- User {- SOURCE -}: look for M.hi-boot
122 | ImportBySystem -- Non user import. Look for M.hi if M is in
123 -- the module this module depends on, or is a system-ish module;
124 -- M.hi-boot otherwise
126 instance Outputable WhereFrom where
127 ppr ImportByUser = empty
128 ppr ImportByUserSource = ptext SLIT("{- SOURCE -}")
129 ppr ImportBySystem = ptext SLIT("{- SYSTEM IMPORT -}")
133 %************************************************************************
135 \subsection{The name of a module}
137 %************************************************************************
140 type ModuleName = EncodedFS
141 -- Haskell module names can include the quote character ',
142 -- so the module names have the z-encoding applied to them
144 pprModuleName :: ModuleName -> SDoc
145 pprModuleName nm = pprEncodedFS nm
147 moduleNameString :: ModuleName -> EncodedString
148 moduleNameString mod = _UNPK_ mod
150 moduleNameUserString :: ModuleName -> UserString
151 moduleNameUserString mod = decode (_UNPK_ mod)
153 mkSrcModule :: UserString -> ModuleName
154 mkSrcModule s = _PK_ (encode s)
156 mkSrcModuleFS :: UserFS -> ModuleName
157 mkSrcModuleFS s = encodeFS s
159 mkSysModuleFS :: EncodedFS -> ModuleName
166 mod_name :: ModuleName,
167 mod_kind :: ModuleKind
172 instance Outputable Module where
175 instance Uniquable Module where
176 getUnique (Module nm _) = mkUniqueGrimily (uniqueOfFS nm)
178 -- Same if they have the same name.
179 instance Eq Module where
180 m1 == m2 = getUnique m1 == getUnique m2
182 -- Warning: gives an ordering relation based on the uniques of the
183 -- FastStrings which are the (encoded) module names. This is _not_
184 -- a lexicographical ordering.
185 instance Ord Module where
186 m1 `compare` m2 = getUnique m1 `compare` getUnique m2
191 pprModule :: Module -> SDoc
192 pprModule (Module mod p) = getPprStyle $ \ sty ->
193 if debugStyle sty then
194 -- Print the package too
195 ppr p <> dot <> pprModuleName mod
202 mkModule :: ModuleName -> ModuleKind -> Module
204 -- I don't think anybody except the Finder should ever try to create a
205 -- Module now, so this lot commented out pro tem (JRS)
206 --mkModule :: ModuleName -- Name of the module
209 --mkModule mod_nm pack_name
210 -- = Module mod_nm pack_info
212 -- pack_info | pack_name == opt_InPackage = ThisPackage
213 -- | otherwise = AnotherPackage pack_name
216 --mkVanillaModule :: ModuleName -> Module
217 --mkVanillaModule name = Module name ThisPackage
218 -- Used temporarily when we first come across Foo.x in an interface
219 -- file, but before we've opened Foo.hi.
220 -- (Until we've opened Foo.hi we don't know what the PackageInfo is.)
222 --mkThisModule :: ModuleName -> Module -- The module being compiled
223 --mkThisModule name = Module name ThisPackage
225 --mkPrelModule :: ModuleName -> Module
226 --mkPrelModule name = mkModule name preludePackage
228 moduleString :: Module -> EncodedString
229 moduleString (Module mod _) = _UNPK_ mod
231 moduleName :: Module -> ModuleName
232 moduleName (Module mod _) = mod
234 moduleUserString :: Module -> UserString
235 moduleUserString (Module mod _) = moduleNameUserString mod
239 --isLocalModule :: Module -> Bool
240 --isLocalModule (Module _ ThisPackage) = True
241 --isLocalModule _ = False