[project @ 1996-12-19 09:10:02 by simonpj]
[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          ( HsDecl(..), TyDecl(..), InstDecl(..), ClassDecl(..), 
34                           DefaultDecl(..), 
35                           FixityDecl(..), Fixity(..), FixityDirection(..), 
36                           ConDecl(..), BangType(..),
37                           IfaceSig(..), HsIdInfo,  SpecDataSig(..), SpecInstSig(..),
38                           hsDeclName
39                         )
40 import HsExpr
41 import HsImpExp
42 import HsLit
43 import HsMatches
44 import HsPat
45 import HsTypes
46 import HsPragmas        ( ClassPragmas, ClassOpPragmas,
47                           DataPragmas, GenPragmas, InstancePragmas )
48 import HsCore
49
50 -- others:
51 import FiniteMap        ( FiniteMap )
52 import Outputable       ( ifPprShowAll, ifnotPprForUser, interpp'SP, Outputable(..) )
53 import Pretty
54 import SrcLoc           ( SrcLoc )
55 \end{code}
56
57 @Fake@ is a placeholder type; for when tyvars and uvars aren't used.
58 \begin{code}
59 data Fake = Fake
60 instance Eq Fake
61 instance Outputable Fake
62 \end{code}
63
64 All we actually declare here is the top-level structure for a module.
65 \begin{code}
66 type Version = Int
67
68 data HsModule tyvar uvar name pat
69   = HsModule
70         Module                  -- module name
71         (Maybe Version)         -- source interface version number
72         (Maybe [IE name])       -- export list; Nothing => export everything
73                                 -- Just [] => export *nothing* (???)
74                                 -- Just [...] => as you would expect...
75         [ImportDecl name]       -- We snaffle interesting stuff out of the
76                                 -- imported interfaces early on, adding that
77                                 -- info to TyDecls/etc; so this list is
78                                 -- often empty, downstream.
79         [FixityDecl name]
80         [HsDecl tyvar uvar name pat]    -- Type, class, value, and interface signature decls
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                       decls 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 decls
104         ]
105       where
106         pp_nonnull [] = ppNil
107         pp_nonnull xs = ppAboves (map (ppr sty) xs)
108
109         pp_iface_version Nothing  = ppNil
110         pp_iface_version (Just n) = ppCat [ppStr "{-# INTERFACE", ppInt n, ppStr "#-}"]
111 \end{code}