2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section{Haskell abstract syntax definition}
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.
11 #include "HsVersions.h"
15 -- NB: don't reexport HsCore or HsPragmas;
16 -- this module tells about "real Haskell"
22 EXP_MODULE(HsImpExp) ,
24 EXP_MODULE(HsMatches) ,
29 collectTopBinders, collectMonoBinders
36 import HsDecls ( HsDecl(..), TyDecl(..), InstDecl(..), ClassDecl(..),
39 ConDecl(..), ConDetails(..), BangType(..),
40 IfaceSig(..), HsIdInfo, SpecDataSig(..), SpecInstSig(..),
49 import HsPragmas ( ClassPragmas, ClassOpPragmas,
50 DataPragmas, GenPragmas, InstancePragmas )
52 import BasicTypes ( Fixity, SYN_IE(Version), NewOrData )
55 import FiniteMap ( FiniteMap )
56 import Outputable ( ifPprShowAll, ifnotPprForUser, interpp'SP, Outputable(..) )
58 import SrcLoc ( SrcLoc )
60 #if __GLASGOW_HASKELL__ >= 202
65 @Fake@ is a placeholder type; for when tyvars and uvars aren't used.
69 instance Outputable Fake
72 All we actually declare here is the top-level structure for a module.
74 data HsModule tyvar uvar name pat
77 (Maybe Version) -- source interface version number
78 (Maybe [IE name]) -- export list; Nothing => export everything
79 -- Just [] => export *nothing* (???)
80 -- Just [...] => as you would expect...
81 [ImportDecl name] -- We snaffle interesting stuff out of the
82 -- imported interfaces early on, adding that
83 -- info to TyDecls/etc; so this list is
84 -- often empty, downstream.
86 [HsDecl tyvar uvar name pat] -- Type, class, value, and interface signature decls
91 instance (NamedThing name, Outputable name, Outputable pat,
92 Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar)
93 => Outputable (HsModule tyvar uvar name pat) where
95 ppr sty (HsModule name iface_version exports imports fixities
98 ifPprShowAll sty (ppr sty src_loc),
99 ifnotPprForUser sty (pp_iface_version iface_version),
101 Nothing -> hsep [ptext SLIT("module"), ptext name, ptext SLIT("where")]
103 hsep [ptext SLIT("module"), ptext name, lparen],
104 nest 8 (interpp'SP sty es),
105 nest 4 (ptext SLIT(") where"))
112 pp_nonnull [] = empty
113 pp_nonnull xs = vcat (map (ppr sty) xs)
115 pp_iface_version Nothing = empty
116 pp_iface_version (Just n) = hsep [text "{-# INTERFACE", int n, text "#-}"]
120 %************************************************************************
122 \subsection{Collecting binders from @HsBinds@}
124 %************************************************************************
126 Get all the binders in some @MonoBinds@, IN THE ORDER OF APPEARANCE.
128 These functions are here, rather than in HsBinds, to avoid a loop between HsPat and HsBinds.
137 it should return @[x, y, f, a, b]@ (remember, order important).
140 collectTopBinders :: HsBinds tyvar uvar name (InPat name) -> Bag (name,SrcLoc)
141 collectTopBinders EmptyBinds = emptyBag
142 collectTopBinders (MonoBind b _ _) = collectMonoBinders b
143 collectTopBinders (ThenBinds b1 b2)
144 = collectTopBinders b1 `unionBags` collectTopBinders b2
146 collectMonoBinders :: MonoBinds tyvar uvar name (InPat name) -> Bag (name,SrcLoc)
147 collectMonoBinders EmptyMonoBinds = emptyBag
148 collectMonoBinders (PatMonoBind pat grhss_w_binds loc) = listToBag (map (\v->(v,loc)) (collectPatBinders pat))
149 collectMonoBinders (FunMonoBind f _ matches loc) = unitBag (f,loc)
150 collectMonoBinders (VarMonoBind v expr) = error "collectMonoBinders"
151 collectMonoBinders (CoreMonoBind v expr) = error "collectMonoBinders"
152 collectMonoBinders (AndMonoBinds bs1 bs2)
153 = collectMonoBinders bs1 `unionBags` collectMonoBinders bs2