Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions clang/bindings/python/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3939,6 +3939,8 @@ def cursor(self):
cursor._tu = self._tu

conf.lib.clang_annotateTokens(self._tu, byref(self), 1, byref(cursor))
if cursor.is_null():
return None

return cursor

Expand Down
8 changes: 8 additions & 0 deletions clang/bindings/python/tests/cindex/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ def test_token_extent(self):

self.assertEqual(extent.start.offset, 4)
self.assertEqual(extent.end.offset, 7)

def test_null_cursor(self):
"""Ensure that null cursors are converted to None by get_tokens"""
tu = get_tu("int i = 5;")
tokens = list(tu.get_tokens(extent=tu.cursor.extent))
for token in tokens:
print(token.spelling, token.kind, token.extent)
self.assertEqual(tokens[-1].cursor, None)
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Clang Frontend Potentially Breaking Changes

Clang Python Bindings Potentially Breaking Changes
--------------------------------------------------
- Return ``None`` instead of null cursors from ``Token.cursor``
- TypeKind ``ELABORATED`` is not used anymore, per clang AST changes removing
ElaboratedTypes. The value becomes unused, and all the existing users should
expect the former underlying type to be reported instead.
Expand Down