[project @ 1997-05-19 00:12:10 by sof]
[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         NewOrData(..)
28      ) where
29
30 IMP_Ubiq()
31
32 -- friends:
33 import HsBinds
34 import HsDecls          ( HsDecl(..), TyDecl(..), InstDecl(..), ClassDecl(..), 
35                           DefaultDecl(..), 
36                           FixityDecl(..), 
37                           ConDecl(..), ConDetails(..), BangType(..),
38                           IfaceSig(..), HsIdInfo,  SpecDataSig(..), SpecInstSig(..),
39                           hsDeclName
40                         )
41 import HsExpr
42 import HsImpExp
43 import HsBasic
44 import HsMatches
45 import HsPat
46 import HsTypes
47 import HsPragmas        ( ClassPragmas, ClassOpPragmas,
48                           DataPragmas, GenPragmas, InstancePragmas )
49 import HsCore
50 import TyCon            ( NewOrData(..) )
51
52 -- others:
53 import FiniteMap        ( FiniteMap )
54 import Outputable       ( ifPprShowAll, ifnotPprForUser, interpp'SP, Outputable(..) )
55 import Pretty
56 import SrcLoc           ( SrcLoc )
57 #if __GLASGOW_HASKELL__ >= 202
58 import Name
59 #endif
60 \end{code}
61
62 @Fake@ is a placeholder type; for when tyvars and uvars aren't used.
63 \begin{code}
64 data Fake = Fake
65 instance Eq Fake
66 instance Outputable Fake
67 \end{code}
68
69 All we actually declare here is the top-level structure for a module.
70 \begin{code}
71 data HsModule tyvar uvar name pat
72   = HsModule
73         Module                  -- module name
74         (Maybe Version)         -- source interface version number
75         (Maybe [IE name])       -- export list; Nothing => export everything
76                                 -- Just [] => export *nothing* (???)
77                                 -- Just [...] => as you would expect...
78         [ImportDecl name]       -- We snaffle interesting stuff out of the
79                                 -- imported interfaces early on, adding that
80                                 -- info to TyDecls/etc; so this list is
81                                 -- often empty, downstream.
82         [FixityDecl name]
83         [HsDecl tyvar uvar name pat]    -- Type, class, value, and interface signature decls
84         SrcLoc
85 \end{code}
86
87 \begin{code}
88 instance (NamedThing name, Outputable name, Outputable pat,
89           Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar)
90         => Outputable (HsModule tyvar uvar name pat) where
91
92     ppr sty (HsModule name iface_version exports imports fixities
93                       decls src_loc)
94       = vcat [
95             ifPprShowAll sty (ppr sty src_loc),
96             ifnotPprForUser sty (pp_iface_version iface_version),
97             case exports of
98               Nothing -> hsep [ptext SLIT("module"), ptext name, ptext SLIT("where")]
99               Just es -> vcat [
100                             hsep [ptext SLIT("module"), ptext name, lparen],
101                             nest 8 (interpp'SP sty es),
102                             nest 4 (ptext SLIT(") where"))
103                           ],
104             pp_nonnull imports,
105             pp_nonnull fixities,
106             pp_nonnull decls
107         ]
108       where
109         pp_nonnull [] = empty
110         pp_nonnull xs = vcat (map (ppr sty) xs)
111
112         pp_iface_version Nothing  = empty
113         pp_iface_version (Just n) = hsep [text "{-# INTERFACE", int n, text "#-}"]
114 \end{code}