]> granicus.if.org Git - clang/commitdiff
ObjectiveC migration: complete migrating class
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 16 Jul 2013 18:58:41 +0000 (18:58 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 16 Jul 2013 18:58:41 +0000 (18:58 +0000)
declaration to include list of protocols class
conforms to.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186443 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Edit/RewriteObjCFoundationAPI.cpp
test/ARCMT/objcmt-protocol-conformance.m [new file with mode: 0644]
test/ARCMT/objcmt-protocol-conformance.m.result [new file with mode: 0644]

index fd9c16ee6a09c5878072c7bbc9a8a43d88d004c0..30a9f522b2f40df5d529372109c5d63b7a1603e6 100644 (file)
@@ -406,31 +406,31 @@ bool edit::rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl,
                   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();
-  
-  if (IDecl->getSuperClass()) {
-    ClassString += " : ";
-    ClassString += IDecl->getSuperClass()->getNameAsString();
-  }
-  if (Protocols.empty())
-    ClassString += '<';
+  std::string ClassString;
+  SourceLocation EndLoc =
+    IDecl->getSuperClass() ? IDecl->getSuperClassLoc() : IDecl->getLocation();
   
-  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 += ", ";
+    }
+    ClassString += "> ";
   }
-  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;
 }
 
diff --git a/test/ARCMT/objcmt-protocol-conformance.m b/test/ARCMT/objcmt-protocol-conformance.m
new file mode 100644 (file)
index 0000000..2ad8a65
--- /dev/null
@@ -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
+
+@interface NSObject @end
+
+@protocol P
+- (id) Meth1: (double) arg;
+@end
+
+@interface Test1  // Test for no super class and no protocol list
+@end
+
+@implementation Test1
+- (id) Meth1: (double) arg { return 0; }
+@end
+
+@protocol P1 @end
+@protocol P2 @end
+
+@interface Test2 <P1, P2>  // Test for no super class and with protocol list
+{
+  id IVAR1;
+  id IVAR2;
+}
+@end
+
+@implementation Test2
+- (id) Meth1: (double) arg { return 0; }
+@end
+
+@interface Test3 : NSObject  { // Test for Super class and no  protocol list
+  id IV1;
+}
+@end
+
+@implementation Test3
+- (id) Meth1: (double) arg { return 0; }
+@end
+
+@interface Test4 : NSObject <P1, P2> // Test for Super class and protocol list
+@end
+
+@implementation Test4
+- (id) Meth1: (double) arg { return 0; }
+@end
+
diff --git a/test/ARCMT/objcmt-protocol-conformance.m.result b/test/ARCMT/objcmt-protocol-conformance.m.result
new file mode 100644 (file)
index 0000000..71fa3b1
--- /dev/null
@@ -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
+
+@interface NSObject @end
+
+@protocol P
+- (id) Meth1: (double) arg;
+@end
+
+@interface Test1<P>   // Test for no super class and no protocol list
+@end
+
+@implementation Test1
+- (id) Meth1: (double) arg { return 0; }
+@end
+
+@protocol P1 @end
+@protocol P2 @end
+
+@interface Test2 <P1, P2, P>  // Test for no super class and with protocol list
+{
+  id IVAR1;
+  id IVAR2;
+}
+@end
+
+@implementation Test2
+- (id) Meth1: (double) arg { return 0; }
+@end
+
+@interface Test3 : NSObject<P>   { // Test for Super class and no  protocol list
+  id IV1;
+}
+@end
+
+@implementation Test3
+- (id) Meth1: (double) arg { return 0; }
+@end
+
+@interface Test4 : NSObject <P1, P2, P> // Test for Super class and protocol list
+@end
+
+@implementation Test4
+- (id) Meth1: (double) arg { return 0; }
+@end
+