aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-13 15:33:34 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-14 12:14:22 +0200
commit84becad3db953a692eb4c1e49531b1fc5d04812f (patch)
tree01578c9679c04fdab969c1a7233bdb9c34d89f24 /sources/shiboken2/ApiExtractor
parent93ae00636551b84ebda8df208f064e132f1c8b5c (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/ApiExtractor')
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp12
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetalang.cpp41
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetalang.h13
3 files changed, 25 insertions, 41 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index b06376866..a2e2841df 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -1258,9 +1258,7 @@ void AbstractMetaBuilderPrivate::fixReturnTypeOfConversionOperator(AbstractMetaF
if (!retType)
return;
- auto *metaType = new AbstractMetaType;
- metaType->setTypeEntry(retType);
- metaFunction->replaceType(metaType);
+ metaFunction->replaceType(new AbstractMetaType(retType));
}
AbstractMetaFunctionList AbstractMetaBuilderPrivate::classFunctionList(const ScopeModelItem &scopeItem,
@@ -2010,8 +2008,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction:
}
// These are only implicit and should not appear in code...
- auto *metaType = new AbstractMetaType;
- metaType->setTypeEntry(type);
+ auto *metaType = new AbstractMetaType(type);
metaType->setIndirections(typeInfo.indirections);
if (typeInfo.isReference)
metaType->setReferenceType(LValueReference);
@@ -2611,7 +2608,7 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass,
const TypeInfo &info)
{
QVector<TypeInfo> targs = info.instantiations();
- QVector<AbstractMetaType *> templateTypes;
+ AbstractMetaTypeList templateTypes;
QString errorMessage;
if (subclass->isTypeDef()) {
@@ -2654,8 +2651,7 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass,
}
if (t) {
- auto *temporaryType = new AbstractMetaType;
- temporaryType->setTypeEntry(t);
+ auto *temporaryType = new AbstractMetaType(t);
temporaryType->setConstant(i.isConstant());
temporaryType->setReferenceType(i.referenceType());
temporaryType->setIndirectionsV(i.indirectionsV());
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp
index 9c54cc0d4..458e54626 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp
@@ -186,7 +186,8 @@ void AbstractMetaAttributes::assignMetaAttributes(const AbstractMetaAttributes &
* AbstractMetaType
*/
-AbstractMetaType::AbstractMetaType() :
+AbstractMetaType::AbstractMetaType(const TypeEntry *t) :
+ m_typeEntry(t),
m_constant(false),
m_volatile(false),
m_cppInstantiation(true),
@@ -217,7 +218,7 @@ QString AbstractMetaType::fullName() const
AbstractMetaType *AbstractMetaType::copy() const
{
- auto *cpy = new AbstractMetaType;
+ auto *cpy = new AbstractMetaType(typeEntry());
cpy->setTypeUsagePattern(typeUsagePattern());
cpy->setConstant(isConstant());
@@ -231,8 +232,6 @@ AbstractMetaType *AbstractMetaType::copy() const
cpy->setArrayElementType(arrayElementType() ? arrayElementType()->copy() : nullptr);
- cpy->setTypeEntry(typeEntry());
-
return cpy;
}
@@ -417,8 +416,7 @@ AbstractMetaType *AbstractMetaType::createVoid()
{
static const TypeEntry *voidTypeEntry = TypeDatabase::instance()->findType(QLatin1String("void"));
Q_ASSERT(voidTypeEntry);
- auto *metaType = new AbstractMetaType;
- metaType->setTypeEntry(voidTypeEntry);
+ auto *metaType = new AbstractMetaType(voidTypeEntry);
metaType->decideUsagePattern();
return metaType;
}
@@ -1418,8 +1416,7 @@ AbstractMetaClass::~AbstractMetaClass()
qDeleteAll(m_fields);
qDeleteAll(m_enums);
qDeleteAll(m_propertySpecs);
- if (hasTemplateBaseClassInstantiations())
- qDeleteAll(templateBaseClassInstantiations());
+ qDeleteAll(m_baseTemplateInstantiations);
}
/*******************************************************************************
@@ -1745,28 +1742,20 @@ QPropertySpec *AbstractMetaClass::propertySpecForReset(const QString &name) cons
return nullptr;
}
-using AbstractMetaClassBaseTemplateInstantiationsMap = QHash<const AbstractMetaClass *, AbstractMetaTypeList>;
-Q_GLOBAL_STATIC(AbstractMetaClassBaseTemplateInstantiationsMap, metaClassBaseTemplateInstantiations);
-
bool AbstractMetaClass::hasTemplateBaseClassInstantiations() const
{
- if (!templateBaseClass())
- return false;
- return metaClassBaseTemplateInstantiations()->contains(this);
+ return m_templateBaseClass != nullptr && !m_baseTemplateInstantiations.isEmpty();
}
-AbstractMetaTypeList AbstractMetaClass::templateBaseClassInstantiations() const
+const AbstractMetaTypeList &AbstractMetaClass::templateBaseClassInstantiations() const
{
- if (!templateBaseClass())
- return AbstractMetaTypeList();
- return metaClassBaseTemplateInstantiations()->value(this);
+ return m_baseTemplateInstantiations;
}
-void AbstractMetaClass::setTemplateBaseClassInstantiations(AbstractMetaTypeList &instantiations)
+void AbstractMetaClass::setTemplateBaseClassInstantiations(const AbstractMetaTypeList &instantiations)
{
- if (!templateBaseClass())
- return;
- metaClassBaseTemplateInstantiations()->insert(this, instantiations);
+ Q_ASSERT(m_templateBaseClass != nullptr);
+ m_baseTemplateInstantiations = instantiations;
}
// Does any of the base classes require deletion in the main thread?
@@ -1965,8 +1954,7 @@ void AbstractMetaClass::addDefaultCopyConstructor(bool isPrivate)
f->setFunctionType(AbstractMetaFunction::CopyConstructorFunction);
f->setDeclaringClass(this);
- auto argType = new AbstractMetaType;
- argType->setTypeEntry(typeEntry());
+ auto argType = new AbstractMetaType(typeEntry());
argType->setReferenceType(LValueReference);
argType->setConstant(true);
argType->setTypeUsagePattern(AbstractMetaType::ValuePattern);
@@ -2195,8 +2183,7 @@ static void addExtraIncludeForType(AbstractMetaClass *metaClass, const AbstractM
}
if (type->hasInstantiations()) {
- const AbstractMetaTypeList &instantiations = type->instantiations();
- for (const AbstractMetaType *instantiation : instantiations)
+ for (const AbstractMetaType *instantiation : type->instantiations())
addExtraIncludeForType(metaClass, instantiation);
}
}
@@ -2641,7 +2628,7 @@ void AbstractMetaClass::format(QDebug &d) const
d << " \"" << b->name() << '"';
}
if (auto templateBase = templateBaseClass()) {
- const auto instantiatedTypes = templateBaseClassInstantiations();
+ const auto &instantiatedTypes = templateBaseClassInstantiations();
d << ", instantiates \"" << templateBase->name();
for (int i = 0, count = instantiatedTypes.size(); i < count; ++i)
d << (i ? ',' : '<') << instantiatedTypes.at(i)->name();
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h
index 5d075f1e8..988815dd3 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetalang.h
+++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h
@@ -303,7 +303,7 @@ public:
};
Q_DECLARE_FLAGS(ComparisonFlags, ComparisonFlag);
- AbstractMetaType();
+ explicit AbstractMetaType(const TypeEntry *t = nullptr);
~AbstractMetaType();
QString package() const;
@@ -341,7 +341,7 @@ public:
}
}
- AbstractMetaTypeList instantiations() const
+ const AbstractMetaTypeList &instantiations() const
{
return m_instantiations;
}
@@ -512,7 +512,7 @@ public:
AbstractMetaType *getSmartPointerInnerType() const
{
Q_ASSERT(isSmartPointer());
- AbstractMetaTypeList instantiations = this->instantiations();
+ const AbstractMetaTypeList &instantiations = this->instantiations();
Q_ASSERT(!instantiations.isEmpty());
AbstractMetaType *innerType = instantiations.at(0);
return innerType;
@@ -540,7 +540,7 @@ private:
QString formatSignature(bool minimal) const;
QString formatPythonSignature() const;
- const TypeEntry *m_typeEntry = nullptr;
+ const TypeEntry *m_typeEntry;
AbstractMetaTypeList m_instantiations;
QString m_package;
mutable QString m_cachedCppSignature;
@@ -1640,8 +1640,8 @@ public:
}
bool hasTemplateBaseClassInstantiations() const;
- AbstractMetaTypeList templateBaseClassInstantiations() const;
- void setTemplateBaseClassInstantiations(AbstractMetaTypeList& instantiations);
+ const AbstractMetaTypeList &templateBaseClassInstantiations() const;
+ void setTemplateBaseClassInstantiations(const AbstractMetaTypeList& instantiations);
void setTypeDef(bool typeDef) { m_isTypeDef = typeDef; }
bool isTypeDef() const { return m_isTypeDef; }
@@ -1712,6 +1712,7 @@ private:
const AbstractMetaClass *m_enclosingClass = nullptr;
AbstractMetaClassList m_baseClasses; // Real base classes after setting up inheritance
+ AbstractMetaTypeList m_baseTemplateInstantiations;
AbstractMetaClass *m_extendedNamespace = nullptr;
const AbstractMetaClass *m_templateBaseClass = nullptr;