{-# LANGUAGE CPP #-}
module GHC.Stack.Annotation.Compat.Class (
StackAnnotation(..),
SomeStackAnnotation(..),
CompatAnnotation(..),
) where
#include "macros.h"
import Data.Typeable ( Typeable )
#if defined(SUPPORT_STACK_ANN_SRCLOC)
import GHC.Stack.Annotation.Experimental (StackAnnotation(..), SomeStackAnnotation(..))
import qualified GHC.Stack.Annotation.Experimental as Annotation
#elif defined(SUPPORT_STACK_ANN)
import GHC.Stack.Annotation.Experimental (SomeStackAnnotation(..))
import qualified GHC.Stack.Annotation.Experimental as Annotation
import GHC.Stack (SrcLoc, prettySrcLoc)
#else
import GHC.Stack (SrcLoc, prettySrcLoc)
#endif
#if !defined(SUPPORT_STACK_ANN_LATEST)
class StackAnnotation a where
displayStackAnnotation :: a -> String
stackAnnotationSourceLocation :: a -> Maybe SrcLoc
displayStackAnnotationShort :: a -> String
{-# MINIMAL displayStackAnnotation | displayStackAnnotationShort #-}
displayStackAnnotation a
ann =
a -> String
forall a. StackAnnotation a => a -> String
displayStackAnnotationShort a
ann
String -> String -> String
forall a. [a] -> [a] -> [a]
++ case a -> Maybe SrcLoc
forall a. StackAnnotation a => a -> Maybe SrcLoc
stackAnnotationSourceLocation a
ann of
Maybe SrcLoc
Nothing -> String
""
Just SrcLoc
srcLoc -> String
", called at " String -> String -> String
forall a. [a] -> [a] -> [a]
++ SrcLoc -> String
prettySrcLoc SrcLoc
srcLoc
stackAnnotationSourceLocation a
_ann = Maybe SrcLoc
forall a. Maybe a
Nothing
displayStackAnnotationShort = a -> String
forall a. StackAnnotation a => a -> String
displayStackAnnotation
#endif
#if !defined(SUPPORT_STACK_ANN)
data SomeStackAnnotation where
SomeStackAnnotation :: forall a. (Typeable a, StackAnnotation a) => a -> SomeStackAnnotation
#endif
#if defined(SUPPORT_STACK_ANN_LATEST)
#elif defined(SUPPORT_STACK_ANN_SRCLOC)
instance StackAnnotation SomeStackAnnotation where
displayStackAnnotation (SomeStackAnnotation ann) =
Annotation.displayStackAnnotation ann
stackAnnotationSourceLocation (SomeStackAnnotation ann) =
Annotation.stackAnnotationSourceLocation ann
displayStackAnnotationShort (SomeStackAnnotation ann) =
Annotation.displayStackAnnotationShort ann
#elif defined(SUPPORT_STACK_ANN)
instance StackAnnotation SomeStackAnnotation where
displayStackAnnotation (SomeStackAnnotation ann) =
Annotation.displayStackAnnotation ann
#else
instance StackAnnotation SomeStackAnnotation where
displayStackAnnotation :: SomeStackAnnotation -> String
displayStackAnnotation (SomeStackAnnotation a
ann) =
a -> String
forall a. StackAnnotation a => a -> String
displayStackAnnotation a
ann
stackAnnotationSourceLocation :: SomeStackAnnotation -> Maybe SrcLoc
stackAnnotationSourceLocation (SomeStackAnnotation a
ann) =
a -> Maybe SrcLoc
forall a. StackAnnotation a => a -> Maybe SrcLoc
stackAnnotationSourceLocation a
ann
displayStackAnnotationShort :: SomeStackAnnotation -> String
displayStackAnnotationShort (SomeStackAnnotation a
ann) =
a -> String
forall a. StackAnnotation a => a -> String
displayStackAnnotationShort a
ann
#endif
newtype CompatAnnotation a = CompatAnnotation a
#if defined(SUPPORT_STACK_ANN)
instance (Typeable a, StackAnnotation a) => Annotation.StackAnnotation (CompatAnnotation a) where
displayStackAnnotation (CompatAnnotation a) =
displayStackAnnotation a
#if defined(SUPPORT_STACK_ANN_SRCLOC)
stackAnnotationSourceLocation (CompatAnnotation a) =
stackAnnotationSourceLocation a
displayStackAnnotationShort (CompatAnnotation a) =
displayStackAnnotationShort a
#endif
#endif