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