Skip to content

Commit

Permalink
Rename formatting function.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Sep 16, 2021
1 parent 6399338 commit dafa6f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
32 changes: 16 additions & 16 deletions libyul/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using namespace solidity::yul;

string AsmPrinter::operator()(Literal const& _literal)
{
string const locationComment = formatSourceLocationComment(_literal);
string const locationComment = formatDebugData(_literal);

switch (_literal.kind)
{
Expand All @@ -65,19 +65,19 @@ string AsmPrinter::operator()(Literal const& _literal)
string AsmPrinter::operator()(Identifier const& _identifier)
{
yulAssert(!_identifier.name.empty(), "Invalid identifier.");
return formatSourceLocationComment(_identifier) + _identifier.name.str();
return formatDebugData(_identifier) + _identifier.name.str();
}

string AsmPrinter::operator()(ExpressionStatement const& _statement)
{
string const locationComment = formatSourceLocationComment(_statement);
string const locationComment = formatDebugData(_statement);

return locationComment + std::visit(*this, _statement.expression);
}

string AsmPrinter::operator()(Assignment const& _assignment)
{
string const locationComment = formatSourceLocationComment(_assignment);
string const locationComment = formatDebugData(_assignment);

yulAssert(_assignment.variableNames.size() >= 1, "");
string variables = (*this)(_assignment.variableNames.front());
Expand All @@ -89,7 +89,7 @@ string AsmPrinter::operator()(Assignment const& _assignment)

string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration)
{
string out = formatSourceLocationComment(_variableDeclaration);
string out = formatDebugData(_variableDeclaration);

out += "let ";
out += boost::algorithm::join(
Expand All @@ -110,7 +110,7 @@ string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition)
{
yulAssert(!_functionDefinition.name.empty(), "Invalid function name.");

string out = formatSourceLocationComment(_functionDefinition);
string out = formatDebugData(_functionDefinition);
out += "function " + _functionDefinition.name.str() + "(";
out += boost::algorithm::join(
_functionDefinition.parameters | ranges::views::transform(
Expand All @@ -135,7 +135,7 @@ string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition)

string AsmPrinter::operator()(FunctionCall const& _functionCall)
{
string const locationComment = formatSourceLocationComment(_functionCall);
string const locationComment = formatDebugData(_functionCall);
string const functionName = (*this)(_functionCall.functionName);
return
locationComment +
Expand All @@ -150,7 +150,7 @@ string AsmPrinter::operator()(If const& _if)
{
yulAssert(_if.condition, "Invalid if condition.");

string out = formatSourceLocationComment(_if);
string out = formatDebugData(_if);
out += "if " + std::visit(*this, *_if.condition);

string body = (*this)(_if.body);
Expand All @@ -165,7 +165,7 @@ string AsmPrinter::operator()(Switch const& _switch)
{
yulAssert(_switch.expression, "Invalid expression pointer.");

string out = formatSourceLocationComment(_switch);
string out = formatDebugData(_switch);
out += "switch " + std::visit(*this, *_switch.expression);

for (auto const& _case: _switch.cases)
Expand All @@ -182,7 +182,7 @@ string AsmPrinter::operator()(Switch const& _switch)
string AsmPrinter::operator()(ForLoop const& _forLoop)
{
yulAssert(_forLoop.condition, "Invalid for loop condition.");
string const locationComment = formatSourceLocationComment(_forLoop);
string const locationComment = formatDebugData(_forLoop);

string pre = (*this)(_forLoop.pre);
string condition = std::visit(*this, *_forLoop.condition);
Expand All @@ -203,23 +203,23 @@ string AsmPrinter::operator()(ForLoop const& _forLoop)

string AsmPrinter::operator()(Break const& _break)
{
return formatSourceLocationComment(_break) + "break";
return formatDebugData(_break) + "break";
}

string AsmPrinter::operator()(Continue const& _continue)
{
return formatSourceLocationComment(_continue) + "continue";
return formatDebugData(_continue) + "continue";
}

// '_leave' and '__leave' is reserved in VisualStudio
string AsmPrinter::operator()(Leave const& leave_)
{
return formatSourceLocationComment(leave_) + "leave";
return formatDebugData(leave_) + "leave";
}

string AsmPrinter::operator()(Block const& _block)
{
string const locationComment = formatSourceLocationComment(_block);
string const locationComment = formatDebugData(_block);

if (_block.statements.empty())
return locationComment + "{ }";
Expand All @@ -239,7 +239,7 @@ string AsmPrinter::operator()(Block const& _block)
string AsmPrinter::formatTypedName(TypedName _variable)
{
yulAssert(!_variable.name.empty(), "Invalid variable name.");
return formatSourceLocationComment(_variable) + _variable.name.str() + appendTypeName(_variable.type);
return formatDebugData(_variable) + _variable.name.str() + appendTypeName(_variable.type);
}

string AsmPrinter::appendTypeName(YulString _type, bool _isBoolLiteral) const
Expand Down Expand Up @@ -300,7 +300,7 @@ string AsmPrinter::formatSourceLocationComment(
"/** " + joinHumanReadable(vector<string>{sourceLocation, solidityCodeSnippet}, " ") + " */ ";
}

string AsmPrinter::formatSourceLocationComment(shared_ptr<DebugData const> const& _debugData, bool _statement)
string AsmPrinter::formatDebugData(shared_ptr<DebugData const> const& _debugData, bool _statement)
{
if (
!_debugData ||
Expand Down
6 changes: 3 additions & 3 deletions libyul/AsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ class AsmPrinter
private:
std::string formatTypedName(TypedName _variable);
std::string appendTypeName(YulString _type, bool _isBoolLiteral = false) const;
std::string formatSourceLocationComment(std::shared_ptr<DebugData const> const& _debugData, bool _statement);
std::string formatDebugData(std::shared_ptr<DebugData const> const& _debugData, bool _statement);
template <class T>
std::string formatSourceLocationComment(T const& _node)
std::string formatDebugData(T const& _node)
{
bool isExpression = std::is_constructible<Expression, T>::value;
return formatSourceLocationComment(_node.debugData, !isExpression);
return formatDebugData(_node.debugData, !isExpression);
}

Dialect const* const m_dialect = nullptr;
Expand Down

0 comments on commit dafa6f5

Please sign in to comment.