C++ Refactoring Tools

Well, I tried to kickstart this year’s attempt to write a C++ refactoring tool by asking EDG if I could somehow get a cheap license for their C++ front end. In the past, I’ve got bogged down in the difficulty of parsing C++ and always gave up in disgust, vowing never to waste my time on such a primitive language. This time, I thought I could avoid doing the work myself and buy in a third party solution. Unfortunately, EDG either want a big up-front sum, or some concrete guarantee that I’ll sell lots of copies of the (expensive) resulting software. That’s understandable, since they need to make money, but it makes this approach unfeasible for me.

A few days later, I notice that the Xrefactory bods have apparently been taking the same route recently. Clever people!

Of course, having a parsed-and-semantically-analysed representation of a C++ program is only half the battle. In an ideal world, you’d throw Bill Opdyke’s thesis at the problem and you’d be done. But in the real world, you have a preprocessor to deal with. Since C and C++ have a preprocessor which works at the lexical level, it can perform horrendously arbitary transformations on the program. The preprocessor munges text, and has no awareness of the syntactic/semantic structures which it is manipulating.

Refactoring in the presence of the preprocessor is hard. Fortunately, some clever people have been worrying about this recently and published a pile of papers on the subject.

I shall read these papers soon, become disgusted by the inelegance of C++ and give up on my “C++ refactoring tool” project for the fifth time.