mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Inline array declarations complete
This commit is contained in:
parent
98684cca90
commit
574e48b0b5
@ -1126,9 +1126,10 @@ private:
|
|||||||
ASTPointer<Expression> m_rightHandSide;
|
ASTPointer<Expression> m_rightHandSide;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tuple or just parenthesized expression.
|
* Tuple, parenthesized expression, or bracketed expression.
|
||||||
* Examples: (1, 2), (x,), (x), ()
|
* Examples: (1, 2), (x,), (x), (), [1, 2],
|
||||||
* Individual components might be empty shared pointers (as in the second example).
|
* Individual components might be empty shared pointers (as in the second example).
|
||||||
* The respective types in lvalue context are: 2-tuple, 2-tuple (with wildcard), type of x, 0-tuple
|
* The respective types in lvalue context are: 2-tuple, 2-tuple (with wildcard), type of x, 0-tuple
|
||||||
* Not in lvalue context: 2-tuple, _1_-tuple, type of x, 0-tuple.
|
* Not in lvalue context: 2-tuple, _1_-tuple, type of x, 0-tuple.
|
||||||
@ -1150,6 +1151,23 @@ private:
|
|||||||
std::vector<ASTPointer<Expression>> m_components;
|
std::vector<ASTPointer<Expression>> m_components;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class InlineArrayExpression: public Expression
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InlineArrayExpression(
|
||||||
|
SourceLocation const& _location,
|
||||||
|
std::vector<ASTPointer<Expression>> const& _components
|
||||||
|
):
|
||||||
|
Expression(_location), m_components(_components) {}
|
||||||
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
||||||
|
|
||||||
|
std::vector<ASTPointer<Expression>> const& components() const { return m_components; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<ASTPointer<Expression>> m_components;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operation involving a unary operator, pre- or postfix.
|
* Operation involving a unary operator, pre- or postfix.
|
||||||
* Examples: ++i, delete x or !true
|
* Examples: ++i, delete x or !true
|
||||||
|
@ -1056,6 +1056,28 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
|
|||||||
expectToken(Token::RParen);
|
expectToken(Token::RParen);
|
||||||
return nodeFactory.createNode<TupleExpression>(components);
|
return nodeFactory.createNode<TupleExpression>(components);
|
||||||
}
|
}
|
||||||
|
case Token::LBrack:
|
||||||
|
{
|
||||||
|
// Inline array expression
|
||||||
|
// Special cases: [] is empty tuple type, (x) is not a real tuple, (x,) is one-dimensional tuple
|
||||||
|
m_scanner->next();
|
||||||
|
vector<ASTPointer<Expression>> components;
|
||||||
|
if (m_scanner->currentToken() != Token::RBrack)
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (m_scanner->currentToken() != Token::Comma && m_scanner->currentToken() != Token::RBrack)
|
||||||
|
components.push_back(parseExpression());
|
||||||
|
else
|
||||||
|
components.push_back(ASTPointer<Expression>());
|
||||||
|
if (m_scanner->currentToken() == Token::RBrack)
|
||||||
|
break;
|
||||||
|
else if (m_scanner->currentToken() == Token::Comma)
|
||||||
|
m_scanner->next();
|
||||||
|
}
|
||||||
|
nodeFactory.markEndPosition();
|
||||||
|
expectToken(Token::RBrack);
|
||||||
|
return nodeFactory.createNode<TupleExpression>(components);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if (Token::isElementaryTypeName(token))
|
if (Token::isElementaryTypeName(token))
|
||||||
{
|
{
|
||||||
|
@ -1047,6 +1047,16 @@ BOOST_AUTO_TEST_CASE(using_for)
|
|||||||
BOOST_CHECK(successParse(text));
|
BOOST_CHECK(successParse(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(inline_array_declaration)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract C {
|
||||||
|
uint[] x = [0, 1, 2, 3];
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK(successParse(text));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user