Index: include/clang/Index/IndexingAction.h =================================================================== --- include/clang/Index/IndexingAction.h +++ include/clang/Index/IndexingAction.h @@ -11,12 +11,15 @@ #define LLVM_CLANG_INDEX_INDEXINGACTION_H #include "clang/Basic/LLVM.h" +#include #include namespace clang { class ASTReader; class ASTUnit; class FrontendAction; + class ASTContext; + class Decl; namespace serialization { class ModuleFile; @@ -47,8 +50,11 @@ std::shared_ptr DataConsumer, IndexingOptions Opts); -void indexModuleFile(serialization::ModuleFile &Mod, - ASTReader &Reader, +void indexTopLevelDecls(ASTContext &Ctx, ArrayRef Decls, + std::shared_ptr DataConsumer, + IndexingOptions Opts); + +void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader, std::shared_ptr DataConsumer, IndexingOptions Opts); Index: lib/Index/IndexingAction.cpp =================================================================== --- lib/Index/IndexingAction.cpp +++ lib/Index/IndexingAction.cpp @@ -177,6 +177,18 @@ DataConsumer->finish(); } +void index::indexTopLevelDecls(ASTContext &Ctx, ArrayRef Decls, + std::shared_ptr 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 DataConsumer,