yvvan created this revision.

Make possible to parse translation Unit in CIndex with incremental processing 
turned on.

1. Why to do that? - Reparse with that option takes less time.
2. What's the affected area? - I don't know. Can someone explain me what 
incremental processing is and what I loose if I parse with that option?


https://reviews.llvm.org/D34098

Files:
  include/clang-c/Index.h
  include/clang/Frontend/ASTUnit.h
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Frontend/ASTUnit.cpp
  lib/Lex/Preprocessor.cpp
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3309,6 +3309,7 @@
   bool SkipFunctionBodies = options & CXTranslationUnit_SkipFunctionBodies;
   bool SingleFileParse = options & CXTranslationUnit_SingleFileParse;
   bool ForSerialization = options & CXTranslationUnit_ForSerialization;
+  bool IncrementalProcessing = options & CXTranslationUnit_IncrementalProcessing;
 
   // Configure the diagnostics.
   IntrusiveRefCntPtr<DiagnosticsEngine>
@@ -3393,7 +3394,7 @@
       /*RemappedFilesKeepOriginalName=*/true, PrecompilePreambleAfterNParses,
       TUKind, CacheCodeCompletionResults, IncludeBriefCommentsInCodeCompletion,
       /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse,
-      /*UserFilesAreVolatile=*/true, ForSerialization,
+      /*UserFilesAreVolatile=*/true, ForSerialization, IncrementalProcessing,
       CXXIdx->getPCHContainerOperations()->getRawReader().getFormat(),
       &ErrUnit));
 
Index: lib/Lex/Preprocessor.cpp
===================================================================
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -942,6 +942,14 @@
   return true;
 }
 
+bool Preprocessor::isIncrementalProcessingEnabled() const {
+  return PPOpts->IncrementalProcessing;
+}
+
+void Preprocessor::enableIncrementalProcessing(bool value) {
+  PPOpts->IncrementalProcessing = value;
+}
+
 ModuleLoader::~ModuleLoader() { }
 
 CommentHandler::~CommentHandler() { }
Index: lib/Frontend/ASTUnit.cpp
===================================================================
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1985,8 +1985,8 @@
     bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,
     bool AllowPCHWithCompilerErrors, bool SkipFunctionBodies,
     bool SingleFileParse, bool UserFilesAreVolatile, bool ForSerialization,
-    llvm::Optional<StringRef> ModuleFormat, std::unique_ptr<ASTUnit> *ErrAST,
-    IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
+    bool IncrementalProcessing, llvm::Optional<StringRef> ModuleFormat,
+    std::unique_ptr<ASTUnit> *ErrAST, IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
   assert(Diags.get() && "no DiagnosticsEngine was provided");
 
   SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
@@ -2014,6 +2014,7 @@
   PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors;
   PPOpts.GeneratePreamble = PrecompilePreambleAfterNParses != 0;
   PPOpts.SingleFileParseMode = SingleFileParse;
+  PPOpts.IncrementalProcessing = IncrementalProcessing;
   
   // Override the resources path.
   CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
Index: include/clang/Lex/PreprocessorOptions.h
===================================================================
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -98,6 +98,9 @@
   /// When enabled, preprocessor is in a mode for parsing a single file only.
   bool SingleFileParseMode = false;
 
+  /// Do incremental processing
+  bool IncrementalProcessing = false;
+
   /// \brief True if the SourceManager should report the original file name for
   /// contents of files that were remapped to other files. Defaults to true.
   bool RemappedFilesKeepOriginalName;
Index: include/clang/Lex/Preprocessor.h
===================================================================
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -1314,12 +1314,10 @@
   void recomputeCurLexerKind();
 
   /// \brief Returns true if incremental processing is enabled
-  bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
+  bool isIncrementalProcessingEnabled() const;
 
   /// \brief Enables the incremental processing
-  void enableIncrementalProcessing(bool value = true) {
-    IncrementalProcessing = value;
-  }
+  void enableIncrementalProcessing(bool value = true);
   
   /// \brief Specify the point at which code-completion will be performed.
   ///
Index: include/clang/Frontend/ASTUnit.h
===================================================================
--- include/clang/Frontend/ASTUnit.h
+++ include/clang/Frontend/ASTUnit.h
@@ -881,6 +881,7 @@
       bool AllowPCHWithCompilerErrors = false, bool SkipFunctionBodies = false,
       bool SingleFileParse = false,
       bool UserFilesAreVolatile = false, bool ForSerialization = false,
+      bool IncrementalProcessing = false,
       llvm::Optional<StringRef> ModuleFormat = llvm::None,
       std::unique_ptr<ASTUnit> *ErrAST = nullptr,
       IntrusiveRefCntPtr<vfs::FileSystem> VFS = nullptr);
Index: include/clang-c/Index.h
===================================================================
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -1239,7 +1239,12 @@
   /**
    * \brief Sets the preprocessor in a mode for parsing a single file only.
    */
-  CXTranslationUnit_SingleFileParse = 0x400
+  CXTranslationUnit_SingleFileParse = 0x400,
+
+  /**
+   * \brief Do incremental processing
+   */
+  CXTranslationUnit_IncrementalProcessing = 0x800
 };
 
 /**
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to