88bf2f35f707b39b827fc0f3141de3de9896f156
[ghc-hetmet.git] / ghc / compiler / prelude / PrelInfo.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[PrelInfo]{The @PrelInfo@ interface to the compiler's prelude knowledge}
5
6 \begin{code}
7 module PrelInfo (
8         module PrelNames,
9         module MkId,
10
11         wiredInNames,   -- Names of wired in things
12         wiredInThings,
13
14         
15         -- Primop RdrNames
16         eqH_Char_RDR,   ltH_Char_RDR,   eqH_Word_RDR,  ltH_Word_RDR, 
17         eqH_Addr_RDR,   ltH_Addr_RDR,   eqH_Float_RDR, ltH_Float_RDR, 
18         eqH_Double_RDR, ltH_Double_RDR, eqH_Int_RDR,   ltH_Int_RDR,
19         geH_RDR, leH_RDR, minusH_RDR, tagToEnumH_RDR, 
20
21         -- Random other things
22         maybeCharLikeCon, maybeIntLikeCon,
23
24         -- Class categories
25         isCcallishClass, isCreturnableClass, isNoDictClass, 
26         isNumericClass, isStandardClass
27
28     ) where
29
30 #include "HsVersions.h"
31
32 -- friends:
33 import PrelNames        -- Prelude module names
34
35 import PrimOp           ( PrimOp(..), allThePrimOps, primOpRdrName )
36 import DataCon          ( DataCon, dataConId, dataConWrapId )
37 import MkId             ( mkPrimOpId, wiredInIds )
38 import MkId             -- All of it, for re-export
39 import TysPrim          ( primTyCons )
40 import TysWiredIn       ( wiredInTyCons )
41 import HscTypes         ( TyThing(..) )
42
43 -- others:
44 import RdrName          ( RdrName )
45 import Name             ( Name, getName )
46 import TyCon            ( tyConDataConsIfAvailable, TyCon )
47 import Class            ( Class, classKey )
48 import Type             ( funTyCon )
49 import Bag
50 import BasicTypes       ( Boxity(..) )
51 import Util             ( isIn )
52 import Outputable       ( ppr, pprPanic )
53 \end{code}
54
55 %************************************************************************
56 %*                                                                      *
57 \subsection[builtinNameInfo]{Lookup built-in names}
58 %*                                                                      *
59 %************************************************************************
60
61 We have two ``builtin name funs,'' one to look up @TyCons@ and
62 @Classes@, the other to look up values.
63
64 \begin{code}
65 wiredInThings :: [TyThing]
66 wiredInThings
67   = concat
68     [           -- Wired in TyCons
69           map ATyCon ([funTyCon] ++ primTyCons ++ wiredInTyCons)
70
71                 -- Wired in Ids
72         , map AnId wiredInIds
73
74                 -- PrimOps
75         , map (AnId . mkPrimOpId) allThePrimOps
76     ]
77
78 wiredInNames :: [Name]
79 wiredInNames = [n | thing <- wiredInThings, n <- tyThingNames thing]
80
81 tyThingNames :: TyThing -> [Name]
82 tyThingNames (AClass cl) = pprPanic "tyThingNames" (ppr cl)     -- Not used
83 tyThingNames (AnId   id) = [getName id]
84 tyThingNames (ATyCon tc) 
85    = getName tc : [ getName n | dc <- tyConDataConsIfAvailable tc, 
86                                 n  <- [dataConId dc, dataConWrapId dc] ]
87                                                 -- Synonyms return empty list of constructors
88 \end{code}
89
90 We let a lot of "non-standard" values be visible, so that we can make
91 sense of them in interface pragmas. It's cool, though they all have
92 "non-standard" names, so they won't get past the parser in user code.
93
94
95 %************************************************************************
96 %*                                                                      *
97 \subsection{RdrNames for the primops}
98 %*                                                                      *
99 %************************************************************************
100
101 These can't be in PrelNames, because we get the RdrName from the PrimOp,
102 which is above PrelNames in the module hierarchy.
103
104 \begin{code}
105 eqH_Char_RDR    = primOpRdrName CharEqOp
106 ltH_Char_RDR    = primOpRdrName CharLtOp
107 eqH_Word_RDR    = primOpRdrName WordEqOp
108 ltH_Word_RDR    = primOpRdrName WordLtOp
109 eqH_Addr_RDR    = primOpRdrName AddrEqOp
110 ltH_Addr_RDR    = primOpRdrName AddrLtOp
111 eqH_Float_RDR   = primOpRdrName FloatEqOp
112 ltH_Float_RDR   = primOpRdrName FloatLtOp
113 eqH_Double_RDR  = primOpRdrName DoubleEqOp
114 ltH_Double_RDR  = primOpRdrName DoubleLtOp
115 eqH_Int_RDR     = primOpRdrName IntEqOp
116 ltH_Int_RDR     = primOpRdrName IntLtOp
117 geH_RDR         = primOpRdrName IntGeOp
118 leH_RDR         = primOpRdrName IntLeOp
119 minusH_RDR      = primOpRdrName IntSubOp
120
121 tagToEnumH_RDR  = primOpRdrName TagToEnumOp
122 \end{code}
123
124
125 %************************************************************************
126 %*                                                                      *
127 \subsection{Built-in keys}
128 %*                                                                      *
129 %************************************************************************
130
131 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
132
133 \begin{code}
134 maybeCharLikeCon, maybeIntLikeCon :: DataCon -> Bool
135 maybeCharLikeCon con = con `hasKey` charDataConKey
136 maybeIntLikeCon  con = con `hasKey` intDataConKey
137 \end{code}
138
139
140 %************************************************************************
141 %*                                                                      *
142 \subsection{Class predicates}
143 %*                                                                      *
144 %************************************************************************
145
146 \begin{code}
147 isCcallishClass, isCreturnableClass, isNoDictClass, 
148   isNumericClass, isStandardClass :: Class -> Bool
149
150 isNumericClass     clas = classKey clas `is_elem` numericClassKeys
151 isStandardClass    clas = classKey clas `is_elem` standardClassKeys
152 isCcallishClass    clas = classKey clas `is_elem` cCallishClassKeys
153 isCreturnableClass clas = classKey clas == cReturnableClassKey
154 isNoDictClass      clas = classKey clas `is_elem` noDictClassKeys
155 is_elem = isIn "is_X_Class"
156 \end{code}