[project @ 1997-07-05 03:02:04 by sof]
[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 #include "HsVersions.h"
8
9 module PprEnv (
10         PprEnv{-abstract-},
11
12         initPprEnv,
13
14         pCon, pLit, pMajBndr, pMinBndr, pOcc, pPrim, pSCC, pStyle,
15         pTy, pTyVarB, pTyVarO, pUVar, pUse
16         
17     ) where
18
19 IMP_Ubiq(){-uitous-}
20
21 import Pretty           ( Doc )
22 import Outputable
23 import Unique           ( Unique )
24 import UniqFM           ( emptyUFM, UniqFM )
25 import Util             ( panic )
26 #if __GLASGOW_HASKELL__ >= 202
27 import {-# SOURCE #-}   Type  ( GenType )
28 import {-# SOURCE #-}   TyVar ( TyVar   )
29 import {-# SOURCE #-}   Id ( Id )
30 import Outputable       ( PprStyle )
31 import Literal          ( Literal )
32 import Usage            ( GenUsage, SYN_IE(Usage) )
33 import {-# SOURCE #-}   PrimOp (PrimOp)
34 import {-# SOURCE #-}   CostCentre ( CostCentre )
35 #endif
36
37 \end{code}
38
39 For tyvars and uvars, we {\em do} normally use these homogenized
40 names; for values, we {\em don't}.  In printing interfaces, though,
41 we use homogenized value names, so that interfaces don't wobble
42 uncontrollably from changing Unique-based names.
43
44 \begin{code}
45 data PprEnv tyvar uvar bndr occ
46   = PE  PprStyle                -- stored for safe keeping
47
48         (Literal    -> Doc)     -- Doing these this way saves
49         (Id    -> Doc)  -- carrying around a PprStyle
50         (PrimOp     -> Doc)
51         (CostCentre -> Doc)
52
53         (tyvar -> Doc)  -- to print tyvar binders
54         (tyvar -> Doc)  -- to print tyvar occurrences
55
56         (uvar -> Doc)   -- to print usage vars
57
58         (bndr -> Doc)   -- to print "major" val_bdrs
59         (bndr -> Doc)   -- to print "minor" val_bdrs
60         (occ  -> Doc)   -- to print bindees
61
62         (GenType tyvar uvar -> Doc)
63         (GenUsage uvar -> Doc)
64 \end{code}
65
66 \begin{code}
67 initPprEnv
68         :: PprStyle
69         -> Maybe (Literal -> Doc)
70         -> Maybe (Id -> Doc)
71         -> Maybe (PrimOp  -> Doc)
72         -> Maybe (CostCentre -> Doc)
73         -> Maybe (tyvar -> Doc)
74         -> Maybe (tyvar -> Doc)
75         -> Maybe (uvar -> Doc)
76         -> Maybe (bndr -> Doc)
77         -> Maybe (bndr -> Doc)
78         -> Maybe (occ -> Doc)
79         -> Maybe (GenType tyvar uvar -> Doc)
80         -> Maybe (GenUsage uvar -> Doc)
81         -> PprEnv tyvar uvar bndr occ
82
83 -- you can specify all the printers individually; if
84 -- you don't specify one, you get bottom
85
86 initPprEnv sty l d p c tvb tvo uv maj_bndr min_bndr occ ty use
87   = PE sty
88        (demaybe l)
89        (demaybe d)
90        (demaybe p)
91        (demaybe c)
92        (demaybe tvb)
93        (demaybe tvo)
94        (demaybe uv)
95        (demaybe maj_bndr)
96        (demaybe min_bndr)
97        (demaybe occ)
98        (demaybe ty)
99        (demaybe use)
100   where
101     demaybe Nothing  = bottom
102     demaybe (Just x) = x
103
104     bottom = panic "PprEnv.initPprEnv: unspecified printing function"
105
106 {-
107 initPprEnv sty pmaj pmin pocc
108   = PE  (ppr sty)   -- for a Literal
109         (ppr sty)   -- for a DataCon
110         (ppr sty)   -- for a PrimOp
111         (\ cc -> text (showCostCentre sty True cc)) -- CostCentre
112
113         (ppr sty)   -- for a tyvar
114         (ppr sty)   -- for a usage var
115
116         pmaj pmin pocc -- for GenIds in various guises
117
118         (ppr sty)   -- for a Type
119         (ppr sty)   -- for a Usage
120 -}
121 \end{code}
122
123 \begin{code}
124 pStyle   (PE s  _  _  _  _  _  _  _  _  _  _  _  _) = s
125 pLit     (PE _ pp  _  _  _  _  _  _  _  _  _  _  _) = pp
126 pCon     (PE _  _ pp  _  _  _  _  _  _  _  _  _  _) = pp
127 pPrim    (PE _  _  _ pp  _  _  _  _  _  _  _  _  _) = pp
128 pSCC     (PE _  _  _  _ pp  _  _  _  _  _  _  _  _) = pp
129                                                  
130 pTyVarB  (PE _  _  _  _  _  pp _  _  _  _  _  _  _) = pp
131 pTyVarO  (PE _  _  _  _  _  _  pp _  _  _  _  _  _) = pp
132 pUVar    (PE _  _  _  _  _  _  _  pp _  _  _  _  _) = pp
133                                                  
134 pMajBndr (PE _  _  _  _  _  _  _  _ pp  _  _  _  _) = pp
135 pMinBndr (PE _  _  _  _  _  _  _  _  _ pp  _  _  _) = pp
136 pOcc     (PE _  _  _  _  _  _  _  _  _  _ pp  _  _) = pp
137                                  
138 pTy      (PE _  _  _  _  _  _  _  _  _  _  _ pp  _) = pp
139 pUse     (PE _  _  _  _  _  _  _  _  _  _  _  _ pp) = pp
140 \end{code}