aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-06-29 12:55:18 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-06-29 18:30:53 +0200
commit4d6f32a6a4033b5986e7d19185bbc6bfb941d218 (patch)
tree20b3e61750a072ac0ea86d28a88ad9e30952a3f9 /sources/shiboken6
parent47044bdd9da774b69cec36e007066f44ca7b3797 (diff)
shiboken6: Introduce a convenience function for argument conversion rules
This simplifies the code. Task-number: PYSIDE-454 Change-Id: I725d407508315eca20ff93383d0f689d512a20d5 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetafunction.cpp5
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetafunction.h1
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp24
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp6
4 files changed, 20 insertions, 16 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp
index 0d51893c1..0ce2d0260 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp
+++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp
@@ -612,6 +612,11 @@ QString AbstractMetaFunction::conversionRule(TypeSystem::Language language, int
return QString();
}
+bool AbstractMetaFunction::hasConversionRule(TypeSystem::Language language, int idx) const
+{
+ return !conversionRule(language, idx).isEmpty();
+}
+
// FIXME If we remove a arg. in the method at the base class, it will not reflect here.
bool AbstractMetaFunction::argumentRemoved(int key) const
{
diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.h b/sources/shiboken6/ApiExtractor/abstractmetafunction.h
index 052528c64..4c0815540 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetafunction.h
+++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.h
@@ -309,6 +309,7 @@ public:
AbstractMetaFunction *copy() const;
QString conversionRule(TypeSystem::Language language, int idx) const;
+ bool hasConversionRule(TypeSystem::Language language, int idx) const;
QList<ReferenceCount> referenceCounts(const AbstractMetaClass *cls, int idx = -2) const;
ArgumentOwner argumentOwner(const AbstractMetaClass *cls, int idx) const;
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index ff541bb44..c2e6a140e 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -1170,9 +1170,8 @@ void CppGenerator::writeVirtualMethodNativeArgs(TextStream &s,
convert = !formatUnits().contains(pte->name());
}
StringStream ac(TextStream::Language::Cpp);
- if (!func->conversionRule(TypeSystem::TargetLangCode,
- arg.argumentIndex() + 1).isEmpty()) {
- // Has conversion rule.
+ if (func->hasConversionRule(TypeSystem::TargetLangCode,
+ arg.argumentIndex() + 1)) {
ac << arg.name() + CONV_RULE_OUT_VAR_SUFFIX;
} else {
QString argName = arg.name();
@@ -1387,8 +1386,7 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s,
}
}
- if (!func->conversionRule(TypeSystem::NativeCode, 0).isEmpty()) {
- // Has conversion rule.
+ if (func->hasConversionRule(TypeSystem::NativeCode, 0)) {
writeConversionRule(s, func, TypeSystem::NativeCode, CPP_RETURN_VAR);
} else if (!func->injectedCodeHasReturnValueAttribution(TypeSystem::NativeCode)) {
returnIndirections = writePythonToCppTypeConversion(
@@ -2621,7 +2619,7 @@ static void checkTypeViability(const AbstractMetaFunctionCPtr &func,
|| type.isCString()
|| isRemoved
|| modified
- || !func->conversionRule(TypeSystem::All, argIdx).isEmpty()
+ || func->hasConversionRule(TypeSystem::All, argIdx)
|| func->hasInjectedCode())
return;
QString message;
@@ -3200,8 +3198,8 @@ void CppGenerator::writeSingleFunctionCall(TextStream &s,
bool mayHaveUnunsedArguments = !func->isUserAdded() && func->hasInjectedCode() && injectCodeCallsFunc;
int removedArgs = 0;
for (qsizetype argIdx = 0; argIdx < func->arguments().size(); ++argIdx) {
- bool hasConversionRule =
- !func->conversionRule(TypeSystem::NativeCode, int(argIdx + 1)).isEmpty();
+ const bool hasConversionRule =
+ func->hasConversionRule(TypeSystem::NativeCode, int(argIdx + 1));
const AbstractMetaArgument &arg = func->arguments().at(argIdx);
if (arg.isModifiedRemoved()) {
if (!arg.defaultValueExpression().isEmpty()) {
@@ -3741,8 +3739,8 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr
int removedArgs = 0;
for (int i = 0; i < maxArgs + removedArgs; i++) {
const AbstractMetaArgument &arg = func->arguments().at(i);
- bool hasConversionRule = !func->conversionRule(TypeSystem::NativeCode,
- arg.argumentIndex() + 1).isEmpty();
+ const bool hasConversionRule =
+ func->hasConversionRule(TypeSystem::NativeCode, arg.argumentIndex() + 1);
if (arg.isModifiedRemoved()) {
// If some argument with default value is removed from a
// method signature, the said value must be explicitly
@@ -3779,8 +3777,8 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr
for (int i = func->arguments().size() - 1; i >= maxArgs + removedArgs; i--) {
const AbstractMetaArgument &arg = func->arguments().at(i);
const bool defValModified = arg.hasModifiedDefaultValueExpression();
- bool hasConversionRule = !func->conversionRule(TypeSystem::NativeCode,
- arg.argumentIndex() + 1).isEmpty();
+ const bool hasConversionRule =
+ func->hasConversionRule(TypeSystem::NativeCode, arg.argumentIndex() + 1);
if (argsClear && !defValModified && !hasConversionRule)
continue;
argsClear = false;
@@ -4002,7 +4000,7 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr
// Convert result
const auto funcType = func->type();
- if (!func->conversionRule(TypeSystem::TargetLangCode, 0).isEmpty()) {
+ if (func->hasConversionRule(TypeSystem::TargetLangCode, 0)) {
writeConversionRule(s, func, TypeSystem::TargetLangCode,
PYTHON_RETURN_VAR);
} else if (!isCtor && !func->isInplaceOperator() && !func->isVoid()
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
index 479156ff8..e583ed4b3 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
@@ -1168,8 +1168,8 @@ void ShibokenGenerator::writeArgumentNames(TextStream &s,
s << ((argCount > 0) ? ", " : "") << argument.name();
if (((options & Generator::VirtualCall) == 0)
- && (!func->conversionRule(TypeSystem::NativeCode, index).isEmpty()
- || !func->conversionRule(TypeSystem::TargetLangCode, index).isEmpty())
+ && (func->hasConversionRule(TypeSystem::NativeCode, index)
+ || func->hasConversionRule(TypeSystem::TargetLangCode, index))
&& !func->isConstructor()) {
s << CONV_RULE_OUT_VAR_SUFFIX;
}
@@ -1310,7 +1310,7 @@ ShibokenGenerator::ArgumentVarReplacementList
const AbstractMetaArgument &arg = func->arguments().at(i);
QString argValue;
if (language == TypeSystem::TargetLangCode) {
- bool hasConversionRule = !func->conversionRule(convLang, i+1).isEmpty();
+ const bool hasConversionRule = func->hasConversionRule(convLang, i + 1);
const bool argRemoved = arg.isModifiedRemoved();
if (argRemoved)
++removed;