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"
25 Fixity, NewOrData, IfaceFlavour,
27 collectTopBinders, collectMonoBinders
30 #include "HsVersions.h"
34 import HsDecls ( HsDecl(..), TyDecl(..), InstDecl(..), ClassDecl(..),
35 DefaultDecl(..), ForeignDecl(..), ForKind(..),
36 ExtName(..), isDynamic, FixityDecl(..),
37 ConDecl(..), ConDetails(..), BangType(..),
38 IfaceSig(..), SpecDataSig(..),
48 import BasicTypes ( Fixity, Version, NewOrData, IfaceFlavour, Module )
52 import SrcLoc ( SrcLoc )
54 import Name ( NamedThing )
57 All we actually declare here is the top-level structure for a module.
59 data HsModule flexi name pat
62 (Maybe Version) -- source interface version number
63 (Maybe [IE name]) -- export list; Nothing => export everything
64 -- Just [] => export *nothing* (???)
65 -- Just [...] => as you would expect...
66 [ImportDecl name] -- We snaffle interesting stuff out of the
67 -- imported interfaces early on, adding that
68 -- info to TyDecls/etc; so this list is
69 -- often empty, downstream.
71 [HsDecl flexi name pat] -- Type, class, value, and interface signature decls
76 instance (NamedThing name, Outputable name, Outputable pat)
77 => Outputable (HsModule flexi name pat) where
79 ppr (HsModule name iface_version exports imports fixities
83 Nothing -> hsep [ptext SLIT("module"), ptext name, ptext SLIT("where")]
85 hsep [ptext SLIT("module"), ptext name, lparen],
86 nest 8 (interpp'SP es),
87 nest 4 (ptext SLIT(") where"))
95 pp_nonnull xs = vcat (map ppr xs)
97 pp_iface_version Nothing = empty
98 pp_iface_version (Just n) = hsep [text "{-# INTERFACE", int n, text "#-}"]
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 flexi name (InPat name) -> Bag (name,SrcLoc)
123 collectTopBinders EmptyBinds = emptyBag
124 collectTopBinders (MonoBind b _ _) = collectMonoBinders b
125 collectTopBinders (ThenBinds b1 b2)
126 = collectTopBinders b1 `unionBags` collectTopBinders b2
128 collectMonoBinders :: MonoBinds flexi name (InPat name) -> Bag (name,SrcLoc)
129 collectMonoBinders EmptyMonoBinds = emptyBag
130 collectMonoBinders (PatMonoBind pat grhss_w_binds loc) = listToBag (map (\v->(v,loc)) (collectPatBinders pat))
131 collectMonoBinders (FunMonoBind f _ matches loc) = unitBag (f,loc)
132 collectMonoBinders (VarMonoBind v expr) = error "collectMonoBinders"
133 collectMonoBinders (CoreMonoBind v expr) = error "collectMonoBinders"
134 collectMonoBinders (AndMonoBinds bs1 bs2)
135 = collectMonoBinders bs1 `unionBags` collectMonoBinders bs2