aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/shiboken6/ApiExtractor/apiextractorresult.cpp12
-rw-r--r--sources/shiboken6/ApiExtractor/apiextractorresult.h3
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp17
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.h4
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp20
5 files changed, 34 insertions, 22 deletions
diff --git a/sources/shiboken6/ApiExtractor/apiextractorresult.cpp b/sources/shiboken6/ApiExtractor/apiextractorresult.cpp
index 2a48a30d1..b53ffa9b6 100644
--- a/sources/shiboken6/ApiExtractor/apiextractorresult.cpp
+++ b/sources/shiboken6/ApiExtractor/apiextractorresult.cpp
@@ -50,6 +50,18 @@ const InstantiatedSmartPointers &ApiExtractorResult::instantiatedSmartPointers()
return m_instantiatedSmartPointers;
}
+std::optional<InstantiatedSmartPointer>
+ ApiExtractorResult::findSmartPointerInstantiation(const SmartPointerTypeEntryCPtr &pointer,
+ const TypeEntryCPtr &pointee) const
+{
+ for (const auto &smp : m_instantiatedSmartPointers) {
+ const auto &i = smp.type;
+ if (i.typeEntry() == pointer && i.instantiations().at(0).typeEntry() == pointee)
+ return smp;
+ }
+ return std::nullopt;
+}
+
const QMultiHash<QString, QString> &ApiExtractorResult::typedefTargetToName() const
{
return m_typedefTargetToName;
diff --git a/sources/shiboken6/ApiExtractor/apiextractorresult.h b/sources/shiboken6/ApiExtractor/apiextractorresult.h
index 88a2093f1..b2aae88ed 100644
--- a/sources/shiboken6/ApiExtractor/apiextractorresult.h
+++ b/sources/shiboken6/ApiExtractor/apiextractorresult.h
@@ -43,6 +43,9 @@ public:
const AbstractMetaTypeList &instantiatedContainers() const;
const InstantiatedSmartPointers &instantiatedSmartPointers() const;
+ std::optional<InstantiatedSmartPointer>
+ findSmartPointerInstantiation(const SmartPointerTypeEntryCPtr &pointer,
+ const TypeEntryCPtr &pointee) const;
const QMultiHash<QString, QString> &typedefTargetToName() const;
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 82ab663ca..a109cd17a 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -5105,6 +5105,17 @@ QList<PyMethodDefEntry>
return result;
}
+QString CppGenerator::pythonSignature(const AbstractMetaType &type) const
+{
+ if (type.isSmartPointer() && !type.instantiations().isEmpty()) {
+ const auto ste = std::static_pointer_cast<const SmartPointerTypeEntry>(type.typeEntry());
+ const auto instantiationTe = type.instantiations().constFirst().typeEntry();
+ if (auto opt = api().findSmartPointerInstantiation(ste, instantiationTe))
+ return opt->specialized->typeEntry()->qualifiedTargetLangName();
+ }
+ return type.pythonSignature();
+}
+
// Format the type signature of a function parameter
QString CppGenerator::signatureParameter(const AbstractMetaArgument &arg) const
{
@@ -5116,7 +5127,7 @@ QString CppGenerator::signatureParameter(const AbstractMetaArgument &arg) const
metaType = *viewOn;
s << arg.name() << ':';
- QStringList signatures(metaType.pythonSignature());
+ QStringList signatures(pythonSignature(metaType));
// Implicit conversions (C++): Check for converting constructors
// "QColor(Qt::GlobalColor)" or conversion operators
@@ -5127,7 +5138,7 @@ QString CppGenerator::signatureParameter(const AbstractMetaArgument &arg) const
// PYSIDE-2712: modified types from converting constructors are not always correct
// candidates if they are modified by the type system reference
if (!f->arguments().constFirst().isTypeModified()) {
- signatures << f->arguments().constFirst().type().pythonSignature();
+ signatures << pythonSignature(f->arguments().constFirst().type());
}
} else if (f->isConversionOperator()) {
signatures << f->ownerClass()->fullName();
@@ -5188,7 +5199,7 @@ void CppGenerator::writeSignatureInfo(TextStream &s, const OverloadData &overloa
QString returnType = f->pyiTypeReplaced(0); // pyi or modified type
if (returnType.isEmpty() && !f->isVoid())
- returnType = f->type().pythonSignature();
+ returnType = pythonSignature(f->type());
if (!returnType.isEmpty())
s << "->" << returnType;
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h
index a31c2ca14..f369ab01b 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.h
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.h
@@ -413,6 +413,7 @@ private:
void writeSignatureInfo(TextStream &s, const OverloadData &overloads) const;
QString signatureParameter(const AbstractMetaArgument &arg) const;
+ QString pythonSignature(const AbstractMetaType &type) const;
/// Writes the implementation of all methods part of python sequence protocol
void writeSequenceMethods(TextStream &s,
const AbstractMetaClassCPtr &metaClass,
@@ -550,9 +551,6 @@ private:
static bool hasBoolCast(const AbstractMetaClassCPtr &metaClass)
{ return boolCast(metaClass).has_value(); }
- std::optional<AbstractMetaType>
- findSmartPointerInstantiation(const SmartPointerTypeEntryCPtr &pointer,
- const TypeEntryCPtr &pointee) const;
void clearTpFuncs();
static QString chopType(QString s);
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp b/sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp
index 1b893640a..a00c2ba50 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp
@@ -86,18 +86,6 @@ static ComparisonOperatorList smartPointeeComparisons(const GeneratorContext &co
return result;
}
-std::optional<AbstractMetaType>
- CppGenerator::findSmartPointerInstantiation(const SmartPointerTypeEntryCPtr &pointer,
- const TypeEntryCPtr &pointee) const
-{
- for (const auto &smp : api().instantiatedSmartPointers()) {
- const auto &i = smp.type;
- if (i.typeEntry() == pointer && i.instantiations().at(0).typeEntry() == pointee)
- return i;
- }
- return {};
-}
-
static bool hasParameterPredicate(const AbstractMetaFunctionCPtr &f)
{
return !f->arguments().isEmpty();
@@ -252,8 +240,8 @@ void CppGenerator::writeSmartPointerConverterFunctions(TextStream &s,
for (const auto &base : baseClasses) {
auto baseTe = base->typeEntry();
if (smartPointerTypeEntry->matchesInstantiation(baseTe)) {
- if (auto opt = findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) {
- const auto smartTargetType = opt.value();
+ if (auto opt = api().findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) {
+ const auto &smartTargetType = opt.value().type;
s << "// SmartPointer derived class: "
<< smartTargetType.cppSignature() << "\n";
writePythonToCppConversionFunctions(s, smartPointerType,
@@ -308,8 +296,8 @@ void CppGenerator::writeSmartPointerConverterInitialization(TextStream &s,
for (const auto &base : classes) {
auto baseTe = base->typeEntry();
- if (auto opt = findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) {
- const auto smartTargetType = opt.value();
+ if (auto opt = api().findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) {
+ const auto &smartTargetType = opt.value().type;
s << "// Convert to SmartPointer derived class: ["
<< smartTargetType.cppSignature() << "]\n";
const QString converter = u"Shiboken::Conversions::getConverter(\""_s