[cfe-commits] r140760 - in /cfe/trunk: include/clang/Basic/Diagnostic.h include/clang/Basic/DiagnosticIDs.h lib/Basic/DiagnosticIDs.cpp lib/Serialization/ASTWriter.cpp
Daniel Dunbar
daniel at zuster.org
Wed Sep 28 18:30:00 PDT 2011
Author: ddunbar
Date: Wed Sep 28 20:30:00 2011
New Revision: 140760
URL: http://llvm.org/viewvc/llvm-project?rev=140760&view=rev
Log:
Basic/Diagnostics: Add a DiagnosticMappingInfo helper class, and switch to
storing mappings with that instead of straying some magic constants about the
source.
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/include/clang/Basic/DiagnosticIDs.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=140760&r1=140759&r2=140760&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Sep 28 20:30:00 2011
@@ -175,18 +175,21 @@
/// the state so that we know what is the diagnostic state at any given
/// source location.
class DiagState {
- llvm::DenseMap<unsigned, unsigned> DiagMap;
+ llvm::DenseMap<unsigned, DiagnosticMappingInfo> DiagMap;
public:
- typedef llvm::DenseMap<unsigned, unsigned>::const_iterator iterator;
+ typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::const_iterator
+ iterator;
- void setMapping(diag::kind Diag, unsigned Map) { DiagMap[Diag] = Map; }
+ void setMappingInfo(diag::kind Diag, DiagnosticMappingInfo Info) {
+ DiagMap[Diag] = Info;
+ }
- diag::Mapping getMapping(diag::kind Diag) const {
+ DiagnosticMappingInfo getMappingInfo(diag::kind Diag) const {
iterator I = DiagMap.find(Diag);
if (I != DiagMap.end())
- return (diag::Mapping)I->second;
- return diag::Mapping();
+ return I->second;
+ return DiagnosticMappingInfo::MakeUnset();
}
iterator begin() const { return DiagMap.begin(); }
@@ -563,12 +566,11 @@
/// \brief Report the delayed diagnostic.
void ReportDelayed();
- void setDiagnosticMappingInternal(unsigned DiagId, unsigned Map,
+ void setDiagnosticMappingInternal(unsigned DiagId, diag::Mapping Map,
DiagState *State,
bool isUser, bool isPragma) const {
- if (isUser) Map |= 8; // Set the high bit for user mappings.
- if (isPragma) Map |= 0x10; // Set the bit for diagnostic pragma mappings.
- State->setMapping((diag::kind)DiagId, Map);
+ State->setMappingInfo((diag::kind)DiagId, DiagnosticMappingInfo::MakeInfo(
+ Map, isUser, isPragma));
}
// This is private state used by DiagnosticBuilder. We put it here instead of
Modified: cfe/trunk/include/clang/Basic/DiagnosticIDs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticIDs.h?rev=140760&r1=140759&r2=140760&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticIDs.h (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h Wed Sep 28 20:30:00 2011
@@ -74,6 +74,34 @@
};
}
+class DiagnosticMappingInfo {
+ unsigned Mapping : 3;
+ unsigned IsUser : 1;
+ unsigned IsPragma : 1;
+
+public:
+ static DiagnosticMappingInfo MakeUnset() {
+ DiagnosticMappingInfo Result;
+ Result.Mapping = Result.IsUser = Result.IsPragma = 0;
+ return Result;
+ }
+
+ static DiagnosticMappingInfo MakeInfo(diag::Mapping Mapping,
+ bool IsUser, bool IsPragma) {
+ DiagnosticMappingInfo Result;
+ Result.Mapping = Mapping;
+ Result.IsUser = IsUser;
+ Result.IsPragma = IsPragma;
+ return Result;
+ }
+
+ diag::Mapping getMapping() const { return diag::Mapping(Mapping); }
+ bool isUser() const { return IsUser; }
+ bool isPragma() const { return IsPragma; }
+
+ bool isUnset() const { return Mapping == 0; }
+};
+
/// \brief Used for handling and querying diagnostic IDs. Can be used and shared
/// by multiple Diagnostics for multiple translation units.
class DiagnosticIDs : public llvm::RefCountedBase<DiagnosticIDs> {
Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=140760&r1=140759&r2=140760&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Wed Sep 28 20:30:00 2011
@@ -183,10 +183,10 @@
return Found;
}
-static unsigned GetDefaultDiagMapping(unsigned DiagID) {
+static diag::Mapping GetDefaultDiagMapping(unsigned DiagID) {
if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) {
// Compute the effective mapping based on the extra bits.
- unsigned Mapping = Info->Mapping;
+ diag::Mapping Mapping = (diag::Mapping) Info->Mapping;
if (Info->WarnNoWerror) {
assert(Mapping == diag::MAP_WARNING &&
@@ -507,20 +507,21 @@
DiagnosticsEngine::DiagState *State = Pos->State;
// Get the mapping information, if unset, compute it lazily.
- unsigned MappingInfo = State->getMapping((diag::kind) DiagID);
- if (MappingInfo == 0) {
- MappingInfo = GetDefaultDiagMapping(DiagID);
- Diag.setDiagnosticMappingInternal(DiagID, MappingInfo, State, false, false);
+ 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);
}
bool ShouldEmitInSystemHeader = false;
- switch (MappingInfo & 7) {
+ switch (MappingInfo.getMapping()) {
default: llvm_unreachable("Unknown mapping!");
case diag::MAP_IGNORE:
if (Diag.EnableAllWarnings) {
// Leave the warning disabled if it was explicitly ignored.
- if ((MappingInfo & 8) != 0)
+ if (MappingInfo.isUser())
return DiagnosticIDs::Ignored;
Result = Diag.WarningsAsErrors ? DiagnosticIDs::Error
@@ -530,7 +531,7 @@
// and we're mapping them onto warnings or errors.
else if (!isBuiltinExtensionDiag(DiagID) || // Not an extension
Diag.ExtBehavior == DiagnosticsEngine::Ext_Ignore || // Ext ignored
- (MappingInfo & 8) != 0) { // User explicitly mapped it.
+ MappingInfo.isUser()) { // User explicitly mapped it.
return DiagnosticIDs::Ignored;
}
else {
@@ -563,7 +564,7 @@
// If this is an extension diagnostic and we're in -pedantic-error mode, and
// if the user didn't explicitly map it, upgrade to an error.
if (Diag.ExtBehavior == DiagnosticsEngine::Ext_Error &&
- (MappingInfo & 8) == 0 &&
+ !MappingInfo.isUser() &&
isBuiltinExtensionDiag(DiagID))
Result = DiagnosticIDs::Error;
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=140760&r1=140759&r2=140760&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed Sep 28 20:30:00 2011
@@ -1815,10 +1815,9 @@
Record.push_back(point.Loc.getRawEncoding());
for (DiagnosticsEngine::DiagState::iterator
I = point.State->begin(), E = point.State->end(); I != E; ++I) {
- unsigned diag = I->first, map = I->second;
- if (map & 0x10) { // mapping from a diagnostic pragma.
- Record.push_back(diag);
- Record.push_back(map & 0x7);
+ if (I->second.isPragma()) {
+ Record.push_back(I->first);
+ Record.push_back(I->second.getMapping());
}
}
Record.push_back(-1); // mark the end of the diag/map pairs for this
More information about the cfe-commits
mailing list