[cfe-dev] Rewriting #include in a source-to-source translator

Craig Silverstein csilvers at google.com
Tue Nov 30 14:24:40 PST 2010


} To accomplish this, my rewriter currently inherits the ASTConsumer
} and PPCallbacks. I have defined the function InclusionDirective in
} my rewriter. However the callback is not being called when I test it
} on a simple test file which has #includes.

Are you registering your callback?  (If you could provide your file,
that would definitely be helpful for debugging.)

Here's what we do in include-what-you-use:
---
// We use an ASTFrontendAction to hook up IWYU with Clang.
class IwyuAction : public ASTFrontendAction {
 protected:
  virtual ASTConsumer* CreateASTConsumer(CompilerInstance& compiler,  // NOLINT
                                         llvm::StringRef /* dummy */) {
    IwyuAstConsumer* const ast_consumer = new IwyuAstConsumer(&compiler);

    compiler.getPreprocessor().addPPCallbacks(
        new IwyuPPCallbacks(ast_consumer));

    return ast_consumer;
  }
};
---

We also do some magic to register the IwyuAction, but I'm not as clear
on that part.

craig



More information about the cfe-dev mailing list