diff options
-rw-r--r-- | include/clang-c/Index.h | 3 | ||||
-rw-r--r-- | include/clang/Index/IndexSymbol.h | 1 | ||||
-rw-r--r-- | lib/Index/IndexSymbol.cpp | 15 | ||||
-rw-r--r-- | test/Index/Core/external-source-symbol-attr.m | 30 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 1 | ||||
-rw-r--r-- | tools/libclang/CXIndexDataConsumer.cpp | 1 |
6 files changed, 35 insertions, 16 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 1ac2b7f802..9acc9b75bf 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -5600,7 +5600,8 @@ typedef enum { CXIdxEntityLang_None = 0, CXIdxEntityLang_C = 1, CXIdxEntityLang_ObjC = 2, - CXIdxEntityLang_CXX = 3 + CXIdxEntityLang_CXX = 3, + CXIdxEntityLang_Swift = 4 } CXIdxEntityLanguage; /** diff --git a/include/clang/Index/IndexSymbol.h b/include/clang/Index/IndexSymbol.h index bc34938fb4..abb132f9e4 100644 --- a/include/clang/Index/IndexSymbol.h +++ b/include/clang/Index/IndexSymbol.h @@ -59,6 +59,7 @@ enum class SymbolLanguage { C, ObjC, CXX, + Swift, }; /// Language specific sub-kinds. diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp index ea66b70179..0bfa19346b 100644 --- a/lib/Index/IndexSymbol.cpp +++ b/lib/Index/IndexSymbol.cpp @@ -318,6 +318,20 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { if (Info.Properties & (unsigned)SymbolProperty::Generic) Info.Lang = SymbolLanguage::CXX; + auto getExternalSymAttr = [](const Decl *D) -> ExternalSourceSymbolAttr* { + if (auto *attr = D->getAttr<ExternalSourceSymbolAttr>()) + return attr; + if (auto *dcd = dyn_cast<Decl>(D->getDeclContext())) { + if (auto *attr = dcd->getAttr<ExternalSourceSymbolAttr>()) + return attr; + } + return nullptr; + }; + if (auto *attr = getExternalSymAttr(D)) { + if (attr->getLanguage() == "Swift") + Info.Lang = SymbolLanguage::Swift; + } + return Info; } @@ -458,6 +472,7 @@ StringRef index::getSymbolLanguageString(SymbolLanguage K) { case SymbolLanguage::C: return "C"; case SymbolLanguage::ObjC: return "ObjC"; case SymbolLanguage::CXX: return "C++"; + case SymbolLanguage::Swift: return "Swift"; } llvm_unreachable("invalid symbol language kind"); } diff --git a/test/Index/Core/external-source-symbol-attr.m b/test/Index/Core/external-source-symbol-attr.m index b0e9c159cd..49a075fc74 100644 --- a/test/Index/Core/external-source-symbol-attr.m +++ b/test/Index/Core/external-source-symbol-attr.m @@ -14,20 +14,20 @@ GEN_DECL("some_module") EXT_DECL("some_module") @interface I2 -// CHECK: [[@LINE-1]]:12 | class/ObjC | I2 | c:@M@some_module@objc(cs)I2 | {{.*}} | Decl | rel: 0 +// CHECK: [[@LINE-1]]:12 | class/Swift | I2 | c:@M@some_module@objc(cs)I2 | {{.*}} | Decl | rel: 0 -(void)method; -// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | method | c:@M@some_module@objc(cs)I2(im)method | -[I2 method] | Decl,Dyn,RelChild | rel: 1 +// CHECK: [[@LINE-1]]:8 | instance-method/Swift | method | c:@M@some_module@objc(cs)I2(im)method | -[I2 method] | Decl,Dyn,RelChild | rel: 1 @end void test1(I1 *o) { -// CHECK: [[@LINE-1]]:12 | class/ObjC | I1 | c:@M@some_module@objc(cs)I1 | +// CHECK: [[@LINE-1]]:12 | class/Swift | I1 | c:@M@some_module@objc(cs)I1 | [o method]; - // CHECK: [[@LINE-1]]:6 | instance-method/ObjC | method | c:@M@some_module@objc(cs)I1(im)method | + // CHECK: [[@LINE-1]]:6 | instance-method/Swift | method | c:@M@some_module@objc(cs)I1(im)method | } EXT_DECL("some_module") @protocol ExtProt -// CHECK: [[@LINE-1]]:11 | protocol/ObjC | ExtProt | c:@M@some_module@objc(pl)ExtProt | +// CHECK: [[@LINE-1]]:11 | protocol/Swift | ExtProt | c:@M@some_module@objc(pl)ExtProt | @end @interface I1(cat) @@ -38,9 +38,9 @@ EXT_DECL("some_module") EXT_DECL("cat_module") @interface I1(cat2) -// CHECK: [[@LINE-1]]:15 | extension/ObjC | cat2 | c:@CM@cat_module@some_module@objc(cy)I1@cat2 | +// CHECK: [[@LINE-1]]:15 | extension/Swift | cat2 | c:@CM@cat_module@some_module@objc(cy)I1@cat2 | -(void)cat_method2; -// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | cat_method2 | c:@CM@cat_module@some_module@objc(cs)I1(im)cat_method2 +// CHECK: [[@LINE-1]]:8 | instance-method/Swift | cat_method2 | c:@CM@cat_module@some_module@objc(cs)I1(im)cat_method2 @end #define NS_ENUM(_name, _type) enum _name:_type _name; enum _name : _type @@ -75,17 +75,17 @@ typedef NS_ENUM(SomeEnum, int) { #pragma clang attribute pop void test2(I3 *i3, id<ExtProt2> prot2, SomeEnum some) { - // CHECK: [[@LINE-1]]:12 | class/ObjC | I3 | c:@M@modname@objc(cs)I3 | - // CHECK: [[@LINE-2]]:23 | protocol/ObjC | ExtProt2 | c:@M@modname@objc(pl)ExtProt2 | - // CHECK: [[@LINE-3]]:40 | enum/C | SomeEnum | c:@M@modname@E@SomeEnum | + // CHECK: [[@LINE-1]]:12 | class/Swift | I3 | c:@M@modname@objc(cs)I3 | + // CHECK: [[@LINE-2]]:23 | protocol/Swift | ExtProt2 | c:@M@modname@objc(pl)ExtProt2 | + // CHECK: [[@LINE-3]]:40 | enum/Swift | SomeEnum | c:@M@modname@E@SomeEnum | [i3 meth]; - // CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth | c:@M@modname@objc(cs)I3(im)meth | + // CHECK: [[@LINE-1]]:7 | instance-method/Swift | meth | c:@M@modname@objc(cs)I3(im)meth | [i3 meth2]; - // CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth2 | c:@CM@modname@objc(cs)I3(im)meth2 | + // CHECK: [[@LINE-1]]:7 | instance-method/Swift | meth2 | c:@CM@modname@objc(cs)I3(im)meth2 | [prot2 meth]; - // CHECK: [[@LINE-1]]:10 | instance-method/ObjC | meth | c:@M@modname@objc(pl)ExtProt2(im)meth | + // CHECK: [[@LINE-1]]:10 | instance-method/Swift | meth | c:@M@modname@objc(pl)ExtProt2(im)meth | some = SomeEnumFirst; - // CHECK: [[@LINE-1]]:10 | enumerator/C | SomeEnumFirst | c:@M@modname@E@SomeEnum@SomeEnumFirst | + // CHECK: [[@LINE-1]]:10 | enumerator/Swift | SomeEnumFirst | c:@M@modname@E@SomeEnum@SomeEnumFirst | } #pragma clang attribute PUSH_GEN_DECL("other_mod_for_cat") @@ -96,5 +96,5 @@ void test2(I3 *i3, id<ExtProt2> prot2, SomeEnum some) { void test3(I3 *i3) { [i3 meth_other_mod]; - // CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth_other_mod | c:@CM@other_mod_for_cat@modname@objc(cs)I3(im)meth_other_mod | + // CHECK: [[@LINE-1]]:7 | instance-method/Swift | meth_other_mod | c:@CM@other_mod_for_cat@modname@objc(cs)I3(im)meth_other_mod | } diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 0dde4c7cc7..e8763ffc00 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -3014,6 +3014,7 @@ static const char *getEntityLanguageString(CXIdxEntityLanguage kind) { case CXIdxEntityLang_C: return "C"; case CXIdxEntityLang_ObjC: return "ObjC"; case CXIdxEntityLang_CXX: return "C++"; + case CXIdxEntityLang_Swift: return "Swift"; } assert(0 && "Garbage language kind"); return 0; diff --git a/tools/libclang/CXIndexDataConsumer.cpp b/tools/libclang/CXIndexDataConsumer.cpp index 5d9776be3b..9cd5ff4f50 100644 --- a/tools/libclang/CXIndexDataConsumer.cpp +++ b/tools/libclang/CXIndexDataConsumer.cpp @@ -1315,6 +1315,7 @@ static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L) { case SymbolLanguage::C: return CXIdxEntityLang_C; case SymbolLanguage::ObjC: return CXIdxEntityLang_ObjC; case SymbolLanguage::CXX: return CXIdxEntityLang_CXX; + case SymbolLanguage::Swift: return CXIdxEntityLang_Swift; } llvm_unreachable("invalid symbol language"); } |