diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-30 11:35:15 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-01 15:50:55 +0200 |
commit | 0428e33307955408187bb33cda1a2c7815f5b0b9 (patch) | |
tree | b69ffd928467fef974476a22dde6b179520a3889 | |
parent | 8772e79ce30414a4a67d8c11316db212fa0a61a6 (diff) |
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 <tismer@stackless.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-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"/> |