This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
#include <utility>
|
||||
|
||||
|
||||
#ifndef PORYGONLANG_DIAGNOSTIC_HPP
|
||||
#define PORYGONLANG_DIAGNOSTIC_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "DiagnosticSeverity.hpp"
|
||||
@@ -28,22 +26,27 @@ namespace Porygon::Diagnostics {
|
||||
delete _message;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline DiagnosticSeverity GetSeverity() {
|
||||
return _severity;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline DiagnosticCode GetCode() {
|
||||
return _code;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline unsigned int GetStartPosition() {
|
||||
return _start;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline unsigned int GetLength() {
|
||||
return _length;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline std::vector<std::string> GetArguments(){
|
||||
return _arguments;
|
||||
}
|
||||
@@ -52,6 +55,7 @@ namespace Porygon::Diagnostics {
|
||||
this -> _message = s;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline std::string* GetMessage(){
|
||||
return _message;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#define PORYGONLANG_DIAGNOSTICCODE_HPP
|
||||
|
||||
namespace Porygon::Diagnostics {
|
||||
enum class DiagnosticCode {
|
||||
enum class DiagnosticCode : u_int8_t {
|
||||
// Lex diagnostics
|
||||
UnexpectedCharacter,
|
||||
InvalidStringControlCharacter,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#include <utility>
|
||||
|
||||
#include <memory> // For std::unique_ptr
|
||||
#include "DiagnosticsHolder.hpp"
|
||||
#include "ErrorMessages-EN-US.cpp"
|
||||
@@ -10,23 +8,23 @@ vector<Diagnostic> DiagnosticsHolder::GetDiagnostics() {
|
||||
}
|
||||
|
||||
void DiagnosticsHolder::Log(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length,
|
||||
std::vector<string> arguments) {
|
||||
const std::vector<string>& arguments) {
|
||||
_diagnostics.emplace_back(severity, code, start, length, arguments);
|
||||
if (severity >= DiagnosticSeverity::Error){
|
||||
_hasErrors = true;
|
||||
}
|
||||
}
|
||||
|
||||
void DiagnosticsHolder::LogError(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments) {
|
||||
Log(DiagnosticSeverity::Error, code, start, length, std::move(arguments));
|
||||
void DiagnosticsHolder::LogError(DiagnosticCode code, unsigned int start, unsigned int length, const std::vector<string>& arguments) {
|
||||
Log(DiagnosticSeverity::Error, code, start, length, arguments);
|
||||
}
|
||||
|
||||
void DiagnosticsHolder::LogWarning(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments) {
|
||||
Log(DiagnosticSeverity::Warning, code, start, length, std::move(arguments));
|
||||
void DiagnosticsHolder::LogWarning(DiagnosticCode code, unsigned int start, unsigned int length, const std::vector<string>& arguments) {
|
||||
Log(DiagnosticSeverity::Warning, code, start, length, arguments);
|
||||
}
|
||||
|
||||
void DiagnosticsHolder::LogInfo(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments) {
|
||||
Log(DiagnosticSeverity::Info, code, start, length, std::move(arguments));
|
||||
void DiagnosticsHolder::LogInfo(DiagnosticCode code, unsigned int start, unsigned int length, const std::vector<string>& arguments) {
|
||||
Log(DiagnosticSeverity::Info, code, start, length, arguments);
|
||||
}
|
||||
|
||||
bool DiagnosticsHolder::HasErrors() {
|
||||
@@ -91,10 +89,10 @@ void findAndReplaceAll(std::string & data, const std::string& toSearch, const st
|
||||
}
|
||||
}
|
||||
|
||||
const string PrettyDiagnostic ( const char * format, vector<string> arguments)
|
||||
string PrettyDiagnostic ( const char * format, vector<string> arguments)
|
||||
{
|
||||
string result = string(format);
|
||||
for (int i = 0; i < arguments.size(); i++){
|
||||
for (size_t i = 0; i < arguments.size(); i++){
|
||||
auto keyToReplace = "{" + to_string(i) + "}";
|
||||
auto argument = arguments[i];
|
||||
findAndReplaceAll(result, keyToReplace, argument);
|
||||
|
||||
@@ -35,13 +35,13 @@ namespace Porygon::Diagnostics {
|
||||
_diagnostics.clear();
|
||||
}
|
||||
|
||||
void Log(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments = {});
|
||||
void Log(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length, const std::vector<string>& arguments = {});
|
||||
|
||||
void LogError(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments = {});
|
||||
void LogError(DiagnosticCode code, unsigned int start, unsigned int length, const std::vector<string>& arguments = {});
|
||||
|
||||
void LogWarning(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments = {});
|
||||
void LogWarning(DiagnosticCode code, unsigned int start, unsigned int length, const std::vector<string>& arguments = {});
|
||||
|
||||
void LogInfo(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments = {});
|
||||
void LogInfo(DiagnosticCode code, unsigned int start, unsigned int length, const std::vector<string>& arguments = {});
|
||||
|
||||
bool HasErrors();
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace Porygon::Diagnostics {
|
||||
Diagnostic *GetDiagnosticAt(int position);
|
||||
|
||||
size_t GetLineFromPosition(size_t i);
|
||||
[[nodiscard]]
|
||||
inline size_t GetStartPositionForLine(size_t i){
|
||||
return _lineStarts[i];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user