diff options
author | Lu Guanqun <guanqun.lu@gmail.com> | 2015-12-23 00:50:24 +0800 |
---|---|---|
committer | Lu Guanqun <guanqun.lu@gmail.com> | 2016-01-23 01:14:00 +0800 |
commit | ff4f1666ab913ae3b90bc0af1477c2042f5ad535 (patch) | |
tree | b05d2f38e06628f38f686a3581e6161c791f686f | |
parent | 047172eb9a49df200b3a046751e90f52fc64999f (diff) | |
download | dexon-solidity-ff4f1666ab913ae3b90bc0af1477c2042f5ad535.tar.gz dexon-solidity-ff4f1666ab913ae3b90bc0af1477c2042f5ad535.tar.zst dexon-solidity-ff4f1666ab913ae3b90bc0af1477c2042f5ad535.zip |
[cond-expr] generate assembly for _ ? _ : _
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 15 | ||||
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.h | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 040217da..6dd9d005 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -176,6 +176,21 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction); } +bool ExpressionCompiler::visit(Conditional const& _condition) +{ + CompilerContext::LocationSetter locationSetter(m_context, _condition); + _condition.condition().accept(*this); + m_context << eth::Instruction::ISZERO; + eth::AssemblyItem falseTag = m_context.appendConditionalJump(); + _condition.trueExpression().accept(*this); + eth::AssemblyItem endTag = m_context.appendJumpToNew(); + m_context << falseTag; + m_context.adjustStackOffset(-1); + _condition.falseExpression().accept(*this); + m_context << endTag; + return false; +} + bool ExpressionCompiler::visit(Assignment const& _assignment) { CompilerContext::LocationSetter locationSetter(m_context, _assignment); diff --git a/libsolidity/codegen/ExpressionCompiler.h b/libsolidity/codegen/ExpressionCompiler.h index 379aa65a..f00b24e8 100644 --- a/libsolidity/codegen/ExpressionCompiler.h +++ b/libsolidity/codegen/ExpressionCompiler.h @@ -71,6 +71,7 @@ public: void appendConstStateVariableAccessor(const VariableDeclaration& _varDecl); private: + virtual bool visit(Conditional const& _condition) override; virtual bool visit(Assignment const& _assignment) override; virtual bool visit(TupleExpression const& _tuple) override; virtual bool visit(UnaryOperation const& _unaryOperation) override; |