{-# LANGUAGE StandaloneKindSignatures #-}

module Language.Fortran.Repr.Type.Scalar.Int where

import Language.Fortran.Repr.Type.Scalar.Common

import GHC.Generics ( Generic )
import Data.Data ( Data )
import Data.Binary ( Binary )
import Text.PrettyPrint.GenericPretty ( Out )

-- | The Fortran integer type.
data FTInt
  = FTInt1  -- ^ @INTEGER(1)@
  | FTInt2  -- ^ @INTEGER(2)@
  | FTInt4  -- ^ @INTEGER(4)@
  | FTInt8  -- ^ @INTEGER(8)@
  | FTInt16 -- ^ @INTEGER(16)@
    deriving stock (Int -> FTInt -> ShowS
[FTInt] -> ShowS
FTInt -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FTInt] -> ShowS
$cshowList :: [FTInt] -> ShowS
show :: FTInt -> String
$cshow :: FTInt -> String
showsPrec :: Int -> FTInt -> ShowS
$cshowsPrec :: Int -> FTInt -> ShowS
Show, forall x. Rep FTInt x -> FTInt
forall x. FTInt -> Rep FTInt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FTInt x -> FTInt
$cfrom :: forall x. FTInt -> Rep FTInt x
Generic, Typeable FTInt
FTInt -> DataType
FTInt -> Constr
(forall b. Data b => b -> b) -> FTInt -> FTInt
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) -> FTInt -> u
forall u. (forall d. Data d => d -> u) -> FTInt -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FTInt -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FTInt -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FTInt -> m FTInt
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FTInt -> m FTInt
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FTInt
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FTInt -> c FTInt
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FTInt)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FTInt)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FTInt -> m FTInt
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FTInt -> m FTInt
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FTInt -> m FTInt
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FTInt -> m FTInt
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FTInt -> m FTInt
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FTInt -> m FTInt
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FTInt -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FTInt -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> FTInt -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FTInt -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FTInt -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FTInt -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FTInt -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FTInt -> r
gmapT :: (forall b. Data b => b -> b) -> FTInt -> FTInt
$cgmapT :: (forall b. Data b => b -> b) -> FTInt -> FTInt
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FTInt)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FTInt)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FTInt)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FTInt)
dataTypeOf :: FTInt -> DataType
$cdataTypeOf :: FTInt -> DataType
toConstr :: FTInt -> Constr
$ctoConstr :: FTInt -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FTInt
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FTInt
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FTInt -> c FTInt
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FTInt -> c FTInt
Data, Int -> FTInt
FTInt -> Int
FTInt -> [FTInt]
FTInt -> FTInt
FTInt -> FTInt -> [FTInt]
FTInt -> FTInt -> FTInt -> [FTInt]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: FTInt -> FTInt -> FTInt -> [FTInt]
$cenumFromThenTo :: FTInt -> FTInt -> FTInt -> [FTInt]
enumFromTo :: FTInt -> FTInt -> [FTInt]
$cenumFromTo :: FTInt -> FTInt -> [FTInt]
enumFromThen :: FTInt -> FTInt -> [FTInt]
$cenumFromThen :: FTInt -> FTInt -> [FTInt]
enumFrom :: FTInt -> [FTInt]
$cenumFrom :: FTInt -> [FTInt]
fromEnum :: FTInt -> Int
$cfromEnum :: FTInt -> Int
toEnum :: Int -> FTInt
$ctoEnum :: Int -> FTInt
pred :: FTInt -> FTInt
$cpred :: FTInt -> FTInt
succ :: FTInt -> FTInt
$csucc :: FTInt -> FTInt
Enum, FTInt -> FTInt -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FTInt -> FTInt -> Bool
$c/= :: FTInt -> FTInt -> Bool
== :: FTInt -> FTInt -> Bool
$c== :: FTInt -> FTInt -> Bool
Eq, Eq FTInt
FTInt -> FTInt -> Bool
FTInt -> FTInt -> Ordering
FTInt -> FTInt -> FTInt
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FTInt -> FTInt -> FTInt
$cmin :: FTInt -> FTInt -> FTInt
max :: FTInt -> FTInt -> FTInt
$cmax :: FTInt -> FTInt -> FTInt
>= :: FTInt -> FTInt -> Bool
$c>= :: FTInt -> FTInt -> Bool
> :: FTInt -> FTInt -> Bool
$c> :: FTInt -> FTInt -> Bool
<= :: FTInt -> FTInt -> Bool
$c<= :: FTInt -> FTInt -> Bool
< :: FTInt -> FTInt -> Bool
$c< :: FTInt -> FTInt -> Bool
compare :: FTInt -> FTInt -> Ordering
$ccompare :: FTInt -> FTInt -> Ordering
Ord)
    deriving anyclass (Get FTInt
[FTInt] -> Put
FTInt -> Put
forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
putList :: [FTInt] -> Put
$cputList :: [FTInt] -> Put
get :: Get FTInt
$cget :: Get FTInt
put :: FTInt -> Put
$cput :: FTInt -> Put
Binary, Int -> FTInt -> Doc
[FTInt] -> Doc
FTInt -> Doc
forall a. (Int -> a -> Doc) -> (a -> Doc) -> ([a] -> Doc) -> Out a
docList :: [FTInt] -> Doc
$cdocList :: [FTInt] -> Doc
doc :: FTInt -> Doc
$cdoc :: FTInt -> Doc
docPrec :: Int -> FTInt -> Doc
$cdocPrec :: Int -> FTInt -> Doc
Out)

instance FKind FTInt where
    parseFKind :: FKindLit -> Maybe FTInt
parseFKind = \case FKindLit
1  -> forall a. a -> Maybe a
Just FTInt
FTInt1
                       FKindLit
2  -> forall a. a -> Maybe a
Just FTInt
FTInt2
                       FKindLit
4  -> forall a. a -> Maybe a
Just FTInt
FTInt4
                       FKindLit
8  -> forall a. a -> Maybe a
Just FTInt
FTInt8
                       FKindLit
16 -> forall a. a -> Maybe a
Just FTInt
FTInt16
                       FKindLit
_  -> forall a. Maybe a
Nothing
    printFKind :: FTInt -> FKindLit
printFKind = \case FTInt
FTInt1  -> FKindLit
1
                       FTInt
FTInt2  -> FKindLit
2
                       FTInt
FTInt4  -> FKindLit
4
                       FTInt
FTInt8  -> FKindLit
8
                       FTInt
FTInt16 -> FKindLit
16

type FTIntCombine :: FTInt -> FTInt -> FTInt
type family FTIntCombine k1 k2 where
    FTIntCombine k k = k
    FTIntCombine 'FTInt16 _        = 'FTInt16
    FTIntCombine _        'FTInt16 = 'FTInt16
    FTIntCombine 'FTInt8  _        = 'FTInt8
    FTIntCombine _        'FTInt8  = 'FTInt8
    FTIntCombine 'FTInt4  _        = 'FTInt4
    FTIntCombine _        'FTInt4  = 'FTInt4
    FTIntCombine 'FTInt2  _        = 'FTInt2
    FTIntCombine _        'FTInt2  = 'FTInt2