I'm searching for a Windows GUI/command line tool or Visual Studio plug-in where I can automate the extraction of C++ code blocks, add some refactoring/renaming steps and insert it into some other C++ file. Once this is setup I want to keep the code blocks source/destination in sync and/or check for diffs.
EDIT: I'm trying to keep things in my project as simple as possible. So I'm hoping for a solution with a low level of complexity. I would prefer a solution utilizing several single task tools (maybe already shipped with my OS/IDE/SCM) over a feature-rich multi-task tool which is build to handle much more.
An Example
To give a very simple example - and I'm not sure if the tool in question would even need to understand the C++ syntax for doing something like this:
OldClass.cpp
class OldClass
{
public:
...
void MyFunctionToReuse()
{
...
// Start OldClass::MyFunctionToReuse() block
mVarOldName = ...;
// End OldClass::MyFunctionToReuse() block
...
}
};
NewClass.cpp
class NewClass
{
public:
...
void SomeFunction()
{
...
// Start OldClass::MyFunctionToReuse() block
// file OldClass.cpp, line 100 - 110
// renamed mVarOldName to mVarNewName
mVarNewName = ...;
// End OldClass::MyFunctionToReuse() block
...
}
};
The possibilities I'm currently seeing
I see four possible ways of doing this:
- Manually extract the code I want to reuse into C++ templates/classes/functions
- Use C++ refactoring tools with a macro recording feature
- Use a transpiler with a set of rules to convert
OldClass
toNewClass
- A text tool only based approach searching for keywords in comments (copy/rename/diff/insert)
The Rationale
I have a long lasting model/view/controller C++ project where the view part is now to be exchanged/moved into a separate application. The old code base is to 80% reusable, but I can't take the classes as they currently are. So I'm now at a point where I branch from my old project to start on the new code.
But the old project will still be to maintained for several years. So if I start with the necessary changes for / refactoring of the new project, I'm searching for something to keep both code streams/branches in sync (mainly for bugfixes).
And huge changes to the old product are only the last resort, because it would mean - even with having a good code coverage with unit tests - retesting major parts of the currently shipping product.
What I've looked into so far
The feature lists of
- The refactoring tools listed here
- But I didn't find a scripting/macro recording feature in those (ReSharper, Visual Assist, ...)
- They seem to handle mostly transformations of single code base in one direction
- The transpilers listed here or here
- But the ROSE compiler infrastructure and DMS Software Reengineering Toolkit with C++ Parser Frontend seem oversized
- I think I would rather go the C++ way to split and retest my old project's functionality, before putting to much time into learning to use the transpilers
- The Pattern-matching and -rewriting source code software listed here