call-stack-0.4.0/0000755000000000000000000000000007346545000011722 5ustar0000000000000000call-stack-0.4.0/LICENSE0000644000000000000000000000206707346545000012734 0ustar0000000000000000Copyright (c) 2016-2021 Simon Hengel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. call-stack-0.4.0/Setup.lhs0000644000000000000000000000011407346545000013526 0ustar0000000000000000#!/usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain call-stack-0.4.0/call-stack.cabal0000644000000000000000000000226007346545000014724 0ustar0000000000000000cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack name: call-stack version: 0.4.0 synopsis: Use GHC call-stacks in a backward compatible way category: Data homepage: https://github.com/sol/call-stack#readme bug-reports: https://github.com/sol/call-stack/issues maintainer: Simon Hengel license: MIT license-file: LICENSE build-type: Simple source-repository head type: git location: https://github.com/sol/call-stack library hs-source-dirs: src ghc-options: -Wall build-depends: base ==4.* if os(windows) cpp-options: -DWINDOWS build-depends: filepath exposed-modules: Data.CallStack other-modules: Data.SrcLoc Paths_call_stack default-language: Haskell2010 test-suite spec type: exitcode-stdio-1.0 main-is: Spec.hs hs-source-dirs: test ghc-options: -Wall build-depends: base ==4.* , call-stack , filepath , nanospec other-modules: Data.CallStackSpec Example Util Paths_call_stack default-language: Haskell2010 call-stack-0.4.0/src/Data/0000755000000000000000000000000007346545000013362 5ustar0000000000000000call-stack-0.4.0/src/Data/CallStack.hs0000644000000000000000000000275107346545000015564 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ImplicitParams #-} #if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE ConstraintKinds #-} #define HasCallStack_ HasCallStack => #else #define HasCallStack_ #endif module Data.CallStack ( #if __GLASGOW_HASKELL__ >= 704 HasCallStack, #endif CallStack , SrcLoc(..) , callStack , callSite ) where import Data.Maybe import Data.SrcLoc #ifdef WINDOWS import System.FilePath #endif #if MIN_VERSION_base(4,8,1) import qualified GHC.Stack as GHC #endif #if MIN_VERSION_base(4,9,0) import GHC.Stack (HasCallStack) #elif MIN_VERSION_base(4,8,1) type HasCallStack = (?callStack :: GHC.CallStack) #elif __GLASGOW_HASKELL__ >= 704 import GHC.Exts (Constraint) type HasCallStack = (() :: Constraint) #endif type CallStack = [(String, SrcLoc)] callStack :: HasCallStack_ CallStack callStack = workaroundForIssue19236 $ #if MIN_VERSION_base(4,9,0) drop 1 $ GHC.getCallStack GHC.callStack #elif MIN_VERSION_base(4,8,1) drop 2 $ GHC.getCallStack ?callStack #else [] #endif callSite :: HasCallStack_ Maybe (String, SrcLoc) callSite = listToMaybe (reverse callStack) workaroundForIssue19236 :: CallStack -> CallStack -- https://gitlab.haskell.org/ghc/ghc/-/issues/19236 workaroundForIssue19236 = #ifdef WINDOWS map (fmap fixSrcLoc) where fixSrcLoc :: SrcLoc -> SrcLoc fixSrcLoc loc = loc { srcLocFile = fixPath $ srcLocFile loc } fixPath :: FilePath -> FilePath fixPath = joinPath . splitDirectories #else id #endif call-stack-0.4.0/src/Data/SrcLoc.hs0000644000000000000000000000065107346545000015105 0ustar0000000000000000{-# LANGUAGE CPP #-} module Data.SrcLoc (SrcLoc(..)) where #if MIN_VERSION_base(4,9,0) import GHC.Stack (SrcLoc(..)) #elif MIN_VERSION_base(4,8,1) import GHC.SrcLoc (SrcLoc(..)) #else data SrcLoc = SrcLoc { srcLocPackage :: String , srcLocModule :: String , srcLocFile :: String , srcLocStartLine :: Int , srcLocStartCol :: Int , srcLocEndLine :: Int , srcLocEndCol :: Int } deriving (Eq, Show) #endif call-stack-0.4.0/test/Data/0000755000000000000000000000000007346545000013552 5ustar0000000000000000call-stack-0.4.0/test/Data/CallStackSpec.hs0000644000000000000000000000167307346545000016571 0ustar0000000000000000{-# LANGUAGE CPP #-} module Data.CallStackSpec (spec) where import Test.Hspec import Util import Example spec :: Spec spec = do describe "callStack" $ do it "returns the call stack" $ do mapLocations test `shouldBe` [ #if MIN_VERSION_base(4,8,1) ("bar" , SrcLoc { srcLocPackage = "main" , srcLocModule = "Example" , srcLocFile = "test" "Example.hs" , srcLocStartLine = 18 , srcLocStartCol = 7 , srcLocEndLine = 18 , srcLocEndCol = 10 } ) , ("foo" , SrcLoc { srcLocPackage = "main" , srcLocModule = "Example" , srcLocFile = "test" "Example.hs" , srcLocStartLine = 15 , srcLocStartCol = 8 , srcLocEndLine = 15 , srcLocEndCol = 11 } ) #endif ] call-stack-0.4.0/test/0000755000000000000000000000000007346545000012701 5ustar0000000000000000call-stack-0.4.0/test/Example.hs0000644000000000000000000000054007346545000014627 0ustar0000000000000000{-# LANGUAGE CPP, FlexibleContexts #-} #if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE ConstraintKinds #-} #define HasCallStack_ HasCallStack => #else #define HasCallStack_ #endif module Example where import Data.CallStack test :: CallStack test = foo foo :: HasCallStack_ CallStack foo = bar bar :: HasCallStack_ CallStack bar = callStack call-stack-0.4.0/test/Spec.hs0000644000000000000000000000026707346545000014134 0ustar0000000000000000module Main where import Test.Hspec import qualified Data.CallStackSpec spec :: Spec spec = do describe "Data.CallStack" Data.CallStackSpec.spec main :: IO () main = hspec spec call-stack-0.4.0/test/Util.hs0000644000000000000000000000202307346545000014147 0ustar0000000000000000{-# 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