#include "clang/Parse/DeclSpec.h"
using namespace clang;
+bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
+ ObjCMethodDecl *GetterMethod,
+ SourceLocation Loc) {
+ if (GetterMethod &&
+ GetterMethod->getResultType() != property->getType()) {
+ AssignConvertType result = Incompatible;
+ if (Context.isObjCObjectPointerType(property->getType()))
+ result = CheckAssignmentConstraints(property->getType(),
+ GetterMethod->getResultType());
+ if (result != Compatible) {
+ Diag(Loc, diag::warn_accessor_property_type_mismatch)
+ << property->getDeclName()
+ << GetterMethod->getSelector();
+ Diag(GetterMethod->getLocation(), diag::note_declared_at);
+ return true;
+ }
+ }
+ return false;
+}
+
/// ActOnStartOfObjCMethodDef - This routine sets up parameters; invisible
/// and user declared, in the method definition's AST.
void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) {
GetterMethod = CD->getInstanceMethod(Context, property->getGetterName());
SetterMethod = CD->getInstanceMethod(Context, property->getSetterName());
-
- if (GetterMethod &&
- GetterMethod->getResultType() != property->getType()) {
- AssignConvertType result = Incompatible;
- if (Context.isObjCObjectPointerType(property->getType()))
- result = CheckAssignmentConstraints(property->getType(),
- GetterMethod->getResultType());
- if (result != Compatible) {
- Diag(property->getLocation(),
- diag::warn_accessor_property_type_mismatch)
- << property->getDeclName()
- << GetterMethod->getSelector();
- Diag(GetterMethod->getLocation(), diag::note_declared_at);
- }
- }
-
+ DiagnosePropertyAccessorMismatch(property, GetterMethod,
+ property->getLocation());
+
if (SetterMethod) {
if (Context.getCanonicalType(SetterMethod->getResultType())
!= Context.VoidTy)
QualType ResTy = PD->getType();
Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Context, Sel);
- if (Getter) {
- AssignConvertType result =
- CheckAssignmentConstraints(PD->getType(), Getter->getResultType());
- if (result != Compatible) {
- Diag(MemberLoc, diag::warn_accessor_property_type_mismatch)
- << PD->getDeclName() << Sel;
- Diag(Getter->getLocation(), diag::note_declared_at);
- ResTy = Getter->getResultType();
- }
- }
-
+ if (DiagnosePropertyAccessorMismatch(PD, Getter, MemberLoc))
+ ResTy = Getter->getResultType();
return Owned(new (Context) ObjCPropertyRefExpr(PD, ResTy,
MemberLoc, BaseExpr));
}