diff --git a/clang/include/clang/Index/IndexSymbol.h b/clang/include/clang/Index/IndexSymbol.h index 2b383ac8fd61..cac0b53a939e 100644 --- a/clang/include/clang/Index/IndexSymbol.h +++ b/clang/include/clang/Index/IndexSymbol.h @@ -59,7 +59,8 @@ enum class SymbolLanguage { CXX, }; -enum class SymbolSubKind : uint8_t { +/// Set of properties that provide additional info about a symbol. +enum class SymbolProperty : uint8_t { Generic = 1 << 0, TemplatePartialSpecialization = 1 << 1, TemplateSpecialization = 1 << 2, @@ -68,8 +69,8 @@ enum class SymbolSubKind : uint8_t { IBOutletCollection = 1 << 5, GKInspectable = 1 << 6, }; -static const unsigned SymbolSubKindBitNum = 7; -typedef unsigned SymbolSubKindSet; +static const unsigned SymbolPropertyBitNum = 7; +typedef unsigned SymbolPropertySet; /// Set of roles that are attributed to symbol occurrences. enum class SymbolRole : uint16_t { @@ -106,7 +107,7 @@ struct SymbolRelation { struct SymbolInfo { SymbolKind Kind; - SymbolSubKindSet SubKinds; + SymbolPropertySet Properties; SymbolLanguage Lang; }; @@ -122,9 +123,9 @@ bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS); StringRef getSymbolKindString(SymbolKind K); StringRef getSymbolLanguageString(SymbolLanguage K); -void applyForEachSymbolSubKind(SymbolSubKindSet SubKinds, - llvm::function_ref Fn); -void printSymbolSubKinds(SymbolSubKindSet SubKinds, raw_ostream &OS); +void applyForEachSymbolProperty(SymbolPropertySet Props, + llvm::function_ref Fn); +void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS); } // namespace index } // namespace clang diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp index f5153fb61d01..b2342453a916 100644 --- a/clang/lib/Index/IndexSymbol.cpp +++ b/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()) { - SubKindSet |= (unsigned)SymbolSubKind::IBAnnotated; + PropSet |= (unsigned)SymbolProperty::IBAnnotated; } else if (D->hasAttr()) { - SubKindSet |= (unsigned)SymbolSubKind::IBAnnotated; - SubKindSet |= (unsigned)SymbolSubKind::IBOutletCollection; + PropSet |= (unsigned)SymbolProperty::IBAnnotated; + PropSet |= (unsigned)SymbolProperty::IBOutletCollection; } } @@ -53,7 +53,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { assert(D); SymbolInfo Info; Info.Kind = SymbolKind::Unknown; - Info.SubKinds = SymbolSubKindSet(); + Info.Properties = SymbolPropertySet(); Info.Lang = SymbolLanguage::C; if (const TagDecl *TD = dyn_cast(D)) { @@ -78,17 +78,17 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { if (!CXXRec->isCLike()) { Info.Lang = SymbolLanguage::CXX; if (CXXRec->getDescribedClassTemplate()) { - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; + Info.Properties |= (unsigned)SymbolProperty::Generic; } } } if (isa(D)) { - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; - Info.SubKinds |= (unsigned)SymbolSubKind::TemplatePartialSpecialization; + Info.Properties |= (unsigned)SymbolProperty::Generic; + Info.Properties |= (unsigned)SymbolProperty::TemplatePartialSpecialization; } else if (isa(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(D)) { @@ -99,15 +99,15 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { } if (isa(D)) { Info.Lang = SymbolLanguage::CXX; - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; - Info.SubKinds |= (unsigned)SymbolSubKind::TemplatePartialSpecialization; + Info.Properties |= (unsigned)SymbolProperty::Generic; + Info.Properties |= (unsigned)SymbolProperty::TemplatePartialSpecialization; } else if (isa(D)) { Info.Lang = SymbolLanguage::CXX; - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; - Info.SubKinds |= (unsigned)SymbolSubKind::TemplateSpecialization; + Info.Properties |= (unsigned)SymbolProperty::Generic; + Info.Properties |= (unsigned)SymbolProperty::TemplateSpecialization; } else if (VD->getDescribedVarTemplate()) { Info.Lang = SymbolLanguage::CXX; - Info.SubKinds |= (unsigned)SymbolSubKind::Generic; + Info.Properties |= (unsigned)SymbolProperty::Generic; } } else { @@ -138,7 +138,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { if (!ClsD) ClsD = cast(D)->getClassInterface(); if (isUnitTestCase(ClsD)) - Info.SubKinds |= (unsigned)SymbolSubKind::UnitTest; + Info.Properties |= (unsigned)SymbolProperty::UnitTest; break; } case Decl::ObjCProtocol: @@ -157,23 +157,23 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Kind = SymbolKind::ClassMethod; Info.Lang = SymbolLanguage::ObjC; if (isUnitTest(cast(D))) - Info.SubKinds |= (unsigned)SymbolSubKind::UnitTest; + Info.Properties |= (unsigned)SymbolProperty::UnitTest; if (D->hasAttr()) - 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()) { if (Annot->getAnnotation() == "gk_inspectable") - Info.SubKinds |= (unsigned)SymbolSubKind::GKInspectable; + 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; @@ -206,12 +206,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( cast(D)->getTemplatedDecl())) { @@ -232,7 +232,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; @@ -249,12 +249,12 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { if (const FunctionDecl *FD = dyn_cast(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; @@ -372,38 +372,38 @@ StringRef index::getSymbolLanguageString(SymbolLanguage K) { llvm_unreachable("invalid symbol language kind"); } -void index::applyForEachSymbolSubKind(SymbolSubKindSet SubKinds, - llvm::function_ref Fn) { -#define APPLY_FOR_SUBKIND(K) \ - if (SubKinds & (unsigned)SymbolSubKind::K) \ - Fn(SymbolSubKind::K) +void index::applyForEachSymbolProperty(SymbolPropertySet Props, + llvm::function_ref 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_SUBKIND(GKInspectable); + 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; - case SymbolSubKind::GKInspectable: OS << "GKI"; 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/clang/tools/c-index-test/core_main.cpp b/clang/tools/c-index-test/core_main.cpp index 7b7acf07704d..3e4052c93ef5 100644 --- a/clang/tools/c-index-test/core_main.cpp +++ b/clang/tools/c-index-test/core_main.cpp @@ -167,9 +167,9 @@ static bool printSourceSymbols(ArrayRef Args) { static void printSymbolInfo(SymbolInfo SymInfo, raw_ostream &OS) { OS << getSymbolKindString(SymInfo.Kind); - if (SymInfo.SubKinds) { + if (SymInfo.Properties) { OS << '('; - printSymbolSubKinds(SymInfo.SubKinds, OS); + printSymbolProperties(SymInfo.Properties, OS); OS << ')'; } OS << '/' << getSymbolLanguageString(SymInfo.Lang); diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp index 74d8f2415c63..45198dd1b168 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.cpp +++ b/clang/tools/libclang/CXIndexDataConsumer.cpp @@ -1142,7 +1142,7 @@ void CXIndexDataConsumer::translateLoc(SourceLocation Loc, static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage L); static CXIdxEntityCXXTemplateKind -getEntityKindFromSymbolSubKinds(SymbolSubKindSet K); +getEntityKindFromSymbolProperties(SymbolPropertySet K); static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L); void CXIndexDataConsumer::getEntityInfo(const NamedDecl *D, @@ -1158,7 +1158,7 @@ void CXIndexDataConsumer::getEntityInfo(const NamedDecl *D, SymbolInfo SymInfo = getSymbolInfo(D); EntityInfo.kind = getEntityKindFromSymbolKind(SymInfo.Kind, SymInfo.Lang); - EntityInfo.templateKind = getEntityKindFromSymbolSubKinds(SymInfo.SubKinds); + EntityInfo.templateKind = getEntityKindFromSymbolProperties(SymInfo.Properties); EntityInfo.lang = getEntityLangFromSymbolLang(SymInfo.Lang); if (D->hasAttrs()) { @@ -1298,12 +1298,12 @@ static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage } static CXIdxEntityCXXTemplateKind -getEntityKindFromSymbolSubKinds(SymbolSubKindSet K) { - if (K & (unsigned)SymbolSubKind::TemplatePartialSpecialization) +getEntityKindFromSymbolProperties(SymbolPropertySet K) { + if (K & (unsigned)SymbolProperty::TemplatePartialSpecialization) return CXIdxEntity_TemplatePartialSpecialization; - if (K & (unsigned)SymbolSubKind::TemplateSpecialization) + if (K & (unsigned)SymbolProperty::TemplateSpecialization) return CXIdxEntity_TemplateSpecialization; - if (K & (unsigned)SymbolSubKind::Generic) + if (K & (unsigned)SymbolProperty::Generic) return CXIdxEntity_Template; return CXIdxEntity_NonTemplate; }