From: Argyrios Kyrtzidis Date: Sun, 8 Jan 2017 23:21:35 +0000 (+0000) Subject: [index] Introduce SymbolSubKind for reporting language-specific details. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c900a4b13d5e4746201cb3c8f6229e5cad3b35d9;p=clang [index] Introduce SymbolSubKind for reporting language-specific details. Initially reports if a constructor symbol is a copy or move constructor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291409 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Index/IndexSymbol.h b/include/clang/Index/IndexSymbol.h index cac0b53a93..559b212b92 100644 --- a/include/clang/Index/IndexSymbol.h +++ b/include/clang/Index/IndexSymbol.h @@ -59,6 +59,13 @@ enum class SymbolLanguage { CXX, }; +/// Language specific sub-kinds. +enum class SymbolSubKind { + None, + CXXCopyConstructor, + CXXMoveConstructor, +}; + /// Set of properties that provide additional info about a symbol. enum class SymbolProperty : uint8_t { Generic = 1 << 0, @@ -107,6 +114,7 @@ struct SymbolRelation { struct SymbolInfo { SymbolKind Kind; + SymbolSubKind SubKind; SymbolPropertySet Properties; SymbolLanguage Lang; }; @@ -121,6 +129,7 @@ void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS); bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS); StringRef getSymbolKindString(SymbolKind K); +StringRef getSymbolSubKindString(SymbolSubKind K); StringRef getSymbolLanguageString(SymbolLanguage K); void applyForEachSymbolProperty(SymbolPropertySet Props, diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp index b2342453a9..be847e7620 100644 --- a/lib/Index/IndexSymbol.cpp +++ b/lib/Index/IndexSymbol.cpp @@ -53,6 +53,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { assert(D); SymbolInfo Info; Info.Kind = SymbolKind::Unknown; + Info.SubKind = SymbolSubKind::None; Info.Properties = SymbolPropertySet(); Info.Lang = SymbolLanguage::C; @@ -183,10 +184,16 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Kind = SymbolKind::NamespaceAlias; Info.Lang = SymbolLanguage::CXX; break; - case Decl::CXXConstructor: + case Decl::CXXConstructor: { Info.Kind = SymbolKind::Constructor; Info.Lang = SymbolLanguage::CXX; + auto *CD = cast(D); + if (CD->isCopyConstructor()) + Info.SubKind = SymbolSubKind::CXXCopyConstructor; + else if (CD->isMoveConstructor()) + Info.SubKind = SymbolSubKind::CXXMoveConstructor; break; + } case Decl::CXXDestructor: Info.Kind = SymbolKind::Destructor; Info.Lang = SymbolLanguage::CXX; @@ -363,6 +370,15 @@ StringRef index::getSymbolKindString(SymbolKind K) { llvm_unreachable("invalid symbol kind"); } +StringRef index::getSymbolSubKindString(SymbolSubKind K) { + switch (K) { + case SymbolSubKind::None: return ""; + case SymbolSubKind::CXXCopyConstructor: return "cxx-copy-ctor"; + case SymbolSubKind::CXXMoveConstructor: return "cxx-move-ctor"; + } + llvm_unreachable("invalid symbol subkind"); +} + StringRef index::getSymbolLanguageString(SymbolLanguage K) { switch (K) { case SymbolLanguage::C: return "C"; diff --git a/test/Index/Core/index-source.cpp b/test/Index/Core/index-source.cpp index 7db5d531f4..0e898d8c83 100644 --- a/test/Index/Core/index-source.cpp +++ b/test/Index/Core/index-source.cpp @@ -1,5 +1,16 @@ // RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target x86_64-apple-macosx10.7 | FileCheck %s +// CHECK: [[@LINE+1]]:7 | class/C++ | Cls | c:@S@Cls | | Def | rel: 0 +class Cls { + // CHECK: [[@LINE+2]]:3 | constructor/C++ | Cls | c:@S@Cls@F@Cls#I# | __ZN3ClsC1Ei | Decl,RelChild | rel: 1 + // CHECK-NEXT: RelChild | Cls | c:@S@Cls + Cls(int x); + // CHECK: [[@LINE+1]]:3 | constructor/cxx-copy-ctor/C++ | Cls | c:@S@Cls@F@Cls#&1$@S@Cls# | __ZN3ClsC1ERKS_ | Decl,RelChild | rel: 1 + Cls(const Cls &); + // CHECK: [[@LINE+1]]:3 | constructor/cxx-move-ctor/C++ | Cls | c:@S@Cls@F@Cls#&&$@S@Cls# | __ZN3ClsC1EOS_ | Decl,RelChild | rel: 1 + Cls(Cls &&); +}; + template class TemplCls { // CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | TemplCls | c:@ST>1#T@TemplCls | | Def | rel: 0 diff --git a/tools/c-index-test/core_main.cpp b/tools/c-index-test/core_main.cpp index 8976d91349..0ab24fb6cc 100644 --- a/tools/c-index-test/core_main.cpp +++ b/tools/c-index-test/core_main.cpp @@ -166,6 +166,8 @@ static bool printSourceSymbols(ArrayRef Args) { static void printSymbolInfo(SymbolInfo SymInfo, raw_ostream &OS) { OS << getSymbolKindString(SymInfo.Kind); + if (SymInfo.SubKind != SymbolSubKind::None) + OS << '/' << getSymbolSubKindString(SymInfo.SubKind); if (SymInfo.Properties) { OS << '('; printSymbolProperties(SymInfo.Properties, OS);