[cfe-commits] r60050 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/AST/Expr.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Nov 25 13:48:26 PST 2008


Author: fjahanian
Date: Tue Nov 25 15:48:26 2008
New Revision: 60050

URL: http://llvm.org/viewvc/llvm-project?rev=60050&view=rev
Log:
Refactored checking on readonly property into a method.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=60050&r1=60049&r2=60050&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Tue Nov 25 15:48:26 2008
@@ -339,6 +339,7 @@
   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();}

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Tue Nov 25 15:48:26 2008
@@ -257,6 +257,26 @@
   }
 }
 
+/// 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.
 ///

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

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Nov 25 15:48:26 2008
@@ -551,24 +551,13 @@
   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?





More information about the cfe-commits mailing list