) where
#include "HsVersions.h"
+#include "Typeable.h"
import Name
import UniqSet
+import Util
+
+import Data.Data
\end{code}
%************************************************************************
\begin{code}
type NameSet = UniqSet Name
+-- TODO: These Data/Typeable instances look very dubious. Surely either
+-- UniqFM should have the instances, or this should be a newtype?
+
+nameSetTc :: TyCon
+nameSetTc = mkTyCon "NameSet"
+instance Typeable NameSet where { typeOf _ = mkTyConApp nameSetTc [] }
+
+instance Data NameSet where
+ gfoldl k z s = z mkNameSet `k` nameSetToList s -- traverse abstractly
+ toConstr _ = abstractConstr "NameSet"
+ gunfold _ _ = error "gunfold"
+ dataTypeOf _ = mkNoRepType "NameSet"
+
emptyNameSet :: NameSet
unitNameSet :: Name -> NameSet
addListToNameSet :: NameSet -> [Name] -> NameSet
type DefUse = (Maybe Defs, Uses)
-- | A number of 'DefUse's in dependency order: earlier 'Defs' scope over later 'Uses'
+-- In a single (def, use) pair, the defs also scope over the uses
type DefUses = [DefUse]
emptyDUs :: DefUses
get (Nothing, _u1) d2 = d2
get (Just d1, _u1) d2 = d1 `unionNameSets` d2
-duUses :: DefUses -> Uses
--- ^ Just like 'allUses', but 'Defs' are not eliminated from the 'Uses' returned
-duUses dus = foldr get emptyNameSet dus
+allUses :: DefUses -> Uses
+-- ^ Just like 'duUses', but 'Defs' are not eliminated from the 'Uses' returned
+allUses dus = foldr get emptyNameSet dus
where
get (_d1, u1) u2 = u1 `unionNameSets` u2
-allUses :: DefUses -> Uses
+duUses :: DefUses -> Uses
-- ^ Collect all 'Uses', regardless of whether the group is itself used,
-- but remove 'Defs' on the way
-allUses dus
- = foldr get emptyNameSet dus
+duUses dus = foldr get emptyNameSet dus
where
get (Nothing, rhs_uses) uses = rhs_uses `unionNameSets` uses
get (Just defs, rhs_uses) uses = (rhs_uses `unionNameSets` uses)