]> granicus.if.org Git - clang/commitdiff
Refactored checking on readonly property into a method.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 25 Nov 2008 21:48:26 +0000 (21:48 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 25 Nov 2008 21:48:26 +0000 (21:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60050 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/AST/Expr.cpp

index ffbb1e56fb837941147ad68191ac08b1e5cad184..b52400ab9f6843452792ba26cace98590ed5f607 100644 (file)
@@ -339,6 +339,7 @@ public:
   ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
   ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
   ObjCIvarDecl *FindIvarDeclaration(IdentifierInfo *IvarId) const;
+  bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl) const;
 
   typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator;
   protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
index 040a921908757d0bdced5f221fc2ab7df6922914..e631bac452e2054ecb3ab93329053c09082eb263 100644 (file)
@@ -257,6 +257,26 @@ void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
   }
 }
 
+/// isPropertyReadonly - Return true if property is a readonly, by seaching
+/// for the property in the class and in its categories.
+///
+bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const
+{
+  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'.
+    for (ObjCCategoryDecl *Category = getCategoryList();
+         Category; Category = Category->getNextClassCategory()) {
+      PDecl= Category->FindPropertyDeclaration(PDecl->getIdentifier());
+      if (PDecl && !PDecl->isReadOnly())
+        return false;
+    }
+    return true;
+  }
+  return false;  
+}
+
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 ///
index 56f08b28d9549e4c81bef910986470a8e8339433..7a8119c5e3d1f8ae281ee6771a8f5bd89aebf42f 100644 (file)
@@ -551,24 +551,13 @@ Expr::isModifiableLvalueResult Expr::isModifiableLvalue(ASTContext &Ctx) const {
   if (getStmtClass() == ObjCPropertyRefExprClass) {
     const ObjCPropertyRefExpr* PropExpr = cast<ObjCPropertyRefExpr>(this);
     if (ObjCPropertyDecl *PDecl = PropExpr->getProperty()) {
-      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;
-      }
+      QualType BaseType = PropExpr->getBase()->getType();
+      if (const PointerType *PTy = BaseType->getAsPointerType())
+        if (const ObjCInterfaceType *IFTy = 
+            PTy->getPointeeType()->getAsObjCInterfaceType())
+          if (ObjCInterfaceDecl *IFace = IFTy->getDecl())
+            if (IFace->isPropertyReadonly(PDecl))
+              return MLV_ReadonlyProperty;
     }
   }
   // Assigning to an 'implicit' property?