Identifying unnecessary #includes
apaku at gmx.de
Sat Mar 27 19:32:26 UTC 2010
On 27.03.10 15:06:50, Casey Link wrote:
> Amarok is working on re-organizing our code base, such that is is
> compartmentalized into libraries with few inter library dependencies.
> Over the years our source files have gathered many #includes that are
> cruft. Aside from manually going through hundreds of files and testing
> via trial and error, we are looking for a way to identify and remove
> unnecessary #includes.
> We figured KDev4 and its DU chains might be able to help us. Could
> someone comment on this please?
Note: I don't have in-depth knowledge about duchain.
That said, as far as I can see the C++ support does know which class is
declared where, so it might be possible to parse a file into a duchain
(this part is already solved by the duchainify app in
kdevplatform/util/) and then walk over all uses in the file and check
where the declared class/function is from. I'm not sure about wether its
possible to find out the "path" though, i.e. if foo.h includes bar.h you
get the declaration for Bar via foo, so including both headers would not
be needed. On the other hand you might actually want to do that so that
in case foo.h is ever removed for some reason you don't run into compile
Also I'm not 100% sure wether its possible to fetch only the uses of the
parsed file from the DUChain and leave out those that are uses in some
#include'd header, thats something that Niko, Milian or David need to
You will engage in a profitable business activity.
More information about the KDevelop-devel