From eacdb14b4d95109b817b1fa99962d1a000f10b0d Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Fri, 25 Mar 2016 17:01:59 +0000 Subject: [PATCH] [index] Remove redundancy between symbol kind and language Condense the ObjCKIND and CXXKIND options into just KIND, since the language was already specified on a per-symbol basis and this information was redundant. This only changes the internal representation; naturally the libclang interface remains the same. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264423 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Index/IndexSymbol.h | 37 +++++------ lib/Index/IndexSymbol.cpp | 89 +++++++++++++------------- test/Index/Core/index-source.cpp | 2 +- test/Index/Core/index-source.m | 24 +++---- tools/libclang/CXIndexDataConsumer.cpp | 58 ++++++++++------- 5 files changed, 107 insertions(+), 103 deletions(-) diff --git a/include/clang/Index/IndexSymbol.h b/include/clang/Index/IndexSymbol.h index 484edda696..56b12fa6be 100644 --- a/include/clang/Index/IndexSymbol.h +++ b/include/clang/Index/IndexSymbol.h @@ -24,38 +24,33 @@ enum class SymbolKind : uint8_t { Unknown, Module, + Namespace, + NamespaceAlias, Macro, Enum, Struct, + Class, + Protocol, + Extension, Union, - Typedef, + TypeAlias, Function, Variable, Field, EnumConstant, - ObjCClass, - ObjCProtocol, - ObjCCategory, - - ObjCInstanceMethod, - ObjCClassMethod, - ObjCProperty, - ObjCIvar, - - CXXClass, - CXXNamespace, - CXXNamespaceAlias, - CXXStaticVariable, - CXXStaticMethod, - CXXInstanceMethod, - CXXConstructor, - CXXDestructor, - CXXConversionFunction, - CXXTypeAlias, - CXXInterface, + InstanceMethod, + ClassMethod, + StaticMethod, + InstanceProperty, + ClassProperty, + StaticProperty, + + Constructor, + Destructor, + ConversionFunction, }; enum class SymbolLanguage { diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp index 62e2facde1..9f91e6274d 100644 --- a/lib/Index/IndexSymbol.cpp +++ b/lib/Index/IndexSymbol.cpp @@ -30,11 +30,11 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { case TTK_Union: Info.Kind = SymbolKind::Union; break; case TTK_Class: - Info.Kind = SymbolKind::CXXClass; + Info.Kind = SymbolKind::Class; Info.Lang = SymbolLanguage::CXX; break; case TTK_Interface: - Info.Kind = SymbolKind::CXXInterface; + Info.Kind = SymbolKind::Protocol; Info.Lang = SymbolLanguage::CXX; break; case TTK_Enum: @@ -57,7 +57,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Kind = SymbolKind::Module; break; case Decl::Typedef: - Info.Kind = SymbolKind::Typedef; break; + Info.Kind = SymbolKind::TypeAlias; break; // Lang = C case Decl::Function: Info.Kind = SymbolKind::Function; break; @@ -67,7 +67,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { case Decl::Var: Info.Kind = SymbolKind::Variable; if (isa(D->getDeclContext())) { - Info.Kind = SymbolKind::CXXStaticVariable; + Info.Kind = SymbolKind::StaticProperty; Info.Lang = SymbolLanguage::CXX; } break; @@ -83,91 +83,94 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Kind = SymbolKind::EnumConstant; break; case Decl::ObjCInterface: case Decl::ObjCImplementation: - Info.Kind = SymbolKind::ObjCClass; + Info.Kind = SymbolKind::Class; Info.Lang = SymbolLanguage::ObjC; break; case Decl::ObjCProtocol: - Info.Kind = SymbolKind::ObjCProtocol; + Info.Kind = SymbolKind::Protocol; Info.Lang = SymbolLanguage::ObjC; break; case Decl::ObjCCategory: case Decl::ObjCCategoryImpl: - Info.Kind = SymbolKind::ObjCCategory; + Info.Kind = SymbolKind::Extension; Info.Lang = SymbolLanguage::ObjC; break; case Decl::ObjCMethod: if (cast(D)->isInstanceMethod()) - Info.Kind = SymbolKind::ObjCInstanceMethod; + Info.Kind = SymbolKind::InstanceMethod; else - Info.Kind = SymbolKind::ObjCClassMethod; + Info.Kind = SymbolKind::ClassMethod; Info.Lang = SymbolLanguage::ObjC; break; case Decl::ObjCProperty: - Info.Kind = SymbolKind::ObjCProperty; + Info.Kind = SymbolKind::InstanceProperty; Info.Lang = SymbolLanguage::ObjC; break; case Decl::ObjCIvar: - Info.Kind = SymbolKind::ObjCIvar; + Info.Kind = SymbolKind::Field; Info.Lang = SymbolLanguage::ObjC; break; case Decl::Namespace: - Info.Kind = SymbolKind::CXXNamespace; + Info.Kind = SymbolKind::Namespace; Info.Lang = SymbolLanguage::CXX; break; case Decl::NamespaceAlias: - Info.Kind = SymbolKind::CXXNamespaceAlias; + Info.Kind = SymbolKind::NamespaceAlias; Info.Lang = SymbolLanguage::CXX; break; case Decl::CXXConstructor: - Info.Kind = SymbolKind::CXXConstructor; + Info.Kind = SymbolKind::Constructor; Info.Lang = SymbolLanguage::CXX; break; case Decl::CXXDestructor: - Info.Kind = SymbolKind::CXXDestructor; + Info.Kind = SymbolKind::Destructor; Info.Lang = SymbolLanguage::CXX; break; case Decl::CXXConversion: - Info.Kind = SymbolKind::CXXConversionFunction; + Info.Kind = SymbolKind::ConversionFunction; Info.Lang = SymbolLanguage::CXX; break; case Decl::CXXMethod: { const CXXMethodDecl *MD = cast(D); if (MD->isStatic()) - Info.Kind = SymbolKind::CXXStaticMethod; + Info.Kind = SymbolKind::StaticMethod; else - Info.Kind = SymbolKind::CXXInstanceMethod; + Info.Kind = SymbolKind::InstanceMethod; Info.Lang = SymbolLanguage::CXX; break; } case Decl::ClassTemplate: - Info.Kind = SymbolKind::CXXClass; + Info.Kind = SymbolKind::Class; Info.TemplateKind = SymbolCXXTemplateKind::Template; + Info.Lang = SymbolLanguage::CXX; break; case Decl::FunctionTemplate: Info.Kind = SymbolKind::Function; Info.TemplateKind = SymbolCXXTemplateKind::Template; + Info.Lang = SymbolLanguage::CXX; if (const CXXMethodDecl *MD = dyn_cast_or_null( cast(D)->getTemplatedDecl())) { if (isa(MD)) - Info.Kind = SymbolKind::CXXConstructor; + Info.Kind = SymbolKind::Constructor; else if (isa(MD)) - Info.Kind = SymbolKind::CXXDestructor; + Info.Kind = SymbolKind::Destructor; else if (isa(MD)) - Info.Kind = SymbolKind::CXXConversionFunction; + Info.Kind = SymbolKind::ConversionFunction; else { if (MD->isStatic()) - Info.Kind = SymbolKind::CXXStaticMethod; + Info.Kind = SymbolKind::StaticMethod; else - Info.Kind = SymbolKind::CXXInstanceMethod; + Info.Kind = SymbolKind::InstanceMethod; } } break; case Decl::TypeAliasTemplate: - Info.Kind = SymbolKind::CXXTypeAlias; + Info.Kind = SymbolKind::TypeAlias; + Info.Lang = SymbolLanguage::CXX; Info.TemplateKind = SymbolCXXTemplateKind::Template; break; case Decl::TypeAlias: - Info.Kind = SymbolKind::CXXTypeAlias; + Info.Kind = SymbolKind::TypeAlias; Info.Lang = SymbolLanguage::CXX; break; default: @@ -262,33 +265,29 @@ StringRef index::getSymbolKindString(SymbolKind K) { switch (K) { case SymbolKind::Unknown: return ""; case SymbolKind::Module: return "module"; + case SymbolKind::Namespace: return "namespace"; + case SymbolKind::NamespaceAlias: return "namespace-alias"; case SymbolKind::Macro: return "macro"; case SymbolKind::Enum: return "enum"; case SymbolKind::Struct: return "struct"; + case SymbolKind::Class: return "class"; + case SymbolKind::Protocol: return "protocol"; + case SymbolKind::Extension: return "extension"; case SymbolKind::Union: return "union"; - case SymbolKind::Typedef: return "typedef"; + case SymbolKind::TypeAlias: return "type-alias"; case SymbolKind::Function: return "function"; case SymbolKind::Variable: return "variable"; case SymbolKind::Field: return "field"; case SymbolKind::EnumConstant: return "enumerator"; - case SymbolKind::ObjCClass: return "objc-class"; - case SymbolKind::ObjCProtocol: return "objc-protocol"; - case SymbolKind::ObjCCategory: return "objc-category"; - case SymbolKind::ObjCInstanceMethod: return "objc-instance-method"; - case SymbolKind::ObjCClassMethod: return "objc-class-method"; - case SymbolKind::ObjCProperty: return "objc-property"; - case SymbolKind::ObjCIvar: return "objc-ivar"; - case SymbolKind::CXXClass: return "c++-class"; - case SymbolKind::CXXNamespace: return "namespace"; - case SymbolKind::CXXNamespaceAlias: return "namespace-alias"; - case SymbolKind::CXXStaticVariable: return "c++-static-var"; - case SymbolKind::CXXStaticMethod: return "c++-static-method"; - case SymbolKind::CXXInstanceMethod: return "c++-instance-method"; - case SymbolKind::CXXConstructor: return "constructor"; - case SymbolKind::CXXDestructor: return "destructor"; - case SymbolKind::CXXConversionFunction: return "coversion-func"; - case SymbolKind::CXXTypeAlias: return "type-alias"; - case SymbolKind::CXXInterface: return "c++-__interface"; + case SymbolKind::InstanceMethod: return "instance-method"; + case SymbolKind::ClassMethod: return "class-method"; + case SymbolKind::StaticMethod: return "static-method"; + case SymbolKind::InstanceProperty: return "instance-property"; + case SymbolKind::ClassProperty: return "class-property"; + case SymbolKind::StaticProperty: return "static-property"; + case SymbolKind::Constructor: return "constructor"; + case SymbolKind::Destructor: return "destructor"; + case SymbolKind::ConversionFunction: return "coversion-func"; } llvm_unreachable("invalid symbol kind"); } diff --git a/test/Index/Core/index-source.cpp b/test/Index/Core/index-source.cpp index 406f70f389..75c6396da5 100644 --- a/test/Index/Core/index-source.cpp +++ b/test/Index/Core/index-source.cpp @@ -2,7 +2,7 @@ template class TemplCls { -// CHECK: [[@LINE-1]]:7 | c++-class/C++ | TemplCls | c:@ST>1#T@TemplCls | | Def | rel: 0 +// CHECK: [[@LINE-1]]:7 | class/C++ | TemplCls | c:@ST>1#T@TemplCls | | Def | rel: 0 TemplCls(int x); // CHECK: [[@LINE-1]]:3 | constructor/C++ | TemplCls | c:@ST>1#T@TemplCls@F@TemplCls#I# | | Decl,RelChild | rel: 1 // CHECK-NEXT: RelChild | TemplCls | c:@ST>1#T@TemplCls diff --git a/test/Index/Core/index-source.m b/test/Index/Core/index-source.m index ac309c8e69..0869c0ac7e 100644 --- a/test/Index/Core/index-source.m +++ b/test/Index/Core/index-source.m @@ -1,9 +1,9 @@ // RUN: c-index-test core -print-source-symbols -- %s -target x86_64-apple-macosx10.7 | FileCheck %s @interface Base -// CHECK: [[@LINE-1]]:12 | objc-class/ObjC | Base | c:objc(cs)Base | _OBJC_CLASS_$_Base | Decl | rel: 0 +// CHECK: [[@LINE-1]]:12 | class/ObjC | Base | c:objc(cs)Base | _OBJC_CLASS_$_Base | Decl | rel: 0 -(void)meth; -// CHECK: [[@LINE-1]]:1 | objc-instance-method/ObjC | meth | c:objc(cs)Base(im)meth | -[Base meth] | Decl,Dyn,RelChild | rel: 1 +// CHECK: [[@LINE-1]]:1 | instance-method/ObjC | meth | c:objc(cs)Base(im)meth | -[Base meth] | Decl,Dyn,RelChild | rel: 1 // CHECK-NEXT: RelChild | Base | c:objc(cs)Base @end @@ -13,28 +13,28 @@ void goo(Base *b) { // CHECK: [[@LINE+2]]:3 | function/C | foo | c:@F@foo | _foo | Ref,Call,RelCall | rel: 1 // CHECK-NEXT: RelCall | goo | c:@F@goo foo(); - // CHECK: [[@LINE+3]]:6 | objc-instance-method/ObjC | meth | c:objc(cs)Base(im)meth | -[Base meth] | Ref,Call,Dyn,RelRec,RelCall | rel: 2 + // CHECK: [[@LINE+3]]:6 | instance-method/ObjC | meth | c:objc(cs)Base(im)meth | -[Base meth] | Ref,Call,Dyn,RelRec,RelCall | rel: 2 // CHECK-NEXT: RelCall | goo | c:@F@goo // CHECK-NEXT: RelRec | Base | c:objc(cs)Base [b meth]; } -// CHECK: [[@LINE+1]]:11 | objc-protocol/ObjC | Prot1 | c:objc(pl)Prot1 | | Decl | rel: 0 +// CHECK: [[@LINE+1]]:11 | protocol/ObjC | Prot1 | c:objc(pl)Prot1 | | Decl | rel: 0 @protocol Prot1 @end -// CHECK: [[@LINE+3]]:11 | objc-protocol/ObjC | Prot2 | c:objc(pl)Prot2 | | Decl | rel: 0 -// CHECK: [[@LINE+2]]:17 | objc-protocol/ObjC | Prot1 | c:objc(pl)Prot1 | | Ref,RelBase | rel: 1 +// CHECK: [[@LINE+3]]:11 | protocol/ObjC | Prot2 | c:objc(pl)Prot2 | | Decl | rel: 0 +// CHECK: [[@LINE+2]]:17 | protocol/ObjC | Prot1 | c:objc(pl)Prot1 | | Ref,RelBase | rel: 1 // CHECK-NEXT: RelBase | Prot2 | c:objc(pl)Prot2 @protocol Prot2 @end -// CHECK: [[@LINE+7]]:12 | objc-class/ObjC | Sub | c:objc(cs)Sub | _OBJC_CLASS_$_Sub | Decl | rel: 0 -// CHECK: [[@LINE+6]]:18 | objc-class/ObjC | Base | c:objc(cs)Base | _OBJC_CLASS_$_Base | Ref,RelBase | rel: 1 +// CHECK: [[@LINE+7]]:12 | class/ObjC | Sub | c:objc(cs)Sub | _OBJC_CLASS_$_Sub | Decl | rel: 0 +// CHECK: [[@LINE+6]]:18 | class/ObjC | Base | c:objc(cs)Base | _OBJC_CLASS_$_Base | Ref,RelBase | rel: 1 // CHECK-NEXT: RelBase | Sub | c:objc(cs)Sub -// CHECK: [[@LINE+4]]:23 | objc-protocol/ObjC | Prot2 | c:objc(pl)Prot2 | | Ref,RelBase | rel: 1 +// CHECK: [[@LINE+4]]:23 | protocol/ObjC | Prot2 | c:objc(pl)Prot2 | | Ref,RelBase | rel: 1 // CHECK-NEXT: RelBase | Sub | c:objc(cs)Sub -// CHECK: [[@LINE+2]]:30 | objc-protocol/ObjC | Prot1 | c:objc(pl)Prot1 | | Ref,RelBase | rel: 1 +// CHECK: [[@LINE+2]]:30 | protocol/ObjC | Prot1 | c:objc(pl)Prot1 | | Ref,RelBase | rel: 1 // CHECK-NEXT: RelBase | Sub | c:objc(cs)Sub @interface Sub : Base @end @@ -66,8 +66,8 @@ enum { Two, }; -// CHECK: [[@LINE+1]]:13 | typedef/C | jmp_buf | c:index-source.m@T@jmp_buf | | Def | rel: 0 +// CHECK: [[@LINE+1]]:13 | type-alias/C | jmp_buf | c:index-source.m@T@jmp_buf | | Def | rel: 0 typedef int jmp_buf[(18)]; // CHECK: [[@LINE+2]]:12 | function/C | setjmp | c:@F@setjmp | _setjmp | Decl | rel: 0 -// CHECK: [[@LINE+1]]:19 | typedef/C | jmp_buf | c:index-source.m@T@jmp_buf | | Ref | rel: 0 +// CHECK: [[@LINE+1]]:19 | type-alias/C | jmp_buf | c:index-source.m@T@jmp_buf | | Ref | rel: 0 extern int setjmp(jmp_buf); diff --git a/tools/libclang/CXIndexDataConsumer.cpp b/tools/libclang/CXIndexDataConsumer.cpp index 4f89e43fd7..bc19d53aea 100644 --- a/tools/libclang/CXIndexDataConsumer.cpp +++ b/tools/libclang/CXIndexDataConsumer.cpp @@ -1126,7 +1126,7 @@ void CXIndexDataConsumer::translateLoc(SourceLocation Loc, *offset = FileOffset; } -static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K); +static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage L); static CXIdxEntityCXXTemplateKind getEntityKindFromSymbolCXXTemplateKind(SymbolCXXTemplateKind K); static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L); @@ -1143,7 +1143,7 @@ void CXIndexDataConsumer::getEntityInfo(const NamedDecl *D, EntityInfo.IndexCtx = this; SymbolInfo SymInfo = getSymbolInfo(D); - EntityInfo.kind = getEntityKindFromSymbolKind(SymInfo.Kind); + EntityInfo.kind = getEntityKindFromSymbolKind(SymInfo.Kind, SymInfo.Lang); EntityInfo.templateKind = getEntityKindFromSymbolCXXTemplateKind(SymInfo.TemplateKind); EntityInfo.lang = getEntityLangFromSymbolLang(SymInfo.Lang); @@ -1236,40 +1236,50 @@ bool CXIndexDataConsumer::isTemplateImplicitInstantiation(const Decl *D) { return false; } -static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K) { +static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage Lang) { switch (K) { case SymbolKind::Unknown: case SymbolKind::Module: case SymbolKind::Macro: + case SymbolKind::ClassProperty: return CXIdxEntity_Unexposed; case SymbolKind::Enum: return CXIdxEntity_Enum; case SymbolKind::Struct: return CXIdxEntity_Struct; case SymbolKind::Union: return CXIdxEntity_Union; - case SymbolKind::Typedef: return CXIdxEntity_Typedef; + case SymbolKind::TypeAlias: + if (Lang == SymbolLanguage::CXX) + return CXIdxEntity_CXXTypeAlias; + return CXIdxEntity_Typedef; case SymbolKind::Function: return CXIdxEntity_Function; case SymbolKind::Variable: return CXIdxEntity_Variable; - case SymbolKind::Field: return CXIdxEntity_Field; + case SymbolKind::Field: + if (Lang == SymbolLanguage::ObjC) + return CXIdxEntity_ObjCIvar; + return CXIdxEntity_Field; case SymbolKind::EnumConstant: return CXIdxEntity_EnumConstant; - case SymbolKind::ObjCClass: return CXIdxEntity_ObjCClass; - case SymbolKind::ObjCProtocol: return CXIdxEntity_ObjCProtocol; - case SymbolKind::ObjCCategory: return CXIdxEntity_ObjCCategory; - case SymbolKind::ObjCInstanceMethod: return CXIdxEntity_ObjCInstanceMethod; - case SymbolKind::ObjCClassMethod: return CXIdxEntity_ObjCClassMethod; - case SymbolKind::ObjCProperty: return CXIdxEntity_ObjCProperty; - case SymbolKind::ObjCIvar: return CXIdxEntity_ObjCIvar; - case SymbolKind::CXXClass: return CXIdxEntity_CXXClass; - case SymbolKind::CXXNamespace: return CXIdxEntity_CXXNamespace; - case SymbolKind::CXXNamespaceAlias: return CXIdxEntity_CXXNamespaceAlias; - case SymbolKind::CXXStaticVariable: return CXIdxEntity_CXXStaticVariable; - case SymbolKind::CXXStaticMethod: return CXIdxEntity_CXXStaticMethod; - case SymbolKind::CXXInstanceMethod: return CXIdxEntity_CXXInstanceMethod; - case SymbolKind::CXXConstructor: return CXIdxEntity_CXXConstructor; - case SymbolKind::CXXDestructor: return CXIdxEntity_CXXDestructor; - case SymbolKind::CXXConversionFunction: - return CXIdxEntity_CXXConversionFunction; - case SymbolKind::CXXTypeAlias: return CXIdxEntity_CXXTypeAlias; - case SymbolKind::CXXInterface: return CXIdxEntity_CXXInterface; + case SymbolKind::Class: + if (Lang == SymbolLanguage::ObjC) + return CXIdxEntity_ObjCClass; + return CXIdxEntity_CXXClass; + case SymbolKind::Protocol: + if (Lang == SymbolLanguage::ObjC) + return CXIdxEntity_ObjCProtocol; + return CXIdxEntity_CXXInterface; + case SymbolKind::Extension: return CXIdxEntity_ObjCCategory; + case SymbolKind::InstanceMethod: + if (Lang == SymbolLanguage::ObjC) + return CXIdxEntity_ObjCInstanceMethod; + return CXIdxEntity_CXXInstanceMethod; + case SymbolKind::ClassMethod: return CXIdxEntity_ObjCClassMethod; + case SymbolKind::StaticMethod: return CXIdxEntity_CXXStaticMethod; + case SymbolKind::InstanceProperty: return CXIdxEntity_ObjCProperty; + case SymbolKind::StaticProperty: return CXIdxEntity_CXXStaticVariable; + case SymbolKind::Namespace: return CXIdxEntity_CXXNamespace; + case SymbolKind::NamespaceAlias: return CXIdxEntity_CXXNamespaceAlias; + case SymbolKind::Constructor: return CXIdxEntity_CXXConstructor; + case SymbolKind::Destructor: return CXIdxEntity_CXXDestructor; + case SymbolKind::ConversionFunction: return CXIdxEntity_CXXConversionFunction; } llvm_unreachable("invalid symbol kind"); } -- 2.40.0