9745409a15d196874737a88213bb3cf8f41fe83a
[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         findHiFiles,
11         cacheInterface,
12         readInterface,
13         rnInterfaces,
14         finalIfaceInfo,
15         IfaceCache(..),
16         VersionInfo(..),
17         ParsedIface(..)
18     ) where
19
20 import PreludeGlaST     ( returnPrimIO, thenPrimIO,
21                           readVar, writeVar, MutableVar(..) )
22
23 import Ubiq
24
25 import HsSyn
26 import RdrHsSyn
27 import RnHsSyn
28
29 import RnMonad
30 import RnUtils          ( RnEnv(..) )
31
32 import Bag              ( emptyBag )
33 import ErrUtils         ( Error(..), Warning(..) )
34 import FiniteMap        ( emptyFM, lookupFM, addToFM )
35 import Pretty
36 import Maybes           ( MaybeErr(..) )
37 import Util             ( panic )
38
39 \end{code}
40
41
42 \begin{code}
43 type IfaceCache = MutableVar _RealWorld (FiniteMap Module ParsedIface,
44                                          FiniteMap Module String)
45
46 data ParsedIface = ParsedIface
47 \end{code}
48
49 *********************************************************
50 *                                                       *
51 \subsection{Looking for interface files}
52 *                                                       *
53 *********************************************************
54
55 \begin{code}
56 findHiFiles :: [String] -> PrimIO (FiniteMap Module String)
57 findHiFiles dirs = returnPrimIO emptyFM
58 \end{code}
59
60 *********************************************************
61 *                                                       *
62 \subsection{Reading interface files}
63 *                                                       *
64 *********************************************************
65
66 \begin{code}
67 cacheInterface :: IfaceCache -> Module
68                -> PrimIO (MaybeErr ParsedIface Error)
69
70 cacheInterface iface_var mod
71   = readVar iface_var `thenPrimIO` \ (iface_fm, file_fm) ->
72     case lookupFM iface_fm mod of
73       Just iface -> returnPrimIO (Succeeded iface)
74       Nothing    ->
75         case lookupFM file_fm mod of
76           Nothing   -> returnPrimIO (Failed (noIfaceErr mod))
77           Just file ->
78             readInterface file mod `thenPrimIO` \ read_iface ->
79             case read_iface of
80               Failed err      -> returnPrimIO (Failed err)
81               Succeeded iface ->
82                 let
83                     iface_fm' = addToFM iface_fm mod iface
84                 in
85                 writeVar iface_var (iface_fm', file_fm) `thenPrimIO` \ _ ->
86                 returnPrimIO (Succeeded iface)
87
88
89 readInterface :: String -> Module
90               -> PrimIO (MaybeErr ParsedIface Error)
91
92 readInterface file mod = panic "readInterface"
93 \end{code}
94
95
96 \begin{code}
97 rnInterfaces ::
98            IfaceCache                           -- iface cache
99         -> RnEnv                                -- original name env
100         -> UniqSupply
101         -> RenamedHsModule                      -- module to extend with iface decls
102         -> [RnName]                             -- imported names required
103         -> PrimIO (RenamedHsModule,             -- extended module
104                    ImplicitEnv,                 -- implicit names required
105                    Bag Error,
106                    Bag Warning)
107
108 rnInterfaces iface_var occ_env us rn_module todo
109   = returnPrimIO (rn_module, (emptyFM, emptyFM), emptyBag, emptyBag)
110 \end{code}
111
112
113 \begin{code}
114 finalIfaceInfo ::
115            IfaceCache                           -- iface cache
116         -> [RnName]                             -- all imported names required
117         -> [Module]                             -- directly imported modules
118         -> PrimIO (VersionInfo,                 -- info about version numbers
119                    [Module])                    -- special instance modules
120
121 type VersionInfo = [(Module, Version, [(FAST_STRING, Version)])]
122
123 finalIfaceInfo iface_var imps_reqd imp_mods
124   = returnPrimIO ([], [])
125 \end{code}
126
127
128 \begin{code}
129 noIfaceErr mod sty
130   = ppCat [ppStr "Could not find interface for", ppPStr mod]
131 \end{code}