Rework evaluation to use shared pointers, fix bugs
This commit is contained in:
@@ -1,25 +1,22 @@
|
||||
|
||||
#include "EvaluationScope.hpp"
|
||||
#include <memory>
|
||||
|
||||
EvaluationScope::EvaluationScope(unordered_map<int, EvalValue *> *scriptVariables, int deepestScope) {
|
||||
EvaluationScope::EvaluationScope(unordered_map<int, shared_ptr<EvalValue>> *scriptVariables, int deepestScope) {
|
||||
_scriptScope = scriptVariables;
|
||||
_localScope = vector<unordered_map<int, EvalValue*>>(deepestScope);
|
||||
_localScope = vector<unordered_map<int, shared_ptr<EvalValue>>>(deepestScope);
|
||||
_currentScope = -1;
|
||||
}
|
||||
|
||||
EvaluationScope::~EvaluationScope() {
|
||||
_localScope.clear();
|
||||
}
|
||||
|
||||
void EvaluationScope::CreateVariable(int scope, int id, EvalValue *value) {
|
||||
void EvaluationScope::CreateVariable(int scope, int id, shared_ptr<EvalValue> value) {
|
||||
if (scope == 0){
|
||||
_scriptScope->insert_or_assign(id, value);
|
||||
} else{
|
||||
_localScope[scope - 1].insert({id, value});
|
||||
_localScope[scope - 1].insert_or_assign(id, value);
|
||||
}
|
||||
}
|
||||
|
||||
void EvaluationScope::SetVariable(int scope, int id, EvalValue *value) {
|
||||
void EvaluationScope::SetVariable(int scope, int id, shared_ptr<EvalValue> value) {
|
||||
if (scope == 0){
|
||||
_scriptScope->insert_or_assign(id, value);
|
||||
} else{
|
||||
@@ -27,7 +24,7 @@ void EvaluationScope::SetVariable(int scope, int id, EvalValue *value) {
|
||||
}
|
||||
}
|
||||
|
||||
EvalValue *EvaluationScope::GetVariable(int scope, int id) {
|
||||
shared_ptr<EvalValue> EvaluationScope::GetVariable(int scope, int id) {
|
||||
if (scope == 0){
|
||||
return _scriptScope->at(id);
|
||||
}
|
||||
@@ -40,9 +37,7 @@ void EvaluationScope::OuterScope() {
|
||||
|
||||
void EvaluationScope::InnerScope() {
|
||||
auto scope = this->_localScope[_currentScope];
|
||||
for (auto v: scope){
|
||||
delete v.second;
|
||||
}
|
||||
scope.clear();
|
||||
_currentScope--;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user