/// 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(); }
/// \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
};
}
+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> {
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 &&
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
// 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 {
// 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;
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