]> granicus.if.org Git - clang/commitdiff
Cleaunup Sema::ActOnClassMessage(). This commit:
authorSteve Naroff <snaroff@apple.com>
Fri, 25 Jul 2008 19:39:00 +0000 (19:39 +0000)
committerSteve Naroff <snaroff@apple.com>
Fri, 25 Jul 2008 19:39:00 +0000 (19:39 +0000)
(a) removes a bogus warning.
(b) removes an undesirable usage of the ObjCMessageExpr constructor that takes an IdentifierInfo * (which I will abolish).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54042 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprObjC.cpp
test/Sema/objc-typedef-class.m

index 5d168232fe0bc1510abd4d0ce928ba7402d66252..97e1579548c5a86fa731d0023dfde9c9937adb10 100644 (file)
@@ -169,7 +169,7 @@ Sema::ExprResult Sema::ActOnClassMessage(
   } 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 @@ Sema::ExprResult Sema::ActOnClassMessage(
   //    _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 @@ Sema::ExprResult Sema::ActOnClassMessage(
   // 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
index 9518ab7a0e5b92932b039f9102b204c5e60f5e8f..1bb3f87aa5ae006adbc0c99e17895dddd7c89b1d 100644 (file)
@@ -72,7 +72,7 @@ typedef XCElementDisplayRect XCElementGraphicsRect;
 {
   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