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

Auto Generate Reflection Information for C++的更多相关文章

  1. shell script auto generate the relevant header information

    first : add follow context in   /etc/vim/vimrc set ignorecaseset cursorlineset autoindentautocmd Buf ...

  2. SQLAutoCode - error when attempting to generate schema

    I'm trying to auto generate a schema for use in SQLalchemy, I'm using sqlautocode to do this, I use ...

  3. Auto Layout Guide----(三)-----Anatomy of a Constraint

    Anatomy of a Constraint 剖析约束 The layout of your view hierarchy is defined as a series of linear equa ...

  4. Android Lint Checks

    Android Lint Checks Here are the current list of checks that lint performs as of Android Studio 2.3 ...

  5. 1Z0-050

    QUESTION 13 View the Exhibit.Examine the following command that is executed for the TRANSPORT table ...

  6. linux显示git commit id,同时解决insmod模块时版本不一致导致无法加载问题

    linux内核默认会包含git的commit ID. 而linux的内核在insmod模块时,会对模块和内核本身的版本做严格的校验.在开发产品时,改动内核后,由于commit ID变更,会导致linu ...

  7. SubSonic指南中文版

    翻译:王鹏程张原 王伟策划:毛凌志2009年1月北京工业大学软件学院PS:有问题反馈至http://lexus.cnblogs.comGetting Started with SubSonicBy S ...

  8. linux根文件系统制作

    在嵌入式中移植的内核下载到开发板上,是没有办法真正的启动Linux操作系统的,会出现无法加载文件系统的错误. 那么根文件系统在系统启动中到底是什么时候挂载的呢?先将/dev/ram0挂载,而后执行/l ...

  9. Allegro16.3约束设置 (转载)

    原文地址:http://blog.chinaunix.net/uid-21198646-id-3212383.html 差分对的约束设置 第一步,差分对的设置 差分对的设置有很多方法,下面介绍两种最常 ...

随机推荐

  1. SpringBoot一个依赖搞定session共享

    原文:微信公众号:Java开发宝典  https://mp.weixin.qq.com/s/_VFY9lXqNhH8Nh4HC9tuMg 1. 前言 在传统的单服务架构中,一般来说,只有一个服务器,那 ...

  2. 《Head First 设计模式》:单件模式

    正文 一.定义 单件模式确保一个类只有一个实例,并提供一个全局访问点. 要点: 定义持有唯一单件实例的类变量. 私有化构造,避免其他类产生实例. 对外提供获取单件实例的静态方法. 二.实现步骤 1.创 ...

  3. 详细记录了python爬取小说《元尊》的整个过程,看了你必会~

    学了好几天的渗透测试基础理论,周末了让自己放松一下,最近听说天蚕土豆有一本新小说,叫做<元尊>,学生时代的我可是十分喜欢读天蚕土豆的小说,<斗破苍穹>相信很多小伙伴都看过吧.今 ...

  4. LeetCode 164. Maximum Gap[翻译]

    164. Maximum Gap 164. 最大间隔 Given an unsorted array, find the maximum difference between the successi ...

  5. 老哥,您看我这篇Java集合,还有机会评优吗?

    集合在我们日常开发使用的次数数不胜数,ArrayList/LinkedList/HashMap/HashSet······信手拈来,抬手就拿来用,在 IDE 上龙飞凤舞,但是作为一名合格的优雅的程序猿 ...

  6. Mybitis根据工具类反射数据库生成映射+整合springboot

    一 反向生成数据库mapper的工具类: 添加依赖 <dependency> <groupId>org.mybatis.generator</groupId> &l ...

  7. 永久修改Ubuntu的主机名称

    Ubuntu主机名称查看方法,使用hostname命令: [ubuntu@ubuntu ~]$hostname ubuntu 永久修改方法: 修改配置文件: sudo vi /etc/hostname ...

  8. 验证Kubernetes YAML的最佳实践和策略

    本文来自Rancher Labs Kubernetes工作负载最常见的定义是YAML格式的文件.使用YAML所面临的挑战之一是,它相当难以表达manifest文件之间的约束或关系. 如果你想检查所有部 ...

  9. 利用Jsoup爬取新冠疫情数据并存至数据库

    需要用到的jar包(用来爬取的jsoup,htmlunit-2.37.0-bin以及连接数据库中的mysql.jar) 链接:https://pan.baidu.com/s/1VlylWmlhjd8K ...

  10. 14、Java文件操作stream、File、IO

    1.文件操作涉及到的基本概念 File File类 是文件操作的主要对象中文意义就是 文件 顾名思意 万物皆文件,在计算上看到的所有东西都是文件保存,不管是你的图片.视频.数据库数据等等都是按照基本的 ...