Apply modernize-use-emplace.

This commit is contained in:
Alexander Arlt 2020-03-31 21:39:38 -05:00
parent 82f57f0465
commit 90bb1d8a7c
14 changed files with 33 additions and 49 deletions

View File

@ -495,7 +495,7 @@ ASTPointer<UserDefinedTypeName> ASTJsonImporter::createUserDefinedTypeName(Json:
string nameString = member(_node, "name").asString(); string nameString = member(_node, "name").asString();
boost::algorithm::split(strs, nameString, boost::is_any_of(".")); boost::algorithm::split(strs, nameString, boost::is_any_of("."));
for (string s: strs) for (string s: strs)
namePath.push_back(ASTString(s)); namePath.emplace_back(s);
return createASTNode<UserDefinedTypeName>( return createASTNode<UserDefinedTypeName>(
_node, _node,
namePath namePath

View File

@ -843,7 +843,7 @@ string ABIFunctions::abiEncodingFunctionStruct(
if (dynamicMember) if (dynamicMember)
solAssert(dynamic, ""); solAssert(dynamic, "");
members.push_back({}); members.emplace_back();
members.back()["preprocess"] = ""; members.back()["preprocess"] = "";
switch (_from.location()) switch (_from.location())
@ -1336,7 +1336,7 @@ string ABIFunctions::abiDecodingFunctionStruct(StructType const& _type, bool _fr
memberTempl("memoryOffset", toCompactHexWithPrefix(_type.memoryOffsetOfMember(member.name))); memberTempl("memoryOffset", toCompactHexWithPrefix(_type.memoryOffsetOfMember(member.name)));
memberTempl("abiDecode", abiDecodingFunction(*member.type, _fromMemory, false)); memberTempl("abiDecode", abiDecodingFunction(*member.type, _fromMemory, false));
members.push_back({}); members.emplace_back();
members.back()["decode"] = memberTempl.render(); members.back()["decode"] = memberTempl.render();
members.back()["memberName"] = member.name; members.back()["memberName"] = member.name;
headPos += decodingType->calldataHeadSize(); headPos += decodingType->calldataHeadSize();

View File

@ -339,7 +339,7 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
vector<map<string, string>> functions; vector<map<string, string>> functions;
for (auto const& function: _contract.interfaceFunctions()) for (auto const& function: _contract.interfaceFunctions())
{ {
functions.push_back({}); functions.emplace_back();
map<string, string>& templ = functions.back(); map<string, string>& templ = functions.back();
templ["functionSelector"] = "0x" + function.first.hex(); templ["functionSelector"] = "0x" + function.first.hex();
FunctionTypePointer const& type = function.second; FunctionTypePointer const& type = function.second;

View File

@ -232,7 +232,7 @@ void EncodingContext::pushSolver()
if (m_accumulateAssertions) if (m_accumulateAssertions)
m_assertions.push_back(assertions()); m_assertions.push_back(assertions());
else else
m_assertions.push_back(smt::Expression(true)); m_assertions.emplace_back(true);
} }
void EncodingContext::popSolver() void EncodingContext::popSolver()

View File

@ -200,7 +200,7 @@ bool isArtifactRequested(Json::Value const& _outputSelection, string const& _fil
/// for Contract-level targets try both contract name and wildcard /// for Contract-level targets try both contract name and wildcard
vector<string> contracts{ _contract }; vector<string> contracts{ _contract };
if (!_contract.empty()) if (!_contract.empty())
contracts.push_back("*"); contracts.emplace_back("*");
for (auto const& contract: contracts) for (auto const& contract: contracts)
if ( if (
_outputSelection[file].isMember(contract) && _outputSelection[file].isMember(contract) &&

View File

@ -104,7 +104,7 @@ void WordSizeTransform::operator()(Block& _block)
auto newLhs = generateU64IdentifierNames(varDecl.variables[0].name); auto newLhs = generateU64IdentifierNames(varDecl.variables[0].name);
vector<Statement> ret; vector<Statement> ret;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
ret.push_back(VariableDeclaration{ ret.emplace_back(VariableDeclaration{
varDecl.location, varDecl.location,
{TypedName{varDecl.location, newLhs[i], m_targetDialect.defaultType}}, {TypedName{varDecl.location, newLhs[i], m_targetDialect.defaultType}},
make_unique<Expression>(Literal{ make_unique<Expression>(Literal{
@ -114,7 +114,7 @@ void WordSizeTransform::operator()(Block& _block)
m_targetDialect.defaultType m_targetDialect.defaultType
}) })
}); });
ret.push_back(VariableDeclaration{ ret.emplace_back(VariableDeclaration{
varDecl.location, varDecl.location,
{TypedName{varDecl.location, newLhs[3], m_targetDialect.defaultType}}, {TypedName{varDecl.location, newLhs[3], m_targetDialect.defaultType}},
std::move(varDecl.value) std::move(varDecl.value)
@ -135,8 +135,7 @@ void WordSizeTransform::operator()(Block& _block)
auto newLhs = generateU64IdentifierNames(varDecl.variables[0].name); auto newLhs = generateU64IdentifierNames(varDecl.variables[0].name);
vector<Statement> ret; vector<Statement> ret;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
ret.push_back( ret.emplace_back(VariableDeclaration{
VariableDeclaration{
varDecl.location, varDecl.location,
{TypedName{varDecl.location, newLhs[i], m_targetDialect.defaultType}}, {TypedName{varDecl.location, newLhs[i], m_targetDialect.defaultType}},
std::move(newRhs[i]) std::move(newRhs[i])
@ -165,7 +164,7 @@ void WordSizeTransform::operator()(Block& _block)
auto newLhs = generateU64IdentifierNames(assignment.variableNames[0].name); auto newLhs = generateU64IdentifierNames(assignment.variableNames[0].name);
vector<Statement> ret; vector<Statement> ret;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
ret.push_back(Assignment{ ret.emplace_back(Assignment{
assignment.location, assignment.location,
{Identifier{assignment.location, newLhs[i]}}, {Identifier{assignment.location, newLhs[i]}},
make_unique<Expression>(Literal{ make_unique<Expression>(Literal{
@ -175,7 +174,7 @@ void WordSizeTransform::operator()(Block& _block)
m_targetDialect.defaultType m_targetDialect.defaultType
}) })
}); });
ret.push_back(Assignment{ ret.emplace_back(Assignment{
assignment.location, assignment.location,
{Identifier{assignment.location, newLhs[3]}}, {Identifier{assignment.location, newLhs[3]}},
std::move(assignment.value) std::move(assignment.value)
@ -196,8 +195,7 @@ void WordSizeTransform::operator()(Block& _block)
YulString lhsName = assignment.variableNames[0].name; YulString lhsName = assignment.variableNames[0].name;
vector<Statement> ret; vector<Statement> ret;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
ret.push_back( ret.emplace_back(Assignment{
Assignment{
assignment.location, assignment.location,
{Identifier{assignment.location, m_variableMapping.at(lhsName)[i]}}, {Identifier{assignment.location, m_variableMapping.at(lhsName)[i]}},
std::move(newRhs[i]) std::move(newRhs[i])

View File

@ -76,13 +76,13 @@ BOOST_AUTO_TEST_CASE(test_alternatives_list)
{ {
vector<string> strings; vector<string> strings;
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), ""); BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "");
strings.push_back("a"); strings.emplace_back("a");
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\""); BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\"");
strings.push_back("b"); strings.emplace_back("b");
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\" or \"b\""); BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\" or \"b\"");
strings.push_back("c"); strings.emplace_back("c");
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\", \"b\" or \"c\""); BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\", \"b\" or \"c\"");
strings.push_back("d"); strings.emplace_back("d");
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\", \"b\", \"c\" or \"d\""); BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\", \"b\", \"c\" or \"d\"");
} }

View File

@ -47,15 +47,15 @@ string toString(SideEffects const& _sideEffects)
{ {
vector<string> ret; vector<string> ret;
if (_sideEffects.movable) if (_sideEffects.movable)
ret.push_back("movable"); ret.emplace_back("movable");
if (_sideEffects.sideEffectFree) if (_sideEffects.sideEffectFree)
ret.push_back("sideEffectFree"); ret.emplace_back("sideEffectFree");
if (_sideEffects.sideEffectFreeIfNoMSize) if (_sideEffects.sideEffectFreeIfNoMSize)
ret.push_back("sideEffectFreeIfNoMSize"); ret.emplace_back("sideEffectFreeIfNoMSize");
if (_sideEffects.invalidatesStorage) if (_sideEffects.invalidatesStorage)
ret.push_back("invalidatesStorage"); ret.emplace_back("invalidatesStorage");
if (_sideEffects.invalidatesMemory) if (_sideEffects.invalidatesMemory)
ret.push_back("invalidatesMemory"); ret.emplace_back("invalidatesMemory");
return joinHumanReadable(ret); return joinHumanReadable(ret);
} }
} }

View File

@ -104,7 +104,7 @@ Allowed options)",
else if (arguments.count("input-files")) else if (arguments.count("input-files"))
inputs = arguments["input-files"].as<vector<string>>(); inputs = arguments["input-files"].as<vector<string>>();
else else
inputs.push_back(""); inputs.emplace_back("");
bool optimize = !arguments.count("without-optimizer"); bool optimize = !arguments.count("without-optimizer");
int retResult = 0; int retResult = 0;

View File

@ -308,7 +308,7 @@ pair<
for (auto const& scope: m_scopes) for (auto const& scope: m_scopes)
{ {
// Copy over all functions. // Copy over all functions.
newScopes.push_back({}); newScopes.emplace_back();
for (auto const& [name, funDef]: scope) for (auto const& [name, funDef]: scope)
if (funDef) if (funDef)
newScopes.back().emplace(name, funDef); newScopes.back().emplace(name, funDef);

View File

@ -136,7 +136,7 @@ private:
/// Evaluates the expression and returns its value. /// Evaluates the expression and returns its value.
std::vector<u256> evaluateMulti(Expression const& _expression); std::vector<u256> evaluateMulti(Expression const& _expression);
void openScope() { m_scopes.push_back({}); } void openScope() { m_scopes.emplace_back(); }
/// Unregisters variables and functions. /// Unregisters variables and functions.
void closeScope(); void closeScope();

View File

@ -32,8 +32,7 @@ void ConstructorKeyword::endVisit(ContractDefinition const& _contract)
{ {
for (auto const* function: _contract.definedFunctions()) for (auto const* function: _contract.definedFunctions())
if (function->name() == _contract.name()) if (function->name() == _contract.name())
m_changes.push_back( m_changes.emplace_back(
UpgradeChange{
UpgradeChange::Level::Safe, UpgradeChange::Level::Safe,
function->location(), function->location(),
SourceTransform::replaceFunctionName( SourceTransform::replaceFunctionName(
@ -41,18 +40,15 @@ void ConstructorKeyword::endVisit(ContractDefinition const& _contract)
function->name(), function->name(),
"constructor" "constructor"
) )
}
); );
} }
void VisibilitySpecifier::endVisit(FunctionDefinition const& _function) void VisibilitySpecifier::endVisit(FunctionDefinition const& _function)
{ {
if (_function.noVisibilitySpecified()) if (_function.noVisibilitySpecified())
m_changes.push_back( m_changes.emplace_back(
UpgradeChange{
UpgradeChange::Level::Safe, UpgradeChange::Level::Safe,
_function.location(), _function.location(),
SourceTransform::insertAfterRightParenthesis(_function.location(), "public") SourceTransform::insertAfterRightParenthesis(_function.location(), "public")
}
); );
} }

View File

@ -106,12 +106,10 @@ void AbstractContract::endVisit(ContractDefinition const& _contract)
!_contract.abstract() && !_contract.abstract() &&
!_contract.isInterface() !_contract.isInterface()
) )
m_changes.push_back( m_changes.emplace_back(
UpgradeChange{
UpgradeChange::Level::Safe, UpgradeChange::Level::Safe,
_contract.location(), _contract.location(),
SourceTransform::insertBeforeKeyword(_contract.location(), "contract", "abstract") SourceTransform::insertBeforeKeyword(_contract.location(), "contract", "abstract")
}
); );
} }
@ -132,12 +130,10 @@ void OverridingFunction::endVisit(ContractDefinition const& _contract)
/// Add override with contract list, if needed. /// Add override with contract list, if needed.
if (!function->overrides() && expectedContracts.size() > 1) if (!function->overrides() && expectedContracts.size() > 1)
m_changes.push_back( m_changes.emplace_back(
UpgradeChange{
UpgradeChange::Level::Safe, UpgradeChange::Level::Safe,
function->location(), function->location(),
appendOverride(*function, expectedContracts) appendOverride(*function, expectedContracts)
}
); );
for (auto [begin, end] = inheritedFunctions.equal_range(proxy); begin != end; begin++) for (auto [begin, end] = inheritedFunctions.equal_range(proxy); begin != end; begin++)
@ -151,12 +147,10 @@ void OverridingFunction::endVisit(ContractDefinition const& _contract)
/// If function does not specify override and no override with /// If function does not specify override and no override with
/// contract list was added before. /// contract list was added before.
if (!function->overrides() && expectedContracts.size() <= 1) if (!function->overrides() && expectedContracts.size() <= 1)
m_changes.push_back( m_changes.emplace_back(
UpgradeChange{
UpgradeChange::Level::Safe, UpgradeChange::Level::Safe,
function->location(), function->location(),
appendOverride(*function, expectedContracts) appendOverride(*function, expectedContracts)
}
); );
} }
} }
@ -181,12 +175,10 @@ void VirtualFunction::endVisit(ContractDefinition const& _contract)
function->visibility() > Visibility::Private function->visibility() > Visibility::Private
) )
{ {
m_changes.push_back( m_changes.emplace_back(
UpgradeChange{
UpgradeChange::Level::Safe, UpgradeChange::Level::Safe,
function->location(), function->location(),
appendVirtual(*function) appendVirtual(*function)
}
); );
} }
@ -198,12 +190,10 @@ void VirtualFunction::endVisit(ContractDefinition const& _contract)
!super.virtualSemantics() !super.virtualSemantics()
) )
{ {
m_changes.push_back( m_changes.emplace_back(
UpgradeChange{
UpgradeChange::Level::Safe, UpgradeChange::Level::Safe,
function->location(), function->location(),
appendVirtual(*function) appendVirtual(*function)
}
); );
} }
} }

View File

@ -41,7 +41,7 @@ vector<tuple<size_t, size_t>> RandomPairSelection::materialise(size_t _poolSize)
index2 = SimulationRNG::uniformInt(0, _poolSize - 1); index2 = SimulationRNG::uniformInt(0, _poolSize - 1);
} while (index1 == index2); } while (index1 == index2);
selection.push_back({index1, index2}); selection.emplace_back(index1, index2);
} }
return selection; return selection;
@ -58,7 +58,7 @@ vector<tuple<size_t, size_t>> PairMosaicSelection::materialise(size_t _poolSize)
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
tuple<size_t, size_t> pair = m_pattern[i % m_pattern.size()]; tuple<size_t, size_t> pair = m_pattern[i % m_pattern.size()];
selection.push_back({min(get<0>(pair), _poolSize - 1), min(get<1>(pair), _poolSize - 1)}); selection.emplace_back(min(get<0>(pair), _poolSize - 1), min(get<1>(pair), _poolSize - 1));
} }
return selection; return selection;