r186443 - ObjectiveC migration: complete migrating class

Fariborz Jahanian fjahanian at apple.com
Tue Jul 16 11:58:41 PDT 2013


Author: fjahanian
Date: Tue Jul 16 13:58:41 2013
New Revision: 186443

URL: http://llvm.org/viewvc/llvm-project?rev=186443&view=rev
Log:
ObjectiveC migration: complete migrating class
declaration to include list of protocols class
conforms to. 

Added:
    cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m
    cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result
Modified:
    cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp

Modified: cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp?rev=186443&r1=186442&r2=186443&view=diff
==============================================================================
--- cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp (original)
+++ cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp Tue Jul 16 13:58:41 2013
@@ -406,31 +406,31 @@ bool edit::rewriteToObjCInterfaceDecl(co
                   llvm::SmallVectorImpl<ObjCProtocolDecl*> &ConformingProtocols,
                   const NSAPI &NS, Commit &commit) {
   const ObjCList<ObjCProtocolDecl> &Protocols = IDecl->getReferencedProtocols();
-    
-  // ASTContext &Context = NS.getASTContext();
-  std::string ClassString = "@interface ";
-  ClassString += IDecl->getNameAsString();
+  std::string ClassString;
+  SourceLocation EndLoc =
+    IDecl->getSuperClass() ? IDecl->getSuperClassLoc() : IDecl->getLocation();
   
-  if (IDecl->getSuperClass()) {
-    ClassString += " : ";
-    ClassString += IDecl->getSuperClass()->getNameAsString();
+  if (Protocols.empty()) {
+    ClassString = '<';
+    for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) {
+      ClassString += ConformingProtocols[i]->getNameAsString();
+      if (i != (e-1))
+        ClassString += ", ";
+    }
+    ClassString += "> ";
   }
-  if (Protocols.empty())
-    ClassString += '<';
-  
-  for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
-       E = Protocols.end(); I != E; ++I) {
-    ClassString += (I == Protocols.begin() ? '<' : ',');
-    ClassString += (*I)->getNameAsString();
-  }
-  if (!Protocols.empty())
-    ClassString += ',';
-  for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) {
-    ClassString += ConformingProtocols[i]->getNameAsString();
-    if (i != (e-1))
-      ClassString += ',';
+  else {
+    ClassString = ", ";
+    for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) {
+      ClassString += ConformingProtocols[i]->getNameAsString();
+      if (i != (e-1))
+        ClassString += ", ";
+    }
+    ObjCInterfaceDecl::protocol_loc_iterator PL = IDecl->protocol_loc_end() - 1;
+    EndLoc = *PL;
   }
-  ClassString += "> ";
+  
+  commit.insertAfterToken(EndLoc, ClassString);
   return true;
 }
 

Added: cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m?rev=186443&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m (added)
+++ cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m Tue Jul 16 13:58:41 2013
@@ -0,0 +1,48 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -objcmt-migrate-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties -triple x86_64-apple-darwin11
+// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
+
+ at interface NSObject @end
+
+ at protocol P
+- (id) Meth1: (double) arg;
+ at end
+
+ at interface Test1  // Test for no super class and no protocol list
+ at end
+
+ at implementation Test1
+- (id) Meth1: (double) arg { return 0; }
+ at end
+
+ at protocol P1 @end
+ at protocol P2 @end
+
+ at interface Test2 <P1, P2>  // Test for no super class and with protocol list
+{
+  id IVAR1;
+  id IVAR2;
+}
+ at end
+
+ at implementation Test2
+- (id) Meth1: (double) arg { return 0; }
+ at end
+
+ at interface Test3 : NSObject  { // Test for Super class and no  protocol list
+  id IV1;
+}
+ at end
+
+ at implementation Test3
+- (id) Meth1: (double) arg { return 0; }
+ at end
+
+ at interface Test4 : NSObject <P1, P2> // Test for Super class and protocol list
+ at end
+
+ at implementation Test4
+- (id) Meth1: (double) arg { return 0; }
+ at end
+

Added: cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result?rev=186443&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result (added)
+++ cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result Tue Jul 16 13:58:41 2013
@@ -0,0 +1,48 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -objcmt-migrate-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties -triple x86_64-apple-darwin11
+// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
+
+ at interface NSObject @end
+
+ at protocol P
+- (id) Meth1: (double) arg;
+ at end
+
+ at interface Test1<P>   // Test for no super class and no protocol list
+ at end
+
+ at implementation Test1
+- (id) Meth1: (double) arg { return 0; }
+ at end
+
+ at protocol P1 @end
+ at protocol P2 @end
+
+ at interface Test2 <P1, P2, P>  // Test for no super class and with protocol list
+{
+  id IVAR1;
+  id IVAR2;
+}
+ at end
+
+ at implementation Test2
+- (id) Meth1: (double) arg { return 0; }
+ at end
+
+ at interface Test3 : NSObject<P>   { // Test for Super class and no  protocol list
+  id IV1;
+}
+ at end
+
+ at implementation Test3
+- (id) Meth1: (double) arg { return 0; }
+ at end
+
+ at interface Test4 : NSObject <P1, P2, P> // Test for Super class and protocol list
+ at end
+
+ at implementation Test4
+- (id) Meth1: (double) arg { return 0; }
+ at end
+





More information about the cfe-commits mailing list