1 //===-- DiagnosticManager.cpp ---------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Expression/DiagnosticManager.h"
11 #include "llvm/Support/ErrorHandling.h"
13 #include "lldb/Utility/Log.h"
14 #include "lldb/Utility/StreamString.h"
16 using namespace lldb_private
;
18 void DiagnosticManager::Dump(Log
*log
) {
22 std::string str
= GetString();
24 // GetString() puts a separator after each diagnostic. We want to remove the
25 // last '\n' because log->PutCString will add one for us.
27 if (str
.size() && str
.back() == '\n') {
31 log
->PutCString(str
.c_str());
34 static const char *StringForSeverity(DiagnosticSeverity severity
) {
36 // this should be exhaustive
37 case lldb_private::eDiagnosticSeverityError
:
39 case lldb_private::eDiagnosticSeverityWarning
:
41 case lldb_private::eDiagnosticSeverityRemark
:
44 llvm_unreachable("switch needs another case for DiagnosticSeverity enum");
47 std::string
DiagnosticManager::GetString(char separator
) {
50 for (const auto &diagnostic
: Diagnostics()) {
51 ret
.append(StringForSeverity(diagnostic
->GetSeverity()));
52 ret
.append(std::string(diagnostic
->GetMessage()));
53 ret
.push_back(separator
);
59 size_t DiagnosticManager::Printf(DiagnosticSeverity severity
,
60 const char *format
, ...) {
64 va_start(args
, format
);
65 size_t result
= ss
.PrintfVarArg(format
, args
);
68 AddDiagnostic(ss
.GetString(), severity
, eDiagnosticOriginLLDB
);
73 void DiagnosticManager::PutString(DiagnosticSeverity severity
,
74 llvm::StringRef str
) {
77 AddDiagnostic(str
, severity
, eDiagnosticOriginLLDB
);