mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
WIP
This commit is contained in:
parent
66d625aa21
commit
f900fe7262
@ -56,5 +56,6 @@
|
|||||||
MACRO(SourceUnitGenerator) SEP \
|
MACRO(SourceUnitGenerator) SEP \
|
||||||
MACRO(StatementGenerator) SEP \
|
MACRO(StatementGenerator) SEP \
|
||||||
MACRO(TestCaseGenerator) SEP \
|
MACRO(TestCaseGenerator) SEP \
|
||||||
|
MACRO(TryCatchStmtGenerator) SEP \
|
||||||
MACRO(VarDeclStmtGenerator) SEP \
|
MACRO(VarDeclStmtGenerator) SEP \
|
||||||
MACRO(WhileStmtGenerator) ENDSEP
|
MACRO(WhileStmtGenerator) ENDSEP
|
||||||
|
@ -1567,13 +1567,36 @@ string FunctionCallGenerator::callStmt(shared_ptr<FunctionState> _callee)
|
|||||||
return callStmtStream.str();
|
return callStmtStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string FunctionCallGenerator::generateTryCatchCall()
|
||||||
|
{
|
||||||
|
set<shared_ptr<FunctionState>> availableFunctions;
|
||||||
|
if (state->insideContract)
|
||||||
|
availableFunctions = state->currentContractState()->functions;
|
||||||
|
if (availableFunctions.empty())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
shared_ptr<FunctionState> callee;
|
||||||
|
if (availableFunctions.size() > 1)
|
||||||
|
{
|
||||||
|
for (auto const& i: availableFunctions)
|
||||||
|
if (uRandDist()->probable(availableFunctions.size()))
|
||||||
|
callee = i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
callee = *availableFunctions.begin();
|
||||||
|
|
||||||
|
if (callee)
|
||||||
|
{
|
||||||
|
ostringstream tryCatchCall;
|
||||||
|
// TODO: Implement try-catch stmt
|
||||||
|
return tryCatchCall.str();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
string FunctionCallGenerator::visit()
|
string FunctionCallGenerator::visit()
|
||||||
{
|
{
|
||||||
// // TODO: Generalise call to varargs function
|
|
||||||
// for (auto const& f: state->currentFunctionState()->inputs)
|
|
||||||
// if (holds_alternative<shared_ptr<FunctionType>>(f.first))
|
|
||||||
// return indentation() + f.second + "();\n";
|
|
||||||
|
|
||||||
// Consolidate available functions
|
// Consolidate available functions
|
||||||
auto availableFunctions = state->currentSourceState()->freeFunctions;
|
auto availableFunctions = state->currentSourceState()->freeFunctions;
|
||||||
if (state->insideContract)
|
if (state->insideContract)
|
||||||
@ -1597,6 +1620,25 @@ string FunctionCallGenerator::visit()
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string TryCatchStmtGenerator::visit()
|
||||||
|
{
|
||||||
|
auto availableFunctions = state->currentSourceState()->freeFunctions;
|
||||||
|
if (state->insideContract)
|
||||||
|
availableFunctions += state->currentContractState()->functions;
|
||||||
|
if (availableFunctions.empty())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
shared_ptr<FunctionState> callee;
|
||||||
|
if (availableFunctions.size() > 1)
|
||||||
|
{
|
||||||
|
for (auto const& i: availableFunctions)
|
||||||
|
if (uRandDist()->probable(availableFunctions.size()))
|
||||||
|
callee = i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
callee = *availableFunctions.begin();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
shared_ptr<T> SolidityGenerator::generator()
|
shared_ptr<T> SolidityGenerator::generator()
|
||||||
{
|
{
|
||||||
|
@ -1281,9 +1281,23 @@ public:
|
|||||||
{
|
{
|
||||||
return "Function call generator";
|
return "Function call generator";
|
||||||
}
|
}
|
||||||
|
std::string generateTryCatchCall();
|
||||||
private:
|
private:
|
||||||
std::string lhs(std::vector<std::pair<SolidityTypePtr, std::string>>& _functionReturnTypeNames);
|
std::string lhs(std::vector<std::pair<SolidityTypePtr, std::string>>& _functionReturnTypeNames);
|
||||||
std::optional<std::string> rhs(std::vector<std::pair<SolidityTypePtr, std::string>>& _functionInputTypeNames);
|
std::optional<std::string> rhs(std::vector<std::pair<SolidityTypePtr, std::string>>& _functionInputTypeNames);
|
||||||
std::string callStmt(std::shared_ptr<FunctionState> _callee);
|
std::string callStmt(std::shared_ptr<FunctionState> _callee);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TryCatchStmtGenerator: public GeneratorBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TryCatchStmtGenerator(SolidityGenerator* _mutator):
|
||||||
|
GeneratorBase(std::move(_mutator))
|
||||||
|
{}
|
||||||
|
std::string visit() override;
|
||||||
|
std::string name() override
|
||||||
|
{
|
||||||
|
return "Try/Catch statement generator";
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user