2016-02-13 07:10:59 +08:00
|
|
|
//===- IndexDecl.cpp - Indexing declarations ------------------------------===//
|
2011-10-18 03:48:19 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "IndexingContext.h"
|
2016-02-13 07:10:59 +08:00
|
|
|
#include "clang/Index/IndexDataConsumer.h"
|
2011-10-18 03:48:19 +08:00
|
|
|
#include "clang/AST/DeclVisitor.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
2016-02-13 07:10:59 +08:00
|
|
|
using namespace index;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2017-04-21 13:42:46 +08:00
|
|
|
#define TRY_DECL(D,CALL_EXPR) \
|
|
|
|
do { \
|
|
|
|
if (!IndexCtx.shouldIndex(D)) return true; \
|
|
|
|
if (!CALL_EXPR) \
|
|
|
|
return false; \
|
|
|
|
} while (0)
|
|
|
|
|
2016-03-03 13:33:54 +08:00
|
|
|
#define TRY_TO(CALL_EXPR) \
|
|
|
|
do { \
|
|
|
|
if (!CALL_EXPR) \
|
|
|
|
return false; \
|
|
|
|
} while (0)
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
namespace {
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
|
2011-10-18 03:48:19 +08:00
|
|
|
IndexingContext &IndexCtx;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit IndexingDeclVisitor(IndexingContext &indexCtx)
|
|
|
|
: IndexCtx(indexCtx) { }
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool Handled = true;
|
|
|
|
|
|
|
|
bool VisitDecl(const Decl *D) {
|
|
|
|
Handled = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-30 07:58:31 +08:00
|
|
|
/// \brief Returns true if the given method has been defined explicitly by the
|
|
|
|
/// user.
|
|
|
|
static bool hasUserDefined(const ObjCMethodDecl *D,
|
|
|
|
const ObjCImplDecl *Container) {
|
|
|
|
const ObjCMethodDecl *MD = Container->getMethod(D->getSelector(),
|
|
|
|
D->isInstanceMethod());
|
|
|
|
return MD && !MD->isImplicit() && MD->isThisDeclarationADefinition();
|
|
|
|
}
|
|
|
|
|
2017-05-13 00:32:26 +08:00
|
|
|
void handleTemplateArgumentLoc(const TemplateArgumentLoc &TALoc,
|
|
|
|
const NamedDecl *Parent,
|
|
|
|
const DeclContext *DC) {
|
|
|
|
const TemplateArgumentLocInfo &LocInfo = TALoc.getLocInfo();
|
|
|
|
switch (TALoc.getArgument().getKind()) {
|
|
|
|
case TemplateArgument::Expression:
|
|
|
|
IndexCtx.indexBody(LocInfo.getAsExpr(), Parent, DC);
|
|
|
|
break;
|
|
|
|
case TemplateArgument::Type:
|
|
|
|
IndexCtx.indexTypeSourceInfo(LocInfo.getAsTypeSourceInfo(), Parent, DC);
|
|
|
|
break;
|
2017-05-23 00:50:54 +08:00
|
|
|
case TemplateArgument::Template:
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
IndexCtx.indexNestedNameSpecifierLoc(TALoc.getTemplateQualifierLoc(),
|
|
|
|
Parent, DC);
|
|
|
|
if (const TemplateDecl *TD = TALoc.getArgument()
|
|
|
|
.getAsTemplateOrTemplatePattern()
|
|
|
|
.getAsTemplateDecl()) {
|
|
|
|
if (const NamedDecl *TTD = TD->getTemplatedDecl())
|
|
|
|
IndexCtx.handleReference(TTD, TALoc.getTemplateNameLoc(), Parent, DC);
|
|
|
|
}
|
|
|
|
break;
|
2017-05-13 00:32:26 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-08 16:38:04 +08:00
|
|
|
void handleDeclarator(const DeclaratorDecl *D,
|
2017-01-12 05:01:07 +08:00
|
|
|
const NamedDecl *Parent = nullptr,
|
|
|
|
bool isIBType = false) {
|
2011-12-14 02:47:41 +08:00
|
|
|
if (!Parent) Parent = D;
|
2012-01-14 10:05:51 +08:00
|
|
|
|
2017-01-12 05:01:07 +08:00
|
|
|
IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), Parent,
|
|
|
|
Parent->getLexicalDeclContext(),
|
|
|
|
/*isBase=*/false, isIBType);
|
2016-02-13 07:10:59 +08:00
|
|
|
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent);
|
|
|
|
if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
|
|
|
|
// Only index parameters in definitions, parameters in declarations are
|
|
|
|
// not useful.
|
2013-02-03 21:42:20 +08:00
|
|
|
if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
|
2016-02-13 07:10:59 +08:00
|
|
|
auto *DC = Parm->getDeclContext();
|
|
|
|
if (auto *FD = dyn_cast<FunctionDecl>(DC)) {
|
|
|
|
if (FD->isThisDeclarationADefinition())
|
|
|
|
IndexCtx.handleDecl(Parm);
|
|
|
|
} else if (auto *MD = dyn_cast<ObjCMethodDecl>(DC)) {
|
|
|
|
if (MD->isThisDeclarationADefinition())
|
|
|
|
IndexCtx.handleDecl(Parm);
|
|
|
|
} else {
|
|
|
|
IndexCtx.handleDecl(Parm);
|
|
|
|
}
|
2013-02-03 21:42:20 +08:00
|
|
|
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
2016-02-13 07:10:59 +08:00
|
|
|
if (FD->isThisDeclarationADefinition()) {
|
2016-06-24 12:05:48 +08:00
|
|
|
for (auto PI : FD->parameters()) {
|
2016-02-13 07:10:59 +08:00
|
|
|
IndexCtx.handleDecl(PI);
|
|
|
|
}
|
2012-01-14 10:05:51 +08:00
|
|
|
}
|
|
|
|
}
|
2017-05-22 23:17:44 +08:00
|
|
|
} else {
|
|
|
|
// Index the default parameter value for function definitions.
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-14 10:05:51 +08:00
|
|
|
}
|
2011-12-14 02:47:41 +08:00
|
|
|
}
|
|
|
|
|
2016-10-26 05:11:22 +08:00
|
|
|
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);
|
|
|
|
|
2017-01-26 10:11:50 +08:00
|
|
|
// 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();
|
|
|
|
|
2017-03-17 02:25:40 +08:00
|
|
|
SourceLocation AttrLoc;
|
|
|
|
|
|
|
|
// check for (getter=/setter=)
|
|
|
|
if (AssociatedProp) {
|
|
|
|
bool isGetter = !D->param_size();
|
|
|
|
AttrLoc = isGetter ?
|
|
|
|
AssociatedProp->getGetterNameLoc():
|
|
|
|
AssociatedProp->getSetterNameLoc();
|
|
|
|
}
|
|
|
|
|
2017-02-17 12:49:41 +08:00
|
|
|
SymbolRoleSet Roles = (SymbolRoleSet)SymbolRole::Dynamic;
|
2017-03-17 02:25:40 +08:00
|
|
|
if (D->isImplicit()) {
|
|
|
|
if (AttrLoc.isValid()) {
|
|
|
|
MethodLoc = AttrLoc;
|
|
|
|
} else {
|
|
|
|
Roles |= (SymbolRoleSet)SymbolRole::Implicit;
|
|
|
|
}
|
|
|
|
} else if (AttrLoc.isValid()) {
|
|
|
|
IndexCtx.handleReference(D, AttrLoc, cast<NamedDecl>(D->getDeclContext()),
|
|
|
|
D->getDeclContext(), 0);
|
|
|
|
}
|
|
|
|
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D, MethodLoc, Roles, Relations));
|
2014-01-26 00:55:45 +08:00
|
|
|
IndexCtx.indexTypeSourceInfo(D->getReturnTypeSourceInfo(), D);
|
2017-01-12 05:01:07 +08:00
|
|
|
bool hasIBActionAndFirst = D->hasAttr<IBActionAttr>();
|
|
|
|
for (const auto *I : D->parameters()) {
|
|
|
|
handleDeclarator(I, D, /*isIBType=*/hasIBActionAndFirst);
|
|
|
|
hasIBActionAndFirst = false;
|
|
|
|
}
|
2012-02-29 01:50:28 +08:00
|
|
|
|
|
|
|
if (D->isThisDeclarationADefinition()) {
|
|
|
|
const Stmt *Body = D->getBody();
|
|
|
|
if (Body) {
|
|
|
|
IndexCtx.indexBody(Body, D, D);
|
|
|
|
}
|
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
return true;
|
2012-02-29 01:50:28 +08:00
|
|
|
}
|
|
|
|
|
2017-04-24 22:04:58 +08:00
|
|
|
/// Gather the declarations which the given declaration \D overrides in a
|
|
|
|
/// pseudo-override manner.
|
|
|
|
///
|
|
|
|
/// Pseudo-overrides occur when a class template specialization declares
|
|
|
|
/// a declaration that has the same name as a similar declaration in the
|
|
|
|
/// non-specialized template.
|
|
|
|
void
|
|
|
|
gatherTemplatePseudoOverrides(const NamedDecl *D,
|
|
|
|
SmallVectorImpl<SymbolRelation> &Relations) {
|
|
|
|
if (!IndexCtx.getLangOpts().CPlusPlus)
|
|
|
|
return;
|
|
|
|
const auto *CTSD =
|
|
|
|
dyn_cast<ClassTemplateSpecializationDecl>(D->getLexicalDeclContext());
|
|
|
|
if (!CTSD)
|
|
|
|
return;
|
|
|
|
llvm::PointerUnion<ClassTemplateDecl *,
|
|
|
|
ClassTemplatePartialSpecializationDecl *>
|
|
|
|
Template = CTSD->getSpecializedTemplateOrPartial();
|
|
|
|
if (const auto *CTD = Template.dyn_cast<ClassTemplateDecl *>()) {
|
|
|
|
const CXXRecordDecl *Pattern = CTD->getTemplatedDecl();
|
|
|
|
bool TypeOverride = isa<TypeDecl>(D);
|
|
|
|
for (const NamedDecl *ND : Pattern->lookup(D->getDeclName())) {
|
|
|
|
if (const auto *CTD = dyn_cast<ClassTemplateDecl>(ND))
|
|
|
|
ND = CTD->getTemplatedDecl();
|
|
|
|
if (ND->isImplicit())
|
|
|
|
continue;
|
|
|
|
// Types can override other types.
|
|
|
|
if (!TypeOverride) {
|
|
|
|
if (ND->getKind() != D->getKind())
|
|
|
|
continue;
|
|
|
|
} else if (!isa<TypeDecl>(ND))
|
|
|
|
continue;
|
|
|
|
if (const auto *FD = dyn_cast<FunctionDecl>(ND)) {
|
|
|
|
const auto *DFD = cast<FunctionDecl>(D);
|
|
|
|
// Function overrides are approximated using the number of parameters.
|
|
|
|
if (FD->getStorageClass() != DFD->getStorageClass() ||
|
|
|
|
FD->getNumParams() != DFD->getNumParams())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Relations.emplace_back(
|
2017-05-04 18:42:06 +08:00
|
|
|
SymbolRoleSet(SymbolRole::RelationSpecializationOf), ND);
|
2017-04-24 22:04:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitFunctionDecl(const FunctionDecl *D) {
|
2016-02-13 07:10:59 +08:00
|
|
|
SymbolRoleSet Roles{};
|
|
|
|
SmallVector<SymbolRelation, 4> Relations;
|
|
|
|
if (auto *CXXMD = dyn_cast<CXXMethodDecl>(D)) {
|
|
|
|
if (CXXMD->isVirtual())
|
|
|
|
Roles |= (unsigned)SymbolRole::Dynamic;
|
|
|
|
for (auto I = CXXMD->begin_overridden_methods(),
|
|
|
|
E = CXXMD->end_overridden_methods(); I != E; ++I) {
|
|
|
|
Relations.emplace_back((unsigned)SymbolRole::RelationOverrideOf, *I);
|
|
|
|
}
|
|
|
|
}
|
2017-04-24 22:04:58 +08:00
|
|
|
gatherTemplatePseudoOverrides(D, Relations);
|
2017-04-25 22:22:29 +08:00
|
|
|
if (const auto *Base = D->getPrimaryTemplate())
|
|
|
|
Relations.push_back(
|
|
|
|
SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf),
|
|
|
|
Base->getTemplatedDecl()));
|
2016-02-13 07:10:59 +08:00
|
|
|
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D, Roles, Relations));
|
2011-12-14 02:47:41 +08:00
|
|
|
handleDeclarator(D);
|
2012-01-24 00:58:36 +08:00
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
|
2017-03-18 07:41:59 +08:00
|
|
|
IndexCtx.handleReference(Ctor->getParent(), Ctor->getLocation(),
|
|
|
|
Ctor->getParent(), Ctor->getDeclContext());
|
|
|
|
|
2012-01-24 00:58:36 +08:00
|
|
|
// Constructor initializers.
|
2014-03-14 01:34:31 +08:00
|
|
|
for (const auto *Init : Ctor->inits()) {
|
2012-01-24 00:58:36 +08:00
|
|
|
if (Init->isWritten()) {
|
|
|
|
IndexCtx.indexTypeSourceInfo(Init->getTypeSourceInfo(), D);
|
|
|
|
if (const FieldDecl *Member = Init->getAnyMember())
|
2016-02-13 07:10:59 +08:00
|
|
|
IndexCtx.handleReference(Member, Init->getMemberLocation(), D, D,
|
|
|
|
(unsigned)SymbolRole::Write);
|
2012-01-24 00:58:36 +08:00
|
|
|
IndexCtx.indexBody(Init->getInit(), D, D);
|
|
|
|
}
|
|
|
|
}
|
2017-03-18 07:41:59 +08:00
|
|
|
} else if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(D)) {
|
|
|
|
if (auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) {
|
|
|
|
IndexCtx.handleReference(Dtor->getParent(),
|
|
|
|
TypeNameInfo->getTypeLoc().getLocStart(),
|
|
|
|
Dtor->getParent(), Dtor->getDeclContext());
|
|
|
|
}
|
2012-01-24 00:58:36 +08:00
|
|
|
}
|
2017-05-13 00:32:26 +08:00
|
|
|
// Template specialization arguments.
|
|
|
|
if (const ASTTemplateArgumentListInfo *TemplateArgInfo =
|
|
|
|
D->getTemplateSpecializationArgsAsWritten()) {
|
|
|
|
for (const auto &Arg : TemplateArgInfo->arguments())
|
|
|
|
handleTemplateArgumentLoc(Arg, D, D->getLexicalDeclContext());
|
|
|
|
}
|
2012-01-24 00:58:36 +08:00
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
if (D->isThisDeclarationADefinition()) {
|
|
|
|
const Stmt *Body = D->getBody();
|
|
|
|
if (Body) {
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.indexBody(Body, D, D);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitVarDecl(const VarDecl *D) {
|
2017-04-24 22:04:58 +08:00
|
|
|
SmallVector<SymbolRelation, 4> Relations;
|
|
|
|
gatherTemplatePseudoOverrides(D, Relations);
|
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D, SymbolRoleSet(), Relations));
|
2011-12-14 02:47:41 +08:00
|
|
|
handleDeclarator(D);
|
|
|
|
IndexCtx.indexBody(D->getInit(), D);
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitFieldDecl(const FieldDecl *D) {
|
2017-04-24 22:04:58 +08:00
|
|
|
SmallVector<SymbolRelation, 4> Relations;
|
|
|
|
gatherTemplatePseudoOverrides(D, Relations);
|
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D, SymbolRoleSet(), Relations));
|
2011-12-14 02:47:41 +08:00
|
|
|
handleDeclarator(D);
|
|
|
|
if (D->isBitField())
|
|
|
|
IndexCtx.indexBody(D->getBitWidth(), D);
|
|
|
|
else if (D->hasInClassInitializer())
|
|
|
|
IndexCtx.indexBody(D->getInClassInitializer(), D);
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
2013-02-03 21:42:20 +08:00
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool VisitObjCIvarDecl(const ObjCIvarDecl *D) {
|
|
|
|
if (D->getSynthesize()) {
|
2017-02-17 12:49:41 +08:00
|
|
|
// handled in VisitObjCPropertyImplDecl
|
|
|
|
return true;
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D));
|
2016-02-13 07:10:59 +08:00
|
|
|
handleDeclarator(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-16 15:28:30 +08:00
|
|
|
bool VisitMSPropertyDecl(const MSPropertyDecl *D) {
|
|
|
|
handleDeclarator(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitEnumConstantDecl(const EnumConstantDecl *D) {
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D));
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.indexBody(D->getInitExpr(), D);
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitTypedefNameDecl(const TypedefNameDecl *D) {
|
2017-04-21 13:42:40 +08:00
|
|
|
if (!D->isTransparentTag()) {
|
2017-04-24 22:04:58 +08:00
|
|
|
SmallVector<SymbolRelation, 4> Relations;
|
|
|
|
gatherTemplatePseudoOverrides(D, Relations);
|
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D, SymbolRoleSet(), Relations));
|
2017-04-21 13:42:40 +08:00
|
|
|
IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D);
|
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitTagDecl(const TagDecl *D) {
|
2011-10-18 03:48:19 +08:00
|
|
|
// Non-free standing tags are handled in indexTypeSourceInfo.
|
2016-02-13 07:10:59 +08:00
|
|
|
if (D->isFreeStanding()) {
|
|
|
|
if (D->isThisDeclarationADefinition()) {
|
2017-04-24 22:04:58 +08:00
|
|
|
SmallVector<SymbolRelation, 4> Relations;
|
|
|
|
gatherTemplatePseudoOverrides(D, Relations);
|
|
|
|
IndexCtx.indexTagDecl(D, Relations);
|
2016-02-13 07:10:59 +08:00
|
|
|
} else {
|
|
|
|
auto *Parent = dyn_cast<NamedDecl>(D->getDeclContext());
|
|
|
|
return IndexCtx.handleReference(D, D->getLocation(), Parent,
|
|
|
|
D->getLexicalDeclContext(),
|
|
|
|
SymbolRoleSet());
|
|
|
|
}
|
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-03 13:33:54 +08:00
|
|
|
bool handleReferencedProtocols(const ObjCProtocolList &ProtList,
|
2017-03-05 01:54:53 +08:00
|
|
|
const ObjCContainerDecl *ContD,
|
|
|
|
SourceLocation SuperLoc) {
|
2016-03-03 13:33:54 +08:00
|
|
|
ObjCInterfaceDecl::protocol_loc_iterator LI = ProtList.loc_begin();
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator
|
|
|
|
I = ProtList.begin(), E = ProtList.end(); I != E; ++I, ++LI) {
|
|
|
|
SourceLocation Loc = *LI;
|
|
|
|
ObjCProtocolDecl *PD = *I;
|
2017-03-05 01:54:53 +08:00
|
|
|
SymbolRoleSet roles{};
|
|
|
|
if (Loc == SuperLoc)
|
|
|
|
roles |= (SymbolRoleSet)SymbolRole::Implicit;
|
|
|
|
TRY_TO(IndexCtx.handleReference(PD, Loc, ContD, ContD, roles,
|
2016-03-03 13:33:54 +08:00
|
|
|
SymbolRelation{(unsigned)SymbolRole::RelationBaseOf, ContD}));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
|
2011-12-28 06:43:10 +08:00
|
|
|
if (D->isThisDeclarationADefinition()) {
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D));
|
2017-03-05 01:54:53 +08:00
|
|
|
SourceLocation SuperLoc = D->getSuperClassLoc();
|
2016-03-03 13:33:54 +08:00
|
|
|
if (auto *SuperD = D->getSuperClass()) {
|
2017-03-05 01:54:53 +08:00
|
|
|
bool hasSuperTypedef = false;
|
|
|
|
if (auto *TInfo = D->getSuperClassTInfo()) {
|
|
|
|
if (auto *TT = TInfo->getType()->getAs<TypedefType>()) {
|
|
|
|
if (auto *TD = TT->getDecl()) {
|
|
|
|
hasSuperTypedef = true;
|
|
|
|
TRY_TO(IndexCtx.handleReference(TD, SuperLoc, D, D,
|
|
|
|
SymbolRoleSet()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SymbolRoleSet superRoles{};
|
|
|
|
if (hasSuperTypedef)
|
|
|
|
superRoles |= (SymbolRoleSet)SymbolRole::Implicit;
|
|
|
|
TRY_TO(IndexCtx.handleReference(SuperD, SuperLoc, D, D, superRoles,
|
2016-03-03 13:33:54 +08:00
|
|
|
SymbolRelation{(unsigned)SymbolRole::RelationBaseOf, D}));
|
|
|
|
}
|
2017-03-05 01:54:53 +08:00
|
|
|
TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D,
|
|
|
|
SuperLoc));
|
2016-03-03 13:33:54 +08:00
|
|
|
TRY_TO(IndexCtx.indexDeclContext(D));
|
2016-02-13 07:10:59 +08:00
|
|
|
} else {
|
2016-03-09 10:12:46 +08:00
|
|
|
return IndexCtx.handleReference(D, D->getLocation(), nullptr,
|
|
|
|
D->getDeclContext(), SymbolRoleSet());
|
2011-12-28 06:43:10 +08:00
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
|
2012-01-02 05:23:57 +08:00
|
|
|
if (D->isThisDeclarationADefinition()) {
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D));
|
2017-03-05 01:54:53 +08:00
|
|
|
TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D,
|
|
|
|
/*superLoc=*/SourceLocation()));
|
2016-03-03 13:33:54 +08:00
|
|
|
TRY_TO(IndexCtx.indexDeclContext(D));
|
2016-02-13 07:10:59 +08:00
|
|
|
} else {
|
2016-03-09 10:12:46 +08:00
|
|
|
return IndexCtx.handleReference(D, D->getLocation(), nullptr,
|
|
|
|
D->getDeclContext(), SymbolRoleSet());
|
2012-01-02 05:23:57 +08:00
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
|
2011-11-15 14:20:24 +08:00
|
|
|
const ObjCInterfaceDecl *Class = D->getClassInterface();
|
2011-11-24 04:27:26 +08:00
|
|
|
if (!Class)
|
|
|
|
return true;
|
|
|
|
|
2011-11-15 14:20:24 +08:00
|
|
|
if (Class->isImplicitInterfaceDecl())
|
2016-02-13 07:10:59 +08:00
|
|
|
IndexCtx.handleDecl(Class);
|
2011-11-15 14:20:24 +08:00
|
|
|
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D));
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2017-02-17 12:49:41 +08:00
|
|
|
// Visit implicit @synthesize property implementations first as their
|
|
|
|
// location is reported at the name of the @implementation block. This
|
|
|
|
// serves no purpose other than to simplify the FileCheck-based tests.
|
|
|
|
for (const auto *I : D->property_impls()) {
|
|
|
|
if (I->getLocation().isInvalid())
|
|
|
|
IndexCtx.indexDecl(I);
|
|
|
|
}
|
2014-03-08 03:56:05 +08:00
|
|
|
for (const auto *I : D->decls()) {
|
2017-02-17 12:49:41 +08:00
|
|
|
if (!isa<ObjCPropertyImplDecl>(I) ||
|
|
|
|
cast<ObjCPropertyImplDecl>(I)->getLocation().isValid())
|
2014-03-08 03:56:05 +08:00
|
|
|
IndexCtx.indexDecl(I);
|
2012-06-08 10:16:11 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
|
2017-04-21 13:42:46 +08:00
|
|
|
if (!IndexCtx.shouldIndex(D))
|
|
|
|
return true;
|
2016-10-26 05:11:22 +08:00
|
|
|
const ObjCInterfaceDecl *C = D->getClassInterface();
|
2017-01-12 05:08:31 +08:00
|
|
|
if (!C)
|
|
|
|
return true;
|
|
|
|
TRY_TO(IndexCtx.handleReference(C, D->getLocation(), D, D, SymbolRoleSet(),
|
|
|
|
SymbolRelation{
|
|
|
|
(unsigned)SymbolRole::RelationExtendedBy, D
|
|
|
|
}));
|
2016-10-26 05:11:22 +08:00
|
|
|
SourceLocation CategoryLoc = D->getCategoryNameLoc();
|
|
|
|
if (!CategoryLoc.isValid())
|
|
|
|
CategoryLoc = D->getLocation();
|
|
|
|
TRY_TO(IndexCtx.handleDecl(D, CategoryLoc));
|
2017-03-05 01:54:53 +08:00
|
|
|
TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D,
|
|
|
|
/*superLoc=*/SourceLocation()));
|
2016-10-26 05:11:22 +08:00
|
|
|
TRY_TO(IndexCtx.indexDeclContext(D));
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
|
2011-11-24 04:27:26 +08:00
|
|
|
const ObjCCategoryDecl *Cat = D->getCategoryDecl();
|
|
|
|
if (!Cat)
|
2011-11-11 08:23:36 +08:00
|
|
|
return true;
|
2016-10-26 05:11:22 +08:00
|
|
|
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();
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D, CategoryLoc));
|
2011-10-18 03:48:19 +08:00
|
|
|
IndexCtx.indexDeclContext(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitObjCMethodDecl(const ObjCMethodDecl *D) {
|
2012-02-29 01:50:28 +08:00
|
|
|
// Methods associated with a property, even user-declared ones, are
|
|
|
|
// handled when we handle the property.
|
2012-10-11 00:42:25 +08:00
|
|
|
if (D->isPropertyAccessor())
|
2012-02-29 01:50:28 +08:00
|
|
|
return true;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2012-02-29 01:50:28 +08:00
|
|
|
handleObjCMethod(D);
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
|
2012-02-29 01:50:28 +08:00
|
|
|
if (ObjCMethodDecl *MD = D->getGetterMethodDecl())
|
|
|
|
if (MD->getLexicalDeclContext() == D->getLexicalDeclContext())
|
2016-10-26 05:11:22 +08:00
|
|
|
handleObjCMethod(MD, D);
|
2012-02-29 01:50:28 +08:00
|
|
|
if (ObjCMethodDecl *MD = D->getSetterMethodDecl())
|
|
|
|
if (MD->getLexicalDeclContext() == D->getLexicalDeclContext())
|
2016-10-26 05:11:22 +08:00
|
|
|
handleObjCMethod(MD, D);
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D));
|
2017-01-12 05:01:07 +08:00
|
|
|
if (IBOutletCollectionAttr *attr = D->getAttr<IBOutletCollectionAttr>())
|
|
|
|
IndexCtx.indexTypeSourceInfo(attr->getInterfaceLoc(), D,
|
|
|
|
D->getLexicalDeclContext(), false, true);
|
2011-10-18 03:48:19 +08:00
|
|
|
IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D);
|
|
|
|
return true;
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
|
2011-11-18 08:26:51 +08:00
|
|
|
ObjCPropertyDecl *PD = D->getPropertyDecl();
|
2017-02-17 12:49:41 +08:00
|
|
|
auto *Container = cast<ObjCImplDecl>(D->getDeclContext());
|
|
|
|
SourceLocation Loc = D->getLocation();
|
|
|
|
SymbolRoleSet Roles = 0;
|
|
|
|
SmallVector<SymbolRelation, 1> Relations;
|
|
|
|
|
|
|
|
if (ObjCIvarDecl *ID = D->getPropertyIvarDecl())
|
|
|
|
Relations.push_back({(SymbolRoleSet)SymbolRole::RelationAccessorOf, ID});
|
|
|
|
if (Loc.isInvalid()) {
|
|
|
|
Loc = Container->getLocation();
|
|
|
|
Roles |= (SymbolRoleSet)SymbolRole::Implicit;
|
|
|
|
}
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D, Loc, Roles, Relations));
|
2011-11-18 08:26:51 +08:00
|
|
|
|
|
|
|
if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
|
|
|
|
return true;
|
|
|
|
|
2017-02-17 12:49:41 +08:00
|
|
|
assert(D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize);
|
2017-04-27 23:05:18 +08:00
|
|
|
SymbolRoleSet AccessorMethodRoles =
|
|
|
|
SymbolRoleSet(SymbolRole::Dynamic) | SymbolRoleSet(SymbolRole::Implicit);
|
2011-11-18 08:26:51 +08:00
|
|
|
if (ObjCMethodDecl *MD = PD->getGetterMethodDecl()) {
|
2013-05-30 07:58:31 +08:00
|
|
|
if (MD->isPropertyAccessor() &&
|
2017-02-17 12:49:41 +08:00
|
|
|
!hasUserDefined(MD, Container))
|
2017-04-27 23:05:18 +08:00
|
|
|
IndexCtx.handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
|
|
|
if (ObjCMethodDecl *MD = PD->getSetterMethodDecl()) {
|
2013-05-30 07:58:31 +08:00
|
|
|
if (MD->isPropertyAccessor() &&
|
2017-02-17 12:49:41 +08:00
|
|
|
!hasUserDefined(MD, Container))
|
2017-04-27 23:05:18 +08:00
|
|
|
IndexCtx.handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
|
2017-02-17 12:49:41 +08:00
|
|
|
}
|
|
|
|
if (ObjCIvarDecl *IvarD = D->getPropertyIvarDecl()) {
|
|
|
|
if (IvarD->getSynthesize()) {
|
|
|
|
// For synthesized ivars, use the location of its name in the
|
|
|
|
// corresponding @synthesize. If there isn't one, use the containing
|
|
|
|
// @implementation's location, rather than the property's location,
|
|
|
|
// otherwise the header file containing the @interface will have different
|
|
|
|
// indexing contents based on whether the @implementation was present or
|
|
|
|
// not in the translation unit.
|
|
|
|
SymbolRoleSet IvarRoles = 0;
|
|
|
|
SourceLocation IvarLoc = D->getPropertyIvarDeclLoc();
|
|
|
|
if (D->getLocation().isInvalid()) {
|
|
|
|
IvarLoc = Container->getLocation();
|
|
|
|
IvarRoles = (SymbolRoleSet)SymbolRole::Implicit;
|
|
|
|
} else if (D->getLocation() == IvarLoc) {
|
|
|
|
IvarRoles = (SymbolRoleSet)SymbolRole::Implicit;
|
|
|
|
}
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(IvarD, IndexCtx.handleDecl(IvarD, IvarLoc, IvarRoles));
|
2017-02-17 12:49:41 +08:00
|
|
|
} else {
|
|
|
|
IndexCtx.handleReference(IvarD, D->getPropertyIvarDeclLoc(), nullptr,
|
|
|
|
D->getDeclContext(), SymbolRoleSet());
|
|
|
|
}
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
2011-11-22 15:24:51 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitNamespaceDecl(const NamespaceDecl *D) {
|
2017-04-21 13:42:46 +08:00
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D));
|
2011-12-07 13:52:06 +08:00
|
|
|
IndexCtx.indexDeclContext(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-15 18:56:31 +08:00
|
|
|
bool VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
|
|
|
|
TRY_DECL(D, IndexCtx.handleDecl(D));
|
|
|
|
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
|
|
|
|
IndexCtx.handleReference(D->getAliasedNamespace(), D->getTargetNameLoc(), D,
|
|
|
|
D->getLexicalDeclContext());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitUsingDecl(const UsingDecl *D) {
|
2016-02-13 07:10:59 +08:00
|
|
|
const DeclContext *DC = D->getDeclContext()->getRedeclContext();
|
|
|
|
const NamedDecl *Parent = dyn_cast<NamedDecl>(DC);
|
2012-02-11 04:10:48 +08:00
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
|
|
|
|
D->getLexicalDeclContext());
|
2014-03-14 02:07:29 +08:00
|
|
|
for (const auto *I : D->shadows())
|
2016-02-13 07:10:59 +08:00
|
|
|
IndexCtx.handleReference(I->getUnderlyingDecl(), D->getLocation(), Parent,
|
|
|
|
D->getLexicalDeclContext(), SymbolRoleSet());
|
2012-02-11 04:10:48 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
|
2016-02-13 07:10:59 +08:00
|
|
|
const DeclContext *DC = D->getDeclContext()->getRedeclContext();
|
|
|
|
const NamedDecl *Parent = dyn_cast<NamedDecl>(DC);
|
|
|
|
|
2017-05-22 22:39:39 +08:00
|
|
|
// NNS for the local 'using namespace' directives is visited by the body
|
|
|
|
// visitor.
|
|
|
|
if (!D->getParentFunctionOrMethod())
|
|
|
|
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
|
|
|
|
D->getLexicalDeclContext());
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
return IndexCtx.handleReference(D->getNominatedNamespaceAsWritten(),
|
|
|
|
D->getLocation(), Parent,
|
|
|
|
D->getLexicalDeclContext(),
|
|
|
|
SymbolRoleSet());
|
2011-11-22 15:24:51 +08:00
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitClassTemplateSpecializationDecl(const
|
2012-02-11 04:10:44 +08:00
|
|
|
ClassTemplateSpecializationDecl *D) {
|
2012-02-15 06:23:11 +08:00
|
|
|
// FIXME: Notify subsequent callbacks if info comes from implicit
|
2012-02-11 04:10:44 +08:00
|
|
|
// instantiation.
|
2017-04-20 18:43:22 +08:00
|
|
|
if (D->isThisDeclarationADefinition()) {
|
|
|
|
llvm::PointerUnion<ClassTemplateDecl *,
|
|
|
|
ClassTemplatePartialSpecializationDecl *>
|
|
|
|
Template = D->getSpecializedTemplateOrPartial();
|
|
|
|
const Decl *SpecializationOf =
|
|
|
|
Template.is<ClassTemplateDecl *>()
|
|
|
|
? (Decl *)Template.get<ClassTemplateDecl *>()
|
|
|
|
: Template.get<ClassTemplatePartialSpecializationDecl *>();
|
|
|
|
IndexCtx.indexTagDecl(
|
|
|
|
D, SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf),
|
|
|
|
SpecializationOf));
|
|
|
|
}
|
2017-04-25 23:13:42 +08:00
|
|
|
if (TypeSourceInfo *TSI = D->getTypeAsWritten())
|
|
|
|
IndexCtx.indexTypeSourceInfo(TSI, /*Parent=*/nullptr,
|
|
|
|
D->getLexicalDeclContext());
|
2012-02-11 04:10:44 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-23 00:50:54 +08:00
|
|
|
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 (const auto *FD = dyn_cast<FunctionDecl>(D))
|
|
|
|
return FD->getCanonicalDecl() == FD;
|
|
|
|
else if (const auto *TD = dyn_cast<TagDecl>(D))
|
|
|
|
return TD->getCanonicalDecl() == TD;
|
|
|
|
else if (const auto *VD = dyn_cast<VarDecl>(D))
|
|
|
|
return VD->getCanonicalDecl() == VD;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool VisitTemplateDecl(const TemplateDecl *D) {
|
|
|
|
// FIXME: Template parameters.
|
2017-05-23 00:50:54 +08:00
|
|
|
|
|
|
|
// Index the default values for the template parameters.
|
|
|
|
const NamedDecl *Parent = D->getTemplatedDecl();
|
|
|
|
if (D->getTemplateParameters() &&
|
|
|
|
shouldIndexTemplateParameterDefaultValue(Parent)) {
|
|
|
|
const TemplateParameterList *Params = D->getTemplateParameters();
|
|
|
|
for (const NamedDecl *TP : *Params) {
|
|
|
|
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(TP)) {
|
|
|
|
if (TTP->hasDefaultArgument())
|
|
|
|
IndexCtx.indexTypeSourceInfo(TTP->getDefaultArgumentInfo(), Parent);
|
|
|
|
} else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(TP)) {
|
|
|
|
if (NTTP->hasDefaultArgument())
|
|
|
|
IndexCtx.indexBody(NTTP->getDefaultArgument(), Parent);
|
|
|
|
} else if (const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(TP)) {
|
|
|
|
if (TTPD->hasDefaultArgument())
|
|
|
|
handleTemplateArgumentLoc(TTPD->getDefaultArgument(), Parent,
|
|
|
|
/*DC=*/nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
return Visit(D->getTemplatedDecl());
|
2011-11-22 15:24:51 +08:00
|
|
|
}
|
2011-11-18 08:26:51 +08:00
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool VisitFriendDecl(const FriendDecl *D) {
|
|
|
|
if (auto ND = D->getFriendDecl()) {
|
|
|
|
// FIXME: Ignore a class template in a dependent context, these are not
|
|
|
|
// linked properly with their redeclarations, ending up with duplicate
|
|
|
|
// USRs.
|
|
|
|
// See comment "Friend templates are visible in fairly strange ways." in
|
|
|
|
// SemaTemplate.cpp which precedes code that prevents the friend template
|
|
|
|
// from becoming visible from the enclosing context.
|
|
|
|
if (isa<ClassTemplateDecl>(ND) && D->getDeclContext()->isDependentContext())
|
|
|
|
return true;
|
|
|
|
return Visit(ND);
|
|
|
|
}
|
|
|
|
if (auto Ty = D->getFriendType()) {
|
|
|
|
IndexCtx.indexTypeSourceInfo(Ty, cast<NamedDecl>(D->getDeclContext()));
|
|
|
|
}
|
2011-11-18 08:26:51 +08:00
|
|
|
return true;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
2012-10-03 00:10:38 +08:00
|
|
|
|
2013-02-03 21:42:20 +08:00
|
|
|
bool VisitImportDecl(const ImportDecl *D) {
|
2016-02-13 07:10:59 +08:00
|
|
|
return IndexCtx.importedModule(D);
|
2012-10-03 00:10:38 +08:00
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool IndexingContext::indexDecl(const Decl *D) {
|
2012-02-08 06:46:16 +08:00
|
|
|
if (D->isImplicit() && shouldIgnoreIfImplicit(D))
|
2016-02-13 07:10:59 +08:00
|
|
|
return true;
|
2012-02-08 06:46:16 +08:00
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
if (isTemplateImplicitInstantiation(D))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
IndexingDeclVisitor Visitor(*this);
|
|
|
|
bool ShouldContinue = Visitor.Visit(D);
|
|
|
|
if (!ShouldContinue)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!Visitor.Handled && isa<DeclContext>(D))
|
|
|
|
return indexDeclContext(cast<DeclContext>(D));
|
|
|
|
|
|
|
|
return true;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool IndexingContext::indexDeclContext(const DeclContext *DC) {
|
2014-03-08 03:56:05 +08:00
|
|
|
for (const auto *I : DC->decls())
|
2016-02-13 07:10:59 +08:00
|
|
|
if (!indexDecl(I))
|
|
|
|
return false;
|
|
|
|
return true;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool IndexingContext::indexTopLevelDecl(const Decl *D) {
|
|
|
|
if (D->getLocation().isInvalid())
|
|
|
|
return true;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-15 14:20:16 +08:00
|
|
|
if (isa<ObjCMethodDecl>(D))
|
2016-02-13 07:10:59 +08:00
|
|
|
return true; // Wait for the objc container.
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
return indexDecl(D);
|
2011-11-15 14:20:16 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool IndexingContext::indexDeclGroupRef(DeclGroupRef DG) {
|
2011-11-15 14:20:16 +08:00
|
|
|
for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
|
2016-02-13 07:10:59 +08:00
|
|
|
if (!indexTopLevelDecl(*I))
|
|
|
|
return false;
|
|
|
|
return true;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|