summaryrefslogtreecommitdiff
path: root/lib/AST/DeclObjC.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/AST/DeclObjC.cpp')
-rw-r--r--lib/AST/DeclObjC.cpp104
1 files changed, 62 insertions, 42 deletions
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 67b71a0c44e5..7d1033d4f15f 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -89,47 +89,69 @@ ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const {
return 0;
}
+ObjCPropertyDecl *
+ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
+ IdentifierInfo *propertyID) {
+
+ DeclContext::lookup_const_iterator I, E;
+ llvm::tie(I, E) = DC->lookup(propertyID);
+ for ( ; I != E; ++I)
+ if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I))
+ return PD;
+
+ return 0;
+}
+
/// 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;
@@ -137,22 +159,21 @@ ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
/// with name 'PropertyId' in the primary class; including those in protocols
-/// (direct or indirect) used by the promary class.
-/// FIXME: Convert to DeclContext lookup...
+/// (direct or indirect) used by the primary class.
///
ObjCPropertyDecl *
-ObjCContainerDecl::FindPropertyVisibleInPrimaryClass(
+ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
IdentifierInfo *PropertyId) const {
- assert(isa<ObjCInterfaceDecl>(this) && "FindPropertyVisibleInPrimaryClass");
- for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I)
- if ((*I)->getIdentifier() == PropertyId)
- return *I;
- const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this);
+ if (ObjCPropertyDecl *PD =
+ ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
+ return PD;
+
// Look through protocols.
- for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(),
- E = OID->protocol_end(); I != E; ++I)
+ for (ObjCInterfaceDecl::protocol_iterator
+ I = protocol_begin(), E = protocol_end(); I != E; ++I)
if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
return P;
+
return 0;
}
@@ -441,7 +462,6 @@ void ObjCInterfaceDecl::Destroy(ASTContext &C) {
for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I)
if (*I) (*I)->Destroy(C);
- IVars.Destroy(C);
// FIXME: CategoryList?
// FIXME: Because there is no clear ownership