From e91b1b98f2359816dbaab4b5af70e02a242b730c Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 16 Jul 2013 18:58:41 +0000 Subject: [PATCH] ObjectiveC migration: complete migrating class 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 | 44 ++++++++--------- test/ARCMT/objcmt-protocol-conformance.m | 48 +++++++++++++++++++ .../objcmt-protocol-conformance.m.result | 48 +++++++++++++++++++ 3 files changed, 118 insertions(+), 22 deletions(-) create mode 100644 test/ARCMT/objcmt-protocol-conformance.m create mode 100644 test/ARCMT/objcmt-protocol-conformance.m.result diff --git a/lib/Edit/RewriteObjCFoundationAPI.cpp b/lib/Edit/RewriteObjCFoundationAPI.cpp index fd9c16ee6a..30a9f522b2 100644 --- a/lib/Edit/RewriteObjCFoundationAPI.cpp +++ b/lib/Edit/RewriteObjCFoundationAPI.cpp @@ -406,31 +406,31 @@ bool edit::rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl, llvm::SmallVectorImpl &ConformingProtocols, const NSAPI &NS, Commit &commit) { const ObjCList &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::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 index 0000000000..2ad8a659fa --- /dev/null +++ b/test/ARCMT/objcmt-protocol-conformance.m @@ -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 // 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 // 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 index 0000000000..71fa3b1b06 --- /dev/null +++ b/test/ARCMT/objcmt-protocol-conformance.m.result @@ -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 // 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 // Test for Super class and protocol list +@end + +@implementation Test4 +- (id) Meth1: (double) arg { return 0; } +@end + -- 2.40.0