【发布时间】:2016-02-23 13:39:59
【问题描述】:
我无法使用 libclang 解析 C++ 中命名空间函数的主体。
我在这样的命名空间中有一个类:
namespace outer {
namespace inner {
class MyClass {
public:
short myMethod(){
return NTOHS(10);
}
short anotherMethod();
};
short MyClass::anotherMethod(){
return NTOHS(11);
}
short myFunction(){
return NTOHS(12);
}
}
}
对libclang使用python包装器,我可以通过递归找到每个节点:
def find_node(node):
print node # Just print stuff about the node (spelling, location, etc.)
for child in node.get_children():
find_node(child)
我能够在 myMethod 和 myFunction 中检测到 NTOHS 的使用情况并打印有关这些节点的信息,但无法在 MyClass::anotherMethod 中检测到它。
Someone else ran into a similar problem, but it doesn't seem to have been answered.
这里的 NTOHS 只是用于将网络转换为主机顺序的 linux/unix 命令。
如何使用 libclang 检测命名空间函数中的 NTOHS?
【问题讨论】:
-
你确定你是在
anotherMethod的定义节点而不是之前出现的声明? -
@KurtStutsman 我很确定我可以找到声明,但找不到定义。