From 2bfd1de3495b18c0ecc251260442a9a46009861e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 20 Jul 2018 14:52:21 +0200 Subject: shiboken: Add a typedef typesystem entry The intention is be able to specify typedef std::optional OptionalInt in the typesystem file and generate code for it (without having a typedef in C++). Task-number: PYSIDE-725 Change-Id: I5847a3c3f68556ac1d0ea3635f65a29caa6cb208 Reviewed-by: Christian Tismer --- sources/shiboken2/ApiExtractor/typedatabase.cpp | 52 ++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'sources/shiboken2/ApiExtractor/typedatabase.cpp') diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp index 77b1ed23d..9639e4f67 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp @@ -307,9 +307,52 @@ bool TypeDatabase::isEnumRejected(const QString& className, const QString& enumN return findRejection(m_rejections, TypeRejection::Enum, className, enumName, reason); } -void TypeDatabase::addType(TypeEntry *e) +TypeEntry *TypeDatabase::resolveTypeDefEntry(TypedefEntry *typedefEntry, + QString *errorMessage) +{ + QString sourceName = typedefEntry->sourceType(); + const int lessThanPos = sourceName.indexOf(QLatin1Char('<')); + if (lessThanPos != -1) + sourceName.truncate(lessThanPos); + ComplexTypeEntry *source = nullptr; + for (TypeEntry *e : findTypes(sourceName)) { + switch (e->type()) { + case TypeEntry::BasicValueType: + case TypeEntry::ContainerType: + case TypeEntry::InterfaceType: + case TypeEntry::ObjectType: + case TypeEntry::SmartPointerType: + source = dynamic_cast(e); + Q_ASSERT(source); + break; + default: + break; + } + } + if (!source) { + if (errorMessage) + *errorMessage = QLatin1String("Unable to resolve typedef \"") + + typedefEntry->sourceType() + QLatin1Char('"'); + return nullptr; + } + + ComplexTypeEntry *result = static_cast(source->clone()); + result->useAsTypedef(typedefEntry); + typedefEntry->setSource(source); + typedefEntry->setTarget(result); + m_typedefEntries.insert(typedefEntry->qualifiedCppName(), typedefEntry); + return result; +} + +bool TypeDatabase::addType(TypeEntry *e, QString *errorMessage) { + if (e->type() == TypeEntry::TypedefType) { + e = resolveTypeDefEntry(static_cast(e), errorMessage); + if (Q_UNLIKELY(!e)) + return false; + } m_entries.insert(e->qualifiedCppName(), e); + return true; } bool TypeDatabase::isFunctionRejected(const QString& className, const QString& functionName, @@ -745,6 +788,13 @@ void ComplexTypeEntry::formatDebug(QDebug &d) const FORMAT_LIST_SIZE("fieldMods", m_fieldMods) } +void TypedefEntry::formatDebug(QDebug &d) const +{ + ComplexTypeEntry::formatDebug(d); + d << ", sourceType=\"" << m_sourceType << '"' + << ", source=" << m_source << ", target=" << m_target; +} + void EnumTypeEntry::formatDebug(QDebug &d) const { TypeEntry::formatDebug(d); -- cgit v1.2.3