ObjectiveC migration: complete migrating class

declaration to include list of protocols class
conforms to. 

llvm-svn: 186443
This commit is contained in:
Fariborz Jahanian 2013-07-16 18:58:41 +00:00
parent 0edeabfe43
commit 3eb3159816
3 changed files with 118 additions and 22 deletions

View 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();
std::string ClassString;
SourceLocation EndLoc =
IDecl->getSuperClass() ? IDecl->getSuperClassLoc() : IDecl->getLocation();
// ASTContext &Context = NS.getASTContext();
std::string ClassString = "@interface ";
ClassString += IDecl->getNameAsString();
if (IDecl->getSuperClass()) {
ClassString += " : ";
ClassString += IDecl->getSuperClass()->getNameAsString();
}
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 += ',';
if (Protocols.empty()) {
ClassString = '<';
for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) {
ClassString += ConformingProtocols[i]->getNameAsString();
if (i != (e-1))
ClassString += ',';
ClassString += ", ";
}
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;
}
commit.insertAfterToken(EndLoc, ClassString);
return true;
}

View File

@ -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

View File

@ -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