From: Steve Naroff Date: Sun, 10 Feb 2008 21:38:56 +0000 (+0000) Subject: Add a diagnostics helper to remove some redundant code. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c2eb66b0acb13c4bdd628e5e148c37958a85ec4;p=clang Add a diagnostics helper to remove some redundant code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46936 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/Sema.h b/Sema/Sema.h index e36049354c..348f83b7a2 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -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. diff --git a/Sema/SemaDeclObjC.cpp b/Sema/SemaDeclObjC.cpp index 824557f4c5..8d5457154c 100644 --- a/Sema/SemaDeclObjC.cpp +++ b/Sema/SemaDeclObjC.cpp @@ -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 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 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.