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