<div dir="ltr"><div>You could do: <span style="color:rgb(33,33,33)">CI.getPreprocessor()</span><span style="color:rgb(33,33,33)">.addCallbacks(...) instead. </span>BTW, have you implemented InclusionDirective in PPInclusion?<br></div><div><br></div><div>This is how clang-move handles it: <a href="https://github.com/llvm-mirror/clang-tools-extra/blob/master/clang-move/ClangMove.cpp#L401">https://github.com/llvm-mirror/clang-tools-extra/blob/master/clang-move/ClangMove.cpp#L401</a><br class="inbox-inbox-Apple-interchange-newline"></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Dec 8, 2016 at 12:51 AM Farzad Sadeghi via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Lets say I want to add a PP callback every time the PP runs into an<br class="gmail_msg">
InclusionDirective.<br class="gmail_msg">
going through the docs, I find that clang::PPCallbacks has the virtual<br class="gmail_msg">
member functions for me implement to do just that. So far so good.<br class="gmail_msg">
Now, how to tell the PP to use my callbacks?<br class="gmail_msg">
I came across addPPCallbacks in clang::Preprocessor.<br class="gmail_msg">
The code already has a class that derives from ASTConsumer to add and<br class="gmail_msg">
run the matchers.<br class="gmail_msg">
There is also a class that derives from ASTFrontendAction that is<br class="gmail_msg">
passed to newFrontendActionFactory to create an instance of, to be<br class="gmail_msg">
passed to a ClangTool instance to run the action.<br class="gmail_msg">
Now the questions:<br class="gmail_msg">
Do i need to cerate a new FrontendAction for the PPCallbacks? If yes,<br class="gmail_msg">
then does that mean that the inputs get lexed and parsed twice?<br class="gmail_msg">
<br class="gmail_msg">
There is only one preprocessor instance used for each frontendaction,right?<br class="gmail_msg">
So i need to get a hold of that instance and add my PPCallbacks there.<br class="gmail_msg">
I went through the docs again and found that I could do that with a<br class="gmail_msg">
clang::CompilerInstace.<br class="gmail_msg">
Now in my class that derives from ASTFrontendAction, I figured I'm<br class="gmail_msg">
getting the CompilerInstance, so maybe i can get the preprocessor<br class="gmail_msg">
there:<br class="gmail_msg">
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,<br class="gmail_msg">
StringRef file) override<br class="gmail_msg">
{<br class="gmail_msg">
    Preprocessor &PP = CI.getPreprocessor();<br class="gmail_msg">
    PP.addCallbacks(std::unique_ptr<PPCallback> PPInclusion)<br class="gmail_msg">
<br class="gmail_msg">
    TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());<br class="gmail_msg">
    return llvm::make_unique<MyASTConsumer>(TheRewriter);<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
PPInclusio is the class that derives from clang::PPCallbacks.<br class="gmail_msg">
But the compiler tells me "error: member access into incomplete type"<br class="gmail_msg">
which basically means that the Preprocessor i got from<br class="gmail_msg">
CompilerInstance is a forward declaration.<br class="gmail_msg">
How can I actually add a preprocessor callback then?<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Farzad Sadeghi<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
</blockquote></div>