[cfe-dev] Clang Checker for Import Statements
jediknil at belkadan.com
Thu Jul 14 15:39:11 PDT 2011
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"
...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
More information about the cfe-dev