mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6780 from ethereum/moveInitialization
make_vector helper for move initialization
This commit is contained in:
commit
88e9fbe671
@ -346,4 +346,27 @@ inline std::string findAnyOf(std::string const& _haystack, std::vector<std::stri
|
|||||||
return needle;
|
return needle;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
void variadicEmplaceBack(std::vector<T>&) {}
|
||||||
|
template<typename T, typename A, typename... Args>
|
||||||
|
void variadicEmplaceBack(std::vector<T>& _vector, A&& _a, Args&&... _args)
|
||||||
|
{
|
||||||
|
_vector.emplace_back(std::forward<A>(_a));
|
||||||
|
variadicEmplaceBack(_vector, std::forward<Args>(_args)...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
std::vector<T> make_vector(Args&&... _args)
|
||||||
|
{
|
||||||
|
std::vector<T> result;
|
||||||
|
result.reserve(sizeof...(_args));
|
||||||
|
detail::variadicEmplaceBack(result, std::forward<Args>(_args)...);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -72,11 +72,7 @@ OptionalStatements reduceNoCaseSwitch(Switch& _switchStmt)
|
|||||||
|
|
||||||
auto loc = locationOf(*_switchStmt.expression);
|
auto loc = locationOf(*_switchStmt.expression);
|
||||||
|
|
||||||
OptionalStatements s = vector<Statement>{};
|
return make_vector<Statement>(makePopExpressionStatement(loc, std::move(*_switchStmt.expression)));
|
||||||
|
|
||||||
s->emplace_back(makePopExpressionStatement(loc, std::move(*_switchStmt.expression)));
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionalStatements reduceSingleCaseSwitch(Switch& _switchStmt)
|
OptionalStatements reduceSingleCaseSwitch(Switch& _switchStmt)
|
||||||
@ -86,9 +82,7 @@ OptionalStatements reduceSingleCaseSwitch(Switch& _switchStmt)
|
|||||||
auto& switchCase = _switchStmt.cases.front();
|
auto& switchCase = _switchStmt.cases.front();
|
||||||
auto loc = locationOf(*_switchStmt.expression);
|
auto loc = locationOf(*_switchStmt.expression);
|
||||||
if (switchCase.value)
|
if (switchCase.value)
|
||||||
{
|
return make_vector<Statement>(If{
|
||||||
OptionalStatements s = vector<Statement>{};
|
|
||||||
s->emplace_back(If{
|
|
||||||
std::move(_switchStmt.location),
|
std::move(_switchStmt.location),
|
||||||
make_unique<Expression>(FunctionalInstruction{
|
make_unique<Expression>(FunctionalInstruction{
|
||||||
std::move(loc),
|
std::move(loc),
|
||||||
@ -97,15 +91,11 @@ OptionalStatements reduceSingleCaseSwitch(Switch& _switchStmt)
|
|||||||
}),
|
}),
|
||||||
std::move(switchCase.body)
|
std::move(switchCase.body)
|
||||||
});
|
});
|
||||||
return s;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return make_vector<Statement>(
|
||||||
OptionalStatements s = vector<Statement>{};
|
makePopExpressionStatement(loc, std::move(*_switchStmt.expression)),
|
||||||
s->emplace_back(makePopExpressionStatement(loc, std::move(*_switchStmt.expression)));
|
std::move(switchCase.body)
|
||||||
s->emplace_back(std::move(switchCase.body));
|
);
|
||||||
return s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,20 +56,18 @@ void SSAReverser::operator()(Block& _block)
|
|||||||
identifier &&
|
identifier &&
|
||||||
identifier->name == varDecl->variables.front().name
|
identifier->name == varDecl->variables.front().name
|
||||||
)
|
)
|
||||||
{
|
return make_vector<Statement>(
|
||||||
vector<Statement> result;
|
Assignment{
|
||||||
result.emplace_back(Assignment{
|
|
||||||
std::move(assignment->location),
|
std::move(assignment->location),
|
||||||
assignment->variableNames,
|
assignment->variableNames,
|
||||||
std::move(varDecl->value)
|
std::move(varDecl->value)
|
||||||
});
|
},
|
||||||
result.emplace_back(VariableDeclaration{
|
VariableDeclaration{
|
||||||
std::move(varDecl->location),
|
std::move(varDecl->location),
|
||||||
std::move(varDecl->variables),
|
std::move(varDecl->variables),
|
||||||
std::make_unique<Expression>(std::move(assignment->variableNames.front()))
|
std::make_unique<Expression>(std::move(assignment->variableNames.front()))
|
||||||
});
|
|
||||||
return { std::move(result) };
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// Replaces
|
// Replaces
|
||||||
// let a_1 := E
|
// let a_1 := E
|
||||||
@ -89,22 +87,22 @@ void SSAReverser::operator()(Block& _block)
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
vector<Statement> result;
|
|
||||||
auto varIdentifier2 = std::make_unique<Expression>(Identifier{
|
auto varIdentifier2 = std::make_unique<Expression>(Identifier{
|
||||||
varDecl2->variables.front().location,
|
varDecl2->variables.front().location,
|
||||||
varDecl2->variables.front().name
|
varDecl2->variables.front().name
|
||||||
});
|
});
|
||||||
result.emplace_back(VariableDeclaration{
|
return make_vector<Statement>(
|
||||||
|
VariableDeclaration{
|
||||||
std::move(varDecl2->location),
|
std::move(varDecl2->location),
|
||||||
std::move(varDecl2->variables),
|
std::move(varDecl2->variables),
|
||||||
std::move(varDecl->value)
|
std::move(varDecl->value)
|
||||||
});
|
},
|
||||||
result.emplace_back(VariableDeclaration{
|
VariableDeclaration{
|
||||||
std::move(varDecl->location),
|
std::move(varDecl->location),
|
||||||
std::move(varDecl->variables),
|
std::move(varDecl->variables),
|
||||||
std::move(varIdentifier2)
|
std::move(varIdentifier2)
|
||||||
});
|
}
|
||||||
return { std::move(result) };
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,12 +51,10 @@ OptionalStatements replaceConstArgSwitch(Switch& _switchStmt, u256 const& _const
|
|||||||
if (!matchingCaseBlock && defaultCase)
|
if (!matchingCaseBlock && defaultCase)
|
||||||
matchingCaseBlock = &defaultCase->body;
|
matchingCaseBlock = &defaultCase->body;
|
||||||
|
|
||||||
OptionalStatements s = vector<Statement>{};
|
|
||||||
|
|
||||||
if (matchingCaseBlock)
|
if (matchingCaseBlock)
|
||||||
s->emplace_back(std::move(*matchingCaseBlock));
|
return make_vector<Statement>(std::move(*matchingCaseBlock));
|
||||||
|
else
|
||||||
return s;
|
return {{}};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user