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/analysis | |
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/analysis')
-rw-r--r-- | libsolidity/analysis/SyntaxChecker.cpp | 42 | ||||
-rw-r--r-- | libsolidity/analysis/SyntaxChecker.h | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 77492499..ac4fa72b 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -24,6 +24,9 @@ #include <libsolidity/interface/Version.h> #include <boost/algorithm/cxx11/all_of.hpp> +#include <boost/algorithm/string.hpp> +#include <string> + using namespace std; using namespace dev; using namespace dev::solidity; @@ -183,6 +186,45 @@ bool SyntaxChecker::visit(Throw const& _throwStatement) return true; } +bool SyntaxChecker::visit(Literal const& _literal) +{ + if (_literal.token() != Token::Number) + return true; + + ASTString const& value = _literal.value(); + solAssert(!value.empty(), ""); + + // Generic checks no matter what base this number literal is of: + if (value.back() == '_') + { + m_errorReporter.syntaxError(_literal.location(), "Invalid use of underscores in number literal. No trailing underscores allowed."); + return true; + } + + if (value.find("__") != ASTString::npos) + { + m_errorReporter.syntaxError(_literal.location(), "Invalid use of underscores in number literal. Only one consecutive underscores between digits allowed."); + return true; + } + + if (!_literal.isHexNumber()) // decimal literal + { + if (value.find("._") != ASTString::npos) + m_errorReporter.syntaxError(_literal.location(), "Invalid use of underscores in number literal. No underscores in front of the fraction part allowed."); + + if (value.find("_.") != ASTString::npos) + m_errorReporter.syntaxError(_literal.location(), "Invalid use of underscores in number literal. No underscores in front of the fraction part allowed."); + + if (value.find("_e") != ASTString::npos) + m_errorReporter.syntaxError(_literal.location(), "Invalid use of underscores in number literal. No underscore at the end of the mantissa allowed."); + + if (value.find("e_") != ASTString::npos) + m_errorReporter.syntaxError(_literal.location(), "Invalid use of underscores in number literal. No underscore in front of exponent allowed."); + } + + return true; +} + bool SyntaxChecker::visit(UnaryOperation const& _operation) { if (_operation.getOperator() == Token::Add) diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h index 28a0f66e..897df676 100644 --- a/libsolidity/analysis/SyntaxChecker.h +++ b/libsolidity/analysis/SyntaxChecker.h @@ -73,6 +73,7 @@ private: virtual bool visit(VariableDeclarationStatement const& _statement) override; virtual bool visit(StructDefinition const& _struct) override; + virtual bool visit(Literal const& _literal) override; ErrorReporter& m_errorReporter; |