Initial work on iterators, rework of variable handling by including actual string
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2019-06-23 15:58:14 +02:00
parent 1a84661c79
commit 76b8ba3ebc
25 changed files with 185 additions and 78 deletions

View File

@@ -24,7 +24,7 @@ namespace Porygon::Evaluation {
}
const char16_t *EvaluateEvalValueString(EvalValue *v) {
return v->EvaluateString()->c_str();
return (new u16string(v->EvaluateString()))->c_str();
}

View File

@@ -37,7 +37,7 @@ namespace Porygon::Evaluation {
throw EvaluationException("Can't evaluate this EvalValue as bool.");
}
virtual const std::u16string *EvaluateString() const {
virtual const std::u16string EvaluateString() const {
throw EvaluationException("Can't evaluate this EvalValue as string.");
}

View File

@@ -4,6 +4,8 @@
#include <sstream>
#include "EvalValue.hpp"
#include "../../Utilities/StringUtils.hpp"
namespace Porygon::Evaluation {
class NumericEvalValue : public EvalValue {
@@ -58,6 +60,10 @@ namespace Porygon::Evaluation {
return _value;
}
const std::u16string EvaluateString() const final{
return Utilities::StringUtils::IntToString(_value);
}
const shared_ptr<EvalValue> Clone() const final {
return make_shared<IntegerEvalValue>(_value);
}

View File

@@ -28,8 +28,8 @@ namespace Porygon::Evaluation {
return this->_hash == b->GetHashCode();
};
const u16string *EvaluateString() const final {
return &_value;
const u16string EvaluateString() const final {
return _value;
}
const shared_ptr<EvalValue> Clone() const final {

View File

@@ -1,23 +1,23 @@
#ifndef PORYGONLANG_TABLEEVALVALUE_HPP
#define PORYGONLANG_TABLEEVALVALUE_HPP
#include <utility>
#include <unordered_map>
#include <map>
#include "EvalValue.hpp"
using namespace std;
namespace Porygon::Evaluation {
class TableEvalValue : public EvalValue {
shared_ptr<unordered_map<uint32_t, shared_ptr<EvalValue>>> _table;
shared_ptr<map<Utilities::HashedString, shared_ptr<EvalValue>>> _table;
size_t _hash;
explicit TableEvalValue(shared_ptr<unordered_map<uint32_t, shared_ptr<EvalValue>>> table, size_t hash) {
explicit TableEvalValue(shared_ptr<map<Utilities::HashedString, shared_ptr<EvalValue>>> table, size_t hash) {
_table = std::move(table);
_hash = hash;
}
public:
explicit TableEvalValue(shared_ptr<unordered_map<uint32_t, shared_ptr<EvalValue>>> table) {
explicit TableEvalValue(shared_ptr<map<Utilities::HashedString, shared_ptr<EvalValue>>> table) {
_table = std::move(table);
_hash = rand();
}
@@ -39,23 +39,30 @@ namespace Porygon::Evaluation {
}
const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final {
auto hash = val->GetHashCode();
return this->_table->at(hash);
const auto stringKey = val->EvaluateString();
return this->_table->at(Utilities::HashedString(stringKey));
}
const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final {
return this->_table->at(hash);
return this->_table->at(Utilities::HashedString(hash));
}
const shared_ptr<EvalValue> IndexValue(const char *val) const {
auto hash = Utilities::HashedString::ConstHash(val);
return this->_table->at(hash);
return this->_table->at(Utilities::HashedString(hash));
}
void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const final {
auto hash = key->GetHashCode();
this->_table->at(hash) = value;
this->_table->at(Utilities::HashedString(hash)) = value;
}
const _Rb_tree_const_iterator<pair<const Utilities::HashedString, shared_ptr<EvalValue>>> GetTableIterator() const{
return _table->cbegin();
};
const _Rb_tree_const_iterator<pair<const Utilities::HashedString, shared_ptr<EvalValue>>> GetTableIteratorEnd() const{
return _table->cend();
};
};
}