aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis/SyntaxChecker.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-08-09 03:36:57 +0800
committerGitHub <noreply@github.com>2018-08-09 03:36:57 +0800
commitd634d20b5b0dac3e5caf1741073fa123fdd56ab9 (patch)
treee88008bc8a8e665d32d8ac8c9125595dd90e8a22 /libsolidity/analysis/SyntaxChecker.cpp
parent551343ae3eb1b3f1575d91a4f7021c0f9529d5bd (diff)
parentb9222808f61e00833f8c11cd196cafb50ec9e1b9 (diff)
downloaddexon-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/SyntaxChecker.cpp')
-rw-r--r--libsolidity/analysis/SyntaxChecker.cpp42
1 files changed, 42 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)