[cfe-commits] [PATCH] -rewrite-includes

Lubos Lunak l.lunak at suse.cz
Wed Mar 14 18:12:57 PDT 2012


 the attached patch is an attempt at option -rewrite-includes, which is 
similar to -rewrite-macros, but it expands only #include directives.

 The primary motivation is a better functionality of clang together with 
icecream, a distributed compile system (like distcc, only better, 
http://en.opensuse.org/Icecream). Remote compilation works by first 
preprocessing the file and sending the result for actual compilation. This 
difference doesn't matter with gcc, but clang disables some warnings for code 
expanded from macros, and also quotes source code, both of which no longer 
work well in the preprocessed case. So the idea is to add -rewrite-includes, 
which will only merge all included files into the resulting file, without any 
other modifications, and the result will be normally compiled again.

 The code is based on RewriteMacros.cpp and PrintPreprocessedOutput.cpp, it 
more or less works now and I consider it almost ready. The only remaining 
problem I have is commenting out the preprocessor directives - I'd like to 
keep them in the resulting file, similarly to what -rewrite-macros does. The 
problem is that neither /**/ nor // are safe for commenting it out in all 
possible cases, and since this should be used for transparent conversion 
during remote compile, I do not want to make assumptions about what the code 
looks like (e.g. my first trivial solution with /**/ failed 
on "#include /*MSVC <cstdlib> */ <stdlib.h>" ). Does somebody know how to 
achieve this? Otherwise I'll probably make it simply erase the directives.

 Lubos Lunak
 l.lunak at suse.cz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rewrite-includes.patch
Type: text/x-diff
Size: 21605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120315/998e25e6/attachment.patch>

More information about the cfe-commits mailing list