]> granicus.if.org Git - clang/commitdiff
Refactoring of my last patch.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 8 May 2009 20:20:55 +0000 (20:20 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 8 May 2009 20:20:55 +0000 (20:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71248 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExpr.cpp

index 389d554813b504ea00e52db767cd4781813f667a..30540287ebf913e27a4e1e0d09b47b89d2f005b4 100644 (file)
@@ -1270,6 +1270,9 @@ public:
   // Expression Parsing Callbacks: SemaExpr.cpp.
 
   bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
+  bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 
+                                        ObjCMethodDecl *Getter,
+                                        SourceLocation Loc);
 
   // Primary Expressions.
   virtual SourceRange getExprRange(ExprTy *E) const;
index 34afdedba7da63c4009a059db836c28474af6c73..981d13c15e4de48fdff6f5bfa3f312564784aaea 100644 (file)
 #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) {
@@ -1312,22 +1332,9 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
   
   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)
index f698620543fbb942bd8bcdbaabcef816cbe63f7a..063e0ec314d4517d8eab78eb0b65910caf801309 100644 (file)
@@ -2099,17 +2099,8 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
       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));
     }