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. js如何从一个数组中随机取出n个不同且不重复的值

    前言 一位正在学习前端的菜鸟,虽菜,但还未放弃. 给大家画张图了解思路 以下是代码 function randomArr(arr,num){ let newArr = [];//创建一个新数组 for ...

  2. 【API进阶之路】帮公司省下20万调研费!如何巧用情感分析API实现用户偏好调研

    摘要:自从学习API后,仿佛解锁了新技能,可别小看了一个小小的API接口,用好了都是能力无穷.这不,用情感分析API来做用户偏好调研,没想到这么一个小创意给公司省了20万调研费用. 上次借着高考热点整 ...

  3. Elasticsearch第二篇:基本概念和基础操作

    上一篇文章,我们已经是在Windows10 上搭建了 Elasticsearch 环境已经安装了相关的插件,现在我们就可以像操作webapi一样简单的操作 ElasticSearch 了,有园友说可以 ...

  4. ECS7天实践进阶训练营Day5:使用ECS自建云端下载服务器

    一.概述 CCAA是服务器离线下载解决方案包,其组件中包含了Aria2提供了离线下载功能,能支持HTTP/HTTPS/FTP/BT/磁力链下载等常用离线下载模式及断点续传等功能.ccaa_web支撑于 ...

  5. Flask实现RESTful API(注意参数位置解析)

    准备工作 首先安装flask_restful三方组件 pip install flask_restful 在models.py中新建一个类,生成表,往里面插入一些数据.(flask要想使用ORM的话需 ...

  6. DB2根据报错代码查看表与字段信息

    select * from syscat.tables where tbspaceid='?' and tableid='?' select * from syscat.columns where t ...

  7. MySQL字符集操作

    一.查看编码 show variables like 'character%'; 二.临时设置编码 1.set names xxx set names ${编码}; "set names x ...

  8. JavaScript在HTML中的基础用法总结

    网页主要由三部分组成,分别为html.CSS和Javascript.如果说HTML是肉身,CSS是皮相,那Javascript就是灵魂.因此,三者的联系与融合则至关重要.本文就来为大家讲解一下Java ...

  9. 还不会springboot,阿里p8大牛一份385页pdf直接甩在脸上,给我啃

    第一章 Java EE简介 Java EE 有相应的规范实现,包括但不限于: Web 支持 事务支持 消息服务 数据库持久层 Container JWS JAX-RS JNDI JAXP/JAXB J ...

  10. Jenkins配置总结

    1.配置全局 系统管理->全局工具配置 2.配置 自己安装安装jdk,git,以及maven 3.系统管理->系统配置 3.1配置Jenkins URL 3.2 配置SSH Servers ...