diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-11-04 12:34:17 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-11-04 12:42:35 +0100 |
commit | 1704567d7ad0d21dd3b588af7aad40cd244c1799 (patch) | |
tree | 932b42988e482f01125dcbf4d470e9a56107689a /sources/shiboken2/generator | |
parent | 1d77cd18510412242384c5b37a00efd5b6ce8a26 (diff) | |
parent | c98ef56544cd54661b61529829caf6a799a1a94f (diff) |
Merge "Merge remote-tracking branch 'origin/5.14' into 5.15"
Diffstat (limited to 'sources/shiboken2/generator')
8 files changed, 103 insertions, 90 deletions
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp index 6da9fd933..7c6e921c7 100644 --- a/sources/shiboken2/generator/generator.cpp +++ b/sources/shiboken2/generator/generator.cpp @@ -760,7 +760,7 @@ DefaultValue Generator::minimalConstructor(const AbstractMetaClass *metaClass) c bool simple = true; bool suitable = true; for (int i = 0, size = arguments.size(); - suitable && i < size && !arguments.at(i)->hasDefaultValueExpression(); ++i) { + suitable && i < size && !arguments.at(i)->hasOriginalDefaultValueExpression(); ++i) { const AbstractMetaArgument *arg = arguments.at(i); const TypeEntry *aType = arg->type()->typeEntry(); suitable &= aType != cType; @@ -777,11 +777,12 @@ DefaultValue Generator::minimalConstructor(const AbstractMetaClass *metaClass) c bool ok = true; for (int i =0, size = arguments.size(); ok && i < size; ++i) { const AbstractMetaArgument *arg = arguments.at(i); - if (arg->hasDefaultValueExpression()) { - if (arg->hasModifiedDefaultValueExpression()) - args << arg->defaultValueExpression(); // Spell out modified values + if (arg->hasModifiedDefaultValueExpression()) { + args << arg->defaultValueExpression(); // Spell out modified values break; } + if (arg->hasOriginalDefaultValueExpression()) + break; auto argValue = minimalConstructor(arg->type()); ok &= argValue.isValid(); args << argValue.constructorParameter(); diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp index 9cad400f3..86abf21b0 100644 --- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp @@ -349,6 +349,7 @@ QtXmlToSphinx::QtXmlToSphinx(QtDocGenerator* generator, const QString& doc, cons m_handlerMap.insert(QLatin1String("skipto"), &QtXmlToSphinx::handleIgnoredTag); m_handlerMap.insert(QLatin1String("target"), &QtXmlToSphinx::handleTargetTag); m_handlerMap.insert(QLatin1String("page"), &QtXmlToSphinx::handlePageTag); + m_handlerMap.insert(QLatin1String("group"), &QtXmlToSphinx::handlePageTag); // useless tags m_handlerMap.insert(QLatin1String("description"), &QtXmlToSphinx::handleUselessTag); @@ -1023,6 +1024,8 @@ QtXmlToSphinx::LinkContext *QtXmlToSphinx::handleLinkStart(const QString &type, result->type = LinkContext::External; else result->type = LinkContext::Reference; + } else if (type == QLatin1String("external")) { + result->type = LinkContext::External; } else { result->type = LinkContext::Reference; } @@ -1228,14 +1231,11 @@ void QtXmlToSphinx::handlePageTag(QXmlStreamReader &reader) m_output << rstLabel(title.toString()); const QStringRef fullTitle = reader.attributes().value(fullTitleAttribute()); - if (!fullTitle.isEmpty()) { - const int size = writeEscapedRstText(m_output, fullTitle); - m_output << endl << Pad('*', size) << endl << endl; - } + const int size = fullTitle.isEmpty() + ? writeEscapedRstText(m_output, title) + : writeEscapedRstText(m_output, fullTitle); - const QStringRef brief = reader.attributes().value(briefAttribute()); - if (!brief.isEmpty()) - m_output << escape(brief) << endl << endl; + m_output << endl << Pad('*', size) << endl << endl; } void QtXmlToSphinx::handleTargetTag(QXmlStreamReader &reader) @@ -1621,7 +1621,7 @@ void QtDocGenerator::generateClass(QTextStream &s, GeneratorContext &classContex m_docParser->setPackageName(metaClass->package()); m_docParser->fillDocumentation(const_cast<AbstractMetaClass*>(metaClass)); - s << ".. module:: " << metaClass->package() << endl; + s << ".. currentmodule:: " << metaClass->package() << endl; QString className = getClassTargetFullName(metaClass, false); s << ".. _" << className << ":" << endl << endl; @@ -2301,8 +2301,9 @@ void QtDocGenerator::writeAdditionalDocumentation() if (fi.isFile()) { const QString rstFileName = fi.baseName() + rstSuffix; const QString rstFile = targetDir + QLatin1Char('/') + rstFileName; + const QString context = targetDir.mid(targetDir.lastIndexOf(QLatin1Char('/')) + 1); if (QtXmlToSphinx::convertToRst(this, fi.absoluteFilePath(), - rstFile, QString(), &errorMessage)) { + rstFile, context, &errorMessage)) { ++successCount; qCDebug(lcShiboken).nospace().noquote() << __FUNCTION__ << " converted " << fi.fileName() diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 5a4aa8eba..5460fd7c7 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -317,7 +317,10 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) s << "#include <pyside.h>" << endl; s << "#include <destroylistener.h>" << endl; s << "#include <qapp_macro.h>" << endl; - } + s << endl; + s << "QT_WARNING_DISABLE_DEPRECATED" << endl; + s << endl; + } s << "#include <typeinfo>" << endl; if (usePySideExtensions() && metaClass->isQObject()) { @@ -368,9 +371,6 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) if (metaClass->typeEntry()->typeFlags() & ComplexTypeEntry::Deprecated) s << "#Deprecated" << endl; - if (usePySideExtensions()) - s << "\nQT_WARNING_DISABLE_DEPRECATED\n"; - // Use class base namespace { const AbstractMetaClass *context = metaClass->enclosingClass(); @@ -1860,18 +1860,19 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction // For custom classes, operations like __radd__ and __rmul__ // will enter an infinite loop. if (rfunc->isBinaryOperator() && revOpName.contains(QLatin1String("shift"))) { + s << INDENT << "Shiboken::AutoDecRef attrName(Py_BuildValue(\"s\", \"" << revOpName << "\"));" << endl; s << INDENT << "if (!isReverse" << endl; { Indentation indent(INDENT); s << INDENT << "&& Shiboken::Object::checkType(" << PYTHON_ARG << ")" << endl; s << INDENT << "&& !PyObject_TypeCheck(" << PYTHON_ARG << ", self->ob_type)" << endl; - s << INDENT << "&& PyObject_HasAttrString(" << PYTHON_ARG << ", const_cast<char *>(\"" << revOpName << "\"))) {" << endl; + s << INDENT << "&& PyObject_HasAttr(" << PYTHON_ARG << ", attrName)) {" << endl; // This PyObject_CallMethod call will emit lots of warnings like // "deprecated conversion from string constant to char *" during compilation // due to the method name argument being declared as "char *" instead of "const char *" // issue 6952 http://bugs.python.org/issue6952 - s << INDENT << "PyObject *revOpMethod = PyObject_GetAttrString(" << PYTHON_ARG << ", const_cast<char *>(\"" << revOpName << "\"));" << endl; + s << INDENT << "PyObject *revOpMethod = PyObject_GetAttr(" << PYTHON_ARG << ", attrName);" << endl; s << INDENT << "if (revOpMethod && PyCallable_Check(revOpMethod)) {" << endl; { Indentation indent(INDENT); @@ -2154,6 +2155,8 @@ void CppGenerator::writeTypeCheck(QTextStream &s, const AbstractMetaType *argTyp QString customCheck; if (!customType.isEmpty()) { AbstractMetaType *metaType; + // PYSIDE-795: Note: XML-Overrides are handled in this shibokengenerator function! + // This enables iterables for QMatrix4x4 for instance. customCheck = guessCPythonCheckFunction(customType, &metaType); if (metaType) argType = metaType; @@ -2939,6 +2942,9 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s, typeCheck = QLatin1String("PyType_Check(%in)"); else if (pyTypeName == QLatin1String("PyObject")) typeCheck = QLatin1String("PyObject_TypeCheck(%in, &PyBaseObject_Type)"); + // PYSIDE-795: We abuse PySequence for iterables + else if (pyTypeName == QLatin1String("PySequence")) + typeCheck = QLatin1String("Shiboken::String::checkIterable(%in)"); else if (pyTypeName.startsWith(QLatin1String("Py"))) typeCheck = pyTypeName + QLatin1String("_Check(%in)"); } @@ -3039,29 +3045,31 @@ void CppGenerator::writeNamedArgumentResolution(QTextStream &s, const AbstractMe QString pyArgName = usePyArgs ? pythonArgsAt(pyArgIndex) : QLatin1String(PYTHON_ARG); s << INDENT << "keyName = Py_BuildValue(\"s\",\"" << arg->name() << "\");" << endl; s << INDENT << "if (PyDict_Contains(kwds, keyName)) {" << endl; - s << INDENT << "value = PyDict_GetItemString(kwds, \"" << arg->name() << "\");" << endl; - s << INDENT << "if (value && " << pyArgName << ") {" << endl; { Indentation indent(INDENT); - s << INDENT << pyErrString.arg(arg->name()) << endl; - s << INDENT << returnStatement(m_currentErrorCode) << endl; - } - s << INDENT << INDENT << "} else if (value) {" << endl; - { - Indentation indent(INDENT); - s << INDENT << pyArgName << " = value;" << endl; - s << INDENT << "if (!"; - writeTypeCheck(s, arg->type(), pyArgName, isNumber(arg->type()->typeEntry()), func->typeReplaced(arg->argumentIndex() + 1)); - s << ')' << endl; + s << INDENT << "value = PyDict_GetItem(kwds, keyName);" << endl; + s << INDENT << "if (value && " << pyArgName << ") {" << endl; { Indentation indent(INDENT); - s << INDENT << "goto " << cpythonFunctionName(func) << "_TypeError;" << endl; + s << INDENT << pyErrString.arg(arg->name()) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << endl; } + s << INDENT << '}' << endl; + s << INDENT << "if (value) {" << endl; + { + Indentation indent(INDENT); + s << INDENT << pyArgName << " = value;" << endl; + s << INDENT << "if (!"; + writeTypeCheck(s, arg->type(), pyArgName, isNumber(arg->type()->typeEntry()), func->typeReplaced(arg->argumentIndex() + 1)); + s << ')' << endl; + { + Indentation indent(INDENT); + s << INDENT << "goto " << cpythonFunctionName(func) << "_TypeError;" << endl; + } + } + s << INDENT << '}' << endl; } s << INDENT << '}' << endl; - if (arg != args.constLast()) - s << INDENT; - s << "}" << endl; } } s << INDENT << '}' << endl; @@ -3933,9 +3941,10 @@ void CppGenerator::writeClassDefinition(QTextStream &s, m_tpFuncs[func->name()] = cpythonFunctionName(func); } if (m_tpFuncs.value(QLatin1String("__repr__")).isEmpty() - && !metaClass->isQObject() && metaClass->hasToStringCapability()) { - m_tpFuncs[QLatin1String("__repr__")] = writeReprFunction(s, classContext); + m_tpFuncs[QLatin1String("__repr__")] = writeReprFunction(s, + classContext, + metaClass->toStringCapabilityIndirections()); } // class or some ancestor has multiple inheritance @@ -4608,6 +4617,15 @@ void CppGenerator::writeEnumsInitialization(QTextStream &s, AbstractMetaEnumList } } +static QString mangleName(QString name) +{ + if ( name == QLatin1String("None") + || name == QLatin1String("False") + || name == QLatin1String("True")) + name += QLatin1Char('_'); + return name; +} + void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnum *cppEnum) { const AbstractMetaClass *enclosingClass = getProperEnclosingClassForEnum(cppEnum); @@ -4687,7 +4705,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu Indentation indent(INDENT); s << INDENT << "PyObject *anonEnumItem = PyInt_FromLong(" << enumValueText << ");" << endl; s << INDENT << "if (PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(reinterpret_cast<SbkObjectType *>(" << enclosingObjectVariable - << "))->tp_dict, \"" << enumValue->name() << "\", anonEnumItem) < 0)" << endl; + << "))->tp_dict, \"" << mangleName(enumValue->name()) << "\", anonEnumItem) < 0)" << endl; { Indentation indent(INDENT); s << INDENT << returnStatement(m_currentErrorCode) << endl; @@ -4696,7 +4714,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu } s << INDENT << '}' << endl; } else { - s << INDENT << "if (PyModule_AddIntConstant(module, \"" << enumValue->name() << "\", "; + s << INDENT << "if (PyModule_AddIntConstant(module, \"" << mangleName(enumValue->name()) << "\", "; s << enumValueText << ") < 0)" << endl; { Indentation indent(INDENT); @@ -4709,7 +4727,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu s << ((enclosingClass || hasUpperEnclosingClass) ? "createScopedEnumItem" : "createGlobalEnumItem"); s << '(' << enumVarTypeObj << ',' << endl; Indentation indent(INDENT); - s << INDENT << enclosingObjectVariable << ", \"" << enumValue->name() << "\", "; + s << INDENT << enclosingObjectVariable << ", \"" << mangleName(enumValue->name()) << "\", "; s << enumValueText << "))" << endl; s << INDENT << returnStatement(m_currentErrorCode) << endl; } @@ -4718,7 +4736,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu s << INDENT << "if (!Shiboken::Enum::createScopedEnumItem(" << enumVarTypeObj << ',' << endl; Indentation indent(INDENT); - s << INDENT << enumVarTypeObj<< ", \"" << enumValue->name() << "\", " + s << INDENT << enumVarTypeObj<< ", \"" << mangleName(enumValue->name()) << "\", " << enumValueText << "))" << endl << INDENT << returnStatement(m_currentErrorCode) << endl; } @@ -5541,10 +5559,11 @@ bool CppGenerator::finishGeneration() { Indentation indentation(INDENT); s << INDENT << "PyObject *pyType = reinterpret_cast<PyObject *>(" << cppApiVariableName() << "[i]);" << endl; - s << INDENT << "if (pyType && PyObject_HasAttrString(pyType, \"staticMetaObject\"))"<< endl; + s << INDENT << "Shiboken::AutoDecRef attrName(Py_BuildValue(\"s\", \"staticMetaObject\"));" << endl; + s << INDENT << "if (pyType && PyObject_HasAttr(pyType, attrName))"<< endl; { Indentation indentation(INDENT); - s << INDENT << "PyObject_SetAttrString(pyType, \"staticMetaObject\", Py_None);" << endl; + s << INDENT << "PyObject_SetAttr(pyType, attrName, Py_None);" << endl; } } s << INDENT << "}" << endl; @@ -5981,7 +6000,9 @@ void CppGenerator::writeIndexError(QTextStream &s, const QString &errorMsg) s << INDENT << '}' << endl; } -QString CppGenerator::writeReprFunction(QTextStream &s, GeneratorContext &context) +QString CppGenerator::writeReprFunction(QTextStream &s, + GeneratorContext &context, + uint indirections) { const AbstractMetaClass *metaClass = context.metaClass(); QString funcName = cpythonBaseName(metaClass) + QLatin1String("__repr__"); @@ -5994,7 +6015,7 @@ QString CppGenerator::writeReprFunction(QTextStream &s, GeneratorContext &contex s << INDENT << "buffer.open(QBuffer::ReadWrite);" << endl; s << INDENT << "QDebug dbg(&buffer);" << endl; s << INDENT << "dbg << "; - if (metaClass->typeEntry()->isValue()) + if (metaClass->typeEntry()->isValue() || indirections == 0) s << '*'; s << CPP_SELF_VAR << ';' << endl; s << INDENT << "buffer.close();" << endl; @@ -6005,7 +6026,8 @@ QString CppGenerator::writeReprFunction(QTextStream &s, GeneratorContext &contex Indentation indent(INDENT); s << INDENT << "str.replace(0, idx, Py_TYPE(self)->tp_name);" << endl; } - s << INDENT << "PyObject *mod = PyDict_GetItemString(Py_TYPE(self)->tp_dict, \"__module__\");" << endl; + s << INDENT << "str = str.trimmed();" << endl; + s << INDENT << "PyObject *mod = PyDict_GetItem(Py_TYPE(self)->tp_dict, Shiboken::PyMagicName::module());" << endl; // PYSIDE-595: The introduction of heap types has the side effect that the module name // is always prepended to the type name. Therefore the strchr check: s << INDENT << "if (mod && !strchr(str, '.'))" << endl; diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.h b/sources/shiboken2/generator/shiboken2/cppgenerator.h index ae6da9582..005518f96 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.h +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.h @@ -336,7 +336,7 @@ private: /// Helper function for writeStdListWrapperMethods. void writeIndexError(QTextStream &s, const QString &errorMsg); - QString writeReprFunction(QTextStream &s, GeneratorContext &context); + QString writeReprFunction(QTextStream &s, GeneratorContext &context, uint indirections); const AbstractMetaFunction *boolCast(const AbstractMetaClass *metaClass) const; bool hasBoolCast(const AbstractMetaClass *metaClass) const diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp index 8a2c56232..e47c37523 100644 --- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp @@ -454,6 +454,11 @@ bool HeaderGenerator::finishGeneration() // TODO-CONVERTER ------------------------------------------------------------------------------ macrosStream << "// Macros for type check" << endl; + + if (usePySideExtensions()) { + typeFunctions << "QT_WARNING_PUSH" << endl; + typeFunctions << "QT_WARNING_DISABLE_DEPRECATED" << endl; + } for (const AbstractMetaEnum *cppEnum : qAsConst(globalEnums)) { if (cppEnum->isAnonymous() || cppEnum->isPrivate()) continue; @@ -489,6 +494,8 @@ bool HeaderGenerator::finishGeneration() includes << classType->include(); writeSbkTypeFunction(typeFunctions, metaType); } + if (usePySideExtensions()) + typeFunctions << "QT_WARNING_POP" << endl; QString moduleHeaderFileName(outputDirectory() + QDir::separator() + subDirectoryForPackage(packageName()) diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.cpp b/sources/shiboken2/generator/shiboken2/overloaddata.cpp index 4aa5e5c02..5f74ee64d 100644 --- a/sources/shiboken2/generator/shiboken2/overloaddata.cpp +++ b/sources/shiboken2/generator/shiboken2/overloaddata.cpp @@ -520,7 +520,7 @@ void OverloadData::addOverload(const AbstractMetaFunction *func) for (int i = 0; m_headOverloadData->m_minArgs > 0 && i < origNumArgs; i++) { if (func->argumentRemoved(i + 1)) continue; - if (!ShibokenGenerator::getDefaultValue(func, func->arguments().at(i)).isEmpty()) { + if (func->arguments().at(i)->hasDefaultValueExpression()) { int fixedArgIndex = i - removed; if (fixedArgIndex < m_headOverloadData->m_minArgs) m_headOverloadData->m_minArgs = fixedArgIndex; @@ -754,7 +754,7 @@ const AbstractMetaFunction *OverloadData::getFunctionWithDefaultValue() const if (func->argumentRemoved(i + 1)) removedArgs++; } - if (!ShibokenGenerator::getDefaultValue(func, func->arguments().at(m_argPos + removedArgs)).isEmpty()) + if (func->arguments().at(m_argPos + removedArgs)->hasDefaultValueExpression()) return func; } return nullptr; @@ -771,7 +771,7 @@ QVector<int> OverloadData::invalidArgumentLengths() const if (func->argumentRemoved(i+1)) { offset++; } else { - if (!ShibokenGenerator::getDefaultValue(func, args[i]).isEmpty()) + if (args.at(i)->hasDefaultValueExpression()) validArgLengths << i-offset; } } @@ -820,7 +820,7 @@ QPair<int, int> OverloadData::getMinMaxArguments(const AbstractMetaFunctionList if (func->argumentRemoved(j + 1)) continue; int fixedArgIndex = j - removed; - if (fixedArgIndex < minArgs && !ShibokenGenerator::getDefaultValue(func, func->arguments().at(j)).isEmpty()) + if (fixedArgIndex < minArgs && func->arguments().at(j)->hasDefaultValueExpression()) minArgs = fixedArgIndex; } } @@ -967,7 +967,7 @@ QString OverloadData::dumpGraph() const const AbstractMetaArgument *arg = argument(func); if (!arg) continue; - QString argDefault = ShibokenGenerator::getDefaultValue(func, arg); + QString argDefault = arg->defaultValueExpression(); if (!argDefault.isEmpty() || argDefault != arg->originalDefaultValueExpression()) { s << "<tr><td bgcolor=\"gray\" align=\"right\">f" << functionNumber(func); @@ -1038,7 +1038,7 @@ bool OverloadData::hasArgumentWithDefaultValue(const AbstractMetaFunction *func) for (const AbstractMetaArgument *arg : arguments) { if (func->argumentRemoved(arg->argumentIndex() + 1)) continue; - if (!ShibokenGenerator::getDefaultValue(func, arg).isEmpty()) + if (arg->hasDefaultValueExpression()) return true; } return false; @@ -1049,7 +1049,7 @@ AbstractMetaArgumentList OverloadData::getArgumentsWithDefaultValues(const Abstr AbstractMetaArgumentList args; const AbstractMetaArgumentList &arguments = func->arguments(); for (AbstractMetaArgument *arg : arguments) { - if (ShibokenGenerator::getDefaultValue(func, arg).isEmpty() + if (!arg->hasDefaultValueExpression() || func->argumentRemoved(arg->argumentIndex() + 1)) continue; args << arg; diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 34e43a4c7..fd75c620e 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -324,18 +324,16 @@ bool ShibokenGenerator::shouldGenerateCppWrapper(const AbstractMetaClass *metaCl void ShibokenGenerator::lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumList &enumList, const AbstractMetaClass *metaClass) { - if (!metaClass) - return; - + Q_ASSERT(metaClass); + // if a scope is not to be generated, collect its enums into the parent scope if (metaClass->typeEntry()->codeGeneration() == TypeEntry::GenerateForSubclass) { const AbstractMetaEnumList &enums = metaClass->enums(); - for (const AbstractMetaEnum *metaEnum : enums) { - if (metaEnum->isPrivate() || metaEnum->typeEntry()->codeGeneration() == TypeEntry::GenerateForSubclass) - continue; - if (!enumList.contains(const_cast<AbstractMetaEnum *>(metaEnum))) - enumList.append(const_cast<AbstractMetaEnum *>(metaEnum)); + for (AbstractMetaEnum *metaEnum : enums) { + if (!metaEnum->isPrivate() && metaEnum->typeEntry()->generateCode() + && !enumList.contains(metaEnum)) { + enumList.append(metaEnum); + } } - lookForEnumsInClassesNotToBeGenerated(enumList, metaClass->enclosingClass()); } } @@ -571,13 +569,13 @@ QString ShibokenGenerator::guessScopeForDefaultFlagsValue(const AbstractMetaFunc QString ShibokenGenerator::guessScopeForDefaultValue(const AbstractMetaFunction *func, const AbstractMetaArgument *arg) const { - QString value = getDefaultValue(func, arg); + QString value = arg->defaultValueExpression(); - if (value.isEmpty()) - return QString(); - - if (isPointer(arg->type())) + if (value.isEmpty() + || arg->hasModifiedDefaultValueExpression() + || isPointer(arg->type())) { return value; + } static const QRegularExpression enumValueRegEx(QStringLiteral("^([A-Za-z_]\\w*)?$")); Q_ASSERT(enumValueRegEx.isValid()); @@ -1255,6 +1253,11 @@ QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry *type, bool gene QString ShibokenGenerator::guessCPythonCheckFunction(const QString &type, AbstractMetaType **metaType) { *metaType = nullptr; + // PYSIDE-795: We abuse PySequence for iterables. + // This part handles the overrides in the XML files. + if (type == QLatin1String("PySequence")) + return QLatin1String("Shiboken::String::checkIterable"); + if (type == QLatin1String("PyTypeObject")) return QLatin1String("PyType_Check"); @@ -2306,7 +2309,7 @@ AbstractMetaType *ShibokenGenerator::buildAbstractMetaTypeFromString(QString typ auto it = m_metaTypeFromStringCache.find(typeSignature); if (it == m_metaTypeFromStringCache.end()) { AbstractMetaType *metaType = - AbstractMetaBuilder::translateType(typeSignature, nullptr, true, errorMessage); + AbstractMetaBuilder::translateType(typeSignature, nullptr, {}, errorMessage); if (Q_UNLIKELY(!metaType)) { if (errorMessage) errorMessage->prepend(msgCannotBuildMetaType(typeSignature)); @@ -2708,22 +2711,6 @@ bool ShibokenGenerator::pythonFunctionWrapperUsesListOfArguments(const OverloadD || overloadData.hasArgumentWithDefaultValue(); } -QString ShibokenGenerator::getDefaultValue(const AbstractMetaFunction *func, const AbstractMetaArgument *arg) -{ - if (!arg->defaultValueExpression().isEmpty()) - return arg->defaultValueExpression(); - - //Check modifications - const FunctionModificationList &mods = func->modifications(); - for (const FunctionModification &m : mods) { - for (const ArgumentModification &am : m.argument_mods) { - if (am.index == (arg->argumentIndex() + 1)) - return am.replacedDefaultExpression; - } - } - return QString(); -} - void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream &s, const AbstractMetaType *type, const QString &defaultCtor) { if (!defaultCtor.isEmpty()) { diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h index 84b3137b8..7970ceb94 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h @@ -71,11 +71,6 @@ public: const char *name() const override { return "Shiboken"; } - /** - * Helper function to find for argument default value - */ - static QString getDefaultValue(const AbstractMetaFunction *func, const AbstractMetaArgument *arg); - /// Returns a list of all ancestor classes for the given class. AbstractMetaClassList getAllAncestors(const AbstractMetaClass *metaClass) const; |