45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "fesa/Core/Types.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace fesa {
|
|
|
|
enum class Severity { Info, Warning, Error };
|
|
|
|
struct SourceLocation {
|
|
std::string file;
|
|
LocalIndex line = 0;
|
|
std::string keyword;
|
|
};
|
|
|
|
struct Diagnostic {
|
|
Severity severity = Severity::Error;
|
|
std::string code;
|
|
std::string message;
|
|
SourceLocation source;
|
|
};
|
|
|
|
inline bool hasError(const std::vector<Diagnostic>& diagnostics) {
|
|
return std::any_of(diagnostics.begin(), diagnostics.end(), [](const Diagnostic& diagnostic) {
|
|
return diagnostic.severity == Severity::Error;
|
|
});
|
|
}
|
|
|
|
inline bool containsDiagnostic(const std::vector<Diagnostic>& diagnostics, const std::string& code) {
|
|
return std::any_of(diagnostics.begin(), diagnostics.end(), [&](const Diagnostic& diagnostic) {
|
|
return diagnostic.code == code;
|
|
});
|
|
}
|
|
|
|
inline Diagnostic makeDiagnostic(Severity severity, std::string code, std::string message, std::string keyword,
|
|
std::string file = "<domain>", LocalIndex line = 0) {
|
|
return {severity, std::move(code), std::move(message), {std::move(file), line, std::move(keyword)}};
|
|
}
|
|
|
|
} // namespace fesa
|