[clang] Add getCommentHandler to PreambleCallbacks
authorKadir Cetinkaya <kadircet@google.com>
Mon, 4 Feb 2019 09:42:33 +0000 (09:42 +0000)
committerKadir Cetinkaya <kadircet@google.com>
Mon, 4 Feb 2019 09:42:33 +0000 (09:42 +0000)
Summary:
Enables users to add comment handlers to preprocessor when building
preambles.

Reviewers: ilya-biryukov, ioeric

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D57507

llvm-svn: 353030

clang/include/clang/Frontend/PrecompiledPreamble.h
clang/lib/Frontend/PrecompiledPreamble.cpp

index ba825af..b1d55d8 100644 (file)
@@ -283,6 +283,8 @@ public:
   /// Creates wrapper class for PPCallbacks so we can also process information
   /// about includes that are inside of a preamble
   virtual std::unique_ptr<PPCallbacks> createPPCallbacks();
+  /// The returned CommentHandler will be added to the preprocessor if not null.
+  virtual CommentHandler *getCommentHandler();
 };
 
 enum class BuildPreambleError {
index 8563882..5d6cc84 100644 (file)
@@ -18,6 +18,7 @@
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/FrontendOptions.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "llvm/ADT/StringExtras.h"
@@ -346,6 +347,8 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
       Callbacks.createPPCallbacks();
   if (DelegatedPPCallbacks)
     Clang->getPreprocessor().addPPCallbacks(std::move(DelegatedPPCallbacks));
+  if (auto CommentHandler = Callbacks.getCommentHandler())
+    Clang->getPreprocessor().addCommentHandler(CommentHandler);
 
   Act->Execute();
 
@@ -742,6 +745,7 @@ void PreambleCallbacks::HandleTopLevelDecl(DeclGroupRef DG) {}
 std::unique_ptr<PPCallbacks> PreambleCallbacks::createPPCallbacks() {
   return nullptr;
 }
+CommentHandler *PreambleCallbacks::getCommentHandler() { return nullptr; }
 
 static llvm::ManagedStatic<BuildPreambleErrorCategory> BuildPreambleErrCategory;