]> granicus.if.org Git - clang/commitdiff
Refactor common Obj-C message send checking code into
authorDaniel Dunbar <daniel@zuster.org>
Thu, 11 Sep 2008 00:01:56 +0000 (00:01 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 11 Sep 2008 00:01:56 +0000 (00:01 +0000)
CheckMessageArgumentTypes.
 - No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56079 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaExprObjC.cpp

index 3fc152a5f04f1b2ed4c8e65af5c2bea74076dcca..a88ce8e3dbe9fcb68e77cc73d1c1854856ca3437 100644 (file)
@@ -961,9 +961,14 @@ private:
   // 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);
index 7c2f45b6db4465a64085d7e5cf00faf9d5fdadf3..0d3bc298400b966f4e28f7f63bbfc9f98e6fe2a1 100644 (file)
@@ -107,10 +107,22 @@ Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId,
   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 @@ Sema::ExprResult Sema::ActOnClassMessage(
   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 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
     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 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
       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 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
         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);
 }