r291409 - [index] Introduce SymbolSubKind for reporting language-specific details.
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 8 15:21:36 PST 2017
Author: akirtzidis
Date: Sun Jan 8 17:21:35 2017
New Revision: 291409
URL: http://llvm.org/viewvc/llvm-project?rev=291409&view=rev
Log:
[index] Introduce SymbolSubKind for reporting language-specific details.
Initially reports if a constructor symbol is a copy or move constructor.
Modified:
cfe/trunk/include/clang/Index/IndexSymbol.h
cfe/trunk/lib/Index/IndexSymbol.cpp
cfe/trunk/test/Index/Core/index-source.cpp
cfe/trunk/tools/c-index-test/core_main.cpp
Modified: cfe/trunk/include/clang/Index/IndexSymbol.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=291409&r1=291408&r2=291409&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/IndexSymbol.h (original)
+++ cfe/trunk/include/clang/Index/IndexSymbol.h Sun Jan 8 17:21:35 2017
@@ -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 Role
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,
Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=291409&r1=291408&r2=291409&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Sun Jan 8 17:21:35 2017
@@ -53,6 +53,7 @@ SymbolInfo index::getSymbolInfo(const De
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 De
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<CXXConstructorDecl>(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(Sym
llvm_unreachable("invalid symbol kind");
}
+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";
+ }
+ llvm_unreachable("invalid symbol subkind");
+}
+
StringRef index::getSymbolLanguageString(SymbolLanguage K) {
switch (K) {
case SymbolLanguage::C: return "C";
Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=291409&r1=291408&r2=291409&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Sun Jan 8 17:21:35 2017
@@ -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 at Cls | <no-cgname> | Def | rel: 0
+class Cls {
+ // CHECK: [[@LINE+2]]:3 | constructor/C++ | Cls | c:@S at Cls@F at Cls#I# | __ZN3ClsC1Ei | Decl,RelChild | rel: 1
+ // CHECK-NEXT: RelChild | Cls | c:@S at Cls
+ Cls(int x);
+ // CHECK: [[@LINE+1]]:3 | constructor/cxx-copy-ctor/C++ | Cls | c:@S at Cls@F at Cls#&1$@S at Cls# | __ZN3ClsC1ERKS_ | Decl,RelChild | rel: 1
+ Cls(const Cls &);
+ // CHECK: [[@LINE+1]]:3 | constructor/cxx-move-ctor/C++ | Cls | c:@S at Cls@F at Cls#&&$@S at Cls# | __ZN3ClsC1EOS_ | Decl,RelChild | rel: 1
+ Cls(Cls &&);
+};
+
template <typename TemplArg>
class TemplCls {
// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | TemplCls | c:@ST>1#T at TemplCls | <no-cgname> | Def | rel: 0
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=291409&r1=291408&r2=291409&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/core_main.cpp (original)
+++ cfe/trunk/tools/c-index-test/core_main.cpp Sun Jan 8 17:21:35 2017
@@ -166,6 +166,8 @@ static bool printSourceSymbols(ArrayRef<
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);
More information about the cfe-commits
mailing list