mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
AsmPrinter functions should be const.
This commit is contained in:
parent
642c69f935
commit
6101258248
@ -40,14 +40,14 @@ using namespace dev::solidity;
|
|||||||
|
|
||||||
//@TODO source locations
|
//@TODO source locations
|
||||||
|
|
||||||
string AsmPrinter::operator()(yul::Instruction const& _instruction)
|
string AsmPrinter::operator()(yul::Instruction const& _instruction) const
|
||||||
{
|
{
|
||||||
solAssert(!m_yul, "");
|
solAssert(!m_yul, "");
|
||||||
solAssert(isValidInstruction(_instruction.instruction), "Invalid instruction");
|
solAssert(isValidInstruction(_instruction.instruction), "Invalid instruction");
|
||||||
return boost::to_lower_copy(instructionInfo(_instruction.instruction).name);
|
return boost::to_lower_copy(instructionInfo(_instruction.instruction).name);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(Literal const& _literal)
|
string AsmPrinter::operator()(Literal const& _literal) const
|
||||||
{
|
{
|
||||||
switch (_literal.kind)
|
switch (_literal.kind)
|
||||||
{
|
{
|
||||||
@ -90,13 +90,13 @@ string AsmPrinter::operator()(Literal const& _literal)
|
|||||||
return "\"" + out + "\"" + appendTypeName(_literal.type);
|
return "\"" + out + "\"" + appendTypeName(_literal.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(Identifier const& _identifier)
|
string AsmPrinter::operator()(Identifier const& _identifier) const
|
||||||
{
|
{
|
||||||
solAssert(!_identifier.name.empty(), "Invalid identifier.");
|
solAssert(!_identifier.name.empty(), "Invalid identifier.");
|
||||||
return _identifier.name.str();
|
return _identifier.name.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(FunctionalInstruction const& _functionalInstruction)
|
string AsmPrinter::operator()(FunctionalInstruction const& _functionalInstruction) const
|
||||||
{
|
{
|
||||||
solAssert(!m_yul, "");
|
solAssert(!m_yul, "");
|
||||||
solAssert(isValidInstruction(_functionalInstruction.instruction), "Invalid instruction");
|
solAssert(isValidInstruction(_functionalInstruction.instruction), "Invalid instruction");
|
||||||
@ -109,26 +109,26 @@ string AsmPrinter::operator()(FunctionalInstruction const& _functionalInstructio
|
|||||||
")";
|
")";
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(ExpressionStatement const& _statement)
|
string AsmPrinter::operator()(ExpressionStatement const& _statement) const
|
||||||
{
|
{
|
||||||
return boost::apply_visitor(*this, _statement.expression);
|
return boost::apply_visitor(*this, _statement.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(Label const& _label)
|
string AsmPrinter::operator()(Label const& _label) const
|
||||||
{
|
{
|
||||||
solAssert(!m_yul, "");
|
solAssert(!m_yul, "");
|
||||||
solAssert(!_label.name.empty(), "Invalid label.");
|
solAssert(!_label.name.empty(), "Invalid label.");
|
||||||
return _label.name.str() + ":";
|
return _label.name.str() + ":";
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(StackAssignment const& _assignment)
|
string AsmPrinter::operator()(StackAssignment const& _assignment) const
|
||||||
{
|
{
|
||||||
solAssert(!m_yul, "");
|
solAssert(!m_yul, "");
|
||||||
solAssert(!_assignment.variableName.name.empty(), "Invalid variable name.");
|
solAssert(!_assignment.variableName.name.empty(), "Invalid variable name.");
|
||||||
return "=: " + (*this)(_assignment.variableName);
|
return "=: " + (*this)(_assignment.variableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(Assignment const& _assignment)
|
string AsmPrinter::operator()(Assignment const& _assignment) const
|
||||||
{
|
{
|
||||||
solAssert(_assignment.variableNames.size() >= 1, "");
|
solAssert(_assignment.variableNames.size() >= 1, "");
|
||||||
string variables = (*this)(_assignment.variableNames.front());
|
string variables = (*this)(_assignment.variableNames.front());
|
||||||
@ -137,7 +137,7 @@ string AsmPrinter::operator()(Assignment const& _assignment)
|
|||||||
return variables + " := " + boost::apply_visitor(*this, *_assignment.value);
|
return variables + " := " + boost::apply_visitor(*this, *_assignment.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration)
|
string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) const
|
||||||
{
|
{
|
||||||
string out = "let ";
|
string out = "let ";
|
||||||
out += boost::algorithm::join(
|
out += boost::algorithm::join(
|
||||||
@ -154,7 +154,7 @@ string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition)
|
string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition) const
|
||||||
{
|
{
|
||||||
solAssert(!_functionDefinition.name.empty(), "Invalid function name.");
|
solAssert(!_functionDefinition.name.empty(), "Invalid function name.");
|
||||||
string out = "function " + _functionDefinition.name.str() + "(";
|
string out = "function " + _functionDefinition.name.str() + "(";
|
||||||
@ -179,7 +179,7 @@ string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition)
|
|||||||
return out + "\n" + (*this)(_functionDefinition.body);
|
return out + "\n" + (*this)(_functionDefinition.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(FunctionCall const& _functionCall)
|
string AsmPrinter::operator()(FunctionCall const& _functionCall) const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
(*this)(_functionCall.functionName) + "(" +
|
(*this)(_functionCall.functionName) + "(" +
|
||||||
@ -189,13 +189,13 @@ string AsmPrinter::operator()(FunctionCall const& _functionCall)
|
|||||||
")";
|
")";
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(If const& _if)
|
string AsmPrinter::operator()(If const& _if) const
|
||||||
{
|
{
|
||||||
solAssert(_if.condition, "Invalid if condition.");
|
solAssert(_if.condition, "Invalid if condition.");
|
||||||
return "if " + boost::apply_visitor(*this, *_if.condition) + "\n" + (*this)(_if.body);
|
return "if " + boost::apply_visitor(*this, *_if.condition) + "\n" + (*this)(_if.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(Switch const& _switch)
|
string AsmPrinter::operator()(Switch const& _switch) const
|
||||||
{
|
{
|
||||||
solAssert(_switch.expression, "Invalid expression pointer.");
|
solAssert(_switch.expression, "Invalid expression pointer.");
|
||||||
string out = "switch " + boost::apply_visitor(*this, *_switch.expression);
|
string out = "switch " + boost::apply_visitor(*this, *_switch.expression);
|
||||||
@ -210,7 +210,7 @@ string AsmPrinter::operator()(Switch const& _switch)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(ForLoop const& _forLoop)
|
string AsmPrinter::operator()(ForLoop const& _forLoop) const
|
||||||
{
|
{
|
||||||
solAssert(_forLoop.condition, "Invalid for loop condition.");
|
solAssert(_forLoop.condition, "Invalid for loop condition.");
|
||||||
string out = "for ";
|
string out = "for ";
|
||||||
@ -224,7 +224,7 @@ string AsmPrinter::operator()(ForLoop const& _forLoop)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(Block const& _block)
|
string AsmPrinter::operator()(Block const& _block) const
|
||||||
{
|
{
|
||||||
if (_block.statements.empty())
|
if (_block.statements.empty())
|
||||||
return "{\n}";
|
return "{\n}";
|
||||||
|
@ -36,21 +36,21 @@ class AsmPrinter: public boost::static_visitor<std::string>
|
|||||||
public:
|
public:
|
||||||
explicit AsmPrinter(bool _yul = false): m_yul(_yul) {}
|
explicit AsmPrinter(bool _yul = false): m_yul(_yul) {}
|
||||||
|
|
||||||
std::string operator()(Instruction const& _instruction);
|
std::string operator()(Instruction const& _instruction) const;
|
||||||
std::string operator()(Literal const& _literal);
|
std::string operator()(Literal const& _literal) const;
|
||||||
std::string operator()(Identifier const& _identifier);
|
std::string operator()(Identifier const& _identifier) const;
|
||||||
std::string operator()(FunctionalInstruction const& _functionalInstruction);
|
std::string operator()(FunctionalInstruction const& _functionalInstruction) const;
|
||||||
std::string operator()(ExpressionStatement const& _expr);
|
std::string operator()(ExpressionStatement const& _expr) const;
|
||||||
std::string operator()(Label const& _label);
|
std::string operator()(Label const& _label) const;
|
||||||
std::string operator()(StackAssignment const& _assignment);
|
std::string operator()(StackAssignment const& _assignment) const;
|
||||||
std::string operator()(Assignment const& _assignment);
|
std::string operator()(Assignment const& _assignment) const;
|
||||||
std::string operator()(VariableDeclaration const& _variableDeclaration);
|
std::string operator()(VariableDeclaration const& _variableDeclaration) const;
|
||||||
std::string operator()(FunctionDefinition const& _functionDefinition);
|
std::string operator()(FunctionDefinition const& _functionDefinition) const;
|
||||||
std::string operator()(FunctionCall const& _functionCall);
|
std::string operator()(FunctionCall const& _functionCall) const;
|
||||||
std::string operator()(If const& _if);
|
std::string operator()(If const& _if) const;
|
||||||
std::string operator()(Switch const& _switch);
|
std::string operator()(Switch const& _switch) const;
|
||||||
std::string operator()(ForLoop const& _forLoop);
|
std::string operator()(ForLoop const& _forLoop) const;
|
||||||
std::string operator()(Block const& _block);
|
std::string operator()(Block const& _block) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string formatTypedName(TypedName _variable) const;
|
std::string formatTypedName(TypedName _variable) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user