Handle bound classes as constants during evaluation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
#ifndef PORYGONLANG_BOUNDEXPRESSION_HPP
|
||||
#define PORYGONLANG_BOUNDEXPRESSION_HPP
|
||||
@@ -29,29 +33,31 @@ enum class BoundExpressionKind{
|
||||
};
|
||||
|
||||
class BoundExpression{
|
||||
unsigned int _start;
|
||||
unsigned int _length;
|
||||
std::shared_ptr<ScriptType> _type;
|
||||
const unsigned int _start;
|
||||
const unsigned int _length;
|
||||
const shared_ptr<ScriptType> _type;
|
||||
public:
|
||||
BoundExpression(unsigned int start, unsigned int length, std::shared_ptr<ScriptType> type){
|
||||
_start = start;
|
||||
_length = length;
|
||||
_type = std::move(type);
|
||||
BoundExpression(unsigned int start, unsigned int length, shared_ptr<ScriptType> type)
|
||||
: _start(start),
|
||||
_length(length),
|
||||
_type(std::move(type))
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~BoundExpression() = default;
|
||||
|
||||
virtual BoundExpressionKind GetKind() = 0;
|
||||
virtual std::shared_ptr<ScriptType> GetType(){
|
||||
virtual const BoundExpressionKind GetKind() const = 0;
|
||||
virtual const std::shared_ptr<ScriptType> GetType() const{
|
||||
return _type;
|
||||
};
|
||||
|
||||
unsigned int GetStartPosition(){
|
||||
const unsigned int GetStartPosition() const{
|
||||
return _start;
|
||||
}
|
||||
unsigned int GetLength(){
|
||||
const unsigned int GetLength() const{
|
||||
return _length;
|
||||
}
|
||||
unsigned int GetEndPosition(){
|
||||
const unsigned int GetEndPosition() const{
|
||||
return _start + _length - 1;
|
||||
}
|
||||
};
|
||||
@@ -60,164 +66,172 @@ class BoundBadExpression : public BoundExpression{
|
||||
public:
|
||||
BoundBadExpression(unsigned int start, unsigned int length) : BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Error)){}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::Bad;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundLiteralIntegerExpression : public BoundExpression{
|
||||
long _value;
|
||||
const long _value;
|
||||
public:
|
||||
BoundLiteralIntegerExpression(long value, unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, make_shared<NumericScriptType>(true, false)){
|
||||
_value = value;
|
||||
: BoundExpression(start, length, make_shared<NumericScriptType>(true, false)),
|
||||
_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::LiteralInteger;
|
||||
}
|
||||
|
||||
long GetValue(){
|
||||
const long GetValue() const{
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundLiteralFloatExpression : public BoundExpression{
|
||||
double _value;
|
||||
const double _value;
|
||||
public:
|
||||
BoundLiteralFloatExpression(double value, unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, make_shared<NumericScriptType>(true, true)){
|
||||
_value = value;
|
||||
: BoundExpression(start, length, make_shared<NumericScriptType>(true, true)),
|
||||
_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::LiteralFloat;
|
||||
}
|
||||
|
||||
double GetValue(){
|
||||
const double GetValue() const{
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundLiteralStringExpression : public BoundExpression{
|
||||
string _value;
|
||||
const string _value;
|
||||
public:
|
||||
BoundLiteralStringExpression(string value, unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, make_shared<StringScriptType>(true, HashedString::ConstHash(value.c_str()))){
|
||||
_value = std::move(value);
|
||||
: BoundExpression(start, length, make_shared<StringScriptType>(true, HashedString::ConstHash(value.c_str()))),
|
||||
_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::LiteralString;
|
||||
}
|
||||
|
||||
string GetValue(){
|
||||
const string GetValue() const{
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundLiteralBoolExpression : public BoundExpression{
|
||||
bool _value;
|
||||
const bool _value;
|
||||
public:
|
||||
BoundLiteralBoolExpression(bool value, unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Bool)){
|
||||
_value = value;
|
||||
: BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Bool)),
|
||||
_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::LiteralBool;
|
||||
}
|
||||
|
||||
bool GetValue(){
|
||||
const bool GetValue() const{
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundVariableExpression : public BoundExpression{
|
||||
BoundVariableKey* _key;
|
||||
const BoundVariableKey* _key;
|
||||
public:
|
||||
BoundVariableExpression(BoundVariableKey* key, shared_ptr<ScriptType> type, unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, std::move(type)){
|
||||
_key = key;
|
||||
: BoundExpression(start, length, std::move(type)),
|
||||
_key(key)
|
||||
{
|
||||
}
|
||||
|
||||
~BoundVariableExpression() override{
|
||||
delete _key;
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::Variable;
|
||||
}
|
||||
|
||||
BoundVariableKey* GetKey(){
|
||||
const BoundVariableKey* GetKey() const{
|
||||
return _key;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundBinaryExpression : public BoundExpression {
|
||||
BoundExpression* _left;
|
||||
BoundExpression* _right;
|
||||
BoundBinaryOperation _operation;
|
||||
const BoundExpression* _left;
|
||||
const BoundExpression* _right;
|
||||
const BoundBinaryOperation _operation;
|
||||
public:
|
||||
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, shared_ptr<ScriptType> result,
|
||||
unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, result){
|
||||
_left = left;
|
||||
_right = right;
|
||||
_operation = op;
|
||||
: BoundExpression(start, length, std::move(result)),
|
||||
_left(left),
|
||||
_right(right),
|
||||
_operation(op)
|
||||
{
|
||||
}
|
||||
|
||||
~BoundBinaryExpression() final{
|
||||
delete _left;
|
||||
delete _right;
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::Binary;
|
||||
}
|
||||
|
||||
BoundExpression* GetLeft(){
|
||||
const BoundExpression* GetLeft() const{
|
||||
return _left;
|
||||
}
|
||||
|
||||
BoundExpression* GetRight(){
|
||||
const BoundExpression* GetRight() const{
|
||||
return _right;
|
||||
}
|
||||
|
||||
BoundBinaryOperation GetOperation(){
|
||||
const BoundBinaryOperation GetOperation() const{
|
||||
return _operation;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundUnaryExpression : public BoundExpression {
|
||||
BoundExpression* _operand;
|
||||
BoundUnaryOperation _operation;
|
||||
const BoundExpression* _operand;
|
||||
const BoundUnaryOperation _operation;
|
||||
public:
|
||||
BoundUnaryExpression(BoundExpression* operand, BoundUnaryOperation op, shared_ptr<ScriptType> result, unsigned int start, unsigned int length)
|
||||
:BoundExpression(start, length, result){
|
||||
_operand = operand;
|
||||
_operation = op;
|
||||
: BoundExpression(start, length, result),
|
||||
_operand(operand),
|
||||
_operation(op)
|
||||
{
|
||||
}
|
||||
|
||||
~BoundUnaryExpression() final{
|
||||
delete _operand;
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::Unary;
|
||||
}
|
||||
|
||||
BoundExpression* GetOperand(){
|
||||
const BoundExpression* GetOperand() const{
|
||||
return _operand;
|
||||
}
|
||||
|
||||
BoundUnaryOperation GetOperation(){
|
||||
const BoundUnaryOperation GetOperation() const{
|
||||
return _operation;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundFunctionCallExpression : public BoundExpression {
|
||||
BoundExpression* _functionExpression;
|
||||
vector<BoundExpression*> _parameters;
|
||||
const BoundExpression* _functionExpression;
|
||||
const vector<BoundExpression*> _parameters;
|
||||
public:
|
||||
BoundFunctionCallExpression(BoundExpression *functionExpression, vector<BoundExpression *> parameters, shared_ptr<ScriptType> result,
|
||||
unsigned int start, unsigned int length)
|
||||
@@ -230,16 +244,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::FunctionCall;
|
||||
}
|
||||
|
||||
BoundExpression* GetFunctionExpression(){
|
||||
const BoundExpression* GetFunctionExpression() const{
|
||||
return _functionExpression;
|
||||
}
|
||||
|
||||
vector<BoundExpression*> GetParameters(){
|
||||
return _parameters;
|
||||
const vector<BoundExpression*>* GetParameters() const{
|
||||
return &_parameters;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -256,26 +270,26 @@ public:
|
||||
delete _indexExpression;
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::Index;
|
||||
}
|
||||
|
||||
BoundExpression* GetIndexableExpression(){
|
||||
BoundExpression* GetIndexableExpression() const{
|
||||
return _indexableExpression;
|
||||
}
|
||||
|
||||
BoundExpression* GetIndexExpression(){
|
||||
BoundExpression* GetIndexExpression() const{
|
||||
return _indexExpression;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundNumericalTableExpression : public BoundExpression{
|
||||
vector<BoundExpression*> _expressions;
|
||||
const vector<BoundExpression*> _expressions;
|
||||
public:
|
||||
BoundNumericalTableExpression(vector<BoundExpression*> expressions, shared_ptr<ScriptType> type, unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, std::move(type)){
|
||||
_expressions = std::move(expressions);
|
||||
}
|
||||
: BoundExpression(start, length, std::move(type)),
|
||||
_expressions(std::move(expressions))
|
||||
{}
|
||||
|
||||
~BoundNumericalTableExpression() final{
|
||||
for (auto e: _expressions){
|
||||
@@ -283,12 +297,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final{
|
||||
return BoundExpressionKind ::NumericalTable;
|
||||
}
|
||||
|
||||
vector<BoundExpression*> GetExpressions(){
|
||||
return _expressions;
|
||||
const vector<BoundExpression*>* GetExpressions() const{
|
||||
return &_expressions;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
delete _block;
|
||||
}
|
||||
|
||||
BoundExpressionKind GetKind() final{
|
||||
const BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind ::Table;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <utility>
|
||||
|
||||
|
||||
#ifndef PORYGONLANG_BOUNDFUNCTIONDECLARATIONSTATEMENT_HPP
|
||||
#define PORYGONLANG_BOUNDFUNCTIONDECLARATIONSTATEMENT_HPP
|
||||
@@ -6,33 +8,32 @@
|
||||
#include "BoundStatement.hpp"
|
||||
|
||||
class BoundFunctionDeclarationStatement : public BoundStatement{
|
||||
BoundVariableKey* _key;
|
||||
std::shared_ptr<BoundBlockStatement> _block;
|
||||
std::shared_ptr<FunctionScriptType> _type;
|
||||
const BoundVariableKey* _key;
|
||||
const std::shared_ptr<BoundBlockStatement> _block;
|
||||
const std::shared_ptr<FunctionScriptType> _type;
|
||||
public:
|
||||
BoundFunctionDeclarationStatement(std::shared_ptr<FunctionScriptType> type, BoundVariableKey* key, BoundBlockStatement* block){
|
||||
_key = key;
|
||||
_block = shared_ptr<BoundBlockStatement>(block);
|
||||
_type = type;
|
||||
BoundFunctionDeclarationStatement(std::shared_ptr<FunctionScriptType> type, BoundVariableKey* key, BoundBlockStatement* block)
|
||||
:_key(key), _block(block), _type(std::move(type))
|
||||
{
|
||||
}
|
||||
|
||||
~BoundFunctionDeclarationStatement() final{
|
||||
delete _key;
|
||||
}
|
||||
|
||||
BoundStatementKind GetKind() final{
|
||||
const BoundStatementKind GetKind() const final{
|
||||
return BoundStatementKind ::FunctionDeclaration;
|
||||
}
|
||||
|
||||
BoundVariableKey* GetKey(){
|
||||
const BoundVariableKey* GetKey() const{
|
||||
return _key;
|
||||
}
|
||||
|
||||
std::shared_ptr<BoundBlockStatement> GetBlock(){
|
||||
const std::shared_ptr<BoundBlockStatement> GetBlock() const{
|
||||
return _block;
|
||||
}
|
||||
|
||||
std::shared_ptr<FunctionScriptType> GetType(){
|
||||
const std::shared_ptr<FunctionScriptType> GetType() const{
|
||||
return _type;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <utility>
|
||||
|
||||
|
||||
|
||||
#ifndef PORYGONLANG_BOUNDSTATEMENT_HPP
|
||||
@@ -23,129 +25,133 @@ enum class BoundStatementKind{
|
||||
|
||||
class BoundStatement{
|
||||
public:
|
||||
virtual BoundStatementKind GetKind() = 0;
|
||||
virtual const BoundStatementKind GetKind() const = 0;
|
||||
virtual ~BoundStatement() = default;
|
||||
};
|
||||
|
||||
class BoundBadStatement : public BoundStatement{
|
||||
public:
|
||||
BoundStatementKind GetKind() final{
|
||||
const BoundStatementKind GetKind() const final{
|
||||
return BoundStatementKind ::Bad;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundBlockStatement : public BoundStatement{
|
||||
vector<BoundStatement*> _statements;
|
||||
const vector<BoundStatement*> _statements;
|
||||
public:
|
||||
explicit BoundBlockStatement(vector<BoundStatement*> statements){
|
||||
_statements = std::move(statements);
|
||||
explicit BoundBlockStatement(vector<BoundStatement*> statements)
|
||||
: _statements(std::move(statements))
|
||||
{
|
||||
}
|
||||
~BoundBlockStatement() override {
|
||||
for (auto s : _statements){
|
||||
delete s;
|
||||
}
|
||||
_statements.clear();
|
||||
}
|
||||
|
||||
BoundStatementKind GetKind() override{
|
||||
const BoundStatementKind GetKind() const override {
|
||||
return BoundStatementKind ::Block;
|
||||
}
|
||||
|
||||
vector<BoundStatement*> GetStatements(){
|
||||
return _statements;
|
||||
const vector<BoundStatement*>* GetStatements() const{
|
||||
return &_statements;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundScriptStatement : public BoundBlockStatement{
|
||||
int _localVariableCount;
|
||||
const int _localVariableCount;
|
||||
public:
|
||||
explicit BoundScriptStatement(vector<BoundStatement*> statements, int localVariableCount)
|
||||
: BoundBlockStatement(std::move(statements)){
|
||||
_localVariableCount = localVariableCount;
|
||||
: BoundBlockStatement(std::move(statements)),
|
||||
_localVariableCount(localVariableCount)
|
||||
{
|
||||
}
|
||||
|
||||
BoundStatementKind GetKind() final{
|
||||
const BoundStatementKind GetKind() const final{
|
||||
return BoundStatementKind ::Script;
|
||||
}
|
||||
|
||||
int GetLocalVariableCount(){
|
||||
const int GetLocalVariableCount() const{
|
||||
return _localVariableCount;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundExpressionStatement : public BoundStatement{
|
||||
BoundExpression* _expression;
|
||||
const BoundExpression* _expression;
|
||||
public:
|
||||
explicit BoundExpressionStatement(BoundExpression* expression){
|
||||
explicit BoundExpressionStatement(BoundExpression* expression)
|
||||
: _expression(expression)
|
||||
{
|
||||
_expression = expression;
|
||||
}
|
||||
~BoundExpressionStatement() final{
|
||||
delete _expression;
|
||||
}
|
||||
|
||||
BoundStatementKind GetKind() final{
|
||||
const BoundStatementKind GetKind() const final{
|
||||
return BoundStatementKind ::Expression;
|
||||
}
|
||||
|
||||
BoundExpression* GetExpression(){
|
||||
const BoundExpression* GetExpression() const{
|
||||
return _expression;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundAssignmentStatement : public BoundStatement{
|
||||
BoundVariableKey* _key;
|
||||
BoundExpression* _expression;
|
||||
const BoundVariableKey* _key;
|
||||
const BoundExpression* _expression;
|
||||
public:
|
||||
BoundAssignmentStatement(BoundVariableKey* key, BoundExpression* expression){
|
||||
_key = key;
|
||||
_expression = expression;
|
||||
BoundAssignmentStatement(BoundVariableKey* key, BoundExpression* expression)
|
||||
: _key(key), _expression(expression)
|
||||
{
|
||||
}
|
||||
|
||||
~BoundAssignmentStatement() final{
|
||||
delete _key;
|
||||
delete _expression;
|
||||
}
|
||||
|
||||
BoundStatementKind GetKind() final{
|
||||
const BoundStatementKind GetKind() const final{
|
||||
return BoundStatementKind ::Assignment;
|
||||
}
|
||||
|
||||
BoundVariableKey* GetKey(){
|
||||
const BoundVariableKey* GetKey() const {
|
||||
return _key;
|
||||
}
|
||||
|
||||
BoundExpression* GetExpression(){
|
||||
const BoundExpression* GetExpression() const {
|
||||
return _expression;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundReturnStatement : public BoundStatement{
|
||||
BoundExpression* _expression;
|
||||
const BoundExpression* _expression;
|
||||
public:
|
||||
explicit BoundReturnStatement(BoundExpression* expression){
|
||||
_expression = expression;
|
||||
explicit BoundReturnStatement(BoundExpression* expression)
|
||||
: _expression(expression)
|
||||
{
|
||||
}
|
||||
~BoundReturnStatement() final{
|
||||
delete _expression;
|
||||
}
|
||||
|
||||
BoundStatementKind GetKind() final{
|
||||
const BoundStatementKind GetKind() const final{
|
||||
return BoundStatementKind ::Return;
|
||||
}
|
||||
|
||||
BoundExpression* GetExpression(){
|
||||
const BoundExpression* GetExpression() const{
|
||||
return _expression;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundConditionalStatement : public BoundStatement{
|
||||
BoundExpression* _condition;
|
||||
BoundStatement* _block;
|
||||
BoundStatement* _elseStatement;
|
||||
const BoundExpression* _condition;
|
||||
const BoundStatement* _block;
|
||||
const BoundStatement* _elseStatement;
|
||||
public:
|
||||
explicit BoundConditionalStatement(BoundExpression* condition, BoundStatement* block, BoundStatement* next){
|
||||
_condition = condition;
|
||||
_block = block;
|
||||
_elseStatement = next;
|
||||
explicit BoundConditionalStatement(BoundExpression* condition, BoundStatement* block, BoundStatement* next)
|
||||
:_condition(condition), _block(block), _elseStatement(next)
|
||||
{
|
||||
}
|
||||
|
||||
~BoundConditionalStatement() final{
|
||||
@@ -154,19 +160,19 @@ public:
|
||||
delete _elseStatement;
|
||||
}
|
||||
|
||||
BoundStatementKind GetKind() final{
|
||||
const BoundStatementKind GetKind() const final{
|
||||
return BoundStatementKind ::Conditional;
|
||||
}
|
||||
|
||||
BoundExpression* GetCondition(){
|
||||
const BoundExpression* GetCondition() const{
|
||||
return _condition;
|
||||
}
|
||||
|
||||
BoundStatement* GetBlock(){
|
||||
const BoundStatement* GetBlock() const{
|
||||
return _block;
|
||||
}
|
||||
|
||||
BoundStatement* GetElseStatement(){
|
||||
const BoundStatement* GetElseStatement() const{
|
||||
return _elseStatement;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,19 +25,19 @@ public:
|
||||
{}
|
||||
|
||||
|
||||
const int GetIdentifier(){
|
||||
const int GetIdentifier() const{
|
||||
return _identifier;
|
||||
}
|
||||
|
||||
const unsigned int GetScopeId(){
|
||||
const unsigned int GetScopeId() const{
|
||||
return _scopeId;
|
||||
}
|
||||
|
||||
const bool IsCreation(){
|
||||
const bool IsCreation() const{
|
||||
return _isCreation;
|
||||
}
|
||||
|
||||
const uint64_t GetHash(){
|
||||
const uint64_t GetHash() const{
|
||||
return _hash;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user