import CmdLineOpts ( opt_NoPruneDecls, opt_IgnoreIfacePragmas )
import HsSyn ( HsDecl(..), TyClDecl(..), InstDecl(..), IfaceSig(..),
HsType(..), ConDecl(..), IE(..), ConDetails(..), Sig(..),
+ ForeignDecl(..), ForKind(..), isDynamic,
FixitySig(..), RuleDecl(..),
isClassOpSig
)
extractHsTyRdrNames
)
import RnEnv ( mkImportedGlobalName, newImportedBinder, mkImportedGlobalFromRdrName,
- lookupOccRn,
+ lookupOccRn, lookupImplicitOccRn,
pprAvail,
availName, availNames, addAvailToNameSet,
FreeVars, emptyFVs
returnRn (Just (Avail var_name))
getDeclBinders new_name (FixD _) = returnRn Nothing
-getDeclBinders new_name (ForD _) = returnRn Nothing
+
+ -- foreign declarations
+getDeclBinders new_name (ForD (ForeignDecl nm kind _ dyn _ loc))
+ | binds_haskell_name kind dyn
+ = new_name nm loc `thenRn` \ name ->
+ returnRn (Just (Avail name))
+
+ | otherwise -- a foreign export
+ = lookupImplicitOccRn nm `thenRn_`
+ returnRn Nothing
+
getDeclBinders new_name (DefD _) = returnRn Nothing
getDeclBinders new_name (InstD _) = returnRn Nothing
getDeclBinders new_name (RuleD _) = returnRn Nothing
+binds_haskell_name (FoImport _) _ = True
+binds_haskell_name FoLabel _ = True
+binds_haskell_name FoExport ext_nm = isDynamic ext_nm
+
----------------
getConFieldNames new_name (ConDecl con _ _ (RecCon fielddecls) src_loc : rest)
= mapRn (\n -> new_name n src_loc) (con:fields) `thenRn` \ cfs ->
do_one (rdr_name, loc) = new_name rdr_name loc `thenRn` \ name ->
returnRn (Avail name)
- -- foreign declarations
-getLocalDeclBinders new_name (ForD (ForeignDecl nm kind _ dyn _ loc))
- | binds_haskell_name kind dyn
- = new_name nm loc `thenRn` \ name ->
- returnRn [Avail name]
-
- | otherwise
- = returnRn []
-
getLocalDeclBinders new_name decl
= getDeclBinders new_name decl `thenRn` \ maybe_avail ->
case maybe_avail of
-- etc, into the cache
new_sys_name rdr_name loc = newImplicitBinder (rdrNameOcc rdr_name) loc
-binds_haskell_name (FoImport _) _ = True
-binds_haskell_name FoLabel _ = True
-binds_haskell_name FoExport ext_nm = isDynamic ext_nm
-
fixitiesFromLocalDecls :: GlobalRdrEnv -> [RdrNameHsDecl] -> RnMG FixityEnv
fixitiesFromLocalDecls gbl_env decls
= foldlRn getFixities emptyNameEnv decls
\begin{code}
rnDecl (ForD (ForeignDecl name imp_exp ty ext_nm cconv src_loc))
= pushSrcLocRn src_loc $
- lookupBndrRn name `thenRn` \ name' ->
+ lookupOccRn name `thenRn` \ name' ->
let
fvs1 = case imp_exp of
FoImport _ | not isDyn -> emptyFVs
FoExport | isDyn -> mkNameSet [makeStablePtr_NAME,
deRefStablePtr_NAME,
bindIO_NAME]
+ | otherwise -> mkNameSet [name']
_ -> emptyFVs
in
rnHsSigType fo_decl_msg ty `thenRn` \ (ty', fvs2) ->