Rework of memory handling in Evaluation
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2019-07-27 17:59:42 +02:00
parent 268f6b59fb
commit ccc6e297f2
32 changed files with 496 additions and 461 deletions

View File

@@ -24,13 +24,13 @@ Porygon::Script *Porygon::Script::Create(const string &script) {
Porygon::Script::Script(const u16string& s)
: Diagnostics(make_shared<Diagnostics::DiagnosticsHolder>(s)),
_boundScript(nullptr),
_scriptVariables(new map<Utilities::HashedString, shared_ptr<const EvalValue>>())
_scriptVariables(new map<Utilities::HashedString, EvalValuePointer>())
{
_evaluator = new Evaluator(this -> _scriptVariables);
this -> Parse(s);
}
shared_ptr<const EvalValue> Porygon::Script::Evaluate() {
EvalValuePointer Porygon::Script::Evaluate() {
return _evaluator->Evaluate(_boundScript.get());
}
@@ -62,8 +62,8 @@ void Porygon::Script::Parse(const u16string& script) {
delete parseResult;
}
const EvalValue *Porygon::Script::GetVariable(const u16string &key) {
return _scriptVariables -> at(HashedString::CreateLookup(key)).get();
const EvalValue* Porygon::Script::GetVariable(const u16string &key) {
return _scriptVariables -> at(HashedString::CreateLookup(key)).Clone();
}
bool Porygon::Script::HasVariable(const u16string &key) {
@@ -80,7 +80,7 @@ bool Porygon::Script::HasFunction(const u16string &key) {
return f != _scriptVariables->end() && f.operator->()->second->GetTypeClass() == TypeClass ::Function;
}
shared_ptr<const EvalValue> Porygon::Script::CallFunction(const u16string &key, const vector<EvalValue *>& variables) {
const EvalValue* Porygon::Script::CallFunction(const u16string &key, const vector<EvalValue *>& variables) {
auto var = (GenericFunctionEvalValue*)GetVariable(key);
return this->_evaluator->EvaluateFunction(var, variables);
}
@@ -98,7 +98,7 @@ Porygon::Script::Script(shared_ptr<BoundScriptStatement> boundScript,
shared_ptr<Porygon::Diagnostics::DiagnosticsHolder> diagnostics)
: _boundScript(std::move(boundScript)),
Diagnostics(std::move(diagnostics)),
_scriptVariables(new map<Utilities::HashedString, shared_ptr<const EvalValue>>())
_scriptVariables(new map<Utilities::HashedString, EvalValuePointer>())
{
_evaluator = new Evaluator(_scriptVariables);
}
@@ -111,8 +111,7 @@ extern "C" {
const EvalValue* EvaluateScript(Porygon::Script* script){
auto result = script -> Evaluate();
auto resultPtr = result.get();
return resultPtr;
return result.Clone();
}
bool HasVariable(Porygon::Script* script, const char16_t* key){
@@ -129,6 +128,6 @@ extern "C" {
const EvalValue* CallFunction(Porygon::Script* script, const char16_t* key, EvalValue* parameters[], int parameterCount){
std::vector<EvalValue*> v(parameters, parameters + parameterCount);
return script->CallFunction(key, v).get();
return script->CallFunction(key, v);
}
}