2016-03-19 08:03:59 +08:00
|
|
|
//===-- DiagnosticManager.cpp -----------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Expression/DiagnosticManager.h"
|
2016-04-29 04:14:44 +08:00
|
|
|
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2016-03-19 08:03:59 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void DiagnosticManager::Dump(Log *log) {
|
|
|
|
if (!log)
|
|
|
|
return;
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
std::string str = GetString();
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// GetString() puts a separator after each diagnostic. We want to remove the
|
|
|
|
// last '\n' because log->PutCString will add one for us.
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (str.size() && str.back() == '\n') {
|
|
|
|
str.pop_back();
|
|
|
|
}
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
log->PutCString(str.c_str());
|
2016-03-19 08:03:59 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
static const char *StringForSeverity(DiagnosticSeverity severity) {
|
|
|
|
switch (severity) {
|
|
|
|
// this should be exhaustive
|
|
|
|
case lldb_private::eDiagnosticSeverityError:
|
|
|
|
return "error: ";
|
|
|
|
case lldb_private::eDiagnosticSeverityWarning:
|
|
|
|
return "warning: ";
|
|
|
|
case lldb_private::eDiagnosticSeverityRemark:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
llvm_unreachable("switch needs another case for DiagnosticSeverity enum");
|
2016-03-19 08:03:59 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
std::string DiagnosticManager::GetString(char separator) {
|
|
|
|
std::string ret;
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
for (const Diagnostic *diagnostic : Diagnostics()) {
|
|
|
|
ret.append(StringForSeverity(diagnostic->GetSeverity()));
|
|
|
|
ret.append(diagnostic->GetMessage());
|
|
|
|
ret.push_back(separator);
|
|
|
|
}
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return ret;
|
2016-03-19 08:03:59 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t DiagnosticManager::Printf(DiagnosticSeverity severity,
|
|
|
|
const char *format, ...) {
|
|
|
|
StreamString ss;
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
size_t result = ss.PrintfVarArg(format, args);
|
|
|
|
va_end(args);
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-11-13 03:12:56 +08:00
|
|
|
AddDiagnostic(ss.GetString(), severity, eDiagnosticOriginLLDB);
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return result;
|
2016-03-19 08:03:59 +08:00
|
|
|
}
|
|
|
|
|
2016-11-13 03:12:56 +08:00
|
|
|
size_t DiagnosticManager::PutString(DiagnosticSeverity severity,
|
|
|
|
llvm::StringRef str) {
|
|
|
|
if (str.empty())
|
2016-09-07 04:57:50 +08:00
|
|
|
return 0;
|
2016-11-13 03:12:56 +08:00
|
|
|
AddDiagnostic(str, severity, eDiagnosticOriginLLDB);
|
|
|
|
return str.size();
|
2016-03-19 08:03:59 +08:00
|
|
|
}
|
2017-04-20 02:56:44 +08:00
|
|
|
|
|
|
|
void DiagnosticManager::CopyDiagnostics(DiagnosticManager &otherDiagnostics) {
|
|
|
|
for (const DiagnosticList::value_type &other_diagnostic:
|
|
|
|
otherDiagnostics.Diagnostics()) {
|
|
|
|
AddDiagnostic(
|
|
|
|
other_diagnostic->GetMessage(), other_diagnostic->GetSeverity(),
|
|
|
|
other_diagnostic->getKind(), other_diagnostic->GetCompilerID());
|
|
|
|
}
|
|
|
|
}
|