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