diff --git a/lib/Interpreter/IncrementalParser.cpp b/lib/Interpreter/IncrementalParser.cpp index 2593c21f..ad4ada1e 100644 --- a/lib/Interpreter/IncrementalParser.cpp +++ b/lib/Interpreter/IncrementalParser.cpp @@ -218,6 +218,14 @@ static void HandlePlugins(CompilerInstance& CI, Consumers.push_back(std::move(PluginConsumer)); } } + + // Copied from Lex/Pragma.cpp + + // Pragmas added by plugins + for (PragmaHandlerRegistry::iterator it = PragmaHandlerRegistry::begin(), + ie = PragmaHandlerRegistry::end(); it != ie; ++it) { + CI.getPreprocessor().AddPragmaHandler(it->instantiate().release()); + } } namespace cling { diff --git a/test/Plugins/Simple.C b/test/Plugins/Simple.C index df64a2dd..f44cbc26 100644 --- a/test/Plugins/Simple.C +++ b/test/Plugins/Simple.C @@ -6,4 +6,9 @@ int dummy = 15; // CHECK-NEXT:PluginConsumer::HandleTopLevelDecl + +#pragma demoplugin + +// CHECK:DemoPluginPragmaHandler::HandlePragma + .q diff --git a/tools/plugins/example/DemoPlugin.cpp b/tools/plugins/example/DemoPlugin.cpp index 6975b5d1..e7121030 100644 --- a/tools/plugins/example/DemoPlugin.cpp +++ b/tools/plugins/example/DemoPlugin.cpp @@ -8,6 +8,7 @@ //------------------------------------------------------------------------------ #include "clang/Frontend/FrontendPluginRegistry.h" +#include "clang/Lex/Preprocessor.h" struct PluginConsumer : public clang::ASTConsumer { virtual bool HandleTopLevelDecl(clang::DeclGroupRef DGR) { @@ -38,6 +39,22 @@ protected: } }; +// Define a pragma handler for #pragma demoplugin +class DemoPluginPragmaHandler : public clang::PragmaHandler { +public: + DemoPluginPragmaHandler() : clang::PragmaHandler("demoplugin") { } + void HandlePragma(clang::Preprocessor &PP, + clang::PragmaIntroducerKind Introducer, + clang::Token &PragmaTok) { + llvm::outs() << "DemoPluginPragmaHandler::HandlePragma\n"; + // Handle the pragma + } +}; + // Register the PluginASTAction in the registry. static clang::FrontendPluginRegistry::Add > X("DemoPlugin", "Used to test plugin mechanisms in cling."); + +// Register the DemoPluginPragmaHandler in the registry. +static clang::PragmaHandlerRegistry::Add +Y("demoplugin","Used to test plugin-attached pragrams in cling.");