[cfe-commits] r95695 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp test/SemaObjC/default-synthesize.m

Fariborz Jahanian fjahanian at apple.com
Tue Feb 9 13:49:50 PST 2010


Author: fjahanian
Date: Tue Feb  9 15:49:50 2010
New Revision: 95695

URL: http://llvm.org/viewvc/llvm-project?rev=95695&view=rev
Log:
Finish implementing property synthesis by default.
(radar 7381956).


Added:
    cfe/trunk/test/SemaObjC/default-synthesize.m
Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=95695&r1=95694&r2=95695&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Feb  9 15:49:50 2010
@@ -1363,6 +1363,9 @@
   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.

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=95695&r1=95694&r2=95695&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Feb  9 15:49:50 2010
@@ -2293,6 +2293,28 @@
   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.

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=95695&r1=95694&r2=95695&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Feb  9 15:49:50 2010
@@ -1343,22 +1343,9 @@
     }
   }
   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);

Added: cfe/trunk/test/SemaObjC/default-synthesize.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize.m?rev=95695&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize.m (added)
+++ cfe/trunk/test/SemaObjC/default-synthesize.m Tue Feb  9 15:49:50 2010
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+
+ at interface NSString @end
+
+ at interface NSObject @end
+
+ at interface SynthItAll
+ at property int howMany;
+ at property (retain) NSString* what;
+ at end
+
+ at implementation SynthItAll
+//@synthesize howMany, what;
+ at end
+
+
+ at interface SynthSetter : NSObject
+ at property (nonatomic) int howMany;  // REM: nonatomic to avoid warnings about only implementing one of the pair
+ at property (nonatomic, retain) NSString* what;
+ at end
+
+ at implementation SynthSetter
+//@synthesize howMany, what;
+
+- (int) howMany {
+    return howMany;
+}
+// - (void) setHowMany: (int) value
+
+- (NSString*) what {
+    return what;
+}
+// - (void) setWhat: (NSString*) value    
+ at end
+
+
+ at interface SynthGetter : NSObject
+ at property (nonatomic) int howMany;  // REM: nonatomic to avoid warnings about only implementing one of the pair
+ at property (nonatomic, retain) NSString* what;
+ at end
+
+ at implementation SynthGetter
+//@synthesize howMany, what;
+
+// - (int) howMany
+- (void) setHowMany: (int) value {
+    howMany = value;
+}
+
+// - (NSString*) what
+- (void) setWhat: (NSString*) value {
+    if (what != value) {
+    }
+}
+ at end
+
+
+ at interface SynthNone : NSObject
+ at property int howMany;
+ at property (retain) NSString* what;
+ at end
+
+ at 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) {
+    }
+}
+ at end
+





More information about the cfe-commits mailing list