Merge pull request #7819 from ethereum/removeNew

Restrict usage of plain "new".
This commit is contained in:
chriseth 2019-11-27 18:46:54 +01:00 committed by GitHub
commit 03fd677f98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 62 additions and 63 deletions

View File

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

View File

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

View File

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

View File

@ -55,11 +55,6 @@ ASTNode::ASTNode(SourceLocation const& _location):
{
}
ASTNode::~ASTNode()
{
delete m_annotation;
}
void ASTNode::resetID()
{
IDDispenser::reset();
@ -68,14 +63,14 @@ void ASTNode::resetID()
ASTAnnotation& ASTNode::annotation() const
{
if (!m_annotation)
m_annotation = new ASTAnnotation();
m_annotation = make_unique<ASTAnnotation>();
return *m_annotation;
}
SourceUnitAnnotation& SourceUnit::annotation() const
{
if (!m_annotation)
m_annotation = new SourceUnitAnnotation();
m_annotation = make_unique<SourceUnitAnnotation>();
return dynamic_cast<SourceUnitAnnotation&>(*m_annotation);
}
@ -99,7 +94,7 @@ set<SourceUnit const*> SourceUnit::referencedSourceUnits(bool _recurse, set<Sour
ImportAnnotation& ImportDirective::annotation() const
{
if (!m_annotation)
m_annotation = new ImportAnnotation();
m_annotation = make_unique<ImportAnnotation>();
return dynamic_cast<ImportAnnotation&>(*m_annotation);
}
@ -168,7 +163,7 @@ vector<EventDefinition const*> const& ContractDefinition::interfaceEvents() cons
if (!m_interfaceEvents)
{
set<string> eventsSeen;
m_interfaceEvents.reset(new vector<EventDefinition const*>());
m_interfaceEvents = make_unique<vector<EventDefinition const*>>();
for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
for (EventDefinition const* e: contract->events())
{
@ -193,7 +188,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::inter
if (!m_interfaceFunctionList)
{
set<string> signaturesSeen;
m_interfaceFunctionList.reset(new vector<pair<FixedHash<4>, FunctionTypePointer>>());
m_interfaceFunctionList = make_unique<vector<pair<FixedHash<4>, FunctionTypePointer>>>();
for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
{
vector<FunctionTypePointer> functions;
@ -225,7 +220,7 @@ vector<Declaration const*> const& ContractDefinition::inheritableMembers() const
{
if (!m_inheritableMembers)
{
m_inheritableMembers.reset(new vector<Declaration const*>());
m_inheritableMembers = make_unique<vector<Declaration const*>>();
auto addInheritableMember = [&](Declaration const* _decl)
{
solAssert(_decl, "addInheritableMember got a nullpointer.");
@ -259,14 +254,14 @@ TypePointer ContractDefinition::type() const
ContractDefinitionAnnotation& ContractDefinition::annotation() const
{
if (!m_annotation)
m_annotation = new ContractDefinitionAnnotation();
m_annotation = make_unique<ContractDefinitionAnnotation>();
return dynamic_cast<ContractDefinitionAnnotation&>(*m_annotation);
}
TypeNameAnnotation& TypeName::annotation() const
{
if (!m_annotation)
m_annotation = new TypeNameAnnotation();
m_annotation = make_unique<TypeNameAnnotation>();
return dynamic_cast<TypeNameAnnotation&>(*m_annotation);
}
@ -278,7 +273,7 @@ TypePointer StructDefinition::type() const
TypeDeclarationAnnotation& StructDefinition::annotation() const
{
if (!m_annotation)
m_annotation = new TypeDeclarationAnnotation();
m_annotation = make_unique<TypeDeclarationAnnotation>();
return dynamic_cast<TypeDeclarationAnnotation&>(*m_annotation);
}
@ -297,7 +292,7 @@ TypePointer EnumDefinition::type() const
TypeDeclarationAnnotation& EnumDefinition::annotation() const
{
if (!m_annotation)
m_annotation = new TypeDeclarationAnnotation();
m_annotation = make_unique<TypeDeclarationAnnotation>();
return dynamic_cast<TypeDeclarationAnnotation&>(*m_annotation);
}
@ -357,7 +352,7 @@ string FunctionDefinition::externalSignature() const
FunctionDefinitionAnnotation& FunctionDefinition::annotation() const
{
if (!m_annotation)
m_annotation = new FunctionDefinitionAnnotation();
m_annotation = make_unique<FunctionDefinitionAnnotation>();
return dynamic_cast<FunctionDefinitionAnnotation&>(*m_annotation);
}
@ -369,7 +364,7 @@ TypePointer ModifierDefinition::type() const
ModifierDefinitionAnnotation& ModifierDefinition::annotation() const
{
if (!m_annotation)
m_annotation = new ModifierDefinitionAnnotation();
m_annotation = make_unique<ModifierDefinitionAnnotation>();
return dynamic_cast<ModifierDefinitionAnnotation&>(*m_annotation);
}
@ -389,14 +384,14 @@ FunctionTypePointer EventDefinition::functionType(bool _internal) const
EventDefinitionAnnotation& EventDefinition::annotation() const
{
if (!m_annotation)
m_annotation = new EventDefinitionAnnotation();
m_annotation = make_unique<EventDefinitionAnnotation>();
return dynamic_cast<EventDefinitionAnnotation&>(*m_annotation);
}
UserDefinedTypeNameAnnotation& UserDefinedTypeName::annotation() const
{
if (!m_annotation)
m_annotation = new UserDefinedTypeNameAnnotation();
m_annotation = make_unique<UserDefinedTypeNameAnnotation>();
return dynamic_cast<UserDefinedTypeNameAnnotation&>(*m_annotation);
}
@ -604,63 +599,63 @@ FunctionTypePointer VariableDeclaration::functionType(bool _internal) const
VariableDeclarationAnnotation& VariableDeclaration::annotation() const
{
if (!m_annotation)
m_annotation = new VariableDeclarationAnnotation();
m_annotation = make_unique<VariableDeclarationAnnotation>();
return dynamic_cast<VariableDeclarationAnnotation&>(*m_annotation);
}
StatementAnnotation& Statement::annotation() const
{
if (!m_annotation)
m_annotation = new StatementAnnotation();
m_annotation = make_unique<StatementAnnotation>();
return dynamic_cast<StatementAnnotation&>(*m_annotation);
}
InlineAssemblyAnnotation& InlineAssembly::annotation() const
{
if (!m_annotation)
m_annotation = new InlineAssemblyAnnotation();
m_annotation = make_unique<InlineAssemblyAnnotation>();
return dynamic_cast<InlineAssemblyAnnotation&>(*m_annotation);
}
ReturnAnnotation& Return::annotation() const
{
if (!m_annotation)
m_annotation = new ReturnAnnotation();
m_annotation = make_unique<ReturnAnnotation>();
return dynamic_cast<ReturnAnnotation&>(*m_annotation);
}
ExpressionAnnotation& Expression::annotation() const
{
if (!m_annotation)
m_annotation = new ExpressionAnnotation();
m_annotation = make_unique<ExpressionAnnotation>();
return dynamic_cast<ExpressionAnnotation&>(*m_annotation);
}
MemberAccessAnnotation& MemberAccess::annotation() const
{
if (!m_annotation)
m_annotation = new MemberAccessAnnotation();
m_annotation = make_unique<MemberAccessAnnotation>();
return dynamic_cast<MemberAccessAnnotation&>(*m_annotation);
}
BinaryOperationAnnotation& BinaryOperation::annotation() const
{
if (!m_annotation)
m_annotation = new BinaryOperationAnnotation();
m_annotation = make_unique<BinaryOperationAnnotation>();
return dynamic_cast<BinaryOperationAnnotation&>(*m_annotation);
}
FunctionCallAnnotation& FunctionCall::annotation() const
{
if (!m_annotation)
m_annotation = new FunctionCallAnnotation();
m_annotation = make_unique<FunctionCallAnnotation>();
return dynamic_cast<FunctionCallAnnotation&>(*m_annotation);
}
IdentifierAnnotation& Identifier::annotation() const
{
if (!m_annotation)
m_annotation = new IdentifierAnnotation();
m_annotation = make_unique<IdentifierAnnotation>();
return dynamic_cast<IdentifierAnnotation&>(*m_annotation);
}

View File

@ -67,7 +67,7 @@ public:
using SourceLocation = langutil::SourceLocation;
explicit ASTNode(SourceLocation const& _location);
virtual ~ASTNode();
virtual ~ASTNode() {}
/// @returns an identifier of this AST node that is unique for a single compilation run.
size_t id() const { return m_id; }
@ -111,7 +111,7 @@ public:
protected:
size_t const m_id = 0;
/// Annotation - is specialised in derived classes, is created upon request (because of polymorphism).
mutable ASTAnnotation* m_annotation = nullptr;
mutable std::unique_ptr<ASTAnnotation> m_annotation;
private:
SourceLocation m_location;

View File

@ -329,7 +329,7 @@ MemberList const& Type::members(ContractDefinition const* _currentScope) const
MemberList::MemberMap members = nativeMembers(_currentScope);
if (_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];
}

View File

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

View File

@ -136,7 +136,7 @@ template <class _LValueType, class... _Arguments>
void ExpressionCompiler::setLValue(Expression const& _expression, _Arguments const&... _arguments)
{
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)
m_currentLValue = move(lvalue);
else

View File

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

View File

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

View File

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

View File

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

View File

@ -96,7 +96,7 @@ int registerTests(
{
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(
[config, _testCaseCreator]
{

View File

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

View File

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

View File

@ -448,7 +448,7 @@ protected:
)
{
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);
sendMessage(*s_compiledWallet + args, true, _value);

View File

@ -36,7 +36,7 @@ class ABIJsonTest: public TestCase
{
public:
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);
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:
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);
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:
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);

View File

@ -34,7 +34,7 @@ class FunctionSideEffects: public dev::solidity::test::TestCase
{
public:
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);
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:
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);

View File

@ -42,7 +42,7 @@ class YulInterpreterTest: public dev::solidity::test::EVMVersionRestrictedTestCa
public:
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);

View File

@ -424,7 +424,11 @@ void YulOptimizerTest::disambiguate()
void YulOptimizerTest::updateContext()
{
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)

View File

@ -51,7 +51,7 @@ class YulOptimizerTest: public dev::solidity::test::EVMVersionRestrictedTestCase
public:
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);