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/codegen | |
parent | dc8a5f4ef5505f2aeb017dfa4c9aca77a9fd93aa (diff) | |
download | dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.tar.gz 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/codegen')
-rw-r--r-- | libsolidity/codegen/ContractCompiler.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index ebb84784..1404963f 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -611,12 +611,25 @@ bool ContractCompiler::visit(WhileStatement const& _whileStatement) m_breakTags.push_back(loopEnd); m_context << loopStart; - compileExpression(_whileStatement.condition()); - m_context << Instruction::ISZERO; - m_context.appendConditionalJumpTo(loopEnd); + + // While loops have the condition prepended + if (!_whileStatement.isDoWhile()) + { + compileExpression(_whileStatement.condition()); + m_context << Instruction::ISZERO; + m_context.appendConditionalJumpTo(loopEnd); + } _whileStatement.body().accept(*this); + // Do-while loops have the condition appended + if (_whileStatement.isDoWhile()) + { + compileExpression(_whileStatement.condition()); + m_context << Instruction::ISZERO; + m_context.appendConditionalJumpTo(loopEnd); + } + m_context.appendJumpTo(loopStart); m_context << loopEnd; |