[cfe-dev] Clang Checker for Import Statements
scott.conger at gmail.com
Thu Jul 14 16:25:58 PDT 2011
If you don't want to touch the code itself, you can still go with
Jordy's solution below and just update the include paths. You can
perhaps even avoid touching makefiles if you use environment
On Thu, Jul 14, 2011 at 4:15 PM, Ted Kremenek <kremenek at apple.com> wrote:
> This information can possibly be groveled through in the SourceManager (so it could be a static analysis check, at least partially), but I don't think we get SourceLocations when we include (say) an empty header or we #include the same header again that we know has include guards.
> On Jul 14, 2011, at 3:39 PM, Jordy Rose wrote:
>> As I understand it, #import is completely taken care of in the preprocessing phase...you won't see it in the AST. That means that writing a static analysis checker won't work.
>> If you really wanted to do this in code, you'd probably be modifying code in the Lex library (which I'm not so familiar with). But an easier way to solve your problem might be to just use the #warning extension: if you put a #warning in x.h, you'll get a warning whenever x.h is included. If you don't have control over x.h, or you want the warning every time x.h is referenced, you could make a wrapper that looks like this:
>> #warning "Use of x.h"
>> #import "x.h"
>> ...and then *#include* your wrapper. Admittedly, that requires a little more intrusion into your project, but it /doesn't/ require a custom compiler build. :-)
>> On Jul 14, 2011, at 13:34, ajotwani wrote:
>>> I want to write a checker that will analyze the #import statements within
>>> Objective-C files and issue a warning when a certain file is included in the
>>> import directive. For example if I have:
>>> #import "x.h"
>>> and x.h is the file name I am looking for then the checker would issue a
>>> warning that x.h is being used when it comes across this import statement.
>>> What would be the best way to go about doing this? Using the
>>> InclusionDirective class?
>>> View this message in context: http://clang-developers.42468.n3.nabble.com/Clang-Checker-for-Import-Statements-tp3170252p3170252.html
>>> Sent from the Clang Developers mailing list archive at Nabble.com.
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
More information about the cfe-dev