[project @ 2002-03-18 09:44:46 by simonmar]
[ghc-hetmet.git] / ghc / compiler / basicTypes / PprEnv.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1996-1998
3 %
4 \section[PprEnv]{The @PprEnv@ type}
5
6 \begin{code}
7 module PprEnv (
8         PprEnv,         -- 
9         BindingSite(..),
10
11         initPprEnv,
12
13         pBndr, pOcc, pSCC, 
14         pTy, pTyVarO
15     ) where
16
17 #include "HsVersions.h"
18
19 import Var              ( Id, TyVar )
20 import CostCentre       ( CostCentre )
21 import Type             ( Type )
22 import Outputable
23 \end{code}
24
25 %************************************************************************
26 %*                                                                      *
27 \subsection{Public interfaces for Core printing (excluding instances)}
28 %*                                                                      *
29 %************************************************************************
30
31 \begin{code}
32 data PprEnv bndr
33   = PE  {
34         pSCC :: CostCentre -> SDoc,
35
36         pTyVarO :: TyVar -> SDoc,       -- to print tyvar occurrences
37         pTy     :: Type -> SDoc,        -- to print types
38
39         pBndr :: BindingSite -> bndr -> SDoc,   -- to print value binders
40         pOcc  :: Id -> SDoc             -- to print value occurrences
41    }
42 \end{code}
43
44 @BindingSite@ is used to tell the thing that prints binder what
45 language construct is binding the identifier.
46
47 \begin{code}
48 data BindingSite = LambdaBind | CaseBind | LetBind
49 \end{code}
50
51 \begin{code}
52 initPprEnv
53         :: Maybe (CostCentre -> SDoc)
54         -> Maybe (TyVar -> SDoc)
55         -> Maybe (Type -> SDoc)
56         -> Maybe (BindingSite -> bndr -> SDoc)
57         -> Maybe (Id -> SDoc)
58         -> PprEnv bndr
59
60 -- you can specify all the printers individually; if
61 -- you don't specify one, you get bottom
62
63 initPprEnv c tvo ty bndr occ
64   = PE (demaybe c)
65        (demaybe tvo)
66        (demaybe ty)
67        (demaybe bndr)
68        (demaybe occ)
69   where
70     demaybe Nothing  = bottom
71     demaybe (Just x) = x
72
73     bottom = panic "PprEnv.initPprEnv: unspecified printing function"
74 \end{code}
75