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

Santosh Nagarakatte santosh.nagarakatte at gmail.com
Wed Dec 1 10:45:59 PST 2010


I have not registered the callback. What are the steps I need to
follow to create PPCallbacks? Is there any other pass in clang which
does the same?

I see you create an instance of IwyuPPCallbacks with a ast_consumer as
an argument? Does IwyuPPCallbacks just inherit from PPCallabacks? Is
this code available somewhere to look at?

Thanks,
Santosh

On Tue, Nov 30, 2010 at 5:24 PM, Craig Silverstein <csilvers at google.com> wrote:
> } 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
>



-- 
Santosh G Nagarakatte,
PhD Student,
Computer and Information Science Department
University of Pennsylvania,
Philadelphia-19104
http://www.cis.upenn.edu/~santoshn




More information about the cfe-dev mailing list