Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a working C++ refactoring tool? [closed]

Visual Assist and 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.


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


I expect clang will 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.

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


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

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


Our DMS Software Reengineering Toolkit is 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.

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 :)

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.

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.

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 :-}

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.

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

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

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


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.