How to use PragmaHandler in an ASTFrontEndAction?

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());
}

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