summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/DeclObjC.cpp55
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp51
2 files changed, 70 insertions, 36 deletions
diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp
index a5eb07a84c4..04e9993101e 100644
--- a/clang/lib/AST/DeclObjC.cpp
+++ b/clang/lib/AST/DeclObjC.cpp
@@ -137,6 +137,47 @@ ObjCMethodDecl::~ObjCMethodDecl() {
delete[] ParamInfo;
}
+/// FindPropertyDeclaration - Finds declaration of the property given its name
+/// in 'PropertyId' and returns it. It returns 0, if not found.
+///
+ObjCPropertyDecl *
+ ObjCInterfaceDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
+ for (ObjCInterfaceDecl::classprop_iterator I = classprop_begin(),
+ E = classprop_end(); I != E; ++I) {
+ ObjCPropertyDecl *property = *I;
+ if (property->getIdentifier() == PropertyId)
+ return property;
+ }
+ return 0;
+}
+
+/// FindCategoryDeclaration - Finds category declaration in the list of
+/// categories for this class and returns it. Name of the category is passed
+/// in 'CategoryId'. If category not found, return 0;
+///
+ObjCCategoryDecl *
+ ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
+ for (ObjCCategoryDecl *Category = getCategoryList();
+ Category; Category = Category->getNextClassCategory())
+ if (Category->getIdentifier() == CategoryId)
+ return Category;
+ return 0;
+}
+
+/// FindIvarDeclaration - Find an Ivar declaration in this class given its
+/// name in 'IvarId'. On failure to find, return 0;
+///
+ObjCIvarDecl *
+ ObjCInterfaceDecl::FindIvarDeclaration(IdentifierInfo *IvarId) const {
+ for (ObjCInterfaceDecl::ivar_iterator IVI = ivar_begin(),
+ IVE = ivar_end(); IVI != IVE; ++IVI) {
+ ObjCIvarDecl* Ivar = (*IVI);
+ if (Ivar->getIdentifier() == IvarId)
+ return Ivar;
+ }
+ return 0;
+}
+
/// ObjCAddInstanceVariablesToClass - Inserts instance variables
/// into ObjCInterfaceDecl's fields.
///
@@ -274,6 +315,20 @@ void ObjCCategoryDecl::addMethods(ObjCMethodDecl **insMethods,
AtEndLoc = endLoc;
}
+/// FindPropertyDeclaration - Finds declaration of the property given its name
+/// in 'PropertyId' and returns it. It returns 0, if not found.
+///
+ObjCPropertyDecl *
+ObjCCategoryDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
+ for (ObjCCategoryDecl::classprop_iterator I = classprop_begin(),
+ E = classprop_end(); I != E; ++I) {
+ ObjCPropertyDecl *property = *I;
+ if (property->getIdentifier() == PropertyId)
+ return property;
+ }
+ return 0;
+}
+
ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) {
ObjCInterfaceDecl* ClassDecl = this;
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 05371e71724..21130a04fa0 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -929,9 +929,9 @@ Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
return PDecl;
}
-/// ActOnPropertyImplDecl - This routine performas semantic checks and
-/// build the AST node for a property implementation declaration; declared
-/// as @synthesize ot @dynamic
+/// ActOnPropertyImplDecl - This routine performs semantic checks and
+/// builds the AST node for a property implementation declaration; declared
+/// as @synthesize or @dynamic.
///
Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
SourceLocation PropertyLoc,
@@ -957,17 +957,11 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
return 0;
}
// Look for this property declaration in the @implementation's @interface
- ObjCInterfaceDecl::classprop_iterator I,E;
- for (I = IDecl->classprop_begin(),
- E = IDecl->classprop_end(); I != E; ++I) {
- property = *I;
- if (property->getIdentifier() == PropertyId)
- break;
- }
- if (I == E) {
- Diag(PropertyLoc, diag::error_bad_property_decl, IDecl->getName());
+ property = IDecl->FindPropertyDeclaration(PropertyId);
+ if (!property) {
+ Diag(PropertyLoc, diag::error_bad_property_decl, IDecl->getName());
return 0;
- }
+ }
}
else if (ObjCCategoryImplDecl* CatImplClass =
dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl)) {
@@ -976,26 +970,18 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
Diag(AtLoc, diag::error_missing_property_interface);
return 0;
}
- ObjCCategoryDecl *Categories;
- for (Categories = IDecl->getCategoryList();
- Categories; Categories = Categories->getNextClassCategory())
- if (Categories->getIdentifier() == CatImplClass->getIdentifier())
- break;
+ ObjCCategoryDecl *Category =
+ IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier());
+
// If category for this implementation not found, it is an error which
// has already been reported eralier.
- if (!Categories)
+ if (!Category)
return 0;
// Look for this property declaration in @implementation's category
- ObjCCategoryDecl::classprop_iterator I,E;
- for (I = Categories->classprop_begin(),
- E = Categories->classprop_end(); I != E; ++I) {
- property = *I;
- if (property->getIdentifier() == PropertyId)
- break;
- }
- if (I == E) {
+ property = Category->FindPropertyDeclaration(PropertyId);
+ if (!property) {
Diag(PropertyLoc, diag::error_bad_property_decl,
- Categories->getName());
+ Category->getName());
return 0;
}
}
@@ -1012,14 +998,7 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
return 0;
}
// Check that this is a previously declared 'ivar' in 'IDecl' interface
- ObjCInterfaceDecl::ivar_iterator IVI, IVE;
- for (IVI = IDecl->ivar_begin(), IVE = IDecl->ivar_end();
- IVI != IVE; ++IVI) {
- ObjCIvarDecl* ImplIvar = (*IVI);
- if (ImplIvar->getIdentifier() == PropertyIvar)
- break;
- }
- if (IVI == IVE) {
+ if (!IDecl->FindIvarDeclaration(PropertyIvar)) {
Diag(PropertyLoc, diag::error_missing_property_ivar_decl);
return 0;
}
OpenPOWER on IntegriCloud