Make function grouper idempotent.

This commit is contained in:
chriseth 2019-01-08 15:03:40 +01:00
parent 6414d63906
commit f5b24a38b8
5 changed files with 59 additions and 7 deletions

View File

@ -33,6 +33,9 @@ using namespace dev::solidity;
void FunctionGrouper::operator()(Block& _block)
{
if (alreadyGrouped(_block))
return;
vector<Statement> reordered;
reordered.emplace_back(Block{_block.location, {}});
@ -45,3 +48,15 @@ void FunctionGrouper::operator()(Block& _block)
}
_block.statements = std::move(reordered);
}
bool FunctionGrouper::alreadyGrouped(Block const& _block)
{
if (_block.statements.empty())
return false;
if (_block.statements.front().type() != typeid(Block))
return false;
for (size_t i = 1; i < _block.statements.size(); ++i)
if (_block.statements.at(i).type() != typeid(FunctionDefinition))
return false;
return true;
}

View File

@ -38,6 +38,9 @@ class FunctionGrouper
{
public:
void operator()(Block& _block);
private:
bool alreadyGrouped(Block const& _block);
};
}

View File

@ -26,13 +26,11 @@
// fullInliner
// {
// {
// {
// let f_x := 100
// mstore(0, f_x)
// mstore(7, h())
// g(10)
// mstore(1, f_x)
// }
// let f_x := 100
// mstore(0, f_x)
// mstore(7, h())
// g(10)
// mstore(1, f_x)
// }
// function f(x)
// {

View File

@ -0,0 +1,17 @@
{
{
let x := 2
}
function f() -> y { y := 8 }
}
// ----
// functionGrouper
// {
// {
// let x := 2
// }
// function f() -> y
// {
// y := 8
// }
// }

View File

@ -0,0 +1,19 @@
{
function f() -> y { y := 8 }
{
let x := 2
}
}
// ----
// functionGrouper
// {
// {
// {
// let x := 2
// }
// }
// function f() -> y
// {
// y := 8
// }
// }