]> granicus.if.org Git - clang/commitdiff
[clang] Add BeforeExecute method to PrecompiledPreamble
authorIlya Biryukov <ibiryukov@google.com>
Wed, 20 Dec 2017 16:48:56 +0000 (16:48 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Wed, 20 Dec 2017 16:48:56 +0000 (16:48 +0000)
Summary: Adds BeforeExecute method to PrecompiledPreamble to be called
before Execute(). This method can be overriden.

Patch by William Enright.

Reviewers: malaperle, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: arphaman, cfe-commits, ilya-biryukov

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321189 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 64342b1dffa815765f0bf35af835952fc822eff5..9af50f918369bbcf872ba847f53be6973a4d84bb 100644 (file)
@@ -244,6 +244,10 @@ class PreambleCallbacks {
 public:
   virtual ~PreambleCallbacks() = default;
 
+  /// Called before FrontendAction::BeginSourceFile.
+  /// Can be used to store references to various CompilerInstance fields
+  /// (e.g. SourceManager) that may be interesting to the consumers of other callbacks.
+  virtual void BeforeExecute(CompilerInstance &CI);
   /// Called after FrontendAction::Execute(), but before
   /// FrontendAction::EndSourceFile(). Can be used to transfer ownership of
   /// various CompilerInstance fields before they are destroyed.
index f6964d02b2373ea6129bf3400f84453e2da5a737..f933ba6cec01255680750ea5aa963e2d04cf2e93 100644 (file)
@@ -333,6 +333,7 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
   std::unique_ptr<PrecompilePreambleAction> Act;
   Act.reset(new PrecompilePreambleAction(
       StoreInMemory ? &Storage.asMemory().Data : nullptr, Callbacks));
+  Callbacks.BeforeExecute(*Clang);
   if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
     return BuildPreambleError::BeginSourceFileFailed;
 
@@ -694,6 +695,7 @@ void PrecompiledPreamble::setupPreambleStorage(
   }
 }
 
+void PreambleCallbacks::BeforeExecute(CompilerInstance &CI) {}
 void PreambleCallbacks::AfterExecute(CompilerInstance &CI) {}
 void PreambleCallbacks::AfterPCHEmitted(ASTWriter &Writer) {}
 void PreambleCallbacks::HandleTopLevelDecl(DeclGroupRef DG) {}