mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add hasHexPrefix() to AST::Literal
This commit is contained in:
parent
79d1336687
commit
8b0c866f02
@ -1886,7 +1886,7 @@ void TypeChecker::expectType(Expression const& _expression, Type const& _expecte
|
||||
{
|
||||
auto literal = dynamic_cast<Literal const*>(&_expression);
|
||||
|
||||
if (literal && !boost::starts_with(literal->value(), "0x"))
|
||||
if (literal && !literal->hasHexPrefix())
|
||||
m_errorReporter.warning(
|
||||
_expression.location(),
|
||||
"Decimal literal assigned to bytesXX variable will be left-aligned. "
|
||||
|
@ -530,20 +530,26 @@ IdentifierAnnotation& Identifier::annotation() const
|
||||
return dynamic_cast<IdentifierAnnotation&>(*m_annotation);
|
||||
}
|
||||
|
||||
bool Literal::hasHexPrefix() const
|
||||
{
|
||||
if (token() != Token::Number)
|
||||
return false;
|
||||
return value().substr(0, 2) == "0x";
|
||||
}
|
||||
|
||||
bool Literal::looksLikeAddress() const
|
||||
{
|
||||
if (subDenomination() != SubDenomination::None)
|
||||
return false;
|
||||
if (token() != Token::Number)
|
||||
|
||||
if (!hasHexPrefix())
|
||||
return false;
|
||||
|
||||
string lit = value();
|
||||
return lit.substr(0, 2) == "0x" && abs(int(lit.length()) - 42) <= 1;
|
||||
return abs(int(value().length()) - 42) <= 1;
|
||||
}
|
||||
|
||||
bool Literal::passesAddressChecksum() const
|
||||
{
|
||||
string lit = value();
|
||||
solAssert(lit.substr(0, 2) == "0x", "Expected hex prefix");
|
||||
return dev::passesAddressChecksum(lit, true);
|
||||
solAssert(hasHexPrefix(), "Expected hex prefix");
|
||||
return dev::passesAddressChecksum(value(), true);
|
||||
}
|
||||
|
@ -1590,6 +1590,9 @@ public:
|
||||
|
||||
SubDenomination subDenomination() const { return m_subDenomination; }
|
||||
|
||||
/// @returns true if this is a number with a hex prefix.
|
||||
bool hasHexPrefix() const;
|
||||
|
||||
/// @returns true if this looks like a checksummed address.
|
||||
bool looksLikeAddress() const;
|
||||
/// @returns true if it passes the address checksum test.
|
||||
|
Loading…
Reference in New Issue
Block a user