diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2008-12-02 18:39:49 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2008-12-02 18:39:49 +0000 |
commit | f3cd3fd859120d58f745ba545c8da808e12a39ac (patch) | |
tree | 0cc416265b4611a1579d693731d20a31af7b84d4 /lib/Sema/SemaDeclObjC.cpp | |
parent | a44c2789244e1acf0205d00f763d6a7c1212b241 (diff) |
More type-checking of setter/getter methods. This is still
work in prgress.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60430 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclObjC.cpp')
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 3a78024f90..ed87516687 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -855,6 +855,33 @@ void Sema::AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method) { } } +/// diagnosePropertySetterGetterMismatch - Make sure that use-defined +/// setter/getter methods have the property type and issue diagnostics +/// if they don't. +/// +void +Sema::diagnosePropertySetterGetterMismatch(ObjCPropertyDecl *property, + const ObjCMethodDecl *GetterMethod, + const ObjCMethodDecl *SetterMethod) { + if (GetterMethod && + GetterMethod->getResultType() != property->getType()) + Diag(property->getLocation(), + diag::err_accessor_property_type_mismatch) + << property->getDeclName() + << GetterMethod->getSelector().getAsIdentifierInfo(); + + if (SetterMethod) { + if (SetterMethod->getResultType() != Context.VoidPtrTy) + Diag(SetterMethod->getLocation(), diag::err_setter_type_void); + if (SetterMethod->getNumParams() != 1 || + (SetterMethod->getParamDecl(0)->getType() != property->getType())) + Diag(property->getLocation(), + diag::err_accessor_property_type_mismatch) + << property->getDeclName() + << SetterMethod->getSelector().getAsIdentifierInfo(); + } +} + // Note: For class/category implemenations, allMethods/allProperties is // always null. void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, @@ -940,15 +967,21 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, ComparePropertiesInBaseAndSuper(I); MergeProtocolPropertiesIntoClass(I, I); for (ObjCInterfaceDecl::classprop_iterator i = I->classprop_begin(), - e = I->classprop_end(); i != e; ++i) + e = I->classprop_end(); i != e; ++i) { + diagnosePropertySetterGetterMismatch((*i), InsMap[(*i)->getGetterName()], + InsMap[(*i)->getSetterName()]); I->addPropertyMethods(Context, *i, insMethods, InsMap); + } I->addMethods(&insMethods[0], insMethods.size(), &clsMethods[0], clsMethods.size(), AtEndLoc); } else if (ObjCProtocolDecl *P = dyn_cast<ObjCProtocolDecl>(ClassDecl)) { for (ObjCProtocolDecl::classprop_iterator i = P->classprop_begin(), - e = P->classprop_end(); i != e; ++i) + e = P->classprop_end(); i != e; ++i) { + diagnosePropertySetterGetterMismatch((*i), InsMap[(*i)->getGetterName()], + InsMap[(*i)->getSetterName()]); P->addPropertyMethods(Context, *i, insMethods, InsMap); + } P->addMethods(&insMethods[0], insMethods.size(), &clsMethods[0], clsMethods.size(), AtEndLoc); } @@ -958,8 +991,11 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, // FIXME: If we merge properties into class we should probably // merge them into category as well? for (ObjCCategoryDecl::classprop_iterator i = C->classprop_begin(), - e = C->classprop_end(); i != e; ++i) + e = C->classprop_end(); i != e; ++i) { + diagnosePropertySetterGetterMismatch((*i), InsMap[(*i)->getGetterName()], + InsMap[(*i)->getSetterName()]); C->addPropertyMethods(Context, *i, insMethods, InsMap); + } C->addMethods(&insMethods[0], insMethods.size(), &clsMethods[0], clsMethods.size(), AtEndLoc); } |