mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9612 from ethereum/yul-rightarrow
Introduce RightArrow (->) token
This commit is contained in:
commit
0798167f3d
@ -15,6 +15,7 @@ Compiler Features:
|
||||
Bugfixes:
|
||||
* AST: Remove ``null`` member values also when the compiler is used in standard-json-mode.
|
||||
* Optimizer: Keep side-effects of ``x`` in ``byte(a, shr(b, x))`` even if the constants ``a`` and ``b`` would make the expression zero unconditionally. This optimizer rule is very hard if not impossible to trigger in a way that it can result in invalid code, though.
|
||||
* Scanner: Fix bug where whitespace would be allowed within the ``->`` token (e.g. ``function f() - > x {}`` becomes invalid in inline assembly and Yul).
|
||||
* SMTChecker: Fix internal error in BMC function inlining.
|
||||
* SMTChecker: Fix internal error on array implicit conversion.
|
||||
* SMTChecker: Fix internal error on fixed bytes index access.
|
||||
|
@ -433,7 +433,7 @@ variableDeclarationTuple:
|
||||
variableDeclarationStatement: ((variableDeclaration (Assign expression)?) | (variableDeclarationTuple Assign expression)) Semicolon;
|
||||
expressionStatement: expression Semicolon;
|
||||
|
||||
mappingType: Mapping LParen key=mappingKeyType Arrow value=typeName RParen;
|
||||
mappingType: Mapping LParen key=mappingKeyType DoubleArrow value=typeName RParen;
|
||||
/**
|
||||
* Only elementary types or user defined types are viable as mapping keys.
|
||||
*/
|
||||
|
@ -111,7 +111,8 @@ Colon: ':';
|
||||
Semicolon: ';';
|
||||
Period: '.';
|
||||
Conditional: '?';
|
||||
Arrow: '=>';
|
||||
DoubleArrow: '=>';
|
||||
RightArrow: '->';
|
||||
|
||||
Assign: '=';
|
||||
AssignBitOr: '|=';
|
||||
@ -283,9 +284,7 @@ YulRParen: ')';
|
||||
YulAssign: ':=';
|
||||
YulPeriod: '.';
|
||||
YulComma: ',';
|
||||
// TODO: remove whitespace workaround once the parser disallows it.
|
||||
//@doc:name ->
|
||||
YulArrow: '->' | '-' YulWS+ '>';
|
||||
YulArrow: '->';
|
||||
|
||||
/**
|
||||
* Yul identifiers consist of letters, dollar signs, underscores and numbers, but may not start with a number.
|
||||
|
@ -540,7 +540,7 @@ void Scanner::scanToken()
|
||||
if (m_char == '=')
|
||||
token = selectToken(Token::Equal);
|
||||
else if (m_char == '>')
|
||||
token = selectToken(Token::Arrow);
|
||||
token = selectToken(Token::DoubleArrow);
|
||||
else
|
||||
token = Token::Assign;
|
||||
break;
|
||||
@ -563,12 +563,14 @@ void Scanner::scanToken()
|
||||
token = Token::Add;
|
||||
break;
|
||||
case '-':
|
||||
// - -- -=
|
||||
// - -- -= ->
|
||||
advance();
|
||||
if (m_char == '-')
|
||||
token = selectToken(Token::Dec);
|
||||
else if (m_char == '=')
|
||||
token = selectToken(Token::AssignSub);
|
||||
else if (m_char == '>')
|
||||
token = selectToken(Token::RightArrow);
|
||||
else
|
||||
token = Token::Sub;
|
||||
break;
|
||||
|
@ -83,7 +83,8 @@ namespace solidity::langutil
|
||||
T(Semicolon, ";", 0) \
|
||||
T(Period, ".", 0) \
|
||||
T(Conditional, "?", 3) \
|
||||
T(Arrow, "=>", 0) \
|
||||
T(DoubleArrow, "=>", 0) \
|
||||
T(RightArrow, "->", 0) \
|
||||
\
|
||||
/* Assignment operators. */ \
|
||||
/* IsAssignmentOp() relies on this block of enum values being */ \
|
||||
|
@ -1050,7 +1050,7 @@ ASTPointer<Mapping> Parser::parseMapping()
|
||||
}
|
||||
else
|
||||
fatalParserError(1005_error, "Expected elementary type name or identifier for mapping key type");
|
||||
expectToken(Token::Arrow);
|
||||
expectToken(Token::DoubleArrow);
|
||||
ASTPointer<TypeName> valueType = parseTypeName();
|
||||
nodeFactory.markEndPosition();
|
||||
expectToken(Token::RParen);
|
||||
|
@ -401,10 +401,9 @@ FunctionDefinition Parser::parseFunctionDefinition()
|
||||
expectToken(Token::Comma);
|
||||
}
|
||||
expectToken(Token::RParen);
|
||||
if (currentToken() == Token::Sub)
|
||||
if (currentToken() == Token::RightArrow)
|
||||
{
|
||||
expectToken(Token::Sub);
|
||||
expectToken(Token::GreaterThan);
|
||||
expectToken(Token::RightArrow);
|
||||
while (true)
|
||||
{
|
||||
funDef.returnVariables.emplace_back(parseTypedName());
|
||||
|
@ -406,7 +406,7 @@ BOOST_AUTO_TEST_CASE(ambiguities)
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::AssignAdd);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Inc);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Arrow);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::DoubleArrow);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::SHL);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::SAR);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::AssignSar);
|
||||
@ -782,8 +782,7 @@ BOOST_AUTO_TEST_CASE(yul_function)
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Comma);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::RParen);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Sub);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::GreaterThan);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::RightArrow);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Comma);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||
@ -797,8 +796,7 @@ BOOST_AUTO_TEST_CASE(yul_function)
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Comma);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::RParen);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Sub);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::GreaterThan);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::RightArrow);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Comma);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||
|
@ -6,3 +6,5 @@ contract C {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (87-88): Expected '{' but got '-'
|
||||
|
@ -2,3 +2,5 @@
|
||||
function f (a, b , c ) - > y,x,z {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (30-31): Expected '{' but got '-'
|
||||
|
Loading…
Reference in New Issue
Block a user