[clang] 4048aad - [clang][ExtractAPI] Fix declaration fragments for ObjC methods

Zixu Wang via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 7 10:23:35 PDT 2022


Author: Zixu Wang
Date: 2022-04-07T10:22:41-07:00
New Revision: 4048aad85a843d2b15cb8e60b2ea37f148b7b770

URL: https://github.com/llvm/llvm-project/commit/4048aad85a843d2b15cb8e60b2ea37f148b7b770
DIFF: https://github.com/llvm/llvm-project/commit/4048aad85a843d2b15cb8e60b2ea37f148b7b770.diff

LOG: [clang][ExtractAPI] Fix declaration fragments for ObjC methods

Objective-C methods selector parts should be considered as identifiers.

Depends on D123259

Differential Revision: https://reviews.llvm.org/D123261

Added: 
    

Modified: 
    clang/lib/ExtractAPI/DeclarationFragments.cpp
    clang/test/ExtractAPI/objc_category.m
    clang/test/ExtractAPI/objc_interface.m

Removed: 
    


################################################################################
diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index a569ff9168bc3..75d360a3ba167 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -593,20 +593,21 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForObjCMethod(
 
   // For Objective-C methods that take arguments, build the selector slots.
   for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
-    Fragments.appendSpace()
-        .append(Selector.getNameForSlot(i),
-                // The first slot is the name of the method, record as an
-                // identifier, otherwise as exteranl parameters.
-                i == 0 ? DeclarationFragments::FragmentKind::Identifier
-                       : DeclarationFragments::FragmentKind::ExternalParam)
-        .append(":", DeclarationFragments::FragmentKind::Text);
+    // Objective-C method selector parts are considered as identifiers instead
+    // of "external parameters" as in Swift. This is because Objective-C method
+    // symbols are referenced with the entire selector, instead of just the
+    // method name in Swift.
+    SmallString<32> ParamID(Selector.getNameForSlot(i));
+    ParamID.append(":");
+    Fragments.appendSpace().append(
+        ParamID, DeclarationFragments::FragmentKind::Identifier);
 
     // Build the internal parameter.
     const ParmVarDecl *Param = Method->getParamDecl(i);
     Fragments.append(getFragmentsForParam(Param));
   }
 
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForObjCProperty(

diff  --git a/clang/test/ExtractAPI/objc_category.m b/clang/test/ExtractAPI/objc_category.m
index 2416e3049bd55..20eefdfbb00e5 100644
--- a/clang/test/ExtractAPI/objc_category.m
+++ b/clang/test/ExtractAPI/objc_category.m
@@ -136,6 +136,10 @@ + (void)ClassMethod;
         {
           "kind": "identifier",
           "spelling": "InstanceMethod"
+        },
+        {
+          "kind": "text",
+          "spelling": ";"
         }
       ],
       "identifier": {
@@ -190,6 +194,10 @@ + (void)ClassMethod;
         {
           "kind": "identifier",
           "spelling": "ClassMethod"
+        },
+        {
+          "kind": "text",
+          "spelling": ";"
         }
       ],
       "identifier": {

diff  --git a/clang/test/ExtractAPI/objc_interface.m b/clang/test/ExtractAPI/objc_interface.m
index a74a53c8db2cf..5ca6404683987 100644
--- a/clang/test/ExtractAPI/objc_interface.m
+++ b/clang/test/ExtractAPI/objc_interface.m
@@ -146,11 +146,7 @@ - (char)getIvar;
         },
         {
           "kind": "identifier",
-          "spelling": "getWithProperty"
-        },
-        {
-          "kind": "text",
-          "spelling": ":"
+          "spelling": "getWithProperty:"
         },
         {
           "kind": "text",
@@ -168,6 +164,10 @@ - (char)getIvar;
         {
           "kind": "internalParam",
           "spelling": "Property"
+        },
+        {
+          "kind": "text",
+          "spelling": ";"
         }
       ],
       "identifier": {
@@ -403,6 +403,10 @@ - (char)getIvar;
         {
           "kind": "identifier",
           "spelling": "getIvar"
+        },
+        {
+          "kind": "text",
+          "spelling": ";"
         }
       ],
       "identifier": {


        


More information about the cfe-commits mailing list