-import Name ( Name, OccName(..), getSrcLoc, occNameString,
- maybeWiredInTyConName, maybeWiredInIdName, pprSym
- )
-import PprStyle
-import Pretty
-import Unique ( pprUnique10{-, pprUnique ToDo:rm-} )
-import UniqFM
-import Util ( zipEqual, zipWithEqual, zipWith3Equal, zipLazy,
- panic, pprPanic{-, pprTrace ToDo:rm-}
- )
+Using the Located versions (eg. tcLookupLocatedGlobal) is preferred,
+unless you know that the SrcSpan in the monad is already set to the
+span of the Name.
+
+\begin{code}
+tcLookupLocatedGlobal :: Located Name -> TcM TyThing
+-- c.f. IfaceEnvEnv.tcIfaceGlobal
+tcLookupLocatedGlobal name
+ = addLocM tcLookupGlobal name
+
+tcLookupGlobal :: Name -> TcM TyThing
+-- The Name is almost always an ExternalName, but not always
+-- In GHCi, we may make command-line bindings (ghci> let x = True)
+-- that bind a GlobalId, but with an InternalName
+tcLookupGlobal name
+ = do { env <- getGblEnv
+
+ -- Try local envt
+ ; case lookupNameEnv (tcg_type_env env) name of {
+ Just thing -> return thing ;
+ Nothing -> do
+
+ -- Try global envt
+ { (eps,hpt) <- getEpsAndHpt
+ ; case lookupType hpt (eps_PTE eps) name of {
+ Just thing -> return thing ;
+ Nothing -> do
+
+ -- Should it have been in the local envt?
+ { let mod = nameModule name
+ ; if mod == tcg_mod env || mod == thFAKE then
+ notFound name -- It should be local, so panic
+ -- The thFAKE possibility is because it
+ -- might be in a declaration bracket
+ else
+ tcImportDecl name -- Go find it in an interface
+ }}}}}
+
+tcLookupGlobalId :: Name -> TcM Id
+-- Never used for Haskell-source DataCons, hence no ADataCon case
+tcLookupGlobalId name
+ = tcLookupGlobal name `thenM` \ thing ->
+ return (tyThingId thing)
+
+tcLookupDataCon :: Name -> TcM DataCon
+tcLookupDataCon con_name
+ = tcLookupGlobal con_name `thenM` \ thing ->
+ return (tyThingDataCon thing)
+
+tcLookupClass :: Name -> TcM Class
+tcLookupClass name
+ = tcLookupGlobal name `thenM` \ thing ->
+ case thing of
+ AClass cls -> return cls
+ other -> wrongThingErr "class" (AGlobal thing) name
+
+tcLookupTyCon :: Name -> TcM TyCon
+tcLookupTyCon name
+ = tcLookupGlobal name `thenM` \ thing ->
+ case thing of
+ ATyCon tc -> return tc
+ other -> wrongThingErr "type constructor" (AGlobal thing) name
+
+tcLookupLocatedGlobalId :: Located Name -> TcM Id
+tcLookupLocatedGlobalId = addLocM tcLookupId
+
+tcLookupLocatedClass :: Located Name -> TcM Class
+tcLookupLocatedClass = addLocM tcLookupClass
+
+tcLookupLocatedTyCon :: Located Name -> TcM TyCon
+tcLookupLocatedTyCon = addLocM tcLookupTyCon