Skip to content

Commit 684b12c

Browse files
committed
Simplify StoringDiagnosticConsumer::handleDiagnostic() (NFC)
1 parent a8c6297 commit 684b12c

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,12 +2751,16 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
27512751
line_col = source_mgr.getPresumedLineAndColumnForLoc(source_loc);
27522752
}
27532753

2754-
if (line_col.first != 0) {
2754+
bool use_fixits = false;
2755+
std::string formatted_text;
2756+
if (!line_col.first) {
2757+
formatted_text = text.str();
2758+
use_fixits = false;
2759+
} else {
27552760
ANSIColorStringStream os(m_colorize);
27562761

27572762
// Determine what kind of diagnostic we're emitting, and whether
27582763
// we want to use its fixits:
2759-
bool use_fixits = false;
27602764
llvm::SourceMgr::DiagKind source_mgr_kind;
27612765
switch (info.Kind) {
27622766
case swift::DiagnosticKind::Error:
@@ -2809,28 +2813,15 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
28092813
ranges, fix_its);
28102814
source_mgr.getLLVMSourceMgr().PrintMessage(os, message);
28112815

2812-
// Use the llvm::raw_string_ostream::str() accessor as it will
2813-
// flush the stream into our "message" and return us a reference
2814-
// to "message".
2815-
std::string &message_ref = os.str();
2816-
2817-
if (message_ref.empty())
2818-
m_raw_diagnostics.push_back(RawDiagnostic(
2819-
std::string(text), info.Kind, bufferName, bufferID, line_col.first,
2820-
line_col.second,
2821-
use_fixits ? info.FixIts
2822-
: llvm::ArrayRef<swift::Diagnostic::FixIt>()));
2823-
else
2824-
m_raw_diagnostics.push_back(RawDiagnostic(
2825-
message_ref, info.Kind, bufferName, bufferID, line_col.first,
2826-
line_col.second,
2827-
use_fixits ? info.FixIts
2828-
: llvm::ArrayRef<swift::Diagnostic::FixIt>()));
2829-
} else {
2830-
m_raw_diagnostics.push_back(RawDiagnostic(
2831-
std::string(text), info.Kind, bufferName, bufferID, line_col.first,
2832-
line_col.second, llvm::ArrayRef<swift::Diagnostic::FixIt>()));
2816+
// str() implicitly flushes the stram.
2817+
std::string &s = os.str();
2818+
formatted_text = !s.empty() ? std::move(s) : std::string(text);
28332819
}
2820+
m_raw_diagnostics.push_back(
2821+
{formatted_text, info.Kind, bufferName, bufferID, line_col.first,
2822+
line_col.second,
2823+
use_fixits ? info.FixIts
2824+
: llvm::ArrayRef<swift::Diagnostic::FixIt>()});
28342825

28352826
if (info.Kind == swift::DiagnosticKind::Error)
28362827
m_num_errors++;

0 commit comments

Comments
 (0)