Skip to content

Commit e9af37d

Browse files
committed
Introduce a Diagnostic::Report function that accepts and emits a StoredDiagnostic.
llvm-svn: 130919
1 parent a48b137 commit e9af37d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

clang/include/clang/Basic/Diagnostic.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace clang {
3232
class LangOptions;
3333
class Preprocessor;
3434
class DiagnosticErrorTrap;
35+
class StoredDiagnostic;
3536

3637
/// \brief Annotates a diagnostic with some code that should be
3738
/// inserted, removed, or replaced to fix the problem.
@@ -487,6 +488,8 @@ class Diagnostic : public llvm::RefCountedBase<Diagnostic> {
487488
inline DiagnosticBuilder Report(SourceLocation Pos, unsigned DiagID);
488489
inline DiagnosticBuilder Report(unsigned DiagID);
489490

491+
void Report(const StoredDiagnostic &storedDiag);
492+
490493
/// \brief Determine whethere there is already a diagnostic in flight.
491494
bool isDiagnosticInFlight() const { return CurDiagID != ~0U; }
492495

@@ -839,8 +842,11 @@ inline DiagnosticBuilder Diagnostic::Report(unsigned DiagID) {
839842
/// about the currently in-flight diagnostic.
840843
class DiagnosticInfo {
841844
const Diagnostic *DiagObj;
845+
llvm::StringRef StoredDiagMessage;
842846
public:
843847
explicit DiagnosticInfo(const Diagnostic *DO) : DiagObj(DO) {}
848+
DiagnosticInfo(const Diagnostic *DO, llvm::StringRef storedDiagMessage)
849+
: DiagObj(DO), StoredDiagMessage(storedDiagMessage) {}
844850

845851
const Diagnostic *getDiags() const { return DiagObj; }
846852
unsigned getID() const { return DiagObj->CurDiagID; }

clang/lib/Basic/Diagnostic.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,42 @@ void Diagnostic::setDiagnosticMapping(diag::kind Diag, diag::Mapping Map,
212212
FullSourceLoc(Loc, *SourceMgr)));
213213
}
214214

215+
void Diagnostic::Report(const StoredDiagnostic &storedDiag) {
216+
assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
217+
218+
CurDiagLoc = storedDiag.getLocation();
219+
CurDiagID = storedDiag.getID();
220+
NumDiagArgs = 0;
221+
222+
NumDiagRanges = storedDiag.range_size();
223+
assert(NumDiagRanges < sizeof(DiagRanges)/sizeof(DiagRanges[0]) &&
224+
"Too many arguments to diagnostic!");
225+
unsigned i = 0;
226+
for (StoredDiagnostic::range_iterator
227+
RI = storedDiag.range_begin(),
228+
RE = storedDiag.range_end(); RI != RE; ++RI)
229+
DiagRanges[i++] = *RI;
230+
231+
NumFixItHints = storedDiag.fixit_size();
232+
assert(NumFixItHints < Diagnostic::MaxFixItHints && "Too many fix-it hints!");
233+
i = 0;
234+
for (StoredDiagnostic::fixit_iterator
235+
FI = storedDiag.fixit_begin(),
236+
FE = storedDiag.fixit_end(); FI != FE; ++FI)
237+
FixItHints[i++] = *FI;
238+
239+
assert(Client && "DiagnosticClient not set!");
240+
Level DiagLevel = storedDiag.getLevel();
241+
DiagnosticInfo Info(this, storedDiag.getMessage());
242+
Client->HandleDiagnostic(DiagLevel, Info);
243+
if (Client->IncludeInDiagnosticCounts()) {
244+
if (DiagLevel == Diagnostic::Warning)
245+
++NumWarnings;
246+
}
247+
248+
CurDiagID = ~0U;
249+
}
250+
215251
void DiagnosticBuilder::FlushCounts() {
216252
DiagObj->NumDiagArgs = NumArgs;
217253
DiagObj->NumDiagRanges = NumRanges;
@@ -486,6 +522,11 @@ static void HandlePluralModifier(const DiagnosticInfo &DInfo, unsigned ValNo,
486522
/// array.
487523
void DiagnosticInfo::
488524
FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
525+
if (!StoredDiagMessage.empty()) {
526+
OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
527+
return;
528+
}
529+
489530
const char *DiagStr = getDiags()->getDiagnosticIDs()->getDescription(getID());
490531
const char *DiagEnd = DiagStr+strlen(DiagStr);
491532

0 commit comments

Comments
 (0)