{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998

\section[HsLit]{Abstract syntax: source-language literals}
-}

{-# LANGUAGE CPP, DeriveDataTypeable #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-} -- Note [Pass sensitive types]
                                      -- in module GHC.Hs.PlaceHolder
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeFamilies #-}

module GHC.Hs.Lit where

#include "GhclibHsVersions.h"

import GhcPrelude

import {-# SOURCE #-} GHC.Hs.Expr( HsExpr, pprExpr )
import BasicTypes ( IntegralLit(..),FractionalLit(..),negateIntegralLit,
                    negateFractionalLit,SourceText(..),pprWithSourceText,
                    PprPrec(..), topPrec )
import Type
import Outputable
import FastString
import GHC.Hs.Extension

import Data.ByteString (ByteString)
import Data.Data hiding ( Fixity )

{-
************************************************************************
*                                                                      *
\subsection[HsLit]{Literals}
*                                                                      *
************************************************************************
-}

-- Note [Literal source text] in BasicTypes for SourceText fields in
-- the following
-- Note [Trees that grow] in GHC.Hs.Extension for the Xxxxx fields in the following
-- | Haskell Literal
data HsLit x
  = HsChar (XHsChar x) {- SourceText -} Char
      -- ^ Character
  | HsCharPrim (XHsCharPrim x) {- SourceText -} Char
      -- ^ Unboxed character
  | HsString (XHsString x) {- SourceText -} FastString
      -- ^ String
  | HsStringPrim (XHsStringPrim x) {- SourceText -} ByteString
      -- ^ Packed bytes
  | HsInt (XHsInt x)  IntegralLit
      -- ^ Genuinely an Int; arises from
      -- @TcGenDeriv@, and from TRANSLATION
  | HsIntPrim (XHsIntPrim x) {- SourceText -} Integer
      -- ^ literal @Int#@
  | HsWordPrim (XHsWordPrim x) {- SourceText -} Integer
      -- ^ literal @Word#@
  | HsInt64Prim (XHsInt64Prim x) {- SourceText -} Integer
      -- ^ literal @Int64#@
  | HsWord64Prim (XHsWord64Prim x) {- SourceText -} Integer
      -- ^ literal @Word64#@
  | HsInteger (XHsInteger x) {- SourceText -} Integer Type
      -- ^ Genuinely an integer; arises only
      -- from TRANSLATION (overloaded
      -- literals are done with HsOverLit)
  | HsRat (XHsRat x)  FractionalLit Type
      -- ^ Genuinely a rational; arises only from
      -- TRANSLATION (overloaded literals are
      -- done with HsOverLit)
  | HsFloatPrim (XHsFloatPrim x)   FractionalLit
      -- ^ Unboxed Float
  | HsDoublePrim (XHsDoublePrim x) FractionalLit
      -- ^ Unboxed Double

  | XLit (XXLit x)

type instance XHsChar       (GhcPass _) = SourceText
type instance XHsCharPrim   (GhcPass _) = SourceText
type instance XHsString     (GhcPass _) = SourceText
type instance XHsStringPrim (GhcPass _) = SourceText
type instance XHsInt        (GhcPass _) = NoExtField
type instance XHsIntPrim    (GhcPass _) = SourceText
type instance XHsWordPrim   (GhcPass _) = SourceText
type instance XHsInt64Prim  (GhcPass _) = SourceText
type instance XHsWord64Prim (GhcPass _) = SourceText
type instance XHsInteger    (GhcPass _) = SourceText
type instance XHsRat        (GhcPass _) = NoExtField
type instance XHsFloatPrim  (GhcPass _) = NoExtField
type instance XHsDoublePrim (GhcPass _) = NoExtField
type instance XXLit         (GhcPass _) = NoExtCon

instance Eq (HsLit x) where
  (HsChar XHsChar x
_ Char
x1)       == :: HsLit x -> HsLit x -> Bool
== (HsChar XHsChar x
_ Char
x2)       = Char
x1Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
x2
  (HsCharPrim XHsCharPrim x
_ Char
x1)   == (HsCharPrim XHsCharPrim x
_ Char
x2)   = Char
x1Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
x2
  (HsString XHsString x
_ FastString
x1)     == (HsString XHsString x
_ FastString
x2)     = FastString
x1FastString -> FastString -> Bool
forall a. Eq a => a -> a -> Bool
==FastString
x2
  (HsStringPrim XHsStringPrim x
_ ByteString
x1) == (HsStringPrim XHsStringPrim x
_ ByteString
x2) = ByteString
x1ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
==ByteString
x2
  (HsInt XHsInt x
_ IntegralLit
x1)        == (HsInt XHsInt x
_ IntegralLit
x2)        = IntegralLit
x1IntegralLit -> IntegralLit -> Bool
forall a. Eq a => a -> a -> Bool
==IntegralLit
x2
  (HsIntPrim XHsIntPrim x
_ Integer
x1)    == (HsIntPrim XHsIntPrim x
_ Integer
x2)    = Integer
x1Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
==Integer
x2
  (HsWordPrim XHsWordPrim x
_ Integer
x1)   == (HsWordPrim XHsWordPrim x
_ Integer
x2)   = Integer
x1Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
==Integer
x2
  (HsInt64Prim XHsInt64Prim x
_ Integer
x1)  == (HsInt64Prim XHsInt64Prim x
_ Integer
x2)  = Integer
x1Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
==Integer
x2
  (HsWord64Prim XHsWord64Prim x
_ Integer
x1) == (HsWord64Prim XHsWord64Prim x
_ Integer
x2) = Integer
x1Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
==Integer
x2
  (HsInteger XHsInteger x
_ Integer
x1 Type
_)  == (HsInteger XHsInteger x
_ Integer
x2 Type
_)  = Integer
x1Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
==Integer
x2
  (HsRat XHsRat x
_ FractionalLit
x1 Type
_)      == (HsRat XHsRat x
_ FractionalLit
x2 Type
_)      = FractionalLit
x1FractionalLit -> FractionalLit -> Bool
forall a. Eq a => a -> a -> Bool
==FractionalLit
x2
  (HsFloatPrim XHsFloatPrim x
_ FractionalLit
x1)  == (HsFloatPrim XHsFloatPrim x
_ FractionalLit
x2)  = FractionalLit
x1FractionalLit -> FractionalLit -> Bool
forall a. Eq a => a -> a -> Bool
==FractionalLit
x2
  (HsDoublePrim XHsDoublePrim x
_ FractionalLit
x1) == (HsDoublePrim XHsDoublePrim x
_ FractionalLit
x2) = FractionalLit
x1FractionalLit -> FractionalLit -> Bool
forall a. Eq a => a -> a -> Bool
==FractionalLit
x2
  HsLit x
_                   == HsLit x
_                   = Bool
False

-- | Haskell Overloaded Literal
data HsOverLit p
  = OverLit {
      HsOverLit p -> XOverLit p
ol_ext :: (XOverLit p),
      HsOverLit p -> OverLitVal
ol_val :: OverLitVal,
      HsOverLit p -> HsExpr p
ol_witness :: HsExpr p}         -- Note [Overloaded literal witnesses]

  | XOverLit
      (XXOverLit p)

data OverLitTc
  = OverLitTc {
        OverLitTc -> Bool
ol_rebindable :: Bool, -- Note [ol_rebindable]
        OverLitTc -> Type
ol_type :: Type }
  deriving Typeable OverLitTc
DataType
Constr
Typeable OverLitTc
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> OverLitTc -> c OverLitTc)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c OverLitTc)
-> (OverLitTc -> Constr)
-> (OverLitTc -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c OverLitTc))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OverLitTc))
-> ((forall b. Data b => b -> b) -> OverLitTc -> OverLitTc)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> OverLitTc -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> OverLitTc -> r)
-> (forall u. (forall d. Data d => d -> u) -> OverLitTc -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> OverLitTc -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc)
-> Data OverLitTc
OverLitTc -> DataType
OverLitTc -> Constr
(forall b. Data b => b -> b) -> OverLitTc -> OverLitTc
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OverLitTc -> c OverLitTc
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OverLitTc
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) -> OverLitTc -> u
forall u. (forall d. Data d => d -> u) -> OverLitTc -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitTc -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitTc -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OverLitTc
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OverLitTc -> c OverLitTc
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OverLitTc)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OverLitTc)
$cOverLitTc :: Constr
$tOverLitTc :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc
gmapMp :: (forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc
gmapM :: (forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OverLitTc -> m OverLitTc
gmapQi :: Int -> (forall d. Data d => d -> u) -> OverLitTc -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OverLitTc -> u
gmapQ :: (forall d. Data d => d -> u) -> OverLitTc -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> OverLitTc -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitTc -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitTc -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitTc -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitTc -> r
gmapT :: (forall b. Data b => b -> b) -> OverLitTc -> OverLitTc
$cgmapT :: (forall b. Data b => b -> b) -> OverLitTc -> OverLitTc
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OverLitTc)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OverLitTc)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c OverLitTc)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OverLitTc)
dataTypeOf :: OverLitTc -> DataType
$cdataTypeOf :: OverLitTc -> DataType
toConstr :: OverLitTc -> Constr
$ctoConstr :: OverLitTc -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OverLitTc
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OverLitTc
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OverLitTc -> c OverLitTc
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OverLitTc -> c OverLitTc
$cp1Data :: Typeable OverLitTc
Data

type instance XOverLit GhcPs = NoExtField
type instance XOverLit GhcRn = Bool            -- Note [ol_rebindable]
type instance XOverLit GhcTc = OverLitTc

type instance XXOverLit (GhcPass _) = NoExtCon

-- Note [Literal source text] in BasicTypes for SourceText fields in
-- the following
-- | Overloaded Literal Value
data OverLitVal
  = HsIntegral   !IntegralLit            -- ^ Integer-looking literals;
  | HsFractional !FractionalLit          -- ^ Frac-looking literals
  | HsIsString   !SourceText !FastString -- ^ String-looking literals
  deriving Typeable OverLitVal
DataType
Constr
Typeable OverLitVal
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> OverLitVal -> c OverLitVal)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c OverLitVal)
-> (OverLitVal -> Constr)
-> (OverLitVal -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c OverLitVal))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c OverLitVal))
-> ((forall b. Data b => b -> b) -> OverLitVal -> OverLitVal)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> OverLitVal -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> OverLitVal -> r)
-> (forall u. (forall d. Data d => d -> u) -> OverLitVal -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> OverLitVal -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal)
-> Data OverLitVal
OverLitVal -> DataType
OverLitVal -> Constr
(forall b. Data b => b -> b) -> OverLitVal -> OverLitVal
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OverLitVal -> c OverLitVal
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OverLitVal
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) -> OverLitVal -> u
forall u. (forall d. Data d => d -> u) -> OverLitVal -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitVal -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitVal -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OverLitVal
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OverLitVal -> c OverLitVal
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OverLitVal)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OverLitVal)
$cHsIsString :: Constr
$cHsFractional :: Constr
$cHsIntegral :: Constr
$tOverLitVal :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal
gmapMp :: (forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal
gmapM :: (forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OverLitVal -> m OverLitVal
gmapQi :: Int -> (forall d. Data d => d -> u) -> OverLitVal -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OverLitVal -> u
gmapQ :: (forall d. Data d => d -> u) -> OverLitVal -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> OverLitVal -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitVal -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitVal -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitVal -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OverLitVal -> r
gmapT :: (forall b. Data b => b -> b) -> OverLitVal -> OverLitVal
$cgmapT :: (forall b. Data b => b -> b) -> OverLitVal -> OverLitVal
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OverLitVal)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OverLitVal)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c OverLitVal)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OverLitVal)
dataTypeOf :: OverLitVal -> DataType
$cdataTypeOf :: OverLitVal -> DataType
toConstr :: OverLitVal -> Constr
$ctoConstr :: OverLitVal -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OverLitVal
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OverLitVal
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OverLitVal -> c OverLitVal
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OverLitVal -> c OverLitVal
$cp1Data :: Typeable OverLitVal
Data

negateOverLitVal :: OverLitVal -> OverLitVal
negateOverLitVal :: OverLitVal -> OverLitVal
negateOverLitVal (HsIntegral IntegralLit
i) = IntegralLit -> OverLitVal
HsIntegral (IntegralLit -> IntegralLit
negateIntegralLit IntegralLit
i)
negateOverLitVal (HsFractional FractionalLit
f) = FractionalLit -> OverLitVal
HsFractional (FractionalLit -> FractionalLit
negateFractionalLit FractionalLit
f)
negateOverLitVal OverLitVal
_ = String -> OverLitVal
forall a. String -> a
panic String
"negateOverLitVal: argument is not a number"

overLitType :: HsOverLit GhcTc -> Type
overLitType :: HsOverLit GhcTc -> Type
overLitType (OverLit (OverLitTc _ ty) OverLitVal
_ HsExpr GhcTc
_) = Type
ty
overLitType (XOverLit XXOverLit GhcTc
nec) = NoExtCon -> Type
forall a. NoExtCon -> a
noExtCon XXOverLit GhcTc
NoExtCon
nec

-- | Convert a literal from one index type to another, updating the annotations
-- according to the relevant 'Convertable' instance
convertLit :: (ConvertIdX a b) => HsLit a -> HsLit b
convertLit :: HsLit a -> HsLit b
convertLit (HsChar XHsChar a
a Char
x)       = (XHsChar b -> Char -> HsLit b
forall x. XHsChar x -> Char -> HsLit x
HsChar (XHsChar b -> XHsChar b
forall a b. Convertable a b => a -> b
convert XHsChar a
XHsChar b
a) Char
x)
convertLit (HsCharPrim XHsCharPrim a
a Char
x)   = (XHsCharPrim b -> Char -> HsLit b
forall x. XHsCharPrim x -> Char -> HsLit x
HsCharPrim (XHsCharPrim b -> XHsCharPrim b
forall a b. Convertable a b => a -> b
convert XHsCharPrim a
XHsCharPrim b
a) Char
x)
convertLit (HsString XHsString a
a FastString
x)     = (XHsString b -> FastString -> HsLit b
forall x. XHsString x -> FastString -> HsLit x
HsString (XHsString b -> XHsString b
forall a b. Convertable a b => a -> b
convert XHsString a
XHsString b
a) FastString
x)
convertLit (HsStringPrim XHsStringPrim a
a ByteString
x) = (XHsStringPrim b -> ByteString -> HsLit b
forall x. XHsStringPrim x -> ByteString -> HsLit x
HsStringPrim (XHsStringPrim b -> XHsStringPrim b
forall a b. Convertable a b => a -> b
convert XHsStringPrim a
XHsStringPrim b
a) ByteString
x)
convertLit (HsInt XHsInt a
a IntegralLit
x)        = (XHsInt b -> IntegralLit -> HsLit b
forall x. XHsInt x -> IntegralLit -> HsLit x
HsInt (XHsInt b -> XHsInt b
forall a b. Convertable a b => a -> b
convert XHsInt a
XHsInt b
a) IntegralLit
x)
convertLit (HsIntPrim XHsIntPrim a
a Integer
x)    = (XHsIntPrim b -> Integer -> HsLit b
forall x. XHsIntPrim x -> Integer -> HsLit x
HsIntPrim (XHsIntPrim b -> XHsIntPrim b
forall a b. Convertable a b => a -> b
convert XHsIntPrim a
XHsIntPrim b
a) Integer
x)
convertLit (HsWordPrim XHsWordPrim a
a Integer
x)   = (XHsWordPrim b -> Integer -> HsLit b
forall x. XHsWordPrim x -> Integer -> HsLit x
HsWordPrim (XHsWordPrim b -> XHsWordPrim b
forall a b. Convertable a b => a -> b
convert XHsWordPrim a
XHsWordPrim b
a) Integer
x)
convertLit (HsInt64Prim XHsInt64Prim a
a Integer
x)  = (XHsInt64Prim b -> Integer -> HsLit b
forall x. XHsInt64Prim x -> Integer -> HsLit x
HsInt64Prim (XHsInt64Prim b -> XHsInt64Prim b
forall a b. Convertable a b => a -> b
convert XHsInt64Prim a
XHsInt64Prim b
a) Integer
x)
convertLit (HsWord64Prim XHsWord64Prim a
a Integer
x) = (XHsWord64Prim b -> Integer -> HsLit b
forall x. XHsWord64Prim x -> Integer -> HsLit x
HsWord64Prim (XHsWord64Prim b -> XHsWord64Prim b
forall a b. Convertable a b => a -> b
convert XHsWord64Prim a
XHsWord64Prim b
a) Integer
x)
convertLit (HsInteger XHsInteger a
a Integer
x Type
b)  = (XHsInteger b -> Integer -> Type -> HsLit b
forall x. XHsInteger x -> Integer -> Type -> HsLit x
HsInteger (XHsInteger b -> XHsInteger b
forall a b. Convertable a b => a -> b
convert XHsInteger a
XHsInteger b
a) Integer
x Type
b)
convertLit (HsRat XHsRat a
a FractionalLit
x Type
b)      = (XHsRat b -> FractionalLit -> Type -> HsLit b
forall x. XHsRat x -> FractionalLit -> Type -> HsLit x
HsRat (XHsRat b -> XHsRat b
forall a b. Convertable a b => a -> b
convert XHsRat a
XHsRat b
a) FractionalLit
x Type
b)
convertLit (HsFloatPrim XHsFloatPrim a
a FractionalLit
x)  = (XHsFloatPrim b -> FractionalLit -> HsLit b
forall x. XHsFloatPrim x -> FractionalLit -> HsLit x
HsFloatPrim (XHsFloatPrim b -> XHsFloatPrim b
forall a b. Convertable a b => a -> b
convert XHsFloatPrim a
XHsFloatPrim b
a) FractionalLit
x)
convertLit (HsDoublePrim XHsDoublePrim a
a FractionalLit
x) = (XHsDoublePrim b -> FractionalLit -> HsLit b
forall x. XHsDoublePrim x -> FractionalLit -> HsLit x
HsDoublePrim (XHsDoublePrim b -> XHsDoublePrim b
forall a b. Convertable a b => a -> b
convert XHsDoublePrim a
XHsDoublePrim b
a) FractionalLit
x)
convertLit (XLit XXLit a
a)           = (XXLit b -> HsLit b
forall x. XXLit x -> HsLit x
XLit (XXLit b -> XXLit b
forall a b. Convertable a b => a -> b
convert XXLit a
XXLit b
a))

{-
Note [ol_rebindable]
~~~~~~~~~~~~~~~~~~~~
The ol_rebindable field is True if this literal is actually
using rebindable syntax.  Specifically:

  False iff ol_witness is the standard one
  True  iff ol_witness is non-standard

Equivalently it's True if
  a) RebindableSyntax is on
  b) the witness for fromInteger/fromRational/fromString
     that happens to be in scope isn't the standard one

Note [Overloaded literal witnesses]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Before* type checking, the HsExpr in an HsOverLit is the
name of the coercion function, 'fromInteger' or 'fromRational'.
*After* type checking, it is a witness for the literal, such as
        (fromInteger 3) or lit_78
This witness should replace the literal.

This dual role is unusual, because we're replacing 'fromInteger' with
a call to fromInteger.  Reason: it allows commoning up of the fromInteger
calls, which wouldn't be possible if the desugarer made the application.

The PostTcType in each branch records the type the overload literal is
found to have.
-}

-- Comparison operations are needed when grouping literals
-- for compiling pattern-matching (module MatchLit)
instance (Eq (XXOverLit p)) => Eq (HsOverLit p) where
  (OverLit XOverLit p
_ OverLitVal
val1 HsExpr p
_) == :: HsOverLit p -> HsOverLit p -> Bool
== (OverLit XOverLit p
_ OverLitVal
val2 HsExpr p
_) = OverLitVal
val1 OverLitVal -> OverLitVal -> Bool
forall a. Eq a => a -> a -> Bool
== OverLitVal
val2
  (XOverLit  XXOverLit p
val1)   == (XOverLit  XXOverLit p
val2)   = XXOverLit p
val1 XXOverLit p -> XXOverLit p -> Bool
forall a. Eq a => a -> a -> Bool
== XXOverLit p
val2
  HsOverLit p
_ == HsOverLit p
_ = String -> Bool
forall a. String -> a
panic String
"Eq HsOverLit"

instance Eq OverLitVal where
  (HsIntegral   IntegralLit
i1)   == :: OverLitVal -> OverLitVal -> Bool
== (HsIntegral   IntegralLit
i2)   = IntegralLit
i1 IntegralLit -> IntegralLit -> Bool
forall a. Eq a => a -> a -> Bool
== IntegralLit
i2
  (HsFractional FractionalLit
f1)   == (HsFractional FractionalLit
f2)   = FractionalLit
f1 FractionalLit -> FractionalLit -> Bool
forall a. Eq a => a -> a -> Bool
== FractionalLit
f2
  (HsIsString SourceText
_ FastString
s1)   == (HsIsString SourceText
_ FastString
s2)   = FastString
s1 FastString -> FastString -> Bool
forall a. Eq a => a -> a -> Bool
== FastString
s2
  OverLitVal
_                   == OverLitVal
_                   = Bool
False

instance (Ord (XXOverLit p)) => Ord (HsOverLit p) where
  compare :: HsOverLit p -> HsOverLit p -> Ordering
compare (OverLit XOverLit p
_ OverLitVal
val1 HsExpr p
_) (OverLit XOverLit p
_ OverLitVal
val2 HsExpr p
_) = OverLitVal
val1 OverLitVal -> OverLitVal -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` OverLitVal
val2
  compare (XOverLit  XXOverLit p
val1)   (XOverLit  XXOverLit p
val2)   = XXOverLit p
val1 XXOverLit p -> XXOverLit p -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` XXOverLit p
val2
  compare HsOverLit p
_ HsOverLit p
_ = String -> Ordering
forall a. String -> a
panic String
"Ord HsOverLit"

instance Ord OverLitVal where
  compare :: OverLitVal -> OverLitVal -> Ordering
compare (HsIntegral IntegralLit
i1)     (HsIntegral IntegralLit
i2)     = IntegralLit
i1 IntegralLit -> IntegralLit -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` IntegralLit
i2
  compare (HsIntegral IntegralLit
_)      (HsFractional FractionalLit
_)    = Ordering
LT
  compare (HsIntegral IntegralLit
_)      (HsIsString SourceText
_ FastString
_)    = Ordering
LT
  compare (HsFractional FractionalLit
f1)   (HsFractional FractionalLit
f2)   = FractionalLit
f1 FractionalLit -> FractionalLit -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` FractionalLit
f2
  compare (HsFractional FractionalLit
_)    (HsIntegral   IntegralLit
_)    = Ordering
GT
  compare (HsFractional FractionalLit
_)    (HsIsString SourceText
_ FastString
_)    = Ordering
LT
  compare (HsIsString SourceText
_ FastString
s1)   (HsIsString SourceText
_ FastString
s2)   = FastString
s1 FastString -> FastString -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` FastString
s2
  compare (HsIsString SourceText
_ FastString
_)    (HsIntegral   IntegralLit
_)    = Ordering
GT
  compare (HsIsString SourceText
_ FastString
_)    (HsFractional FractionalLit
_)    = Ordering
GT

-- Instance specific to GhcPs, need the SourceText
instance Outputable (HsLit (GhcPass p)) where
    ppr :: HsLit (GhcPass p) -> SDoc
ppr (HsChar XHsChar (GhcPass p)
st Char
c)       = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
XHsChar (GhcPass p)
st (Char -> SDoc
pprHsChar Char
c)
    ppr (HsCharPrim XHsCharPrim (GhcPass p)
st Char
c)   = SourceText -> SDoc -> SDoc -> SDoc
pp_st_suffix SourceText
XHsCharPrim (GhcPass p)
st SDoc
primCharSuffix (Char -> SDoc
pprPrimChar Char
c)
    ppr (HsString XHsString (GhcPass p)
st FastString
s)     = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
XHsString (GhcPass p)
st (FastString -> SDoc
pprHsString FastString
s)
    ppr (HsStringPrim XHsStringPrim (GhcPass p)
st ByteString
s) = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
XHsStringPrim (GhcPass p)
st (ByteString -> SDoc
pprHsBytes ByteString
s)
    ppr (HsInt XHsInt (GhcPass p)
_ IntegralLit
i)
      = SourceText -> SDoc -> SDoc
pprWithSourceText (IntegralLit -> SourceText
il_text IntegralLit
i) (Integer -> SDoc
integer (IntegralLit -> Integer
il_value IntegralLit
i))
    ppr (HsInteger XHsInteger (GhcPass p)
st Integer
i Type
_)  = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
XHsInteger (GhcPass p)
st (Integer -> SDoc
integer Integer
i)
    ppr (HsRat XHsRat (GhcPass p)
_ FractionalLit
f Type
_)       = FractionalLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr FractionalLit
f
    ppr (HsFloatPrim XHsFloatPrim (GhcPass p)
_ FractionalLit
f)   = FractionalLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr FractionalLit
f SDoc -> SDoc -> SDoc
<> SDoc
primFloatSuffix
    ppr (HsDoublePrim XHsDoublePrim (GhcPass p)
_ FractionalLit
d)  = FractionalLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr FractionalLit
d SDoc -> SDoc -> SDoc
<> SDoc
primDoubleSuffix
    ppr (HsIntPrim XHsIntPrim (GhcPass p)
st Integer
i)    = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
XHsIntPrim (GhcPass p)
st (Integer -> SDoc
pprPrimInt Integer
i)
    ppr (HsWordPrim XHsWordPrim (GhcPass p)
st Integer
w)   = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
XHsWordPrim (GhcPass p)
st (Integer -> SDoc
pprPrimWord Integer
w)
    ppr (HsInt64Prim XHsInt64Prim (GhcPass p)
st Integer
i)  = SourceText -> SDoc -> SDoc -> SDoc
pp_st_suffix SourceText
XHsInt64Prim (GhcPass p)
st SDoc
primInt64Suffix  (Integer -> SDoc
pprPrimInt64 Integer
i)
    ppr (HsWord64Prim XHsWord64Prim (GhcPass p)
st Integer
w) = SourceText -> SDoc -> SDoc -> SDoc
pp_st_suffix SourceText
XHsWord64Prim (GhcPass p)
st SDoc
primWord64Suffix (Integer -> SDoc
pprPrimWord64 Integer
w)
    ppr (XLit XXLit (GhcPass p)
x) = NoExtCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr XXLit (GhcPass p)
NoExtCon
x

pp_st_suffix :: SourceText -> SDoc -> SDoc -> SDoc
pp_st_suffix :: SourceText -> SDoc -> SDoc -> SDoc
pp_st_suffix SourceText
NoSourceText         SDoc
_ SDoc
doc = SDoc
doc
pp_st_suffix (SourceText String
st) SDoc
suffix SDoc
_   = String -> SDoc
text String
st SDoc -> SDoc -> SDoc
<> SDoc
suffix

-- in debug mode, print the expression that it's resolved to, too
instance OutputableBndrId p
       => Outputable (HsOverLit (GhcPass p)) where
  ppr :: HsOverLit (GhcPass p) -> SDoc
ppr (OverLit {ol_val :: forall p. HsOverLit p -> OverLitVal
ol_val=OverLitVal
val, ol_witness :: forall p. HsOverLit p -> HsExpr p
ol_witness=HsExpr (GhcPass p)
witness})
        = OverLitVal -> SDoc
forall a. Outputable a => a -> SDoc
ppr OverLitVal
val SDoc -> SDoc -> SDoc
<+> (SDoc -> SDoc
whenPprDebug (SDoc -> SDoc
parens (HsExpr (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr HsExpr (GhcPass p)
witness)))
  ppr (XOverLit XXOverLit (GhcPass p)
x) = NoExtCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr XXOverLit (GhcPass p)
NoExtCon
x

instance Outputable OverLitVal where
  ppr :: OverLitVal -> SDoc
ppr (HsIntegral IntegralLit
i)     = SourceText -> SDoc -> SDoc
pprWithSourceText (IntegralLit -> SourceText
il_text IntegralLit
i) (Integer -> SDoc
integer (IntegralLit -> Integer
il_value IntegralLit
i))
  ppr (HsFractional FractionalLit
f)   = FractionalLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr FractionalLit
f
  ppr (HsIsString SourceText
st FastString
s)  = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st (FastString -> SDoc
pprHsString FastString
s)

-- | pmPprHsLit pretty prints literals and is used when pretty printing pattern
-- match warnings. All are printed the same (i.e., without hashes if they are
-- primitive and not wrapped in constructors if they are boxed). This happens
-- mainly for too reasons:
--  * We do not want to expose their internal representation
--  * The warnings become too messy
pmPprHsLit :: HsLit (GhcPass x) -> SDoc
pmPprHsLit :: HsLit (GhcPass x) -> SDoc
pmPprHsLit (HsChar XHsChar (GhcPass x)
_ Char
c)       = Char -> SDoc
pprHsChar Char
c
pmPprHsLit (HsCharPrim XHsCharPrim (GhcPass x)
_ Char
c)   = Char -> SDoc
pprHsChar Char
c
pmPprHsLit (HsString XHsString (GhcPass x)
st FastString
s)    = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
XHsString (GhcPass x)
st (FastString -> SDoc
pprHsString FastString
s)
pmPprHsLit (HsStringPrim XHsStringPrim (GhcPass x)
_ ByteString
s) = ByteString -> SDoc
pprHsBytes ByteString
s
pmPprHsLit (HsInt XHsInt (GhcPass x)
_ IntegralLit
i)        = Integer -> SDoc
integer (IntegralLit -> Integer
il_value IntegralLit
i)
pmPprHsLit (HsIntPrim XHsIntPrim (GhcPass x)
_ Integer
i)    = Integer -> SDoc
integer Integer
i
pmPprHsLit (HsWordPrim XHsWordPrim (GhcPass x)
_ Integer
w)   = Integer -> SDoc
integer Integer
w
pmPprHsLit (HsInt64Prim XHsInt64Prim (GhcPass x)
_ Integer
i)  = Integer -> SDoc
integer Integer
i
pmPprHsLit (HsWord64Prim XHsWord64Prim (GhcPass x)
_ Integer
w) = Integer -> SDoc
integer Integer
w
pmPprHsLit (HsInteger XHsInteger (GhcPass x)
_ Integer
i Type
_)  = Integer -> SDoc
integer Integer
i
pmPprHsLit (HsRat XHsRat (GhcPass x)
_ FractionalLit
f Type
_)      = FractionalLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr FractionalLit
f
pmPprHsLit (HsFloatPrim XHsFloatPrim (GhcPass x)
_ FractionalLit
f)  = FractionalLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr FractionalLit
f
pmPprHsLit (HsDoublePrim XHsDoublePrim (GhcPass x)
_ FractionalLit
d) = FractionalLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr FractionalLit
d
pmPprHsLit (XLit XXLit (GhcPass x)
x)           = NoExtCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr XXLit (GhcPass x)
NoExtCon
x

-- | @'hsLitNeedsParens' p l@ returns 'True' if a literal @l@ needs
-- to be parenthesized under precedence @p@.
hsLitNeedsParens :: PprPrec -> HsLit x -> Bool
hsLitNeedsParens :: PprPrec -> HsLit x -> Bool
hsLitNeedsParens PprPrec
p = HsLit x -> Bool
go
  where
    go :: HsLit x -> Bool
go (HsChar {})        = Bool
False
    go (HsCharPrim {})    = Bool
False
    go (HsString {})      = Bool
False
    go (HsStringPrim {})  = Bool
False
    go (HsInt XHsInt x
_ IntegralLit
x)        = PprPrec
p PprPrec -> PprPrec -> Bool
forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec Bool -> Bool -> Bool
&& IntegralLit -> Bool
il_neg IntegralLit
x
    go (HsIntPrim XHsIntPrim x
_ Integer
x)    = PprPrec
p PprPrec -> PprPrec -> Bool
forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec Bool -> Bool -> Bool
&& Integer
x Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0
    go (HsWordPrim {})    = Bool
False
    go (HsInt64Prim XHsInt64Prim x
_ Integer
x)  = PprPrec
p PprPrec -> PprPrec -> Bool
forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec Bool -> Bool -> Bool
&& Integer
x Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0
    go (HsWord64Prim {})  = Bool
False
    go (HsInteger XHsInteger x
_ Integer
x Type
_)  = PprPrec
p PprPrec -> PprPrec -> Bool
forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec Bool -> Bool -> Bool
&& Integer
x Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0
    go (HsRat XHsRat x
_ FractionalLit
x Type
_)      = PprPrec
p PprPrec -> PprPrec -> Bool
forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec Bool -> Bool -> Bool
&& FractionalLit -> Bool
fl_neg FractionalLit
x
    go (HsFloatPrim XHsFloatPrim x
_ FractionalLit
x)  = PprPrec
p PprPrec -> PprPrec -> Bool
forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec Bool -> Bool -> Bool
&& FractionalLit -> Bool
fl_neg FractionalLit
x
    go (HsDoublePrim XHsDoublePrim x
_ FractionalLit
x) = PprPrec
p PprPrec -> PprPrec -> Bool
forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec Bool -> Bool -> Bool
&& FractionalLit -> Bool
fl_neg FractionalLit
x
    go (XLit XXLit x
_)           = Bool
False

-- | @'hsOverLitNeedsParens' p ol@ returns 'True' if an overloaded literal
-- @ol@ needs to be parenthesized under precedence @p@.
hsOverLitNeedsParens :: PprPrec -> HsOverLit x -> Bool
hsOverLitNeedsParens :: PprPrec -> HsOverLit x -> Bool
hsOverLitNeedsParens PprPrec
p (OverLit { ol_val :: forall p. HsOverLit p -> OverLitVal
ol_val = OverLitVal
olv }) = OverLitVal -> Bool
go OverLitVal
olv
  where
    go :: OverLitVal -> Bool
    go :: OverLitVal -> Bool
go (HsIntegral IntegralLit
x)   = PprPrec
p PprPrec -> PprPrec -> Bool
forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec Bool -> Bool -> Bool
&& IntegralLit -> Bool
il_neg IntegralLit
x
    go (HsFractional FractionalLit
x) = PprPrec
p PprPrec -> PprPrec -> Bool
forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec Bool -> Bool -> Bool
&& FractionalLit -> Bool
fl_neg FractionalLit
x
    go (HsIsString {})  = Bool
False
hsOverLitNeedsParens PprPrec
_ (XOverLit { }) = Bool
False