Introduce expression statement.

This commit is contained in:
Bhargava Shastry 2021-05-20 11:12:51 +02:00
parent c5f92c6bdc
commit c007e16ee5
3 changed files with 27 additions and 2 deletions

View File

@ -44,6 +44,7 @@
MACRO(AssignmentStmtGenerator) SEP \
MACRO(BlockStmtGenerator) SEP \
MACRO(ContractGenerator) SEP \
MACRO(ExpressionStmtGenerator) SEP \
MACRO(FunctionCallGenerator) SEP \
MACRO(FunctionGenerator) SEP \
MACRO(ImportGenerator) SEP \

View File

@ -425,12 +425,24 @@ string AssignmentStmtGenerator::visit()
return indentation() + lhs.value().second + assignOp(operation) + rhs.value().second + ";\n";
}
string ExpressionStmtGenerator::visit()
{
ExpressionGenerator exprGen{state};
auto randomType = TypeProvider{state}.type();
auto expression = exprGen.rOrLValueExpression({randomType, {}});
if (expression.has_value())
return indentation() + expression.value().second + ";\n";
else
return "\n";
}
void StatementGenerator::setup()
{
set<pair<GeneratorPtr, unsigned>> dependsOn = {
{mutator->generator<BlockStmtGenerator>(), 1},
{mutator->generator<AssignmentStmtGenerator>(), 1},
{mutator->generator<FunctionCallGenerator>(), 1}
{mutator->generator<FunctionCallGenerator>(), 1},
{mutator->generator<ExpressionStmtGenerator>(), 1}
};
addGenerators(std::move(dependsOn));
}

View File

@ -816,7 +816,6 @@ struct ExpressionGenerator
std::pair<SolidityTypePtr, std::string>& _typeName
);
void incrementNestingDepth()
{
nestingDepth++;
@ -1056,6 +1055,19 @@ private:
static constexpr unsigned s_uncheckedBlockInvProb = 37;
};
class ExpressionStmtGenerator: public GeneratorBase
{
public:
explicit ExpressionStmtGenerator(SolidityGenerator* _mutator):
GeneratorBase(std::move(_mutator))
{}
std::string visit() override;
std::string name() override
{
return "Expression statement generator";
}
};
class AssignmentStmtGenerator: public GeneratorBase
{
public: