[cfe-commits] r43989 - in /cfe/trunk: AST/Decl.cpp Sema/Sema.h Sema/SemaDecl.cpp Sema/SemaExpr.cpp include/clang/AST/DeclObjC.h test/Sema/message.m

Steve Naroff snaroff at apple.com
Sat Nov 10 16:10:48 PST 2007


Author: snaroff
Date: Sat Nov 10 18:10:47 2007
New Revision: 43989

URL: http://llvm.org/viewvc/llvm-project?rev=43989&view=rev
Log:

Teach Sema::ActOnInstanceMessage() about private methods. That is, methods declared in an implementation (but not listed in the interface).

This commit is only 95% of the bug fix. The last piece to this puzzle is to add the method decls to the implementation incrementally (as we encounter them). At the moment, the methods aren't added until we see an @end (which is too late).

I will complete this later...


Added:
    cfe/trunk/test/Sema/message.m
Modified:
    cfe/trunk/AST/Decl.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h

Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=43989&r1=43988&r2=43989&view=diff

==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Sat Nov 10 18:10:47 2007
@@ -510,4 +510,31 @@
   return NULL;
 }
 
+// lookupInstanceMethod - This method returns an instance method by looking in
+// the class implementation. Unlike interfaces, we don't look outside the
+// implementation.
+ObjcMethodDecl *ObjcImplementationDecl::lookupInstanceMethod(Selector &Sel) {
+  ObjcMethodDecl **methods = getInstanceMethods();
+  int methodCount = getNumInstanceMethods();
+  for (int i = 0; i < methodCount; ++i) {
+    if (methods[i]->getSelector() == Sel) {
+      return methods[i];
+    }
+  }
+  return NULL;
+}
+
+// lookupClassMethod - This method returns an instance method by looking in
+// the class implementation. Unlike interfaces, we don't look outside the
+// implementation.
+ObjcMethodDecl *ObjcImplementationDecl::lookupClassMethod(Selector &Sel) {
+  ObjcMethodDecl **methods = getClassMethods();
+  int methodCount = getNumClassMethods();
+  for (int i = 0; i < methodCount; ++i) {
+    if (methods[i]->getSelector() == Sel) {
+      return methods[i];
+    }
+  }
+  return NULL;
+}
 

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=43989&r1=43988&r2=43989&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Sat Nov 10 18:10:47 2007
@@ -85,7 +85,7 @@
 
   /// ObjcImplementations - Keep track of all of the classes with
   /// @implementation's, so that we can emit errors on duplicates.
-  llvm::SmallPtrSet<IdentifierInfo*, 8> ObjcImplementations;
+  llvm::DenseMap<IdentifierInfo*, ObjcImplementationDecl*> ObjcImplementations;
   
   /// ObjcProtocols - Keep track of all protocol declarations declared
   /// with @protocol keyword, so that we can emit errors on duplicates and

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=43989&r1=43988&r2=43989&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Sat Nov 10 18:10:47 2007
@@ -1477,9 +1477,10 @@
   new ObjcImplementationDecl(AtClassImplLoc, ClassName, IDecl, SDecl);
   
   // Check that there is no duplicate implementation of this class.
-  if (!ObjcImplementations.insert(ClassName))
+  if (ObjcImplementations[ClassName])
     Diag(ClassLoc, diag::err_dup_implementation_class, ClassName->getName());
-
+  else // add it to the list.
+    ObjcImplementations[ClassName] = IMPDecl;
   return IMPDecl;
 }
 

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=43989&r1=43988&r2=43989&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sat Nov 10 18:10:47 2007
@@ -2126,6 +2126,12 @@
     // idea is to add class info to InstanceMethodPool...
     Method = ClassDecl->lookupInstanceMethod(Sel);
     if (!Method) {
+      // If we have an implementation in scope, check "private" methods.
+      if (ObjcImplementationDecl *ImpDecl = 
+            ObjcImplementations[ClassDecl->getIdentifier()])
+        Method = ImpDecl->lookupInstanceMethod(Sel);
+    }
+    if (!Method) {
       Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(),
            SourceRange(lbrac, rbrac));
       returnType = Context.getObjcIdType();

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=43989&r1=43988&r2=43989&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sat Nov 10 18:10:47 2007
@@ -667,6 +667,9 @@
   
   ObjcMethodDecl **getClassMethods() const { return ClassMethods; }
   int getNumClassMethods() const { return NumClassMethods; }
+
+  ObjcMethodDecl *lookupInstanceMethod(Selector &Sel);
+  ObjcMethodDecl *lookupClassMethod(Selector &Sel);
   
   ObjcIvarDecl **getImplDeclIVars() const { return Ivars; }
   int getImplDeclNumIvars() const { return NumIvars; }

Added: cfe/trunk/test/Sema/message.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/message.m?rev=43989&view=auto

==============================================================================
--- cfe/trunk/test/Sema/message.m (added)
+++ cfe/trunk/test/Sema/message.m Sat Nov 10 18:10:47 2007
@@ -0,0 +1,11 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface foo
+- (void)meth;
+ at end
+
+ at implementation foo
+- (void) contents {}			// No declaration in @interface!
+- (void) meth { [self contents]; } // expected-warning {{method '-contents' not found (return type defaults to 'id')}}
+ at end
+





More information about the cfe-commits mailing list