KiCS-0.8.5: src/Names.hs
module Names where
import Char
import List
import System.FilePath
import ShowFunctionalProg (isTuple,isInfixOpName)
---------------------------------------------------------------------------
-- generating names to avoid clashes with Haskell
---------------------------------------------------------------------------
-- constructor names
preludeConstructorName "()" = "T0"
preludeConstructorName "[]" = "List"
preludeConstructorName ":" = ":<"
preludeConstructorName n
| isTuple n = "T"++show (1+length (takeWhile (==',') (tail n)))
| otherwise = 'C':'_':n
constructorName = preludeConstructorName
consName (m,n) =
case m of
"" -> ("",preludeConstructorName n)
_ -> (modName m,constructorName n)
{-
extConsName exts (m,n) = case m of
"Prelude" -> (datamod m,preludeConstructorName n)
"" -> ("",preludeConstructorName n)
_ -> (datamod m,constructorName n)
where
datamod = if elem (m,n) exts then extDataModName else dataModName
-}
functionName n | isInfixOpName n = elimInfix n
| otherwise = 'c':'_':n
funName (m,n) = (modName m,functionName n)
elimInfix name = "op_"++concat (intersperse "_" (map (show . ord) name))
-----------------------------------------
-- naming conventions for new objects
-----------------------------------------
-- module names
insertName :: String -> FilePath -> FilePath
insertName s xs = replaceFileName xs (s++takeFileName xs)
modName s = insertName "Curry.Module." s
funcHsName s = replaceExtension s ".hs"
externalSpecName s = replaceExtension s ".hs.include"
dbgMName = "Oracle"
dbgModName = insertName dbgMName
strictPrefix = "S"
mkStrictName = insertName strictPrefix
-- names for new constructors
--addPrefix s _ (p@"Prelude","Int") = (instModName p,"C_Int"++s)
--addPrefix s _ (p@"Prelude","Float") = (instModName p,"Prim"++s)
addPrefix s (m,n) = (m,n++s)
freeVarName = addPrefix "FreeVar"
failName = addPrefix "Fail"
orName = addPrefix "Or"
suspName = addPrefix "Susp"