diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-13 15:33:34 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-14 12:14:22 +0200 |
commit | 84becad3db953a692eb4c1e49531b1fc5d04812f (patch) | |
tree | 01578c9679c04fdab969c1a7233bdb9c34d89f24 /sources/shiboken2/generator | |
parent | 93ae00636551b84ebda8df208f064e132f1c8b5c (diff) |
shiboken2: Some Refactorings
- AbstractMetaType: Pass TypeEntry to constructor
- AbstractMetaType: Return instantiations() by const ref
- AbstractMetaClass: Make baseTemplateInstantiations a member instead of
a global hash.
Simplify the code accordingly.
Task-number: PYSIDE-1202
Change-Id: I1a18aa4ff97481af8cb13e8732fe3952c48edb29
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/generator')
4 files changed, 12 insertions, 21 deletions
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp index c0a2af2ee..dd56ab7cd 100644 --- a/sources/shiboken2/generator/generator.cpp +++ b/sources/shiboken2/generator/generator.cpp @@ -229,7 +229,7 @@ QString Generator::getSimplifiedContainerTypeName(const AbstractMetaType *type) // Strip a "const QSharedPtr<const Foo> &" or similar to "QSharedPtr<Foo>" (PYSIDE-1016/454) const AbstractMetaType *canonicalSmartPtrInstantiation(const AbstractMetaType *type) { - AbstractMetaTypeList instantiations = type->instantiations(); + const AbstractMetaTypeList &instantiations = type->instantiations(); Q_ASSERT(instantiations.size() == 1); const bool needsFix = type->isConstant() || type->referenceType() != NoReference; const bool pointeeNeedsFix = instantiations.constFirst()->isConstant(); @@ -256,8 +256,7 @@ void Generator::addInstantiatedContainersAndSmartPointers(const AbstractMetaType { if (!type) return; - const AbstractMetaTypeList &instantiations = type->instantiations(); - for (const AbstractMetaType *t : instantiations) + for (const auto *t : type->instantiations()) addInstantiatedContainersAndSmartPointers(t, context); const auto typeEntry = type->typeEntry(); const bool isContainer = typeEntry->isContainer(); diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index ea970331e..906e82c93 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -85,10 +85,9 @@ static const char *typeNameOf(const T &t) inline AbstractMetaType *getTypeWithoutContainer(AbstractMetaType *arg) { if (arg && arg->typeEntry()->isContainer()) { - AbstractMetaTypeList lst = arg->instantiations(); // only support containers with 1 type - if (lst.size() == 1) - return lst[0]; + if (arg->instantiations().size() == 1) + return arg->instantiations().constFirst(); } return arg; } @@ -6265,7 +6264,7 @@ void CppGenerator::writeDefaultSequenceMethods(QTextStream &s, const GeneratorCo << CPP_SELF_VAR << "->begin();\n" << INDENT << "std::advance(_item, _i);\n"; - const AbstractMetaTypeList instantiations = metaClass->templateBaseClassInstantiations(); + const AbstractMetaTypeList &instantiations = metaClass->templateBaseClassInstantiations(); if (instantiations.isEmpty()) { qFatal("shiboken: %s: Internal error, no instantiations of \"%s\" were found.", __FUNCTION__, qPrintable(metaClass->qualifiedCppName())); diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.cpp b/sources/shiboken2/generator/shiboken2/overloaddata.cpp index 9f79060da..193384853 100644 --- a/sources/shiboken2/generator/shiboken2/overloaddata.cpp +++ b/sources/shiboken2/generator/shiboken2/overloaddata.cpp @@ -57,8 +57,7 @@ static QString getTypeName(const AbstractMetaType *type) QString typeName = typeEntry->name(); if (typeEntry->isContainer()) { QStringList types; - const AbstractMetaTypeList &instantiations = type->instantiations(); - for (const AbstractMetaType *cType : instantiations) { + for (const auto *cType : type->instantiations()) { const TypeEntry *typeEntry = getReferencedTypeEntry(cType->typeEntry()); types << typeEntry->name(); } @@ -147,8 +146,7 @@ static QString getImplicitConversionTypeName(const AbstractMetaType *containerTy impConv = getTypeName(function->arguments().constFirst()->type()); QStringList types; - const AbstractMetaTypeList &instantiations = containerType->instantiations(); - for (const AbstractMetaType *otherType : instantiations) + for (const auto *otherType : containerType->instantiations()) types << (otherType == instantiation ? impConv : getTypeName(otherType)); return containerType->typeEntry()->qualifiedCppName() + QLatin1Char('<') @@ -258,8 +256,7 @@ void OverloadData::sortNextOverloads() qstringIndex = sortData.lastProcessedItemId(); } - const AbstractMetaTypeList &instantiations = ov->argType()->instantiations(); - for (const AbstractMetaType *instantiation : instantiations) { + for (const auto *instantiation : ov->argType()->instantiations()) { // Add dependencies for type instantiation of container. QString typeName = getTypeName(instantiation); sortData.mapType(typeName); @@ -346,8 +343,7 @@ void OverloadData::sortNextOverloads() } // Process template instantiations - const AbstractMetaTypeList &instantiations = targetType->instantiations(); - for (const AbstractMetaType *instantiation : instantiations) { + for (const auto *instantiation : targetType->instantiations()) { if (sortData.map.contains(getTypeName(instantiation))) { int convertible = sortData.map[getTypeName(instantiation)]; diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 3cd6b8e53..4ff3e8408 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -2406,8 +2406,7 @@ AbstractMetaType *ShibokenGenerator::buildAbstractMetaTypeFromTypeEntry(const Ty typeName.remove(0, 2); if (m_metaTypeFromStringCache.contains(typeName)) return m_metaTypeFromStringCache.value(typeName); - auto *metaType = new AbstractMetaType; - metaType->setTypeEntry(typeEntry); + auto *metaType = new AbstractMetaType(typeEntry); metaType->clearIndirections(); metaType->setReferenceType(NoReference); metaType->setConstant(false); @@ -2737,8 +2736,7 @@ QString ShibokenGenerator::convertersVariableName(const QString &moduleName) con static QString processInstantiationsVariableName(const AbstractMetaType *type) { QString res = QLatin1Char('_') + _fixedCppTypeName(type->typeEntry()->qualifiedCppName()).toUpper(); - const AbstractMetaTypeList &instantiations = type->instantiations(); - for (const AbstractMetaType *instantiation : instantiations) { + for (const auto *instantiation : type->instantiations()) { res += instantiation->isContainer() ? processInstantiationsVariableName(instantiation) : QLatin1Char('_') + _fixedCppTypeName(instantiation->cppSignature()).toUpper(); @@ -2762,8 +2760,7 @@ QString ShibokenGenerator::getTypeIndexVariableName(const AbstractMetaClass *met return QString(); QString result = QLatin1String("SBK_") + _fixedCppTypeName(templateBaseClass->typeEntry()->qualifiedCppName()).toUpper(); - const AbstractMetaTypeList &templateBaseClassInstantiations = metaClass->templateBaseClassInstantiations(); - for (const AbstractMetaType *instantiation : templateBaseClassInstantiations) + for (const auto *instantiation : metaClass->templateBaseClassInstantiations()) result += processInstantiationsVariableName(instantiation); appendIndexSuffix(&result); return result; |