Restrict usage of plain "new".

This commit is contained in:
chriseth 2019-11-27 17:24:21 +01:00
parent 87943bf444
commit 0bb88dabb7
22 changed files with 37 additions and 33 deletions

View File

@ -40,7 +40,7 @@ GasMeter::GasConsumption PathGasMeter::estimateMax(
shared_ptr<KnownState> const& _state shared_ptr<KnownState> const& _state
) )
{ {
auto path = unique_ptr<GasPath>(new GasPath()); auto path = make_unique<GasPath>();
path->index = _startIndex; path->index = _startIndex;
path->state = _state->copy(); path->state = _state->copy();
queue(move(path)); queue(move(path));
@ -120,7 +120,7 @@ GasMeter::GasConsumption PathGasMeter::handleQueueItem()
for (u256 const& tag: jumpTags) for (u256 const& tag: jumpTags)
{ {
auto newPath = unique_ptr<GasPath>(new GasPath()); auto newPath = make_unique<GasPath>();
newPath->index = m_items.size(); newPath->index = m_items.size();
if (m_tagPositions.count(tag)) if (m_tagPositions.count(tag))
newPath->index = m_tagPositions.at(tag); newPath->index = m_tagPositions.at(tag);

View File

@ -35,7 +35,7 @@ unique_ptr<FunctionFlow> ControlFlowBuilder::createFunctionFlow(
FunctionDefinition const& _function FunctionDefinition const& _function
) )
{ {
auto functionFlow = unique_ptr<FunctionFlow>(new FunctionFlow()); auto functionFlow = make_unique<FunctionFlow>();
functionFlow->entry = _nodeContainer.newNode(); functionFlow->entry = _nodeContainer.newNode();
functionFlow->exit = _nodeContainer.newNode(); functionFlow->exit = _nodeContainer.newNode();
functionFlow->revert = _nodeContainer.newNode(); functionFlow->revert = _nodeContainer.newNode();

View File

@ -48,7 +48,7 @@ NameAndTypeResolver::NameAndTypeResolver(
m_globalContext(_globalContext) m_globalContext(_globalContext)
{ {
if (!m_scopes[nullptr]) if (!m_scopes[nullptr])
m_scopes[nullptr].reset(new DeclarationContainer()); m_scopes[nullptr] = make_shared<DeclarationContainer>();
for (Declaration const* declaration: _globalContext.declarations()) for (Declaration const* declaration: _globalContext.declarations())
{ {
solAssert(m_scopes[nullptr]->registerDeclaration(*declaration), "Unable to register global declaration."); solAssert(m_scopes[nullptr]->registerDeclaration(*declaration), "Unable to register global declaration.");
@ -545,7 +545,7 @@ bool DeclarationRegistrationHelper::visit(SourceUnit& _sourceUnit)
{ {
if (!m_scopes[&_sourceUnit]) if (!m_scopes[&_sourceUnit])
// By importing, it is possible that the container already exists. // By importing, it is possible that the container already exists.
m_scopes[&_sourceUnit].reset(new DeclarationContainer(m_currentScope, m_scopes[m_currentScope].get())); m_scopes[&_sourceUnit] = make_shared<DeclarationContainer>(m_currentScope, m_scopes[m_currentScope].get());
m_currentScope = &_sourceUnit; m_currentScope = &_sourceUnit;
return true; return true;
} }
@ -561,7 +561,7 @@ bool DeclarationRegistrationHelper::visit(ImportDirective& _import)
SourceUnit const* importee = _import.annotation().sourceUnit; SourceUnit const* importee = _import.annotation().sourceUnit;
solAssert(!!importee, ""); solAssert(!!importee, "");
if (!m_scopes[importee]) if (!m_scopes[importee])
m_scopes[importee].reset(new DeclarationContainer(nullptr, m_scopes[nullptr].get())); m_scopes[importee] = make_shared<DeclarationContainer>(nullptr, m_scopes[nullptr].get());
m_scopes[&_import] = m_scopes[importee]; m_scopes[&_import] = m_scopes[importee];
registerDeclaration(_import, false); registerDeclaration(_import, false);
return true; return true;
@ -705,7 +705,7 @@ void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _subScope)
{ {
map<ASTNode const*, shared_ptr<DeclarationContainer>>::iterator iter; map<ASTNode const*, shared_ptr<DeclarationContainer>>::iterator iter;
bool newlyAdded; bool newlyAdded;
shared_ptr<DeclarationContainer> container(new DeclarationContainer(m_currentScope, m_scopes[m_currentScope].get())); shared_ptr<DeclarationContainer> container{make_shared<DeclarationContainer>(m_currentScope, m_scopes[m_currentScope].get())};
tie(iter, newlyAdded) = m_scopes.emplace(&_subScope, move(container)); tie(iter, newlyAdded) = m_scopes.emplace(&_subScope, move(container));
solAssert(newlyAdded, "Unable to add new scope."); solAssert(newlyAdded, "Unable to add new scope.");
m_currentScope = &_subScope; m_currentScope = &_subScope;

View File

@ -329,7 +329,7 @@ MemberList const& Type::members(ContractDefinition const* _currentScope) const
MemberList::MemberMap members = nativeMembers(_currentScope); MemberList::MemberMap members = nativeMembers(_currentScope);
if (_currentScope) if (_currentScope)
members += boundFunctions(*this, *_currentScope); members += boundFunctions(*this, *_currentScope);
m_members[_currentScope] = unique_ptr<MemberList>(new MemberList(move(members))); m_members[_currentScope] = make_unique<MemberList>(move(members));
} }
return *m_members[_currentScope]; return *m_members[_currentScope];
} }

View File

@ -345,7 +345,7 @@ bool ExpressionCompiler::visit(TupleExpression const& _tuple)
if (_tuple.components().size() == 1) if (_tuple.components().size() == 1)
m_currentLValue = move(lvalues[0]); m_currentLValue = move(lvalues[0]);
else else
m_currentLValue.reset(new TupleObject(m_context, move(lvalues))); m_currentLValue = make_unique<TupleObject>(m_context, move(lvalues));
} }
} }
return false; return false;

View File

@ -136,7 +136,7 @@ template <class _LValueType, class... _Arguments>
void ExpressionCompiler::setLValue(Expression const& _expression, _Arguments const&... _arguments) void ExpressionCompiler::setLValue(Expression const& _expression, _Arguments const&... _arguments)
{ {
solAssert(!m_currentLValue, "Current LValue not reset before trying to set new one."); solAssert(!m_currentLValue, "Current LValue not reset before trying to set new one.");
std::unique_ptr<_LValueType> lvalue(new _LValueType(m_context, _arguments...)); std::unique_ptr<_LValueType> lvalue = std::make_unique<_LValueType>(m_context, _arguments...);
if (_expression.annotation().lValueRequested) if (_expression.annotation().lValueRequested)
m_currentLValue = move(lvalue); m_currentLValue = move(lvalue);
else else

View File

@ -512,7 +512,7 @@ string const* CompilerStack::sourceMapping(string const& _contractName) const
if (!c.sourceMapping) if (!c.sourceMapping)
{ {
if (auto items = assemblyItems(_contractName)) if (auto items = assemblyItems(_contractName))
c.sourceMapping.reset(new string(computeSourceMapping(*items))); c.sourceMapping = make_unique<string>(computeSourceMapping(*items));
} }
return c.sourceMapping.get(); return c.sourceMapping.get();
} }
@ -526,7 +526,7 @@ string const* CompilerStack::runtimeSourceMapping(string const& _contractName) c
if (!c.runtimeSourceMapping) if (!c.runtimeSourceMapping)
{ {
if (auto items = runtimeAssemblyItems(_contractName)) if (auto items = runtimeAssemblyItems(_contractName))
c.runtimeSourceMapping.reset(new string(computeSourceMapping(*items))); c.runtimeSourceMapping = make_unique<string>(computeSourceMapping(*items));
} }
return c.runtimeSourceMapping.get(); return c.runtimeSourceMapping.get();
} }
@ -663,7 +663,7 @@ Json::Value const& CompilerStack::contractABI(Contract const& _contract) const
// caches the result // caches the result
if (!_contract.abi) if (!_contract.abi)
_contract.abi.reset(new Json::Value(ABI::generate(*_contract.contract))); _contract.abi = make_unique<Json::Value>(ABI::generate(*_contract.contract));
return *_contract.abi; return *_contract.abi;
} }
@ -685,7 +685,7 @@ Json::Value const& CompilerStack::storageLayout(Contract const& _contract) const
// caches the result // caches the result
if (!_contract.storageLayout) if (!_contract.storageLayout)
_contract.storageLayout.reset(new Json::Value(StorageLayout().generate(*_contract.contract))); _contract.storageLayout = make_unique<Json::Value>(StorageLayout().generate(*_contract.contract));
return *_contract.storageLayout; return *_contract.storageLayout;
} }
@ -707,7 +707,7 @@ Json::Value const& CompilerStack::natspecUser(Contract const& _contract) const
// caches the result // caches the result
if (!_contract.userDocumentation) if (!_contract.userDocumentation)
_contract.userDocumentation.reset(new Json::Value(Natspec::userDocumentation(*_contract.contract))); _contract.userDocumentation = make_unique<Json::Value>(Natspec::userDocumentation(*_contract.contract));
return *_contract.userDocumentation; return *_contract.userDocumentation;
} }
@ -729,7 +729,7 @@ Json::Value const& CompilerStack::natspecDev(Contract const& _contract) const
// caches the result // caches the result
if (!_contract.devDocumentation) if (!_contract.devDocumentation)
_contract.devDocumentation.reset(new Json::Value(Natspec::devDocumentation(*_contract.contract))); _contract.devDocumentation = make_unique<Json::Value>(Natspec::devDocumentation(*_contract.contract));
return *_contract.devDocumentation; return *_contract.devDocumentation;
} }
@ -762,7 +762,7 @@ string const& CompilerStack::metadata(Contract const& _contract) const
// cache the result // cache the result
if (!_contract.metadata) if (!_contract.metadata)
_contract.metadata.reset(new string(createMetadata(_contract))); _contract.metadata = make_unique<string>(createMetadata(_contract));
return *_contract.metadata; return *_contract.metadata;
} }

View File

@ -350,7 +350,7 @@ ASTPointer<InheritanceSpecifier> Parser::parseInheritanceSpecifier()
if (m_scanner->currentToken() == Token::LParen) if (m_scanner->currentToken() == Token::LParen)
{ {
m_scanner->next(); m_scanner->next();
arguments.reset(new vector<ASTPointer<Expression>>(parseFunctionCallListArguments())); arguments = make_unique<vector<ASTPointer<Expression>>>(parseFunctionCallListArguments());
nodeFactory.markEndPosition(); nodeFactory.markEndPosition();
expectToken(Token::RParen); expectToken(Token::RParen);
} }
@ -811,7 +811,7 @@ ASTPointer<ModifierInvocation> Parser::parseModifierInvocation()
if (m_scanner->currentToken() == Token::LParen) if (m_scanner->currentToken() == Token::LParen)
{ {
m_scanner->next(); m_scanner->next();
arguments.reset(new vector<ASTPointer<Expression>>(parseFunctionCallListArguments())); arguments = make_unique<vector<ASTPointer<Expression>>>(parseFunctionCallListArguments());
nodeFactory.markEndPosition(); nodeFactory.markEndPosition();
expectToken(Token::RParen); expectToken(Token::RParen);
} }

View File

@ -217,7 +217,7 @@ Statement Parser::parseStatement()
expectToken(Token::AssemblyAssign); expectToken(Token::AssemblyAssign);
assignment.value.reset(new Expression(parseExpression())); assignment.value = make_unique<Expression>(parseExpression());
assignment.location.end = locationOf(*assignment.value).end; assignment.location.end = locationOf(*assignment.value).end;
return Statement{std::move(assignment)}; return Statement{std::move(assignment)};

View File

@ -933,7 +933,7 @@ bool CommandLineInterface::processInput()
return link(); return link();
} }
m_compiler.reset(new CompilerStack(fileReader)); m_compiler = make_unique<CompilerStack>(fileReader);
unique_ptr<SourceReferenceFormatter> formatter; unique_ptr<SourceReferenceFormatter> formatter;
if (m_args.count(g_argNewReporter)) if (m_args.count(g_argNewReporter))

View File

@ -96,7 +96,7 @@ int registerTests(
{ {
static vector<unique_ptr<string>> filenames; static vector<unique_ptr<string>> filenames;
filenames.emplace_back(new string(_path.string())); filenames.emplace_back(make_unique<string>(_path.string()));
_suite.add(make_test_case( _suite.add(make_test_case(
[config, _testCaseCreator] [config, _testCaseCreator]
{ {

View File

@ -223,7 +223,7 @@ protected:
void deployRegistrar() void deployRegistrar()
{ {
if (!s_compiledRegistrar) if (!s_compiledRegistrar)
s_compiledRegistrar.reset(new bytes(compileContract(registrarCode, "GlobalRegistrar"))); s_compiledRegistrar = make_unique<bytes>(compileContract(registrarCode, "GlobalRegistrar"));
sendMessage(*s_compiledRegistrar, true); sendMessage(*s_compiledRegistrar, true);
BOOST_REQUIRE(m_transactionSuccessful); BOOST_REQUIRE(m_transactionSuccessful);

View File

@ -132,7 +132,7 @@ protected:
void deployRegistrar() void deployRegistrar()
{ {
if (!s_compiledRegistrar) if (!s_compiledRegistrar)
s_compiledRegistrar.reset(new bytes(compileContract(registrarCode, "FixedFeeRegistrar"))); s_compiledRegistrar = make_unique<bytes>(compileContract(registrarCode, "FixedFeeRegistrar"));
sendMessage(*s_compiledRegistrar, true); sendMessage(*s_compiledRegistrar, true);
BOOST_REQUIRE(m_transactionSuccessful); BOOST_REQUIRE(m_transactionSuccessful);

View File

@ -448,7 +448,7 @@ protected:
) )
{ {
if (!s_compiledWallet) if (!s_compiledWallet)
s_compiledWallet.reset(new bytes(compileContract(walletCode, "Wallet"))); s_compiledWallet = make_unique<bytes>(compileContract(walletCode, "Wallet"));
bytes args = encodeArgs(u256(0x60), _required, _dailyLimit, u256(_owners.size()), _owners); bytes args = encodeArgs(u256(0x60), _required, _dailyLimit, u256(_owners.size()), _owners);
sendMessage(*s_compiledWallet + args, true, _value); sendMessage(*s_compiledWallet + args, true, _value);

View File

@ -36,7 +36,7 @@ class ABIJsonTest: public TestCase
{ {
public: public:
static std::unique_ptr<TestCase> create(Config const& _config) static std::unique_ptr<TestCase> create(Config const& _config)
{ return std::unique_ptr<TestCase>(new ABIJsonTest(_config.filename)); } { return std::make_unique<ABIJsonTest>(_config.filename); }
ABIJsonTest(std::string const& _filename); ABIJsonTest(std::string const& _filename);
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override; TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;

View File

@ -36,7 +36,7 @@ class ASTJSONTest: public TestCase
{ {
public: public:
static std::unique_ptr<TestCase> create(Config const& _config) static std::unique_ptr<TestCase> create(Config const& _config)
{ return std::unique_ptr<TestCase>(new ASTJSONTest(_config.filename)); } { return std::make_unique<ASTJSONTest>(_config.filename); }
ASTJSONTest(std::string const& _filename); ASTJSONTest(std::string const& _filename);
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override; TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;

View File

@ -37,7 +37,7 @@ class EWasmTranslationTest: public dev::solidity::test::EVMVersionRestrictedTest
public: public:
static std::unique_ptr<TestCase> create(Config const& _config) static std::unique_ptr<TestCase> create(Config const& _config)
{ {
return std::unique_ptr<TestCase>(new EWasmTranslationTest(_config.filename)); return std::make_unique<EWasmTranslationTest>(_config.filename);
} }
explicit EWasmTranslationTest(std::string const& _filename); explicit EWasmTranslationTest(std::string const& _filename);

View File

@ -34,7 +34,7 @@ class FunctionSideEffects: public dev::solidity::test::TestCase
{ {
public: public:
static std::unique_ptr<TestCase> create(Config const& _config) static std::unique_ptr<TestCase> create(Config const& _config)
{ return std::unique_ptr<TestCase>(new FunctionSideEffects(_config.filename)); } { return std::make_unique<FunctionSideEffects>(_config.filename); }
explicit FunctionSideEffects(std::string const& _filename); explicit FunctionSideEffects(std::string const& _filename);
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override; TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;

View File

@ -42,7 +42,7 @@ class ObjectCompilerTest: public dev::solidity::test::TestCase
public: public:
static std::unique_ptr<TestCase> create(Config const& _config) static std::unique_ptr<TestCase> create(Config const& _config)
{ {
return std::unique_ptr<TestCase>(new ObjectCompilerTest(_config.filename)); return std::make_unique<ObjectCompilerTest>(_config.filename);
} }
explicit ObjectCompilerTest(std::string const& _filename); explicit ObjectCompilerTest(std::string const& _filename);

View File

@ -42,7 +42,7 @@ class YulInterpreterTest: public dev::solidity::test::EVMVersionRestrictedTestCa
public: public:
static std::unique_ptr<TestCase> create(Config const& _config) static std::unique_ptr<TestCase> create(Config const& _config)
{ {
return std::unique_ptr<TestCase>(new YulInterpreterTest(_config.filename)); return std::make_unique<YulInterpreterTest>(_config.filename);
} }
explicit YulInterpreterTest(std::string const& _filename); explicit YulInterpreterTest(std::string const& _filename);

View File

@ -424,7 +424,11 @@ void YulOptimizerTest::disambiguate()
void YulOptimizerTest::updateContext() void YulOptimizerTest::updateContext()
{ {
m_nameDispenser = make_unique<NameDispenser>(*m_dialect, *m_ast, m_reservedIdentifiers); m_nameDispenser = make_unique<NameDispenser>(*m_dialect, *m_ast, m_reservedIdentifiers);
m_context = unique_ptr<OptimiserStepContext>(new OptimiserStepContext{*m_dialect, *m_nameDispenser, m_reservedIdentifiers}); m_context = make_unique<OptimiserStepContext>(OptimiserStepContext{
*m_dialect,
*m_nameDispenser,
m_reservedIdentifiers
});
} }
void YulOptimizerTest::printErrors(ostream& _stream, ErrorList const& _errors) void YulOptimizerTest::printErrors(ostream& _stream, ErrorList const& _errors)

View File

@ -51,7 +51,7 @@ class YulOptimizerTest: public dev::solidity::test::EVMVersionRestrictedTestCase
public: public:
static std::unique_ptr<TestCase> create(Config const& _config) static std::unique_ptr<TestCase> create(Config const& _config)
{ {
return std::unique_ptr<TestCase>(new YulOptimizerTest(_config.filename)); return std::make_unique<YulOptimizerTest>(_config.filename);
} }
explicit YulOptimizerTest(std::string const& _filename); explicit YulOptimizerTest(std::string const& _filename);