diff options
author | chriseth <chris@ethereum.org> | 2018-08-09 03:36:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-09 03:36:57 +0800 |
commit | d634d20b5b0dac3e5caf1741073fa123fdd56ab9 (patch) | |
tree | e88008bc8a8e665d32d8ac8c9125595dd90e8a22 /libsolidity/ast/Types.cpp | |
parent | 551343ae3eb1b3f1575d91a4f7021c0f9529d5bd (diff) | |
parent | b9222808f61e00833f8c11cd196cafb50ec9e1b9 (diff) | |
download | dexon-solidity-d634d20b5b0dac3e5caf1741073fa123fdd56ab9.tar dexon-solidity-d634d20b5b0dac3e5caf1741073fa123fdd56ab9.tar.gz dexon-solidity-d634d20b5b0dac3e5caf1741073fa123fdd56ab9.tar.bz2 dexon-solidity-d634d20b5b0dac3e5caf1741073fa123fdd56ab9.tar.lz dexon-solidity-d634d20b5b0dac3e5caf1741073fa123fdd56ab9.tar.xz dexon-solidity-d634d20b5b0dac3e5caf1741073fa123fdd56ab9.tar.zst dexon-solidity-d634d20b5b0dac3e5caf1741073fa123fdd56ab9.zip |
Merge pull request #4684 from ethereum/underscores_in_numeric_literals
[BREAKING] Underscores in numeric literals
Diffstat (limited to 'libsolidity/ast/Types.cpp')
-rw-r--r-- | libsolidity/ast/Types.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 349a59d4..3dbbca91 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -39,6 +39,7 @@ #include <boost/range/algorithm/copy.hpp> #include <boost/range/adaptor/sliced.hpp> #include <boost/range/adaptor/transformed.hpp> +#include <boost/algorithm/string.hpp> #include <limits> @@ -783,19 +784,22 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal rational value; try { - auto expPoint = find(_literal.value().begin(), _literal.value().end(), 'e'); - if (expPoint == _literal.value().end()) - expPoint = find(_literal.value().begin(), _literal.value().end(), 'E'); + ASTString valueString = _literal.value(); + boost::erase_all(valueString, "_");// Remove underscore separators - if (boost::starts_with(_literal.value(), "0x")) + auto expPoint = find(valueString.begin(), valueString.end(), 'e'); + if (expPoint == valueString.end()) + expPoint = find(valueString.begin(), valueString.end(), 'E'); + + if (boost::starts_with(valueString, "0x")) { // process as hex - value = bigint(_literal.value()); + value = bigint(valueString); } - else if (expPoint != _literal.value().end()) + else if (expPoint != valueString.end()) { // Parse mantissa and exponent. Checks numeric limit. - tuple<bool, rational> mantissa = parseRational(string(_literal.value().begin(), expPoint)); + tuple<bool, rational> mantissa = parseRational(string(valueString.begin(), expPoint)); if (!get<0>(mantissa)) return make_tuple(false, rational(0)); @@ -805,7 +809,7 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal if (value == 0) return make_tuple(true, rational(0)); - bigint exp = bigint(string(expPoint + 1, _literal.value().end())); + bigint exp = bigint(string(expPoint + 1, valueString.end())); if (exp > numeric_limits<int32_t>::max() || exp < numeric_limits<int32_t>::min()) return make_tuple(false, rational(0)); @@ -834,7 +838,7 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal else { // parse as rational number - tuple<bool, rational> tmp = parseRational(_literal.value()); + tuple<bool, rational> tmp = parseRational(valueString); if (!get<0>(tmp)) return tmp; value = get<1>(tmp); |