From c78f684c8e300414956bc1566957a17a48da2fc8 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Sat, 11 Dec 2010 18:39:37 +0000 Subject: [PATCH] Enhance my implementation of //rdar ://8747333 in r121597 to allow for declaration of property setter/getter in forward class extensions and also skip over propeties which are @dynamic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121617 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclObjC.cpp | 51 +++++++++++++-------- test/SemaObjC/property-in-class-extension.m | 13 +++++- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index a7014f6755..f29a01eb45 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1525,25 +1525,6 @@ void Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, if (C->IsClassExtension()) { ObjCInterfaceDecl *CCPrimary = C->getClassInterface(); DiagnoseClassExtensionDupMethods(C, CCPrimary); - for (ObjCContainerDecl::prop_iterator I = C->prop_begin(), - E = C->prop_end(); I != E; ++I) { - // Any property declared in a class extension might have user - // declared setter or getter in current class extension or one - // of the other class extensions. Mark them as synthesized as - // property will be synthesized when property with same name is - // seen in the @implementation. - for (const ObjCCategoryDecl *ClsExtDecl = - CCPrimary->getFirstClassExtension(); - ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension()) { - if (ObjCMethodDecl *GetterMethod = - ClsExtDecl->getInstanceMethod((*I)->getGetterName())) - GetterMethod->setSynthesized(true); - if (!(*I)->isReadOnly()) - if (ObjCMethodDecl *SetterMethod = - ClsExtDecl->getInstanceMethod((*I)->getSetterName())) - SetterMethod->setSynthesized(true); - } - } } } if (ObjCContainerDecl *CDecl = dyn_cast(ClassDecl)) { @@ -1560,6 +1541,38 @@ void Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, if (ObjCImplementationDecl *IC=dyn_cast(ClassDecl)) { IC->setAtEndRange(AtEnd); if (ObjCInterfaceDecl* IDecl = IC->getClassInterface()) { + // Any property declared in a class extension might have user + // declared setter or getter in current class extension or one + // of the other class extensions. Mark them as synthesized as + // property will be synthesized when property with same name is + // seen in the @implementation. + for (const ObjCCategoryDecl *ClsExtDecl = + IDecl->getFirstClassExtension(); + ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension()) { + for (ObjCContainerDecl::prop_iterator I = ClsExtDecl->prop_begin(), + E = ClsExtDecl->prop_end(); I != E; ++I) { + ObjCPropertyDecl *Property = (*I); + // Skip over properties declared @dynamic + if (const ObjCPropertyImplDecl *PIDecl + = IC->FindPropertyImplDecl(Property->getIdentifier())) + if (PIDecl->getPropertyImplementation() + == ObjCPropertyImplDecl::Dynamic) + continue; + + for (const ObjCCategoryDecl *CExtDecl = + IDecl->getFirstClassExtension(); + CExtDecl; CExtDecl = CExtDecl->getNextClassExtension()) { + if (ObjCMethodDecl *GetterMethod = + CExtDecl->getInstanceMethod(Property->getGetterName())) + GetterMethod->setSynthesized(true); + if (!Property->isReadOnly()) + if (ObjCMethodDecl *SetterMethod = + CExtDecl->getInstanceMethod(Property->getSetterName())) + SetterMethod->setSynthesized(true); + } + } + } + if (LangOpts.ObjCNonFragileABI2) DefaultSynthesizeProperties(S, IC, IDecl); ImplMethodsVsClassMethods(S, IC, IDecl); diff --git a/test/SemaObjC/property-in-class-extension.m b/test/SemaObjC/property-in-class-extension.m index 0f0c884015..6ae0b8148a 100644 --- a/test/SemaObjC/property-in-class-extension.m +++ b/test/SemaObjC/property-in-class-extension.m @@ -19,6 +19,7 @@ void FUNC () { @private NSObject *_bar; NSObject *_baz; + NSObject *_bam; } - (NSObject *)baz; @end @@ -30,10 +31,20 @@ void FUNC () { @interface rdar8747333 () @property (readwrite, assign) NSObject *bar; @property (readwrite, assign) NSObject *baz; +@property (readwrite, assign) NSObject *bam; +@property (readwrite, assign) NSObject *warn; @end -@implementation rdar8747333 +@interface rdar8747333 () +- (NSObject *)bam; +- (NSObject *)warn; // expected-note {{method definition for 'warn' not found}} +- (void)setWarn : (NSObject *)val; // expected-note {{method definition for 'setWarn:' not found}} +@end + +@implementation rdar8747333 // expected-warning {{incomplete implementation}} @synthesize bar = _bar; @synthesize baz = _baz; +@synthesize bam = _bam; +@dynamic warn; @end -- 2.40.0