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. Boolean源码解剖学

    一.类继承 Boolean的源码类定义部分如下: 1 public final class Boolean implements java.io.Serializable, 2 Comparable& ...

  2. Flexible实现H5移动端适配小demo

    前言 看了宇哥关于移动端适配的分享后,加上目前公司项目也需要做移动端适配,今天就抽空搞了搞.目前业界还是比较推崇手淘使用"rem+viewport"的解决方案,今天自己模仿手淘fl ...

  3. python5.2文件写入

    fh=open(r"C:\55.txt","w")#文件编写新的文字,替代原有的文字!w:writedata = "努力让生活更美好!"fh ...

  4. 有用的20个Python代码段

    Python是一种非BS编程语言.设计简单和易读性是它广受欢迎的两大原因.正如Python的宗旨:美丽胜于丑陋,显式胜于隐式. 记住一些帮助提高编码设计的常用小诀窍是有用的.在必要时刻,这些小诀窍能够 ...

  5. Hive对字段进行urlDecode

    最近项目中需要对埋点日志hive表进行分析,并且按一定的规则统计出来满足要求的用户pin.本来以为是一件比较简单的事,结果在查看导出的词表时发现很多带有"%"的明显具有url en ...

  6. 前端面试 vue 部分 (5)——VUE组件之间通信的方式有哪些

    VUE组件之间通信的方式有哪些(SSS) 常见使用场景可以分为三类: 父子通信: null 父向子传递数据是通过 props ,子向父是通过 $emit / $on $emit / $bus Vuex ...

  7. 在Linux系统中安装Tomcat详细教程

    首先在官网下载jdk和Tomcat的压缩包 这里下载jdk-8u241-linux-x64 .tar.gz 和apache-tomcat-8.5.50.tar.gz 然后解压jdk压缩包 tar –z ...

  8. 综合CSS3 transition、transform、animation写的一个动画导航

    打算好好写博客开始,就想把博客给装修下,近几个月一直处在准备找工作疯狂学习前端的状态.感觉博客装修要等到工作稳定下来才有时间和经历去想想要搞成什么样的了.也看过一些博主的博客导航有这种样式的,趁着回顾 ...

  9. C#LeetCode刷题之#876-链表的中间结点(Middle of the Linked List)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3836 访问. 给定一个带有头结点 head 的非空单链表,返回链 ...

  10. vue或者js中平均分割数组

    vue中 把一段长数组按照指定份数 均分 sliceArray(array, size) { var result = []; for (var x = 0; x < Math.ceil(arr ...