Move makeUniqueName and findUnscopedName into CompState.

This commit is contained in:
Adam Sampson 2008-04-06 17:42:12 +00:00
parent 3ab0c30589
commit 8cedbed5fc
2 changed files with 17 additions and 16 deletions

View File

@ -186,6 +186,23 @@ lookupNameOrError n err
Just nd -> return nd
Nothing -> err
-- | Make a name unique by appending a suffix to it.
makeUniqueName :: CSM m => String -> m String
makeUniqueName s
= do st <- get
put $ st { csNameCounter = csNameCounter st + 1 }
return $ s ++ "_u" ++ show (csNameCounter st)
-- | Find an unscoped name -- or define a new one if it doesn't already exist.
findUnscopedName :: CSM m => A.Name -> m A.Name
findUnscopedName n@(A.Name m nt s)
= do st <- get
case Map.lookup s (csUnscopedNames st) of
Just s' -> return $ A.Name m nt s'
Nothing ->
do s' <- makeUniqueName s
modify (\st -> st { csUnscopedNames = Map.insert s s' (csUnscopedNames st) })
return $ A.Name m nt s'
--}}}
--{{{ pulled items

View File

@ -371,22 +371,6 @@ findName thisN
then dieP (A.nameMeta thisN) $ "expected " ++ show (A.nameType thisN) ++ " (" ++ A.nameName origN ++ " is " ++ show (A.nameType origN) ++ ")"
else return $ thisN { A.nameName = A.nameName origN }
makeUniqueName :: String -> OccParser String
makeUniqueName s
= do st <- get
put $ st { csNameCounter = csNameCounter st + 1 }
return $ s ++ "_u" ++ show (csNameCounter st)
findUnscopedName :: A.Name -> OccParser A.Name
findUnscopedName n@(A.Name m nt s)
= do st <- get
case Map.lookup s (csUnscopedNames st) of
Just s' -> return $ A.Name m nt s'
Nothing ->
do s' <- makeUniqueName s
modify (\st -> st { csUnscopedNames = Map.insert s s' (csUnscopedNames st) })
return $ A.Name m nt s'
scopeIn :: A.Name -> A.SpecType -> A.AbbrevMode -> OccParser A.Name
scopeIn n@(A.Name m nt s) specType am
= do st <- getState