- from_ty (TyData _ n _ _ _ _ _) acc = maybe_add acc n
- from_ty (TyNew _ n _ _ _ _ _) acc = maybe_add acc n
- from_ty (TySynonym n _ _ _) acc = maybe_add acc n
-
- from_cls (ClassDecl _ n _ _ _ _ _) acc = maybe_add acc n
-
- from_sig (Sig n _ _ _) acc = maybe_add acc n
-
- from_binds bs acc = maybe_add_list acc (collectTopLevelBinders bs)
-
- --------------
- from_wired is_val_ish rn acc
- | on_in_acc = acc -- if already in acc (presumably from real decl),
- -- don't take the dubious export flag from the
- -- wired-in chappy
- | is_val_ish && isRnConstr rn
- = acc -- these things don't cause export-ery
- | exportFlagOn ef = addToFM acc on ef
- | otherwise = acc
- where
- n = getName rn
- ef = export_fn n
- on = origName "from_wired" n
- (OrigName _ str) = on
- on_in_acc = maybeToBool (lookupFM acc on)
-
- --------------
- maybe_add :: FiniteMap OrigName ExportFlag -> RnName -> FiniteMap OrigName ExportFlag
-
- maybe_add acc rn
- | on_in_acc = trace "maybe_add?" acc -- surprising!
- | exportFlagOn ef = addToFM acc on ef
- | otherwise = acc
- where
- ef = nameExportFlag n
- n = getName rn
- on = origName "maybe_add" n
- on_in_acc = maybeToBool (lookupFM acc on)
-
- --------------
- maybe_add_list acc [] = acc
- maybe_add_list acc (n:ns) = maybe_add (maybe_add_list acc ns) n
-
- --------------
- lexical_lt (n1,_) (n2,_) = n1 < n2
-
- --------------
- upp_pair (OrigName m n, ef)
- = uppBesides [uppPStr m, uppSP, uppPStr n, uppSP, upp_export ef]
- where
- upp_export ExportAll = uppPStr SLIT("(..)")
- upp_export ExportAbs = uppNil
+ ty_decl | isSynTyCon tycon
+ = TySynonym { tcdName = getName tycon,
+ tcdTyVars = toHsTyVars tyvars,
+ tcdSynRhs = toHsType syn_ty,
+ tcdLoc = noSrcLoc }
+
+ | isAlgTyCon tycon
+ = TyData { tcdND = new_or_data,
+ tcdCtxt = toHsContext (tyConTheta tycon),
+ tcdName = getName tycon,
+ tcdTyVars = toHsTyVars tyvars,
+ tcdCons = map ifaceConDecl (tyConDataCons tycon),
+ tcdNCons = tyConFamilySize tycon,
+ tcdDerivs = Nothing,
+ tcdSysNames = map getName (tyConGenIds tycon),
+ tcdLoc = noSrcLoc }
+
+ | otherwise = pprPanic "ifaceTyCls" (ppr tycon)
+
+ tyvars = tyConTyVars tycon
+ (_, syn_ty) = getSynTyConDefn tycon
+ new_or_data | isNewTyCon tycon = NewType
+ | otherwise = DataType
+
+ ifaceConDecl data_con
+ = ConDecl (getName data_con) (getName (dataConId data_con))
+ (toHsTyVars ex_tyvars)
+ (toHsContext ex_theta)
+ details noSrcLoc
+ where
+ (tyvars1, _, ex_tyvars, ex_theta, arg_tys, tycon1) = dataConSig data_con
+ field_labels = dataConFieldLabels data_con
+ strict_marks = dataConStrictMarks data_con
+ details | null field_labels
+ = ASSERT( tycon == tycon1 && tyvars == tyvars1 )
+ VanillaCon (zipWith mk_bang_ty strict_marks arg_tys)
+
+ | otherwise
+ = RecCon (zipWith mk_field strict_marks field_labels)
+
+ mk_bang_ty NotMarkedStrict ty = Unbanged (toHsType ty)
+ mk_bang_ty (MarkedUnboxed _ _) ty = Unpacked (toHsType ty)
+ mk_bang_ty MarkedStrict ty = Banged (toHsType ty)
+
+ mk_field strict_mark field_label
+ = ([getName field_label], mk_bang_ty strict_mark (fieldLabelType field_label))
+
+ifaceTyCls (AnId id) so_far
+ | isImplicitId id = so_far
+ | otherwise = iface_sig : so_far
+ where
+ iface_sig = IfaceSig { tcdName = getName id,
+ tcdType = toHsType id_type,
+ tcdIdInfo = hs_idinfo,
+ tcdLoc = noSrcLoc }
+
+ id_type = idType id
+ id_info = idInfo id
+
+ hs_idinfo | opt_OmitInterfacePragmas = []
+ | otherwise = arity_hsinfo ++ caf_hsinfo ++ cpr_hsinfo ++
+ strict_hsinfo ++ wrkr_hsinfo ++ unfold_hsinfo
+
+ ------------ Arity --------------
+ arity_hsinfo = case arityInfo id_info of
+ a@(ArityExactly n) -> [HsArity a]
+ other -> []
+
+ ------------ Caf Info --------------
+ caf_hsinfo = case cafInfo id_info of
+ NoCafRefs -> [HsNoCafRefs]
+ otherwise -> []
+
+ ------------ CPR Info --------------
+ cpr_hsinfo = case cprInfo id_info of
+ ReturnsCPR -> [HsCprInfo]
+ NoCPRInfo -> []
+
+ ------------ Strictness --------------
+ strict_hsinfo = case strictnessInfo id_info of
+ NoStrictnessInfo -> []
+ info -> [HsStrictness info]
+
+ ------------ Worker --------------
+ work_info = workerInfo id_info
+ has_worker = case work_info of { HasWorker _ _ -> True; other -> False }
+ wrkr_hsinfo = case work_info of
+ HasWorker work_id wrap_arity -> [HsWorker (getName work_id)]
+ NoWorker -> []
+
+ ------------ Unfolding --------------
+ -- The unfolding is redundant if there is a worker
+ unfold_info = unfoldingInfo id_info
+ inline_prag = inlinePragInfo id_info
+ rhs = unfoldingTemplate unfold_info
+ unfold_hsinfo | neverUnfold unfold_info
+ || has_worker = []
+ | otherwise = [HsUnfold inline_prag (toUfExpr rhs)]