当我使用LIbCLANG的Python绑定解析C++代码文件时,发现交叉文件引用的光标丢失了。你知道吗
#include "controller/LocalController.h"
int addition(int a, int b)
{
return a + b;
}
auto c = addition(1, 2);
auto d = LocalController::getTextByKey("100000");
Python脚本:
index = clang.cindex.Index.create()
tu = index.parse("MazeController.cpp", clang_args, None, 1)
for child in tu.cursor.walk_preorder():
if child.location.file != None:
if child.location.file.name == tu.cursor.displayname:
print child.displayname, child.kind, child.location.line, child.location.column
变量clangu args包含基本路径“controller/LocalController.h”。以下是输出:
controller/LocalController.h CursorKind.INCLUSION_DIRECTIVE 1 4
addition(int, int) CursorKind.FUNCTION_DECL 3 5
a CursorKind.PARM_DECL 3 18
b CursorKind.PARM_DECL 3 25
CursorKind.COMPOUND_STMT 4 1
CursorKind.RETURN_STMT 5 5
CursorKind.BINARY_OPERATOR 5 12
a CursorKind.UNEXPOSED_EXPR 5 12
a CursorKind.DECL_REF_EXPR 5 12
b CursorKind.UNEXPOSED_EXPR 5 16
b CursorKind.DECL_REF_EXPR 5 16
c CursorKind.VAR_DECL 8 6
addition CursorKind.CALL_EXPR 8 10
addition CursorKind.UNEXPOSED_EXPR 8 10
addition CursorKind.DECL_REF_EXPR 8 10
CursorKind.INTEGER_LITERAL 8 19
CursorKind.INTEGER_LITERAL 8 22
d CursorKind.VAR_DECL 10 6
addition的本地函数调用完全由libclang解析,但是缺少LocalController::getTextByKey的跨文件函数调用解析,因为输出的最后一行是d的游标
有人能帮我吗?非常感谢!你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐