#encoding=gbk
import sys
import clang.cindex
def find_typerefs(node, typename):
""" 找'类型名'的定义
"""
if node.kind.is_reference():
#ref_node = clang.cindex.Cursor_ref(node)#这一句有毛病
#上一句有毛病
ref_node = node.get_definition()
if ref_node.spelling == typename:
print('Found %s [line=%s, col=%s]'%(typename, node.location.line, node.location.column))
# Recurse for children of this node
for c in node.get_children():
find_typerefs(c, typename)
from clang.cindex import Config
Config.set_library_path('f:\path')
#这里设置路径,不是文件,在路径里面要有`libclang.dll`.写详细点,免得搞不定
index = clang.cindex.Index.create()
tu = index.parse(sys.argv[1])
print('翻译单元:', tu.spelling)
find_typerefs(tu.cursor, sys.argv[2])#几个参数#c.cpp见下面
#python ab.py c.cpp Person
#命令如上
用py
搞了好久,都搞不了,东一个问题,西一个问题.还要搞.有的东西不懂.
class Person {
};
class Room {
public:
void add_person(Person person)
{
// do stuff
}
private:
Person* people_in_room;
};
template <class T, int N>
class Bag<T, N> {
};
int main()
{
Person* p = new Person();
Bag<Person, 42> bagofpersons;
return 0;
}
这样就管用了,我还要加,别人的,到处都有问题.前面的py文件,我用cpp渲染的,还好看点
.
问题出现:libclang.dll : fatal error LNK1107: 文件无效或损坏: 无法在 0x2D8 处读取
该如何解决?