diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-04-07 15:53:02 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-04-09 09:46:17 +0200 |
commit | 36e32cb9a0e2d204e62d67241a6db0c0ccdf7841 (patch) | |
tree | e336a5ba89b8bdae549b09b3916379e3424b4adf | |
parent | 8973104f1f758d47f7b9cec2609327878dcf7dde (diff) |
shiboken6: Remove namespace from smart pointer names
Rename the functions for clarity and remove the namespace
("std.shared_ptr_Integer" instead of "std.std_shared_ptr_Integer").
Task-number: PYSIDE-454
Change-Id: I3274630aa9c1b10258d34b75fc6b7bec6f45c519
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | sources/shiboken6/generator/generator.cpp | 35 | ||||
-rw-r--r-- | sources/shiboken6/generator/generator.h | 4 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 4 |
3 files changed, 31 insertions, 12 deletions
diff --git a/sources/shiboken6/generator/generator.cpp b/sources/shiboken6/generator/generator.cpp index e02a73a18..49843ede4 100644 --- a/sources/shiboken6/generator/generator.cpp +++ b/sources/shiboken6/generator/generator.cpp @@ -973,18 +973,35 @@ QString getClassTargetFullName(const AbstractMetaEnum &metaEnum, bool includePac return getClassTargetFullName_(&metaEnum, includePackageName); } -QString getClassTargetFullName(const AbstractMetaType &metaType, bool 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(); - name.replace(QLatin1String("::"), QLatin1String("_")); - name.replace(QLatin1Char('<'), QLatin1Char('_')); - name.remove(QLatin1Char('>')); - name.remove(QLatin1Char(' ')); - if (includePackageName) { - name.prepend(QLatin1Char('.')); - name.prepend(metaType.package()); + 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 name; + return fixSmartPointerName(name); } QString getFilteredCppSignatureString(QString signature) diff --git a/sources/shiboken6/generator/generator.h b/sources/shiboken6/generator/generator.h index 02f48c74f..1871e5091 100644 --- a/sources/shiboken6/generator/generator.h +++ b/sources/shiboken6/generator/generator.h @@ -59,7 +59,9 @@ class ContainerTypeEntry; QString getClassTargetFullName(const AbstractMetaClass *metaClass, bool includePackageName = true); QString getClassTargetFullName(const AbstractMetaEnum &metaEnum, bool includePackageName = true); -QString getClassTargetFullName(const AbstractMetaType &metaType, 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 1c7f64848..930d5404a 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -4539,7 +4539,7 @@ void CppGenerator::writeClassDefinition(TextStream &s, if (!classContext.forSmartPointer()) computedClassTargetFullName = getClassTargetFullName(metaClass); else - computedClassTargetFullName = getClassTargetFullName(classContext.preciseType()); + computedClassTargetFullName = getSmartpointerTargetFullName(classContext.preciseType()); const QString typePtr = QLatin1String("_") + className + QLatin1String("_Type"); @@ -5821,7 +5821,7 @@ void CppGenerator::writeClassRegister(TextStream &s, if (!classContext.forSmartPointer()) typeName = metaClass->name(); else - typeName = getClassTargetFullName(classContext.preciseType(), false); + typeName = getSmartpointerTargetName(classContext.preciseType()); // 2:typeName s << "\"" << typeName << "\",\n"; |