It works!

Back to Real Life

Just over a month ago I ran into this problem. Before last month I hoped to never have to work on the C preprocessor or a parser generator. So much for that plan. Now my head is full of CPP-expansion-related trivia.

After a month of design and implementing changes to mcpp, elsa, elkhound and oink I can finally move on. During the last week all of the pieces of the puzzle finally came together ( without any nasty surprises other than bugs). Now I can go back to solving real problems.

Upcoming Features

Benefits of having CPP support don’t stop at actually being able to rewrite code. Now that the Oink C++ parser is aware of the C preprocessor, it should be possible to refactor C++ almost as easily as Java. Here are some cool things that are possible now:

  • Nicer UI. Exact source position info allows for eclipse-style context menus for renaming & other refactorings in lxr (or other online code browsers).
  • Richer type system. It should be possible to detect macro constants. Tools will be able to tell the difference between a prnull and 0. Should also be able to detect and maintain NSRESULT and other macros used for declarations.
  • Macro refactoring. Now it’s possible to write a tool to automate the process of converting function-like macro calls to actual function calls. For example, PR_MAX could be converted into std::max calls with all of the accompanying casts to ensure that the resulting C++ is correct.
  • Other nasty tricks like rewriting code within macro declarations.

I’m not sure how much of these features I will work on, but they are relatively easy to implement now.

I plan to write a minimalistic successor to squash and develop more aggressive refactorings than renames.

Additionally, I will continue pushing above changes upstream and trying to facilitate a more open oink development community.

2 comments

  1. Does the CPP-awareness of the rewired Oink also imply that it will work directly on the .cpp/.h files, rather than having to be applied to the intermediary (preprocessed) .i files?

    Essentially, is it now (large parts of) a compiler front-end with extra tasty meta-data sugar?

    Also, does one have to wait until the patches are pushed upstream to Oink before it’s possible to get to poke at it?

    I’m curious. And impressed. Nice work!

  2. I didn’t rewire oink. I just added some basic API so it is aware of macro expansion. The secret sauce is in the modified MCPP which outputs an undo-log while doing macro expansion.

    And yes it is possible to make oink apps work directly on .cpp/.h files. However it’d be done the same way as a classical C compiler. Ie the apps would just run the preprocessor for you.

    To get the source, ask me on irc. I’m taras on irc.mozilla.org