qmake: eradicate Q_FOREACH loops [already const]

(or trivially marked const) ... by replacing them
with C++11 range-for loops.

Change-Id: I1522e220a57ecb1c5ee0d4281233b3c3931a2ff8
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2016-01-26 14:38:54 +01:00
parent e31541fa6f
commit d9229d849f
11 changed files with 36 additions and 36 deletions

View File

@ -1646,7 +1646,7 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
if (attributes.isEmpty()) if (attributes.isEmpty())
continue; continue;
t << "\t\t\t\t\t" << target << " = {\n"; t << "\t\t\t\t\t" << target << " = {\n";
foreach (const ProString &attribute, attributes) for (const ProString &attribute : attributes)
t << "\t\t\t\t\t\t" << writeSettings(attribute.toQString(), project->first(ProKey("QMAKE_PBX_TARGET_ATTRIBUTES_" + target + "_" + attribute))) << ";\n"; t << "\t\t\t\t\t\t" << writeSettings(attribute.toQString(), project->first(ProKey("QMAKE_PBX_TARGET_ATTRIBUTES_" + target + "_" + attribute))) << ";\n";
t << "\t\t\t\t\t};\n"; t << "\t\t\t\t\t};\n";
} }

View File

@ -954,7 +954,7 @@ static QString
qv(const ProStringList &val) qv(const ProStringList &val)
{ {
QString ret; QString ret;
foreach (const ProString &v, val) for (const ProString &v : val)
ret += qv(v); ret += qv(v);
return ret; return ret;
} }

View File

@ -173,7 +173,7 @@ QStringList CeSdkHandler::getMsBuildToolPaths() const
QStringList CeSdkHandler::filterMsBuildToolPaths(const QStringList &paths) const QStringList CeSdkHandler::filterMsBuildToolPaths(const QStringList &paths) const
{ {
QStringList result; QStringList result;
foreach (const QString &path, paths) { for (const QString &path : paths) {
QDir dirVC110(path); QDir dirVC110(path);
if (path.endsWith(QLatin1String("bin"))) if (path.endsWith(QLatin1String("bin")))
dirVC110.cdUp(); dirVC110.cdUp();
@ -191,9 +191,9 @@ bool CeSdkHandler::retrieveEnvironment(const QStringList &relativePaths,
CeSdkInfo *info) CeSdkInfo *info)
{ {
bool result = false; bool result = false;
foreach (const QString &path, toolPaths) { for (const QString &path : toolPaths) {
const QDir dir(path); const QDir dir(path);
foreach (const QString &filePath, relativePaths) { for (const QString &filePath : relativePaths) {
QFile file(dir.absoluteFilePath(filePath)); QFile file(dir.absoluteFilePath(filePath));
if (file.exists()) if (file.exists())
result = parseMsBuildFile(&file, info) || result; result = parseMsBuildFile(&file, info) || result;
@ -209,7 +209,7 @@ void CeSdkHandler::retrieveWEC2013SDKs()
const QStringList filteredToolPaths = filterMsBuildToolPaths(toolPaths); const QStringList filteredToolPaths = filterMsBuildToolPaths(toolPaths);
QSettings settings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows CE Tools\\SDKs", QSettings::NativeFormat); QSettings settings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows CE Tools\\SDKs", QSettings::NativeFormat);
const QStringList keys = settings.allKeys(); const QStringList keys = settings.allKeys();
foreach (const QString &key, keys) { for (const QString &key : keys) {
if (key.contains(QLatin1String("SDKInformation")) || key.contains(QLatin1Char('.'))) { if (key.contains(QLatin1String("SDKInformation")) || key.contains(QLatin1Char('.'))) {
QFile sdkPropertyFile(settings.value(key).toString()); QFile sdkPropertyFile(settings.value(key).toString());
if (!sdkPropertyFile.exists()) if (!sdkPropertyFile.exists())

View File

@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE
static QString nmakePathList(const QStringList &list) static QString nmakePathList(const QStringList &list)
{ {
QStringList pathList; QStringList pathList;
foreach (const QString &path, list) for (const QString &path : list)
pathList.append(QDir::cleanPath(path)); pathList.append(QDir::cleanPath(path));
return QDir::toNativeSeparators(pathList.join(QLatin1Char(';'))) return QDir::toNativeSeparators(pathList.join(QLatin1Char(';')))
@ -79,7 +79,7 @@ NmakeMakefileGenerator::writeMakefile(QTextStream &t)
+ " (" + variables["CE_ARCH"].join(' ') + ")"; + " (" + variables["CE_ARCH"].join(' ') + ")";
const QList<CeSdkInfo> sdkList = sdkhandler.listAll(); const QList<CeSdkInfo> sdkList = sdkhandler.listAll();
CeSdkInfo sdk; CeSdkInfo sdk;
foreach (const CeSdkInfo &info, sdkList) { for (const CeSdkInfo &info : sdkList) {
if (info.name().compare(sdkName, Qt::CaseInsensitive ) == 0) { if (info.name().compare(sdkName, Qt::CaseInsensitive ) == 0) {
sdk = info; sdk = info;
break; break;
@ -91,7 +91,7 @@ NmakeMakefileGenerator::writeMakefile(QTextStream &t)
t << "\nPATH = " << sdk.binPath() << "\n"; t << "\nPATH = " << sdk.binPath() << "\n";
} else { } else {
QStringList sdkStringList; QStringList sdkStringList;
foreach (const CeSdkInfo &info, sdkList) for (const CeSdkInfo &info : sdkList)
sdkStringList << info.name(); sdkStringList << info.name();
fprintf(stderr, "Failed to find Windows CE SDK matching %s, found: %s\n" fprintf(stderr, "Failed to find Windows CE SDK matching %s, found: %s\n"

View File

@ -124,7 +124,7 @@ DotNET which_dotnet_version(const QByteArray &preferredVersion = QByteArray())
// More than one version installed, search directory path // More than one version installed, search directory path
QString paths = qgetenv("PATH"); QString paths = qgetenv("PATH");
const QStringList pathlist = paths.split(QLatin1Char(';')); const QStringList pathlist = paths.split(QLatin1Char(';'));
foreach (const QString &path, pathlist) { for (const QString &path : pathlist) {
for (i = 0; dotNetCombo[i].version; ++i) { for (i = 0; dotNetCombo[i].version; ++i) {
const QString productPath = installPaths.value(dotNetCombo[i].version); const QString productPath = installPaths.value(dotNetCombo[i].version);
if (productPath.isEmpty()) if (productPath.isEmpty())
@ -533,13 +533,13 @@ ProStringList VcprojGenerator::collectDependencies(QMakeProject *proj, QHash<QSt
if (tmpList.size()) { if (tmpList.size()) {
const ProStringList depends = tmpList; const ProStringList depends = tmpList;
foreach (const ProString &dep, depends) { for (const ProString &dep : depends) {
QString depend = dep.toQString(); QString depend = dep.toQString();
if (!projGuids[depend].isEmpty()) { if (!projGuids[depend].isEmpty()) {
newDep->dependencies << projGuids[depend]; newDep->dependencies << projGuids[depend];
} else if (subdirProjectLookup[projLookup[depend]].size() > 0) { } else if (subdirProjectLookup[projLookup[depend]].size() > 0) {
ProStringList tmpLst = subdirProjectLookup[projLookup[depend]]; const ProStringList tmpLst = subdirProjectLookup[projLookup[depend]];
foreach (const ProString &tDep, tmpLst) { for (const ProString &tDep : tmpLst) {
QString tmpDep = tDep.toQString(); QString tmpDep = tDep.toQString();
newDep->dependencies << projGuids[projLookup[tmpDep]]; newDep->dependencies << projGuids[projLookup[tmpDep]];
} }
@ -1264,7 +1264,7 @@ void VcprojGenerator::initDeploymentTool()
if (targetPath.endsWith("/") || targetPath.endsWith("\\")) if (targetPath.endsWith("/") || targetPath.endsWith("\\"))
targetPath.chop(1); targetPath.chop(1);
} }
ProStringList dllPaths = project->values("QMAKE_DLL_PATHS"); const ProStringList dllPaths = project->values("QMAKE_DLL_PATHS");
// Only deploy Qt libs for shared build // Only deploy Qt libs for shared build
if (!dllPaths.isEmpty() && if (!dllPaths.isEmpty() &&
!(conf.WinRT && project->first("MSVC_VER").toQString() == "14.0")) { !(conf.WinRT && project->first("MSVC_VER").toQString() == "14.0")) {
@ -1282,7 +1282,7 @@ void VcprojGenerator::initDeploymentTool()
// Use only the file name and check in Qt's install path and LIBPATHs to check for existence // Use only the file name and check in Qt's install path and LIBPATHs to check for existence
dllName.remove(0, dllName.lastIndexOf(QLatin1Char('/')) + 1); dllName.remove(0, dllName.lastIndexOf(QLatin1Char('/')) + 1);
QFileInfo info; QFileInfo info;
foreach (const ProString &dllPath, dllPaths) { for (const ProString &dllPath : dllPaths) {
QString absoluteDllFilePath = dllPath.toQString(); QString absoluteDllFilePath = dllPath.toQString();
if (!absoluteDllFilePath.endsWith(QLatin1Char('/'))) if (!absoluteDllFilePath.endsWith(QLatin1Char('/')))
absoluteDllFilePath += QLatin1Char('/'); absoluteDllFilePath += QLatin1Char('/');
@ -1664,7 +1664,7 @@ void VcprojGenerator::initExtraCompilerOutputs()
// provided that the input file variable is not handled already (those in otherFilters // provided that the input file variable is not handled already (those in otherFilters
// are handled, so we avoid them). // are handled, so we avoid them).
const ProStringList &inputVars = project->values(ProKey(*it + ".input")); const ProStringList &inputVars = project->values(ProKey(*it + ".input"));
foreach (const ProString &inputVar, inputVars) { for (const ProString &inputVar : inputVars) {
if (!otherFilters.contains(inputVar)) { if (!otherFilters.contains(inputVar)) {
const ProStringList &tmp_in = project->values(inputVar.toKey()); const ProStringList &tmp_in = project->values(inputVar.toKey());
for (int i = 0; i < tmp_in.count(); ++i) { for (int i = 0; i < tmp_in.count(); ++i) {

View File

@ -391,7 +391,7 @@ void ProStringList::removeAll(const char *str)
void ProStringList::removeEach(const ProStringList &value) void ProStringList::removeEach(const ProStringList &value)
{ {
foreach (const ProString &str, value) for (const ProString &str : value)
if (!str.isEmpty()) if (!str.isEmpty())
removeAll(str); removeAll(str);
} }
@ -424,7 +424,7 @@ void ProStringList::removeDuplicates()
void ProStringList::insertUnique(const ProStringList &value) void ProStringList::insertUnique(const ProStringList &value)
{ {
foreach (const ProString &str, value) for (const ProString &str : value)
if (!str.isEmpty() && !contains(str)) if (!str.isEmpty() && !contains(str))
append(str); append(str);
} }
@ -432,7 +432,7 @@ void ProStringList::insertUnique(const ProStringList &value)
ProStringList::ProStringList(const QStringList &list) ProStringList::ProStringList(const QStringList &list)
{ {
reserve(list.size()); reserve(list.size());
foreach (const QString &str, list) for (const QString &str : list)
*this << ProString(str); *this << ProString(str);
} }
@ -440,8 +440,8 @@ QStringList ProStringList::toQStringList() const
{ {
QStringList ret; QStringList ret;
ret.reserve(size()); ret.reserve(size());
for (int i = 0; i < size(); i++) // foreach causes MSVC2010 ICE for (const auto &e : *this)
ret << at(i).toQString(); ret.append(e.toQString());
return ret; return ret;
} }

View File

@ -428,11 +428,11 @@ void QMakeEvaluator::populateDeps(
QHash<ProKey, QSet<ProKey> > &dependencies, ProValueMap &dependees, QHash<ProKey, QSet<ProKey> > &dependencies, ProValueMap &dependees,
QMultiMap<int, ProString> &rootSet) const QMultiMap<int, ProString> &rootSet) const
{ {
foreach (const ProString &item, deps) for (const ProString &item : deps)
if (!dependencies.contains(item.toKey())) { if (!dependencies.contains(item.toKey())) {
QSet<ProKey> &dset = dependencies[item.toKey()]; // Always create entry QSet<ProKey> &dset = dependencies[item.toKey()]; // Always create entry
ProStringList depends; ProStringList depends;
foreach (const ProString &suffix, suffixes) for (const ProString &suffix : suffixes)
depends += values(ProKey(prefix + item + suffix)); depends += values(ProKey(prefix + item + suffix));
if (depends.isEmpty()) { if (depends.isEmpty()) {
rootSet.insert(first(ProKey(prefix + item + priosfx)).toInt(), item); rootSet.insert(first(ProKey(prefix + item + priosfx)).toInt(), item);
@ -599,7 +599,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
const ProStringList &var = values(map(args.at(0))); const ProStringList &var = values(map(args.at(0)));
if (!var.isEmpty()) { if (!var.isEmpty()) {
const ProFile *src = currentProFile(); const ProFile *src = currentProFile();
foreach (const ProString &v, var) for (const ProString &v : var)
if (const ProFile *s = v.sourceFile()) { if (const ProFile *s = v.sourceFile()) {
src = s; src = s;
break; break;
@ -750,7 +750,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
tmp.sprintf(".QMAKE_INTERNAL_TMP_variableName_%d", m_listCount++); tmp.sprintf(".QMAKE_INTERNAL_TMP_variableName_%d", m_listCount++);
ret = ProStringList(ProString(tmp)); ret = ProStringList(ProString(tmp));
ProStringList lst; ProStringList lst;
foreach (const ProString &arg, args) for (const ProString &arg : args)
lst += split_value_list(arg.toQString(m_tmp1), arg.sourceFile()); // Relies on deep copy lst += split_value_list(arg.toQString(m_tmp1), arg.sourceFile()); // Relies on deep copy
m_valuemapStack.top()[ret.at(0).toKey()] = lst; m_valuemapStack.top()[ret.at(0).toKey()] = lst;
break; } break; }
@ -870,7 +870,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
} else { } else {
const ProStringList &vals = values(args.at(0).toKey()); const ProStringList &vals = values(args.at(0).toKey());
ret.reserve(vals.size()); ret.reserve(vals.size());
foreach (const ProString &str, vals) for (const ProString &str : vals)
ret += ProString(quoteValue(str)); ret += ProString(quoteValue(str));
} }
break; break;
@ -1753,7 +1753,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
varstr += QLatin1Char(' '); varstr += QLatin1Char(' ');
varstr += quoteValue(diffval.at(0)); varstr += quoteValue(diffval.at(0));
} else if (!diffval.isEmpty()) { } else if (!diffval.isEmpty()) {
foreach (const ProString &vval, diffval) { for (const ProString &vval : diffval) {
varstr += QLatin1String(" \\\n "); varstr += QLatin1String(" \\\n ");
varstr += quoteValue(vval); varstr += quoteValue(vval);
} }

View File

@ -1774,7 +1774,7 @@ bool QMakeEvaluator::evaluateConditional(const QString &cond, const QString &whe
void QMakeEvaluator::checkRequirements(const ProStringList &deps) void QMakeEvaluator::checkRequirements(const ProStringList &deps)
{ {
ProStringList &failed = valuesRef(ProKey("QMAKE_FAILED_REQUIREMENTS")); ProStringList &failed = valuesRef(ProKey("QMAKE_FAILED_REQUIREMENTS"));
foreach (const ProString &dep, deps) for (const ProString &dep : deps)
if (!evaluateConditional(dep.toQString(), m_current.pro->fileName(), m_current.line)) if (!evaluateConditional(dep.toQString(), m_current.pro->fileName(), m_current.line))
failed << dep; failed << dep;
} }
@ -1871,9 +1871,9 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateFileChecked(
{ {
if (fileName.isEmpty()) if (fileName.isEmpty())
return ReturnFalse; return ReturnFalse;
QMakeEvaluator *ref = this; const QMakeEvaluator *ref = this;
do { do {
foreach (const ProFile *pf, ref->m_profileStack) for (const ProFile *pf : ref->m_profileStack)
if (pf->fileName() == fileName) { if (pf->fileName() == fileName) {
evalError(fL1S("Circular inclusion of %1.").arg(fileName)); evalError(fL1S("Circular inclusion of %1.").arg(fileName));
return ReturnFalse; return ReturnFalse;
@ -2074,7 +2074,7 @@ QString QMakeEvaluator::formatValueList(const ProStringList &vals, bool commas)
{ {
QString ret; QString ret;
foreach (const ProString &str, vals) { for (const ProString &str : vals) {
if (!ret.isEmpty()) { if (!ret.isEmpty()) {
if (commas) if (commas)
ret += QLatin1Char(','); ret += QLatin1Char(',');
@ -2089,7 +2089,7 @@ QString QMakeEvaluator::formatValueListList(const QList<ProStringList> &lists)
{ {
QString ret; QString ret;
foreach (const ProStringList &list, lists) { for (const ProStringList &list : lists) {
if (!ret.isEmpty()) if (!ret.isEmpty())
ret += QLatin1String(", "); ret += QLatin1String(", ");
ret += formatValueList(list); ret += formatValueList(list);

View File

@ -248,9 +248,9 @@ QStringList QMakeGlobals::splitPathList(const QString &val) const
QStringList ret; QStringList ret;
if (!val.isEmpty()) { if (!val.isEmpty()) {
QDir bdir; QDir bdir;
QStringList vals = val.split(dirlist_sep); const QStringList vals = val.split(dirlist_sep);
ret.reserve(vals.length()); ret.reserve(vals.length());
foreach (const QString &it, vals) for (const QString &it : vals)
ret << QDir::cleanPath(bdir.absoluteFilePath(it)); ret << QDir::cleanPath(bdir.absoluteFilePath(it));
} }
return ret; return ret;

View File

@ -153,7 +153,7 @@ struct Option
inline static bool hasFileExtension(const QString &str, const QStringList &extensions) inline static bool hasFileExtension(const QString &str, const QStringList &extensions)
{ {
foreach (const QString &ext, extensions) for (const QString &ext : extensions)
if (str.endsWith(ext)) if (str.endsWith(ext))
return true; return true;
return false; return false;

View File

@ -73,7 +73,7 @@ static ProStringList prepareBuiltinArgs(const QList<ProStringList> &args)
{ {
ProStringList ret; ProStringList ret;
ret.reserve(args.size()); ret.reserve(args.size());
foreach (const ProStringList &arg, args) for (const ProStringList &arg : args)
ret << arg.join(' '); ret << arg.join(' ');
return ret; return ret;
} }