35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
|
|
#include "EvaluationScope.hpp"
|
|
#include <memory>
|
|
|
|
EvaluationScope::EvaluationScope(unordered_map<size_t, shared_ptr<EvalValue>> *scriptVariables, int deepestScope) {
|
|
_scriptScope = scriptVariables;
|
|
_localScope = unordered_map<uint64_t, shared_ptr<EvalValue>>(deepestScope);
|
|
}
|
|
|
|
void EvaluationScope::CreateVariable(BoundVariableKey* key, const shared_ptr<EvalValue> &value) {
|
|
if (key->GetScopeId() == 0){
|
|
_scriptScope -> at(key->GetIdentifier()) = value;
|
|
} else{
|
|
auto insert = _localScope.insert({key->GetHash(), value});
|
|
if (!insert.second){
|
|
_localScope[key->GetHash()] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
void EvaluationScope::SetVariable(BoundVariableKey* key, const shared_ptr<EvalValue> &value) {
|
|
if (key->GetScopeId() == 0){
|
|
_scriptScope -> at(key->GetIdentifier()) = value;
|
|
} else{
|
|
_localScope[key->GetHash()] = value;
|
|
}
|
|
}
|
|
|
|
shared_ptr<EvalValue> EvaluationScope::GetVariable(BoundVariableKey* key) {
|
|
if (key->GetScopeId() == 0){
|
|
return _scriptScope -> at(key->GetIdentifier());
|
|
} else{
|
|
return _localScope[key->GetHash()];
|
|
}
|
|
} |