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
14 -- this module tells about "real Haskell"
27 collectTopBinders, collectMonoBinders, collectLocatedMonoBinders
30 #include "HsVersions.h"
41 import BasicTypes ( Fixity, Version, NewOrData )
45 import SrcLoc ( SrcLoc )
47 import Module ( ModuleName )
50 All we actually declare here is the top-level structure for a module.
52 data HsModule name pat
54 ModuleName -- module name
55 (Maybe Version) -- source interface version number
56 (Maybe [IE name]) -- export list; Nothing => export everything
57 -- Just [] => export *nothing* (???)
58 -- Just [...] => as you would expect...
59 [ImportDecl name] -- We snaffle interesting stuff out of the
60 -- imported interfaces early on, adding that
61 -- info to TyDecls/etc; so this list is
62 -- often empty, downstream.
63 [HsDecl name pat] -- Type, class, value, and interface signature decls
64 (Maybe DeprecTxt) -- reason/explanation for deprecation of this module
69 instance (Outputable name, Outputable pat)
70 => Outputable (HsModule name pat) where
72 ppr (HsModule name iface_version exports imports
76 Nothing -> pp_header (ptext SLIT("where"))
79 nest 8 (fsep (punctuate comma (map ppr es))),
80 nest 4 (ptext SLIT(") where"))
86 pp_header rest = case deprec of
87 Nothing -> pp_modname <+> rest
88 Just d -> vcat [ pp_modname, ppr d, rest ]
90 pp_modname = ptext SLIT("module") <+> ppr name
93 pp_nonnull xs = vcat (map ppr xs)
97 %************************************************************************
99 \subsection{Collecting binders from @HsBinds@}
101 %************************************************************************
103 Get all the binders in some @MonoBinds@, IN THE ORDER OF APPEARANCE.
105 These functions are here, rather than in HsBinds, to avoid a loop between HsPat and HsBinds.
114 it should return @[x, y, f, a, b]@ (remember, order important).
117 collectTopBinders :: HsBinds name (InPat name) -> Bag (name,SrcLoc)
118 collectTopBinders EmptyBinds = emptyBag
119 collectTopBinders (MonoBind b _ _) = listToBag (collectLocatedMonoBinders b)
120 collectTopBinders (ThenBinds b1 b2) = collectTopBinders b1 `unionBags` collectTopBinders b2
122 collectLocatedMonoBinders :: MonoBinds name (InPat name) -> [(name,SrcLoc)]
123 collectLocatedMonoBinders binds
126 go EmptyMonoBinds acc = acc
127 go (PatMonoBind pat _ loc) acc = map (\v->(v,loc)) (collectPatBinders pat) ++ acc
128 go (FunMonoBind f _ _ loc) acc = (f,loc) : acc
129 go (AndMonoBinds bs1 bs2) acc = go bs1 (go bs2 acc)
131 collectMonoBinders :: MonoBinds name (InPat name) -> [name]
132 collectMonoBinders binds
135 go EmptyMonoBinds acc = acc
136 go (PatMonoBind pat _ loc) acc = collectPatBinders pat ++ acc
137 go (FunMonoBind f _ _ loc) acc = f : acc
138 go (AndMonoBinds bs1 bs2) acc = go bs1 (go bs2 acc)