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