From 8cedbed5fceddf771d64c5b42be8d6e0280c9480 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sun, 6 Apr 2008 17:42:12 +0000 Subject: [PATCH] Move makeUniqueName and findUnscopedName into CompState. --- data/CompState.hs | 17 +++++++++++++++++ frontends/ParseOccam.hs | 16 ---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/data/CompState.hs b/data/CompState.hs index 6bc46a0..01c17f1 100644 --- a/data/CompState.hs +++ b/data/CompState.hs @@ -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 diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index a072750..9db7f2c 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -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