mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Yul] Support conditionals
This commit is contained in:
@@ -180,6 +180,24 @@ void IRGeneratorForStatements::endVisit(VariableDeclarationStatement const& _var
|
||||
declare(m_context.addLocalVariable(*decl));
|
||||
}
|
||||
|
||||
bool IRGeneratorForStatements::visit(Conditional const& _conditional)
|
||||
{
|
||||
_conditional.condition().accept(*this);
|
||||
|
||||
string condition = expressionAsType(_conditional.condition(), *TypeProvider::boolean());
|
||||
declare(_conditional);
|
||||
|
||||
m_code << "switch " << condition << "\n" "case 0 {\n";
|
||||
_conditional.falseExpression().accept(*this);
|
||||
assign(_conditional, _conditional.falseExpression());
|
||||
m_code << "}\n" "default {\n";
|
||||
_conditional.trueExpression().accept(*this);
|
||||
assign(_conditional, _conditional.trueExpression());
|
||||
m_code << "}\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRGeneratorForStatements::visit(Assignment const& _assignment)
|
||||
{
|
||||
_assignment.rightHandSide().accept(*this);
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
void initializeStateVar(VariableDeclaration const& _varDecl);
|
||||
|
||||
void endVisit(VariableDeclarationStatement const& _variableDeclaration) override;
|
||||
bool visit(Conditional const& _conditional) override;
|
||||
bool visit(Assignment const& _assignment) override;
|
||||
bool visit(TupleExpression const& _tuple) override;
|
||||
bool visit(IfStatement const& _ifStatement) override;
|
||||
|
||||
Reference in New Issue
Block a user