From: Argyrios Kyrtzidis Date: Thu, 5 May 2011 07:54:59 +0000 (+0000) Subject: Introduce a Diagnostic::Report function that accepts and emits a StoredDiagnostic. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e59abb56ce0e1c206fb80bd945a0c358b0abe1ef;p=clang Introduce a Diagnostic::Report function that accepts and emits a StoredDiagnostic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130919 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 7fc400f31b..fc76f1cebf 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -32,6 +32,7 @@ namespace clang { class LangOptions; class Preprocessor; class DiagnosticErrorTrap; + class StoredDiagnostic; /// \brief Annotates a diagnostic with some code that should be /// inserted, removed, or replaced to fix the problem. @@ -487,6 +488,8 @@ public: inline DiagnosticBuilder Report(SourceLocation Pos, unsigned DiagID); inline DiagnosticBuilder Report(unsigned DiagID); + void Report(const StoredDiagnostic &storedDiag); + /// \brief Determine whethere there is already a diagnostic in flight. bool isDiagnosticInFlight() const { return CurDiagID != ~0U; } @@ -839,8 +842,11 @@ inline DiagnosticBuilder Diagnostic::Report(unsigned DiagID) { /// about the currently in-flight diagnostic. class DiagnosticInfo { const Diagnostic *DiagObj; + llvm::StringRef StoredDiagMessage; public: explicit DiagnosticInfo(const Diagnostic *DO) : DiagObj(DO) {} + DiagnosticInfo(const Diagnostic *DO, llvm::StringRef storedDiagMessage) + : DiagObj(DO), StoredDiagMessage(storedDiagMessage) {} const Diagnostic *getDiags() const { return DiagObj; } unsigned getID() const { return DiagObj->CurDiagID; } diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index e8cd21885d..c79fe7b83d 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -212,6 +212,42 @@ void Diagnostic::setDiagnosticMapping(diag::kind Diag, diag::Mapping Map, FullSourceLoc(Loc, *SourceMgr))); } +void Diagnostic::Report(const StoredDiagnostic &storedDiag) { + assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!"); + + CurDiagLoc = storedDiag.getLocation(); + CurDiagID = storedDiag.getID(); + NumDiagArgs = 0; + + NumDiagRanges = storedDiag.range_size(); + assert(NumDiagRanges < sizeof(DiagRanges)/sizeof(DiagRanges[0]) && + "Too many arguments to diagnostic!"); + unsigned i = 0; + for (StoredDiagnostic::range_iterator + RI = storedDiag.range_begin(), + RE = storedDiag.range_end(); RI != RE; ++RI) + DiagRanges[i++] = *RI; + + NumFixItHints = storedDiag.fixit_size(); + assert(NumFixItHints < Diagnostic::MaxFixItHints && "Too many fix-it hints!"); + i = 0; + for (StoredDiagnostic::fixit_iterator + FI = storedDiag.fixit_begin(), + FE = storedDiag.fixit_end(); FI != FE; ++FI) + FixItHints[i++] = *FI; + + assert(Client && "DiagnosticClient not set!"); + Level DiagLevel = storedDiag.getLevel(); + DiagnosticInfo Info(this, storedDiag.getMessage()); + Client->HandleDiagnostic(DiagLevel, Info); + if (Client->IncludeInDiagnosticCounts()) { + if (DiagLevel == Diagnostic::Warning) + ++NumWarnings; + } + + CurDiagID = ~0U; +} + void DiagnosticBuilder::FlushCounts() { DiagObj->NumDiagArgs = NumArgs; DiagObj->NumDiagRanges = NumRanges; @@ -486,6 +522,11 @@ static void HandlePluralModifier(const DiagnosticInfo &DInfo, unsigned ValNo, /// array. void DiagnosticInfo:: FormatDiagnostic(llvm::SmallVectorImpl &OutStr) const { + if (!StoredDiagMessage.empty()) { + OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end()); + return; + } + const char *DiagStr = getDiags()->getDiagnosticIDs()->getDescription(getID()); const char *DiagEnd = DiagStr+strlen(DiagStr);