diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-04 14:49:23 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-05 10:39:46 +0200 |
commit | 7a3d79fb13d9f1ef31e7ee3e1e2691abf6d615e4 (patch) | |
tree | 2685d89f33b2ccb8e686393a3dae5e607ec3a7b8 /sources/shiboken6/generator/shiboken/cppgenerator.cpp | |
parent | d410d3b621a9273be7a466a7ab3eb278fc225cdf (diff) |
shiboken6: Refactor the code generating the type check
- Use pyInVariable in more places.
- Replace placeholder string formatting by concatenation/QTextStream.
- Simplify the code appending the "pyIn" variable to check function
and handle the constants true/false.
- Remove unused code path replacing "%in", which is handled
elsewhere (conversion rules).
Task-number: PYSIDE-1660
Change-Id: Ib7d3a9ca940860bf99f6731284c01e1a61df2618
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 8f86cbaff..284553901 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -1569,34 +1569,27 @@ return result;)"; const AbstractMetaClass *sourceClass = conv->ownerClass(); typeCheck = u"PyObject_TypeCheck(pyIn, "_qs + cpythonTypeNameExt(sourceClass->typeEntry()) + u')'; - toCppConv = QLatin1Char('*') + cpythonWrapperCPtr(sourceClass->typeEntry(), QLatin1String("pyIn")); + toCppConv = QLatin1Char('*') + cpythonWrapperCPtr(sourceClass->typeEntry(), + pyInVariable); } else { // Constructor that does implicit conversion. const auto &firstArg = conv->arguments().constFirst(); if (firstArg.isTypeModified() || conv->isModifiedToArray(1)) continue; const AbstractMetaType &sourceType = firstArg.type(); - typeCheck = cpythonCheckFunction(sourceType); - bool isUserPrimitiveWithoutTargetLangName = sourceType.isUserPrimitive() - && !sourceType.typeEntry()->hasTargetLangApiType(); - if (!sourceType.isWrapperType() - && !isUserPrimitiveWithoutTargetLangName - && !sourceType.typeEntry()->isEnum() - && !sourceType.typeEntry()->isFlags() - && !sourceType.typeEntry()->isContainer()) { - typeCheck += QLatin1Char('('); - } if (sourceType.isWrapperType()) { - typeCheck += QLatin1String("pyIn)"); - toCppConv = (sourceType.referenceType() == LValueReference - || !sourceType.isPointerToWrapperType()) - ? QLatin1String(" *") : QString(); - toCppConv += cpythonWrapperCPtr(sourceType.typeEntry(), QLatin1String("pyIn")); - } else if (typeCheck.contains(QLatin1String("%in"))) { - typeCheck.replace(QLatin1String("%in"), QLatin1String("pyIn")); - typeCheck.append(QLatin1Char(')')); - } else { - typeCheck += QLatin1String("pyIn)"); + if (sourceType.referenceType() == LValueReference + || !sourceType.isPointerToWrapperType()) { + toCppConv = u" *"_qs; + } + toCppConv += cpythonWrapperCPtr(sourceType.typeEntry(), pyInVariable); + } + + typeCheck = cpythonCheckFunction(sourceType); + if (typeCheck.endsWith(u", ")) { + typeCheck += pyInVariable + u')'; + } else if (typeCheck != u"true" && typeCheck != u"false") { + typeCheck += u'(' + pyInVariable + u')'; } if (sourceType.isUserPrimitive() @@ -1607,13 +1600,15 @@ return result;)"; StringStream pc(TextStream::Language::Cpp); pc << getFullTypeNameWithoutModifiers(sourceType) << " cppIn" << minimalConstructorExpression(api(), sourceType) << ";\n"; - writeToCppConversion(pc, sourceType, nullptr, QLatin1String("pyIn"), QLatin1String("cppIn")); + writeToCppConversion(pc, sourceType, nullptr, pyInVariable, + u"cppIn"_qs); pc << ';'; toCppPreConv = pc.toString(); toCppConv.append(QLatin1String("cppIn")); } else if (!sourceType.isWrapperType()) { StringStream tcc(TextStream::Language::Cpp); - writeToCppConversion(tcc, sourceType, metaClass, QLatin1String("pyIn"), QLatin1String("/*BOZO-1061*/")); + writeToCppConversion(tcc, sourceType, metaClass, pyInVariable, + u"/*BOZO-1061*/"_qs); toCppConv = tcc.toString(); } } |