]> granicus.if.org Git - clang/commitdiff
Add a diagnostics helper to remove some redundant code.
authorSteve Naroff <snaroff@apple.com>
Sun, 10 Feb 2008 21:38:56 +0000 (21:38 +0000)
committerSteve Naroff <snaroff@apple.com>
Sun, 10 Feb 2008 21:38:56 +0000 (21:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46936 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/Sema.h
Sema/SemaDeclObjC.cpp

index e36049354c0360749fcd68964ccf57401b2f80ca..348f83b7a23af1b4c494d6dca14d13559f4de6f3 100644 (file)
@@ -268,6 +268,9 @@ private:
   
   void HandleAlignedAttribute(Decl *d, AttributeList *rawAttr);
     
+  void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
+                           bool &IncompleteImpl);
+                           
   /// CheckProtocolMethodDefs - This routine checks unimpletented methods
   /// Declared in protocol, and those referenced by it.
   void CheckProtocolMethodDefs(SourceLocation ImpLoc,
@@ -280,7 +283,7 @@ private:
   /// listed in the implelementation match those listed in the interface. 
   void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
                                 ObjCIvarDecl **Fields, unsigned nIvars,
-                               SourceLocation Loc);
+                                SourceLocation Loc);
   
   /// ImplMethodsVsClassMethods - This is main routine to warn if any method
   /// remains unimplemented in the @implementation class.
index 824557f4c585c9ff2376e4e52a6867674817b47a..8d5457154c910abaf226e2ae518af98143940179 100644 (file)
@@ -457,6 +457,15 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
     Diag((*IVI)->getLocation(), diag::err_inconsistant_ivar_count);
 }
 
+void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
+                               bool &IncompleteImpl) {
+  if (!IncompleteImpl) {
+    Diag(ImpLoc, diag::warn_incomplete_impl);
+    IncompleteImpl = true;
+  }
+  Diag(ImpLoc, diag::warn_undef_method_impl, method->getSelector().getName());
+}
+
 /// CheckProtocolMethodDefs - This routine checks unimplemented methods
 /// Declared in protocol, and those referenced by it.
 void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
@@ -469,28 +478,16 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
        E = PDecl->instmeth_end(); I != E; ++I) {
     ObjCMethodDecl *method = *I;
     if (!InsMap.count(method->getSelector()) && 
-        method->getImplementationControl() != ObjCMethodDecl::Optional) {
-      if (!IncompleteImpl) {
-        Diag(ImpLoc, diag::warn_incomplete_impl);
-        IncompleteImpl = true;
-      }
-      Diag(ImpLoc, diag::warn_undef_method_impl,
-           method->getSelector().getName());
-    }
+        method->getImplementationControl() != ObjCMethodDecl::Optional)
+      WarnUndefinedMethod(ImpLoc, method, IncompleteImpl);
   }
   // check unimplemented class methods
   for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(), 
        E = PDecl->classmeth_end(); I != E; ++I) {
     ObjCMethodDecl *method = *I;
     if (!ClsMap.count(method->getSelector()) &&
-        method->getImplementationControl() != ObjCMethodDecl::Optional) {
-      if (!IncompleteImpl) {
-        Diag(ImpLoc, diag::warn_incomplete_impl);
-        IncompleteImpl = true;
-      }
-      Diag(ImpLoc, diag::warn_undef_method_impl,
-           method->getSelector().getName());
-    }
+        method->getImplementationControl() != ObjCMethodDecl::Optional)
+      WarnUndefinedMethod(ImpLoc, method, IncompleteImpl);
   }
   // Check on this protocols's referenced protocols, recursively
   ObjCProtocolDecl** RefPDecl = PDecl->getReferencedProtocols();
@@ -510,14 +507,8 @@ void Sema::ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl,
   bool IncompleteImpl = false;
   for (ObjCInterfaceDecl::instmeth_iterator I = IDecl->instmeth_begin(),
        E = IDecl->instmeth_end(); I != E; ++I)
-    if (!InsMap.count((*I)->getSelector())) {
-      if (!IncompleteImpl) {
-        Diag(IMPDecl->getLocation(), diag::warn_incomplete_impl);
-        IncompleteImpl = true;
-      }
-      Diag(IMPDecl->getLocation(), diag::warn_undef_method_impl, 
-           (*I)->getSelector().getName());
-    }
+    if (!InsMap.count((*I)->getSelector()))
+      WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl);
       
   llvm::DenseSet<Selector> ClsMap;
   // Check and see if class methods in class interface have been
@@ -528,14 +519,8 @@ void Sema::ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl,
   
   for (ObjCInterfaceDecl::classmeth_iterator I = IDecl->classmeth_begin(),
        E = IDecl->classmeth_end(); I != E; ++I)
-    if (!ClsMap.count((*I)->getSelector())) {
-      if (!IncompleteImpl) {
-        Diag(IMPDecl->getLocation(), diag::warn_incomplete_impl);
-        IncompleteImpl = true;
-      }
-      Diag(IMPDecl->getLocation(), diag::warn_undef_method_impl,
-           (*I)->getSelector().getName());
-    }
+    if (!ClsMap.count((*I)->getSelector()))
+      WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl);
   
   // Check the protocol list for unimplemented methods in the @implementation
   // class.
@@ -559,14 +544,9 @@ void Sema::ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl,
   bool IncompleteImpl = false;
   for (ObjCCategoryDecl::instmeth_iterator I = CatClassDecl->instmeth_begin(),
        E = CatClassDecl->instmeth_end(); I != E; ++I)
-    if (!InsMap.count((*I)->getSelector())) {
-      if (!IncompleteImpl) {
-        Diag(CatImplDecl->getLocation(), diag::warn_incomplete_impl);
-        IncompleteImpl = true;
-      }
-      Diag(CatImplDecl->getLocation(), diag::warn_undef_method_impl,
-           (*I)->getSelector().getName());
-    }
+    if (!InsMap.count((*I)->getSelector()))
+      WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl);
+
   llvm::DenseSet<Selector> ClsMap;
   // Check and see if class methods in category interface have been
   // implemented in its implementation class.
@@ -577,14 +557,8 @@ void Sema::ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl,
   
   for (ObjCCategoryDecl::classmeth_iterator I = CatClassDecl->classmeth_begin(),
        E = CatClassDecl->classmeth_end(); I != E; ++I)
-    if (!ClsMap.count((*I)->getSelector())) {
-      if (!IncompleteImpl) {
-        Diag(CatImplDecl->getLocation(), diag::warn_incomplete_impl);
-        IncompleteImpl = true;
-      }
-      Diag(CatImplDecl->getLocation(), diag::warn_undef_method_impl,
-           (*I)->getSelector().getName());
-    }
+    if (!ClsMap.count((*I)->getSelector()))
+      WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl);
   
   // Check the protocol list for unimplemented methods in the @implementation
   // class.