[project @ 1998-04-16 09:08:32 by simonm]
[ghc-hetmet.git] / ghc / compiler / utils / UniqFM.lhs
index 48be3f6..68bd7a7 100644 (file)
@@ -11,17 +11,8 @@ Basically, the things need to be in class @Uniquable@, and we use the
 (A similar thing to @UniqSet@, as opposed to @Set@.)
 
 \begin{code}
-#if defined(COMPILING_GHC)
-#include "HsVersions.h"
-#define IF_NOT_GHC(a) {--}
-#else
-#define ASSERT(e) {--}
-#define IF_NOT_GHC(a) a
-#endif
-
 module UniqFM (
        UniqFM,   -- abstract type
-       Uniquable(..), -- class to go with it
 
        emptyUFM,
        unitUFM,
@@ -39,32 +30,27 @@ module UniqFM (
        plusUFM_C,
        minusUFM,
        intersectUFM,
-       IF_NOT_GHC(intersectUFM_C COMMA)
-       IF_NOT_GHC(foldUFM COMMA)
+       intersectUFM_C,
+       foldUFM,
        mapUFM,
+       elemUFM,
        filterUFM,
        sizeUFM,
        isNullUFM,
        lookupUFM, lookupUFM_Directly,
        lookupWithDefaultUFM, lookupWithDefaultUFM_Directly,
        eltsUFM, keysUFM,
-       ufmToList
-#if defined(COMPILING_GHC)
-       ,FAST_STRING
-#endif
+       ufmToList, 
+       FastString
     ) where
 
-#if defined(COMPILING_GHC)
-IMPORT_DELOOPER( SpecLoop )
-#endif
-IMP_Ubiq()
+#include "HsVersions.h"
+
+import {-# SOURCE #-} Name     ( Name )
 
-import Unique          ( Unique, u2i, mkUniqueGrimily )
+import Unique          ( Uniquable(..), Unique, u2i, mkUniqueGrimily )
 import Util
-import Pretty          ( Doc )
-import Outputable      ( Outputable(..) )
-import PprStyle                ( PprStyle )
-import SrcLoc          ( SrcLoc )
+import GlaExts         -- Lots of Int# operations
 
 #if ! OMIT_NATIVE_CODEGEN
 #define IF_NCG(a) a
@@ -121,6 +107,7 @@ mapUFM              :: (elt1 -> elt2) -> UniqFM elt1 -> UniqFM elt2
 filterUFM      :: (elt -> Bool) -> UniqFM elt -> UniqFM elt
 
 sizeUFM                :: UniqFM elt -> Int
+elemUFM                :: Uniquable key => key -> UniqFM elt -> Bool
 
 lookupUFM      :: Uniquable key => UniqFM elt -> key -> Maybe elt
 lookupUFM_Directly  -- when you've got the Unique already
@@ -142,6 +129,9 @@ ufmToList   :: UniqFM elt -> [(Unique, elt)]
 %************************************************************************
 
 \begin{code}
+-- Turn off for now, these need to be updated (SDM 4/98)
+
+#if 0
 #ifdef __GLASGOW_HASKELL__
 -- I don't think HBC was too happy about this (WDP 94/10)
 
@@ -163,6 +153,7 @@ ufmToList   :: UniqFM elt -> [(Unique, elt)]
   #-}
 
 #endif {- __GLASGOW_HASKELL__ -}
+#endif
 \end{code}
 
 %************************************************************************
@@ -203,9 +194,6 @@ data UniqFM ele
            (UniqFM ele)
            (UniqFM ele)
 
-class Uniquable a where
-    uniqueOf :: a -> Unique
-
 -- for debugging only :-)
 {-
 instance Text (UniqFM a) where
@@ -545,6 +533,10 @@ looking up in a hurry is the {\em whole point} of this binary tree lark.
 Lookup up a binary tree is easy (and fast).
 
 \begin{code}
+elemUFM key fm = case lookUp fm (u2i (uniqueOf key)) of
+                       Nothing -> False
+                       Just _  -> True
+
 lookupUFM         fm key = lookUp fm (u2i (uniqueOf key))
 lookupUFM_Directly fm key = lookUp fm (u2i key)