@@ -70,6 +70,7 @@ module Verifier.SAW.SharedTerm
70
70
, scExtCns
71
71
, scGlobalDef
72
72
, scRegisterGlobal
73
+ , scFreshenGlobalIdent
73
74
-- ** Recursors and datatypes
74
75
, scRecursorElimTypes
75
76
, scRecursorRetTypeType
@@ -269,7 +270,7 @@ import Control.Lens
269
270
import Control.Monad.State.Strict as State
270
271
import Control.Monad.Reader
271
272
import Data.Bits
272
- import Data.List (inits )
273
+ import Data.List (inits , find )
273
274
import Data.Maybe
274
275
import qualified Data.Foldable as Fold
275
276
import Data.Foldable (foldl' , foldlM , foldrM , maximum )
@@ -441,6 +442,16 @@ scRegisterGlobal sc ident t =
441
442
Just _ -> (m, True )
442
443
Nothing -> (HMap. insert ident t m, False )
443
444
445
+ -- | Find a variant of an identifier that is not already being used as a global,
446
+ -- by possibly adding a numeric suffix
447
+ scFreshenGlobalIdent :: SharedContext -> Ident -> IO Ident
448
+ scFreshenGlobalIdent sc ident =
449
+ readIORef (scGlobalEnv sc) >>= \ gmap ->
450
+ return $ fromJust $ find (\ i -> not $ HMap. member i gmap) $
451
+ ident : map (mkIdent (identModule ident) .
452
+ Text. append (identBaseName ident) .
453
+ Text. pack . show ) [(0 :: Integer ) .. ]
454
+
444
455
-- | Create a function application term.
445
456
scApply :: SharedContext
446
457
-> Term -- ^ The function to apply
0 commit comments