This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
#include "BoundExpressions/BoundTableExpression.hpp"
|
||||
#include "BoundExpressions/BoundFunctionCallExpression.hpp"
|
||||
#include "../UserData/UserDataScriptType.hpp"
|
||||
#include "../FunctionScriptType.hpp"
|
||||
|
||||
using namespace Porygon::Parser;
|
||||
|
||||
@@ -16,7 +15,7 @@ namespace Porygon::Binder {
|
||||
|
||||
binder._scope = scriptScope;
|
||||
auto statements = s->GetStatements();
|
||||
vector<BoundStatement *> boundStatements(statements->size());
|
||||
vector<const BoundStatement *> boundStatements(statements->size());
|
||||
for (int i = 0; i < statements->size(); i++) {
|
||||
boundStatements[i] = binder.BindStatement(statements->at(i));
|
||||
}
|
||||
@@ -62,7 +61,7 @@ namespace Porygon::Binder {
|
||||
|
||||
BoundStatement *Binder::BindBlockStatement(const ParsedStatement *statement) {
|
||||
auto statements = ((ParsedBlockStatement *) statement)->GetStatements();
|
||||
vector<BoundStatement *> boundStatements(statements->size());
|
||||
vector<const BoundStatement *> boundStatements(statements->size());
|
||||
this->_scope->GoInnerScope();
|
||||
for (int i = 0; i < statements->size(); i++) {
|
||||
boundStatements[i] = this->BindStatement(statements->at(i));
|
||||
@@ -114,8 +113,8 @@ namespace Porygon::Binder {
|
||||
return new BoundIndexAssignmentStatement(indexable, valueExpression);
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> ParseTypeIdentifier(const HashedString& s) {
|
||||
auto hash = s.GetHash();
|
||||
std::shared_ptr<ScriptType> ParseTypeIdentifier(const HashedString* s) {
|
||||
auto hash = s->GetHash();
|
||||
switch (hash) {
|
||||
case HashedString::ConstHash("number"):
|
||||
return std::make_shared<NumericScriptType>(false, false);
|
||||
@@ -135,11 +134,10 @@ namespace Porygon::Binder {
|
||||
auto functionStatement = (ParsedFunctionDeclarationStatement *) statement;
|
||||
auto parameters = functionStatement->GetParameters();
|
||||
auto parameterTypes = vector<shared_ptr<ScriptType>>(parameters->size());
|
||||
auto parameterKeys = vector<shared_ptr<BoundVariableKey>>(parameters->size());
|
||||
auto parameterKeys = vector<shared_ptr<const BoundVariableKey>>(parameters->size());
|
||||
|
||||
auto scopeIndex = this->_scope->GetCurrentScope();
|
||||
this->_scope->GoInnerScope();
|
||||
for (int i = 0; i < parameters->size(); i++) {
|
||||
for (long i = 0; i < parameters->size(); i++) {
|
||||
auto var = parameters->at(i);
|
||||
auto parsedType = ParseTypeIdentifier(var->GetType());
|
||||
if (parsedType == nullptr) {
|
||||
@@ -148,9 +146,9 @@ namespace Porygon::Binder {
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
parameterTypes.at(i) = parsedType;
|
||||
auto parameterAssignment = this->_scope->CreateExplicitLocal(var->GetIdentifier(), parsedType);
|
||||
auto parameterAssignment = this->_scope->CreateExplicitLocal(*var->GetIdentifier(), parsedType);
|
||||
if (parameterAssignment.GetResult() == VariableAssignmentResult::Ok) {
|
||||
parameterKeys.at(i) = std::shared_ptr<BoundVariableKey>(parameterAssignment.GetKey());
|
||||
parameterKeys.at(i) = std::shared_ptr<const BoundVariableKey>(parameterAssignment.GetKey());
|
||||
} else {
|
||||
//TODO: log error
|
||||
continue;
|
||||
@@ -162,9 +160,9 @@ namespace Porygon::Binder {
|
||||
auto option = new ScriptFunctionOption(returnType, parameterTypes, parameterKeys);
|
||||
this->_currentFunction = option;
|
||||
|
||||
shared_ptr<GenericFunctionScriptType> type;
|
||||
shared_ptr<const GenericFunctionScriptType> type;
|
||||
auto scope = this -> _scope -> Exists(identifier);
|
||||
BoundVariableKey* assignmentKey;
|
||||
const BoundVariableKey* assignmentKey;
|
||||
if (scope >= 0){
|
||||
auto var = this -> _scope -> GetVariable(scope, identifier);
|
||||
auto varType =var->GetType();
|
||||
@@ -172,11 +170,11 @@ namespace Porygon::Binder {
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantAssignVariable, statement->GetStartPosition(),
|
||||
statement->GetLength());
|
||||
}
|
||||
type = dynamic_pointer_cast<GenericFunctionScriptType>(varType);
|
||||
type = dynamic_pointer_cast<const GenericFunctionScriptType>(varType);
|
||||
type->RegisterFunctionOption(option);
|
||||
assignmentKey = new BoundVariableKey(identifier, scope, false);
|
||||
} else{
|
||||
type = make_shared<GenericFunctionScriptType>();
|
||||
type = make_shared<const GenericFunctionScriptType>();
|
||||
type->RegisterFunctionOption(option);
|
||||
auto assignment = this->_scope->AssignVariable(identifier, type);
|
||||
if (assignment.GetResult() != VariableAssignmentResult::Ok) {
|
||||
@@ -195,7 +193,7 @@ namespace Porygon::Binder {
|
||||
|
||||
BoundStatement *Binder::BindReturnStatement(const ParsedStatement *statement) {
|
||||
auto expression = ((ParsedReturnStatement *) statement)->GetExpression();
|
||||
shared_ptr<ScriptType> currentReturnType;
|
||||
shared_ptr<const ScriptType> currentReturnType;
|
||||
if (this->_currentFunction == nullptr) {
|
||||
currentReturnType = this->_scriptData->GetReturnType();
|
||||
} else {
|
||||
@@ -303,7 +301,7 @@ namespace Porygon::Binder {
|
||||
|
||||
auto valueIdentifier = genericFor -> GetValueIdentifier();
|
||||
auto isValueVariableDefined = valueIdentifier.GetHash() != 0;
|
||||
BoundVariableKey* valueVariable = nullptr;
|
||||
const BoundVariableKey* valueVariable = nullptr;
|
||||
if (isValueVariableDefined){
|
||||
auto valueType = itType -> GetIndexedType(keyType.get());
|
||||
auto valueVariableAssignment = this -> _scope -> CreateExplicitLocal(valueIdentifier, valueType);
|
||||
@@ -403,8 +401,8 @@ namespace Porygon::Binder {
|
||||
switch (expression->GetOperatorKind()) {
|
||||
case BinaryOperatorKind::Addition:
|
||||
if (boundLeftType->GetClass() == TypeClass::Number && boundRightType->GetClass() == TypeClass::Number) {
|
||||
auto leftNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundLeftType);
|
||||
auto rightNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundRightType);
|
||||
auto leftNumeric = std::static_pointer_cast<const NumericScriptType>(boundLeftType);
|
||||
auto rightNumeric = std::static_pointer_cast<const NumericScriptType>(boundRightType);
|
||||
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()) {
|
||||
return new BoundBinaryExpression(boundLeft, boundRight,
|
||||
BoundBinaryOperation::Addition,
|
||||
@@ -426,8 +424,8 @@ namespace Porygon::Binder {
|
||||
break;
|
||||
case BinaryOperatorKind::Subtraction:
|
||||
if (boundLeftType->GetClass() == TypeClass::Number && boundRightType->GetClass() == TypeClass::Number) {
|
||||
auto leftNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundLeftType);
|
||||
auto rightNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundRightType);
|
||||
auto leftNumeric = std::dynamic_pointer_cast<const NumericScriptType>(boundLeftType);
|
||||
auto rightNumeric = std::dynamic_pointer_cast<const NumericScriptType>(boundRightType);
|
||||
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()) {
|
||||
return new BoundBinaryExpression(boundLeft, boundRight,
|
||||
BoundBinaryOperation::Subtraction,
|
||||
@@ -444,8 +442,8 @@ namespace Porygon::Binder {
|
||||
break;
|
||||
case BinaryOperatorKind::Multiplication:
|
||||
if (boundLeftType->GetClass() == TypeClass::Number && boundRightType->GetClass() == TypeClass::Number) {
|
||||
auto leftNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundLeftType);
|
||||
auto rightNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundRightType);
|
||||
auto leftNumeric = std::dynamic_pointer_cast<const NumericScriptType>(boundLeftType);
|
||||
auto rightNumeric = std::dynamic_pointer_cast<const NumericScriptType>(boundRightType);
|
||||
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()) {
|
||||
return new BoundBinaryExpression(boundLeft, boundRight,
|
||||
BoundBinaryOperation::Multiplication,
|
||||
@@ -462,8 +460,8 @@ namespace Porygon::Binder {
|
||||
break;
|
||||
case BinaryOperatorKind::Division:
|
||||
if (boundLeftType->GetClass() == TypeClass::Number && boundRightType->GetClass() == TypeClass::Number) {
|
||||
auto leftNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundLeftType);
|
||||
auto rightNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundRightType);
|
||||
auto leftNumeric = std::dynamic_pointer_cast<const NumericScriptType>(boundLeftType);
|
||||
auto rightNumeric = std::dynamic_pointer_cast<const NumericScriptType>(boundRightType);
|
||||
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()) {
|
||||
return new BoundBinaryExpression(boundLeft, boundRight,
|
||||
BoundBinaryOperation::Division,
|
||||
@@ -544,7 +542,7 @@ namespace Porygon::Binder {
|
||||
break;
|
||||
case UnaryOperatorKind::Negation:
|
||||
if (operandType->GetClass() == TypeClass::Number) {
|
||||
auto innerType = std::dynamic_pointer_cast<NumericScriptType>(operandType);
|
||||
auto innerType = std::dynamic_pointer_cast<const NumericScriptType>(operandType);
|
||||
return new BoundUnaryExpression(operand, BoundUnaryOperation::Negation,
|
||||
std::make_shared<NumericScriptType>(
|
||||
innerType.get()->IsAwareOfFloat(),
|
||||
@@ -577,11 +575,11 @@ namespace Porygon::Binder {
|
||||
expression->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
auto functionType = std::dynamic_pointer_cast<GenericFunctionScriptType>(type);
|
||||
auto functionType = std::dynamic_pointer_cast<const GenericFunctionScriptType>(type);
|
||||
auto givenParameters = expression->GetParameters();
|
||||
auto givenParameterTypes = vector<shared_ptr<ScriptType>>(givenParameters->size());
|
||||
auto givenParameterTypes = vector<shared_ptr<const ScriptType>>(givenParameters->size());
|
||||
vector<BoundExpression *> boundParameters = vector<BoundExpression *>(givenParameters->size());
|
||||
for (int i = 0; i < givenParameters->size(); i++){
|
||||
for (long i = 0; i < givenParameters->size(); i++){
|
||||
boundParameters[i] = this -> BindExpression(givenParameters->at(i));
|
||||
givenParameterTypes[i] = boundParameters[i]->GetType();
|
||||
}
|
||||
@@ -609,8 +607,8 @@ namespace Porygon::Binder {
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
if (indexerType->GetClass() == TypeClass::UserData) {
|
||||
auto stringKey = dynamic_pointer_cast<StringScriptType>(index->GetType());
|
||||
auto field = dynamic_pointer_cast<UserData::UserDataScriptType>(indexerType)->GetField(stringKey->GetHashValue());
|
||||
auto stringKey = dynamic_pointer_cast<const StringScriptType>(index->GetType());
|
||||
auto field = dynamic_pointer_cast<const UserData::UserDataScriptType>(indexerType)->GetField(stringKey->GetHashValue());
|
||||
if (!setter) {
|
||||
if (!field->HasGetter()) {
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UserDataFieldNoGetter,
|
||||
@@ -643,7 +641,7 @@ namespace Porygon::Binder {
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
if (indexerType->GetClass() == TypeClass::UserData) {
|
||||
auto field = dynamic_pointer_cast<UserData::UserDataScriptType>(indexerType)->GetField(identifier.GetHash());
|
||||
auto field = dynamic_pointer_cast<const UserData::UserDataScriptType>(indexerType)->GetField(identifier.GetHash());
|
||||
if (!setter) {
|
||||
if (!field->HasGetter()) {
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UserDataFieldNoGetter,
|
||||
@@ -670,11 +668,11 @@ namespace Porygon::Binder {
|
||||
BoundExpression *Binder::BindNumericalTableExpression(const ParsedNumericalTableExpression *expression) {
|
||||
auto expressions = expression->GetExpressions();
|
||||
auto boundExpressions = vector<const BoundExpression *>(expressions->size());
|
||||
shared_ptr<ScriptType> valueType = nullptr;
|
||||
shared_ptr<const ScriptType> valueType = nullptr;
|
||||
if (!boundExpressions.empty()) {
|
||||
boundExpressions[0] = this->BindExpression(expressions->at(0));
|
||||
valueType = boundExpressions[0]->GetType();
|
||||
for (int i = 1; i < expressions->size(); i++) {
|
||||
for (long i = 1; i < expressions->size(); i++) {
|
||||
boundExpressions[i] = this->BindExpression(expressions->at(i));
|
||||
if (boundExpressions[i]->GetType().get()->operator!=(valueType.get())) {
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::InvalidTableValueType,
|
||||
@@ -684,9 +682,9 @@ namespace Porygon::Binder {
|
||||
}
|
||||
}
|
||||
if (valueType == nullptr) {
|
||||
valueType = std::make_shared<ScriptType>(TypeClass::Nil);
|
||||
valueType = std::make_shared<const ScriptType>(TypeClass::Nil);
|
||||
}
|
||||
auto tableType = std::make_shared<NumericalTableScriptType>(valueType);
|
||||
auto tableType = std::make_shared<const NumericalTableScriptType>(valueType);
|
||||
return new BoundNumericalTableExpression(boundExpressions, tableType, expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
using namespace std;
|
||||
|
||||
namespace Porygon::Binder {
|
||||
enum class BoundExpressionKind {
|
||||
enum class BoundExpressionKind : u_int8_t {
|
||||
Bad,
|
||||
|
||||
LiteralInteger,
|
||||
@@ -33,9 +33,9 @@ namespace Porygon::Binder {
|
||||
class BoundExpression {
|
||||
const unsigned int _start;
|
||||
const unsigned int _length;
|
||||
const shared_ptr<ScriptType> _type;
|
||||
const shared_ptr<const ScriptType> _type;
|
||||
public:
|
||||
BoundExpression(unsigned int start, unsigned int length, shared_ptr<ScriptType> type)
|
||||
BoundExpression(unsigned int start, unsigned int length, shared_ptr<const ScriptType> type)
|
||||
: _start(start),
|
||||
_length(length),
|
||||
_type(std::move(type)) {
|
||||
@@ -43,23 +43,23 @@ namespace Porygon::Binder {
|
||||
|
||||
virtual ~BoundExpression() = default;
|
||||
|
||||
virtual const BoundExpressionKind GetKind() const = 0;
|
||||
[[nodiscard]]
|
||||
virtual BoundExpressionKind GetKind() const = 0;
|
||||
|
||||
virtual const std::shared_ptr<ScriptType> &GetType() const {
|
||||
[[nodiscard]]
|
||||
virtual const std::shared_ptr<const ScriptType> &GetType() const {
|
||||
return _type;
|
||||
};
|
||||
|
||||
inline const unsigned int GetStartPosition() const {
|
||||
[[nodiscard]]
|
||||
inline unsigned int GetStartPosition() const {
|
||||
return _start;
|
||||
}
|
||||
|
||||
inline const unsigned int GetLength() const {
|
||||
[[nodiscard]]
|
||||
inline unsigned int GetLength() const {
|
||||
return _length;
|
||||
}
|
||||
|
||||
inline const unsigned int GetEndPosition() const {
|
||||
return _start + _length - 1;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundBadExpression : public BoundExpression {
|
||||
@@ -68,7 +68,8 @@ namespace Porygon::Binder {
|
||||
make_shared<ScriptType>(
|
||||
TypeClass::Error)) {}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::Bad;
|
||||
}
|
||||
};
|
||||
@@ -81,11 +82,13 @@ namespace Porygon::Binder {
|
||||
_value(value) {
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::LiteralInteger;
|
||||
}
|
||||
|
||||
inline const long GetValue() const {
|
||||
[[nodiscard]]
|
||||
inline long GetValue() const {
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
@@ -98,11 +101,13 @@ namespace Porygon::Binder {
|
||||
_value(value) {
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::LiteralFloat;
|
||||
}
|
||||
|
||||
inline const double GetValue() const {
|
||||
[[nodiscard]]
|
||||
inline double GetValue() const {
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
@@ -116,12 +121,14 @@ namespace Porygon::Binder {
|
||||
_value(value) {
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::LiteralString;
|
||||
}
|
||||
|
||||
inline const u16string GetValue() const {
|
||||
return _value;
|
||||
[[nodiscard]]
|
||||
inline const u16string* GetValue() const {
|
||||
return &_value;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -133,11 +140,13 @@ namespace Porygon::Binder {
|
||||
_value(value) {
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::LiteralBool;
|
||||
}
|
||||
|
||||
inline const bool GetValue() const {
|
||||
[[nodiscard]]
|
||||
inline bool GetValue() const {
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
@@ -145,9 +154,9 @@ namespace Porygon::Binder {
|
||||
class BoundVariableExpression : public BoundExpression {
|
||||
const BoundVariableKey *_key;
|
||||
public:
|
||||
BoundVariableExpression(BoundVariableKey *key, shared_ptr<ScriptType> type, unsigned int start,
|
||||
BoundVariableExpression(BoundVariableKey *key, const shared_ptr<const ScriptType>& type, unsigned int start,
|
||||
unsigned int length)
|
||||
: BoundExpression(start, length, std::move(type)),
|
||||
: BoundExpression(start, length, type),
|
||||
_key(key) {
|
||||
}
|
||||
|
||||
@@ -155,10 +164,12 @@ namespace Porygon::Binder {
|
||||
delete _key;
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::Variable;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundVariableKey *GetKey() const {
|
||||
return _key;
|
||||
}
|
||||
@@ -183,19 +194,23 @@ namespace Porygon::Binder {
|
||||
delete _right;
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::Binary;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetLeft() const {
|
||||
return _left;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetRight() const {
|
||||
return _right;
|
||||
}
|
||||
|
||||
inline const BoundBinaryOperation GetOperation() const {
|
||||
[[nodiscard]]
|
||||
inline BoundBinaryOperation GetOperation() const {
|
||||
return _operation;
|
||||
}
|
||||
};
|
||||
@@ -215,15 +230,18 @@ namespace Porygon::Binder {
|
||||
delete _operand;
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::Unary;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetOperand() const {
|
||||
return _operand;
|
||||
}
|
||||
|
||||
inline const BoundUnaryOperation GetOperation() const {
|
||||
[[nodiscard]]
|
||||
inline BoundUnaryOperation GetOperation() const {
|
||||
return _operation;
|
||||
}
|
||||
};
|
||||
@@ -233,7 +251,7 @@ namespace Porygon::Binder {
|
||||
const BoundExpression *_indexExpression;
|
||||
public:
|
||||
BoundIndexExpression(BoundExpression *indexableExpression, BoundExpression *indexExpression,
|
||||
shared_ptr<ScriptType> result,
|
||||
shared_ptr<const ScriptType> result,
|
||||
unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, std::move(result)), _indexableExpression(indexableExpression),
|
||||
_indexExpression(indexExpression) {}
|
||||
@@ -243,14 +261,17 @@ namespace Porygon::Binder {
|
||||
delete _indexExpression;
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::Index;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetIndexableExpression() const {
|
||||
return _indexableExpression;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetIndexExpression() const {
|
||||
return _indexExpression;
|
||||
}
|
||||
@@ -260,8 +281,8 @@ namespace Porygon::Binder {
|
||||
const BoundExpression *_indexableExpression;
|
||||
const Utilities::HashedString _index;
|
||||
public:
|
||||
BoundPeriodIndexExpression(BoundExpression *indexableExpression, Utilities::HashedString index,
|
||||
shared_ptr<ScriptType> result,
|
||||
BoundPeriodIndexExpression(BoundExpression *indexableExpression, const Utilities::HashedString& index,
|
||||
shared_ptr<const ScriptType> result,
|
||||
unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, std::move(result)), _indexableExpression(indexableExpression),
|
||||
_index(index) {}
|
||||
@@ -270,23 +291,26 @@ namespace Porygon::Binder {
|
||||
delete _indexableExpression;
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::PeriodIndex;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetIndexableExpression() const {
|
||||
return _indexableExpression;
|
||||
}
|
||||
|
||||
inline const Utilities::HashedString GetIndex() const {
|
||||
return _index;
|
||||
[[nodiscard]]
|
||||
inline const Utilities::HashedString* GetIndex() const {
|
||||
return &_index;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundNumericalTableExpression : public BoundExpression {
|
||||
const vector<const BoundExpression *> _expressions;
|
||||
public:
|
||||
BoundNumericalTableExpression(vector<const BoundExpression *> expressions, shared_ptr<ScriptType> type,
|
||||
BoundNumericalTableExpression(vector<const BoundExpression *> expressions, shared_ptr<const ScriptType> type,
|
||||
unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, std::move(type)),
|
||||
_expressions(std::move(expressions)) {}
|
||||
@@ -297,10 +321,12 @@ namespace Porygon::Binder {
|
||||
}
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::NumericalTable;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const vector<const BoundExpression *> *GetExpressions() const {
|
||||
return &_expressions;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Porygon::Binder {
|
||||
const Porygon::GenericFunctionOption *_option;
|
||||
public:
|
||||
BoundFunctionCallExpression(BoundExpression *functionExpression, vector<BoundExpression *> parameters,
|
||||
Porygon::GenericFunctionOption *option, shared_ptr<Porygon::ScriptType> result,
|
||||
Porygon::GenericFunctionOption *option, shared_ptr<const Porygon::ScriptType> result,
|
||||
unsigned int start, unsigned int length)
|
||||
: BoundExpression(start, length, move(result)), _functionExpression(functionExpression),
|
||||
_parameters(move(parameters)), _option(option) {}
|
||||
@@ -22,18 +22,22 @@ namespace Porygon::Binder {
|
||||
}
|
||||
}
|
||||
|
||||
inline const Porygon::Binder::BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline Porygon::Binder::BoundExpressionKind GetKind() const final {
|
||||
return Porygon::Binder::BoundExpressionKind::FunctionCall;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetFunctionExpression() const {
|
||||
return _functionExpression;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const vector<BoundExpression *> *GetParameters() const {
|
||||
return &_parameters;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const Porygon::GenericFunctionOption *GetFunctionOption() const {
|
||||
return _option;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <utility>
|
||||
|
||||
|
||||
#ifndef PORYGONLANG_BOUNDTABLEEXPRESSION_HPP
|
||||
#define PORYGONLANG_BOUNDTABLEEXPRESSION_HPP
|
||||
|
||||
#include <utility>
|
||||
#include "../BoundStatements/BoundStatement.hpp"
|
||||
|
||||
namespace Porygon::Binder {
|
||||
@@ -20,10 +20,12 @@ namespace Porygon::Binder {
|
||||
delete _block;
|
||||
}
|
||||
|
||||
inline const BoundExpressionKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundExpressionKind GetKind() const final {
|
||||
return BoundExpressionKind::Table;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundBlockStatement *GetBlock() const {
|
||||
return _block;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace Porygon::Binder {
|
||||
class BoundFunctionDeclarationStatement : public BoundStatement {
|
||||
const BoundVariableKey *_key;
|
||||
const std::shared_ptr<BoundBlockStatement> _block;
|
||||
const std::shared_ptr<GenericFunctionScriptType> _type;
|
||||
const std::shared_ptr<const GenericFunctionScriptType> _type;
|
||||
public:
|
||||
BoundFunctionDeclarationStatement(std::shared_ptr<GenericFunctionScriptType> type, BoundVariableKey *key,
|
||||
BoundFunctionDeclarationStatement(std::shared_ptr<const GenericFunctionScriptType> type, const BoundVariableKey *key,
|
||||
BoundBlockStatement *block)
|
||||
: _key(key), _block(block), _type(std::move(type)) {
|
||||
}
|
||||
@@ -21,19 +21,23 @@ namespace Porygon::Binder {
|
||||
delete _key;
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::FunctionDeclaration;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundVariableKey *GetKey() const {
|
||||
return _key;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<BoundBlockStatement> GetBlock() const {
|
||||
[[nodiscard]]
|
||||
inline std::shared_ptr<const BoundBlockStatement> GetBlock() const {
|
||||
return _block;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<GenericFunctionScriptType> GetType() const {
|
||||
[[nodiscard]]
|
||||
inline std::shared_ptr<const GenericFunctionScriptType> GetType() const {
|
||||
return _type;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
using namespace std;
|
||||
|
||||
namespace Porygon::Binder {
|
||||
enum class BoundStatementKind {
|
||||
enum class BoundStatementKind : u_int8_t {
|
||||
Bad,
|
||||
Break,
|
||||
Script,
|
||||
@@ -28,29 +28,32 @@ namespace Porygon::Binder {
|
||||
|
||||
class BoundStatement {
|
||||
public:
|
||||
virtual const BoundStatementKind GetKind() const = 0;
|
||||
[[nodiscard]]
|
||||
virtual BoundStatementKind GetKind() const = 0;
|
||||
|
||||
virtual ~BoundStatement() = default;
|
||||
};
|
||||
|
||||
class BoundBadStatement : public BoundStatement {
|
||||
public:
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::Bad;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundBreakStatement : public BoundStatement {
|
||||
public:
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::Break;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundBlockStatement : public BoundStatement {
|
||||
const vector<BoundStatement *> _statements;
|
||||
const vector<const BoundStatement *> _statements;
|
||||
public:
|
||||
explicit BoundBlockStatement(vector<BoundStatement *> statements)
|
||||
explicit BoundBlockStatement(vector<const BoundStatement *> statements)
|
||||
: _statements(std::move(statements)) {
|
||||
}
|
||||
|
||||
@@ -60,11 +63,13 @@ namespace Porygon::Binder {
|
||||
}
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const override {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const override {
|
||||
return BoundStatementKind::Block;
|
||||
}
|
||||
|
||||
inline const vector<BoundStatement *> *GetStatements() const {
|
||||
[[nodiscard]]
|
||||
inline const vector<const BoundStatement *> *GetStatements() const {
|
||||
return &_statements;
|
||||
}
|
||||
};
|
||||
@@ -72,16 +77,18 @@ namespace Porygon::Binder {
|
||||
class BoundScriptStatement : public BoundBlockStatement {
|
||||
const int _localVariableCount;
|
||||
public:
|
||||
explicit BoundScriptStatement(vector<BoundStatement *> statements, int localVariableCount)
|
||||
explicit BoundScriptStatement(vector<const BoundStatement *> statements, int localVariableCount)
|
||||
: BoundBlockStatement(std::move(statements)),
|
||||
_localVariableCount(localVariableCount) {
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::Script;
|
||||
}
|
||||
|
||||
inline const int GetLocalVariableCount() const {
|
||||
[[nodiscard]]
|
||||
inline int GetLocalVariableCount() const {
|
||||
return _localVariableCount;
|
||||
}
|
||||
};
|
||||
@@ -98,10 +105,12 @@ namespace Porygon::Binder {
|
||||
delete _expression;
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::Expression;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetExpression() const {
|
||||
return _expression;
|
||||
}
|
||||
@@ -111,7 +120,7 @@ namespace Porygon::Binder {
|
||||
const BoundVariableKey *_key;
|
||||
const BoundExpression *_expression;
|
||||
public:
|
||||
BoundAssignmentStatement(BoundVariableKey *key, BoundExpression *expression)
|
||||
BoundAssignmentStatement(const BoundVariableKey *key, BoundExpression *expression)
|
||||
: _key(key), _expression(expression) {
|
||||
}
|
||||
|
||||
@@ -120,14 +129,17 @@ namespace Porygon::Binder {
|
||||
delete _expression;
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::Assignment;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundVariableKey *GetKey() const {
|
||||
return _key;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetExpression() const {
|
||||
return _expression;
|
||||
}
|
||||
@@ -146,14 +158,17 @@ namespace Porygon::Binder {
|
||||
delete _valueExpression;
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::IndexAssignment;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetIndexExpression() const {
|
||||
return _indexExpression;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetValueExpression() const {
|
||||
return _valueExpression;
|
||||
}
|
||||
@@ -170,10 +185,12 @@ namespace Porygon::Binder {
|
||||
delete _expression;
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::Return;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetExpression() const {
|
||||
return _expression;
|
||||
}
|
||||
@@ -194,18 +211,22 @@ namespace Porygon::Binder {
|
||||
delete _elseStatement;
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::Conditional;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression *GetCondition() const {
|
||||
return _condition;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundStatement *GetBlock() const {
|
||||
return _block;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundStatement *GetElseStatement() const {
|
||||
return _elseStatement;
|
||||
}
|
||||
@@ -233,26 +254,32 @@ namespace Porygon::Binder {
|
||||
delete _block;
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::NumericalFor;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundVariableKey* GetIdentifier() const{
|
||||
return _identifier;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression* GetStart() const{
|
||||
return _start;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression* GetEnd() const{
|
||||
return _end;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression* GetStep() const{
|
||||
return _step;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundStatement* GetBlock() const{
|
||||
return _block;
|
||||
}
|
||||
@@ -278,22 +305,27 @@ namespace Porygon::Binder {
|
||||
delete _block;
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::GenericFor;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundVariableKey* GetKeyIdentifier() const{
|
||||
return _keyIdentifier;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundVariableKey* GetValueIdentifier() const{
|
||||
return _valueIdentifier;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression* GetIterator() const{
|
||||
return _iterator;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundStatement* GetBlock() const{
|
||||
return _block;
|
||||
}
|
||||
@@ -312,14 +344,17 @@ namespace Porygon::Binder {
|
||||
delete _block;
|
||||
}
|
||||
|
||||
inline const BoundStatementKind GetKind() const final {
|
||||
[[nodiscard]]
|
||||
inline BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::While;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundExpression* GetCondition() const{
|
||||
return _condition;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline const BoundStatement* GetBlock() const{
|
||||
return _block;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#include <utility>
|
||||
|
||||
|
||||
#include "BoundScope.hpp"
|
||||
#include "../../StandardLibraries/StaticScope.hpp"
|
||||
|
||||
@@ -15,7 +13,7 @@ namespace Porygon::Binder {
|
||||
|
||||
BoundScope::~BoundScope() {
|
||||
for (auto scope : _localScope) {
|
||||
for (auto v : *scope) {
|
||||
for (const auto& v : *scope) {
|
||||
delete v.second;
|
||||
}
|
||||
delete scope;
|
||||
@@ -33,7 +31,7 @@ namespace Porygon::Binder {
|
||||
|
||||
void BoundScope::GoOuterScope() {
|
||||
auto scope = _localScope[_currentScope - 1];
|
||||
for (auto v : *scope) {
|
||||
for (const auto& v : *scope) {
|
||||
delete v.second;
|
||||
}
|
||||
scope->clear();
|
||||
@@ -79,7 +77,7 @@ namespace Porygon::Binder {
|
||||
}
|
||||
}
|
||||
|
||||
VariableAssignment BoundScope::CreateExplicitLocal(const Utilities::HashedString& identifier, std::shared_ptr<ScriptType> type) {
|
||||
VariableAssignment BoundScope::CreateExplicitLocal(const Utilities::HashedString& identifier, std::shared_ptr<const ScriptType> type) {
|
||||
auto scope = this->_localScope.at(this->_currentScope - 1);
|
||||
if (scope->find(identifier) != scope->end()) {
|
||||
return VariableAssignment(VariableAssignmentResult::ExplicitLocalVariableExists, nullptr);
|
||||
@@ -89,7 +87,7 @@ namespace Porygon::Binder {
|
||||
new BoundVariableKey(identifier, this->_currentScope, true));
|
||||
}
|
||||
|
||||
VariableAssignment BoundScope::AssignVariable(const Utilities::HashedString& identifier, const std::shared_ptr<ScriptType> &type) {
|
||||
VariableAssignment BoundScope::AssignVariable(const Utilities::HashedString& identifier, const std::shared_ptr<const ScriptType> &type) {
|
||||
int exists = this->Exists(identifier);
|
||||
if (exists < 0) {
|
||||
// Creation
|
||||
|
||||
@@ -32,17 +32,13 @@ namespace Porygon::Binder {
|
||||
|
||||
BoundVariable *GetVariable(uint32_t scope, const Utilities::HashedString& identifier);
|
||||
|
||||
VariableAssignment CreateExplicitLocal(const Utilities::HashedString& identifier, std::shared_ptr<ScriptType> type);
|
||||
VariableAssignment CreateExplicitLocal(const Utilities::HashedString& identifier, std::shared_ptr<const ScriptType> type);
|
||||
|
||||
VariableAssignment AssignVariable(const Utilities::HashedString& identifier, const std::shared_ptr<ScriptType> &type);
|
||||
VariableAssignment AssignVariable(const Utilities::HashedString& identifier, const std::shared_ptr<const ScriptType> &type);
|
||||
|
||||
inline size_t GetLocalVariableCount() {
|
||||
return _localScope.size();
|
||||
}
|
||||
|
||||
inline int GetCurrentScope() {
|
||||
return _currentScope;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <utility>
|
||||
|
||||
|
||||
#ifndef PORYGONLANG_BOUNDVARIABLE_HPP
|
||||
#define PORYGONLANG_BOUNDVARIABLE_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include "../../ScriptType.hpp"
|
||||
|
||||
@@ -11,12 +11,12 @@ using namespace std;
|
||||
|
||||
namespace Porygon::Binder {
|
||||
class BoundVariable {
|
||||
std::shared_ptr<ScriptType> _type;
|
||||
std::shared_ptr<const ScriptType> _type;
|
||||
public:
|
||||
inline explicit BoundVariable(std::shared_ptr<ScriptType> type) : _type(std::move(type)) {
|
||||
inline explicit BoundVariable(std::shared_ptr<const ScriptType> type) : _type(std::move(type)) {
|
||||
}
|
||||
|
||||
inline std::shared_ptr<ScriptType> GetType() {
|
||||
inline std::shared_ptr<const ScriptType> GetType() {
|
||||
return _type;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,26 +19,30 @@ namespace Porygon::Binder {
|
||||
}
|
||||
|
||||
public:
|
||||
BoundVariableKey(Utilities::HashedString id, unsigned int scope, bool creation)
|
||||
BoundVariableKey(const Utilities::HashedString& id, unsigned int scope, bool creation)
|
||||
: _identifier(id),
|
||||
_scopeId(scope),
|
||||
_isCreation(creation),
|
||||
_hash(KnuthsHash(id.GetHash(), scope)) {}
|
||||
|
||||
|
||||
inline const Utilities::HashedString GetIdentifier() const {
|
||||
return _identifier;
|
||||
[[nodiscard]]
|
||||
inline const Utilities::HashedString* GetIdentifier() const {
|
||||
return &_identifier;
|
||||
}
|
||||
|
||||
inline const unsigned int GetScopeId() const {
|
||||
[[nodiscard]]
|
||||
inline unsigned int GetScopeId() const {
|
||||
return _scopeId;
|
||||
}
|
||||
|
||||
inline const bool IsCreation() const {
|
||||
[[nodiscard]]
|
||||
inline bool IsCreation() const {
|
||||
return _isCreation;
|
||||
}
|
||||
|
||||
inline const uint64_t GetHash() const {
|
||||
[[nodiscard]]
|
||||
inline uint64_t GetHash() const {
|
||||
return _hash;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,18 +13,20 @@ namespace Porygon::Binder {
|
||||
|
||||
class VariableAssignment {
|
||||
VariableAssignmentResult _result;
|
||||
BoundVariableKey *_key;
|
||||
const BoundVariableKey *_key;
|
||||
public:
|
||||
VariableAssignment(VariableAssignmentResult result, BoundVariableKey *key) {
|
||||
_result = result;
|
||||
_key = key;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline VariableAssignmentResult GetResult() {
|
||||
return _result;
|
||||
}
|
||||
|
||||
inline BoundVariableKey *GetKey() {
|
||||
[[nodiscard]]
|
||||
inline const BoundVariableKey *GetKey() {
|
||||
return _key;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user