Clean up EvaluationScope class
This commit is contained in:
parent
bda561b775
commit
257eb942c7
|
@ -1,2 +1,31 @@
|
||||||
|
|
||||||
#include "EvaluationScope.hpp"
|
#include "EvaluationScope.hpp"
|
||||||
|
|
||||||
|
EvaluationScope::EvaluationScope(unordered_map<int, EvalValue *> *scriptVariables, int deepestScope) {
|
||||||
|
_scriptScope = scriptVariables;
|
||||||
|
_localScope = vector<unordered_map<int, EvalValue*>>(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];
|
||||||
|
}
|
||||||
|
|
|
@ -10,34 +10,12 @@ class EvaluationScope {
|
||||||
unordered_map<int, EvalValue*>* _scriptScope;
|
unordered_map<int, EvalValue*>* _scriptScope;
|
||||||
vector<unordered_map<int, EvalValue*>> _localScope;
|
vector<unordered_map<int, EvalValue*>> _localScope;
|
||||||
public:
|
public:
|
||||||
explicit EvaluationScope(unordered_map<int, EvalValue*>* scriptVariables, int deepestScope){
|
explicit EvaluationScope(unordered_map<int, EvalValue*>* scriptVariables, int deepestScope);
|
||||||
_scriptScope = scriptVariables;
|
~EvaluationScope();
|
||||||
_localScope = vector<unordered_map<int, EvalValue*>>(deepestScope);
|
|
||||||
}
|
|
||||||
|
|
||||||
~EvaluationScope(){
|
void CreateVariable(int scope, int id, EvalValue* value);
|
||||||
_localScope.clear();
|
void SetVariable(int scope, int id, EvalValue* value);
|
||||||
}
|
EvalValue* GetVariable(int scope, int id);
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue