Promote gwei to a proper keyword.

This commit is contained in:
Daniel Kirchner 2020-07-08 20:35:02 +02:00 committed by Leonardo Alt
parent 38c6ecbbe2
commit c3e13b6733
7 changed files with 13 additions and 15 deletions

View File

@ -5,6 +5,7 @@ Breaking changes:
* Constructors should not have visibility.
* Deprecated dot syntax for `value` and `gas`.
* Deprecated the identifier `now`.
* Disallow `gwei` as identifier.
* JSON AST: Removes members with ``null`` value from JSON output.
* Parser: NatSpec comments on variables are only allowed for public state variables.
* Type Checker: Disallow shifts by signed types.

View File

@ -196,6 +196,7 @@ namespace solidity::langutil
\
/* Ether subdenominations */ \
K(SubWei, "wei", 0) \
K(SubGwei, "gwei", 0) \
K(SubEther, "ether", 0) \
K(SubSecond, "seconds", 0) \
K(SubMinute, "minutes", 0) \
@ -230,7 +231,6 @@ namespace solidity::langutil
\
/* Identifiers (not keywords or future reserved words). */ \
T(Identifier, nullptr, 0) \
T(SubGwei, "gwei", 0) \
\
/* Keywords reserved for future use. */ \
K(After, "after", 0) \
@ -311,7 +311,7 @@ namespace TokenTraits
|| op == Token::Pure || op == Token::View || op == Token::Payable;
}
constexpr bool isEtherSubdenomination(Token op) { return op == Token::SubWei || op == Token::SubEther; }
constexpr bool isEtherSubdenomination(Token op) { return op >= Token::SubWei && op <= Token::SubEther; }
constexpr bool isTimeSubdenomination(Token op) { return op == Token::SubSecond || op == Token::SubMinute || op == Token::SubHour || op == Token::SubDay || op == Token::SubWeek || op == Token::SubYear; }
constexpr bool isReservedKeyword(Token op) { return (Token::After <= op && op <= Token::Unchecked); }

View File

@ -1825,16 +1825,11 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
expression = nodeFactory.createNode<Literal>(token, getLiteralAndAdvance());
break;
case Token::Number:
if (
(m_scanner->peekNextToken() == Token::Identifier && m_scanner->peekLiteral() == "gwei") ||
TokenTraits::isEtherSubdenomination(m_scanner->peekNextToken())
)
if (TokenTraits::isEtherSubdenomination(m_scanner->peekNextToken()))
{
ASTPointer<ASTString> literal = getLiteralAndAdvance();
nodeFactory.markEndPosition();
Token actualToken = m_scanner->currentToken() == Token::Identifier ? Token::SubGwei : m_scanner->currentToken();
Literal::SubDenomination subdenomination = static_cast<Literal::SubDenomination>(actualToken);
Literal::SubDenomination subdenomination = static_cast<Literal::SubDenomination>(m_scanner->currentToken());
m_scanner->next();
expression = nodeFactory.createNode<Literal>(token, literal, subdenomination);
}

View File

@ -430,7 +430,7 @@ BOOST_AUTO_TEST_CASE(ether_subdenominations)
{
Scanner scanner(CharStream("wei gwei ether", ""));
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::SubWei);
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
BOOST_CHECK_EQUAL(scanner.next(), Token::SubGwei);
BOOST_CHECK_EQUAL(scanner.next(), Token::SubEther);
}

View File

@ -1,7 +1,7 @@
contract C {
uint constant gwei = 1 gwei;
uint constant x = 1 gwei;
function f() public view returns(uint) { return gwei; }
function f() public view returns(uint) { return x; }
}
// ====
// compileViaYul: also

View File

@ -1,3 +0,0 @@
contract C {
uint constant gwei = 1 gwei;
}

View File

@ -0,0 +1,5 @@
contract C {
uint constant gwei = 1;
}
// ----
// ParserError 2314: (28-32): Expected identifier but got 'gwei'