Merge pull request #8570 from aarlt/clang-tidy-apply-modernize-use-emplace

clang-tidy: Apply modernize-use-emplace.
This commit is contained in:
chriseth 2020-04-07 17:28:50 +02:00 committed by GitHub
commit 823a119117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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();
boost::algorithm::split(strs, nameString, boost::is_any_of("."));
for (string s: strs)
namePath.push_back(ASTString(s));
namePath.emplace_back(s);
return createASTNode<UserDefinedTypeName>(
_node,
namePath

View File

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

View File

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

View File

@ -192,7 +192,7 @@ void EncodingContext::pushSolver()
if (m_accumulateAssertions)
m_assertions.push_back(assertions());
else
m_assertions.push_back(smt::Expression(true));
m_assertions.emplace_back(true);
}
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
vector<string> contracts{ _contract };
if (!_contract.empty())
contracts.push_back("*");
contracts.emplace_back("*");
for (auto const& contract: contracts)
if (
_outputSelection[file].isMember(contract) &&

View File

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

View File

@ -76,13 +76,13 @@ BOOST_AUTO_TEST_CASE(test_alternatives_list)
{
vector<string> strings;
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "");
strings.push_back("a");
strings.emplace_back("a");
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\"");
strings.push_back("b");
strings.emplace_back("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\"");
strings.push_back("d");
strings.emplace_back("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;
if (_sideEffects.movable)
ret.push_back("movable");
ret.emplace_back("movable");
if (_sideEffects.sideEffectFree)
ret.push_back("sideEffectFree");
ret.emplace_back("sideEffectFree");
if (_sideEffects.sideEffectFreeIfNoMSize)
ret.push_back("sideEffectFreeIfNoMSize");
ret.emplace_back("sideEffectFreeIfNoMSize");
if (_sideEffects.invalidatesStorage)
ret.push_back("invalidatesStorage");
ret.emplace_back("invalidatesStorage");
if (_sideEffects.invalidatesMemory)
ret.push_back("invalidatesMemory");
ret.emplace_back("invalidatesMemory");
return joinHumanReadable(ret);
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -106,12 +106,10 @@ void AbstractContract::endVisit(ContractDefinition const& _contract)
!_contract.abstract() &&
!_contract.isInterface()
)
m_changes.push_back(
UpgradeChange{
m_changes.emplace_back(
UpgradeChange::Level::Safe,
_contract.location(),
SourceTransform::insertBeforeKeyword(_contract.location(), "contract", "abstract")
}
);
}
@ -132,12 +130,10 @@ void OverridingFunction::endVisit(ContractDefinition const& _contract)
/// Add override with contract list, if needed.
if (!function->overrides() && expectedContracts.size() > 1)
m_changes.push_back(
UpgradeChange{
m_changes.emplace_back(
UpgradeChange::Level::Safe,
function->location(),
appendOverride(*function, expectedContracts)
}
);
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
/// contract list was added before.
if (!function->overrides() && expectedContracts.size() <= 1)
m_changes.push_back(
UpgradeChange{
m_changes.emplace_back(
UpgradeChange::Level::Safe,
function->location(),
appendOverride(*function, expectedContracts)
}
);
}
}
@ -181,12 +175,10 @@ void VirtualFunction::endVisit(ContractDefinition const& _contract)
function->visibility() > Visibility::Private
)
{
m_changes.push_back(
UpgradeChange{
m_changes.emplace_back(
UpgradeChange::Level::Safe,
function->location(),
appendVirtual(*function)
}
);
}
@ -198,12 +190,10 @@ void VirtualFunction::endVisit(ContractDefinition const& _contract)
!super.virtualSemantics()
)
{
m_changes.push_back(
UpgradeChange{
m_changes.emplace_back(
UpgradeChange::Level::Safe,
function->location(),
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);
} while (index1 == index2);
selection.push_back({index1, index2});
selection.emplace_back(index1, index2);
}
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)
{
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;