aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaObjCProperty.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-09-21 20:46:37 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-09-21 20:46:37 +0000
commitfd09088880f758c874edc8d3d22fa922baec0483 (patch)
treedf4eac22e617887bdf6c4c5fb911df0c5362e436 /lib/Sema/SemaObjCProperty.cpp
parent022301b85823fc474965ce487fc9d61a156287e2 (diff)
objective-C: when diagnosing deprecated/unavailable usage of
setter or getter backing a deprecated/unavailable property, also not location of the property. // rdar://12324295 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164412 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaObjCProperty.cpp')
-rw-r--r--lib/Sema/SemaObjCProperty.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp
index 0f6ae4c7c7..82b8094e76 100644
--- a/lib/Sema/SemaObjCProperty.cpp
+++ b/lib/Sema/SemaObjCProperty.cpp
@@ -22,6 +22,7 @@
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallString.h"
+#include "clang/Lex/Preprocessor.h"
using namespace clang;
@@ -1560,6 +1561,58 @@ ObjCPropertyDecl *Sema::LookupPropertyDecl(const ObjCContainerDecl *CDecl,
return Prop;
}
}
+ else if (const ObjCCategoryDecl *CatDecl =
+ dyn_cast<ObjCCategoryDecl>(CDecl)) {
+ for (ObjCContainerDecl::prop_iterator P = CatDecl->prop_begin(),
+ E = CatDecl->prop_end(); P != E; ++P) {
+ ObjCPropertyDecl *Prop = *P;
+ if (Prop->getIdentifier() == II)
+ return Prop;
+ }
+ }
+ return 0;
+}
+
+/// PropertyIfSetterOrGetter - Looks up the property if named declaration
+/// is a setter or getter method backing a property.
+ObjCPropertyDecl *Sema::PropertyIfSetterOrGetter(NamedDecl *D) {
+ if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) {
+ Selector Sel = Method->getSelector();
+ IdentifierInfo *Id = 0;
+ if (Sel.getNumArgs() == 0)
+ Id = Sel.getIdentifierInfoForSlot(0);
+ else if (Sel.getNumArgs() == 1) {
+ StringRef str = Sel.getNameForSlot(0);
+ if (str.startswith("set")) {
+ str = str.substr(3);
+ char front = str.front();
+ front = islower(front) ? toupper(front) : tolower(front);
+ SmallString<100> PropertyName = str;
+ PropertyName[0] = front;
+ Id = &PP.getIdentifierTable().get(PropertyName);
+ }
+ }
+ if (Id) {
+ if (isa<ObjCInterfaceDecl>(Method->getDeclContext())) {
+ const ObjCInterfaceDecl *IDecl = Method->getClassInterface();
+ while (IDecl) {
+ ObjCPropertyDecl *PDecl =
+ LookupPropertyDecl(cast<ObjCContainerDecl>(IDecl), Id);
+ if (PDecl)
+ return PDecl;
+ for (ObjCCategoryDecl *Category = IDecl->getCategoryList();
+ Category; Category = Category->getNextClassCategory())
+ if ((PDecl =
+ LookupPropertyDecl(cast<ObjCContainerDecl>(Category), Id)))
+ return PDecl;
+ IDecl = IDecl->getSuperClass();
+ }
+ } else if (ObjCPropertyDecl *PDecl =
+ LookupPropertyDecl(
+ cast<ObjCContainerDecl>(Method->getDeclContext()), Id))
+ return PDecl;
+ }
+ }
return 0;
}