6e07e395c83f444b83b17b72db8c5f59cc82f9e6
[ghc-hetmet.git] / ghc / compiler / basicTypes / PprEnv.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1996
3 %
4 \section[PprEnv]{The @PprEnv@ type}
5
6 \begin{code}
7 module PprEnv (
8         PprEnv{-abstract-}, 
9         BindingSite(..),
10
11         initPprEnv,
12
13         pCon, pLit, pValBndr, pOcc, pPrim, pSCC, 
14         pTy, pTyVarB, pTyVarO
15         
16     ) where
17
18 #include "HsVersions.h"
19
20 import {-# SOURCE #-} Id ( Id )
21 import {-# SOURCE #-} PrimOp ( PrimOp )
22 import {-# SOURCE #-} CostCentre ( CostCentre )
23
24 import Type             ( GenType )
25 import TyVar            ( GenTyVar   )
26 import Literal          ( Literal )
27 import Outputable
28 import Unique           ( Unique )
29 import UniqFM           ( emptyUFM, UniqFM )
30 \end{code}
31
32 %************************************************************************
33 %*                                                                      *
34 \subsection{Public interfaces for Core printing (excluding instances)}
35 %*                                                                      *
36 %************************************************************************
37
38 \begin{code}
39 data PprEnv flexi bndr occ
40   = PE  (Literal    -> SDoc)
41         (Id         -> SDoc)
42         (PrimOp     -> SDoc)
43         (CostCentre -> SDoc)
44
45         (GenTyVar flexi -> SDoc)        -- to print tyvar binders
46         (GenTyVar flexi -> SDoc)        -- to print tyvar occurrences
47         (GenType flexi -> SDoc)         -- to print types
48
49         (BindingSite -> bndr -> SDoc)   -- to print val_bdrs
50         (occ                 -> SDoc)   -- to print bindees
51
52 \end{code}
53
54 @BindingSite@ is used to tell the thing that prints binder what
55 language construct is binding the identifier.
56
57 \begin{code}
58 data BindingSite = LambdaBind | CaseBind | LetBind
59 \end{code}
60
61 \begin{code}
62 initPprEnv
63         :: Maybe (Literal -> SDoc)
64         -> Maybe (Id -> SDoc)
65         -> Maybe (PrimOp  -> SDoc)
66         -> Maybe (CostCentre -> SDoc)
67         -> Maybe (GenTyVar flexi -> SDoc)
68         -> Maybe (GenTyVar flexi -> SDoc)
69         -> Maybe (GenType flexi -> SDoc)
70         -> Maybe (BindingSite -> bndr -> SDoc)
71         -> Maybe (occ -> SDoc)
72         -> PprEnv flexi bndr occ
73
74 -- you can specify all the printers individually; if
75 -- you don't specify one, you get bottom
76
77 initPprEnv l d p c tvb tvo ty val_bndr occ
78   = PE (demaybe l)
79        (demaybe d)
80        (demaybe p)
81        (demaybe c)
82        (demaybe tvb)
83        (demaybe tvo)
84        (demaybe ty)
85        (demaybe val_bndr)
86        (demaybe occ)
87   where
88     demaybe Nothing  = bottom
89     demaybe (Just x) = x
90
91     bottom = panic "PprEnv.initPprEnv: unspecified printing function"
92 \end{code}
93
94 \begin{code}
95 pLit     (PE pp  _  _  _  _  _   _  _  _) = pp
96 pCon     (PE  _ pp  _  _  _  _   _  _  _) = pp
97 pPrim    (PE  _  _ pp  _  _  _   _  _  _) = pp
98 pSCC     (PE  _  _  _ pp  _  _   _  _  _) = pp
99                                     
100 pTyVarB  (PE  _  _  _  _  pp _   _  _  _) = pp
101 pTyVarO  (PE  _  _  _  _  _  pp  _  _  _) = pp
102 pTy      (PE  _  _  _  _  _  _   pp _  _) = pp
103                                     
104 pValBndr (PE  _  _  _  _  _  _   _ pp  _) = pp
105 pOcc     (PE  _  _  _  _  _  _   _ _  pp) = pp
106 \end{code}