mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix bug in break/continue placement and introduce do-while loops.
This commit is contained in:
parent
0d8800eec4
commit
55932cf5eb
@ -518,10 +518,15 @@ string WhileStmtGenerator::visit()
|
|||||||
pair<SolidityTypePtr, string> boolTypeName = {boolType, {}};
|
pair<SolidityTypePtr, string> boolTypeName = {boolType, {}};
|
||||||
auto expression = exprGen.rLValueOrLiteral(boolTypeName);
|
auto expression = exprGen.rLValueOrLiteral(boolTypeName);
|
||||||
solAssert(expression.has_value(), "");
|
solAssert(expression.has_value(), "");
|
||||||
whileStmt << indentation()
|
bool doWhile = uRandDist()->probable(2);
|
||||||
<< "while ("
|
if (doWhile)
|
||||||
<< expression.value().second
|
whileStmt << indentation()
|
||||||
<< ")\n";
|
<< "do\n";
|
||||||
|
else
|
||||||
|
whileStmt << indentation()
|
||||||
|
<< "while ("
|
||||||
|
<< expression.value().second
|
||||||
|
<< ")\n";
|
||||||
// Make sure block stmt generator does not output an unchecked block
|
// Make sure block stmt generator does not output an unchecked block
|
||||||
mutator->generator<BlockStmtGenerator>()->unchecked(false);
|
mutator->generator<BlockStmtGenerator>()->unchecked(false);
|
||||||
ostringstream whileBlock;
|
ostringstream whileBlock;
|
||||||
@ -529,6 +534,11 @@ string WhileStmtGenerator::visit()
|
|||||||
if (whileBlock.str().empty())
|
if (whileBlock.str().empty())
|
||||||
whileBlock << indentation() << "{ }\n";
|
whileBlock << indentation() << "{ }\n";
|
||||||
whileStmt << whileBlock.str();
|
whileStmt << whileBlock.str();
|
||||||
|
if (doWhile)
|
||||||
|
whileStmt << indentation()
|
||||||
|
<< "while ("
|
||||||
|
<< expression.value().second
|
||||||
|
<< ")\n";
|
||||||
return whileStmt.str();
|
return whileStmt.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <stack>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
#include <range/v3/algorithm/all_of.hpp>
|
#include <range/v3/algorithm/all_of.hpp>
|
||||||
@ -525,7 +526,7 @@ struct TestState
|
|||||||
numFunctions(0),
|
numFunctions(0),
|
||||||
indentationLevel(0),
|
indentationLevel(0),
|
||||||
insideContract(false),
|
insideContract(false),
|
||||||
loopState(false, false)
|
loopState({false})
|
||||||
{}
|
{}
|
||||||
/// Adds @param _path to @name sourceUnitPaths updates
|
/// Adds @param _path to @name sourceUnitPaths updates
|
||||||
/// @name currentSourceUnitPath.
|
/// @name currentSourceUnitPath.
|
||||||
@ -652,16 +653,15 @@ struct TestState
|
|||||||
}
|
}
|
||||||
void enterLoop()
|
void enterLoop()
|
||||||
{
|
{
|
||||||
loopState.wasLoop = loopState.inLoop;
|
loopState.push(true);
|
||||||
loopState.inLoop = true;
|
|
||||||
}
|
}
|
||||||
void exitLoop()
|
void exitLoop()
|
||||||
{
|
{
|
||||||
loopState.inLoop = loopState.wasLoop;
|
loopState.pop();
|
||||||
}
|
}
|
||||||
bool inLoop()
|
bool inLoop()
|
||||||
{
|
{
|
||||||
return loopState.inLoop;
|
return loopState.top();
|
||||||
}
|
}
|
||||||
~TestState()
|
~TestState()
|
||||||
{
|
{
|
||||||
@ -703,7 +703,7 @@ struct TestState
|
|||||||
/// Contract scope
|
/// Contract scope
|
||||||
bool insideContract;
|
bool insideContract;
|
||||||
/// Loop state
|
/// Loop state
|
||||||
LoopState loopState;
|
std::stack<bool> loopState;
|
||||||
/// Source name prefix
|
/// Source name prefix
|
||||||
std::string const sourceUnitNamePrefix = "su";
|
std::string const sourceUnitNamePrefix = "su";
|
||||||
/// Contract name prefix
|
/// Contract name prefix
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user