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.
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(..), HsIdInfo, SpecDataSig(..),
47 import HsPragmas ( ClassPragmas, ClassOpPragmas,
48 DataPragmas, GenPragmas, InstancePragmas )
50 import BasicTypes ( Fixity, Version, NewOrData, IfaceFlavour, Module )
53 import FiniteMap ( FiniteMap )
55 import SrcLoc ( SrcLoc )
57 import Name ( NamedThing )
60 All we actually declare here is the top-level structure for a module.
62 data HsModule flexi name pat
65 (Maybe Version) -- source interface version number
66 (Maybe [IE name]) -- export list; Nothing => export everything
67 -- Just [] => export *nothing* (???)
68 -- Just [...] => as you would expect...
69 [ImportDecl name] -- We snaffle interesting stuff out of the
70 -- imported interfaces early on, adding that
71 -- info to TyDecls/etc; so this list is
72 -- often empty, downstream.
74 [HsDecl flexi name pat] -- Type, class, value, and interface signature decls
79 instance (NamedThing name, Outputable name, Outputable pat)
80 => Outputable (HsModule flexi name pat) where
82 ppr (HsModule name iface_version exports imports fixities
86 Nothing -> hsep [ptext SLIT("module"), ptext name, ptext SLIT("where")]
88 hsep [ptext SLIT("module"), ptext name, lparen],
89 nest 8 (interpp'SP es),
90 nest 4 (ptext SLIT(") where"))
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 flexi 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 flexi name (InPat name) -> Bag (name,SrcLoc)
132 collectMonoBinders EmptyMonoBinds = emptyBag
133 collectMonoBinders (PatMonoBind pat grhss_w_binds 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)
138 = collectMonoBinders bs1 `unionBags` collectMonoBinders bs2