Properly clear up memory of parsed results
This commit is contained in:
parent
1e5cd010a1
commit
2fe6f570ec
|
@ -23,12 +23,13 @@ class ParsedExpression {
|
|||
unsigned int _position;
|
||||
unsigned int _length;
|
||||
public:
|
||||
virtual ParsedExpressionKind GetKind() = 0;
|
||||
|
||||
ParsedExpression(unsigned int position, unsigned int length){
|
||||
_position = position;
|
||||
_length = length;
|
||||
}
|
||||
virtual ~ParsedExpression() = default;
|
||||
|
||||
virtual ParsedExpressionKind GetKind() = 0;
|
||||
|
||||
unsigned int GetStartPosition(){
|
||||
return _position;
|
||||
|
@ -100,6 +101,10 @@ public:
|
|||
class ParenthesizedExpression : public ParsedExpression{
|
||||
ParsedExpression* _expression;
|
||||
public:
|
||||
~ParenthesizedExpression() override {
|
||||
delete _expression;
|
||||
}
|
||||
|
||||
ParsedExpressionKind GetKind() final{
|
||||
return ParsedExpressionKind::Parenthesized;
|
||||
}
|
||||
|
@ -118,6 +123,10 @@ class UnaryExpression : public ParsedExpression{
|
|||
UnaryOperatorKind _kind;
|
||||
ParsedExpression* _operand;
|
||||
public:
|
||||
~UnaryExpression() override {
|
||||
delete _operand;
|
||||
}
|
||||
|
||||
ParsedExpressionKind GetKind() final{
|
||||
return ParsedExpressionKind::Unary;
|
||||
}
|
||||
|
@ -142,6 +151,11 @@ class BinaryExpression : public ParsedExpression{
|
|||
ParsedExpression* _left;
|
||||
ParsedExpression* _right;
|
||||
public:
|
||||
~BinaryExpression() override {
|
||||
delete _left;
|
||||
delete _right;
|
||||
}
|
||||
|
||||
ParsedExpressionKind GetKind() final{
|
||||
return ParsedExpressionKind::Binary;
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
#ifndef PORYGONLANG_PARSEDSCRIPTSTATEMENT_HPP
|
||||
#define PORYGONLANG_PARSEDSCRIPTSTATEMENT_HPP
|
||||
|
||||
#include "ParsedStatement.hpp"
|
||||
|
||||
class ParsedScriptStatement : public ParsedBlockStatement{
|
||||
public:
|
||||
explicit ParsedScriptStatement(vector<ParsedStatement*> statements) : ParsedBlockStatement(move(statements)){}
|
||||
|
||||
ParsedStatementKind GetKind() final{
|
||||
return ParsedStatementKind ::Script;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //PORYGONLANG_PARSEDSCRIPTSTATEMENT_HPP
|
|
@ -24,6 +24,7 @@ public:
|
|||
_start = start;
|
||||
_length = length;
|
||||
}
|
||||
virtual ~ParsedStatement() = default;
|
||||
|
||||
unsigned int GetStartPosition(){
|
||||
return _start;
|
||||
|
@ -41,6 +42,12 @@ public:
|
|||
: ParsedStatement(statements.front()->GetStartPosition(), statements.back()->GetEndPosition() - statements.front()->GetStartPosition()){
|
||||
_statements = std::move(statements);
|
||||
}
|
||||
~ParsedBlockStatement() override {
|
||||
for (auto s: _statements){
|
||||
delete s;
|
||||
}
|
||||
_statements.clear();
|
||||
}
|
||||
|
||||
ParsedStatementKind GetKind() override{
|
||||
return ParsedStatementKind ::Block;
|
||||
|
@ -51,12 +58,24 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class ParsedScriptStatement : public ParsedBlockStatement{
|
||||
public:
|
||||
explicit ParsedScriptStatement(vector<ParsedStatement*> statements) : ParsedBlockStatement(move(statements)){}
|
||||
|
||||
ParsedStatementKind GetKind() final{
|
||||
return ParsedStatementKind ::Script;
|
||||
}
|
||||
};
|
||||
|
||||
class ParsedExpressionStatement : public ParsedStatement{
|
||||
ParsedExpression* _expression;
|
||||
public:
|
||||
explicit ParsedExpressionStatement(ParsedExpression* expression) : ParsedStatement(expression->GetStartPosition(), expression->GetLength()){
|
||||
_expression = expression;
|
||||
}
|
||||
~ParsedExpressionStatement() override {
|
||||
delete _expression;
|
||||
}
|
||||
|
||||
ParsedStatementKind GetKind() final{
|
||||
return ParsedStatementKind ::Expression;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "Parser.hpp"
|
||||
#include "UnaryOperatorKind.hpp"
|
||||
#include "BinaryOperatorKind.hpp"
|
||||
#include "ParsedScriptStatement.hpp"
|
||||
|
||||
|
||||
ParsedScriptStatement* Parser::Parse() {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "ParsedStatements/ParsedStatement.hpp"
|
||||
#include "../Script.hpp"
|
||||
#include "ParsedScriptStatement.hpp"
|
||||
|
||||
enum class OperatorPrecedence {
|
||||
No,
|
||||
|
|
Loading…
Reference in New Issue