aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cppgenerator.cpp19
-rw-r--r--shibokengenerator.cpp7
-rw-r--r--shibokengenerator.h4
3 files changed, 18 insertions, 12 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 84dcdee70..76b233e28 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -299,9 +299,10 @@ void CppGenerator::writeConstructorNative(QTextStream& s, const AbstractMetaFunc
if (usePySideExtensions() && func->ownerClass()->isQObject())
s << ", m_metaObject(0)";
s << " {" << endl;
- writeCodeSnips(s, func->injectedCodeSnips(), CodeSnip::Beginning, TypeSystem::NativeCode, func);
+ const AbstractMetaArgument* lastArg = func->arguments().isEmpty() ? 0 : func->arguments().last();
+ writeCodeSnips(s, func->injectedCodeSnips(), CodeSnip::Beginning, TypeSystem::NativeCode, func, lastArg);
s << INDENT << "// ... middle" << endl;
- writeCodeSnips(s, func->injectedCodeSnips(), CodeSnip::End, TypeSystem::NativeCode, func);
+ writeCodeSnips(s, func->injectedCodeSnips(), CodeSnip::End, TypeSystem::NativeCode, func, lastArg);
s << '}' << endl << endl;
}
@@ -402,7 +403,8 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
if (injectedCodeUsesPySelf(func))
s << INDENT << "PyObject* pySelf = BindingManager::instance().retrieveWrapper(this);" << endl;
- writeCodeSnips(s, snips, CodeSnip::Beginning, TypeSystem::NativeCode, func);
+ const AbstractMetaArgument* lastArg = func->arguments().isEmpty() ? 0 : func->arguments().last();
+ writeCodeSnips(s, snips, CodeSnip::Beginning, TypeSystem::NativeCode, func, lastArg);
s << endl;
}
@@ -426,7 +428,8 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
if (func->hasInjectedCode()) {
s << endl;
- writeCodeSnips(s, snips, CodeSnip::End, TypeSystem::NativeCode, func);
+ const AbstractMetaArgument* lastArg = func->arguments().isEmpty() ? 0 : func->arguments().last();
+ writeCodeSnips(s, snips, CodeSnip::End, TypeSystem::NativeCode, func, lastArg);
}
s << INDENT << "Py_XDECREF(pyargs);" << endl;
@@ -1057,14 +1060,15 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f
// Find the last argument available in the method call to provide
// the injected code writer with information to avoid invalid replacements
// on the %# variable.
- if (maxArgs > 0
- && maxArgs < func->arguments().size() - OverloadData::numberOfRemovedArguments(func)) {
+ if (maxArgs > 0 && maxArgs < func->arguments().size() - OverloadData::numberOfRemovedArguments(func)) {
int removedArgs = 0;
for (int i = 0; i < maxArgs + removedArgs; i++) {
lastArg = func->arguments()[i];
if (func->argumentRemoved(i + 1))
removedArgs++;
}
+ } else if (maxArgs != 0 && !func->arguments().isEmpty()) {
+ lastArg = func->arguments().last();
}
writeCodeSnips(s, snips, CodeSnip::Beginning, TypeSystem::TargetLangCode, func, lastArg);
@@ -1535,7 +1539,8 @@ void CppGenerator::writeSequenceMethods(QTextStream& s, const AbstractMetaClass*
s << cpythonWrapperCPtr(func->ownerClass(), "self") << ';' << endl;
s << INDENT << "(void)cppSelf; // avoid warnings about unused variables" << endl;
- writeCodeSnips(s, snips,CodeSnip::Any, TypeSystem::TargetLangCode, func);
+ const AbstractMetaArgument* lastArg = func->arguments().isEmpty() ? 0 : func->arguments().last();
+ writeCodeSnips(s, snips,CodeSnip::Any, TypeSystem::TargetLangCode, func, lastArg);
s << '}' << endl << endl;
}
}
diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp
index d8b4aefb2..933aca5fa 100644
--- a/shibokengenerator.cpp
+++ b/shibokengenerator.cpp
@@ -930,14 +930,13 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s,
const AbstractMetaArgument* arg = func->arguments().at(i);
QString argReplacement;
if (snip.language == TypeSystem::TargetLangCode) {
- if (func->argumentRemoved(i+1)) {
+ if (!lastArg || func->argumentRemoved(i+1)) {
if (!arg->defaultValueExpression().isEmpty())
argReplacement = arg->defaultValueExpression();
removed++;
- }
-
- if (lastArg && arg->argumentIndex() > lastArg->argumentIndex())
+ } else if (lastArg && (arg->argumentIndex() > lastArg->argumentIndex())) {
argReplacement = arg->defaultValueExpression();
+ }
if (argReplacement.isEmpty()) {
argReplacement = QString("cpp_arg%1").arg(i - removed);
diff --git a/shibokengenerator.h b/shibokengenerator.h
index 74477ad77..83cf195f8 100644
--- a/shibokengenerator.h
+++ b/shibokengenerator.h
@@ -102,7 +102,9 @@ public:
* \param position the position to insert the code snip
* \param language the kind of code snip
* \param func the cpp function
- * \param lastArg last argument whose value is available
+ * \param lastArg last argument whose value is available, usually the last;
+ * a NULL pointer indicates that no argument will be available,
+ * i.e. a call without arguments.
* \param context the class context for the place where the code snip will be written
*/
void writeCodeSnips(QTextStream &s,