<div dir="ltr">Did you #include "clang/Lex/Preprocessor.h"?</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Dec 8, 2016 at 12:44 PM Farzad Sadeghi <<a href="mailto:thabogre@gmail.com">thabogre@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">using CI.getPreprocessor().addCallbacks(...) also gets me the same<br class="gmail_msg">
error. it says i'm accessing an incomplete type.<br class="gmail_msg">
I looked at clang-move. I'm using the exact same methods but im still<br class="gmail_msg">
having problems with forward declaration of Preprocessor. could this<br class="gmail_msg">
problem be cause by the fact that I'm putting everything in a cpp file<br class="gmail_msg">
and i have no header?<br class="gmail_msg">
<br class="gmail_msg">
On 12/8/16, Farzad Sadeghi <<a href="mailto:thabogre@gmail.com" class="gmail_msg" target="_blank">thabogre@gmail.com</a>> wrote:<br class="gmail_msg">
> yes, InclusionDirective is implemented in PPInclusion.<br class="gmail_msg">
> ok, thank you.<br class="gmail_msg">
><br class="gmail_msg">
> On 12/8/16, Eric Liu <<a href="mailto:ioeric@google.com" class="gmail_msg" target="_blank">ioeric@google.com</a>> wrote:<br class="gmail_msg">
>> You could do: CI.getPreprocessor().addCallbacks(...) instead. BTW, have<br class="gmail_msg">
>> you<br class="gmail_msg">
>> implemented InclusionDirective in PPInclusion?<br class="gmail_msg">
>><br class="gmail_msg">
>> This is how clang-move handles it:<br class="gmail_msg">
>> <a href="https://github.com/llvm-mirror/clang-tools-extra/blob/master/clang-move/ClangMove.cpp#L401" rel="noreferrer" class="gmail_msg" target="_blank">https://github.com/llvm-mirror/clang-tools-extra/blob/master/clang-move/ClangMove.cpp#L401</a><br class="gmail_msg">
>><br class="gmail_msg">
>> On Thu, Dec 8, 2016 at 12:51 AM Farzad Sadeghi via cfe-dev <<br class="gmail_msg">
>> <a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br class="gmail_msg">
>><br class="gmail_msg">
>>> 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<br class="gmail_msg">
>>> 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">
>>><br class="gmail_msg">
>><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">
<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Farzad Sadeghi<br class="gmail_msg">
</blockquote></div>