任何基于libclang的C / C ++重构工具? (甚至最简单的“玩具示例”) [英] any C/C++ refactoring tool based on libclang? (even simplest "toy example" )

查看:558
本文介绍了任何基于libclang的C / C ++重构工具? (甚至最简单的“玩具示例”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我已经指出 - 这里 - 似乎clang的libclang应该是伟大的实现硬的任务是C / C ++代码分析和修改(查看视频演示和幻灯片)。

As I've pointed out - here - it seems clang's libclang should be great for implementing the hard task that is C/C++ code analysis and modifications (check out video presentation and slides).

您知道基于libclang的任何 C / C ++重构工具吗?

Do you know of any C/C++ refactoring tool based on libclang ?

包括甚至简单的alpha状态项目,支持一种重构技术。它可以没有预处理器支持。作为我的功能的一个例子:改变方法名称,无论它支持多个文件或一次只有一个文件。你可能想知道什么目标是要求甚至小的工作示例我的想法是创建一个代码示例和小工具,在一个地方的列表将提供一个更好的资源,以学习如何实现重构的libclang 。我相信从简单的项目可能会生长更大的项目 - 以正确的开源方式:

"Any" includes even simple alpha state project, with support of one refactoristation technique. It can be without preprocessor support. As an example of the functionally about which I'm talking: changing method names, whether it supports multiple files or only one file at a time. You might be wondering what the goal is of asking for even small working examples My thought is that creating a list of code examples and small tools that are in one place will provide a better resource to learn how to implement refactorisation with libclang. I believe that from simple projects might grow bigger projects - in a proper opensource manner :).

推荐答案

Clang包含一个名为 CIndex,我相信,在IDE中做代码完成。它也可以用于解析C ++和走的AST,但没有任何重构的方式。请参阅Eli Bendersky的文章此处

Clang contains a library called "CIndex" which was developed, I believe, for doing code completion in IDEs. It can also be used for parsing C++ and walking the AST, but doesn't have anything in the way of refactoring. See Eli Bendersky's article here.

我最近开始了这样的项目: cmonster 。它是一个基于Python的API,用于解析C ++(使用libclang),分析AST,使用重写接口(即插入/删除/修改源范围)。对于修改函数名和将其转换为源代码修改这样的事情,没有什么好办法,但是这样做并不是非常困难。

I have started such a project recently: cmonster. It's a Python-based API for parsing C++ (using libclang), analyzing the AST, with an interface for "rewriting" (i.e. inserting/removing/modifying source ranges). There's no nice way (yet) for doing things like modifying function names and having that translated into source-modifications, but it wouldn't be terribly difficult to do that.

我还没有创建一个版本的这个功能(虽然它在github repo),因为我正在等待llvm / clang 3.0被释放。

I have not yet created a release with this functionality (although it's in the github repo), as I'm waiting for llvm/clang 3.0 to be released.

我应该指出几个事情:


  • 代码很粗糙,称它为alpha可能很大。

  • 我并不是这个问题的专家(不同于那里的Ira Baxter博士)。

适当调整期望。

更新:已发布cmonster 0.2,其中包含所述功能。请在 Github 上查看。

Update: cmonster 0.2 has been released, which includes the described features. Check it out on Github.

这篇关于任何基于libclang的C / C ++重构工具? (甚至最简单的“玩具示例”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆