diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-13 15:52:37 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-10-14 17:59:01 +0000 |
commit | 9121b09ab00ae2bcc5a40cd138eb262fbac3fa00 (patch) | |
tree | a5c7a0a28ba9ec17043485588c4d7a5829341777 /sources/shiboken6/generator/shiboken/shibokengenerator.cpp | |
parent | 706fc86ac231208894ff7e2e8b26bfe596f55a45 (diff) |
Add an option to disable implicit conversions
Add option and extract a helper to return the list of implicit
conversions depending on it.
[ChangeLog][shiboken6] An option to disable implicit conversions
has been added.
Task-number: PYSIDE-1669
Change-Id: Iaefbbf272a6c033bac10635f48057dd69fc83549
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit 78d929b957bfe200806602e1e1dfedd7e044cb20)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/shibokengenerator.cpp')
-rw-r--r-- | sources/shiboken6/generator/shiboken/shibokengenerator.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 07c41b1c5..f3e7c1f6d 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -60,6 +60,7 @@ static const char DISABLE_VERBOSE_ERROR_MESSAGES[] = "disable-verbose-error-mess static const char USE_ISNULL_AS_NB_NONZERO[] = "use-isnull-as-nb_nonzero"; static const char USE_OPERATOR_BOOL_AS_NB_NONZERO[] = "use-operator-bool-as-nb_nonzero"; static const char WRAPPER_DIAGNOSTICS[] = "wrapper-diagnostics"; +static const char NO_IMPLICIT_CONVERSIONS[] = "no-implicit-conversions"; const char *CPP_ARG = "cppArg"; const char *CPP_ARG_REMOVED = "removed_cppArg"; @@ -241,6 +242,23 @@ bool ShibokenGenerator::shouldWriteVirtualMethodNative(const AbstractMetaFunctio && !func->attributes().testFlag(AbstractMetaFunction::FinalCppMethod)); } +AbstractMetaFunctionCList ShibokenGenerator::implicitConversions(const TypeEntry *t) const +{ + if (!generateImplicitConversions()) + return {}; + auto *customConversion = t->customConversion(); + if (customConversion && customConversion->replaceOriginalTargetToNativeConversions()) + return {}; + + auto result = api().implicitConversions(t); + auto end = std::remove_if(result.begin(), result.end(), + [](const AbstractMetaFunctionCPtr &f) { + return f->isUserAdded(); + }); + result.erase(end, result.end()); + return result; +} + QString ShibokenGenerator::wrapperName(const AbstractMetaClass *metaClass) const { Q_ASSERT(shouldGenerateCppWrapper(metaClass)); @@ -2383,6 +2401,8 @@ Generator::OptionDescriptions ShibokenGenerator::options() const {QLatin1String(USE_OPERATOR_BOOL_AS_NB_NONZERO), QLatin1String("If a class has an operator bool, it will be used to compute\n" "the value of boolean casts")}, + {QLatin1String(NO_IMPLICIT_CONVERSIONS), + u"Do not generate implicit_conversions for function arguments."_qs}, {QLatin1String(WRAPPER_DIAGNOSTICS), QLatin1String("Generate diagnostic code around wrappers")} }); @@ -2405,6 +2425,10 @@ bool ShibokenGenerator::handleOption(const QString &key, const QString &value) return (m_useOperatorBoolAsNbNonZero = true); if (key == QLatin1String(AVOID_PROTECTED_HACK)) return (m_avoidProtectedHack = true); + if (key == QLatin1String(NO_IMPLICIT_CONVERSIONS)) { + return m_generateImplicitConversions = false; + return true; + } if (key == QLatin1String(WRAPPER_DIAGNOSTICS)) return (m_wrapperDiagnostics = true); return false; @@ -2515,6 +2539,11 @@ bool ShibokenGenerator::avoidProtectedHack() const return m_avoidProtectedHack; } +bool ShibokenGenerator::generateImplicitConversions() const +{ + return m_generateImplicitConversions; +} + QString ShibokenGenerator::moduleCppPrefix(const QString &moduleName) { QString result = moduleName.isEmpty() ? packageName() : moduleName; |