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

Ted Kremenek kremenek at apple.com
Mon Mar 15 13:11:53 PDT 2010


Author: kremenek
Date: Mon Mar 15 15:11:53 2010
New Revision: 98571

URL: http://llvm.org/viewvc/llvm-project?rev=98571&view=rev
Log:
Change ObjCCategoryDecl::FindPropertyDeclaration() to lookup
property decls using DeclContext::lookup().

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

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=98571&r1=98570&r2=98571&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Mar 15 15:11:53 2010
@@ -1328,7 +1328,7 @@
   }
 
   /// Lookup a property by name in the specified DeclContext.
-  static ObjCPropertyDecl *findPropertyDecl(DeclContext *DC,
+  static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
                                             IdentifierInfo *propertyID);
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=98571&r1=98570&r2=98571&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Mar 15 15:11:53 2010
@@ -90,10 +90,10 @@
 }
 
 ObjCPropertyDecl *
-ObjCPropertyDecl::findPropertyDecl(DeclContext *DC,
+ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
                                    IdentifierInfo *propertyID) {
 
-  DeclContext::lookup_iterator I, E;
+  DeclContext::lookup_const_iterator I, E;
   llvm::tie(I, E) = DC->lookup(propertyID);
   for ( ; I != E; ++I)
     if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I))
@@ -104,45 +104,54 @@
 
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
-/// FIXME: Convert to DeclContext lookup...
-///
 ObjCPropertyDecl *
 ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
-  for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I)
-    if ((*I)->getIdentifier() == PropertyId)
-      return *I;
-
-  const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this);
-  if (PID) {
-    for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
-         E = PID->protocol_end(); I != E; ++I)
-      if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
-        return P;
-  }
 
-  if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this)) {
-    // Look through categories.
-    for (ObjCCategoryDecl *Category = OID->getCategoryList();
-         Category; Category = Category->getNextClassCategory()) {
-      if (!Category->IsClassExtension())
-        if (ObjCPropertyDecl *P = Category->FindPropertyDeclaration(PropertyId))
+  if (ObjCPropertyDecl *PD =
+        ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
+    return PD;
+
+  switch (getKind()) {
+    default:
+      break;
+    case Decl::ObjCProtocol: {
+      const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
+      for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
+           E = PID->protocol_end(); I != E; ++I)
+        if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
           return P;
+      break;
     }
-    // Look through protocols.
-    for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(),
-         E = OID->protocol_end(); I != E; ++I) {
-      if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
-        return P;
+    case Decl::ObjCInterface: {
+      const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this);
+      // Look through categories.
+      for (ObjCCategoryDecl *Cat = OID->getCategoryList();
+           Cat; Cat = Cat->getNextClassCategory())
+        if (!Cat->IsClassExtension())
+          if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId))
+            return P;
+
+      // Look through protocols.
+      for (ObjCInterfaceDecl::protocol_iterator
+            I = OID->protocol_begin(), E = OID->protocol_end(); I != E; ++I)
+        if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
+          return P;
+
+      // Finally, check the super class.
+      if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
+        return superClass->FindPropertyDeclaration(PropertyId);
+      break;
     }
-    if (OID->getSuperClass())
-      return OID->getSuperClass()->FindPropertyDeclaration(PropertyId);
-  } else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) {
-    // Look through protocols.
-    if (!OCD->IsClassExtension())
-      for (ObjCInterfaceDecl::protocol_iterator I = OCD->protocol_begin(),
-           E = OCD->protocol_end(); I != E; ++I) {
+    case Decl::ObjCCategory: {
+      const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this);
+      // Look through protocols.
+      if (!OCD->IsClassExtension())
+        for (ObjCCategoryDecl::protocol_iterator
+              I = OCD->protocol_begin(), E = OCD->protocol_end(); I != E; ++I)
         if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
           return P;
+
+      break;
     }
   }
   return 0;





More information about the cfe-commits mailing list