[project @ 1996-04-07 15:41:24 by partain]
[ghc-hetmet.git] / ghc / compiler / rename / RnIfaces.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 %
4 \section[RnIfaces]{Cacheing and Renaming of Interfaces}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module RnIfaces (
10         cacheInterface,
11         readInterface,
12         rnInterfaces,
13         finalIfaceInfo,
14         IfaceCache(..),
15         VersionInfo(..),
16         ParsedIface(..)
17     ) where
18
19 import PreludeGlaST     ( returnPrimIO, thenPrimIO,
20                           readVar, writeVar, MutableVar(..) )
21
22 import Ubiq
23
24 import HsSyn
25 import RdrHsSyn
26 import RnHsSyn
27
28 import RnMonad
29 import RnUtils          ( RnEnv(..) )
30
31 import Bag              ( emptyBag )
32 import ErrUtils         ( Error(..), Warning(..) )
33 import FiniteMap        ( emptyFM, lookupFM, addToFM )
34 import Pretty
35 import Maybes           ( MaybeErr(..) )
36 import Util             ( panic )
37
38 \end{code}
39
40
41 \begin{code}
42 type IfaceCache = MutableVar _RealWorld (FiniteMap Module ParsedIface,
43                                          FiniteMap Module FAST_STRING)
44
45 data ParsedIface = ParsedIface
46
47
48 cacheInterface :: IfaceCache -> Module
49                -> PrimIO (MaybeErr ParsedIface Error)
50
51 cacheInterface iface_var mod
52   = readVar iface_var `thenPrimIO` \ (iface_fm, file_fm) ->
53     case lookupFM iface_fm mod of
54       Just iface -> returnPrimIO (Succeeded iface)
55       Nothing    ->
56         case lookupFM file_fm mod of
57           Nothing   -> returnPrimIO (Failed (noIfaceErr mod))
58           Just file ->
59             readInterface file mod `thenPrimIO` \ read_iface ->
60             case read_iface of
61               Failed err      -> returnPrimIO (Failed err)
62               Succeeded iface ->
63                 let
64                     iface_fm' = addToFM iface_fm mod iface
65                 in
66                 writeVar iface_var (iface_fm', file_fm) `thenPrimIO` \ _ ->
67                 returnPrimIO (Succeeded iface)
68
69
70 readInterface :: FAST_STRING -> Module
71               -> PrimIO (MaybeErr ParsedIface Error)
72
73 readInterface file mod = panic "readInterface"
74 \end{code}
75
76
77 \begin{code}
78 rnInterfaces ::
79            IfaceCache                           -- iface cache
80         -> RnEnv                                -- original name env
81         -> UniqSupply
82         -> RenamedHsModule                      -- module to extend with iface decls
83         -> [RnName]                             -- imported names required
84         -> PrimIO (RenamedHsModule,             -- extended module
85                    ImplicitEnv,                 -- implicit names required
86                    Bag Error,
87                    Bag Warning)
88
89 rnInterfaces iface_var occ_env us rn_module todo
90   = returnPrimIO (rn_module, (emptyFM, emptyFM), emptyBag, emptyBag)
91 \end{code}
92
93
94 \begin{code}
95 finalIfaceInfo ::
96            IfaceCache                           -- iface cache
97         -> [RnName]                             -- all imported names required
98         -> [Module]                             -- directly imported modules
99         -> PrimIO (VersionInfo,                 -- info about version numbers
100                    [Module])                    -- special instance modules
101
102 type VersionInfo = [(Module, Version, [(FAST_STRING, Version)])]
103
104 finalIfaceInfo iface_var imps_reqd imp_mods
105   = returnPrimIO ([], [])
106 \end{code}
107
108
109 \begin{code}
110 noIfaceErr mod sty
111   = ppCat [ppStr "Could not find interface for", ppPStr mod]
112 \end{code}