make objectApply recursive

This commit is contained in:
Daniel Lupu 2022-04-30 18:15:39 +03:00 committed by r0qs
parent da28f9f315
commit 4a5c108dbd
No known key found for this signature in database
GPG Key ID: 61503DBA6667276C

View File

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