[cfe-commits] r46897 - in /cfe/trunk: Driver/TextDiagnosticPrinter.cpp Driver/TextDiagnosticPrinter.h Sema/Sema.h Sema/SemaDeclObjC.cpp 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

Steve Naroff snaroff at apple.com
Fri Feb 8 14:06:17 PST 2008


Author: snaroff
Date: Fri Feb  8 16:06:17 2008
New Revision: 46897

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

A bunch-o changes to fix <rdar://problem/5716046> incomplete implementation of ObjC class warning is incomplete

As part of this fix, I made a low-level change to the text diagnostics machinery (to basically avoid printing duplicate source lines/carets when you have multiple diagnostics that refer to the same exact place). For now, this only happens with we don't have a source range (could be extended to support source ranges as well). 

Modified:
    cfe/trunk/Driver/TextDiagnosticPrinter.cpp
    cfe/trunk/Driver/TextDiagnosticPrinter.h
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDeclObjC.cpp
    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/Driver/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.cpp?rev=46897&r1=46896&r2=46897&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.cpp Fri Feb  8 16:06:17 2008
@@ -159,7 +159,10 @@
   
   llvm::cerr << FormatDiagnostic(Diags, Level, ID, Strs, NumStrs) << "\n";
   
-  if (!NoCaretDiagnostics && Pos.isValid()) {
+  if (!NoCaretDiagnostics && Pos.isValid() && ((LastLoc != Pos) && !Ranges)) {
+    // Cache the LastLoc, it allows us to omit duplicate source/caret spewage.
+    LastLoc = Pos;
+    
     // Get the line of the source file.
     std::string SourceLine(LineStart, LineEnd);
     

Modified: cfe/trunk/Driver/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.h?rev=46897&r1=46896&r2=46897&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.h Fri Feb  8 16:06:17 2008
@@ -23,6 +23,7 @@
 
 class TextDiagnosticPrinter : public TextDiagnostics {
   FullSourceLoc LastWarningLoc;
+  FullSourceLoc LastLoc;
 public:
   TextDiagnosticPrinter() {}
 

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Fri Feb  8 16:06:17 2008
@@ -270,7 +270,8 @@
     
   /// CheckProtocolMethodDefs - This routine checks unimpletented methods
   /// Declared in protocol, and those referenced by it.
-  void CheckProtocolMethodDefs(ObjCProtocolDecl *PDecl,
+  void CheckProtocolMethodDefs(SourceLocation ImpLoc,
+                               ObjCProtocolDecl *PDecl,
                                bool& IncompleteImpl,
                                const llvm::DenseSet<Selector> &InsMap,
                                const llvm::DenseSet<Selector> &ClsMap);

Modified: cfe/trunk/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDeclObjC.cpp?rev=46897&r1=46896&r2=46897&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/Sema/SemaDeclObjC.cpp Fri Feb  8 16:06:17 2008
@@ -457,21 +457,25 @@
     Diag((*IVI)->getLocation(), diag::err_inconsistant_ivar_count);
 }
 
-/// CheckProtocolMethodDefs - This routine checks unimpletented methods
+/// CheckProtocolMethodDefs - This routine checks unimplemented methods
 /// Declared in protocol, and those referenced by it.
-void Sema::CheckProtocolMethodDefs(ObjCProtocolDecl *PDecl,
+void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
+                                   ObjCProtocolDecl *PDecl,
                                    bool& IncompleteImpl,
-             const llvm::DenseSet<Selector> &InsMap,
-             const llvm::DenseSet<Selector> &ClsMap) {
+                                   const llvm::DenseSet<Selector> &InsMap,
+                                   const llvm::DenseSet<Selector> &ClsMap) {
   // check unimplemented instance methods.
   for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), 
        E = PDecl->instmeth_end(); I != E; ++I) {
     ObjCMethodDecl *method = *I;
     if (!InsMap.count(method->getSelector()) && 
         method->getImplementationControl() != ObjCMethodDecl::Optional) {
-      Diag(method->getLocation(), diag::warn_undef_method_impl,
+      if (!IncompleteImpl) {
+        Diag(ImpLoc, diag::warn_incomplete_impl);
+        IncompleteImpl = true;
+      }
+      Diag(ImpLoc, diag::warn_undef_method_impl,
            method->getSelector().getName());
-      IncompleteImpl = true;
     }
   }
   // check unimplemented class methods
@@ -480,15 +484,18 @@
     ObjCMethodDecl *method = *I;
     if (!ClsMap.count(method->getSelector()) &&
         method->getImplementationControl() != ObjCMethodDecl::Optional) {
-      Diag(method->getLocation(), diag::warn_undef_method_impl,
+      if (!IncompleteImpl) {
+        Diag(ImpLoc, diag::warn_incomplete_impl);
+        IncompleteImpl = true;
+      }
+      Diag(ImpLoc, diag::warn_undef_method_impl,
            method->getSelector().getName());
-      IncompleteImpl = true;
     }
   }
   // Check on this protocols's referenced protocols, recursively
   ObjCProtocolDecl** RefPDecl = PDecl->getReferencedProtocols();
   for (unsigned i = 0; i < PDecl->getNumReferencedProtocols(); i++)
-    CheckProtocolMethodDefs(RefPDecl[i], IncompleteImpl, InsMap, ClsMap);
+    CheckProtocolMethodDefs(ImpLoc, RefPDecl[i], IncompleteImpl, InsMap, ClsMap);
 }
 
 void Sema::ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl, 
@@ -504,9 +511,12 @@
   for (ObjCInterfaceDecl::instmeth_iterator I = IDecl->instmeth_begin(),
        E = IDecl->instmeth_end(); I != E; ++I)
     if (!InsMap.count((*I)->getSelector())) {
-      Diag((*I)->getLocation(), diag::warn_undef_method_impl,
+      if (!IncompleteImpl) {
+        Diag(IMPDecl->getLocation(), diag::warn_incomplete_impl);
+        IncompleteImpl = true;
+      }
+      Diag(IMPDecl->getLocation(), diag::warn_undef_method_impl, 
            (*I)->getSelector().getName());
-      IncompleteImpl = true;
     }
       
   llvm::DenseSet<Selector> ClsMap;
@@ -519,20 +529,20 @@
   for (ObjCInterfaceDecl::classmeth_iterator I = IDecl->classmeth_begin(),
        E = IDecl->classmeth_end(); I != E; ++I)
     if (!ClsMap.count((*I)->getSelector())) {
-      Diag((*I)->getLocation(), diag::warn_undef_method_impl,
+      if (!IncompleteImpl) {
+        Diag(IMPDecl->getLocation(), diag::warn_incomplete_impl);
+        IncompleteImpl = true;
+      }
+      Diag(IMPDecl->getLocation(), diag::warn_undef_method_impl,
            (*I)->getSelector().getName());
-      IncompleteImpl = true;
     }
   
   // Check the protocol list for unimplemented methods in the @implementation
   // class.
   ObjCProtocolDecl** protocols = IDecl->getReferencedProtocols();
   for (unsigned i = 0; i < IDecl->getNumIntfRefProtocols(); i++)
-    CheckProtocolMethodDefs(protocols[i], IncompleteImpl, InsMap, ClsMap);
-
-  if (IncompleteImpl)
-    Diag(IMPDecl->getLocation(), diag::warn_incomplete_impl_class, 
-         IMPDecl->getName());
+    CheckProtocolMethodDefs(IMPDecl->getLocation(), protocols[i], 
+                            IncompleteImpl, InsMap, ClsMap);
 }
 
 /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
@@ -550,9 +560,12 @@
   for (ObjCCategoryDecl::instmeth_iterator I = CatClassDecl->instmeth_begin(),
        E = CatClassDecl->instmeth_end(); I != E; ++I)
     if (!InsMap.count((*I)->getSelector())) {
-      Diag((*I)->getLocation(), diag::warn_undef_method_impl,
+      if (!IncompleteImpl) {
+        Diag(CatImplDecl->getLocation(), diag::warn_incomplete_impl);
+        IncompleteImpl = true;
+      }
+      Diag(CatImplDecl->getLocation(), diag::warn_undef_method_impl,
            (*I)->getSelector().getName());
-      IncompleteImpl = true;
     }
   llvm::DenseSet<Selector> ClsMap;
   // Check and see if class methods in category interface have been
@@ -565,9 +578,12 @@
   for (ObjCCategoryDecl::classmeth_iterator I = CatClassDecl->classmeth_begin(),
        E = CatClassDecl->classmeth_end(); I != E; ++I)
     if (!ClsMap.count((*I)->getSelector())) {
-      Diag((*I)->getLocation(), diag::warn_undef_method_impl,
+      if (!IncompleteImpl) {
+        Diag(CatImplDecl->getLocation(), diag::warn_incomplete_impl);
+        IncompleteImpl = true;
+      }
+      Diag(CatImplDecl->getLocation(), diag::warn_undef_method_impl,
            (*I)->getSelector().getName());
-      IncompleteImpl = true;
     }
   
   // Check the protocol list for unimplemented methods in the @implementation
@@ -575,11 +591,9 @@
   ObjCProtocolDecl** protocols = CatClassDecl->getReferencedProtocols();
   for (unsigned i = 0; i < CatClassDecl->getNumReferencedProtocols(); i++) {
     ObjCProtocolDecl* PDecl = protocols[i];
-    CheckProtocolMethodDefs(PDecl, IncompleteImpl, InsMap, ClsMap);
+    CheckProtocolMethodDefs(CatImplDecl->getLocation(), PDecl, IncompleteImpl, 
+                            InsMap, ClsMap);
   }
-  if (IncompleteImpl)
-    Diag(CatImplDecl->getLocation(), diag::warn_incomplete_impl_category, 
-         CatClassDecl->getName());
 }
 
 /// ActOnForwardClassDeclaration - 

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Feb  8 16:06:17 2008
@@ -446,10 +446,8 @@
      "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'")
+DIAG(warn_incomplete_impl, WARNING,
+     "incomplete implementation")
 DIAG(error_duplicate_method_decl, ERROR,
      "duplicate declaration of method '%0'")
 DIAG(err_previous_declaration, ERROR,

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=46897&r1=46896&r2=46897&view=diff

==============================================================================
--- cfe/trunk/test/Sema/method-undef-category-warn-1.m (original)
+++ cfe/trunk/test/Sema/method-undef-category-warn-1.m Fri Feb  8 16:06:17 2008
@@ -4,23 +4,27 @@
 @end
 
 @protocol P
-- (void) Pmeth;	// expected-warning {{method definition for 'Pmeth' not found}}
-- (void) Pmeth1; // expected-warning {{method definition for 'Pmeth1' not found}}
+- (void) Pmeth;	
+- (void) Pmeth1;  
 @end
 
 @interface MyClass1(CAT) <P>
-- (void) meth2;	// expected-warning {{method definition for 'meth2' not found}}
+- (void) meth2;	
 @end
 
- at implementation MyClass1(CAT) // expected-warning {{incomplete implementation of category 'CAT'}}
+ at implementation MyClass1(CAT) // expected-warning {{incomplete implementation}} \
+                                 expected-warning {{method definition for 'meth2' not found}} \
+                                 expected-warning {{method definition for 'Pmeth' not found}}
 - (void) Pmeth1{}
 @end
 
 @interface MyClass1(DOG) <P>
-- (void)ppp;  // expected-warning {{method definition for 'ppp' not found}}
+- (void)ppp;   
 @end
 
- at implementation MyClass1(DOG) // expected-warning {{incomplete implementation of category 'DOG'}}
+ at implementation MyClass1(DOG) // expected-warning {{incomplete implementation}} \
+                                 expected-warning {{method definition for 'ppp' not found}} \
+                                 expected-warning {{method definition for 'Pmeth1' not found}}
 - (void) Pmeth {}
 @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=46897&r1=46896&r2=46897&view=diff

==============================================================================
--- cfe/trunk/test/Sema/method-undefined-warn-1.m (original)
+++ cfe/trunk/test/Sema/method-undefined-warn-1.m Fri Feb  8 16:06:17 2008
@@ -3,12 +3,12 @@
 @interface INTF
 - (void) meth;
 - (void) meth : (int) arg1;
-- (int)  int_meth;	// expected-warning {{method definition for 'int_meth' not found}}
-+ (int) cls_meth;	// expected-warning {{method definition for 'cls_meth' not found}}
-+ (void) cls_meth1 : (int) arg1; // expected-warning {{method definition for 'cls_meth1:' not found}}
+- (int)  int_meth; 
++ (int) cls_meth;
++ (void) cls_meth1 : (int) arg1; 
 @end
 
- at implementation INTF 	// expected-warning {{incomplete implementation of class 'INTF'}}
+ at implementation INTF 	// expected-warning {{incomplete implementation}} expected-warning {{method definition for 'int_meth' not found}} expected-warning {{method definition for 'cls_meth' not found}} expected-warning {{method definition for 'cls_meth1:' not found}}
 - (void) meth {}
 - (void) meth : (int) arg2{}
 - (void) cls_meth1 : (int) arg2{}
@@ -17,12 +17,12 @@
 @interface INTF1
 - (void) meth;
 - (void) meth : (int) arg1;
-- (int)  int_meth;      // expected-warning {{method definition for 'int_meth' not found}}
-+ (int) cls_meth;       // expected-warning {{method definition for 'cls_meth' not found}}
-+ (void) cls_meth1 : (int) arg1; // expected-warning {{method definition for 'cls_meth1:' not found}}
+- (int)  int_meth;      
++ (int) cls_meth;       
++ (void) cls_meth1 : (int) arg1; 
 @end
 
- at implementation INTF1 // expected-warning {{incomplete implementation of class 'INTF1'}}
+ at implementation INTF1 // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'int_meth' not found}} expected-warning {{method definition for 'cls_meth' not found}} expected-warning {{method definition for 'cls_meth1:' not found}}
 - (void) meth {}
 - (void) meth : (int) arg2{}
 - (void) cls_meth1 : (int) arg2{}

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=46897&r1=46896&r2=46897&view=diff

==============================================================================
--- cfe/trunk/test/Sema/undef-protocol-methods-1.m (original)
+++ cfe/trunk/test/Sema/undef-protocol-methods-1.m Fri Feb  8 16:06:17 2008
@@ -1,31 +1,40 @@
 // RUN: clang -fsyntax-only -verify %s
 
 @protocol P1
-- (void) P1proto; // expected-warning {{method definition for 'P1proto' not found}}
-+ (void) ClsP1Proto; // expected-warning {{method definition for 'ClsP1Proto' not found}}
+- (void) P1proto;
++ (void) ClsP1Proto;  
 - (void) DefP1proto;
 @end
 @protocol P2
-- (void) P2proto;  // expected-warning {{method definition for 'P2proto' not found}}
-+ (void) ClsP2Proto; // expected-warning {{method definition for 'ClsP2Proto' not found}}
+- (void) P2proto;  
++ (void) ClsP2Proto; 
 @end
 
 @protocol P3<P2>
-- (void) P3proto; // expected-warning {{method definition for 'P3proto' not found}}
-+ (void) ClsP3Proto; // expected-warning {{method definition for 'ClsP3Proto' not found}}
+- (void) P3proto; 
++ (void) ClsP3Proto; 
 + (void) DefClsP3Proto;
 @end
 
 @protocol PROTO<P1, P3>
-- (void) meth;			// expected-warning {{method definition for 'meth' not found}}
-- (void) meth : (int) arg1;	// expected-warning {{method definition for 'meth:' not found}}
-+ (void) cls_meth : (int) arg1; // expected-warning {{method definition for 'cls_meth:' not found}}
+- (void) meth;		
+- (void) meth : (int) arg1; 
++ (void) cls_meth : (int) arg1; 
 @end
 
 @interface INTF <PROTO>
 @end
 
- at implementation INTF   // expected-warning {{incomplete implementation of class 'INTF'}}
+ at implementation INTF   // expected-warning {{incomplete implementation}} \
+                          expected-warning {{method definition for 'meth' not found}} \
+                          expected-warning {{method definition for 'meth:' not found}} \
+                          expected-warning {{method definition for 'cls_meth:' not found}} \
+                          expected-warning {{method definition for 'P3proto' not found}} \
+                          expected-warning {{method definition for 'ClsP3Proto' not found}} \
+                          expected-warning {{method definition for 'P2proto' not found}} \
+                          expected-warning {{method definition for 'ClsP2Proto' not found}} \
+                          expected-warning {{method definition for 'ClsP1Proto' not found}} \
+                          expected-warning {{method definition for 'P1proto' not found}}
 - (void) DefP1proto{}
 
 + (void) DefClsP3Proto{}





More information about the cfe-commits mailing list