Fix bug in break/continue placement and introduce do-while loops.

This commit is contained in:
Bhargava Shastry 2021-06-08 14:17:56 +02:00
parent 0d8800eec4
commit 55932cf5eb
2 changed files with 20 additions and 10 deletions

View File

@ -518,6 +518,11 @@ string WhileStmtGenerator::visit()
pair<SolidityTypePtr, string> boolTypeName = {boolType, {}};
auto expression = exprGen.rLValueOrLiteral(boolTypeName);
solAssert(expression.has_value(), "");
bool doWhile = uRandDist()->probable(2);
if (doWhile)
whileStmt << indentation()
<< "do\n";
else
whileStmt << indentation()
<< "while ("
<< expression.value().second
@ -529,6 +534,11 @@ string WhileStmtGenerator::visit()
if (whileBlock.str().empty())
whileBlock << indentation() << "{ }\n";
whileStmt << whileBlock.str();
if (doWhile)
whileStmt << indentation()
<< "while ("
<< expression.value().second
<< ")\n";
return whileStmt.str();
}

View File

@ -30,6 +30,7 @@
#include <memory>
#include <random>
#include <set>
#include <stack>
#include <variant>
#include <range/v3/algorithm/all_of.hpp>
@ -525,7 +526,7 @@ struct TestState
numFunctions(0),
indentationLevel(0),
insideContract(false),
loopState(false, false)
loopState({false})
{}
/// Adds @param _path to @name sourceUnitPaths updates
/// @name currentSourceUnitPath.
@ -652,16 +653,15 @@ struct TestState
}
void enterLoop()
{
loopState.wasLoop = loopState.inLoop;
loopState.inLoop = true;
loopState.push(true);
}
void exitLoop()
{
loopState.inLoop = loopState.wasLoop;
loopState.pop();
}
bool inLoop()
{
return loopState.inLoop;
return loopState.top();
}
~TestState()
{
@ -703,7 +703,7 @@ struct TestState
/// Contract scope
bool insideContract;
/// Loop state
LoopState loopState;
std::stack<bool> loopState;
/// Source name prefix
std::string const sourceUnitNamePrefix = "su";
/// Contract name prefix