diff options
author | chriseth <chris@ethereum.org> | 2018-12-13 20:57:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-13 20:57:19 +0800 |
commit | b103c68fe115e61f9fd5a14fcc1a23ed588a71f9 (patch) | |
tree | fdae75b9db8cad0226392fb50e9491f3be88f45e | |
parent | 642c69f935c41d70f0dcfb0e89fcf3e626f7b38f (diff) | |
parent | 6101258248567b0e670a1fc9226159d7f6687eef (diff) | |
download | dexon-solidity-b103c68fe115e61f9fd5a14fcc1a23ed588a71f9.tar.gz dexon-solidity-b103c68fe115e61f9fd5a14fcc1a23ed588a71f9.tar.zst dexon-solidity-b103c68fe115e61f9fd5a14fcc1a23ed588a71f9.zip |
Merge pull request #5650 from ethereum/printerConst
AsmPrinter functions should be const.
-rw-r--r-- | libyul/AsmPrinter.cpp | 30 | ||||
-rw-r--r-- | libyul/AsmPrinter.h | 30 |
2 files changed, 30 insertions, 30 deletions
diff --git a/libyul/AsmPrinter.cpp b/libyul/AsmPrinter.cpp index eaaba9f3..a5b14953 100644 --- a/libyul/AsmPrinter.cpp +++ b/libyul/AsmPrinter.cpp @@ -40,14 +40,14 @@ using namespace dev::solidity; //@TODO source locations -string AsmPrinter::operator()(yul::Instruction const& _instruction) +string AsmPrinter::operator()(yul::Instruction const& _instruction) const { solAssert(!m_yul, ""); solAssert(isValidInstruction(_instruction.instruction), "Invalid instruction"); 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) { @@ -90,13 +90,13 @@ string AsmPrinter::operator()(Literal const& _literal) return "\"" + out + "\"" + appendTypeName(_literal.type); } -string AsmPrinter::operator()(Identifier const& _identifier) +string AsmPrinter::operator()(Identifier const& _identifier) const { solAssert(!_identifier.name.empty(), "Invalid identifier."); return _identifier.name.str(); } -string AsmPrinter::operator()(FunctionalInstruction const& _functionalInstruction) +string AsmPrinter::operator()(FunctionalInstruction const& _functionalInstruction) const { solAssert(!m_yul, ""); 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); } -string AsmPrinter::operator()(Label const& _label) +string AsmPrinter::operator()(Label const& _label) const { solAssert(!m_yul, ""); solAssert(!_label.name.empty(), "Invalid label."); return _label.name.str() + ":"; } -string AsmPrinter::operator()(StackAssignment const& _assignment) +string AsmPrinter::operator()(StackAssignment const& _assignment) const { solAssert(!m_yul, ""); solAssert(!_assignment.variableName.name.empty(), "Invalid variable name."); return "=: " + (*this)(_assignment.variableName); } -string AsmPrinter::operator()(Assignment const& _assignment) +string AsmPrinter::operator()(Assignment const& _assignment) const { solAssert(_assignment.variableNames.size() >= 1, ""); string variables = (*this)(_assignment.variableNames.front()); @@ -137,7 +137,7 @@ string AsmPrinter::operator()(Assignment const& _assignment) return variables + " := " + boost::apply_visitor(*this, *_assignment.value); } -string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) +string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) const { string out = "let "; out += boost::algorithm::join( @@ -154,7 +154,7 @@ string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) return out; } -string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition) +string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition) const { solAssert(!_functionDefinition.name.empty(), "Invalid function name."); string out = "function " + _functionDefinition.name.str() + "("; @@ -179,7 +179,7 @@ string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition) return out + "\n" + (*this)(_functionDefinition.body); } -string AsmPrinter::operator()(FunctionCall const& _functionCall) +string AsmPrinter::operator()(FunctionCall const& _functionCall) const { return (*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."); 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."); string out = "switch " + boost::apply_visitor(*this, *_switch.expression); @@ -210,7 +210,7 @@ string AsmPrinter::operator()(Switch const& _switch) return out; } -string AsmPrinter::operator()(ForLoop const& _forLoop) +string AsmPrinter::operator()(ForLoop const& _forLoop) const { solAssert(_forLoop.condition, "Invalid for loop condition."); string out = "for "; @@ -224,7 +224,7 @@ string AsmPrinter::operator()(ForLoop const& _forLoop) return out; } -string AsmPrinter::operator()(Block const& _block) +string AsmPrinter::operator()(Block const& _block) const { if (_block.statements.empty()) return "{\n}"; diff --git a/libyul/AsmPrinter.h b/libyul/AsmPrinter.h index 61dfc18c..a1b9d6cd 100644 --- a/libyul/AsmPrinter.h +++ b/libyul/AsmPrinter.h @@ -36,21 +36,21 @@ class AsmPrinter: public boost::static_visitor<std::string> public: explicit AsmPrinter(bool _yul = false): m_yul(_yul) {} - std::string operator()(Instruction const& _instruction); - std::string operator()(Literal const& _literal); - std::string operator()(Identifier const& _identifier); - std::string operator()(FunctionalInstruction const& _functionalInstruction); - std::string operator()(ExpressionStatement const& _expr); - std::string operator()(Label const& _label); - std::string operator()(StackAssignment const& _assignment); - std::string operator()(Assignment const& _assignment); - std::string operator()(VariableDeclaration const& _variableDeclaration); - std::string operator()(FunctionDefinition const& _functionDefinition); - std::string operator()(FunctionCall const& _functionCall); - std::string operator()(If const& _if); - std::string operator()(Switch const& _switch); - std::string operator()(ForLoop const& _forLoop); - std::string operator()(Block const& _block); + std::string operator()(Instruction const& _instruction) const; + std::string operator()(Literal const& _literal) const; + std::string operator()(Identifier const& _identifier) const; + std::string operator()(FunctionalInstruction const& _functionalInstruction) const; + std::string operator()(ExpressionStatement const& _expr) const; + std::string operator()(Label const& _label) const; + std::string operator()(StackAssignment const& _assignment) const; + std::string operator()(Assignment const& _assignment) const; + std::string operator()(VariableDeclaration const& _variableDeclaration) const; + std::string operator()(FunctionDefinition const& _functionDefinition) const; + std::string operator()(FunctionCall const& _functionCall) const; + std::string operator()(If const& _if) const; + std::string operator()(Switch const& _switch) const; + std::string operator()(ForLoop const& _forLoop) const; + std::string operator()(Block const& _block) const; private: std::string formatTypedName(TypedName _variable) const; |