diff options
-rw-r--r-- | sources/shiboken6/ApiExtractor/typedatabase.cpp | 31 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/typedatabase.h | 5 | ||||
-rw-r--r-- | sources/shiboken6/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<CustomTypeEntry *>(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 <class Predicate> 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 @@ <suppress-warning text="Duplicate type entry: 'sample'" /> <suppress-warning text="Duplicate type entry: 'SampleNamespace'" /> - <primitive-type name="std::string"/> - <primitive-type name="std::string_view" view-on="std::string"/> - <primitive-type name="std::wstring"/> <primitive-type name="ObjectType::Identifier"/> <primitive-type name="Foo::HANDLE" target-lang-api-name="PyLong"/> |