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"
|
2010-04-11 11:45:24 +04:00
|
|
|
#include "Lookup.h"
|
2010-04-22 03:24:10 +04:00
|
|
|
#include "SemaInit.h"
|
2008-01-05 01:32:30 +03:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
2008-05-30 01:12:08 +04:00
|
|
|
#include "clang/AST/ExprObjC.h"
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
#include "clang/AST/TypeLoc.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);
|
2010-04-24 03:19:04 +04:00
|
|
|
} else if (getLangOptions().NoConstantCFStrings) {
|
|
|
|
IdentifierInfo *NSIdent = &Context.Idents.get("NSConstantString");
|
|
|
|
NamedDecl *IF = LookupSingleName(TUScope, NSIdent, AtLocs[0],
|
|
|
|
LookupOrdinaryName);
|
|
|
|
if (ObjCInterfaceDecl *StrIF = dyn_cast_or_null<ObjCInterfaceDecl>(IF)) {
|
|
|
|
Context.setObjCConstantStringInterface(StrIF);
|
|
|
|
Ty = Context.getObjCConstantStringInterface();
|
|
|
|
Ty = Context.getObjCObjectPointerType(Ty);
|
|
|
|
} else {
|
|
|
|
// If there is no NSConstantString interface defined then treat this
|
|
|
|
// as error and recover from it.
|
|
|
|
Diag(S->getLocStart(), diag::err_no_nsconstant_string_class) << NSIdent
|
|
|
|
<< S->getSourceRange();
|
|
|
|
Ty = Context.getObjCIdType();
|
|
|
|
}
|
2008-06-22 01:44:18 +04:00
|
|
|
} else {
|
2009-04-07 18:18:33 +04:00
|
|
|
IdentifierInfo *NSIdent = &Context.Idents.get("NSString");
|
2010-04-16 02:33:43 +04:00
|
|
|
NamedDecl *IF = LookupSingleName(TUScope, NSIdent, AtLocs[0],
|
|
|
|
LookupOrdinaryName);
|
2009-02-18 09:06:56 +03:00
|
|
|
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,
|
2010-04-20 19:39:42 +04:00
|
|
|
TypeSourceInfo *EncodedTypeInfo,
|
2009-06-07 22:45:35 +04:00
|
|
|
SourceLocation RParenLoc) {
|
2010-04-20 19:39:42 +04:00
|
|
|
QualType EncodedType = EncodedTypeInfo->getType();
|
2009-06-07 22:45:35 +04:00
|
|
|
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).
|
2010-03-15 13:54:44 +03:00
|
|
|
if (getLangOptions().CPlusPlus || getLangOptions().ConstStrings)
|
2009-06-07 22:45:35 +04:00
|
|
|
StrTy.addConst();
|
|
|
|
StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Str.size()+1),
|
|
|
|
ArrayType::Normal, 0);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-04-20 19:39:42 +04:00
|
|
|
return new (Context) ObjCEncodeExpr(StrTy, EncodedTypeInfo, AtLoc, RParenLoc);
|
2009-06-07 22:45:35 +04:00
|
|
|
}
|
|
|
|
|
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 ?
|
2010-04-20 19:39:42 +04:00
|
|
|
TypeSourceInfo *TInfo;
|
|
|
|
QualType EncodedType = GetTypeFromParser(ty, &TInfo);
|
|
|
|
if (!TInfo)
|
|
|
|
TInfo = Context.getTrivialTypeSourceInfo(EncodedType,
|
|
|
|
PP.getLocForEndOfToken(LParenLoc));
|
2008-01-05 01:32:30 +03:00
|
|
|
|
2010-04-20 19:39:42 +04:00
|
|
|
return BuildObjCEncodeExpression(AtLoc, TInfo, 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();
|
2010-02-03 23:11:42 +03:00
|
|
|
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) {
|
2010-04-16 02:33:43 +04:00
|
|
|
ObjCProtocolDecl* PDecl = LookupProtocol(ProtocolId, ProtoLoc);
|
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).
|
2010-04-22 20:44:27 +04:00
|
|
|
for (unsigned i = 0; i != NumArgs; i++) {
|
|
|
|
if (Args[i]->isTypeDependent())
|
|
|
|
continue;
|
|
|
|
|
2008-09-11 04:04:36 +04:00
|
|
|
DefaultArgumentPromotion(Args[i]);
|
2010-04-22 20:44:27 +04:00
|
|
|
}
|
2008-09-11 04:04:36 +04:00
|
|
|
|
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
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
ReturnType = Method->getResultType().getNonReferenceType();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-09-11 04:50:25 +04:00
|
|
|
unsigned NumNamedArgs = Sel.getNumArgs();
|
2010-04-08 04:30:06 +04:00
|
|
|
// Method might have more arguments than selector indicates. This is due
|
|
|
|
// to addition of c-style arguments in method.
|
|
|
|
if (Method->param_size() > Sel.getNumArgs())
|
|
|
|
NumNamedArgs = Method->param_size();
|
|
|
|
// FIXME. This need be cleaned up.
|
|
|
|
if (NumArgs < NumNamedArgs) {
|
2010-04-16 08:48:22 +04:00
|
|
|
Diag(lbrac, diag::err_typecheck_call_too_few_args) << 2
|
|
|
|
<< NumNamedArgs << NumArgs;
|
2010-04-08 04:30:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
2008-09-11 04:50:25 +04:00
|
|
|
|
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++) {
|
2010-04-22 20:44:27 +04:00
|
|
|
// We can't do any type-checking on a type-dependent argument.
|
|
|
|
if (Args[i]->isTypeDependent())
|
|
|
|
continue;
|
|
|
|
|
2008-01-05 01:32:30 +03:00
|
|
|
Expr *argExpr = Args[i];
|
2010-04-22 20:44:27 +04:00
|
|
|
|
2010-04-22 03:24:10 +04:00
|
|
|
ParmVarDecl *Param = Method->param_begin()[i];
|
2008-01-05 01:32:30 +03:00
|
|
|
assert(argExpr && "CheckMessageArgumentTypes(): missing expression");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-04-22 03:24:10 +04:00
|
|
|
if (RequireCompleteType(argExpr->getSourceRange().getBegin(),
|
|
|
|
Param->getType(),
|
|
|
|
PDiag(diag::err_call_incomplete_argument)
|
|
|
|
<< argExpr->getSourceRange()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
InitializedEntity Entity = InitializedEntity::InitializeParameter(Param);
|
|
|
|
OwningExprResult ArgE = PerformCopyInitialization(Entity,
|
|
|
|
SourceLocation(),
|
|
|
|
Owned(argExpr->Retain()));
|
|
|
|
if (ArgE.isInvalid())
|
|
|
|
IsError = true;
|
|
|
|
else
|
|
|
|
Args[i] = ArgE.takeAs<Expr>();
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
2008-09-11 04:50:25 +04:00
|
|
|
|
|
|
|
// Promote additional arguments to variadic methods.
|
|
|
|
if (Method->isVariadic()) {
|
2010-04-22 20:44:27 +04:00
|
|
|
for (unsigned i = NumNamedArgs; i < NumArgs; ++i) {
|
|
|
|
if (Args[i]->isTypeDependent())
|
|
|
|
continue;
|
|
|
|
|
2009-04-12 12:11:20 +04:00
|
|
|
IsError |= DefaultVariadicArgumentPromotion(Args[i], VariadicMethod);
|
2010-04-22 20:44:27 +04:00
|
|
|
}
|
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)
|
2010-04-16 08:56:46 +04:00
|
|
|
<< 2 /*method*/ << NumNamedArgs << NumArgs
|
|
|
|
<< 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
DiagnoseSentinelCalls(Method, lbrac, Args, NumArgs);
|
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;
|
|
|
|
}
|
|
|
|
|
2010-04-11 11:45:24 +04:00
|
|
|
/// HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an
|
|
|
|
/// objective C interface. This is a property reference expression.
|
|
|
|
Action::OwningExprResult Sema::
|
|
|
|
HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
|
2010-04-11 11:51:10 +04:00
|
|
|
Expr *BaseExpr, DeclarationName MemberName,
|
|
|
|
SourceLocation MemberLoc) {
|
2010-04-11 11:45:24 +04:00
|
|
|
const ObjCInterfaceType *IFaceT = OPT->getInterfaceType();
|
|
|
|
ObjCInterfaceDecl *IFace = IFaceT->getDecl();
|
|
|
|
IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
|
|
|
|
|
|
|
|
// Search for a declared property first.
|
|
|
|
if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(Member)) {
|
|
|
|
// Check whether we can reference this property.
|
|
|
|
if (DiagnoseUseOfDecl(PD, MemberLoc))
|
|
|
|
return ExprError();
|
|
|
|
QualType ResTy = PD->getType();
|
|
|
|
Selector Sel = PP.getSelectorTable().getNullarySelector(Member);
|
|
|
|
ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Sel);
|
|
|
|
if (DiagnosePropertyAccessorMismatch(PD, Getter, MemberLoc))
|
|
|
|
ResTy = Getter->getResultType();
|
|
|
|
return Owned(new (Context) ObjCPropertyRefExpr(PD, ResTy,
|
|
|
|
MemberLoc, BaseExpr));
|
|
|
|
}
|
|
|
|
// Check protocols on qualified interfaces.
|
|
|
|
for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(),
|
|
|
|
E = OPT->qual_end(); I != E; ++I)
|
|
|
|
if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(Member)) {
|
|
|
|
// Check whether we can reference this property.
|
|
|
|
if (DiagnoseUseOfDecl(PD, MemberLoc))
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
|
|
|
|
MemberLoc, BaseExpr));
|
|
|
|
}
|
|
|
|
// If that failed, look for an "implicit" property by seeing if the nullary
|
|
|
|
// selector is implemented.
|
|
|
|
|
|
|
|
// FIXME: The logic for looking up nullary and unary selectors should be
|
|
|
|
// shared with the code in ActOnInstanceMessage.
|
|
|
|
|
|
|
|
Selector Sel = PP.getSelectorTable().getNullarySelector(Member);
|
|
|
|
ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Sel);
|
|
|
|
|
|
|
|
// If this reference is in an @implementation, check for 'private' methods.
|
|
|
|
if (!Getter)
|
|
|
|
Getter = IFace->lookupPrivateInstanceMethod(Sel);
|
|
|
|
|
|
|
|
// Look through local category implementations associated with the class.
|
|
|
|
if (!Getter)
|
|
|
|
Getter = IFace->getCategoryInstanceMethod(Sel);
|
|
|
|
if (Getter) {
|
|
|
|
// Check if we can reference this property.
|
|
|
|
if (DiagnoseUseOfDecl(Getter, MemberLoc))
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
// If we found a getter then this may be a valid dot-reference, we
|
|
|
|
// will look for the matching setter, in case it is needed.
|
|
|
|
Selector SetterSel =
|
|
|
|
SelectorTable::constructSetterName(PP.getIdentifierTable(),
|
|
|
|
PP.getSelectorTable(), Member);
|
|
|
|
ObjCMethodDecl *Setter = IFace->lookupInstanceMethod(SetterSel);
|
|
|
|
if (!Setter) {
|
|
|
|
// If this reference is in an @implementation, also check for 'private'
|
|
|
|
// methods.
|
|
|
|
Setter = IFace->lookupPrivateInstanceMethod(SetterSel);
|
|
|
|
}
|
|
|
|
// Look through local category implementations associated with the class.
|
|
|
|
if (!Setter)
|
|
|
|
Setter = IFace->getCategoryInstanceMethod(SetterSel);
|
|
|
|
|
|
|
|
if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (Getter) {
|
|
|
|
QualType PType;
|
|
|
|
PType = Getter->getResultType();
|
|
|
|
return Owned(new (Context) ObjCImplicitSetterGetterRefExpr(Getter, PType,
|
|
|
|
Setter, MemberLoc, BaseExpr));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to correct for typos in property names.
|
|
|
|
LookupResult Res(*this, MemberName, MemberLoc, LookupOrdinaryName);
|
2010-04-15 00:04:41 +04:00
|
|
|
if (CorrectTypo(Res, 0, 0, IFace, false, CTC_NoKeywords, OPT) &&
|
2010-04-11 11:45:24 +04:00
|
|
|
Res.getAsSingle<ObjCPropertyDecl>()) {
|
2010-04-11 11:51:10 +04:00
|
|
|
DeclarationName TypoResult = Res.getLookupName();
|
2010-04-11 11:45:24 +04:00
|
|
|
Diag(MemberLoc, diag::err_property_not_found_suggest)
|
2010-04-11 11:51:10 +04:00
|
|
|
<< MemberName << QualType(OPT, 0) << TypoResult
|
|
|
|
<< FixItHint::CreateReplacement(MemberLoc, TypoResult.getAsString());
|
2010-04-11 11:45:24 +04:00
|
|
|
ObjCPropertyDecl *Property = Res.getAsSingle<ObjCPropertyDecl>();
|
|
|
|
Diag(Property->getLocation(), diag::note_previous_decl)
|
|
|
|
<< Property->getDeclName();
|
2010-04-11 11:51:10 +04:00
|
|
|
return HandleExprPropertyRefExpr(OPT, BaseExpr, TypoResult, MemberLoc);
|
2010-04-11 11:45:24 +04:00
|
|
|
}
|
2010-04-11 11:51:10 +04:00
|
|
|
|
2010-04-11 11:45:24 +04:00
|
|
|
Diag(MemberLoc, diag::err_property_not_found)
|
|
|
|
<< MemberName << QualType(OPT, 0);
|
|
|
|
if (Setter && !Getter)
|
|
|
|
Diag(Setter->getLocation(), diag::note_getter_unavailable)
|
|
|
|
<< MemberName << BaseExpr->getSourceRange();
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-11 12:28:14 +04:00
|
|
|
Action::OwningExprResult Sema::
|
|
|
|
ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
|
|
|
|
IdentifierInfo &propertyName,
|
|
|
|
SourceLocation receiverNameLoc,
|
|
|
|
SourceLocation propertyNameLoc) {
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-01-03 21:01:57 +03:00
|
|
|
IdentifierInfo *receiverNamePtr = &receiverName;
|
2010-04-16 02:33:43 +04:00
|
|
|
ObjCInterfaceDecl *IFace = getObjCInterfaceDecl(receiverNamePtr,
|
|
|
|
receiverNameLoc);
|
2010-04-11 12:28:14 +04:00
|
|
|
if (IFace == 0) {
|
|
|
|
// If the "receiver" is 'super' in a method, handle it as an expression-like
|
|
|
|
// property reference.
|
|
|
|
if (ObjCMethodDecl *CurMethod = getCurMethodDecl())
|
|
|
|
if (receiverNamePtr->isStr("super")) {
|
|
|
|
if (CurMethod->isInstanceMethod()) {
|
|
|
|
QualType T =
|
|
|
|
Context.getObjCInterfaceType(CurMethod->getClassInterface());
|
|
|
|
T = Context.getObjCObjectPointerType(T);
|
|
|
|
Expr *SuperExpr = new (Context) ObjCSuperExpr(receiverNameLoc, T);
|
|
|
|
|
|
|
|
return HandleExprPropertyRefExpr(T->getAsObjCInterfacePointerType(),
|
|
|
|
SuperExpr, &propertyName,
|
|
|
|
propertyNameLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, if this is a class method, try dispatching to our
|
|
|
|
// superclass.
|
|
|
|
IFace = CurMethod->getClassInterface()->getSuperClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IFace == 0) {
|
|
|
|
Diag(receiverNameLoc, diag::err_expected_ident_or_lparen);
|
|
|
|
return ExprError();
|
|
|
|
}
|
2010-03-23 00:02:34 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-04-11 12:28:14 +04:00
|
|
|
// Search for a declared property first.
|
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));
|
|
|
|
}
|
|
|
|
|
2010-04-14 06:46:37 +04:00
|
|
|
Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S,
|
2010-04-22 00:38:13 +04:00
|
|
|
IdentifierInfo *Name,
|
2010-04-14 06:46:37 +04:00
|
|
|
SourceLocation NameLoc,
|
|
|
|
bool IsSuper,
|
2010-04-22 00:38:13 +04:00
|
|
|
bool HasTrailingDot,
|
|
|
|
TypeTy *&ReceiverType) {
|
|
|
|
ReceiverType = 0;
|
|
|
|
|
2010-04-14 06:46:37 +04:00
|
|
|
// If the identifier is "super" and there is no trailing dot, we're
|
|
|
|
// messaging super.
|
|
|
|
if (IsSuper && !HasTrailingDot && S->isInObjcMethodScope())
|
|
|
|
return ObjCSuperMessage;
|
|
|
|
|
|
|
|
LookupResult Result(*this, Name, NameLoc, LookupOrdinaryName);
|
|
|
|
LookupName(Result, S);
|
|
|
|
|
|
|
|
switch (Result.getResultKind()) {
|
|
|
|
case LookupResult::NotFound:
|
2010-04-20 00:09:36 +04:00
|
|
|
// Normal name lookup didn't find anything. If we're in an
|
|
|
|
// Objective-C method, look for ivars. If we find one, we're done!
|
|
|
|
// FIXME: This is a hack. Ivar lookup should be part of normal lookup.
|
|
|
|
if (ObjCMethodDecl *Method = getCurMethodDecl()) {
|
|
|
|
ObjCInterfaceDecl *ClassDeclared;
|
|
|
|
if (Method->getClassInterface()->lookupInstanceVariable(Name,
|
|
|
|
ClassDeclared))
|
|
|
|
return ObjCInstanceMessage;
|
|
|
|
}
|
|
|
|
|
2010-04-14 06:46:37 +04:00
|
|
|
// Break out; we'll perform typo correction below.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LookupResult::NotFoundInCurrentInstantiation:
|
|
|
|
case LookupResult::FoundOverloaded:
|
|
|
|
case LookupResult::FoundUnresolvedValue:
|
|
|
|
case LookupResult::Ambiguous:
|
|
|
|
Result.suppressDiagnostics();
|
|
|
|
return ObjCInstanceMessage;
|
|
|
|
|
|
|
|
case LookupResult::Found: {
|
|
|
|
// We found something. If it's a type, then we have a class
|
|
|
|
// message. Otherwise, it's an instance message.
|
|
|
|
NamedDecl *ND = Result.getFoundDecl();
|
2010-04-22 00:38:13 +04:00
|
|
|
QualType T;
|
|
|
|
if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(ND))
|
|
|
|
T = Context.getObjCInterfaceType(Class);
|
|
|
|
else if (TypeDecl *Type = dyn_cast<TypeDecl>(ND))
|
|
|
|
T = Context.getTypeDeclType(Type);
|
|
|
|
else
|
|
|
|
return ObjCInstanceMessage;
|
|
|
|
|
|
|
|
// We have a class message, and T is the type we're
|
|
|
|
// messaging. Build source-location information for it.
|
|
|
|
TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
|
|
|
|
ReceiverType = CreateLocInfoType(T, TSInfo).getAsOpaquePtr();
|
|
|
|
return ObjCClassMessage;
|
2010-04-14 06:46:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-15 00:04:41 +04:00
|
|
|
// Determine our typo-correction context.
|
|
|
|
CorrectTypoContext CTC = CTC_Expression;
|
|
|
|
if (ObjCMethodDecl *Method = getCurMethodDecl())
|
|
|
|
if (Method->getClassInterface() &&
|
|
|
|
Method->getClassInterface()->getSuperClass())
|
|
|
|
CTC = CTC_ObjCMessageReceiver;
|
|
|
|
|
|
|
|
if (DeclarationName Corrected = CorrectTypo(Result, S, 0, 0, false, CTC)) {
|
|
|
|
if (Result.isSingleResult()) {
|
|
|
|
// If we found a declaration, correct when it refers to an Objective-C
|
|
|
|
// class.
|
|
|
|
NamedDecl *ND = Result.getFoundDecl();
|
2010-04-22 00:38:13 +04:00
|
|
|
if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(ND)) {
|
2010-04-15 00:04:41 +04:00
|
|
|
Diag(NameLoc, diag::err_unknown_receiver_suggest)
|
|
|
|
<< Name << Result.getLookupName()
|
|
|
|
<< FixItHint::CreateReplacement(SourceRange(NameLoc),
|
|
|
|
ND->getNameAsString());
|
|
|
|
Diag(ND->getLocation(), diag::note_previous_decl)
|
|
|
|
<< Corrected;
|
|
|
|
|
2010-04-22 00:38:13 +04:00
|
|
|
QualType T = Context.getObjCInterfaceType(Class);
|
|
|
|
TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
|
|
|
|
ReceiverType = CreateLocInfoType(T, TSInfo).getAsOpaquePtr();
|
2010-04-15 00:04:41 +04:00
|
|
|
return ObjCClassMessage;
|
|
|
|
}
|
|
|
|
} else if (Result.empty() && Corrected.getAsIdentifierInfo() &&
|
|
|
|
Corrected.getAsIdentifierInfo()->isStr("super")) {
|
|
|
|
// If we've found the keyword "super", this is a send to super.
|
2010-04-14 06:46:37 +04:00
|
|
|
Diag(NameLoc, diag::err_unknown_receiver_suggest)
|
2010-04-15 00:04:41 +04:00
|
|
|
<< Name << Corrected
|
|
|
|
<< FixItHint::CreateReplacement(SourceRange(NameLoc), "super");
|
|
|
|
Name = Corrected.getAsIdentifierInfo();
|
|
|
|
return ObjCSuperMessage;
|
2010-04-14 06:46:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back: let the parser try to parse it as an instance message.
|
|
|
|
return ObjCInstanceMessage;
|
|
|
|
}
|
2009-03-10 00:12:44 +03:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
Sema::OwningExprResult Sema::ActOnSuperMessage(Scope *S,
|
|
|
|
SourceLocation SuperLoc,
|
|
|
|
Selector Sel,
|
|
|
|
SourceLocation LBracLoc,
|
|
|
|
SourceLocation SelectorLoc,
|
|
|
|
SourceLocation RBracLoc,
|
|
|
|
MultiExprArg Args) {
|
|
|
|
// Determine whether we are inside a method or not.
|
|
|
|
ObjCMethodDecl *Method = getCurMethodDecl();
|
2010-04-22 00:01:04 +04:00
|
|
|
if (!Method) {
|
|
|
|
Diag(SuperLoc, diag::err_invalid_receiver_to_message_super);
|
|
|
|
return ExprError();
|
|
|
|
}
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
|
2010-04-22 00:01:04 +04:00
|
|
|
ObjCInterfaceDecl *Class = Method->getClassInterface();
|
|
|
|
if (!Class) {
|
|
|
|
Diag(SuperLoc, diag::error_no_super_class_message)
|
|
|
|
<< Method->getDeclName();
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
return ExprError();
|
2010-04-12 09:38:43 +04:00
|
|
|
}
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
|
2010-04-22 00:01:04 +04:00
|
|
|
ObjCInterfaceDecl *Super = Class->getSuperClass();
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
if (!Super) {
|
2010-04-22 00:01:04 +04:00
|
|
|
// The current class does not have a superclass.
|
|
|
|
Diag(SuperLoc, diag::error_no_super_class) << Class->getIdentifier();
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
2010-04-22 00:01:04 +04:00
|
|
|
// We are in a method whose class has a superclass, so 'super'
|
|
|
|
// is acting as a keyword.
|
|
|
|
if (Method->isInstanceMethod()) {
|
|
|
|
// Since we are in an instance method, this is an instance
|
|
|
|
// message to the superclass instance.
|
|
|
|
QualType SuperTy = Context.getObjCInterfaceType(Super);
|
|
|
|
SuperTy = Context.getObjCObjectPointerType(SuperTy);
|
|
|
|
return BuildInstanceMessage(ExprArg(*this), SuperTy, SuperLoc,
|
2010-04-22 21:01:48 +04:00
|
|
|
Sel, /*Method=*/0, LBracLoc, RBracLoc,
|
|
|
|
move(Args));
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
}
|
2010-04-22 00:01:04 +04:00
|
|
|
|
|
|
|
// Since we are in a class method, this is a class message to
|
|
|
|
// the superclass.
|
|
|
|
return BuildClassMessage(/*ReceiverTypeInfo=*/0,
|
|
|
|
Context.getObjCInterfaceType(Super),
|
2010-04-22 21:01:48 +04:00
|
|
|
SuperLoc, Sel, /*Method=*/0, LBracLoc, RBracLoc,
|
|
|
|
move(Args));
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build an Objective-C class message expression.
|
|
|
|
///
|
|
|
|
/// This routine takes care of both normal class messages and
|
|
|
|
/// class messages to the superclass.
|
|
|
|
///
|
|
|
|
/// \param ReceiverTypeInfo Type source information that describes the
|
|
|
|
/// receiver of this message. This may be NULL, in which case we are
|
|
|
|
/// sending to the superclass and \p SuperLoc must be a valid source
|
|
|
|
/// location.
|
|
|
|
|
|
|
|
/// \param ReceiverType The type of the object receiving the
|
|
|
|
/// message. When \p ReceiverTypeInfo is non-NULL, this is the same
|
|
|
|
/// type as that refers to. For a superclass send, this is the type of
|
|
|
|
/// the superclass.
|
|
|
|
///
|
|
|
|
/// \param SuperLoc The location of the "super" keyword in a
|
|
|
|
/// superclass message.
|
|
|
|
///
|
|
|
|
/// \param Sel The selector to which the message is being sent.
|
|
|
|
///
|
2010-04-22 21:01:48 +04:00
|
|
|
/// \param Method The method that this class message is invoking, if
|
|
|
|
/// already known.
|
|
|
|
///
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
/// \param LBracLoc The location of the opening square bracket ']'.
|
|
|
|
///
|
|
|
|
/// \param RBrac The location of the closing square bracket ']'.
|
|
|
|
///
|
|
|
|
/// \param Args The message arguments.
|
|
|
|
Sema::OwningExprResult Sema::BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
|
|
|
|
QualType ReceiverType,
|
|
|
|
SourceLocation SuperLoc,
|
|
|
|
Selector Sel,
|
2010-04-22 21:01:48 +04:00
|
|
|
ObjCMethodDecl *Method,
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
SourceLocation LBracLoc,
|
|
|
|
SourceLocation RBracLoc,
|
|
|
|
MultiExprArg ArgsIn) {
|
2010-04-22 20:44:27 +04:00
|
|
|
if (ReceiverType->isDependentType()) {
|
|
|
|
// If the receiver type is dependent, we can't type-check anything
|
|
|
|
// at this point. Build a dependent expression.
|
|
|
|
unsigned NumArgs = ArgsIn.size();
|
|
|
|
Expr **Args = reinterpret_cast<Expr **>(ArgsIn.release());
|
|
|
|
assert(SuperLoc.isInvalid() && "Message to super with dependent type");
|
|
|
|
return Owned(ObjCMessageExpr::Create(Context, ReceiverType, LBracLoc,
|
|
|
|
ReceiverTypeInfo, Sel, /*Method=*/0,
|
|
|
|
Args, NumArgs, RBracLoc));
|
|
|
|
}
|
2010-04-12 09:38:43 +04:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
SourceLocation Loc = SuperLoc.isValid()? SuperLoc
|
|
|
|
: ReceiverTypeInfo->getTypeLoc().getSourceRange().getBegin();
|
|
|
|
|
|
|
|
// Find the class to which we are sending this message.
|
|
|
|
ObjCInterfaceDecl *Class = 0;
|
|
|
|
if (const ObjCInterfaceType *ClassType
|
|
|
|
= ReceiverType->getAs<ObjCInterfaceType>())
|
|
|
|
Class = ClassType->getDecl();
|
|
|
|
else {
|
|
|
|
Diag(Loc, diag::err_invalid_receiver_class_message)
|
|
|
|
<< ReceiverType;
|
|
|
|
return ExprError();
|
2008-07-25 23:39:00 +04:00
|
|
|
}
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
assert(Class && "We don't know which class we're messaging?");
|
|
|
|
|
|
|
|
// Find the method we are messaging.
|
2010-04-22 21:01:48 +04:00
|
|
|
if (!Method) {
|
|
|
|
if (Class->isForwardDecl()) {
|
|
|
|
// A forward class used in messaging is treated as a 'Class'
|
|
|
|
Diag(Loc, diag::warn_receiver_forward_class) << Class->getDeclName();
|
|
|
|
Method = LookupFactoryMethodInGlobalPool(Sel,
|
|
|
|
SourceRange(LBracLoc, RBracLoc));
|
|
|
|
if (Method)
|
|
|
|
Diag(Method->getLocation(), diag::note_method_sent_forward_class)
|
|
|
|
<< Method->getDeclName();
|
|
|
|
}
|
|
|
|
if (!Method)
|
|
|
|
Method = Class->lookupClassMethod(Sel);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-04-22 21:01:48 +04:00
|
|
|
// If we have an implementation in scope, check "private" methods.
|
|
|
|
if (!Method)
|
|
|
|
Method = LookupPrivateClassMethod(Sel, Class);
|
2008-07-25 23:39:00 +04:00
|
|
|
|
2010-04-22 21:01:48 +04:00
|
|
|
if (Method && DiagnoseUseOfDecl(Method, Loc))
|
|
|
|
return ExprError();
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
// Check the argument types and determine the result type.
|
|
|
|
QualType ReturnType;
|
|
|
|
unsigned NumArgs = ArgsIn.size();
|
|
|
|
Expr **Args = reinterpret_cast<Expr **>(ArgsIn.release());
|
|
|
|
if (CheckMessageArgumentTypes(Args, NumArgs, Sel, Method, true,
|
|
|
|
LBracLoc, RBracLoc, ReturnType)) {
|
|
|
|
for (unsigned I = 0; I != NumArgs; ++I)
|
|
|
|
Args[I]->Destroy(Context);
|
|
|
|
return ExprError();
|
|
|
|
}
|
2008-06-24 19:50:53 +04:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
// Construct the appropriate ObjCMessageExpr.
|
|
|
|
if (SuperLoc.isValid())
|
|
|
|
return Owned(ObjCMessageExpr::Create(Context, ReturnType, LBracLoc,
|
|
|
|
SuperLoc, /*IsInstanceSuper=*/false,
|
|
|
|
ReceiverType, Sel, Method, Args,
|
|
|
|
NumArgs, RBracLoc));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
return Owned(ObjCMessageExpr::Create(Context, ReturnType, LBracLoc,
|
|
|
|
ReceiverTypeInfo, Sel, Method, Args,
|
|
|
|
NumArgs, RBracLoc));
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
// ActOnClassMessage - used for both unary and keyword messages.
|
2008-01-05 01:32:30 +03:00
|
|
|
// ArgExprs is optional - if it is present, the number of expressions
|
|
|
|
// is obtained from Sel.getNumArgs().
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
Sema::OwningExprResult Sema::ActOnClassMessage(Scope *S,
|
|
|
|
TypeTy *Receiver,
|
|
|
|
Selector Sel,
|
|
|
|
SourceLocation LBracLoc,
|
|
|
|
SourceLocation SelectorLoc,
|
|
|
|
SourceLocation RBracLoc,
|
|
|
|
MultiExprArg Args) {
|
|
|
|
TypeSourceInfo *ReceiverTypeInfo;
|
|
|
|
QualType ReceiverType = GetTypeFromParser(Receiver, &ReceiverTypeInfo);
|
|
|
|
if (ReceiverType.isNull())
|
|
|
|
return ExprError();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
if (!ReceiverTypeInfo)
|
|
|
|
ReceiverTypeInfo = Context.getTrivialTypeSourceInfo(ReceiverType, LBracLoc);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
return BuildClassMessage(ReceiverTypeInfo, ReceiverType,
|
2010-04-22 21:01:48 +04:00
|
|
|
/*SuperLoc=*/SourceLocation(), Sel, /*Method=*/0,
|
2010-04-22 20:50:51 +04:00
|
|
|
LBracLoc, RBracLoc, move(Args));
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
}
|
2008-11-18 01:29:32 +03:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
/// \brief Build an Objective-C instance message expression.
|
|
|
|
///
|
|
|
|
/// This routine takes care of both normal instance messages and
|
|
|
|
/// instance messages to the superclass instance.
|
|
|
|
///
|
|
|
|
/// \param Receiver The expression that computes the object that will
|
|
|
|
/// receive this message. This may be empty, in which case we are
|
|
|
|
/// sending to the superclass instance and \p SuperLoc must be a valid
|
|
|
|
/// source location.
|
|
|
|
///
|
|
|
|
/// \param ReceiverType The (static) type of the object receiving the
|
|
|
|
/// message. When a \p Receiver expression is provided, this is the
|
|
|
|
/// same type as that expression. For a superclass instance send, this
|
|
|
|
/// is a pointer to the type of the superclass.
|
|
|
|
///
|
|
|
|
/// \param SuperLoc The location of the "super" keyword in a
|
|
|
|
/// superclass instance message.
|
|
|
|
///
|
|
|
|
/// \param Sel The selector to which the message is being sent.
|
|
|
|
///
|
2010-04-22 21:01:48 +04:00
|
|
|
/// \param Method The method that this instance message is invoking, if
|
|
|
|
/// already known.
|
|
|
|
///
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
/// \param LBracLoc The location of the opening square bracket ']'.
|
|
|
|
///
|
|
|
|
/// \param RBrac The location of the closing square bracket ']'.
|
|
|
|
///
|
|
|
|
/// \param Args The message arguments.
|
|
|
|
Sema::OwningExprResult Sema::BuildInstanceMessage(ExprArg ReceiverE,
|
|
|
|
QualType ReceiverType,
|
|
|
|
SourceLocation SuperLoc,
|
|
|
|
Selector Sel,
|
2010-04-22 21:01:48 +04:00
|
|
|
ObjCMethodDecl *Method,
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
SourceLocation LBracLoc,
|
|
|
|
SourceLocation RBracLoc,
|
|
|
|
MultiExprArg ArgsIn) {
|
|
|
|
// If we have a receiver expression, perform appropriate promotions
|
|
|
|
// and determine receiver type.
|
|
|
|
Expr *Receiver = ReceiverE.takeAs<Expr>();
|
|
|
|
if (Receiver) {
|
2010-04-22 20:44:27 +04:00
|
|
|
if (Receiver->isTypeDependent()) {
|
|
|
|
// If the receiver is type-dependent, we can't type-check anything
|
|
|
|
// at this point. Build a dependent expression.
|
|
|
|
unsigned NumArgs = ArgsIn.size();
|
|
|
|
Expr **Args = reinterpret_cast<Expr **>(ArgsIn.release());
|
|
|
|
assert(SuperLoc.isInvalid() && "Message to super with dependent type");
|
|
|
|
return Owned(ObjCMessageExpr::Create(Context, Context.DependentTy,
|
|
|
|
LBracLoc, Receiver, Sel,
|
|
|
|
/*Method=*/0, Args, NumArgs,
|
|
|
|
RBracLoc));
|
|
|
|
}
|
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
// If necessary, apply function/array conversion to the receiver.
|
|
|
|
// C99 6.7.5.3p[7,8].
|
|
|
|
DefaultFunctionArrayLvalueConversion(Receiver);
|
|
|
|
ReceiverType = Receiver->getType();
|
|
|
|
}
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
// The location of the receiver.
|
|
|
|
SourceLocation Loc = SuperLoc.isValid()? SuperLoc : Receiver->getLocStart();
|
|
|
|
|
2010-04-22 21:01:48 +04:00
|
|
|
if (!Method) {
|
|
|
|
// Handle messages to id.
|
|
|
|
if (ReceiverType->isObjCIdType() || ReceiverType->isBlockPointerType() ||
|
|
|
|
(Receiver && Context.isObjCNSObjectType(Receiver->getType()))) {
|
|
|
|
Method = LookupInstanceMethodInGlobalPool(Sel,
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
SourceRange(LBracLoc, RBracLoc));
|
2010-04-22 21:01:48 +04:00
|
|
|
if (!Method)
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
Method = LookupFactoryMethodInGlobalPool(Sel,
|
2010-04-22 21:01:48 +04:00
|
|
|
SourceRange(LBracLoc, RBracLoc));
|
|
|
|
} else if (ReceiverType->isObjCClassType() ||
|
|
|
|
ReceiverType->isObjCQualifiedClassType()) {
|
|
|
|
// Handle messages to Class.
|
|
|
|
if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) {
|
|
|
|
if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) {
|
|
|
|
// First check the public methods in the class interface.
|
|
|
|
Method = ClassDecl->lookupClassMethod(Sel);
|
|
|
|
|
|
|
|
if (!Method)
|
|
|
|
Method = LookupPrivateClassMethod(Sel, ClassDecl);
|
|
|
|
|
|
|
|
// FIXME: if we still haven't found a method, we need to look in
|
|
|
|
// protocols (if we have qualifiers).
|
2009-03-04 18:11:40 +03:00
|
|
|
}
|
2010-04-22 21:01:48 +04:00
|
|
|
if (Method && DiagnoseUseOfDecl(Method, Loc))
|
|
|
|
return ExprError();
|
2009-03-04 01:19:15 +03:00
|
|
|
}
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
if (!Method) {
|
2010-04-22 21:01:48 +04:00
|
|
|
// If not messaging 'self', look for any factory method named 'Sel'.
|
|
|
|
if (!Receiver || !isSelfExpr(Receiver)) {
|
|
|
|
Method = LookupFactoryMethodInGlobalPool(Sel,
|
|
|
|
SourceRange(LBracLoc, RBracLoc));
|
|
|
|
if (!Method) {
|
|
|
|
// If no class (factory) method was found, check if an _instance_
|
|
|
|
// method of the same name exists in the root class only.
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
Method = LookupInstanceMethodInGlobalPool(Sel,
|
|
|
|
SourceRange(LBracLoc, RBracLoc));
|
2010-04-22 21:01:48 +04:00
|
|
|
if (Method)
|
|
|
|
if (const ObjCInterfaceDecl *ID =
|
|
|
|
dyn_cast<ObjCInterfaceDecl>(Method->getDeclContext())) {
|
|
|
|
if (ID->getSuperClass())
|
|
|
|
Diag(Loc, diag::warn_root_inst_method_not_found)
|
|
|
|
<< Sel << SourceRange(LBracLoc, RBracLoc);
|
|
|
|
}
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-04-22 21:01:48 +04:00
|
|
|
ObjCInterfaceDecl* ClassDecl = 0;
|
|
|
|
|
|
|
|
// We allow sending a message to a qualified ID ("id<foo>"), which is ok as
|
|
|
|
// long as one of the protocols implements the selector (if not, warn).
|
|
|
|
if (const ObjCObjectPointerType *QIdTy
|
|
|
|
= ReceiverType->getAsObjCQualifiedIdType()) {
|
|
|
|
// Search protocols for instance methods.
|
|
|
|
for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(),
|
|
|
|
E = QIdTy->qual_end(); I != E; ++I) {
|
|
|
|
ObjCProtocolDecl *PDecl = *I;
|
|
|
|
if (PDecl && (Method = PDecl->lookupInstanceMethod(Sel)))
|
|
|
|
break;
|
|
|
|
// Since we aren't supporting "Class<foo>", look for a class method.
|
|
|
|
if (PDecl && (Method = PDecl->lookupClassMethod(Sel)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (const ObjCObjectPointerType *OCIType
|
|
|
|
= ReceiverType->getAsObjCInterfacePointerType()) {
|
|
|
|
// We allow sending a message to a pointer to an interface (an object).
|
|
|
|
ClassDecl = OCIType->getInterfaceDecl();
|
|
|
|
// FIXME: consider using LookupInstanceMethodInGlobalPool, since it will be
|
|
|
|
// faster than the following method (which can do *many* linear searches).
|
|
|
|
// The idea is to add class info to InstanceMethodPool.
|
|
|
|
Method = ClassDecl->lookupInstanceMethod(Sel);
|
|
|
|
|
|
|
|
if (!Method) {
|
|
|
|
// Search protocol qualifiers.
|
|
|
|
for (ObjCObjectPointerType::qual_iterator QI = OCIType->qual_begin(),
|
|
|
|
E = OCIType->qual_end(); QI != E; ++QI) {
|
|
|
|
if ((Method = (*QI)->lookupInstanceMethod(Sel)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!Method) {
|
|
|
|
// If we have implementations in scope, check "private" methods.
|
|
|
|
Method = LookupPrivateInstanceMethod(Sel, ClassDecl);
|
|
|
|
|
|
|
|
if (!Method && (!Receiver || !isSelfExpr(Receiver))) {
|
|
|
|
// 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??
|
|
|
|
if (OCIType->qual_empty()) {
|
|
|
|
Method = LookupInstanceMethodInGlobalPool(Sel,
|
|
|
|
SourceRange(LBracLoc, RBracLoc));
|
|
|
|
if (Method && !OCIType->getInterfaceDecl()->isForwardDecl())
|
|
|
|
Diag(Loc, diag::warn_maynot_respond)
|
|
|
|
<< OCIType->getInterfaceDecl()->getIdentifier() << Sel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Method && DiagnoseUseOfDecl(Method, Loc))
|
|
|
|
return ExprError();
|
|
|
|
} else if (!Context.getObjCIdType().isNull() &&
|
|
|
|
(ReceiverType->isPointerType() ||
|
|
|
|
(ReceiverType->isIntegerType() &&
|
|
|
|
ReceiverType->isScalarType()))) {
|
|
|
|
// Implicitly convert integers and pointers to 'id' but emit a warning.
|
|
|
|
Diag(Loc, diag::warn_bad_receiver_type)
|
|
|
|
<< ReceiverType
|
|
|
|
<< Receiver->getSourceRange();
|
|
|
|
if (ReceiverType->isPointerType())
|
|
|
|
ImpCastExprToType(Receiver, Context.getObjCIdType(),
|
|
|
|
CastExpr::CK_BitCast);
|
|
|
|
else
|
|
|
|
ImpCastExprToType(Receiver, Context.getObjCIdType(),
|
|
|
|
CastExpr::CK_IntegralToPointer);
|
|
|
|
ReceiverType = Receiver->getType();
|
|
|
|
} else {
|
|
|
|
// Reject other random receiver types (e.g. structs).
|
|
|
|
Diag(Loc, diag::err_bad_receiver_type)
|
|
|
|
<< ReceiverType << Receiver->getSourceRange();
|
|
|
|
return ExprError();
|
|
|
|
}
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
}
|
2008-07-21 09:57:44 +04:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
// Check the message arguments.
|
|
|
|
unsigned NumArgs = ArgsIn.size();
|
|
|
|
Expr **Args = reinterpret_cast<Expr **>(ArgsIn.release());
|
|
|
|
QualType ReturnType;
|
|
|
|
if (CheckMessageArgumentTypes(Args, NumArgs, Sel, Method, false,
|
|
|
|
LBracLoc, RBracLoc, ReturnType))
|
|
|
|
return ExprError();
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
// Construct the appropriate ObjCMessageExpr instance.
|
|
|
|
if (SuperLoc.isValid())
|
|
|
|
return Owned(ObjCMessageExpr::Create(Context, ReturnType, LBracLoc,
|
|
|
|
SuperLoc, /*IsInstanceSuper=*/true,
|
|
|
|
ReceiverType, Sel, Method,
|
|
|
|
Args, NumArgs, RBracLoc));
|
|
|
|
|
|
|
|
return Owned(ObjCMessageExpr::Create(Context, ReturnType, LBracLoc, Receiver,
|
|
|
|
Sel, Method, Args, NumArgs, RBracLoc));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ActOnInstanceMessage - used for both unary and keyword messages.
|
|
|
|
// ArgExprs is optional - if it is present, the number of expressions
|
|
|
|
// is obtained from Sel.getNumArgs().
|
|
|
|
Sema::OwningExprResult Sema::ActOnInstanceMessage(Scope *S,
|
|
|
|
ExprArg ReceiverE,
|
|
|
|
Selector Sel,
|
|
|
|
SourceLocation LBracLoc,
|
|
|
|
SourceLocation SelectorLoc,
|
|
|
|
SourceLocation RBracLoc,
|
|
|
|
MultiExprArg Args) {
|
|
|
|
Expr *Receiver = static_cast<Expr *>(ReceiverE.get());
|
|
|
|
if (!Receiver)
|
|
|
|
return ExprError();
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102021 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:57:20 +04:00
|
|
|
return BuildInstanceMessage(move(ReceiverE), Receiver->getType(),
|
2010-04-22 21:01:48 +04:00
|
|
|
/*SuperLoc=*/SourceLocation(), Sel, /*Method=*/0,
|
|
|
|
LBracLoc, RBracLoc, move(Args));
|
2008-01-05 01:32:30 +03:00
|
|
|
}
|
2008-04-07 09:30:13 +04:00
|
|
|
|