[cfe-dev] questions regarding using addPPCallbacks
Eric Liu via cfe-dev
cfe-dev at lists.llvm.org
Thu Dec 8 02:36:25 PST 2016
You could do: CI.getPreprocessor().addCallbacks(...) instead. BTW, have you
implemented InclusionDirective in PPInclusion?
This is how clang-move handles it:
https://github.com/llvm-mirror/clang-tools-extra/blob/master/clang-move/ClangMove.cpp#L401
On Thu, Dec 8, 2016 at 12:51 AM Farzad Sadeghi via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> Lets say I want to add a PP callback every time the PP runs into an
> InclusionDirective.
> going through the docs, I find that clang::PPCallbacks has the virtual
> member functions for me implement to do just that. So far so good.
> Now, how to tell the PP to use my callbacks?
> I came across addPPCallbacks in clang::Preprocessor.
> The code already has a class that derives from ASTConsumer to add and
> run the matchers.
> There is also a class that derives from ASTFrontendAction that is
> passed to newFrontendActionFactory to create an instance of, to be
> passed to a ClangTool instance to run the action.
> Now the questions:
> Do i need to cerate a new FrontendAction for the PPCallbacks? If yes,
> then does that mean that the inputs get lexed and parsed twice?
>
> There is only one preprocessor instance used for each frontendaction,right?
> So i need to get a hold of that instance and add my PPCallbacks there.
> I went through the docs again and found that I could do that with a
> clang::CompilerInstace.
> Now in my class that derives from ASTFrontendAction, I figured I'm
> getting the CompilerInstance, so maybe i can get the preprocessor
> there:
> std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
> StringRef file) override
> {
> Preprocessor &PP = CI.getPreprocessor();
> PP.addCallbacks(std::unique_ptr<PPCallback> PPInclusion)
>
> TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
> return llvm::make_unique<MyASTConsumer>(TheRewriter);
> }
>
> PPInclusio is the class that derives from clang::PPCallbacks.
> But the compiler tells me "error: member access into incomplete type"
> which basically means that the Preprocessor i got from
> CompilerInstance is a forward declaration.
> How can I actually add a preprocessor callback then?
>
>
> --
> Farzad Sadeghi
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161208/c6e97abb/attachment.html>
More information about the cfe-dev
mailing list