是否有可用的 C++ 重构工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1388469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:49:11  来源:igfitidea点击:

Is there a working C++ refactoring tool?

c++refactoring

提问by RED SOFT ADAIR

Does anybody know a fully featured refactoring tool for C++ that works reliably with large code bases (some 100.000 lines)?

有没有人知道一个功能齐全的 C++ 重构工具,它可以在大型代码库(大约 100.000 行)上可靠地工作?

I tried whatever i can find again and again over the last years: SlickEdit, Eclipse CDT. They all were not at all usable.

在过去的几年里,我一次又一次地尝试了任何我能找到的东西:SlickEdit、Eclipse CDT。它们都根本无法使用。

SUMMARY: I took time and evaluated "Visual Assist X" as well as "Refactor for C++". Both have some impressing features, but both as well are far from perfect. Extracting a large block of code usually is not done satisfying without manual modifications - and therefore does not pay off.

总结:我花时间评估了“Visual Assist X”以及“Refactor for C++”。两者都有一些令人印象深刻的功能,但都远非完美。如果不进行手动修改,提取一大块代码通常不会令人满意 - 因此不会有回报。

"Visual Assist X" has nice features such as much more complete autocompletition etc. But it leads to so much flickering and slows down much at certain points.

“Visual Assist X”有很好的功能,例如更完整的自动完成等。但它会导致如此多的闪烁并在某些点上减慢速度。

By my opinion therefore the answer is: "No, there is no production ready refactoring tool for C++"

因此,我认为答案是:“不,没有用于 C++ 的生产就绪重构工具”

UPDATE March 2015As for hdoghmens reply today i tried Resharper for C++. His link https://www.jetbrains.com/resharper/does not say anything about C++. But i found Resharper C++ that was announced more than a year ago here:

2015 年 3 月更新至于 hdoghmens 今天的回复,我尝试了 Resharper for C++。他的链接 https://www.jetbrains.com/resharper/没有提及 C++。但是我在这里发现了一年多前宣布的 Resharper C++:

https://www.jetbrains.com/resharper/features/cpp.html

https://www.jetbrains.com/resharper/features/cpp.html

I gave it a try with VC2010 using a code base of 20MB.

我使用 20MB 的代码库尝试了 VC2010。

Test 1: Extract Method: results in a Resharper exception. No source code changed.

测试 1:提取方法:导致 Resharper 异常。没有更改源代码。

Test 2: Extract Method with different source: Works fine

测试 2:使用不同来源的提取方法:工作正常

Test 3: Change signature of extracted function: Results in broken C++ code:

测试 3:更改提取函数的签名:导致 C++ 代码损坏:

bool myclass::do_work123(<unknown long Color>int& Filled*&, long, int&)

Maybe thats why C++ its not listed on the main page.

也许这就是为什么 C++ 没有列在主页上的原因。

By my opinion the answer to this question still is "NO".

在我看来,这个问题的答案仍然是“不”

采纳答案by Gant

I find Visual Assist Xwith Visual Studio very useful. Another choice is Refactor for C++.

我发现带有 Visual Studio 的Visual Assist X非常有用。另一种选择是Refactor for C++

回答by Tom Leys

Visual Assistand Visual Studio make dealing with large codebases much easier. Visual assist is good at tracking down how a class or member is used and is more effective at renaming it without false positives than search and replace.

Visual Assist和 Visual Studio 使处理大型代码库变得更加容易。视觉辅助擅长跟踪类或成员的使用方式,并且在没有误报的情况下重命名它比搜索和替换更有效。

回答by HighCommander4

I expect clangwill significantly change the landscape of C++ refactoring tools out there over the next couple of years. It's an open-source, modular compiler that exposes an API for parsing and semantically analyzing C++ code. IDEs and other tools will be able to use this API rather than doing the difficult work of writing their own parser and semantic analyzer.

我预计clang将在未来几年内显着改变 C++ 重构工具的格局。它是一个开源的模块化编译器,公开了一个 API,用于解析和语义分析 C++ 代码。IDE 和其他工具将能够使用此 API,而无需执行编写自己的解析器和语义分析器的艰巨工作。

Google already made a large-scale refactoring tool using clang.

谷歌已经使用 clang 制作了一个大规模的重构工具

回答by Cristian Adam

Mozilla has their own refactoring tool named Pork (Wiki, Developer Wiki). Hereis the blog of the developer behind Pork. From what I've read Pork was successfully used in refactorings at Mozilla.

Mozilla 有自己的重构工具 Pork ( WikiDeveloper Wiki)。是 Pork 背后的开发者的博客。从我所读到的,Pork 已成功用于 Mozilla 的重构。

Pork should help if you come from *nix land, for Visual Studio I too recommend Visual Assist.

如果你来自 *nix 土地,猪肉应该会有所帮助,对于 Visual Studio,我也推荐 Visual Assist。

回答by Ira Baxter

Our DMS Software Reengineering Toolkitis a transformation engine designed to carry out complex transforms over large bodies of code, including C++. It has been used to make reliable changes on systems of millions of lines of code. It operates by using compiler-accurate langauges analyzers and transformers.

我们的DMS 软件再工程工具包是一种转换引擎,旨在对包括 C++ 在内的大量代码执行复杂的转换。它已被用于对数百万行代码的系统进行可靠的更改。它通过使用编译器准确的语言分析器和转换器来运行。

It has a full C++ parser with name and type resolution, builds ASTs of code, can apply procedural or source-to-source transformations (with C++ surface syntax) to revise those trees, and regenerate compilable output with comments preserved. (Edit: 7/1/2011: Now does C++1X to the extent we understand the standard :)

它有一个完整的 C++ 解析器,具有名称和类型解析,构建代码的 AST,可以应用程序或源到源转换(使用 C++ 表面语法)来修改这些树,并重新生成保留注释的可编译输出。(编辑:2011 年 7 月 1 日:现在 C++1X 达到我们理解标准的程度:)

It has been used on large scale reengineering projects, including C++ component re-architecting, and 100% fully automated translations between langauges. You can read about this at the website.

它已被用于大规模的再工程项目,包括 C++ 组件重新架构和语言之间的 100% 全自动翻译。您可以在网站上阅读有关此内容的信息。

DMS is also used to build arbitrary source analysis tools. Examples include clone detection, test coverage, smart difference (comparision of source code structures and abstract editing operations rather than lines with simple insert and delete), etc.

DMS 还用于构建任意源分析工具。例子包括克隆检测、测试覆盖、智能差异(比较源代码结构和抽象编辑操作而不是简单的插入和删除行)等。

What it is not (presently) is an interactive refactoring tool. We believe that to do most refactorings well, you need deep control and data fow analyses. DMS has generic machinery to support this, and that machinery is implemented for C, COBOL and Java at this point, with C++ being next in line. This is a tough job. You won't see a lot of serious C++ refactoring tools from anybody until this kind of problem has been solved well. First you need a full C++ parser :-}

它不是(目前)是一个交互式重构工具。我们相信,要做好大多数重构,您需要深入的控制和数据流分析。DMS 具有通用机制来支持这一点,并且此时该机制是为 C、COBOL 和 Java 实现的,紧随其后的是 C++。这是一项艰巨的工作。在这种问题得到很好解决之前,您不会看到任何人提供很多严肃的 C++ 重构工具。首先你需要一个完整的 C++ 解析器 :-}

EDIT 7/5/2011: Looks like we are going to take a run at the interactive version. We have won a Department of Energy Phase I SBIR to investigate how to do this.See http://science.energy.gov/sbir/awards-and-general-stats/fy-2011/phase-i-by-state/?p=1#tx(Look for Semantic Designs under "Texas"). Don't expect a result in a hurry; this is just the start of 3 phase multi-year program to get to a tool.

2011 年 7 月 5 日编辑: 看起来我们将在交互式版本上运行。我们赢得了能源部 I 阶段 SBIR 以调查如何做到这一点。参见http://science.energy.gov/sbir/awards-and-general-stats/fy-2011/phase-i-by-state/?p=1#tx(在“Texas”下寻找语义设计)。不要急于求成;这只是获得工具的 3 阶段多年计划的开始。

EDIT 8/11/2011: First progress... we now handle all of C++0x and OpenMP directives.

编辑 8/11/2011:第一个进展……我们现在处理所有 C++0x 和 OpenMP 指令。

EDIT 1/4/2012: Does full control flow analysis of C++ code.

编辑 1/4/2012:对 C++ 代码进行完全控制流分析。

EDIT 9/15/2014: Now have C++14 front end parser/transformation engine well in hand. Even does rename pretty reliably at this point :-}

编辑 9/15/2014:现在手头有 C++14 前端解析器/转换引擎。甚至在这一点上重命名非常可靠:-}

回答by bmeric

If you're using emacs, try Xrefactory. It supports method extraction, renaming of classes/functions/variables and insert/delete/move parameters.It also has very good/fast code completion engine.

如果您使用的是 emacs,请尝试Xrefactory。它支持方法提取、类/函数/变量的重命名和插入/删除/移动参数。它还具有非常好的/快速的代码完成引擎。

回答by quamrana

Currently I can't recommend anyrefactoring tool for C++, certainly not for large code bases of 100k lines and above. I've been hoping this will change, like the OP, and I hope one day there will be something. I fear that the language itself might have to change significantly before we see any really good tools.

目前我不推荐任何用于 C++ 的重构工具,当然也不推荐用于 100k 行及以上的大型代码库。我一直希望这会改变,就像 OP 一样,我希望有一天会有所改变。我担心在我们看到任何真正好的工具之前,语言本身可能必须发生重大变化。

btw, has SlickEdit dropped its refactoring features?

顺便说一句,SlickEdit 是否放弃了其重构功能?

回答by quamrana

The DMS software rengineering toolkitdoes this I think. It is a code transformation engine, designed for large scale and handles C++. Have no idea how elegant the output is though.

DMS软件工具包rengineering做到这一点,我认为。它是一个代码转换引擎,专为大规模设计并处理 C++。不知道输出有多优雅。

回答by Nikolay Bobovnikov

I recommend to try rtagsif you use emacs and haven't tried it yet (there is also a packagefor vim available). It is a clang based client/server application that indexes C/C++ code, with these features included:

如果您使用 emacs 并且还没有尝试过,我建议您尝试使用rtags(还有一个适用于 vim的可用)。它是一个基于 Clang 的客户端/服务器应用程序,可以索引 C/C++ 代码,包括以下功能:

  • go to definition/declaration
  • find all references, go to next/previous
  • rename symbol
  • integration with clang's “fixits”
  • 转到定义/声明
  • 找到所有参考文献,转到下一个/上一个
  • 重命名符号
  • 与 clang 的“fixits”集成

I decided to give it a try after watching this talkwhich introduced rtags (and emacs) for me.

在观看了为我介绍了 rtags(和 emacs)的演讲后,我决定尝试一下。

(I have to say that I went this far only after my QtCreator failed to rename some symbols properly, which is a show-stopper for my using this great IDE for now)

(我不得不说,我只是在我的 QtCreator 未能正确重命名某些符号之后才走到这一步,这是我现在使用这个伟大的 IDE 的一个障碍)

Besides what is supported by rtags, I also need some additional neat features, including:

除了 rtags 支持的功能外,我还需要一些额外的简洁功能,包括:

  • create function definition/prototype
  • extract function
  • create getter/setter methods
  • 创建函数定义/原型
  • 提取功能
  • 创建 getter/setter 方法

For these, I recommend to use a semantic-refactorpackage for emacs (not sure if there are alternatives for vim)

对于这些,我建议对 emacs使用语义重构包(不确定 vim 是否有替代方案)

Generally, clang based tools looks verypromising. If you are interested in more information about clang tools for C++ refactoring, including for projects with large codebase, there are somegreattalks by Chandler Carruth.

通常,基于 clang 的工具看起来非常有前途。如果您对 C++ 重构的 clang 工具的更多信息感兴趣,包括具有大型代码库的项目,Chandler Carruth有一些很棒的演讲。

回答by muenalan

One surely has to mention Klocworkas a commercial code refactoring suite. It does look very promising when you go through the demo video.

肯定不得不提到Klocwork作为一种商业代码重构套件。当您浏览演示视频时,它看起来确实很有希望。