mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add/remove if statement mutation; also remove first instance and bail in all remove mutations
This commit is contained in:
parent
b6f9a2d380
commit
fc93d9e5f8
@ -108,7 +108,10 @@ static YulProtoMutator removeBreak(
|
|||||||
#endif
|
#endif
|
||||||
for (auto &stmt: *forStmt->mutable_for_body()->mutable_statements())
|
for (auto &stmt: *forStmt->mutable_for_body()->mutable_statements())
|
||||||
if (stmt.has_breakstmt())
|
if (stmt.has_breakstmt())
|
||||||
|
{
|
||||||
stmt.clear_breakstmt();
|
stmt.clear_breakstmt();
|
||||||
|
break;
|
||||||
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -158,7 +161,10 @@ static YulProtoMutator removeContinue(
|
|||||||
#endif
|
#endif
|
||||||
for (auto &stmt: *forStmt->mutable_for_body()->mutable_statements())
|
for (auto &stmt: *forStmt->mutable_for_body()->mutable_statements())
|
||||||
if (stmt.has_contstmt())
|
if (stmt.has_contstmt())
|
||||||
|
{
|
||||||
stmt.clear_contstmt();
|
stmt.clear_contstmt();
|
||||||
|
break;
|
||||||
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -361,7 +367,10 @@ static YulProtoMutator removeLeave(
|
|||||||
FunctionDef *funcDef = static_cast<FunctionDef*>(_message);
|
FunctionDef *funcDef = static_cast<FunctionDef*>(_message);
|
||||||
for (auto &stmt: *funcDef->mutable_block()->mutable_statements())
|
for (auto &stmt: *funcDef->mutable_block()->mutable_statements())
|
||||||
if (stmt.has_leave())
|
if (stmt.has_leave())
|
||||||
|
{
|
||||||
stmt.clear_leave();
|
stmt.clear_leave();
|
||||||
|
break;
|
||||||
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -411,7 +420,55 @@ static YulProtoMutator removeAssignment(
|
|||||||
Block *block = static_cast<Block*>(_message);
|
Block *block = static_cast<Block*>(_message);
|
||||||
for (auto &stmt: *block->mutable_statements())
|
for (auto &stmt: *block->mutable_statements())
|
||||||
if (stmt.has_assignment())
|
if (stmt.has_assignment())
|
||||||
|
{
|
||||||
stmt.clear_assignment();
|
stmt.clear_assignment();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Add if statement
|
||||||
|
static YulProtoMutator addIf(
|
||||||
|
Block::descriptor(),
|
||||||
|
[](google::protobuf::Message* _message, unsigned int _seed)
|
||||||
|
{
|
||||||
|
if (_seed % YulProtoMutator::s_mediumIP == 0) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
||||||
|
std::cout << "YULMUTATOR: Add if" << std::endl;
|
||||||
|
#endif
|
||||||
|
Block *block = static_cast<Block*>(_message);
|
||||||
|
Statement *stmt = block->add_statements();
|
||||||
|
IfStmt *ifStmt = new IfStmt();
|
||||||
|
stmt->set_allocated_ifstmt(ifStmt);
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Remove if statement
|
||||||
|
static YulProtoMutator removeIf(
|
||||||
|
Block::descriptor(),
|
||||||
|
[](google::protobuf::Message* _message, unsigned int _seed)
|
||||||
|
{
|
||||||
|
if (_seed % YulProtoMutator::s_mediumIP == 1) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
||||||
|
std::cout << "YULMUTATOR: Remove if" << std::endl;
|
||||||
|
#endif
|
||||||
|
Block *block = static_cast<Block*>(_message);
|
||||||
|
for (auto &stmt: *block->mutable_statements())
|
||||||
|
if (stmt.has_ifstmt())
|
||||||
|
{
|
||||||
|
stmt.clear_ifstmt();
|
||||||
|
break;
|
||||||
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user