Wednesday, May 19, 2010
Iolaus Include Incinerator (i3)
When I first heard about the new GCC plugin support I knew I had to try it out. To that effect I've been playing around with the nifty Dehydra plugin, creating a tool called i3 to analyze C++ code looking for buggy and un-optimized include directives.
If you want to try it, you can download the beta here.
By the way, the i3 project is in no way connected with the development of the Dehydra software or the Dehydra project; it just uses the plugin.
There are two basic cases that the i3 analysis will search for.
1) Unnecessary includes:
This is just what it sounds like. You are including a file that you don't have to. This is (in most cases) considered poor design, since it adds unnecessary coupling between different files. The practical benefits of reducing the number of unnecessary includes is that you get faster builds and that less code has to be re-built if you make a change.
2) Indirect includes:
This is often a bug. It is considered good practice to include all the header files required by a particular compilation unit (cpp-file) directly.
It's not finished yet
This is an early beta release and there are a number of limitations to the analysis that i3 can perform.
It can't interpret preprocessor directives properly. If you use #ifdef's etc. to conditionally include files, i3 isn't going to get it. It will interpret every #include statement found in a file as really including a file.
About the name
The name "Iolaus Include Incinerator" is an homage to the Dehydra project. From your Greek mythology class, you may recall that Heracles companion Iolaus helped the hero in slaying the Lernaean Hydra. Every time Heracles cut of one of the Hydras heads, Iolaus scorched the neck stump to stop a new one from growing out. This program, i3, is also a helpful companion; and like any good side kick it lets you, the programmer hero, take all the credit.