PorygonLang/src/Evaluator/EvalValues/TableEvalValue.cpp

34 lines
1.2 KiB
C++
Raw Normal View History

2019-06-26 14:19:34 +00:00
#include "TableEvalValue.hpp"
#include "../Iterator/SimpleKeyIterator.hpp"
2019-09-12 16:19:06 +00:00
#include "NumericEvalValue.hpp"
2019-09-15 11:08:11 +00:00
#include "../Iterator/NumericalKeyIterator.hpp"
2019-06-26 14:19:34 +00:00
2019-09-15 11:08:11 +00:00
Porygon::Evaluation::Iterator * Porygon::Evaluation::TableEvalValue::GetKeyIterator() const {
2019-06-26 14:19:34 +00:00
return new TableKeyIterator(this);
}
2019-09-12 16:19:06 +00:00
Porygon::Evaluation::EvalValue *
Porygon::Evaluation::TableEvalValue::UnaryOperation(Porygon::Binder::BoundUnaryOperation operation) const {
if (operation == Porygon::Binder::BoundUnaryOperation::Count){
return new NumericEvalValue(static_cast<int64_t>(this->_table->size()));
}
return EvalValue::UnaryOperation(operation);
}
2019-09-15 11:08:11 +00:00
void Porygon::Evaluation::TableEvalValue::SetIndexValue(const Porygon::Utilities::HashedString *key,
const Porygon::Evaluation::EvalValue *value) const {
auto insert = _table->insert({*key, value});
if (!insert.second) {
_table->at(*key).ClearAssign(value);
}
}
Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericTableEvalValue::GetKeyIterator() const {
return new NumericalKeyIterator(this);
}
Porygon::Evaluation::EvalValue *Porygon::Evaluation::NumericTableEvalValue::Clone() const {
return new NumericTableEvalValue(_table, _hash);
}