mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Initial introduction of array slices with partial implementation for dynamic calldata arrays.
This commit is contained in:
@@ -1607,11 +1607,24 @@ ASTPointer<Expression> Parser::parseLeftHandSideExpression(
|
||||
{
|
||||
m_scanner->next();
|
||||
ASTPointer<Expression> index;
|
||||
if (m_scanner->currentToken() != Token::RBrack)
|
||||
ASTPointer<Expression> endIndex;
|
||||
if (m_scanner->currentToken() != Token::RBrack && m_scanner->currentToken() != Token::Colon)
|
||||
index = parseExpression();
|
||||
nodeFactory.markEndPosition();
|
||||
expectToken(Token::RBrack);
|
||||
expression = nodeFactory.createNode<IndexAccess>(expression, index);
|
||||
if (m_scanner->currentToken() == Token::Colon)
|
||||
{
|
||||
expectToken(Token::Colon);
|
||||
if (m_scanner->currentToken() != Token::RBrack)
|
||||
endIndex = parseExpression();
|
||||
nodeFactory.markEndPosition();
|
||||
expectToken(Token::RBrack);
|
||||
expression = nodeFactory.createNode<IndexRangeAccess>(expression, index, endIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeFactory.markEndPosition();
|
||||
expectToken(Token::RBrack);
|
||||
expression = nodeFactory.createNode<IndexAccess>(expression, index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Token::Period:
|
||||
@@ -1861,12 +1874,25 @@ Parser::IndexAccessedPath Parser::parseIndexAccessedPath()
|
||||
{
|
||||
expectToken(Token::LBrack);
|
||||
ASTPointer<Expression> index;
|
||||
if (m_scanner->currentToken() != Token::RBrack)
|
||||
if (m_scanner->currentToken() != Token::RBrack && m_scanner->currentToken() != Token::Colon)
|
||||
index = parseExpression();
|
||||
SourceLocation indexLocation = iap.path.front()->location();
|
||||
indexLocation.end = endPosition();
|
||||
iap.indices.emplace_back(index, indexLocation);
|
||||
expectToken(Token::RBrack);
|
||||
if (m_scanner->currentToken() == Token::Colon)
|
||||
{
|
||||
expectToken(Token::Colon);
|
||||
ASTPointer<Expression> endIndex;
|
||||
if (m_scanner->currentToken() != Token::RBrack)
|
||||
endIndex = parseExpression();
|
||||
indexLocation.end = endPosition();
|
||||
iap.indices.emplace_back(IndexAccessedPath::Index{index, {endIndex}, indexLocation});
|
||||
expectToken(Token::RBrack);
|
||||
}
|
||||
else
|
||||
{
|
||||
indexLocation.end = endPosition();
|
||||
iap.indices.emplace_back(IndexAccessedPath::Index{index, {}, indexLocation});
|
||||
expectToken(Token::RBrack);
|
||||
}
|
||||
}
|
||||
|
||||
return iap;
|
||||
@@ -1898,8 +1924,10 @@ ASTPointer<TypeName> Parser::typeNameFromIndexAccessStructure(Parser::IndexAcces
|
||||
}
|
||||
for (auto const& lengthExpression: _iap.indices)
|
||||
{
|
||||
nodeFactory.setLocation(lengthExpression.second);
|
||||
type = nodeFactory.createNode<ArrayTypeName>(type, lengthExpression.first);
|
||||
if (lengthExpression.end)
|
||||
parserError(lengthExpression.location, "Expected array length expression.");
|
||||
nodeFactory.setLocation(lengthExpression.location);
|
||||
type = nodeFactory.createNode<ArrayTypeName>(type, lengthExpression.start);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
@@ -1927,8 +1955,11 @@ ASTPointer<Expression> Parser::expressionFromIndexAccessStructure(
|
||||
}
|
||||
for (auto const& index: _iap.indices)
|
||||
{
|
||||
nodeFactory.setLocation(index.second);
|
||||
expression = nodeFactory.createNode<IndexAccess>(expression, index.first);
|
||||
nodeFactory.setLocation(index.location);
|
||||
if (index.end)
|
||||
expression = nodeFactory.createNode<IndexRangeAccess>(expression, index.start, *index.end);
|
||||
else
|
||||
expression = nodeFactory.createNode<IndexAccess>(expression, index.start);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user