[project @ 1997-01-18 10:03:27 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(HsBasic) ,
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(..), 
36                           ConDecl(..), BangType(..),
37                           IfaceSig(..), HsIdInfo,  SpecDataSig(..), SpecInstSig(..),
38                           hsDeclName
39                         )
40 import HsExpr
41 import HsImpExp
42 import HsBasic
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 data HsModule tyvar uvar name pat
67   = HsModule
68         Module                  -- module name
69         (Maybe Version)         -- source interface version number
70         (Maybe [IE name])       -- export list; Nothing => export everything
71                                 -- Just [] => export *nothing* (???)
72                                 -- Just [...] => as you would expect...
73         [ImportDecl name]       -- We snaffle interesting stuff out of the
74                                 -- imported interfaces early on, adding that
75                                 -- info to TyDecls/etc; so this list is
76                                 -- often empty, downstream.
77         [FixityDecl name]
78         [HsDecl tyvar uvar name pat]    -- Type, class, value, and interface signature decls
79         SrcLoc
80 \end{code}
81
82 \begin{code}
83 instance (NamedThing name, Outputable name, Outputable pat,
84           Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar)
85         => Outputable (HsModule tyvar uvar name pat) where
86
87     ppr sty (HsModule name iface_version exports imports fixities
88                       decls src_loc)
89       = ppAboves [
90             ifPprShowAll sty (ppr sty src_loc),
91             ifnotPprForUser sty (pp_iface_version iface_version),
92             case exports of
93               Nothing -> ppCat [ppPStr SLIT("module"), ppPStr name, ppPStr SLIT("where")]
94               Just es -> ppAboves [
95                             ppCat [ppPStr SLIT("module"), ppPStr name, ppLparen],
96                             ppNest 8 (interpp'SP sty es),
97                             ppNest 4 (ppPStr SLIT(") where"))
98                           ],
99             pp_nonnull imports,
100             pp_nonnull fixities,
101             pp_nonnull decls
102         ]
103       where
104         pp_nonnull [] = ppNil
105         pp_nonnull xs = ppAboves (map (ppr sty) xs)
106
107         pp_iface_version Nothing  = ppNil
108         pp_iface_version (Just n) = ppCat [ppStr "{-# INTERFACE", ppInt n, ppStr "#-}"]
109 \end{code}