[cfe-commits] r56079 - in /cfe/trunk/lib/Sema: Sema.h SemaExprObjC.cpp

Daniel Dunbar daniel at zuster.org
Wed Sep 10 17:01:56 PDT 2008


Author: ddunbar
Date: Wed Sep 10 19:01:56 2008
New Revision: 56079

URL: http://llvm.org/viewvc/llvm-project?rev=56079&view=rev
Log:
Refactor common Obj-C message send checking code into
CheckMessageArgumentTypes.
 - No functionality change.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=56079&r1=56078&r2=56079&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Sep 10 19:01:56 2008
@@ -961,9 +961,14 @@
   // returns true if the cast is invalid
   bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
   
-  // returns true if there were any incompatible arguments.                           
-  bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
-                                 ObjCMethodDecl *Method);
+  /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 
+  /// \param Method - May be null.
+  /// \param [out] ReturnType - The return type of the send.
+  /// \return true iff there were any incompatible types.
+  bool CheckMessageArgumentTypes(Expr **Args, Selector Sel,
+                                 ObjCMethodDecl *Method, const char *PrefixStr,
+                                 SourceLocation lbrac, SourceLocation rbrac,
+                                 QualType &ReturnType);  
 
   /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
   bool CheckCXXBooleanCondition(Expr *&CondExpr);

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=56079&r1=56078&r2=56079&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Sep 10 19:01:56 2008
@@ -107,10 +107,22 @@
   return new ObjCProtocolExpr(t, PDecl, AtLoc, RParenLoc);
 }
 
-bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
-                                     ObjCMethodDecl *Method) {
+bool Sema::CheckMessageArgumentTypes(Expr **Args, Selector Sel,
+                                     ObjCMethodDecl *Method, 
+                                     const char *PrefixStr,
+                                     SourceLocation lbrac, SourceLocation rbrac,
+                                     QualType &ReturnType) {  
+  unsigned NumArgs = Sel.getNumArgs();  
+  if (!Method) {
+    Diag(lbrac, diag::warn_method_not_found, std::string(PrefixStr),
+         Sel.getName(), SourceRange(lbrac, rbrac));
+    ReturnType = Context.getObjCIdType();
+    return false;
+  } else {
+    ReturnType = Method->getResultType();
+  }
+   
   bool anyIncompatibleArgs = false;
-  
   for (unsigned i = 0; i < NumArgs; i++) {
     Expr *argExpr = Args[i];
     assert(argExpr && "CheckMessageArgumentTypes(): missing expression");
@@ -204,17 +216,9 @@
   if (!Method)
     Method = ClassDecl->lookupInstanceMethod(Sel);
 
-  if (!Method) {
-    Diag(lbrac, diag::warn_method_not_found, std::string("+"), Sel.getName(),
-         SourceRange(lbrac, rbrac));
-    returnType = Context.getObjCIdType();
-  } else {
-    returnType = Method->getResultType();
-    if (Sel.getNumArgs()) {
-      if (CheckMessageArgumentTypes(ArgExprs, Sel.getNumArgs(), Method))
-        return true;
-    }
-  }
+  if (CheckMessageArgumentTypes(ArgExprs, Sel, Method, "+", 
+                                lbrac, rbrac, returnType))
+    return true;
 
   // If we have the ObjCInterfaceDecl* for the class that is receiving
   // the message, use that to construct the ObjCMessageExpr.  Otherwise
@@ -251,16 +255,9 @@
     ObjCMethodDecl *Method = InstanceMethodPool[Sel].Method;
     if (!Method)
       Method = FactoryMethodPool[Sel].Method;
-    if (!Method) {
-      Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(),
-           SourceRange(lbrac, rbrac));
-      returnType = Context.getObjCIdType();
-    } else {
-      returnType = Method->getResultType();
-      if (Sel.getNumArgs())
-        if (CheckMessageArgumentTypes(ArgExprs, Sel.getNumArgs(), Method))
-          return true;
-    }
+    if (CheckMessageArgumentTypes(ArgExprs, Sel, Method, "-", 
+                                  lbrac, rbrac, returnType))
+      return true;
     return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
                                ArgExprs, NumArgs);
   }
@@ -279,17 +276,9 @@
       Method = FactoryMethodPool[Sel].Method;
     if (!Method)
       Method = InstanceMethodPool[Sel].Method;
-    if (!Method) {
-      Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(),
-           RExpr->getSourceRange());
-      returnType = Context.getObjCIdType();
-    } else {
-      returnType = Method->getResultType();
-      if (Sel.getNumArgs())
-        if (CheckMessageArgumentTypes(ArgExprs, Sel.getNumArgs(), Method))
-          return true;
-    }
-
+    if (CheckMessageArgumentTypes(ArgExprs, Sel, Method, "-", 
+                                  lbrac, rbrac, returnType))
+      return true;
     return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
                                ArgExprs, NumArgs);
   }
@@ -351,16 +340,9 @@
         if (!Method)
           Method = InstanceMethodPool[Sel].Method;
   }
-  if (!Method) {
-    Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(),
-         SourceRange(lbrac, rbrac));
-    returnType = Context.getObjCIdType();
-  } else {
-    returnType = Method->getResultType();
-    if (Sel.getNumArgs())
-      if (CheckMessageArgumentTypes(ArgExprs, Sel.getNumArgs(), Method))
-        return true;
-  }
+  if (CheckMessageArgumentTypes(ArgExprs, Sel, Method, "-", 
+                                lbrac, rbrac, returnType))
+    return true;
   return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
                              ArgExprs, NumArgs);
 }





More information about the cfe-commits mailing list