aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-11 11:43:32 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-20 12:44:39 +0200
commit2633a59741e481571c81c46e83b3eae86d2fc0f0 (patch)
tree4658d858450494717b507b49f56a0728addaac03
parentc5465d5a43e0c65828d57036c987ae380d4589b8 (diff)
shiboken6: Move the smartpointer naming helpers to the type entry
Pick-to: 6.3 Task-number: PYSIDE-454 Change-Id: Idaac93329210b893519aaf24d81e6508a6b6147c Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem.cpp31
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem.h5
-rw-r--r--sources/shiboken6/generator/generator.cpp31
-rw-r--r--sources/shiboken6/generator/generator.h3
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp4
5 files changed, 38 insertions, 36 deletions
diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp
index 8d0a73d2a..0bdaa73c0 100644
--- a/sources/shiboken6/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken6/ApiExtractor/typesystem.cpp
@@ -1834,6 +1834,37 @@ bool SmartPointerTypeEntry::matchesInstantiation(const TypeEntry *e) const
return d->m_instantiations.isEmpty() || d->m_instantiations.contains(e);
}
+static QString fixSmartPointerName(QString name)
+{
+ name.replace(u"::"_qs, u"_"_qs);
+ name.replace(u'<', u'_');
+ name.remove(u'>');
+ name.remove(u' ');
+ return name;
+}
+
+QString SmartPointerTypeEntry::getTargetFullName(const AbstractMetaType &metaType,
+ bool includePackageName)
+{
+ QString result;
+ if (includePackageName)
+ result += metaType.package() + u'.';
+ result += fixSmartPointerName(metaType.cppSignature());
+ return result;
+}
+
+QString SmartPointerTypeEntry::getTargetName(const AbstractMetaType &metaType)
+{
+ QString name = metaType.cppSignature();
+ const auto templatePos = name.indexOf(u'<');
+ if (templatePos != -1) { // "std::shared_ptr<A::B>" -> "shared_ptr<A::B>"
+ const auto colonPos = name.lastIndexOf(u"::"_qs, templatePos);
+ if (colonPos != -1)
+ name.remove(0, colonPos + 2);
+ }
+ return fixSmartPointerName(name);
+}
+
// ----------------- NamespaceTypeEntry
class NamespaceTypeEntryPrivate : public ComplexTypeEntryPrivate
{
diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h
index e06dd3fd8..922c89b5f 100644
--- a/sources/shiboken6/ApiExtractor/typesystem.h
+++ b/sources/shiboken6/ApiExtractor/typesystem.h
@@ -36,6 +36,7 @@
#include <QtCore/QStringList>
#include <QtCore/QScopedPointer>
+class AbstractMetaType;
class CustomFunction;
class CustomConversion;
class EnumValueTypeEntry;
@@ -735,6 +736,10 @@ public:
void setInstantiations(const Instantiations &i);
bool matchesInstantiation(const TypeEntry *e) const;
+ static QString getTargetFullName(const AbstractMetaType &metaType,
+ bool includePackageName = true);
+ static QString getTargetName(const AbstractMetaType &metaType);
+
#ifndef QT_NO_DEBUG_STREAM
void formatDebug(QDebug &d) const override;
#endif
diff --git a/sources/shiboken6/generator/generator.cpp b/sources/shiboken6/generator/generator.cpp
index 8d1d4b597..a5c936b1b 100644
--- a/sources/shiboken6/generator/generator.cpp
+++ b/sources/shiboken6/generator/generator.cpp
@@ -794,37 +794,6 @@ QString getClassTargetFullName(const AbstractMetaEnum &metaEnum, bool includePac
return getClassTargetFullName_(&metaEnum, includePackageName);
}
-static QString fixSmartPointerName(QString name)
-{
- name.replace(u"::"_qs, u"_"_qs);
- name.replace(u'<', u'_');
- name.remove(u'>');
- name.remove(u' ');
- return name;
-}
-
-QString getSmartpointerTargetFullName(const AbstractMetaType &metaType,
- bool includePackageName)
-{
- QString result;
- if (includePackageName)
- result += metaType.package() + u'.';
- result += fixSmartPointerName(metaType.cppSignature());
- return result;
-}
-
-QString getSmartpointerTargetName(const AbstractMetaType &metaType)
-{
- QString name = metaType.cppSignature();
- const auto templatePos = name.indexOf(u'<');
- if (templatePos != -1) { // "std::shared_ptr<A::B>" -> "shared_ptr<A::B>"
- const auto colonPos = name.lastIndexOf(u"::"_qs, templatePos);
- if (colonPos != -1)
- name.remove(0, colonPos + 2);
- }
- return fixSmartPointerName(name);
-}
-
QString getFilteredCppSignatureString(QString signature)
{
signature.replace(QLatin1String("::"), QLatin1String("_"));
diff --git a/sources/shiboken6/generator/generator.h b/sources/shiboken6/generator/generator.h
index b33a5443c..82b08ee8e 100644
--- a/sources/shiboken6/generator/generator.h
+++ b/sources/shiboken6/generator/generator.h
@@ -59,9 +59,6 @@ class ContainerTypeEntry;
QString getClassTargetFullName(const AbstractMetaClass *metaClass, bool includePackageName = true);
QString getClassTargetFullName(const AbstractMetaEnum &metaEnum, bool includePackageName = true);
-QString getSmartpointerTargetFullName(const AbstractMetaType &metaType,
- bool includePackageName = true);
-QString getSmartpointerTargetName(const AbstractMetaType &metaType);
QString getFilteredCppSignatureString(QString signature);
/**
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 7397648de..c05ba979a 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -4540,7 +4540,7 @@ void CppGenerator::writeClassDefinition(TextStream &s,
if (!classContext.forSmartPointer())
computedClassTargetFullName = getClassTargetFullName(metaClass);
else
- computedClassTargetFullName = getSmartpointerTargetFullName(classContext.preciseType());
+ computedClassTargetFullName = SmartPointerTypeEntry::getTargetFullName(classContext.preciseType());
const QString typePtr = QLatin1String("_") + className
+ QLatin1String("_Type");
@@ -5822,7 +5822,7 @@ void CppGenerator::writeClassRegister(TextStream &s,
if (!classContext.forSmartPointer())
typeName = metaClass->name();
else
- typeName = getSmartpointerTargetName(classContext.preciseType());
+ typeName = SmartPointerTypeEntry::getTargetName(classContext.preciseType());
// 2:typeName
s << "\"" << typeName << "\",\n";