r308016 - [index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 14 03:47:45 PDT 2017


Author: ibiryukov
Date: Fri Jul 14 03:47:45 2017
New Revision: 308016

URL: http://llvm.org/viewvc/llvm-project?rev=308016&view=rev
Log:
[index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

Summary:
We need it in clangd for refactoring that replaces ASTUnit
with manual AST management.

Reviewers: akyrtzi, benlangmuir, arphaman, klimek

Reviewed By: arphaman

Subscribers: cfe-commits

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

Modified:
    cfe/trunk/include/clang/Index/IndexingAction.h
    cfe/trunk/lib/Index/IndexingAction.cpp

Modified: cfe/trunk/include/clang/Index/IndexingAction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexingAction.h?rev=308016&r1=308015&r2=308016&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/IndexingAction.h (original)
+++ cfe/trunk/include/clang/Index/IndexingAction.h Fri Jul 14 03:47:45 2017
@@ -11,11 +11,14 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/ArrayRef.h"
 #include <memory>
 
 namespace clang {
+  class ASTContext;
   class ASTReader;
   class ASTUnit;
+  class Decl;
   class FrontendAction;
 
 namespace serialization {
@@ -47,8 +50,11 @@ void indexASTUnit(ASTUnit &Unit,
                   std::shared_ptr<IndexDataConsumer> DataConsumer,
                   IndexingOptions Opts);
 
-void indexModuleFile(serialization::ModuleFile &Mod,
-                     ASTReader &Reader,
+void indexTopLevelDecls(ASTContext &Ctx, ArrayRef<const Decl *> Decls,
+                        std::shared_ptr<IndexDataConsumer> DataConsumer,
+                        IndexingOptions Opts);
+
+void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader,
                      std::shared_ptr<IndexDataConsumer> DataConsumer,
                      IndexingOptions Opts);
 

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=308016&r1=308015&r2=308016&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Fri Jul 14 03:47:45 2017
@@ -177,6 +177,18 @@ void index::indexASTUnit(ASTUnit &Unit,
   DataConsumer->finish();
 }
 
+void index::indexTopLevelDecls(ASTContext &Ctx, ArrayRef<const Decl *> Decls,
+                               std::shared_ptr<IndexDataConsumer> DataConsumer,
+                               IndexingOptions Opts) {
+  IndexingContext IndexCtx(Opts, *DataConsumer);
+  IndexCtx.setASTContext(Ctx);
+
+  DataConsumer->initialize(Ctx);
+  for (const Decl *D : Decls)
+    IndexCtx.indexTopLevelDecl(D);
+  DataConsumer->finish();
+}
+
 void index::indexModuleFile(serialization::ModuleFile &Mod,
                             ASTReader &Reader,
                             std::shared_ptr<IndexDataConsumer> DataConsumer,




More information about the cfe-commits mailing list