-- Copyright 2019 Google LLC
--
-- Use of this source code is governed by a BSD-style
-- license that can be found in the LICENSE file or at
-- https://developers.google.com/open-source/licenses/bsd

module GHC.SourceGen.Lit.Internal where

import BasicTypes (SourceText(NoSourceText), FractionalLit(..))
import BasicTypes (IntegralLit(..))
import GHC.Hs.Lit
import GHC.SourceGen.Syntax.Internal

noSourceText :: (SourceText -> a) -> a
noSourceText :: (SourceText -> a) -> a
noSourceText = ((SourceText -> a) -> SourceText -> a
forall a b. (a -> b) -> a -> b
$ SourceText
NoSourceText)

litNeedsParen :: HsLit' -> Bool
-- For now, ignoring cases that only arrive from internal compiler passes.
-- Furthermore, GHC parses primitive numbers like -3.0# without needing parentheses.
-- So we can uniformly ignore this step.
litNeedsParen :: HsLit' -> Bool
litNeedsParen HsLit'
_ = Bool
False

overLitNeedsParen :: HsOverLit' -> Bool
overLitNeedsParen :: HsOverLit' -> Bool
overLitNeedsParen = OverLitVal -> Bool
needs (OverLitVal -> Bool)
-> (HsOverLit' -> OverLitVal) -> HsOverLit' -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsOverLit' -> OverLitVal
forall p. HsOverLit p -> OverLitVal
ol_val
  where
    needs :: OverLitVal -> Bool
needs (HsIntegral IntegralLit
x) = IntegralLit -> Bool
il_neg IntegralLit
x
    needs (HsFractional FractionalLit
x) = FractionalLit -> Bool
fl_neg FractionalLit
x
    needs OverLitVal
_ = Bool
False