I'm researching methods to port a large (>10M lines) amount of C++ code to 64-bit. I have looked at static code analyzers and compiler flags, and I am now looking at macros or other tools that can make common, repetitive changes.
I've written a few regular expressions to see how well they work in practice, and as predicted, they're quite effective. That said, it takes a while to build the expressions in the first place, so I'd like to see if there are any lists of such expressions or software tools that can perform changes automatically.
The following lines are prototypical examples of code to be matched and fixed. (To clarify, these lines are not meant to represent a single block of code, but instead are lines pulled from different places.)
int i = 0;
long objcount;
int count = channels.count(ch);
for (int k = 0; k < n; k++) { /*...*/ }
The objective is not to thoroughly port code to 64-bit, but instead to perform a first pass over the code to reduce the amount of code that needs to be manually inspected. It's okay for some needed changes to be missed, and it's probably okay for some wrong changes to be made, but those should be minimized.
Visual Studio is the IDE that will be used for conversion work, so something that works well with VS is a plus. Cost is not an issue.
Rexexps suffer from a high false positive rate; by definition, a "regular expression" cannot parse a context free langauge such as C++. Futhermore, regexps cannot take into account type information; is
fooT i=0;
ok, for some typedef'd fooT? Finally, a regexp cannot change code; you might consider Perl or SED (using regexps to drive changes), but you'll get erroneous changes due to the false positives of regexps. At 10M SLOC, that can't be fun; a 5% error rate means possibly 50,000 lines of code to fix by hand.
You might consider a program transformation tool. Such engines operate on language structures, not text, and more sophisticated versions know scopes, types, and the meaning of symbol (e.g., what is fooT, exactly?). They offer you the ability to write langauge- and context-specific patterns, and propose structurally correct code changes, using the surface syntax of the target language. This enables the reliable application of code changes on scale.
Our DMS Software Reengineering Toolkit with its C++ Front End has been used to carry out massive changes to large C++ systems in a syntax- and type-accurate way. (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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With