From 6669db9d80d77d10f101aa9f8e488bbd2d98f76c Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 25 Nov 2008 17:56:43 +0000 Subject: [PATCH] Patch to allow over-riding of readonly property to a writable property in one of its category. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60035 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 22 ++++++++++++++---- test/Analysis/ObjCProperties.m | 2 +- test/SemaObjC/property-category-1.m | 35 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 test/SemaObjC/property-category-1.m diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 835a467fc2..56f08b28d9 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -551,14 +551,28 @@ Expr::isModifiableLvalueResult Expr::isModifiableLvalue(ASTContext &Ctx) const { if (getStmtClass() == ObjCPropertyRefExprClass) { const ObjCPropertyRefExpr* PropExpr = cast(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(this); if (KVCExpr->getSetterMethod() == 0) return MLV_NoSetterProperty; diff --git a/test/Analysis/ObjCProperties.m b/test/Analysis/ObjCProperties.m index 03eefc23fe..f207475bd6 100644 --- a/test/Analysis/ObjCProperties.m +++ b/test/Analysis/ObjCProperties.m @@ -8,7 +8,7 @@ id _X; } - (id)initWithY:(id)Y; -@property(copy, readonly) id X; +@property(copy, readwrite) id X; @end @implementation MyClass diff --git a/test/SemaObjC/property-category-1.m b/test/SemaObjC/property-category-1.m new file mode 100644 index 0000000000..32e14f00c1 --- /dev/null +++ b/test/SemaObjC/property-category-1.m @@ -0,0 +1,35 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface Object +- (id)new; +@end + +@interface ReadOnly : Object +{ + int _object; + int _Anotherobject; +} +@property(readonly) int object; +@property(readonly) int Anotherobject; +@end + +@interface ReadOnly () +@property(readwrite) int object; +@property(readwrite, setter = myAnotherobjectSetter:) int Anotherobject; +@end + +@implementation ReadOnly +@synthesize object = _object; +@synthesize Anotherobject = _Anotherobject; +- (void) myAnotherobjectSetter : (int)val { + _Anotherobject = val; +} +@end + +int main(int argc, char **argv) { + ReadOnly *test = [ReadOnly new]; + test.object = 12345; + test.Anotherobject = 200; + return test.object - 12345 + test.Anotherobject - 200; +} + -- 2.40.0