[project @ 1997-05-19 00:12:10 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 Outputable
14 import PprStyle         ( PprStyle(..) )
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                   (Maybe Module)                -- as Module
34                   (Maybe (Bool, [IE name]))     -- (True => hiding, names)
35                   SrcLoc
36 \end{code}
37
38 \begin{code}
39 instance (NamedThing name, Outputable name) => Outputable (ImportDecl name) where
40     ppr sty (ImportDecl mod qual as spec _)
41       = hang (hsep [ptext SLIT("import"), pp_qual qual, ptext mod, pp_as as])
42              4 (pp_spec spec)
43       where
44         pp_qual False   = empty
45         pp_qual True    = ptext SLIT("qualified")
46
47         pp_as Nothing   = empty
48         pp_as (Just a)  = (<>) (ptext SLIT("as ")) (ptext a)
49
50         pp_spec Nothing = empty
51         pp_spec (Just (False, spec))
52                         = parens (interpp'SP sty spec)
53         pp_spec (Just (True, spec))
54                         = (<>) (ptext SLIT("hiding ")) (parens (interpp'SP sty spec))
55 \end{code}
56
57 %************************************************************************
58 %*                                                                      *
59 \subsection{Imported and exported entities}
60 %*                                                                      *
61 %************************************************************************
62
63 \begin{code}
64 data IE name
65   = IEVar               name
66   | IEThingAbs          name            -- Class/Type (can't tell)
67   | IEThingAll          name            -- Class/Type plus all methods/constructors
68   | IEThingWith         name [name]     -- Class/Type plus some methods/constructors
69   | IEModuleContents    Module          -- (Export Only)
70 \end{code}
71
72 \begin{code}
73 ieName :: IE name -> name
74 ieName (IEVar n)         = n
75 ieName (IEThingAbs  n)   = n
76 ieName (IEThingWith n _) = n
77 ieName (IEThingAll  n)   = n
78 \end{code}
79
80 \begin{code}
81 instance (NamedThing name, Outputable name) => Outputable (IE name) where
82     ppr sty (IEVar      var)    = ppr sty var
83     ppr sty (IEThingAbs thing)  = ppr sty thing
84     ppr sty (IEThingAll thing)
85         = hcat [ppr sty thing, text "(..)"]
86     ppr sty (IEThingWith thing withs)
87         = (<>) (ppr sty thing)
88             (parens (fsep (punctuate comma (map (ppr sty) withs))))
89     ppr sty (IEModuleContents mod)
90         = (<>) (ptext SLIT("module ")) (ptext mod)
91 \end{code}
92