https://www.reddit.com/r/gamedev/comments/3lh0ba/using_clang_to_generate_c_reflection_data/

https://eli.thegreenplace.net/2011/07/03/parsing-c-in-python-with-clang/

代码

https://github.com/chakaz/reflang

https://shaharmike.com/cpp/libclang/

文档

https://clang.llvm.org/doxygen/group__CINDEX.html

Windows上安装libclang的方法

在官网https://llvm.org/下载LLVM Win Installer。安装完成后,在安装目录下找libclang.dll。

Mac上安装libclang的python绑定的方法

pip install clang

Mac上libclang的位置

With the latest (appstore) XCode 4.3.2, the location changed, it can now be found in

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib

The /Developer directory, among others, no longer exists by default. Everything is now packaged inside the XCode application, so that delta updates from the appstore work.

找不到Cursor_ref方法的问题

AttributeError: module 'clang.cindex' has no attribute 'Cursor_ref'

您需要将ref_node = clang.cindex.Cursor_ref(node)更改为ref_node = node.get_definition(),以避免获得AttributeError,因为Cursor_ref不再是clang.cindex模块的属性。

Python代码find_ref.py

 #!/usr/bin/env python
""" Usage: call with <filename> <typename>
""" import sys
import clang.cindex def find_typerefs(node, typename):
""" Find all references to the type named 'typename'
"""
if node.kind.is_reference():
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) index = clang.cindex.Index.create()
tu = index.parse(sys.argv[1])
print('Translation unit:', tu.spelling)
find_typerefs(tu.cursor, sys.argv[2])

C++代码person.cpp

 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;
}

运行

python3 find_ref.py person.cpp Person

最新文章

  1. Error Domain=NSURLErrorDomain Code=-999 “The operation couldn’t be completed.
  2. 用Java来写常见的排序算法
  3. 通过shell命令编辑xml文件--sed工具
  4. asp.net-枚举绑定控件
  5. jquery.cookie.js存与取以及过期时间设置
  6. Java中的GC操作及相关概念
  7. 【转】Linux高级字符设备之Poll操作
  8. 七行jquery代码实现图片渐变切换【兼容ie6+、 Chrome、 Firefox】
  9. WisDom.Net 框架设计(八) 持久层
  10. Linux Shell编程(13)——数字常量
  11. php浮点数计算比较及取整不准确解决方法
  12. css基础语法二(常用文本与背景属性)
  13. C# 发送电子邮件源码片段
  14. 简化版的AXI-LITE4和配合使用的RTL
  15. conda常用命令
  16. benthos 通过rest api 配置 stream 说明
  17. WinForm下ComboBox设定SelectedValue总结 (SelectedValue==null解决办法)[转]
  18. 【Git】Git与GitHub 入门【转】
  19. CMDB经验分享之 – 剖析CMDB的设计过程
  20. python使用set来去重碰到TypeError: unhashable type

热门文章

  1. PHP爬取网页的主要方法,你掌握了吗
  2. demo3同通讯录展示的方式分组排序
  3. 她娇羞道“不用这样细致认真的说啊~~”———详细图解在Linux环境中创建运行C程序
  4. 职场老鸟,一文教你如何正确入门Python爬虫!
  5. 干!一张图整理了 Python 所有内置异常
  6. 8道python练习题,能做出来的没几个
  7. 【工具】之001-CentOS7 最小化安装配置
  8. 机器学习经典算法(进阶篇)——8.KNN
  9. JVM初探(五):类的实例化
  10. 2020-06-20:一句话总结ZK?