diff options
Diffstat (limited to 'sources/shiboken2/generator')
8 files changed, 357 insertions, 319 deletions
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp index 484b1f641..3cc625488 100644 --- a/sources/shiboken2/generator/generator.cpp +++ b/sources/shiboken2/generator/generator.cpp @@ -159,7 +159,6 @@ struct Generator::GeneratorPrivate QString licenseComment; QString moduleName; QStringList instantiatedContainersNames; - QStringList instantiatedSmartPointerNames; QVector<const AbstractMetaType *> instantiatedContainers; QVector<const AbstractMetaType *> instantiatedSmartPointers; @@ -211,6 +210,31 @@ QString Generator::getSimplifiedContainerTypeName(const AbstractMetaType *type) return typeName; } +// Strip a "const QSharedPtr<const Foo> &" or similar to "QSharedPtr<Foo>" (PYSIDE-1016/454) +const AbstractMetaType *canonicalSmartPtrInstantiation(const AbstractMetaType *type) +{ + AbstractMetaTypeList instantiations = type->instantiations(); + Q_ASSERT(instantiations.size() == 1); + const bool needsFix = type->isConstant() || type->referenceType() != NoReference; + const bool pointeeNeedsFix = instantiations.constFirst()->isConstant(); + if (!needsFix && !pointeeNeedsFix) + return type; + auto fixedType = type->copy(); + fixedType->setReferenceType(NoReference); + fixedType->setConstant(false); + if (pointeeNeedsFix) { + auto fixedPointeeType = instantiations.constFirst()->copy(); + fixedPointeeType->setConstant(false); + fixedType->setInstantiations(AbstractMetaTypeList(1, fixedPointeeType)); + } + return fixedType; +} + +static inline const TypeEntry *pointeeTypeEntry(const AbstractMetaType *smartPtrType) +{ + return smartPtrType->instantiations().constFirst()->typeEntry(); +} + void Generator::addInstantiatedContainersAndSmartPointers(const AbstractMetaType *type, const QString &context) { @@ -244,18 +268,15 @@ void Generator::addInstantiatedContainersAndSmartPointers(const AbstractMetaType m_d->instantiatedContainers.append(type); } } else { - // Is smart pointer. - if (!m_d->instantiatedSmartPointerNames.contains(typeName)) { - m_d->instantiatedSmartPointerNames.append(typeName); - if (type->isConstant() || type->referenceType() != NoReference) { - // Strip a "const QSharedPtr<Foo> &" or similar to "QSharedPtr<Foo>" (PYSIDE-1016) - auto fixedType = type->copy(); - fixedType->setReferenceType(NoReference); - fixedType->setConstant(false); - type = fixedType; - } - m_d->instantiatedSmartPointers.append(type); - } + // Is smart pointer. Check if the (const?) pointee is already known + auto pt = pointeeTypeEntry(type); + const bool present = + std::any_of(m_d->instantiatedSmartPointers.cbegin(), m_d->instantiatedSmartPointers.cend(), + [pt] (const AbstractMetaType *t) { + return pointeeTypeEntry(t) == pt; + }); + if (!present) + m_d->instantiatedSmartPointers.append(canonicalSmartPtrInstantiation(type)); } } @@ -449,7 +470,8 @@ bool Generator::generate() bool Generator::shouldGenerateTypeEntry(const TypeEntry *type) const { - return type->codeGeneration() & TypeEntry::GenerateTargetLang; + return (type->codeGeneration() & TypeEntry::GenerateTargetLang) + && NamespaceTypeEntry::isVisibleScope(type); } bool Generator::shouldGenerate(const AbstractMetaClass *metaClass) const @@ -529,7 +551,7 @@ QTextStream &formatCode(QTextStream &s, const QString &code, Indentor &indentor) s << indentor << line.remove(0, limit); } - s << endl; + s << Qt::endl; } return s; } @@ -670,6 +692,9 @@ DefaultValue Generator::minimalConstructor(const AbstractMetaType *type) const if (Generator::isPointer(type)) return DefaultValue(DefaultValue::Pointer, QLatin1String("::") + type->typeEntry()->qualifiedCppName()); + if (type->typeEntry()->isSmartPointer()) + return minimalConstructor(type->typeEntry()); + if (type->typeEntry()->isComplex()) { auto cType = static_cast<const ComplexTypeEntry *>(type->typeEntry()); if (cType->hasDefaultConstructor()) @@ -724,6 +749,9 @@ DefaultValue Generator::minimalConstructor(const TypeEntry *type) const : DefaultValue(DefaultValue::Custom, ctor); } + if (type->isSmartPointer()) + return DefaultValue(DefaultValue::DefaultConstructor, type->qualifiedCppName()); + if (type->isComplex()) return minimalConstructor(AbstractMetaClass::findClass(classes(), type)); @@ -893,8 +921,12 @@ static QString getClassTargetFullName_(const T *t, bool includePackageName) QString name = t->name(); const AbstractMetaClass *context = t->enclosingClass(); while (context) { - name.prepend(QLatin1Char('.')); - name.prepend(context->name()); + // If the type was marked as 'visible=false' we should not use it in + // the type name + if (NamespaceTypeEntry::isVisibleScope(context->typeEntry())) { + name.prepend(QLatin1Char('.')); + name.prepend(context->name()); + } context = context->enclosingClass(); } if (includePackageName) { diff --git a/sources/shiboken2/generator/main.cpp b/sources/shiboken2/generator/main.cpp index 700dc00bb..e4d86f489 100644 --- a/sources/shiboken2/generator/main.cpp +++ b/sources/shiboken2/generator/main.cpp @@ -73,11 +73,11 @@ static void printOptions(QTextStream &s, const OptionDescriptions &options) if (od.second.isEmpty()) { s << ", "; } else { - s << endl; + s << Qt::endl; const auto lines = od.second.splitRef(QLatin1Char('\n')); for (const auto &line : lines) - s << " " << line << endl; - s << endl; + s << " " << line << Qt::endl; + s << Qt::endl; } } } @@ -343,7 +343,7 @@ void printUsage() for (const GeneratorPtr &generator : generators) { const OptionDescriptions options = generator->options(); if (!options.isEmpty()) { - s << endl << generator->name() << " options:\n\n"; + s << Qt::endl << generator->name() << " options:\n\n"; printOptions(s, generator->options()); } } diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp index f4efc293f..40cc255f0 100644 --- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp @@ -172,7 +172,7 @@ static QChar lastChar(const QTextStream &str) static QTextStream &ensureEndl(QTextStream &s) { if (lastChar(s) != QLatin1Char('\n')) - s << endl; + s << Qt::endl; return s; } @@ -502,10 +502,10 @@ QString QtXmlToSphinx::transform(const QString& doc) if (!m_inlineImages.isEmpty()) { // Write out inline image definitions stored in handleInlineImageTag(). - m_output << endl; + m_output << Qt::endl; for (const InlineImage &img : qAsConst(m_inlineImages)) - m_output << ".. |" << img.tag << "| image:: " << img.href << endl; - m_output << endl; + m_output << ".. |" << img.tag << "| image:: " << img.href << Qt::endl; + m_output << Qt::endl; m_inlineImages.clear(); } @@ -608,11 +608,11 @@ void QtXmlToSphinx::handleHeadingTag(QXmlStreamReader& reader) else type = types[typeIdx]; } else if (token == QXmlStreamReader::EndElement) { - m_output << Pad(type, headingSize) << endl << endl; + m_output << Pad(type, headingSize) << Qt::endl << Qt::endl; } else if (token == QXmlStreamReader::Characters) { - m_output << endl << endl; + m_output << Qt::endl << Qt::endl; headingSize = writeEscapedRstText(m_output, reader.text().trimmed()); - m_output << endl; + m_output << Qt::endl; } } @@ -628,7 +628,7 @@ void QtXmlToSphinx::handleParaTag(QXmlStreamReader& reader) else if (result.startsWith(QLatin1String("**Note:**"))) result.replace(0, 9, QLatin1String(".. note:: ")); - m_output << INDENT << result << endl << endl; + m_output << INDENT << result << Qt::endl << Qt::endl; } else if (token == QXmlStreamReader::Characters) { const QStringRef text = reader.text(); const QChar end = lastChar(m_output); @@ -726,7 +726,7 @@ void QtXmlToSphinx::handleSeeAlsoTag(QXmlStreamReader& reader) handleLinkEnd(m_seeAlsoContext.data()); m_seeAlsoContext.reset(); } - m_output << endl << endl; + m_output << Qt::endl << Qt::endl; break; default: break; @@ -747,7 +747,7 @@ void formatSnippet(QTextStream &str, Indent indent, const QString &snippet) for (const QStringRef &line : lines) { if (!line.trimmed().isEmpty()) str << indent << line; - str << endl; + str << Qt::endl; } } @@ -811,7 +811,7 @@ void QtXmlToSphinx::handleSnippetTag(QXmlStreamReader& reader) m_output << INDENT << "<Code snippet \"" << location << ':' << identifier << "\" not found>\n"; else formatSnippet(m_output, INDENT, code); - m_output << endl; + m_output << Qt::endl; } } void QtXmlToSphinx::handleDotsTag(QXmlStreamReader& reader) @@ -930,16 +930,16 @@ void QtXmlToSphinx::handleListTag(QXmlStreamReader& reader) switch (listType) { case BulletList: case OrderedList: { - m_output << endl; + m_output << Qt::endl; const char *separator = listType == BulletList ? "* " : "#. "; const char *indent = listType == BulletList ? " " : " "; for (const TableCell &cell : m_currentTable.constFirst()) { const QVector<QStringRef> itemLines = cell.data.splitRef(QLatin1Char('\n')); - m_output << INDENT << separator << itemLines.constFirst() << endl; + m_output << INDENT << separator << itemLines.constFirst() << Qt::endl; for (int i = 1, max = itemLines.count(); i < max; ++i) - m_output << INDENT << indent << itemLines[i] << endl; + m_output << INDENT << indent << itemLines[i] << Qt::endl; } - m_output << endl; + m_output << Qt::endl; } break; case EnumeratedList: @@ -1144,7 +1144,7 @@ void QtXmlToSphinx::handleImageTag(QXmlStreamReader& reader) return; const QString href = reader.attributes().value(QLatin1String("href")).toString(); if (copyImage(href)) - m_output << INDENT << ".. image:: " << href << endl << endl; + m_output << INDENT << ".. image:: " << href << Qt::endl << Qt::endl; } void QtXmlToSphinx::handleInlineImageTag(QXmlStreamReader& reader) @@ -1174,13 +1174,13 @@ void QtXmlToSphinx::handleRawTag(QXmlStreamReader& reader) QXmlStreamReader::TokenType token = reader.tokenType(); if (token == QXmlStreamReader::StartElement) { QString format = reader.attributes().value(QLatin1String("format")).toString(); - m_output << INDENT << ".. raw:: " << format.toLower() << endl << endl; + m_output << INDENT << ".. raw:: " << format.toLower() << Qt::endl << Qt::endl; } else if (token == QXmlStreamReader::Characters) { const QVector<QStringRef> lst(reader.text().split(QLatin1Char('\n'))); for (const QStringRef &row : lst) - m_output << INDENT << INDENT << row << endl; + m_output << INDENT << INDENT << row << Qt::endl; } else if (token == QXmlStreamReader::EndElement) { - m_output << endl << endl; + m_output << Qt::endl << Qt::endl; } } @@ -1193,9 +1193,9 @@ void QtXmlToSphinx::handleCodeTag(QXmlStreamReader& reader) } else if (token == QXmlStreamReader::Characters) { const QVector<QStringRef> lst(reader.text().split(QLatin1Char('\n'))); for (const QStringRef &row : lst) - m_output << INDENT << INDENT << row << endl; + m_output << INDENT << INDENT << row << Qt::endl; } else if (token == QXmlStreamReader::EndElement) { - m_output << endl << endl; + m_output << Qt::endl << Qt::endl; INDENT.indent--; } } @@ -1235,7 +1235,7 @@ void QtXmlToSphinx::handlePageTag(QXmlStreamReader &reader) ? writeEscapedRstText(m_output, title) : writeEscapedRstText(m_output, fullTitle); - m_output << endl << Pad('*', size) << endl << endl; + m_output << Qt::endl << Pad('*', size) << Qt::endl << Qt::endl; } void QtXmlToSphinx::handleTargetTag(QXmlStreamReader &reader) @@ -1299,7 +1299,7 @@ void QtXmlToSphinx::handleQuoteFileTag(QXmlStreamReader& reader) m_output << INDENT << "<Code snippet \"" << location << "\" not found>\n"; else formatCode(m_output, code, INDENT); - m_output << endl; + m_output << Qt::endl; } } @@ -1435,7 +1435,7 @@ void QtXmlToSphinx::Table::format (QTextStream& s) const c = '-'; s << Pad(c, colWidths.at(col)) << '+'; } - s << endl; + s << Qt::endl; // Print the table cells @@ -1452,7 +1452,7 @@ void QtXmlToSphinx::Table::format (QTextStream& s) const else s << ' '; if (rowLine < rowLines.count()) - s << qSetFieldWidth(colWidths[j]) << left << rowLines.at(rowLine) << qSetFieldWidth(0); + s << qSetFieldWidth(colWidths[j]) << Qt::left << rowLines.at(rowLine) << qSetFieldWidth(0); else s << Pad(' ', colWidths.at(j)); } @@ -1461,7 +1461,7 @@ void QtXmlToSphinx::Table::format (QTextStream& s) const s << "|\n"; } } - s << INDENT << horizontalLine << endl << endl; + s << INDENT << horizontalLine << Qt::endl << Qt::endl; } static QString getFuncName(const AbstractMetaFunction* cppFunc) { @@ -1562,11 +1562,11 @@ void QtDocGenerator::writeFormattedText(QTextStream &s, const Documentation &doc s << INDENT << (typesystemIndentation > 0 && typesystemIndentation < line.size() ? line.right(line.size() - typesystemIndentation) : line) - << endl; + << Qt::endl; } } - s << endl; + s << Qt::endl; } static void writeInheritedByList(QTextStream& s, const AbstractMetaClass* metaClass, const AbstractMetaClassList& allClasses) @@ -1584,7 +1584,7 @@ static void writeInheritedByList(QTextStream& s, const AbstractMetaClass* metaCl QStringList classes; for (AbstractMetaClass *c : qAsConst(res)) classes << QLatin1String(":ref:`") + getClassTargetFullName(c, false) + QLatin1Char('`'); - s << classes.join(QLatin1String(", ")) << endl << endl; + s << classes.join(QLatin1String(", ")) << Qt::endl << Qt::endl; } // Extract the <brief> section from a WebXML (class) documentation and remove it @@ -1625,15 +1625,15 @@ void QtDocGenerator::generateClass(QTextStream &s, GeneratorContext &classContex s << ".. _" << className << ":" << "\n\n"; s << ".. currentmodule:: " << metaClass->package() << "\n\n\n"; - s << className << endl; - s << Pad('*', className.count()) << endl << endl; + s << className << Qt::endl; + s << Pad('*', className.count()) << Qt::endl << Qt::endl; auto documentation = metaClass->documentation(); Documentation brief; if (extractBrief(&documentation, &brief)) writeFormattedText(s, brief, metaClass); - s << ".. inheritance-diagram:: " << getClassTargetFullName(metaClass, true) << endl + s << ".. inheritance-diagram:: " << getClassTargetFullName(metaClass, true) << Qt::endl << " :parts: 2\n\n"; // TODO: This would be a parameter in the future... @@ -1740,17 +1740,17 @@ void QtDocGenerator::writeFunctionList(QTextStream& s, const AbstractMetaClass* void QtDocGenerator::writeFunctionBlock(QTextStream& s, const QString& title, QStringList& functions) { if (!functions.isEmpty()) { - s << title << endl - << QString(title.size(), QLatin1Char('^')) << endl; + s << title << Qt::endl + << QString(title.size(), QLatin1Char('^')) << Qt::endl; std::sort(functions.begin(), functions.end()); s << ".. container:: function_list\n\n"; Indentation indentation(INDENT); for (const QString &func : qAsConst(functions)) - s << INDENT << '*' << ' ' << func << endl; + s << INDENT << '*' << ' ' << func << Qt::endl; - s << endl << endl; + s << Qt::endl << Qt::endl; } } @@ -1760,7 +1760,7 @@ void QtDocGenerator::writeEnums(QTextStream& s, const AbstractMetaClass* cppClas const AbstractMetaEnumList &enums = cppClass->enums(); for (AbstractMetaEnum *en : enums) { - s << section_title << getClassTargetFullName(cppClass) << '.' << en->name() << endl << endl; + s << section_title << getClassTargetFullName(cppClass) << '.' << en->name() << Qt::endl << Qt::endl; writeFormattedText(s, en->documentation(), cppClass); const auto version = versionOf(en->typeEntry()); if (!version.isNull()) @@ -1775,7 +1775,7 @@ void QtDocGenerator::writeFields(QTextStream& s, const AbstractMetaClass* cppCla const AbstractMetaFieldList &fields = cppClass->fields(); for (AbstractMetaField *field : fields) { - s << section_title << getClassTargetFullName(cppClass) << "." << field->name() << endl << endl; + s << section_title << getClassTargetFullName(cppClass) << "." << field->name() << Qt::endl << Qt::endl; //TODO: request for member ‘documentation’ is ambiguous writeFormattedText(s, field->AbstractMetaAttributes::documentation(), cppClass); } @@ -1819,14 +1819,14 @@ void QtDocGenerator::writeConstructors(QTextStream& s, const AbstractMetaClass* } } - s << endl; + s << Qt::endl; for (QHash<QString, AbstractMetaArgument*>::const_iterator it = arg_map.cbegin(), end = arg_map.cend(); it != end; ++it) { Indentation indentation(INDENT, 2); writeParameterType(s, cppClass, it.value()); } - s << endl; + s << Qt::endl; for (AbstractMetaFunction *func : qAsConst(lst)) writeFormattedText(s, func->documentation(), cppClass); @@ -1917,7 +1917,7 @@ void QtDocGenerator::writeDocSnips(QTextStream &s, if (row.trimmed().size() == 0) { if (currentRow == 0) continue; - s << endl; + s << Qt::endl; } if (currentRow == 0) { @@ -1931,7 +1931,7 @@ void QtDocGenerator::writeDocSnips(QTextStream &s, break; } } - s << row.midRef(offset) << endl; + s << row.midRef(offset) << Qt::endl; currentRow++; } @@ -1971,7 +1971,7 @@ bool QtDocGenerator::writeInjectDocumentation(QTextStream& s, } } - s << endl; + s << Qt::endl; // TODO: Deprecate the use of doc string on glue code. // This is pre "add-function" and "inject-documentation" tags. @@ -2046,13 +2046,13 @@ QString QtDocGenerator::translateToPythonType(const AbstractMetaType* type, cons void QtDocGenerator::writeParameterType(QTextStream& s, const AbstractMetaClass* cppClass, const AbstractMetaArgument* arg) { s << INDENT << ":param " << arg->name() << ": " - << translateToPythonType(arg->type(), cppClass) << endl; + << translateToPythonType(arg->type(), cppClass) << Qt::endl; } void QtDocGenerator::writeFunctionParametersType(QTextStream &s, const AbstractMetaClass *cppClass, const AbstractMetaFunction *func) { - s << endl; + s << Qt::endl; const AbstractMetaArgumentList &funcArgs = func->arguments(); for (AbstractMetaArgument *arg : funcArgs) { @@ -2078,9 +2078,9 @@ void QtDocGenerator::writeFunctionParametersType(QTextStream &s, const AbstractM if (retType.isEmpty()) retType = translateToPythonType(func->type(), cppClass); - s << INDENT << ":rtype: " << retType << endl; + s << INDENT << ":rtype: " << retType << Qt::endl; } - s << endl; + s << Qt::endl; } void QtDocGenerator::writeFunction(QTextStream& s, const AbstractMetaClass* cppClass, @@ -2134,7 +2134,7 @@ static void writeFancyToc(QTextStream& s, const QStringList& items, int cols = 4 std::sort(it.value().begin(), it.value().end()); if (i) - ss << endl; + ss << Qt::endl; ss << "**" << it.key() << "**\n\n"; i += 2; // a letter title is equivalent to two entries in space @@ -2184,11 +2184,11 @@ void QtDocGenerator::writeModuleDocumentation() FileOut output(outputDir + QLatin1String("/index.rst")); QTextStream& s = output.stream; - s << ".. module:: " << it.key() << endl << endl; + s << ".. module:: " << it.key() << Qt::endl << Qt::endl; const QString &title = it.key(); - s << title << endl; - s << Pad('*', title.length()) << endl << endl; + s << title << Qt::endl; + s << Pad('*', title.length()) << Qt::endl << Qt::endl; /* Avoid showing "Detailed Description for *every* class in toc tree */ Indentation indentation(INDENT); @@ -2230,8 +2230,8 @@ void QtDocGenerator::writeModuleDocumentation() Indentation deeperIndentation(INDENT); s << INDENT << ":maxdepth: 1\n\n"; for (const QString &className : qAsConst(it.value())) - s << INDENT << className << endl; - s << endl << endl; + s << INDENT << className << Qt::endl; + s << Qt::endl << Qt::endl; } s << "Detailed Description\n--------------------\n\n"; diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 6b29272e0..9e7b96c7f 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -44,8 +44,7 @@ #include <QMetaType> #include <algorithm> - -#include <algorithm> +#include <cstring> static const char CPP_ARG0[] = "cppArg0"; @@ -300,7 +299,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) qCDebug(lcShiboken) << "Generating wrapper implementation for " << metaClass->fullName(); // write license comment - s << licenseComment() << endl; + s << licenseComment() << Qt::endl; if (!avoidProtectedHack() && !metaClass->isNamespace() && !metaClass->hasPrivateDestructor()) { s << "//workaround to access protected functions\n"; @@ -339,11 +338,11 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) headerfile.replace(QLatin1String(".cpp"), QLatin1String(".h")); s << "\n// main header\n" << "#include \"" << headerfile << "\"\n"; - s << endl << "// inner classes\n"; + s << Qt::endl << "// inner classes\n"; const AbstractMetaClassList &innerClasses = metaClass->innerClasses(); for (AbstractMetaClass *innerClass : innerClasses) { GeneratorContext innerClassContext(innerClass); - if (shouldGenerate(innerClass)) { + if (shouldGenerate(innerClass) && !innerClass->typeEntry()->isSmartPointer()) { QString headerfile = fileNameForContext(innerClassContext); headerfile.replace(QLatin1String(".cpp"), QLatin1String(".h")); s << "#include \"" << headerfile << "\"\n"; @@ -361,8 +360,8 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) includes.append(cppEnum->typeEntry()->extraIncludes()); std::sort(includes.begin(), includes.end()); for (const Include &inc : qAsConst(includes)) - s << inc.toString() << endl; - s << endl; + s << inc.toString() << Qt::endl; + s << Qt::endl; s << "\n#include <cctype>\n#include <cstring>\n"; @@ -381,7 +380,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) } } - s << endl << endl << typeNameFunc << endl; + s << Qt::endl << Qt::endl << typeNameFunc << Qt::endl; // Create string literal for smart pointer getter method. if (classContext.forSmartPointer()) { @@ -395,13 +394,13 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) // class inject-code native/beginning if (!metaClass->typeEntry()->codeSnips().isEmpty()) { writeCodeSnips(s, metaClass->typeEntry()->codeSnips(), TypeSystem::CodeSnipPositionBeginning, TypeSystem::NativeCode, metaClass); - s << endl; + s << Qt::endl; } // python conversion rules if (metaClass->typeEntry()->hasTargetConversionRule()) { s << "// Python Conversion\n"; - s << metaClass->typeEntry()->conversionRule() << endl; + s << metaClass->typeEntry()->conversionRule() << Qt::endl; } if (shouldGenerateCppWrapper(metaClass)) { @@ -553,7 +552,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) // Write methods definition s << "static PyMethodDef " << className << "_methods[] = {\n"; - s << methodsDefinitions << endl; + s << methodsDefinitions << Qt::endl; if (metaClass->typeEntry()->isValue() || metaClass->typeEntry()->isSmartPointer()) { s << INDENT << "{\"__copy__\", reinterpret_cast<PyCFunction>(" << className << "___copy__)" << ", METH_NOARGS},\n"; @@ -580,9 +579,9 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) writeCppSelfDefinition(s, classContext); if (f->allowThread()) { s << INDENT << "int result;\n"; - s << INDENT << BEGIN_ALLOW_THREADS << endl; + s << INDENT << BEGIN_ALLOW_THREADS << Qt::endl; s << INDENT << "result = !" << CPP_SELF_VAR << "->isNull();\n"; - s << INDENT << END_ALLOW_THREADS << endl; + s << INDENT << END_ALLOW_THREADS << Qt::endl; s << INDENT << "return result;\n"; } else { s << INDENT << "return !" << CPP_SELF_VAR << "->isNull();\n"; @@ -635,10 +634,10 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) writeGetterFunction(s, metaField, classContext); if (canGenerateFieldSetter(metaField)) writeSetterFunction(s, metaField, classContext); - s << endl; + s << Qt::endl; } - s << "// Getters and Setters for " << metaClass->name() << endl; + s << "// Getters and Setters for " << metaClass->name() << Qt::endl; s << "static PyGetSetDef " << cpythonGettersSettersDefinitionName(metaClass) << "[] = {\n"; for (const AbstractMetaField *metaField : fields) { if (metaField->isStatic()) @@ -666,7 +665,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) writeTpClearFunction(s, metaClass); writeClassDefinition(s, metaClass, classContext); - s << endl; + s << Qt::endl; if (metaClass->isPolymorphic() && metaClass->baseClass()) writeTypeDiscoveryFunction(s, metaClass); @@ -680,10 +679,10 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) if (hasFlags) { writeFlagsMethods(s, cppEnum); writeFlagsNumberMethodsDefinition(s, cppEnum); - s << endl; + s << Qt::endl; } } - s << endl; + s << Qt::endl; writeConverterFunctions(s, metaClass, classContext); writeClassRegister(s, metaClass, classContext, signatureStream); @@ -691,7 +690,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) // class inject-code native/end if (!metaClass->typeEntry()->codeSnips().isEmpty()) { writeCodeSnips(s, metaClass->typeEntry()->codeSnips(), TypeSystem::CodeSnipPositionEnd, TypeSystem::NativeCode, metaClass); - s << endl; + s << Qt::endl; } } @@ -750,11 +749,14 @@ QString CppGenerator::getVirtualFunctionReturnTypeName(const AbstractMetaFunctio return QLatin1Char('"') + func->typeReplaced(0) + QLatin1Char('"'); // SbkType would return null when the type is a container. - if (func->type()->typeEntry()->isContainer()) { + auto typeEntry = func->type()->typeEntry(); + if (typeEntry->isContainer()) { return QLatin1Char('"') - + reinterpret_cast<const ContainerTypeEntry *>(func->type()->typeEntry())->typeName() + + reinterpret_cast<const ContainerTypeEntry *>(typeEntry)->typeName() + QLatin1Char('"'); } + if (typeEntry->isSmartPointer()) + return QLatin1Char('"') + typeEntry->qualifiedCppName() + QLatin1Char('"'); if (avoidProtectedHack()) { const AbstractMetaEnum *metaEnum = findAbstractMetaEnum(func->type()); @@ -765,7 +767,8 @@ QString CppGenerator::getVirtualFunctionReturnTypeName(const AbstractMetaFunctio if (func->type()->isPrimitive()) return QLatin1Char('"') + func->type()->name() + QLatin1Char('"'); - return QString::fromLatin1("reinterpret_cast<PyTypeObject *>(Shiboken::SbkType< %1 >())->tp_name").arg(func->type()->typeEntry()->qualifiedCppName()); + return QLatin1String("reinterpret_cast<PyTypeObject *>(Shiboken::SbkType< ") + + typeEntry->qualifiedCppName() + QLatin1String(" >())->tp_name"); } void CppGenerator::writeVirtualMethodNative(QTextStream &s, @@ -821,7 +824,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, errorMsg += func->signature(); errorMsg = msgCouldNotFindMinimalConstructor(errorMsg, func->type()->cppSignature()); qCWarning(lcShiboken).noquote().nospace() << errorMsg; - s << endl << INDENT << "#error " << errorMsg << endl; + s << Qt::endl << INDENT << "#error " << errorMsg << Qt::endl; } } else { defaultReturnExpr.setType(DefaultValue::Void); @@ -832,7 +835,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, << QString::fromLatin1("Pure virtual method '%1::%2' must be implement but was "\ "completely removed on type system.") .arg(func->ownerClass()->name(), func->minimalSignature()); - s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl; + s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl; s << "}\n\n"; return; } @@ -842,7 +845,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, CodeSnipList snips = func->injectedCodeSnips(); const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast(); writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionDeclaration, TypeSystem::NativeCode, func, lastArg); - s << endl; + s << Qt::endl; } // PYSIDE-803: Build a boolean cache for unused overrides. @@ -873,7 +876,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, s << INDENT << "if (PyErr_Occurred())\n"; { Indentation indentation(INDENT); - s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl; + s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl; } s << INDENT << "Shiboken::AutoDecRef " << PYTHON_OVERRIDE_VAR << "(Shiboken::BindingManager::instance().getOverride(this, \""; @@ -887,7 +890,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, snips = func->injectedCodeSnips(); const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast(); writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::ShellCode, func, lastArg); - s << endl; + s << Qt::endl; } if (func->isAbstract()) { @@ -962,7 +965,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, } s << "Py_BuildValue(\"(" << getFormatUnitString(func, false) << ")\",\n"; - s << argConversions.join(QLatin1String(",\n")) << endl; + s << argConversions.join(QLatin1String(",\n")) << Qt::endl; s << INDENT << "));\n"; } @@ -980,7 +983,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, } } } - s << endl; + s << Qt::endl; CodeSnipList snips; if (func->hasInjectedCode()) { @@ -991,7 +994,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast(); writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::NativeCode, func, lastArg); - s << endl; + s << Qt::endl; } if (!injectedCodeCallsPythonOverride(func)) { @@ -1004,7 +1007,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, { Indentation indent(INDENT); s << INDENT << "PyErr_Print();\n"; - s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl; + s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl; } s << INDENT << "}\n"; @@ -1026,7 +1029,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, "\"Invalid return value in function %s, expected %s, got %s.\", \""; s << func->ownerClass()->name() << '.' << funcName << "\", " << getVirtualFunctionReturnTypeName(func); s << ", Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);\n"; - s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl; + s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl; } s << INDENT << "}\n"; @@ -1047,7 +1050,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, "\"Invalid return value in function %s, expected %s, got %s.\", \""; s << func->ownerClass()->name() << '.' << funcName << "\", " << getVirtualFunctionReturnTypeName(func); s << ", Py_TYPE(" << PYTHON_RETURN_VAR << ")->tp_name);\n"; - s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << endl; + s << INDENT << returnStatement(defaultReturnExpr.returnValue()) << Qt::endl; } s << INDENT << "}\n"; @@ -1090,7 +1093,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, } if (func->hasInjectedCode()) { - s << endl; + s << Qt::endl; const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast(); writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionEnd, TypeSystem::NativeCode, func, lastArg); } @@ -1215,7 +1218,7 @@ void CppGenerator::writeEnumConverterFunctions(QTextStream &s, const TypeEntry * } c << ";\n"; writeCppToPythonFunction(s, code, typeName, typeName); - s << endl; + s << Qt::endl; if (enumType->isFlags()) return; @@ -1295,7 +1298,7 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla const QString pyTypeCheck = QLatin1String("PyObject_TypeCheck(pyIn, reinterpret_cast<PyTypeObject *>(") + cpythonType + QLatin1String("))"); writeIsPythonConvertibleToCppFunction(s, sourceTypeName, targetTypeName, pyTypeCheck, QString(), true); - s << endl; + s << Qt::endl; // C++ pointer to a Python wrapper, keeping identity. s << "// C++ to Python pointer conversion - tries to find the Python wrapper for the C++ object (keeps object identity).\n"; @@ -1332,12 +1335,12 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla // The conversions for an Object Type end here. if (!metaClass->typeEntry()->isValue() && !metaClass->typeEntry()->isSmartPointer()) { - s << endl; + s << Qt::endl; return; } // Always copies C++ value (not pointer, and not reference) to a new Python wrapper. - s << endl << "// C++ to Python copy conversion.\n"; + s << Qt::endl << "// C++ to Python copy conversion.\n"; if (!classContext.forSmartPointer()) targetTypeName = metaClass->name(); else @@ -1357,7 +1360,7 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla << ", new ::" << computedWrapperName << "(*reinterpret_cast<const " << typeName << " *>(cppIn)), true, true);"; writeCppToPythonFunction(s, code, sourceTypeName, targetTypeName); - s << endl; + s << Qt::endl; // Python to C++ copy conversion. s << "// Python to C++ copy conversion.\n"; @@ -1382,7 +1385,7 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla // "Is convertible" function for the Python object to C++ value copy conversion. writeIsPythonConvertibleToCppFunction(s, sourceTypeName, targetTypeName, pyTypeCheck); - s << endl; + s << Qt::endl; // User provided implicit conversions. CustomConversion *customConversion = metaClass->typeEntry()->customConversion(); @@ -1477,7 +1480,7 @@ void CppGenerator::writeCustomConverterFunctions(QTextStream &s, const CustomCon s << "// Python to C++ conversions for type '" << customConversion->ownerType()->qualifiedCppName() << "'.\n"; for (CustomConversion::TargetToNativeConversion *toNative : toCppConversions) writePythonToCppConversionFunctions(s, toNative, customConversion->ownerType()); - s << endl; + s << Qt::endl; } void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClass *metaClass, @@ -1487,24 +1490,24 @@ void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClas return; s << INDENT << "// Register Converter\n"; s << INDENT << "SbkConverter *converter = Shiboken::Conversions::createConverter("; - s << cpythonTypeName(metaClass) << ',' << endl; + s << cpythonTypeName(metaClass) << ',' << Qt::endl; { Indentation indent(INDENT); QString sourceTypeName = metaClass->name(); QString targetTypeName = sourceTypeName + QLatin1String("_PTR"); - s << INDENT << pythonToCppFunctionName(sourceTypeName, targetTypeName) << ',' << endl; - s << INDENT << convertibleToCppFunctionName(sourceTypeName, targetTypeName) << ',' << endl; + s << INDENT << pythonToCppFunctionName(sourceTypeName, targetTypeName) << ',' << Qt::endl; + s << INDENT << convertibleToCppFunctionName(sourceTypeName, targetTypeName) << ',' << Qt::endl; std::swap(targetTypeName, sourceTypeName); s << INDENT << cppToPythonFunctionName(sourceTypeName, targetTypeName); if (metaClass->typeEntry()->isValue() || metaClass->typeEntry()->isSmartPointer()) { - s << ',' << endl; + s << ',' << Qt::endl; sourceTypeName = metaClass->name() + QLatin1String("_COPY"); s << INDENT << cppToPythonFunctionName(sourceTypeName, targetTypeName); } } s << ");\n"; - s << endl; + s << Qt::endl; QStringList cppSignature; if (!classContext.forSmartPointer()) { @@ -1536,7 +1539,7 @@ void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClas s << wrapperName(metaClass) << ").name());\n"; } - s << endl; + s << Qt::endl; if (!metaClass->typeEntry()->isValue() && !metaClass->typeEntry()->isSmartPointer()) return; @@ -1631,7 +1634,7 @@ void CppGenerator::writeMethodWrapperPreamble(QTextStream &s, OverloadData &over s << qualifiedCppName << " >()))\n"; Indentation indent(INDENT); - s << INDENT << returnStatement(m_currentErrorCode) << endl << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl << Qt::endl; } // Declare pointer for the underlying C++ object. s << INDENT << "::"; @@ -1736,7 +1739,7 @@ void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFun s << INDENT << "\"'" << metaClass->qualifiedCppName(); } s << "' represents a C++ abstract class and cannot be instantiated\");\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } s << INDENT<< "}\n\n"; } @@ -1755,24 +1758,24 @@ void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFun writeMethodWrapperPreamble(s, overloadData, classContext); - s << endl; + s << Qt::endl; if (overloadData.maxArgs() > 0) writeOverloadedFunctionDecisor(s, overloadData); writeFunctionCalls(s, overloadData, classContext); - s << endl; + s << Qt::endl; s << INDENT << "if (PyErr_Occurred() || !Shiboken::Object::setCppPointer(sbkSelf, Shiboken::SbkType< ::" << metaClass->qualifiedCppName() << " >(), cptr)) {\n"; { Indentation indent(INDENT); s << INDENT << "delete cptr;\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } s << INDENT << "}\n"; if (overloadData.maxArgs() > 0) { s << INDENT << "if (!cptr) goto " << cpythonFunctionName(rfunc) << "_TypeError;\n"; - s << endl; + s << Qt::endl; } s << INDENT << "Shiboken::Object::setValidCpp(sbkSelf, true);\n"; @@ -1794,13 +1797,13 @@ void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFun // Create metaObject and register signal/slot if (metaClass->isQObject() && usePySideExtensions()) { - s << endl << INDENT << "// QObject setup\n"; + s << Qt::endl << INDENT << "// QObject setup\n"; s << INDENT << "PySide::Signal::updateSourceObject(self);\n"; s << INDENT << "metaObject = cptr->metaObject(); // <- init python qt properties\n"; s << INDENT << "if (kwds && !PySide::fillQtProperties(self, metaObject, kwds, argNames, " << argNamesSet.count() << "))\n"; { Indentation indentation(INDENT); - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } } @@ -1823,7 +1826,7 @@ void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFun const CodeSnipList &injectedCodeSnips = func->injectedCodeSnips(); for (const CodeSnip &cs : injectedCodeSnips) { if (cs.position == TypeSystem::CodeSnipPositionEnd) { - s << INDENT << "case " << metaClass->functions().indexOf(func) << ':' << endl; + s << INDENT << "case " << metaClass->functions().indexOf(func) << ':' << Qt::endl; s << INDENT << "{\n"; { Indentation indent(INDENT); @@ -1837,8 +1840,8 @@ void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFun s << "}\n"; } - s << endl; - s << endl << INDENT << "return 1;\n"; + s << Qt::endl; + s << Qt::endl << INDENT << "return 1;\n"; if (overloadData.maxArgs() > 0) writeErrorSection(s, overloadData); s<< "}\n\n"; @@ -1863,7 +1866,7 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction writeMethodWrapperPreamble(s, overloadData, classContext); - s << endl; + s << Qt::endl; /* * This code is intended for shift operations only: @@ -1926,9 +1929,9 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction writeFunctionCalls(s, overloadData, classContext); if (callExtendedReverseOperator) - s << endl << INDENT << "} // End of \"if (!" << PYTHON_RETURN_VAR << ")\"\n"; + s << Qt::endl << INDENT << "} // End of \"if (!" << PYTHON_RETURN_VAR << ")\"\n"; - s << endl; + s << Qt::endl; writeFunctionReturnErrorCheckSection(s, hasReturnValue && !rfunc->isInplaceOperator()); @@ -1962,7 +1965,7 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl s << PYTHON_ARGS << "[] = {" << QString(maxArgs, QLatin1Char('0')).split(QLatin1String(""), Qt::SkipEmptyParts).join(QLatin1String(", ")) << "};\n"; - s << endl; + s << Qt::endl; if (overloadData.hasVarargs()) { maxArgs--; @@ -1973,7 +1976,7 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl s << INDENT << "Shiboken::AutoDecRef auto_nonvarargs(nonvarargs);\n"; s << INDENT << PYTHON_ARGS << '[' << maxArgs << "] = PyTuple_GetSlice(args, " << maxArgs << ", numArgs);\n"; s << INDENT << "Shiboken::AutoDecRef auto_varargs(" << PYTHON_ARGS << "[" << maxArgs << "]);\n"; - s << endl; + s << Qt::endl; } bool usesNamedArguments = overloadData.hasArgumentWithDefaultValue(); @@ -1986,7 +1989,7 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl { Indentation indent(INDENT); s << INDENT << "PyErr_SetString(PyExc_TypeError, \"" << fullPythonFunctionName(rfunc) << "(): too many arguments\");\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } s << INDENT << '}'; } @@ -1999,7 +2002,7 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl { Indentation indent(INDENT); s << INDENT << "PyErr_SetString(PyExc_TypeError, \"" << fullPythonFunctionName(rfunc) << "(): not enough arguments\");\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } s << INDENT << '}'; } @@ -2017,7 +2020,7 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl Indentation indent(INDENT); s << INDENT << "goto " << cpythonFunctionName(rfunc) << "_TypeError;"; } - s << endl << endl; + s << Qt::endl << Qt::endl; QString funcName; if (rfunc->isOperatorOverload()) @@ -2036,9 +2039,9 @@ void CppGenerator::writeArgumentsInitializer(QTextStream &s, OverloadData &overl s << "))\n"; { Indentation indent(INDENT); - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } - s << endl; + s << Qt::endl; } void CppGenerator::writeCppSelfAssigment(QTextStream &s, const GeneratorContext &context, @@ -2128,7 +2131,7 @@ void CppGenerator::writeCppSelfDefinition(QTextStream &s, void CppGenerator::writeErrorSection(QTextStream &s, OverloadData &overloadData) { const AbstractMetaFunction *rfunc = overloadData.referenceFunction(); - s << endl << INDENT << cpythonFunctionName(rfunc) << "_TypeError:\n"; + s << Qt::endl << INDENT << cpythonFunctionName(rfunc) << "_TypeError:\n"; Indentation indentation(INDENT); QString funcName = fullPythonFunctionName(rfunc); @@ -2148,7 +2151,7 @@ void CppGenerator::writeFunctionReturnErrorCheckSection(QTextStream &s, bool has Indentation indent(INDENT); if (hasReturnValue) s << INDENT << "Py_XDECREF(" << PYTHON_RETURN_VAR << ");\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } s << INDENT << "}\n"; } @@ -2157,7 +2160,7 @@ void CppGenerator::writeInvalidPyObjectCheck(QTextStream &s, const QString &pyOb { s << INDENT << "if (!Shiboken::Object::isValid(" << pyObj << "))\n"; Indentation indent(INDENT); - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } static QString pythonToCppConverterForArgumentName(const QString &argumentName) @@ -2423,7 +2426,7 @@ void CppGenerator::writePythonToCppTypeConversion(QTextStream &s, if (!defaultValue.isEmpty()) s << INDENT << '}'; - s << endl; + s << Qt::endl; } static void addConversionRuleCodeSnippet(CodeSnipList &snippetList, QString &rule, @@ -2486,10 +2489,10 @@ void CppGenerator::writeOverloadedFunctionDecisor(QTextStream &s, const Overload s << "static "; if (const auto *decl = func->declaringClass()) s << decl->name() << "::"; - s << func->minimalSignature() << endl; + s << func->minimalSignature() << Qt::endl; } writeOverloadedFunctionDecisorEngine(s, &overloadData); - s << endl; + s << Qt::endl; // Ensure that the direct overload that called this reverse // is called. @@ -2505,7 +2508,7 @@ void CppGenerator::writeOverloadedFunctionDecisor(QTextStream &s, const Overload s << INDENT << "// Function signature not found.\n"; s << INDENT << "if (overloadId == -1) goto " << cpythonFunctionName(overloadData.referenceFunction()) << "_TypeError;\n"; - s << endl; + s << Qt::endl; } void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const OverloadData *parentOverloadData) @@ -2536,7 +2539,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov // Functions without arguments are identified right away. if (maxArgs == 0) { s << INDENT << "overloadId = " << parentOverloadData->headOverloadData()->overloads().indexOf(referenceFunction); - s << "; // " << referenceFunction->minimalSignature() << endl; + s << "; // " << referenceFunction->minimalSignature() << Qt::endl; return; } @@ -2552,7 +2555,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov if (isLastArgument || (signatureFound && !hasDefaultCall)) { const AbstractMetaFunction *func = parentOverloadData->referenceFunction(); s << INDENT << "overloadId = " << parentOverloadData->headOverloadData()->overloads().indexOf(func); - s << "; // " << func->minimalSignature() << endl; + s << "; // " << func->minimalSignature() << Qt::endl; return; } } @@ -2578,7 +2581,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov } } s << INDENT << "overloadId = " << parentOverloadData->headOverloadData()->overloads().indexOf(func); - s << "; // " << func->minimalSignature() << endl; + s << "; // " << func->minimalSignature() << Qt::endl; } s << INDENT << '}'; } @@ -2635,9 +2638,11 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov if (usePyArgs && signatureFound) { AbstractMetaArgumentList args = refFunc->arguments(); - int lastArgIsVarargs = (int) (args.size() > 1 && args.constLast()->type()->isVarargs()); - int numArgs = args.size() - OverloadData::numberOfRemovedArguments(refFunc) - lastArgIsVarargs; - typeChecks.prepend(QString::fromLatin1("numArgs %1 %2").arg(lastArgIsVarargs ? QLatin1String(">=") : QLatin1String("==")).arg(numArgs)); + const bool isVarargs = args.size() > 1 && args.constLast()->type()->isVarargs(); + int numArgs = args.size() - OverloadData::numberOfRemovedArguments(refFunc); + if (isVarargs) + --numArgs; + typeChecks.prepend(QString::fromLatin1("numArgs %1 %2").arg(isVarargs ? QLatin1String(">=") : QLatin1String("==")).arg(numArgs)); } else if (sequenceArgCount > 1) { typeChecks.prepend(QString::fromLatin1("numArgs >= %1").arg(startArg + sequenceArgCount)); } else if (refFunc->isOperatorOverload() && !refFunc->isCallOperator()) { @@ -2657,7 +2662,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov Indentation indent(INDENT); QString separator; QTextStream sep(&separator); - sep << endl << INDENT << "&& "; + sep << Qt::endl << INDENT << "&& "; s << typeChecks.join(separator); } s << ") {\n"; @@ -2667,7 +2672,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov } s << INDENT << "}"; } - s << endl; + s << Qt::endl; } void CppGenerator::writeFunctionCalls(QTextStream &s, const OverloadData &overloadData, @@ -2683,7 +2688,7 @@ void CppGenerator::writeFunctionCalls(QTextStream &s, const OverloadData &overlo } else { for (int i = 0; i < overloads.count(); i++) { const AbstractMetaFunction *func = overloads.at(i); - s << INDENT << "case " << i << ": // " << func->signature() << endl; + s << INDENT << "case " << i << ": // " << func->signature() << Qt::endl; s << INDENT << "{\n"; { Indentation indent(INDENT); @@ -2718,7 +2723,7 @@ void CppGenerator::writeSingleFunctionCall(QTextStream &s, s << INDENT << "PyErr_Format(PyExc_TypeError, \"%s is a private method.\", \"" << func->signature().replace(QLatin1String("::"), QLatin1String(".")) << "\");\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; return; } @@ -2761,7 +2766,7 @@ void CppGenerator::writeSingleFunctionCall(QTextStream &s, writeArgumentConversion(s, argType, argName, pyArgName, func->implementingClass(), defaultValue, func->isUserAdded()); } - s << endl; + s << Qt::endl; int numRemovedArgs = OverloadData::numberOfRemovedArguments(func); @@ -2916,7 +2921,7 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s, if (conversion.isEmpty()) conversion = QLatin1Char('*') + cpythonWrapperCPtr(sourceType->typeEntry(), QLatin1String("pyIn")); if (!preConversion.isEmpty()) - c << INDENT << preConversion << endl; + c << INDENT << preConversion << Qt::endl; const QString fullTypeName = getFullTypeName(targetType->typeEntry()); c << INDENT << "*reinterpret_cast<" << fullTypeName << " *>(cppOut) = " << fullTypeName << '(' << conversion << ");"; @@ -2928,7 +2933,7 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s, if (typeCheck.isEmpty()) typeCheck = QString::fromLatin1("PyObject_TypeCheck(pyIn, %1)").arg(sourcePyType); writeIsPythonConvertibleToCppFunction(s, sourceTypeName, targetTypeName, typeCheck); - s << endl; + s << Qt::endl; } void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s, @@ -3036,15 +3041,15 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s, const Abs else typeCheck = QString::fromLatin1("%1pyIn)").arg(typeCheck); writeIsPythonConvertibleToCppFunction(s, typeName, typeName, typeCheck); - s << endl; + s << Qt::endl; } void CppGenerator::writeAddPythonToCppConversion(QTextStream &s, const QString &converterVar, const QString &pythonToCppFunc, const QString &isConvertibleFunc) { - s << INDENT << "Shiboken::Conversions::addPythonToCppValueConversion(" << converterVar << ',' << endl; + s << INDENT << "Shiboken::Conversions::addPythonToCppValueConversion(" << converterVar << ',' << Qt::endl; { Indentation indent(INDENT); - s << INDENT << pythonToCppFunc << ',' << endl; + s << INDENT << pythonToCppFunc << ',' << Qt::endl; s << INDENT << isConvertibleFunc; } s << ");\n"; @@ -3075,8 +3080,8 @@ void CppGenerator::writeNamedArgumentResolution(QTextStream &s, const AbstractMe s << INDENT << "if (value && " << pyArgName << ") {\n"; { Indentation indent(INDENT); - s << INDENT << pyErrString.arg(arg->name()) << endl; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << pyErrString.arg(arg->name()) << Qt::endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } s << INDENT << "}\n"; s << INDENT << "if (value) {\n"; @@ -3151,7 +3156,7 @@ static QStringList defaultExceptionHandling() void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *func, GeneratorContext &context, int maxArgs) { - s << INDENT << "// " << func->minimalSignature() << (func->isReverseOperator() ? " [reverse operator]": "") << endl; + s << INDENT << "// " << func->minimalSignature() << (func->isReverseOperator() ? " [reverse operator]": "") << Qt::endl; if (func->isConstructor()) { const CodeSnipList &snips = func->injectedCodeSnips(); for (const CodeSnip &cs : snips) { @@ -3168,7 +3173,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f Indentation indent(INDENT); s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"pure virtual method '"; s << func->ownerClass()->name() << '.' << func->name() << "()' not implemented.\");\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } s << INDENT << "}\n"; } @@ -3195,7 +3200,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f } writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::TargetLangCode, func, lastArg); - s << endl; + s << Qt::endl; } writeConversionRule(s, func, TypeSystem::NativeCode); @@ -3280,14 +3285,14 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f std::swap(firstArg, secondArg); QString op = func->originalName(); - op = op.right(op.size() - (sizeof("operator")/sizeof(char)-1)); + op.remove(0, int(std::strlen("operator"))); if (func->isBinaryOperator()) { if (func->isReverseOperator()) std::swap(firstArg, secondArg); if (((op == QLatin1String("++")) || (op == QLatin1String("--"))) && !func->isReverseOperator()) { - s << endl << INDENT << "for (int i=0; i < " << secondArg << "; i++, " << firstArg << op << ");\n"; + s << Qt::endl << INDENT << "for (int i=0; i < " << secondArg << "; i++, " << firstArg << op << ");\n"; mc << firstArg; } else { mc << firstArg << ' ' << op << ' ' << secondArg; @@ -3314,7 +3319,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f << ctorCall << ";\n" << INDENT << "PySide::setNextQObjectMemoryAddr(0);" - << endl; + << Qt::endl; } uva << INDENT << "} else {\n"; { @@ -3418,12 +3423,12 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f << INDENT << "threadSaver.save();\n"; } } else if (allowThread) { - s << INDENT << BEGIN_ALLOW_THREADS << endl; + s << INDENT << BEGIN_ALLOW_THREADS << Qt::endl; } s << INDENT; if (isCtor) { s << (useVAddr.isEmpty() ? - QString::fromLatin1("cptr = %1;").arg(methodCall) : useVAddr) << endl; + QString::fromLatin1("cptr = %1;").arg(methodCall) : useVAddr) << Qt::endl; } else if (func->type() && !func->isInplaceOperator()) { bool writeReturnType = true; if (avoidProtectedHack()) { @@ -3484,7 +3489,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f } if (func->hasInjectedCode() && !func->isConstructor()) { - s << endl; + s << Qt::endl; writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionEnd, TypeSystem::TargetLangCode, func, lastArg); } @@ -3509,12 +3514,12 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f hasReturnPolicy = true; if (!ownership_mods.isEmpty()) { - s << endl << INDENT << "// Ownership transferences.\n"; + s << Qt::endl << INDENT << "// Ownership transferences.\n"; for (const ArgumentModification &arg_mod : qAsConst(ownership_mods)) { const AbstractMetaClass *wrappedClass = nullptr; QString pyArgName = argumentNameFromIndex(func, arg_mod.index, &wrappedClass); if (!wrappedClass) { - s << "#error Invalid ownership modification for argument " << arg_mod.index << '(' << pyArgName << ")\n" << endl; + s << "#error Invalid ownership modification for argument " << arg_mod.index << '(' << pyArgName << ")\n" << Qt::endl; break; } @@ -3537,7 +3542,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f } else { s << "invalidate(" << pyArgName << ");"; } - s << endl; + s << Qt::endl; } } else if (!refcount_mods.isEmpty()) { @@ -3557,7 +3562,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f } else { pyArgName = argumentNameFromIndex(func, arg_mod.index, &wrappedClass); if (pyArgName.isEmpty()) { - s << "#error Invalid reference count modification for argument " << arg_mod.index << endl << endl; + s << "#error Invalid reference count modification for argument " << arg_mod.index << Qt::endl << Qt::endl; break; } } @@ -3628,9 +3633,9 @@ void CppGenerator::writeMultipleInheritanceInitializerFunction(QTextStream &s, c for (const QString &ancestor : ancestors) s << INDENT << "offsets.insert(int(" << ancestor << "));\n"; - s << endl; + s << Qt::endl; s << INDENT << "offsets.erase(0);\n"; - s << endl; + s << Qt::endl; s << INDENT << "std::copy(offsets.cbegin(), offsets.cend(), mi_offsets);\n"; } @@ -3698,7 +3703,7 @@ void CppGenerator::writeEnumConverterInitialization(QTextStream &s, const TypeEn { Indentation indent(INDENT); QString typeName = fixedCppTypeName(enumType); - s << INDENT << "SbkConverter *converter = Shiboken::Conversions::createConverter(" << enumPythonType << ',' << endl; + s << INDENT << "SbkConverter *converter = Shiboken::Conversions::createConverter(" << enumPythonType << ',' << Qt::endl; { Indentation indent(INDENT); s << INDENT << cppToPythonFunctionName(typeName, typeName) << ");\n"; @@ -3783,7 +3788,7 @@ void CppGenerator::writeContainerConverterInitialization(QTextStream &s, const A void CppGenerator::writeExtendedConverterInitialization(QTextStream &s, const TypeEntry *externalType, const QVector<const AbstractMetaClass *>& conversions) { - s << INDENT << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << endl; + s << INDENT << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << Qt::endl; for (const AbstractMetaClass *sourceClass : conversions) { const QString converterVar = QLatin1String("reinterpret_cast<SbkObjectType *>(") + cppApiVariableName(externalType->targetLangPackage()) + QLatin1Char('[') @@ -3971,7 +3976,7 @@ void CppGenerator::writeClassDefinition(QTextStream &s, if (metaClass == miClass) writeMultipleInheritanceInitializerFunction(s, metaClass); writeSpecialCastFunction(s, metaClass); - s << endl; + s << Qt::endl; } s << "// Class Definition -----------------------------------------------\n"; @@ -4000,7 +4005,7 @@ void CppGenerator::writeClassDefinition(QTextStream &s, s << "{\n"; s << INDENT << "return " << typePtr << ";\n"; s << "}\n"; - s << endl; + s << Qt::endl; s << "static PyType_Slot " << className << "_slots[] = {\n"; s << INDENT << "{Py_tp_base, nullptr}, // inserted by introduceWrapperType\n"; s << INDENT << pyTypeSlotEntry("Py_tp_dealloc", tp_dealloc) @@ -4041,8 +4046,8 @@ void CppGenerator::writeClassDefinition(QTextStream &s, s << INDENT << tp_flags << ",\n"; s << INDENT << className << "_slots\n"; s << "};\n"; - s << endl; - s << "} //extern \"C\"" << endl; + s << Qt::endl; + s << "} //extern \"C\"" << Qt::endl; } void CppGenerator::writeMappingMethods(QTextStream &s, @@ -4090,7 +4095,7 @@ void CppGenerator::writeSequenceMethods(QTextStream &s, writeCppSelfDefinition(s, func, context); - const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? 0 : func->arguments().constLast(); + const AbstractMetaArgument *lastArg = func->arguments().isEmpty() ? nullptr : func->arguments().constLast(); writeCodeSnips(s, snips,TypeSystem::CodeSnipPositionAny, TypeSystem::TargetLangCode, func, lastArg); s<< "}\n\n"; } @@ -4275,7 +4280,7 @@ void CppGenerator::writeCopyFunction(QTextStream &s, GeneratorContext &context) writeFunctionReturnErrorCheckSection(s); s << INDENT << "return " << PYTHON_RETURN_VAR << ";\n"; s << "}\n"; - s << endl; + s << Qt::endl; } void CppGenerator::writeGetterFunction(QTextStream &s, @@ -4414,7 +4419,7 @@ void CppGenerator::writeSetterFunction(QTextStream &s, s << cppField << ";\n"; s << INDENT << PYTHON_TO_CPP_VAR << "(pyIn, &cppOut_ptr)"; } - s << ";\n" << endl; + s << ";\n" << Qt::endl; if (isPointerToWrapperType(fieldType)) { s << INDENT << "Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(self), \""; @@ -4437,7 +4442,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, GeneratorContext &co s << INDENT << "PyObject *" << PYTHON_RETURN_VAR << "{};\n"; s << INDENT << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << ";\n"; writeUnusedVariableCast(s, QLatin1String(PYTHON_TO_CPP_VAR)); - s << endl; + s << Qt::endl; s << INDENT << "switch (op) {\n"; { @@ -4447,7 +4452,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, GeneratorContext &co const AbstractMetaFunction *rfunc = overloads[0]; QString operatorId = ShibokenGenerator::pythonRichCompareOperatorId(rfunc); - s << INDENT << "case " << operatorId << ':' << endl; + s << INDENT << "case " << operatorId << ':' << Qt::endl; Indentation indent(INDENT); @@ -4482,7 +4487,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, GeneratorContext &co s << ") {\n"; { Indentation indent(INDENT); - s << INDENT << "// " << func->signature() << endl; + s << INDENT << "// " << func->signature() << Qt::endl; writeArgumentConversion(s, argType, QLatin1String(CPP_ARG0), QLatin1String(PYTHON_ARG), metaClass, QString(), func->isUserAdded()); @@ -4542,7 +4547,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, GeneratorContext &co } s << INDENT << baseName << "_RichComparison_TypeError:\n"; s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"operator not implemented.\");\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl << Qt::endl; s<< "}\n\n"; } @@ -4586,7 +4591,7 @@ void CppGenerator::writeMethodDefinition(QTextStream &s, const AbstractMetaFunct writeMethodDefinitionEntry(s, overloads); s << '}'; } - s << ',' << endl; + s << ',' << Qt::endl; } void CppGenerator::writeSignatureInfo(QTextStream &s, const AbstractMetaFunctionList &overloads) @@ -4619,7 +4624,7 @@ void CppGenerator::writeSignatureInfo(QTextStream &s, const AbstractMetaFunction s << funcName << '(' << args.join(QLatin1Char(',')) << ')'; if (f->type()) s << "->" << f->type()->pythonSignature(); - s << endl; + s << Qt::endl; } } @@ -4646,9 +4651,8 @@ static QString mangleName(QString name) void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnum *cppEnum) { - const AbstractMetaClass *enclosingClass = getProperEnclosingClassForEnum(cppEnum); - const AbstractMetaClass *upper = enclosingClass ? enclosingClass->enclosingClass() : nullptr; - bool hasUpperEnclosingClass = upper && upper->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass; + const AbstractMetaClass *enclosingClass = cppEnum->targetLangEnclosingClass(); + bool hasUpperEnclosingClass = enclosingClass && enclosingClass->targetLangEnclosingClass() != nullptr; const EnumTypeEntry *enumTypeEntry = cppEnum->typeEntry(); QString enclosingObjectVariable; if (enclosingClass) @@ -4679,7 +4683,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu s << INDENT << enumVarTypeObj << " = Shiboken::Enum::"; s << ((enclosingClass || hasUpperEnclosingClass) ? "createScopedEnum" : "createGlobalEnum"); - s << '(' << enclosingObjectVariable << ',' << endl; + s << '(' << enclosingObjectVariable << ',' << Qt::endl; { Indentation indent(INDENT); s << INDENT << '"' << cppEnum->name() << "\",\n"; @@ -4687,13 +4691,13 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu s << INDENT << '"' << (cppEnum->enclosingClass() ? (cppEnum->enclosingClass()->qualifiedCppName() + QLatin1String("::")) : QString()); s << cppEnum->name() << '"'; if (flags) - s << ',' << endl << INDENT << cpythonTypeNameExt(flags); + s << ',' << Qt::endl << INDENT << cpythonTypeNameExt(flags); s << ");\n"; } s << INDENT << "if (!" << cpythonTypeNameExt(cppEnum->typeEntry()) << ")\n"; { Indentation indent(INDENT); - s << INDENT << returnStatement(m_currentErrorCode) << endl << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl << Qt::endl; } } @@ -4726,7 +4730,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu << "))->tp_dict, \"" << mangleName(enumValue->name()) << "\", anonEnumItem) < 0)\n"; { Indentation indent(INDENT); - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } s << INDENT << "Py_DECREF(anonEnumItem);\n"; } @@ -4736,27 +4740,27 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu s << enumValueText << ") < 0)\n"; { Indentation indent(INDENT); - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } } break; case CEnum: { s << INDENT << "if (!Shiboken::Enum::"; s << ((enclosingClass || hasUpperEnclosingClass) ? "createScopedEnumItem" : "createGlobalEnumItem"); - s << '(' << enumVarTypeObj << ',' << endl; + s << '(' << enumVarTypeObj << ',' << Qt::endl; Indentation indent(INDENT); s << INDENT << enclosingObjectVariable << ", \"" << mangleName(enumValue->name()) << "\", "; s << enumValueText << "))\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } break; case EnumClass: { s << INDENT << "if (!Shiboken::Enum::createScopedEnumItem(" - << enumVarTypeObj << ',' << endl; + << enumVarTypeObj << ',' << Qt::endl; Indentation indent(INDENT); s << INDENT << enumVarTypeObj<< ", \"" << mangleName(enumValue->name()) << "\", " << enumValueText << "))\n" - << INDENT << returnStatement(m_currentErrorCode) << endl; + << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } break; } @@ -4767,7 +4771,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu s << INDENT << "// End of '" << cppEnum->name() << "' enum"; if (cppEnum->typeEntry()->flags()) s << "/flags"; - s << '.' << endl << endl; + s << '.' << Qt::endl << Qt::endl; } void CppGenerator::writeSignalInitialization(QTextStream &s, const AbstractMetaClass *metaClass) @@ -4835,7 +4839,7 @@ void CppGenerator::writeFlagsMethods(QTextStream &s, const AbstractMetaEnum *cpp writeFlagsToLong(s, cppEnum); writeFlagsNonZero(s, cppEnum); - s << endl; + s << Qt::endl; } void CppGenerator::writeFlagsNumberMethodsDefinition(QTextStream &s, const AbstractMetaEnum *cppEnum) @@ -4859,7 +4863,7 @@ void CppGenerator::writeFlagsNumberMethodsDefinition(QTextStream &s, const Abstr s << INDENT << "{Py_nb_long, (void *)" << cpythonName << "_long},\n"; s << "#endif\n"; s << INDENT << "{0, " << NULL_PTR << "} // sentinel\n"; - s << "};" << endl << endl; + s << "};\n\n"; } void CppGenerator::writeFlagsBinaryOperator(QTextStream &s, const AbstractMetaEnum *cppEnum, @@ -4944,9 +4948,8 @@ void CppGenerator::writeClassRegister(QTextStream &s, { const ComplexTypeEntry *classTypeEntry = metaClass->typeEntry(); - const AbstractMetaClass *enc = metaClass->enclosingClass(); - bool hasEnclosingClass = enc && enc->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass; - QString enclosingObjectVariable = hasEnclosingClass ? QLatin1String("enclosingClass") : QLatin1String("module"); + const AbstractMetaClass *enc = metaClass->targetLangEnclosingClass(); + QString enclosingObjectVariable = enc ? QLatin1String("enclosingClass") : QLatin1String("module"); QString pyTypeName = cpythonTypeName(metaClass); QString initFunctionName = getInitFunctionName(classContext); @@ -4967,7 +4970,7 @@ void CppGenerator::writeClassRegister(QTextStream &s, const AbstractMetaClassList baseClasses = getBaseClasses(metaClass); if (metaClass->baseClassNames().size() > 1) { s << INDENT << "PyObject *" << pyTypeBasesVariable - << " = PyTuple_Pack(" << baseClasses.size() << ',' << endl; + << " = PyTuple_Pack(" << baseClasses.size() << ',' << Qt::endl; Indentation indent(INDENT); for (int i = 0, size = baseClasses.size(); i < size; ++i) { if (i) @@ -5039,13 +5042,13 @@ void CppGenerator::writeClassRegister(QTextStream &s, // 8:baseTypes if (metaClass->baseClassNames().size() > 1) - s << INDENT << pyTypeBasesVariable << ',' << endl; + s << INDENT << pyTypeBasesVariable << ',' << Qt::endl; else s << INDENT << "0,\n"; // 9:wrapperflags QByteArrayList wrapperFlags; - if (hasEnclosingClass) + if (enc) wrapperFlags.append(QByteArrayLiteral("Shiboken::ObjectType::WrapperFlags::InnerClass")); if (metaClass->deleteInMainThread()) wrapperFlags.append(QByteArrayLiteral("Shiboken::ObjectType::WrapperFlags::DeleteInMainThread")); @@ -5055,23 +5058,23 @@ void CppGenerator::writeClassRegister(QTextStream &s, s << INDENT << wrapperFlags.join(" | "); } s << INDENT << ");\n"; - s << INDENT << endl; + s << INDENT << Qt::endl; if (!classContext.forSmartPointer()) - s << INDENT << cpythonTypeNameExt(classTypeEntry) << endl; + s << INDENT << cpythonTypeNameExt(classTypeEntry) << Qt::endl; else - s << INDENT << cpythonTypeNameExt(classContext.preciseType()) << endl; + s << INDENT << cpythonTypeNameExt(classContext.preciseType()) << Qt::endl; s << INDENT << " = reinterpret_cast<PyTypeObject *>(" << pyTypeName << ");\n"; - s << endl; + s << Qt::endl; // Register conversions for the type. writeConverterRegister(s, metaClass, classContext); - s << endl; + s << Qt::endl; // class inject-code target/beginning if (!classTypeEntry->codeSnips().isEmpty()) { writeCodeSnips(s, classTypeEntry->codeSnips(), TypeSystem::CodeSnipPositionBeginning, TypeSystem::TargetLangCode, metaClass); - s << endl; + s << Qt::endl; } // Fill multiple inheritance data, if needed. @@ -5117,11 +5120,11 @@ void CppGenerator::writeClassRegister(QTextStream &s, writeToPythonConversion(s, field->type(), metaClass, metaClass->qualifiedCppName() + QLatin1String("::") + field->name()); s << ");\n"; } - s << endl; + s << Qt::endl; // class inject-code target/end if (!classTypeEntry->codeSnips().isEmpty()) { - s << endl; + s << Qt::endl; writeCodeSnips(s, classTypeEntry->codeSnips(), TypeSystem::CodeSnipPositionEnd, TypeSystem::TargetLangCode, metaClass); } @@ -5439,6 +5442,25 @@ void CppGenerator::writeSmartPointerGetattroFunction(QTextStream &s, GeneratorCo s << INDENT << "return tmp;\n}\n\n"; } +// Write declaration and invocation of the init function for the module init +// function. +void CppGenerator::writeInitFunc(QTextStream &declStr, QTextStream &callStr, + const Indentor &indent, const QString &initFunctionName, + const TypeEntry *enclosingEntry) +{ + const bool hasParent = + enclosingEntry && enclosingEntry->type() != TypeEntry::TypeSystemType; + declStr << "void init_" << initFunctionName << "(PyObject *" + << (hasParent ? "enclosingClass" : "module") << ");\n"; + callStr << indent << "init_" << initFunctionName; + if (hasParent) { + callStr << "(reinterpret_cast<PyTypeObject *>(" + << cpythonTypeNameExt(enclosingEntry) << ")->tp_dict);\n"; + } else { + callStr << "(module);\n"; + } +} + bool CppGenerator::finishGeneration() { //Generate CPython wrapper file @@ -5493,33 +5515,20 @@ bool CppGenerator::finishGeneration() const AbstractMetaClassList lst = classesTopologicalSorted(additionalDependencies); for (const AbstractMetaClass *cls : lst){ - if (!shouldGenerate(cls)) - continue; - - const QString initFunctionName = QLatin1String("init_") + getSimpleClassInitFunctionName(cls); - - s_classInitDecl << "void " << initFunctionName << "(PyObject *module);" << endl; - - s_classPythonDefines << INDENT << initFunctionName; - if (cls->enclosingClass() - && (cls->enclosingClass()->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass)) { - s_classPythonDefines << "(reinterpret_cast<PyTypeObject *>(" - << cpythonTypeNameExt(cls->enclosingClass()->typeEntry()) << ")->tp_dict);"; - } else { - s_classPythonDefines << "(module);"; + if (shouldGenerate(cls)) { + writeInitFunc(s_classInitDecl, s_classPythonDefines, INDENT, + getSimpleClassInitFunctionName(cls), + cls->typeEntry()->targetLangEnclosingEntry()); } - s_classPythonDefines << endl; } // Initialize smart pointer types. const QVector<const AbstractMetaType *> &smartPtrs = instantiatedSmartPointers(); for (const AbstractMetaType *metaType : smartPtrs) { GeneratorContext context(nullptr, metaType, true); - QString initFunctionName = getInitFunctionName(context); - s_classInitDecl << "void init_" << initFunctionName << "(PyObject *module);" << endl; - QString defineStr = QLatin1String("init_") + initFunctionName; - defineStr += QLatin1String("(module);"); - s_classPythonDefines << INDENT << defineStr << endl; + writeInitFunc(s_classInitDecl, s_classPythonDefines, INDENT, + getInitFunctionName(context), + metaType->typeEntry()->targetLangEnclosingEntry()); } QString moduleFileName(outputDirectory() + QLatin1Char('/') + subDirectoryForPackage(packageName())); @@ -5532,7 +5541,7 @@ bool CppGenerator::finishGeneration() QTextStream &s = file.stream; // write license comment - s << licenseComment() << endl; + s << licenseComment() << Qt::endl; s << "#include <sbkpython.h>\n"; s << "#include <shiboken.h>\n"; @@ -5544,19 +5553,18 @@ bool CppGenerator::finishGeneration() s << "#include <qapp_macro.h>\n"; } - s << "#include \"" << getModuleHeaderFileName() << '"' << endl << endl; + s << "#include \"" << getModuleHeaderFileName() << '"' << Qt::endl << Qt::endl; for (const Include &include : qAsConst(includes)) s << include; - s << endl; + s << Qt::endl; // Global enums AbstractMetaEnumList globalEnums = this->globalEnums(); const AbstractMetaClassList &classList = classes(); for (const AbstractMetaClass *metaClass : classList) { const AbstractMetaClass *encClass = metaClass->enclosingClass(); - if (encClass && encClass->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass) - continue; - lookForEnumsInClassesNotToBeGenerated(globalEnums, metaClass); + if (!encClass || !NamespaceTypeEntry::isVisibleScope(encClass->typeEntry())) + lookForEnumsInClassesNotToBeGenerated(globalEnums, metaClass); } TypeDatabase *typeDb = TypeDatabase::instance(); @@ -5564,14 +5572,14 @@ bool CppGenerator::finishGeneration() Q_ASSERT(moduleEntry); //Extra includes - s << endl << "// Extra includes\n"; + s << Qt::endl << "// Extra includes\n"; QVector<Include> extraIncludes = moduleEntry->extraIncludes(); for (AbstractMetaEnum *cppEnum : qAsConst(globalEnums)) extraIncludes.append(cppEnum->typeEntry()->extraIncludes()); std::sort(extraIncludes.begin(), extraIncludes.end()); for (const Include &inc : qAsConst(extraIncludes)) s << inc; - s << endl; + s << Qt::endl; s << "// Current module's type array.\n"; s << "PyTypeObject **" << cppApiVariableName() << " = nullptr;\n"; @@ -5587,7 +5595,7 @@ bool CppGenerator::finishGeneration() // module inject-code native/beginning if (!snips.isEmpty()) { writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::NativeCode); - s << endl; + s << Qt::endl; } // cleanup staticMetaObject attribute @@ -5612,7 +5620,7 @@ bool CppGenerator::finishGeneration() s << "// Global functions "; s << "------------------------------------------------------------\n"; - s << globalFunctionImpl << endl; + s << globalFunctionImpl << Qt::endl; s << "static PyMethodDef " << moduleName() << "_methods[] = {\n"; s << globalFunctionDecl; @@ -5620,7 +5628,7 @@ bool CppGenerator::finishGeneration() s << "// Classes initialization functions "; s << "------------------------------------------------------------\n"; - s << classInitDecl << endl; + s << classInitDecl << Qt::endl; if (!globalEnums.isEmpty()) { QString converterImpl; @@ -5632,14 +5640,14 @@ bool CppGenerator::finishGeneration() if (cppEnum->isAnonymous() || cppEnum->isPrivate()) continue; writeEnumConverterFunctions(s, cppEnum); - s << endl; + s << Qt::endl; } if (!converterImpl.isEmpty()) { s << "// Enum converters "; s << "------------------------------------------------------------\n"; s << "namespace Shiboken\n{\n"; - s << converterImpl << endl; + s << converterImpl << Qt::endl; s << "} // namespace Shiboken\n\n"; } } @@ -5651,16 +5659,16 @@ bool CppGenerator::finishGeneration() s << "PyTypeObject **" << cppApiVariableName(requiredModule) << ";\n"; s << "SbkConverter **" << convertersVariableName(requiredModule) << ";\n"; } - s << endl; + s << Qt::endl; s << "// Module initialization "; s << "------------------------------------------------------------\n"; ExtendedConverterData extendedConverters = getExtendedConverters(); if (!extendedConverters.isEmpty()) { - s << endl << "// Extended Converters.\n\n"; + s << Qt::endl << "// Extended Converters.\n\n"; for (ExtendedConverterData::const_iterator it = extendedConverters.cbegin(), end = extendedConverters.cend(); it != end; ++it) { const TypeEntry *externalType = it.key(); - s << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << endl; + s << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << Qt::endl; for (const AbstractMetaClass *sourceClass : it.value()) { AbstractMetaType *sourceType = buildAbstractMetaTypeFromAbstractMetaClass(sourceClass); AbstractMetaType *targetType = buildAbstractMetaTypeFromTypeEntry(externalType); @@ -5671,13 +5679,13 @@ bool CppGenerator::finishGeneration() const QVector<const CustomConversion *> &typeConversions = getPrimitiveCustomConversions(); if (!typeConversions.isEmpty()) { - s << endl << "// Primitive Type converters.\n\n"; + s << Qt::endl << "// Primitive Type converters.\n\n"; for (const CustomConversion *conversion : typeConversions) { s << "// C++ to Python conversion for type '" << conversion->ownerType()->qualifiedCppName() << "'.\n"; writeCppToPythonFunction(s, conversion); writeCustomConverterFunctions(s, conversion); } - s << endl; + s << Qt::endl; } const QVector<const AbstractMetaType *> &containers = instantiatedContainers(); @@ -5687,7 +5695,7 @@ bool CppGenerator::finishGeneration() s << "// C++ to Python conversion for type '" << container->cppSignature() << "'.\n"; writeContainerConverterFunctions(s, container); } - s << endl; + s << Qt::endl; } s << "#if defined _WIN32 || defined __CYGWIN__\n"; @@ -5727,7 +5735,7 @@ bool CppGenerator::finishGeneration() // module inject-code target/beginning if (!snips.isEmpty()) { writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionBeginning, TypeSystem::TargetLangCode); - s << endl; + s << Qt::endl; } for (const QString &requiredModule : requiredModules) { @@ -5774,26 +5782,26 @@ bool CppGenerator::finishGeneration() s << classPythonDefines; if (!typeConversions.isEmpty()) { - s << endl; + s << Qt::endl; for (const CustomConversion *conversion : typeConversions) { writePrimitiveConverterInitialization(s, conversion); - s << endl; + s << Qt::endl; } } if (!containers.isEmpty()) { - s << endl; + s << Qt::endl; for (const AbstractMetaType *container : containers) { writeContainerConverterInitialization(s, container); - s << endl; + s << Qt::endl; } } if (!extendedConverters.isEmpty()) { - s << endl; + s << Qt::endl; for (ExtendedConverterData::const_iterator it = extendedConverters.cbegin(), end = extendedConverters.cend(); it != end; ++it) { writeExtendedConverterInitialization(s, it.key(), it.value()); - s << endl; + s << Qt::endl; } } @@ -5816,12 +5824,12 @@ bool CppGenerator::finishGeneration() } } - s << endl; + s << Qt::endl; if (maxTypeIndex) s << INDENT << "Shiboken::Module::registerTypes(module, " << cppApiVariableName() << ");\n"; s << INDENT << "Shiboken::Module::registerTypeConverters(module, " << convertersVariableName() << ");\n"; - s << endl << INDENT << "if (PyErr_Occurred()) {\n"; + s << Qt::endl << INDENT << "if (PyErr_Occurred()) {\n"; { Indentation indentation(INDENT); s << INDENT << "PyErr_Print();\n"; @@ -5832,13 +5840,13 @@ bool CppGenerator::finishGeneration() // module inject-code target/end if (!snips.isEmpty()) { writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionEnd, TypeSystem::TargetLangCode); - s << endl; + s << Qt::endl; } // module inject-code native/end if (!snips.isEmpty()) { writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionEnd, TypeSystem::NativeCode); - s << endl; + s << Qt::endl; } if (usePySideExtensions()) { @@ -5855,7 +5863,7 @@ bool CppGenerator::finishGeneration() s << INDENT << "FinishSignatureInitialization(module, " << moduleName() << "_SignatureStrings);\n"; - s << endl; + s << Qt::endl; s << "SBK_MODULE_INIT_FUNCTION_END\n"; return file.done() != FileOut::Failure; @@ -6031,7 +6039,7 @@ void CppGenerator::writeIndexError(QTextStream &s, const QString &errorMsg) { Indentation indent(INDENT); s << INDENT << "PyErr_SetString(PyExc_IndexError, \"" << errorMsg << "\");\n"; - s << INDENT << returnStatement(m_currentErrorCode) << endl; + s << INDENT << returnStatement(m_currentErrorCode) << Qt::endl; } s << INDENT << "}\n"; } diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp index 34bba408a..af56d944a 100644 --- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp @@ -119,7 +119,7 @@ void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classConte s << "#define protected public\n\n"; //Includes - s << metaClass->typeEntry()->include() << endl; + s << metaClass->typeEntry()->include() << Qt::endl; if (shouldGenerateCppWrapper(metaClass) && usePySideExtensions() && metaClass->isQObject()) @@ -337,7 +337,8 @@ void HeaderGenerator::writeTypeIndexValueLine(QTextStream &s, const TypeEntry *t void HeaderGenerator::writeTypeIndexValueLines(QTextStream &s, const AbstractMetaClass *metaClass) { - if (!metaClass->typeEntry()->generateCode()) + auto typeEntry = metaClass->typeEntry(); + if (!typeEntry->generateCode() || !NamespaceTypeEntry::isVisibleScope(typeEntry)) return; writeTypeIndexValueLine(s, metaClass->typeEntry()); const AbstractMetaEnumList &enums = metaClass->enums(); @@ -411,9 +412,17 @@ bool HeaderGenerator::finishGeneration() int smartPointerCount = 0; const QVector<const AbstractMetaType *> &instantiatedSmartPtrs = instantiatedSmartPointers(); for (const AbstractMetaType *metaType : instantiatedSmartPtrs) { - _writeTypeIndexValue(macrosStream, getTypeIndexVariableName(metaType), - smartPointerCountIndex); - macrosStream << ", // " << metaType->cppSignature() << endl; + QString indexName = getTypeIndexVariableName(metaType); + _writeTypeIndexValue(macrosStream, indexName, smartPointerCountIndex); + macrosStream << ", // " << metaType->cppSignature() << Qt::endl; + // Add a the same value for const pointees (shared_ptr<const Foo>). + const auto ptrName = metaType->typeEntry()->entryName(); + int pos = indexName.indexOf(ptrName, 0, Qt::CaseInsensitive); + if (pos >= 0) { + indexName.insert(pos + ptrName.size() + 1, QLatin1String("CONST")); + _writeTypeIndexValue(macrosStream, indexName, smartPointerCountIndex); + macrosStream << ", // (const)\n"; + } ++smartPointerCountIndex; ++smartPointerCount; } @@ -449,7 +458,7 @@ bool HeaderGenerator::finishGeneration() const QVector<const AbstractMetaType *> &containers = instantiatedContainers(); for (const AbstractMetaType *container : containers) { _writeTypeIndexValue(macrosStream, getTypeIndexVariableName(container), pCount); - macrosStream << ", // " << container->cppSignature() << endl; + macrosStream << ", // " << container->cppSignature() << Qt::endl; pCount++; } @@ -517,10 +526,10 @@ bool HeaderGenerator::finishGeneration() FileOut file(moduleHeaderFileName); QTextStream &s = file.stream; // write license comment - s << licenseComment() << endl << endl; + s << licenseComment() << Qt::endl << Qt::endl; - s << "#ifndef " << includeShield << endl; - s << "#define " << includeShield << endl << endl; + s << "#ifndef " << includeShield << Qt::endl; + s << "#define " << includeShield << Qt::endl << Qt::endl; if (!avoidProtectedHack()) { s << "//workaround to access protected functions\n"; s << "#define protected public\n\n"; @@ -534,7 +543,7 @@ bool HeaderGenerator::finishGeneration() s << "// Module Includes\n"; for (const QString &requiredModule : qAsConst(requiredTargetImports)) s << "#include <" << getModuleHeaderFileName(requiredModule) << ">\n"; - s << endl; + s << Qt::endl; } s << "// Bound library includes\n"; @@ -546,7 +555,7 @@ bool HeaderGenerator::finishGeneration() const PrimitiveTypeEntryList &primitiveTypeList = primitiveTypes(); for (const PrimitiveTypeEntry *ptype : primitiveTypeList) s << ptype->include(); - s << endl; + s << Qt::endl; } if (!containerTypes().isEmpty()) { @@ -554,24 +563,24 @@ bool HeaderGenerator::finishGeneration() const ContainerTypeEntryList &containerTypeList = containerTypes(); for (const ContainerTypeEntry *ctype : containerTypeList) s << ctype->include(); - s << endl; + s << Qt::endl; } - s << macros << endl; + s << macros << Qt::endl; if (!protectedEnumSurrogates.isEmpty()) { s << "// Protected enum surrogates\n"; - s << protectedEnumSurrogates << endl; + s << protectedEnumSurrogates << Qt::endl; } s << "namespace Shiboken\n{\n\n"; s << "// PyType functions, to get the PyObjectType for a type T\n"; - s << sbkTypeFunctions << endl; + s << sbkTypeFunctions << Qt::endl; s << "} // namespace Shiboken\n\n"; - s << "#endif // " << includeShield << endl << endl; + s << "#endif // " << includeShield << Qt::endl << Qt::endl; return file.done() != FileOut::Failure; } diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.cpp b/sources/shiboken2/generator/shiboken2/overloaddata.cpp index 56b64bbd5..bd39e9444 100644 --- a/sources/shiboken2/generator/shiboken2/overloaddata.cpp +++ b/sources/shiboken2/generator/shiboken2/overloaddata.cpp @@ -106,7 +106,7 @@ struct OverloadSortData return; map[typeName] = counter; if (!reverseMap.contains(counter)) - reverseMap[counter] = 0; + reverseMap[counter] = nullptr; counter++; } diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index fbd3c314b..170cbd74e 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -335,7 +335,7 @@ void ShibokenGenerator::lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumLi { Q_ASSERT(metaClass); // if a scope is not to be generated, collect its enums into the parent scope - if (metaClass->typeEntry()->codeGeneration() == TypeEntry::GenerateForSubclass) { + if (!NamespaceTypeEntry::isVisibleScope(metaClass->typeEntry())) { const AbstractMetaEnumList &enums = metaClass->enums(); for (AbstractMetaEnum *metaEnum : enums) { if (!metaEnum->isPrivate() && metaEnum->typeEntry()->generateCode() @@ -346,22 +346,6 @@ void ShibokenGenerator::lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumLi } } -static const AbstractMetaClass *getProperEnclosingClass(const AbstractMetaClass *metaClass) -{ - if (!metaClass) - return nullptr; - - if (metaClass->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass) - return metaClass; - - return getProperEnclosingClass(metaClass->enclosingClass()); -} - -const AbstractMetaClass *ShibokenGenerator::getProperEnclosingClassForEnum(const AbstractMetaEnum *metaEnum) -{ - return getProperEnclosingClass(metaEnum->enclosingClass()); -} - QString ShibokenGenerator::wrapperName(const AbstractMetaClass *metaClass) const { if (shouldGenerateCppWrapper(metaClass)) { @@ -394,7 +378,8 @@ QString ShibokenGenerator::fullPythonClassName(const AbstractMetaClass *metaClas QString fullClassName = metaClass->name(); const AbstractMetaClass *enclosing = metaClass->enclosingClass(); while (enclosing) { - fullClassName.prepend(enclosing->name() + QLatin1Char('.')); + if (NamespaceTypeEntry::isVisibleScope(enclosing->typeEntry())) + fullClassName.prepend(enclosing->name() + QLatin1Char('.')); enclosing = enclosing->enclosingClass(); } fullClassName.prepend(packageName() + QLatin1Char('.')); @@ -2393,7 +2378,7 @@ static bool isGroupable(const AbstractMetaFunction *func) return false; // weird operator overloads if (func->name() == QLatin1String("operator[]") || func->name() == QLatin1String("operator->")) // FIXME: what about cast operators? - return false;; + return false; return true; } @@ -2594,13 +2579,19 @@ void ShibokenGenerator::collectContainerTypesFromConverterMacros(const QString & QString convMacro = toPythonMacro ? QLatin1String("%CONVERTTOPYTHON[") : QLatin1String("%CONVERTTOCPP["); int offset = toPythonMacro ? sizeof("%CONVERTTOPYTHON") : sizeof("%CONVERTTOCPP"); int start = 0; + QString errorMessage; while ((start = code.indexOf(convMacro, start)) != -1) { int end = code.indexOf(QLatin1Char(']'), start); start += offset; if (code.at(start) != QLatin1Char('%')) { QString typeString = code.mid(start, end - start); - AbstractMetaType *type = buildAbstractMetaTypeFromString(typeString); - addInstantiatedContainersAndSmartPointers(type, type->originalTypeDescription()); + if (AbstractMetaType *type = + buildAbstractMetaTypeFromString(typeString, &errorMessage)) { + addInstantiatedContainersAndSmartPointers(type, type->originalTypeDescription()); + } else { + qFatal("%s: Cannot translate type \"%s\": %s", __FUNCTION__, + qPrintable(typeString), qPrintable(errorMessage)); + } } start = end; } @@ -2773,7 +2764,7 @@ void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream &s, const } else { const QString message = msgCouldNotFindMinimalConstructor(QLatin1String(__FUNCTION__), type->qualifiedCppName()); qCWarning(lcShiboken()).noquote() << message; - s << ";\n#error " << message << endl; + s << ";\n#error " << message << Qt::endl; } } diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h index 24c1374ae..d0e9073c8 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h @@ -219,8 +219,6 @@ protected: /// Adds enums eligible for generation from classes/namespaces marked not to be generated. static void lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumList &enumList, const AbstractMetaClass *metaClass); - /// Returns the enclosing class for an enum, or nullptr if it should be global. - const AbstractMetaClass *getProperEnclosingClassForEnum(const AbstractMetaEnum *metaEnum); QString wrapperName(const AbstractMetaClass *metaClass) const; QString wrapperName(const AbstractMetaType *metaType) const; |