1 //===-- DiagnosticManager.cpp -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Expression/DiagnosticManager.h"
12 #include "llvm/Support/ErrorHandling.h"
14 #include "lldb/Utility/Log.h"
15 #include "lldb/Utility/StreamString.h"
17 using namespace lldb_private;
19 void DiagnosticManager::Dump(Log *log) {
23 std::string str = GetString();
25 // GetString() puts a separator after each diagnostic. We want to remove the
26 // last '\n' because log->PutCString will add one for us.
28 if (str.size() && str.back() == '\n') {
32 log->PutCString(str.c_str());
35 static const char *StringForSeverity(DiagnosticSeverity severity) {
37 // this should be exhaustive
38 case lldb_private::eDiagnosticSeverityError:
40 case lldb_private::eDiagnosticSeverityWarning:
42 case lldb_private::eDiagnosticSeverityRemark:
45 llvm_unreachable("switch needs another case for DiagnosticSeverity enum");
48 std::string DiagnosticManager::GetString(char separator) {
51 for (const Diagnostic *diagnostic : Diagnostics()) {
52 ret.append(StringForSeverity(diagnostic->GetSeverity()));
53 ret.append(diagnostic->GetMessage());
54 ret.push_back(separator);
60 size_t DiagnosticManager::Printf(DiagnosticSeverity severity,
61 const char *format, ...) {
65 va_start(args, format);
66 size_t result = ss.PrintfVarArg(format, args);
69 AddDiagnostic(ss.GetString(), severity, eDiagnosticOriginLLDB);
74 size_t DiagnosticManager::PutString(DiagnosticSeverity severity,
75 llvm::StringRef str) {
78 AddDiagnostic(str, severity, eDiagnosticOriginLLDB);
82 void DiagnosticManager::CopyDiagnostics(DiagnosticManager &otherDiagnostics) {
83 for (const DiagnosticList::value_type &other_diagnostic:
84 otherDiagnostics.Diagnostics()) {
86 other_diagnostic->GetMessage(), other_diagnostic->GetSeverity(),
87 other_diagnostic->getKind(), other_diagnostic->GetCompilerID());