From: Fariborz Jahanian Date: Tue, 9 Feb 2010 21:49:50 +0000 (+0000) Subject: Finish implementing property synthesis by default. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=77e2dde750c271155f35949a6d3c22f8e7d287f8;p=clang Finish implementing property synthesis by default. (radar 7381956). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95695 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index bf6888762f..8b3b465038 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1363,6 +1363,9 @@ public: ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl, IdentifierInfo *II); + ObjCIvarDecl *SynthesizeNewPropertyIvar(ObjCInterfaceDecl *IDecl, + IdentifierInfo *NameII); + /// AtomicPropertySetterGetterRules - This routine enforces the rule (via /// warning) when atomic property has one but not the other user-declared /// setter or getter. diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index c0e8219f67..13eeb6c761 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -2293,6 +2293,28 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, return DeclPtrTy::make(PDecl); } +ObjCIvarDecl* +Sema::SynthesizeNewPropertyIvar(ObjCInterfaceDecl *IDecl, + IdentifierInfo *NameII) { + ObjCIvarDecl *Ivar = 0; + ObjCPropertyDecl *Prop = LookupPropertyDecl(IDecl, NameII); + if (Prop && !Prop->isInvalidDecl()) { + DeclContext *EnclosingContext = cast_or_null(IDecl); + QualType PropType = Context.getCanonicalType(Prop->getType()); + assert(EnclosingContext && + "null DeclContext for synthesized ivar - SynthesizeNewPropertyIvar"); + Ivar = ObjCIvarDecl::Create(Context, EnclosingContext, + Prop->getLocation(), + NameII, PropType, /*Dinfo=*/0, + ObjCIvarDecl::Public, + (Expr *)0); + Ivar->setLexicalDeclContext(IDecl); + IDecl->addDecl(Ivar); + Prop->setPropertyIvarDecl(Ivar); + } + return Ivar; +} + /// ActOnPropertyImplDecl - This routine performs semantic checks and /// builds the AST node for a property implementation declaration; declared /// as @synthesize or @dynamic. diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 0da57330ee..044216381c 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1343,22 +1343,9 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S, } } if (LangOpts.ObjCNonFragileABI2 && LookForIvars && Lookup.empty()) { - // Find property name matching variable name. - ObjCPropertyDecl *Prop = LookupPropertyDecl(IFace, II); - if (Prop && !Prop->isInvalidDecl()) { - DeclContext *EnclosingContext = cast_or_null(IFace); - QualType PropType = Context.getCanonicalType(Prop->getType()); - assert(EnclosingContext && - "null DeclContext for synthesized ivar - LookupInObjCMethod"); - ObjCIvarDecl *Ivar = ObjCIvarDecl::Create(Context, EnclosingContext, - Prop->getLocation(), - II, PropType, /*Dinfo=*/0, - ObjCIvarDecl::Public, - (Expr *)0); - Ivar->setLexicalDeclContext(IFace); - IFace->addDecl(Ivar); + ObjCIvarDecl *Ivar = SynthesizeNewPropertyIvar(IFace, II); + if (Ivar) return LookupInObjCMethod(Lookup, S, II, AllowBuiltinCreation); - } } // Sentinel value saying that we didn't do anything special. return Owned((Expr*) 0); diff --git a/test/SemaObjC/default-synthesize.m b/test/SemaObjC/default-synthesize.m new file mode 100644 index 0000000000..be2397bd20 --- /dev/null +++ b/test/SemaObjC/default-synthesize.m @@ -0,0 +1,81 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s + +@interface NSString @end + +@interface NSObject @end + +@interface SynthItAll +@property int howMany; +@property (retain) NSString* what; +@end + +@implementation SynthItAll +//@synthesize howMany, what; +@end + + +@interface SynthSetter : NSObject +@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair +@property (nonatomic, retain) NSString* what; +@end + +@implementation SynthSetter +//@synthesize howMany, what; + +- (int) howMany { + return howMany; +} +// - (void) setHowMany: (int) value + +- (NSString*) what { + return what; +} +// - (void) setWhat: (NSString*) value +@end + + +@interface SynthGetter : NSObject +@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair +@property (nonatomic, retain) NSString* what; +@end + +@implementation SynthGetter +//@synthesize howMany, what; + +// - (int) howMany +- (void) setHowMany: (int) value { + howMany = value; +} + +// - (NSString*) what +- (void) setWhat: (NSString*) value { + if (what != value) { + } +} +@end + + +@interface SynthNone : NSObject +@property int howMany; +@property (retain) NSString* what; +@end + +@implementation SynthNone +//@synthesize howMany, what; // REM: Redundant anyway + +- (int) howMany { + return howMany; +} +- (void) setHowMany: (int) value { + howMany = value; +} + +- (NSString*) what { + return what; +} +- (void) setWhat: (NSString*) value { + if (what != value) { + } +} +@end +