18#include "llvm/ADT/STLExtras.h"
27 std::shared_ptr<IndexingContext> IndexCtx;
30 IndexPPCallbacks(std::shared_ptr<IndexingContext> IndexCtx)
31 : IndexCtx(
std::move(IndexCtx)) {}
102 std::shared_ptr<IndexDataConsumer> DataConsumer;
103 std::shared_ptr<IndexingContext> IndexCtx;
104 std::shared_ptr<Preprocessor> PP;
105 std::function<
bool(
const Decl *)> ShouldSkipFunctionBody;
108 IndexASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
110 std::shared_ptr<Preprocessor> PP,
111 std::function<
bool(
const Decl *)> ShouldSkipFunctionBody)
112 : DataConsumer(
std::move(DataConsumer)),
115 ShouldSkipFunctionBody(
std::move(ShouldSkipFunctionBody)) {
116 assert(this->DataConsumer !=
nullptr);
117 assert(this->PP !=
nullptr);
122 IndexCtx->setASTContext(Context);
123 IndexCtx->getDataConsumer().initialize(Context);
124 IndexCtx->getDataConsumer().setPreprocessor(PP);
125 PP->addPPCallbacks(std::make_unique<IndexPPCallbacks>(IndexCtx));
129 return IndexCtx->indexDeclGroupRef(DG);
137 IndexCtx->indexDeclGroupRef(DG);
141 DataConsumer->finish();
145 return ShouldSkipFunctionBody(
D);
150 std::shared_ptr<IndexDataConsumer> DataConsumer;
154 IndexAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
156 : DataConsumer(
std::move(DataConsumer)), Opts(Opts) {
157 assert(this->DataConsumer !=
nullptr);
162 StringRef InFile)
override {
163 return std::make_unique<IndexASTConsumer>(
165 [](
const Decl *) { return false; });
172 std::shared_ptr<IndexDataConsumer> DataConsumer,
174 std::function<
bool(
const Decl *)> ShouldSkipFunctionBody) {
175 return std::make_unique<IndexASTConsumer>(DataConsumer, Opts, PP,
176 ShouldSkipFunctionBody);
180 std::shared_ptr<IndexDataConsumer> DataConsumer,
182 std::function<
bool(
const Decl *)> ShouldSkipFunctionBody = [](
const Decl *) {
186 ShouldSkipFunctionBody =
188 return !ShouldTraverseDecl(
D);
191 std::move(ShouldSkipFunctionBody));
194std::unique_ptr<FrontendAction>
197 assert(DataConsumer !=
nullptr);
198 return std::make_unique<IndexAction>(std::move(DataConsumer), Opts);
227 ? SymbolRole::Definition
228 : SymbolRole::Undefinition;
234 for (
const auto &M : PP.
macros()) {
235 for (
auto *MD = M.second.getLatest(); MD; MD = MD->getPrevious()) {
237 MD->getLocation(), DataConsumer);
245 for (
const auto &M : PP.
macros()) {
246 if (M.second.getLatest() ==
nullptr) {
248 auto *OwningMod = MM->getOwningModule();
249 if (OwningMod && OwningMod->getASTFile() == Mod.
File) {
250 if (
auto *MI = MM->getMacroInfo()) {
252 MI->getDefinitionLoc(), DataConsumer);