/// modifications done through the command-line.
struct DiagStatePoint {
DiagState *State;
- FullSourceLoc Loc;
- DiagStatePoint(DiagState *State, FullSourceLoc Loc)
+ SourceLocation Loc;
+ DiagStatePoint(DiagState *State, SourceLocation Loc)
: State(State), Loc(Loc) { }
-
- bool operator<(const DiagStatePoint &RHS) const {
- // If Loc is invalid it means it came from <command-line>, in which case
- // we regard it as coming before any valid source location.
- if (RHS.Loc.isInvalid())
- return false;
- if (Loc.isInvalid())
- return true;
- return Loc.isBeforeInTranslationUnitThan(RHS.Loc);
- }
};
/// \brief A sorted vector of all DiagStatePoints representing changes in
return DiagStatePoints.back().State;
}
- void PushDiagStatePoint(DiagState *State, SourceLocation L) {
- FullSourceLoc Loc(L, getSourceManager());
- // Make sure that DiagStatePoints is always sorted according to Loc.
- assert(Loc.isValid() && "Adding invalid loc point");
- assert(!DiagStatePoints.empty() &&
- (DiagStatePoints.back().Loc.isInvalid() ||
- DiagStatePoints.back().Loc.isBeforeInTranslationUnitThan(Loc)) &&
- "Previous point loc comes after or is the same as new one");
- DiagStatePoints.push_back(DiagStatePoint(State, Loc));
- }
+ void PushDiagStatePoint(DiagState *State, SourceLocation L);
/// \brief Finds the DiagStatePoint that contains the diagnostic state of
/// the given source location.
assert(SourceMgr && "SourceManager not set!");
return *SourceMgr;
}
- void setSourceManager(SourceManager *SrcMgr) { SourceMgr = SrcMgr; }
+ void setSourceManager(SourceManager *SrcMgr) {
+ assert(DiagStatePoints.size() == 1 && DiagStatePoints[0].Loc.isInvalid() &&
+ "Leftover diag state from a different SourceManager.");
+ SourceMgr = SrcMgr;
+ }
//===--------------------------------------------------------------------===//
// DiagnosticsEngine characterization methods, used by a client to customize
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/PartialDiagnostic.h"
+#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CrashRecoveryContext.h"
// Create a DiagState and DiagStatePoint representing diagnostic changes
// through command-line.
DiagStates.emplace_back();
- DiagStatePoints.push_back(DiagStatePoint(&DiagStates.back(), FullSourceLoc()));
+ DiagStatePoints.emplace_back(&DiagStates.back(), SourceLocation());
}
void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1,
DelayedDiagArg2.clear();
}
+void DiagnosticsEngine::PushDiagStatePoint(DiagState *State,
+ SourceLocation Loc) {
+ // Make sure that DiagStatePoints is always sorted according to Loc.
+ assert(Loc.isValid() && "Adding invalid loc point");
+ assert(!DiagStatePoints.empty() &&
+ (DiagStatePoints.back().Loc.isInvalid() ||
+ getSourceManager().isBeforeInTranslationUnit(
+ DiagStatePoints.back().Loc, Loc)) &&
+ "Previous point loc comes after or is the same as new one");
+ DiagStatePoints.push_back(DiagStatePoint(State, Loc));
+}
+
DiagnosticsEngine::DiagStatePointsTy::iterator
DiagnosticsEngine::GetDiagStatePointForLoc(SourceLocation L) const {
assert(!DiagStatePoints.empty());
return DiagStatePoints.end() - 1;
DiagStatePointsTy::iterator Pos = DiagStatePoints.end();
- FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc;
+ SourceLocation LastStateChangePos = DiagStatePoints.back().Loc;
if (LastStateChangePos.isValid() &&
Loc.isBeforeInTranslationUnitThan(LastStateChangePos))
- Pos = std::upper_bound(DiagStatePoints.begin(), DiagStatePoints.end(),
- DiagStatePoint(nullptr, Loc));
+ Pos = std::upper_bound(
+ DiagStatePoints.begin(), DiagStatePoints.end(),
+ DiagStatePoint(nullptr, Loc),
+ [this](const DiagStatePoint &LHS, const DiagStatePoint &RHS) {
+ // If Loc is invalid it means it came from <command-line>, in which
+ // case we regard it as coming before any valid source location.
+ if (RHS.Loc.isInvalid())
+ return false;
+ if (LHS.Loc.isInvalid())
+ return true;
+ return SourceMgr->isBeforeInTranslationUnit(LHS.Loc, RHS.Loc);
+ });
--Pos;
return Pos;
}
assert(!DiagStatePoints.empty());
assert((L.isInvalid() || SourceMgr) && "No SourceMgr for valid location");
- FullSourceLoc Loc = SourceMgr? FullSourceLoc(L, *SourceMgr) : FullSourceLoc();
- FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc;
+ SourceLocation Loc = SourceMgr ? L : SourceLocation();
+ SourceLocation LastStateChangePos = DiagStatePoints.back().Loc;
// Don't allow a mapping to a warning override an error/fatal mapping.
if (Map == diag::Severity::Warning) {
DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
// Another common case; modifying diagnostic state in a source location
// after the previous one.
if ((Loc.isValid() && LastStateChangePos.isInvalid()) ||
- LastStateChangePos.isBeforeInTranslationUnitThan(Loc)) {
+ SourceMgr->isBeforeInTranslationUnit(LastStateChangePos, Loc)) {
// A diagnostic pragma occurred, create a new DiagState initialized with
// the current one and a new DiagStatePoint to record at which location
// the new state became active.
// Create a new state/point and fit it into the vector of DiagStatePoints
// so that the vector is always ordered according to location.
- assert(Pos->Loc.isBeforeInTranslationUnitThan(Loc));
+ assert(SourceMgr->isBeforeInTranslationUnit(Pos->Loc, Loc));
DiagStates.push_back(*Pos->State);
DiagState *NewState = &DiagStates.back();
NewState->setMapping(Diag, Mapping);
- DiagStatePoints.insert(Pos+1, DiagStatePoint(NewState,
- FullSourceLoc(Loc, *SourceMgr)));
+ DiagStatePoints.insert(Pos + 1, DiagStatePoint(NewState, Loc));
}
bool DiagnosticsEngine::setSeverityForGroup(diag::Flavor Flavor,