From 257eb942c7a7f1bc2b7a50da6f2af5ddacc8ac79 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 29 May 2019 15:12:13 +0200 Subject: [PATCH] Clean up EvaluationScope class --- .../EvaluationScope/EvaluationScope.cpp | 29 +++++++++++++++++ .../EvaluationScope/EvaluationScope.hpp | 32 +++---------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/Evaluator/EvaluationScope/EvaluationScope.cpp b/src/Evaluator/EvaluationScope/EvaluationScope.cpp index 4961418..1d86772 100644 --- a/src/Evaluator/EvaluationScope/EvaluationScope.cpp +++ b/src/Evaluator/EvaluationScope/EvaluationScope.cpp @@ -1,2 +1,31 @@ #include "EvaluationScope.hpp" + +EvaluationScope::EvaluationScope(unordered_map *scriptVariables, int deepestScope) { + _scriptScope = scriptVariables; + _localScope = vector>(deepestScope); +} + +EvaluationScope::~EvaluationScope() { + _localScope.clear(); +} + +void EvaluationScope::CreateVariable(int scope, int id, EvalValue *value) { + if (scope == 0){ + _scriptScope->insert_or_assign(id, value); + } else{ + _localScope[scope - 1].insert({id, value}); + } +} + +void EvaluationScope::SetVariable(int scope, int id, EvalValue *value) { + if (scope == 0){ + _scriptScope->insert_or_assign(id, value); + } else{ + _localScope[scope - 1][id] = value; + } +} + +EvalValue *EvaluationScope::GetVariable(int scope, int id) { + return _localScope[scope - 1][id]; +} diff --git a/src/Evaluator/EvaluationScope/EvaluationScope.hpp b/src/Evaluator/EvaluationScope/EvaluationScope.hpp index 273ee6f..9b0f69c 100644 --- a/src/Evaluator/EvaluationScope/EvaluationScope.hpp +++ b/src/Evaluator/EvaluationScope/EvaluationScope.hpp @@ -10,34 +10,12 @@ class EvaluationScope { unordered_map* _scriptScope; vector> _localScope; public: - explicit EvaluationScope(unordered_map* scriptVariables, int deepestScope){ - _scriptScope = scriptVariables; - _localScope = vector>(deepestScope); - } + explicit EvaluationScope(unordered_map* scriptVariables, int deepestScope); + ~EvaluationScope(); - ~EvaluationScope(){ - _localScope.clear(); - } - - void CreateVariable(int scope, int id, EvalValue* value){ - if (scope == 0){ - _scriptScope->insert_or_assign(id, value); - } else{ - _localScope[scope - 1].insert({id, value}); - } - } - - void SetVariable(int scope, int id, EvalValue* value){ - if (scope == 0){ - _scriptScope->insert_or_assign(id, value); - } else{ - _localScope[scope - 1][id] = value; - } - } - - EvalValue* GetVariable(int scope, int id){ - return _localScope[scope - 1][id]; - } + void CreateVariable(int scope, int id, EvalValue* value); + void SetVariable(int scope, int id, EvalValue* value); + EvalValue* GetVariable(int scope, int id); };