Skip to content

clang_equalCursors not work as expect #136435

Open
@neko-para

Description

@neko-para

I'm using my own nodejs binding of libclang to parse my source to generate a simplified ast.

// dfs logic, using cursors as a stack
function parseAnnotate(tu: CTranslationUnit) {
    const root = tu.cursor
    const cursors: CCursor[] = [root]
    tu.cursor.visitChildren((cursor, parent) => {
        while (cursors.length > 0 && !cursors[0].equal(parent)) {
            cursors.shift()
        }
        if (cursors.length === 0) {
            console.warn('jump out root', cursor, parent)
        }
        cursors.unshift(cursor)

        console.log('  '.repeat(cursors.length - 2), cursor.spelling, cursor.kindStr)
        return CXChildVisitResult.Recurse
    })
}

The code above works quite well, but when parsing the code below, the cursors that should be equal become different.

 _Const_lvalue_cond_oper ClassTemplatePartialSpecialization
       _Ty1 TemplateTypeParameter
       _Ty2 TemplateTypeParameter
        RequiresExpr
> Here should be a TemplateRef with parent of RequiresExpr, but my program crashed

Image

https://github.com/microsoft/STL/blob/5762e6bcaf7f5f8b5dba0a9aabf0acbd0e335e80/stl/inc/type_traits#L1288

After dumping the CXCursor data, it shows that the parent.data[0] is non-zero, while cursors[0].data[0] (previously stored one) is zero, causing clang_equalCursors return false.

I think there should be some problem either on my binding code or the way I use libclang, but I'm not sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions