{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE FlexibleInstances  #-}
{-# LANGUAGE RankNTypes         #-}
module Ide.Plugin.Literals (
    collectLiterals
    , Literal(..)
    , getSrcText
    , getSrcSpan
) where

import           Data.Maybe                    (maybeToList)
import           Data.Text                     (Text)
import qualified Data.Text                     as T
import           Development.IDE.GHC.Compat    hiding (getSrcSpan)
import           Development.IDE.GHC.Util      (unsafePrintSDoc)
import           Development.IDE.Graph.Classes (NFData (rnf))
import qualified GHC.Generics                  as GHC
import           Generics.SYB                  (Data, Typeable, everything,
                                                extQ)

-- data type to capture what type of literal we are dealing with
-- provides location and possibly source text (for OverLits) as well as it's value
-- we currently don't have any use for PrimLiterals. They never have source text so we always drop them
-- | Captures a Numeric Literals Location, Source Text, and Value.
data Literal = IntLiteral  RealSrcSpan Text Integer
             | FracLiteral RealSrcSpan Text Rational
             deriving ((forall x. Literal -> Rep Literal x)
-> (forall x. Rep Literal x -> Literal) -> Generic Literal
forall x. Rep Literal x -> Literal
forall x. Literal -> Rep Literal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Literal x -> Literal
$cfrom :: forall x. Literal -> Rep Literal x
GHC.Generic, Int -> Literal -> ShowS
[Literal] -> ShowS
Literal -> String
(Int -> Literal -> ShowS)
-> (Literal -> String) -> ([Literal] -> ShowS) -> Show Literal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Literal] -> ShowS
$cshowList :: [Literal] -> ShowS
show :: Literal -> String
$cshow :: Literal -> String
showsPrec :: Int -> Literal -> ShowS
$cshowsPrec :: Int -> Literal -> ShowS
Show, Eq Literal
Eq Literal
-> (Literal -> Literal -> Ordering)
-> (Literal -> Literal -> Bool)
-> (Literal -> Literal -> Bool)
-> (Literal -> Literal -> Bool)
-> (Literal -> Literal -> Bool)
-> (Literal -> Literal -> Literal)
-> (Literal -> Literal -> Literal)
-> Ord Literal
Literal -> Literal -> Bool
Literal -> Literal -> Ordering
Literal -> Literal -> Literal
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Literal -> Literal -> Literal
$cmin :: Literal -> Literal -> Literal
max :: Literal -> Literal -> Literal
$cmax :: Literal -> Literal -> Literal
>= :: Literal -> Literal -> Bool
$c>= :: Literal -> Literal -> Bool
> :: Literal -> Literal -> Bool
$c> :: Literal -> Literal -> Bool
<= :: Literal -> Literal -> Bool
$c<= :: Literal -> Literal -> Bool
< :: Literal -> Literal -> Bool
$c< :: Literal -> Literal -> Bool
compare :: Literal -> Literal -> Ordering
$ccompare :: Literal -> Literal -> Ordering
$cp1Ord :: Eq Literal
Ord, Literal -> Literal -> Bool
(Literal -> Literal -> Bool)
-> (Literal -> Literal -> Bool) -> Eq Literal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Literal -> Literal -> Bool
$c/= :: Literal -> Literal -> Bool
== :: Literal -> Literal -> Bool
$c== :: Literal -> Literal -> Bool
Eq, Typeable Literal
DataType
Constr
Typeable Literal
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Literal -> c Literal)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Literal)
-> (Literal -> Constr)
-> (Literal -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Literal))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Literal))
-> ((forall b. Data b => b -> b) -> Literal -> Literal)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Literal -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Literal -> r)
-> (forall u. (forall d. Data d => d -> u) -> Literal -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Literal -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Literal -> m Literal)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Literal -> m Literal)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Literal -> m Literal)
-> Data Literal
Literal -> DataType
Literal -> Constr
(forall b. Data b => b -> b) -> Literal -> Literal
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Literal -> c Literal
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Literal
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Literal -> u
forall u. (forall d. Data d => d -> u) -> Literal -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Literal -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Literal -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Literal -> m Literal
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Literal -> m Literal
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Literal
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Literal -> c Literal
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Literal)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Literal)
$cFracLiteral :: Constr
$cIntLiteral :: Constr
$tLiteral :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Literal -> m Literal
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Literal -> m Literal
gmapMp :: (forall d. Data d => d -> m d) -> Literal -> m Literal
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Literal -> m Literal
gmapM :: (forall d. Data d => d -> m d) -> Literal -> m Literal
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Literal -> m Literal
gmapQi :: Int -> (forall d. Data d => d -> u) -> Literal -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Literal -> u
gmapQ :: (forall d. Data d => d -> u) -> Literal -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Literal -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Literal -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Literal -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Literal -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Literal -> r
gmapT :: (forall b. Data b => b -> b) -> Literal -> Literal
$cgmapT :: (forall b. Data b => b -> b) -> Literal -> Literal
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Literal)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Literal)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Literal)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Literal)
dataTypeOf :: Literal -> DataType
$cdataTypeOf :: Literal -> DataType
toConstr :: Literal -> Constr
$ctoConstr :: Literal -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Literal
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Literal
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Literal -> c Literal
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Literal -> c Literal
$cp1Data :: Typeable Literal
Data)

instance NFData RealSrcSpan where
    rnf :: RealSrcSpan -> ()
rnf RealSrcSpan
x = RealSrcSpan
x RealSrcSpan -> () -> ()
`seq` ()

instance NFData Literal

-- | Return a Literal's Source representation
getSrcText :: Literal -> Text
getSrcText :: Literal -> Text
getSrcText = \case
  IntLiteral RealSrcSpan
_ Text
txt Integer
_  -> Text
txt
  FracLiteral RealSrcSpan
_ Text
txt Rational
_ -> Text
txt

-- | Return a Literal's Real Source location
getSrcSpan :: Literal -> RealSrcSpan
getSrcSpan :: Literal -> RealSrcSpan
getSrcSpan = \case
    IntLiteral RealSrcSpan
ss Text
_ Integer
_  -> RealSrcSpan
ss
    FracLiteral RealSrcSpan
ss Text
_ Rational
_ -> RealSrcSpan
ss

-- | Find all literals in a Parsed Source File
collectLiterals :: (Data ast, Typeable ast) => ast -> [Literal]
collectLiterals :: ast -> [Literal]
collectLiterals = ([Literal] -> [Literal] -> [Literal])
-> GenericQ [Literal] -> GenericQ [Literal]
forall r. (r -> r -> r) -> GenericQ r -> GenericQ r
everything [Literal] -> [Literal] -> [Literal]
forall a. Semigroup a => a -> a -> a
(<>) (Maybe Literal -> [Literal]
forall a. Maybe a -> [a]
maybeToList (Maybe Literal -> [Literal])
-> (a -> Maybe Literal) -> a -> [Literal]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Literal -> a -> Maybe Literal
forall a b. a -> b -> a
const Maybe Literal
forall a. Maybe a
Nothing (a -> Maybe Literal)
-> (GenLocated SrcSpan (HsExpr GhcPs) -> Maybe Literal)
-> a
-> Maybe Literal
forall a b q.
(Typeable a, Typeable b) =>
(a -> q) -> (b -> q) -> a -> q
`extQ` GenLocated SrcSpan (HsExpr GhcPs) -> Maybe Literal
getLiteral (a -> Maybe Literal)
-> (GenLocated SrcSpan (Pat GhcPs) -> Maybe Literal)
-> a
-> Maybe Literal
forall a b q.
(Typeable a, Typeable b) =>
(a -> q) -> (b -> q) -> a -> q
`extQ` GenLocated SrcSpan (Pat GhcPs) -> Maybe Literal
getPattern))

-- | Translate from HsLit and HsOverLit Types to our Literal Type
getLiteral :: GenLocated SrcSpan (HsExpr GhcPs) -> Maybe Literal
getLiteral :: GenLocated SrcSpan (HsExpr GhcPs) -> Maybe Literal
getLiteral (L (UnhelpfulSpan FastString
_) HsExpr GhcPs
_) = Maybe Literal
forall a. Maybe a
Nothing
getLiteral (L (RealSrcSpan RealSrcSpan
sSpan Maybe ()
_ ) HsExpr GhcPs
expr) = case HsExpr GhcPs
expr of
    HsLit XLitE GhcPs
_ HsLit GhcPs
lit         -> HsLit GhcPs -> RealSrcSpan -> Maybe Literal
forall p. HsLit p -> RealSrcSpan -> Maybe Literal
fromLit HsLit GhcPs
lit RealSrcSpan
sSpan
    HsOverLit XOverLitE GhcPs
_ HsOverLit GhcPs
overLit -> HsOverLit GhcPs -> RealSrcSpan -> Maybe Literal
forall p. HsOverLit p -> RealSrcSpan -> Maybe Literal
fromOverLit HsOverLit GhcPs
overLit RealSrcSpan
sSpan
    HsExpr GhcPs
_                   -> Maybe Literal
forall a. Maybe a
Nothing

-- | Destructure Patterns to unwrap any Literals
getPattern :: GenLocated SrcSpan (Pat GhcPs) -> Maybe Literal
getPattern :: GenLocated SrcSpan (Pat GhcPs) -> Maybe Literal
getPattern (L (UnhelpfulSpan FastString
_) Pat GhcPs
_)       = Maybe Literal
forall a. Maybe a
Nothing
getPattern (L (RealSrcSpan RealSrcSpan
patSpan Maybe ()
_) Pat GhcPs
pat) = case Pat GhcPs
pat of
    LitPat XLitPat GhcPs
_ HsLit GhcPs
lit -> case HsLit GhcPs
lit of
        HsInt XHsInt GhcPs
_ IntegralLit
val   -> RealSrcSpan -> IntegralLit -> Maybe Literal
fromIntegralLit RealSrcSpan
patSpan IntegralLit
val
        HsRat XHsRat GhcPs
_ FractionalLit
val Type
_ -> RealSrcSpan -> FractionalLit -> Maybe Literal
fromFractionalLit RealSrcSpan
patSpan FractionalLit
val
        HsLit GhcPs
_             -> Maybe Literal
forall a. Maybe a
Nothing
    NPat XNPat GhcPs
_ (L (RealSrcSpan RealSrcSpan
sSpan Maybe ()
_) HsOverLit GhcPs
overLit) Maybe (SyntaxExpr GhcPs)
_ SyntaxExpr GhcPs
_ -> HsOverLit GhcPs -> RealSrcSpan -> Maybe Literal
forall p. HsOverLit p -> RealSrcSpan -> Maybe Literal
fromOverLit HsOverLit GhcPs
overLit RealSrcSpan
sSpan
    NPlusKPat XNPlusKPat GhcPs
_ Located (IdP GhcPs)
_ (L (RealSrcSpan RealSrcSpan
sSpan Maybe ()
_) HsOverLit GhcPs
overLit1) HsOverLit GhcPs
_ SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_ -> HsOverLit GhcPs -> RealSrcSpan -> Maybe Literal
forall p. HsOverLit p -> RealSrcSpan -> Maybe Literal
fromOverLit HsOverLit GhcPs
overLit1 RealSrcSpan
sSpan
    Pat GhcPs
_ -> Maybe Literal
forall a. Maybe a
Nothing

fromLit :: HsLit p -> RealSrcSpan -> Maybe Literal
fromLit :: HsLit p -> RealSrcSpan -> Maybe Literal
fromLit HsLit p
lit RealSrcSpan
sSpan = case HsLit p
lit of
        HsInt XHsInt p
_ IntegralLit
val   -> RealSrcSpan -> IntegralLit -> Maybe Literal
fromIntegralLit RealSrcSpan
sSpan IntegralLit
val
        HsRat XHsRat p
_ FractionalLit
val Type
_ -> RealSrcSpan -> FractionalLit -> Maybe Literal
fromFractionalLit RealSrcSpan
sSpan FractionalLit
val
        HsLit p
_             -> Maybe Literal
forall a. Maybe a
Nothing

fromOverLit :: HsOverLit p -> RealSrcSpan -> Maybe Literal
fromOverLit :: HsOverLit p -> RealSrcSpan -> Maybe Literal
fromOverLit OverLit{OverLitVal
HsExpr p
XOverLit p
ol_ext :: forall p. HsOverLit p -> XOverLit p
ol_val :: forall p. HsOverLit p -> OverLitVal
ol_witness :: forall p. HsOverLit p -> HsExpr p
ol_witness :: HsExpr p
ol_val :: OverLitVal
ol_ext :: XOverLit p
..} RealSrcSpan
sSpan = case OverLitVal
ol_val of
        HsIntegral IntegralLit
il   -> RealSrcSpan -> IntegralLit -> Maybe Literal
fromIntegralLit RealSrcSpan
sSpan IntegralLit
il
        HsFractional FractionalLit
fl -> RealSrcSpan -> FractionalLit -> Maybe Literal
fromFractionalLit RealSrcSpan
sSpan FractionalLit
fl
        OverLitVal
_               -> Maybe Literal
forall a. Maybe a
Nothing
fromOverLit HsOverLit p
_ RealSrcSpan
_ = Maybe Literal
forall a. Maybe a
Nothing

fromIntegralLit :: RealSrcSpan -> IntegralLit -> Maybe Literal
fromIntegralLit :: RealSrcSpan -> IntegralLit -> Maybe Literal
fromIntegralLit RealSrcSpan
s IL{Bool
Integer
SourceText
il_text :: IntegralLit -> SourceText
il_neg :: IntegralLit -> Bool
il_value :: IntegralLit -> Integer
il_value :: Integer
il_neg :: Bool
il_text :: SourceText
..} = (Text -> Literal) -> Maybe Text -> Maybe Literal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Text
txt' -> RealSrcSpan -> Text -> Integer -> Literal
IntLiteral RealSrcSpan
s Text
txt' Integer
il_value) (SourceText -> Maybe Text
fromSourceText SourceText
il_text)

fromFractionalLit  :: RealSrcSpan -> FractionalLit -> Maybe Literal
fromFractionalLit :: RealSrcSpan -> FractionalLit -> Maybe Literal
fromFractionalLit RealSrcSpan
s FL{Bool
Rational
SourceText
fl_text :: FractionalLit -> SourceText
fl_neg :: FractionalLit -> Bool
fl_value :: FractionalLit -> Rational
fl_value :: Rational
fl_neg :: Bool
fl_text :: SourceText
..} = (Text -> Literal) -> Maybe Text -> Maybe Literal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Text
txt' -> RealSrcSpan -> Text -> Rational -> Literal
FracLiteral RealSrcSpan
s Text
txt' Rational
fl_value) (SourceText -> Maybe Text
fromSourceText SourceText
fl_text)

fromSourceText :: SourceText -> Maybe Text
fromSourceText :: SourceText -> Maybe Text
fromSourceText = \case
  SourceText String
s -> Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
s
  SourceText
NoSourceText -> Maybe Text
forall a. Maybe a
Nothing

-- mostly for debugging purposes
literalToString :: HsLit p -> String
literalToString :: HsLit p -> String
literalToString = \case
  HsChar XHsChar p
_ Char
c        -> String
"Char: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Char -> String
forall a. Show a => a -> String
show Char
c
  HsCharPrim XHsCharPrim p
_ Char
c    -> String
"CharPrim: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Char -> String
forall a. Show a => a -> String
show Char
c
  HsString XHsString p
_ FastString
fs     -> String
"String: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> FastString -> String
forall a. Show a => a -> String
show FastString
fs
  HsStringPrim XHsStringPrim p
_ ByteString
bs -> String
"StringPrim: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ByteString -> String
forall a. Show a => a -> String
show ByteString
bs
  HsInt XHsInt p
_ IntegralLit
il        -> String
"Int: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> IntegralLit -> String
forall a. Show a => a -> String
show IntegralLit
il
  HsIntPrim XHsIntPrim p
_ Integer
n     -> String
"IntPrim: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
n
  HsWordPrim XHsWordPrim p
_ Integer
n    -> String
"WordPrim: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
n
  HsInt64Prim XHsInt64Prim p
_ Integer
n   -> String
"Int64Prim: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
n
  HsWord64Prim XHsWord64Prim p
_ Integer
n  -> String
"Word64Prim: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
n
  HsInteger XHsInteger p
_ Integer
n Type
ty  -> String
"Integer: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
n String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" Type: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Type -> String
tyToLiteral Type
ty
  HsRat XHsRat p
_ FractionalLit
fl Type
ty     -> String
"Rat: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> FractionalLit -> String
forall a. Show a => a -> String
show FractionalLit
fl String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" Type: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Type -> String
tyToLiteral Type
ty
  HsFloatPrim XHsFloatPrim p
_ FractionalLit
fl  -> String
"FloatPrim: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> FractionalLit -> String
forall a. Show a => a -> String
show FractionalLit
fl
  HsDoublePrim XHsDoublePrim p
_ FractionalLit
fl -> String
"DoublePrim: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<>  FractionalLit -> String
forall a. Show a => a -> String
show FractionalLit
fl
  HsLit p
_                 -> String
"XHsLit"
  where
    tyToLiteral :: Type -> String
    tyToLiteral :: Type -> String
tyToLiteral = SDoc -> String
unsafePrintSDoc (SDoc -> String) -> (Type -> SDoc) -> Type -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.  Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr

overLitToString :: OverLitVal -> String
overLitToString :: OverLitVal -> String
overLitToString = \case
     HsIntegral IntegralLit
int -> case IntegralLit
int of { IL{Integer
il_value :: Integer
il_value :: IntegralLit -> Integer
il_value} -> String
"IntegralOverLit: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
il_value}
     HsFractional FractionalLit
frac -> case FractionalLit
frac of { FL{Rational
fl_value :: Rational
fl_value :: FractionalLit -> Rational
fl_value} -> String
"RationalOverLit: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Rational -> String
forall a. Show a => a -> String
show Rational
fl_value}
     HsIsString SourceText
_ FastString
str -> String
"HIsString: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> FastString -> String
forall a. Show a => a -> String
show FastString
str