Change ObjCCategoryDecl::FindPropertyDeclaration() to lookup
property decls using DeclContext::lookup().

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98571 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 597b0d1..6a03360 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -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 (ObjCPropertyDecl *PD =
+        ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
+    return PD;
 
-  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))
-          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;
-    }
-    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) {
+  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;
+    }
+    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;
+    }
+    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;