| 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 -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 | |
|---|
| 21 | module 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: |
|---|
| 37 | import HsDecls |
|---|
| 38 | import HsBinds |
|---|
| 39 | import HsExpr |
|---|
| 40 | import HsImpExp |
|---|
| 41 | import HsLit |
|---|
| 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 IfaceSyn ( IfaceBinding ) |
|---|
| 51 | import Outputable |
|---|
| 52 | import SrcLoc |
|---|
| 53 | import Module ( Module, ModuleName ) |
|---|
| 54 | import FastString |
|---|
| 55 | |
|---|
| 56 | -- libraries: |
|---|
| 57 | import 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. |
|---|
| 62 | data 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 | |
|---|
| 88 | data 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} |
|---|
| 98 | instance Outputable Char where |
|---|
| 99 | ppr c = text [c] |
|---|
| 100 | |
|---|
| 101 | instance (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 | |
|---|
| 127 | pp_mb :: Outputable t => Maybe t -> SDoc |
|---|
| 128 | pp_mb (Just x) = ppr x |
|---|
| 129 | pp_mb Nothing = empty |
|---|
| 130 | |
|---|
| 131 | pp_nonnull :: Outputable t => [t] -> SDoc |
|---|
| 132 | pp_nonnull [] = empty |
|---|
| 133 | pp_nonnull xs = vcat (map ppr xs) |
|---|
| 134 | \end{code} |
|---|