2019-05-21 11:56:08 +00:00
|
|
|
|
2019-06-06 17:01:54 +00:00
|
|
|
#ifndef PORYGONLANG_DIAGNOSTICSHOLDER_HPP
|
|
|
|
#define PORYGONLANG_DIAGNOSTICSHOLDER_HPP
|
2019-05-21 11:56:08 +00:00
|
|
|
|
|
|
|
#include <vector>
|
2019-06-18 15:14:18 +00:00
|
|
|
#include <string>
|
2019-06-18 17:56:47 +00:00
|
|
|
#include <sstream>
|
2019-05-21 11:56:08 +00:00
|
|
|
#include "DiagnosticSeverity.hpp"
|
|
|
|
#include "DiagnosticCode.hpp"
|
|
|
|
#include "Diagnostic.hpp"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2019-06-18 14:39:36 +00:00
|
|
|
namespace Porygon::Diagnostics {
|
|
|
|
class DiagnosticsHolder {
|
|
|
|
bool _hasErrors;
|
|
|
|
vector<Diagnostic> _diagnostics;
|
2019-06-18 15:14:18 +00:00
|
|
|
vector<size_t> _lineStarts;
|
|
|
|
vector<size_t> _lineLength;
|
2019-06-18 17:56:47 +00:00
|
|
|
|
2019-06-18 14:39:36 +00:00
|
|
|
public:
|
2019-06-18 15:14:18 +00:00
|
|
|
explicit DiagnosticsHolder(const u16string& str) {
|
2019-06-18 14:39:36 +00:00
|
|
|
_hasErrors = false;
|
2019-06-18 15:14:18 +00:00
|
|
|
_lineStarts = vector<size_t>{0};
|
|
|
|
size_t lineLength = 0;
|
|
|
|
for (size_t i = 0; i < str.size(); i++){
|
|
|
|
lineLength++;
|
|
|
|
if (str[i] == '\n'){
|
|
|
|
_lineStarts.push_back(i + 1);
|
|
|
|
_lineLength.push_back(lineLength);
|
|
|
|
lineLength = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-06-18 14:39:36 +00:00
|
|
|
}
|
2019-05-21 11:56:08 +00:00
|
|
|
|
2019-06-18 14:39:36 +00:00
|
|
|
~DiagnosticsHolder() {
|
|
|
|
_diagnostics.clear();
|
|
|
|
}
|
2019-05-21 13:11:00 +00:00
|
|
|
|
2019-06-18 17:56:47 +00:00
|
|
|
void Log(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments = {});
|
2019-05-21 11:56:08 +00:00
|
|
|
|
2019-06-18 17:56:47 +00:00
|
|
|
void LogError(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments = {});
|
2019-05-21 11:56:08 +00:00
|
|
|
|
2019-06-18 17:56:47 +00:00
|
|
|
void LogWarning(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments = {});
|
2019-05-21 11:56:08 +00:00
|
|
|
|
2019-06-18 17:56:47 +00:00
|
|
|
void LogInfo(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments = {});
|
2019-05-21 13:11:00 +00:00
|
|
|
|
2019-06-18 14:39:36 +00:00
|
|
|
bool HasErrors();
|
2019-05-21 11:56:08 +00:00
|
|
|
|
2019-06-18 14:39:36 +00:00
|
|
|
vector<Diagnostic> GetDiagnostics();
|
|
|
|
|
|
|
|
int DiagnosticsCount();
|
|
|
|
|
|
|
|
Diagnostic *GetDiagnosticAt(int position);
|
2019-06-18 15:14:18 +00:00
|
|
|
|
2019-06-18 17:56:47 +00:00
|
|
|
size_t GetLineFromPosition(size_t i);
|
|
|
|
size_t GetStartPositionForLine(size_t i){
|
|
|
|
return _lineStarts[i];
|
2019-06-18 15:14:18 +00:00
|
|
|
}
|
2019-06-18 17:56:47 +00:00
|
|
|
|
2019-06-19 11:37:39 +00:00
|
|
|
std::string GetFullDiagnostic(Diagnostic* diagnostic);
|
2019-06-18 14:39:36 +00:00
|
|
|
};
|
|
|
|
}
|
2019-05-21 11:56:08 +00:00
|
|
|
|
2019-06-06 17:01:54 +00:00
|
|
|
#endif //PORYGONLANG_DIAGNOSTICSHOLDER_HPP
|