libclang:标准库函数没有游标

时间:2016-09-18 11:08:43

标签: c++ clang libclang

libclang存在问题 - 它似乎无法获取标准库函数的游标。我有以下Python代码:

import clang.cindex

def traverse(node, depth=0):
    depth += 1
    print depth * '--', node.spelling or node.displayname, node.kind, node.location
    for c in node.get_children():
        traverse(c, depth)

index = clang.cindex.Index.create()
translation_unit = index.parse('main.cpp', args=['-x', 'c++', '-std=c++11'])
traverse(translation_unit.cursor)

对于像这样的代码

 6 int main(int argc, char* argv[])
 7 {
 8    printf("printf %s", "test");
 9    return 1;
10 }

它将打印以下内容:

---- main CursorKind.FUNCTION_DECL <SourceLocation file 'main.cpp', line 6, column 5>
------ argc CursorKind.PARM_DECL <SourceLocation file 'main.cpp', line 6, column 14>
------ argv CursorKind.PARM_DECL <SourceLocation file 'main.cpp', line 6, column 26>
------  CursorKind.COMPOUND_STMT <SourceLocation file 'main.cpp', line 7, column 1>
--------  CursorKind.RETURN_STMT <SourceLocation file 'main.cpp', line 9, column 5>
----------  CursorKind.INTEGER_LITERAL <SourceLocation file 'main.cpp', line 9, column 12>

如您所见,没有第8行。

唯一可以绕过这个问题的方法是处理令牌并获取所需的功能,但我认为应该有一个更清洁的&#34;这样做的方式。或许我错过了一些明显的东西。

0 个答案:

没有答案