Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Language/C/Clang/Cursor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ module Language.C.Clang.Cursor

, TypeLayoutError(..)
, offsetOfField
, isDefaulted
, isPureVirtual
, isStatic
, isVirtual
, isConst
, CursorKind(..)
)
where
Expand All @@ -61,4 +66,4 @@ cursorDescendantsF = cosmosOf cursorChildrenF

-- | List a `Cursor` and all of its descendants recursively.
cursorDescendants :: Cursor -> [ Cursor ]
cursorDescendants = toListOf cursorDescendantsF
cursorDescendants = toListOf cursorDescendantsF
48 changes: 47 additions & 1 deletion src/Language/C/Clang/Cursor/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,27 @@ module Language.C.Clang.Cursor.Typed
, TypeLayoutError(..)
, offsetOfField

{--
, isConvertingConstructor
, isCopyConstructor
, isDefaultConstructor
, isMoveConstructor
, isMutable
--}
, isDefaulted
, isPureVirtual
, isStatic
, isVirtual
, isConst

, HasType
, HasChildren
, HasExtent
, HasSpelling
, CursorKind(..)
) where


import qualified Data.ByteString as BS
import Data.Functor.Contravariant
import Data.Maybe
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -303,4 +349,4 @@ instance HasSpelling 'TemplateRef
instance HasSpelling 'TranslationUnit
instance HasSpelling 'TypeRef
instance HasSpelling 'TypedefDecl
instance HasSpelling 'UsingDeclaration
instance HasSpelling 'UsingDeclaration
31 changes: 31 additions & 0 deletions src/Language/C/Clang/Internal/FFI.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <$>
Expand All @@ -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 ->
Expand Down