mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Solidity ForStatements expressions are now optional
This commit is contained in:
parent
3f2600bb31
commit
90e39c04d6
18
AST_accept.h
18
AST_accept.h
@ -271,9 +271,12 @@ void ForStatement::accept(ASTVisitor& _visitor)
|
||||
{
|
||||
if (_visitor.visit(*this))
|
||||
{
|
||||
m_initExpression->accept(_visitor);
|
||||
m_condExpression->accept(_visitor);
|
||||
m_loopExpression->accept(_visitor);
|
||||
if (m_initExpression)
|
||||
m_initExpression->accept(_visitor);
|
||||
if (m_condExpression)
|
||||
m_condExpression->accept(_visitor);
|
||||
if (m_loopExpression)
|
||||
m_loopExpression->accept(_visitor);
|
||||
m_body->accept(_visitor);
|
||||
}
|
||||
_visitor.endVisit(*this);
|
||||
@ -283,9 +286,12 @@ void ForStatement::accept(ASTConstVisitor& _visitor) const
|
||||
{
|
||||
if (_visitor.visit(*this))
|
||||
{
|
||||
m_initExpression->accept(_visitor);
|
||||
m_condExpression->accept(_visitor);
|
||||
m_loopExpression->accept(_visitor);
|
||||
if (m_initExpression)
|
||||
m_initExpression->accept(_visitor);
|
||||
if (m_condExpression)
|
||||
m_condExpression->accept(_visitor);
|
||||
if (m_loopExpression)
|
||||
m_loopExpression->accept(_visitor);
|
||||
m_body->accept(_visitor);
|
||||
}
|
||||
_visitor.endVisit(*this);
|
||||
|
17
Parser.cpp
17
Parser.cpp
@ -374,14 +374,25 @@ ASTPointer<WhileStatement> Parser::parseWhileStatement()
|
||||
ASTPointer<ForStatement> Parser::parseForStatement()
|
||||
{
|
||||
ASTNodeFactory nodeFactory(*this);
|
||||
ASTPointer<ASTNode> initExpression;
|
||||
ASTPointer<Expression> conditionExpression;
|
||||
ASTPointer<ExpressionStatement> loopExpression;
|
||||
expectToken(Token::FOR);
|
||||
expectToken(Token::LPAREN);
|
||||
ASTPointer<ASTNode> initExpression = parseVardefOrExprstatement();
|
||||
|
||||
// LTODO: Maybe here have some predicate like peekExpression() instead of checking for semicolon and RPAREN?
|
||||
if (m_scanner->getCurrentToken() != Token::SEMICOLON)
|
||||
initExpression = parseVardefOrExprstatement();
|
||||
expectToken(Token::SEMICOLON);
|
||||
ASTPointer<Expression> conditionExpression = parseExpression();
|
||||
|
||||
if (m_scanner->getCurrentToken() != Token::SEMICOLON)
|
||||
conditionExpression = parseExpression();
|
||||
expectToken(Token::SEMICOLON);
|
||||
ASTPointer<ExpressionStatement> loopExpression = parseExpressionStatement();
|
||||
|
||||
if (m_scanner->getCurrentToken() != Token::RPAREN)
|
||||
loopExpression = parseExpressionStatement();
|
||||
expectToken(Token::RPAREN);
|
||||
|
||||
ASTPointer<Statement> body = parseStatement();
|
||||
nodeFactory.setEndPositionFromNode(body);
|
||||
return nodeFactory.createNode<ForStatement>(initExpression,
|
||||
|
@ -20,7 +20,7 @@ Statement = IfStatement | WhileStatement | Block |
|
||||
|
||||
IfStatement = 'if' '(' Expression ')' Statement ( 'else' Statement )?
|
||||
WhileStatement = 'while' '(' Expression ')' Statement
|
||||
ForStatement = 'for' '(' VardefOrExpressionstatement ';' Expression ';' Expressionstatement ')' Statement
|
||||
ForStatement = 'for' '(' (VardefOrExpressionstatement)? ';' (Expression)? ';' (Expressionstatement)? ')' Statement
|
||||
Continue = 'continue' ';'
|
||||
Break = 'break' ';'
|
||||
Return = 'return' Expression? ';'
|
||||
|
Loading…
Reference in New Issue
Block a user