[cfe-commits] r140765 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/DiagnosticIDs.cpp lib/Serialization/ASTWriter.cpp
Daniel Dunbar
daniel at zuster.org
Wed Sep 28 18:42:26 PDT 2011
Author: ddunbar
Date: Wed Sep 28 20:42:25 2011
New Revision: 140765
URL: http://llvm.org/viewvc/llvm-project?rev=140765&view=rev
Log:
Basic/Diagnostic: Add a DiagSate::getOrAddMappingInfo method.
- Also, spell const_iterator as const_iterator.
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=140765&r1=140764&r2=140765&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Sep 28 20:42:25 2011
@@ -178,22 +178,26 @@
llvm::DenseMap<unsigned, DiagnosticMappingInfo> DiagMap;
public:
- typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::const_iterator
+ typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::iterator
iterator;
+ typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::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.
Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=140765&r1=140764&r2=140765&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Wed Sep 28 20:42:25 2011
@@ -234,6 +234,25 @@
};
}
+// 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<iterator, bool> 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 @@
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;
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=140765&r1=140764&r2=140765&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed Sep 28 20:42:25 2011
@@ -1813,7 +1813,7 @@
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);
More information about the cfe-commits
mailing list