{-# LANGUAGE GADTs, ViewPatterns, DataKinds #-}
module GHC.Debugger.Runtime.Term.Key where
import Prelude hiding ((<>))
import GHC
import GHC.Utils.Outputable
import GHC.Runtime.Eval
data TermKey where
FromId :: Id -> TermKey
FromPath :: TermKey -> PathFragment False -> TermKey
FromCustomTerm :: TermKey -> String -> Term -> TermKey
data PathFragment (b :: Bool ) where
PositionalIndex :: Int -> PathFragment b
LabeledField :: Int -> Name -> PathFragment b
deriving instance Eq (PathFragment b)
deriving instance Ord (PathFragment b)
instance Outputable TermKey where
ppr :: TermKey -> SDoc
ppr (FromId Id
i) = Id -> SDoc
forall a. Outputable a => a -> SDoc
ppr Id
i
ppr (FromPath TermKey
_ PathFragment 'False
last_p) = PathFragment 'False -> SDoc
forall a. Outputable a => a -> SDoc
ppr PathFragment 'False
last_p
ppr (FromCustomTerm TermKey
_ String
s Term
_) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
s
instance Outputable (PathFragment b) where
ppr :: PathFragment b -> SDoc
ppr (PositionalIndex Int
i) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"_" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
i
ppr (LabeledField Int
_ Name
n) = Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
n