[cfe-dev] questions regarding using addPPCallbacks
Farzad Sadeghi via cfe-dev
cfe-dev at lists.llvm.org
Thu Dec 8 04:09:41 PST 2016
no. that solved the issue. thank you.
i thought since I'm already running matchers, the Preprocessor is
being included anyways somewhere so i don't need to explicitly include
it...
On 12/8/16, Eric Liu <ioeric at google.com> wrote:
> Did you #include "clang/Lex/Preprocessor.h"?
>
> On Thu, Dec 8, 2016 at 12:44 PM Farzad Sadeghi <thabogre at gmail.com> wrote:
>
>> using CI.getPreprocessor().addCallbacks(...) also gets me the same
>> error. it says i'm accessing an incomplete type.
>> I looked at clang-move. I'm using the exact same methods but im still
>> having problems with forward declaration of Preprocessor. could this
>> problem be cause by the fact that I'm putting everything in a cpp file
>> and i have no header?
>>
>> On 12/8/16, Farzad Sadeghi <thabogre at gmail.com> wrote:
>> > yes, InclusionDirective is implemented in PPInclusion.
>> > ok, thank you.
>> >
>> > On 12/8/16, Eric Liu <ioeric at google.com> wrote:
>> >> 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
>> >>>
>> >>
>> >
>> >
>> > --
>> > Farzad Sadeghi
>> >
>>
>>
>> --
>> Farzad Sadeghi
>>
>
--
Farzad Sadeghi
More information about the cfe-dev
mailing list