module Data.GI.CodeGen.Properties
( genInterfaceProperties
, genObjectProperties
, genNamespacedPropLabels
) where
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative ((<$>))
#endif
import Control.Monad (forM_, when, unless)
#if !MIN_VERSION_base(4,11,0)
import Data.Monoid ((<>))
#endif
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Set as S
import Foreign.C.Types (CInt, CUInt)
import Foreign.Storable (sizeOf)
import Data.GI.CodeGen.API
import Data.GI.CodeGen.Conversions
import Data.GI.CodeGen.Code
import Data.GI.CodeGen.GObject
import Data.GI.CodeGen.Haddock (addSectionDocumentation, writeHaddock,
RelativeDocPosition(DocBeforeSymbol))
import Data.GI.CodeGen.Inheritance (fullObjectPropertyList, fullInterfacePropertyList)
import Data.GI.CodeGen.ModulePath (dotModulePath)
import Data.GI.CodeGen.SymbolNaming (lowerName, upperName, classConstraint,
hyphensToCamelCase, qualifiedSymbol,
typeConstraint, callbackDynamicWrapper,
callbackHaskellToForeign,
callbackWrapperAllocator, safeCast,
hackageModuleLink, moduleLocation,
haddockAttrAnchor)
import Data.GI.CodeGen.Type
import Data.GI.CodeGen.Util
propTypeStr :: Type -> ExcCodeGen Text
propTypeStr :: Type -> ExcCodeGen Text
propTypeStr Type
t = case Type
t of
TBasicType BasicType
TUTF8 -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"String"
TBasicType BasicType
TFileName -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"String"
TBasicType BasicType
TPtr -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Ptr"
Type
TByteArray -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"ByteArray"
TGHash Type
_ Type
_ -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Hash"
Type
TVariant -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Variant"
Type
TParamSpec -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"ParamSpec"
TGClosure Maybe Type
_ -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Closure"
Type
TError -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"GError"
Type
TGValue -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"GValue"
TBasicType BasicType
TInt -> case CInt -> Int
forall a. Storable a => a -> Int
sizeOf (CInt
0 :: CInt) of
Int
4 -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Int32"
Int
n -> [Char] -> ExcCodeGen Text
forall a. HasCallStack => [Char] -> a
error ([Char]
"Unsupported `gint' type length: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n)
TBasicType BasicType
TUInt -> case CUInt -> Int
forall a. Storable a => a -> Int
sizeOf (CUInt
0 :: CUInt) of
Int
4 -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"UInt32"
Int
n -> [Char] -> ExcCodeGen Text
forall a. HasCallStack => [Char] -> a
error ([Char]
"Unsupported `guint' type length: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n)
TBasicType BasicType
TLong -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Long"
TBasicType BasicType
TULong -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"ULong"
TBasicType BasicType
TInt32 -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Int32"
TBasicType BasicType
TUInt32 -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"UInt32"
TBasicType BasicType
TInt64 -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Int64"
TBasicType BasicType
TUInt64 -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"UInt64"
TBasicType BasicType
TBoolean -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Bool"
TBasicType BasicType
TFloat -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Float"
TBasicType BasicType
TDouble -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Double"
TBasicType BasicType
TGType -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"GType"
TCArray Bool
True Int
_ Int
_ (TBasicType BasicType
TUTF8) -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"StringArray"
TCArray Bool
True Int
_ Int
_ (TBasicType BasicType
TFileName) -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"StringArray"
TGList (TBasicType BasicType
TPtr) -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"PtrGList"
t :: Type
t@(TInterface Name
n) -> do
API
api <- Name -> CodeGen CGError API
forall e. HasCallStack => Name -> CodeGen e API
findAPIByName Name
n
case API
api of
APIEnum Enumeration
_ -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Enum"
APIFlags Flags
_ -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Flags"
APICallback Callback
_ -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Callback"
APIStruct Struct
s -> if Struct -> Bool
structIsBoxed Struct
s
then Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Boxed"
else Text -> ExcCodeGen Text
forall a. Text -> ExcCodeGen a
notImplementedError (Text -> ExcCodeGen Text) -> Text -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Text
"Unboxed struct property : " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Type -> Text
forall a. Show a => a -> Text
tshow Type
t
APIUnion Union
u -> if Union -> Bool
unionIsBoxed Union
u
then Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Boxed"
else Text -> ExcCodeGen Text
forall a. Text -> ExcCodeGen a
notImplementedError (Text -> ExcCodeGen Text) -> Text -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Text
"Unboxed union property : " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Type -> Text
forall a. Show a => a -> Text
tshow Type
t
APIObject Object
o -> do
Bool
isGO <- Type -> CodeGen CGError Bool
forall e. Type -> CodeGen e Bool
isGObject Type
t
if Bool
isGO
then Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Object"
else case (Object -> Maybe Text
objGetValueFunc Object
o, Object -> Maybe Text
objSetValueFunc Object
o) of
(Just Text
_, Just Text
_) -> Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"IsGValueInstance"
(Maybe Text, Maybe Text)
_ -> Text -> ExcCodeGen Text
forall a. Text -> ExcCodeGen a
notImplementedError (Text -> ExcCodeGen Text) -> Text -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Text
"Non-GObject object property without known gvalue_set and/or gvalue_get: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Type -> Text
forall a. Show a => a -> Text
tshow Type
t
APIInterface Interface
_ -> do
Bool
isGO <- Type -> CodeGen CGError Bool
forall e. Type -> CodeGen e Bool
isGObject Type
t
if Bool
isGO
then Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"Object"
else Text -> ExcCodeGen Text
forall a. Text -> ExcCodeGen a
notImplementedError (Text -> ExcCodeGen Text) -> Text -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Text
"Non-GObject interface property : " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Type -> Text
forall a. Show a => a -> Text
tshow Type
t
API
_ -> Text -> ExcCodeGen Text
forall a. Text -> ExcCodeGen a
notImplementedError (Text -> ExcCodeGen Text) -> Text -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Text
"Unknown interface property of type : " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Type -> Text
forall a. Show a => a -> Text
tshow Type
t
Type
_ -> Text -> ExcCodeGen Text
forall a. Text -> ExcCodeGen a
notImplementedError (Text -> ExcCodeGen Text) -> Text -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Text
"Don't know how to handle properties of type " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Type -> Text
forall a. Show a => a -> Text
tshow Type
t
castProp :: Type -> Text -> CodeGen e Text
castProp :: forall e. Type -> Text -> CodeGen e Text
castProp t :: Type
t@(TInterface Name
n) Text
val = do
API
api <- Name -> CodeGen e API
forall e. HasCallStack => Name -> CodeGen e API
findAPIByName Name
n
case API
api of
APIObject Object
o -> do
Bool
isGO <- Type -> CodeGen e Bool
forall e. Type -> CodeGen e Bool
isGObject Type
t
if Bool -> Bool
not Bool
isGO
then case (Object -> Maybe Text
objGetValueFunc Object
o, Object -> Maybe Text
objSetValueFunc Object
o) of
(Just Text
_, Just Text
_) -> do
let val' :: Text
val' = Text -> Text
prime Text
val
Text
cast <- Name -> CodeGen e Text
forall e. Name -> CodeGen e Text
safeCast Name
n
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
val' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" <- " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cast Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
val
Text -> CodeGen e Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
val'
(Maybe Text, Maybe Text)
_ -> Text -> CodeGen e Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
val
else Text -> CodeGen e Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
val
API
_ -> Text -> CodeGen e Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
val
castProp Type
_ Text
val = Text -> CodeGen e Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
val
propSetTypeConstraint :: Type -> CodeGen e Text
propSetTypeConstraint :: forall e. Type -> CodeGen e Text
propSetTypeConstraint (TGClosure Maybe Type
Nothing) =
Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text)
-> Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a b. (a -> b) -> a -> b
$ Text
"(~) " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
parenthesize (TypeRep -> Text
typeShow (Text
"GClosure" Text -> [TypeRep] -> TypeRep
`con` [Text -> TypeRep
con0 Text
"()"]))
propSetTypeConstraint Type
t = do
Bool
isGO <- Type -> CodeGen e Bool
forall e. Type -> CodeGen e Bool
isGObject Type
t
if Bool
isGO
then Type
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall e. Type -> CodeGen e Text
typeConstraint Type
t
else do
Bool
isCallback <- Type -> CodeGen e Bool
forall e. Type -> CodeGen e Bool
typeIsCallback Type
t
Text
hInType <- if Bool
isCallback
then TypeRep -> Text
typeShow (TypeRep -> Text)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
forall e. Type -> CodeGen e TypeRep
foreignType Type
t
else TypeRep -> Text
typeShow (TypeRep -> Text)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
forall e. Type -> CodeGen e TypeRep
haskellType Type
t
Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text)
-> Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a b. (a -> b) -> a -> b
$ Text
"(~) " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if (Char -> Bool) -> Text -> Bool
T.any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ') Text
hInType
then Text -> Text
parenthesize Text
hInType
else Text
hInType
propTransferTypeConstraint :: Type -> CodeGen e Text
propTransferTypeConstraint :: forall e. Type -> CodeGen e Text
propTransferTypeConstraint Type
t = do
Bool
isGO <- Type -> CodeGen e Bool
forall e. Type -> CodeGen e Bool
isGObject Type
t
if Bool
isGO
then Type -> CodeGen e Text
forall e. Type -> CodeGen e Text
typeConstraint Type
t
else do
Text
hInType <- TypeRep -> Text
typeShow (TypeRep -> Text)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
-> CodeGen e Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
forall e. Type -> CodeGen e TypeRep
isoHaskellType Type
t
Text -> CodeGen e Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> CodeGen e Text) -> Text -> CodeGen e Text
forall a b. (a -> b) -> a -> b
$ Text
"(~) " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if (Char -> Bool) -> Text -> Bool
T.any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ') Text
hInType
then Text -> Text
parenthesize Text
hInType
else Text
hInType
propTransferType :: Type -> CodeGen e Text
propTransferType :: forall e. Type -> CodeGen e Text
propTransferType (TGClosure Maybe Type
Nothing) =
Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text)
-> Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a b. (a -> b) -> a -> b
$ TypeRep -> Text
typeShow (Text
"GClosure" Text -> [TypeRep] -> TypeRep
`con` [Text -> TypeRep
con0 Text
"()"])
propTransferType Type
t = do
Bool
isCallback <- Type -> CodeGen e Bool
forall e. Type -> CodeGen e Bool
typeIsCallback Type
t
if Bool
isCallback
then TypeRep -> Text
typeShow (TypeRep -> Text)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
forall e. Type -> CodeGen e TypeRep
foreignType Type
t
else TypeRep -> Text
typeShow (TypeRep -> Text)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
forall e. Type -> CodeGen e TypeRep
haskellType Type
t
genPropTransfer :: Text -> Type -> CodeGen e ()
genPropTransfer :: forall e. Text -> Type -> CodeGen e ()
genPropTransfer Text
var (TGClosure Maybe Type
Nothing) = Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"return " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
var
genPropTransfer Text
var Type
t = do
Bool
isGO <- Type -> CodeGen e Bool
forall e. Type -> CodeGen e Bool
isGObject Type
t
if Bool
isGO
then do
Text
ht <- TypeRep -> Text
typeShow (TypeRep -> Text)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) TypeRep
forall e. Type -> CodeGen e TypeRep
haskellType Type
t
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"unsafeCastTo " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ht Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
var
else case Type
t of
TInterface tn :: Name
tn@(Name Text
_ Text
n) -> do
Bool
isCallback <- Type -> CodeGen e Bool
forall e. Type -> CodeGen e Bool
typeIsCallback Type
t
if Bool -> Bool
not Bool
isCallback
then Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"return " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
var
else do
Text
wrapper <- Text
-> Name
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall e. Text -> Name -> CodeGen e Text
qualifiedSymbol (Text -> Text
callbackHaskellToForeign Text
n) Name
tn
Text
maker <- Text
-> Name
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall e. Text -> Name -> CodeGen e Text
qualifiedSymbol (Text -> Text
callbackWrapperAllocator Text
n) Name
tn
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
maker Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text -> Text
parenthesize (Text
wrapper Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" Nothing " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
var)
Type
_ -> Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"return " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
var
attrType :: Property -> CodeGen e ([Text], Text)
attrType :: forall e. Property -> CodeGen e ([Text], Text)
attrType Property
prop = do
CodeGen e ()
forall e. CodeGen e ()
resetTypeVariableScope
Bool
isCallback <- Type -> CodeGen e Bool
forall e. Type -> CodeGen e Bool
typeIsCallback (Property -> Type
propType Property
prop)
if Bool
isCallback
then do
TypeRep
ftype <- Type -> CodeGen e TypeRep
forall e. Type -> CodeGen e TypeRep
foreignType (Property -> Type
propType Property
prop)
([Text], Text) -> CodeGen e ([Text], Text)
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], TypeRep -> Text
typeShow TypeRep
ftype)
else do
(Text
t,[Text]
constraints) <- Type -> ExposeClosures -> CodeGen e (Text, [Text])
forall e. Type -> ExposeClosures -> CodeGen e (Text, [Text])
argumentType (Property -> Type
propType Property
prop) ExposeClosures
WithoutClosures
([Text], Text) -> CodeGen e ([Text], Text)
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Text]
constraints, Text
t)
setterDoc :: Name -> Property -> Text
setterDoc :: Name -> Property -> Text
setterDoc Name
n Property
prop = [Text] -> Text
T.unlines [
Text
"Set the value of the “@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"@” property."
, Text
"When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to"
, Text
""
, Text
"@"
, Text
"'Data.GI.Base.Attributes.set' " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Name -> Text
lowerName Name
n Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" [ #" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
hPropName Property
prop
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" 'Data.GI.Base.Attributes.:=' value ]"
, Text
"@"]
genPropertySetter :: Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertySetter :: Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertySetter Text
setter Name
n HaddockSection
docSection Property
prop = ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
group (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
([Text]
constraints, Text
t) <- Property -> CodeGen CGError ([Text], Text)
forall e. Property -> CodeGen e ([Text], Text)
attrType Property
prop
Bool
isNullable <- Type -> CodeGen CGError Bool
forall e. Type -> CodeGen e Bool
typeIsNullable (Property -> Type
propType Property
prop)
Bool
isCallback <- Type -> CodeGen CGError Bool
forall e. Type -> CodeGen e Bool
typeIsCallback (Property -> Type
propType Property
prop)
Text
cls <- Name -> ExcCodeGen Text
forall e. Name -> CodeGen e Text
classConstraint Name
n
let constraints' :: [Text]
constraints' = Text
"MonadIO m"Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:(Text
cls Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" o")Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
constraints
Text
tStr <- Type -> ExcCodeGen Text
propTypeStr (Type -> ExcCodeGen Text) -> Type -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Property -> Type
propType Property
prop
RelativeDocPosition -> Text -> ExcCodeGen ()
forall e. RelativeDocPosition -> Text -> CodeGen e ()
writeHaddock RelativeDocPosition
DocBeforeSymbol (Name -> Property -> Text
setterDoc Name
n Property
prop)
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
setter Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" :: (" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
", " [Text]
constraints'
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
") => o -> " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" -> m ()"
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
setter Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" obj val = MIO.liftIO $ do"
ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
indent (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
Text
val' <- Type -> Text -> ExcCodeGen Text
forall e. Type -> Text -> CodeGen e Text
castProp (Property -> Type
propType Property
prop) Text
"val"
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"B.Properties.setObjectProperty" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tStr
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" obj \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if Bool
isNullable Bool -> Bool -> Bool
&& (Bool -> Bool
not Bool
isCallback)
then Text
"\" (Just " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
val' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")"
else Text
"\" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
val'
HaddockSection -> Text -> ExcCodeGen ()
forall e. HaddockSection -> Text -> CodeGen e ()
export HaddockSection
docSection Text
setter
getterDoc :: Name -> Property -> Text
getterDoc :: Name -> Property -> Text
getterDoc Name
n Property
prop = [Text] -> Text
T.unlines [
Text
"Get the value of the “@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"@” property."
, Text
"When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to"
, Text
""
, Text
"@"
, Text
"'Data.GI.Base.Attributes.get' " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Name -> Text
lowerName Name
n Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" #" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
hPropName Property
prop
, Text
"@"]
genPropertyGetter :: Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertyGetter :: Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertyGetter Text
getter Name
n HaddockSection
docSection Property
prop = ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
group (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
Bool
isNullable <- Type -> CodeGen CGError Bool
forall e. Type -> CodeGen e Bool
typeIsNullable (Property -> Type
propType Property
prop)
let isMaybe :: Bool
isMaybe = Bool
isNullable Bool -> Bool -> Bool
&& Property -> Maybe Bool
propReadNullable Property
prop Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
TypeRep
constructorType <- Type -> CodeGen CGError TypeRep
forall e. Type -> CodeGen e TypeRep
isoHaskellType (Property -> Type
propType Property
prop)
Text
tStr <- Type -> ExcCodeGen Text
propTypeStr (Type -> ExcCodeGen Text) -> Type -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Property -> Type
propType Property
prop
Text
cls <- Name -> ExcCodeGen Text
forall e. Name -> CodeGen e Text
classConstraint Name
n
let constraints :: Text
constraints = Text
"(MonadIO m, " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cls Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" o)"
outType :: TypeRep
outType = if Bool
isMaybe
then TypeRep -> TypeRep
maybeT TypeRep
constructorType
else TypeRep
constructorType
returnType :: Text
returnType = TypeRep -> Text
typeShow (TypeRep -> Text) -> TypeRep -> Text
forall a b. (a -> b) -> a -> b
$ Text
"m" Text -> [TypeRep] -> TypeRep
`con` [TypeRep
outType]
getProp :: Text
getProp = if Bool
isNullable Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
isMaybe
then Text
"checkUnexpectedNothing \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
getter
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\" $ B.Properties.getObjectProperty" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tStr
else Text
"B.Properties.getObjectProperty" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tStr
Text
constructorArg <-
if Text
tStr Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"Object", Text
"Boxed"]
then Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ExcCodeGen Text) -> Text -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TypeRep -> Text
typeShow TypeRep
constructorType
else (if Text
tStr Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"Callback"
then do
TypeRep
callbackType <- Type -> CodeGen CGError TypeRep
forall e. Type -> CodeGen e TypeRep
haskellType (Property -> Type
propType Property
prop)
Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ExcCodeGen Text) -> Text -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
callbackDynamicWrapper (TypeRep -> Text
typeShow TypeRep
callbackType)
else Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"")
RelativeDocPosition -> Text -> ExcCodeGen ()
forall e. RelativeDocPosition -> Text -> CodeGen e ()
writeHaddock RelativeDocPosition
DocBeforeSymbol (Name -> Property -> Text
getterDoc Name
n Property
prop)
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
getter Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" :: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
constraints Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
" => o -> " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
returnType
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
getter Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" obj = MIO.liftIO $ " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
getProp
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" obj \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
constructorArg
HaddockSection -> Text -> ExcCodeGen ()
forall e. HaddockSection -> Text -> CodeGen e ()
export HaddockSection
docSection Text
getter
constructorDoc :: Property -> Text
constructorDoc :: Property -> Text
constructorDoc Property
prop = [Text] -> Text
T.unlines [
Text
"Construct a `GValueConstruct` with valid value for the “@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`."
]
genPropertyConstructor :: Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertyConstructor :: Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertyConstructor Text
constructor Name
n HaddockSection
docSection Property
prop = ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
group (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
([Text]
constraints, Text
t) <- Property -> CodeGen CGError ([Text], Text)
forall e. Property -> CodeGen e ([Text], Text)
attrType Property
prop
Text
tStr <- Type -> ExcCodeGen Text
propTypeStr (Type -> ExcCodeGen Text) -> Type -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Property -> Type
propType Property
prop
Bool
isNullable <- Type -> CodeGen CGError Bool
forall e. Type -> CodeGen e Bool
typeIsNullable (Property -> Type
propType Property
prop)
Bool
isCallback <- Type -> CodeGen CGError Bool
forall e. Type -> CodeGen e Bool
typeIsCallback (Property -> Type
propType Property
prop)
Text
cls <- Name -> ExcCodeGen Text
forall e. Name -> CodeGen e Text
classConstraint Name
n
let constraints' :: [Text]
constraints' = (Text
cls Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" o") Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: Text
"MIO.MonadIO m" Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Text]
constraints
pconstraints :: Text
pconstraints = Text -> Text
parenthesize (Text -> [Text] -> Text
T.intercalate Text
", " [Text]
constraints') Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" => "
RelativeDocPosition -> Text -> ExcCodeGen ()
forall e. RelativeDocPosition -> Text -> CodeGen e ()
writeHaddock RelativeDocPosition
DocBeforeSymbol (Property -> Text
constructorDoc Property
prop)
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
constructor Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" :: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
pconstraints
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" -> m (GValueConstruct o)"
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
constructor Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" val = MIO.liftIO $ do"
ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
indent (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
Text
val' <- Type -> Text -> ExcCodeGen Text
forall e. Type -> Text -> CodeGen e Text
castProp (Property -> Type
propType Property
prop) Text
"val"
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"MIO.liftIO $ B.Properties.constructObjectProperty" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tStr
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if Bool
isNullable Bool -> Bool -> Bool
&& (Bool -> Bool
not Bool
isCallback)
then Text
"\" (P.Just " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
val' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")"
else Text
"\" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
val'
HaddockSection -> Text -> ExcCodeGen ()
forall e. HaddockSection -> Text -> CodeGen e ()
export HaddockSection
docSection Text
constructor
clearDoc :: Property -> Text
clearDoc :: Property -> Text
clearDoc Property
prop = [Text] -> Text
T.unlines [
Text
"Set the value of the “@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"@” property to `Nothing`."
, Text
"When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to"
, Text
""
, Text
"@"
, Text
"'Data.GI.Base.Attributes.clear'" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" #" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
hPropName Property
prop
, Text
"@"]
genPropertyClear :: Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertyClear :: Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertyClear Text
clear Name
n HaddockSection
docSection Property
prop = ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
group (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
Text
cls <- Name -> ExcCodeGen Text
forall e. Name -> CodeGen e Text
classConstraint Name
n
let constraints :: [Text]
constraints = [Text
"MonadIO m", Text
cls Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" o"]
Text
tStr <- Type -> ExcCodeGen Text
propTypeStr (Type -> ExcCodeGen Text) -> Type -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ Property -> Type
propType Property
prop
RelativeDocPosition -> Text -> ExcCodeGen ()
forall e. RelativeDocPosition -> Text -> CodeGen e ()
writeHaddock RelativeDocPosition
DocBeforeSymbol (Property -> Text
clearDoc Property
prop)
Text
nothingType <- TypeRep -> Text
typeShow (TypeRep -> Text) -> (TypeRep -> TypeRep) -> TypeRep -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeRep -> TypeRep
maybeT (TypeRep -> Text) -> CodeGen CGError TypeRep -> ExcCodeGen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> CodeGen CGError TypeRep
forall e. Type -> CodeGen e TypeRep
haskellType (Property -> Type
propType Property
prop)
Bool
isCallback <- Type -> CodeGen CGError Bool
forall e. Type -> CodeGen e Bool
typeIsCallback (Property -> Type
propType Property
prop)
let nothing :: Text
nothing = if Bool
isCallback
then Text
"FP.nullFunPtr"
else Text
"(Nothing :: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
nothingType Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")"
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
clear Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" :: (" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
", " [Text]
constraints
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
") => o -> m ()"
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
clear Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" obj = liftIO $ B.Properties.setObjectProperty" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tStr
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" obj \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
nothing
HaddockSection -> Text -> ExcCodeGen ()
forall e. HaddockSection -> Text -> CodeGen e ()
export HaddockSection
docSection Text
clear
hPropName :: Property -> Text
hPropName :: Property -> Text
hPropName = Text -> Text
lcFirst (Text -> Text) -> (Property -> Text) -> Property -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
hyphensToCamelCase (Text -> Text) -> (Property -> Text) -> Property -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Property -> Text
propName
genObjectProperties :: Name -> Object -> CodeGen e ()
genObjectProperties :: forall e. Name -> Object -> CodeGen e ()
genObjectProperties Name
n Object
o = do
Bool
isGO <- Name -> API -> CodeGen e Bool
forall e. Name -> API -> CodeGen e Bool
apiIsGObject Name
n (Object -> API
APIObject Object
o)
Bool -> CodeGen e () -> CodeGen e ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isGO (CodeGen e () -> CodeGen e ()) -> CodeGen e () -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ do
[Text]
allProps <- Name -> Object -> CodeGen e [(Name, Property)]
forall e. Name -> Object -> CodeGen e [(Name, Property)]
fullObjectPropertyList Name
n Object
o CodeGen e [(Name, Property)]
-> ([(Name, Property)]
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) [Text])
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) [Text]
forall a b.
ReaderT CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
-> (a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) b)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
((Name, Property)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text)
-> [(Name, Property)]
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\(Name
owner, Property
prop) -> do
Text
pi <- Name
-> Property
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall e. Name -> Property -> CodeGen e Text
infoType Name
owner Property
prop
Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text)
-> Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a b. (a -> b) -> a -> b
$ Text
"'(\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
hPropName Property
prop
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\", " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
pi Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")")
Name -> [Property] -> [Text] -> CodeGen e ()
forall e. Name -> [Property] -> [Text] -> CodeGen e ()
genProperties Name
n (Object -> [Property]
objProperties Object
o) [Text]
allProps
genInterfaceProperties :: Name -> Interface -> CodeGen e ()
genInterfaceProperties :: forall e. Name -> Interface -> CodeGen e ()
genInterfaceProperties Name
n Interface
iface = do
[Text]
allProps <- Name -> Interface -> CodeGen e [(Name, Property)]
forall e. Name -> Interface -> CodeGen e [(Name, Property)]
fullInterfacePropertyList Name
n Interface
iface CodeGen e [(Name, Property)]
-> ([(Name, Property)]
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) [Text])
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) [Text]
forall a b.
ReaderT CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
-> (a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) b)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
((Name, Property)
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text)
-> [(Name, Property)]
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\(Name
owner, Property
prop) -> do
Text
pi <- Name
-> Property
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall e. Name -> Property -> CodeGen e Text
infoType Name
owner Property
prop
Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text)
-> Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a b. (a -> b) -> a -> b
$ Text
"'(\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
hPropName Property
prop
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\", " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
pi Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")")
Name -> [Property] -> [Text] -> CodeGen e ()
forall e. Name -> [Property] -> [Text] -> CodeGen e ()
genProperties Name
n (Interface -> [Property]
ifProperties Interface
iface) [Text]
allProps
accessorOrUndefined :: Bool -> Text -> Name -> Text -> CodeGen e Text
accessorOrUndefined :: forall e. Bool -> Text -> Name -> Text -> CodeGen e Text
accessorOrUndefined Bool
available Text
accessor owner :: Name
owner@(Name Text
_ Text
on) Text
cName =
if Bool -> Bool
not Bool
available
then Text
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"undefined"
else Text
-> Name
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except e)) Text
forall e. Text -> Name -> CodeGen e Text
qualifiedSymbol (Text
accessor Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
on Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cName) Name
owner
infoType :: Name -> Property -> CodeGen e Text
infoType :: forall e. Name -> Property -> CodeGen e Text
infoType Name
owner Property
prop =
let infoType :: Text
infoType = Name -> Text
upperName Name
owner Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Text -> Text
hyphensToCamelCase (Text -> Text) -> (Property -> Text) -> Property -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Property -> Text
propName) Property
prop
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"PropertyInfo"
in Text -> Name -> CodeGen e Text
forall e. Text -> Name -> CodeGen e Text
qualifiedSymbol Text
infoType Name
owner
genOneProperty :: Name -> Property -> ExcCodeGen ()
genOneProperty :: Name -> Property -> ExcCodeGen ()
genOneProperty Name
owner Property
prop = do
let name :: Text
name = Name -> Text
upperName Name
owner
cName :: Text
cName = (Text -> Text
hyphensToCamelCase (Text -> Text) -> (Property -> Text) -> Property -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Property -> Text
propName) Property
prop
lcAttr :: Text
lcAttr = Text -> Text
lcFirst Text
cName
docSection :: HaddockSection
docSection = NamedSection -> Text -> HaddockSection
NamedSubsection NamedSection
PropertySection Text
lcAttr
pName :: Text
pName = Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cName
flags :: [PropertyFlag]
flags = Property -> [PropertyFlag]
propFlags Property
prop
writable :: Bool
writable = PropertyFlag
PropertyWritable PropertyFlag -> [PropertyFlag] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [PropertyFlag]
flags Bool -> Bool -> Bool
&&
(PropertyFlag
PropertyConstructOnly PropertyFlag -> [PropertyFlag] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [PropertyFlag]
flags)
readable :: Bool
readable = PropertyFlag
PropertyReadable PropertyFlag -> [PropertyFlag] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [PropertyFlag]
flags
constructOnly :: Bool
constructOnly = PropertyFlag
PropertyConstructOnly PropertyFlag -> [PropertyFlag] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [PropertyFlag]
flags
HaddockSection -> Documentation -> ExcCodeGen ()
forall e. HaddockSection -> Documentation -> CodeGen e ()
addSectionDocumentation HaddockSection
docSection (Property -> Documentation
propDoc Property
prop)
Bool -> ExcCodeGen () -> ExcCodeGen ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Property -> Transfer
propTransfer Property
prop Transfer -> Transfer -> Bool
forall a. Eq a => a -> a -> Bool
/= Transfer
TransferNothing) (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$
Text -> ExcCodeGen ()
forall a. Text -> ExcCodeGen a
notImplementedError (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"Property " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
pName
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" has unsupported transfer type "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Transfer -> Text
forall a. Show a => a -> Text
tshow (Property -> Transfer
propTransfer Property
prop)
Bool
isNullable <- Type -> CodeGen CGError Bool
forall e. Type -> CodeGen e Bool
typeIsNullable (Property -> Type
propType Property
prop)
Bool -> ExcCodeGen () -> ExcCodeGen ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bool
readable Bool -> Bool -> Bool
|| Bool
writable Bool -> Bool -> Bool
|| Bool
constructOnly) (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$
Text -> ExcCodeGen ()
forall a. Text -> ExcCodeGen a
notImplementedError (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"Property is not readable, writable, or constructible: "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
forall a. Show a => a -> Text
tshow Text
pName
ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
group (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"-- VVV Prop \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\""
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
" -- Type: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Type -> Text
forall a. Show a => a -> Text
tshow (Property -> Type
propType Property
prop)
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
" -- Flags: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [PropertyFlag] -> Text
forall a. Show a => a -> Text
tshow (Property -> [PropertyFlag]
propFlags Property
prop)
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
" -- Nullable: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Maybe Bool, Maybe Bool) -> Text
forall a. Show a => a -> Text
tshow (Property -> Maybe Bool
propReadNullable Property
prop,
Property -> Maybe Bool
propWriteNullable Property
prop)
Text
getter <- Bool -> Text -> Name -> Text -> ExcCodeGen Text
forall e. Bool -> Text -> Name -> Text -> CodeGen e Text
accessorOrUndefined Bool
readable Text
"get" Name
owner Text
cName
Text
setter <- Bool -> Text -> Name -> Text -> ExcCodeGen Text
forall e. Bool -> Text -> Name -> Text -> CodeGen e Text
accessorOrUndefined Bool
writable Text
"set" Name
owner Text
cName
Text
constructor <- Bool -> Text -> Name -> Text -> ExcCodeGen Text
forall e. Bool -> Text -> Name -> Text -> CodeGen e Text
accessorOrUndefined (Bool
writable Bool -> Bool -> Bool
|| Bool
constructOnly)
Text
"construct" Name
owner Text
cName
Text
clear <- Bool -> Text -> Name -> Text -> ExcCodeGen Text
forall e. Bool -> Text -> Name -> Text -> CodeGen e Text
accessorOrUndefined (Bool
isNullable Bool -> Bool -> Bool
&& Bool
writable Bool -> Bool -> Bool
&&
Property -> Maybe Bool
propWriteNullable Property
prop Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
Text
"clear" Name
owner Text
cName
Bool -> ExcCodeGen () -> ExcCodeGen ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Text
getter Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"undefined") (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertyGetter Text
getter Name
owner HaddockSection
docSection Property
prop
Bool -> ExcCodeGen () -> ExcCodeGen ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Text
setter Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"undefined") (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertySetter Text
setter Name
owner HaddockSection
docSection Property
prop
Bool -> ExcCodeGen () -> ExcCodeGen ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Text
constructor Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"undefined") (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$
Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertyConstructor Text
constructor Name
owner HaddockSection
docSection Property
prop
Bool -> ExcCodeGen () -> ExcCodeGen ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Text
clear Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"undefined") (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text -> Name -> HaddockSection -> Property -> ExcCodeGen ()
genPropertyClear Text
clear Name
owner HaddockSection
docSection Property
prop
Text
outType <- if Bool -> Bool
not Bool
readable
then Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"()"
else do
Text
sOutType <- if Bool
isNullable Bool -> Bool -> Bool
&& Property -> Maybe Bool
propReadNullable Property
prop Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
then TypeRep -> Text
typeShow (TypeRep -> Text) -> (TypeRep -> TypeRep) -> TypeRep -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeRep -> TypeRep
maybeT (TypeRep -> Text) -> CodeGen CGError TypeRep -> ExcCodeGen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> CodeGen CGError TypeRep
forall e. Type -> CodeGen e TypeRep
isoHaskellType (Property -> Type
propType Property
prop)
else TypeRep -> Text
typeShow (TypeRep -> Text) -> CodeGen CGError TypeRep -> ExcCodeGen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> CodeGen CGError TypeRep
forall e. Type -> CodeGen e TypeRep
isoHaskellType (Property -> Type
propType Property
prop)
Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ExcCodeGen Text) -> Text -> ExcCodeGen Text
forall a b. (a -> b) -> a -> b
$ if (Char -> Bool) -> Text -> Bool
T.any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ') Text
sOutType
then Text -> Text
parenthesize Text
sOutType
else Text
sOutType
CPPGuard -> ExcCodeGen () -> ExcCodeGen ()
forall e a. CPPGuard -> CodeGen e a -> CodeGen e a
cppIf CPPGuard
CPPOverloading (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
Text
cls <- Name -> ExcCodeGen Text
forall e. Name -> CodeGen e Text
classConstraint Name
owner
Text
inConstraint <- if Bool
writable Bool -> Bool -> Bool
|| Bool
constructOnly
then Type -> ExcCodeGen Text
forall e. Type -> CodeGen e Text
propSetTypeConstraint (Property -> Type
propType Property
prop)
else Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"(~) ()"
Text
transferConstraint <- if Bool
writable Bool -> Bool -> Bool
|| Bool
constructOnly
then Type -> ExcCodeGen Text
forall e. Type -> CodeGen e Text
propTransferTypeConstraint (Property -> Type
propType Property
prop)
else Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"(~) ()"
Text
transferType <- if Bool
writable Bool -> Bool -> Bool
|| Bool
constructOnly
then Type -> ExcCodeGen Text
forall e. Type -> CodeGen e Text
propTransferType (Property -> Type
propType Property
prop)
else Text -> ExcCodeGen Text
forall a.
a
-> ReaderT
CodeGenConfig (StateT (CGState, ModuleInfo) (Except CGError)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"()"
let allowedOps :: [Text]
allowedOps = (if Bool
writable
then [Text
"'AttrSet", Text
"'AttrConstruct"]
else [])
[Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> (if Bool
constructOnly
then [Text
"'AttrConstruct"]
else [])
[Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> (if Bool
readable
then [Text
"'AttrGet"]
else [])
[Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> (if Bool
isNullable Bool -> Bool -> Bool
&& Property -> Maybe Bool
propWriteNullable Property
prop Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
then [Text
"'AttrClear"]
else [])
Text
it <- Name -> Property -> ExcCodeGen Text
forall e. Name -> Property -> CodeGen e Text
infoType Name
owner Property
prop
HaddockSection -> Text -> ExcCodeGen ()
forall e. HaddockSection -> Text -> CodeGen e ()
export HaddockSection
docSection Text
it
API
api <- Name -> CodeGen CGError API
forall e. HasCallStack => Name -> CodeGen e API
findAPIByName Name
owner
Text
hackageLink <- Name -> ExcCodeGen Text
forall e. Name -> CodeGen e Text
hackageModuleLink Name
owner
let qualifiedAttrName :: Text
qualifiedAttrName = ModulePath -> Text
dotModulePath (Name -> API -> ModulePath
moduleLocation Name
owner API
api)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"." Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
lcAttr
attrInfoURL :: Text
attrInfoURL = Text
hackageLink Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
haddockAttrAnchor Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
lcAttr
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
bline (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"data " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"instance AttrInfo " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" where"
ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
indent (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrAllowedOps " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = '[ " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
", " [Text]
allowedOps Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]"
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrBaseTypeConstraint " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cls
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrSetTypeConstraint " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
inConstraint
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrTransferTypeConstraint " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
transferConstraint
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrTransferType " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
transferType
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrGetType " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
outType
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrLabel " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\""
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrOrigin " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"attrGet = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
getter
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"attrSet = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
setter
if Bool
writable Bool -> Bool -> Bool
|| Bool
constructOnly
then do Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"attrTransfer _ v = do"
ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
indent (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text -> Type -> ExcCodeGen ()
forall e. Text -> Type -> CodeGen e ()
genPropTransfer Text
"v" (Property -> Type
propType Property
prop)
else Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"attrTransfer _ = undefined"
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"attrConstruct = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
constructor
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"attrClear = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
clear
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {"
ExcCodeGen () -> ExcCodeGen ()
forall e a. CodeGen e a -> CodeGen e a
indent (ExcCodeGen () -> ExcCodeGen ()) -> ExcCodeGen () -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ do
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"O.resolvedSymbolName = \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
qualifiedAttrName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\""
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
", O.resolvedSymbolURL = \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
attrInfoURL Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\""
Text -> ExcCodeGen ()
forall e. Text -> CodeGen e ()
line (Text -> ExcCodeGen ()) -> Text -> ExcCodeGen ()
forall a b. (a -> b) -> a -> b
$ Text
"})"
genPlaceholderProperty :: Name -> Property -> CodeGen e ()
genPlaceholderProperty :: forall e. Name -> Property -> CodeGen e ()
genPlaceholderProperty Name
owner Property
prop = do
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"-- XXX Placeholder"
Text
it <- Name -> Property -> CodeGen e Text
forall e. Name -> Property -> CodeGen e Text
infoType Name
owner Property
prop
let cName :: Text
cName = (Text -> Text
hyphensToCamelCase (Text -> Text) -> (Property -> Text) -> Property -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Property -> Text
propName) Property
prop
docSection :: HaddockSection
docSection = NamedSection -> Text -> HaddockSection
NamedSubsection NamedSection
PropertySection (Text -> Text
lcFirst Text
cName)
HaddockSection -> Text -> CodeGen e ()
forall e. HaddockSection -> Text -> CodeGen e ()
export HaddockSection
docSection Text
it
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
bline (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"data " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"instance AttrInfo " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" where"
CodeGen e () -> CodeGen e ()
forall e a. CodeGen e a -> CodeGen e a
indent (CodeGen e () -> CodeGen e ()) -> CodeGen e () -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ do
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrAllowedOps " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = '[]"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrSetTypeConstraint " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = (~) ()"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrTransferTypeConstraint " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = (~) ()"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrTransferType " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = ()"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrBaseTypeConstraint " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = (~) ()"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrGetType " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = ()"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrLabel " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = \"\""
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type AttrOrigin " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
it Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Name -> Text
upperName Name
owner
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"attrGet = undefined"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"attrSet = undefined"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"attrConstruct = undefined"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"attrClear = undefined"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"attrTransfer = undefined"
genProperties :: Name -> [Property] -> [Text] -> CodeGen e ()
genProperties :: forall e. Name -> [Property] -> [Text] -> CodeGen e ()
genProperties Name
n [Property]
ownedProps [Text]
allProps = do
let name :: Text
name = Name -> Text
upperName Name
n
[Property] -> (Property -> CodeGen e ()) -> CodeGen e ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Property]
ownedProps ((Property -> CodeGen e ()) -> CodeGen e ())
-> (Property -> CodeGen e ()) -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ \Property
prop -> do
(CGError -> CodeGen e ()) -> ExcCodeGen () -> CodeGen e ()
forall e a. (CGError -> CodeGen e a) -> ExcCodeGen a -> CodeGen e a
handleCGExc (\CGError
err -> do
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"-- XXX Generation of property \""
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Property -> Text
propName Property
prop Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\" of object \""
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\" failed."
CGError -> CodeGen e ()
forall e. CGError -> CodeGen e ()
printCGError CGError
err
CPPGuard -> CodeGen e () -> CodeGen e ()
forall e a. CPPGuard -> CodeGen e a -> CodeGen e a
cppIf CPPGuard
CPPOverloading (Name -> Property -> CodeGen e ()
forall e. Name -> Property -> CodeGen e ()
genPlaceholderProperty Name
n Property
prop))
(Name -> Property -> ExcCodeGen ()
genOneProperty Name
n Property
prop)
CPPGuard -> CodeGen e () -> CodeGen e ()
forall e a. CPPGuard -> CodeGen e a -> CodeGen e a
cppIf CPPGuard
CPPOverloading (CodeGen e () -> CodeGen e ()) -> CodeGen e () -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ do
let propListType :: Text
propListType = Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"AttributeList"
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"instance O.HasAttributeList " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type instance O.AttributeList " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
propListType
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
"type " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
propListType Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = ('[ "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
", " [Text]
allProps Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"] :: [(Symbol, *)])"
genNamespacedPropLabels :: Name -> [Property] -> [Method] -> CodeGen e ()
genNamespacedPropLabels :: forall e. Name -> [Property] -> [Method] -> CodeGen e ()
genNamespacedPropLabels Name
owner [Property]
props [Method]
methods =
let lName :: Property -> Text
lName = Text -> Text
lcFirst (Text -> Text) -> (Property -> Text) -> Property -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
hyphensToCamelCase (Text -> Text) -> (Property -> Text) -> Property -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Property -> Text
propName
in Name -> [Text] -> [Method] -> CodeGen e ()
forall e. Name -> [Text] -> [Method] -> CodeGen e ()
genNamespacedAttrLabels Name
owner ((Property -> Text) -> [Property] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Property -> Text
lName [Property]
props) [Method]
methods
genNamespacedAttrLabels :: Name -> [Text] -> [Method] -> CodeGen e ()
genNamespacedAttrLabels :: forall e. Name -> [Text] -> [Method] -> CodeGen e ()
genNamespacedAttrLabels Name
owner [Text]
attrNames [Method]
methods = do
let name :: Text
name = Name -> Text
upperName Name
owner
let methodNames :: Set Text
methodNames = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
S.fromList ((Method -> Text) -> [Method] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Name -> Text
lowerName (Name -> Text) -> (Method -> Name) -> Method -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Method -> Name
methodName) [Method]
methods)
filteredAttrs :: [Text]
filteredAttrs = (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.notMember` Set Text
methodNames) [Text]
attrNames
[Text] -> (Text -> CodeGen e ()) -> CodeGen e ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Text]
filteredAttrs ((Text -> CodeGen e ()) -> CodeGen e ())
-> (Text -> CodeGen e ()) -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ \Text
attr -> CodeGen e () -> CodeGen e ()
forall e a. CodeGen e a -> CodeGen e a
group (CodeGen e () -> CodeGen e ()) -> CodeGen e () -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ do
let cName :: Text
cName = Text -> Text
ucFirst Text
attr
labelProxy :: Text
labelProxy = Text -> Text
lcFirst Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cName
docSection :: HaddockSection
docSection = NamedSection -> Text -> HaddockSection
NamedSubsection NamedSection
PropertySection (Text -> Text
lcFirst Text
cName)
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
labelProxy Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" :: AttrLabelProxy \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
lcFirst Text
cName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\""
Text -> CodeGen e ()
forall e. Text -> CodeGen e ()
line (Text -> CodeGen e ()) -> Text -> CodeGen e ()
forall a b. (a -> b) -> a -> b
$ Text
labelProxy Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = AttrLabelProxy"
HaddockSection -> Text -> CodeGen e ()
forall e. HaddockSection -> Text -> CodeGen e ()
export HaddockSection
docSection Text
labelProxy