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.
12 {-# LANGUAGE DeriveDataTypeable #-}
26 HsModule(..), HsExtCore(..),
37 import BasicTypes ( Fixity, WarningTxt )
42 import IfaceSyn ( IfaceBinding )
44 import SrcLoc ( Located(..) )
45 import Module ( Module, ModuleName )
49 import Data.Data hiding ( Fixity )
53 -- | All we actually declare here is the top-level structure for a module.
56 hsmodName :: Maybe (Located ModuleName),
57 -- ^ @Nothing@: \"module X where\" is omitted (in which case the next
58 -- field is Nothing too)
59 hsmodExports :: Maybe [LIE name],
62 -- - @Nothing@: export list omitted, so export everything
64 -- - @Just []@: export /nothing/
66 -- - @Just [...]@: as you would expect...
68 hsmodImports :: [LImportDecl name],
69 -- ^ We snaffle interesting stuff out of the imported interfaces early
70 -- on, adding that info to TyDecls/etc; so this list is often empty,
72 hsmodDecls :: [LHsDecl name],
73 -- ^ Type, class, value, and interface signature decls
74 hsmodDeprecMessage :: Maybe WarningTxt,
75 -- ^ reason\/explanation for warning/deprecation of this module
76 hsmodHaddockModHeader :: Maybe LHsDocString
77 -- ^ Haddock module info and description, unparsed
78 } deriving (Data, Typeable)
80 data HsExtCore name -- Read from Foo.hcr
83 [TyClDecl name] -- Type declarations only; just as in Haskell source,
84 -- so that we can infer kinds etc
85 [IfaceBinding] -- And the bindings
90 instance Outputable Char where
93 instance (OutputableBndr name)
94 => Outputable (HsModule name) where
96 ppr (HsModule Nothing _ imports decls _ mbDoc)
97 = pp_mb mbDoc $$ pp_nonnull imports $$ pp_nonnull decls
99 ppr (HsModule (Just name) exports imports decls deprec mbDoc)
103 Nothing -> pp_header (ptext (sLit "where"))
106 nest 8 (fsep (punctuate comma (map ppr es))),
107 nest 4 (ptext (sLit ") where"))
113 pp_header rest = case deprec of
114 Nothing -> pp_modname <+> rest
115 Just d -> vcat [ pp_modname, ppr d, rest ]
117 pp_modname = ptext (sLit "module") <+> ppr name
119 pp_mb :: Outputable t => Maybe t -> SDoc
120 pp_mb (Just x) = ppr x
121 pp_mb Nothing = empty
123 pp_nonnull :: Outputable t => [t] -> SDoc
124 pp_nonnull [] = empty
125 pp_nonnull xs = vcat (map ppr xs)