]> granicus.if.org Git - clang/commitdiff
Introduce ObjCMessageExpr::getReceiverRange() to get the source range of the receiver.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 10 Dec 2010 20:08:30 +0000 (20:08 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 10 Dec 2010 20:08:30 +0000 (20:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121517 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprObjC.h
lib/AST/Expr.cpp

index aaad04b3040071ac9d53517a58c5eb03e16576ca..263ba17a02138a13ab491bb6cbdfc854646eec02 100644 (file)
@@ -610,6 +610,9 @@ public:
   /// sent to.
   ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
 
+  /// \brief Source range of the receiver.
+  SourceRange getReceiverRange() const;
+
   /// \brief Determine whether this is an instance message to either a
   /// computed object or to super.
   bool isInstanceMessage() const {
index 93ebb704429a76492be43ccfead43b42b1de65ee..bb9193466914f0b881ca719f0d0dbcc9f31c81da 100644 (file)
@@ -2330,7 +2330,23 @@ ObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context,
   void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
   return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs);
 }
-         
+
+SourceRange ObjCMessageExpr::getReceiverRange() const {
+  switch (getReceiverKind()) {
+  case Instance:
+    return getInstanceReceiver()->getSourceRange();
+
+  case Class:
+    return getClassReceiverTypeInfo()->getTypeLoc().getSourceRange();
+
+  case SuperInstance:
+  case SuperClass:
+    return getSuperLoc();
+  }
+
+  return SourceLocation();
+}
+
 Selector ObjCMessageExpr::getSelector() const {
   if (HasMethod)
     return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod)