From 0428e33307955408187bb33cda1a2c7815f5b0b9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 30 Sep 2021 11:35:15 +0200 Subject: shiboken6: Add std::string types as builtin Add std::(w)string and their views. Task-number: PYSIDE-1660 Change-Id: I4201f0561ead327ab310a22fb1dcfe59e4adb86a Reviewed-by: Christian Tismer Reviewed-by: Qt CI Bot --- sources/shiboken6/ApiExtractor/typedatabase.cpp | 31 ++++++++++++++++++++++ sources/shiboken6/ApiExtractor/typedatabase.h | 5 ++++ .../tests/samplebinding/typesystem_sample.xml | 3 --- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/sources/shiboken6/ApiExtractor/typedatabase.cpp b/sources/shiboken6/ApiExtractor/typedatabase.cpp index ac76aeda4..427b923d1 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken6/ApiExtractor/typedatabase.cpp @@ -1004,6 +1004,20 @@ PrimitiveTypeEntry * return result; } +void TypeDatabase::addBuiltInCppStringPrimitiveType(const QString &name, + const QString &viewName, + const TypeSystemTypeEntry *root, + const QString &rootPackage, + CustomTypeEntry *targetLang) + +{ + auto *stringType = addBuiltInPrimitiveType(name, root, rootPackage, + targetLang); + auto *viewType = addBuiltInPrimitiveType(viewName, root, rootPackage, + nullptr); + viewType->setViewOn(stringType); +} + void TypeDatabase::addBuiltInPrimitiveTypes() { auto *root = defaultTypeSystemType(); @@ -1038,6 +1052,23 @@ void TypeDatabase::addBuiltInPrimitiveTypes() if (!m_entries.contains(t)) addBuiltInPrimitiveType(t, root, rootPackage, pyFloatCustomEntry); } + + auto *pyUnicodeEntry = findType(u"PyUnicode"_qs); + Q_ASSERT(pyUnicodeEntry && pyUnicodeEntry->isCustom()); + auto *pyUnicodeCustomEntry = static_cast(pyUnicodeEntry); + + const QString stdString = u"std::string"_qs; + if (!m_entries.contains(stdString)) { + addBuiltInCppStringPrimitiveType(stdString, u"std::string_view"_qs, + root, rootPackage, + pyUnicodeCustomEntry); + } + const QString stdWString = u"std::wstring"_qs; + if (!m_entries.contains(stdWString)) { + addBuiltInCppStringPrimitiveType(stdWString, u"std::wstring_view"_qs, + root, rootPackage, + pyUnicodeCustomEntry); + } } QDebug operator<<(QDebug d, const TypeDatabase &db) diff --git a/sources/shiboken6/ApiExtractor/typedatabase.h b/sources/shiboken6/ApiExtractor/typedatabase.h index f90a178d0..aaf174081 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.h +++ b/sources/shiboken6/ApiExtractor/typedatabase.h @@ -218,6 +218,11 @@ private: const TypeSystemTypeEntry *root, const QString &rootPackage, CustomTypeEntry *targetLang); + void addBuiltInCppStringPrimitiveType(const QString &name, + const QString &viewName, + const TypeSystemTypeEntry *root, + const QString &rootPackage, + CustomTypeEntry *targetLang); void addBuiltInPrimitiveTypes(); TypeEntryMultiMapConstIteratorRange findTypeRange(const QString &name) const; template diff --git a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml index 839333374..aa3c60975 100644 --- a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml @@ -3,9 +3,6 @@ - - - -- cgit v1.2.3