43941695feef3d79b41e60c70b077e392280162f
[ghc-hetmet.git] / compiler / hsSyn / HsSyn.lhs
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 \begin{code}
12 {-# OPTIONS -w #-}
13 -- The above warning supression flag is a temporary kludge.
14 -- While working on this module you are encouraged to remove it and fix
15 -- any warnings in the module. See
16 --     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
17 -- for details
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         Fixity,
30
31         HsModule(..), HsExtCore(..),
32
33         HaddockModInfo(..),
34         emptyHaddockModInfo,
35 ) where
36
37 #include "HsVersions.h"
38
39 -- friends:
40 import HsDecls          
41 import HsBinds
42 import HsExpr
43 import HsImpExp
44 import HsLit
45 import HsPat
46 import HsTypes
47 import BasicTypes       ( Fixity, DeprecTxt )
48 import HsUtils
49 import HsDoc
50
51 -- others:
52 import IfaceSyn         ( IfaceBinding )
53 import Outputable
54 import SrcLoc           ( Located(..) )
55 import Module           ( Module, ModuleName )
56 \end{code}
57
58 All we actually declare here is the top-level structure for a module.
59 \begin{code}
60 data HsModule name
61   = HsModule
62         (Maybe (Located ModuleName))-- Nothing => "module X where" is omitted
63                                 --      (in which case the next field is Nothing too)
64         (Maybe [LIE name])      -- Export list; Nothing => export list omitted, so export everything
65                                 -- Just [] => export *nothing*
66                                 -- Just [...] => as you would expect...
67         [LImportDecl name]      -- We snaffle interesting stuff out of the
68                                 -- imported interfaces early on, adding that
69                                 -- info to TyDecls/etc; so this list is
70                                 -- often empty, downstream.
71         [LHsDecl name]          -- Type, class, value, and interface signature decls
72         (Maybe DeprecTxt)       -- reason/explanation for deprecation of this module
73         (HaddockModInfo name)   -- Haddock module info
74         (Maybe (HsDoc name))    -- Haddock module description
75
76 data HaddockModInfo name = HaddockModInfo { 
77         hmi_description :: Maybe (HsDoc name),
78         hmi_portability :: Maybe String,
79         hmi_stability   :: Maybe String,
80         hmi_maintainer  :: Maybe String
81 }
82
83 emptyHaddockModInfo :: HaddockModInfo a                                                  
84 emptyHaddockModInfo = HaddockModInfo {                                                  
85         hmi_description = Nothing,
86         hmi_portability = Nothing,
87         hmi_stability   = Nothing,
88         hmi_maintainer  = Nothing
89 }       
90
91 data HsExtCore name     -- Read from Foo.hcr
92   = HsExtCore
93         Module
94         [TyClDecl name] -- Type declarations only; just as in Haskell source,
95                         -- so that we can infer kinds etc
96         [IfaceBinding]  -- And the bindings
97 \end{code}
98
99
100 \begin{code}
101 instance Outputable Char where
102   ppr c = text [c]
103
104 instance (OutputableBndr name)
105         => Outputable (HsModule name) where
106
107     ppr (HsModule Nothing _ imports decls _ _ mbDoc)
108       = pp_mb mbDoc $$ pp_nonnull imports $$ pp_nonnull decls
109
110     ppr (HsModule (Just name) exports imports decls deprec _ mbDoc)
111       = vcat [
112             pp_mb mbDoc,
113             case exports of
114               Nothing -> pp_header (ptext SLIT("where"))
115               Just es -> vcat [
116                            pp_header lparen,
117                            nest 8 (fsep (punctuate comma (map ppr es))),
118                            nest 4 (ptext SLIT(") where"))
119                           ],
120             pp_nonnull imports,
121             pp_nonnull decls
122           ]
123       where
124         pp_header rest = case deprec of
125            Nothing -> pp_modname <+> rest
126            Just d -> vcat [ pp_modname, ppr d, rest ]
127
128         pp_modname = ptext SLIT("module") <+> ppr name
129
130 pp_mb (Just x) = ppr x 
131 pp_mb Nothing  = empty
132
133 pp_nonnull [] = empty
134 pp_nonnull xs = vcat (map ppr xs)
135 \end{code}