aboutsummaryrefslogtreecommitdiff
path: root/lib/Index
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Index')
-rw-r--r--lib/Index/CommentToXML.cpp1
-rw-r--r--lib/Index/IndexBody.cpp41
-rw-r--r--lib/Index/IndexDecl.cpp2
-rw-r--r--lib/Index/IndexSymbol.cpp5
-rw-r--r--lib/Index/IndexTypeSourceInfo.cpp14
-rw-r--r--lib/Index/IndexingAction.cpp24
-rw-r--r--lib/Index/IndexingContext.cpp26
-rw-r--r--lib/Index/SimpleFormatContext.h10
-rw-r--r--lib/Index/USRGeneration.cpp54
9 files changed, 151 insertions, 26 deletions
diff --git a/lib/Index/CommentToXML.cpp b/lib/Index/CommentToXML.cpp
index 918068a2405f..a2659119a2ff 100644
--- a/lib/Index/CommentToXML.cpp
+++ b/lib/Index/CommentToXML.cpp
@@ -720,6 +720,7 @@ void CommentASTToXMLConverter::visitBlockCommandComment(
case CommandTraits::KCI_version:
case CommandTraits::KCI_warning:
ParagraphKind = C->getCommandName(Traits);
+ break;
default:
break;
}
diff --git a/lib/Index/IndexBody.cpp b/lib/Index/IndexBody.cpp
index 786563a44a4d..54a6df2496a9 100644
--- a/lib/Index/IndexBody.cpp
+++ b/lib/Index/IndexBody.cpp
@@ -9,6 +9,7 @@
#include "IndexingContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/ASTLambda.h"
using namespace clang;
using namespace clang::index;
@@ -143,7 +144,7 @@ public:
bool VisitMemberExpr(MemberExpr *E) {
SourceLocation Loc = E->getMemberLoc();
if (Loc.isInvalid())
- Loc = E->getLocStart();
+ Loc = E->getBeginLoc();
SmallVector<SymbolRelation, 4> Relations;
SymbolRoleSet Roles = getRolesForRef(E, Relations);
return IndexCtx.handleReference(E->getMemberDecl(), Loc,
@@ -175,7 +176,7 @@ public:
return true;
SourceLocation Loc = NameInfo.getLoc();
if (Loc.isInvalid())
- Loc = E->getLocStart();
+ Loc = E->getBeginLoc();
SmallVector<SymbolRelation, 4> Relations;
SymbolRoleSet Roles = getRolesForRef(E, Relations);
return IndexCtx.handleReference(Symbols[0], Loc, Parent, ParentDC, Roles,
@@ -259,8 +260,24 @@ public:
if (isDynamic(E)) {
Roles |= (unsigned)SymbolRole::Dynamic;
- if (auto *RecD = E->getReceiverInterface())
- Relations.emplace_back((unsigned)SymbolRole::RelationReceivedBy, RecD);
+
+ auto addReceivers = [&](const ObjCObjectType *Ty) {
+ if (!Ty)
+ return;
+ if (const auto *clsD = Ty->getInterface()) {
+ Relations.emplace_back((unsigned)SymbolRole::RelationReceivedBy,
+ clsD);
+ }
+ for (const auto *protD : Ty->quals()) {
+ Relations.emplace_back((unsigned)SymbolRole::RelationReceivedBy,
+ protD);
+ }
+ };
+ QualType recT = E->getReceiverType();
+ if (const auto *Ptr = recT->getAs<ObjCObjectPointerType>())
+ addReceivers(Ptr->getObjectType());
+ else
+ addReceivers(recT->getAs<ObjCObjectType>());
}
return IndexCtx.handleReference(MD, E->getSelectorStartLoc(),
@@ -312,8 +329,8 @@ public:
SmallVector<SymbolRelation, 2> Relations;
addCallRole(Roles, Relations);
Roles |= (unsigned)SymbolRole::Implicit;
- return IndexCtx.handleReference(MD, E->getLocStart(),
- Parent, ParentDC, Roles, Relations, E);
+ return IndexCtx.handleReference(MD, E->getBeginLoc(), Parent, ParentDC,
+ Roles, Relations, E);
}
bool VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
@@ -432,12 +449,22 @@ public:
for (unsigned I = 0, E = S->getNumComponents(); I != E; ++I) {
const OffsetOfNode &Component = S->getComponent(I);
if (Component.getKind() == OffsetOfNode::Field)
- IndexCtx.handleReference(Component.getField(), Component.getLocEnd(),
+ IndexCtx.handleReference(Component.getField(), Component.getEndLoc(),
Parent, ParentDC, SymbolRoleSet(), {});
// FIXME: Try to resolve dependent field references.
}
return true;
}
+
+ bool VisitParmVarDecl(ParmVarDecl* D) {
+ // Index the parameters of lambda expression.
+ if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+ const auto *DC = D->getDeclContext();
+ if (DC && isLambdaCallOperator(DC))
+ IndexCtx.handleDecl(D);
+ }
+ return true;
+ }
};
} // anonymous namespace
diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp
index 01ad3a277216..a7725f9dd97f 100644
--- a/lib/Index/IndexDecl.cpp
+++ b/lib/Index/IndexDecl.cpp
@@ -263,7 +263,7 @@ public:
} else if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(D)) {
if (auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) {
IndexCtx.handleReference(Dtor->getParent(),
- TypeNameInfo->getTypeLoc().getLocStart(),
+ TypeNameInfo->getTypeLoc().getBeginLoc(),
Dtor->getParent(), Dtor->getDeclContext());
}
} else if (const auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp
index 03b55ffe8a4e..1cdc0984f780 100644
--- a/lib/Index/IndexSymbol.cpp
+++ b/lib/Index/IndexSymbol.cpp
@@ -96,6 +96,9 @@ SymbolInfo index::getSymbolInfo(const Decl *D) {
if (isFunctionLocalSymbol(D)) {
Info.Properties |= (SymbolPropertySet)SymbolProperty::Local;
}
+ if (isa<ObjCProtocolDecl>(D->getDeclContext())) {
+ Info.Properties |= (SymbolPropertySet)SymbolProperty::ProtocolInterface;
+ }
if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
switch (TD->getTagKind()) {
@@ -519,6 +522,7 @@ void index::applyForEachSymbolProperty(SymbolPropertySet Props,
APPLY_FOR_PROPERTY(IBOutletCollection);
APPLY_FOR_PROPERTY(GKInspectable);
APPLY_FOR_PROPERTY(Local);
+ APPLY_FOR_PROPERTY(ProtocolInterface);
#undef APPLY_FOR_PROPERTY
}
@@ -539,6 +543,7 @@ void index::printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS) {
case SymbolProperty::IBOutletCollection: OS << "IBColl"; break;
case SymbolProperty::GKInspectable: OS << "GKI"; break;
case SymbolProperty::Local: OS << "local"; break;
+ case SymbolProperty::ProtocolInterface: OS << "protocol"; break;
}
});
}
diff --git a/lib/Index/IndexTypeSourceInfo.cpp b/lib/Index/IndexTypeSourceInfo.cpp
index 4b6bfbc67eff..85afc6345053 100644
--- a/lib/Index/IndexTypeSourceInfo.cpp
+++ b/lib/Index/IndexTypeSourceInfo.cpp
@@ -100,7 +100,8 @@ public:
bool VisitTagTypeLoc(TagTypeLoc TL) {
TagDecl *D = TL.getDecl();
- if (D->getParentFunctionOrMethod())
+ if (!IndexCtx.shouldIndexFunctionLocalSymbols() &&
+ D->getParentFunctionOrMethod())
return true;
if (TL.isDefinition()) {
@@ -130,14 +131,15 @@ public:
bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) {
if (const auto *T = TL.getTypePtr()) {
if (IndexCtx.shouldIndexImplicitInstantiation()) {
- if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
+ if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) {
IndexCtx.handleReference(RD, TL.getTemplateNameLoc(),
Parent, ParentDC, SymbolRoleSet(), Relations);
- } else {
- if (const TemplateDecl *D = T->getTemplateName().getAsTemplateDecl())
- IndexCtx.handleReference(D, TL.getTemplateNameLoc(),
- Parent, ParentDC, SymbolRoleSet(), Relations);
+ return true;
+ }
}
+ if (const TemplateDecl *D = T->getTemplateName().getAsTemplateDecl())
+ IndexCtx.handleReference(D, TL.getTemplateNameLoc(), Parent, ParentDC,
+ SymbolRoleSet(), Relations);
}
return true;
}
diff --git a/lib/Index/IndexingAction.cpp b/lib/Index/IndexingAction.cpp
index 16f6c21745ef..5cdec4b4528e 100644
--- a/lib/Index/IndexingAction.cpp
+++ b/lib/Index/IndexingAction.cpp
@@ -37,6 +37,7 @@ bool IndexDataConsumer::handleMacroOccurence(const IdentifierInfo *Name,
}
bool IndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD,
+ const Module *Mod,
SymbolRoleSet Roles,
SourceLocation Loc) {
return true;
@@ -215,23 +216,41 @@ static void indexTranslationUnit(ASTUnit &Unit, IndexingContext &IndexCtx) {
Unit.visitLocalTopLevelDecls(&IndexCtx, topLevelDeclVisitor);
}
+static void indexPreprocessorMacros(const Preprocessor &PP,
+ IndexDataConsumer &DataConsumer) {
+ for (const auto &M : PP.macros())
+ if (MacroDirective *MD = M.second.getLatest())
+ DataConsumer.handleMacroOccurence(
+ M.first, MD->getMacroInfo(),
+ static_cast<unsigned>(index::SymbolRole::Definition),
+ MD->getLocation());
+}
+
void index::indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
IndexingOptions Opts) {
IndexingContext IndexCtx(Opts, DataConsumer);
IndexCtx.setASTContext(Unit.getASTContext());
DataConsumer.initialize(Unit.getASTContext());
DataConsumer.setPreprocessor(Unit.getPreprocessorPtr());
+
+ if (Opts.IndexMacrosInPreprocessor)
+ indexPreprocessorMacros(Unit.getPreprocessor(), DataConsumer);
indexTranslationUnit(Unit, IndexCtx);
DataConsumer.finish();
}
-void index::indexTopLevelDecls(ASTContext &Ctx, ArrayRef<const Decl *> Decls,
+void index::indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP,
+ ArrayRef<const Decl *> Decls,
IndexDataConsumer &DataConsumer,
IndexingOptions Opts) {
IndexingContext IndexCtx(Opts, DataConsumer);
IndexCtx.setASTContext(Ctx);
DataConsumer.initialize(Ctx);
+
+ if (Opts.IndexMacrosInPreprocessor)
+ indexPreprocessorMacros(PP, DataConsumer);
+
for (const Decl *D : Decls)
IndexCtx.indexTopLevelDecl(D);
DataConsumer.finish();
@@ -251,6 +270,9 @@ void index::indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader,
IndexCtx.setASTContext(Ctx);
DataConsumer.initialize(Ctx);
+ if (Opts.IndexMacrosInPreprocessor)
+ indexPreprocessorMacros(Reader.getPreprocessor(), DataConsumer);
+
for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) {
IndexCtx.indexTopLevelDecl(D);
}
diff --git a/lib/Index/IndexingContext.cpp b/lib/Index/IndexingContext.cpp
index 333f9dc3091b..bba6c8390b56 100644
--- a/lib/Index/IndexingContext.cpp
+++ b/lib/Index/IndexingContext.cpp
@@ -80,11 +80,27 @@ bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
RefE, RefD, DC);
}
+static void reportModuleReferences(const Module *Mod,
+ ArrayRef<SourceLocation> IdLocs,
+ const ImportDecl *ImportD,
+ IndexDataConsumer &DataConsumer) {
+ if (!Mod)
+ return;
+ reportModuleReferences(Mod->Parent, IdLocs.drop_back(), ImportD,
+ DataConsumer);
+ DataConsumer.handleModuleOccurence(ImportD, Mod,
+ (SymbolRoleSet)SymbolRole::Reference,
+ IdLocs.back());
+}
+
bool IndexingContext::importedModule(const ImportDecl *ImportD) {
+ if (ImportD->isInvalidDecl())
+ return true;
+
SourceLocation Loc;
auto IdLocs = ImportD->getIdentifierLocs();
if (!IdLocs.empty())
- Loc = IdLocs.front();
+ Loc = IdLocs.back();
else
Loc = ImportD->getLocation();
@@ -108,11 +124,17 @@ bool IndexingContext::importedModule(const ImportDecl *ImportD) {
}
}
+ const Module *Mod = ImportD->getImportedModule();
+ if (!ImportD->isImplicit() && Mod->Parent && !IdLocs.empty()) {
+ reportModuleReferences(Mod->Parent, IdLocs.drop_back(), ImportD,
+ DataConsumer);
+ }
+
SymbolRoleSet Roles = (unsigned)SymbolRole::Declaration;
if (ImportD->isImplicit())
Roles |= (unsigned)SymbolRole::Implicit;
- return DataConsumer.handleModuleOccurence(ImportD, Roles, Loc);
+ return DataConsumer.handleModuleOccurence(ImportD, Mod, Roles, Loc);
}
bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) {
diff --git a/lib/Index/SimpleFormatContext.h b/lib/Index/SimpleFormatContext.h
index 9c6d29bec329..24adcac60201 100644
--- a/lib/Index/SimpleFormatContext.h
+++ b/lib/Index/SimpleFormatContext.h
@@ -36,12 +36,10 @@ class SimpleFormatContext {
public:
SimpleFormatContext(LangOptions Options)
: DiagOpts(new DiagnosticOptions()),
- Diagnostics(new DiagnosticsEngine(new DiagnosticIDs,
- DiagOpts.get())),
- InMemoryFileSystem(new vfs::InMemoryFileSystem),
+ Diagnostics(new DiagnosticsEngine(new DiagnosticIDs, DiagOpts.get())),
+ InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
Files(FileSystemOptions(), InMemoryFileSystem),
- Sources(*Diagnostics, Files),
- Rewrite(Sources, Options) {
+ Sources(*Diagnostics, Files), Rewrite(Sources, Options) {
Diagnostics->setClient(new IgnoringDiagConsumer, true);
}
@@ -63,7 +61,7 @@ public:
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
- IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem;
+ IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem;
FileManager Files;
SourceManager Sources;
Rewriter Rewrite;
diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp
index b128b69931a3..84ca753bf840 100644
--- a/lib/Index/USRGeneration.cpp
+++ b/lib/Index/USRGeneration.cpp
@@ -97,6 +97,7 @@ public:
void VisitTypedefDecl(const TypedefDecl *D);
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
void VisitVarDecl(const VarDecl *D);
+ void VisitBindingDecl(const BindingDecl *D);
void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
@@ -269,7 +270,8 @@ void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) {
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
if (MD->isStatic())
Out << 'S';
- if (unsigned quals = MD->getTypeQualifiers())
+ // FIXME: OpenCL: Need to consider address spaces
+ if (unsigned quals = MD->getTypeQualifiers().getCVRUQualifiers())
Out << (char)('0' + quals);
switch (MD->getRefQualifier()) {
case RQ_None: break;
@@ -334,6 +336,12 @@ void USRGenerator::VisitVarDecl(const VarDecl *D) {
}
}
+void USRGenerator::VisitBindingDecl(const BindingDecl *D) {
+ if (isLocal(D) && GenLoc(D, /*IncludeOffset=*/true))
+ return;
+ VisitNamedDecl(D);
+}
+
void USRGenerator::VisitNonTypeTemplateParmDecl(
const NonTypeTemplateParmDecl *D) {
GenLoc(D, /*IncludeOffset=*/true);
@@ -599,7 +607,7 @@ bool USRGenerator::GenLoc(const Decl *D, bool IncludeOffset) {
D = D->getCanonicalDecl();
IgnoreResults =
- IgnoreResults || printLoc(Out, D->getLocStart(),
+ IgnoreResults || printLoc(Out, D->getBeginLoc(),
Context->getSourceManager(), IncludeOffset);
return IgnoreResults;
@@ -704,6 +712,9 @@ void USRGenerator::VisitType(QualType T) {
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/Basic/OpenCLImageTypes.def"
+#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
+ case BuiltinType::Id:
+#include "clang/Basic/OpenCLExtensionTypes.def"
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:
case BuiltinType::OCLQueue:
@@ -935,7 +946,7 @@ void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) {
case TemplateArgument::TemplateExpansion:
Out << 'P'; // pack expansion of...
- // Fall through
+ LLVM_FALLTHROUGH;
case TemplateArgument::Template:
VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
break;
@@ -1094,3 +1105,40 @@ bool clang::index::generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
Out << MacroName;
return false;
}
+
+bool clang::index::generateUSRForType(QualType T, ASTContext &Ctx,
+ SmallVectorImpl<char> &Buf) {
+ if (T.isNull())
+ return true;
+ T = T.getCanonicalType();
+
+ USRGenerator UG(&Ctx, Buf);
+ UG.VisitType(T);
+ return UG.ignoreResults();
+}
+
+bool clang::index::generateFullUSRForModule(const Module *Mod,
+ raw_ostream &OS) {
+ if (!Mod->Parent)
+ return generateFullUSRForTopLevelModuleName(Mod->Name, OS);
+ if (generateFullUSRForModule(Mod->Parent, OS))
+ return true;
+ return generateUSRFragmentForModule(Mod, OS);
+}
+
+bool clang::index::generateFullUSRForTopLevelModuleName(StringRef ModName,
+ raw_ostream &OS) {
+ OS << getUSRSpacePrefix();
+ return generateUSRFragmentForModuleName(ModName, OS);
+}
+
+bool clang::index::generateUSRFragmentForModule(const Module *Mod,
+ raw_ostream &OS) {
+ return generateUSRFragmentForModuleName(Mod->Name, OS);
+}
+
+bool clang::index::generateUSRFragmentForModuleName(StringRef ModName,
+ raw_ostream &OS) {
+ OS << "@M@" << ModName;
+ return false;
+}