]> granicus.if.org Git - clang/commitdiff
Finish implementing property synthesis by default.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 9 Feb 2010 21:49:50 +0000 (21:49 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 9 Feb 2010 21:49:50 +0000 (21:49 +0000)
(radar 7381956).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95695 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExpr.cpp
test/SemaObjC/default-synthesize.m [new file with mode: 0644]

index bf6888762f3649d838ca3c577eb04590a3f7e9ca..8b3b4650387a7a607aaec6e042e27787e2f860df 100644 (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.
index c0e8219f67fcf677bdb34d132a982e8f27a6c480..13eeb6c761a0fdd46f0be9e83a5b6e6f58d0a79f 100644 (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.
index 0da57330eeb67e4fff32481e2852b85d885deb86..044216381cfb414ab2b870fec4d66cc751f793f4 100644 (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);
diff --git a/test/SemaObjC/default-synthesize.m b/test/SemaObjC/default-synthesize.m
new file mode 100644 (file)
index 0000000..be2397b
--- /dev/null
@@ -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
+