diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-07-13 11:17:47 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-07-13 15:29:31 -0300 |
commit | 6988b9cb5d770389123ced8f55cec617b2217ddb (patch) | |
tree | 6e3ecc09d34d8f4627581bf59f9ad8d7682d4ef6 /cppgenerator.cpp | |
parent | 4807359481f136145f404421ab8e99dd5f4cfefd (diff) |
Fixed wrong overload decisor generated code.
The decisor must check for the number of arguments before calling
Converter::isConvertible method, to avoid passing NULL pointers to it.
Unit tests were added.
Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Reviewed by Renato Araújo <renato.filho@openbossa.org>
Diffstat (limited to 'cppgenerator.cpp')
-rw-r--r-- | cppgenerator.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index a75542baa..3d9d74337 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -1544,17 +1544,6 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream& s, const Ov s << " else "; } - s << "if ("; - if (usePyArgs && signatureFound) { - AbstractMetaArgumentList args = refFunc->arguments(); - int lastArgIsVarargs = (int) (args.size() > 1 && args.last()->type()->isVarargs()); - int numArgs = args.size() - OverloadData::numberOfRemovedArguments(refFunc) - lastArgIsVarargs; - s << "numArgs " << (lastArgIsVarargs ? ">=" : "==") << " " << numArgs << " && "; - } - - if (refFunc->isOperatorOverload()) - s << (refFunc->isReverseOperator() ? "" : "!") << "isReverse && "; - QString typeChecks; QTextStream tck(&typeChecks); QString typeConversions; @@ -1563,11 +1552,14 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream& s, const Ov QString pyArgName = (usePyArgs && maxArgs > 1) ? QString("pyargs[%1]").arg(overloadData->argPos()) : "arg"; OverloadData* od = overloadData; + int startArg = od->argPos(); + int sequenceArgCount = 0; while (od && !od->argType()->isVarargs()) { if (usePyArgs && maxArgs > 1) pyArgName = QString("pyargs[%1]").arg(od->argPos()); writeTypeCheck(tck, od, pyArgName); + sequenceArgCount++; if (od->nextOverloadData().isEmpty() || od->nextArgumentHasDefaultValue() @@ -1582,6 +1574,19 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream& s, const Ov } } + s << "if ("; + if (usePyArgs && signatureFound) { + AbstractMetaArgumentList args = refFunc->arguments(); + int lastArgIsVarargs = (int) (args.size() > 1 && args.last()->type()->isVarargs()); + int numArgs = args.size() - OverloadData::numberOfRemovedArguments(refFunc) - lastArgIsVarargs; + s << "numArgs " << (lastArgIsVarargs ? ">=" : "==") << " " << numArgs << " && "; + } else if (sequenceArgCount > 1) { + s << "numArgs >= " << (startArg + sequenceArgCount) << " && "; + } + + if (refFunc->isOperatorOverload()) + s << (refFunc->isReverseOperator() ? "" : "!") << "isReverse && "; + s << typeChecks << ") {" << endl; s << typeConversions; |