unsigned Mapping : 3;
unsigned IsUser : 1;
unsigned IsPragma : 1;
+ unsigned HasShowInSystemHeader : 1;
+ unsigned HasNoWarningAsError : 1;
+ unsigned HasNoErrorAsFatal : 1;
public:
static DiagnosticMappingInfo MakeUnset() {
DiagnosticMappingInfo Result;
- Result.Mapping = Result.IsUser = Result.IsPragma = 0;
+ Result.Mapping = 0;
return Result;
}
Result.Mapping = Mapping;
Result.IsUser = IsUser;
Result.IsPragma = IsPragma;
+ Result.HasShowInSystemHeader = 0;
+ Result.HasNoWarningAsError = 0;
+ Result.HasNoErrorAsFatal = 0;
return Result;
}
+ bool isUnset() const { return Mapping == 0; }
+
diag::Mapping getMapping() const { return diag::Mapping(Mapping); }
+ void setMapping(diag::Mapping Value) { Mapping = Value; }
+
bool isUser() const { return IsUser; }
bool isPragma() const { return IsPragma; }
- bool isUnset() const { return Mapping == 0; }
+ bool hasShowInSystemHeader() const { return HasShowInSystemHeader; }
+ void setShowInSystemHeader(bool Value) { HasShowInSystemHeader = Value; }
+
+ bool hasNoWarningAsError() const { return HasNoWarningAsError; }
+ void setNoWarningAsError(bool Value) { HasNoWarningAsError = Value; }
+
+ bool hasNoErrorAsFatal() const { return HasNoErrorAsFatal; }
+ void setNoErrorAsFatal(bool Value) { HasNoErrorAsFatal = Value; }
};
/// \brief Used for handling and querying diagnostic IDs. Can be used and shared
bool DiagnosticsEngine::setDiagnosticGroupWarningAsError(StringRef Group,
bool Enabled) {
- diag::Mapping Map = Enabled ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR;
- return setDiagnosticGroupMapping(Group, Map);
+ // If we are enabling this feature, just set the diagnostic mappings to map to
+ // errors.
+ if (Enabled)
+ return setDiagnosticGroupMapping(Group, diag::MAP_ERROR);
+
+ // Otherwise, we want to set the diagnostic mapping's "no Werror" bit, and
+ // potentially downgrade anything already mapped to be a warning.
+
+ // Get the diagnostics in this group.
+ llvm::SmallVector<diag::kind, 8> GroupDiags;
+ if (Diags->getDiagnosticsInGroup(Group, GroupDiags))
+ return true;
+
+ // Perform the mapping change.
+ for (unsigned i = 0, e = GroupDiags.size(); i != e; ++i) {
+ DiagnosticMappingInfo &Info = GetCurDiagState()->getOrAddMappingInfo(
+ GroupDiags[i]);
+
+ Info.setMapping(diag::MAP_WARNING_NO_WERROR);
+ Info.setNoWarningAsError(true);
+ }
+
+ return false;
}
bool DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(StringRef Group,
bool Enabled) {
- diag::Mapping Map = Enabled ? diag::MAP_FATAL : diag::MAP_ERROR_NO_WFATAL;
- return setDiagnosticGroupMapping(Group, Map);
+ // If we are enabling this feature, just set the diagnostic mappings to map to
+ // fatal errors.
+ if (Enabled)
+ return setDiagnosticGroupMapping(Group, diag::MAP_FATAL);
+
+ // Otherwise, we want to set the diagnostic mapping's "no Werror" bit, and
+ // potentially downgrade anything already mapped to be an error.
+
+ // Get the diagnostics in this group.
+ llvm::SmallVector<diag::kind, 8> GroupDiags;
+ if (Diags->getDiagnosticsInGroup(Group, GroupDiags))
+ return true;
+
+ // Perform the mapping change.
+ for (unsigned i = 0, e = GroupDiags.size(); i != e; ++i) {
+ DiagnosticMappingInfo &Info = GetCurDiagState()->getOrAddMappingInfo(
+ GroupDiags[i]);
+
+ Info.setMapping(diag::MAP_ERROR_NO_WFATAL);
+ Info.setNoErrorAsFatal(true);
+ }
+
+ return false;
}
void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) {
return Found;
}
-static diag::Mapping GetDefaultDiagMapping(unsigned DiagID) {
- if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) {
- // Compute the effective mapping based on the extra bits.
- diag::Mapping Mapping = (diag::Mapping) Info->Mapping;
+static DiagnosticMappingInfo GetDefaultDiagMappingInfo(unsigned DiagID) {
+ DiagnosticMappingInfo Info = DiagnosticMappingInfo::MakeInfo(
+ diag::MAP_FATAL, /*IsUser=*/false, /*IsPragma=*/false);
+
+ if (const StaticDiagInfoRec *StaticInfo = GetDiagInfo(DiagID)) {
+ Info.setMapping((diag::Mapping) StaticInfo->Mapping);
- if (Info->WarnNoWerror) {
- assert(Mapping == diag::MAP_WARNING &&
+ if (StaticInfo->WarnNoWerror) {
+ assert(Info.getMapping() == diag::MAP_WARNING &&
"Unexpected mapping with no-Werror bit!");
- Mapping = diag::MAP_WARNING_NO_WERROR;
+ Info.setMapping(diag::MAP_WARNING_NO_WERROR);
+ Info.setNoWarningAsError(true);
}
- if (Info->WarnShowInSystemHeader) {
- assert(Mapping == diag::MAP_WARNING &&
+ if (StaticInfo->WarnShowInSystemHeader) {
+ assert(Info.getMapping() == diag::MAP_WARNING &&
"Unexpected mapping with show-in-system-header bit!");
- Mapping = diag::MAP_WARNING_SHOW_IN_SYSTEM_HEADER;
+ Info.setMapping(diag::MAP_WARNING_SHOW_IN_SYSTEM_HEADER);
+ Info.setShowInSystemHeader(true);
}
-
- return Mapping;
}
- return diag::MAP_FATAL;
+
+ return Info;
}
/// getWarningOptionForDiag - Return the lowest-level warning option that
// 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);
+ Result.first->second = GetDefaultDiagMappingInfo(Diag);
}
return Result.first->second;
getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
return false;
- EnabledByDefault = GetDefaultDiagMapping(DiagID) != diag::MAP_IGNORE;
+ EnabledByDefault =
+ GetDefaultDiagMappingInfo(DiagID).getMapping() != diag::MAP_IGNORE;
return true;
}
if (DiagID >= diag::DIAG_UPPER_LIMIT)
return false;
- return GetDefaultDiagMapping(DiagID) == diag::MAP_ERROR;
+ return GetDefaultDiagMappingInfo(DiagID).getMapping() == diag::MAP_ERROR;
}
/// getDescription - Given a diagnostic ID, return a description of the