Extend ObjCMessageExpr for class method sends with the source location
of the class name.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97943 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index a2914bc..c08a3a2 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -2115,12 +2115,12 @@
 // constructor for class messages.
 // FIXME: clsName should be typed to ObjCInterfaceType
 ObjCMessageExpr::ObjCMessageExpr(ASTContext &C, IdentifierInfo *clsName,
-                                 Selector selInfo, QualType retType,
-                                 ObjCMethodDecl *mproto,
+                                 SourceLocation clsNameLoc, Selector selInfo, 
+                                 QualType retType, ObjCMethodDecl *mproto,
                                  SourceLocation LBrac, SourceLocation RBrac,
                                  Expr **ArgExprs, unsigned nargs)
-  : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
-    MethodProto(mproto) {
+  : Expr(ObjCMessageExprClass, retType, false, false), ClassNameLoc(clsNameLoc),
+    SelName(selInfo), MethodProto(mproto) {
   NumArgs = nargs;
   SubExprs = new (C) Stmt*[NumArgs+1];
   SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown);
@@ -2134,12 +2134,14 @@
 
 // constructor for class messages.
 ObjCMessageExpr::ObjCMessageExpr(ASTContext &C, ObjCInterfaceDecl *cls,
-                                 Selector selInfo, QualType retType,
+                                 SourceLocation clsNameLoc, Selector selInfo, 
+                                 QualType retType,
                                  ObjCMethodDecl *mproto, SourceLocation LBrac,
                                  SourceLocation RBrac, Expr **ArgExprs,
                                  unsigned nargs)
-: Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
-MethodProto(mproto) {
+  : Expr(ObjCMessageExprClass, retType, false, false), ClassNameLoc(clsNameLoc),
+    SelName(selInfo), MethodProto(mproto) 
+{
   NumArgs = nargs;
   SubExprs = new (C) Stmt*[NumArgs+1];
   SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown);
@@ -2157,23 +2159,27 @@
     default:
       assert(false && "Invalid ObjCMessageExpr.");
     case IsInstMeth:
-      return ClassInfo(0, 0);
+      return ClassInfo(0, 0, SourceLocation());
     case IsClsMethDeclUnknown:
-      return ClassInfo(0, (IdentifierInfo*) (x & ~Flags));
+      return ClassInfo(0, (IdentifierInfo*) (x & ~Flags), ClassNameLoc);
     case IsClsMethDeclKnown: {
       ObjCInterfaceDecl* D = (ObjCInterfaceDecl*) (x & ~Flags);
-      return ClassInfo(D, D->getIdentifier());
+      return ClassInfo(D, D->getIdentifier(), ClassNameLoc);
     }
   }
 }
 
 void ObjCMessageExpr::setClassInfo(const ObjCMessageExpr::ClassInfo &CI) {
-  if (CI.first == 0 && CI.second == 0)
+  if (CI.Decl == 0 && CI.Name == 0) {
     SubExprs[RECEIVER] = (Expr*)((uintptr_t)0 | IsInstMeth);
-  else if (CI.first == 0)
-    SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.second | IsClsMethDeclUnknown);
+    return;
+  }
+
+  if (CI.Decl == 0)
+    SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.Name | IsClsMethDeclUnknown);
   else
-    SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.first | IsClsMethDeclKnown);
+    SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.Decl | IsClsMethDeclKnown);
+  ClassNameLoc = CI.Loc;
 }
 
 void ObjCMessageExpr::DoDestroy(ASTContext &C) {
diff --git a/lib/Checker/CFRefCount.cpp b/lib/Checker/CFRefCount.cpp
index ecb98a0..9a76f6a 100644
--- a/lib/Checker/CFRefCount.cpp
+++ b/lib/Checker/CFRefCount.cpp
@@ -853,7 +853,7 @@
 
   RetainSummary *getClassMethodSummary(const ObjCMessageExpr *ME) {
     return getClassMethodSummary(ME->getSelector(), ME->getClassName(),
-                                 ME->getClassInfo().first,
+                                 ME->getClassInfo().Decl,
                                  ME->getMethodDecl(), ME->getType());
   }
 
@@ -2511,7 +2511,7 @@
         // id, id<...>, or Class. If we have an ObjCInterfaceDecl, we know this
         // is a call to a class method whose type we can resolve.  In such
         // cases, promote the return type to XXX* (where XXX is the class).
-        const ObjCInterfaceDecl *D = ME->getClassInfo().first;
+        const ObjCInterfaceDecl *D = ME->getClassInfo().Decl;
         return !D ? RetTy : Ctx.getPointerType(Ctx.getObjCInterfaceType(D));
       }
 
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index b62e6ed..3ff77f0 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -59,7 +59,7 @@
   // Find the receiver
   llvm::Value *Receiver;
   if (!ReceiverExpr) {
-    const ObjCInterfaceDecl *OID = E->getClassInfo().first;
+    const ObjCInterfaceDecl *OID = E->getClassInfo().Decl;
 
     // Very special case, super send in class method. The receiver is
     // self (the class object) and the send uses super semantics.
diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp
index d123694..7b94805 100644
--- a/lib/Frontend/PCHReaderStmt.cpp
+++ b/lib/Frontend/PCHReaderStmt.cpp
@@ -792,8 +792,9 @@
          cast_or_null<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1]));
   if (!E->getReceiver()) {
     ObjCMessageExpr::ClassInfo CI;
-    CI.first = cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]));
-    CI.second = Reader.GetIdentifierInfo(Record, Idx);
+    CI.Decl = cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]));
+    CI.Name = Reader.GetIdentifierInfo(Record, Idx);
+    CI.Loc = SourceLocation::getFromRawEncoding(Record[Idx++]);
     E->setClassInfo(CI);
   }
 
diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp
index a8cc9d6..9a5417c 100644
--- a/lib/Frontend/PCHWriterStmt.cpp
+++ b/lib/Frontend/PCHWriterStmt.cpp
@@ -720,8 +720,9 @@
 
   if (!E->getReceiver()) {
     ObjCMessageExpr::ClassInfo CI = E->getClassInfo();
-    Writer.AddDeclRef(CI.first, Record);
-    Writer.AddIdentifierRef(CI.second, Record);
+    Writer.AddDeclRef(CI.Decl, Record);
+    Writer.AddIdentifierRef(CI.Name, Record);
+    Writer.AddSourceLocation(CI.Loc, Record);
   }
 
   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
diff --git a/lib/Index/Analyzer.cpp b/lib/Index/Analyzer.cpp
index fb3529d..7b414f2 100644
--- a/lib/Index/Analyzer.cpp
+++ b/lib/Index/Analyzer.cpp
@@ -177,7 +177,7 @@
       if (IsInstanceMethod)
         return false;
 
-      MsgD = Msg->getClassInfo().first;
+      MsgD = Msg->getClassInfo().Decl;
       // FIXME: Case when we only have an identifier.
       assert(MsgD && "Identifier only");
     }
@@ -250,7 +250,7 @@
     while (true) {
       if (Msg->getReceiver() == 0) {
         CanBeClassMethod = true;
-        MsgD = Msg->getClassInfo().first;
+        MsgD = Msg->getClassInfo().Decl;
         // FIXME: Case when we only have an identifier.
         assert(MsgD && "Identifier only");
         break;
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 3a05241..c60455d 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -470,13 +470,13 @@
   // now, we simply pass the "super" identifier through (which isn't consistent
   // with instance methods.
   if (isSuper)
-    return new (Context) ObjCMessageExpr(Context, receiverName, Sel, returnType,
-                                         Method, lbrac, rbrac, ArgExprs,
-                                         NumArgs);
+    return new (Context) ObjCMessageExpr(Context, receiverName, receiverLoc,
+                                         Sel, returnType, Method, lbrac, rbrac, 
+                                         ArgExprs, NumArgs);
   else
-    return new (Context) ObjCMessageExpr(Context, ClassDecl, Sel, returnType,
-                                         Method, lbrac, rbrac, ArgExprs,
-                                         NumArgs);
+    return new (Context) ObjCMessageExpr(Context, ClassDecl, receiverLoc,
+                                         Sel, returnType, Method, lbrac, rbrac, 
+                                         ArgExprs, NumArgs);
 }
 
 // ActOnInstanceMessage - used for both unary and keyword messages.