[cfe-dev] How to use PragmaHandler in an ASTFrontEndAction?
Marcel Schaible via cfe-dev
cfe-dev at lists.llvm.org
Fri Jul 28 02:35:33 PDT 2017
Hi,
just for the protocol:
After digging though the clang source tree I came to the following
working solution:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef file) override {
clang::Preprocessor &PP = CI.getPreprocessor();
PP.AddPragmaHandler(new MyPragmaHandler());
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
return llvm::make_unique<MyASTConsumer>(TheRewriter);
}
Thanks
Marcel
Am 27.07.2017 um 17:03 schrieb Marcel Schaible via cfe-dev:
> Hi,
>
> how can I instantiate a PragmaHandler for a user defined pragma in an
> ASTFrontEndAction?
>
> Thanks
>
> Marcel
>
> <-- snippet-->
>
> class MyPragmaHandler : public PragmaHandler { ... }
>
> class MyFrontendAction : public ASTFrontendAction {
> public:
> ...
>
> std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
> StringRef file)
> override {
> return llvm::make_unique<MyASTConsumer>(TheRewriter);
> }
> };
>
> int main(int argc, const char **argv) {
> CommonOptionsParser op(argc, argv, ToolingSampleCategory);
> ClangTool Tool(op.getCompilations(), op.getSourcePathList());
> return Tool.run(newFrontendActionFactory<MyFrontendAction>().get());
> }
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list