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(..),
38 import BasicTypes ( Fixity, WarningTxt )
43 import IfaceSyn ( IfaceBinding )
45 import SrcLoc ( Located(..) )
46 import Module ( Module, ModuleName )
51 -- | All we actually declare here is the top-level structure for a module.
54 hsmodName :: Maybe (Located ModuleName),
55 -- ^ @Nothing@: \"module X where\" is omitted (in which case the next
56 -- field is Nothing too)
57 hsmodExports :: Maybe [LIE name],
60 -- - @Nothing@: export list omitted, so export everything
62 -- - @Just []@: export /nothing/
64 -- - @Just [...]@: as you would expect...
66 hsmodImports :: [LImportDecl name],
67 -- ^ We snaffle interesting stuff out of the imported interfaces early
68 -- on, adding that info to TyDecls/etc; so this list is often empty,
70 hsmodDecls :: [LHsDecl name],
71 -- ^ Type, class, value, and interface signature decls
72 hsmodDeprecMessage :: Maybe WarningTxt,
73 -- ^ reason\/explanation for warning/deprecation of this module
74 hsmodHaddockModInfo :: HaddockModInfo name,
75 -- ^ Haddock module info
76 hsmodHaddockModDescr :: Maybe (HsDoc name)
77 -- ^ Haddock module description
80 data HaddockModInfo name = HaddockModInfo {
81 hmi_description :: Maybe (HsDoc name),
82 hmi_portability :: Maybe String,
83 hmi_stability :: Maybe String,
84 hmi_maintainer :: Maybe String
87 emptyHaddockModInfo :: HaddockModInfo a
88 emptyHaddockModInfo = HaddockModInfo {
89 hmi_description = Nothing,
90 hmi_portability = Nothing,
91 hmi_stability = Nothing,
92 hmi_maintainer = Nothing
95 data HsExtCore name -- Read from Foo.hcr
98 [TyClDecl name] -- Type declarations only; just as in Haskell source,
99 -- so that we can infer kinds etc
100 [IfaceBinding] -- And the bindings
105 instance Outputable Char where
108 instance (OutputableBndr name)
109 => Outputable (HsModule name) where
111 ppr (HsModule Nothing _ imports decls _ _ mbDoc)
112 = pp_mb mbDoc $$ pp_nonnull imports $$ pp_nonnull decls
114 ppr (HsModule (Just name) exports imports decls deprec _ mbDoc)
118 Nothing -> pp_header (ptext (sLit "where"))
121 nest 8 (fsep (punctuate comma (map ppr es))),
122 nest 4 (ptext (sLit ") where"))
128 pp_header rest = case deprec of
129 Nothing -> pp_modname <+> rest
130 Just d -> vcat [ pp_modname, ppr d, rest ]
132 pp_modname = ptext (sLit "module") <+> ppr name
134 pp_mb :: Outputable t => Maybe t -> SDoc
135 pp_mb (Just x) = ppr x
136 pp_mb Nothing = empty
138 pp_nonnull :: Outputable t => [t] -> SDoc
139 pp_nonnull [] = empty
140 pp_nonnull xs = vcat (map ppr xs)