{-# OPTIONS_GHC -Wno-orphans #-} -- Outputable, Binary
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveDataTypeable #-}

-- | Fixity
module GHC.Hs.Basic
   ( module Language.Haskell.Syntax.Basic
   ) where

import GHC.Prelude

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

import Data.Data ()

import Language.Haskell.Syntax.Basic

instance Outputable LexicalFixity where
  ppr :: LexicalFixity -> SDoc
ppr LexicalFixity
Prefix = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Prefix"
  ppr LexicalFixity
Infix  = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Infix"

instance Outputable FixityDirection where
    ppr :: FixityDirection -> SDoc
ppr FixityDirection
InfixL = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"infixl"
    ppr FixityDirection
InfixR = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"infixr"
    ppr FixityDirection
InfixN = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"infix"

instance Outputable Fixity where
    ppr :: Fixity -> SDoc
ppr (Fixity Int
prec FixityDirection
dir) = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hcat [FixityDirection -> SDoc
forall a. Outputable a => a -> SDoc
ppr FixityDirection
dir, SDoc
forall doc. IsLine doc => doc
space, Int -> SDoc
forall doc. IsLine doc => Int -> doc
int Int
prec]


instance Binary Fixity where
    put_ :: WriteBinHandle -> Fixity -> IO ()
put_ WriteBinHandle
bh (Fixity Int
aa FixityDirection
ab) = do
            WriteBinHandle -> Int -> IO ()
forall a. Binary a => WriteBinHandle -> a -> IO ()
put_ WriteBinHandle
bh Int
aa
            WriteBinHandle -> FixityDirection -> IO ()
forall a. Binary a => WriteBinHandle -> a -> IO ()
put_ WriteBinHandle
bh FixityDirection
ab
    get :: ReadBinHandle -> IO Fixity
get ReadBinHandle
bh = do
          aa <- ReadBinHandle -> IO Int
forall a. Binary a => ReadBinHandle -> IO a
get ReadBinHandle
bh
          ab <- get bh
          return (Fixity aa ab)

------------------------

instance Binary FixityDirection where
    put_ :: WriteBinHandle -> FixityDirection -> IO ()
put_ WriteBinHandle
bh FixityDirection
InfixL =
            WriteBinHandle -> Word8 -> IO ()
putByte WriteBinHandle
bh Word8
0
    put_ WriteBinHandle
bh FixityDirection
InfixR =
            WriteBinHandle -> Word8 -> IO ()
putByte WriteBinHandle
bh Word8
1
    put_ WriteBinHandle
bh FixityDirection
InfixN =
            WriteBinHandle -> Word8 -> IO ()
putByte WriteBinHandle
bh Word8
2
    get :: ReadBinHandle -> IO FixityDirection
get ReadBinHandle
bh = do
            h <- ReadBinHandle -> IO Word8
getByte ReadBinHandle
bh
            case h of
              Word8
0 -> FixityDirection -> IO FixityDirection
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return FixityDirection
InfixL
              Word8
1 -> FixityDirection -> IO FixityDirection
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return FixityDirection
InfixR
              Word8
_ -> FixityDirection -> IO FixityDirection
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return FixityDirection
InfixN