+ -- Fixity and deprecations have been dealt with already; ignore them
+ go fvs ds' [] = returnRn (ds', fvs)
+ go fvs ds' (FixD _:ds) = go fvs ds' ds
+ go fvs ds' (DeprecD _:ds) = go fvs ds' ds
+ go fvs ds' (d:ds) = rnSourceDecl d `thenRn` \(d', fvs') ->
+ go (fvs `plusFV` fvs') (d':ds') ds
+
+
+rnSourceDecl :: RdrNameHsDecl -> RnMS (RenamedHsDecl, FreeVars)
+
+rnSourceDecl (ValD binds) = rnTopBinds binds `thenRn` \ (new_binds, fvs) ->
+ returnRn (ValD new_binds, fvs)
+
+rnSourceDecl (TyClD tycl_decl)
+ = rnTyClDecl tycl_decl `thenRn` \ new_decl ->
+ rnClassBinds tycl_decl new_decl `thenRn` \ (new_decl', fvs) ->
+ returnRn (TyClD new_decl', fvs `plusFV` tyClDeclFVs new_decl')
+
+rnSourceDecl (InstD inst)
+ = rnInstDecl inst `thenRn` \ new_inst ->
+ rnInstBinds inst new_inst `thenRn` \ (new_inst', fvs) ->
+ returnRn (InstD new_inst', fvs `plusFV` instDeclFVs new_inst')
+
+rnSourceDecl (RuleD rule)
+ = rnHsRuleDecl rule `thenRn` \ (new_rule, fvs) ->
+ returnRn (RuleD new_rule, fvs)
+
+rnSourceDecl (DefD (DefaultDecl tys src_loc))
+ = pushSrcLocRn src_loc $
+ mapFvRn (rnHsTypeFVs doc_str) tys `thenRn` \ (tys', fvs) ->
+ returnRn (DefD (DefaultDecl tys' src_loc), fvs)
+ where
+ doc_str = text "a `default' declaration"
+
+rnSourceDecl (ForD (ForeignDecl name imp_exp ty ext_nm cconv src_loc))
+ = pushSrcLocRn src_loc $
+ lookupOccRn name `thenRn` \ name' ->
+ let
+ extra_fvs FoExport
+ | isDyn = lookupOrigNames [newStablePtr_RDR, deRefStablePtr_RDR,
+ bindIO_RDR, returnIO_RDR]
+ | otherwise =
+ lookupOrigNames [bindIO_RDR, returnIO_RDR] `thenRn` \ fvs ->
+ returnRn (addOneFV fvs name')
+ extra_fvs other = returnRn emptyFVs
+ in
+ checkRn (ok_ext_nm ext_nm) (badExtName ext_nm) `thenRn_`
+
+ extra_fvs imp_exp `thenRn` \ fvs1 ->
+
+ rnHsTypeFVs fo_decl_msg ty `thenRn` \ (ty', fvs2) ->
+ returnRn (ForD (ForeignDecl name' imp_exp ty' ext_nm cconv src_loc),
+ fvs1 `plusFV` fvs2)
+ where
+ fo_decl_msg = ptext SLIT("The foreign declaration for") <+> ppr name
+ isDyn = isDynamicExtName ext_nm
+
+ ok_ext_nm Dynamic = True
+ ok_ext_nm (ExtName nm (Just mb)) = isCLabelString nm && isCLabelString mb
+ ok_ext_nm (ExtName nm Nothing) = isCLabelString nm