1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
{-# LANGUAGE CPP #-}
module Util (SrcLoc(..), mapLocations, (</>)) where
import System.FilePath
#if MIN_VERSION_base(4,8,1) && !MIN_VERSION_base(4,9,0)
import qualified GHC.SrcLoc as GHC
import Data.CallStack hiding (SrcLoc(..))
data SrcLoc = SrcLoc {
srcLocPackage :: String
, srcLocModule :: String
, srcLocFile :: String
, srcLocStartLine :: Int
, srcLocStartCol :: Int
, srcLocEndLine :: Int
, srcLocEndCol :: Int
} deriving (Eq, Show)
mapLocations :: CallStack -> [(String, SrcLoc)]
mapLocations = map (fmap mapLocation)
where
mapLocation location = SrcLoc {
srcLocPackage = GHC.srcLocPackage location
, srcLocModule = GHC.srcLocModule location
, srcLocFile = GHC.srcLocFile location
, srcLocStartLine = GHC.srcLocStartLine location
, srcLocStartCol = GHC.srcLocStartCol location
, srcLocEndLine = GHC.srcLocEndLine location
, srcLocEndCol = GHC.srcLocEndCol location
}
#else
import Data.CallStack
mapLocations :: CallStack -> CallStack
mapLocations = id
#endif
|