summaryrefslogtreecommitdiff
path: root/clang/lib/Index
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Index')
-rw-r--r--clang/lib/Index/CommentToXML.cpp2
-rw-r--r--clang/lib/Index/FileIndexRecord.cpp1
-rw-r--r--clang/lib/Index/IndexBody.cpp2
-rw-r--r--clang/lib/Index/IndexDecl.cpp18
-rw-r--r--clang/lib/Index/IndexSymbol.cpp12
-rw-r--r--clang/lib/Index/IndexTypeSourceInfo.cpp5
-rw-r--r--clang/lib/Index/IndexingAction.cpp15
-rw-r--r--clang/lib/Index/IndexingContext.cpp11
-rw-r--r--clang/lib/Index/USRGeneration.cpp20
9 files changed, 70 insertions, 16 deletions
diff --git a/clang/lib/Index/CommentToXML.cpp b/clang/lib/Index/CommentToXML.cpp
index ce6f9e2b13bd..1cbd14cd326c 100644
--- a/clang/lib/Index/CommentToXML.cpp
+++ b/clang/lib/Index/CommentToXML.cpp
@@ -11,6 +11,8 @@
#include "clang/AST/Attr.h"
#include "clang/AST/Comment.h"
#include "clang/AST/CommentVisitor.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
#include "clang/Format/Format.h"
#include "clang/Index/USRGeneration.h"
#include "llvm/ADT/StringExtras.h"
diff --git a/clang/lib/Index/FileIndexRecord.cpp b/clang/lib/Index/FileIndexRecord.cpp
index c9dcb0f5377d..753bdf2ce21d 100644
--- a/clang/lib/Index/FileIndexRecord.cpp
+++ b/clang/lib/Index/FileIndexRecord.cpp
@@ -10,6 +10,7 @@
#include "FileIndexRecord.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclTemplate.h"
+#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index 07a94f30c883..01cf559d7057 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -414,7 +414,7 @@ public:
auto visitSyntacticDesignatedInitExpr = [&](DesignatedInitExpr *E) -> bool {
for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) {
- if (D.isFieldDesignator())
+ if (D.isFieldDesignator() && D.getField())
return IndexCtx.handleReference(D.getField(), D.getFieldLoc(),
Parent, ParentDC, SymbolRoleSet(),
{}, E);
diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp
index c59b1372e399..2ba323e63575 100644
--- a/clang/lib/Index/IndexDecl.cpp
+++ b/clang/lib/Index/IndexDecl.cpp
@@ -80,7 +80,7 @@ public:
!MD->isSynthesizedAccessorStub();
}
-
+
void handleDeclarator(const DeclaratorDecl *D,
const NamedDecl *Parent = nullptr,
bool isIBType = false) {
@@ -90,6 +90,12 @@ public:
Parent->getLexicalDeclContext(),
/*isBase=*/false, isIBType);
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent);
+ auto IndexDefaultParmeterArgument = [&](const ParmVarDecl *Parm,
+ const NamedDecl *Parent) {
+ if (Parm->hasDefaultArg() && !Parm->hasUninstantiatedDefaultArg() &&
+ !Parm->hasUnparsedDefaultArg())
+ IndexCtx.indexBody(Parm->getDefaultArg(), Parent);
+ };
if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
auto *DC = Parm->getDeclContext();
@@ -106,7 +112,8 @@ public:
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
if (IndexCtx.shouldIndexParametersInDeclarations() ||
FD->isThisDeclarationADefinition()) {
- for (auto PI : FD->parameters()) {
+ for (const auto *PI : FD->parameters()) {
+ IndexDefaultParmeterArgument(PI, D);
IndexCtx.handleDecl(PI);
}
}
@@ -116,9 +123,7 @@ public:
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
if (FD->isThisDeclarationADefinition()) {
for (const auto *PV : FD->parameters()) {
- if (PV->hasDefaultArg() && !PV->hasUninstantiatedDefaultArg() &&
- !PV->hasUnparsedDefaultArg())
- IndexCtx.indexBody(PV->getDefaultArg(), D);
+ IndexDefaultParmeterArgument(PV, D);
}
}
}
@@ -760,6 +765,9 @@ bool IndexingContext::indexTopLevelDecl(const Decl *D) {
if (isa<ObjCMethodDecl>(D))
return true; // Wait for the objc container.
+ if (IndexOpts.ShouldTraverseDecl && !IndexOpts.ShouldTraverseDecl(D))
+ return true; // skip
+
return indexDecl(D);
}
diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp
index ae9134bf1182..0d2e557cdd36 100644
--- a/clang/lib/Index/IndexSymbol.cpp
+++ b/clang/lib/Index/IndexSymbol.cpp
@@ -357,6 +357,15 @@ SymbolInfo index::getSymbolInfo(const Decl *D) {
case Decl::VarTemplate:
llvm_unreachable("variables handled before");
break;
+ case Decl::TemplateTypeParm:
+ Info.Kind = SymbolKind::TemplateTypeParm;
+ break;
+ case Decl::TemplateTemplateParm:
+ Info.Kind = SymbolKind::TemplateTemplateParm;
+ break;
+ case Decl::NonTypeTemplateParm:
+ Info.Kind = SymbolKind::NonTypeTemplateParm;
+ break;
// Other decls get the 'unknown' kind.
default:
break;
@@ -517,6 +526,9 @@ StringRef index::getSymbolKindString(SymbolKind K) {
case SymbolKind::ConversionFunction: return "conversion-func";
case SymbolKind::Parameter: return "param";
case SymbolKind::Using: return "using";
+ case SymbolKind::TemplateTypeParm: return "template-type-param";
+ case SymbolKind::TemplateTemplateParm: return "template-template-param";
+ case SymbolKind::NonTypeTemplateParm: return "non-type-template-param";
}
llvm_unreachable("invalid symbol kind");
}
diff --git a/clang/lib/Index/IndexTypeSourceInfo.cpp b/clang/lib/Index/IndexTypeSourceInfo.cpp
index 959d5f1197fe..b9fc90040cfc 100644
--- a/clang/lib/Index/IndexTypeSourceInfo.cpp
+++ b/clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -170,6 +170,11 @@ public:
return true;
}
+ bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
+ return IndexCtx.handleReference(TL.getDecl(), TL.getNameLoc(), Parent,
+ ParentDC, SymbolRoleSet(), Relations);
+ }
+
bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
const DependentNameType *DNT = TL.getTypePtr();
const NestedNameSpecifier *NNS = DNT->getQualifier();
diff --git a/clang/lib/Index/IndexingAction.cpp b/clang/lib/Index/IndexingAction.cpp
index 4f402135672c..e698c07133a9 100644
--- a/clang/lib/Index/IndexingAction.cpp
+++ b/clang/lib/Index/IndexingAction.cpp
@@ -131,6 +131,21 @@ std::unique_ptr<ASTConsumer> index::createIndexingASTConsumer(
ShouldSkipFunctionBody);
}
+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));
+}
+
std::unique_ptr<FrontendAction>
index::createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
const IndexingOptions &Opts) {
diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp
index a7c37e8528d1..784a6008575b 100644
--- a/clang/lib/Index/IndexingContext.cpp
+++ b/clang/lib/Index/IndexingContext.cpp
@@ -169,6 +169,10 @@ bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) {
}
switch (TKind) {
case TSK_Undeclared:
+ // Instantiation maybe not happen yet when we see a SpecializationDecl,
+ // e.g. when the type doesn't need to be complete, we still treat it as an
+ // instantiation as we'd like to keep the canonicalized result consistent.
+ return isa<ClassTemplateSpecializationDecl>(D);
case TSK_ExplicitSpecialization:
return false;
case TSK_ImplicitInstantiation:
@@ -206,7 +210,12 @@ getDeclContextForTemplateInstationPattern(const Decl *D) {
static const Decl *adjustTemplateImplicitInstantiation(const Decl *D) {
if (const ClassTemplateSpecializationDecl *
SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
- return SD->getTemplateInstantiationPattern();
+ const auto *Template = SD->getTemplateInstantiationPattern();
+ if (Template)
+ return Template;
+ // Fallback to primary template if no instantiation is available yet (e.g.
+ // the type doesn't need to be complete).
+ return SD->getSpecializedTemplate()->getTemplatedDecl();
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
return FD->getTemplateInstantiationPattern();
} else if (auto *VD = dyn_cast<VarDecl>(D)) {
diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index 394daf94c4b2..0d1e81219823 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -11,6 +11,7 @@
#include "clang/AST/Attr.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclVisitor.h"
+#include "clang/Basic/FileManager.h"
#include "clang/Lex/PreprocessingRecord.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
@@ -382,6 +383,14 @@ void USRGenerator::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Out << "@NA@" << D->getName();
}
+static const ObjCCategoryDecl *getCategoryContext(const NamedDecl *D) {
+ if (auto *CD = dyn_cast<ObjCCategoryDecl>(D->getDeclContext()))
+ return CD;
+ if (auto *ICD = dyn_cast<ObjCCategoryImplDecl>(D->getDeclContext()))
+ return ICD->getCategoryDecl();
+ return nullptr;
+}
+
void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
const DeclContext *container = D->getDeclContext();
if (const ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) {
@@ -395,14 +404,6 @@ void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
IgnoreResults = true;
return;
}
- auto getCategoryContext = [](const ObjCMethodDecl *D) ->
- const ObjCCategoryDecl * {
- if (auto *CD = dyn_cast<ObjCCategoryDecl>(D->getDeclContext()))
- return CD;
- if (auto *ICD = dyn_cast<ObjCCategoryImplDecl>(D->getDeclContext()))
- return ICD->getCategoryDecl();
- return nullptr;
- };
auto *CD = getCategoryContext(D);
VisitObjCContainerDecl(ID, CD);
}
@@ -475,7 +476,7 @@ void USRGenerator::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
// The USR for a property declared in a class extension or category is based
// on the ObjCInterfaceDecl, not the ObjCCategoryDecl.
if (const ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D))
- Visit(ID);
+ VisitObjCContainerDecl(ID, getCategoryContext(D));
else
Visit(cast<Decl>(D->getDeclContext()));
GenObjCProperty(D->getName(), D->isClassProperty());
@@ -752,6 +753,7 @@ void USRGenerator::VisitType(QualType T) {
case BuiltinType::SatUShortFract:
case BuiltinType::SatUFract:
case BuiltinType::SatULongFract:
+ case BuiltinType::BFloat16:
IgnoreResults = true;
return;
case BuiltinType::ObjCId: