From 32976b22bcfc96dde43da1311029052c3c09143c Mon Sep 17 00:00:00 2001 From: Argiris Kirtzidis Date: Fri, 10 Dec 2010 20:08:27 +0000 Subject: [PATCH] Keep the source location of the selector in ObjCMessageExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121516 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprObjC.h | 16 +++++++++--- include/clang/Sema/Sema.h | 2 ++ lib/AST/Expr.cpp | 26 +++++++++++-------- lib/Rewrite/RewriteObjC.cpp | 12 ++++++--- lib/Sema/SemaExprObjC.cpp | 51 ++++++++++++++++++++----------------- lib/Sema/TreeTransform.h | 12 ++++++--- lib/Serialization/ASTReaderStmt.cpp | 5 ++-- lib/Serialization/ASTWriterStmt.cpp | 1 + 8 files changed, 78 insertions(+), 47 deletions(-) diff --git a/include/clang/AST/ExprObjC.h b/include/clang/AST/ExprObjC.h index c0f4c1b75..aaad04b30 100644 --- a/include/clang/AST/ExprObjC.h +++ b/include/clang/AST/ExprObjC.h @@ -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. diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 0aff2f6bf..4df4b7b53 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -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); diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 9439d6875..93ebb7044 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -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(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(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(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::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::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::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, diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp index d689f22f6..0d3881197 100644 --- a/lib/Rewrite/RewriteObjC.cpp +++ b/lib/Rewrite/RewriteObjC.cpp @@ -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(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(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(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(Receiver), - Sel, OMD, + Sel, SelectorLoc, OMD, 0, 0, /*FIXME:*/SourceLocation()); } diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index d63b228f3..5d5e8a528 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -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)); } diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 9f6f84bec..f4a4ae28c 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -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::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::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), diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index ab9d677f4..353477d96 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -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()); diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 99599a750..35b096e65 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -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) -- 2.11.4.GIT