Skip to content

Commit

Permalink
add $$num_add() (numeric addition) function
Browse files Browse the repository at this point in the history
amazing how we managed to do without it for so long. ^^

the name is intentionally somewhat obscure to avoid clashes, and some
namespacing is good anyway.

[ChangeLog][qmake] Added $$num_add() function.

Change-Id: Ib7648b1f425ef096a87b51f158d0f1409e5c4daa
Reviewed-by: Leena Miettinen <[email protected]>
Reviewed-by: Lars Knoll <[email protected]>
Reviewed-by: Joerg Bornemann <[email protected]>
(cherry picked from qtbase/d3cc25ef52d0b2b7ba1cb06609f7c205ee19c2d6)
Reviewed-by: Jake Petroules <[email protected]>
  • Loading branch information
ossilator committed Oct 10, 2016
1 parent 25d06d2 commit 0711887
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/linguist/shared/qmakebuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ QT_BEGIN_NAMESPACE

enum ExpandFunc {
E_INVALID = 0, E_MEMBER, E_FIRST, E_TAKE_FIRST, E_LAST, E_TAKE_LAST, E_SIZE,
E_CAT, E_FROMFILE, E_EVAL, E_LIST,
E_SPRINTF, E_FORMAT_NUMBER, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
E_CAT, E_FROMFILE, E_EVAL, E_LIST, E_SPRINTF, E_FORMAT_NUMBER,
E_NUM_ADD, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
E_FIND, E_SYSTEM, E_UNIQUE, E_REVERSE, E_QUOTE, E_ESCAPE_EXPAND,
E_UPPER, E_LOWER, E_TITLE, E_FILES, E_PROMPT, E_RE_ESCAPE, E_VAL_ESCAPE,
E_REPLACE, E_SORT_DEPENDS, E_RESOLVE_DEPENDS, E_ENUMERATE_VARS,
Expand Down Expand Up @@ -120,6 +120,7 @@ void QMakeEvaluator::initFunctionStatics()
{ "list", E_LIST },
{ "sprintf", E_SPRINTF },
{ "format_number", E_FORMAT_NUMBER },
{ "num_add", E_NUM_ADD },
{ "join", E_JOIN },
{ "split", E_SPLIT },
{ "basename", E_BASENAME },
Expand Down Expand Up @@ -603,6 +604,29 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
}
formfail:
break;
case E_NUM_ADD:
if (args.count() < 1 || args.at(0).isEmpty()) {
evalError(fL1S("num_add(num, ...) requires at least one argument."));
} else {
qlonglong sum = 0;
for (const ProString &arg : qAsConst(args)) {
if (arg.contains(QLatin1Char('.'))) {
evalError(fL1S("num_add(): floats are currently not supported."));
goto nafail;
}
bool ok;
qlonglong num = arg.toLongLong(&ok);
if (!ok) {
evalError(fL1S("num_add(): malformed number %1.")
.arg(arg.toQString(m_tmp3)));
goto nafail;
}
sum += num;
}
ret += ProString(QString::number(sum));
}
nafail:
break;
case E_JOIN: {
if (args.count() < 1 || args.count() > 4) {
evalError(fL1S("join(var, glue, before, after) requires one to four arguments."));
Expand Down

0 comments on commit 0711887

Please sign in to comment.