[project @ 1996-06-05 06:44:31 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 IMP_Ubiq()
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 -- others:
44 import FiniteMap        ( FiniteMap )
45 import Outputable       ( ifPprShowAll, ifnotPprForUser, interpp'SP, Outputable(..) )
46 import Pretty
47 import SrcLoc           ( SrcLoc )
48 \end{code}
49
50 @Fake@ is a placeholder type; for when tyvars and uvars aren't used.
51 \begin{code}
52 data Fake = Fake
53 instance Eq Fake
54 instance Outputable Fake
55 \end{code}
56
57 All we actually declare here is the top-level structure for a module.
58 \begin{code}
59 type Version = Int
60
61 data HsModule tyvar uvar name pat
62   = HsModule
63         Module                  -- module name
64         (Maybe Version)         -- source interface version number
65         (Maybe [IE name])       -- export list; Nothing => export everything
66                                 -- Just [] => export *nothing* (???)
67                                 -- Just [...] => as you would expect...
68         [ImportDecl name]       -- We snaffle interesting stuff out of the
69                                 -- imported interfaces early on, adding that
70                                 -- info to TyDecls/etc; so this list is
71                                 -- often empty, downstream.
72         [FixityDecl name]
73         [TyDecl name]
74         [SpecDataSig name]              -- user pragmas that modify TyDecls
75         [ClassDecl tyvar uvar name pat]
76         [InstDecl  tyvar uvar name pat]
77         [SpecInstSig name]              -- user pragmas that modify InstDecls
78         [DefaultDecl name]
79         (HsBinds tyvar uvar name pat)   -- the main stuff, includes source sigs
80         [Sig name]                      -- interface sigs
81         SrcLoc
82 \end{code}
83
84 \begin{code}
85 instance (NamedThing name, Outputable name, Outputable pat,
86           Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar)
87         => Outputable (HsModule tyvar uvar name pat) where
88
89     ppr sty (HsModule name iface_version exports imports fixities
90                       typedecls typesigs classdecls instdecls instsigs
91                       defdecls binds sigs src_loc)
92       = ppAboves [
93             ifPprShowAll sty (ppr sty src_loc),
94             ifnotPprForUser sty (pp_iface_version iface_version),
95             case exports of
96               Nothing -> ppCat [ppPStr SLIT("module"), ppPStr name, ppPStr SLIT("where")]
97               Just es -> ppAboves [
98                             ppCat [ppPStr SLIT("module"), ppPStr name, ppLparen],
99                             ppNest 8 (interpp'SP sty es),
100                             ppNest 4 (ppPStr SLIT(") where"))
101                           ],
102             pp_nonnull imports,
103             pp_nonnull fixities,
104             pp_nonnull typedecls,
105             pp_nonnull typesigs,
106             pp_nonnull classdecls,
107             pp_nonnull instdecls,
108             pp_nonnull instsigs,
109             pp_nonnull defdecls,
110             ppr sty binds,
111             pp_nonnull sigs
112         ]
113       where
114         pp_nonnull [] = ppNil
115         pp_nonnull xs = ppAboves (map (ppr sty) xs)
116
117         pp_iface_version Nothing  = ppNil
118         pp_iface_version (Just n) = ppCat [ppStr "{-# INTERFACE", ppInt n, ppStr "#-}"]
119 \end{code}