2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
5 \section{Haskell abstract syntax definition}
7 This module glues together the pieces of the Haskell abstract syntax,
8 which is declared in the various \tr{Hs*} modules. This module,
9 therefore, is almost nothing but re-exporting.
24 HsModule(..), HsExtCore(..),
30 #include "HsVersions.h"
40 import BasicTypes ( Fixity, DeprecTxt )
45 import IfaceSyn ( IfaceBinding )
47 import SrcLoc ( Located(..) )
48 import Module ( Module, ModuleName )
51 All we actually declare here is the top-level structure for a module.
55 (Maybe (Located ModuleName))-- Nothing => "module X where" is omitted
56 -- (in which case the next field is Nothing too)
57 (Maybe [LIE name]) -- Export list; Nothing => export list omitted, so export everything
58 -- Just [] => export *nothing*
59 -- Just [...] => as you would expect...
60 [LImportDecl 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 [LHsDecl name] -- Type, class, value, and interface signature decls
65 (Maybe DeprecTxt) -- reason/explanation for deprecation of this module
66 (HaddockModInfo name) -- Haddock module info
67 (Maybe (HsDoc name)) -- Haddock module description
69 data HaddockModInfo name = HaddockModInfo {
70 hmi_description :: Maybe (HsDoc name),
71 hmi_portability :: Maybe String,
72 hmi_stability :: Maybe String,
73 hmi_maintainer :: Maybe String
76 emptyHaddockModInfo :: HaddockModInfo a
77 emptyHaddockModInfo = HaddockModInfo {
78 hmi_description = Nothing,
79 hmi_portability = Nothing,
80 hmi_stability = Nothing,
81 hmi_maintainer = Nothing
84 data HsExtCore name -- Read from Foo.hcr
87 [TyClDecl name] -- Type declarations only; just as in Haskell source,
88 -- so that we can infer kinds etc
89 [IfaceBinding] -- And the bindings
94 instance Outputable Char where
97 instance (OutputableBndr name)
98 => Outputable (HsModule name) where
100 ppr (HsModule Nothing _ imports decls _ _ mbDoc)
101 = pp_mb mbDoc $$ pp_nonnull imports $$ pp_nonnull decls
103 ppr (HsModule (Just name) exports imports decls deprec _ mbDoc)
107 Nothing -> pp_header (ptext SLIT("where"))
110 nest 8 (fsep (punctuate comma (map ppr es))),
111 nest 4 (ptext SLIT(") where"))
117 pp_header rest = case deprec of
118 Nothing -> pp_modname <+> rest
119 Just d -> vcat [ pp_modname, ppr d, rest ]
121 pp_modname = ptext SLIT("module") <+> ppr name
123 pp_mb :: Outputable t => Maybe t -> SDoc
124 pp_mb (Just x) = ppr x
125 pp_mb Nothing = empty
127 pp_nonnull :: Outputable t => [t] -> SDoc
128 pp_nonnull [] = empty
129 pp_nonnull xs = vcat (map ppr xs)