diff options
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r-- | sources/shiboken2/generator/generator.cpp | 18 | ||||
-rw-r--r-- | sources/shiboken2/generator/generator.h | 3 | ||||
-rw-r--r-- | sources/shiboken2/generator/main.cpp | 3 | ||||
-rw-r--r-- | sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp | 6 | ||||
-rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 10 | ||||
-rw-r--r-- | sources/shiboken2/generator/shiboken2/shibokengenerator.cpp | 19 | ||||
-rw-r--r-- | sources/shiboken2/generator/shiboken2/shibokengenerator.h | 4 |
7 files changed, 36 insertions, 27 deletions
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp index f90cd312f..60282828a 100644 --- a/sources/shiboken2/generator/generator.cpp +++ b/sources/shiboken2/generator/generator.cpp @@ -43,6 +43,8 @@ #include <QDebug> #include <typedatabase.h> +static const char ENABLE_PYSIDE_EXTENSIONS[] = "enable-pyside-extensions"; + /** * DefaultValue is used for storing default values of types for which code is * generated in different contexts: @@ -169,6 +171,7 @@ struct Generator::GeneratorPrivate QVector<const AbstractMetaType *> instantiatedContainers; QVector<const AbstractMetaType *> instantiatedSmartPointers; AbstractMetaClassList m_invisibleTopNamespaces; + bool m_usePySideExtensions = false; }; Generator::Generator() : m_d(new GeneratorPrivate) @@ -339,11 +342,17 @@ QVector<const AbstractMetaType *> Generator::instantiatedSmartPointers() const Generator::OptionDescriptions Generator::options() const { - return OptionDescriptions(); + return { + {QLatin1String(ENABLE_PYSIDE_EXTENSIONS), + QLatin1String("Enable PySide extensions, such as support for signal/slots,\n" + "use this if you are creating a binding for a Qt-based library.")} + }; } -bool Generator::handleOption(const QString & /* key */, const QString & /* value */) +bool Generator::handleOption(const QString & key, const QString & /* value */) { + if (key == QLatin1String(ENABLE_PYSIDE_EXTENSIONS)) + return ( m_d->m_usePySideExtensions = true); return false; } @@ -615,6 +624,11 @@ bool Generator::isVoidPointer(const AbstractMetaType *type) && type->name() == QLatin1String("void"); } +bool Generator::usePySideExtensions() const +{ + return m_d->m_usePySideExtensions; +} + QString Generator::getFullTypeName(const TypeEntry *type) const { QString result = type->qualifiedCppName(); diff --git a/sources/shiboken2/generator/generator.h b/sources/shiboken2/generator/generator.h index cf6df528f..0cedbd255 100644 --- a/sources/shiboken2/generator/generator.h +++ b/sources/shiboken2/generator/generator.h @@ -244,6 +244,9 @@ public: /// Returns the generator's name. Used for cosmetic purposes. virtual const char *name() const = 0; + /// Returns true if the user enabled PySide extensions (command line option) + bool usePySideExtensions() const; + /** * Retrieves the name of the currently processed module. * While package name is a complete package idetification, e.g. 'PySide.QtCore', diff --git a/sources/shiboken2/generator/main.cpp b/sources/shiboken2/generator/main.cpp index cad6acdd1..fa41cb622 100644 --- a/sources/shiboken2/generator/main.cpp +++ b/sources/shiboken2/generator/main.cpp @@ -612,8 +612,7 @@ int main(int argc, char *argv[]) extractor.setCppFileNames(cppFileNames); extractor.setTypeSystem(typeSystemFileName); - auto shibokenGenerator = dynamic_cast<const ShibokenGenerator *>(generators.constFirst().data()); - const bool usePySideExtensions = shibokenGenerator && shibokenGenerator->usePySideExtensions(); + const bool usePySideExtensions = generators.constFirst().data()->usePySideExtensions(); if (!extractor.run(usePySideExtensions)) { errorPrint(QLatin1String("Error running ApiExtractor.")); diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp index d330d8c18..1b7c786d0 100644 --- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp @@ -2353,7 +2353,8 @@ bool QtDocGenerator::doSetup() Generator::OptionDescriptions QtDocGenerator::options() const { - return OptionDescriptions() + OptionDescriptions result = Generator::options(); + result << qMakePair(QLatin1String("doc-parser=<parser>"), QLatin1String("The documentation parser used to interpret the documentation\n" "input files (qdoc|doxygen)")) @@ -2368,10 +2369,13 @@ Generator::OptionDescriptions QtDocGenerator::options() const << qMakePair(additionalDocumentationOption() + QLatin1String("=<file>"), QLatin1String("List of additional XML files to be converted to .rst files\n" "(for example, tutorials).")); + return result; } bool QtDocGenerator::handleOption(const QString &key, const QString &value) { + if (Generator::handleOption(key, value)) + return true; if (key == QLatin1String("library-source-dir")) { m_libSourceDir = value; return true; diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 7743d50a2..6572fca9a 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -1061,7 +1061,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, QString argConv; QTextStream ac(&argConv); - auto argType = static_cast<const PrimitiveTypeEntry *>(arg->type()->typeEntry()); + const auto *argType = arg->type()->typeEntry(); bool convert = argType->isObject() || argType->isValue() || arg->type()->isValuePointer() @@ -1070,11 +1070,11 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, || argType->isEnum() || argType->isContainer() || arg->type()->referenceType() == LValueReference; - if (!convert && argType->isPrimitive()) { - if (argType->basicReferencedTypeEntry()) - argType = argType->basicReferencedTypeEntry(); - convert = !m_formatUnits.contains(argType->name()); + const auto *pte = static_cast<const PrimitiveTypeEntry *>(argType); + if (pte->basicReferencedTypeEntry()) + pte = pte->basicReferencedTypeEntry(); + convert = !m_formatUnits.contains(pte->name()); } Indentor nested; diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 0f5f09d60..42850e87d 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -46,7 +46,6 @@ static const char AVOID_PROTECTED_HACK[] = "avoid-protected-hack"; static const char PARENT_CTOR_HEURISTIC[] = "enable-parent-ctor-heuristic"; static const char RETURN_VALUE_HEURISTIC[] = "enable-return-value-heuristic"; -static const char ENABLE_PYSIDE_EXTENSIONS[] = "enable-pyside-extensions"; static const char DISABLE_VERBOSE_ERROR_MESSAGES[] = "disable-verbose-error-messages"; static const char USE_ISNULL_AS_NB_NONZERO[] = "use-isnull-as-nb_nonzero"; static const char WRAPPER_DIAGNOSTICS[] = "wrapper-diagnostics"; @@ -2567,7 +2566,8 @@ AbstractMetaFunctionList ShibokenGenerator::getFunctionOverloads(const AbstractM Generator::OptionDescriptions ShibokenGenerator::options() const { - return OptionDescriptions() + OptionDescriptions result = Generator::options(); + result << qMakePair(QLatin1String(AVOID_PROTECTED_HACK), QLatin1String("Avoid the use of the '#define protected public' hack.")) << qMakePair(QLatin1String(DISABLE_VERBOSE_ERROR_MESSAGES), @@ -2575,9 +2575,6 @@ Generator::OptionDescriptions ShibokenGenerator::options() const "but safe few kB on the generated bindings.")) << qMakePair(QLatin1String(PARENT_CTOR_HEURISTIC), QLatin1String("Enable heuristics to detect parent relationship on constructors.")) - << qMakePair(QLatin1String(ENABLE_PYSIDE_EXTENSIONS), - QLatin1String("Enable PySide extensions, such as support for signal/slots,\n" - "use this if you are creating a binding for a Qt-based library.")) << qMakePair(QLatin1String(RETURN_VALUE_HEURISTIC), QLatin1String("Enable heuristics to detect parent relationship on return values\n" "(USE WITH CAUTION!)")) @@ -2586,14 +2583,15 @@ Generator::OptionDescriptions ShibokenGenerator::options() const "the value of boolean casts")) << qMakePair(QLatin1String(WRAPPER_DIAGNOSTICS), QLatin1String("Generate diagnostic code around wrappers")); + return result; } -bool ShibokenGenerator::handleOption(const QString &key, const QString & /* value */) +bool ShibokenGenerator::handleOption(const QString &key, const QString &value) { + if (Generator::handleOption(key, value)) + return true; if (key == QLatin1String(PARENT_CTOR_HEURISTIC)) return (m_useCtorHeuristic = true); - if (key == QLatin1String(ENABLE_PYSIDE_EXTENSIONS)) - return (m_usePySideExtensions = true); if (key == QLatin1String(RETURN_VALUE_HEURISTIC)) return (m_userReturnValueHeuristic = true); if (key == QLatin1String(DISABLE_VERBOSE_ERROR_MESSAGES)) @@ -2695,11 +2693,6 @@ bool ShibokenGenerator::useReturnValueHeuristic() const return m_userReturnValueHeuristic; } -bool ShibokenGenerator::usePySideExtensions() const -{ - return m_usePySideExtensions; -} - bool ShibokenGenerator::useIsNullAsNbNonZero() const { return m_useIsNullAsNbNonZero; diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h index cbe796313..c776ac8c8 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h @@ -90,9 +90,6 @@ public: /// Returns a list of all ancestor classes for the given class. AbstractMetaClassList getAllAncestors(const AbstractMetaClass *metaClass) const; - /// Returns true if the user enabled PySide extensions. - bool usePySideExtensions() const; - protected: bool doSetup() override; @@ -564,7 +561,6 @@ private: bool m_useCtorHeuristic = false; bool m_userReturnValueHeuristic = false; - bool m_usePySideExtensions = false; bool m_verboseErrorMessagesDisabled = false; bool m_useIsNullAsNbNonZero = false; bool m_avoidProtectedHack = false; |