Keep the source location of the selector in ObjCMessageExpr.

llvm-svn: 121516
This commit is contained in:
Argyrios Kyrtzidis 2010-12-10 20:08:27 +00:00
parent e54c2a8fd8
commit d0039e56f2
8 changed files with 78 additions and 47 deletions

View File

@ -426,6 +426,9 @@ class ObjCMessageExpr : public Expr {
/// referring to the method that we type-checked against.
uintptr_t SelectorOrMethod;
/// \brief Location of the selector.
SourceLocation SelectorLoc;
/// \brief The source locations of the open and close square
/// brackets ('[' and ']', respectively).
SourceLocation LBracLoc, RBracLoc;
@ -440,6 +443,7 @@ class ObjCMessageExpr : public Expr {
bool IsInstanceSuper,
QualType SuperType,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc);
@ -447,6 +451,7 @@ class ObjCMessageExpr : public Expr {
SourceLocation LBracLoc,
TypeSourceInfo *Receiver,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc);
@ -454,6 +459,7 @@ class ObjCMessageExpr : public Expr {
SourceLocation LBracLoc,
Expr *Receiver,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc);
@ -516,6 +522,7 @@ public:
bool IsInstanceSuper,
QualType SuperType,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc);
@ -550,6 +557,7 @@ public:
SourceLocation LBracLoc,
TypeSourceInfo *Receiver,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc);
@ -584,6 +592,7 @@ public:
SourceLocation LBracLoc,
Expr *Receiver,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc);
@ -751,9 +760,7 @@ public:
SourceLocation getLeftLoc() const { return LBracLoc; }
SourceLocation getRightLoc() const { return RBracLoc; }
void setLeftLoc(SourceLocation L) { LBracLoc = L; }
void setRightLoc(SourceLocation L) { RBracLoc = L; }
SourceLocation getSelectorLoc() const { return SelectorLoc; }
void setSourceRange(SourceRange R) {
LBracLoc = R.getBegin();
@ -779,6 +786,9 @@ public:
arg_iterator arg_end() { return getArgs() + NumArgs; }
const_arg_iterator arg_begin() const { return getArgs(); }
const_arg_iterator arg_end() const { return getArgs() + NumArgs; }
friend class ASTStmtReader;
friend class ASTStmtWriter;
};
/// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.

View File

@ -3868,6 +3868,7 @@ public:
Selector Sel,
ObjCMethodDecl *Method,
SourceLocation LBracLoc,
SourceLocation SelectorLoc,
SourceLocation RBracLoc,
MultiExprArg Args);
@ -3885,6 +3886,7 @@ public:
Selector Sel,
ObjCMethodDecl *Method,
SourceLocation LBracLoc,
SourceLocation SelectorLoc,
SourceLocation RBracLoc,
MultiExprArg Args);

View File

@ -2211,6 +2211,7 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
bool IsInstanceSuper,
QualType SuperType,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc)
@ -2220,7 +2221,7 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
HasMethod(Method != 0), SuperLoc(SuperLoc),
SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
: Sel.getAsOpaquePtr())),
LBracLoc(LBracLoc), RBracLoc(RBracLoc)
SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc)
{
setReceiverPointer(SuperType.getAsOpaquePtr());
if (NumArgs)
@ -2231,7 +2232,8 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
ExprValueKind VK,
SourceLocation LBracLoc,
TypeSourceInfo *Receiver,
Selector Sel,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc)
@ -2241,7 +2243,7 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
NumArgs(NumArgs), Kind(Class), HasMethod(Method != 0),
SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
: Sel.getAsOpaquePtr())),
LBracLoc(LBracLoc), RBracLoc(RBracLoc)
SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc)
{
setReceiverPointer(Receiver);
if (NumArgs)
@ -2253,6 +2255,7 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
SourceLocation LBracLoc,
Expr *Receiver,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc)
@ -2262,7 +2265,7 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
NumArgs(NumArgs), Kind(Instance), HasMethod(Method != 0),
SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
: Sel.getAsOpaquePtr())),
LBracLoc(LBracLoc), RBracLoc(RBracLoc)
SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc)
{
setReceiverPointer(Receiver);
if (NumArgs)
@ -2276,6 +2279,7 @@ ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
bool IsInstanceSuper,
QualType SuperType,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc) {
@ -2283,7 +2287,7 @@ ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
NumArgs * sizeof(Expr *);
void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper,
SuperType, Sel, Method, Args, NumArgs,
SuperType, Sel, SelLoc, Method, Args,NumArgs,
RBracLoc);
}
@ -2292,29 +2296,31 @@ ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
SourceLocation LBracLoc,
TypeSourceInfo *Receiver,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc) {
unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
NumArgs * sizeof(Expr *);
void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, Method, Args,
NumArgs, RBracLoc);
return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, SelLoc,
Method, Args, NumArgs, RBracLoc);
}
ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
ExprValueKind VK,
SourceLocation LBracLoc,
Expr *Receiver,
Selector Sel,
Selector Sel,
SourceLocation SelLoc,
ObjCMethodDecl *Method,
Expr **Args, unsigned NumArgs,
SourceLocation RBracLoc) {
unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
NumArgs * sizeof(Expr *);
void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, Method, Args,
NumArgs, RBracLoc);
return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, SelLoc,
Method, Args, NumArgs, RBracLoc);
}
ObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context,

View File

@ -1228,10 +1228,12 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitSetter(BinaryOperator *BinOp, Expr *
bool Super = false;
QualType SuperTy;
SourceLocation SuperLocation;
SourceLocation SelectorLoc;
// Synthesize a ObjCMessageExpr from a ObjCPropertyRefExpr or ObjCImplicitSetterGetterRefExpr.
// This allows us to reuse all the fun and games in SynthMessageExpr().
if (ObjCPropertyRefExpr *PropRefExpr =
dyn_cast<ObjCPropertyRefExpr>(BinOp->getLHS())) {
SelectorLoc = PropRefExpr->getLocation();
if (PropRefExpr->isExplicitProperty()) {
ObjCPropertyDecl *PDecl = PropRefExpr->getExplicitProperty();
OMD = PDecl->getSetterMethodDecl();
@ -1264,7 +1266,7 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitSetter(BinaryOperator *BinOp, Expr *
SuperLocation,
/*IsInstanceSuper=*/true,
SuperTy,
Sel, OMD,
Sel, SelectorLoc, OMD,
&ExprVec[0], 1,
/*FIXME:*/SourceLocation());
else {
@ -1281,7 +1283,7 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitSetter(BinaryOperator *BinOp, Expr *
Expr::getValueKindForType(Ty),
/*FIXME: */SourceLocation(),
cast<Expr>(Receiver),
Sel, OMD,
Sel, SelectorLoc, OMD,
&ExprVec[0], 1,
/*FIXME:*/SourceLocation());
}
@ -1306,8 +1308,10 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitGetter(Expr *PropOrGetterRefExpr) {
bool Super = false;
QualType SuperTy;
SourceLocation SuperLocation;
SourceLocation SelectorLoc;
if (ObjCPropertyRefExpr *PropRefExpr =
dyn_cast<ObjCPropertyRefExpr>(PropOrGetterRefExpr)) {
SelectorLoc = PropRefExpr->getLocation();
if (PropRefExpr->isExplicitProperty()) {
ObjCPropertyDecl *PDecl = PropRefExpr->getExplicitProperty();
OMD = PDecl->getGetterMethodDecl();
@ -1338,7 +1342,7 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitGetter(Expr *PropOrGetterRefExpr) {
SuperLocation,
/*IsInstanceSuper=*/true,
SuperTy,
Sel, OMD,
Sel, SelectorLoc, OMD,
0, 0,
/*FIXME:*/SourceLocation());
else {
@ -1352,7 +1356,7 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitGetter(Expr *PropOrGetterRefExpr) {
Expr::getValueKindForType(Ty),
/*FIXME:*/SourceLocation(),
cast<Expr>(Receiver),
Sel, OMD,
Sel, SelectorLoc, OMD,
0, 0,
/*FIXME:*/SourceLocation());
}

View File

@ -716,16 +716,16 @@ ExprResult Sema::ActOnSuperMessage(Scope *S,
QualType SuperTy = Context.getObjCInterfaceType(Super);
SuperTy = Context.getObjCObjectPointerType(SuperTy);
return BuildInstanceMessage(0, SuperTy, SuperLoc,
Sel, /*Method=*/0, LBracLoc, RBracLoc,
move(Args));
Sel, /*Method=*/0,
LBracLoc, SelectorLoc, RBracLoc, move(Args));
}
// Since we are in a class method, this is a class message to
// the superclass.
return BuildClassMessage(/*ReceiverTypeInfo=*/0,
Context.getObjCInterfaceType(Super),
SuperLoc, Sel, /*Method=*/0, LBracLoc, RBracLoc,
move(Args));
SuperLoc, Sel, /*Method=*/0,
LBracLoc, SelectorLoc, RBracLoc, move(Args));
}
/// \brief Build an Objective-C class message expression.
@ -762,6 +762,7 @@ ExprResult Sema::BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
Selector Sel,
ObjCMethodDecl *Method,
SourceLocation LBracLoc,
SourceLocation SelectorLoc,
SourceLocation RBracLoc,
MultiExprArg ArgsIn) {
SourceLocation Loc = SuperLoc.isValid()? SuperLoc
@ -780,7 +781,7 @@ ExprResult Sema::BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
assert(SuperLoc.isInvalid() && "Message to super with dependent type");
return Owned(ObjCMessageExpr::Create(Context, ReceiverType,
VK_RValue, LBracLoc, ReceiverTypeInfo,
Sel, /*Method=*/0,
Sel, SelectorLoc, /*Method=*/0,
Args, NumArgs, RBracLoc));
}
@ -831,12 +832,12 @@ ExprResult Sema::BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
if (SuperLoc.isValid())
Result = ObjCMessageExpr::Create(Context, ReturnType, VK, LBracLoc,
SuperLoc, /*IsInstanceSuper=*/false,
ReceiverType, Sel, Method, Args,
NumArgs, RBracLoc);
ReceiverType, Sel, SelectorLoc,
Method, Args, NumArgs, RBracLoc);
else
Result = ObjCMessageExpr::Create(Context, ReturnType, VK, LBracLoc,
ReceiverTypeInfo, Sel, Method, Args,
NumArgs, RBracLoc);
ReceiverTypeInfo, Sel, SelectorLoc,
Method, Args, NumArgs, RBracLoc);
return MaybeBindToTemporary(Result);
}
@ -861,7 +862,7 @@ ExprResult Sema::ActOnClassMessage(Scope *S,
return BuildClassMessage(ReceiverTypeInfo, ReceiverType,
/*SuperLoc=*/SourceLocation(), Sel, /*Method=*/0,
LBracLoc, RBracLoc, move(Args));
LBracLoc, SelectorLoc, RBracLoc, move(Args));
}
/// \brief Build an Objective-C instance message expression.
@ -893,13 +894,14 @@ ExprResult Sema::ActOnClassMessage(Scope *S,
///
/// \param Args The message arguments.
ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
QualType ReceiverType,
SourceLocation SuperLoc,
Selector Sel,
ObjCMethodDecl *Method,
SourceLocation LBracLoc,
SourceLocation RBracLoc,
MultiExprArg ArgsIn) {
QualType ReceiverType,
SourceLocation SuperLoc,
Selector Sel,
ObjCMethodDecl *Method,
SourceLocation LBracLoc,
SourceLocation SelectorLoc,
SourceLocation RBracLoc,
MultiExprArg ArgsIn) {
// The location of the receiver.
SourceLocation Loc = SuperLoc.isValid()? SuperLoc : Receiver->getLocStart();
@ -920,8 +922,8 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
assert(SuperLoc.isInvalid() && "Message to super with dependent type");
return Owned(ObjCMessageExpr::Create(Context, Context.DependentTy,
VK_RValue, LBracLoc, Receiver, Sel,
/*Method=*/0, Args, NumArgs,
RBracLoc));
SelectorLoc, /*Method=*/0,
Args, NumArgs, RBracLoc));
}
// If necessary, apply function/array conversion to the receiver.
@ -1064,7 +1066,8 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
SuperLoc,
Sel,
Method,
LBracLoc,
LBracLoc,
SelectorLoc,
RBracLoc,
move(ArgsIn));
} else {
@ -1098,12 +1101,12 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
if (SuperLoc.isValid())
Result = ObjCMessageExpr::Create(Context, ReturnType, VK, LBracLoc,
SuperLoc, /*IsInstanceSuper=*/true,
ReceiverType, Sel, Method,
ReceiverType, Sel, SelectorLoc, Method,
Args, NumArgs, RBracLoc);
else
Result = ObjCMessageExpr::Create(Context, ReturnType, VK, LBracLoc,
Receiver,
Sel, Method, Args, NumArgs, RBracLoc);
Receiver, Sel, SelectorLoc, Method,
Args, NumArgs, RBracLoc);
return MaybeBindToTemporary(Result);
}
@ -1122,6 +1125,6 @@ ExprResult Sema::ActOnInstanceMessage(Scope *S,
return BuildInstanceMessage(Receiver, Receiver->getType(),
/*SuperLoc=*/SourceLocation(), Sel, /*Method=*/0,
LBracLoc, RBracLoc, move(Args));
LBracLoc, SelectorLoc, RBracLoc, move(Args));
}

View File

@ -1815,6 +1815,7 @@ public:
/// \brief Build a new Objective-C class message.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Selector Sel,
SourceLocation SelectorLoc,
ObjCMethodDecl *Method,
SourceLocation LBracLoc,
MultiExprArg Args,
@ -1822,13 +1823,14 @@ public:
return SemaRef.BuildClassMessage(ReceiverTypeInfo,
ReceiverTypeInfo->getType(),
/*SuperLoc=*/SourceLocation(),
Sel, Method, LBracLoc, RBracLoc,
move(Args));
Sel, Method, LBracLoc, SelectorLoc,
RBracLoc, move(Args));
}
/// \brief Build a new Objective-C instance message.
ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Selector Sel,
SourceLocation SelectorLoc,
ObjCMethodDecl *Method,
SourceLocation LBracLoc,
MultiExprArg Args,
@ -1836,8 +1838,8 @@ public:
return SemaRef.BuildInstanceMessage(Receiver,
Receiver->getType(),
/*SuperLoc=*/SourceLocation(),
Sel, Method, LBracLoc, RBracLoc,
move(Args));
Sel, Method, LBracLoc, SelectorLoc,
RBracLoc, move(Args));
}
/// \brief Build a new Objective-C ivar reference expression.
@ -6165,6 +6167,7 @@ TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
// Build a new class message send.
return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
E->getSelector(),
E->getSelectorLoc(),
E->getMethodDecl(),
E->getLeftLoc(),
move_arg(Args),
@ -6187,6 +6190,7 @@ TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
// Build a new instance message send.
return getDerived().RebuildObjCMessageExpr(Receiver.get(),
E->getSelector(),
E->getSelectorLoc(),
E->getMethodDecl(),
E->getLeftLoc(),
move_arg(Args),

View File

@ -897,8 +897,9 @@ void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
else
E->setSelector(Reader.GetSelector(Record, Idx));
E->setLeftLoc(ReadSourceLocation(Record, Idx));
E->setRightLoc(ReadSourceLocation(Record, Idx));
E->LBracLoc = ReadSourceLocation(Record, Idx);
E->RBracLoc = ReadSourceLocation(Record, Idx);
E->SelectorLoc = ReadSourceLocation(Record, Idx);
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
E->setArg(I, Reader.ReadSubExpr());

View File

@ -870,6 +870,7 @@ void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
Writer.AddSourceLocation(E->getLeftLoc(), Record);
Writer.AddSourceLocation(E->getRightLoc(), Record);
Writer.AddSourceLocation(E->getSelectorLoc(), Record);
for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
Arg != ArgEnd; ++Arg)