Merge pull request #12793 from ethereum/hasDefaultHelper

Add helper to see if a switch has a default case.
This commit is contained in:
chriseth 2022-03-15 15:20:53 +01:00 committed by GitHub
commit d946b6b3a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 9 deletions

View File

@ -457,8 +457,7 @@ void ControlFlowBuilder::operator()(yul::Switch const& _switch)
}
mergeFlow(nodes);
bool hasDefault = util::contains_if(_switch.cases, [](yul::Case const& _case) { return !_case.value; });
if (!hasDefault)
if (!hasDefaultCase(_switch))
connect(beforeSwitch, m_currentNode);
}

View File

@ -144,4 +144,13 @@ template <class... Args> inline std::shared_ptr<DebugData const> debugDataOf(std
return std::visit([](auto const& _arg) { return debugDataOf(_arg); }, _node);
}
inline bool hasDefaultCase(Switch const& _switch)
{
return std::any_of(
_switch.cases.begin(),
_switch.cases.end(),
[](Case const& _case) { return !_case.value; }
);
}
}

View File

@ -60,13 +60,7 @@ void removeEmptyDefaultFromSwitch(Switch& _switchStmt)
void removeEmptyCasesFromSwitch(Switch& _switchStmt)
{
bool hasDefault = std::any_of(
_switchStmt.cases.begin(),
_switchStmt.cases.end(),
[](Case const& _case) { return !_case.value; }
);
if (hasDefault)
if (hasDefaultCase(_switchStmt))
return;
ranges::actions::remove_if(