[libclang] annotateTokens()
produces different cursor than visitChildren()
#76472
Labels
clang:as-a-library
libclang and C++ API
While testing the
annotateTokens()
function (used byToken.cursor
of the python binding), I found that for some cursor, the (only) token that belongs to that cursor does not maps back to the cursor itself.For example, on the following code,
I made a script that selects the
DeclRefExpr
that refersptr
in the statementint r = ptr->b
, and check if the only token that belongs to the expression,ptr
's cursor maps to the cursor.The result of the above script is
The cursors
node
andtoken.cursor
should be the same, and they indeed share the same spelling and extent. However,libclang
consider them as different cursors.The equality of cursor is provided by
clang_equalCursors()
, and the only difference between these two cursors aredata[0]
.llvm-project/clang/tools/libclang/CIndex.cpp
Lines 6289 to 6303 in 1c1eaf7
I suspect that the creation for
DeclRefExpr
cursors are inMakeCXCursor()
, anddata[0]
probably means the parent cursor.llvm-project/clang/tools/libclang/CXCursor.cpp
Lines 570 to 583 in 1c1eaf7
llvm-project/clang/tools/libclang/CXCursor.cpp
Lines 876 to 878 in 1c1eaf7
There might be an issue where the
data[0]
(parent) field is not being set properly, orclang_equalCursors()
should ignoredata[0]
when comparing statements?The text was updated successfully, but these errors were encountered: