[project @ 1998-12-02 13:17:09 by simonm]
[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         pCon, pBndr, pOcc, pSCC, 
14         pTy, pTyVarO
15     ) where
16
17 #include "HsVersions.h"
18
19 import {-# SOURCE #-} Const ( Con )
20
21 import Var              ( GenId, GenTyVar )
22 import CostCentre       ( CostCentre )
23 import Type             ( GenType )
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 flexi
35   = PE  {
36         pCon :: Con        -> SDoc,
37         pSCC :: CostCentre -> SDoc,
38
39         pTyVarO :: GenTyVar flexi -> SDoc,      -- to print tyvar occurrences
40         pTy     :: GenType flexi -> SDoc,       -- to print types
41
42         pBndr :: BindingSite -> bndr -> SDoc,   -- to print value binders
43         pOcc  :: GenId flexi -> SDoc            -- to print value occurrences
44    }
45 \end{code}
46
47 @BindingSite@ is used to tell the thing that prints binder what
48 language construct is binding the identifier.
49
50 \begin{code}
51 data BindingSite = LambdaBind | CaseBind | LetBind
52 \end{code}
53
54 \begin{code}
55 initPprEnv
56         :: Maybe (Con -> SDoc)
57         -> Maybe (CostCentre -> SDoc)
58         -> Maybe (GenTyVar flexi -> SDoc)
59         -> Maybe (GenType flexi -> SDoc)
60         -> Maybe (BindingSite -> bndr -> SDoc)
61         -> Maybe (GenId flexi -> SDoc)
62         -> PprEnv bndr flexi
63
64 -- you can specify all the printers individually; if
65 -- you don't specify one, you get bottom
66
67 initPprEnv p c tvo ty bndr occ
68   = PE (demaybe p)
69        (demaybe c)
70        (demaybe tvo)
71        (demaybe ty)
72        (demaybe bndr)
73        (demaybe occ)
74   where
75     demaybe Nothing  = bottom
76     demaybe (Just x) = x
77
78     bottom = panic "PprEnv.initPprEnv: unspecified printing function"
79 \end{code}
80