[project @ 2000-10-12 11:32:33 by sewardj]
[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 \end{code}
52
53 %************************************************************************
54 %*                                                                      *
55 \subsection{Imported and exported entities}
56 %*                                                                      *
57 %************************************************************************
58
59 \begin{code}
60 data IE name
61   = IEVar               name
62   | IEThingAbs          name            -- Class/Type (can't tell)
63   | IEThingAll          name            -- Class/Type plus all methods/constructors
64   | IEThingWith         name [name]     -- Class/Type plus some methods/constructors
65   | IEModuleContents    ModuleName      -- (Export Only)
66 \end{code}
67
68 \begin{code}
69 ieName :: IE name -> name
70 ieName (IEVar n)         = n
71 ieName (IEThingAbs  n)   = n
72 ieName (IEThingWith n _) = n
73 ieName (IEThingAll  n)   = n
74
75 ieNames :: IE a -> [a]
76 ieNames (IEVar            n   ) = [n]
77 ieNames (IEThingAbs       n   ) = [n]
78 ieNames (IEThingAll       n   ) = [n]
79 ieNames (IEThingWith      n ns) = n:ns
80 ieNames (IEModuleContents _   ) = []
81 \end{code}
82
83 \begin{code}
84 instance (Outputable name) => Outputable (IE name) where
85     ppr (IEVar          var)    = ppr var
86     ppr (IEThingAbs     thing)  = ppr thing
87     ppr (IEThingAll     thing)  = hcat [ppr thing, text "(..)"]
88     ppr (IEThingWith thing withs)
89         = ppr thing <> parens (fsep (punctuate comma (map ppr withs)))
90     ppr (IEModuleContents mod)
91         = ptext SLIT("module") <+> ppr mod
92 \end{code}
93