diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/lib/Basic/DiagnosticIDs.cpp @@ -356,42 +356,56 @@ namespace clang { namespace diag { - class CustomDiagInfo { - typedef std::pair DiagDesc; - std::vector DiagInfo; - std::map DiagIDs; - public: - - /// getDescription - Return the description of the specified custom - /// diagnostic. - StringRef getDescription(unsigned DiagID) const { - assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() && - "Invalid diagnostic ID"); - return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second; - } - - /// getLevel - Return the level of the specified custom diagnostic. - DiagnosticIDs::Level getLevel(unsigned DiagID) const { - assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() && - "Invalid diagnostic ID"); - return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first; - } - - unsigned getOrCreateDiagID(DiagnosticIDs::Level L, StringRef Message, - DiagnosticIDs &Diags) { - DiagDesc D(L, std::string(Message)); - // Check to see if it already exists. - std::map::iterator I = DiagIDs.lower_bound(D); - if (I != DiagIDs.end() && I->first == D) - return I->second; - - // If not, assign a new ID. - unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT; - DiagIDs.insert(std::make_pair(D, ID)); - DiagInfo.push_back(D); - return ID; - } - }; + using DiagDesc = std::pair; + struct DiagDescRef { + DiagDescRef(DiagnosticIDs::Level Level, StringRef FormatString) + : Level(Level), FormatString(FormatString) {} + DiagDescRef(const DiagDesc &D) : DiagDescRef(D.first, D.second) {} + DiagnosticIDs::Level Level; + StringRef FormatString; + }; + static bool operator<(const DiagDesc &LHS, const DiagDescRef &RHS) { + if (LHS.first == RHS.Level) + return LHS.second < RHS.FormatString; + return LHS.first < RHS.Level; + } + class CustomDiagInfo { + std::vector DiagInfo; + std::map> DiagIDs; + + public: + /// getDescription - Return the description of the specified custom + /// diagnostic. + StringRef getDescription(unsigned DiagID) const { + assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() && + "Invalid diagnostic ID"); + return DiagInfo[DiagID - DIAG_UPPER_LIMIT].FormatString; + } + + /// getLevel - Return the level of the specified custom diagnostic. + DiagnosticIDs::Level getLevel(unsigned DiagID) const { + assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() && + "Invalid diagnostic ID"); + return DiagInfo[DiagID - DIAG_UPPER_LIMIT].Level; + } + + unsigned getOrCreateDiagID(DiagnosticIDs::Level L, StringRef Message, + DiagnosticIDs &Diags) { + // Check to see if it already exists. + + auto I = DiagIDs.lower_bound(DiagDescRef(L, Message)); + if (I != DiagIDs.end() && I->first.first == L && + I->first.second == Message) + return I->second; + + // If not, assign a new ID. + unsigned ID = DiagInfo.size() + DIAG_UPPER_LIMIT; + auto InsertRet = + DiagIDs.insert(std::make_pair(DiagDesc{L, Message.str()}, ID)); + DiagInfo.emplace_back(InsertRet.first->first); + return ID; + } + }; } // end diag namespace } // end clang namespace