mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use shared_ptr refs where possible.
This commit is contained in:
parent
321e09b62f
commit
d93339a209
@ -53,9 +53,10 @@ SolidityCustomMutatorInterface::SolidityCustomMutatorInterface(
|
|||||||
):
|
):
|
||||||
data(_data),
|
data(_data),
|
||||||
size(_size),
|
size(_size),
|
||||||
maxMutantSize(_maxSize),
|
maxMutantSize(_maxSize)
|
||||||
generator(make_shared<SolidityGenerator>(_seed))
|
{
|
||||||
{}
|
generator = make_shared<SolidityGenerator>(_seed);
|
||||||
|
}
|
||||||
|
|
||||||
size_t SolidityCustomMutatorInterface::generate()
|
size_t SolidityCustomMutatorInterface::generate()
|
||||||
{
|
{
|
||||||
|
@ -33,10 +33,9 @@ using namespace solidity::test::fuzzer::mutator;
|
|||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
GeneratorBase::GeneratorBase(SolidityGenerator* _mutator)
|
GeneratorBase::GeneratorBase(SolidityGenerator* _mutator): state(_mutator->testState())
|
||||||
{
|
{
|
||||||
mutator = _mutator;
|
mutator = _mutator;
|
||||||
state = mutator->testState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string GeneratorBase::visitChildren()
|
string GeneratorBase::visitChildren()
|
||||||
|
@ -347,10 +347,10 @@ struct FunctionState;
|
|||||||
struct SourceState
|
struct SourceState
|
||||||
{
|
{
|
||||||
explicit SourceState(
|
explicit SourceState(
|
||||||
std::shared_ptr<UniformRandomDistribution> _urd,
|
std::shared_ptr<UniformRandomDistribution>& _urd,
|
||||||
std::string _sourceName
|
std::string _sourceName
|
||||||
):
|
):
|
||||||
uRandDist(std::move(_urd)),
|
uRandDist(_urd),
|
||||||
importedSources({}),
|
importedSources({}),
|
||||||
sourceName(_sourceName)
|
sourceName(_sourceName)
|
||||||
{}
|
{}
|
||||||
@ -417,7 +417,7 @@ struct SourceState
|
|||||||
}
|
}
|
||||||
/// Prints source state to @param _os.
|
/// Prints source state to @param _os.
|
||||||
void print(std::ostream& _os) const;
|
void print(std::ostream& _os) const;
|
||||||
std::shared_ptr<UniformRandomDistribution> uRandDist;
|
std::shared_ptr<UniformRandomDistribution>& uRandDist;
|
||||||
std::set<std::string> importedSources;
|
std::set<std::string> importedSources;
|
||||||
std::map<SolidityTypePtr, std::string> exports;
|
std::map<SolidityTypePtr, std::string> exports;
|
||||||
std::set<std::shared_ptr<FunctionState>> freeFunctions;
|
std::set<std::shared_ptr<FunctionState>> freeFunctions;
|
||||||
@ -485,10 +485,10 @@ struct FunctionState
|
|||||||
struct ContractState
|
struct ContractState
|
||||||
{
|
{
|
||||||
explicit ContractState(
|
explicit ContractState(
|
||||||
std::shared_ptr<UniformRandomDistribution> _urd,
|
std::shared_ptr<UniformRandomDistribution>& _urd,
|
||||||
std::string _contractName
|
std::string _contractName
|
||||||
):
|
):
|
||||||
uRandDist(std::move(_urd)),
|
uRandDist(_urd),
|
||||||
name(_contractName)
|
name(_contractName)
|
||||||
{}
|
{}
|
||||||
~ContractState()
|
~ContractState()
|
||||||
@ -502,19 +502,19 @@ struct ContractState
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::set<std::shared_ptr<FunctionState>> functions;
|
std::set<std::shared_ptr<FunctionState>> functions;
|
||||||
std::shared_ptr<UniformRandomDistribution> uRandDist;
|
std::shared_ptr<UniformRandomDistribution>& uRandDist;
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TestState
|
struct TestState
|
||||||
{
|
{
|
||||||
explicit TestState(std::shared_ptr<UniformRandomDistribution> _urd):
|
explicit TestState(std::shared_ptr<UniformRandomDistribution>& _urd):
|
||||||
sourceUnitState({}),
|
sourceUnitState({}),
|
||||||
contractState({}),
|
contractState({}),
|
||||||
currentSourceUnitPath({}),
|
currentSourceUnitPath({}),
|
||||||
currentContract({}),
|
currentContract({}),
|
||||||
currentFunction({}),
|
currentFunction({}),
|
||||||
uRandDist(std::move(_urd)),
|
uRandDist(_urd),
|
||||||
numSourceUnits(0),
|
numSourceUnits(0),
|
||||||
numContracts(0),
|
numContracts(0),
|
||||||
numFunctions(0),
|
numFunctions(0),
|
||||||
@ -673,7 +673,7 @@ struct TestState
|
|||||||
/// Current function
|
/// Current function
|
||||||
std::string currentFunction;
|
std::string currentFunction;
|
||||||
/// Uniform random distribution.
|
/// Uniform random distribution.
|
||||||
std::shared_ptr<UniformRandomDistribution> uRandDist;
|
std::shared_ptr<UniformRandomDistribution>& uRandDist;
|
||||||
/// Number of source units in test input
|
/// Number of source units in test input
|
||||||
size_t numSourceUnits;
|
size_t numSourceUnits;
|
||||||
/// Number of contracts in test input
|
/// Number of contracts in test input
|
||||||
@ -694,14 +694,9 @@ struct TestState
|
|||||||
|
|
||||||
struct TypeProvider
|
struct TypeProvider
|
||||||
{
|
{
|
||||||
TypeProvider(std::shared_ptr<TestState> _state): state(std::move(_state))
|
TypeProvider(std::shared_ptr<TestState>& _state): state(_state)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~TypeProvider()
|
|
||||||
{
|
|
||||||
state.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class Type: size_t
|
enum class Type: size_t
|
||||||
{
|
{
|
||||||
INTEGER = 1,
|
INTEGER = 1,
|
||||||
@ -722,7 +717,7 @@ struct TypeProvider
|
|||||||
return static_cast<Type>(state->uRandDist->distributionOneToN(static_cast<size_t>(Type::TYPEMAX) - 1));
|
return static_cast<Type>(state->uRandDist->distributionOneToN(static_cast<size_t>(Type::TYPEMAX) - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TestState> state;
|
std::shared_ptr<TestState>& state;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TypeComparator
|
struct TypeComparator
|
||||||
@ -743,14 +738,9 @@ struct TypeComparator
|
|||||||
|
|
||||||
struct LiteralGenerator
|
struct LiteralGenerator
|
||||||
{
|
{
|
||||||
explicit LiteralGenerator(std::shared_ptr<TestState> _state): state(std::move(_state))
|
explicit LiteralGenerator(std::shared_ptr<TestState>& _state): state(_state)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~LiteralGenerator()
|
|
||||||
{
|
|
||||||
state.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string operator()(std::shared_ptr<AddressType> const& _type);
|
std::string operator()(std::shared_ptr<AddressType> const& _type);
|
||||||
std::string operator()(std::shared_ptr<BoolType> const& _type);
|
std::string operator()(std::shared_ptr<BoolType> const& _type);
|
||||||
std::string operator()(std::shared_ptr<BytesType> const& _type);
|
std::string operator()(std::shared_ptr<BytesType> const& _type);
|
||||||
@ -759,19 +749,14 @@ struct LiteralGenerator
|
|||||||
std::string operator()(std::shared_ptr<FunctionType> const& _type);
|
std::string operator()(std::shared_ptr<FunctionType> const& _type);
|
||||||
std::string operator()(std::shared_ptr<IntegerType> const& _type);
|
std::string operator()(std::shared_ptr<IntegerType> const& _type);
|
||||||
|
|
||||||
std::shared_ptr<TestState> state;
|
std::shared_ptr<TestState>& state;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExpressionGenerator
|
struct ExpressionGenerator
|
||||||
{
|
{
|
||||||
ExpressionGenerator(std::shared_ptr<TestState> _state): state(std::move(_state))
|
ExpressionGenerator(std::shared_ptr<TestState>& _state): state(_state)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~ExpressionGenerator()
|
|
||||||
{
|
|
||||||
state.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class RLValueExpr: size_t
|
enum class RLValueExpr: size_t
|
||||||
{
|
{
|
||||||
VARREF = 1,
|
VARREF = 1,
|
||||||
@ -847,7 +832,7 @@ struct ExpressionGenerator
|
|||||||
{
|
{
|
||||||
return nestingDepth > s_maxNestingDepth;
|
return nestingDepth > s_maxNestingDepth;
|
||||||
}
|
}
|
||||||
std::shared_ptr<TestState> state;
|
std::shared_ptr<TestState>& state;
|
||||||
unsigned nestingDepth;
|
unsigned nestingDepth;
|
||||||
static constexpr unsigned s_maxNestingDepth = 30;
|
static constexpr unsigned s_maxNestingDepth = 30;
|
||||||
};
|
};
|
||||||
@ -869,14 +854,14 @@ public:
|
|||||||
std::shared_ptr<T> generator();
|
std::shared_ptr<T> generator();
|
||||||
/// @returns a shared ptr to underlying random
|
/// @returns a shared ptr to underlying random
|
||||||
/// number distribution.
|
/// number distribution.
|
||||||
std::shared_ptr<UniformRandomDistribution> uniformRandomDist()
|
std::shared_ptr<UniformRandomDistribution>& uniformRandomDist()
|
||||||
{
|
{
|
||||||
return m_urd;
|
return m_urd;
|
||||||
}
|
}
|
||||||
/// @returns a pseudo randomly generated test case.
|
/// @returns a pseudo randomly generated test case.
|
||||||
std::string generateTestProgram();
|
std::string generateTestProgram();
|
||||||
/// @returns shared ptr to global test state.
|
/// @returns shared ptr to global test state.
|
||||||
std::shared_ptr<TestState> testState()
|
std::shared_ptr<TestState>& testState()
|
||||||
{
|
{
|
||||||
return m_state;
|
return m_state;
|
||||||
}
|
}
|
||||||
@ -946,9 +931,8 @@ struct GeneratorBase
|
|||||||
virtual ~GeneratorBase()
|
virtual ~GeneratorBase()
|
||||||
{
|
{
|
||||||
generators.clear();
|
generators.clear();
|
||||||
state.reset();
|
|
||||||
}
|
}
|
||||||
std::shared_ptr<UniformRandomDistribution> uRandDist()
|
std::shared_ptr<UniformRandomDistribution>& uRandDist()
|
||||||
{
|
{
|
||||||
return mutator->uniformRandomDist();
|
return mutator->uniformRandomDist();
|
||||||
}
|
}
|
||||||
@ -958,7 +942,7 @@ struct GeneratorBase
|
|||||||
/// Set of generators used by this generator.
|
/// Set of generators used by this generator.
|
||||||
std::set<std::pair<GeneratorPtr, unsigned>> generators;
|
std::set<std::pair<GeneratorPtr, unsigned>> generators;
|
||||||
/// Shared ptr to global test state.
|
/// Shared ptr to global test state.
|
||||||
std::shared_ptr<TestState> state;
|
std::shared_ptr<TestState>& state;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestCaseGenerator: public GeneratorBase
|
class TestCaseGenerator: public GeneratorBase
|
||||||
|
Loading…
Reference in New Issue
Block a user