Add assignment statement

This commit is contained in:
Bhargava Shastry 2021-04-30 16:26:33 +02:00
parent f6242ef6b7
commit c87d788f78
2 changed files with 24 additions and 3 deletions

View File

@ -274,7 +274,7 @@ string AssignmentStmtGenerator::visit()
auto rhs = exprGen.expression(lhs.value().first);
if (!rhs.has_value())
return "\n";
return lhs.value().second + " = " + rhs.value().second + ";\n";
return indentation() + lhs.value().second + " = " + rhs.value().second + ";\n";
}
void StatementGenerator::setup()
@ -346,6 +346,7 @@ string FunctionGenerator::visit()
function << " returns"
<< state->currentFunctionState()->params(FunctionState::Params::OUTPUT);
function << "\n" << generator<BlockStmtGenerator>()->visit();
generator<BlockStmtGenerator>()->endVisit();
return function.str();
}
@ -383,10 +384,14 @@ optional<pair<SolidityTypePtr, string>> ExpressionGenerator::expression()
optional<pair<SolidityTypePtr, string>> ExpressionGenerator::expression(SolidityTypePtr _type)
{
auto liveTypedVariables = state->currentFunctionState()->inputs |
ranges::views::filter([&_type](auto& _item) { return _item.first == _type; }) |
ranges::views::filter([&_type](auto& _item) {
return _item.first.index() == _type.index() && visit(TypeComparator{}, _item.first, _type);
}) |
ranges::to<vector<pair<SolidityTypePtr, string>>>();
liveTypedVariables += state->currentFunctionState()->outputs |
ranges::views::filter([&_type](auto& _item) { return _item.first == _type; }) |
ranges::views::filter([&_type](auto& _item) {
return _item.first.index() == _type.index() && visit(TypeComparator{}, _item.first, _type);
}) |
ranges::to<vector<pair<SolidityTypePtr, string>>>();
if (liveTypedVariables.empty())
return nullopt;

View File

@ -614,6 +614,22 @@ struct TypeProvider
std::shared_ptr<TestState> state;
};
struct TypeComparator
{
template <typename T>
bool operator()(T _i1, T _i2)
{
return *_i1 == *_i2;
}
template <typename T1, typename T2>
bool operator()(T1 _i1, T2 _i2)
{
if (std::is_same_v<T1, T2>)
return this->template operator()(_i1, _i2);
return false;
}
};
struct ExpressionGenerator
{
ExpressionGenerator(std::shared_ptr<TestState> _state): state(std::move(_state))