[cfe-commits] r54042 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp test/Sema/objc-typedef-class.m

Steve Naroff snaroff at apple.com
Fri Jul 25 12:39:00 PDT 2008


Author: snaroff
Date: Fri Jul 25 14:39:00 2008
New Revision: 54042

URL: http://llvm.org/viewvc/llvm-project?rev=54042&view=rev
Log:
Cleaunup Sema::ActOnClassMessage(). This commit:
(a) removes a bogus warning.
(b) removes an undesirable usage of the ObjCMessageExpr constructor that takes an IdentifierInfo * (which I will abolish).

Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/Sema/objc-typedef-class.m

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Jul 25 14:39:00 2008
@@ -169,7 +169,7 @@
   } else
     ClassDecl = getObjCInterfaceDecl(receiverName);
   
-  // ClassDecl is null in the following case.
+  // The following code allows for the following GCC-ism:
   //
   //  typedef XCElementDisplayRect XCElementGraphicsRect;
   //
@@ -178,22 +178,31 @@
   //    _sGraphicsDelegate =[[XCElementGraphicsRect alloc] init];
   //  }
   //
-  // FIXME: Investigate why GCC allows the above.
+  // If necessary, the following lookup could move to getObjCInterfaceDecl().
+  if (!ClassDecl) {
+    Decl *IDecl = LookupDecl(receiverName, Decl::IDNS_Ordinary, 0, false);
+    if (TypedefDecl *OCTD = dyn_cast_or_null<TypedefDecl>(IDecl)) {
+      const ObjCInterfaceType *OCIT;
+      OCIT = OCTD->getUnderlyingType()->getAsObjCInterfaceType();
+      if (OCIT)
+        ClassDecl = OCIT->getDecl();
+    }
+  }
+  assert(ClassDecl && "missing interface declaration");
   ObjCMethodDecl *Method = 0;
   QualType returnType;
-  if (ClassDecl) {
-    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);
-    }
-    // Before we give up, check if the selector is an instance method.
-    if (!Method)
-      Method = ClassDecl->lookupInstanceMethod(Sel);
+  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);
   }
+  // Before we give up, check if the selector is an instance method.
+  if (!Method)
+    Method = ClassDecl->lookupInstanceMethod(Sel);
+
   if (!Method) {
     Diag(lbrac, diag::warn_method_not_found, std::string("+"), Sel.getName(),
          SourceRange(lbrac, rbrac));
@@ -212,7 +221,7 @@
   // FIXME: need to do a better job handling 'super' usage within a class 
   // For now, we simply pass the "super" identifier through (which isn't
   // consistent with instance methods.
-  if (isSuper || !ClassDecl)
+  if (isSuper)
     return new ObjCMessageExpr(receiverName, Sel, returnType, Method,
                                lbrac, rbrac, ArgExprs, NumArgs);
   else

Modified: cfe/trunk/test/Sema/objc-typedef-class.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-typedef-class.m?rev=54042&r1=54041&r2=54042&view=diff

==============================================================================
--- cfe/trunk/test/Sema/objc-typedef-class.m (original)
+++ cfe/trunk/test/Sema/objc-typedef-class.m Fri Jul 25 14:39:00 2008
@@ -72,7 +72,7 @@
 {
   static XCElementGraphicsRect *_sGraphicsDelegate = ((void *) 0);
   if (!_sGraphicsDelegate) {
-    _sGraphicsDelegate =[[XCElementGraphicsRect alloc] init]; // expected-warning{{method '+alloc' not found (return type defaults to 'id')}}
+    _sGraphicsDelegate =[[XCElementGraphicsRect alloc] init]; 
   }
 }
 @end





More information about the cfe-commits mailing list