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.
26 // We want to remove the last '\n' because log->PutCString will add one for
29 if (str.size() && str.back() == '\n') {
33 log->PutCString(str.c_str());
36 static const char *StringForSeverity(DiagnosticSeverity severity) {
38 // this should be exhaustive
39 case lldb_private::eDiagnosticSeverityError:
41 case lldb_private::eDiagnosticSeverityWarning:
43 case lldb_private::eDiagnosticSeverityRemark:
46 llvm_unreachable("switch needs another case for DiagnosticSeverity enum");
49 std::string DiagnosticManager::GetString(char separator) {
52 for (const Diagnostic *diagnostic : Diagnostics()) {
53 ret.append(StringForSeverity(diagnostic->GetSeverity()));
54 ret.append(diagnostic->GetMessage());
55 ret.push_back(separator);
61 size_t DiagnosticManager::Printf(DiagnosticSeverity severity,
62 const char *format, ...) {
66 va_start(args, format);
67 size_t result = ss.PrintfVarArg(format, args);
70 AddDiagnostic(ss.GetString(), severity, eDiagnosticOriginLLDB);
75 size_t DiagnosticManager::PutString(DiagnosticSeverity severity,
76 llvm::StringRef str) {
79 AddDiagnostic(str, severity, eDiagnosticOriginLLDB);
83 void DiagnosticManager::CopyDiagnostics(DiagnosticManager &otherDiagnostics) {
84 for (const DiagnosticList::value_type &other_diagnostic:
85 otherDiagnostics.Diagnostics()) {
87 other_diagnostic->GetMessage(), other_diagnostic->GetSeverity(),
88 other_diagnostic->getKind(), other_diagnostic->GetCompilerID());