Files
PorygonLang/src/Binder/BoundStatements/BoundStatement.hpp

122 lines
2.7 KiB
C++

#include <utility>
#ifndef PORYGONLANG_BOUNDSTATEMENT_HPP
#define PORYGONLANG_BOUNDSTATEMENT_HPP
#include <vector>
#include "../BoundExpressions/BoundExpression.hpp"
#include "../BoundVariables/BoundVariableKey.hpp"
using namespace std;
enum class BoundStatementKind{
Bad,
Script,
Block,
Expression,
Assignment,
FunctionDeclaration,
};
class BoundStatement{
public:
virtual BoundStatementKind GetKind() = 0;
virtual ~BoundStatement() = default;
};
class BoundBadStatement : public BoundStatement{
public:
BoundStatementKind GetKind() final{
return BoundStatementKind ::Bad;
}
};
class BoundBlockStatement : public BoundStatement{
vector<BoundStatement*> _statements;
public:
explicit BoundBlockStatement(vector<BoundStatement*> statements){
_statements = std::move(statements);
}
~BoundBlockStatement() override {
for (auto s : _statements){
delete s;
}
_statements.clear();
}
BoundStatementKind GetKind() override{
return BoundStatementKind ::Block;
}
vector<BoundStatement*> GetStatements(){
return _statements;
}
};
class BoundScriptStatement : public BoundBlockStatement{
int _deepestScope;
public:
explicit BoundScriptStatement(vector<BoundStatement*> statements, int deepestScope) : BoundBlockStatement(std::move(statements)){
_deepestScope = deepestScope;
}
BoundStatementKind GetKind() final{
return BoundStatementKind ::Script;
}
int GetDeepestScope(){
return _deepestScope;
}
};
class BoundExpressionStatement : public BoundStatement{
BoundExpression* _expression;
public:
explicit BoundExpressionStatement(BoundExpression* expression){
_expression = expression;
}
~BoundExpressionStatement() final{
delete _expression;
}
BoundStatementKind GetKind() final{
return BoundStatementKind ::Expression;
}
BoundExpression* GetExpression(){
return _expression;
}
};
class BoundAssignmentStatement : public BoundStatement{
BoundVariableKey* _key;
BoundExpression* _expression;
public:
BoundAssignmentStatement(BoundVariableKey* key, BoundExpression* expression){
_key = key;
_expression = expression;
}
~BoundAssignmentStatement() final{
delete _key;
delete _expression;
}
BoundStatementKind GetKind() final{
return BoundStatementKind ::Assignment;
}
BoundVariableKey* GetKey(){
return _key;
}
BoundExpression* GetExpression(){
return _expression;
}
};
#include "BoundFunctionDeclarationStatement.hpp"
#endif //PORYGONLANG_BOUNDSTATEMENT_HPP