Finish implementing property synthesis by default.

(radar 7381956).

llvm-svn: 95695
This commit is contained in:
Fariborz Jahanian 2010-02-09 21:49:50 +00:00
parent c319f5c044
commit 5db5281db8
4 changed files with 108 additions and 15 deletions

View File

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

View File

@ -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<DeclContext>(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.

View File

@ -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<DeclContext>(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);

View File

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