diff options
author | Rhett Aultman <roadriverrail@gmail.com> | 2016-07-30 15:13:05 +0800 |
---|---|---|
committer | Rhett Aultman <roadriverrail@gmail.com> | 2016-11-10 23:07:25 +0800 |
commit | 4524ad08701939cc22d28494c57dda1cdfba9e10 (patch) | |
tree | 70ff8928bf6a84f50e2ca54d355be81db01e7bcd /libsolidity/parsing | |
parent | dc8a5f4ef5505f2aeb017dfa4c9aca77a9fd93aa (diff) | |
download | dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.tar dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.tar.gz dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.tar.bz2 dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.tar.lz dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.tar.xz dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.tar.zst dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.zip |
Add support for do/while loops
This commit adds support for a standard do <statement> while <expr>;
form of statement. While loops were already being supported; supporting
a do/while loop mostly involves reusing code from while loops but putting
the conditional checking last.
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 19 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.h | 1 |
2 files changed, 19 insertions, 1 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 0e99d1e7..52b53619 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -722,6 +722,8 @@ ASTPointer<Statement> Parser::parseStatement() return parseIfStatement(docString); case Token::While: return parseWhileStatement(docString); + case Token::Do: + return parseDoWhileStatement(docString); case Token::For: return parseForStatement(docString); case Token::LBrace: @@ -816,9 +818,24 @@ ASTPointer<WhileStatement> Parser::parseWhileStatement(ASTPointer<ASTString> con expectToken(Token::RParen); ASTPointer<Statement> body = parseStatement(); nodeFactory.setEndPositionFromNode(body); - return nodeFactory.createNode<WhileStatement>(_docString, condition, body); + return nodeFactory.createNode<WhileStatement>(_docString, condition, body, false); } +ASTPointer<WhileStatement> Parser::parseDoWhileStatement(ASTPointer<ASTString> const& _docString) +{ + ASTNodeFactory nodeFactory(*this); + expectToken(Token::Do); + ASTPointer<Statement> body = parseStatement(); + expectToken(Token::While); + expectToken(Token::LParen); + ASTPointer<Expression> condition = parseExpression(); + expectToken(Token::RParen); + nodeFactory.markEndPosition(); + expectToken(Token::Semicolon); + return nodeFactory.createNode<WhileStatement>(_docString, condition, body, true); +} + + ASTPointer<ForStatement> Parser::parseForStatement(ASTPointer<ASTString> const& _docString) { ASTNodeFactory nodeFactory(*this); diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 9c30cf60..26f347cb 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -85,6 +85,7 @@ private: ASTPointer<InlineAssembly> parseInlineAssembly(ASTPointer<ASTString> const& _docString = {}); ASTPointer<IfStatement> parseIfStatement(ASTPointer<ASTString> const& _docString); ASTPointer<WhileStatement> parseWhileStatement(ASTPointer<ASTString> const& _docString); + ASTPointer<WhileStatement> parseDoWhileStatement(ASTPointer<ASTString> const& _docString); ASTPointer<ForStatement> parseForStatement(ASTPointer<ASTString> const& _docString); /// A "simple statement" can be a variable declaration statement or an expression statement. ASTPointer<Statement> parseSimpleStatement(ASTPointer<ASTString> const& _docString); |