[project @ 1996-03-19 08:58:34 by partain]
[ghc-hetmet.git] / ghc / compiler / hsSyn / HsSyn.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 %
4 \section{Haskell abstract syntax definition}
5
6 This module glues together the pieces of the Haskell abstract syntax,
7 which is declared in the various \tr{Hs*} modules.  This module,
8 therefore, is almost nothing but re-exporting.
9
10 \begin{code}
11 #include "HsVersions.h"
12
13 module HsSyn (
14
15         -- NB: don't reexport HsCore or HsPragmas;
16         -- this module tells about "real Haskell"
17
18         HsSyn.. ,
19         HsBinds.. ,
20         HsDecls.. ,
21         HsExpr.. ,
22         HsImpExp.. ,
23         HsLit.. ,
24         HsMatches.. ,
25         HsPat.. ,
26         HsTypes..
27
28      ) where
29
30 import Ubiq{-uitous-}
31
32 -- friends:
33 import HsBinds
34 import HsDecls
35 import HsExpr
36 import HsImpExp
37 import HsLit
38 import HsMatches
39 import HsPat
40 import HsTypes
41 import HsPragmas        ( ClassPragmas, ClassOpPragmas,
42                           DataPragmas, GenPragmas, InstancePragmas
43                         )
44 -- others:
45 import FiniteMap        ( FiniteMap )
46 import Outputable       ( ifPprShowAll, interpp'SP, Outputable(..){-instances-} )
47 import Pretty
48 import SrcLoc           ( SrcLoc{-instances-} )
49 \end{code}
50
51 @Fake@ is a placeholder type; for when tyvars and uvars aren't used.
52 \begin{code}
53 data Fake = Fake
54 instance Eq Fake
55 instance Outputable Fake
56 \end{code}
57
58 All we actually declare here is the top-level structure for a module.
59 \begin{code}
60 data HsModule tyvar uvar name pat
61   = HsModule
62         FAST_STRING             -- module name
63         (Maybe [IE name])       -- export list; Nothing => export everything
64                                 -- Just [] => export *nothing* (???)
65                                 -- Just [...] => as you would expect...
66         [ImportedInterface tyvar uvar name pat]
67                                 -- We snaffle interesting stuff out of the
68                                 -- imported interfaces early on, adding that
69                                 -- info to TyDecls/etc; so this list is
70                                 -- often empty, downstream.
71         [FixityDecl name]
72         [TyDecl name]
73         [SpecDataSig name]      -- user pragmas that modify TyDecls
74         [ClassDecl tyvar uvar name pat]
75         [InstDecl  tyvar uvar name pat]
76         [SpecInstSig name]      -- user pragmas that modify InstDecls
77         [DefaultDecl name]
78         (HsBinds tyvar uvar name pat)   -- the main stuff!
79         [Sig name]              -- "Sigs" are folded into the "HsBinds"
80                                 -- pretty early on, so this list is
81                                 -- often either empty or just the
82                                 -- interface signatures.
83         SrcLoc
84 \end{code}
85
86 \begin{code}
87 instance (NamedThing name, Outputable name, Outputable pat,
88           Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar)
89         => Outputable (HsModule tyvar uvar name pat) where
90
91     ppr sty (HsModule name exports imports fixities
92                       typedecls typesigs classdecls instdecls instsigs
93                       defdecls binds sigs src_loc)
94       = ppAboves [
95             ifPprShowAll sty (ppr sty src_loc),
96             case exports of
97               Nothing -> ppCat [ppPStr SLIT("module"), ppPStr name, ppPStr SLIT("where")]
98               Just es -> ppAboves [
99                             ppCat [ppPStr SLIT("module"), ppPStr name, ppLparen],
100                             ppNest 8 (interpp'SP sty es),
101                             ppNest 4 (ppPStr SLIT(") where"))
102                           ],
103             pp_nonnull imports,     pp_nonnull fixities,
104             pp_nonnull typedecls,   pp_nonnull typesigs,
105             pp_nonnull classdecls,
106             pp_nonnull instdecls,   pp_nonnull instsigs,
107             pp_nonnull defdecls,
108             ppr sty binds,          pp_nonnull sigs
109         ]
110       where
111         pp_nonnull [] = ppNil
112         pp_nonnull xs = ppAboves (map (ppr sty) xs)
113 \end{code}