diff options
author | chriseth <chris@ethereum.org> | 2018-12-17 21:07:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-17 21:07:24 +0800 |
commit | bf7d71d6b301a8eb4db0d06b7bf0ad1e6b67e679 (patch) | |
tree | c3c9d4ed59cbedb402269358ecab0cac41a4e414 | |
parent | bc85a8915f0cc8214a8b5a4be2410ac935532fa3 (diff) | |
parent | 5ac7620045012c2ed565b81978dc35f5f83f7eea (diff) | |
download | dexon-solidity-bf7d71d6b301a8eb4db0d06b7bf0ad1e6b67e679.tar.gz dexon-solidity-bf7d71d6b301a8eb4db0d06b7bf0ad1e6b67e679.tar.zst dexon-solidity-bf7d71d6b301a8eb4db0d06b7bf0ad1e6b67e679.zip |
Merge pull request #5613 from ethereum/yulStringLiterals
[Yul] Use C++ user-defined literals for creating YulString constants.
-rw-r--r-- | libyul/AsmAnalysis.cpp | 2 | ||||
-rw-r--r-- | libyul/AsmParser.cpp | 6 | ||||
-rw-r--r-- | libyul/AsmPrinter.cpp | 4 | ||||
-rw-r--r-- | libyul/ObjectParser.cpp | 2 | ||||
-rw-r--r-- | libyul/YulString.h | 5 | ||||
-rw-r--r-- | libyul/backends/evm/EVMCodeTransform.cpp | 2 | ||||
-rw-r--r-- | libyul/optimiser/MainFunction.cpp | 4 | ||||
-rw-r--r-- | test/libyul/Parser.cpp | 6 |
8 files changed, 18 insertions, 13 deletions
diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 821da005..0ecc5a30 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -102,7 +102,7 @@ bool AsmAnalyzer::operator()(Literal const& _literal) else if (_literal.kind == LiteralKind::Boolean) { solAssert(m_dialect->flavour == AsmFlavour::Yul, ""); - solAssert(_literal.value == YulString{string("true")} || _literal.value == YulString{string("false")}, ""); + solAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, ""); } m_info.stackHeightInfo[&_literal] = m_stackHeight; return true; diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index c7302063..f3ca6cd0 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -354,11 +354,11 @@ Parser::ElementaryOperation Parser::parseElementaryOperation() { YulString literal; if (currentToken() == Token::Return) - literal = YulString{"return"}; + literal = "return"_yulstring; else if (currentToken() == Token::Byte) - literal = YulString{"byte"}; + literal = "byte"_yulstring; else if (currentToken() == Token::Address) - literal = YulString{"address"}; + literal = "address"_yulstring; else literal = YulString{currentLiteral()}; // first search the set of builtins, then the instructions. diff --git a/libyul/AsmPrinter.cpp b/libyul/AsmPrinter.cpp index a5b14953..b7af4778 100644 --- a/libyul/AsmPrinter.cpp +++ b/libyul/AsmPrinter.cpp @@ -55,8 +55,8 @@ string AsmPrinter::operator()(Literal const& _literal) const solAssert(isValidDecimal(_literal.value.str()) || isValidHex(_literal.value.str()), "Invalid number literal"); return _literal.value.str() + appendTypeName(_literal.type); case LiteralKind::Boolean: - solAssert(_literal.value.str() == "true" || _literal.value.str() == "false", "Invalid bool literal."); - return ((_literal.value.str() == "true") ? "true" : "false") + appendTypeName(_literal.type); + solAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "Invalid bool literal."); + return ((_literal.value == "true"_yulstring) ? "true" : "false") + appendTypeName(_literal.type); case LiteralKind::String: break; } diff --git a/libyul/ObjectParser.cpp b/libyul/ObjectParser.cpp index ba19e099..5f1eadef 100644 --- a/libyul/ObjectParser.cpp +++ b/libyul/ObjectParser.cpp @@ -42,7 +42,7 @@ shared_ptr<Object> ObjectParser::parse(shared_ptr<Scanner> const& _scanner, bool { // Special case: Code-only form. object = make_shared<Object>(); - object->name = YulString{"object"}; + object->name = "object"_yulstring; object->code = parseBlock(); if (!object->code) return nullptr; diff --git a/libyul/YulString.h b/libyul/YulString.h index 2179c23b..35c1d92d 100644 --- a/libyul/YulString.h +++ b/libyul/YulString.h @@ -127,4 +127,9 @@ private: YulStringRepository::Handle m_handle{ 0, YulStringRepository::emptyHash() }; }; +inline YulString operator "" _yulstring(const char *_string, std::size_t _size) +{ + return YulString(std::string(_string, _size)); +} + } diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index bd18985c..04dc5040 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -387,7 +387,7 @@ void CodeTransform::operator()(Literal const& _literal) m_assembly.appendConstant(u256(_literal.value.str())); else if (_literal.kind == LiteralKind::Boolean) { - if (_literal.value.str() == "true") + if (_literal.value == "true"_yulstring) m_assembly.appendConstant(u256(1)); else m_assembly.appendConstant(u256(0)); diff --git a/libyul/optimiser/MainFunction.cpp b/libyul/optimiser/MainFunction.cpp index 63eea2db..fabbf66f 100644 --- a/libyul/optimiser/MainFunction.cpp +++ b/libyul/optimiser/MainFunction.cpp @@ -40,12 +40,12 @@ void MainFunction::operator()(Block& _block) for (size_t i = 1; i < _block.statements.size(); ++i) assertThrow(_block.statements.at(i).type() == typeid(FunctionDefinition), OptimizerException, ""); /// @todo this should handle scopes properly and instead of an assertion it should rename the conflicting function - assertThrow(NameCollector(_block).names().count(YulString{"main"}) == 0, OptimizerException, ""); + assertThrow(NameCollector(_block).names().count("main"_yulstring) == 0, OptimizerException, ""); Block& block = boost::get<Block>(_block.statements[0]); FunctionDefinition main{ block.location, - YulString{"main"}, + "main"_yulstring, {}, {}, std::move(block) diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index 5e9fba86..df7e32a1 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE(builtins_parser) SimpleDialect(): Dialect(AsmFlavour::Strict) {} BuiltinFunction const* builtin(YulString _name) const override { - return _name == YulString{"builtin"} ? &f : nullptr; + return _name == "builtin"_yulstring ? &f : nullptr; } BuiltinFunction f; }; @@ -329,9 +329,9 @@ BOOST_AUTO_TEST_CASE(builtins_analysis) SimpleDialect(): Dialect(AsmFlavour::Strict) {} BuiltinFunction const* builtin(YulString _name) const override { - return _name == YulString{"builtin"} ? &f : nullptr; + return _name == "builtin"_yulstring ? &f : nullptr; } - BuiltinFunction f{YulString{"builtin"}, vector<Type>(2), vector<Type>(3), false}; + BuiltinFunction f{"builtin"_yulstring, vector<Type>(2), vector<Type>(3), false}; }; shared_ptr<Dialect> dialect = make_shared<SimpleDialect>(); |