[cfe-commits] r65300 - /cfe/trunk/lib/Sema/SemaExprObjC.cpp

Steve Naroff snaroff at apple.com
Sun Feb 22 18:25:41 PST 2009


Author: snaroff
Date: Sun Feb 22 20:25:40 2009
New Revision: 65300

URL: http://llvm.org/viewvc/llvm-project?rev=65300&view=rev
Log:
Sema::ActOnInstanceMessage(): Tighen up the lookup rules for handling messages to 'Class'. Also improve "super" handling.

Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=65300&r1=65299&r2=65300&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sun Feb 22 20:25:40 2009
@@ -309,6 +309,22 @@
                                          lbrac, rbrac, ArgExprs, NumArgs);
 }
 
+// This routine makes sure we handle the following:
+//
+// [(Object <Func> *)super class_func0];
+// [(id <Func>)super class_func0];
+//
+static bool isSuperExpr(Stmt *S) {
+  for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end();
+       CI != E; ++CI) {
+    if (*CI)
+      return isSuperExpr(*CI);
+  }
+  if (isa<ObjCSuperExpr>(S))
+    return true;
+  return false;
+}
+
 // ActOnInstanceMessage - used for both unary and keyword messages.
 // ArgExprs is optional - if it is present, the number of expressions
 // is obtained from Sel.getNumArgs().
@@ -327,7 +343,7 @@
     Context.getCanonicalType(RExpr->getType()).getUnqualifiedType();
 
   // Handle messages to 'super'.
-  if (isa<ObjCSuperExpr>(RExpr)) {
+  if (isSuperExpr(RExpr)) {
     ObjCMethodDecl *Method = 0;
     if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) {
       // If we have an interface in scope, check 'super' methods.
@@ -364,17 +380,23 @@
   if (ReceiverCType == Context.getCanonicalType(Context.getObjCClassType())) {
     ObjCMethodDecl *Method = 0;
     if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) {
-      // If we have an implementation in scope, check "private" methods.
-      if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface())
-        if (ObjCImplementationDecl *ImpDecl = 
-              ObjCImplementations[ClassDecl->getIdentifier()])
-          Method = ImpDecl->getClassMethod(Sel);
-      
+      if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) {
+        // 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 && DiagnoseUseOfDecl(Method, receiverLoc))
         return true;
-    }
-    if (!Method)
+    } else {
+      // We're not in a method context, look for any factory method named 'Sel'.
       Method = FactoryMethodPool[Sel].Method;
+    }
     if (!Method)
       Method = LookupInstanceMethodInGlobalPool(
                                Sel, SourceRange(lbrac,rbrac));





More information about the cfe-commits mailing list