{-
  Filename mangling for several intermediate file formats.

  The functions in this module were collected from several
  compiler modules in order to provide a unique accessing
  point for this functionality.

  (c) 2009, Holger Siegel.
-}

module Curry.Files.Filenames where

import System.FilePath

-- Various filename extensions
curryExt, lcurryExt, icurryExt, oExt :: String
curryExt = ".curry"

lcurryExt = ".lcurry"

icurryExt = ".icurry"

flatExt = ".fcy"

extFlatExt = ".efc"

flatIntExt = ".fint"
-- fintExt = ".fint"

xmlExt = "_flat.xml"

acyExt = ".acy"

uacyExt = ".uacy"

sourceRepExt = ".cy"

oExt = ".o"

debugExt = ".d.o"

sourceExts, moduleExts, objectExts :: [String]
sourceExts = [curryExt,lcurryExt]
moduleExts = sourceExts ++ [icurryExt]
objectExts = [oExt]

{-
  The following functions compute the name of the target file (e.g.
  interface file, flat curry file etc.)
  for a source module. Note that
  output files are always created in the same directory as the source
  file.
-}

interfName :: FilePath -> FilePath
interfName sfn = replaceExtension sfn icurryExt


flatName :: FilePath -> FilePath
flatName fn = replaceExtension fn flatExt

extFlatName :: FilePath -> FilePath
extFlatName fn = replaceExtension fn extFlatExt

flatIntName :: FilePath -> FilePath
flatIntName fn = replaceExtension fn flatIntExt

xmlName :: FilePath -> FilePath
xmlName fn = replaceExtension fn xmlExt

acyName :: FilePath -> FilePath
acyName fn = replaceExtension fn acyExt

uacyName :: FilePath -> FilePath
uacyName fn = replaceExtension fn uacyExt

sourceRepName :: FilePath -> FilePath
sourceRepName fn = replaceExtension fn sourceRepExt

objectName :: Bool -> FilePath -> FilePath
objectName debug = name (if debug then debugExt else oExt)
    where name ext fn = replaceExtension fn ext