never executed always true always false
1 {-
2 %
3 % (c) The University of Glasgow 2006
4 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
5 %
6 -}
7
8 -- | FastStringEnv: FastString environments
9 module GHC.Data.FastString.Env (
10 -- * FastString environments (maps)
11 FastStringEnv,
12
13 -- ** Manipulating these environments
14 mkFsEnv,
15 emptyFsEnv, unitFsEnv,
16 extendFsEnv_C, extendFsEnv_Acc, extendFsEnv,
17 extendFsEnvList, extendFsEnvList_C,
18 filterFsEnv,
19 plusFsEnv, plusFsEnv_C, alterFsEnv,
20 lookupFsEnv, lookupFsEnv_NF, delFromFsEnv, delListFromFsEnv,
21 elemFsEnv, mapFsEnv,
22
23 -- * Deterministic FastString environments (maps)
24 DFastStringEnv,
25
26 -- ** Manipulating these environments
27 mkDFsEnv, emptyDFsEnv, dFsEnvElts, lookupDFsEnv
28 ) where
29
30 import GHC.Prelude
31
32 import GHC.Types.Unique.FM
33 import GHC.Types.Unique.DFM
34 import GHC.Data.Maybe
35 import GHC.Data.FastString
36
37
38 -- | A non-deterministic set of FastStrings.
39 -- See Note [Deterministic UniqFM] in "GHC.Types.Unique.DFM" for explanation why it's not
40 -- deterministic and why it matters. Use DFastStringEnv if the set eventually
41 -- gets converted into a list or folded over in a way where the order
42 -- changes the generated code.
43 type FastStringEnv a = UniqFM FastString a -- Domain is FastString
44
45 emptyFsEnv :: FastStringEnv a
46 mkFsEnv :: [(FastString,a)] -> FastStringEnv a
47 alterFsEnv :: (Maybe a-> Maybe a) -> FastStringEnv a -> FastString -> FastStringEnv a
48 extendFsEnv_C :: (a->a->a) -> FastStringEnv a -> FastString -> a -> FastStringEnv a
49 extendFsEnv_Acc :: (a->b->b) -> (a->b) -> FastStringEnv b -> FastString -> a -> FastStringEnv b
50 extendFsEnv :: FastStringEnv a -> FastString -> a -> FastStringEnv a
51 plusFsEnv :: FastStringEnv a -> FastStringEnv a -> FastStringEnv a
52 plusFsEnv_C :: (a->a->a) -> FastStringEnv a -> FastStringEnv a -> FastStringEnv a
53 extendFsEnvList :: FastStringEnv a -> [(FastString,a)] -> FastStringEnv a
54 extendFsEnvList_C :: (a->a->a) -> FastStringEnv a -> [(FastString,a)] -> FastStringEnv a
55 delFromFsEnv :: FastStringEnv a -> FastString -> FastStringEnv a
56 delListFromFsEnv :: FastStringEnv a -> [FastString] -> FastStringEnv a
57 elemFsEnv :: FastString -> FastStringEnv a -> Bool
58 unitFsEnv :: FastString -> a -> FastStringEnv a
59 lookupFsEnv :: FastStringEnv a -> FastString -> Maybe a
60 lookupFsEnv_NF :: FastStringEnv a -> FastString -> a
61 filterFsEnv :: (elt -> Bool) -> FastStringEnv elt -> FastStringEnv elt
62 mapFsEnv :: (elt1 -> elt2) -> FastStringEnv elt1 -> FastStringEnv elt2
63
64 emptyFsEnv = emptyUFM
65 unitFsEnv x y = unitUFM x y
66 extendFsEnv x y z = addToUFM x y z
67 extendFsEnvList x l = addListToUFM x l
68 lookupFsEnv x y = lookupUFM x y
69 alterFsEnv = alterUFM
70 mkFsEnv l = listToUFM l
71 elemFsEnv x y = elemUFM x y
72 plusFsEnv x y = plusUFM x y
73 plusFsEnv_C f x y = plusUFM_C f x y
74 extendFsEnv_C f x y z = addToUFM_C f x y z
75 mapFsEnv f x = mapUFM f x
76 extendFsEnv_Acc x y z a b = addToUFM_Acc x y z a b
77 extendFsEnvList_C x y z = addListToUFM_C x y z
78 delFromFsEnv x y = delFromUFM x y
79 delListFromFsEnv x y = delListFromUFM x y
80 filterFsEnv x y = filterUFM x y
81
82 lookupFsEnv_NF env n = expectJust "lookupFsEnv_NF" (lookupFsEnv env n)
83
84 -- Deterministic FastStringEnv
85 -- See Note [Deterministic UniqFM] in GHC.Types.Unique.DFM for explanation why we need
86 -- DFastStringEnv.
87
88 type DFastStringEnv a = UniqDFM FastString a -- Domain is FastString
89
90 emptyDFsEnv :: DFastStringEnv a
91 emptyDFsEnv = emptyUDFM
92
93 dFsEnvElts :: DFastStringEnv a -> [a]
94 dFsEnvElts = eltsUDFM
95
96 mkDFsEnv :: [(FastString,a)] -> DFastStringEnv a
97 mkDFsEnv l = listToUDFM l
98
99 lookupDFsEnv :: DFastStringEnv a -> FastString -> Maybe a
100 lookupDFsEnv = lookupUDFM