Move Diagnostics to separate namespace

This commit is contained in:
2019-06-18 16:39:36 +02:00
parent 88df299e14
commit e07d5cb7cb
11 changed files with 127 additions and 118 deletions

View File

@@ -5,33 +5,35 @@
#include "DiagnosticSeverity.hpp"
#include "DiagnosticCode.hpp"
class Diagnostic{
DiagnosticSeverity _severity;
DiagnosticCode _code;
unsigned int _start;
unsigned int _length;
public:
Diagnostic(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length){
_severity = severity;
_code = code;
_start = start;
_length = length;
}
namespace Porygon::Diagnostics {
class Diagnostic {
DiagnosticSeverity _severity;
DiagnosticCode _code;
unsigned int _start;
unsigned int _length;
public:
Diagnostic(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length) {
_severity = severity;
_code = code;
_start = start;
_length = length;
}
DiagnosticSeverity GetSeverity(){
return _severity;
}
DiagnosticCode GetCode(){
return _code;
}
DiagnosticSeverity GetSeverity() {
return _severity;
}
unsigned int GetStartPosition(){
return _start;
}
DiagnosticCode GetCode() {
return _code;
}
unsigned int GetLength(){
return _length;
}
};
unsigned int GetStartPosition() {
return _start;
}
unsigned int GetLength() {
return _length;
}
};
}
#endif //PORYGONLANG_DIAGNOSTIC_HPP

View File

@@ -2,29 +2,30 @@
#ifndef PORYGONLANG_DIAGNOSTICCODE_HPP
#define PORYGONLANG_DIAGNOSTICCODE_HPP
enum class DiagnosticCode{
// Lex diagnostics
UnexpectedCharacter,
InvalidStringControlCharacter,
namespace Porygon::Diagnostics {
enum class DiagnosticCode {
// Lex diagnostics
UnexpectedCharacter,
InvalidStringControlCharacter,
// Parse diagnostics
UnexpectedToken,
// Bind diagnostics
NoBinaryOperationFound,
NoUnaryOperationFound,
CantAssignVariable,
VariableNotFound,
ExpressionIsNotAFunction,
ParameterCountMismatch,
ParameterTypeMismatch,
CantIndex,
InvalidReturnType,
ConditionNotABool,
InvalidTableValueType,
InvalidTypeName,
UserDataFieldNoGetter,
UserDataFieldNoSetter
};
// Parse diagnostics
UnexpectedToken,
// Bind diagnostics
NoBinaryOperationFound,
NoUnaryOperationFound,
CantAssignVariable,
VariableNotFound,
ExpressionIsNotAFunction,
ParameterCountMismatch,
ParameterTypeMismatch,
CantIndex,
InvalidReturnType,
ConditionNotABool,
InvalidTableValueType,
InvalidTypeName,
UserDataFieldNoGetter,
UserDataFieldNoSetter
};
}
#endif //PORYGONLANG_DIAGNOSTICCODE_HPP

View File

@@ -2,10 +2,12 @@
#ifndef PORYGONLANG_DIAGNOSTICSEVERITY_HPP
#define PORYGONLANG_DIAGNOSTICSEVERITY_HPP
enum class DiagnosticSeverity{
Info,
Warning,
Error,
};
namespace Porygon::Diagnostics {
enum class DiagnosticSeverity {
Info,
Warning,
Error,
};
}
#endif //PORYGONLANG_DIAGNOSTICSEVERITY_HPP

View File

@@ -1,5 +1,5 @@
#include "DiagnosticsHolder.hpp"
using namespace Porygon::Diagnostics;
vector<Diagnostic> DiagnosticsHolder::GetDiagnostics() {
return _diagnostics;
}

View File

@@ -9,31 +9,35 @@
using namespace std;
class DiagnosticsHolder {
bool _hasErrors;
vector<Diagnostic> _diagnostics;
public:
DiagnosticsHolder(){
_hasErrors = false;
}
namespace Porygon::Diagnostics {
class DiagnosticsHolder {
bool _hasErrors;
vector<Diagnostic> _diagnostics;
public:
DiagnosticsHolder() {
_hasErrors = false;
}
~DiagnosticsHolder(){
_diagnostics.clear();
}
~DiagnosticsHolder() {
_diagnostics.clear();
}
void Log(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length);
void LogError(DiagnosticCode code, unsigned int start, unsigned int length);
void LogWarning(DiagnosticCode code, unsigned int start, unsigned int length);
void LogInfo(DiagnosticCode code, unsigned int start, unsigned int length);
void Log(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length);
bool HasErrors();
void LogError(DiagnosticCode code, unsigned int start, unsigned int length);
vector<Diagnostic> GetDiagnostics();
void LogWarning(DiagnosticCode code, unsigned int start, unsigned int length);
int DiagnosticsCount();
void LogInfo(DiagnosticCode code, unsigned int start, unsigned int length);
Diagnostic* GetDiagnosticAt(int position);
};
bool HasErrors();
vector<Diagnostic> GetDiagnostics();
int DiagnosticsCount();
Diagnostic *GetDiagnosticAt(int position);
};
}
#endif //PORYGONLANG_DIAGNOSTICSHOLDER_HPP