aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator/generator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/generator/generator.cpp')
-rw-r--r--sources/shiboken2/generator/generator.cpp60
1 files changed, 43 insertions, 17 deletions
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp
index 484b1f641..585102b01 100644
--- a/sources/shiboken2/generator/generator.cpp
+++ b/sources/shiboken2/generator/generator.cpp
@@ -159,7 +159,6 @@ struct Generator::GeneratorPrivate
QString licenseComment;
QString moduleName;
QStringList instantiatedContainersNames;
- QStringList instantiatedSmartPointerNames;
QVector<const AbstractMetaType *> instantiatedContainers;
QVector<const AbstractMetaType *> instantiatedSmartPointers;
@@ -211,6 +210,31 @@ QString Generator::getSimplifiedContainerTypeName(const AbstractMetaType *type)
return typeName;
}
+// Strip a "const QSharedPtr<const Foo> &" or similar to "QSharedPtr<Foo>" (PYSIDE-1016/454)
+const AbstractMetaType *canonicalSmartPtrInstantiation(const AbstractMetaType *type)
+{
+ AbstractMetaTypeList instantiations = type->instantiations();
+ Q_ASSERT(instantiations.size() == 1);
+ const bool needsFix = type->isConstant() || type->referenceType() != NoReference;
+ const bool pointeeNeedsFix = instantiations.constFirst()->isConstant();
+ if (!needsFix && !pointeeNeedsFix)
+ return type;
+ auto fixedType = type->copy();
+ fixedType->setReferenceType(NoReference);
+ fixedType->setConstant(false);
+ if (pointeeNeedsFix) {
+ auto fixedPointeeType = instantiations.constFirst()->copy();
+ fixedPointeeType->setConstant(false);
+ fixedType->setInstantiations(AbstractMetaTypeList(1, fixedPointeeType));
+ }
+ return fixedType;
+}
+
+static inline const TypeEntry *pointeeTypeEntry(const AbstractMetaType *smartPtrType)
+{
+ return smartPtrType->instantiations().constFirst()->typeEntry();
+}
+
void Generator::addInstantiatedContainersAndSmartPointers(const AbstractMetaType *type,
const QString &context)
{
@@ -244,18 +268,15 @@ void Generator::addInstantiatedContainersAndSmartPointers(const AbstractMetaType
m_d->instantiatedContainers.append(type);
}
} else {
- // Is smart pointer.
- if (!m_d->instantiatedSmartPointerNames.contains(typeName)) {
- m_d->instantiatedSmartPointerNames.append(typeName);
- if (type->isConstant() || type->referenceType() != NoReference) {
- // Strip a "const QSharedPtr<Foo> &" or similar to "QSharedPtr<Foo>" (PYSIDE-1016)
- auto fixedType = type->copy();
- fixedType->setReferenceType(NoReference);
- fixedType->setConstant(false);
- type = fixedType;
- }
- m_d->instantiatedSmartPointers.append(type);
- }
+ // Is smart pointer. Check if the (const?) pointee is already known
+ auto pt = pointeeTypeEntry(type);
+ const bool present =
+ std::any_of(m_d->instantiatedSmartPointers.cbegin(), m_d->instantiatedSmartPointers.cend(),
+ [pt] (const AbstractMetaType *t) {
+ return pointeeTypeEntry(t) == pt;
+ });
+ if (!present)
+ m_d->instantiatedSmartPointers.append(canonicalSmartPtrInstantiation(type));
}
}
@@ -449,7 +470,8 @@ bool Generator::generate()
bool Generator::shouldGenerateTypeEntry(const TypeEntry *type) const
{
- return type->codeGeneration() & TypeEntry::GenerateTargetLang;
+ return (type->codeGeneration() & TypeEntry::GenerateTargetLang)
+ && NamespaceTypeEntry::isVisibleScope(type);
}
bool Generator::shouldGenerate(const AbstractMetaClass *metaClass) const
@@ -529,7 +551,7 @@ QTextStream &formatCode(QTextStream &s, const QString &code, Indentor &indentor)
s << indentor << line.remove(0, limit);
}
- s << endl;
+ s << Qt::endl;
}
return s;
}
@@ -893,8 +915,12 @@ static QString getClassTargetFullName_(const T *t, bool includePackageName)
QString name = t->name();
const AbstractMetaClass *context = t->enclosingClass();
while (context) {
- name.prepend(QLatin1Char('.'));
- name.prepend(context->name());
+ // If the type was marked as 'visible=false' we should not use it in
+ // the type name
+ if (NamespaceTypeEntry::isVisibleScope(context->typeEntry())) {
+ name.prepend(QLatin1Char('.'));
+ name.prepend(context->name());
+ }
context = context->enclosingClass();
}
if (includePackageName) {