forked from OSchip/llvm-project
[clangd] Get rid of AST matchers in SymbolCollector. NFC
Reviewers: ilya-biryukov, kadircet Subscribers: MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D52089 llvm-svn: 342362
This commit is contained in:
parent
cac6d21731
commit
a57afd091f
|
@ -15,12 +15,16 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "SourceCode.h"
|
#include "SourceCode.h"
|
||||||
#include "URI.h"
|
#include "URI.h"
|
||||||
|
#include "clang/AST/Decl.h"
|
||||||
|
#include "clang/AST/DeclBase.h"
|
||||||
#include "clang/AST/DeclCXX.h"
|
#include "clang/AST/DeclCXX.h"
|
||||||
#include "clang/AST/DeclTemplate.h"
|
#include "clang/AST/DeclTemplate.h"
|
||||||
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
||||||
#include "clang/Basic/SourceManager.h"
|
#include "clang/Basic/SourceManager.h"
|
||||||
|
#include "clang/Basic/Specifiers.h"
|
||||||
#include "clang/Index/IndexSymbol.h"
|
#include "clang/Index/IndexSymbol.h"
|
||||||
#include "clang/Index/USRGeneration.h"
|
#include "clang/Index/USRGeneration.h"
|
||||||
|
#include "llvm/Support/Casting.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
|
@ -235,6 +239,13 @@ RefKind toRefKind(index::SymbolRoleSet Roles) {
|
||||||
return static_cast<RefKind>(static_cast<unsigned>(RefKind::All) & Roles);
|
return static_cast<RefKind>(static_cast<unsigned>(RefKind::All) & Roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T> bool explicitTemplateSpecialization(const NamedDecl &ND) {
|
||||||
|
if (const auto *TD = llvm::dyn_cast<T>(&ND))
|
||||||
|
if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
SymbolCollector::SymbolCollector(Options Opts) : Opts(std::move(Opts)) {}
|
SymbolCollector::SymbolCollector(Options Opts) : Opts(std::move(Opts)) {}
|
||||||
|
@ -271,21 +282,33 @@ bool SymbolCollector::shouldCollectSymbol(const NamedDecl &ND,
|
||||||
// FunctionDecl, BlockDecl, ObjCMethodDecl and OMPDeclareReductionDecl.
|
// FunctionDecl, BlockDecl, ObjCMethodDecl and OMPDeclareReductionDecl.
|
||||||
// FIXME: Need a matcher for ExportDecl in order to include symbols declared
|
// FIXME: Need a matcher for ExportDecl in order to include symbols declared
|
||||||
// within an export.
|
// within an export.
|
||||||
auto InNonLocalContext = hasDeclContext(anyOf(
|
const auto *DeclCtx = ND.getDeclContext();
|
||||||
translationUnitDecl(), namespaceDecl(), linkageSpecDecl(), recordDecl(),
|
switch (DeclCtx->getDeclKind()) {
|
||||||
enumDecl(), objcProtocolDecl(), objcInterfaceDecl(), objcCategoryDecl(),
|
case Decl::TranslationUnit:
|
||||||
objcCategoryImplDecl(), objcImplementationDecl()));
|
case Decl::Namespace:
|
||||||
// Don't index template specializations and expansions in main files.
|
case Decl::LinkageSpec:
|
||||||
auto IsSpecialization =
|
case Decl::Enum:
|
||||||
anyOf(functionDecl(isExplicitTemplateSpecialization()),
|
case Decl::ObjCProtocol:
|
||||||
cxxRecordDecl(isExplicitTemplateSpecialization()),
|
case Decl::ObjCInterface:
|
||||||
varDecl(isExplicitTemplateSpecialization()));
|
case Decl::ObjCCategory:
|
||||||
if (match(decl(allOf(unless(isExpansionInMainFile()), InNonLocalContext,
|
case Decl::ObjCCategoryImpl:
|
||||||
unless(IsSpecialization))),
|
case Decl::ObjCImplementation:
|
||||||
ND, ASTCtx)
|
break;
|
||||||
.empty())
|
default:
|
||||||
|
// Record has a few derivations (e.g. CXXRecord, Class specialization), it's
|
||||||
|
// easier to cast.
|
||||||
|
if (!llvm::isa<RecordDecl>(DeclCtx))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (explicitTemplateSpecialization<FunctionDecl>(ND) ||
|
||||||
|
explicitTemplateSpecialization<CXXRecordDecl>(ND) ||
|
||||||
|
explicitTemplateSpecialization<VarDecl>(ND))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
const auto &SM = ASTCtx.getSourceManager();
|
||||||
|
// Skip decls in the main file.
|
||||||
|
if (SM.isInMainFile(SM.getExpansionLoc(ND.getBeginLoc())))
|
||||||
|
return false;
|
||||||
// Avoid indexing internal symbols in protobuf generated headers.
|
// Avoid indexing internal symbols in protobuf generated headers.
|
||||||
if (isPrivateProtoDecl(ND))
|
if (isPrivateProtoDecl(ND))
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue