qmake: eradicate Q_FOREACH loops [const-& returns]

... by replacing them with C++11 range-for loops.

The functions QMakeProject::values(), QMakeMetaInfo::values()
and QHashIterator::value() all return by const-reference,
so they can be passed to range-for without further changes.

Change-Id: Ic3b39ed8ff8cd7a6f287f1aa9d61a1acd67d7aaa
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2016-01-26 14:38:54 +01:00
parent c9cb20c01a
commit 3f3140d38a
7 changed files with 23 additions and 23 deletions

View File

@ -1641,7 +1641,7 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
<< "\t\t\t" << writeSettings("targets", project->values("QMAKE_PBX_TARGETS"), SettingsAsList, 4) << ";\n"
<< "\t\t\t" << "attributes = {\n"
<< "\t\t\t\tTargetAttributes = {\n";
foreach (const ProString &target, project->values("QMAKE_PBX_TARGETS")) {
for (const ProString &target : project->values("QMAKE_PBX_TARGETS")) {
const ProStringList &attributes = project->values(ProKey("QMAKE_PBX_TARGET_ATTRIBUTES_" + target));
if (attributes.isEmpty())
continue;

View File

@ -904,7 +904,7 @@ MakefileGenerator::processPrlFile(QString &file)
project->values("QMAKE_CURRENT_PRL_LIBS") = libinfo.values("QMAKE_PRL_LIBS");
ProStringList &defs = project->values("DEFINES");
const ProStringList &prl_defs = project->values("PRL_EXPORT_DEFINES");
foreach (const ProString &def, libinfo.values("QMAKE_PRL_DEFINES"))
for (const ProString &def : libinfo.values("QMAKE_PRL_DEFINES"))
if (!defs.contains(def) && prl_defs.contains(def))
defs.append(def);
if (try_replace_file) {
@ -1141,7 +1141,7 @@ MakefileGenerator::writeObj(QTextStream &t, const char *src)
<< " " << escapeDependencyPaths(findDependencies(srcf)).join(" \\\n\t\t");
ProKey comp;
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
for (const ProString &compiler : project->values("QMAKE_BUILTIN_COMPILERS")) {
// Unfortunately we were not consistent about the C++ naming
ProString extensionSuffix = compiler;
if (extensionSuffix == "CXX")
@ -1152,7 +1152,7 @@ MakefileGenerator::writeObj(QTextStream &t, const char *src)
if (compilerSuffix == "C")
compilerSuffix = ProString("CC");
foreach (const ProString &extension, project->values(ProKey("QMAKE_EXT_" + extensionSuffix))) {
for (const ProString &extension : project->values(ProKey("QMAKE_EXT_" + extensionSuffix))) {
if ((*sit).endsWith(extension)) {
comp = ProKey("QMAKE_RUN_" + compilerSuffix);
break;
@ -1450,7 +1450,7 @@ QString
MakefileGenerator::fixFileVarGlue(const ProKey &var, const QString &before, const QString &glue, const QString &after) const
{
ProStringList varList;
foreach (const ProString &val, project->values(var))
for (const ProString &val : project->values(var))
varList << escapeFilePath(Option::fixPathToTargetOS(val.toQString()));
return valGlue(varList, before, glue, after);
}
@ -2769,11 +2769,11 @@ MakefileGenerator::parseLibFlag(const ProString &flag, ProString *arg)
ProStringList
MakefileGenerator::fixLibFlags(const ProKey &var)
{
ProStringList in = project->values(var);
const ProStringList &in = project->values(var);
ProStringList ret;
ret.reserve(in.length());
foreach (const ProString &v, in)
for (const ProString &v : in)
ret << fixLibFlag(v);
return ret;
}

View File

@ -60,7 +60,7 @@ UnixMakefileGenerator::init()
project->values("VER_PAT").append(l[2]);
QString sroot = project->sourceRoot();
foreach (const ProString &iif, project->values("QMAKE_INTERNAL_INCLUDED_FILES")) {
for (const ProString &iif : project->values("QMAKE_INTERNAL_INCLUDED_FILES")) {
if (iif == project->cacheFile())
continue;
if (iif.startsWith(sroot) && iif.at(sroot.length()) == QLatin1Char('/'))
@ -156,7 +156,7 @@ UnixMakefileGenerator::init()
if (project->isActiveConfig("objective_c"))
project->values("QMAKE_BUILTIN_COMPILERS") << "OBJC" << "OBJCXX";
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
for (const ProString &compiler : project->values("QMAKE_BUILTIN_COMPILERS")) {
QString compile_flag = var("QMAKE_COMPILE_FLAG");
if(compile_flag.isEmpty())
compile_flag = "-c";
@ -334,7 +334,7 @@ QStringList
? project->first("QMAKE_PCH_OUTPUT_EXT").toQString() : "";
header_prefix += Option::dir_sep + project->first("QMAKE_PRECOMP_PREFIX");
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
for (const ProString &compiler : project->values("QMAKE_BUILTIN_COMPILERS")) {
if (project->isEmpty(ProKey("QMAKE_" + compiler + "FLAGS_PRECOMPILE")))
continue;
@ -347,7 +347,7 @@ QStringList
if (extensionSuffix == "CXX")
extensionSuffix = ProString("CPP");
foreach (const ProString &extension, project->values(ProKey("QMAKE_EXT_" + extensionSuffix))) {
for (const ProString &extension : project->values(ProKey("QMAKE_EXT_" + extensionSuffix))) {
if (!file.endsWith(extension.toQString()))
continue;
@ -376,7 +376,7 @@ UnixMakefileGenerator::findLibraries(bool linkPrl, bool mergeLflags)
{
QList<QMakeLocalFileName> libdirs, frameworkdirs;
int libidx = 0, fwidx = 0;
foreach (const ProString &dlib, project->values("QMAKE_DEFAULT_LIBDIRS"))
for (const ProString &dlib : project->values("QMAKE_DEFAULT_LIBDIRS"))
libdirs.append(QMakeLocalFileName(dlib.toQString()));
frameworkdirs.append(QMakeLocalFileName("/System/Library/Frameworks"));
frameworkdirs.append(QMakeLocalFileName("/Library/Frameworks"));
@ -648,7 +648,7 @@ UnixMakefileGenerator::defaultInstall(const QString &t)
uninst.append("-$(DEL_FILE) " + dst_targ);
if (bundle == SlicedBundle) {
int dstlen = project->first("DESTDIR").length();
foreach (const ProString &src, project->values("QMAKE_BUNDLED_FILES")) {
for (const ProString &src : project->values("QMAKE_BUNDLED_FILES")) {
ProString file = src.mid(dstlen);
QString dst = escapeFilePath(
filePrefixRoot(root, fileFixify(targetdir + file, FileFixifyAbsolute)));

View File

@ -988,7 +988,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
ProString header_suffix = project->isActiveConfig("clang_pch_style")
? project->first("QMAKE_PCH_OUTPUT_EXT") : "";
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
for (const ProString &compiler : project->values("QMAKE_BUILTIN_COMPILERS")) {
if (project->isEmpty(ProKey("QMAKE_" + compiler + "FLAGS_PRECOMPILE")))
continue;
ProString language = project->first(ProKey("QMAKE_LANGUAGE_" + compiler));
@ -1050,7 +1050,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) {
QString pchInput = project->first("PRECOMPILED_HEADER").toQString();
t << "###### Precompiled headers\n";
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
for (const ProString &compiler : project->values("QMAKE_BUILTIN_COMPILERS")) {
QString pchFlags = var(ProKey("QMAKE_" + compiler + "FLAGS_PRECOMPILE"));
if(pchFlags.isEmpty())
continue;

View File

@ -409,7 +409,7 @@ bool VcprojGenerator::isStandardSuffix(const QString &suffix) const
ProString VcprojGenerator::firstInputFileName(const ProString &extraCompilerName) const
{
foreach (const ProString &var, project->values(ProKey(extraCompilerName + ".input"))) {
for (const ProString &var : project->values(ProKey(extraCompilerName + ".input"))) {
const ProStringList &files = project->values(var.toKey());
if (!files.isEmpty())
return files.first();
@ -688,7 +688,7 @@ void VcprojGenerator::writeSubDirs(QTextStream &t)
QHashIterator<VcsolutionDepend *, QStringList> extraIt(extraSubdirs);
while (extraIt.hasNext()) {
extraIt.next();
foreach (const QString &depend, extraIt.value()) {
for (const QString &depend : extraIt.value()) {
if (!projGuids[depend].isEmpty()) {
extraIt.key()->dependencies << projGuids[depend];
} else if (!profileLookup[depend].isEmpty()) {
@ -867,7 +867,7 @@ void VcprojGenerator::init()
// Add all input files for a custom compiler into a map for uniqueness,
// unless the compiler is configure as a combined stage, then use the first one
foreach (const ProString &quc, project->values("QMAKE_EXTRA_COMPILERS")) {
for (const ProString &quc : project->values("QMAKE_EXTRA_COMPILERS")) {
const ProStringList &invar = project->values(ProKey(quc + ".input"));
const QString compiler_out = project->first(ProKey(quc + ".output")).toQString();
for (ProStringList::ConstIterator iit = invar.constBegin(); iit != invar.constEnd(); ++iit) {
@ -1189,7 +1189,7 @@ void VcprojGenerator::initResourceTool()
else
conf.resource.PreprocessorDefinitions = conf.compiler.PreprocessorDefinitions;
foreach (const ProString &path, project->values("RC_INCLUDEPATH")) {
for (const ProString &path : project->values("RC_INCLUDEPATH")) {
QString fixedPath = fileFixify(path.toQString());
if (fileInfo(fixedPath).isRelative()) {
if (fixedPath == QLatin1String("."))
@ -1344,7 +1344,7 @@ void VcprojGenerator::initDeploymentTool()
}
}
foreach (const ProString &item, project->values("INSTALLS")) {
for (const ProString &item : project->values("INSTALLS")) {
// get item.path
QString devicePath = project->first(ProKey(item + ".path")).toQString();
if (!conf.WinRT) {
@ -1359,7 +1359,7 @@ void VcprojGenerator::initDeploymentTool()
}
}
// foreach d in item.files
foreach (const ProString &src, project->values(ProKey(item + ".files"))) {
for (const ProString &src : project->values(ProKey(item + ".files"))) {
QString itemDevicePath = devicePath;
QString source = Option::normalizePath(src.toQString());
QString nameFilter;

View File

@ -263,7 +263,7 @@ void Win32MakefileGenerator::processRcFileVar()
QString versionString = vers.join('.');
QStringList rcIcons;
foreach (const ProString &icon, project->values("RC_ICONS"))
for (const ProString &icon : project->values("RC_ICONS"))
rcIcons.append(fileFixify(icon.toQString(), FileFixifyAbsolute));
QString companyName;

View File

@ -146,7 +146,7 @@ void QMakeProject::dump() const
it != m_valuemapStack.first().end(); ++it) {
if (!it.key().startsWith('.')) {
QString str = it.key() + " =";
foreach (const ProString &v, it.value())
for (const ProString &v : it.value())
str += ' ' + formatValue(v);
out << str;
}