// 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);
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");
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
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);
}
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);
}
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);
}