2016-02-12 23:10:59 +00:00
|
|
|
//===- IndexingAction.cpp - Frontend index action -------------------------===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-02-12 23:10:59 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Index/IndexingAction.h"
|
|
|
|
#include "IndexingContext.h"
|
2017-12-07 11:04:24 +00:00
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
2016-02-12 23:10:59 +00:00
|
|
|
#include "clang/Frontend/FrontendAction.h"
|
|
|
|
#include "clang/Frontend/MultiplexConsumer.h"
|
2017-12-07 11:04:24 +00:00
|
|
|
#include "clang/Index/IndexDataConsumer.h"
|
2018-07-09 08:44:05 +00:00
|
|
|
#include "clang/Lex/PPCallbacks.h"
|
2016-02-12 23:10:59 +00:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2017-01-30 06:05:58 +00:00
|
|
|
#include "clang/Serialization/ASTReader.h"
|
2018-07-09 08:44:05 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include <memory>
|
2016-02-12 23:10:59 +00:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::index;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-08-29 10:23:29 +00:00
|
|
|
class IndexPPCallbacks final : public PPCallbacks {
|
|
|
|
std::shared_ptr<IndexingContext> IndexCtx;
|
|
|
|
|
|
|
|
public:
|
|
|
|
IndexPPCallbacks(std::shared_ptr<IndexingContext> IndexCtx)
|
|
|
|
: IndexCtx(std::move(IndexCtx)) {}
|
|
|
|
|
|
|
|
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
|
|
|
|
SourceRange Range, const MacroArgs *Args) override {
|
|
|
|
IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
Range.getBegin(), *MD.getMacroInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacroDefined(const Token &MacroNameTok,
|
|
|
|
const MacroDirective *MD) override {
|
|
|
|
IndexCtx->handleMacroDefined(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
MacroNameTok.getLocation(),
|
|
|
|
*MD->getMacroInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD,
|
|
|
|
const MacroDirective *Undef) override {
|
|
|
|
if (!MD.getMacroInfo()) // Ignore noop #undef.
|
|
|
|
return;
|
|
|
|
IndexCtx->handleMacroUndefined(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
MacroNameTok.getLocation(),
|
|
|
|
*MD.getMacroInfo());
|
|
|
|
}
|
[index] Improve macro indexing support
The major change here is to index macro occurrences in more places than
before, specifically
* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
all definition locations and undefinitions instead of just the latest
one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
macros, and we no longer report unrelated preprocessor macros during
indexing the module, which could have caused duplication.
Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.
Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.
Differential Revision: https://reviews.llvm.org/D99758
2021-03-23 15:22:58 -07:00
|
|
|
|
|
|
|
void Defined(const Token &MacroNameTok, const MacroDefinition &MD,
|
|
|
|
SourceRange Range) override {
|
|
|
|
if (!MD.getMacroInfo()) // Ignore nonexistent macro.
|
|
|
|
return;
|
|
|
|
// Note: this is defined(M), not #define M
|
|
|
|
IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
MacroNameTok.getLocation(),
|
|
|
|
*MD.getMacroInfo());
|
|
|
|
}
|
|
|
|
void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
|
|
|
|
const MacroDefinition &MD) override {
|
|
|
|
if (!MD.getMacroInfo()) // Ignore non-existent macro.
|
|
|
|
return;
|
|
|
|
IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
MacroNameTok.getLocation(),
|
|
|
|
*MD.getMacroInfo());
|
|
|
|
}
|
|
|
|
void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
|
|
|
|
const MacroDefinition &MD) override {
|
|
|
|
if (!MD.getMacroInfo()) // Ignore nonexistent macro.
|
|
|
|
return;
|
|
|
|
IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
MacroNameTok.getLocation(),
|
|
|
|
*MD.getMacroInfo());
|
|
|
|
}
|
2021-05-27 08:41:00 -04:00
|
|
|
|
2021-05-27 09:54:09 -04:00
|
|
|
using PPCallbacks::Elifdef;
|
|
|
|
using PPCallbacks::Elifndef;
|
2021-05-27 08:41:00 -04:00
|
|
|
void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
|
|
|
|
const MacroDefinition &MD) override {
|
|
|
|
if (!MD.getMacroInfo()) // Ignore non-existent macro.
|
|
|
|
return;
|
|
|
|
IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
MacroNameTok.getLocation(),
|
|
|
|
*MD.getMacroInfo());
|
|
|
|
}
|
|
|
|
void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
|
|
|
|
const MacroDefinition &MD) override {
|
|
|
|
if (!MD.getMacroInfo()) // Ignore non-existent macro.
|
|
|
|
return;
|
|
|
|
IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
MacroNameTok.getLocation(),
|
|
|
|
*MD.getMacroInfo());
|
|
|
|
}
|
2019-08-29 10:23:29 +00:00
|
|
|
};
|
|
|
|
|
2019-08-29 10:16:41 +00:00
|
|
|
class IndexASTConsumer final : public ASTConsumer {
|
2019-08-29 11:38:43 +00:00
|
|
|
std::shared_ptr<IndexDataConsumer> DataConsumer;
|
2018-07-09 08:44:05 +00:00
|
|
|
std::shared_ptr<IndexingContext> IndexCtx;
|
2019-08-29 11:38:43 +00:00
|
|
|
std::shared_ptr<Preprocessor> PP;
|
2019-08-29 11:47:34 +00:00
|
|
|
std::function<bool(const Decl *)> ShouldSkipFunctionBody;
|
2016-02-12 23:10:59 +00:00
|
|
|
|
|
|
|
public:
|
2019-08-29 11:38:43 +00:00
|
|
|
IndexASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
|
|
|
|
const IndexingOptions &Opts,
|
2019-08-29 11:47:34 +00:00
|
|
|
std::shared_ptr<Preprocessor> PP,
|
|
|
|
std::function<bool(const Decl *)> ShouldSkipFunctionBody)
|
2019-08-29 11:38:43 +00:00
|
|
|
: DataConsumer(std::move(DataConsumer)),
|
|
|
|
IndexCtx(new IndexingContext(Opts, *this->DataConsumer)),
|
2019-08-29 11:47:34 +00:00
|
|
|
PP(std::move(PP)),
|
|
|
|
ShouldSkipFunctionBody(std::move(ShouldSkipFunctionBody)) {
|
2019-08-29 11:38:43 +00:00
|
|
|
assert(this->DataConsumer != nullptr);
|
|
|
|
assert(this->PP != nullptr);
|
|
|
|
}
|
2016-02-12 23:10:59 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void Initialize(ASTContext &Context) override {
|
2018-07-09 08:44:05 +00:00
|
|
|
IndexCtx->setASTContext(Context);
|
|
|
|
IndexCtx->getDataConsumer().initialize(Context);
|
|
|
|
IndexCtx->getDataConsumer().setPreprocessor(PP);
|
2019-08-29 10:23:29 +00:00
|
|
|
PP->addPPCallbacks(std::make_unique<IndexPPCallbacks>(IndexCtx));
|
2016-02-12 23:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HandleTopLevelDecl(DeclGroupRef DG) override {
|
2018-07-09 08:44:05 +00:00
|
|
|
return IndexCtx->indexDeclGroupRef(DG);
|
2016-02-12 23:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HandleInterestingDecl(DeclGroupRef DG) override {
|
|
|
|
// Ignore deserialized decls.
|
|
|
|
}
|
|
|
|
|
|
|
|
void HandleTopLevelDeclInObjCContainer(DeclGroupRef DG) override {
|
2018-07-09 08:44:05 +00:00
|
|
|
IndexCtx->indexDeclGroupRef(DG);
|
2016-02-12 23:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HandleTranslationUnit(ASTContext &Ctx) override {
|
2019-08-29 11:38:43 +00:00
|
|
|
DataConsumer->finish();
|
2016-02-12 23:10:59 +00:00
|
|
|
}
|
2019-08-29 11:47:34 +00:00
|
|
|
|
|
|
|
bool shouldSkipFunctionBody(Decl *D) override {
|
|
|
|
return ShouldSkipFunctionBody(D);
|
|
|
|
}
|
2016-02-12 23:10:59 +00:00
|
|
|
};
|
|
|
|
|
2019-08-29 11:43:05 +00:00
|
|
|
class IndexAction final : public ASTFrontendAction {
|
2016-02-12 23:10:59 +00:00
|
|
|
std::shared_ptr<IndexDataConsumer> DataConsumer;
|
2019-08-29 11:38:43 +00:00
|
|
|
IndexingOptions Opts;
|
2016-02-14 06:39:03 +00:00
|
|
|
|
2016-02-12 23:10:59 +00:00
|
|
|
public:
|
2016-02-14 06:39:03 +00:00
|
|
|
IndexAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
|
2019-08-29 11:43:05 +00:00
|
|
|
const IndexingOptions &Opts)
|
|
|
|
: DataConsumer(std::move(DataConsumer)), Opts(Opts) {
|
|
|
|
assert(this->DataConsumer != nullptr);
|
2016-02-14 06:39:03 +00:00
|
|
|
}
|
2016-02-12 23:10:59 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
|
2018-07-09 08:44:05 +00:00
|
|
|
StringRef InFile) override {
|
2019-08-29 11:47:34 +00:00
|
|
|
return std::make_unique<IndexASTConsumer>(
|
|
|
|
DataConsumer, Opts, CI.getPreprocessorPtr(),
|
|
|
|
/*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
|
2018-07-09 08:44:05 +00:00
|
|
|
}
|
|
|
|
};
|
2016-02-12 23:10:59 +00:00
|
|
|
|
2018-07-09 08:44:05 +00:00
|
|
|
} // anonymous namespace
|
2016-02-12 23:10:59 +00:00
|
|
|
|
2019-08-29 11:47:34 +00:00
|
|
|
std::unique_ptr<ASTConsumer> index::createIndexingASTConsumer(
|
|
|
|
std::shared_ptr<IndexDataConsumer> DataConsumer,
|
|
|
|
const IndexingOptions &Opts, std::shared_ptr<Preprocessor> PP,
|
|
|
|
std::function<bool(const Decl *)> ShouldSkipFunctionBody) {
|
|
|
|
return std::make_unique<IndexASTConsumer>(DataConsumer, Opts, PP,
|
|
|
|
ShouldSkipFunctionBody);
|
2019-08-29 11:43:05 +00:00
|
|
|
}
|
|
|
|
|
[clangd] Don't traverse the AST within uninteresting files during indexing
Summary:
We already skip function bodies from these files while parsing, and drop symbols
found in them. However, traversing their ASTs still takes a substantial amount
of time.
Non-scientific benchmark on my machine:
background-indexing llvm-project (llvm+clang+clang-tools-extra), wall time
before: 7:46
after: 5:13
change: -33%
Indexer.cpp libclang should be updated too, I'm less familiar with that code,
and it's doing tricky things with the ShouldSkipFunctionBody callback, so it
needs to be done separately.
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80296
2020-05-20 16:03:42 +02:00
|
|
|
std::unique_ptr<ASTConsumer> clang::index::createIndexingASTConsumer(
|
|
|
|
std::shared_ptr<IndexDataConsumer> DataConsumer,
|
|
|
|
const IndexingOptions &Opts, std::shared_ptr<Preprocessor> PP) {
|
|
|
|
std::function<bool(const Decl *)> ShouldSkipFunctionBody = [](const Decl *) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
if (Opts.ShouldTraverseDecl)
|
|
|
|
ShouldSkipFunctionBody =
|
|
|
|
[ShouldTraverseDecl(Opts.ShouldTraverseDecl)](const Decl *D) {
|
|
|
|
return !ShouldTraverseDecl(D);
|
|
|
|
};
|
|
|
|
return createIndexingASTConsumer(std::move(DataConsumer), Opts, std::move(PP),
|
|
|
|
std::move(ShouldSkipFunctionBody));
|
|
|
|
}
|
|
|
|
|
2016-02-12 23:10:59 +00:00
|
|
|
std::unique_ptr<FrontendAction>
|
2016-02-14 06:39:03 +00:00
|
|
|
index::createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
|
2019-08-29 11:43:05 +00:00
|
|
|
const IndexingOptions &Opts) {
|
2019-08-29 11:38:43 +00:00
|
|
|
assert(DataConsumer != nullptr);
|
2019-08-14 23:04:18 +00:00
|
|
|
return std::make_unique<IndexAction>(std::move(DataConsumer), Opts);
|
2016-02-12 23:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool topLevelDeclVisitor(void *context, const Decl *D) {
|
2024-03-01 16:36:16 -08:00
|
|
|
IndexingContext &IndexCtx = *static_cast<IndexingContext *>(context);
|
2016-02-12 23:10:59 +00:00
|
|
|
return IndexCtx.indexTopLevelDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void indexTranslationUnit(ASTUnit &Unit, IndexingContext &IndexCtx) {
|
|
|
|
Unit.visitLocalTopLevelDecls(&IndexCtx, topLevelDeclVisitor);
|
|
|
|
}
|
|
|
|
|
[index] Improve macro indexing support
The major change here is to index macro occurrences in more places than
before, specifically
* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
all definition locations and undefinitions instead of just the latest
one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
macros, and we no longer report unrelated preprocessor macros during
indexing the module, which could have caused duplication.
Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.
Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.
Differential Revision: https://reviews.llvm.org/D99758
2021-03-23 15:22:58 -07:00
|
|
|
static void indexPreprocessorMacro(const IdentifierInfo *II,
|
|
|
|
const MacroInfo *MI,
|
|
|
|
MacroDirective::Kind DirectiveKind,
|
|
|
|
SourceLocation Loc,
|
|
|
|
IndexDataConsumer &DataConsumer) {
|
|
|
|
// When using modules, it may happen that we find #undef of a macro that
|
|
|
|
// was defined in another module. In such case, MI may be nullptr, since
|
|
|
|
// we only look for macro definitions in the current TU. In that case,
|
|
|
|
// there is nothing to index.
|
|
|
|
if (!MI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Skip implicit visibility change.
|
|
|
|
if (DirectiveKind == MacroDirective::MD_Visibility)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto Role = DirectiveKind == MacroDirective::MD_Define
|
|
|
|
? SymbolRole::Definition
|
|
|
|
: SymbolRole::Undefinition;
|
|
|
|
DataConsumer.handleMacroOccurrence(II, MI, static_cast<unsigned>(Role), Loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void indexPreprocessorMacros(Preprocessor &PP,
|
2018-09-18 08:51:08 +00:00
|
|
|
IndexDataConsumer &DataConsumer) {
|
[index] Improve macro indexing support
The major change here is to index macro occurrences in more places than
before, specifically
* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
all definition locations and undefinitions instead of just the latest
one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
macros, and we no longer report unrelated preprocessor macros during
indexing the module, which could have caused duplication.
Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.
Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.
Differential Revision: https://reviews.llvm.org/D99758
2021-03-23 15:22:58 -07:00
|
|
|
for (const auto &M : PP.macros()) {
|
|
|
|
for (auto *MD = M.second.getLatest(); MD; MD = MD->getPrevious()) {
|
|
|
|
indexPreprocessorMacro(M.first, MD->getMacroInfo(), MD->getKind(),
|
|
|
|
MD->getLocation(), DataConsumer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void indexPreprocessorModuleMacros(Preprocessor &PP,
|
|
|
|
serialization::ModuleFile &Mod,
|
|
|
|
IndexDataConsumer &DataConsumer) {
|
|
|
|
for (const auto &M : PP.macros()) {
|
|
|
|
if (M.second.getLatest() == nullptr) {
|
|
|
|
for (auto *MM : PP.getLeafModuleMacros(M.first)) {
|
|
|
|
auto *OwningMod = MM->getOwningModule();
|
|
|
|
if (OwningMod && OwningMod->getASTFile() == Mod.File) {
|
|
|
|
if (auto *MI = MM->getMacroInfo()) {
|
|
|
|
indexPreprocessorMacro(M.first, MI, MacroDirective::MD_Define,
|
|
|
|
MI->getDefinitionLoc(), DataConsumer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 17:24:22 +02:00
|
|
|
}
|
[index] Improve macro indexing support
The major change here is to index macro occurrences in more places than
before, specifically
* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
all definition locations and undefinitions instead of just the latest
one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
macros, and we no longer report unrelated preprocessor macros during
indexing the module, which could have caused duplication.
Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.
Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.
Differential Revision: https://reviews.llvm.org/D99758
2021-03-23 15:22:58 -07:00
|
|
|
}
|
2018-09-18 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 14:30:21 +00:00
|
|
|
void index::indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
|
2016-02-12 23:10:59 +00:00
|
|
|
IndexingOptions Opts) {
|
2018-04-23 14:30:21 +00:00
|
|
|
IndexingContext IndexCtx(Opts, DataConsumer);
|
2016-02-12 23:10:59 +00:00
|
|
|
IndexCtx.setASTContext(Unit.getASTContext());
|
2018-04-23 14:30:21 +00:00
|
|
|
DataConsumer.initialize(Unit.getASTContext());
|
|
|
|
DataConsumer.setPreprocessor(Unit.getPreprocessorPtr());
|
2018-09-18 08:51:08 +00:00
|
|
|
|
|
|
|
if (Opts.IndexMacrosInPreprocessor)
|
|
|
|
indexPreprocessorMacros(Unit.getPreprocessor(), DataConsumer);
|
2016-02-12 23:10:59 +00:00
|
|
|
indexTranslationUnit(Unit, IndexCtx);
|
2018-04-23 14:30:21 +00:00
|
|
|
DataConsumer.finish();
|
2017-01-30 06:05:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 08:51:08 +00:00
|
|
|
void index::indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP,
|
|
|
|
ArrayRef<const Decl *> Decls,
|
2018-04-23 14:30:21 +00:00
|
|
|
IndexDataConsumer &DataConsumer,
|
2017-07-14 10:47:45 +00:00
|
|
|
IndexingOptions Opts) {
|
2018-04-23 14:30:21 +00:00
|
|
|
IndexingContext IndexCtx(Opts, DataConsumer);
|
2017-07-14 10:47:45 +00:00
|
|
|
IndexCtx.setASTContext(Ctx);
|
|
|
|
|
2018-04-23 14:30:21 +00:00
|
|
|
DataConsumer.initialize(Ctx);
|
2018-09-18 08:51:08 +00:00
|
|
|
|
|
|
|
if (Opts.IndexMacrosInPreprocessor)
|
|
|
|
indexPreprocessorMacros(PP, DataConsumer);
|
|
|
|
|
2017-07-14 10:47:45 +00:00
|
|
|
for (const Decl *D : Decls)
|
|
|
|
IndexCtx.indexTopLevelDecl(D);
|
2018-04-23 14:30:21 +00:00
|
|
|
DataConsumer.finish();
|
2017-07-14 10:47:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 08:44:05 +00:00
|
|
|
std::unique_ptr<PPCallbacks>
|
|
|
|
index::indexMacrosCallback(IndexDataConsumer &Consumer, IndexingOptions Opts) {
|
2019-08-14 23:04:18 +00:00
|
|
|
return std::make_unique<IndexPPCallbacks>(
|
2018-07-09 08:44:05 +00:00
|
|
|
std::make_shared<IndexingContext>(Opts, Consumer));
|
|
|
|
}
|
|
|
|
|
2018-04-23 14:30:21 +00:00
|
|
|
void index::indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader,
|
|
|
|
IndexDataConsumer &DataConsumer,
|
2017-01-30 06:05:58 +00:00
|
|
|
IndexingOptions Opts) {
|
|
|
|
ASTContext &Ctx = Reader.getContext();
|
2018-04-23 14:30:21 +00:00
|
|
|
IndexingContext IndexCtx(Opts, DataConsumer);
|
2017-01-30 06:05:58 +00:00
|
|
|
IndexCtx.setASTContext(Ctx);
|
2018-04-23 14:30:21 +00:00
|
|
|
DataConsumer.initialize(Ctx);
|
2017-01-30 06:05:58 +00:00
|
|
|
|
[index] Improve macro indexing support
The major change here is to index macro occurrences in more places than
before, specifically
* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
all definition locations and undefinitions instead of just the latest
one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
macros, and we no longer report unrelated preprocessor macros during
indexing the module, which could have caused duplication.
Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.
Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.
Differential Revision: https://reviews.llvm.org/D99758
2021-03-23 15:22:58 -07:00
|
|
|
if (Opts.IndexMacrosInPreprocessor) {
|
|
|
|
indexPreprocessorModuleMacros(Reader.getPreprocessor(), Mod, DataConsumer);
|
|
|
|
}
|
2018-09-18 08:51:08 +00:00
|
|
|
|
2017-12-07 11:04:24 +00:00
|
|
|
for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) {
|
2017-01-30 06:05:58 +00:00
|
|
|
IndexCtx.indexTopLevelDecl(D);
|
|
|
|
}
|
2018-04-23 14:30:21 +00:00
|
|
|
DataConsumer.finish();
|
2016-02-12 23:10:59 +00:00
|
|
|
}
|