{-# LANGUAGE CPP #-}
module GHC.SourceGen.Lit.Internal where
import BasicTypes (SourceText(NoSourceText), FractionalLit(..))
#if MIN_VERSION_ghc(8,4,0)
import BasicTypes (IntegralLit(..))
#endif
import HsLit
import GHC.SourceGen.Syntax.Internal
noSourceText :: (SourceText -> a) -> a
noSourceText = ($ NoSourceText)
litNeedsParen :: HsLit' -> Bool
litNeedsParen _ = False
overLitNeedsParen :: HsOverLit' -> Bool
overLitNeedsParen = needs . ol_val
where
#if MIN_VERSION_ghc(8,4,0)
needs (HsIntegral x) = il_neg x
needs (HsFractional x) = fl_neg x
#else
needs (HsIntegral _ x) = x < 0
needs (HsFractional x) = fl_value x < 0
#endif
needs _ = False