From: Daniel Dunbar Date: Thu, 29 Sep 2011 01:42:25 +0000 (+0000) Subject: Basic/Diagnostic: Add a DiagSate::getOrAddMappingInfo method. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba494c64365d78b1cdb6baea4d1e79263389fda9;p=clang Basic/Diagnostic: Add a DiagSate::getOrAddMappingInfo method. - Also, spell const_iterator as const_iterator. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140765 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 2924dfcbfb..1d39dec2f6 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -178,22 +178,26 @@ private: llvm::DenseMap DiagMap; public: - typedef llvm::DenseMap::const_iterator + typedef llvm::DenseMap::iterator iterator; + typedef llvm::DenseMap::const_iterator + const_iterator; void setMappingInfo(diag::kind Diag, DiagnosticMappingInfo Info) { DiagMap[Diag] = Info; } DiagnosticMappingInfo getMappingInfo(diag::kind Diag) const { - iterator I = DiagMap.find(Diag); + const_iterator I = DiagMap.find(Diag); if (I != DiagMap.end()) return I->second; return DiagnosticMappingInfo::MakeUnset(); } - iterator begin() const { return DiagMap.begin(); } - iterator end() const { return DiagMap.end(); } + DiagnosticMappingInfo &getOrAddMappingInfo(diag::kind Diag); + + const_iterator begin() const { return DiagMap.begin(); } + const_iterator end() const { return DiagMap.end(); } }; /// \brief Keeps and automatically disposes all DiagStates that we create. diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp index 45d5102714..f865e0b594 100644 --- a/lib/Basic/DiagnosticIDs.cpp +++ b/lib/Basic/DiagnosticIDs.cpp @@ -234,6 +234,25 @@ namespace { }; } +// Unfortunately, the split between DiagnosticIDs and Diagnostic is not +// particularly clean, but for now we just implement this method here so we can +// access GetDefaultDiagMapping. +DiagnosticMappingInfo &DiagnosticsEngine::DiagState::getOrAddMappingInfo( + diag::kind Diag) +{ + std::pair Result = DiagMap.insert( + std::make_pair(Diag, DiagnosticMappingInfo::MakeUnset())); + + // Initialize the entry if we added it. + if (Result.second) { + assert(Result.first->second.isUnset() && "unexpected unset entry"); + Result.first->second = DiagnosticMappingInfo::MakeInfo( + GetDefaultDiagMapping(Diag), /*IsUser=*/false, /*IsPragma=*/false); + } + + return Result.first->second; +} + static const StaticDiagCategoryRec CategoryNameTable[] = { #define GET_CATEGORY_TABLE #define CATEGORY(X, ENUM) { X, STR_SIZE(X, uint8_t) }, @@ -506,13 +525,9 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, Pos = Diag.GetDiagStatePointForLoc(Loc); DiagnosticsEngine::DiagState *State = Pos->State; - // Get the mapping information, if unset, compute it lazily. - DiagnosticMappingInfo MappingInfo = State->getMappingInfo((diag::kind)DiagID); - if (MappingInfo.isUnset()) { - MappingInfo = DiagnosticMappingInfo::MakeInfo( - GetDefaultDiagMapping(DiagID), /*IsUser=*/false, /*IsPragma=*/false); - State->setMappingInfo((diag::kind) DiagID, MappingInfo); - } + // Get the mapping information, or compute it lazily. + DiagnosticMappingInfo &MappingInfo = State->getOrAddMappingInfo( + (diag::kind)DiagID); bool ShouldEmitInSystemHeader = false; diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 1232900be3..9b534c9165 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1813,7 +1813,7 @@ void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) { continue; Record.push_back(point.Loc.getRawEncoding()); - for (DiagnosticsEngine::DiagState::iterator + for (DiagnosticsEngine::DiagState::const_iterator I = point.State->begin(), E = point.State->end(); I != E; ++I) { if (I->second.isPragma()) { Record.push_back(I->first);