Skip to content

Commit

Permalink
Add more top-level API (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisCardwell committed Oct 9, 2024
1 parent 895528f commit 4c7876d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hs-bindgen-libclang/cbits/doxygen_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ static inline enum CXCommentKind wrap_Comment_getKind(const CXComment* Comment)
return clang_Comment_getKind(*Comment);
}

static inline unsigned wrap_Comment_getNumChildren(const CXComment* Comment) {
return clang_Comment_getNumChildren(*Comment);
}

static inline void wrap_Comment_getChild(const CXComment* Comment, unsigned childIdx, CXComment* result) {
*result = clang_Comment_getChild(*Comment, childIdx);
}

static inline unsigned wrap_Comment_isWhitespace(const CXComment* Comment) {
return clang_Comment_isWhitespace(*Comment);
}

static inline unsigned wrap_InlineContentComment_hasTrailingNewline(const CXComment* Comment) {
return clang_InlineContentComment_hasTrailingNewline(*Comment);
}

/**
* Comment type 'CXComment_Text'
*/
Expand Down
63 changes: 63 additions & 0 deletions hs-bindgen-libclang/src/HsBindgen/Clang/Doxygen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module HsBindgen.Clang.Doxygen (
, CXCommentKind(..)
, clang_Cursor_getParsedComment
, clang_Comment_getKind
, clang_Comment_getNumChildren
, clang_Comment_getChild
, clang_Comment_isWhitespace
, clang_InlineContentComment_hasTrailingNewline
-- * Comment type 'CXComment_Text'
, clang_TextComment_getText
-- * Comment type 'CXComment_InlineCommand'
Expand All @@ -35,6 +39,7 @@ import HsBindgen.Clang.Doxygen.Instances ()
import HsBindgen.Clang.Doxygen.Structs
import HsBindgen.Clang.Internal.ByValue
import HsBindgen.Clang.Internal.CXString ()
import HsBindgen.Clang.Internal.Results
import HsBindgen.Patterns

{-------------------------------------------------------------------------------
Expand All @@ -51,6 +56,18 @@ foreign import capi unsafe "doxygen_wrappers.h wrap_Cursor_getParsedComment"
foreign import capi unsafe "doxygen_wrappers.h wrap_Comment_getKind"
wrap_Comment_getKind :: R CXComment_ -> IO (SimpleEnum CXCommentKind)

foreign import capi unsafe "doxygen_wrappers.h wrap_Comment_getNumChildren"
wrap_Comment_getNumChildren :: R CXComment_ -> IO CUInt

foreign import capi unsafe "doxygen_wrappers.h wrap_Comment_getChild"
wrap_Comment_getChild :: R CXComment_ -> CUInt -> W CXComment_ -> IO ()

foreign import capi unsafe "doxygen_wrappers.h wrap_Comment_isWhitespace"
wrap_Comment_isWhitespace :: R CXComment_ -> IO CUInt

foreign import capi unsafe "doxygen_wrappers.h wrap_InlineContentComment_hasTrailingNewline"
wrap_InlineContentComment_hasTrailingNewline :: R CXComment_ -> IO CUInt

-- | Given a cursor that represents a documentable entity (e.g., declaration),
-- return the associated parsed comment as a 'CXComment_FullComment' AST node.
--
Expand All @@ -68,6 +85,52 @@ clang_Comment_getKind comment =
onHaskellHeap comment $ \comment' ->
wrap_Comment_getKind comment'

-- | Get the number of children of the AST node.
--
-- <https://clang.llvm.org/doxygen/group__CINDEX__COMMENT.html#gaad4eba69493735a4db462bb4b5bed97a>
clang_Comment_getNumChildren ::
CXComment -- ^ AST node of any kind
-> IO CUInt
clang_Comment_getNumChildren comment =
onHaskellHeap comment $ \comment' ->
wrap_Comment_getNumChildren comment'

-- | Get the specified child of the AST node.
--
-- <https://clang.llvm.org/doxygen/group__CINDEX__COMMENT.html#gad5567ecc26b083562e42b83170c105aa>
clang_Comment_getChild ::
CXComment -- ^ AST node of any kind
-> CUInt -- ^ child index (zero-based)
-> IO CXComment
clang_Comment_getChild comment childIdx =
onHaskellHeap comment $ \comment' ->
preallocate_ $ wrap_Comment_getChild comment' childIdx

-- | Determine whether the comment is considered whitespace.
--
-- A @CXComment_Paragraph@ node is considered whitespace if it contains only
-- @CXComment_Text@ nodes that are empty or whitespace.
--
-- Other AST nodes (except @CXComment_Paragraph@ and @CXComment_Text@) are
-- never considered whitespace.
--
-- <https://clang.llvm.org/doxygen/group__CINDEX__COMMENT.html#ga1193c1dc798aecad92cb30cea78bf71e>
clang_Comment_isWhitespace :: CXComment -> IO Bool
clang_Comment_isWhitespace comment =
onHaskellHeap comment $ \comment' ->
cToBool <$> wrap_Comment_isWhitespace comment'

-- | Determine whether the comment is inline content and has a newline
-- immediately following it in the comment text.
--
-- Newlines between paragraphs do not count.
--
-- <https://clang.llvm.org/doxygen/group__CINDEX__COMMENT.html#gacbc2924271ca86226c024e859e0a75c8>
clang_InlineContentComment_hasTrailingNewline :: CXComment -> IO Bool
clang_InlineContentComment_hasTrailingNewline comment =
onHaskellHeap comment $ \comment' ->
cToBool <$> wrap_InlineContentComment_hasTrailingNewline comment'

{-------------------------------------------------------------------------------
Comment type 'CXComment_Text'
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit 4c7876d

Please sign in to comment.