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

查看:90
本文介绍了任何基于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.

由于我正在等待llvm/clang 3.0的发布,因此我尚未创建具有此功能的发行版(尽管它在github存储库中).

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.

另外,我应该指出几件事:

Also, I should point out a couple of things:

  • 代码很粗糙,称它为alpha可能会很慷慨.
  • 我绝不是这个问题的专家(不同于那边的艾拉·巴克斯特博士).

适当调整期望值.

更新: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天全站免登陆