[project @ 1997-06-05 08:51:03 by sof]
[ghc-hetmet.git] / ghc / compiler / utils / UniqFM.lhs
index 8f9e9f9..1cd56ff 100644 (file)
@@ -47,19 +47,27 @@ module UniqFM (
        isNullUFM,
        lookupUFM, lookupUFM_Directly,
        lookupWithDefaultUFM, lookupWithDefaultUFM_Directly,
-       eltsUFM,
+       eltsUFM, keysUFM,
        ufmToList
+#if defined(COMPILING_GHC)
+       ,FAST_STRING
+#endif
     ) where
 
+IMP_Ubiq()
+
 #if defined(COMPILING_GHC)
+# if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ <= 201
 IMPORT_DELOOPER( SpecLoop )
+# else
+import {-# SOURCE #-} Name
+# endif
 #endif
 
 import Unique          ( Unique, u2i, mkUniqueGrimily )
 import Util
-import Pretty          ( SYN_IE(Pretty), PrettyRep )
-import Outputable      ( Outputable(..) )
-import PprStyle                ( PprStyle )
+import Pretty          ( Doc )
+import Outputable      ( PprStyle, Outputable(..) )
 import SrcLoc          ( SrcLoc )
 
 #if ! OMIT_NATIVE_CODEGEN
@@ -126,6 +134,7 @@ lookupWithDefaultUFM
 lookupWithDefaultUFM_Directly
                :: UniqFM elt -> elt -> Unique -> elt
 
+keysUFM                :: UniqFM elt -> [Int]          -- Get the keys
 eltsUFM                :: UniqFM elt -> [elt]
 ufmToList      :: UniqFM elt -> [(Unique, elt)]
 \end{code}
@@ -509,9 +518,12 @@ intersectUFM_C f fm1 fm2    = intersect_trees fm1 fm2
 Now the usual set of `collection' operators, like map, fold, etc.
 
 \begin{code}
-foldUFM fn a EmptyUFM = a
-foldUFM fn a fm              = fold_tree fn a fm
+foldUFM f a (NodeUFM _ _ t1 t2) = foldUFM f (foldUFM f a t2) t1
+foldUFM f a (LeafUFM _ obj)     = f obj a
+foldUFM f a EmptyUFM           = a
+\end{code}
 
+\begin{code}
 mapUFM fn EmptyUFM    = EmptyUFM
 mapUFM fn fm         = map_tree fn fm
 
@@ -568,17 +580,15 @@ lookUp fm i           = lookup_tree fm
 folds are *wonderful* things.
 
 \begin{code}
-eltsUFM EmptyUFM = []
-eltsUFM fm       = fold_tree (:) [] fm
+eltsUFM fm = foldUFM (:) [] fm
 
-ufmToList EmptyUFM = []
-ufmToList fm
-  = fold_tree (\ iu elt rest -> (mkUniqueGrimily iu, elt) : rest) [] fm
-  where
-    fold_tree f a (NodeUFM _ _ t1 t2) = fold_tree f (fold_tree f a t2) t1
-    fold_tree f a (LeafUFM iu obj)    = f iu obj a
+ufmToList fm = fold_tree (\ iu elt rest -> (mkUniqueGrimily iu, elt) : rest) [] fm
+
+keysUFM fm = fold_tree (\ iu elt rest -> IBOX(iu) : rest) [] fm
 
-    fold_tree f a EmptyUFM = panic "Should Never fold over an EmptyUFM"
+fold_tree f a (NodeUFM _ _ t1 t2) = fold_tree f (fold_tree f a t2) t1
+fold_tree f a (LeafUFM iu obj)    = f iu obj a
+fold_tree f a EmptyUFM           = a
 \end{code}
 
 %************************************************************************
@@ -688,14 +698,7 @@ insert_ele f n@(NodeUFM j p t1 t2) i a
                  (mkLeafUFM i a)
 \end{code}
 
-This has got a left to right ordering.
 
-\begin{code}
-fold_tree f a (NodeUFM _ _ t1 t2) = fold_tree f (fold_tree f a t2) t1
-fold_tree f a (LeafUFM _ obj)    = f obj a
-
-fold_tree f a EmptyUFM = panic "Should Never fold over an EmptyUFM"
-\end{code}
 
 \begin{code}
 map_tree f (NodeUFM j p t1 t2)
@@ -713,6 +716,7 @@ filter_tree f nd@(NodeUFM j p t1 t2)
 filter_tree f lf@(LeafUFM i obj)
   | f obj = lf
   | otherwise = EmptyUFM
+filter_tree f _ = panic "filter_tree failed"
 \end{code}
 
 %************************************************************************
@@ -813,12 +817,7 @@ shiftR_ n p = n `quot` (2 ^ p)
 #endif {- not GHC -}
 \end{code}
 
-Andy's extras: ToDo: to Util.
-
 \begin{code}
-use_fst :: a -> b -> a
-use_fst a b = a
-
 use_snd :: a -> b -> b
 use_snd a b = b
 \end{code}