Rename Selector::getName() to Selector::getAsString(), and add
a new NamedDecl::getAsString() method.

Change uses of Selector::getName() to just pass in a Selector 
where possible (e.g. to diagnostics) instead of going through
an std::string.

This also adds new formatters for objcinstance and objcclass
as described in the dox.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59933 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index be21c36..6b913fb 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -23,22 +23,33 @@
 /// ConvertQualTypeToStringFn - This function is used to pretty print the 
 /// specified QualType as a string in diagnostics.
 static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val,
-                                      const char *Modifier, unsigned ML,
+                                      const char *Modifier, unsigned ModLen,
                                       const char *Argument, unsigned ArgLen,
                                       llvm::SmallVectorImpl<char> &Output) {
-  assert(ML == 0 && ArgLen == 0 && "Invalid modifier for QualType argument");
   
   std::string S;
   if (Kind == Diagnostic::ak_qualtype) {
     QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast<void*>(Val)));
-  
+
     // FIXME: Playing with std::string is really slow.
     S = Ty.getAsString();
+
+    assert(ModLen == 0 && ArgLen == 0 &&
+           "Invalid modifier for QualType argument");
+    
   } else {
     assert(Kind == Diagnostic::ak_declarationname);
    
     DeclarationName N = DeclarationName::getFromOpaqueInteger(Val);
     S = N.getAsString();
+    
+    if (ModLen == 9 && !memcmp(Modifier, "objcclass", 9) && ArgLen == 0)
+      S = '+' + S;
+    else if (ModLen == 12 && !memcmp(Modifier, "objcinstance", 12) && ArgLen==0)
+      S = '-' + S;
+    else
+      assert(ModLen == 0 && ArgLen == 0 &&
+             "Invalid modifier for DeclarationName argument");
   }
   Output.append(S.begin(), S.end());
 }
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 410c254..de588c5 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1317,7 +1317,7 @@
   /// \param [out] ReturnType - The return type of the send.
   /// \return true iff there were any incompatible types.
   bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
-                                 ObjCMethodDecl *Method, const char *PrefixStr,
+                                 ObjCMethodDecl *Method, bool isClassMessage,
                                  SourceLocation lbrac, SourceLocation rbrac,
                                  QualType &ReturnType);  
 
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index cc54e89..64fd6c5 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -805,8 +805,7 @@
     if (!match) {
       // We have a new signature for an existing method - add it.
       // This is extremely rare. Only 1% of Cocoa selectors are "overloaded".
-      struct ObjCMethodList *OMI = new ObjCMethodList(Method, FirstMethod.Next);
-      FirstMethod.Next = OMI;
+      FirstMethod.Next = new ObjCMethodList(Method, FirstMethod.Next);;
     }
   }
 }
@@ -824,7 +823,7 @@
         issueWarning = true;
   }
   if (issueWarning && (MethList.Method && MethList.Next)) {
-    Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel.getName() << R;
+    Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R;
     Diag(MethList.Method->getLocStart(), diag::note_using_decl)
       << MethList.Method->getSourceRange();
     for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next)
@@ -905,7 +904,7 @@
       if (isInterfaceDeclKind && PrevMethod && !match 
           || checkIdenticalMethods && match) {
           Diag(Method->getLocation(), diag::err_duplicate_method_decl)
-            << Method->getSelector().getName();
+            << Method->getDeclName();
           Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
       } else {
         insMethods.push_back(Method);
@@ -922,7 +921,7 @@
       if (isInterfaceDeclKind && PrevMethod && !match 
           || checkIdenticalMethods && match) {
         Diag(Method->getLocation(), diag::err_duplicate_method_decl)
-          << Method->getSelector().getName();
+          << Method->getDeclName();
         Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
       } else {
         clsMethods.push_back(Method);
@@ -1115,7 +1114,7 @@
   if (PrevMethod) {
     // You can never have two method definitions with the same name.
     Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl)
-      << ObjCMethod->getSelector().getName();
+      << ObjCMethod->getDeclName();
     Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
   } 
   return ObjCMethod;
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index f587dd6..2225d67 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -109,7 +109,7 @@
 
 bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, 
                                      Selector Sel, ObjCMethodDecl *Method, 
-                                     const char *PrefixStr,
+                                     bool isClassMessage,
                                      SourceLocation lbrac, SourceLocation rbrac,
                                      QualType &ReturnType) {  
   if (!Method) {
@@ -117,13 +117,15 @@
     for (unsigned i = 0; i != NumArgs; i++)
       DefaultArgumentPromotion(Args[i]);
 
-    Diag(lbrac, diag::warn_method_not_found)
-      << PrefixStr << Sel.getName() << SourceRange(lbrac, rbrac);
+    unsigned DiagID = isClassMessage ? diag::warn_class_method_not_found :
+                                       diag::warn_inst_method_not_found;
+    Diag(lbrac, DiagID)
+      << Sel << isClassMessage << SourceRange(lbrac, rbrac);
     ReturnType = Context.getObjCIdType();
     return false;
-  } else {
-    ReturnType = Method->getResultType();
   }
+  
+  ReturnType = Method->getResultType();
    
   unsigned NumNamedArgs = Sel.getNumArgs();
   assert(NumArgs >= NumNamedArgs && "Too few arguments for selector!");
@@ -261,7 +263,7 @@
   if (!Method)
     Method = ClassDecl->lookupInstanceMethod(Sel);
 
-  if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "+", 
+  if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, true, 
                                 lbrac, rbrac, returnType))
     return true;
 
@@ -304,7 +306,7 @@
         if (ObjCInterfaceDecl *SuperDecl = ClassDecl->getSuperClass())
           Method = SuperDecl->lookupInstanceMethod(Sel);
     }
-    if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", 
+    if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
                                   lbrac, rbrac, returnType))
       return true;
     return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
@@ -318,7 +320,7 @@
                                Sel, SourceRange(lbrac,rbrac));
     if (!Method)
       Method = FactoryMethodPool[Sel].Method;
-    if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", 
+    if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, 
                                   lbrac, rbrac, returnType))
       return true;
     return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
@@ -340,7 +342,7 @@
     if (!Method)
       Method = LookupInstanceMethodInGlobalPool(
                                Sel, SourceRange(lbrac,rbrac));
-    if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", 
+    if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
                                   lbrac, rbrac, returnType))
       return true;
     return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
@@ -361,7 +363,7 @@
     }
     if (!Method)
       Diag(lbrac, diag::warn_method_not_found_in_protocol)
-        << "-" << Sel.getName() << RExpr->getSourceRange();
+        << Sel << RExpr->getSourceRange();
   } else if (const ObjCInterfaceType *OCIReceiver = 
                 ReceiverCType->getAsPointerToObjCInterfaceType()) {
     // We allow sending a message to a pointer to an interface (an object).
@@ -383,7 +385,7 @@
     
     if (!Method && !OCIReceiver->qual_empty())
       Diag(lbrac, diag::warn_method_not_found_in_protocol)
-        << "-" << Sel.getName() << SourceRange(lbrac, rbrac);
+        << Sel << SourceRange(lbrac, rbrac);
   } else {
     Diag(lbrac, diag::error_bad_receiver_type)
       << RExpr->getType().getAsString() << RExpr->getSourceRange();
@@ -403,7 +405,7 @@
           Method = LookupInstanceMethodInGlobalPool(
                                Sel, SourceRange(lbrac,rbrac));
   }
-  if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", 
+  if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
                                 lbrac, rbrac, returnType))
     return true;
   return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac,