-- * AnnEnv for collecting and querying Annotations
AnnEnv,
- mkAnnEnv, extendAnnEnvList, plusAnnEnv, emptyAnnEnv, findAnns
+ mkAnnEnv, extendAnnEnvList, plusAnnEnv, emptyAnnEnv, findAnns,
+ deserializeAnns
) where
import Name
import Serialized
import Unique
-import Control.Monad
import Data.Typeable
import Data.Maybe
import Data.Word ( Word8 )
ppr (NamedTarget nm) = text "Named target" <+> ppr nm
ppr (ModuleTarget mod) = text "Module target" <+> ppr mod
+instance Outputable Annotation where
+ ppr ann = ppr (ann_target ann)
-- | A collection of annotations
newtype AnnEnv = MkAnnEnv (UniqFM [Serialized])
findAnns deserialize (MkAnnEnv ann_env)
= (mapMaybe (fromSerialized deserialize))
. (lookupWithDefaultUFM ann_env [])
-\end{code}
\ No newline at end of file
+
+-- | Deserialize all annotations of a given type. This happens lazily, that is
+-- no deserialization will take place until the [a] is actually demanded and
+-- the [a] can also be empty (the UniqFM is not filtered).
+deserializeAnns :: Typeable a => ([Word8] -> a) -> AnnEnv -> UniqFM [a]
+deserializeAnns deserialize (MkAnnEnv ann_env)
+ = mapUFM (mapMaybe (fromSerialized deserialize)) ann_env
+\end{code}