2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
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.
13 -- NB: don't reexport HsCore or HsPragmas;
14 -- this module tells about "real Haskell"
27 collectTopBinders, collectMonoBinders
30 #include "HsVersions.h"
42 import BasicTypes ( Fixity, Version, NewOrData )
46 import SrcLoc ( SrcLoc )
48 import Module ( ModuleName, pprModuleName )
51 All we actually declare here is the top-level structure for a module.
53 data HsModule name pat
55 ModuleName -- module name
56 (Maybe Version) -- source interface version number
57 (Maybe [IE name]) -- export list; Nothing => export everything
58 -- Just [] => export *nothing* (???)
59 -- Just [...] => as you would expect...
60 [ImportDecl name] -- We snaffle interesting stuff out of the
61 -- imported interfaces early on, adding that
62 -- info to TyDecls/etc; so this list is
63 -- often empty, downstream.
64 [HsDecl name pat] -- Type, class, value, and interface signature decls
65 (Maybe DeprecTxt) -- reason/explanation for deprecation of this module
70 instance (Outputable name, Outputable pat)
71 => Outputable (HsModule name pat) where
73 ppr (HsModule name iface_version exports imports
77 Nothing -> pp_header (ptext SLIT("where"))
80 nest 8 (fsep (punctuate comma (map ppr es))),
81 nest 4 (ptext SLIT(") where"))
87 pp_header rest = case deprec of
88 Nothing -> pp_modname <+> rest
91 hsep [ptext SLIT("{-# DEPRECATED"), doubleQuotes (ppr dt), ptext SLIT("#-}")],
95 pp_modname = ptext SLIT("module") <+> pprModuleName name
98 pp_nonnull xs = vcat (map ppr xs)
100 pp_iface_version Nothing = empty
101 pp_iface_version (Just n) = hsep [text "{-# INTERFACE", int n, text "#-}"]
105 %************************************************************************
107 \subsection{Collecting binders from @HsBinds@}
109 %************************************************************************
111 Get all the binders in some @MonoBinds@, IN THE ORDER OF APPEARANCE.
113 These functions are here, rather than in HsBinds, to avoid a loop between HsPat and HsBinds.
122 it should return @[x, y, f, a, b]@ (remember, order important).
125 collectTopBinders :: HsBinds name (InPat name) -> Bag (name,SrcLoc)
126 collectTopBinders EmptyBinds = emptyBag
127 collectTopBinders (MonoBind b _ _) = collectMonoBinders b
128 collectTopBinders (ThenBinds b1 b2)
129 = collectTopBinders b1 `unionBags` collectTopBinders b2
131 collectMonoBinders :: MonoBinds name (InPat name) -> Bag (name,SrcLoc)
132 collectMonoBinders EmptyMonoBinds = emptyBag
133 collectMonoBinders (PatMonoBind pat _ loc) = listToBag (map (\v->(v,loc)) (collectPatBinders pat))
134 collectMonoBinders (FunMonoBind f _ matches loc) = unitBag (f,loc)
135 collectMonoBinders (VarMonoBind v expr) = error "collectMonoBinders"
136 collectMonoBinders (CoreMonoBind v expr) = error "collectMonoBinders"
137 collectMonoBinders (AndMonoBinds bs1 bs2) = collectMonoBinders bs1 `unionBags`
138 collectMonoBinders bs2