diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:49 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:49 +0000 |
commit | 2298981669bf3bd63335a4be179bc0f96823a8f4 (patch) | |
tree | 1cbe2eb27f030d2d70b80ee5ca3c86bee7326a9f /lib/Index | |
parent | 9a83721404652cea39e9f02ae3e3b5c964602a5c (diff) |
Notes
Diffstat (limited to 'lib/Index')
-rw-r--r-- | lib/Index/CodegenNameGenerator.cpp | 200 | ||||
-rw-r--r-- | lib/Index/CommentToXML.cpp | 14 | ||||
-rw-r--r-- | lib/Index/FileIndexRecord.cpp | 60 | ||||
-rw-r--r-- | lib/Index/FileIndexRecord.h | 57 | ||||
-rw-r--r-- | lib/Index/IndexBody.cpp | 7 | ||||
-rw-r--r-- | lib/Index/IndexDecl.cpp | 35 | ||||
-rw-r--r-- | lib/Index/IndexSymbol.cpp | 49 | ||||
-rw-r--r-- | lib/Index/IndexTypeSourceInfo.cpp | 58 | ||||
-rw-r--r-- | lib/Index/IndexingAction.cpp | 7 | ||||
-rw-r--r-- | lib/Index/IndexingContext.cpp | 28 | ||||
-rw-r--r-- | lib/Index/IndexingContext.h | 11 | ||||
-rw-r--r-- | lib/Index/SimpleFormatContext.h | 7 | ||||
-rw-r--r-- | lib/Index/USRGeneration.cpp | 16 |
13 files changed, 271 insertions, 278 deletions
diff --git a/lib/Index/CodegenNameGenerator.cpp b/lib/Index/CodegenNameGenerator.cpp index bf52e2108baa..56d3d0603486 100644 --- a/lib/Index/CodegenNameGenerator.cpp +++ b/lib/Index/CodegenNameGenerator.cpp @@ -1,9 +1,8 @@ //===- CodegenNameGenerator.cpp - Codegen name generation -----------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -13,203 +12,12 @@ #include "clang/Index/CodegenNameGenerator.h" #include "clang/AST/ASTContext.h" -#include "clang/AST/DeclCXX.h" -#include "clang/AST/DeclObjC.h" -#include "clang/AST/Mangle.h" -#include "clang/AST/VTableBuilder.h" -#include "clang/Basic/TargetInfo.h" -#include "llvm/IR/DataLayout.h" -#include "llvm/IR/Mangler.h" -#include "llvm/Support/raw_ostream.h" using namespace clang; using namespace clang::index; -struct CodegenNameGenerator::Implementation { - std::unique_ptr<MangleContext> MC; - llvm::DataLayout DL; - - Implementation(ASTContext &Ctx) - : MC(Ctx.createMangleContext()), - DL(Ctx.getTargetInfo().getDataLayout()) {} - - bool writeName(const Decl *D, raw_ostream &OS) { - // First apply frontend mangling. - SmallString<128> FrontendBuf; - llvm::raw_svector_ostream FrontendBufOS(FrontendBuf); - if (auto *FD = dyn_cast<FunctionDecl>(D)) { - if (FD->isDependentContext()) - return true; - if (writeFuncOrVarName(FD, FrontendBufOS)) - return true; - } else if (auto *VD = dyn_cast<VarDecl>(D)) { - if (writeFuncOrVarName(VD, FrontendBufOS)) - return true; - } else if (auto *MD = dyn_cast<ObjCMethodDecl>(D)) { - MC->mangleObjCMethodNameWithoutSize(MD, OS); - return false; - } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { - writeObjCClassName(ID, FrontendBufOS); - } else { - return true; - } - - // Now apply backend mangling. - llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL); - return false; - } - - std::string getName(const Decl *D) { - std::string Name; - { - llvm::raw_string_ostream OS(Name); - writeName(D, OS); - } - return Name; - } - - enum ObjCKind { - ObjCClass, - ObjCMetaclass, - }; - - std::vector<std::string> getAllManglings(const ObjCContainerDecl *OCD) { - StringRef ClassName; - if (const auto *OID = dyn_cast<ObjCInterfaceDecl>(OCD)) - ClassName = OID->getObjCRuntimeNameAsString(); - else if (const auto *OID = dyn_cast<ObjCImplementationDecl>(OCD)) - ClassName = OID->getObjCRuntimeNameAsString(); - - if (ClassName.empty()) - return {}; - - auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string { - SmallString<40> Mangled; - auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext()); - llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL); - return Mangled.str(); - }; - - return { - Mangle(ObjCClass, ClassName), - Mangle(ObjCMetaclass, ClassName), - }; - } - - std::vector<std::string> getAllManglings(const Decl *D) { - if (const auto *OCD = dyn_cast<ObjCContainerDecl>(D)) - return getAllManglings(OCD); - - if (!(isa<CXXRecordDecl>(D) || isa<CXXMethodDecl>(D))) - return {}; - - const NamedDecl *ND = cast<NamedDecl>(D); - - ASTContext &Ctx = ND->getASTContext(); - std::unique_ptr<MangleContext> M(Ctx.createMangleContext()); - - std::vector<std::string> Manglings; - - auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) { - auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false, - /*IsCSSMethod=*/true); - auto CC = MD->getType()->getAs<FunctionProtoType>()->getCallConv(); - return CC == DefaultCC; - }; - - if (const auto *CD = dyn_cast_or_null<CXXConstructorDecl>(ND)) { - Manglings.emplace_back(getMangledStructor(CD, Ctor_Base)); - - if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily()) - if (!CD->getParent()->isAbstract()) - Manglings.emplace_back(getMangledStructor(CD, Ctor_Complete)); - - if (Ctx.getTargetInfo().getCXXABI().isMicrosoft()) - if (CD->hasAttr<DLLExportAttr>() && CD->isDefaultConstructor()) - if (!(hasDefaultCXXMethodCC(Ctx, CD) && CD->getNumParams() == 0)) - Manglings.emplace_back(getMangledStructor(CD, Ctor_DefaultClosure)); - } else if (const auto *DD = dyn_cast_or_null<CXXDestructorDecl>(ND)) { - Manglings.emplace_back(getMangledStructor(DD, Dtor_Base)); - if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily()) { - Manglings.emplace_back(getMangledStructor(DD, Dtor_Complete)); - if (DD->isVirtual()) - Manglings.emplace_back(getMangledStructor(DD, Dtor_Deleting)); - } - } else if (const auto *MD = dyn_cast_or_null<CXXMethodDecl>(ND)) { - Manglings.emplace_back(getName(ND)); - if (MD->isVirtual()) - if (const auto *TIV = Ctx.getVTableContext()->getThunkInfo(MD)) - for (const auto &T : *TIV) - Manglings.emplace_back(getMangledThunk(MD, T)); - } - - return Manglings; - } - -private: - bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS) { - if (MC->shouldMangleDeclName(D)) { - if (const auto *CtorD = dyn_cast<CXXConstructorDecl>(D)) - MC->mangleCXXCtor(CtorD, Ctor_Complete, OS); - else if (const auto *DtorD = dyn_cast<CXXDestructorDecl>(D)) - MC->mangleCXXDtor(DtorD, Dtor_Complete, OS); - else - MC->mangleName(D, OS); - return false; - } else { - IdentifierInfo *II = D->getIdentifier(); - if (!II) - return true; - OS << II->getName(); - return false; - } - } - - void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS) { - OS << getClassSymbolPrefix(ObjCClass, D->getASTContext()); - OS << D->getObjCRuntimeNameAsString(); - } - - static StringRef getClassSymbolPrefix(ObjCKind Kind, const ASTContext &Context) { - if (Context.getLangOpts().ObjCRuntime.isGNUFamily()) - return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_"; - return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_"; - } - - std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType) { - std::string FrontendBuf; - llvm::raw_string_ostream FOS(FrontendBuf); - - if (const auto *CD = dyn_cast_or_null<CXXConstructorDecl>(ND)) - MC->mangleCXXCtor(CD, static_cast<CXXCtorType>(StructorType), FOS); - else if (const auto *DD = dyn_cast_or_null<CXXDestructorDecl>(ND)) - MC->mangleCXXDtor(DD, static_cast<CXXDtorType>(StructorType), FOS); - - std::string BackendBuf; - llvm::raw_string_ostream BOS(BackendBuf); - - llvm::Mangler::getNameWithPrefix(BOS, FOS.str(), DL); - - return BOS.str(); - } - - std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo &T) { - std::string FrontendBuf; - llvm::raw_string_ostream FOS(FrontendBuf); - - MC->mangleThunk(MD, T, FOS); - - std::string BackendBuf; - llvm::raw_string_ostream BOS(BackendBuf); - - llvm::Mangler::getNameWithPrefix(BOS, FOS.str(), DL); - - return BOS.str(); - } -}; - CodegenNameGenerator::CodegenNameGenerator(ASTContext &Ctx) - : Impl(new Implementation(Ctx)) { + : Impl(new ASTNameGenerator(Ctx)) { } CodegenNameGenerator::~CodegenNameGenerator() { diff --git a/lib/Index/CommentToXML.cpp b/lib/Index/CommentToXML.cpp index a2659119a2ff..55923d679fea 100644 --- a/lib/Index/CommentToXML.cpp +++ b/lib/Index/CommentToXML.cpp @@ -1,9 +1,8 @@ //===--- CommentToXML.cpp - Convert comments to XML representation --------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -189,11 +188,8 @@ FullCommentParts::FullCommentParts(const FullComment *C, // Sort params in order they are declared in the function prototype. // Unresolved parameters are put at the end of the list in the same order // they were seen in the comment. - std::stable_sort(Params.begin(), Params.end(), - ParamCommandCommentCompareIndex()); - - std::stable_sort(TParams.begin(), TParams.end(), - TParamCommandCommentComparePosition()); + llvm::stable_sort(Params, ParamCommandCommentCompareIndex()); + llvm::stable_sort(TParams, TParamCommandCommentComparePosition()); } void printHTMLStartTagComment(const HTMLStartTagComment *C, diff --git a/lib/Index/FileIndexRecord.cpp b/lib/Index/FileIndexRecord.cpp new file mode 100644 index 000000000000..c9dcb0f5377d --- /dev/null +++ b/lib/Index/FileIndexRecord.cpp @@ -0,0 +1,60 @@ +//===--- FileIndexRecord.cpp - Index data per file --------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "FileIndexRecord.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclTemplate.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Path.h" + +using namespace clang; +using namespace clang::index; + +void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, + const Decl *D, + ArrayRef<SymbolRelation> Relations) { + assert(D->isCanonicalDecl() && + "Occurrences should be associated with their canonical decl"); + + auto IsNextOccurence = [&]() -> bool { + if (Decls.empty()) + return true; + auto &Last = Decls.back(); + return Last.Offset < Offset; + }; + + if (IsNextOccurence()) { + Decls.emplace_back(Roles, Offset, D, Relations); + return; + } + + DeclOccurrence NewInfo(Roles, Offset, D, Relations); + // We keep Decls in order as we need to access them in this order in all cases. + auto It = llvm::upper_bound(Decls, NewInfo); + Decls.insert(It, std::move(NewInfo)); +} + +void FileIndexRecord::print(llvm::raw_ostream &OS) const { + OS << "DECLS BEGIN ---\n"; + for (auto &DclInfo : Decls) { + const Decl *D = DclInfo.Dcl; + SourceManager &SM = D->getASTContext().getSourceManager(); + SourceLocation Loc = SM.getFileLoc(D->getLocation()); + PresumedLoc PLoc = SM.getPresumedLoc(Loc); + OS << llvm::sys::path::filename(PLoc.getFilename()) << ':' << PLoc.getLine() + << ':' << PLoc.getColumn(); + + if (auto ND = dyn_cast<NamedDecl>(D)) { + OS << ' ' << ND->getNameAsString(); + } + + OS << '\n'; + } + OS << "DECLS END ---\n"; +} diff --git a/lib/Index/FileIndexRecord.h b/lib/Index/FileIndexRecord.h new file mode 100644 index 000000000000..37bf96a71964 --- /dev/null +++ b/lib/Index/FileIndexRecord.h @@ -0,0 +1,57 @@ +//===--- FileIndexRecord.h - Index data per file ----------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H +#define LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H + +#include "clang/Basic/SourceLocation.h" +#include "clang/Index/DeclOccurrence.h" +#include "clang/Index/IndexSymbol.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" +#include <vector> + +namespace clang { +class IdentifierInfo; + +namespace index { + +/// Stores the declaration occurrences seen in a particular source or header +/// file of a translation unit +class FileIndexRecord { +private: + FileID FID; + bool IsSystem; + std::vector<DeclOccurrence> Decls; + +public: + FileIndexRecord(FileID FID, bool IsSystem) : FID(FID), IsSystem(IsSystem) {} + + ArrayRef<DeclOccurrence> getDeclOccurrencesSortedByOffset() const { + return Decls; + } + + FileID getFileID() const { return FID; } + bool isSystem() const { return IsSystem; } + + /// Adds an occurrence of the canonical declaration \c D at the supplied + /// \c Offset + /// + /// \param Roles the roles the occurrence fulfills in this position. + /// \param Offset the offset in the file of this occurrence. + /// \param D the canonical declaration this is an occurrence of. + /// \param Relations the set of symbols related to this occurrence. + void addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, const Decl *D, + ArrayRef<SymbolRelation> Relations); + void print(llvm::raw_ostream &OS) const; +}; + +} // end namespace index +} // end namespace clang + +#endif // LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H diff --git a/lib/Index/IndexBody.cpp b/lib/Index/IndexBody.cpp index 54a6df2496a9..07a94f30c883 100644 --- a/lib/Index/IndexBody.cpp +++ b/lib/Index/IndexBody.cpp @@ -1,9 +1,8 @@ //===- IndexBody.cpp - Indexing statements --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index a7725f9dd97f..5bbbb0d32bf4 100644 --- a/lib/Index/IndexDecl.cpp +++ b/lib/Index/IndexDecl.cpp @@ -1,9 +1,8 @@ //===- IndexDecl.cpp - Indexing declarations ------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -89,12 +88,11 @@ public: /*isBase=*/false, isIBType); IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent); if (IndexCtx.shouldIndexFunctionLocalSymbols()) { - // Only index parameters in definitions, parameters in declarations are - // not useful. if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { auto *DC = Parm->getDeclContext(); if (auto *FD = dyn_cast<FunctionDecl>(DC)) { - if (FD->isThisDeclarationADefinition()) + if (IndexCtx.shouldIndexParametersInDeclarations() || + FD->isThisDeclarationADefinition()) IndexCtx.handleDecl(Parm); } else if (auto *MD = dyn_cast<ObjCMethodDecl>(DC)) { if (MD->isThisDeclarationADefinition()) @@ -103,7 +101,8 @@ public: IndexCtx.handleDecl(Parm); } } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { - if (FD->isThisDeclarationADefinition()) { + if (IndexCtx.shouldIndexParametersInDeclarations() || + FD->isThisDeclarationADefinition()) { for (auto PI : FD->parameters()) { IndexCtx.handleDecl(PI); } @@ -248,7 +247,8 @@ public: if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) { IndexCtx.handleReference(Ctor->getParent(), Ctor->getLocation(), - Ctor->getParent(), Ctor->getDeclContext()); + Ctor->getParent(), Ctor->getDeclContext(), + (unsigned)SymbolRole::NameReference); // Constructor initializers. for (const auto *Init : Ctor->inits()) { @@ -264,7 +264,8 @@ public: if (auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) { IndexCtx.handleReference(Dtor->getParent(), TypeNameInfo->getTypeLoc().getBeginLoc(), - Dtor->getParent(), Dtor->getDeclContext()); + Dtor->getParent(), Dtor->getDeclContext(), + (unsigned)SymbolRole::NameReference); } } else if (const auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) { IndexCtx.handleReference(Guide->getDeducedTemplate()->getTemplatedDecl(), @@ -325,6 +326,7 @@ public: } bool VisitMSPropertyDecl(const MSPropertyDecl *D) { + TRY_DECL(D, IndexCtx.handleDecl(D)); handleDeclarator(D); return true; } @@ -414,7 +416,7 @@ public: if (D->isThisDeclarationADefinition()) { TRY_DECL(D, IndexCtx.handleDecl(D)); TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D, - /*superLoc=*/SourceLocation())); + /*SuperLoc=*/SourceLocation())); TRY_TO(IndexCtx.indexDeclContext(D)); } else { return IndexCtx.handleReference(D, D->getLocation(), nullptr, @@ -464,7 +466,7 @@ public: CategoryLoc = D->getLocation(); TRY_TO(IndexCtx.handleDecl(D, CategoryLoc)); TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D, - /*superLoc=*/SourceLocation())); + /*SuperLoc=*/SourceLocation())); TRY_TO(IndexCtx.indexDeclContext(D)); return true; } @@ -581,9 +583,10 @@ public: } bool VisitUsingDecl(const UsingDecl *D) { + IndexCtx.handleDecl(D); + const DeclContext *DC = D->getDeclContext()->getRedeclContext(); const NamedDecl *Parent = dyn_cast<NamedDecl>(DC); - IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent, D->getLexicalDeclContext()); for (const auto *I : D->shadows()) @@ -649,10 +652,10 @@ public: } static bool shouldIndexTemplateParameterDefaultValue(const NamedDecl *D) { - if (!D) - return false; // We want to index the template parameters only once when indexing the // canonical declaration. + if (!D) + return false; if (const auto *FD = dyn_cast<FunctionDecl>(D)) return FD->getCanonicalDecl() == FD; else if (const auto *TD = dyn_cast<TagDecl>(D)) @@ -673,6 +676,8 @@ public: shouldIndexTemplateParameterDefaultValue(Parent)) { const TemplateParameterList *Params = D->getTemplateParameters(); for (const NamedDecl *TP : *Params) { + if (IndexCtx.shouldIndexTemplateParameters()) + IndexCtx.handleDecl(TP); if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(TP)) { if (TTP->hasDefaultArgument()) IndexCtx.indexTypeSourceInfo(TTP->getDefaultArgumentInfo(), Parent); diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp index 1cdc0984f780..064f3ae32f9e 100644 --- a/lib/Index/IndexSymbol.cpp +++ b/lib/Index/IndexSymbol.cpp @@ -1,9 +1,8 @@ //===--- IndexSymbol.cpp - Types and functions for indexing symbols -------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -56,9 +55,6 @@ bool index::isFunctionLocalSymbol(const Decl *D) { if (isa<ParmVarDecl>(D)) return true; - if (isa<TemplateTemplateParmDecl>(D)) - return true; - if (isa<ObjCTypeParamDecl>(D)) return true; @@ -100,6 +96,13 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Properties |= (SymbolPropertySet)SymbolProperty::ProtocolInterface; } + if (auto *VT = dyn_cast<VarTemplateDecl>(D)) { + Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; + Info.Lang = SymbolLanguage::CXX; + // All other fields are filled from the templated decl. + D = VT->getTemplatedDecl(); + } + if (const TagDecl *TD = dyn_cast<TagDecl>(D)) { switch (TD->getTagKind()) { case TTK_Struct: @@ -172,6 +175,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Kind = SymbolKind::Function; break; case Decl::Field: + case Decl::IndirectField: Info.Kind = SymbolKind::Field; if (const CXXRecordDecl * CXXRec = dyn_cast<CXXRecordDecl>(D->getDeclContext())) { @@ -320,10 +324,39 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Lang = SymbolLanguage::CXX; Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; break; + case Decl::Using: + Info.Kind = SymbolKind::Using; + Info.Lang = SymbolLanguage::CXX; + break; case Decl::Binding: Info.Kind = SymbolKind::Variable; Info.Lang = SymbolLanguage::CXX; break; + case Decl::MSProperty: + Info.Kind = SymbolKind::InstanceProperty; + if (const CXXRecordDecl *CXXRec = + dyn_cast<CXXRecordDecl>(D->getDeclContext())) { + if (!CXXRec->isCLike()) + Info.Lang = SymbolLanguage::CXX; + } + break; + case Decl::ClassTemplatePartialSpecialization: + case Decl::ClassScopeFunctionSpecialization: + case Decl::ClassTemplateSpecialization: + case Decl::CXXRecord: + case Decl::Enum: + case Decl::Record: + llvm_unreachable("records handled before"); + break; + case Decl::VarTemplateSpecialization: + case Decl::VarTemplatePartialSpecialization: + case Decl::ImplicitParam: + case Decl::ParmVar: + case Decl::Var: + case Decl::VarTemplate: + llvm_unreachable("variables handled before"); + break; + // Other decls get the 'unknown' kind. default: break; } @@ -388,6 +421,7 @@ bool index::applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, APPLY_FOR_ROLE(RelationContainedBy); APPLY_FOR_ROLE(RelationIBTypeOf); APPLY_FOR_ROLE(RelationSpecializationOf); + APPLY_FOR_ROLE(NameReference); #undef APPLY_FOR_ROLE @@ -430,6 +464,7 @@ void index::printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS) { case SymbolRole::RelationContainedBy: OS << "RelCont"; break; case SymbolRole::RelationIBTypeOf: OS << "RelIBType"; break; case SymbolRole::RelationSpecializationOf: OS << "RelSpecialization"; break; + case SymbolRole::NameReference: OS << "NameReference"; break; } }); } diff --git a/lib/Index/IndexTypeSourceInfo.cpp b/lib/Index/IndexTypeSourceInfo.cpp index 85afc6345053..959d5f1197fe 100644 --- a/lib/Index/IndexTypeSourceInfo.cpp +++ b/lib/Index/IndexTypeSourceInfo.cpp @@ -1,9 +1,8 @@ //===- IndexTypeSourceInfo.cpp - Indexing types ---------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -46,6 +45,13 @@ public: return false; \ } while (0) + bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TTPL) { + SourceLocation Loc = TTPL.getNameLoc(); + TemplateTypeParmDecl *TTPD = TTPL.getDecl(); + return IndexCtx.handleReference(TTPD, Loc, Parent, ParentDC, + SymbolRoleSet()); + } + bool VisitTypedefTypeLoc(TypedefTypeLoc TL) { SourceLocation Loc = TL.getNameLoc(); TypedefNameDecl *ND = TL.getTypedefNameDecl(); @@ -127,29 +133,41 @@ public: return true; } - template<typename TypeLocType> - bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) { - if (const auto *T = TL.getTypePtr()) { - if (IndexCtx.shouldIndexImplicitInstantiation()) { - if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) { - IndexCtx.handleReference(RD, TL.getTemplateNameLoc(), - Parent, ParentDC, SymbolRoleSet(), Relations); - return true; - } - } - if (const TemplateDecl *D = T->getTemplateName().getAsTemplateDecl()) - IndexCtx.handleReference(D, TL.getTemplateNameLoc(), Parent, ParentDC, - SymbolRoleSet(), Relations); + void HandleTemplateSpecializationTypeLoc(TemplateName TemplName, + SourceLocation TemplNameLoc, + CXXRecordDecl *ResolvedClass, + bool IsTypeAlias) { + // In presence of type aliases, the resolved class was never written in + // the code so don't report it. + if (!IsTypeAlias && ResolvedClass && + (!ResolvedClass->isImplicit() || + IndexCtx.shouldIndexImplicitInstantiation())) { + IndexCtx.handleReference(ResolvedClass, TemplNameLoc, Parent, ParentDC, + SymbolRoleSet(), Relations); + } else if (const TemplateDecl *D = TemplName.getAsTemplateDecl()) { + IndexCtx.handleReference(D, TemplNameLoc, Parent, ParentDC, + SymbolRoleSet(), Relations); } - return true; } bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) { - return HandleTemplateSpecializationTypeLoc(TL); + auto *T = TL.getTypePtr(); + if (!T) + return true; + HandleTemplateSpecializationTypeLoc( + T->getTemplateName(), TL.getTemplateNameLoc(), T->getAsCXXRecordDecl(), + T->isTypeAlias()); + return true; } bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) { - return HandleTemplateSpecializationTypeLoc(TL); + auto *T = TL.getTypePtr(); + if (!T) + return true; + HandleTemplateSpecializationTypeLoc( + T->getTemplateName(), TL.getTemplateNameLoc(), T->getAsCXXRecordDecl(), + /*IsTypeAlias=*/false); + return true; } bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { diff --git a/lib/Index/IndexingAction.cpp b/lib/Index/IndexingAction.cpp index 5cdec4b4528e..5a805c4abcd6 100644 --- a/lib/Index/IndexingAction.cpp +++ b/lib/Index/IndexingAction.cpp @@ -1,9 +1,8 @@ //===- IndexingAction.cpp - Frontend index action -------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/lib/Index/IndexingContext.cpp b/lib/Index/IndexingContext.cpp index bba6c8390b56..e29856007149 100644 --- a/lib/Index/IndexingContext.cpp +++ b/lib/Index/IndexingContext.cpp @@ -1,9 +1,8 @@ //===- IndexingContext.cpp - Indexing context data ------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -41,6 +40,14 @@ bool IndexingContext::shouldIndexImplicitInstantiation() const { return IndexOpts.IndexImplicitInstantiation; } +bool IndexingContext::shouldIndexParametersInDeclarations() const { + return IndexOpts.IndexParametersInDeclarations; +} + +bool IndexingContext::shouldIndexTemplateParameters() const { + return IndexOpts.IndexTemplateParameters; +} + bool IndexingContext::handleDecl(const Decl *D, SymbolRoleSet Roles, ArrayRef<SymbolRelation> Relations) { @@ -73,8 +80,11 @@ bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalSymbol(D)) return true; - if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D)) + if (!shouldIndexTemplateParameters() && + (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) || + isa<TemplateTemplateParmDecl>(D))) { return true; + } return handleDeclOccurrence(D, Loc, /*IsRef=*/true, Parent, Roles, Relations, RefE, RefD, DC); @@ -322,6 +332,7 @@ static bool shouldReportOccurrenceForSystemDeclOnlyMode( case SymbolRole::RelationCalledBy: case SymbolRole::RelationContainedBy: case SymbolRole::RelationSpecializationOf: + case SymbolRole::NameReference: return true; } llvm_unreachable("Unsupported SymbolRole value!"); @@ -400,10 +411,9 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc, FinalRelations.reserve(Relations.size()+1); auto addRelation = [&](SymbolRelation Rel) { - auto It = std::find_if(FinalRelations.begin(), FinalRelations.end(), - [&](SymbolRelation Elem)->bool { - return Elem.RelatedSymbol == Rel.RelatedSymbol; - }); + auto It = llvm::find_if(FinalRelations, [&](SymbolRelation Elem) -> bool { + return Elem.RelatedSymbol == Rel.RelatedSymbol; + }); if (It != FinalRelations.end()) { It->Roles |= Rel.Roles; } else { diff --git a/lib/Index/IndexingContext.h b/lib/Index/IndexingContext.h index 04960086d092..3136878c080c 100644 --- a/lib/Index/IndexingContext.h +++ b/lib/Index/IndexingContext.h @@ -1,9 +1,8 @@ //===- IndexingContext.h - Indexing context data ----------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -62,6 +61,10 @@ public: bool shouldIndexImplicitInstantiation() const; + bool shouldIndexParametersInDeclarations() const; + + bool shouldIndexTemplateParameters() const; + static bool isTemplateImplicitInstantiation(const Decl *D); bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(), diff --git a/lib/Index/SimpleFormatContext.h b/lib/Index/SimpleFormatContext.h index 24adcac60201..17793154a3ae 100644 --- a/lib/Index/SimpleFormatContext.h +++ b/lib/Index/SimpleFormatContext.h @@ -1,9 +1,8 @@ //===--- SimpleFormatContext.h ----------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp index 84ca753bf840..228651de928e 100644 --- a/lib/Index/USRGeneration.cpp +++ b/lib/Index/USRGeneration.cpp @@ -1,9 +1,8 @@ //===- USRGeneration.cpp - Routines for USR generation --------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -112,7 +111,12 @@ public: } void VisitUsingDecl(const UsingDecl *D) { - IgnoreResults = true; + VisitDeclContext(D->getDeclContext()); + Out << "@UD@"; + + bool EmittedDeclName = !EmitDeclName(D); + assert(EmittedDeclName && "EmitDeclName can not fail for UsingDecls"); + (void)EmittedDeclName; } bool ShouldGenerateLocation(const NamedDecl *D); @@ -271,7 +275,7 @@ void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) { if (MD->isStatic()) Out << 'S'; // FIXME: OpenCL: Need to consider address spaces - if (unsigned quals = MD->getTypeQualifiers().getCVRUQualifiers()) + if (unsigned quals = MD->getMethodQualifiers().getCVRUQualifiers()) Out << (char)('0' + quals); switch (MD->getRefQualifier()) { case RQ_None: break; |