Make Diagnostics usage a pointer

This commit is contained in:
Deukhoofd 2019-05-21 14:15:39 +02:00
parent 99f50b6471
commit 8f2f122215
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
4 changed files with 13 additions and 4 deletions

View File

@ -60,7 +60,7 @@ IToken* Lexer::LexNext(char c){
if (isalpha(c)){ if (isalpha(c)){
return LexIdentifierOrKeyword(c); return LexIdentifierOrKeyword(c);
} }
this -> ScriptData->Diagnostics.LogError(DiagnosticCode::UnexpectedCharacter, this -> Position - 1, 1); this -> ScriptData -> Diagnostics -> LogError(DiagnosticCode::UnexpectedCharacter, this -> Position - 1, 1);
return new SimpleToken(TokenKind::BadToken, this -> Position - 1, 1); return new SimpleToken(TokenKind::BadToken, this -> Position - 1, 1);
} }
} }

View File

@ -111,7 +111,7 @@ ParsedExpression *Parser::ParsePrimaryExpression(IToken *current) {
case TokenKind ::TrueKeyword: return new LiteralBoolExpression(current); case TokenKind ::TrueKeyword: return new LiteralBoolExpression(current);
case TokenKind ::FalseKeyword: return new LiteralBoolExpression(current); case TokenKind ::FalseKeyword: return new LiteralBoolExpression(current);
default: default:
this -> ScriptData -> Diagnostics.LogError(DiagnosticCode::UnexpectedToken, current->GetStartPosition(), current->GetLength()); this -> ScriptData -> Diagnostics -> LogError(DiagnosticCode::UnexpectedToken, current->GetStartPosition(), current->GetLength());
return new BadExpression(current->GetStartPosition(), current->GetLength()); return new BadExpression(current->GetStartPosition(), current->GetLength());
} }
} }

View File

@ -11,6 +11,10 @@ Script Script::Create(string script) {
return s; return s;
} }
Script::~Script() {
delete this -> Diagnostics;
}
void Script::Parse(string script) { void Script::Parse(string script) {
auto lexer = Lexer(std::move(script), this); auto lexer = Lexer(std::move(script), this);
auto lexResult = lexer.Lex(); auto lexResult = lexer.Lex();
@ -21,3 +25,4 @@ void Script::Parse(string script) {
} }
lexResult.clear(); lexResult.clear();
} }

View File

@ -10,12 +10,16 @@
using namespace std; using namespace std;
class Script { class Script {
explicit Script() = default; explicit Script(){
Diagnostics = new class Diagnostics();
};
void Parse(string script); void Parse(string script);
public: public:
static Script Create(string script); static Script Create(string script);
Diagnostics Diagnostics; Diagnostics* Diagnostics;
~Script();
}; };