Lets say I want to add a PP callback every time the PP runs into an
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
Now in my class that derives from ASTFrontendAction, I figured I'm
getting the CompilerInstance, so maybe i can get the preprocessor
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef file) override
Preprocessor &PP = CI.getPreprocessor();
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?