2016-02-13 07:10:59 +08:00
|
|
|
//===--- IndexSymbol.cpp - Types and functions for indexing symbols -------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2016-02-13 07:10:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Index/IndexSymbol.h"
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2016-02-15 09:32:36 +08:00
|
|
|
#include "clang/AST/PrettyPrinter.h"
|
2018-07-09 16:44:05 +08:00
|
|
|
#include "clang/Lex/MacroInfo.h"
|
2016-02-13 07:10:59 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::index;
|
|
|
|
|
2016-04-22 15:21:10 +08:00
|
|
|
/// \returns true if \c D is a subclass of 'XCTestCase'.
|
|
|
|
static bool isUnitTestCase(const ObjCInterfaceDecl *D) {
|
|
|
|
if (!D)
|
|
|
|
return false;
|
|
|
|
while (const ObjCInterfaceDecl *SuperD = D->getSuperClass()) {
|
|
|
|
if (SuperD->getName() == "XCTestCase")
|
|
|
|
return true;
|
|
|
|
D = SuperD;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \returns true if \c D is in a subclass of 'XCTestCase', returns void, has
|
|
|
|
/// no parameters, and its name starts with 'test'.
|
|
|
|
static bool isUnitTest(const ObjCMethodDecl *D) {
|
|
|
|
if (!D->parameters().empty())
|
|
|
|
return false;
|
|
|
|
if (!D->getReturnType()->isVoidType())
|
|
|
|
return false;
|
|
|
|
if (!D->getSelector().getNameForSlot(0).startswith("test"))
|
|
|
|
return false;
|
|
|
|
return isUnitTestCase(D->getClassInterface());
|
|
|
|
}
|
|
|
|
|
2016-11-12 07:49:55 +08:00
|
|
|
static void checkForIBOutlets(const Decl *D, SymbolPropertySet &PropSet) {
|
2016-04-22 15:21:16 +08:00
|
|
|
if (D->hasAttr<IBOutletAttr>()) {
|
2017-12-24 03:31:24 +08:00
|
|
|
PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
|
2016-04-22 15:21:16 +08:00
|
|
|
} else if (D->hasAttr<IBOutletCollectionAttr>()) {
|
2017-12-24 03:31:24 +08:00
|
|
|
PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
|
|
|
|
PropSet |= (SymbolPropertySet)SymbolProperty::IBOutletCollection;
|
2016-04-22 15:21:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-26 13:37:56 +08:00
|
|
|
bool index::isFunctionLocalSymbol(const Decl *D) {
|
|
|
|
assert(D);
|
|
|
|
|
|
|
|
if (isa<ParmVarDecl>(D))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (isa<ObjCTypeParamDecl>(D))
|
|
|
|
return true;
|
|
|
|
|
2017-05-22 22:39:39 +08:00
|
|
|
if (isa<UsingDirectiveDecl>(D))
|
|
|
|
return false;
|
2017-02-26 13:37:56 +08:00
|
|
|
if (!D->getParentFunctionOrMethod())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
|
|
|
|
switch (ND->getFormalLinkage()) {
|
|
|
|
case NoLinkage:
|
|
|
|
case InternalLinkage:
|
|
|
|
return true;
|
2017-07-08 04:04:28 +08:00
|
|
|
case VisibleNoLinkage:
|
2017-02-26 13:37:56 +08:00
|
|
|
case UniqueExternalLinkage:
|
2017-07-08 04:04:28 +08:00
|
|
|
case ModuleInternalLinkage:
|
2017-02-26 13:37:56 +08:00
|
|
|
llvm_unreachable("Not a sema linkage");
|
2017-07-08 04:04:28 +08:00
|
|
|
case ModuleLinkage:
|
2017-02-26 13:37:56 +08:00
|
|
|
case ExternalLinkage:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
SymbolInfo index::getSymbolInfo(const Decl *D) {
|
|
|
|
assert(D);
|
|
|
|
SymbolInfo Info;
|
|
|
|
Info.Kind = SymbolKind::Unknown;
|
2017-01-09 07:21:35 +08:00
|
|
|
Info.SubKind = SymbolSubKind::None;
|
2016-11-12 07:49:55 +08:00
|
|
|
Info.Properties = SymbolPropertySet();
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::C;
|
|
|
|
|
2017-02-26 13:37:56 +08:00
|
|
|
if (isFunctionLocalSymbol(D)) {
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Local;
|
2017-02-26 13:37:56 +08:00
|
|
|
}
|
2018-08-26 14:27:23 +08:00
|
|
|
if (isa<ObjCProtocolDecl>(D->getDeclContext())) {
|
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::ProtocolInterface;
|
|
|
|
}
|
2017-02-26 13:37:56 +08:00
|
|
|
|
2019-05-30 01:49:30 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
|
|
|
|
switch (TD->getTagKind()) {
|
|
|
|
case TTK_Struct:
|
|
|
|
Info.Kind = SymbolKind::Struct; break;
|
|
|
|
case TTK_Union:
|
|
|
|
Info.Kind = SymbolKind::Union; break;
|
|
|
|
case TTK_Class:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Class;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
|
|
|
case TTK_Interface:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Protocol;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
|
|
|
case TTK_Enum:
|
|
|
|
Info.Kind = SymbolKind::Enum; break;
|
|
|
|
}
|
|
|
|
|
2016-11-08 05:20:08 +08:00
|
|
|
if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) {
|
|
|
|
if (!CXXRec->isCLike()) {
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2016-11-08 05:20:08 +08:00
|
|
|
if (CXXRec->getDescribedClassTemplate()) {
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
2016-11-08 05:20:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
|
|
|
|
if (isa<ClassTemplatePartialSpecializationDecl>(D)) {
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
|
|
|
Info.Properties |=
|
|
|
|
(SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization;
|
2016-02-13 07:10:59 +08:00
|
|
|
} else if (isa<ClassTemplateSpecializationDecl>(D)) {
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
|
|
|
Info.Properties |=
|
|
|
|
(SymbolPropertySet)SymbolProperty::TemplateSpecialization;
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 05:20:15 +08:00
|
|
|
} else if (auto *VD = dyn_cast<VarDecl>(D)) {
|
|
|
|
Info.Kind = SymbolKind::Variable;
|
2017-02-26 13:37:56 +08:00
|
|
|
if (isa<ParmVarDecl>(D)) {
|
|
|
|
Info.Kind = SymbolKind::Parameter;
|
|
|
|
} else if (isa<CXXRecordDecl>(D->getDeclContext())) {
|
2016-11-08 05:20:15 +08:00
|
|
|
Info.Kind = SymbolKind::StaticProperty;
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
}
|
2017-02-26 13:37:56 +08:00
|
|
|
|
2016-11-08 05:20:15 +08:00
|
|
|
if (isa<VarTemplatePartialSpecializationDecl>(D)) {
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
|
|
|
Info.Properties |=
|
|
|
|
(SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization;
|
2016-11-08 05:20:15 +08:00
|
|
|
} else if (isa<VarTemplateSpecializationDecl>(D)) {
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
|
|
|
Info.Properties |=
|
|
|
|
(SymbolPropertySet)SymbolProperty::TemplateSpecialization;
|
2016-11-08 05:20:15 +08:00
|
|
|
} else if (VD->getDescribedVarTemplate()) {
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
2016-11-08 05:20:15 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
} else {
|
|
|
|
switch (D->getKind()) {
|
2016-02-29 15:56:07 +08:00
|
|
|
case Decl::Import:
|
|
|
|
Info.Kind = SymbolKind::Module;
|
|
|
|
break;
|
2016-02-13 07:10:59 +08:00
|
|
|
case Decl::Typedef:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::TypeAlias; break; // Lang = C
|
2016-02-13 07:10:59 +08:00
|
|
|
case Decl::Function:
|
|
|
|
Info.Kind = SymbolKind::Function;
|
|
|
|
break;
|
|
|
|
case Decl::Field:
|
2019-05-29 18:11:14 +08:00
|
|
|
case Decl::IndirectField:
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Kind = SymbolKind::Field;
|
|
|
|
if (const CXXRecordDecl *
|
|
|
|
CXXRec = dyn_cast<CXXRecordDecl>(D->getDeclContext())) {
|
|
|
|
if (!CXXRec->isCLike())
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Decl::EnumConstant:
|
|
|
|
Info.Kind = SymbolKind::EnumConstant; break;
|
|
|
|
case Decl::ObjCInterface:
|
2016-04-22 15:21:10 +08:00
|
|
|
case Decl::ObjCImplementation: {
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Class;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::ObjC;
|
2016-04-22 15:21:10 +08:00
|
|
|
const ObjCInterfaceDecl *ClsD = dyn_cast<ObjCInterfaceDecl>(D);
|
|
|
|
if (!ClsD)
|
|
|
|
ClsD = cast<ObjCImplementationDecl>(D)->getClassInterface();
|
|
|
|
if (isUnitTestCase(ClsD))
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::UnitTest;
|
2016-02-13 07:10:59 +08:00
|
|
|
break;
|
2016-04-22 15:21:10 +08:00
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
case Decl::ObjCProtocol:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Protocol;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::ObjC;
|
|
|
|
break;
|
|
|
|
case Decl::ObjCCategory:
|
2017-03-07 17:38:08 +08:00
|
|
|
case Decl::ObjCCategoryImpl: {
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Extension;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::ObjC;
|
2017-03-07 17:38:08 +08:00
|
|
|
const ObjCInterfaceDecl *ClsD = nullptr;
|
|
|
|
if (auto *CatD = dyn_cast<ObjCCategoryDecl>(D))
|
|
|
|
ClsD = CatD->getClassInterface();
|
|
|
|
else
|
|
|
|
ClsD = cast<ObjCCategoryImplDecl>(D)->getClassInterface();
|
|
|
|
if (isUnitTestCase(ClsD))
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::UnitTest;
|
2016-02-13 07:10:59 +08:00
|
|
|
break;
|
2017-03-07 17:38:08 +08:00
|
|
|
}
|
2017-07-22 07:04:27 +08:00
|
|
|
case Decl::ObjCMethod: {
|
|
|
|
const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(D);
|
|
|
|
Info.Kind = MD->isInstanceMethod() ? SymbolKind::InstanceMethod : SymbolKind::ClassMethod;
|
|
|
|
if (MD->isPropertyAccessor()) {
|
|
|
|
if (MD->param_size())
|
|
|
|
Info.SubKind = SymbolSubKind::AccessorSetter;
|
|
|
|
else
|
|
|
|
Info.SubKind = SymbolSubKind::AccessorGetter;
|
2017-01-12 05:42:48 +08:00
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::ObjC;
|
2017-07-22 07:04:27 +08:00
|
|
|
if (isUnitTest(MD))
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::UnitTest;
|
2016-04-22 15:21:16 +08:00
|
|
|
if (D->hasAttr<IBActionAttr>())
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
|
2016-02-13 07:10:59 +08:00
|
|
|
break;
|
2017-07-22 07:04:27 +08:00
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
case Decl::ObjCProperty:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::InstanceProperty;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::ObjC;
|
2016-11-12 07:49:55 +08:00
|
|
|
checkForIBOutlets(D, Info.Properties);
|
2016-11-11 07:27:11 +08:00
|
|
|
if (auto *Annot = D->getAttr<AnnotateAttr>()) {
|
|
|
|
if (Annot->getAnnotation() == "gk_inspectable")
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::GKInspectable;
|
2016-11-11 07:27:11 +08:00
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
break;
|
|
|
|
case Decl::ObjCIvar:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Field;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::ObjC;
|
2016-11-12 07:49:55 +08:00
|
|
|
checkForIBOutlets(D, Info.Properties);
|
2016-02-13 07:10:59 +08:00
|
|
|
break;
|
|
|
|
case Decl::Namespace:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Namespace;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
|
|
|
case Decl::NamespaceAlias:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::NamespaceAlias;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
2017-01-09 07:21:35 +08:00
|
|
|
case Decl::CXXConstructor: {
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Constructor;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2017-01-09 07:21:35 +08:00
|
|
|
auto *CD = cast<CXXConstructorDecl>(D);
|
|
|
|
if (CD->isCopyConstructor())
|
|
|
|
Info.SubKind = SymbolSubKind::CXXCopyConstructor;
|
|
|
|
else if (CD->isMoveConstructor())
|
|
|
|
Info.SubKind = SymbolSubKind::CXXMoveConstructor;
|
2016-02-13 07:10:59 +08:00
|
|
|
break;
|
2017-01-09 07:21:35 +08:00
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
case Decl::CXXDestructor:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Destructor;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
|
|
|
case Decl::CXXConversion:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::ConversionFunction;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
|
|
|
case Decl::CXXMethod: {
|
|
|
|
const CXXMethodDecl *MD = cast<CXXMethodDecl>(D);
|
|
|
|
if (MD->isStatic())
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::StaticMethod;
|
2016-02-13 07:10:59 +08:00
|
|
|
else
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::InstanceMethod;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ClassTemplate:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Class;
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2016-02-13 07:10:59 +08:00
|
|
|
break;
|
|
|
|
case Decl::FunctionTemplate:
|
|
|
|
Info.Kind = SymbolKind::Function;
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2016-02-13 07:10:59 +08:00
|
|
|
if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(
|
|
|
|
cast<FunctionTemplateDecl>(D)->getTemplatedDecl())) {
|
|
|
|
if (isa<CXXConstructorDecl>(MD))
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Constructor;
|
2016-02-13 07:10:59 +08:00
|
|
|
else if (isa<CXXDestructorDecl>(MD))
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::Destructor;
|
2016-02-13 07:10:59 +08:00
|
|
|
else if (isa<CXXConversionDecl>(MD))
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::ConversionFunction;
|
2016-02-13 07:10:59 +08:00
|
|
|
else {
|
|
|
|
if (MD->isStatic())
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::StaticMethod;
|
2016-02-13 07:10:59 +08:00
|
|
|
else
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::InstanceMethod;
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Decl::TypeAliasTemplate:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::TypeAlias;
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
2016-02-13 07:10:59 +08:00
|
|
|
break;
|
|
|
|
case Decl::TypeAlias:
|
2016-03-26 01:01:59 +08:00
|
|
|
Info.Kind = SymbolKind::TypeAlias;
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
2017-08-17 07:12:21 +08:00
|
|
|
case Decl::UnresolvedUsingTypename:
|
|
|
|
Info.Kind = SymbolKind::Using;
|
|
|
|
Info.SubKind = SymbolSubKind::UsingTypename;
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
2017-08-17 07:12:21 +08:00
|
|
|
break;
|
|
|
|
case Decl::UnresolvedUsingValue:
|
|
|
|
Info.Kind = SymbolKind::Using;
|
|
|
|
Info.SubKind = SymbolSubKind::UsingValue;
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
2017-08-17 07:12:21 +08:00
|
|
|
break;
|
2019-02-26 22:23:12 +08:00
|
|
|
case Decl::Using:
|
|
|
|
Info.Kind = SymbolKind::Using;
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
2017-06-16 05:19:01 +08:00
|
|
|
case Decl::Binding:
|
|
|
|
Info.Kind = SymbolKind::Variable;
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
break;
|
2019-02-27 09:04:53 +08:00
|
|
|
case Decl::MSProperty:
|
|
|
|
Info.Kind = SymbolKind::InstanceProperty;
|
|
|
|
if (const CXXRecordDecl *CXXRec =
|
|
|
|
dyn_cast<CXXRecordDecl>(D->getDeclContext())) {
|
|
|
|
if (!CXXRec->isCLike())
|
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
}
|
|
|
|
break;
|
2019-05-30 01:49:30 +08:00
|
|
|
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.
|
2016-02-13 07:10:59 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Info.Kind == SymbolKind::Unknown)
|
|
|
|
return Info;
|
|
|
|
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
if (FD->getTemplatedKind() ==
|
2016-04-22 15:21:04 +08:00
|
|
|
FunctionDecl::TK_FunctionTemplateSpecialization) {
|
2017-12-24 03:31:24 +08:00
|
|
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
|
|
|
Info.Properties |=
|
|
|
|
(SymbolPropertySet)SymbolProperty::TemplateSpecialization;
|
2016-04-22 15:21:04 +08:00
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
|
|
|
|
2017-12-24 03:31:24 +08:00
|
|
|
if (Info.Properties & (SymbolPropertySet)SymbolProperty::Generic)
|
2016-02-13 07:10:59 +08:00
|
|
|
Info.Lang = SymbolLanguage::CXX;
|
|
|
|
|
2017-05-20 12:11:33 +08:00
|
|
|
if (auto *attr = D->getExternalSourceSymbolAttr()) {
|
2017-04-24 22:52:00 +08:00
|
|
|
if (attr->getLanguage() == "Swift")
|
|
|
|
Info.Lang = SymbolLanguage::Swift;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
return Info;
|
|
|
|
}
|
2016-02-14 14:39:11 +08:00
|
|
|
|
2018-07-09 16:44:05 +08:00
|
|
|
SymbolInfo index::getSymbolInfoForMacro(const MacroInfo &) {
|
|
|
|
SymbolInfo Info;
|
|
|
|
Info.Kind = SymbolKind::Macro;
|
|
|
|
Info.SubKind = SymbolSubKind::None;
|
|
|
|
Info.Properties = SymbolPropertySet();
|
|
|
|
Info.Lang = SymbolLanguage::C;
|
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
|
2017-03-24 00:34:47 +08:00
|
|
|
bool index::applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
|
|
|
|
llvm::function_ref<bool(SymbolRole)> Fn) {
|
2016-02-14 14:39:11 +08:00
|
|
|
#define APPLY_FOR_ROLE(Role) \
|
|
|
|
if (Roles & (unsigned)SymbolRole::Role) \
|
2017-03-24 00:34:47 +08:00
|
|
|
if (!Fn(SymbolRole::Role)) \
|
|
|
|
return false;
|
2016-02-14 14:39:11 +08:00
|
|
|
|
|
|
|
APPLY_FOR_ROLE(Declaration);
|
|
|
|
APPLY_FOR_ROLE(Definition);
|
|
|
|
APPLY_FOR_ROLE(Reference);
|
|
|
|
APPLY_FOR_ROLE(Read);
|
|
|
|
APPLY_FOR_ROLE(Write);
|
|
|
|
APPLY_FOR_ROLE(Call);
|
|
|
|
APPLY_FOR_ROLE(Dynamic);
|
|
|
|
APPLY_FOR_ROLE(AddressOf);
|
|
|
|
APPLY_FOR_ROLE(Implicit);
|
2018-07-09 16:44:05 +08:00
|
|
|
APPLY_FOR_ROLE(Undefinition);
|
2016-02-14 14:39:11 +08:00
|
|
|
APPLY_FOR_ROLE(RelationChildOf);
|
|
|
|
APPLY_FOR_ROLE(RelationBaseOf);
|
|
|
|
APPLY_FOR_ROLE(RelationOverrideOf);
|
|
|
|
APPLY_FOR_ROLE(RelationReceivedBy);
|
2016-02-29 15:56:00 +08:00
|
|
|
APPLY_FOR_ROLE(RelationCalledBy);
|
2016-10-26 05:11:22 +08:00
|
|
|
APPLY_FOR_ROLE(RelationExtendedBy);
|
|
|
|
APPLY_FOR_ROLE(RelationAccessorOf);
|
2017-01-12 04:51:10 +08:00
|
|
|
APPLY_FOR_ROLE(RelationContainedBy);
|
2017-01-12 05:01:07 +08:00
|
|
|
APPLY_FOR_ROLE(RelationIBTypeOf);
|
2017-04-20 18:43:22 +08:00
|
|
|
APPLY_FOR_ROLE(RelationSpecializationOf);
|
2019-03-08 16:30:20 +08:00
|
|
|
APPLY_FOR_ROLE(NameReference);
|
2016-02-14 14:39:11 +08:00
|
|
|
|
|
|
|
#undef APPLY_FOR_ROLE
|
2017-03-24 00:34:47 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void index::applyForEachSymbolRole(SymbolRoleSet Roles,
|
|
|
|
llvm::function_ref<void(SymbolRole)> Fn) {
|
|
|
|
applyForEachSymbolRoleInterruptible(Roles, [&](SymbolRole r) -> bool {
|
|
|
|
Fn(r);
|
|
|
|
return true;
|
|
|
|
});
|
2016-02-14 14:39:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void index::printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS) {
|
|
|
|
bool VisitedOnce = false;
|
|
|
|
applyForEachSymbolRole(Roles, [&](SymbolRole Role) {
|
|
|
|
if (VisitedOnce)
|
2016-02-29 15:55:51 +08:00
|
|
|
OS << ',';
|
2016-02-14 14:39:11 +08:00
|
|
|
else
|
|
|
|
VisitedOnce = true;
|
|
|
|
switch (Role) {
|
|
|
|
case SymbolRole::Declaration: OS << "Decl"; break;
|
|
|
|
case SymbolRole::Definition: OS << "Def"; break;
|
|
|
|
case SymbolRole::Reference: OS << "Ref"; break;
|
|
|
|
case SymbolRole::Read: OS << "Read"; break;
|
|
|
|
case SymbolRole::Write: OS << "Writ"; break;
|
|
|
|
case SymbolRole::Call: OS << "Call"; break;
|
|
|
|
case SymbolRole::Dynamic: OS << "Dyn"; break;
|
|
|
|
case SymbolRole::AddressOf: OS << "Addr"; break;
|
|
|
|
case SymbolRole::Implicit: OS << "Impl"; break;
|
2018-07-09 16:44:05 +08:00
|
|
|
case SymbolRole::Undefinition: OS << "Undef"; break;
|
2016-02-14 14:39:11 +08:00
|
|
|
case SymbolRole::RelationChildOf: OS << "RelChild"; break;
|
|
|
|
case SymbolRole::RelationBaseOf: OS << "RelBase"; break;
|
|
|
|
case SymbolRole::RelationOverrideOf: OS << "RelOver"; break;
|
|
|
|
case SymbolRole::RelationReceivedBy: OS << "RelRec"; break;
|
2016-02-29 15:56:00 +08:00
|
|
|
case SymbolRole::RelationCalledBy: OS << "RelCall"; break;
|
2016-10-26 05:11:22 +08:00
|
|
|
case SymbolRole::RelationExtendedBy: OS << "RelExt"; break;
|
|
|
|
case SymbolRole::RelationAccessorOf: OS << "RelAcc"; break;
|
2017-01-12 04:51:10 +08:00
|
|
|
case SymbolRole::RelationContainedBy: OS << "RelCont"; break;
|
2017-01-12 05:01:07 +08:00
|
|
|
case SymbolRole::RelationIBTypeOf: OS << "RelIBType"; break;
|
2017-04-20 18:43:22 +08:00
|
|
|
case SymbolRole::RelationSpecializationOf: OS << "RelSpecialization"; break;
|
2019-03-08 16:30:20 +08:00
|
|
|
case SymbolRole::NameReference: OS << "NameReference"; break;
|
2016-02-14 14:39:11 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-15 09:32:36 +08:00
|
|
|
bool index::printSymbolName(const Decl *D, const LangOptions &LO,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
if (auto *ND = dyn_cast<NamedDecl>(D)) {
|
|
|
|
PrintingPolicy Policy(LO);
|
|
|
|
// Forward references can have different template argument names. Suppress
|
|
|
|
// the template argument names in constructors to make their name more
|
|
|
|
// stable.
|
|
|
|
Policy.SuppressTemplateArgsInCXXConstructors = true;
|
|
|
|
DeclarationName DeclName = ND->getDeclName();
|
|
|
|
if (DeclName.isEmpty())
|
|
|
|
return true;
|
|
|
|
DeclName.print(OS, Policy);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-14 14:39:11 +08:00
|
|
|
StringRef index::getSymbolKindString(SymbolKind K) {
|
|
|
|
switch (K) {
|
|
|
|
case SymbolKind::Unknown: return "<unknown>";
|
|
|
|
case SymbolKind::Module: return "module";
|
2016-03-26 01:01:59 +08:00
|
|
|
case SymbolKind::Namespace: return "namespace";
|
|
|
|
case SymbolKind::NamespaceAlias: return "namespace-alias";
|
2016-02-14 14:39:11 +08:00
|
|
|
case SymbolKind::Macro: return "macro";
|
|
|
|
case SymbolKind::Enum: return "enum";
|
|
|
|
case SymbolKind::Struct: return "struct";
|
2016-03-26 01:01:59 +08:00
|
|
|
case SymbolKind::Class: return "class";
|
|
|
|
case SymbolKind::Protocol: return "protocol";
|
|
|
|
case SymbolKind::Extension: return "extension";
|
2016-02-14 14:39:11 +08:00
|
|
|
case SymbolKind::Union: return "union";
|
2016-03-26 01:01:59 +08:00
|
|
|
case SymbolKind::TypeAlias: return "type-alias";
|
2016-02-14 14:39:11 +08:00
|
|
|
case SymbolKind::Function: return "function";
|
|
|
|
case SymbolKind::Variable: return "variable";
|
|
|
|
case SymbolKind::Field: return "field";
|
|
|
|
case SymbolKind::EnumConstant: return "enumerator";
|
2016-03-26 01:01:59 +08:00
|
|
|
case SymbolKind::InstanceMethod: return "instance-method";
|
|
|
|
case SymbolKind::ClassMethod: return "class-method";
|
|
|
|
case SymbolKind::StaticMethod: return "static-method";
|
|
|
|
case SymbolKind::InstanceProperty: return "instance-property";
|
|
|
|
case SymbolKind::ClassProperty: return "class-property";
|
|
|
|
case SymbolKind::StaticProperty: return "static-property";
|
|
|
|
case SymbolKind::Constructor: return "constructor";
|
|
|
|
case SymbolKind::Destructor: return "destructor";
|
2019-07-24 00:54:11 +08:00
|
|
|
case SymbolKind::ConversionFunction: return "conversion-func";
|
2017-02-26 13:37:56 +08:00
|
|
|
case SymbolKind::Parameter: return "param";
|
2017-08-17 07:12:21 +08:00
|
|
|
case SymbolKind::Using: return "using";
|
2016-02-14 14:39:11 +08:00
|
|
|
}
|
2016-02-15 08:36:52 +08:00
|
|
|
llvm_unreachable("invalid symbol kind");
|
2016-02-14 14:39:11 +08:00
|
|
|
}
|
|
|
|
|
2017-01-09 07:21:35 +08:00
|
|
|
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";
|
2017-01-12 05:42:48 +08:00
|
|
|
case SymbolSubKind::AccessorGetter: return "acc-get";
|
|
|
|
case SymbolSubKind::AccessorSetter: return "acc-set";
|
2017-08-17 07:12:21 +08:00
|
|
|
case SymbolSubKind::UsingTypename: return "using-typename";
|
|
|
|
case SymbolSubKind::UsingValue: return "using-value";
|
2017-01-09 07:21:35 +08:00
|
|
|
}
|
|
|
|
llvm_unreachable("invalid symbol subkind");
|
|
|
|
}
|
|
|
|
|
2016-02-14 14:39:11 +08:00
|
|
|
StringRef index::getSymbolLanguageString(SymbolLanguage K) {
|
|
|
|
switch (K) {
|
|
|
|
case SymbolLanguage::C: return "C";
|
|
|
|
case SymbolLanguage::ObjC: return "ObjC";
|
|
|
|
case SymbolLanguage::CXX: return "C++";
|
2017-04-24 22:52:00 +08:00
|
|
|
case SymbolLanguage::Swift: return "Swift";
|
2016-02-14 14:39:11 +08:00
|
|
|
}
|
2016-02-15 08:36:52 +08:00
|
|
|
llvm_unreachable("invalid symbol language kind");
|
2016-02-14 14:39:11 +08:00
|
|
|
}
|
2016-04-22 15:21:04 +08:00
|
|
|
|
2016-11-12 07:49:55 +08:00
|
|
|
void index::applyForEachSymbolProperty(SymbolPropertySet Props,
|
|
|
|
llvm::function_ref<void(SymbolProperty)> Fn) {
|
2017-12-24 03:31:24 +08:00
|
|
|
#define APPLY_FOR_PROPERTY(K) \
|
|
|
|
if (Props & (SymbolPropertySet)SymbolProperty::K) \
|
|
|
|
Fn(SymbolProperty::K)
|
2016-04-22 15:21:04 +08:00
|
|
|
|
2016-11-12 07:49:55 +08:00
|
|
|
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);
|
2017-02-26 13:37:56 +08:00
|
|
|
APPLY_FOR_PROPERTY(Local);
|
2018-08-26 14:27:23 +08:00
|
|
|
APPLY_FOR_PROPERTY(ProtocolInterface);
|
2016-04-22 15:21:04 +08:00
|
|
|
|
2016-11-12 07:49:55 +08:00
|
|
|
#undef APPLY_FOR_PROPERTY
|
2016-04-22 15:21:04 +08:00
|
|
|
}
|
|
|
|
|
2016-11-12 07:49:55 +08:00
|
|
|
void index::printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS) {
|
2016-04-22 15:21:04 +08:00
|
|
|
bool VisitedOnce = false;
|
2016-11-12 07:49:55 +08:00
|
|
|
applyForEachSymbolProperty(Props, [&](SymbolProperty Prop) {
|
2016-04-22 15:21:04 +08:00
|
|
|
if (VisitedOnce)
|
|
|
|
OS << ',';
|
|
|
|
else
|
|
|
|
VisitedOnce = true;
|
2016-11-12 07:49:55 +08:00
|
|
|
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;
|
2017-02-26 13:37:56 +08:00
|
|
|
case SymbolProperty::Local: OS << "local"; break;
|
2018-08-26 14:27:23 +08:00
|
|
|
case SymbolProperty::ProtocolInterface: OS << "protocol"; break;
|
2016-04-22 15:21:04 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|