2022-08-19 19:52:57 +02:00
|
|
|
|
2023-05-23 16:07:58 +02:00
|
|
|
// FIXME writeExcerpt does not work well with the last line in a file
|
|
|
|
|
2022-08-21 20:56:58 +02:00
|
|
|
#include <sstream>
|
2022-08-24 12:36:43 +02:00
|
|
|
#include <cmath>
|
2022-08-21 20:56:58 +02:00
|
|
|
|
|
|
|
#include "zen/config.hpp"
|
|
|
|
|
2023-05-24 14:11:59 +02:00
|
|
|
#include "bolt/CST.hpp"
|
|
|
|
#include "bolt/Type.hpp"
|
2023-05-24 19:38:04 +02:00
|
|
|
#include "bolt/DiagnosticEngine.hpp"
|
2022-08-19 19:52:57 +02:00
|
|
|
#include "bolt/Diagnostics.hpp"
|
2023-06-11 11:04:04 +02:00
|
|
|
#include "bolt/ConsolePrinter.hpp"
|
2022-08-21 20:56:58 +02:00
|
|
|
|
|
|
|
#define ANSI_RESET "\u001b[0m"
|
|
|
|
#define ANSI_BOLD "\u001b[1m"
|
2023-05-29 20:37:23 +02:00
|
|
|
#define ANSI_ITALIC "\u001b[3m"
|
2022-08-21 20:56:58 +02:00
|
|
|
#define ANSI_UNDERLINE "\u001b[4m"
|
|
|
|
#define ANSI_REVERSED "\u001b[7m"
|
|
|
|
|
|
|
|
#define ANSI_FG_BLACK "\u001b[30m"
|
|
|
|
#define ANSI_FG_RED "\u001b[31m"
|
|
|
|
#define ANSI_FG_GREEN "\u001b[32m"
|
|
|
|
#define ANSI_FG_YELLOW "\u001b[33m"
|
|
|
|
#define ANSI_FG_BLUE "\u001b[34m"
|
|
|
|
#define ANSI_FG_CYAN "\u001b[35m"
|
|
|
|
#define ANSI_FG_MAGENTA "\u001b[36m"
|
|
|
|
#define ANSI_FG_WHITE "\u001b[37m"
|
|
|
|
|
|
|
|
#define ANSI_BG_BLACK "\u001b[40m"
|
|
|
|
#define ANSI_BG_RED "\u001b[41m"
|
|
|
|
#define ANSI_BG_GREEN "\u001b[42m"
|
|
|
|
#define ANSI_BG_YELLOW "\u001b[43m"
|
|
|
|
#define ANSI_BG_BLUE "\u001b[44m"
|
|
|
|
#define ANSI_BG_CYAN "\u001b[45m"
|
|
|
|
#define ANSI_BG_MAGENTA "\u001b[46m"
|
|
|
|
#define ANSI_BG_WHITE "\u001b[47m"
|
2022-08-19 19:52:57 +02:00
|
|
|
|
|
|
|
namespace bolt {
|
|
|
|
|
2022-08-21 20:56:58 +02:00
|
|
|
Diagnostic::Diagnostic(DiagnosticKind Kind):
|
2024-01-21 01:12:02 +01:00
|
|
|
Kind(Kind) {}
|
2022-08-21 20:56:58 +02:00
|
|
|
|
2023-06-08 14:52:22 +02:00
|
|
|
bool sourceLocLessThan(const Diagnostic* L, const Diagnostic* R) {
|
|
|
|
auto N1 = L->getNode();
|
|
|
|
auto N2 = R->getNode();
|
|
|
|
if (N1 == nullptr && N2 == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (N1 == nullptr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (N2 == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return N1->getStartLine() < N2->getStartLine() || N1->getStartColumn() < N2->getStartColumn();
|
|
|
|
};
|
|
|
|
|
|
|
|
void DiagnosticStore::sort() {
|
|
|
|
std::sort(Diagnostics.begin(), Diagnostics.end(), sourceLocLessThan);
|
|
|
|
}
|
|
|
|
|
2023-05-24 19:38:04 +02:00
|
|
|
DiagnosticStore::~DiagnosticStore() {
|
2023-06-11 11:04:04 +02:00
|
|
|
for (auto D: Diagnostics) {
|
|
|
|
delete D;
|
2022-08-24 12:36:43 +02:00
|
|
|
}
|
2023-05-29 20:37:23 +02:00
|
|
|
}
|
|
|
|
|
2023-06-11 11:04:04 +02:00
|
|
|
ConsoleDiagnostics::ConsoleDiagnostics(ConsolePrinter& P):
|
|
|
|
ThePrinter(P) {}
|
2023-05-24 14:11:59 +02:00
|
|
|
|
|
|
|
void ConsoleDiagnostics::addDiagnostic(Diagnostic* D) {
|
|
|
|
|
2023-06-11 11:04:04 +02:00
|
|
|
ThePrinter.writeDiagnostic(*D);
|
2023-05-24 19:38:04 +02:00
|
|
|
|
|
|
|
// Since this DiagnosticEngine is expected to own the diagnostic, we simply
|
|
|
|
// destroy the processed diagnostic so that there are no memory leaks.
|
|
|
|
delete D;
|
|
|
|
}
|
|
|
|
|
2022-08-19 19:52:57 +02:00
|
|
|
}
|