diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Index')
8 files changed, 261 insertions, 158 deletions
diff --git a/contrib/llvm/tools/clang/lib/Index/CommentToXML.cpp b/contrib/llvm/tools/clang/lib/Index/CommentToXML.cpp index c4beef2..ee066cc 100644 --- a/contrib/llvm/tools/clang/lib/Index/CommentToXML.cpp +++ b/contrib/llvm/tools/clang/lib/Index/CommentToXML.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "clang/Index/CommentToXML.h" -#include "SimpleFormatContext.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" #include "clang/AST/Comment.h" @@ -531,12 +530,8 @@ public: CommentASTToXMLConverter(const FullComment *FC, SmallVectorImpl<char> &Str, const CommandTraits &Traits, - const SourceManager &SM, - SimpleFormatContext &SFC, - unsigned FUID) : - FC(FC), Result(Str), Traits(Traits), SM(SM), - FormatRewriterContext(SFC), - FormatInMemoryUniqueId(FUID) { } + const SourceManager &SM) : + FC(FC), Result(Str), Traits(Traits), SM(SM) { } // Inline content. void visitTextComment(const TextComment *C); @@ -574,8 +569,6 @@ private: const CommandTraits &Traits; const SourceManager &SM; - SimpleFormatContext &FormatRewriterContext; - unsigned FormatInMemoryUniqueId; }; void getSourceTextOfDeclaration(const DeclInfo *ThisDecl, @@ -596,21 +589,17 @@ void CommentASTToXMLConverter::formatTextOfDeclaration( StringRef StringDecl(Declaration.c_str(), Declaration.size()); // Formatter specific code. - // Form a unique in memory buffer name. - SmallString<128> filename; - filename += "xmldecl"; - filename += llvm::utostr(FormatInMemoryUniqueId); - filename += ".xd"; - FileID ID = FormatRewriterContext.createInMemoryFile(filename, StringDecl); - SourceLocation Start = FormatRewriterContext.Sources.getLocForStartOfFile(ID) - .getLocWithOffset(0); + unsigned Offset = 0; unsigned Length = Declaration.size(); - tooling::Replacements Replace = reformat( - format::getLLVMStyle(), FormatRewriterContext.Sources, ID, - CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length))); - applyAllReplacements(Replace, FormatRewriterContext.Rewrite); - Declaration = FormatRewriterContext.getRewrittenText(ID); + bool IncompleteFormat = false; + tooling::Replacements Replaces = + reformat(format::getLLVMStyle(), StringDecl, + tooling::Range(Offset, Length), "xmldecl.xd", &IncompleteFormat); + auto FormattedStringDecl = applyAllReplacements(StringDecl, Replaces); + if (static_cast<bool>(FormattedStringDecl)) { + Declaration = *FormattedStringDecl; + } } } // end unnamed namespace @@ -1126,7 +1115,7 @@ void CommentASTToXMLConverter::appendToResultWithCDATAEscaping(StringRef S) { Result << "]]>"; } -CommentToXMLConverter::CommentToXMLConverter() : FormatInMemoryUniqueId(0) {} +CommentToXMLConverter::CommentToXMLConverter() {} CommentToXMLConverter::~CommentToXMLConverter() {} void CommentToXMLConverter::convertCommentToHTML(const FullComment *FC, @@ -1148,15 +1137,7 @@ void CommentToXMLConverter::convertHTMLTagNodeToText( void CommentToXMLConverter::convertCommentToXML(const FullComment *FC, SmallVectorImpl<char> &XML, const ASTContext &Context) { - if (!FormatContext || (FormatInMemoryUniqueId % 1000) == 0) { - // Create a new format context, or re-create it after some number of - // iterations, so the buffers don't grow too large. - FormatContext.reset(new SimpleFormatContext(Context.getLangOpts())); - } - CommentASTToXMLConverter Converter(FC, XML, Context.getCommentCommandTraits(), - Context.getSourceManager(), *FormatContext, - FormatInMemoryUniqueId++); + Context.getSourceManager()); Converter.visit(FC); } - diff --git a/contrib/llvm/tools/clang/lib/Index/IndexBody.cpp b/contrib/llvm/tools/clang/lib/Index/IndexBody.cpp index 4908d85..3aa0152 100644 --- a/contrib/llvm/tools/clang/lib/Index/IndexBody.cpp +++ b/contrib/llvm/tools/clang/lib/Index/IndexBody.cpp @@ -148,7 +148,7 @@ public: bool VisitDesignatedInitExpr(DesignatedInitExpr *E) { 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); } @@ -276,7 +276,8 @@ public: return true; } - bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C) { + bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C, + Expr *Init) { if (C->capturesThis() || C->capturesVLAType()) return true; @@ -293,31 +294,6 @@ public: // Also visit things that are in the syntactic form but not the semantic one, // for example the indices in DesignatedInitExprs. bool TraverseInitListExpr(InitListExpr *S, DataRecursionQueue *Q = nullptr) { - - class SyntacticFormIndexer : - public RecursiveASTVisitor<SyntacticFormIndexer> { - IndexingContext &IndexCtx; - const NamedDecl *Parent; - const DeclContext *ParentDC; - - public: - SyntacticFormIndexer(IndexingContext &indexCtx, - const NamedDecl *Parent, const DeclContext *DC) - : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { } - - bool shouldWalkTypesOfTypeLocs() const { return false; } - - bool VisitDesignatedInitExpr(DesignatedInitExpr *E) { - for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) { - if (D.isFieldDesignator()) - return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), - Parent, ParentDC, SymbolRoleSet(), - {}, E); - } - return true; - } - }; - auto visitForm = [&](InitListExpr *Form) { for (Stmt *SubStmt : Form->children()) { if (!TraverseStmt(SubStmt, Q)) @@ -326,13 +302,26 @@ public: return true; }; + auto visitSyntacticDesignatedInitExpr = [&](DesignatedInitExpr *E) -> bool { + for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) { + if (D.isFieldDesignator()) + return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), + Parent, ParentDC, SymbolRoleSet(), + {}, E); + } + return true; + }; + InitListExpr *SemaForm = S->isSemanticForm() ? S : S->getSemanticForm(); InitListExpr *SyntaxForm = S->isSemanticForm() ? S->getSyntacticForm() : S; if (SemaForm) { // Visit things present in syntactic form but not the semantic form. if (SyntaxForm) { - SyntacticFormIndexer(IndexCtx, Parent, ParentDC).TraverseStmt(SyntaxForm); + for (Expr *init : SyntaxForm->inits()) { + if (auto *DIE = dyn_cast<DesignatedInitExpr>(init)) + visitSyntacticDesignatedInitExpr(DIE); + } } return visitForm(SemaForm); } diff --git a/contrib/llvm/tools/clang/lib/Index/IndexDecl.cpp b/contrib/llvm/tools/clang/lib/Index/IndexDecl.cpp index eb3e151..3b4f3f8 100644 --- a/contrib/llvm/tools/clang/lib/Index/IndexDecl.cpp +++ b/contrib/llvm/tools/clang/lib/Index/IndexDecl.cpp @@ -46,10 +46,13 @@ public: } void handleDeclarator(const DeclaratorDecl *D, - const NamedDecl *Parent = nullptr) { + const NamedDecl *Parent = nullptr, + bool isIBType = false) { if (!Parent) Parent = D; - IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), Parent); + IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), Parent, + Parent->getLexicalDeclContext(), + /*isBase=*/false, isIBType); IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent); if (IndexCtx.shouldIndexFunctionLocalSymbols()) { // Only index parameters in definitions, parameters in declarations are @@ -75,12 +78,34 @@ public: } } - bool handleObjCMethod(const ObjCMethodDecl *D) { - if (!IndexCtx.handleDecl(D, (unsigned)SymbolRole::Dynamic)) + bool handleObjCMethod(const ObjCMethodDecl *D, + const ObjCPropertyDecl *AssociatedProp = nullptr) { + SmallVector<SymbolRelation, 4> Relations; + SmallVector<const ObjCMethodDecl*, 4> Overriden; + + D->getOverriddenMethods(Overriden); + for(auto overridden: Overriden) { + Relations.emplace_back((unsigned) SymbolRole::RelationOverrideOf, + overridden); + } + if (AssociatedProp) + Relations.emplace_back((unsigned)SymbolRole::RelationAccessorOf, + AssociatedProp); + + // getLocation() returns beginning token of a method declaration, but for + // indexing purposes we want to point to the base name. + SourceLocation MethodLoc = D->getSelectorStartLoc(); + if (MethodLoc.isInvalid()) + MethodLoc = D->getLocation(); + + if (!IndexCtx.handleDecl(D, MethodLoc, (unsigned)SymbolRole::Dynamic, Relations)) return false; IndexCtx.indexTypeSourceInfo(D->getReturnTypeSourceInfo(), D); - for (const auto *I : D->parameters()) - handleDeclarator(I, D); + bool hasIBActionAndFirst = D->hasAttr<IBActionAttr>(); + for (const auto *I : D->parameters()) { + handleDeclarator(I, D, /*isIBType=*/hasIBActionAndFirst); + hasIBActionAndFirst = false; + } if (D->isThisDeclarationADefinition()) { const Stmt *Body = D->getBody(); @@ -269,9 +294,19 @@ public: } bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { - if (!IndexCtx.handleDecl(D)) - return false; - IndexCtx.indexDeclContext(D); + const ObjCInterfaceDecl *C = D->getClassInterface(); + if (!C) + return true; + TRY_TO(IndexCtx.handleReference(C, D->getLocation(), D, D, SymbolRoleSet(), + SymbolRelation{ + (unsigned)SymbolRole::RelationExtendedBy, D + })); + SourceLocation CategoryLoc = D->getCategoryNameLoc(); + if (!CategoryLoc.isValid()) + CategoryLoc = D->getLocation(); + TRY_TO(IndexCtx.handleDecl(D, CategoryLoc)); + TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D)); + TRY_TO(IndexCtx.indexDeclContext(D)); return true; } @@ -279,8 +314,14 @@ public: const ObjCCategoryDecl *Cat = D->getCategoryDecl(); if (!Cat) return true; - - if (!IndexCtx.handleDecl(D)) + const ObjCInterfaceDecl *C = D->getClassInterface(); + if (C) + TRY_TO(IndexCtx.handleReference(C, D->getLocation(), D, D, + SymbolRoleSet())); + SourceLocation CategoryLoc = D->getCategoryNameLoc(); + if (!CategoryLoc.isValid()) + CategoryLoc = D->getLocation(); + if (!IndexCtx.handleDecl(D, CategoryLoc)) return false; IndexCtx.indexDeclContext(D); return true; @@ -299,12 +340,15 @@ public: bool VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { if (ObjCMethodDecl *MD = D->getGetterMethodDecl()) if (MD->getLexicalDeclContext() == D->getLexicalDeclContext()) - handleObjCMethod(MD); + handleObjCMethod(MD, D); if (ObjCMethodDecl *MD = D->getSetterMethodDecl()) if (MD->getLexicalDeclContext() == D->getLexicalDeclContext()) - handleObjCMethod(MD); + handleObjCMethod(MD, D); if (!IndexCtx.handleDecl(D)) return false; + if (IBOutletCollectionAttr *attr = D->getAttr<IBOutletCollectionAttr>()) + IndexCtx.indexTypeSourceInfo(attr->getInterfaceLoc(), D, + D->getLexicalDeclContext(), false, true); IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D); return true; } diff --git a/contrib/llvm/tools/clang/lib/Index/IndexSymbol.cpp b/contrib/llvm/tools/clang/lib/Index/IndexSymbol.cpp index 13a8452..84984fc 100644 --- a/contrib/llvm/tools/clang/lib/Index/IndexSymbol.cpp +++ b/contrib/llvm/tools/clang/lib/Index/IndexSymbol.cpp @@ -40,12 +40,12 @@ static bool isUnitTest(const ObjCMethodDecl *D) { return isUnitTestCase(D->getClassInterface()); } -static void checkForIBOutlets(const Decl *D, SymbolSubKindSet &SubKindSet) { +static void checkForIBOutlets(const Decl *D, SymbolPropertySet &PropSet) { if (D->hasAttr<IBOutletAttr>()) { - SubKindSet |= (unsigned)SymbolSubKind::IBAnnotated; + PropSet |= (unsigned)SymbolProperty::IBAnnotated; } else if (D->hasAttr<IBOutletCollectionAttr>()) { - SubKindSet |= (unsigned)SymbolSubKind::IBAnnotated; - SubKindSet |= (unsigned)SymbolSubKind::IBOutletCollection; + PropSet |= (unsigned)SymbolProperty::IBAnnotated; + PropSet |= (unsigned)SymbolProperty::IBOutletCollection; } } @@ -53,7 +53,8 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { assert(D); SymbolInfo Info; Info.Kind = SymbolKind::Unknown; - Info.SubKinds = SymbolSubKindSet(); + Info.SubKind = SymbolSubKind::None; + Info.Properties = SymbolPropertySet(); Info.Lang = SymbolLanguage::C; if (const TagDecl *TD = dyn_cast<TagDecl>(D)) { @@ -74,16 +75,40 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Kind = SymbolKind::Enum; break; } - if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) - if (!CXXRec->isCLike()) + if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) { + if (!CXXRec->isCLike()) { Info.Lang = SymbolLanguage::CXX; + if (CXXRec->getDescribedClassTemplate()) { + Info.Properties |= (unsigned)SymbolProperty::Generic; + } + } + } if (isa<ClassTemplatePartialSpecializationDecl>(D)) { - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; - Info.SubKinds |= (unsigned)SymbolSubKind::TemplatePartialSpecialization; + Info.Properties |= (unsigned)SymbolProperty::Generic; + Info.Properties |= (unsigned)SymbolProperty::TemplatePartialSpecialization; } else if (isa<ClassTemplateSpecializationDecl>(D)) { - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; - Info.SubKinds |= (unsigned)SymbolSubKind::TemplateSpecialization; + Info.Properties |= (unsigned)SymbolProperty::Generic; + Info.Properties |= (unsigned)SymbolProperty::TemplateSpecialization; + } + + } else if (auto *VD = dyn_cast<VarDecl>(D)) { + Info.Kind = SymbolKind::Variable; + if (isa<CXXRecordDecl>(D->getDeclContext())) { + Info.Kind = SymbolKind::StaticProperty; + Info.Lang = SymbolLanguage::CXX; + } + if (isa<VarTemplatePartialSpecializationDecl>(D)) { + Info.Lang = SymbolLanguage::CXX; + Info.Properties |= (unsigned)SymbolProperty::Generic; + Info.Properties |= (unsigned)SymbolProperty::TemplatePartialSpecialization; + } else if (isa<VarTemplateSpecializationDecl>(D)) { + Info.Lang = SymbolLanguage::CXX; + Info.Properties |= (unsigned)SymbolProperty::Generic; + Info.Properties |= (unsigned)SymbolProperty::TemplateSpecialization; + } else if (VD->getDescribedVarTemplate()) { + Info.Lang = SymbolLanguage::CXX; + Info.Properties |= (unsigned)SymbolProperty::Generic; } } else { @@ -96,16 +121,6 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { case Decl::Function: Info.Kind = SymbolKind::Function; break; - case Decl::ParmVar: - Info.Kind = SymbolKind::Variable; - break; - case Decl::Var: - Info.Kind = SymbolKind::Variable; - if (isa<CXXRecordDecl>(D->getDeclContext())) { - Info.Kind = SymbolKind::StaticProperty; - Info.Lang = SymbolLanguage::CXX; - } - break; case Decl::Field: Info.Kind = SymbolKind::Field; if (const CXXRecordDecl * @@ -124,7 +139,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { if (!ClsD) ClsD = cast<ObjCImplementationDecl>(D)->getClassInterface(); if (isUnitTestCase(ClsD)) - Info.SubKinds |= (unsigned)SymbolSubKind::UnitTest; + Info.Properties |= (unsigned)SymbolProperty::UnitTest; break; } case Decl::ObjCProtocol: @@ -137,25 +152,37 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Lang = SymbolLanguage::ObjC; break; case Decl::ObjCMethod: - if (cast<ObjCMethodDecl>(D)->isInstanceMethod()) + if (cast<ObjCMethodDecl>(D)->isInstanceMethod()) { + const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(D); Info.Kind = SymbolKind::InstanceMethod; - else + if (MD->isPropertyAccessor()) { + if (MD->param_size()) + Info.SubKind = SymbolSubKind::AccessorSetter; + else + Info.SubKind = SymbolSubKind::AccessorGetter; + } + } else { Info.Kind = SymbolKind::ClassMethod; + } Info.Lang = SymbolLanguage::ObjC; if (isUnitTest(cast<ObjCMethodDecl>(D))) - Info.SubKinds |= (unsigned)SymbolSubKind::UnitTest; + Info.Properties |= (unsigned)SymbolProperty::UnitTest; if (D->hasAttr<IBActionAttr>()) - Info.SubKinds |= (unsigned)SymbolSubKind::IBAnnotated; + Info.Properties |= (unsigned)SymbolProperty::IBAnnotated; break; case Decl::ObjCProperty: Info.Kind = SymbolKind::InstanceProperty; Info.Lang = SymbolLanguage::ObjC; - checkForIBOutlets(D, Info.SubKinds); + checkForIBOutlets(D, Info.Properties); + if (auto *Annot = D->getAttr<AnnotateAttr>()) { + if (Annot->getAnnotation() == "gk_inspectable") + Info.Properties |= (unsigned)SymbolProperty::GKInspectable; + } break; case Decl::ObjCIvar: Info.Kind = SymbolKind::Field; Info.Lang = SymbolLanguage::ObjC; - checkForIBOutlets(D, Info.SubKinds); + checkForIBOutlets(D, Info.Properties); break; case Decl::Namespace: Info.Kind = SymbolKind::Namespace; @@ -165,10 +192,16 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Kind = SymbolKind::NamespaceAlias; Info.Lang = SymbolLanguage::CXX; break; - case Decl::CXXConstructor: + case Decl::CXXConstructor: { Info.Kind = SymbolKind::Constructor; Info.Lang = SymbolLanguage::CXX; + auto *CD = cast<CXXConstructorDecl>(D); + if (CD->isCopyConstructor()) + Info.SubKind = SymbolSubKind::CXXCopyConstructor; + else if (CD->isMoveConstructor()) + Info.SubKind = SymbolSubKind::CXXMoveConstructor; break; + } case Decl::CXXDestructor: Info.Kind = SymbolKind::Destructor; Info.Lang = SymbolLanguage::CXX; @@ -188,12 +221,12 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { } case Decl::ClassTemplate: Info.Kind = SymbolKind::Class; - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; + Info.Properties |= (unsigned)SymbolProperty::Generic; Info.Lang = SymbolLanguage::CXX; break; case Decl::FunctionTemplate: Info.Kind = SymbolKind::Function; - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; + Info.Properties |= (unsigned)SymbolProperty::Generic; Info.Lang = SymbolLanguage::CXX; if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>( cast<FunctionTemplateDecl>(D)->getTemplatedDecl())) { @@ -214,7 +247,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { case Decl::TypeAliasTemplate: Info.Kind = SymbolKind::TypeAlias; Info.Lang = SymbolLanguage::CXX; - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; + Info.Properties |= (unsigned)SymbolProperty::Generic; break; case Decl::TypeAlias: Info.Kind = SymbolKind::TypeAlias; @@ -231,12 +264,12 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization) { - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; - Info.SubKinds |= (unsigned)SymbolSubKind::TemplateSpecialization; + Info.Properties |= (unsigned)SymbolProperty::Generic; + Info.Properties |= (unsigned)SymbolProperty::TemplateSpecialization; } } - if (Info.SubKinds & (unsigned)SymbolSubKind::Generic) + if (Info.Properties & (unsigned)SymbolProperty::Generic) Info.Lang = SymbolLanguage::CXX; return Info; @@ -262,6 +295,10 @@ void index::applyForEachSymbolRole(SymbolRoleSet Roles, APPLY_FOR_ROLE(RelationOverrideOf); APPLY_FOR_ROLE(RelationReceivedBy); APPLY_FOR_ROLE(RelationCalledBy); + APPLY_FOR_ROLE(RelationExtendedBy); + APPLY_FOR_ROLE(RelationAccessorOf); + APPLY_FOR_ROLE(RelationContainedBy); + APPLY_FOR_ROLE(RelationIBTypeOf); #undef APPLY_FOR_ROLE } @@ -288,6 +325,10 @@ void index::printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS) { case SymbolRole::RelationOverrideOf: OS << "RelOver"; break; case SymbolRole::RelationReceivedBy: OS << "RelRec"; break; case SymbolRole::RelationCalledBy: OS << "RelCall"; break; + case SymbolRole::RelationExtendedBy: OS << "RelExt"; break; + case SymbolRole::RelationAccessorOf: OS << "RelAcc"; break; + case SymbolRole::RelationContainedBy: OS << "RelCont"; break; + case SymbolRole::RelationIBTypeOf: OS << "RelIBType"; break; } }); } @@ -341,6 +382,17 @@ StringRef index::getSymbolKindString(SymbolKind K) { llvm_unreachable("invalid symbol kind"); } +StringRef index::getSymbolSubKindString(SymbolSubKind K) { + switch (K) { + case SymbolSubKind::None: return "<none>"; + case SymbolSubKind::CXXCopyConstructor: return "cxx-copy-ctor"; + case SymbolSubKind::CXXMoveConstructor: return "cxx-move-ctor"; + case SymbolSubKind::AccessorGetter: return "acc-get"; + case SymbolSubKind::AccessorSetter: return "acc-set"; + } + llvm_unreachable("invalid symbol subkind"); +} + StringRef index::getSymbolLanguageString(SymbolLanguage K) { switch (K) { case SymbolLanguage::C: return "C"; @@ -350,36 +402,38 @@ StringRef index::getSymbolLanguageString(SymbolLanguage K) { llvm_unreachable("invalid symbol language kind"); } -void index::applyForEachSymbolSubKind(SymbolSubKindSet SubKinds, - llvm::function_ref<void(SymbolSubKind)> Fn) { -#define APPLY_FOR_SUBKIND(K) \ - if (SubKinds & (unsigned)SymbolSubKind::K) \ - Fn(SymbolSubKind::K) +void index::applyForEachSymbolProperty(SymbolPropertySet Props, + llvm::function_ref<void(SymbolProperty)> Fn) { +#define APPLY_FOR_PROPERTY(K) \ + if (Props & (unsigned)SymbolProperty::K) \ + Fn(SymbolProperty::K) - APPLY_FOR_SUBKIND(Generic); - APPLY_FOR_SUBKIND(TemplatePartialSpecialization); - APPLY_FOR_SUBKIND(TemplateSpecialization); - APPLY_FOR_SUBKIND(UnitTest); - APPLY_FOR_SUBKIND(IBAnnotated); - APPLY_FOR_SUBKIND(IBOutletCollection); + APPLY_FOR_PROPERTY(Generic); + APPLY_FOR_PROPERTY(TemplatePartialSpecialization); + APPLY_FOR_PROPERTY(TemplateSpecialization); + APPLY_FOR_PROPERTY(UnitTest); + APPLY_FOR_PROPERTY(IBAnnotated); + APPLY_FOR_PROPERTY(IBOutletCollection); + APPLY_FOR_PROPERTY(GKInspectable); -#undef APPLY_FOR_SUBKIND +#undef APPLY_FOR_PROPERTY } -void index::printSymbolSubKinds(SymbolSubKindSet SubKinds, raw_ostream &OS) { +void index::printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS) { bool VisitedOnce = false; - applyForEachSymbolSubKind(SubKinds, [&](SymbolSubKind SubKind) { + applyForEachSymbolProperty(Props, [&](SymbolProperty Prop) { if (VisitedOnce) OS << ','; else VisitedOnce = true; - switch (SubKind) { - case SymbolSubKind::Generic: OS << "Gen"; break; - case SymbolSubKind::TemplatePartialSpecialization: OS << "TPS"; break; - case SymbolSubKind::TemplateSpecialization: OS << "TS"; break; - case SymbolSubKind::UnitTest: OS << "test"; break; - case SymbolSubKind::IBAnnotated: OS << "IB"; break; - case SymbolSubKind::IBOutletCollection: OS << "IBColl"; break; + switch (Prop) { + case SymbolProperty::Generic: OS << "Gen"; break; + case SymbolProperty::TemplatePartialSpecialization: OS << "TPS"; break; + case SymbolProperty::TemplateSpecialization: OS << "TS"; break; + case SymbolProperty::UnitTest: OS << "test"; break; + case SymbolProperty::IBAnnotated: OS << "IB"; break; + case SymbolProperty::IBOutletCollection: OS << "IBColl"; break; + case SymbolProperty::GKInspectable: OS << "GKI"; break; } }); } diff --git a/contrib/llvm/tools/clang/lib/Index/IndexTypeSourceInfo.cpp b/contrib/llvm/tools/clang/lib/Index/IndexTypeSourceInfo.cpp index 619a9a4..38bbb30 100644 --- a/contrib/llvm/tools/clang/lib/Index/IndexTypeSourceInfo.cpp +++ b/contrib/llvm/tools/clang/lib/Index/IndexTypeSourceInfo.cpp @@ -26,12 +26,16 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> { public: TypeIndexer(IndexingContext &indexCtx, const NamedDecl *parent, - const DeclContext *DC, bool isBase) + const DeclContext *DC, bool isBase, bool isIBType) : IndexCtx(indexCtx), Parent(parent), ParentDC(DC), IsBase(isBase) { if (IsBase) { assert(Parent); Relations.emplace_back((unsigned)SymbolRole::RelationBaseOf, Parent); } + if (isIBType) { + assert(Parent); + Relations.emplace_back((unsigned)SymbolRole::RelationIBTypeOf, Parent); + } } bool shouldWalkTypesOfTypeLocs() const { return false; } @@ -93,13 +97,13 @@ public: bool VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { return IndexCtx.handleReference(TL.getIFaceDecl(), TL.getNameLoc(), - Parent, ParentDC, SymbolRoleSet()); + Parent, ParentDC, SymbolRoleSet(), Relations); } bool VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) { IndexCtx.handleReference(TL.getProtocol(i), TL.getProtocolLoc(i), - Parent, ParentDC, SymbolRoleSet()); + Parent, ParentDC, SymbolRoleSet(), Relations); } return true; } @@ -130,23 +134,25 @@ public: void IndexingContext::indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC, - bool isBase) { + bool isBase, + bool isIBType) { if (!TInfo || TInfo->getTypeLoc().isNull()) return; - indexTypeLoc(TInfo->getTypeLoc(), Parent, DC, isBase); + indexTypeLoc(TInfo->getTypeLoc(), Parent, DC, isBase, isIBType); } void IndexingContext::indexTypeLoc(TypeLoc TL, const NamedDecl *Parent, const DeclContext *DC, - bool isBase) { + bool isBase, + bool isIBType) { if (TL.isNull()) return; if (!DC) DC = Parent->getLexicalDeclContext(); - TypeIndexer(*this, Parent, DC, isBase).TraverseTypeLoc(TL); + TypeIndexer(*this, Parent, DC, isBase, isIBType).TraverseTypeLoc(TL); } void IndexingContext::indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, diff --git a/contrib/llvm/tools/clang/lib/Index/IndexingContext.cpp b/contrib/llvm/tools/clang/lib/Index/IndexingContext.cpp index bcc367c..6dd6c0c 100644 --- a/contrib/llvm/tools/clang/lib/Index/IndexingContext.cpp +++ b/contrib/llvm/tools/clang/lib/Index/IndexingContext.cpp @@ -130,9 +130,10 @@ bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) { if (const ClassTemplateSpecializationDecl * SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) { TKind = SD->getSpecializationKind(); - } - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { TKind = FD->getTemplateSpecializationKind(); + } else if (auto *VD = dyn_cast<VarDecl>(D)) { + TKind = VD->getTemplateSpecializationKind(); } switch (TKind) { case TSK_Undeclared: @@ -164,9 +165,10 @@ static const Decl *adjustTemplateImplicitInstantiation(const Decl *D) { if (const ClassTemplateSpecializationDecl * SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) { return SD->getTemplateInstantiationPattern(); - } - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { return FD->getTemplateInstantiationPattern(); + } else if (auto *VD = dyn_cast<VarDecl>(D)) { + return VD->getTemplateInstantiationPattern(); } return nullptr; } @@ -290,19 +292,9 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc, Roles |= (unsigned)SymbolRole::Declaration; D = getCanonicalDecl(D); - if (D->isImplicit() && !isa<ObjCMethodDecl>(D) && - !(isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->getBuiltinID())) { - // operator new declarations will link to the implicit one as canonical. - return true; - } Parent = adjustParent(Parent); if (Parent) Parent = getCanonicalDecl(Parent); - assert((!Parent || !Parent->isImplicit() || - (isa<FunctionDecl>(Parent) && - cast<FunctionDecl>(Parent)->getBuiltinID()) || - isa<ObjCInterfaceDecl>(Parent) || isa<ObjCMethodDecl>(Parent)) && - "unexpected implicit parent!"); SmallVector<SymbolRelation, 6> FinalRelations; FinalRelations.reserve(Relations.size()+1); @@ -320,9 +312,20 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc, Roles |= Rel.Roles; }; - if (!IsRef && Parent && !cast<DeclContext>(Parent)->isFunctionOrMethod()) { - addRelation(SymbolRelation{(unsigned)SymbolRole::RelationChildOf, Parent}); + if (Parent) { + if (IsRef) { + addRelation(SymbolRelation{ + (unsigned)SymbolRole::RelationContainedBy, + Parent + }); + } else if (!cast<DeclContext>(Parent)->isFunctionOrMethod()) { + addRelation(SymbolRelation{ + (unsigned)SymbolRole::RelationChildOf, + Parent + }); + } } + for (auto &Rel : Relations) { addRelation(SymbolRelation(Rel.Roles, Rel.RelatedSymbol->getCanonicalDecl())); diff --git a/contrib/llvm/tools/clang/lib/Index/IndexingContext.h b/contrib/llvm/tools/clang/lib/Index/IndexingContext.h index 600fc43..dd1dd32 100644 --- a/contrib/llvm/tools/clang/lib/Index/IndexingContext.h +++ b/contrib/llvm/tools/clang/lib/Index/IndexingContext.h @@ -85,11 +85,13 @@ public: void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC = nullptr, - bool isBase = false); + bool isBase = false, + bool isIBType = false); void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent, const DeclContext *DC = nullptr, - bool isBase = false); + bool isBase = false, + bool isIBType = false); void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, diff --git a/contrib/llvm/tools/clang/lib/Index/USRGeneration.cpp b/contrib/llvm/tools/clang/lib/Index/USRGeneration.cpp index 30f1add..58f61c3 100644 --- a/contrib/llvm/tools/clang/lib/Index/USRGeneration.cpp +++ b/contrib/llvm/tools/clang/lib/Index/USRGeneration.cpp @@ -12,7 +12,6 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclVisitor.h" #include "clang/Lex/PreprocessingRecord.h" -#include "llvm/ADT/SmallString.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" @@ -174,8 +173,11 @@ bool USRGenerator::ShouldGenerateLocation(const NamedDecl *D) { return false; if (D->getParentFunctionOrMethod()) return true; + SourceLocation Loc = D->getLocation(); + if (Loc.isInvalid()) + return false; const SourceManager &SM = Context->getSourceManager(); - return !SM.isInSystemHeader(D->getLocation()); + return !SM.isInSystemHeader(Loc); } void USRGenerator::VisitDeclContext(const DeclContext *DC) { @@ -284,6 +286,15 @@ void USRGenerator::VisitVarDecl(const VarDecl *D) { VisitDeclContext(D->getDeclContext()); + if (VarTemplateDecl *VarTmpl = D->getDescribedVarTemplate()) { + Out << "@VT"; + VisitTemplateParameterList(VarTmpl->getTemplateParameters()); + } else if (const VarTemplatePartialSpecializationDecl *PartialSpec + = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { + Out << "@VP"; + VisitTemplateParameterList(PartialSpec->getTemplateParameters()); + } + // Variables always have simple names. StringRef s = D->getName(); @@ -295,6 +306,17 @@ void USRGenerator::VisitVarDecl(const VarDecl *D) { IgnoreResults = true; else Out << '@' << s; + + // For a template specialization, mangle the template arguments. + if (const VarTemplateSpecializationDecl *Spec + = dyn_cast<VarTemplateSpecializationDecl>(D)) { + const TemplateArgumentList &Args = Spec->getTemplateInstantiationArgs(); + Out << '>'; + for (unsigned I = 0, N = Args.size(); I != N; ++I) { + Out << '#'; + VisitTemplateArgument(Args.get(I)); + } + } } void USRGenerator::VisitNonTypeTemplateParmDecl( @@ -875,9 +897,11 @@ void clang::index::generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS) { bool clang::index::generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf) { - // Don't generate USRs for things with invalid locations. - if (!D || D->getLocStart().isInvalid()) + if (!D) return true; + // We don't ignore decls with invalid source locations. Implicit decls, like + // C++'s operator new function, can have invalid locations but it is fine to + // create USRs that can identify them. USRGenerator UG(&D->getASTContext(), Buf); UG.Visit(D); |