diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index d36d03701..61c2541fc 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -208,29 +208,21 @@ public: } } - void objectApply(function _fn) + void objectApply(shared_ptr _object, function _fn) { - vector> stack; - stack.push_back(m_object); + for (auto const& subObjectNode: _object->subObjects) { + auto subObject = dynamic_pointer_cast(subObjectNode); - while (!stack.empty()) { - auto object = stack.back(); - stack.pop_back(); - - for (auto const& subObjectNode: object->subObjects) { - auto subObject = dynamic_pointer_cast(subObjectNode); - - if (subObject != nullptr) - stack.push_back(subObject); - } - - _fn(*object); + if (subObject != nullptr) + objectApply(subObject, _fn); } + + _fn(*_object); } void analyze(ErrorReporter& errorReporter) { - objectApply([&](Object& object) -> void { + objectApply(m_object, [&](Object& object) { object.analysisInfo = make_shared(); AsmAnalyzer analyzer( @@ -248,7 +240,7 @@ public: void disambiguate() { - objectApply([&](Object& object) -> void { + objectApply(m_object, [&](Object& object) { object.code = make_shared( std::get(Disambiguator(m_dialect, *object.analysisInfo)(*object.code)) ); @@ -259,21 +251,21 @@ public: void runSequence(string_view _steps) { - objectApply([&](Object& object) -> void { + objectApply(m_object, [&](Object& object) { OptimiserSuite{*m_context}.runSequence(_steps, *object.code); }); } void runVarNameCleaner() { - objectApply([&](Object& object) -> void { + objectApply(m_object, [&](Object& object) { VarNameCleaner::run(*m_context, *object.code); }); } void runStackCompressor() { - objectApply([&](Object& object) -> void { + objectApply(m_object, [&](Object& object) { StackCompressor::run(m_dialect, object, true, 16); }); }