How to use PragmaHandler in an ASTFrontEndAction?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to use PragmaHandler in an ASTFrontEndAction?

Sumner, Brian 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use PragmaHandler in an ASTFrontEndAction?

Sumner, Brian via cfe-dev
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
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...