fix custom functions inheriting other functions' arguments

Task-number: QTBUG-41830
Change-Id: Iba3eee4975a1ee671b7190e52c0efc9a18147c62
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Oswald Buddenhagen 2016-06-30 17:26:01 +02:00
parent 1b4ea11332
commit dacf3994ba
2 changed files with 56 additions and 17 deletions

View File

@ -1809,19 +1809,35 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::checkRequirements(const ProStringLis
}
#endif
static bool isFunctParam(const ProKey &variableName)
{
const int len = variableName.size();
const QChar *data = variableName.constData();
for (int i = 0; i < len; i++) {
ushort c = data[i].unicode();
if (c < '0' || c > '9')
return false;
}
return true;
}
ProValueMap *QMakeEvaluator::findValues(const ProKey &variableName, ProValueMap::Iterator *rit)
{
ProValueMapStack::Iterator vmi = m_valuemapStack.end();
do {
for (bool first = true; ; first = false) {
--vmi;
ProValueMap::Iterator it = (*vmi).find(variableName);
if (it != (*vmi).end()) {
if (it->constBegin() == statics.fakeValue.constBegin())
return 0;
break;
*rit = it;
return &(*vmi);
}
} while (vmi != m_valuemapStack.begin());
if (vmi == m_valuemapStack.begin())
break;
if (first && isFunctParam(variableName))
break;
}
return 0;
}
@ -1833,18 +1849,20 @@ ProStringList &QMakeEvaluator::valuesRef(const ProKey &variableName)
it->clear();
return *it;
}
ProValueMapStack::Iterator vmi = m_valuemapStack.end();
if (--vmi != m_valuemapStack.begin()) {
do {
--vmi;
ProValueMap::ConstIterator it = (*vmi).constFind(variableName);
if (it != (*vmi).constEnd()) {
ProStringList &ret = m_valuemapStack.top()[variableName];
if (it->constBegin() != statics.fakeValue.constBegin())
ret = *it;
return ret;
}
} while (vmi != m_valuemapStack.begin());
if (!isFunctParam(variableName)) {
ProValueMapStack::Iterator vmi = m_valuemapStack.end();
if (--vmi != m_valuemapStack.begin()) {
do {
--vmi;
ProValueMap::ConstIterator it = (*vmi).constFind(variableName);
if (it != (*vmi).constEnd()) {
ProStringList &ret = m_valuemapStack.top()[variableName];
if (it->constBegin() != statics.fakeValue.constBegin())
ret = *it;
return ret;
}
} while (vmi != m_valuemapStack.begin());
}
}
return m_valuemapStack.top()[variableName];
}
@ -1852,7 +1870,7 @@ ProStringList &QMakeEvaluator::valuesRef(const ProKey &variableName)
ProStringList QMakeEvaluator::values(const ProKey &variableName) const
{
ProValueMapStack::ConstIterator vmi = m_valuemapStack.constEnd();
do {
for (bool first = true; ; first = false) {
--vmi;
ProValueMap::ConstIterator it = (*vmi).constFind(variableName);
if (it != (*vmi).constEnd()) {
@ -1860,7 +1878,11 @@ ProStringList QMakeEvaluator::values(const ProKey &variableName) const
break;
return *it;
}
} while (vmi != m_valuemapStack.constBegin());
if (vmi == m_valuemapStack.constBegin())
break;
if (first && isFunctParam(variableName))
break;
}
return ProStringList();
}

View File

@ -599,6 +599,23 @@ void tst_qmakelib::addControlStructs()
<< ""
<< true;
QTest::newRow("function arguments")
<< "defineTest(func) {\n"
"defined(1, var) {\nd1 = 1\nexport(d1)\n}\n"
"defined(3, var) {\nd3 = 1\nexport(d3)\n}\n"
"x1 = $$1\nexport(x1)\n"
"2 += foo\nx2 = $$2\nexport(x2)\n"
"x3 = $$3\nexport(x3)\n"
"4 += foo\nx4 = $$4\nexport(x4)\n"
"x5 = $$5\nexport(x5)\n"
"6 += foo\nx6 = $$6\nexport(x6)\n"
"}\n"
"1 = first\n2 = second\n3 = third\n4 = fourth\nfunc(one, two)"
<< "1 = first\n2 = second\n3 = third\n4 = fourth\n5 = UNDEF\n6 = UNDEF\n"
"d1 = 1\nd3 = UNDEF\nx1 = one\nx2 = two foo\nx3 =\nx4 = foo\nx5 =\nx6 = foo"
<< ""
<< true;
QTest::newRow("ARGC and ARGS")
<< "defineTest(func) {\n"
"export(ARGC)\n"