适用于 C++ 的良好代码可视化/重构工具?
我发现自己最近在工作中遇到了很多相当大、复杂的代码库,我被要求审查或重构或两者兼而有之。当代码高度并发、大量使用模板(特别是静态多态性)并且具有依赖于回调/信号/条件变量/等的逻辑时,这可能非常耗时。
C++ 时期是否有好的可视化工具,其中是否有真正能够很好地发挥“高级”C++ 功能的工具?任何方法都可能比我现在的方法更好,我现在的方法基本上是笔+纸或单步执行调试器。调试器方法可以很好地跟踪特定的代码路径,但不太适合在进行认真的重构时查看真正需要的全局。
编辑:我应该提一下,Visual Studio 插件对我来说不会有太大帮助,因为我们的东西大多只适用于 Linux。
I've found myself coming across a lot of reasonably large, complicated codebases at work recently which I've been asked to either review or refactor or both. This can be extremely time consuming when the code is highly concurrent, makes heavy use of templates (particularly static polymorphism) and has logic that depends on callbacks/signals/condition variables/etc.
Are there any good visualization tools for C++ period, and of those are there any that actually play well with "advanced" C++ features? Anything would probably be better than my approach now, which is basically pen+paper or stepping through the debugger. The debugger method can be good for following a particular code path, but isn't great for seeing the big picture you really need when doing serious refactoring.
EDIT: I should mention that Visual Studio plugins aren't going to be a lot of help to me, since our stuff is mostly Linux-only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用 Doxygen 来开始;一旦简单的部分完成(类布局、层次结构……),您需要编写无法通过 doxygen 等工具轻松处理的软件的其余部分。
祝你好运。
M。
You could use Doxygen to get you started; once the easy part is done (class layout, hierarchies, ...) you need to write about the rest of the software that cannot be easily be process by tools like doxygen.
good luck.
M.
可视化:
我不知道 UML 世界之外发生了什么,但是其中可用的内容根本不能很好地对现代基于模板的 C++ 进行逆向工程。充其量,您将获得简单的类图。
重构:
Mozilla 创建了 deHydra / Pork 工具,用于分析和重构其 C++ 源代码,以使用更好的习惯用法改变旧式 XPCOM 和内存管理。它不依赖于可视化工具,而是使用模式匹配和 JavaScript。我自己还没有尝试过,幸运的是没有处于需要它的位置。
Visualising:
I'm not aware of what's going on outside of the UML world, but what is available within it does not reverse engineer modern, template based C++ at all well. At best, you will get simple class diagrams.
Refactoring:
Mozilla created the dehydra / Pork tools to analyse and refactor their C++ source to change their old-style XPCOM and memory management with better idioms. It's not tied to a visualisation tool, instead uses pattern matching and JavaScript. I haven't tried it myself, being fortunate to not having been in a position where it's required.
有一个用于代码可视化的 KDevelop 插件:
http://liveblue .wordpress.com/2009/08/21/gsoc-wrap-up-static-code-visualization-in-kdevelop/
There is a KDevelop plugin for code visualization:
http://liveblue.wordpress.com/2009/08/21/gsoc-wrap-up-static-code-visualization-in-kdevelop/
不,不,还是不。您需要手动记录代码库并绘制图表;一些应该至少已经部分完成的事情。
有一个用于 xemacs 的重构工具,或者至少声称是这样。 VS 有一个,但效果不是很好,只知道 5-10 次重构。 xemacs 的价格大概是 250 美元左右。不知道有没有 Eclipse 的。您很可能需要手动进行重构。
No. No. and No. You'll need to document and diagram the codebase by hand; something that should already have at least been partially done.
There's a refactoring tool, or at least claims to be, for xemacs. There's one for VS but it doesn't work to great and only knew like 5-10 refactors. The xemacs one is like $250 or something. Don't know of one for Eclipse. You'll most likely need to do your refactors by hand.
我不知道 C++ 的重构工具与 Java 的重构工具属于同一级别。 Eclipse/CTD 有一些小的重构(提取方法、设为 public/private/getter+setter),但仅此而已。
尽管如此,Eclipse/CDT 仍然是一个了解庞大代码库的好工具。代码导航功能(显示引用、显示定义、显示声明、类层次结构等)是我在 C/C++ 编辑器中见过的最好的功能。
I am not aware of a refactoring tool for C++ that is even in the same league as for example the refactoring tools you can find for Java. Eclipse/CTD has some small refactorings (extract methods, make public/private/getter+setter) but thats about it.
Still Eclipse/CDT is a good tool to get an overview of a huge code base. The code navigation features (show references, show definition, show declaration, class hierarchy, etc...) are the best i have seen in a C/C++ editor.
我不能保证这一点,但有 CDT 重构项目。
编辑:该页面看起来已经过时了。也许其他人可以证明 CDT 重构的状态?
I can't vouch for it but there is the CDT Refactoring Project.
edit: that page looks out of date. Maybe someone else can attest to the status of CDT refactoring?
DMS 软件再工程工具包是一个由语言定义参数化的程序转换引擎。它具有完整的 C++ 前端,并已用于对用 C++ 编码的软件系统进行大规模重构。
请参阅 Akers, R、Baxter, I.、Mehlich, M.、Ellis, B.、Luecke, K.,案例研究:通过自动程序转换、信息和信息重新设计 C++ 组件模型。 Software Technology 49(3):275-291 2007,讨论 DMS 以及如何将其应用于 C++ 模块以支持航空电子软件。
The DMS Software Reengineering Toolkit is a program transformation engine parameterized by language definitions. It has a full C++ front end, and has been used to carry mass refactorings of software systems coded in C++.
See Akers, R, Baxter, I., Mehlich, M. , Ellis, B. , Luecke, K., Case Study: Re-engineering C++ Component Models Via Automatic Program Transformation, Information & Software Technology 49(3):275-291 2007 for discussion about DMS and how it was applied to C++ modules to support avionics software.