Skip to content
Merged
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
11 changes: 11 additions & 0 deletions src/hawkmoth/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
TranslationUnit,
TranslationUnitLoadError,
Diagnostic,
conf,
)

from hawkmoth import docstring
Expand Down Expand Up @@ -151,6 +152,14 @@ def _comment_extract(tu):

def is_doc(cursor): return cursor and docstring.Docstring.is_doc(cursor.spelling)

# Check for null cursors. Clang 21's cindex.py should be replacing all
# returned null cursors with None. However, due to a bug (as of 21.1.3) it
# still returns null cursors from tu.get_tokens.
#
# We need to explicitly check for these because cindex.py 21 also raises an
# exception when any property of a null cursor is accessed.
def is_null(cursor): return cursor is None or cursor == conf.lib.clang_getNullCursor()

for token in tu.get_tokens(extent=tu.cursor.extent):
# Handle all comments we come across.
if token.kind == TokenKind.COMMENT:
Expand All @@ -163,6 +172,8 @@ def is_doc(cursor): return cursor and docstring.Docstring.is_doc(cursor.spelling
# Store off the token's cursor for a slight performance improvement
# instead of accessing the `cursor` property multiple times.
token_cursor = token.cursor
if is_null(token_cursor):
continue

# Cursors that are 1) never documented themselves, and 2) allowed
# between the comment and the actual cursor being documented.
Expand Down
Loading