aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-16 12:58:33 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-16 12:58:33 +0200
commit4c93e4299eb210e98adc02d1e02c134e29464537 (patch)
treef4ad07fd55ab01605718cee83cb9c16898ec1c42 /sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
parentb3491d9aef009a7ee6d796c1217c155618d348e6 (diff)
parentd1306c1efa629842eda2666307375d4d3951c6dc (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp82
1 files changed, 65 insertions, 17 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index af10f1831..c8b9c173b 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -514,6 +514,8 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom)
for (AbstractMetaClass *cls : qAsConst(m_metaClasses)) {
if (!cls->isNamespace()) {
setupInheritance(cls);
+ if (cls->templateBaseClass())
+ inheritTemplateFunctions(cls);
if (!cls->hasVirtualDestructor() && cls->baseClass()
&& cls->baseClass()->hasVirtualDestructor())
cls->setHasVirtualDestructor(true);
@@ -671,6 +673,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom)
}
m_itemToClass.clear();
+ m_typeSystemTypeDefs.clear();
ReportHandler::endProgress();
}
@@ -991,6 +994,23 @@ void AbstractMetaBuilderPrivate::traverseTypesystemTypedefs()
*metaClass += AbstractMetaAttributes::Public;
fillAddedFunctions(metaClass);
addAbstractMetaClass(metaClass, nullptr);
+ // Ensure base classes are set up when traversing functions for the
+ // type to be resolved.
+ if (setupInheritance(metaClass)) {
+ // Create an entry to look up up types obtained from parsing
+ // functions in reverse. As opposed to container specializations,
+ // which are generated into every instantiating module (indicated
+ // by ContainerTypeEntry::targetLangPackage() being empty), the
+ // correct index array of the module needs to be found by reverse
+ // mapping the instantiations to the typedef entry.
+ // Synthesize a AbstractMetaType which would be found by an
+ // instantiation.
+ auto sourceType = new AbstractMetaType;
+ sourceType->setTypeEntry(metaClass->templateBaseClass()->typeEntry());
+ sourceType->setInstantiations(metaClass->templateBaseClassInstantiations());
+ sourceType->decideUsagePattern();
+ m_typeSystemTypeDefs.append({AbstractMetaTypeCPtr(sourceType), metaClass});
+ }
}
}
@@ -2098,6 +2118,20 @@ TypeEntries AbstractMetaBuilderPrivate::findTypeEntries(const QString &qualified
return {};
}
+// Reverse lookup of AbstractMetaType representing a template specialization
+// found during traversing function arguments to its type system typedef'ed
+// class.
+const AbstractMetaClass *AbstractMetaBuilderPrivate::resolveTypeSystemTypeDef(const AbstractMetaType *t) const
+{
+ if (t->hasInstantiations()) {
+ auto pred = [t](const TypeClassEntry &e) { return e.type->compare(*t); };
+ auto it = std::find_if(m_typeSystemTypeDefs.cbegin(), m_typeSystemTypeDefs.cend(), pred);
+ if (it != m_typeSystemTypeDefs.cend())
+ return it->klass;
+ }
+ return nullptr;
+}
+
AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typei,
AbstractMetaClass *currentClass,
TranslateTypeFlags flags,
@@ -2333,6 +2367,15 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
// AbstractMetaType::cppSignature().
metaType->decideUsagePattern();
+ if (d) {
+ // Reverse lookup of type system typedefs. Replace by class.
+ if (auto klass = d->resolveTypeSystemTypeDef(metaType.data())) {
+ metaType.reset(new AbstractMetaType);
+ metaType->setTypeEntry(klass->typeEntry());
+ metaType->decideUsagePattern();
+ }
+ }
+
return metaType.take();
}
@@ -2624,17 +2667,6 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass,
{
QVector<TypeInfo> targs = info.instantiations();
AbstractMetaTypeList templateTypes;
- QString errorMessage;
-
- if (subclass->isTypeDef()) {
- subclass->setHasCloneOperator(templateClass->hasCloneOperator());
- subclass->setHasEqualsOperator(templateClass->hasEqualsOperator());
- subclass->setHasHashFunction(templateClass->hasHashFunction());
- subclass->setHasNonPrivateConstructor(templateClass->hasNonPrivateConstructor());
- subclass->setHasPrivateDestructor(templateClass->hasPrivateDestructor());
- subclass->setHasProtectedDestructor(templateClass->hasProtectedDestructor());
- subclass->setHasVirtualDestructor(templateClass->hasVirtualDestructor());
- }
for (const TypeInfo &i : qAsConst(targs)) {
QString typeName = i.qualifiedName().join(colonColon());
@@ -2679,6 +2711,28 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass,
}
}
+ subclass->setTemplateBaseClass(templateClass);
+ subclass->setTemplateBaseClassInstantiations(templateTypes);
+ subclass->setBaseClass(templateClass->baseClass());
+ return true;
+}
+
+void AbstractMetaBuilderPrivate::inheritTemplateFunctions(AbstractMetaClass *subclass)
+{
+ QString errorMessage;
+ auto templateClass = subclass->templateBaseClass();
+
+ if (subclass->isTypeDef()) {
+ subclass->setHasCloneOperator(templateClass->hasCloneOperator());
+ subclass->setHasEqualsOperator(templateClass->hasEqualsOperator());
+ subclass->setHasHashFunction(templateClass->hasHashFunction());
+ subclass->setHasNonPrivateConstructor(templateClass->hasNonPrivateConstructor());
+ subclass->setHasPrivateDestructor(templateClass->hasPrivateDestructor());
+ subclass->setHasProtectedDestructor(templateClass->hasProtectedDestructor());
+ subclass->setHasVirtualDestructor(templateClass->hasVirtualDestructor());
+ }
+
+ const auto &templateTypes = subclass->templateBaseClassInstantiations();
const AbstractMetaFunctionList &subclassFuncs = subclass->functions();
const AbstractMetaFunctionList &templateClassFunctions = templateClass->functions();
for (const AbstractMetaFunction *function : templateClassFunctions) {
@@ -2781,12 +2835,6 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass,
f->replaceType(fieldType);
subclass->addField(f.take());
}
-
- subclass->setTemplateBaseClass(templateClass);
- subclass->setTemplateBaseClassInstantiations(templateTypes);
- subclass->setBaseClass(templateClass->baseClass());
-
- return true;
}
void AbstractMetaBuilderPrivate::parseQ_Properties(AbstractMetaClass *metaClass,