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,
28 hsModuleName, hsModuleImports
31 #include "HsVersions.h"
42 import BasicTypes ( Fixity, Version, NewOrData )
45 import Name ( NamedThing )
47 import SrcLoc ( SrcLoc )
49 import Module ( ModuleName )
52 All we actually declare here is the top-level structure for a module.
54 data HsModule name pat
56 ModuleName -- module name
57 (Maybe Version) -- source interface version number
58 (Maybe [IE name]) -- export list; Nothing => export everything
59 -- Just [] => export *nothing* (???)
60 -- Just [...] => as you would expect...
61 [ImportDecl name] -- We snaffle interesting stuff out of the
62 -- imported interfaces early on, adding that
63 -- info to TyDecls/etc; so this list is
64 -- often empty, downstream.
65 [HsDecl name pat] -- Type, class, value, and interface signature decls
66 (Maybe DeprecTxt) -- reason/explanation for deprecation of this module
71 instance (NamedThing name, Outputable name, Outputable pat)
72 => Outputable (HsModule name pat) where
74 ppr (HsModule name iface_version exports imports
78 Nothing -> pp_header (ptext SLIT("where"))
81 nest 8 (fsep (punctuate comma (map ppr es))),
82 nest 4 (ptext SLIT(") where"))
88 pp_header rest = case deprec of
89 Nothing -> pp_modname <+> rest
90 Just d -> vcat [ pp_modname, ppr d, rest ]
92 pp_modname = ptext SLIT("module") <+> ppr name
95 pp_nonnull xs = vcat (map ppr xs)
97 hsModuleName (HsModule mod_name _ _ _ _ _ _) = mod_name
98 hsModuleImports (HsModule mod_name vers exports imports decls deprec src_loc) = imports
102 %************************************************************************
104 \subsection{Collecting binders from @HsBinds@}
106 %************************************************************************
108 Get all the binders in some @MonoBinds@, IN THE ORDER OF APPEARANCE.
110 These functions are here, rather than in HsBinds, to avoid a loop between HsPat and HsBinds.
119 it should return @[x, y, f, a, b]@ (remember, order important).
122 collectTopBinders :: HsBinds name (InPat name) -> Bag (name,SrcLoc)
123 collectTopBinders EmptyBinds = emptyBag
124 collectTopBinders (MonoBind b _ _) = listToBag (collectLocatedMonoBinders b)
125 collectTopBinders (ThenBinds b1 b2) = collectTopBinders b1 `unionBags` collectTopBinders b2
127 collectLocatedMonoBinders :: MonoBinds name (InPat name) -> [(name,SrcLoc)]
128 collectLocatedMonoBinders binds
131 go EmptyMonoBinds acc = acc
132 go (PatMonoBind pat _ loc) acc = map (\v->(v,loc)) (collectPatBinders pat) ++ acc
133 go (FunMonoBind f _ _ loc) acc = (f,loc) : acc
134 go (AndMonoBinds bs1 bs2) acc = go bs1 (go bs2 acc)
136 collectMonoBinders :: MonoBinds name (InPat name) -> [name]
137 collectMonoBinders binds
140 go EmptyMonoBinds acc = acc
141 go (PatMonoBind pat _ loc) acc = collectPatBinders pat ++ acc
142 go (FunMonoBind f _ _ loc) acc = f : acc
143 go (AndMonoBinds bs1 bs2) acc = go bs1 (go bs2 acc)