Include type in BoundVariableKey for debugging purposes
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:
@@ -178,7 +178,7 @@ namespace Porygon::Binder {
|
||||
}
|
||||
type = dynamic_pointer_cast<const GenericFunctionScriptType>(varType);
|
||||
type->RegisterFunctionOption(option);
|
||||
assignmentKey = new BoundVariableKey(identifier, scope, false);
|
||||
assignmentKey = new BoundVariableKey(identifier, scope, false, type);
|
||||
} else {
|
||||
type = make_shared<const GenericFunctionScriptType>();
|
||||
type->RegisterFunctionOption(option);
|
||||
@@ -409,7 +409,7 @@ namespace Porygon::Binder {
|
||||
}
|
||||
auto var = this->_scope->GetVariable(scope, key);
|
||||
auto type = var->GetType();
|
||||
return new BoundVariableExpression(new BoundVariableKey(key, scope, false), type,
|
||||
return new BoundVariableExpression(new BoundVariableKey(key, scope, false, type), type,
|
||||
expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "../BoundExpressions/BoundExpression.hpp"
|
||||
#include "../BoundVariables/BoundVariableKey.hpp"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Porygon::Binder {
|
||||
@@ -437,9 +436,9 @@ namespace Porygon::Binder {
|
||||
DrawIndents(stream, indents);
|
||||
stream << "GenericForLoopStatement" << endl;
|
||||
DrawIndents(stream, indents);
|
||||
stream << "Key: " << _keyIdentifier->GetIdentifier()->GetDebugString() << endl;
|
||||
stream << "Key: " << _keyIdentifier->GetIdentifier()->GetDebugString() << " (" << _keyIdentifier->GetType()->ToString() << ")" << endl;
|
||||
DrawIndents(stream, indents);
|
||||
stream << "Value: " << _valueIdentifier->GetIdentifier()->GetDebugString() << endl;
|
||||
stream << "Value: " << _valueIdentifier->GetIdentifier()->GetDebugString() << " (" << _keyIdentifier->GetType()->ToString() << ")" << endl;
|
||||
DrawIndents(stream, indents);
|
||||
stream << "Iterator:" << endl;
|
||||
_iterator->GetTreeString(stream, indents + 1);
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Porygon::Binder {
|
||||
}
|
||||
scope->insert({identifier, new BoundVariable(std::move(type))});
|
||||
return VariableAssignment(VariableAssignmentResult::Ok,
|
||||
new BoundVariableKey(identifier, this->_currentScope, true));
|
||||
new BoundVariableKey(identifier, this->_currentScope, true, type));
|
||||
}
|
||||
|
||||
VariableAssignment BoundScope::AssignVariable(const Utilities::HashedString& identifier, const std::shared_ptr<const ScriptType> &type) {
|
||||
@@ -97,14 +97,14 @@ namespace Porygon::Binder {
|
||||
if (_tableVariableTypes != nullptr){
|
||||
_tableVariableTypes->insert({identifier, type});
|
||||
}
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, 0, true));
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, 0, true, type));
|
||||
} else {
|
||||
// Assigning
|
||||
auto var = this->GetVariable(exists, identifier);
|
||||
if (var->GetType()->operator!=(type)) {
|
||||
return VariableAssignment(VariableAssignmentResult::VariableDefinedWithDifferentType, nullptr);
|
||||
}
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, exists, false));
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, exists, false, type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <string>
|
||||
#include "../../Utilities/HashedString.hpp"
|
||||
#include "../../ScriptTypes/ScriptType.hpp"
|
||||
|
||||
namespace Porygon::Binder {
|
||||
class BoundVariableKey {
|
||||
@@ -11,6 +12,7 @@ namespace Porygon::Binder {
|
||||
const unsigned int _scopeId;
|
||||
const bool _isCreation;
|
||||
const uint64_t _hash;
|
||||
shared_ptr<const ScriptType> _type;
|
||||
|
||||
static uint64_t KnuthsHash(unsigned int i1, unsigned int i2) {
|
||||
uint64_t ret = i1;
|
||||
@@ -19,10 +21,11 @@ namespace Porygon::Binder {
|
||||
}
|
||||
|
||||
public:
|
||||
BoundVariableKey(const Utilities::HashedString& id, unsigned int scope, bool creation)
|
||||
BoundVariableKey(const Utilities::HashedString& id, unsigned int scope, bool creation, shared_ptr<const ScriptType> type)
|
||||
: _identifier(id),
|
||||
_scopeId(scope),
|
||||
_isCreation(creation),
|
||||
_type(type),
|
||||
_hash(KnuthsHash(id.GetHash(), scope)) {}
|
||||
|
||||
|
||||
@@ -45,6 +48,10 @@ namespace Porygon::Binder {
|
||||
inline uint64_t GetHash() const {
|
||||
return _hash;
|
||||
}
|
||||
|
||||
inline shared_ptr<const ScriptType> GetType() const{
|
||||
return _type;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
#include "../EvalValues/EvalValue.hpp"
|
||||
#include "../EvalValuePointer.hpp"
|
||||
#include "../../Binder/BoundVariables/BoundVariableKey.hpp"
|
||||
|
||||
using namespace Porygon::Binder;
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
#include <utility>
|
||||
|
||||
|
||||
#ifndef PORYGONLANG_SCRIPTTYPE_HPP
|
||||
#define PORYGONLANG_SCRIPTTYPE_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "../Binder/BoundVariables/BoundVariableKey.hpp"
|
||||
#include "../Utilities/HashedString.hpp"
|
||||
#include "CastResult.hpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user