Skip to content

Commit

Permalink
Merge pull request #58 from owenv/diag-info-refactor (#67)
Browse files Browse the repository at this point in the history
[Diagnostics] Update SwiftASTContext to use the new DiagnosticConsumer interface
  • Loading branch information
jrose-apple authored Oct 30, 2019
1 parent 86514fe commit d0d3541
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lldb/source/Symbol/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2856,24 +2856,20 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
m_ast_context.GetDiagnosticEngine().takeConsumers();
}

virtual void
handleDiagnostic(swift::SourceManager &source_mgr,
swift::SourceLoc source_loc, swift::DiagnosticKind kind,
llvm::StringRef formatString,
llvm::ArrayRef<swift::DiagnosticArgument> formatArgs,
const swift::DiagnosticInfo &info,
const swift::SourceLoc bufferIndirectlyCausingDiagnostic) {
virtual void handleDiagnostic(swift::SourceManager &source_mgr,
const swift::DiagnosticInfo &info) {
llvm::StringRef bufferName = "<anonymous>";
unsigned bufferID = 0;
std::pair<unsigned, unsigned> line_col = {0, 0};

llvm::SmallString<256> text;
{
llvm::raw_svector_ostream out(text);
swift::DiagnosticEngine::formatDiagnosticText(out, formatString,
formatArgs);
swift::DiagnosticEngine::formatDiagnosticText(out, info.FormatString,
info.FormatArgs);
}

swift::SourceLoc source_loc = info.Loc;
if (source_loc.isValid()) {
bufferID = source_mgr.findBufferContainingLoc(source_loc);
bufferName = source_mgr.getDisplayNameForLoc(source_loc);
Expand All @@ -2887,7 +2883,7 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
// we want to use its fixits:
bool use_fixits = false;
llvm::SourceMgr::DiagKind source_mgr_kind;
switch (kind) {
switch (info.Kind) {
default:
case swift::DiagnosticKind::Error:
source_mgr_kind = llvm::SourceMgr::DK_Error;
Expand Down Expand Up @@ -2924,23 +2920,23 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {

if (message_ref.empty())
m_diagnostics.push_back(RawDiagnostic(
text.str(), kind, bufferName, bufferID, line_col.first,
text.str(), info.Kind, bufferName, bufferID, line_col.first,
line_col.second,
use_fixits ? info.FixIts
: llvm::ArrayRef<swift::Diagnostic::FixIt>()));
else
m_diagnostics.push_back(RawDiagnostic(
message_ref, kind, bufferName, bufferID, line_col.first,
message_ref, info.Kind, bufferName, bufferID, line_col.first,
line_col.second,
use_fixits ? info.FixIts
: llvm::ArrayRef<swift::Diagnostic::FixIt>()));
} else {
m_diagnostics.push_back(RawDiagnostic(
text.str(), kind, bufferName, bufferID, line_col.first,
text.str(), info.Kind, bufferName, bufferID, line_col.first,
line_col.second, llvm::ArrayRef<swift::Diagnostic::FixIt>()));
}

if (kind == swift::DiagnosticKind::Error)
if (info.Kind == swift::DiagnosticKind::Error)
m_num_errors++;
}

Expand Down

0 comments on commit d0d3541

Please sign in to comment.