[project @ 2003-09-16 13:03:37 by simonmar]
[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         wiredInThingEnv,
12         ghcPrimExports,
13         knownKeyNames,
14         
15         -- Random other things
16         maybeCharLikeCon, maybeIntLikeCon,
17
18         -- Class categories
19         isNoDictClass, isNumericClass, isStandardClass
20
21     ) where
22
23 #include "HsVersions.h"
24
25 import PrelNames        ( basicKnownKeyNames, 
26                           hasKey, charDataConKey, intDataConKey,
27                           numericClassKeys, standardClassKeys,
28                           noDictClassKeys )
29 #ifdef GHCI
30 import DsMeta           ( templateHaskellNames )
31 import NameSet          ( nameSetToList )
32 #endif
33
34 import PrimOp           ( allThePrimOps, primOpOcc )
35 import DataCon          ( DataCon )
36 import Id               ( idName )
37 import MkId             ( mkPrimOpId, wiredInIds )
38 import MkId             -- All of it, for re-export
39 import Name             ( Name, nameOccName, NamedThing(..) )
40 import RdrName          ( mkRdrUnqual )
41 import HsSyn            ( HsTyVarBndr(..) )
42 import OccName          ( mkVarOcc )
43 import TysPrim          ( primTyCons )
44 import TysWiredIn       ( wiredInTyCons )
45 import HscTypes         ( TyThing(..), implicitTyThings, TypeEnv, mkTypeEnv,
46                           GenAvailInfo(..), RdrAvailInfo )
47 import Class            ( Class, classKey, className )
48 import Type             ( funTyCon, openTypeKind, liftedTypeKind )
49 import TyCon            ( tyConName )
50 import Util             ( isIn )
51 \end{code}
52
53 %************************************************************************
54 %*                                                                      *
55 \subsection[builtinNameInfo]{Lookup built-in names}
56 %*                                                                      *
57 %************************************************************************
58
59 We have two ``builtin name funs,'' one to look up @TyCons@ and
60 @Classes@, the other to look up values.
61
62 \begin{code}
63 wiredInThings :: [TyThing]
64 wiredInThings
65   = concat
66     [           -- Wired in TyCons and their implicit Ids
67           tycon_things
68         , implicitTyThings tycon_things
69
70                 -- Wired in Ids
71         , map AnId wiredInIds
72
73                 -- PrimOps
74         , map (AnId . mkPrimOpId) allThePrimOps
75     ]
76   where
77     tycon_things = map ATyCon ([funTyCon] ++ primTyCons ++ wiredInTyCons)
78
79 wiredInThingEnv :: TypeEnv
80 wiredInThingEnv = mkTypeEnv wiredInThings
81
82 knownKeyNames :: [Name]
83 knownKeyNames 
84   = map getName wiredInThings 
85     ++ basicKnownKeyNames
86 #ifdef GHCI
87     ++ nameSetToList templateHaskellNames
88 #endif
89 \end{code}
90
91 We let a lot of "non-standard" values be visible, so that we can make
92 sense of them in interface pragmas. It's cool, though they all have
93 "non-standard" names, so they won't get past the parser in user code.
94
95 %************************************************************************
96 %*                                                                      *
97 \subsection{Export lists for pseudo-modules (GHC.Prim)}
98 %*                                                                      *
99 %************************************************************************
100
101 GHC.Prim "exports" all the primops and primitive types, some 
102 wired-in Ids.
103
104 \begin{code}
105 ghcPrimExports :: [RdrAvailInfo]
106  = map (Avail . nameOccName . idName) ghcPrimIds ++
107    map (Avail . primOpOcc) allThePrimOps ++
108    [ AvailTC occ [occ] |
109      n <- funTyCon : primTyCons, let occ = nameOccName (tyConName n) 
110    ]
111
112 alpha = mkRdrUnqual (mkVarOcc FSLIT("a"))
113 openAlpha = IfaceTyVar alpha openTypeKind
114 liftedAlpha = IfaceTyVar alpha liftedTypeKind
115 \end{code}
116
117
118 %************************************************************************
119 %*                                                                      *
120 \subsection{Built-in keys}
121 %*                                                                      *
122 %************************************************************************
123
124 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
125
126 \begin{code}
127 maybeCharLikeCon, maybeIntLikeCon :: DataCon -> Bool
128 maybeCharLikeCon con = con `hasKey` charDataConKey
129 maybeIntLikeCon  con = con `hasKey` intDataConKey
130 \end{code}
131
132
133 %************************************************************************
134 %*                                                                      *
135 \subsection{Class predicates}
136 %*                                                                      *
137 %************************************************************************
138
139 \begin{code}
140 isNoDictClass, isNumericClass, isStandardClass :: Class -> Bool
141
142 isNumericClass     clas = classKey clas `is_elem` numericClassKeys
143 isStandardClass    clas = classKey clas `is_elem` standardClassKeys
144 isNoDictClass      clas = classKey clas `is_elem` noDictClassKeys
145 is_elem = isIn "is_X_Class"
146 \end{code}