root/compiler/hsSyn/HsSyn.lhs

Revision 00448643b9ac5ae0be89a31fa48d41ff66181d7d, 3.6 KB (checked in by Iavor S. Diatchki <iavor.diatchki@…>, 2 months ago)

Fix pretty-printing of type operators in imports/exports.

When we see a type operator in an import or an export, we tag it
with the keyword 'type' so that it is not confused with value level
operators with the same name.

  • Property mode set to 100644
Line 
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
7This module glues together the pieces of the Haskell abstract syntax,
8which is declared in the various \tr{Hs*} modules.  This module,
9therefore, is almost nothing but re-exporting.
10
11\begin{code}
12{-# OPTIONS -fno-warn-tabs #-}
13-- The above warning supression flag is a temporary kludge.
14-- While working on this module you are encouraged to remove it and
15-- detab the module (please do the detabbing in a separate patch). See
16--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
17-- for details
18
19{-# LANGUAGE DeriveDataTypeable #-}
20
21module HsSyn (
22        module HsBinds,
23        module HsDecls,
24        module HsExpr,
25        module HsImpExp,
26        module HsLit,
27        module HsPat,
28        module HsTypes,
29        module HsUtils,
30        module HsDoc,
31        Fixity,
32
33        HsModule(..), HsExtCore(..),
34) where
35
36-- friends:
37import HsDecls         
38import HsBinds
39import HsExpr
40import HsImpExp
41import HsLit
42import HsPat
43import HsTypes
44import BasicTypes       ( Fixity, WarningTxt )
45import HsUtils
46import HsDoc
47
48-- others:
49import OccName          ( HasOccName )
50import IfaceSyn         ( IfaceBinding )
51import Outputable
52import SrcLoc
53import Module           ( Module, ModuleName )
54import FastString
55
56-- libraries:
57import Data.Data hiding ( Fixity )
58\end{code}
59
60\begin{code}
61-- | All we actually declare here is the top-level structure for a module.
62data HsModule name
63  = HsModule {
64      hsmodName :: Maybe (Located ModuleName),
65        -- ^ @Nothing@: \"module X where\" is omitted (in which case the next
66        --     field is Nothing too)
67      hsmodExports :: Maybe [LIE name],
68        -- ^ Export list
69        --
70        --  - @Nothing@: export list omitted, so export everything
71        --
72        --  - @Just []@: export /nothing/
73        --
74        --  - @Just [...]@: as you would expect...
75        --
76      hsmodImports :: [LImportDecl name],
77        -- ^ We snaffle interesting stuff out of the imported interfaces early
78        -- on, adding that info to TyDecls/etc; so this list is often empty,
79        -- downstream.
80      hsmodDecls :: [LHsDecl name],
81        -- ^ Type, class, value, and interface signature decls
82      hsmodDeprecMessage :: Maybe WarningTxt,
83        -- ^ reason\/explanation for warning/deprecation of this module
84      hsmodHaddockModHeader :: Maybe LHsDocString
85        -- ^ Haddock module info and description, unparsed
86   } deriving (Data, Typeable)
87
88data HsExtCore name     -- Read from Foo.hcr
89  = HsExtCore
90        Module
91        [TyClDecl name] -- Type declarations only; just as in Haskell source,
92                        -- so that we can infer kinds etc
93        [IfaceBinding]  -- And the bindings
94\end{code}
95
96
97\begin{code}
98instance Outputable Char where
99  ppr c = text [c]
100
101instance (OutputableBndr name, HasOccName name)
102        => Outputable (HsModule name) where
103
104    ppr (HsModule Nothing _ imports decls _ mbDoc)
105      = pp_mb mbDoc $$ pp_nonnull imports $$ pp_nonnull decls
106
107    ppr (HsModule (Just name) exports imports decls deprec mbDoc)
108      = vcat [
109            pp_mb mbDoc,
110            case exports of
111              Nothing -> pp_header (ptext (sLit "where"))
112              Just es -> vcat [
113                           pp_header lparen,
114                           nest 8 (fsep (punctuate comma (map ppr es))),
115                           nest 4 (ptext (sLit ") where"))
116                          ],
117            pp_nonnull imports,
118            pp_nonnull decls
119          ]
120      where
121        pp_header rest = case deprec of
122           Nothing -> pp_modname <+> rest
123           Just d -> vcat [ pp_modname, ppr d, rest ]
124
125        pp_modname = ptext (sLit "module") <+> ppr name
126
127pp_mb :: Outputable t => Maybe t -> SDoc
128pp_mb (Just x) = ppr x
129pp_mb Nothing  = empty
130
131pp_nonnull :: Outputable t => [t] -> SDoc
132pp_nonnull [] = empty
133pp_nonnull xs = vcat (map ppr xs)
134\end{code}
Note: See TracBrowser for help on using the browser.