Merge pull request #6333 from ethereum/proto-add-for-switch-stmts

Proto support for "for" and "switch" statements
This commit is contained in:
Alex Beregszaszi 2019-03-20 19:24:45 +00:00 committed by GitHub
commit 56f2912e61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 0 deletions

View File

@ -235,6 +235,31 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, StoreFunc const& _x)
return _os;
}
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, ForStmt const& _x)
{
_os << "for { let i := 0 } lt(i, 0x100) { i := add(i, 0x20) } ";
return _os << _x.for_body();
}
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, CaseStmt const& _x)
{
_os << "case " << _x.case_lit() << " ";
return _os << _x.case_block();
}
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, SwitchStmt const& _x)
{
if (_x.case_stmt_size() > 0 || _x.has_default_block())
{
_os << "switch " << _x.switch_expr() << "\n";
for (auto const& caseStmt: _x.case_stmt())
_os << caseStmt;
if (_x.has_default_block())
_os << "default " << _x.default_block();
}
return _os;
}
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Statement const& _x)
{
switch (_x.stmt_oneof_case())
@ -254,6 +279,12 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Statement const& _x)
case Statement::kBlockstmt:
_os << _x.blockstmt();
break;
case Statement::kForstmt:
_os << _x.forstmt();
break;
case Statement::kSwitchstmt:
_os << _x.switchstmt();
break;
case Statement::STMT_ONEOF_NOT_SET:
break;
}

View File

@ -46,6 +46,9 @@ std::ostream& operator<<(std::ostream& _os, StoreFunc const& _x);
std::ostream& operator<<(std::ostream& _os, Statement const& _x);
std::ostream& operator<<(std::ostream& _os, Block const& _x);
std::ostream& operator<<(std::ostream& _os, Function const& _x);
std::ostream& operator<<(std::ostream& _os, ForStmt const& _x);
std::ostream& operator<<(std::ostream& _os, CaseStmt const& _x);
std::ostream& operator<<(std::ostream& _os, SwitchStmt const& _x);
}
}
}

View File

@ -139,6 +139,21 @@ message IfStmt {
required Block if_body = 2;
}
message ForStmt {
required Block for_body = 2;
}
message CaseStmt {
required Literal case_lit = 1;
required Block case_block = 2;
}
message SwitchStmt {
required Expression switch_expr = 1;
repeated CaseStmt case_stmt = 2;
optional Block default_block = 3;
}
message Statement {
oneof stmt_oneof {
VarDecl decl = 1;
@ -146,6 +161,8 @@ message Statement {
IfStmt ifstmt = 3;
StoreFunc storage_func = 4;
Block blockstmt = 5;
ForStmt forstmt = 6;
SwitchStmt switchstmt = 7;
}
}