[project @ 1997-07-05 03:02:04 by sof]
[ghc-hetmet.git] / ghc / compiler / hsSyn / HsImpExp.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 %
4 \section[HsImpExp]{Abstract syntax: imports, exports, interfaces}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module HsImpExp where
10
11 IMP_Ubiq()
12
13 import BasicTypes       ( IfaceFlavour(..) )
14 import Outputable
15 import Pretty
16 import SrcLoc           ( SrcLoc )
17 #if __GLASGOW_HASKELL__ >= 202
18 import Name
19 #endif
20 \end{code}
21
22 %************************************************************************
23 %*                                                                      *
24 \subsection{Import and export declaration lists}
25 %*                                                                      *
26 %************************************************************************
27
28 One per \tr{import} declaration in a module.
29 \begin{code}
30 data ImportDecl name
31   = ImportDecl    Module                        -- module name
32                   Bool                          -- True => qualified
33                   IfaceFlavour                  -- True => source imported module 
34                                                 --    (current interpretation: ignore ufolding info)
35                   (Maybe Module)                -- as Module
36                   (Maybe (Bool, [IE name]))     -- (True => hiding, names)
37                   SrcLoc
38 \end{code}
39
40 \begin{code}
41 instance (NamedThing name, Outputable name) => Outputable (ImportDecl name) where
42     ppr sty (ImportDecl mod qual as_source as spec _)
43       = hang (hsep [ptext SLIT("import"), pp_src as_source, 
44                     pp_qual qual, ptext mod, pp_as as])
45              4 (pp_spec spec)
46       where
47         pp_src HiFile     = empty
48         pp_src HiBootFile = ptext SLIT("{-# SOURCE #-}")
49
50         pp_qual False   = empty
51         pp_qual True    = ptext SLIT("qualified")
52
53         pp_as Nothing   = empty
54         pp_as (Just a)  = (<>) (ptext SLIT("as ")) (ptext a)
55
56         pp_spec Nothing = empty
57         pp_spec (Just (False, spec))
58                         = parens (interpp'SP sty spec)
59         pp_spec (Just (True, spec))
60                         = (<>) (ptext SLIT("hiding ")) (parens (interpp'SP sty spec))
61 \end{code}
62
63 %************************************************************************
64 %*                                                                      *
65 \subsection{Imported and exported entities}
66 %*                                                                      *
67 %************************************************************************
68
69 \begin{code}
70 data IE name
71   = IEVar               name
72   | IEThingAbs          name            -- Class/Type (can't tell)
73   | IEThingAll          name            -- Class/Type plus all methods/constructors
74   | IEThingWith         name [name]     -- Class/Type plus some methods/constructors
75   | IEModuleContents    Module          -- (Export Only)
76 \end{code}
77
78 \begin{code}
79 ieName :: IE name -> name
80 ieName (IEVar n)         = n
81 ieName (IEThingAbs  n)   = n
82 ieName (IEThingWith n _) = n
83 ieName (IEThingAll  n)   = n
84 \end{code}
85
86 \begin{code}
87 instance (NamedThing name, Outputable name) => Outputable (IE name) where
88     ppr sty (IEVar      var)    = ppr sty var
89     ppr sty (IEThingAbs thing)  = ppr sty thing
90     ppr sty (IEThingAll thing)
91         = hcat [ppr sty thing, text "(..)"]
92     ppr sty (IEThingWith thing withs)
93         = (<>) (ppr sty thing)
94             (parens (fsep (punctuate comma (map (ppr sty) withs))))
95     ppr sty (IEModuleContents mod)
96         = (<>) (ptext SLIT("module ")) (ptext mod)
97 \end{code}
98