{-# OPTIONS_HADDOCK hide #-}

-- NOTE: For now, this module is classified "Internal"; however, it may become
-- public in the future. See also
-- https://github.com/well-typed/hs-bindgen/issues/1565.

-- | Datatypes for the 'HsBindgen.Runtime.HasFFIType.HasFFIType' class.
--
-- These datatypes reify all possible values of the
-- 'HsBindgen.Runtime.HasFFIType.FFIType' type. These datatypes are for internal
-- use in the 'HsBindgen.Runtime.HasFFIType.HasFFIType' class, and they are
-- exported for the @hs-bindgen@ package to use. You probably won't need to use
-- these directly, but you might find the datatypes useful as documentation for
-- the 'HsBindgen.Runtime.HasFFIType.HasFFIType' class.
module HsBindgen.Runtime.Internal.FFIType (
    FFIType (..)
  , BasicFFIType (..)
  ) where

-- | A foreign type without newtypes
--
-- This datatype does not restrict itself to valid foreign types. For example,
-- @IO Unit `FunArrow` IO Unit@ is not a valid foreign type, but we can
-- represent it nonetheless. See the discussion on the
-- 'HsBindgen.Runtime.HasFFIType.HasFFIType' class for why this
-- is okay.
--
-- Also, see the "8.4.2 Foreign Types" section of the report for more
-- information about foreign types:
-- <https://www.haskell.org/onlinereport/haskell2010/haskellch8.html#x15-1560008.4.2>
data FFIType =
    -- === Foreign types ===
    FunArrow FFIType FFIType

    -- === Marshallable foreign result types ===
  | Unit
  | IO FFIType

    -- === Marshallable foreign types ===
  | Basic BasicFFIType
  deriving stock (Int -> FFIType -> ShowS
[FFIType] -> ShowS
FFIType -> String
(Int -> FFIType -> ShowS)
-> (FFIType -> String) -> ([FFIType] -> ShowS) -> Show FFIType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FFIType -> ShowS
showsPrec :: Int -> FFIType -> ShowS
$cshow :: FFIType -> String
show :: FFIType -> String
$cshowList :: [FFIType] -> ShowS
showList :: [FFIType] -> ShowS
Show, FFIType -> FFIType -> Bool
(FFIType -> FFIType -> Bool)
-> (FFIType -> FFIType -> Bool) -> Eq FFIType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FFIType -> FFIType -> Bool
== :: FFIType -> FFIType -> Bool
$c/= :: FFIType -> FFIType -> Bool
/= :: FFIType -> FFIType -> Bool
Eq, Eq FFIType
Eq FFIType =>
(FFIType -> FFIType -> Ordering)
-> (FFIType -> FFIType -> Bool)
-> (FFIType -> FFIType -> Bool)
-> (FFIType -> FFIType -> Bool)
-> (FFIType -> FFIType -> Bool)
-> (FFIType -> FFIType -> FFIType)
-> (FFIType -> FFIType -> FFIType)
-> Ord FFIType
FFIType -> FFIType -> Bool
FFIType -> FFIType -> Ordering
FFIType -> FFIType -> FFIType
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
$ccompare :: FFIType -> FFIType -> Ordering
compare :: FFIType -> FFIType -> Ordering
$c< :: FFIType -> FFIType -> Bool
< :: FFIType -> FFIType -> Bool
$c<= :: FFIType -> FFIType -> Bool
<= :: FFIType -> FFIType -> Bool
$c> :: FFIType -> FFIType -> Bool
> :: FFIType -> FFIType -> Bool
$c>= :: FFIType -> FFIType -> Bool
>= :: FFIType -> FFIType -> Bool
$cmax :: FFIType -> FFIType -> FFIType
max :: FFIType -> FFIType -> FFIType
$cmin :: FFIType -> FFIType -> FFIType
min :: FFIType -> FFIType -> FFIType
Ord)

-- | A basic foreign type as described in the "8.4.2
-- Foreign Types" section of the "Haskell 2010 Language" report:
--
-- <https://www.haskell.org/onlinereport/haskell2010/haskellch8.html#x15-1560008.4.2>
data BasicFFIType =
    -- Prelude
    Char
  | Int
  | Double
  | Float
  | Bool
    -- Data.Int
  | Int8
  | Int16
  | Int32
  | Int64
    -- Data.Word
  | Word
  | Word8
  | Word16
  | Word32
  | Word64
    -- Foreign.Ptr
  | Ptr
  | FunPtr
    -- Foreign.StablePtr
  | StablePtr
  deriving stock (Int -> BasicFFIType -> ShowS
[BasicFFIType] -> ShowS
BasicFFIType -> String
(Int -> BasicFFIType -> ShowS)
-> (BasicFFIType -> String)
-> ([BasicFFIType] -> ShowS)
-> Show BasicFFIType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BasicFFIType -> ShowS
showsPrec :: Int -> BasicFFIType -> ShowS
$cshow :: BasicFFIType -> String
show :: BasicFFIType -> String
$cshowList :: [BasicFFIType] -> ShowS
showList :: [BasicFFIType] -> ShowS
Show, BasicFFIType -> BasicFFIType -> Bool
(BasicFFIType -> BasicFFIType -> Bool)
-> (BasicFFIType -> BasicFFIType -> Bool) -> Eq BasicFFIType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BasicFFIType -> BasicFFIType -> Bool
== :: BasicFFIType -> BasicFFIType -> Bool
$c/= :: BasicFFIType -> BasicFFIType -> Bool
/= :: BasicFFIType -> BasicFFIType -> Bool
Eq, Eq BasicFFIType
Eq BasicFFIType =>
(BasicFFIType -> BasicFFIType -> Ordering)
-> (BasicFFIType -> BasicFFIType -> Bool)
-> (BasicFFIType -> BasicFFIType -> Bool)
-> (BasicFFIType -> BasicFFIType -> Bool)
-> (BasicFFIType -> BasicFFIType -> Bool)
-> (BasicFFIType -> BasicFFIType -> BasicFFIType)
-> (BasicFFIType -> BasicFFIType -> BasicFFIType)
-> Ord BasicFFIType
BasicFFIType -> BasicFFIType -> Bool
BasicFFIType -> BasicFFIType -> Ordering
BasicFFIType -> BasicFFIType -> BasicFFIType
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
$ccompare :: BasicFFIType -> BasicFFIType -> Ordering
compare :: BasicFFIType -> BasicFFIType -> Ordering
$c< :: BasicFFIType -> BasicFFIType -> Bool
< :: BasicFFIType -> BasicFFIType -> Bool
$c<= :: BasicFFIType -> BasicFFIType -> Bool
<= :: BasicFFIType -> BasicFFIType -> Bool
$c> :: BasicFFIType -> BasicFFIType -> Bool
> :: BasicFFIType -> BasicFFIType -> Bool
$c>= :: BasicFFIType -> BasicFFIType -> Bool
>= :: BasicFFIType -> BasicFFIType -> Bool
$cmax :: BasicFFIType -> BasicFFIType -> BasicFFIType
max :: BasicFFIType -> BasicFFIType -> BasicFFIType
$cmin :: BasicFFIType -> BasicFFIType -> BasicFFIType
min :: BasicFFIType -> BasicFFIType -> BasicFFIType
Ord, Int -> BasicFFIType
BasicFFIType -> Int
BasicFFIType -> [BasicFFIType]
BasicFFIType -> BasicFFIType
BasicFFIType -> BasicFFIType -> [BasicFFIType]
BasicFFIType -> BasicFFIType -> BasicFFIType -> [BasicFFIType]
(BasicFFIType -> BasicFFIType)
-> (BasicFFIType -> BasicFFIType)
-> (Int -> BasicFFIType)
-> (BasicFFIType -> Int)
-> (BasicFFIType -> [BasicFFIType])
-> (BasicFFIType -> BasicFFIType -> [BasicFFIType])
-> (BasicFFIType -> BasicFFIType -> [BasicFFIType])
-> (BasicFFIType -> BasicFFIType -> BasicFFIType -> [BasicFFIType])
-> Enum BasicFFIType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: BasicFFIType -> BasicFFIType
succ :: BasicFFIType -> BasicFFIType
$cpred :: BasicFFIType -> BasicFFIType
pred :: BasicFFIType -> BasicFFIType
$ctoEnum :: Int -> BasicFFIType
toEnum :: Int -> BasicFFIType
$cfromEnum :: BasicFFIType -> Int
fromEnum :: BasicFFIType -> Int
$cenumFrom :: BasicFFIType -> [BasicFFIType]
enumFrom :: BasicFFIType -> [BasicFFIType]
$cenumFromThen :: BasicFFIType -> BasicFFIType -> [BasicFFIType]
enumFromThen :: BasicFFIType -> BasicFFIType -> [BasicFFIType]
$cenumFromTo :: BasicFFIType -> BasicFFIType -> [BasicFFIType]
enumFromTo :: BasicFFIType -> BasicFFIType -> [BasicFFIType]
$cenumFromThenTo :: BasicFFIType -> BasicFFIType -> BasicFFIType -> [BasicFFIType]
enumFromThenTo :: BasicFFIType -> BasicFFIType -> BasicFFIType -> [BasicFFIType]
Enum, BasicFFIType
BasicFFIType -> BasicFFIType -> Bounded BasicFFIType
forall a. a -> a -> Bounded a
$cminBound :: BasicFFIType
minBound :: BasicFFIType
$cmaxBound :: BasicFFIType
maxBound :: BasicFFIType
Bounded)