From: Fariborz Jahanian Date: Tue, 17 Sep 2013 19:00:30 +0000 (+0000) Subject: ObjectiveC migrator. Infer property in categories X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c4759149c80464ca26dcc90c756f439e6640684;p=clang ObjectiveC migrator. Infer property in categories declared as getter with or without setter method. // rdar://15010020 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190878 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 35739f1f21..b859c0b19d 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -43,7 +43,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer { }; void migrateDecl(Decl *D); - void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCInterfaceDecl *D); + void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCContainerDecl *D); void migrateProtocolConformance(ASTContext &Ctx, const ObjCImplementationDecl *ImpDecl); void migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl, @@ -51,7 +51,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer { void migrateMethods(ASTContext &Ctx, ObjCContainerDecl *CDecl); void migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl, ObjCMethodDecl *OM); - bool migrateProperty(ASTContext &Ctx, ObjCInterfaceDecl *D, ObjCMethodDecl *OM); + bool migrateProperty(ASTContext &Ctx, ObjCContainerDecl *D, ObjCMethodDecl *OM); void migrateNsReturnsInnerPointer(ASTContext &Ctx, ObjCMethodDecl *OM); void migrateFactoryMethod(ASTContext &Ctx, ObjCContainerDecl *CDecl, ObjCMethodDecl *OM, @@ -339,7 +339,7 @@ static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter, } void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx, - ObjCInterfaceDecl *D) { + ObjCContainerDecl *D) { for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end(); M != MEnd; ++M) { ObjCMethodDecl *Method = (*M); @@ -716,7 +716,7 @@ static bool TypeIsInnerPointer(QualType T) { } bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx, - ObjCInterfaceDecl *D, + ObjCContainerDecl *D, ObjCMethodDecl *Method) { if (Method->isPropertyAccessor() || !Method->isInstanceMethod() || Method->param_size() != 0) @@ -735,7 +735,7 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx, SelectorTable::constructSetterSelector(PP.getIdentifierTable(), PP.getSelectorTable(), getterName); - ObjCMethodDecl *SetterMethod = D->lookupMethod(SetterSelector, true); + ObjCMethodDecl *SetterMethod = D->getInstanceMethod(SetterSelector); unsigned LengthOfPrefix = 0; if (!SetterMethod) { // try a different naming convention for getter: isXxxxx @@ -755,7 +755,7 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx, SelectorTable::constructSetterSelector(PP.getIdentifierTable(), PP.getSelectorTable(), getterName); - SetterMethod = D->lookupMethod(SetterSelector, true); + SetterMethod = D->getInstanceMethod(SetterSelector); } } } @@ -1237,6 +1237,8 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { if (ObjCInterfaceDecl *CDecl = dyn_cast(*D)) migrateObjCInterfaceDecl(Ctx, CDecl); + if (ObjCCategoryDecl *CatDecl = dyn_cast(*D)) + migrateObjCInterfaceDecl(Ctx, CatDecl); else if (ObjCProtocolDecl *PDecl = dyn_cast(*D)) ObjCProtocolDecls.insert(PDecl); else if (const ObjCImplementationDecl *ImpDecl = diff --git a/test/ARCMT/objcmt-property.m b/test/ARCMT/objcmt-property.m index 60346d7631..9ddd9edb9b 100644 --- a/test/ARCMT/objcmt-property.m +++ b/test/ARCMT/objcmt-property.m @@ -115,3 +115,46 @@ typedef char BOOL; @end +@interface NSInvocation(CAT) +- (id)target; +- (void)setTarget:(id)target; + +- (id) dataSource; + +- (id)xxxdelegateYYY; +- (void)setXxxdelegateYYY:(id)delegate; + +- (void)setDataSource:(id)source; + +- (id)MYtarget; +- (void)setMYtarget: (id)target; + +- (id)targetX; +- (void)setTargetX: (id)t; + +- (int)value; +- (void)setValue: (int)val; + +-(BOOL) isContinuous; +-(void) setContinuous:(BOOL)value; + +- (id) isAnObject; +- (void)setAnObject : (id) object; + +- (BOOL) isinValid; +- (void) setInValid : (BOOL) arg; + +- (void) Nothing; +- (int) Length; +- (id) object; ++ (double) D; + +- (BOOL)is3bar; // watch out +- (NSString *)get3foo; // watch out + +- (BOOL) getM; +- (BOOL) getMA; +- (BOOL) getALL; +- (BOOL) getMANY; +- (BOOL) getSome; +@end diff --git a/test/ARCMT/objcmt-property.m.result b/test/ARCMT/objcmt-property.m.result index 7066a50a60..eff89294cf 100644 --- a/test/ARCMT/objcmt-property.m.result +++ b/test/ARCMT/objcmt-property.m.result @@ -115,3 +115,46 @@ typedef char BOOL; @end +@interface NSInvocation(CAT) +@property(nonatomic, unsafe_unretained) id target; + + +@property(nonatomic, unsafe_unretained) id dataSource; + +@property(nonatomic, unsafe_unretained) id xxxdelegateYYY; + + + + +@property(nonatomic, retain) id MYtarget; + + +@property(nonatomic, retain) id targetX; + + +@property(nonatomic) int value; + + +@property(nonatomic, getter=isContinuous) BOOL continuous; + + +@property(nonatomic, readonly) id isAnObject; +- (void)setAnObject : (id) object; + +@property(nonatomic, getter=isinValid, readonly) BOOL inValid; +- (void) setInValid : (BOOL) arg; + +- (void) Nothing; +@property(nonatomic, readonly) int Length; +@property(nonatomic, readonly) id object; ++ (double) D; + +- (BOOL)is3bar; // watch out +- (NSString *)get3foo; // watch out + +@property(nonatomic, getter=getM, readonly) BOOL m; +@property(nonatomic, getter=getMA, readonly) BOOL MA; +@property(nonatomic, getter=getALL, readonly) BOOL ALL; +@property(nonatomic, getter=getMANY, readonly) BOOL MANY; +@property(nonatomic, getter=getSome, readonly) BOOL some; +@end