-%*********************************************************
-%* *
-\subsection{Looking up names}
-%* *
-%*********************************************************
-
-Looking up a name in the RnEnv.
-
-\begin{code}
-lookupBndrRn rdr_name
- = getNameEnvs `thenRn` \ (global_env, local_env) ->
-
- -- Try local env
- case lookupRdrEnv local_env rdr_name of {
- Just name -> returnRn name ;
- Nothing ->
-
- getModeRn `thenRn` \ mode ->
- case mode of
- InterfaceMode -> -- Look in the global name cache
- mkImportedGlobalFromRdrName rdr_name
-
- SourceMode -> -- Source mode, so look up a *qualified* version
- -- of the name, so that we get the right one even
- -- if there are many with the same occ name
- -- There must *be* a binding
- getModuleRn `thenRn` \ mod ->
- case lookupRdrEnv global_env (qualifyRdrName mod rdr_name) of
- Just (name:rest) -> ASSERT( null rest )
- returnRn name
- Nothing -> pprPanic "lookupBndrRn" (ppr mod <+> ppr rdr_name)
- }
-
--- Just like lookupRn except that we record the occurrence too
--- Perhaps surprisingly, even wired-in names are recorded.
--- Why? So that we know which wired-in names are referred to when
--- deciding which instance declarations to import.
-lookupOccRn :: RdrName -> RnMS Name
-lookupOccRn rdr_name
- = getNameEnvs `thenRn` \ (global_env, local_env) ->
- lookup_occ global_env local_env rdr_name
-
--- lookupGlobalOccRn is like lookupOccRn, except that it looks in the global
--- environment. It's used only for
--- record field names
--- class op names in class and instance decls
-lookupGlobalOccRn :: RdrName -> RnMS Name
-lookupGlobalOccRn rdr_name
- = getNameEnvs `thenRn` \ (global_env, local_env) ->
- lookup_global_occ global_env rdr_name
-
--- Look in both local and global env
-lookup_occ global_env local_env rdr_name
- = case lookupRdrEnv local_env rdr_name of
- Just name -> returnRn name
- Nothing -> lookup_global_occ global_env rdr_name
-
--- Look in global env only
-lookup_global_occ global_env rdr_name
- = case lookupRdrEnv global_env rdr_name of
- Just [name] -> returnRn name
- Just stuff@(name:_) -> addNameClashErrRn rdr_name stuff `thenRn_`
- returnRn name
- Nothing -> getModeRn `thenRn` \ mode ->
- case mode of
- -- Not found when processing source code; so fail
- SourceMode -> failWithRn (mkUnboundName rdr_name)
- (unknownNameErr rdr_name)
-
- -- Not found when processing an imported declaration,
- -- so we create a new name for the purpose
- InterfaceMode -> mkImportedGlobalFromRdrName rdr_name
-\end{code}
-%
-@lookupImplicitOccRn@ takes an RdrName representing an {\em original} name,
-and adds it to the occurrence pool so that it'll be loaded later.
-This is used when language constructs
-(such as monad comprehensions, overloaded literals, or deriving clauses)
-require some stuff to be loaded that isn't explicitly mentioned in the code.
-
-This doesn't apply in interface mode, where everything is explicit,
-but we don't check for this case:
-it does no harm to record an ``extra'' occurrence
-and @lookupImplicitOccRn@ isn't used much in interface mode
-(it's only the @Nothing@ clause of @rnDerivs@ that calls it at all I think).
-
- \fbox{{\em Jan 98: this comment is wrong: @rnHsType@ uses it quite a bit.}}
-
-For List and Tuple types it's important to get the correct
-@isLocallyDefined@ flag, which is used in turn when deciding
-whether there are any instance decls in this module are ``special''.
-The name cache should have the correct provenance, though.
-
-\begin{code}
-lookupImplicitOccRn :: RdrName -> RnM d Name
-lookupImplicitOccRn rdr_name = mkImportedGlobalFromRdrName rdr_name
-\end{code}
-
-@unQualInScope@ returns a function that takes a @Name@ and tells whether
-its unqualified name is in scope. This is put as a boolean flag in
-the @Name@'s provenance to guide whether or not to print the name qualified
-in error messages.
-
-\begin{code}
-unQualInScope :: GlobalRdrEnv -> Name -> Bool
-unQualInScope env
- = lookup
- where
- lookup name = case lookupRdrEnv env (mkRdrUnqual (nameOccName name)) of
- Just [name'] -> name == name'
- other -> False
-\end{code}
-