change mappings to distinguish between "unset", "set by the user" and
"set to the default value".
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69264 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index caf30fa..19bfeee 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -43,7 +43,7 @@
};
static const DefaultMappingInfo DefaultMappings[] = {
-#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC) { diag::ENUM, DEFAULT_MAPPING },
+#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC) { diag::ENUM, DEFAULT_MAPPING-1 },
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
@@ -56,6 +56,16 @@
};
#undef DIAG
+static unsigned GetDefaultDiagMapping(unsigned DiagID) {
+ // FIXME: Binary search.
+ for (unsigned i = 0, e = sizeof(DefaultMappings)/sizeof(DefaultMappings[0]);
+ i != e; ++i)
+ if (DefaultMappings[i].DiagID == DiagID)
+ return DefaultMappings[i].Mapping+1;
+ return diag::MAP_FATAL;
+}
+
+
// Diagnostic classes.
enum {
CLASS_NOTE = 0x01,
@@ -264,11 +274,8 @@
ArgToStringFn = DummyArgToStringFn;
ArgToStringCookie = 0;
- // Set all mappings to their default.
- for (unsigned i = 0, e = sizeof(DefaultMappings)/sizeof(DefaultMappings[0]);
- i != e; ++i)
- setDiagnosticMappingInternal(DefaultMappings[i].DiagID,
- DefaultMappings[i].Mapping);
+ // Set all mappings to 'unset'.
+ memset(DiagMappings, 0, sizeof(DiagMappings));
}
Diagnostic::~Diagnostic() {
@@ -353,7 +360,16 @@
// Specific non-error diagnostics may be mapped to various levels from ignored
// to error. Errors can only be mapped to fatal.
Diagnostic::Level Result = Diagnostic::Fatal;
- switch (getDiagnosticMapping((diag::kind)DiagID)) {
+
+ // Get the mapping information, if unset, compute it lazily.
+ unsigned MappingInfo = getDiagnosticMappingInfo((diag::kind)DiagID);
+ if (MappingInfo == 0) {
+ MappingInfo = GetDefaultDiagMapping(DiagID);
+ setDiagnosticMappingInternal(DiagID, MappingInfo, false);
+ }
+
+ switch (MappingInfo & 7) {
+ default: assert(0 && "Unknown mapping!");
case diag::MAP_IGNORE:
return Diagnostic::Ignored;
case diag::MAP_ERROR: