call-stack-0.2.0/0000755000000000000000000000000013521434276011724 5ustar0000000000000000call-stack-0.2.0/call-stack.cabal0000644000000000000000000000226213521434276014730 0ustar0000000000000000cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.31.0. -- -- see: https://github.com/sol/hpack -- -- hash: ead73de1f27ca13dbc12434ae8a06a86ce7c6fc59801f6807140632fc1e44df8 name: call-stack version: 0.2.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.5.0.0 && <5 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.5.0.0 && <5 , call-stack , nanospec other-modules: Data.CallStackSpec Example Util Paths_call_stack default-language: Haskell2010 call-stack-0.2.0/Setup.lhs0000644000000000000000000000011413521434276013530 0ustar0000000000000000#!/usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain call-stack-0.2.0/LICENSE0000644000000000000000000000206213521434276012731 0ustar0000000000000000Copyright (c) 2016 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.2.0/test/0000755000000000000000000000000013521434276012703 5ustar0000000000000000call-stack-0.2.0/test/Util.hs0000644000000000000000000000175213521434276014161 0ustar0000000000000000{-# LANGUAGE CPP #-} module Util (SrcLoc(..), mapLocations) where #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 call-stack-0.2.0/test/Example.hs0000644000000000000000000000036513521434276014636 0ustar0000000000000000{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ConstraintKinds #-} module Example where import Data.CallStack test :: CallStack test = foo foo :: HasCallStack => CallStack foo = bar bar :: HasCallStack => CallStack bar = callStack call-stack-0.2.0/test/Spec.hs0000644000000000000000000000026713521434276014136 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.2.0/test/Data/0000755000000000000000000000000013521434276013554 5ustar0000000000000000call-stack-0.2.0/test/Data/CallStackSpec.hs0000644000000000000000000000165513521434276016573 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 = 11 , srcLocStartCol = 7 , srcLocEndLine = 11 , srcLocEndCol = 10 } ) , ("foo" , SrcLoc { srcLocPackage = "main" , srcLocModule = "Example" , srcLocFile = "test/Example.hs" , srcLocStartLine = 8 , srcLocStartCol = 8 , srcLocEndLine = 8 , srcLocEndCol = 11 } ) #endif ] call-stack-0.2.0/src/0000755000000000000000000000000013521434276012513 5ustar0000000000000000call-stack-0.2.0/src/Data/0000755000000000000000000000000013521434276013364 5ustar0000000000000000call-stack-0.2.0/src/Data/CallStack.hs0000644000000000000000000000162113521434276015561 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ImplicitParams #-} module Data.CallStack ( HasCallStack , CallStack , SrcLoc(..) , callStack , callSite ) where import Data.Maybe import Data.SrcLoc #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) #else import GHC.Exts (Constraint) type HasCallStack = (() :: Constraint) #endif type CallStack = [(String, SrcLoc)] callStack :: HasCallStack => CallStack #if MIN_VERSION_base(4,9,0) callStack = drop 1 $ GHC.getCallStack GHC.callStack #elif MIN_VERSION_base(4,8,1) callStack = drop 2 $ GHC.getCallStack ?callStack #else callStack = [] #endif callSite :: HasCallStack => Maybe (String, SrcLoc) callSite = listToMaybe (reverse callStack) call-stack-0.2.0/src/Data/SrcLoc.hs0000644000000000000000000000065113521434276015107 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