/// \brief Mapping information for diagnostics.
///
/// Mapping info is packed into four bits per diagnostic. The low three
- /// bits are the mapping (an instance of diag::Mapping), or zero if unset.
+ /// bits are the mapping (an instance of diag::Severity), or zero if unset.
/// The high bit is set when the mapping was established as a user mapping.
/// If the high bit is clear, then the low bits are set to the default
/// value, and should be mapped with -pedantic, -Werror, etc.
/// the state so that we know what is the diagnostic state at any given
/// source location.
class DiagState {
- llvm::DenseMap<unsigned, DiagnosticMappingInfo> DiagMap;
+ llvm::DenseMap<unsigned, DiagnosticMapping> DiagMap;
public:
- typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::iterator
- iterator;
- typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::const_iterator
- const_iterator;
+ typedef llvm::DenseMap<unsigned, DiagnosticMapping>::iterator iterator;
+ typedef llvm::DenseMap<unsigned, DiagnosticMapping>::const_iterator
+ const_iterator;
- void setMappingInfo(diag::kind Diag, DiagnosticMappingInfo Info) {
+ void setMapping(diag::kind Diag, DiagnosticMapping Info) {
DiagMap[Diag] = Info;
}
- DiagnosticMappingInfo &getOrAddMappingInfo(diag::kind Diag);
+ DiagnosticMapping &getOrAddMapping(diag::kind Diag);
const_iterator begin() const { return DiagMap.begin(); }
const_iterator end() const { return DiagMap.end(); }
///
/// \param Loc The source location that this change of diagnostic state should
/// take affect. It can be null if we are setting the latest state.
- void setDiagnosticMapping(diag::kind Diag, diag::Mapping Map,
+ void setDiagnosticMapping(diag::kind Diag, diag::Severity Map,
SourceLocation Loc);
/// \brief Change an entire diagnostic group (e.g. "unknown-pragmas") to
///
/// \param Loc The source location that this change of diagnostic state should
/// take affect. It can be null if we are setting the state from command-line.
- bool setDiagnosticGroupMapping(StringRef Group, diag::Mapping Map,
+ bool setDiagnosticGroupMapping(StringRef Group, diag::Severity Map,
SourceLocation Loc = SourceLocation());
/// \brief Set the warning-as-error flag for the given diagnostic group.
///
/// Mainly to be used by -Wno-everything to disable all warnings but allow
/// subsequent -W options to enable specific warnings.
- void setMappingToAllDiagnostics(diag::Mapping Map,
- SourceLocation Loc = SourceLocation());
+ void setMappingForAllDiagnostics(diag::Severity Map,
+ SourceLocation Loc = SourceLocation());
bool hasErrorOccurred() const { return ErrorOccurred; }
/// or modify at a particular position.
SmallVector<FixItHint, 8> DiagFixItHints;
- DiagnosticMappingInfo makeMappingInfo(diag::Mapping Map, SourceLocation L) {
+ DiagnosticMapping makeUserMapping(diag::Severity Map, SourceLocation L) {
bool isPragma = L.isValid();
- DiagnosticMappingInfo MappingInfo = DiagnosticMappingInfo::Make(
- Map, /*IsUser=*/true, isPragma);
+ DiagnosticMapping Mapping =
+ DiagnosticMapping::Make(Map, /*IsUser=*/true, isPragma);
// If this is a pragma mapping, then set the diagnostic mapping flags so
// that we override command line options.
if (isPragma) {
- MappingInfo.setNoWarningAsError(true);
- MappingInfo.setNoErrorAsFatal(true);
+ Mapping.setNoWarningAsError(true);
+ Mapping.setNoErrorAsFatal(true);
}
- return MappingInfo;
+ return Mapping;
}
/// \brief Used to report a diagnostic that is finally fully formed.
/// (emit a warning), MAP_ERROR (emit as an error). It allows clients to
/// map errors to MAP_ERROR/MAP_DEFAULT or MAP_FATAL (stop emitting
/// diagnostics after this one).
- enum Mapping {
+ enum Severity {
// NOTE: 0 means "uncomputed".
- MAP_IGNORE = 1, ///< Map this diagnostic to nothing, ignore it.
- MAP_REMARK = 2, ///< Map this diagnostic to a remark.
- MAP_WARNING = 3, ///< Map this diagnostic to a warning.
- MAP_ERROR = 4, ///< Map this diagnostic to an error.
- MAP_FATAL = 5 ///< Map this diagnostic to a fatal error.
+ MAP_IGNORE = 1, ///< Map this diagnostic to nothing, ignore it.
+ MAP_REMARK = 2, ///< Map this diagnostic to a remark.
+ MAP_WARNING = 3, ///< Map this diagnostic to a warning.
+ MAP_ERROR = 4, ///< Map this diagnostic to an error.
+ MAP_FATAL = 5 ///< Map this diagnostic to a fatal error.
};
}
-class DiagnosticMappingInfo {
- unsigned Mapping : 3;
+class DiagnosticMapping {
+ unsigned Severity : 3;
unsigned IsUser : 1;
unsigned IsPragma : 1;
unsigned HasNoWarningAsError : 1;
unsigned HasNoErrorAsFatal : 1;
public:
- static DiagnosticMappingInfo Make(diag::Mapping Mapping, bool IsUser,
- bool IsPragma) {
- DiagnosticMappingInfo Result;
- Result.Mapping = Mapping;
+ static DiagnosticMapping Make(diag::Severity Severity, bool IsUser,
+ bool IsPragma) {
+ DiagnosticMapping Result;
+ Result.Severity = Severity;
Result.IsUser = IsUser;
Result.IsPragma = IsPragma;
Result.HasNoWarningAsError = 0;
return Result;
}
- diag::Mapping getMapping() const { return diag::Mapping(Mapping); }
- void setMapping(diag::Mapping Value) { Mapping = Value; }
+ diag::Severity getSeverity() const { return diag::Severity(Severity); }
+ void setSeverity(diag::Severity Value) { Severity = Value; }
bool isUser() const { return IsUser; }
bool isPragma() const { return IsPragma; }
/// \brief Callback invoked when a \#pragma gcc dianostic directive is read.
virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
- diag::Mapping mapping, StringRef Str) {
- }
+ diag::Severity mapping, StringRef Str) {}
/// \brief Called when an OpenCL extension is either disabled or
/// enabled with a pragma.
}
void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
- diag::Mapping mapping, StringRef Str) override {
+ diag::Severity mapping, StringRef Str) override {
First->PragmaDiagnostic(Loc, Namespace, mapping, Str);
Second->PragmaDiagnostic(Loc, Namespace, mapping, Str);
}
return Pos;
}
-void DiagnosticsEngine::setDiagnosticMapping(diag::kind Diag, diag::Mapping Map,
+void DiagnosticsEngine::setDiagnosticMapping(diag::kind Diag,
+ diag::Severity Map,
SourceLocation L) {
assert(Diag < diag::DIAG_UPPER_LIMIT &&
"Can only map builtin diagnostics");
FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc;
// Don't allow a mapping to a warning override an error/fatal mapping.
if (Map == diag::MAP_WARNING) {
- DiagnosticMappingInfo &Info = GetCurDiagState()->getOrAddMappingInfo(Diag);
- if (Info.getMapping() == diag::MAP_ERROR ||
- Info.getMapping() == diag::MAP_FATAL)
- Map = Info.getMapping();
+ DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
+ if (Info.getSeverity() == diag::MAP_ERROR ||
+ Info.getSeverity() == diag::MAP_FATAL)
+ Map = Info.getSeverity();
}
- DiagnosticMappingInfo MappingInfo = makeMappingInfo(Map, L);
+ DiagnosticMapping Mapping = makeUserMapping(Map, L);
// Common case; setting all the diagnostics of a group in one place.
if (Loc.isInvalid() || Loc == LastStateChangePos) {
- GetCurDiagState()->setMappingInfo(Diag, MappingInfo);
+ GetCurDiagState()->setMapping(Diag, Mapping);
return;
}
// the new state became active.
DiagStates.push_back(*GetCurDiagState());
PushDiagStatePoint(&DiagStates.back(), Loc);
- GetCurDiagState()->setMappingInfo(Diag, MappingInfo);
+ GetCurDiagState()->setMapping(Diag, Mapping);
return;
}
// Update all diagnostic states that are active after the given location.
for (DiagStatePointsTy::iterator
I = Pos+1, E = DiagStatePoints.end(); I != E; ++I) {
- GetCurDiagState()->setMappingInfo(Diag, MappingInfo);
+ GetCurDiagState()->setMapping(Diag, Mapping);
}
// If the location corresponds to an existing point, just update its state.
if (Pos->Loc == Loc) {
- GetCurDiagState()->setMappingInfo(Diag, MappingInfo);
+ GetCurDiagState()->setMapping(Diag, Mapping);
return;
}
assert(Pos->Loc.isBeforeInTranslationUnitThan(Loc));
DiagStates.push_back(*Pos->State);
DiagState *NewState = &DiagStates.back();
- GetCurDiagState()->setMappingInfo(Diag, MappingInfo);
+ GetCurDiagState()->setMapping(Diag, Mapping);
DiagStatePoints.insert(Pos+1, DiagStatePoint(NewState,
FullSourceLoc(Loc, *SourceMgr)));
}
-bool DiagnosticsEngine::setDiagnosticGroupMapping(
- StringRef Group, diag::Mapping Map, SourceLocation Loc)
-{
+bool DiagnosticsEngine::setDiagnosticGroupMapping(StringRef Group,
+ diag::Severity Map,
+ SourceLocation Loc) {
// Get the diagnostics in this group.
SmallVector<diag::kind, 8> GroupDiags;
if (Diags->getDiagnosticsInGroup(Group, GroupDiags))
// Perform the mapping change.
for (unsigned i = 0, e = GroupDiags.size(); i != e; ++i) {
- DiagnosticMappingInfo &Info = GetCurDiagState()->getOrAddMappingInfo(
- GroupDiags[i]);
+ DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(GroupDiags[i]);
- if (Info.getMapping() == diag::MAP_ERROR ||
- Info.getMapping() == diag::MAP_FATAL)
- Info.setMapping(diag::MAP_WARNING);
+ if (Info.getSeverity() == diag::MAP_ERROR ||
+ Info.getSeverity() == diag::MAP_FATAL)
+ Info.setSeverity(diag::MAP_WARNING);
Info.setNoWarningAsError(true);
}
// Perform the mapping change.
for (unsigned i = 0, e = GroupDiags.size(); i != e; ++i) {
- DiagnosticMappingInfo &Info = GetCurDiagState()->getOrAddMappingInfo(
- GroupDiags[i]);
+ DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(GroupDiags[i]);
- if (Info.getMapping() == diag::MAP_FATAL)
- Info.setMapping(diag::MAP_ERROR);
+ if (Info.getSeverity() == diag::MAP_FATAL)
+ Info.setSeverity(diag::MAP_ERROR);
Info.setNoErrorAsFatal(true);
}
return false;
}
-void DiagnosticsEngine::setMappingToAllDiagnostics(diag::Mapping Map,
- SourceLocation Loc) {
+void DiagnosticsEngine::setMappingForAllDiagnostics(diag::Severity Map,
+ SourceLocation Loc) {
// Get all the diagnostics.
SmallVector<diag::kind, 64> AllDiags;
Diags->getAllDiagnostics(AllDiags);
struct StaticDiagInfoRec {
uint16_t DiagID;
- unsigned Mapping : 3;
+ unsigned DefaultSeverity : 3;
unsigned Class : 3;
unsigned SFINAE : 2;
unsigned WarnNoWerror : 1;
} // namespace anonymous
static const StaticDiagInfoRec StaticDiagInfo[] = {
-#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \
- SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) \
- { diag::ENUM, DEFAULT_MAPPING, CLASS, \
- DiagnosticIDs::SFINAE, \
- NOWERROR, SHOWINSYSHEADER, CATEGORY, GROUP, \
- STR_SIZE(DESC, uint16_t), DESC },
+#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
+ SHOWINSYSHEADER, CATEGORY) \
+ { \
+ diag::ENUM, DEFAULT_SEVERITY, CLASS, DiagnosticIDs::SFINAE, NOWERROR, \
+ SHOWINSYSHEADER, CATEGORY, GROUP, STR_SIZE(DESC, uint16_t), DESC \
+ } \
+ ,
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
return Found;
}
-static DiagnosticMappingInfo GetDefaultDiagMappingInfo(unsigned DiagID) {
- DiagnosticMappingInfo Info = DiagnosticMappingInfo::Make(
- diag::MAP_FATAL, /*IsUser=*/false, /*IsPragma=*/false);
+static DiagnosticMapping GetDefaultDiagMapping(unsigned DiagID) {
+ DiagnosticMapping Info = DiagnosticMapping::Make(
+ diag::MAP_FATAL, /*IsUser=*/false, /*IsPragma=*/false);
if (const StaticDiagInfoRec *StaticInfo = GetDiagInfo(DiagID)) {
- Info.setMapping((diag::Mapping) StaticInfo->Mapping);
+ Info.setSeverity((diag::Severity)StaticInfo->DefaultSeverity);
if (StaticInfo->WarnNoWerror) {
- assert(Info.getMapping() == diag::MAP_WARNING &&
+ assert(Info.getSeverity() == diag::MAP_WARNING &&
"Unexpected mapping with no-Werror bit!");
Info.setNoWarningAsError(true);
}
// 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()));
+DiagnosticMapping &
+DiagnosticsEngine::DiagState::getOrAddMapping(diag::kind Diag) {
+ std::pair<iterator, bool> Result =
+ DiagMap.insert(std::make_pair(Diag, DiagnosticMapping()));
// Initialize the entry if we added it.
if (Result.second)
- Result.first->second = GetDefaultDiagMappingInfo(Diag);
+ Result.first->second = GetDefaultDiagMapping(Diag);
return Result.first->second;
}
if (DiagID >= diag::DIAG_UPPER_LIMIT ||
getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
return false;
-
+
EnabledByDefault =
- GetDefaultDiagMappingInfo(DiagID).getMapping() != diag::MAP_IGNORE;
+ GetDefaultDiagMapping(DiagID).getSeverity() != diag::MAP_IGNORE;
return true;
}
if (DiagID >= diag::DIAG_UPPER_LIMIT)
return false;
- return GetDefaultDiagMappingInfo(DiagID).getMapping() == diag::MAP_ERROR;
+ return GetDefaultDiagMapping(DiagID).getSeverity() == diag::MAP_ERROR;
}
bool DiagnosticIDs::isRemark(unsigned DiagID) {
DiagnosticsEngine::DiagState *State = Pos->State;
// Get the mapping information, or compute it lazily.
- DiagnosticMappingInfo &MappingInfo = State->getOrAddMappingInfo(
- (diag::kind)DiagID);
+ DiagnosticMapping &Mapping = State->getOrAddMapping((diag::kind)DiagID);
- switch (MappingInfo.getMapping()) {
+ switch (Mapping.getSeverity()) {
case diag::MAP_IGNORE:
Result = DiagnosticIDs::Ignored;
break;
// Upgrade ignored diagnostics if -Weverything is enabled.
if (Diag.EnableAllWarnings && Result == DiagnosticIDs::Ignored &&
- !MappingInfo.isUser())
+ !Mapping.isUser())
Result = DiagnosticIDs::Warning;
// Diagnostics of class REMARK are either printed as remarks or in case they
// For extension diagnostics that haven't been explicitly mapped, check if we
// should upgrade the diagnostic.
- if (IsExtensionDiag && !MappingInfo.isUser()) {
+ if (IsExtensionDiag && !Mapping.isUser()) {
switch (Diag.ExtBehavior) {
case DiagnosticsEngine::Ext_Ignore:
break;
// If -Werror is enabled, map warnings to errors unless explicitly disabled.
if (Result == DiagnosticIDs::Warning) {
- if (Diag.WarningsAsErrors && !MappingInfo.hasNoWarningAsError())
+ if (Diag.WarningsAsErrors && !Mapping.hasNoWarningAsError())
Result = DiagnosticIDs::Error;
}
// If -Wfatal-errors is enabled, map errors to fatal unless explicity
// disabled.
if (Result == DiagnosticIDs::Error) {
- if (Diag.ErrorsAsFatal && !MappingInfo.hasNoErrorAsFatal())
+ if (Diag.ErrorsAsFatal && !Mapping.hasNoErrorAsFatal())
Result = DiagnosticIDs::Fatal;
}
// Figure out how this option affects the warning. If -Wfoo, map the
// diagnostic to a warning, if -Wno-foo, map it to ignore.
- diag::Mapping Mapping = isPositive ? diag::MAP_WARNING : diag::MAP_IGNORE;
-
+ diag::Severity Mapping =
+ isPositive ? diag::MAP_WARNING : diag::MAP_IGNORE;
+
// -Wsystem-headers is a special case, not driven by the option table. It
// cannot be controlled with -Werror.
if (Opt == "system-headers") {
Diags.setEnableAllWarnings(true);
} else {
Diags.setEnableAllWarnings(false);
- Diags.setMappingToAllDiagnostics(diag::MAP_IGNORE);
+ Diags.setMappingForAllDiagnostics(diag::MAP_IGNORE);
}
}
continue;
void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override;
void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override;
void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
- diag::Mapping Map, StringRef Str) override;
+ diag::Severity Map, StringRef Str) override;
void PragmaWarning(SourceLocation Loc, StringRef WarningSpec,
ArrayRef<int> Ids) override;
void PragmaWarningPush(SourceLocation Loc, int Level) override;
setEmittedDirectiveOnThisLine();
}
-void PrintPPOutputPPCallbacks::
-PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
- diag::Mapping Map, StringRef Str) {
+void PrintPPOutputPPCallbacks::PragmaDiagnostic(SourceLocation Loc,
+ StringRef Namespace,
+ diag::Severity Map,
+ StringRef Str) {
startNewLineIfNeeded();
MoveToLine(Loc);
OS << "#pragma " << Namespace << " diagnostic ";
IdentifierInfo *II = Tok.getIdentifierInfo();
PPCallbacks *Callbacks = PP.getPPCallbacks();
- diag::Mapping Map;
+ diag::Severity Map;
if (II->isStr("warning"))
Map = diag::MAP_WARNING;
else if (II->isStr("error"))
if (DiagID == (unsigned)-1) {
break; // no more diag/map pairs for this location.
}
- diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++];
- DiagnosticMappingInfo MappingInfo = Diag.makeMappingInfo(Map, Loc);
- Diag.GetCurDiagState()->setMappingInfo(DiagID, MappingInfo);
+ diag::Severity Map = (diag::Severity)F.PragmaDiagMappings[Idx++];
+ DiagnosticMapping Mapping = Diag.makeUserMapping(Map, Loc);
+ Diag.GetCurDiagState()->setMapping(DiagID, Mapping);
}
}
}
I = point.State->begin(), E = point.State->end(); I != E; ++I) {
if (I->second.isPragma()) {
Record.push_back(I->first);
- Record.push_back(I->second.getMapping());
+ Record.push_back(I->second.getSeverity());
}
}
Record.push_back(-1); // mark the end of the diag/map pairs for this