r267116 - [index] Change SymbolCXXTemplateKind to a 'SymbolSubKinds' bitset.
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 22 00:21:04 PDT 2016
Author: akirtzidis
Date: Fri Apr 22 02:21:04 2016
New Revision: 267116
URL: http://llvm.org/viewvc/llvm-project?rev=267116&view=rev
Log:
[index] Change SymbolCXXTemplateKind to a 'SymbolSubKinds' bitset.
This provides a more general and flexible way to annotate special symbols.
Modified:
cfe/trunk/include/clang/Index/IndexSymbol.h
cfe/trunk/lib/Index/IndexSymbol.cpp
cfe/trunk/tools/c-index-test/core_main.cpp
cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
Modified: cfe/trunk/include/clang/Index/IndexSymbol.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=267116&r1=267115&r2=267116&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/IndexSymbol.h (original)
+++ cfe/trunk/include/clang/Index/IndexSymbol.h Fri Apr 22 02:21:04 2016
@@ -59,12 +59,13 @@ enum class SymbolLanguage {
CXX,
};
-enum class SymbolCXXTemplateKind {
- NonTemplate,
- Template,
- TemplatePartialSpecialization,
- TemplateSpecialization,
+enum class SymbolSubKind : uint8_t {
+ Generic = 1 << 0,
+ TemplatePartialSpecialization = 1 << 1,
+ TemplateSpecialization = 1 << 2,
};
+static const unsigned SymbolSubKindBitNum = 3;
+typedef unsigned SymbolSubKindSet;
/// Set of roles that are attributed to symbol occurrences.
enum class SymbolRole : uint16_t {
@@ -99,7 +100,7 @@ struct SymbolRelation {
struct SymbolInfo {
SymbolKind Kind;
- SymbolCXXTemplateKind TemplateKind;
+ SymbolSubKindSet SubKinds;
SymbolLanguage Lang;
};
@@ -113,9 +114,12 @@ void printSymbolRoles(SymbolRoleSet Role
bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
StringRef getSymbolKindString(SymbolKind K);
-StringRef getTemplateKindStr(SymbolCXXTemplateKind TK);
StringRef getSymbolLanguageString(SymbolLanguage K);
+void applyForEachSymbolSubKind(SymbolSubKindSet SubKinds,
+ llvm::function_ref<void(SymbolSubKind)> Fn);
+void printSymbolSubKinds(SymbolSubKindSet SubKinds, raw_ostream &OS);
+
} // namespace index
} // namespace clang
Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=267116&r1=267115&r2=267116&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Fri Apr 22 02:21:04 2016
@@ -20,7 +20,7 @@ SymbolInfo index::getSymbolInfo(const De
assert(D);
SymbolInfo Info;
Info.Kind = SymbolKind::Unknown;
- Info.TemplateKind = SymbolCXXTemplateKind::NonTemplate;
+ Info.SubKinds = SymbolSubKindSet();
Info.Lang = SymbolLanguage::C;
if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
@@ -46,9 +46,11 @@ SymbolInfo index::getSymbolInfo(const De
Info.Lang = SymbolLanguage::CXX;
if (isa<ClassTemplatePartialSpecializationDecl>(D)) {
- Info.TemplateKind = SymbolCXXTemplateKind::TemplatePartialSpecialization;
+ Info.SubKinds |= (unsigned)SymbolSubKind::Generic;
+ Info.SubKinds |= (unsigned)SymbolSubKind::TemplatePartialSpecialization;
} else if (isa<ClassTemplateSpecializationDecl>(D)) {
- Info.TemplateKind = SymbolCXXTemplateKind::TemplateSpecialization;
+ Info.SubKinds |= (unsigned)SymbolSubKind::Generic;
+ Info.SubKinds |= (unsigned)SymbolSubKind::TemplateSpecialization;
}
} else {
@@ -141,12 +143,12 @@ SymbolInfo index::getSymbolInfo(const De
}
case Decl::ClassTemplate:
Info.Kind = SymbolKind::Class;
- Info.TemplateKind = SymbolCXXTemplateKind::Template;
+ Info.SubKinds |= (unsigned)SymbolSubKind::Generic;
Info.Lang = SymbolLanguage::CXX;
break;
case Decl::FunctionTemplate:
Info.Kind = SymbolKind::Function;
- Info.TemplateKind = SymbolCXXTemplateKind::Template;
+ Info.SubKinds |= (unsigned)SymbolSubKind::Generic;
Info.Lang = SymbolLanguage::CXX;
if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(
cast<FunctionTemplateDecl>(D)->getTemplatedDecl())) {
@@ -167,7 +169,7 @@ SymbolInfo index::getSymbolInfo(const De
case Decl::TypeAliasTemplate:
Info.Kind = SymbolKind::TypeAlias;
Info.Lang = SymbolLanguage::CXX;
- Info.TemplateKind = SymbolCXXTemplateKind::Template;
+ Info.SubKinds |= (unsigned)SymbolSubKind::Generic;
break;
case Decl::TypeAlias:
Info.Kind = SymbolKind::TypeAlias;
@@ -183,11 +185,13 @@ SymbolInfo index::getSymbolInfo(const De
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
if (FD->getTemplatedKind() ==
- FunctionDecl::TK_FunctionTemplateSpecialization)
- Info.TemplateKind = SymbolCXXTemplateKind::TemplateSpecialization;
+ FunctionDecl::TK_FunctionTemplateSpecialization) {
+ Info.SubKinds |= (unsigned)SymbolSubKind::Generic;
+ Info.SubKinds |= (unsigned)SymbolSubKind::TemplateSpecialization;
+ }
}
- if (Info.TemplateKind != SymbolCXXTemplateKind::NonTemplate)
+ if (Info.SubKinds & (unsigned)SymbolSubKind::Generic)
Info.Lang = SymbolLanguage::CXX;
return Info;
@@ -292,16 +296,6 @@ StringRef index::getSymbolKindString(Sym
llvm_unreachable("invalid symbol kind");
}
-StringRef index::getTemplateKindStr(SymbolCXXTemplateKind TK) {
- switch (TK) {
- case SymbolCXXTemplateKind::NonTemplate: return "NT";
- case SymbolCXXTemplateKind::Template : return "T";
- case SymbolCXXTemplateKind::TemplatePartialSpecialization : return "TPS";
- case SymbolCXXTemplateKind::TemplateSpecialization: return "TS";
- }
- llvm_unreachable("invalid template kind");
-}
-
StringRef index::getSymbolLanguageString(SymbolLanguage K) {
switch (K) {
case SymbolLanguage::C: return "C";
@@ -310,3 +304,31 @@ StringRef index::getSymbolLanguageString
}
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)
+
+ APPLY_FOR_SUBKIND(Generic);
+ APPLY_FOR_SUBKIND(TemplatePartialSpecialization);
+ APPLY_FOR_SUBKIND(TemplateSpecialization);
+
+#undef APPLY_FOR_SUBKIND
+}
+
+void index::printSymbolSubKinds(SymbolSubKindSet SubKinds, raw_ostream &OS) {
+ bool VisitedOnce = false;
+ applyForEachSymbolSubKind(SubKinds, [&](SymbolSubKind SubKind) {
+ 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;
+ }
+ });
+}
Modified: cfe/trunk/tools/c-index-test/core_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/core_main.cpp?rev=267116&r1=267115&r2=267116&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/core_main.cpp (original)
+++ cfe/trunk/tools/c-index-test/core_main.cpp Fri Apr 22 02:21:04 2016
@@ -168,8 +168,9 @@ static bool printSourceSymbols(ArrayRef<
static void printSymbolInfo(SymbolInfo SymInfo, raw_ostream &OS) {
OS << getSymbolKindString(SymInfo.Kind);
- if (SymInfo.TemplateKind != SymbolCXXTemplateKind::NonTemplate) {
- OS << '-' << getTemplateKindStr(SymInfo.TemplateKind);
+ if (SymInfo.SubKinds) {
+ OS << '-';
+ printSymbolSubKinds(SymInfo.SubKinds, OS);
}
OS << '/' << getSymbolLanguageString(SymInfo.Lang);
}
Modified: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp?rev=267116&r1=267115&r2=267116&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp (original)
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp Fri Apr 22 02:21:04 2016
@@ -1134,7 +1134,7 @@ void CXIndexDataConsumer::translateLoc(S
static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage L);
static CXIdxEntityCXXTemplateKind
-getEntityKindFromSymbolCXXTemplateKind(SymbolCXXTemplateKind K);
+getEntityKindFromSymbolSubKinds(SymbolSubKindSet K);
static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L);
void CXIndexDataConsumer::getEntityInfo(const NamedDecl *D,
@@ -1150,8 +1150,7 @@ void CXIndexDataConsumer::getEntityInfo(
SymbolInfo SymInfo = getSymbolInfo(D);
EntityInfo.kind = getEntityKindFromSymbolKind(SymInfo.Kind, SymInfo.Lang);
- EntityInfo.templateKind =
- getEntityKindFromSymbolCXXTemplateKind(SymInfo.TemplateKind);
+ EntityInfo.templateKind = getEntityKindFromSymbolSubKinds(SymInfo.SubKinds);
EntityInfo.lang = getEntityLangFromSymbolLang(SymInfo.Lang);
if (D->hasAttrs()) {
@@ -1291,16 +1290,14 @@ static CXIdxEntityKind getEntityKindFrom
}
static CXIdxEntityCXXTemplateKind
-getEntityKindFromSymbolCXXTemplateKind(SymbolCXXTemplateKind K) {
- switch (K) {
- case SymbolCXXTemplateKind::NonTemplate: return CXIdxEntity_NonTemplate;
- case SymbolCXXTemplateKind::Template: return CXIdxEntity_Template;
- case SymbolCXXTemplateKind::TemplatePartialSpecialization:
+getEntityKindFromSymbolSubKinds(SymbolSubKindSet K) {
+ if (K & (unsigned)SymbolSubKind::TemplatePartialSpecialization)
return CXIdxEntity_TemplatePartialSpecialization;
- case SymbolCXXTemplateKind::TemplateSpecialization:
+ if (K & (unsigned)SymbolSubKind::TemplateSpecialization)
return CXIdxEntity_TemplateSpecialization;
- }
- llvm_unreachable("invalid template kind");
+ if (K & (unsigned)SymbolSubKind::Generic)
+ return CXIdxEntity_Template;
+ return CXIdxEntity_NonTemplate;
}
static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L) {
More information about the cfe-commits
mailing list