Remove 'deriving Typeable' statements
[ghc.git] / compiler / hsSyn / HsSyn.hs
1 {-
2 (c) The University of Glasgow 2006
3 (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4
5 \section{Haskell abstract syntax definition}
6
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.
10 -}
11
12 {-# LANGUAGE DeriveDataTypeable #-}
13 {-# LANGUAGE StandaloneDeriving #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE UndecidableInstances #-} -- Note [Pass sensitive types]
16 -- in module PlaceHolder
17 {-# LANGUAGE ConstraintKinds #-}
18
19 module HsSyn (
20 module HsBinds,
21 module HsDecls,
22 module HsExpr,
23 module HsImpExp,
24 module HsLit,
25 module HsPat,
26 module HsTypes,
27 module HsUtils,
28 module HsDoc,
29 module PlaceHolder,
30 Fixity,
31
32 HsModule(..)
33 ) where
34
35 -- friends:
36 import HsDecls
37 import HsBinds
38 import HsExpr
39 import HsImpExp
40 import HsLit
41 import PlaceHolder
42 import HsPat
43 import HsTypes
44 import BasicTypes ( Fixity, WarningTxt )
45 import HsUtils
46 import HsDoc
47
48 -- others:
49 import OccName ( HasOccName )
50 import Outputable
51 import SrcLoc
52 import Module ( ModuleName )
53
54 -- libraries:
55 import Data.Data hiding ( Fixity )
56
57 -- | All we actually declare here is the top-level structure for a module.
58 data HsModule name
59 = HsModule {
60 hsmodName :: Maybe (Located ModuleName),
61 -- ^ @Nothing@: \"module X where\" is omitted (in which case the next
62 -- field is Nothing too)
63 hsmodExports :: Maybe (Located [LIE name]),
64 -- ^ Export list
65 --
66 -- - @Nothing@: export list omitted, so export everything
67 --
68 -- - @Just []@: export /nothing/
69 --
70 -- - @Just [...]@: as you would expect...
71 --
72 --
73 -- - 'ApiAnnotation.AnnKeywordId's : 'ApiAnnotation.AnnOpen'
74 -- ,'ApiAnnotation.AnnClose'
75
76 -- For details on above see note [Api annotations] in ApiAnnotation
77 hsmodImports :: [LImportDecl name],
78 -- ^ We snaffle interesting stuff out of the imported interfaces early
79 -- on, adding that info to TyDecls/etc; so this list is often empty,
80 -- downstream.
81 hsmodDecls :: [LHsDecl name],
82 -- ^ Type, class, value, and interface signature decls
83 hsmodDeprecMessage :: Maybe (Located WarningTxt),
84 -- ^ reason\/explanation for warning/deprecation of this module
85 --
86 -- - 'ApiAnnotation.AnnKeywordId's : 'ApiAnnotation.AnnOpen'
87 -- ,'ApiAnnotation.AnnClose'
88 --
89
90 -- For details on above see note [Api annotations] in ApiAnnotation
91 hsmodHaddockModHeader :: Maybe LHsDocString
92 -- ^ Haddock module info and description, unparsed
93 --
94 -- - 'ApiAnnotation.AnnKeywordId's : 'ApiAnnotation.AnnOpen'
95 -- ,'ApiAnnotation.AnnClose'
96
97 -- For details on above see note [Api annotations] in ApiAnnotation
98 }
99 -- ^ 'ApiAnnotation.AnnKeywordId's
100 --
101 -- - 'ApiAnnotation.AnnModule','ApiAnnotation.AnnWhere'
102 --
103 -- - 'ApiAnnotation.AnnOpen','ApiAnnotation.AnnSemi',
104 -- 'ApiAnnotation.AnnClose' for explicit braces and semi around
105 -- hsmodImports,hsmodDecls if this style is used.
106
107 -- For details on above see note [Api annotations] in ApiAnnotation
108 deriving instance (DataId name) => Data (HsModule name)
109
110 instance (OutputableBndr name, HasOccName name)
111 => Outputable (HsModule name) where
112
113 ppr (HsModule Nothing _ imports decls _ mbDoc)
114 = pp_mb mbDoc $$ pp_nonnull imports
115 $$ pp_nonnull decls
116
117 ppr (HsModule (Just name) exports imports decls deprec mbDoc)
118 = vcat [
119 pp_mb mbDoc,
120 case exports of
121 Nothing -> pp_header (text "where")
122 Just es -> vcat [
123 pp_header lparen,
124 nest 8 (fsep (punctuate comma (map ppr (unLoc es)))),
125 nest 4 (text ") where")
126 ],
127 pp_nonnull imports,
128 pp_nonnull decls
129 ]
130 where
131 pp_header rest = case deprec of
132 Nothing -> pp_modname <+> rest
133 Just d -> vcat [ pp_modname, ppr d, rest ]
134
135 pp_modname = text "module" <+> ppr name
136
137 pp_mb :: Outputable t => Maybe t -> SDoc
138 pp_mb (Just x) = ppr x
139 pp_mb Nothing = empty
140
141 pp_nonnull :: Outputable t => [t] -> SDoc
142 pp_nonnull [] = empty
143 pp_nonnull xs = vcat (map ppr xs)