summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExprObjC.cpp
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2009-02-26 15:55:06 +0000
committerSteve Naroff <snaroff@apple.com>2009-02-26 15:55:06 +0000
commitb162f170da450fd6f910800f93a7834a3876dea7 (patch)
treed02eb54d3d1acf1a6786b55ce1dbc16c06087e17 /clang/lib/Sema/SemaExprObjC.cpp
parentd7b8508daae8da86b84cd6578c83ff87630ca7e7 (diff)
downloadbcm5719-llvm-b162f170da450fd6f910800f93a7834a3876dea7.tar.gz
bcm5719-llvm-b162f170da450fd6f910800f93a7834a3876dea7.zip
Fix http://llvm.org/bugs/show_bug.cgi?id=3544.
The code for looking up local/private method in Sema::ActOnInstanceMessage() was not handling categories properly. Sema::ActOnClassMessage() didn't have this bug. Created a helper with the correct logic and changed both methods to use it. llvm-svn: 65532
Diffstat (limited to 'clang/lib/Sema/SemaExprObjC.cpp')
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp45
1 files changed, 26 insertions, 19 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 7696cf06084..e3d2074c0e2 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -202,6 +202,27 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
return anyIncompatibleArgs;
}
+// Helper method for ActOnClassMethod/ActOnInstanceMethod.
+// Will search "local" class/category implementations for a method decl.
+// Returns 0 if no method is found.
+ObjCMethodDecl *Sema::LookupPrivateMethod(Selector Sel,
+ ObjCInterfaceDecl *ClassDecl) {
+ ObjCMethodDecl *Method = 0;
+
+ if (ObjCImplementationDecl *ImpDecl =
+ ObjCImplementations[ClassDecl->getIdentifier()])
+ Method = ImpDecl->getClassMethod(Sel);
+
+ // Look through local category implementations associated with the class.
+ if (!Method) {
+ for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Method; i++) {
+ if (ObjCCategoryImpls[i]->getClassInterface() == ClassDecl)
+ Method = ObjCCategoryImpls[i]->getClassMethod(Sel);
+ }
+ }
+ return Method;
+}
+
// ActOnClassMessage - used for both unary and keyword messages.
// ArgExprs is optional - if it is present, the number of expressions
// is obtained from Sel.getNumArgs().
@@ -282,19 +303,9 @@ Sema::ExprResult Sema::ActOnClassMessage(
Method = ClassDecl->lookupClassMethod(Sel);
// If we have an implementation in scope, check "private" methods.
- if (!Method) {
- if (ObjCImplementationDecl *ImpDecl =
- ObjCImplementations[ClassDecl->getIdentifier()])
- Method = ImpDecl->getClassMethod(Sel);
-
- // Look through local category implementations associated with the class.
- if (!Method) {
- for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Method; i++) {
- if (ObjCCategoryImpls[i]->getClassInterface() == ClassDecl)
- Method = ObjCCategoryImpls[i]->getClassMethod(Sel);
- }
- }
- }
+ if (!Method)
+ Method = LookupPrivateMethod(Sel, ClassDecl);
+
// Before we give up, check if the selector is an instance method.
if (!Method)
Method = ClassDecl->lookupInstanceMethod(Sel);
@@ -379,12 +390,8 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
// First check the public methods in the class interface.
Method = ClassDecl->lookupClassMethod(Sel);
- if (!Method) {
- // If we have an implementation in scope, check "private" methods.
- if (ObjCImplementationDecl *ImpDecl =
- ObjCImplementations[ClassDecl->getIdentifier()])
- Method = ImpDecl->getClassMethod(Sel);
- }
+ if (!Method)
+ Method = LookupPrivateMethod(Sel, ClassDecl);
}
if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
return true;
OpenPOWER on IntegriCloud