mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Implement block nesting depth properly
This commit is contained in:
parent
c87d788f78
commit
86fec73a8c
@ -301,7 +301,6 @@ string BlockStmtGenerator::visit()
|
||||
{
|
||||
if (nestingTooDeep())
|
||||
return "\n";
|
||||
|
||||
incrementNestingDepth();
|
||||
ostringstream block;
|
||||
block << indentation() + "{\n";
|
||||
@ -345,11 +344,21 @@ string FunctionGenerator::visit()
|
||||
if (!state->currentFunctionState()->outputs.empty())
|
||||
function << " returns"
|
||||
<< state->currentFunctionState()->params(FunctionState::Params::OUTPUT);
|
||||
function << "\n" << generator<BlockStmtGenerator>()->visit();
|
||||
generator<BlockStmtGenerator>()->endVisit();
|
||||
ostringstream block;
|
||||
// Since visitChildren() may not visit block stmt, we default to an empty
|
||||
// block.
|
||||
block << visitChildren();
|
||||
if (block.str().empty())
|
||||
block << indentation() << "{ }\n";
|
||||
function << "\n" << block.str();
|
||||
return function.str();
|
||||
}
|
||||
|
||||
void FunctionGenerator::endVisit()
|
||||
{
|
||||
mutator->generator<BlockStmtGenerator>()->resetNestingDepth();
|
||||
}
|
||||
|
||||
pair<SolidityTypePtr, string> ExpressionGenerator::randomLValueExpression()
|
||||
{
|
||||
LValueExpr exprType = static_cast<LValueExpr>(
|
||||
|
@ -288,13 +288,13 @@ public:
|
||||
{
|
||||
return name();
|
||||
}
|
||||
std::string name()
|
||||
std::string name() const
|
||||
{
|
||||
return contractName;
|
||||
}
|
||||
bool operator==(ContractType const&)
|
||||
bool operator==(ContractType const& _rhs)
|
||||
{
|
||||
return true;
|
||||
return _rhs.name() == this->name();
|
||||
}
|
||||
std::string contractName;
|
||||
};
|
||||
@ -530,7 +530,8 @@ struct TestState
|
||||
}
|
||||
void addSource()
|
||||
{
|
||||
updateSourcePath(newPath());
|
||||
std::string path = newPath();
|
||||
updateSourcePath(path);
|
||||
}
|
||||
/// Increments indentation level globally.
|
||||
void indent()
|
||||
@ -806,6 +807,7 @@ public:
|
||||
{}
|
||||
std::string visit() override;
|
||||
std::string name() override { return "Function generator"; }
|
||||
void endVisit() override;
|
||||
void setup() override;
|
||||
/// Sets @name m_freeFunction to @param _freeFunction.
|
||||
void scope(bool _freeFunction)
|
||||
@ -849,12 +851,20 @@ public:
|
||||
{}
|
||||
void endVisit() override
|
||||
{
|
||||
m_nestingDepth = 0;
|
||||
decrementNestingDepth();
|
||||
}
|
||||
void incrementNestingDepth()
|
||||
{
|
||||
++m_nestingDepth;
|
||||
}
|
||||
void decrementNestingDepth()
|
||||
{
|
||||
--m_nestingDepth;
|
||||
}
|
||||
void resetNestingDepth()
|
||||
{
|
||||
m_nestingDepth = 0;
|
||||
}
|
||||
bool nestingTooDeep()
|
||||
{
|
||||
return m_nestingDepth > s_maxNestingDepth;
|
||||
|
Loading…
Reference in New Issue
Block a user