r301183 - [index] If the 'external_source_symbol' attribute indicates 'Swift' as the language then report it accordingly

Argyrios Kyrtzidis via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 24 07:52:00 PDT 2017


Author: akirtzidis
Date: Mon Apr 24 09:52:00 2017
New Revision: 301183

URL: http://llvm.org/viewvc/llvm-project?rev=301183&view=rev
Log:
[index] If the 'external_source_symbol' attribute indicates 'Swift' as the language then report it accordingly

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/include/clang/Index/IndexSymbol.h
    cfe/trunk/lib/Index/IndexSymbol.cpp
    cfe/trunk/test/Index/Core/external-source-symbol-attr.m
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=301183&r1=301182&r2=301183&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Mon Apr 24 09:52:00 2017
@@ -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;
 
 /**

Modified: cfe/trunk/include/clang/Index/IndexSymbol.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=301183&r1=301182&r2=301183&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/IndexSymbol.h (original)
+++ cfe/trunk/include/clang/Index/IndexSymbol.h Mon Apr 24 09:52:00 2017
@@ -59,6 +59,7 @@ enum class SymbolLanguage {
   C,
   ObjC,
   CXX,
+  Swift,
 };
 
 /// Language specific sub-kinds.

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=301183&r1=301182&r2=301183&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Mon Apr 24 09:52:00 2017
@@ -318,6 +318,20 @@ SymbolInfo index::getSymbolInfo(const De
   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
   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");
 }

Modified: cfe/trunk/test/Index/Core/external-source-symbol-attr.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/external-source-symbol-attr.m?rev=301183&r1=301182&r2=301183&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/external-source-symbol-attr.m (original)
+++ cfe/trunk/test/Index/Core/external-source-symbol-attr.m Mon Apr 24 09:52:00 2017
@@ -14,20 +14,20 @@ GEN_DECL("some_module")
 
 EXT_DECL("some_module")
 @interface I2
-// CHECK: [[@LINE-1]]:12 | class/ObjC | I2 | c:@M at some_module@objc(cs)I2 | {{.*}} | Decl | rel: 0
+// CHECK: [[@LINE-1]]:12 | class/Swift | I2 | c:@M at some_module@objc(cs)I2 | {{.*}} | Decl | rel: 0
 -(void)method;
-// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | method | c:@M at some_module@objc(cs)I2(im)method | -[I2 method] | Decl,Dyn,RelChild | rel: 1
+// CHECK: [[@LINE-1]]:8 | instance-method/Swift | method | c:@M at 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 at some_module@objc(cs)I1 |
+// CHECK: [[@LINE-1]]:12 | class/Swift | I1 | c:@M at some_module@objc(cs)I1 |
   [o method];
-  // CHECK: [[@LINE-1]]:6 | instance-method/ObjC | method | c:@M at some_module@objc(cs)I1(im)method |
+  // CHECK: [[@LINE-1]]:6 | instance-method/Swift | method | c:@M at some_module@objc(cs)I1(im)method |
 }
 
 EXT_DECL("some_module")
 @protocol ExtProt
-// CHECK: [[@LINE-1]]:11 | protocol/ObjC | ExtProt | c:@M at some_module@objc(pl)ExtProt |
+// CHECK: [[@LINE-1]]:11 | protocol/Swift | ExtProt | c:@M at 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 at cat_module@some_module at objc(cy)I1 at cat2 |
+// CHECK: [[@LINE-1]]:15 | extension/Swift | cat2 | c:@CM at cat_module@some_module at objc(cy)I1 at cat2 |
 -(void)cat_method2;
-// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | cat_method2 | c:@CM at cat_module@some_module at objc(cs)I1(im)cat_method2
+// CHECK: [[@LINE-1]]:8 | instance-method/Swift | cat_method2 | c:@CM at cat_module@some_module at 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 at modname@objc(cs)I3 |
-  // CHECK: [[@LINE-2]]:23 | protocol/ObjC | ExtProt2 | c:@M at modname@objc(pl)ExtProt2 |
-  // CHECK: [[@LINE-3]]:40 | enum/C | SomeEnum | c:@M at modname@E at SomeEnum |
+  // CHECK: [[@LINE-1]]:12 | class/Swift | I3 | c:@M at modname@objc(cs)I3 |
+  // CHECK: [[@LINE-2]]:23 | protocol/Swift | ExtProt2 | c:@M at modname@objc(pl)ExtProt2 |
+  // CHECK: [[@LINE-3]]:40 | enum/Swift | SomeEnum | c:@M at modname@E at SomeEnum |
   [i3 meth];
-  // CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth | c:@M at modname@objc(cs)I3(im)meth |
+  // CHECK: [[@LINE-1]]:7 | instance-method/Swift | meth | c:@M at modname@objc(cs)I3(im)meth |
   [i3 meth2];
-  // CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth2 | c:@CM at modname@objc(cs)I3(im)meth2 |
+  // CHECK: [[@LINE-1]]:7 | instance-method/Swift | meth2 | c:@CM at modname@objc(cs)I3(im)meth2 |
   [prot2 meth];
-  // CHECK: [[@LINE-1]]:10 | instance-method/ObjC | meth | c:@M at modname@objc(pl)ExtProt2(im)meth |
+  // CHECK: [[@LINE-1]]:10 | instance-method/Swift | meth | c:@M at modname@objc(pl)ExtProt2(im)meth |
   some = SomeEnumFirst;
-  // CHECK: [[@LINE-1]]:10 | enumerator/C | SomeEnumFirst | c:@M at modname@E at SomeEnum@SomeEnumFirst |
+  // CHECK: [[@LINE-1]]:10 | enumerator/Swift | SomeEnumFirst | c:@M at modname@E at SomeEnum@SomeEnumFirst |
 }
 
 #pragma clang attribute PUSH_GEN_DECL("other_mod_for_cat")
@@ -96,5 +96,5 @@ void test2(I3 *i3, id<ExtProt2> prot2, S
 
 void test3(I3 *i3) {
   [i3 meth_other_mod];
-  // CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth_other_mod | c:@CM at other_mod_for_cat@modname at objc(cs)I3(im)meth_other_mod |
+  // CHECK: [[@LINE-1]]:7 | instance-method/Swift | meth_other_mod | c:@CM at other_mod_for_cat@modname at objc(cs)I3(im)meth_other_mod |
 }

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=301183&r1=301182&r2=301183&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Apr 24 09:52:00 2017
@@ -3014,6 +3014,7 @@ static const char *getEntityLanguageStri
   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;

Modified: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp?rev=301183&r1=301182&r2=301183&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp (original)
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp Mon Apr 24 09:52:00 2017
@@ -1315,6 +1315,7 @@ static CXIdxEntityLanguage getEntityLang
   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");
 }




More information about the cfe-commits mailing list