diff --git a/src/Language/C/Clang/Cursor.hs b/src/Language/C/Clang/Cursor.hs index 412241e..628b451 100644 --- a/src/Language/C/Clang/Cursor.hs +++ b/src/Language/C/Clang/Cursor.hs @@ -38,6 +38,11 @@ module Language.C.Clang.Cursor , TypeLayoutError(..) , offsetOfField + , isDefaulted + , isPureVirtual + , isStatic + , isVirtual + , isConst , CursorKind(..) ) where @@ -61,4 +66,4 @@ cursorDescendantsF = cosmosOf cursorChildrenF -- | List a `Cursor` and all of its descendants recursively. cursorDescendants :: Cursor -> [ Cursor ] -cursorDescendants = toListOf cursorDescendantsF \ No newline at end of file +cursorDescendants = toListOf cursorDescendantsF diff --git a/src/Language/C/Clang/Cursor/Typed.hs b/src/Language/C/Clang/Cursor/Typed.hs index c00e927..440b127 100644 --- a/src/Language/C/Clang/Cursor/Typed.hs +++ b/src/Language/C/Clang/Cursor/Typed.hs @@ -33,6 +33,19 @@ module Language.C.Clang.Cursor.Typed , TypeLayoutError(..) , offsetOfField + {-- + , isConvertingConstructor + , isCopyConstructor + , isDefaultConstructor + , isMoveConstructor + , isMutable + --} + , isDefaulted + , isPureVirtual + , isStatic + , isVirtual + , isConst + , HasType , HasChildren , HasExtent @@ -40,6 +53,7 @@ module Language.C.Clang.Cursor.Typed , CursorKind(..) ) where + import qualified Data.ByteString as BS import Data.Functor.Contravariant import Data.Maybe @@ -103,6 +117,38 @@ cursorSpelling = UT.cursorSpelling . withoutKind offsetOfField :: CursorK 'FieldDecl -> Either TypeLayoutError Word64 offsetOfField = UT.offsetOfField . withoutKind +{-- +isConvertingConstructor :: CursorK 'CXXConstructor -> Bool +isConvertingConstructor = UT.isConvertingConstructor . withoutKind + +isCopyConstructor :: CursorK 'CXXConstructor -> Bool +isCopyConstructor = UT.isCopyConstructor . withoutKind + +isDefaultConstructor :: CursorK 'CXXConstructor -> Bool +isDefaultConstructor = UT.isDefaultConstructor . withoutKind + +isMoveConstructor :: CursorK 'CXXConstructor -> Bool +isMoveConstructor = UT.isMoveConstructor . withoutKind + +isMutable :: CursorK 'CXXField -> Bool +isMutable = UT.isMutable . withoutKind +--} + +isDefaulted :: CursorK 'CXXMethod -> Bool +isDefaulted = UT.isDefaulted . withoutKind + +isPureVirtual :: CursorK 'CXXMethod -> Bool +isPureVirtual = UT.isPureVirtual . withoutKind + +isStatic :: CursorK 'CXXMethod -> Bool +isStatic = UT.isStatic . withoutKind + +isVirtual :: CursorK 'CXXMethod -> Bool +isVirtual = UT.isVirtual . withoutKind + +isConst :: CursorK 'CXXMethod -> Bool +isConst = UT.isConst . withoutKind + -- instances derived experimentally with the find-classes executable instance HasChildren 'ArraySubscriptExpr instance HasChildren 'BinaryOperator @@ -303,4 +349,4 @@ instance HasSpelling 'TemplateRef instance HasSpelling 'TranslationUnit instance HasSpelling 'TypeRef instance HasSpelling 'TypedefDecl -instance HasSpelling 'UsingDeclaration \ No newline at end of file +instance HasSpelling 'UsingDeclaration diff --git a/src/Language/C/Clang/Internal/FFI.hsc b/src/Language/C/Clang/Internal/FFI.hsc index a6129a7..f54939b 100644 --- a/src/Language/C/Clang/Internal/FFI.hsc +++ b/src/Language/C/Clang/Internal/FFI.hsc @@ -572,6 +572,12 @@ eitherTypeLayoutErrorOrWord64 n = case n of #{const CXTypeLayoutError_Dependent} -> Left TypeLayoutErrorDependent _ -> Right $ fromIntegral n +boolFromUnsigned :: CUInt -> Bool +boolFromUnsigned n = case n of + 0 -> False + 1 -> True + _ -> True {- XXX NO NO NO -} + typeSizeOf :: Type -> Either TypeLayoutError Word64 typeSizeOf t = uderef t $ \tp -> eitherTypeLayoutErrorOrWord64 <$> @@ -582,6 +588,31 @@ offsetOfField c = uderef c $ \cp -> eitherTypeLayoutErrorOrWord64 <$> [C.exp| long long { clang_Cursor_getOffsetOfField(*$(CXCursor* cp)) } |] +isDefaulted :: Cursor -> Bool +isDefaulted c = uderef c $ \cp -> + boolFromUnsigned <$> + [C.exp| unsigned int { clang_CXXMethod_isDefaulted(*$(CXCursor* cp)) } |] + +isPureVirtual :: Cursor -> Bool +isPureVirtual c = uderef c $ \cp -> + boolFromUnsigned <$> + [C.exp| unsigned int { clang_CXXMethod_isPureVirtual(*$(CXCursor* cp)) } |] + +isStatic :: Cursor -> Bool +isStatic c = uderef c $ \cp -> + boolFromUnsigned <$> + [C.exp| unsigned int { clang_CXXMethod_isStatic(*$(CXCursor* cp)) } |] + +isVirtual :: Cursor -> Bool +isVirtual c = uderef c $ \cp -> + boolFromUnsigned <$> + [C.exp| unsigned int { clang_CXXMethod_isVirtual(*$(CXCursor* cp)) } |] + +isConst :: Cursor -> Bool +isConst c = uderef c $ \cp -> + boolFromUnsigned <$> + [C.exp| unsigned int { clang_CXXMethod_isConst(*$(CXCursor* cp)) } |] + typeSpelling :: Type -> ByteString typeSpelling t = uderef t $ \tp -> withCXString $ \cxsp ->