forked from OSchip/llvm-project
[index] Change SymbolCXXTemplateKind to a 'SymbolSubKinds' bitset.
This provides a more general and flexible way to annotate special symbols. llvm-svn: 267116
This commit is contained in:
parent
6013f45f92
commit
f2142cbca8
|
@ -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 Roles, raw_ostream &OS);
|
|||
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
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) {
|
|||
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 Decl *D) {
|
|||
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 Decl *D) {
|
|||
}
|
||||
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 Decl *D) {
|
|||
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 Decl *D) {
|
|||
|
||||
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(SymbolKind K) {
|
|||
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(SymbolLanguage K) {
|
|||
}
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -168,8 +168,9 @@ static bool printSourceSymbols(ArrayRef<const char *> Args) {
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1134,7 +1134,7 @@ void CXIndexDataConsumer::translateLoc(SourceLocation Loc,
|
|||
|
||||
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(const NamedDecl *D,
|
|||
|
||||
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 getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue