mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Inline functions returning nothing.
This commit is contained in:
parent
5cd84a630c
commit
4370bf5c40
@ -119,7 +119,7 @@ void InlineModifier::visit(Expression& _expression)
|
|||||||
// TODO: Insert good heuristic here. Perhaps implement that inside the driver.
|
// TODO: Insert good heuristic here. Perhaps implement that inside the driver.
|
||||||
bool doInline = funCall.functionName.name != m_currentFunction;
|
bool doInline = funCall.functionName.name != m_currentFunction;
|
||||||
|
|
||||||
if (fun.returnVariables.size() != 1)
|
if (fun.returnVariables.size() > 1)
|
||||||
doInline = false;
|
doInline = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -137,18 +137,23 @@ void InlineModifier::visit(Expression& _expression)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
map<string, string> variableReplacements;
|
map<string, string> variableReplacements;
|
||||||
string returnVariable = fun.returnVariables[0].name;
|
|
||||||
for (size_t i = 0; i < funCall.arguments.size(); ++i)
|
for (size_t i = 0; i < funCall.arguments.size(); ++i)
|
||||||
variableReplacements[fun.parameters[i].name] = boost::get<Identifier>(funCall.arguments[i]).name;
|
variableReplacements[fun.parameters[i].name] = boost::get<Identifier>(funCall.arguments[i]).name;
|
||||||
variableReplacements[returnVariable] = newName(fun.name + "_" + returnVariable);
|
if (fun.returnVariables.empty())
|
||||||
|
_expression = noop(funCall.location);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string returnVariable = fun.returnVariables[0].name;
|
||||||
|
variableReplacements[returnVariable] = newName(fun.name + "_" + returnVariable);
|
||||||
|
|
||||||
m_statementsToPrefix.emplace_back(VariableDeclaration{
|
m_statementsToPrefix.emplace_back(VariableDeclaration{
|
||||||
funCall.location,
|
funCall.location,
|
||||||
{{funCall.location, variableReplacements[returnVariable], fun.returnVariables[0].type}},
|
{{funCall.location, variableReplacements[returnVariable], fun.returnVariables[0].type}},
|
||||||
{}
|
{}
|
||||||
});
|
});
|
||||||
|
_expression = Identifier{funCall.location, variableReplacements[returnVariable]};
|
||||||
|
}
|
||||||
m_statementsToPrefix.emplace_back(BodyCopier(m_nameDispenser, fun.name + "_", variableReplacements)(fun.body));
|
m_statementsToPrefix.emplace_back(BodyCopier(m_nameDispenser, fun.name + "_", variableReplacements)(fun.body));
|
||||||
_expression = Identifier{funCall.location, variableReplacements[returnVariable]};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InlineModifier::visitArguments(
|
void InlineModifier::visitArguments(
|
||||||
@ -202,6 +207,13 @@ string InlineModifier::newName(string const& _prefix)
|
|||||||
return m_nameDispenser.newName(_prefix);
|
return m_nameDispenser.newName(_prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Expression InlineModifier::noop(SourceLocation const& _location)
|
||||||
|
{
|
||||||
|
return FunctionalInstruction{_location, solidity::Instruction::POP, {
|
||||||
|
Literal{_location, assembly::LiteralKind::Number, "0", ""}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
Statement BodyCopier::operator()(VariableDeclaration const& _varDecl)
|
Statement BodyCopier::operator()(VariableDeclaration const& _varDecl)
|
||||||
{
|
{
|
||||||
for (auto const& var: _varDecl.variables)
|
for (auto const& var: _varDecl.variables)
|
||||||
|
@ -137,6 +137,9 @@ private:
|
|||||||
|
|
||||||
std::string newName(std::string const& _prefix);
|
std::string newName(std::string const& _prefix);
|
||||||
|
|
||||||
|
/// @returns an expression returning nothing.
|
||||||
|
Expression noop(SourceLocation const& _location);
|
||||||
|
|
||||||
/// List of statements that should go in front of the currently visited AST element,
|
/// List of statements that should go in front of the currently visited AST element,
|
||||||
/// at the statement level.
|
/// at the statement level.
|
||||||
std::vector<Statement> m_statementsToPrefix;
|
std::vector<Statement> m_statementsToPrefix;
|
||||||
|
Loading…
Reference in New Issue
Block a user