mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactor termination detection.
This commit is contained in:
@@ -72,3 +72,41 @@ void MovableChecker::visit(Statement const&)
|
||||
{
|
||||
assertThrow(false, OptimizerException, "Movability for statement requested.");
|
||||
}
|
||||
|
||||
pair<TerminationFinder::ControlFlow, size_t> TerminationFinder::firstUnconditionalControlFlowChange(
|
||||
vector<Statement> const& _statements
|
||||
)
|
||||
{
|
||||
for (size_t i = 0; i < _statements.size(); ++i)
|
||||
{
|
||||
ControlFlow controlFlow = controlFlowKind(_statements[i]);
|
||||
if (controlFlow != ControlFlow::FlowOut)
|
||||
return {controlFlow, i};
|
||||
}
|
||||
return {ControlFlow::FlowOut, size_t(-1)};
|
||||
}
|
||||
|
||||
TerminationFinder::ControlFlow TerminationFinder::controlFlowKind(Statement const& _statement)
|
||||
{
|
||||
if (
|
||||
_statement.type() == typeid(ExpressionStatement) &&
|
||||
isTerminatingBuiltin(boost::get<ExpressionStatement>(_statement))
|
||||
)
|
||||
return ControlFlow::Terminate;
|
||||
else if (_statement.type() == typeid(Break))
|
||||
return ControlFlow::Break;
|
||||
else if (_statement.type() == typeid(Continue))
|
||||
return ControlFlow::Continue;
|
||||
else
|
||||
return ControlFlow::FlowOut;
|
||||
}
|
||||
|
||||
bool TerminationFinder::isTerminatingBuiltin(ExpressionStatement const& _exprStmnt)
|
||||
{
|
||||
if (_exprStmnt.expression.type() != typeid(FunctionalInstruction))
|
||||
return false;
|
||||
|
||||
return eth::SemanticInformation::terminatesControlFlow(
|
||||
boost::get<FunctionalInstruction>(_exprStmnt.expression).instruction
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user