-
-
--- Yuk!
-ifaceFlavour name = case getNameProvenance name of
- NonLocalDef _ hif _ -> hif
- other -> HiFile -- Shouldn't happen
-\end{code}
-
-
-%*********************************************************
-%* *
-\subsection{Looking up names}
-%* *
-%*********************************************************
-
-Looking up a name in the RnEnv.
-
-\begin{code}
-lookupRn :: RdrName
- -> Maybe Name -- Result of environment lookup
- -> RnMS s Name
-
-lookupRn rdr_name (Just name)
- = -- Found the name in the envt
- returnRn name -- In interface mode the only things in
- -- the environment are things in local (nested) scopes
-
-lookupRn rdr_name Nothing
- = -- We didn't find the name in the environment
- getModeRn `thenRn` \ mode ->
- case mode of {
- SourceMode -> failWithRn (mkUnboundName rdr_name)
- (unknownNameErr rdr_name) ;
- -- Souurce mode; lookup failure is an error
-
- InterfaceMode _ _ ->
-
-
- ----------------------------------------------------
- -- OK, so we're in interface mode
- -- An Unqual is allowed; interface files contain
- -- unqualified names for locally-defined things, such as
- -- constructors of a data type.
- -- So, qualify the unqualified name with the
- -- module of the interface file, and try again
- case rdr_name of
- Unqual occ -> getModuleRn `thenRn` \ mod ->
- newImportedGlobalName mod occ HiFile
- Qual mod occ hif -> newImportedGlobalName mod occ hif
-
- }
-
-lookupBndrRn rdr_name
- = lookupNameRn rdr_name `thenRn` \ maybe_name ->
- lookupRn rdr_name maybe_name `thenRn` \ name ->
-
- if isLocalName name then
- returnRn name
- else
-
- ----------------------------------------------------
- -- OK, so we're at the binding site of a top-level defn
- -- Check to see whether its an imported decl
- getModeRn `thenRn` \ mode ->
- case mode of {
- SourceMode -> returnRn name ;
-
- InterfaceMode _ print_unqual_fn ->
-
- ----------------------------------------------------
- -- OK, the binding site of an *imported* defn
- -- so we can make the provenance more informative
- getSrcLocRn `thenRn` \ src_loc ->
- let
- name' = case getNameProvenance name of
- NonLocalDef _ hif _ -> setNameProvenance name
- (NonLocalDef src_loc hif (print_unqual_fn name'))
- other -> name
- in
- returnRn 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 s Name
-lookupOccRn rdr_name
- = lookupNameRn rdr_name `thenRn` \ maybe_name ->
- lookupRn rdr_name maybe_name `thenRn` \ name ->
- let
- name' = mungePrintUnqual rdr_name name
- in
- addOccurrenceName name'
-
--- lookupGlobalOccRn is like lookupOccRn, except that it looks in the global
--- environment only. It's used for record field names only.
-lookupGlobalOccRn :: RdrName -> RnMS s Name
-lookupGlobalOccRn rdr_name
- = lookupGlobalNameRn rdr_name `thenRn` \ maybe_name ->
- lookupRn rdr_name maybe_name `thenRn` \ name ->
- let
- name' = mungePrintUnqual rdr_name name
- in
- addOccurrenceName name'
-
--- mungePrintUnqual is used to make *imported* *occurrences* print unqualified
--- if they were mentioned unqualified in the source code.
--- This improves error messages from the type checker.
--- NB: the binding site is treated differently; see lookupBndrRn
--- After the type checker all occurrences are replaced by the one
--- at the binding site.
-mungePrintUnqual (Qual _ _ _) name = name
-mungePrintUnqual (Unqual _) name = case new_prov of
- Nothing -> name
- Just prov' -> setNameProvenance name prov'
- where
- new_prov = case getNameProvenance name of
- NonLocalDef loc hif False -> Just (NonLocalDef loc hif True)
- other -> Nothing
-
--- lookupImplicitOccRn takes an RdrName representing an *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).
--- [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.
-
-lookupImplicitOccRn :: RdrName -> RnMS s Name
-lookupImplicitOccRn (Qual mod occ hif)
- = newImportedGlobalName mod occ hif `thenRn` \ name ->
- addOccurrenceName name
-
-addImplicitOccRn :: Name -> RnMS s Name
-addImplicitOccRn name = addOccurrenceName name
-
-addImplicitOccsRn :: [Name] -> RnMS s ()
-addImplicitOccsRn names = addOccurrenceNames names
-
-listType_RDR = qual (modAndOcc listType_name)
-tupleType_RDR n = qual (modAndOcc (tupleType_name n))
-
-charType_name = getName charTyCon
-listType_name = getName listTyCon
-tupleType_name n = getName (tupleTyCon n)
-\end{code}
-
-\begin{code}
-lookupFixity :: RdrName -> RnMS s Fixity
-lookupFixity rdr_name
- = getFixityEnv `thenRn` \ fixity_env ->
- returnRn (lookupFixityEnv fixity_env rdr_name)