From 9fb835b710f7f0dc9f2089df6301f0ce55d1e4aa Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 1 Oct 2018 14:36:57 +0200 Subject: Fixes #5051 (introduced in #4684), effectively allowing underscores in address literals. --- libsolidity/ast/AST.cpp | 11 ++++++++--- libsolidity/ast/AST.h | 2 ++ libsolidity/ast/Types.cpp | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'libsolidity/ast') diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index a11b1146..d9264230 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -633,6 +633,11 @@ IdentifierAnnotation& Identifier::annotation() const return dynamic_cast(*m_annotation); } +ASTString Literal::valueWithoutUnderscores() const +{ + return boost::erase_all_copy(value(), "_"); +} + bool Literal::isHexNumber() const { if (token() != Token::Number) @@ -648,20 +653,20 @@ bool Literal::looksLikeAddress() const if (!isHexNumber()) return false; - return abs(int(value().length()) - 42) <= 1; + return abs(int(valueWithoutUnderscores().length()) - 42) <= 1; } bool Literal::passesAddressChecksum() const { solAssert(isHexNumber(), "Expected hex number"); - return dev::passesAddressChecksum(value(), true); + return dev::passesAddressChecksum(valueWithoutUnderscores(), true); } string Literal::getChecksummedAddress() const { solAssert(isHexNumber(), "Expected hex number"); /// Pad literal to be a proper hex address. - string address = value().substr(2); + string address = valueWithoutUnderscores().substr(2); if (address.length() > 40) return string(); address.insert(address.begin(), 40 - address.size(), '0'); diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index f3464f92..b84f9730 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -1679,6 +1679,8 @@ public: /// @returns the non-parsed value of the literal ASTString const& value() const { return *m_value; } + ASTString valueWithoutUnderscores() const; + SubDenomination subDenomination() const { return m_subDenomination; } /// @returns true if this is a number with a hex prefix. diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index fd72bf41..e45fc81d 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -499,7 +499,7 @@ u256 AddressType::literalValue(Literal const* _literal) const { solAssert(_literal, ""); solAssert(_literal->value().substr(0, 2) == "0x", ""); - return u256(_literal->value()); + return u256(_literal->valueWithoutUnderscores()); } TypePointer AddressType::unaryOperatorResult(Token::Value _operator) const -- cgit v1.2.3