Remove the unuseful -fdiagnostics-show-name

This option was added in r129614 and doesn't have any use case that I'm aware
of. It's possible that external tools are using these names - and if that's
the case we can certainly reassess the functionality, but for now it lets us
shave out a few unneeded bits from clang.

Move the "StaticDiagNameIndex" table into the only remaining consumer, diagtool.
This removes the actual diagnostic name strings from clang entirely.

Reviewed by Chris Lattner & Ted Kremenek.

llvm-svn: 150612
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index 6c15e25..754d7c0 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -52,19 +52,14 @@
   unsigned WarnShowInSystemHeader : 1;
   unsigned Category : 5;
 
-  uint8_t  NameLen;
   uint8_t  OptionGroupLen;
 
   uint16_t DescriptionLen;
 
-  const char *NameStr;
   const char *OptionGroupStr;
 
   const char *DescriptionStr;
 
-  StringRef getName() const {
-    return StringRef(NameStr, NameLen);
-  }
   StringRef getOptionGroup() const {
     return StringRef(OptionGroupStr, OptionGroupLen);
   }
@@ -78,24 +73,6 @@
   }
 };
 
-struct StaticDiagNameIndexRec {
-  const char *NameStr;
-  unsigned short DiagID;
-  uint8_t NameLen;
-
-  StringRef getName() const {
-    return StringRef(NameStr, NameLen);
-  }
-
-  bool operator<(const StaticDiagNameIndexRec &RHS) const {
-    return getName() < RHS.getName();
-  }
-  
-  bool operator==(const StaticDiagNameIndexRec &RHS) const {
-    return getName() == RHS.getName();
-  }
-};
-
 template <size_t SizeOfStr, typename FieldType>
 class StringSizerHelper {
   char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1];
@@ -113,9 +90,9 @@
              CATEGORY)                                            \
   { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, ACCESS,           \
     NOWERROR, SHOWINSYSHEADER, CATEGORY,                          \
-    STR_SIZE(#ENUM, uint8_t), STR_SIZE(GROUP, uint8_t),           \
+    STR_SIZE(GROUP, uint8_t),           \
     STR_SIZE(DESC, uint16_t),                                     \
-    #ENUM, GROUP, DESC },
+    GROUP, DESC },
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
@@ -126,23 +103,12 @@
 #include "clang/Basic/DiagnosticSemaKinds.inc"
 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
 #undef DIAG
-  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
+  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
 };
 
 static const unsigned StaticDiagInfoSize =
   sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1;
 
-/// To be sorted before first use (since it's splitted among multiple files)
-static const StaticDiagNameIndexRec StaticDiagNameIndex[] = {
-#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
-#include "clang/Basic/DiagnosticIndexName.inc"
-#undef DIAG_NAME_INDEX
-  { 0, 0, 0 }
-};
-
-static const unsigned StaticDiagNameIndexSize =
-  sizeof(StaticDiagNameIndex)/sizeof(StaticDiagNameIndex[0])-1;
-
 /// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
 /// or null if the ID is invalid.
 static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
@@ -164,7 +130,7 @@
 
   // Search the diagnostic table with a binary search.
   StaticDiagInfoRec Find = { static_cast<unsigned short>(DiagID),
-                             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+                             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
   const StaticDiagInfoRec *Found =
     std::lower_bound(StaticDiagInfo, StaticDiagInfo + StaticDiagInfoSize, Find);
@@ -286,34 +252,6 @@
   return SFINAE_Report;
 }
 
-/// getName - Given a diagnostic ID, return its name
-StringRef DiagnosticIDs::getName(unsigned DiagID) {
-  if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
-    return Info->getName();
-  return StringRef();
-}
-
-/// getIdFromName - Given a diagnostic name, return its ID, or 0
-unsigned DiagnosticIDs::getIdFromName(StringRef Name) {
-  const StaticDiagNameIndexRec *StaticDiagNameIndexEnd =
-    StaticDiagNameIndex + StaticDiagNameIndexSize;
-  
-  if (Name.empty()) { return diag::DIAG_UPPER_LIMIT; }
-  
-  assert(Name.size() == static_cast<uint8_t>(Name.size()) &&
-         "Name is too long");
-  StaticDiagNameIndexRec Find = { Name.data(), 0,
-                                  static_cast<uint8_t>(Name.size()) };
-  
-  const StaticDiagNameIndexRec *Found =
-    std::lower_bound( StaticDiagNameIndex, StaticDiagNameIndexEnd, Find);
-  if (Found == StaticDiagNameIndexEnd ||
-      Found->getName() != Name)
-    return diag::DIAG_UPPER_LIMIT;
-  
-  return Found->DiagID;
-}
-
 /// getBuiltinDiagClass - Return the class field of the diagnostic.
 ///
 static unsigned getBuiltinDiagClass(unsigned DiagID) {
@@ -323,35 +261,6 @@
 }
 
 //===----------------------------------------------------------------------===//
-// diag_iterator
-//===----------------------------------------------------------------------===//
-
-llvm::StringRef DiagnosticIDs::diag_iterator::getDiagName() const {
-  return static_cast<const StaticDiagNameIndexRec*>(impl)->getName();
-}
-
-unsigned DiagnosticIDs::diag_iterator::getDiagID() const {
-  return static_cast<const StaticDiagNameIndexRec*>(impl)->DiagID;
-}
-
-DiagnosticIDs::diag_iterator &DiagnosticIDs::diag_iterator::operator++() {
-  const StaticDiagNameIndexRec* ptr =
-    static_cast<const StaticDiagNameIndexRec*>(impl);;
-  ++ptr;
-  impl = ptr;
-  return *this;
-}
-
-DiagnosticIDs::diag_iterator DiagnosticIDs::diags_begin() {
-  return DiagnosticIDs::diag_iterator(StaticDiagNameIndex);
-}
-
-DiagnosticIDs::diag_iterator DiagnosticIDs::diags_end() {
-  return DiagnosticIDs::diag_iterator(StaticDiagNameIndex +
-                                      StaticDiagNameIndexSize);
-}
-
-//===----------------------------------------------------------------------===//
 // Custom Diagnostic information
 //===----------------------------------------------------------------------===//
 
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 796b876..4f8febd 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -2350,11 +2350,6 @@
                     options::OPT_fno_diagnostics_fixit_info))
     CmdArgs.push_back("-fno-diagnostics-fixit-info");
 
-  // Enable -fdiagnostics-show-name by default.
-  if (Args.hasFlag(options::OPT_fdiagnostics_show_name,
-                   options::OPT_fno_diagnostics_show_name, false))
-    CmdArgs.push_back("-fdiagnostics-show-name");
-
   // Enable -fdiagnostics-show-option by default.
   if (Args.hasFlag(options::OPT_fdiagnostics_show_option,
                    options::OPT_fno_diagnostics_show_option))
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 8417aa4..d418896 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -322,8 +322,6 @@
     Res.push_back("-fcolor-diagnostics");
   if (Opts.VerifyDiagnostics)
     Res.push_back("-verify");
-  if (Opts.ShowNames)
-    Res.push_back("-fdiagnostics-show-name");
   if (Opts.ShowOptionNames)
     Res.push_back("-fdiagnostics-show-option");
   if (Opts.ShowCategories == 1)
@@ -1217,7 +1215,6 @@
                                  /*Default=*/true);
   Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info);
   Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location);
-  Opts.ShowNames = Args.hasArg(OPT_fdiagnostics_show_name);
   Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option);
 
   // Default behavior is to not to show note include stacks.
diff --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
index 465dcad..6445a0c 100644
--- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -46,16 +46,6 @@
   TextDiag.reset(0);
 }
 
-/// \brief Print the diagnostic name to a raw_ostream.
-///
-/// This prints the diagnostic name to a raw_ostream if it has one. It formats
-/// the name according to the expected diagnostic message formatting:
-///   " [diagnostic_name_here]"
-static void printDiagnosticName(raw_ostream &OS, const Diagnostic &Info) {
-  if (!DiagnosticIDs::isBuiltinNote(Info.getID()))
-    OS << " [" << DiagnosticIDs::getName(Info.getID()) << "]";
-}
-
 /// \brief Print any diagnostic option information to a raw_ostream.
 ///
 /// This implements all of the logic for adding diagnostic options to a message
@@ -136,8 +126,6 @@
   Info.FormatDiagnostic(OutStr);
 
   llvm::raw_svector_ostream DiagMessageStream(OutStr);
-  if (DiagOpts->ShowNames)
-    printDiagnosticName(DiagMessageStream, Info);
   printDiagnosticOptions(DiagMessageStream, Level, Info, *DiagOpts);
 
   // Keeps track of the the starting position of the location