[project @ 1996-07-15 11:32: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         EXP_MODULE(HsSyn) ,
19         EXP_MODULE(HsBinds) ,
20         EXP_MODULE(HsDecls) ,
21         EXP_MODULE(HsExpr) ,
22         EXP_MODULE(HsImpExp) ,
23         EXP_MODULE(HsLit) ,
24         EXP_MODULE(HsMatches) ,
25         EXP_MODULE(HsPat) ,
26         EXP_MODULE(HsTypes)
27      ) where
28
29 IMP_Ubiq()
30
31 -- friends:
32 import HsBinds
33 import HsDecls
34 import HsExpr
35 import HsImpExp
36 import HsLit
37 import HsMatches
38 import HsPat
39 import HsTypes
40 import HsPragmas        ( ClassPragmas, ClassOpPragmas,
41                           DataPragmas, GenPragmas, InstancePragmas )
42 -- others:
43 import FiniteMap        ( FiniteMap )
44 import Outputable       ( ifPprShowAll, ifnotPprForUser, interpp'SP, Outputable(..) )
45 import Pretty
46 import SrcLoc           ( SrcLoc )
47 \end{code}
48
49 @Fake@ is a placeholder type; for when tyvars and uvars aren't used.
50 \begin{code}
51 data Fake = Fake
52 instance Eq Fake
53 instance Outputable Fake
54 \end{code}
55
56 All we actually declare here is the top-level structure for a module.
57 \begin{code}
58 type Version = Int
59
60 data HsModule tyvar uvar name pat
61   = HsModule
62         Module                  -- module name
63         (Maybe Version)         -- source interface version number
64         (Maybe [IE name])       -- export list; Nothing => export everything
65                                 -- Just [] => export *nothing* (???)
66                                 -- Just [...] => as you would expect...
67         [ImportDecl name]       -- 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, includes source sigs
79         [Sig name]                      -- interface sigs
80         SrcLoc
81 \end{code}
82
83 \begin{code}
84 instance (NamedThing name, Outputable name, Outputable pat,
85           Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar)
86         => Outputable (HsModule tyvar uvar name pat) where
87
88     ppr sty (HsModule name iface_version exports imports fixities
89                       typedecls typesigs classdecls instdecls instsigs
90                       defdecls binds sigs src_loc)
91       = ppAboves [
92             ifPprShowAll sty (ppr sty src_loc),
93             ifnotPprForUser sty (pp_iface_version iface_version),
94             case exports of
95               Nothing -> ppCat [ppPStr SLIT("module"), ppPStr name, ppPStr SLIT("where")]
96               Just es -> ppAboves [
97                             ppCat [ppPStr SLIT("module"), ppPStr name, ppLparen],
98                             ppNest 8 (interpp'SP sty es),
99                             ppNest 4 (ppPStr SLIT(") where"))
100                           ],
101             pp_nonnull imports,
102             pp_nonnull fixities,
103             pp_nonnull typedecls,
104             pp_nonnull typesigs,
105             pp_nonnull classdecls,
106             pp_nonnull instdecls,
107             pp_nonnull instsigs,
108             pp_nonnull defdecls,
109             ppr sty binds,
110             pp_nonnull sigs
111         ]
112       where
113         pp_nonnull [] = ppNil
114         pp_nonnull xs = ppAboves (map (ppr sty) xs)
115
116         pp_iface_version Nothing  = ppNil
117         pp_iface_version (Just n) = ppCat [ppStr "{-# INTERFACE", ppInt n, ppStr "#-}"]
118 \end{code}