2008-01-05 01:32:30 +03:00
|
|
|
//===--- SemaExprObjC.cpp - Semantic Analysis for ObjC Expressions --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements semantic analysis for Objective-C expressions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Sema.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
2008-05-30 01:12:08 +04:00
|
|
|
#include "clang/AST/ExprObjC.h"
|
2009-02-18 09:48:40 +03:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2009-03-10 00:12:44 +03:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
|
2008-01-05 01:32:30 +03:00
|
|
|
using namespace clang;
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
|
2009-02-18 09:48:40 +03:00
|
|
|
ExprTy **strings,
|
2008-01-05 01:32:30 +03:00
|
|
|
unsigned NumStrings) {
|
2009-02-18 09:48:40 +03:00
|
|
|
StringLiteral **Strings = reinterpret_cast<StringLiteral**>(strings);
|
|
|
|
|
2009-02-18 09:13:04 +03:00
|
|
|
// Most ObjC strings are formed out of a single piece. However, we *can*
|
|
|
|
// have strings formed out of multiple @ strings with multiple pptokens in
|
|
|
|
// each one, e.g. @"foo" "bar" @"baz" "qux" which need to be turned into one
|
|
|
|
// StringLiteral for ObjCStringLiteral to hold onto.
|
2009-02-18 09:48:40 +03:00
|
|
|
StringLiteral *S = Strings[0];
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 09:13:04 +03:00
|
|
|
// If we have a multi-part string, merge it all together.
|
|
|
|
if (NumStrings != 1) {
|
2008-01-05 01:32:30 +03:00
|
|
|
// Concatenate objc strings.
|
2009-02-18 09:48:40 +03:00
|
|
|
llvm::SmallString<128> StrBuf;
|
|
|
|
llvm::SmallVector<SourceLocation, 8> StrLocs;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 08:49:11 +03:00
|
|
|
for (unsigned i = 0; i != NumStrings; ++i) {
|
2009-02-18 09:48:40 +03:00
|
|
|
S = Strings[i];
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 09:48:40 +03:00
|
|
|
// ObjC strings can't be wide.
|
2009-02-18 09:13:04 +03:00
|
|
|
if (S->isWide()) {
|
|
|
|
Diag(S->getLocStart(), diag::err_cfstring_literal_not_string_constant)
|
|
|
|
<< S->getSourceRange();
|
|
|
|
return true;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 09:48:40 +03:00
|
|
|
// Get the string data.
|
|
|
|
StrBuf.append(S->getStrData(), S->getStrData()+S->getByteLength());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 09:48:40 +03:00
|
|
|
// Get the locations of the string tokens.
|
|
|
|
StrLocs.append(S->tokloc_begin(), S->tokloc_end());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 09:48:40 +03:00
|
|
|
// Free the temporary string.
|
2009-02-07 04:47:29 +03:00
|
|
|
S->Destroy(Context);
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 09:48:40 +03:00
|
|
|
// Create the aggregate string with the appropriate content and location
|
|
|
|
// information.
|
|
|
|
S = StringLiteral::Create(Context, &StrBuf[0], StrBuf.size(), false,
|
2009-02-18 09:40:38 +03:00
|
|
|
Context.getPointerType(Context.CharTy),
|
2009-02-18 09:48:40 +03:00
|
|
|
&StrLocs[0], StrLocs.size());
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 09:01:06 +03:00
|
|
|
// Verify that this composite string is acceptable for ObjC strings.
|
|
|
|
if (CheckObjCString(S))
|
2008-01-05 01:32:30 +03:00
|
|
|
return true;
|
2009-02-18 09:06:56 +03:00
|
|
|
|
|
|
|
// Initialize the constant string interface lazily. This assumes
|
2009-04-07 18:18:33 +04:00
|
|
|
// the NSString interface is seen in this translation unit. Note: We
|
|
|
|
// don't use NSConstantString, since the runtime team considers this
|
|
|
|
// interface private (even though it appears in the header files).
|
2009-02-18 09:06:56 +03:00
|
|
|
QualType Ty = Context.getObjCConstantStringInterface();
|
|
|
|
if (!Ty.isNull()) {
|
2009-07-11 03:34:53 +04:00
|
|
|
Ty = Context.getObjCObjectPointerType(Ty);
|
2008-06-22 01:44:18 +04:00
|
|
|
} else {
|
2009-04-07 18:18:33 +04:00
|
|
|
IdentifierInfo *NSIdent = &Context.Idents.get("NSString");
|
2009-02-18 09:06:56 +03:00
|
|
|
NamedDecl *IF = LookupName(TUScope, NSIdent, LookupOrdinaryName);
|
|
|
|
if (ObjCInterfaceDecl *StrIF = dyn_cast_or_null<ObjCInterfaceDecl>(IF)) {
|
|
|
|
Context.setObjCConstantStringInterface(StrIF);
|
|
|
|
Ty = Context.getObjCConstantStringInterface();
|
2009-07-11 03:34:53 +04:00
|
|
|
Ty = Context.getObjCObjectPointerType(Ty);
|
2009-02-18 09:06:56 +03:00
|
|
|
} else {
|
2009-04-07 18:18:33 +04:00
|
|
|
// If there is no NSString interface defined then treat constant
|
2009-02-18 09:06:56 +03:00
|
|
|
// strings as untyped objects and let the runtime figure it out later.
|
|
|
|
Ty = Context.getObjCIdType();
|
|
|
|
}
|
2008-06-22 01:44:18 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 09:13:04 +03:00
|
|
|
return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]);
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc,
|
2009-06-07 22:45:35 +04:00
|
|
|
QualType EncodedType,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
QualType StrTy;
|
2009-09-09 19:08:12 +04:00
|
|
|
if (EncodedType->isDependentType())
|
2009-06-07 22:45:35 +04:00
|
|
|
StrTy = Context.DependentTy;
|
|
|
|
else {
|
|
|
|
std::string Str;
|
|
|
|
Context.getObjCEncodingForType(EncodedType, Str);
|
|
|
|
|
|
|
|
// The type of @encode is the same as the type of the corresponding string,
|
|
|
|
// which is an array type.
|
|
|
|
StrTy = Context.CharTy;
|
|
|
|
// A C++ string literal has a const-qualified element type (C++ 2.13.4p1).
|
|
|
|
if (getLangOptions().CPlusPlus)
|
|
|
|
StrTy.addConst();
|
|
|
|
StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Str.size()+1),
|
|
|
|
ArrayType::Normal, 0);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-06-07 22:45:35 +04:00
|
|
|
return new (Context) ObjCEncodeExpr(StrTy, EncodedType, AtLoc, RParenLoc);
|
|
|
|
}
|
|
|
|
|
2008-01-05 01:32:30 +03:00
|
|
|
Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
|
|
|
|
SourceLocation EncodeLoc,
|
|
|
|
SourceLocation LParenLoc,
|
2009-02-18 09:06:56 +03:00
|
|
|
TypeTy *ty,
|
2008-01-05 01:32:30 +03:00
|
|
|
SourceLocation RParenLoc) {
|
2009-08-19 05:28:28 +04:00
|
|
|
// FIXME: Preserve type source info ?
|
|
|
|
QualType EncodedType = GetTypeFromParser(ty);
|
2008-01-05 01:32:30 +03:00
|
|
|
|
2009-06-07 22:45:35 +04:00
|
|
|
return BuildObjCEncodeExpression(AtLoc, EncodedType, RParenLoc);
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
|
|
|
|
SourceLocation AtLoc,
|
|
|
|
SourceLocation SelLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation RParenLoc) {
|
2009-09-09 19:08:12 +04:00
|
|
|
ObjCMethodDecl *Method = LookupInstanceMethodInGlobalPool(Sel,
|
2009-08-23 01:13:55 +04:00
|
|
|
SourceRange(LParenLoc, RParenLoc), false);
|
2009-06-16 20:25:00 +04:00
|
|
|
if (!Method)
|
|
|
|
Method = LookupFactoryMethodInGlobalPool(Sel,
|
|
|
|
SourceRange(LParenLoc, RParenLoc));
|
|
|
|
if (!Method)
|
|
|
|
Diag(SelLoc, diag::warn_undeclared_selector) << Sel;
|
|
|
|
|
2009-02-18 09:06:56 +03:00
|
|
|
QualType Ty = Context.getObjCSelType();
|
|
|
|
return new (Context) ObjCSelectorExpr(Ty, Sel, AtLoc, RParenLoc);
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId,
|
|
|
|
SourceLocation AtLoc,
|
|
|
|
SourceLocation ProtoLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation RParenLoc) {
|
2009-04-24 03:18:26 +04:00
|
|
|
ObjCProtocolDecl* PDecl = LookupProtocol(ProtocolId);
|
2008-01-05 01:32:30 +03:00
|
|
|
if (!PDecl) {
|
2008-11-19 11:23:25 +03:00
|
|
|
Diag(ProtoLoc, diag::err_undeclared_protocol) << ProtocolId;
|
2008-01-05 01:32:30 +03:00
|
|
|
return true;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-18 09:06:56 +03:00
|
|
|
QualType Ty = Context.getObjCProtoType();
|
|
|
|
if (Ty.isNull())
|
2008-01-05 01:32:30 +03:00
|
|
|
return true;
|
2009-07-11 03:34:53 +04:00
|
|
|
Ty = Context.getObjCObjectPointerType(Ty);
|
2009-02-18 09:06:56 +03:00
|
|
|
return new (Context) ObjCProtocolExpr(Ty, PDecl, AtLoc, RParenLoc);
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
|
|
|
|
Selector Sel, ObjCMethodDecl *Method,
|
2008-11-24 06:33:13 +03:00
|
|
|
bool isClassMessage,
|
2008-09-11 04:01:56 +04:00
|
|
|
SourceLocation lbrac, SourceLocation rbrac,
|
2009-09-09 19:08:12 +04:00
|
|
|
QualType &ReturnType) {
|
2008-09-11 04:01:56 +04:00
|
|
|
if (!Method) {
|
2008-09-11 04:04:36 +04:00
|
|
|
// Apply default argument promotion as for (C99 6.5.2.2p6).
|
|
|
|
for (unsigned i = 0; i != NumArgs; i++)
|
|
|
|
DefaultArgumentPromotion(Args[i]);
|
|
|
|
|
2008-11-24 06:33:13 +03:00
|
|
|
unsigned DiagID = isClassMessage ? diag::warn_class_method_not_found :
|
|
|
|
diag::warn_inst_method_not_found;
|
|
|
|
Diag(lbrac, DiagID)
|
|
|
|
<< Sel << isClassMessage << SourceRange(lbrac, rbrac);
|
2008-09-11 04:01:56 +04:00
|
|
|
ReturnType = Context.getObjCIdType();
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-11-24 06:33:13 +03:00
|
|
|
ReturnType = Method->getResultType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-09-11 04:50:25 +04:00
|
|
|
unsigned NumNamedArgs = Sel.getNumArgs();
|
|
|
|
assert(NumArgs >= NumNamedArgs && "Too few arguments for selector!");
|
|
|
|
|
2009-04-12 12:11:20 +04:00
|
|
|
bool IsError = false;
|
2008-09-11 04:50:25 +04:00
|
|
|
for (unsigned i = 0; i < NumNamedArgs; i++) {
|
2008-01-05 01:32:30 +03:00
|
|
|
Expr *argExpr = Args[i];
|
|
|
|
assert(argExpr && "CheckMessageArgumentTypes(): missing expression");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-20 21:43:26 +03:00
|
|
|
QualType lhsType = Method->param_begin()[i]->getType();
|
2008-01-05 01:32:30 +03:00
|
|
|
QualType rhsType = argExpr->getType();
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
// If necessary, apply function/array conversion. C99 6.7.5.3p[7,8].
|
2008-04-02 21:17:33 +04:00
|
|
|
if (lhsType->isArrayType())
|
|
|
|
lhsType = Context.getArrayDecayedType(lhsType);
|
2008-01-05 01:32:30 +03:00
|
|
|
else if (lhsType->isFunctionType())
|
|
|
|
lhsType = Context.getPointerType(lhsType);
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
AssignConvertType Result =
|
2008-04-02 21:17:33 +04:00
|
|
|
CheckSingleAssignmentConstraints(lhsType, argExpr);
|
2008-01-05 01:32:30 +03:00
|
|
|
if (Args[i] != argExpr) // The expression was converted.
|
|
|
|
Args[i] = argExpr; // Make sure we store the converted expression.
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
IsError |=
|
2008-01-05 01:32:30 +03:00
|
|
|
DiagnoseAssignmentResult(Result, argExpr->getLocStart(), lhsType, rhsType,
|
|
|
|
argExpr, "sending");
|
|
|
|
}
|
2008-09-11 04:50:25 +04:00
|
|
|
|
|
|
|
// Promote additional arguments to variadic methods.
|
|
|
|
if (Method->isVariadic()) {
|
2009-01-16 19:48:51 +03:00
|
|
|
for (unsigned i = NumNamedArgs; i < NumArgs; ++i)
|
2009-04-12 12:11:20 +04:00
|
|
|
IsError |= DefaultVariadicArgumentPromotion(Args[i], VariadicMethod);
|
2008-09-11 04:50:25 +04:00
|
|
|
} else {
|
|
|
|
// Check for extra arguments to non-variadic methods.
|
|
|
|
if (NumArgs != NumNamedArgs) {
|
2009-09-09 19:08:12 +04:00
|
|
|
Diag(Args[NumNamedArgs]->getLocStart(),
|
2008-11-19 08:08:23 +03:00
|
|
|
diag::err_typecheck_call_too_many_args)
|
2008-11-21 21:44:24 +03:00
|
|
|
<< 2 /*method*/ << Method->getSourceRange()
|
2008-11-19 08:08:23 +03:00
|
|
|
<< SourceRange(Args[NumNamedArgs]->getLocStart(),
|
|
|
|
Args[NumArgs-1]->getLocEnd());
|
2008-09-11 04:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-12 12:11:20 +04:00
|
|
|
return IsError;
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
|
|
|
|
2009-03-04 18:11:40 +03:00
|
|
|
bool Sema::isSelfExpr(Expr *RExpr) {
|
|
|
|
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(RExpr))
|
|
|
|
if (DRE->getDecl()->getIdentifier() == &Context.Idents.get("self"))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-26 18:55:06 +03:00
|
|
|
// Helper method for ActOnClassMethod/ActOnInstanceMethod.
|
|
|
|
// Will search "local" class/category implementations for a method decl.
|
2009-03-04 21:15:57 +03:00
|
|
|
// If failed, then we search in class's root for an instance method.
|
2009-02-26 18:55:06 +03:00
|
|
|
// Returns 0 if no method is found.
|
2009-03-08 21:56:13 +03:00
|
|
|
ObjCMethodDecl *Sema::LookupPrivateClassMethod(Selector Sel,
|
2009-02-26 18:55:06 +03:00
|
|
|
ObjCInterfaceDecl *ClassDecl) {
|
|
|
|
ObjCMethodDecl *Method = 0;
|
2009-03-08 21:56:13 +03:00
|
|
|
// lookup in class and all superclasses
|
|
|
|
while (ClassDecl && !Method) {
|
2009-07-21 04:06:04 +04:00
|
|
|
if (ObjCImplementationDecl *ImpDecl = ClassDecl->getImplementation())
|
2009-06-30 06:36:12 +04:00
|
|
|
Method = ImpDecl->getClassMethod(Sel);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-08 21:56:13 +03:00
|
|
|
// Look through local category implementations associated with the class.
|
2009-07-21 04:06:20 +04:00
|
|
|
if (!Method)
|
|
|
|
Method = ClassDecl->getCategoryClassMethod(Sel);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-08 21:56:13 +03:00
|
|
|
// Before we give up, check if the selector is an instance method.
|
|
|
|
// But only in the root. This matches gcc's behaviour and what the
|
|
|
|
// runtime expects.
|
|
|
|
if (!Method && !ClassDecl->getSuperClass()) {
|
2009-06-30 06:36:12 +04:00
|
|
|
Method = ClassDecl->lookupInstanceMethod(Sel);
|
2009-09-09 19:08:12 +04:00
|
|
|
// Look through local category implementations associated
|
2009-03-08 21:56:13 +03:00
|
|
|
// with the root class.
|
2009-09-09 19:08:12 +04:00
|
|
|
if (!Method)
|
2009-03-08 21:56:13 +03:00
|
|
|
Method = LookupPrivateInstanceMethod(Sel, ClassDecl);
|
2009-02-26 18:55:06 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-08 21:56:13 +03:00
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
2009-02-26 18:55:06 +03:00
|
|
|
}
|
2009-03-08 21:56:13 +03:00
|
|
|
return Method;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCMethodDecl *Sema::LookupPrivateInstanceMethod(Selector Sel,
|
|
|
|
ObjCInterfaceDecl *ClassDecl) {
|
|
|
|
ObjCMethodDecl *Method = 0;
|
|
|
|
while (ClassDecl && !Method) {
|
|
|
|
// If we have implementations in scope, check "private" methods.
|
2009-07-21 04:06:04 +04:00
|
|
|
if (ObjCImplementationDecl *ImpDecl = ClassDecl->getImplementation())
|
2009-06-30 06:36:12 +04:00
|
|
|
Method = ImpDecl->getInstanceMethod(Sel);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-08 21:56:13 +03:00
|
|
|
// Look through local category implementations associated with the class.
|
2009-07-21 04:06:20 +04:00
|
|
|
if (!Method)
|
|
|
|
Method = ClassDecl->getCategoryInstanceMethod(Sel);
|
2009-03-08 21:56:13 +03:00
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
2009-03-04 21:15:57 +03:00
|
|
|
}
|
2009-02-26 18:55:06 +03:00
|
|
|
return Method;
|
|
|
|
}
|
|
|
|
|
2009-03-10 00:12:44 +03:00
|
|
|
Action::OwningExprResult Sema::ActOnClassPropertyRefExpr(
|
|
|
|
IdentifierInfo &receiverName,
|
|
|
|
IdentifierInfo &propertyName,
|
|
|
|
SourceLocation &receiverNameLoc,
|
|
|
|
SourceLocation &propertyNameLoc) {
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-10 00:12:44 +03:00
|
|
|
ObjCInterfaceDecl *IFace = getObjCInterfaceDecl(&receiverName);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-10 00:12:44 +03:00
|
|
|
// Search for a declared property first.
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-10 00:12:44 +03:00
|
|
|
Selector Sel = PP.getSelectorTable().getNullarySelector(&propertyName);
|
2009-06-30 06:36:12 +04:00
|
|
|
ObjCMethodDecl *Getter = IFace->lookupClassMethod(Sel);
|
2009-03-10 00:12:44 +03:00
|
|
|
|
|
|
|
// If this reference is in an @implementation, check for 'private' methods.
|
|
|
|
if (!Getter)
|
|
|
|
if (ObjCMethodDecl *CurMeth = getCurMethodDecl())
|
|
|
|
if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface())
|
2009-07-21 04:06:04 +04:00
|
|
|
if (ObjCImplementationDecl *ImpDecl = ClassDecl->getImplementation())
|
2009-06-30 06:36:12 +04:00
|
|
|
Getter = ImpDecl->getClassMethod(Sel);
|
2009-03-10 00:12:44 +03:00
|
|
|
|
|
|
|
if (Getter) {
|
|
|
|
// FIXME: refactor/share with ActOnMemberReference().
|
|
|
|
// Check if we can reference this property.
|
|
|
|
if (DiagnoseUseOfDecl(Getter, propertyNameLoc))
|
|
|
|
return ExprError();
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-10 00:12:44 +03:00
|
|
|
// Look for the matching setter, in case it is needed.
|
2009-09-09 19:08:12 +04:00
|
|
|
Selector SetterSel =
|
|
|
|
SelectorTable::constructSetterName(PP.getIdentifierTable(),
|
2009-03-10 20:24:38 +03:00
|
|
|
PP.getSelectorTable(), &propertyName);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-06-30 06:36:12 +04:00
|
|
|
ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel);
|
2009-03-10 00:12:44 +03:00
|
|
|
if (!Setter) {
|
|
|
|
// If this reference is in an @implementation, also check for 'private'
|
|
|
|
// methods.
|
|
|
|
if (ObjCMethodDecl *CurMeth = getCurMethodDecl())
|
|
|
|
if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface())
|
2009-07-21 04:06:04 +04:00
|
|
|
if (ObjCImplementationDecl *ImpDecl = ClassDecl->getImplementation())
|
2009-06-30 06:36:12 +04:00
|
|
|
Setter = ImpDecl->getClassMethod(SetterSel);
|
2009-03-10 00:12:44 +03:00
|
|
|
}
|
|
|
|
// Look through local category implementations associated with the class.
|
2009-07-21 04:06:20 +04:00
|
|
|
if (!Setter)
|
|
|
|
Setter = IFace->getCategoryClassMethod(SetterSel);
|
2009-03-10 00:12:44 +03:00
|
|
|
|
|
|
|
if (Setter && DiagnoseUseOfDecl(Setter, propertyNameLoc))
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (Getter || Setter) {
|
|
|
|
QualType PType;
|
|
|
|
|
|
|
|
if (Getter)
|
|
|
|
PType = Getter->getResultType();
|
|
|
|
else {
|
|
|
|
for (ObjCMethodDecl::param_iterator PI = Setter->param_begin(),
|
|
|
|
E = Setter->param_end(); PI != E; ++PI)
|
|
|
|
PType = (*PI)->getType();
|
|
|
|
}
|
2009-08-20 21:02:02 +04:00
|
|
|
return Owned(new (Context) ObjCImplicitSetterGetterRefExpr(
|
2009-09-09 19:08:12 +04:00
|
|
|
Getter, PType, Setter,
|
2009-03-10 00:12:44 +03:00
|
|
|
propertyNameLoc, IFace, receiverNameLoc));
|
|
|
|
}
|
|
|
|
return ExprError(Diag(propertyNameLoc, diag::err_property_not_found)
|
|
|
|
<< &propertyName << Context.getObjCInterfaceType(IFace));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-05 01:32:30 +03:00
|
|
|
// ActOnClassMessage - used for both unary and keyword messages.
|
|
|
|
// ArgExprs is optional - if it is present, the number of expressions
|
|
|
|
// is obtained from Sel.getNumArgs().
|
|
|
|
Sema::ExprResult Sema::ActOnClassMessage(
|
|
|
|
Scope *S,
|
|
|
|
IdentifierInfo *receiverName, Selector Sel,
|
2009-02-14 21:21:46 +03:00
|
|
|
SourceLocation lbrac, SourceLocation receiverLoc,
|
2009-09-09 19:08:12 +04:00
|
|
|
SourceLocation selectorLoc, SourceLocation rbrac,
|
|
|
|
ExprTy **Args, unsigned NumArgs) {
|
2008-01-05 01:32:30 +03:00
|
|
|
assert(receiverName && "missing receiver class name");
|
|
|
|
|
|
|
|
Expr **ArgExprs = reinterpret_cast<Expr **>(Args);
|
2008-01-07 22:49:32 +03:00
|
|
|
ObjCInterfaceDecl* ClassDecl = 0;
|
2008-07-24 23:44:33 +04:00
|
|
|
bool isSuper = false;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-11-20 08:35:30 +03:00
|
|
|
if (receiverName->isStr("super")) {
|
2008-11-19 18:54:23 +03:00
|
|
|
if (getCurMethodDecl()) {
|
|
|
|
isSuper = true;
|
2009-01-08 00:01:41 +03:00
|
|
|
ObjCInterfaceDecl *OID = getCurMethodDecl()->getClassInterface();
|
|
|
|
if (!OID)
|
2009-09-09 19:08:12 +04:00
|
|
|
return Diag(lbrac, diag::error_no_super_class_message)
|
2009-01-08 00:01:41 +03:00
|
|
|
<< getCurMethodDecl()->getDeclName();
|
|
|
|
ClassDecl = OID->getSuperClass();
|
2008-11-19 18:54:23 +03:00
|
|
|
if (!ClassDecl)
|
2009-01-08 00:01:41 +03:00
|
|
|
return Diag(lbrac, diag::error_no_super_class) << OID->getDeclName();
|
2009-01-09 20:18:27 +03:00
|
|
|
if (getCurMethodDecl()->isInstanceMethod()) {
|
2008-11-19 18:54:23 +03:00
|
|
|
QualType superTy = Context.getObjCInterfaceType(ClassDecl);
|
2009-07-11 03:34:53 +04:00
|
|
|
superTy = Context.getObjCObjectPointerType(superTy);
|
2009-02-07 04:47:29 +03:00
|
|
|
ExprResult ReceiverExpr = new (Context) ObjCSuperExpr(SourceLocation(),
|
|
|
|
superTy);
|
2008-11-19 18:54:23 +03:00
|
|
|
// We are really in an instance method, redirect.
|
2009-09-09 19:08:12 +04:00
|
|
|
return ActOnInstanceMessage(ReceiverExpr.get(), Sel, lbrac,
|
2009-02-14 21:21:46 +03:00
|
|
|
selectorLoc, rbrac, Args, NumArgs);
|
2008-11-19 18:54:23 +03:00
|
|
|
}
|
|
|
|
// We are sending a message to 'super' within a class method. Do nothing,
|
|
|
|
// the receiver will pass through as 'super' (how convenient:-).
|
|
|
|
} else {
|
|
|
|
// 'super' has been used outside a method context. If a variable named
|
|
|
|
// 'super' has been declared, redirect. If not, produce a diagnostic.
|
2009-02-04 20:27:36 +03:00
|
|
|
NamedDecl *SuperDecl = LookupName(S, receiverName, LookupOrdinaryName);
|
2008-11-19 18:54:23 +03:00
|
|
|
ValueDecl *VD = dyn_cast_or_null<ValueDecl>(SuperDecl);
|
|
|
|
if (VD) {
|
2009-09-09 19:08:12 +04:00
|
|
|
ExprResult ReceiverExpr = new (Context) DeclRefExpr(VD, VD->getType(),
|
2009-02-07 04:47:29 +03:00
|
|
|
receiverLoc);
|
2008-11-19 18:54:23 +03:00
|
|
|
// We are really in an instance method, redirect.
|
2009-09-09 19:08:12 +04:00
|
|
|
return ActOnInstanceMessage(ReceiverExpr.get(), Sel, lbrac,
|
2009-02-14 21:21:46 +03:00
|
|
|
selectorLoc, rbrac, Args, NumArgs);
|
2008-11-19 18:54:23 +03:00
|
|
|
}
|
2008-11-24 00:45:46 +03:00
|
|
|
return Diag(receiverLoc, diag::err_undeclared_var_use) << receiverName;
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
2008-01-05 01:32:30 +03:00
|
|
|
} else
|
|
|
|
ClassDecl = getObjCInterfaceDecl(receiverName);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-07-25 23:39:00 +04:00
|
|
|
// The following code allows for the following GCC-ism:
|
2008-06-05 03:08:38 +04:00
|
|
|
//
|
|
|
|
// typedef XCElementDisplayRect XCElementGraphicsRect;
|
|
|
|
//
|
|
|
|
// @implementation XCRASlice
|
|
|
|
// - whatever { // Note that XCElementGraphicsRect is a typedef name.
|
|
|
|
// _sGraphicsDelegate =[[XCElementGraphicsRect alloc] init];
|
|
|
|
// }
|
|
|
|
//
|
2008-07-25 23:39:00 +04:00
|
|
|
// If necessary, the following lookup could move to getObjCInterfaceDecl().
|
|
|
|
if (!ClassDecl) {
|
2009-02-04 20:27:36 +03:00
|
|
|
NamedDecl *IDecl = LookupName(TUScope, receiverName, LookupOrdinaryName);
|
2008-07-25 23:39:00 +04:00
|
|
|
if (TypedefDecl *OCTD = dyn_cast_or_null<TypedefDecl>(IDecl)) {
|
|
|
|
const ObjCInterfaceType *OCIT;
|
|
|
|
OCIT = OCTD->getUnderlyingType()->getAsObjCInterfaceType();
|
2009-03-29 09:01:10 +04:00
|
|
|
if (!OCIT) {
|
|
|
|
Diag(receiverLoc, diag::err_invalid_receiver_to_message);
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-16 23:35:09 +03:00
|
|
|
ClassDecl = OCIT->getDecl();
|
2008-07-25 23:39:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(ClassDecl && "missing interface declaration");
|
2008-06-05 03:08:38 +04:00
|
|
|
ObjCMethodDecl *Method = 0;
|
2008-01-05 01:32:30 +03:00
|
|
|
QualType returnType;
|
2009-05-09 03:02:36 +04:00
|
|
|
if (ClassDecl->isForwardDecl()) {
|
|
|
|
// A forward class used in messaging is tread as a 'Class'
|
2009-05-09 03:45:49 +04:00
|
|
|
Diag(lbrac, diag::warn_receiver_forward_class) << ClassDecl->getDeclName();
|
2009-05-09 03:02:36 +04:00
|
|
|
Method = LookupFactoryMethodInGlobalPool(Sel, SourceRange(lbrac,rbrac));
|
|
|
|
if (Method)
|
2009-09-09 19:08:12 +04:00
|
|
|
Diag(Method->getLocation(), diag::note_method_sent_forward_class)
|
2009-05-09 03:45:49 +04:00
|
|
|
<< Method->getDeclName();
|
2009-05-09 03:02:36 +04:00
|
|
|
}
|
|
|
|
if (!Method)
|
2009-06-30 06:36:12 +04:00
|
|
|
Method = ClassDecl->lookupClassMethod(Sel);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-07-25 23:39:00 +04:00
|
|
|
// If we have an implementation in scope, check "private" methods.
|
2009-02-26 18:55:06 +03:00
|
|
|
if (!Method)
|
2009-03-08 21:56:13 +03:00
|
|
|
Method = LookupPrivateClassMethod(Sel, ClassDecl);
|
2008-07-25 23:39:00 +04:00
|
|
|
|
2009-02-19 00:56:37 +03:00
|
|
|
if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
|
|
|
|
return true;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, true,
|
2008-09-11 04:01:56 +04:00
|
|
|
lbrac, rbrac, returnType))
|
|
|
|
return true;
|
2008-06-24 19:50:53 +04:00
|
|
|
|
2009-05-26 19:22:25 +04:00
|
|
|
returnType = returnType.getNonReferenceType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-05-16 11:39:55 +04:00
|
|
|
// If we have the ObjCInterfaceDecl* for the class that is receiving the
|
|
|
|
// message, use that to construct the ObjCMessageExpr. Otherwise pass on the
|
|
|
|
// IdentifierInfo* for the class.
|
|
|
|
// FIXME: need to do a better job handling 'super' usage within a class. For
|
|
|
|
// now, we simply pass the "super" identifier through (which isn't consistent
|
|
|
|
// with instance methods.
|
2008-07-25 23:39:00 +04:00
|
|
|
if (isSuper)
|
2009-02-07 04:47:29 +03:00
|
|
|
return new (Context) ObjCMessageExpr(receiverName, Sel, returnType, Method,
|
|
|
|
lbrac, rbrac, ArgExprs, NumArgs);
|
2008-06-24 19:50:53 +04:00
|
|
|
else
|
2009-02-07 04:47:29 +03:00
|
|
|
return new (Context) ObjCMessageExpr(ClassDecl, Sel, returnType, Method,
|
|
|
|
lbrac, rbrac, ArgExprs, NumArgs);
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ActOnInstanceMessage - used for both unary and keyword messages.
|
|
|
|
// ArgExprs is optional - if it is present, the number of expressions
|
|
|
|
// is obtained from Sel.getNumArgs().
|
2008-07-21 10:31:05 +04:00
|
|
|
Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
|
2009-09-09 19:08:12 +04:00
|
|
|
SourceLocation lbrac,
|
2009-02-14 21:21:46 +03:00
|
|
|
SourceLocation receiverLoc,
|
2008-07-27 02:17:49 +04:00
|
|
|
SourceLocation rbrac,
|
|
|
|
ExprTy **Args, unsigned NumArgs) {
|
2008-01-05 01:32:30 +03:00
|
|
|
assert(receiver && "missing receiver expression");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-01-05 01:32:30 +03:00
|
|
|
Expr **ArgExprs = reinterpret_cast<Expr **>(Args);
|
|
|
|
Expr *RExpr = static_cast<Expr *>(receiver);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-04-29 09:48:32 +04:00
|
|
|
// If necessary, apply function/array conversion to the receiver.
|
|
|
|
// C99 6.7.5.3p[7,8].
|
|
|
|
DefaultFunctionArrayConversion(RExpr);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-01-05 01:32:30 +03:00
|
|
|
QualType returnType;
|
2008-07-27 02:17:49 +04:00
|
|
|
QualType ReceiverCType =
|
|
|
|
Context.getCanonicalType(RExpr->getType()).getUnqualifiedType();
|
2008-11-18 01:29:32 +03:00
|
|
|
|
|
|
|
// Handle messages to 'super'.
|
2009-02-23 18:40:48 +03:00
|
|
|
if (isa<ObjCSuperExpr>(RExpr)) {
|
2008-11-18 01:29:32 +03:00
|
|
|
ObjCMethodDecl *Method = 0;
|
|
|
|
if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) {
|
|
|
|
// If we have an interface in scope, check 'super' methods.
|
|
|
|
if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface())
|
2009-03-08 21:56:13 +03:00
|
|
|
if (ObjCInterfaceDecl *SuperDecl = ClassDecl->getSuperClass()) {
|
2009-06-30 06:36:12 +04:00
|
|
|
Method = SuperDecl->lookupInstanceMethod(Sel);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
if (!Method)
|
2009-03-08 21:56:13 +03:00
|
|
|
// If we have implementations in scope, check "private" methods.
|
|
|
|
Method = LookupPrivateInstanceMethod(Sel, SuperDecl);
|
|
|
|
}
|
2008-11-18 01:29:32 +03:00
|
|
|
}
|
2009-02-14 21:21:46 +03:00
|
|
|
|
2009-02-19 00:56:37 +03:00
|
|
|
if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
|
|
|
|
return true;
|
2009-02-14 22:08:58 +03:00
|
|
|
|
2008-11-24 06:33:13 +03:00
|
|
|
if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
|
2008-11-18 01:29:32 +03:00
|
|
|
lbrac, rbrac, returnType))
|
|
|
|
return true;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-05-26 19:22:25 +04:00
|
|
|
returnType = returnType.getNonReferenceType();
|
2009-02-07 04:47:29 +03:00
|
|
|
return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
|
|
|
|
rbrac, ArgExprs, NumArgs);
|
2008-11-18 01:29:32 +03:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
// Handle messages to id.
|
2009-07-22 20:07:01 +04:00
|
|
|
if (ReceiverCType->isObjCIdType() || ReceiverCType->isBlockPointerType() ||
|
2009-05-22 01:04:28 +04:00
|
|
|
Context.isObjCNSObjectType(RExpr->getType())) {
|
2008-09-30 18:38:43 +04:00
|
|
|
ObjCMethodDecl *Method = LookupInstanceMethodInGlobalPool(
|
|
|
|
Sel, SourceRange(lbrac,rbrac));
|
2008-02-01 09:57:39 +03:00
|
|
|
if (!Method)
|
2009-04-25 01:10:55 +04:00
|
|
|
Method = LookupFactoryMethodInGlobalPool(Sel, SourceRange(lbrac, rbrac));
|
2009-09-09 19:08:12 +04:00
|
|
|
if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
|
2008-09-11 04:01:56 +04:00
|
|
|
lbrac, rbrac, returnType))
|
|
|
|
return true;
|
2009-05-26 19:22:25 +04:00
|
|
|
returnType = returnType.getNonReferenceType();
|
2009-02-07 04:47:29 +03:00
|
|
|
return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
|
|
|
|
rbrac, ArgExprs, NumArgs);
|
2008-07-21 09:57:44 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-07-21 09:57:44 +04:00
|
|
|
// Handle messages to Class.
|
2009-09-09 19:08:12 +04:00
|
|
|
if (ReceiverCType->isObjCClassType() ||
|
2009-07-22 20:07:01 +04:00
|
|
|
ReceiverCType->isObjCQualifiedClassType()) {
|
2008-07-21 10:12:56 +04:00
|
|
|
ObjCMethodDecl *Method = 0;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-07-21 10:44:27 +04:00
|
|
|
if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) {
|
2009-02-23 05:25:40 +03:00
|
|
|
if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) {
|
|
|
|
// First check the public methods in the class interface.
|
2009-06-30 06:36:12 +04:00
|
|
|
Method = ClassDecl->lookupClassMethod(Sel);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-26 18:55:06 +03:00
|
|
|
if (!Method)
|
2009-03-08 21:56:13 +03:00
|
|
|
Method = LookupPrivateClassMethod(Sel, ClassDecl);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
// FIXME: if we still haven't found a method, we need to look in
|
2009-07-22 20:07:01 +04:00
|
|
|
// protocols (if we have qualifiers).
|
2009-02-23 05:25:40 +03:00
|
|
|
}
|
2009-02-19 00:56:37 +03:00
|
|
|
if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
|
|
|
|
return true;
|
2009-02-23 05:25:40 +03:00
|
|
|
}
|
2009-03-04 18:11:40 +03:00
|
|
|
if (!Method) {
|
|
|
|
// If not messaging 'self', look for any factory method named 'Sel'.
|
|
|
|
if (!isSelfExpr(RExpr)) {
|
2009-04-25 01:10:55 +04:00
|
|
|
Method = LookupFactoryMethodInGlobalPool(Sel, SourceRange(lbrac,rbrac));
|
2009-03-04 20:50:39 +03:00
|
|
|
if (!Method) {
|
2009-05-05 22:34:37 +04:00
|
|
|
// If no class (factory) method was found, check if an _instance_
|
|
|
|
// method of the same name exists in the root class only.
|
2009-03-04 18:11:40 +03:00
|
|
|
Method = LookupInstanceMethodInGlobalPool(
|
|
|
|
Sel, SourceRange(lbrac,rbrac));
|
2009-05-05 22:34:37 +04:00
|
|
|
if (Method)
|
|
|
|
if (const ObjCInterfaceDecl *ID =
|
|
|
|
dyn_cast<ObjCInterfaceDecl>(Method->getDeclContext())) {
|
|
|
|
if (ID->getSuperClass())
|
|
|
|
Diag(lbrac, diag::warn_root_inst_method_not_found)
|
|
|
|
<< Sel << SourceRange(lbrac, rbrac);
|
|
|
|
}
|
2009-03-04 20:50:39 +03:00
|
|
|
}
|
2009-03-04 18:11:40 +03:00
|
|
|
}
|
|
|
|
}
|
2008-11-24 06:33:13 +03:00
|
|
|
if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
|
2008-09-11 04:01:56 +04:00
|
|
|
lbrac, rbrac, returnType))
|
|
|
|
return true;
|
2009-05-26 19:22:25 +04:00
|
|
|
returnType = returnType.getNonReferenceType();
|
2009-02-07 04:47:29 +03:00
|
|
|
return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
|
|
|
|
rbrac, ArgExprs, NumArgs);
|
2008-07-21 09:57:44 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-07-21 10:12:56 +04:00
|
|
|
ObjCMethodDecl *Method = 0;
|
2008-07-21 09:57:44 +04:00
|
|
|
ObjCInterfaceDecl* ClassDecl = 0;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
// We allow sending a message to a qualified ID ("id<foo>"), which is ok as
|
2008-07-21 10:12:56 +04:00
|
|
|
// long as one of the protocols implements the selector (if not, warn).
|
2009-09-09 19:08:12 +04:00
|
|
|
if (const ObjCObjectPointerType *QIdTy =
|
2009-06-18 02:40:22 +04:00
|
|
|
ReceiverCType->getAsObjCQualifiedIdType()) {
|
2009-02-22 00:17:01 +03:00
|
|
|
// Search protocols for instance methods.
|
2009-06-18 02:40:22 +04:00
|
|
|
for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(),
|
2009-05-27 20:21:00 +04:00
|
|
|
E = QIdTy->qual_end(); I != E; ++I) {
|
|
|
|
ObjCProtocolDecl *PDecl = *I;
|
2009-06-30 06:36:12 +04:00
|
|
|
if (PDecl && (Method = PDecl->lookupInstanceMethod(Sel)))
|
2008-07-21 09:57:44 +04:00
|
|
|
break;
|
2009-04-07 19:07:57 +04:00
|
|
|
// Since we aren't supporting "Class<foo>", look for a class method.
|
2009-06-30 06:36:12 +04:00
|
|
|
if (PDecl && (Method = PDecl->lookupClassMethod(Sel)))
|
2009-04-07 19:07:57 +04:00
|
|
|
break;
|
2008-07-21 09:57:44 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
} else if (const ObjCObjectPointerType *OCIType =
|
2009-07-11 03:34:53 +04:00
|
|
|
ReceiverCType->getAsObjCInterfacePointerType()) {
|
2008-07-21 10:12:56 +04:00
|
|
|
// We allow sending a message to a pointer to an interface (an object).
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-07-11 03:34:53 +04:00
|
|
|
ClassDecl = OCIType->getInterfaceDecl();
|
2008-09-30 18:38:43 +04:00
|
|
|
// FIXME: consider using LookupInstanceMethodInGlobalPool, since it will be
|
2009-05-16 11:39:55 +04:00
|
|
|
// faster than the following method (which can do *many* linear searches).
|
2008-09-30 18:38:43 +04:00
|
|
|
// The idea is to add class info to InstanceMethodPool.
|
2009-06-30 06:36:12 +04:00
|
|
|
Method = ClassDecl->lookupInstanceMethod(Sel);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-07-21 09:57:44 +04:00
|
|
|
if (!Method) {
|
|
|
|
// Search protocol qualifiers.
|
2009-07-11 03:34:53 +04:00
|
|
|
for (ObjCObjectPointerType::qual_iterator QI = OCIType->qual_begin(),
|
2009-02-23 18:40:48 +03:00
|
|
|
E = OCIType->qual_end(); QI != E; ++QI) {
|
2009-06-30 06:36:12 +04:00
|
|
|
if ((Method = (*QI)->lookupInstanceMethod(Sel)))
|
2008-01-05 01:32:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-02-22 22:35:57 +03:00
|
|
|
if (!Method) {
|
2009-03-08 21:56:13 +03:00
|
|
|
// If we have implementations in scope, check "private" methods.
|
|
|
|
Method = LookupPrivateInstanceMethod(Sel, ClassDecl);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-08 21:56:13 +03:00
|
|
|
if (!Method && !isSelfExpr(RExpr)) {
|
2009-03-04 18:11:40 +03:00
|
|
|
// If we still haven't found a method, look in the global pool. This
|
|
|
|
// behavior isn't very desirable, however we need it for GCC
|
|
|
|
// compatibility. FIXME: should we deviate??
|
2009-03-08 21:56:13 +03:00
|
|
|
if (OCIType->qual_empty()) {
|
2009-03-04 18:11:40 +03:00
|
|
|
Method = LookupInstanceMethodInGlobalPool(
|
|
|
|
Sel, SourceRange(lbrac,rbrac));
|
2009-07-11 03:34:53 +04:00
|
|
|
if (Method && !OCIType->getInterfaceDecl()->isForwardDecl())
|
2009-09-09 19:08:12 +04:00
|
|
|
Diag(lbrac, diag::warn_maynot_respond)
|
2009-07-11 03:34:53 +04:00
|
|
|
<< OCIType->getInterfaceDecl()->getIdentifier()->getName() << Sel;
|
2009-03-04 18:11:40 +03:00
|
|
|
}
|
2009-03-04 01:19:15 +03:00
|
|
|
}
|
2009-02-22 22:35:57 +03:00
|
|
|
}
|
2009-02-19 00:56:37 +03:00
|
|
|
if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
|
|
|
|
return true;
|
2009-03-10 00:19:16 +03:00
|
|
|
} else if (!Context.getObjCIdType().isNull() &&
|
|
|
|
(ReceiverCType->isPointerType() ||
|
2009-09-09 19:08:12 +04:00
|
|
|
(ReceiverCType->isIntegerType() &&
|
2009-03-10 00:19:16 +03:00
|
|
|
ReceiverCType->isScalarType()))) {
|
|
|
|
// Implicitly convert integers and pointers to 'id' but emit a warning.
|
2009-03-01 20:14:31 +03:00
|
|
|
Diag(lbrac, diag::warn_bad_receiver_type)
|
2008-11-24 09:25:27 +03:00
|
|
|
<< RExpr->getType() << RExpr->getSourceRange();
|
2009-03-10 00:19:16 +03:00
|
|
|
ImpCastExprToType(RExpr, Context.getObjCIdType());
|
|
|
|
} else {
|
|
|
|
// Reject other random receiver types (e.g. structs).
|
|
|
|
Diag(lbrac, diag::err_bad_receiver_type)
|
|
|
|
<< RExpr->getType() << RExpr->getSourceRange();
|
2008-07-21 10:12:56 +04:00
|
|
|
return true;
|
2008-07-21 09:57:44 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-05-13 22:09:35 +04:00
|
|
|
if (Method)
|
|
|
|
DiagnoseSentinelCalls(Method, receiverLoc, ArgExprs, NumArgs);
|
2008-11-24 06:33:13 +03:00
|
|
|
if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
|
2008-09-11 04:01:56 +04:00
|
|
|
lbrac, rbrac, returnType))
|
|
|
|
return true;
|
2009-05-26 19:22:25 +04:00
|
|
|
returnType = returnType.getNonReferenceType();
|
2009-02-07 04:47:29 +03:00
|
|
|
return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
|
|
|
|
rbrac, ArgExprs, NumArgs);
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
2008-04-07 09:30:13 +04:00
|
|
|
|