[Diagnostics] Refactor DiagnosticConsumer interface

DiagnosticInfo now holds all the information needed to consume
a diagnostic, so remove unneeded parameters from handleDiagnostic.
This commit is contained in:
Owen Voorhees
2019-10-24 14:47:33 -07:00
parent dfe00c3217
commit 8a6711769e
22 changed files with 314 additions and 414 deletions

View File

@@ -233,21 +233,18 @@ struct SynParserDiagConsumer: public DiagnosticConsumer {
const unsigned BufferID;
SynParserDiagConsumer(SynParser &Parser, unsigned BufferID):
Parser(Parser), BufferID(BufferID) {}
void
handleDiagnostic(SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
StringRef FormatString,
ArrayRef<DiagnosticArgument> FormatArgs,
const DiagnosticInfo &Info,
const SourceLoc bufferIndirectlyCausingDiagnostic) override {
assert(Kind != DiagnosticKind::Remark && "Shouldn't see this in parser.");
void handleDiagnostic(SourceManager &SM,
const DiagnosticInfo &Info) override {
assert(Info.Kind != DiagnosticKind::Remark &&
"Shouldn't see this in parser.");
// The buffer where all char* will point into.
llvm::SmallString<256> Buffer;
auto getCurrentText = [&]() -> const char* {
return Buffer.data() + Buffer.size();
};
DiagnosticDetail Result;
Result.Severity = getSeverity(Kind);
Result.Offset = getByteOffset(Loc, SM, BufferID);
Result.Severity = getSeverity(Info.Kind);
Result.Offset = getByteOffset(Info.Loc, SM, BufferID);
// Terminate each printed text with 0 so the client-side can use char* directly.
char NullTerm = '\0';
@@ -255,7 +252,8 @@ struct SynParserDiagConsumer: public DiagnosticConsumer {
// Print the error message to buffer and record it.
llvm::raw_svector_ostream OS(Buffer);
Result.Message = getCurrentText();
DiagnosticEngine::formatDiagnosticText(OS, FormatString, FormatArgs);
DiagnosticEngine::formatDiagnosticText(OS, Info.FormatString,
Info.FormatArgs);
OS << NullTerm;
}
for (auto R: Info.Ranges) {