[project @ 2000-03-23 17:45:17 by simonpj]
[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 {-# SOURCE #-} DataCon ( DataCon )
20
21 import Var              ( Id, TyVar )
22 import CostCentre       ( CostCentre )
23 import Type             ( Type )
24 import Outputable
25 \end{code}
26
27 %************************************************************************
28 %*                                                                      *
29 \subsection{Public interfaces for Core printing (excluding instances)}
30 %*                                                                      *
31 %************************************************************************
32
33 \begin{code}
34 data PprEnv bndr
35   = PE  {
36         pSCC :: CostCentre -> SDoc,
37
38         pTyVarO :: TyVar -> SDoc,       -- to print tyvar occurrences
39         pTy     :: Type -> SDoc,        -- to print types
40
41         pBndr :: BindingSite -> bndr -> SDoc,   -- to print value binders
42         pOcc  :: Id -> SDoc             -- to print value occurrences
43    }
44 \end{code}
45
46 @BindingSite@ is used to tell the thing that prints binder what
47 language construct is binding the identifier.
48
49 \begin{code}
50 data BindingSite = LambdaBind | CaseBind | LetBind
51 \end{code}
52
53 \begin{code}
54 initPprEnv
55         :: Maybe (CostCentre -> SDoc)
56         -> Maybe (TyVar -> SDoc)
57         -> Maybe (Type -> SDoc)
58         -> Maybe (BindingSite -> bndr -> SDoc)
59         -> Maybe (Id -> SDoc)
60         -> PprEnv bndr
61
62 -- you can specify all the printers individually; if
63 -- you don't specify one, you get bottom
64
65 initPprEnv c tvo ty bndr occ
66   = PE (demaybe c)
67        (demaybe tvo)
68        (demaybe ty)
69        (demaybe bndr)
70        (demaybe occ)
71   where
72     demaybe Nothing  = bottom
73     demaybe (Just x) = x
74
75     bottom = panic "PprEnv.initPprEnv: unspecified printing function"
76 \end{code}
77