Include type in BoundVariableKey for debugging purposes
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
629adafeaf
commit
8f078e580e
|
@ -178,7 +178,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
type = dynamic_pointer_cast<const GenericFunctionScriptType>(varType);
|
type = dynamic_pointer_cast<const GenericFunctionScriptType>(varType);
|
||||||
type->RegisterFunctionOption(option);
|
type->RegisterFunctionOption(option);
|
||||||
assignmentKey = new BoundVariableKey(identifier, scope, false);
|
assignmentKey = new BoundVariableKey(identifier, scope, false, type);
|
||||||
} else {
|
} else {
|
||||||
type = make_shared<const GenericFunctionScriptType>();
|
type = make_shared<const GenericFunctionScriptType>();
|
||||||
type->RegisterFunctionOption(option);
|
type->RegisterFunctionOption(option);
|
||||||
|
@ -409,7 +409,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
auto var = this->_scope->GetVariable(scope, key);
|
auto var = this->_scope->GetVariable(scope, key);
|
||||||
auto type = var->GetType();
|
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());
|
expression->GetStartPosition(), expression->GetLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include "../BoundExpressions/BoundExpression.hpp"
|
#include "../BoundExpressions/BoundExpression.hpp"
|
||||||
#include "../BoundVariables/BoundVariableKey.hpp"
|
#include "../BoundVariables/BoundVariableKey.hpp"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace Porygon::Binder {
|
namespace Porygon::Binder {
|
||||||
|
@ -437,9 +436,9 @@ namespace Porygon::Binder {
|
||||||
DrawIndents(stream, indents);
|
DrawIndents(stream, indents);
|
||||||
stream << "GenericForLoopStatement" << endl;
|
stream << "GenericForLoopStatement" << endl;
|
||||||
DrawIndents(stream, indents);
|
DrawIndents(stream, indents);
|
||||||
stream << "Key: " << _keyIdentifier->GetIdentifier()->GetDebugString() << endl;
|
stream << "Key: " << _keyIdentifier->GetIdentifier()->GetDebugString() << " (" << _keyIdentifier->GetType()->ToString() << ")" << endl;
|
||||||
DrawIndents(stream, indents);
|
DrawIndents(stream, indents);
|
||||||
stream << "Value: " << _valueIdentifier->GetIdentifier()->GetDebugString() << endl;
|
stream << "Value: " << _valueIdentifier->GetIdentifier()->GetDebugString() << " (" << _keyIdentifier->GetType()->ToString() << ")" << endl;
|
||||||
DrawIndents(stream, indents);
|
DrawIndents(stream, indents);
|
||||||
stream << "Iterator:" << endl;
|
stream << "Iterator:" << endl;
|
||||||
_iterator->GetTreeString(stream, indents + 1);
|
_iterator->GetTreeString(stream, indents + 1);
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
scope->insert({identifier, new BoundVariable(std::move(type))});
|
scope->insert({identifier, new BoundVariable(std::move(type))});
|
||||||
return VariableAssignment(VariableAssignmentResult::Ok,
|
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) {
|
VariableAssignment BoundScope::AssignVariable(const Utilities::HashedString& identifier, const std::shared_ptr<const ScriptType> &type) {
|
||||||
|
@ -97,14 +97,14 @@ namespace Porygon::Binder {
|
||||||
if (_tableVariableTypes != nullptr){
|
if (_tableVariableTypes != nullptr){
|
||||||
_tableVariableTypes->insert({identifier, type});
|
_tableVariableTypes->insert({identifier, type});
|
||||||
}
|
}
|
||||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, 0, true));
|
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, 0, true, type));
|
||||||
} else {
|
} else {
|
||||||
// Assigning
|
// Assigning
|
||||||
auto var = this->GetVariable(exists, identifier);
|
auto var = this->GetVariable(exists, identifier);
|
||||||
if (var->GetType()->operator!=(type)) {
|
if (var->GetType()->operator!=(type)) {
|
||||||
return VariableAssignment(VariableAssignmentResult::VariableDefinedWithDifferentType, nullptr);
|
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 <string>
|
||||||
#include "../../Utilities/HashedString.hpp"
|
#include "../../Utilities/HashedString.hpp"
|
||||||
|
#include "../../ScriptTypes/ScriptType.hpp"
|
||||||
|
|
||||||
namespace Porygon::Binder {
|
namespace Porygon::Binder {
|
||||||
class BoundVariableKey {
|
class BoundVariableKey {
|
||||||
|
@ -11,6 +12,7 @@ namespace Porygon::Binder {
|
||||||
const unsigned int _scopeId;
|
const unsigned int _scopeId;
|
||||||
const bool _isCreation;
|
const bool _isCreation;
|
||||||
const uint64_t _hash;
|
const uint64_t _hash;
|
||||||
|
shared_ptr<const ScriptType> _type;
|
||||||
|
|
||||||
static uint64_t KnuthsHash(unsigned int i1, unsigned int i2) {
|
static uint64_t KnuthsHash(unsigned int i1, unsigned int i2) {
|
||||||
uint64_t ret = i1;
|
uint64_t ret = i1;
|
||||||
|
@ -19,10 +21,11 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
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),
|
: _identifier(id),
|
||||||
_scopeId(scope),
|
_scopeId(scope),
|
||||||
_isCreation(creation),
|
_isCreation(creation),
|
||||||
|
_type(type),
|
||||||
_hash(KnuthsHash(id.GetHash(), scope)) {}
|
_hash(KnuthsHash(id.GetHash(), scope)) {}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +48,10 @@ namespace Porygon::Binder {
|
||||||
inline uint64_t GetHash() const {
|
inline uint64_t GetHash() const {
|
||||||
return _hash;
|
return _hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline shared_ptr<const ScriptType> GetType() const{
|
||||||
|
return _type;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../EvalValues/EvalValue.hpp"
|
#include "../EvalValues/EvalValue.hpp"
|
||||||
#include "../EvalValuePointer.hpp"
|
#include "../EvalValuePointer.hpp"
|
||||||
|
#include "../../Binder/BoundVariables/BoundVariableKey.hpp"
|
||||||
|
|
||||||
using namespace Porygon::Binder;
|
using namespace Porygon::Binder;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef PORYGONLANG_SCRIPTTYPE_HPP
|
#ifndef PORYGONLANG_SCRIPTTYPE_HPP
|
||||||
#define PORYGONLANG_SCRIPTTYPE_HPP
|
#define PORYGONLANG_SCRIPTTYPE_HPP
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "../Binder/BoundVariables/BoundVariableKey.hpp"
|
|
||||||
#include "../Utilities/HashedString.hpp"
|
#include "../Utilities/HashedString.hpp"
|
||||||
#include "CastResult.hpp"
|
#include "CastResult.hpp"
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
#include "../src/ScriptTypes/ScriptType.hpp"
|
#include "../src/ScriptTypes/ScriptType.hpp"
|
||||||
#include "../src/Binder/BoundStatements/BoundStatement.hpp"
|
#include "../src/Binder/BoundStatements/BoundStatement.hpp"
|
||||||
#include "../src/Utilities/HashedString.hpp"
|
|
||||||
using namespace Porygon;
|
using namespace Porygon;
|
||||||
using namespace Porygon::Binder;
|
using namespace Porygon::Binder;
|
||||||
using namespace Porygon::Utilities;
|
using namespace Porygon::Utilities;
|
||||||
|
@ -44,7 +43,7 @@ TEST_CASE( "Expression Statement To String", "[BoundTreeString]" ) {
|
||||||
TEST_CASE( "Assignment Statement To String", "[BoundTreeString]" ) {
|
TEST_CASE( "Assignment Statement To String", "[BoundTreeString]" ) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
auto key = new u16string(u"key");
|
auto key = new u16string(u"key");
|
||||||
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true);
|
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true, ScriptType::NilType);
|
||||||
auto s = new BoundAssignmentStatement(keyObj, new BoundLiteralIntegerExpression(5, 0,0));
|
auto s = new BoundAssignmentStatement(keyObj, new BoundLiteralIntegerExpression(5, 0,0));
|
||||||
s->GetTreeString(stream, 1);
|
s->GetTreeString(stream, 1);
|
||||||
REQUIRE(stream.str() == "\tAssignment -> global key\n\t\tLiteralInteger: 5 (number)");
|
REQUIRE(stream.str() == "\tAssignment -> global key\n\t\tLiteralInteger: 5 (number)");
|
||||||
|
@ -94,7 +93,7 @@ TEST_CASE( "Conditional To String", "[BoundTreeString]" ) {
|
||||||
TEST_CASE( "Numerical For to String", "[BoundTreeString]" ) {
|
TEST_CASE( "Numerical For to String", "[BoundTreeString]" ) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
auto key = new u16string(u"i");
|
auto key = new u16string(u"i");
|
||||||
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true);
|
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true, NumericScriptType::AwareInt);
|
||||||
auto s = new BoundNumericalForStatement(keyObj, new BoundLiteralIntegerExpression(0,0,0),
|
auto s = new BoundNumericalForStatement(keyObj, new BoundLiteralIntegerExpression(0,0,0),
|
||||||
new BoundLiteralIntegerExpression(5,0,0),
|
new BoundLiteralIntegerExpression(5,0,0),
|
||||||
new BoundLiteralIntegerExpression(1,0,0),
|
new BoundLiteralIntegerExpression(1,0,0),
|
||||||
|
@ -116,15 +115,15 @@ TEST_CASE( "Numerical For to String", "[BoundTreeString]" ) {
|
||||||
TEST_CASE( "Generic For to String", "[BoundTreeString]" ) {
|
TEST_CASE( "Generic For to String", "[BoundTreeString]" ) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
auto key = new u16string(u"k");
|
auto key = new u16string(u"k");
|
||||||
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true);
|
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true, NumericScriptType::AwareInt);
|
||||||
auto valueKey = new u16string(u"v");
|
auto valueKey = new u16string(u"v");
|
||||||
const BoundVariableKey *valueKeyObj = new BoundVariableKey(HashedString(valueKey), 0, true);
|
const BoundVariableKey *valueKeyObj = new BoundVariableKey(HashedString(valueKey), 0, true, NumericScriptType::AwareInt);
|
||||||
auto s = new BoundGenericForStatement(keyObj, valueKeyObj, new BoundNilExpression(0,0), new BoundBadStatement());
|
auto s = new BoundGenericForStatement(keyObj, valueKeyObj, new BoundNilExpression(0,0), new BoundBadStatement());
|
||||||
s->GetTreeString(stream, 1);
|
s->GetTreeString(stream, 1);
|
||||||
REQUIRE(stream.str() ==
|
REQUIRE(stream.str() ==
|
||||||
R"( GenericForLoopStatement
|
R"( GenericForLoopStatement
|
||||||
Key: k
|
Key: k (number)
|
||||||
Value: v
|
Value: v (number)
|
||||||
Iterator:
|
Iterator:
|
||||||
NilExpression (nil)
|
NilExpression (nil)
|
||||||
Do:
|
Do:
|
||||||
|
@ -150,7 +149,7 @@ TEST_CASE( "Function Declaration To String", "[BoundTreeString]" ) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
auto t = make_shared<const GenericFunctionScriptType>();
|
auto t = make_shared<const GenericFunctionScriptType>();
|
||||||
auto key = new u16string(u"func");
|
auto key = new u16string(u"func");
|
||||||
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true);
|
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true, NumericScriptType::AwareInt);
|
||||||
auto s = new BoundFunctionDeclarationStatement(t, keyObj, new BoundBlockStatement({}));
|
auto s = new BoundFunctionDeclarationStatement(t, keyObj, new BoundBlockStatement({}));
|
||||||
s->GetTreeString(stream, 1);
|
s->GetTreeString(stream, 1);
|
||||||
REQUIRE(stream.str() ==
|
REQUIRE(stream.str() ==
|
||||||
|
@ -213,7 +212,7 @@ TEST_CASE( "Nil Expression To String", "[BoundTreeString]" ) {
|
||||||
TEST_CASE( "Variable Expression To String", "[BoundTreeString]" ) {
|
TEST_CASE( "Variable Expression To String", "[BoundTreeString]" ) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
auto type = ScriptType::BoolType;
|
auto type = ScriptType::BoolType;
|
||||||
auto key = new BoundVariableKey(HashedString(new u16string(u"var")), 0, false);
|
auto key = new BoundVariableKey(HashedString(new u16string(u"var")), 0, false, NumericScriptType::AwareInt);
|
||||||
auto s = new BoundVariableExpression(key, type,0,0);
|
auto s = new BoundVariableExpression(key, type,0,0);
|
||||||
s->GetTreeString(stream, 1);
|
s->GetTreeString(stream, 1);
|
||||||
REQUIRE(stream.str() == "\tVariableExpression: var (bool)");
|
REQUIRE(stream.str() == "\tVariableExpression: var (bool)");
|
||||||
|
|
Loading…
Reference in New Issue