diff options
Diffstat (limited to 'lib/Index/IndexDecl.cpp')
| -rw-r--r-- | lib/Index/IndexDecl.cpp | 35 | 
1 files changed, 20 insertions, 15 deletions
diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index a7725f9dd97fc..5bbbb0d32bf45 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);  | 
