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. day10.函数基础及函数参数

    一.函数 功能:包裹一部分代码 实现某一个功能 达成某一个目的 特点: """ 特点:可以反复调用,提高代码的复用性,提高开发效率,便于维护管理 函数基本格式 函数的定义 ...

  2. python4.5实用内置模块

    #引入urllib百度网页的数据爬取 from urllib import request url="http://www.baidu.com"data=request.urlop ...

  3. 008_用go语言实现简单的冒泡排序

    冒泡排序是各个语言中的基本排序算法,本次我们用go语言实现简单的冒泡排序 package main import "fmt" // [13,10,5,7,2] // [10,13, ...

  4. Android Studio--家庭记账本(五)

    想到每次删除之后将表单自动初始化,却发现会导致除去已经删除的不在出现在表单上,数据库中剩余的数据还会再次出现在表单中.导致表单上的数据越来越多.后来又想到,当我实现删除之后,把表单采用全部清除,再重新 ...

  5. 01-java实现动态数组

    01-手撸动态数组 本篇是恋上数据结构第一季个人总结 借鉴https://juejin.im/post/6844904001478066183#heading-0 本人git https://gith ...

  6. c++之广度优先搜索

    广度优先搜索BFS(Breadth First Search)也称为宽度优先搜索,它是一种先生成的结点先扩展的策略. 在广度优先搜索算法中,解答树上结点的扩展是按它们在树中的层次进行的.首先生成第一层 ...

  7. CSS 学习第二天

    超链接的样式: 1.颜色变化:未访问时的样式a:link:鼠标点击后的样式a:visited;鼠标放上去的样式a:hover;鼠标点击时的样式a:active 2.鼠标变小手:cursor:point ...

  8. [HNOI2009]最小圈 题解

    题目大意 给你一个有向图,求出图中环的平均值的最小值 环的平均值定义:环中所有的边权和/环中点数量 思路 看到使平均值最大或最小,可以考虑分数规划 分数规划用于解决一些要让平均值最大或最小的问题 具体 ...

  9. C#LeetCode刷题之#788-旋转数字(Rotated Digits)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3967 访问. 我们称一个数 X 为好数, 如果它的每位数字逐个地 ...

  10. LeetCode 到底怎么刷?GitHub 上多位大厂程序员亲测的高效刷题方式

    作者:HelloGitHub-小鱼干 在众多的诸如阿里.腾讯等大厂之中,最看中面试者刷题技能的大概要数有"链表厂"之称的字节跳动了.作为一个新晋大厂,字节跳动以高薪.技术大佬云集吸 ...