[cfe-commits] r60035 - in /cfe/trunk: lib/AST/Expr.cpp test/Analysis/ObjCProperties.m test/SemaObjC/property-category-1.m

Fariborz Jahanian fjahanian at apple.com
Tue Nov 25 09:56:44 PST 2008


Author: fjahanian
Date: Tue Nov 25 11:56:43 2008
New Revision: 60035

URL: http://llvm.org/viewvc/llvm-project?rev=60035&view=rev
Log:
Patch to allow over-riding of readonly property to 
a writable property in one of its category.

Added:
    cfe/trunk/test/SemaObjC/property-category-1.m
Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/Analysis/ObjCProperties.m

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=60035&r1=60034&r2=60035&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Nov 25 11:56:43 2008
@@ -551,14 +551,28 @@
   if (getStmtClass() == ObjCPropertyRefExprClass) {
     const ObjCPropertyRefExpr* PropExpr = cast<ObjCPropertyRefExpr>(this);
     if (ObjCPropertyDecl *PDecl = PropExpr->getProperty()) {
-      ObjCPropertyDecl::PropertyAttributeKind Pkind = 
-        PDecl->getPropertyAttributes();
-      if (Pkind == ObjCPropertyDecl::OBJC_PR_readonly)
+      if (PDecl->isReadOnly()) {
+        // Main class has the property as 'readyonly'. Must search
+        // through the category list to see if the property's 
+        // attribute has been over-ridden to 'readwrite'.
+        const Expr *BaseExpr = PropExpr->getBase();
+        QualType BaseType = BaseExpr->getType();
+        const PointerType *PTy = BaseType->getAsPointerType();
+        const ObjCInterfaceType *IFTy = 
+          PTy->getPointeeType()->getAsObjCInterfaceType();
+        ObjCInterfaceDecl *IFace = IFTy->getDecl();
+        for (ObjCCategoryDecl *Category = IFace->getCategoryList();
+             Category; Category = Category->getNextClassCategory()) {
+          PDecl= Category->FindPropertyDeclaration(PDecl->getIdentifier());
+          if (PDecl && !PDecl->isReadOnly())
+            return MLV_Valid;
+        }
         return MLV_ReadonlyProperty;
+      }
     }
   }
   // Assigning to an 'implicit' property?
-  if (getStmtClass() == ObjCKVCRefExprClass) {
+  else if (getStmtClass() == ObjCKVCRefExprClass) {
     const ObjCKVCRefExpr* KVCExpr = cast<ObjCKVCRefExpr>(this);
     if (KVCExpr->getSetterMethod() == 0)
       return MLV_NoSetterProperty;

Modified: cfe/trunk/test/Analysis/ObjCProperties.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/ObjCProperties.m?rev=60035&r1=60034&r2=60035&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/ObjCProperties.m (original)
+++ cfe/trunk/test/Analysis/ObjCProperties.m Tue Nov 25 11:56:43 2008
@@ -8,7 +8,7 @@
     id _X;
 }
 - (id)initWithY:(id)Y;
- at property(copy, readonly) id X;
+ at property(copy, readwrite) id X;
 @end
 
 @implementation MyClass

Added: cfe/trunk/test/SemaObjC/property-category-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-category-1.m?rev=60035&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/property-category-1.m (added)
+++ cfe/trunk/test/SemaObjC/property-category-1.m Tue Nov 25 11:56:43 2008
@@ -0,0 +1,35 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface Object
+- (id)new;
+ at end
+
+ at interface ReadOnly : Object
+{
+  int _object;
+  int _Anotherobject;
+}
+ at property(readonly) int object;
+ at property(readonly) int Anotherobject;
+ at end
+
+ at interface ReadOnly ()
+ at property(readwrite) int object;
+ at property(readwrite, setter = myAnotherobjectSetter:) int Anotherobject;
+ at end
+
+ at implementation ReadOnly
+ at synthesize object = _object;
+ at synthesize  Anotherobject = _Anotherobject;
+- (void) myAnotherobjectSetter : (int)val {
+    _Anotherobject = val;
+}
+ at end
+
+int main(int argc, char **argv) {
+    ReadOnly *test = [ReadOnly new];
+    test.object = 12345;
+    test.Anotherobject = 200;
+    return test.object - 12345 + test.Anotherobject - 200;
+}
+





More information about the cfe-commits mailing list