diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-16 15:54:15 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-30 07:37:06 +0200 |
| commit | 7f2874cf7e9c955a009d06da0b4c848c6a404215 (patch) | |
| tree | a26e930cd293b812243adcfe385fc96bbfdeab6d | |
| parent | 2e291350fd6294912bf29680a76819400ad693b7 (diff) | |
shiboken6: Remove ShibokenGenerator::guessCPythonCheckFunction()
Since all CPython types are now built-in custom types, there is no
longer a need to guess the check functions.
Custom types passed to writeTypeCheck should be valid
AbstractMetaTypes; throw an exception if this fails.
Define a check function for Qml's VolatileBool where it was relying on
heuristics.
Task-number: PYSIDE-1660
Change-Id: I9641c63ae2942db86dbf84488429b7e25f0491a0
Reviewed-by: Christian Tismer <tismer@stackless.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
6 files changed, 22 insertions, 85 deletions
diff --git a/sources/pyside6/PySide6/QtQml/typesystem_qml.xml b/sources/pyside6/PySide6/QtQml/typesystem_qml.xml index 9a60eb84b..58e5d3a60 100644 --- a/sources/pyside6/PySide6/QtQml/typesystem_qml.xml +++ b/sources/pyside6/PySide6/QtQml/typesystem_qml.xml @@ -60,7 +60,7 @@ </inject-code> <!-- This is to inform the generator that the VolatileBool python type exists --> - <custom-type name="VolatileBool"/> + <custom-type name="VolatileBool" check-function="VolatileBool_Check"/> <primitive-type name="bool volatile" target-lang-api-name="VolatileBool"> <!-- No conversion rules are specified here, because the generator does not handle pointer to primitive types without function adjustment. diff --git a/sources/shiboken6/ApiExtractor/messages.cpp b/sources/shiboken6/ApiExtractor/messages.cpp index 00d9dd816..ff4a9fa42 100644 --- a/sources/shiboken6/ApiExtractor/messages.cpp +++ b/sources/shiboken6/ApiExtractor/messages.cpp @@ -832,3 +832,9 @@ QString msgInvalidTargetLanguageApiName(const QString &name) return u"Invalid target language API name \""_qs + name + u"\"."_qs; } + +QString msgUnknownCheckFunction(const TypeEntry *t) +{ + return u"Unknown check function for type: '"_qs + + t->qualifiedCppName() + u"'."_qs; +} diff --git a/sources/shiboken6/ApiExtractor/messages.h b/sources/shiboken6/ApiExtractor/messages.h index 7e6fd87a5..fb4b28e26 100644 --- a/sources/shiboken6/ApiExtractor/messages.h +++ b/sources/shiboken6/ApiExtractor/messages.h @@ -239,4 +239,6 @@ QString msgDuplicateBuiltInTypeEntry(const QString &name); QString msgDuplicateTypeEntry(const QString &name); QString msgInvalidTargetLanguageApiName(const QString &name); +QString msgUnknownCheckFunction(const TypeEntry *t); + #endif // MESSAGES_H diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 412546767..1eff93016 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -2387,27 +2387,20 @@ void CppGenerator::writeTypeCheck(TextStream &s, AbstractMetaType argType, const QString &argumentName, bool isNumber, const QString &customType, bool rejectNull) const { - QString customCheck; if (!customType.isEmpty()) { - AbstractMetaType metaType; - // PYSIDE-795: Note: XML-Overrides are handled in this shibokengenerator function! - // This enables iterables for QMatrix4x4 for instance. - auto customCheckResult = guessCPythonCheckFunction(customType); - customCheck = customCheckResult.checkFunction; - if (customCheckResult.type.has_value()) - argType = customCheckResult.type.value(); + QString errorMessage; + const auto metaTypeOpt = AbstractMetaType::fromString(customType, &errorMessage); + if (!metaTypeOpt.has_value()) + throw Exception(errorMessage); + argType = metaTypeOpt.value(); } // TODO-CONVERTER: merge this with the code below. - QString typeCheck; - if (customCheck.isEmpty()) - typeCheck = cpythonIsConvertibleFunction(argType); - else - typeCheck = customCheck; + QString typeCheck = cpythonIsConvertibleFunction(argType); typeCheck.append(u'(' +argumentName + u')'); // TODO-CONVERTER ----------------------------------------------------------------------- - if (customCheck.isEmpty() && !argType.typeEntry()->isCustom()) { + if (!argType.typeEntry()->isCustom()) { typeCheck = u'(' + pythonToCppConverterForArgumentName(argumentName) + u" = "_qs + typeCheck + u"))"_qs; if (!isNumber && argType.typeEntry()->isCppPrimitive()) { diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 99e90c1ef..c05ee2e25 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -1009,11 +1009,7 @@ QString ShibokenGenerator::cpythonCheckFunction(AbstractMetaType metaType) const const auto *cte = static_cast<const CustomTypeEntry *>(typeEntry); if (cte->hasCheckFunction()) return cte->checkFunction(); - auto customCheckResult = guessCPythonCheckFunction(typeEntry->name()); - if (!customCheckResult.checkFunction.isEmpty()) - return customCheckResult.checkFunction; - if (customCheckResult.type.has_value()) - metaType = customCheckResult.type.value(); + throw Exception(msgUnknownCheckFunction(typeEntry)); } if (metaType.isExtendedCppPrimitive()) { @@ -1077,10 +1073,7 @@ QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry *type) const const auto *cte = static_cast<const CustomTypeEntry *>(type); if (cte->hasCheckFunction()) return cte->checkFunction(); - auto customCheckResult = guessCPythonCheckFunction(type->name()); - if (customCheckResult.type.has_value()) - return cpythonCheckFunction(customCheckResult.type.value()); - return customCheckResult.checkFunction; + throw Exception(msgUnknownCheckFunction(type)); } if (type->isEnum() || type->isFlags() || type->isWrapperType()) @@ -1103,44 +1096,6 @@ QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry *type) const return cpythonIsConvertibleFunction(type); } -ShibokenGenerator::CPythonCheckFunctionResult - ShibokenGenerator::guessCPythonCheckFunction(const QString &type) -{ - // PYSIDE-795: We abuse PySequence for iterables. - // This part handles the overrides in the XML files. - if (type == cPySequenceT()) - return {QLatin1String("Shiboken::String::checkIterable"), {}}; - - if (type == cPyTypeObjectT()) - return {QLatin1String("PyType_Check"), {}}; - - if (type == cPyBufferT()) - return {QLatin1String("Shiboken::Buffer::checkType"), {}}; - - if (type == pyStrT()) - return {QLatin1String("Shiboken::String::check"), {}}; - - if (type == cPyArrayObjectT()) - return {QLatin1String("PyArray_Check"), {}}; - - // PYSIDE-1499: We replace some strings by path objects. - if (type == pyPathLikeT()) - return {QLatin1String("Shiboken::String::checkPath"), {}}; - - CPythonCheckFunctionResult result; - result.type = AbstractMetaType::fromString(type); - - if (!result.type.has_value()) { - result.checkFunction = type + QLatin1String("_Check"); - } else if (result.type->typeEntry()->isCustom()) { - auto ct = static_cast<const CustomTypeEntry *>(result.type->typeEntry()); - result.checkFunction = ct->checkFunction(); - if (result.checkFunction.isEmpty()) - result.checkFunction = type + QLatin1String("_Check"); - } - return result; -} - QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry *type) { if (type->isWrapperType()) { @@ -1162,15 +1117,12 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry *type) } QString ShibokenGenerator::cpythonIsConvertibleFunction(AbstractMetaType metaType) const { - if (metaType.typeEntry()->isCustom()) { - const auto *cte = static_cast<const CustomTypeEntry *>(metaType.typeEntry()); + const auto *typeEntry = metaType.typeEntry(); + if (typeEntry->isCustom()) { + const auto *cte = static_cast<const CustomTypeEntry *>(typeEntry); if (cte->hasCheckFunction()) return cte->checkFunction(); - auto customCheckResult = guessCPythonCheckFunction(metaType.typeEntry()->name()); - if (!customCheckResult.checkFunction.isEmpty()) - return customCheckResult.checkFunction; - if (customCheckResult.type.has_value()) - metaType = customCheckResult.type.value(); + throw Exception(msgUnknownCheckFunction(typeEntry)); } QString result = QLatin1String("Shiboken::Conversions::"); diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h index 454083768..e89316cd0 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.h +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h @@ -238,22 +238,6 @@ protected: static QString cpythonTypeNameExt(const AbstractMetaType &type) ; QString cpythonCheckFunction(const TypeEntry *type) const; QString cpythonCheckFunction(AbstractMetaType metaType) const; - /** - * Receives the argument \p type and tries to find the appropriate AbstractMetaType for it - * or a custom type check. - * \param type A string representing the type to be discovered. - * \param metaType A pointer to an AbstractMetaType pointer, to where write a new meta type object - * if one is produced from the \p type string. This object must be deallocated by - * the caller. It will set the target variable to nullptr, is \p type is a Python type. - * \return A custom check if \p type is a custom type, or an empty string if \p metaType - * receives an existing type object. - */ - struct CPythonCheckFunctionResult - { - QString checkFunction; - std::optional<AbstractMetaType> type; - }; - static CPythonCheckFunctionResult guessCPythonCheckFunction(const QString &type); static QString cpythonIsConvertibleFunction(const TypeEntry *type); QString cpythonIsConvertibleFunction(AbstractMetaType metaType) const; QString cpythonIsConvertibleFunction(const AbstractMetaArgument &metaArg) const; |
