summaryrefslogtreecommitdiffstats
path: root/qmake/library/qmakebuiltins.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qmake/library/qmakebuiltins.cpp')
-rw-r--r--qmake/library/qmakebuiltins.cpp125
1 files changed, 69 insertions, 56 deletions
diff --git a/qmake/library/qmakebuiltins.cpp b/qmake/library/qmakebuiltins.cpp
index 8f3849e6d8..199c49e315 100644
--- a/qmake/library/qmakebuiltins.cpp
+++ b/qmake/library/qmakebuiltins.cpp
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the qmake application of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -154,6 +149,7 @@ void QMakeEvaluator::initFunctionStatics()
{ "shell_quote", E_SHELL_QUOTE },
{ "getenv", E_GETENV },
};
+ statics.expands.reserve((int)(sizeof(expandInits)/sizeof(expandInits[0])));
for (unsigned i = 0; i < sizeof(expandInits)/sizeof(expandInits[0]); ++i)
statics.expands.insert(ProKey(expandInits[i].name), expandInits[i].func);
@@ -195,13 +191,13 @@ void QMakeEvaluator::initFunctionStatics()
{ "touch", T_TOUCH },
{ "cache", T_CACHE },
};
+ statics.functions.reserve((int)(sizeof(testInits)/sizeof(testInits[0])));
for (unsigned i = 0; i < sizeof(testInits)/sizeof(testInits[0]); ++i)
statics.functions.insert(ProKey(testInits[i].name), testInits[i].func);
}
-static bool isTrue(const ProString &_str, QString &tmp)
+static bool isTrue(const ProString &str)
{
- const QString &str = _str.toQString(tmp);
return !str.compare(statics.strtrue, Qt::CaseInsensitive) || str.toInt();
}
@@ -302,19 +298,26 @@ static void insertJsonKeyValue(const QString &key, const QStringList &values, Pr
static void addJsonArray(const QJsonArray &array, const QString &keyPrefix, ProValueMap *map)
{
QStringList keys;
- for (int i = 0; i < array.count(); ++i) {
- keys.append(QString::number(i));
- addJsonValue(array.at(i), keyPrefix + QString::number(i), map);
+ const int size = array.count();
+ keys.reserve(size);
+ for (int i = 0; i < size; ++i) {
+ const QString number = QString::number(i);
+ keys.append(number);
+ addJsonValue(array.at(i), keyPrefix + number, map);
}
insertJsonKeyValue(keyPrefix + QLatin1String("_KEYS_"), keys, map);
}
static void addJsonObject(const QJsonObject &object, const QString &keyPrefix, ProValueMap *map)
{
- foreach (const QString &key, object.keys())
- addJsonValue(object.value(key), keyPrefix + key, map);
-
- insertJsonKeyValue(keyPrefix + QLatin1String("_KEYS_"), object.keys(), map);
+ QStringList keys;
+ keys.reserve(object.size());
+ for (auto it = object.begin(), end = object.end(); it != end; ++it) {
+ const QString key = it.key();
+ keys.append(key);
+ addJsonValue(it.value(), keyPrefix + key, map);
+ }
+ insertJsonKeyValue(keyPrefix + QLatin1String("_KEYS_"), keys, map);
}
static void addJsonValue(const QJsonValue &value, const QString &keyPrefix, ProValueMap *map)
@@ -442,16 +445,16 @@ void QMakeEvaluator::populateDeps(
QHash<ProKey, QSet<ProKey> > &dependencies, ProValueMap &dependees,
QMultiMap<int, ProString> &rootSet) const
{
- foreach (const ProString &item, deps)
+ for (const ProString &item : deps)
if (!dependencies.contains(item.toKey())) {
QSet<ProKey> &dset = dependencies[item.toKey()]; // Always create entry
ProStringList depends;
- foreach (const ProString &suffix, suffixes)
+ for (const ProString &suffix : suffixes)
depends += values(ProKey(prefix + item + suffix));
if (depends.isEmpty()) {
rootSet.insert(first(ProKey(prefix + item + priosfx)).toInt(), item);
} else {
- foreach (const ProString &dep, depends) {
+ for (const ProString &dep : qAsConst(depends)) {
dset.insert(dep.toKey());
dependees[dep.toKey()] << item;
}
@@ -483,9 +486,9 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
} else {
var = args[0];
sep = args.at(1).toQString();
- beg = args.at(2).toQString(m_tmp2).toInt();
+ beg = args.at(2).toInt();
if (args.count() == 4)
- end = args.at(3).toQString(m_tmp2).toInt();
+ end = args.at(3).toInt();
}
} else {
if (args.count() != 1) {
@@ -501,14 +504,15 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
}
}
if (!var.isEmpty()) {
+ const auto strings = values(map(var));
if (regexp) {
QRegExp sepRx(sep);
- foreach (const ProString &str, values(map(var))) {
+ for (const ProString &str : strings) {
const QString &rstr = str.toQString(m_tmp1).section(sepRx, beg, end);
ret << (rstr.isSharedWith(m_tmp1) ? str : ProString(rstr).setSource(str));
}
} else {
- foreach (const ProString &str, values(map(var))) {
+ for (const ProString &str : strings) {
const QString &rstr = str.toQString(m_tmp1).section(sep, beg, end);
ret << (rstr.isSharedWith(m_tmp1) ? str : ProString(rstr).setSource(str));
}
@@ -537,7 +541,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
bool leftalign = false;
enum { DefaultSign, PadSign, AlwaysSign } sign = DefaultSign;
if (args.count() >= 2) {
- foreach (const ProString &opt, split_value_list(args.at(1).toQString(m_tmp2))) {
+ const auto opts = split_value_list(args.at(1).toQString(m_tmp2));
+ for (const ProString &opt : opts) {
opt.toQString(m_tmp3);
if (m_tmp3.startsWith(QLatin1String("ibase="))) {
ibase = m_tmp3.mid(6).toInt();
@@ -565,7 +570,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
break;
}
bool ok;
- qlonglong num = m_tmp3.toLongLong(&ok, ibase);
+ qlonglong num = args.at(0).toLongLong(&ok, ibase);
if (!ok) {
evalError(fL1S("format_number(): malformed number %2 for base %1.")
.arg(ibase).arg(m_tmp3));
@@ -611,7 +616,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
const ProStringList &var = values(map(args.at(0)));
if (!var.isEmpty()) {
const ProFile *src = currentProFile();
- foreach (const ProString &v, var)
+ for (const ProString &v : var)
if (const ProFile *s = v.sourceFile()) {
src = s;
break;
@@ -626,9 +631,12 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
evalError(fL1S("split(var, sep) requires one or two arguments."));
} else {
const QString &sep = (args.count() == 2) ? args.at(1).toQString(m_tmp1) : statics.field_sep;
- foreach (const ProString &var, values(map(args.at(0))))
- foreach (const QString &splt, var.toQString(m_tmp2).split(sep))
+ const auto vars = values(map(args.at(0)));
+ for (const ProString &var : vars) {
+ const auto splits = var.toQString(m_tmp2).split(sep);
+ for (const QString &splt : splits)
ret << (splt.isSharedWith(m_tmp2) ? var : ProString(splt).setSource(var));
+ }
}
break;
case E_MEMBER:
@@ -639,7 +647,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
const ProStringList &var = values(map(args.at(0)));
int start = 0, end = 0;
if (args.count() >= 2) {
- const QString &start_str = args.at(1).toQString(m_tmp1);
+ const ProString &start_str = args.at(1);
start = start_str.toInt(&ok);
if (!ok) {
if (args.count() == 2) {
@@ -652,11 +660,11 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
}
if (!ok)
evalError(fL1S("member() argument 2 (start) '%2' invalid.")
- .arg(start_str));
+ .arg(start_str.toQString(m_tmp1)));
} else {
end = start;
if (args.count() == 3)
- end = args.at(2).toQString(m_tmp1).toInt(&ok);
+ end = args.at(2).toInt(&ok);
if (!ok)
evalError(fL1S("member() argument 3 (end) '%2' invalid.")
.arg(args.at(2).toQString(m_tmp1)));
@@ -759,7 +767,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
tmp.sprintf(".QMAKE_INTERNAL_TMP_variableName_%d", m_listCount++);
ret = ProStringList(ProString(tmp));
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
m_valuemapStack.top()[ret.at(0).toKey()] = lst;
break; }
@@ -769,7 +777,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
} else {
QRegExp regx(args.at(1).toQString());
int t = 0;
- foreach (const ProString &val, values(map(args.at(0)))) {
+ const auto vals = values(map(args.at(0)));
+ for (const ProString &val : vals) {
if (regx.indexIn(val.toQString(m_tmp[t])) != -1)
ret += val;
t ^= 1;
@@ -878,7 +887,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
} else {
const ProStringList &vals = values(args.at(0).toKey());
ret.reserve(vals.size());
- foreach (const ProString &str, vals)
+ for (const ProString &str : vals)
ret += ProString(quoteValue(str));
}
break;
@@ -903,7 +912,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
} else {
bool recursive = false;
if (args.count() == 2)
- recursive = isTrue(args.at(1), m_tmp2);
+ recursive = isTrue(args.at(1));
QStringList dirs;
QString r = m_option->expandEnvVars(args.at(0).toQString(m_tmp1))
.replace(QLatin1Char('\\'), QLatin1Char('/'));
@@ -966,7 +975,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
} else {
const QRegExp before(args.at(1).toQString());
const QString &after(args.at(2).toQString(m_tmp2));
- foreach (const ProString &val, values(map(args.at(0)))) {
+ const auto vals = values(map(args.at(0)));
+ for (const ProString &val : vals) {
QString rstr = val.toQString(m_tmp1);
QString copy = rstr; // Force a detach on modify
rstr.replace(before, after);
@@ -996,7 +1006,7 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
rootSet.erase(it);
if ((func_t == E_RESOLVE_DEPENDS) || orgList.contains(item))
ret.prepend(item);
- foreach (const ProString &dep, dependees[item.toKey()]) {
+ for (const ProString &dep : qAsConst(dependees[item.toKey()])) {
QSet<ProKey> &dset = dependencies[dep.toKey()];
dset.remove(item.toKey());
if (dset.isEmpty())
@@ -1007,11 +1017,11 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
break;
case E_ENUMERATE_VARS: {
QSet<ProString> keys;
- foreach (const ProValueMap &vmap, m_valuemapStack)
+ for (const ProValueMap &vmap : qAsConst(m_valuemapStack))
for (ProValueMap::ConstIterator it = vmap.constBegin(); it != vmap.constEnd(); ++it)
keys.insert(it.key());
ret.reserve(keys.size());
- foreach (const ProString &key, keys)
+ for (const ProString &key : qAsConst(keys))
ret << key;
break; }
case E_SHADOWED:
@@ -1199,7 +1209,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
regx.setPattern(copy);
}
int t = 0;
- foreach (const ProString &s, vars.value(map(args.at(1)))) {
+ const auto strings = vars.value(map(args.at(1)));
+ for (const ProString &s : strings) {
if ((!regx.isEmpty() && regx.exactMatch(s.toQString(m_tmp[t]))) || s == qry)
return ReturnTrue;
t ^= 1;
@@ -1294,7 +1305,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
return ReturnFalse;
}
int cnt = values(map(args.at(0))).count();
- int val = args.at(1).toQString(m_tmp1).toInt();
+ int val = args.at(1).toInt();
if (args.count() == 3) {
const ProString &comp = args.at(2);
if (comp == QLatin1String(">") || comp == QLatin1String("greaterThan")) {
@@ -1405,7 +1416,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
flags = LoadSilent;
if (args.count() >= 2) {
parseInto = args.at(1).toQString(m_tmp2);
- if (args.count() >= 3 && isTrue(args.at(2), m_tmp3))
+ if (args.count() >= 3 && isTrue(args.at(2)))
flags = LoadSilent;
}
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
@@ -1443,7 +1454,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
case T_LOAD: {
bool ignore_error = false;
if (args.count() == 2) {
- ignore_error = isTrue(args.at(1), m_tmp2);
+ ignore_error = isTrue(args.at(1));
} else if (args.count() != 1) {
evalError(fL1S("load(feature) requires one or two arguments."));
return ReturnFalse;
@@ -1577,7 +1588,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
if (!vals.isEmpty())
contents = vals.join(QLatin1Char('\n')) + QLatin1Char('\n');
if (args.count() >= 3) {
- foreach (const ProString &opt, split_value_list(args.at(2).toQString(m_tmp2))) {
+ const auto opts = split_value_list(args.at(2).toQString(m_tmp2));
+ for (const ProString &opt : opts) {
opt.toQString(m_tmp3);
if (m_tmp3 == QLatin1String("append")) {
mode = QIODevice::Append;
@@ -1649,7 +1661,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
enum { CacheSet, CacheAdd, CacheSub } mode = CacheSet;
ProKey srcvar;
if (args.count() >= 2) {
- foreach (const ProString &opt, split_value_list(args.at(1).toQString(m_tmp2))) {
+ const auto opts = split_value_list(args.at(1).toQString(m_tmp2));
+ for (const ProString &opt : opts) {
opt.toQString(m_tmp3);
if (m_tmp3 == QLatin1String("transient")) {
persist = false;
@@ -1767,7 +1780,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
varstr += QLatin1Char(' ');
varstr += quoteValue(diffval.at(0));
} else if (!diffval.isEmpty()) {
- foreach (const ProString &vval, diffval) {
+ for (const ProString &vval : diffval) {
varstr += QLatin1String(" \\\n ");
varstr += quoteValue(vval);
}