mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Introduce if statement
This commit is contained in:
parent
c007e16ee5
commit
d1b7078d8d
@ -47,6 +47,7 @@
|
||||
MACRO(ExpressionStmtGenerator) SEP \
|
||||
MACRO(FunctionCallGenerator) SEP \
|
||||
MACRO(FunctionGenerator) SEP \
|
||||
MACRO(IfStmtGenerator) SEP \
|
||||
MACRO(ImportGenerator) SEP \
|
||||
MACRO(PragmaGenerator) SEP \
|
||||
MACRO(SourceUnitGenerator) SEP \
|
||||
|
@ -436,13 +436,45 @@ string ExpressionStmtGenerator::visit()
|
||||
return "\n";
|
||||
}
|
||||
|
||||
void IfStmtGenerator::setup()
|
||||
{
|
||||
set<pair<GeneratorPtr, unsigned>> dependsOn = {
|
||||
{mutator->generator<BlockStmtGenerator>(), 1},
|
||||
};
|
||||
addGenerators(std::move(dependsOn));
|
||||
}
|
||||
|
||||
string IfStmtGenerator::visit()
|
||||
{
|
||||
ostringstream ifStmt;
|
||||
ExpressionGenerator exprGen{state};
|
||||
auto boolType = make_shared<BoolType>();
|
||||
auto expression = exprGen.rOrLValueExpression({boolType, {}});
|
||||
if (expression.has_value())
|
||||
ifStmt << indentation()
|
||||
<< "if ("
|
||||
<< expression.value().second
|
||||
<< ")\n";
|
||||
else
|
||||
return "\n";
|
||||
// Make sure block stmt generator does not output an unchecked block
|
||||
mutator->generator<BlockStmtGenerator>()->unchecked(false);
|
||||
ostringstream ifBlock;
|
||||
ifBlock << visitChildren();
|
||||
if (ifBlock.str().empty())
|
||||
ifBlock << indentation() << "{ }\n";
|
||||
ifStmt << ifBlock.str();
|
||||
return ifStmt.str();
|
||||
}
|
||||
|
||||
void StatementGenerator::setup()
|
||||
{
|
||||
set<pair<GeneratorPtr, unsigned>> dependsOn = {
|
||||
{mutator->generator<BlockStmtGenerator>(), 1},
|
||||
{mutator->generator<AssignmentStmtGenerator>(), 1},
|
||||
{mutator->generator<FunctionCallGenerator>(), 1},
|
||||
{mutator->generator<ExpressionStmtGenerator>(), 1}
|
||||
{mutator->generator<ExpressionStmtGenerator>(), 1},
|
||||
{mutator->generator<IfStmtGenerator>(), 2},
|
||||
};
|
||||
addGenerators(std::move(dependsOn));
|
||||
}
|
||||
@ -488,7 +520,7 @@ void BlockStmtGenerator::setup()
|
||||
string BlockStmtGenerator::visit()
|
||||
{
|
||||
if (nestingTooDeep())
|
||||
return "\n";
|
||||
return indentation() + "{ }\n";
|
||||
incrementNestingDepth();
|
||||
ostringstream block;
|
||||
if (unchecked() && !m_inUnchecked)
|
||||
|
@ -1068,6 +1068,17 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class IfStmtGenerator: public GeneratorBase
|
||||
{
|
||||
public:
|
||||
explicit IfStmtGenerator(SolidityGenerator* _mutator):
|
||||
GeneratorBase(std::move(_mutator))
|
||||
{}
|
||||
void setup() override;
|
||||
std::string visit() override;
|
||||
std::string name() override { return "If statement generator"; }
|
||||
};
|
||||
|
||||
class AssignmentStmtGenerator: public GeneratorBase
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user