1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
module Data.GI.CodeGen.GObject
( isGObject
, apiIsGObject
, nameIsGObject
) where
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative ((<$>))
#endif
import Data.GI.CodeGen.API
import Data.GI.CodeGen.Code
import Data.GI.CodeGen.Type
-- Returns whether the given type is a descendant of the given parent.
typeDoParentSearch :: Name -> Type -> CodeGen e Bool
typeDoParentSearch parent (TInterface n) = findAPIByName n >>=
apiDoParentSearch parent n
typeDoParentSearch _ _ = return False
apiDoParentSearch :: Name -> Name -> API -> CodeGen e Bool
apiDoParentSearch parent n api
| parent == n = return True
| otherwise = case api of
APIObject o ->
case objParent o of
Just p -> typeDoParentSearch parent (TInterface p)
Nothing -> return False
APIInterface iface ->
do let prs = ifPrerequisites iface
prereqs <- zip prs <$> mapM findAPIByName prs
or <$> mapM (uncurry (apiDoParentSearch parent)) prereqs
_ -> return False
-- | Check whether the given type descends from GObject.
isGObject :: Type -> CodeGen e Bool
isGObject = typeDoParentSearch $ Name "GObject" "Object"
-- | Check whether the given name descends from GObject.
nameIsGObject :: Name -> CodeGen e Bool
nameIsGObject n = findAPIByName n >>= apiIsGObject n
-- | Check whether the given API descends from GObject.
apiIsGObject :: Name -> API -> CodeGen e Bool
apiIsGObject = apiDoParentSearch $ Name "GObject" "Object"
|