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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user