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