+ ppr (DefaultDecl tys src_loc)
+ = ptext SLIT("default") <+> parens (interpp'SP tys)
+\end{code}
+
+%************************************************************************
+%* *
+\subsection{Foreign function interface declaration}
+%* *
+%************************************************************************
+
+\begin{code}
+data ForeignDecl name =
+ ForeignDecl
+ name
+ ForKind
+ (HsType name)
+ ExtName
+ CallConv
+ SrcLoc
+
+instance (Outputable name)
+ => Outputable (ForeignDecl name) where
+
+ ppr (ForeignDecl nm imp_exp ty ext_name cconv src_loc)
+ = ptext SLIT("foreign") <+> ppr_imp_exp <+> pprCallConv cconv <+>
+ ppr ext_name <+> ppr_unsafe <+> ppr nm <+> dcolon <+> ppr ty
+ where
+ (ppr_imp_exp, ppr_unsafe) =
+ case imp_exp of
+ FoLabel -> (ptext SLIT("label"), empty)
+ FoExport -> (ptext SLIT("export"), empty)
+ FoImport us
+ | us -> (ptext SLIT("import"), ptext SLIT("unsafe"))
+ | otherwise -> (ptext SLIT("import"), empty)
+
+data ForKind
+ = FoLabel
+ | FoExport
+ | FoImport Bool -- True => unsafe call.
+
+data ExtName
+ = Dynamic
+ | ExtName CLabelString -- The external name of the foreign thing,
+ (Maybe CLabelString) -- and optionally its DLL or module name
+ -- Both of these are completely unencoded;
+ -- we just print them as they are
+
+isDynamicExtName :: ExtName -> Bool
+isDynamicExtName Dynamic = True
+isDynamicExtName _ = False
+
+extNameStatic :: ExtName -> CLabelString
+extNameStatic (ExtName f _) = f
+extNameStatic Dynamic = panic "staticExtName: Dynamic - shouldn't ever happen."
+
+instance Outputable ExtName where
+ ppr Dynamic = ptext SLIT("dynamic")
+ ppr (ExtName nm mb_mod) =
+ case mb_mod of { Nothing -> empty; Just m -> doubleQuotes (ptext m) } <+>
+ doubleQuotes (pprCLabelString nm)
+\end{code}
+
+%************************************************************************
+%* *
+\subsection{Transformation rules}
+%* *
+%************************************************************************
+
+\begin{code}
+data RuleDecl name pat
+ = HsRule -- Source rule
+ FAST_STRING -- Rule name
+ [name] -- Forall'd tyvars, filled in by the renamer with
+ -- tyvars mentioned in sigs; then filled out by typechecker
+ [RuleBndr name] -- Forall'd term vars
+ (HsExpr name pat) -- LHS
+ (HsExpr name pat) -- RHS
+ SrcLoc
+
+ | IfaceRule -- One that's come in from an interface file; pre-typecheck
+ FAST_STRING
+ [UfBinder name] -- Tyvars and term vars
+ name -- Head of lhs
+ [UfExpr name] -- Args of LHS
+ (UfExpr name) -- Pre typecheck
+ SrcLoc
+
+ | IfaceRuleOut -- Post typecheck
+ name -- Head of LHS
+ CoreRule
+
+
+data RuleBndr name
+ = RuleBndr name
+ | RuleBndrSig name (HsType name)
+
+instance Ord name => Eq (RuleDecl name pat) where
+ -- Works for IfaceRules only; used when comparing interface file versions
+ (IfaceRule n1 bs1 f1 es1 rhs1 _) == (IfaceRule n2 bs2 f2 es2 rhs2 _)
+ = n1==n2 && f1 == f2 &&
+ eq_ufBinders emptyEqHsEnv bs1 bs2 (\env ->
+ eqListBy (eq_ufExpr env) (rhs1:es1) (rhs2:es2))
+
+instance (Outputable name, Outputable pat)
+ => Outputable (RuleDecl name pat) where
+ ppr (HsRule name tvs ns lhs rhs loc)
+ = sep [text "{-# RULES" <+> doubleQuotes (ptext name),
+ pp_forall, ppr lhs, equals <+> ppr rhs,
+ text "#-}" ]
+ where
+ pp_forall | null tvs && null ns = empty
+ | otherwise = text "forall" <+>
+ fsep (map ppr tvs ++ map ppr ns)
+ <> dot
+
+ ppr (IfaceRule name tpl_vars fn tpl_args rhs loc)
+ = hsep [ doubleQuotes (ptext name),
+ ptext SLIT("__forall") <+> braces (interppSP tpl_vars),
+ ppr fn <+> sep (map (pprUfExpr parens) tpl_args),
+ ptext SLIT("=") <+> ppr rhs
+ ] <+> semi
+
+ ppr (IfaceRuleOut fn rule) = pprCoreRule (ppr fn) rule
+
+instance Outputable name => Outputable (RuleBndr name) where
+ ppr (RuleBndr name) = ppr name
+ ppr (RuleBndrSig name ty) = ppr name <> dcolon <> ppr ty
+
+toHsRule id (BuiltinRule _)
+ = pprTrace "toHsRule: builtin" (ppr id) (bogusIfaceRule id)
+
+toHsRule id (Rule name bndrs args rhs)
+ = IfaceRule name (map toUfBndr bndrs) (toRdrName id)
+ (map toUfExpr args) (toUfExpr rhs) noSrcLoc
+
+bogusIfaceRule id
+ = IfaceRule SLIT("bogus") [] (toRdrName id) [] (UfVar (toRdrName id)) noSrcLoc
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection[DeprecDecl]{Deprecations}
+%* *
+%************************************************************************
+
+We use exported entities for things to deprecate. Cunning trick (hack?):
+`IEModuleContents undefined' is used for module deprecation.
+
+\begin{code}
+data DeprecDecl name = Deprecation (IE name) DeprecTxt SrcLoc
+
+type DeprecTxt = FAST_STRING -- reason/explanation for deprecation
+
+instance Outputable name => Outputable (DeprecDecl name) where
+ ppr (Deprecation (IEModuleContents _) txt _)
+ = hsep [text "{-# DEPRECATED", doubleQuotes (ppr txt), text "#-}"]
+ ppr (Deprecation thing txt _)
+ = hsep [text "{-# DEPRECATED", ppr thing, doubleQuotes (ppr txt), text "#-}"]