[cfe-commits] r42544 - in /cfe/trunk: Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/DeclObjC.h include/clang/Basic/DiagnosticKinds.def test/Sema/method-undef-category-warn-1.m test/Sema/method-undefined-warn-1.m test/Sema/undef-protocol-methods-1.m

Fariborz Jahanian fjahanian at apple.com
Tue Oct 2 13:06:02 PDT 2007


Author: fjahanian
Date: Tue Oct  2 15:06:01 2007
New Revision: 42544

URL: http://llvm.org/viewvc/llvm-project?rev=42544&view=rev
Log:
Previously, I warned those methods not implemented in implementation class/category.
Now, I also warn those class/categories which are incomplete because of this.

Modified:
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/test/Sema/method-undef-category-warn-1.m
    cfe/trunk/test/Sema/method-undefined-warn-1.m
    cfe/trunk/test/Sema/undef-protocol-methods-1.m

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Oct  2 15:06:01 2007
@@ -212,6 +212,7 @@
   /// CheckProtocolMethodDefs - This routine checks unimpletented methods
   /// Declared in protocol, and those referenced by it.
   void CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl,
+                               bool& IncompleteImpl,
                                const llvm::DenseMap<void *, char>& InsMap,
                                const llvm::DenseMap<void *, char>& ClsMap);
   
@@ -223,7 +224,7 @@
   /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
   /// category interface is implemented in the category @implementation.
   void ImplCategoryMethodsVsIntfMethods(ObjcCategoryImplDecl *CatImplDecl,
-                                         ObjcCategoryDecl *CatClassDecl);
+                                        ObjcCategoryDecl *CatClassDecl);
   
   //===--------------------------------------------------------------------===//
   // Statement Parsing Callbacks: SemaStmt.cpp.

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Oct  2 15:06:01 2007
@@ -1216,6 +1216,7 @@
 /// CheckProtocolMethodDefs - This routine checks unimpletented methods
 /// Declared in protocol, and those referenced by it.
 void Sema::CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl,
+                                   bool& IncompleteImpl,
              const llvm::DenseMap<void *, char>& InsMap,
              const llvm::DenseMap<void *, char>& ClsMap) {
   // check unimplemented instance methods.
@@ -1225,6 +1226,7 @@
       llvm::SmallString<128> buf;
       Diag(methods[j]->getLocation(), diag::warn_undef_method_impl,
            methods[j]->getSelector().getName(buf));
+      IncompleteImpl = true;
     }
   // check unimplemented class methods
   methods = PDecl->getClsMethods();
@@ -1233,12 +1235,13 @@
       llvm::SmallString<128> buf;
       Diag(methods[j]->getLocation(), diag::warn_undef_method_impl,
            methods[j]->getSelector().getName(buf));
+      IncompleteImpl = true;
     }
   
   // Check on this protocols's referenced protocols, recursively
   ObjcProtocolDecl** RefPDecl = PDecl->getReferencedProtocols();
   for (int i = 0; i < PDecl->getNumReferencedProtocols(); i++)
-    CheckProtocolMethodDefs(RefPDecl[i], InsMap, ClsMap);
+    CheckProtocolMethodDefs(RefPDecl[i], IncompleteImpl, InsMap, ClsMap);
 }
 
 void Sema::ImplMethodsVsClassMethods(ObjcImplementationDecl* IMPDecl, 
@@ -1251,12 +1254,14 @@
     InsMap[methods[i]->getSelector().getAsOpaquePtr()] = 'a';
   }
   
+  bool IncompleteImpl = false;
   methods = IDecl->getInsMethods();
   for (int j = 0; j < IDecl->getNumInsMethods(); j++)
     if (!InsMap.count(methods[j]->getSelector().getAsOpaquePtr())) {
       llvm::SmallString<128> buf;
       Diag(methods[j]->getLocation(), diag::warn_undef_method_impl,
            methods[j]->getSelector().getName(buf));
+      IncompleteImpl = true;
     }
   llvm::DenseMap<void *, char> ClsMap;
   // Check and see if class methods in class interface have been
@@ -1272,6 +1277,7 @@
       llvm::SmallString<128> buf;
       Diag(methods[j]->getLocation(), diag::warn_undef_method_impl,
            methods[j]->getSelector().getName(buf));
+      IncompleteImpl = true;
     }
   
   // Check the protocol list for unimplemented methods in the @implementation
@@ -1279,8 +1285,11 @@
   ObjcProtocolDecl** protocols = IDecl->getIntfRefProtocols();
   for (int i = 0; i < IDecl->getNumIntfRefProtocols(); i++) {
     ObjcProtocolDecl* PDecl = protocols[i];
-    CheckProtocolMethodDefs(PDecl, InsMap, ClsMap);
+    CheckProtocolMethodDefs(PDecl, IncompleteImpl, InsMap, ClsMap);
   }
+  if (IncompleteImpl)
+    Diag(IDecl->getLocation(), diag::warn_incomplete_impl_class, 
+         IDecl->getName());
 }
 
 /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
@@ -1295,12 +1304,14 @@
     InsMap[methods[i]->getSelector().getAsOpaquePtr()] = 'a';
   }
   
+  bool IncompleteImpl = false;
   methods = CatClassDecl->getCatInsMethods();
   for (int j = 0; j < CatClassDecl->getNumCatInsMethods(); j++)
     if (!InsMap.count(methods[j]->getSelector().getAsOpaquePtr())) {
       llvm::SmallString<128> buf;
       Diag(methods[j]->getLocation(), diag::warn_undef_method_impl,
            methods[j]->getSelector().getName(buf));
+      IncompleteImpl = true;
     }
   llvm::DenseMap<void *, char> ClsMap;
   // Check and see if class methods in category interface have been
@@ -1316,6 +1327,7 @@
       llvm::SmallString<128> buf;
       Diag(methods[j]->getLocation(), diag::warn_undef_method_impl,
            methods[j]->getSelector().getName(buf));
+      IncompleteImpl = true;
     }
   
   // Check the protocol list for unimplemented methods in the @implementation
@@ -1323,9 +1335,11 @@
   ObjcProtocolDecl** protocols = CatClassDecl->getCatReferencedProtocols();
   for (int i = 0; i < CatClassDecl->getNumCatReferencedProtocols(); i++) {
     ObjcProtocolDecl* PDecl = protocols[i];
-    CheckProtocolMethodDefs(PDecl, InsMap, ClsMap);
+    CheckProtocolMethodDefs(PDecl, IncompleteImpl, InsMap, ClsMap);
   }
-  
+  if (IncompleteImpl)
+    Diag(CatClassDecl->getCatLoc(), diag::warn_incomplete_impl_category, 
+         CatClassDecl->getCatName()->getName());
 }
 
 /// ObjcClassDeclaration - 

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Tue Oct  2 15:06:01 2007
@@ -424,6 +424,9 @@
   
   /// Next category belonging to this class
   ObjcCategoryDecl *NextClassCategory;
+  
+  /// Location of cetagory declaration
+  SourceLocation CatLoc;
 
 public:
   ObjcCategoryDecl(SourceLocation L, unsigned numRefProtocol)
@@ -432,7 +435,7 @@
       CatReferencedProtocols(0), NumCatReferencedProtocols(-1),
       CatInsMethods(0), NumCatInsMethods(-1),
       CatClsMethods(0), NumCatClsMethods(-1),
-      NextClassCategory(0) {
+      NextClassCategory(0), CatLoc(L) {
         if (numRefProtocol) {
           CatReferencedProtocols = new ObjcProtocolDecl*[numRefProtocol];
           memset(CatReferencedProtocols, '\0', 
@@ -471,7 +474,9 @@
     NextClassCategory = ClassInterface->getListCategories();
     ClassInterface->setListCategories(this);
   }
-
+  
+  SourceLocation getCatLoc() const { return CatLoc; }
+  
   static bool classof(const Decl *D) {
     return D->getKind() == ObjcCategory;
   }
@@ -517,7 +522,6 @@
   ObjcMethodDecl **getCatClsMethods() const { return CatClsMethods; }
   int getNumCatClsMethods() const { return NumCatClsMethods; }
   
-  
   void ObjcAddCatImplMethods(
         ObjcMethodDecl **insMethods, unsigned numInsMembers,
         ObjcMethodDecl **clsMethods, unsigned numClsMembers);

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=42544&r1=42543&r2=42544&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Oct  2 15:06:01 2007
@@ -434,6 +434,11 @@
      "conflicting instance variable type")
 DIAG(warn_undef_method_impl, WARNING,
      "method definition for '%0' not found")
+DIAG(warn_incomplete_impl_class, WARNING,
+     "incomplete implementation of class '%0'")
+DIAG(warn_incomplete_impl_category, WARNING,
+     "incomplete implementation of category '%0'")
+
 
 //===----------------------------------------------------------------------===//
 // Semantic Analysis

Modified: cfe/trunk/test/Sema/method-undef-category-warn-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/method-undef-category-warn-1.m?rev=42544&r1=42543&r2=42544&view=diff

==============================================================================
--- cfe/trunk/test/Sema/method-undef-category-warn-1.m (original)
+++ cfe/trunk/test/Sema/method-undef-category-warn-1.m Tue Oct  2 15:06:01 2007
@@ -12,7 +12,7 @@
 
 @implementation MyClass1(CAT)
 - (void) Pmeth1{}
- at end
+ at end  // expected-warning {{incomplete implementation of category 'CAT'}}
 
 @interface MyClass1(DOG) <P>
 - (void)ppp;  // expected-warning {{method definition for 'ppp' not found}}
@@ -20,7 +20,7 @@
 
 @implementation MyClass1(DOG)
 - (void) Pmeth {}
- at end
+ at end  // expected-warning {{incomplete implementation of category 'DOG'}}
 
 @implementation MyClass1(CAT1)
 @end

Modified: cfe/trunk/test/Sema/method-undefined-warn-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/method-undefined-warn-1.m?rev=42544&r1=42543&r2=42544&view=diff

==============================================================================
--- cfe/trunk/test/Sema/method-undefined-warn-1.m (original)
+++ cfe/trunk/test/Sema/method-undefined-warn-1.m Tue Oct  2 15:06:01 2007
@@ -10,7 +10,7 @@
 - (void) meth {}
 - (void) meth : (int) arg2{}
 - (void) cls_meth1 : (int) arg2{}
- at end
+ at end	// expected-warning {{incomplete implementation of class 'INTF'}}
 
 
 @interface INTF1
@@ -25,7 +25,7 @@
 - (void) meth {}
 - (void) meth : (int) arg2{}
 - (void) cls_meth1 : (int) arg2{}
- at end
+ at end // expected-warning {{incomplete implementation of class 'INTF1'}}
 
 
 @interface INTF2

Modified: cfe/trunk/test/Sema/undef-protocol-methods-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/undef-protocol-methods-1.m?rev=42544&r1=42543&r2=42544&view=diff

==============================================================================
--- cfe/trunk/test/Sema/undef-protocol-methods-1.m (original)
+++ cfe/trunk/test/Sema/undef-protocol-methods-1.m Tue Oct  2 15:06:01 2007
@@ -28,4 +28,4 @@
 
 + (void) DefClsP3Proto{}
 
- at end
+ at end // expected-warning {{ncomplete implementation of class 'INTF'}}





More information about the cfe-commits mailing list