{-# OPTIONS_GHC -Wno-orphans #-}
module GHC.Hs.Specificity where

import Prelude
import Control.DeepSeq (NFData(..))

import GHC.Utils.Outputable
import GHC.Utils.Binary

import Language.Haskell.Syntax.Specificity

{- *********************************************************************
*                                                                      *
*                   ForAllTyFlag
*                                                                      *
********************************************************************* -}

instance Outputable ForAllTyFlag where
  ppr :: ForAllTyFlag -> SDoc
ppr ForAllTyFlag
Required  = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"[req]"
  ppr ForAllTyFlag
Specified = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"[spec]"
  ppr ForAllTyFlag
Inferred  = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"[infrd]"

instance Binary Specificity where
  put_ :: WriteBinHandle -> Specificity -> IO ()
put_ WriteBinHandle
bh Specificity
SpecifiedSpec = WriteBinHandle -> Word8 -> IO ()
putByte WriteBinHandle
bh Word8
0
  put_ WriteBinHandle
bh Specificity
InferredSpec  = WriteBinHandle -> Word8 -> IO ()
putByte WriteBinHandle
bh Word8
1

  get :: ReadBinHandle -> IO Specificity
get ReadBinHandle
bh = do
    h <- ReadBinHandle -> IO Word8
getByte ReadBinHandle
bh
    case h of
      Word8
0 -> Specificity -> IO Specificity
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Specificity
SpecifiedSpec
      Word8
_ -> Specificity -> IO Specificity
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Specificity
InferredSpec

instance Binary ForAllTyFlag where
  put_ :: WriteBinHandle -> ForAllTyFlag -> IO ()
put_ WriteBinHandle
bh ForAllTyFlag
Required  = WriteBinHandle -> Word8 -> IO ()
putByte WriteBinHandle
bh Word8
0
  put_ WriteBinHandle
bh ForAllTyFlag
Specified = WriteBinHandle -> Word8 -> IO ()
putByte WriteBinHandle
bh Word8
1
  put_ WriteBinHandle
bh ForAllTyFlag
Inferred  = WriteBinHandle -> Word8 -> IO ()
putByte WriteBinHandle
bh Word8
2

  get :: ReadBinHandle -> IO ForAllTyFlag
get ReadBinHandle
bh = do
    h <- ReadBinHandle -> IO Word8
getByte ReadBinHandle
bh
    case h of
      Word8
0 -> ForAllTyFlag -> IO ForAllTyFlag
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ForAllTyFlag
Required
      Word8
1 -> ForAllTyFlag -> IO ForAllTyFlag
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ForAllTyFlag
Specified
      Word8
_ -> ForAllTyFlag -> IO ForAllTyFlag
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ForAllTyFlag
Inferred

instance NFData Specificity where
  rnf :: Specificity -> ()
rnf Specificity
SpecifiedSpec = ()
  rnf Specificity
InferredSpec = ()
instance NFData ForAllTyFlag where
  rnf :: ForAllTyFlag -> ()
rnf (Invisible Specificity
spec) = Specificity -> ()
forall a. NFData a => a -> ()
rnf Specificity
spec
  rnf ForAllTyFlag
Required = ()