diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-11-10 15:28:55 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-11-11 17:14:14 +0000 |
| commit | 154ef5831fcae56f9cbf53301b410a21bbdd6265 (patch) | |
| tree | c8322efaf9dfe208173b769c9106bb968e659a09 | |
| parent | c527b0bac89679aa01fbc409077dd5640fc59c9b (diff) | |
shiboken6: Port QPropertySpec to use QSharedDataPointer
Change the client code to store it by value. Use a
std::optional to replace the pointer.
Replace the pointer QPropertySpec* stored in AbstractMetaFunction
by a the index of the property in the enclosing class.
Change-Id: Iffca9e0a6f311534ba001dc2b34bbf5ff7c01813
Reviewed-by: Christian Tismer <tismer@stackless.com>
12 files changed, 308 insertions, 180 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index da086053e..afd0ec3c1 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -1272,28 +1272,37 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, if (metaClass->isNamespace()) *metaFunction += AbstractMetaAttributes::Static; - QPropertySpec *read = nullptr; - if (!metaFunction->isSignal() && (read = metaClass->propertySpecForRead(metaFunction->name()))) { - // Property reader must be in the form "<type> name()" - if (read->typeEntry() == metaFunction->type().typeEntry() - && metaFunction->arguments().isEmpty()) { - *metaFunction += AbstractMetaAttributes::PropertyReader; - metaFunction->setPropertySpec(read); - } - } else if (QPropertySpec *write = metaClass->propertySpecForWrite(metaFunction->name())) { - // Property setter must be in the form "void name(<type>)" - // Make sure the function was created with all arguments; some argument can be - // missing during the parsing because of errors in the typesystem. - if (metaFunction->isVoid() && metaFunction->arguments().size() == 1 - && (write->typeEntry() == metaFunction->arguments().at(0).type().typeEntry())) { - *metaFunction += AbstractMetaAttributes::PropertyWriter; - metaFunction->setPropertySpec(write); - } - } else if (QPropertySpec *reset = metaClass->propertySpecForReset(metaFunction->name())) { - // Property resetter must be in the form "void name()" - if (metaFunction->isVoid() && metaFunction->arguments().isEmpty()) { - *metaFunction += AbstractMetaAttributes::PropertyResetter; - metaFunction->setPropertySpec(reset); + const auto propertyFunction = metaClass->searchPropertyFunction(metaFunction->name()); + if (propertyFunction.index >= 0) { + QPropertySpec prop = metaClass->propertySpecs().at(propertyFunction.index); + switch (propertyFunction.function) { + case AbstractMetaClass::PropertyFunction::Read: + // Property reader must be in the form "<type> name()" + if (!metaFunction->isSignal() + && prop.typeEntry() == metaFunction->type().typeEntry() + && metaFunction->arguments().isEmpty()) { + *metaFunction += AbstractMetaAttributes::PropertyReader; + metaFunction->setPropertySpecIndex(propertyFunction.index); + } + break; + case AbstractMetaClass::PropertyFunction::Write: + // Property setter must be in the form "void name(<type>)" + // Make sure the function was created with all arguments; some + // argument can be missing during the parsing because of errors + // in the typesystem. + if (metaFunction->isVoid() && metaFunction->arguments().size() == 1 + && (prop.typeEntry() == metaFunction->arguments().at(0).type().typeEntry())) { + *metaFunction += AbstractMetaAttributes::PropertyWriter; + metaFunction->setPropertySpecIndex(propertyFunction.index); + } + break; + case AbstractMetaClass::PropertyFunction::Reset: + // Property resetter must be in the form "void name()" + if (metaFunction->isVoid() && metaFunction->arguments().isEmpty()) { + *metaFunction += AbstractMetaAttributes::PropertyResetter; + metaFunction->setPropertySpecIndex(propertyFunction.index); + } + break; } } @@ -2743,9 +2752,10 @@ void AbstractMetaBuilderPrivate::parseQ_Properties(AbstractMetaClass *metaClass, QString errorMessage; int i = 0; for (; i < declarations.size(); ++i) { - if (auto spec = QPropertySpec::parseQ_Property(this, metaClass, declarations.at(i), scopes, &errorMessage)) { + auto spec = QPropertySpec::parseQ_Property(this, metaClass, declarations.at(i), scopes, &errorMessage); + if (spec.has_value()) { spec->setIndex(i); - metaClass->addPropertySpec(spec); + metaClass->addPropertySpec(spec.value()); } else { QString message; QTextStream str(&message); @@ -2757,15 +2767,15 @@ void AbstractMetaBuilderPrivate::parseQ_Properties(AbstractMetaClass *metaClass, // User-added properties auto typeEntry = metaClass->typeEntry(); for (const TypeSystemProperty &tp : typeEntry->properties()) { - QPropertySpec *spec = nullptr; + std::optional<QPropertySpec> spec; if (metaClass->propertySpecByName(tp.name)) errorMessage = msgPropertyExists(metaClass->name(), tp.name); else spec = QPropertySpec::fromTypeSystemProperty(this, metaClass, tp, scopes, &errorMessage); - if (spec) { + if (spec.has_value()) { spec->setIndex(i++); - metaClass->addPropertySpec(spec); + metaClass->addPropertySpec(spec.value()); } else { QString message; QTextStream str(&message); diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.h b/sources/shiboken6/ApiExtractor/abstractmetafunction.h index 33345a4d4..7dd3cd1a1 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.h +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.h @@ -41,7 +41,6 @@ QT_FORWARD_DECLARE_CLASS(QDebug) class FunctionTypeEntry; -class QPropertySpec; struct ArgumentOwner; struct FieldModification; @@ -274,8 +273,8 @@ public: */ QString argumentName(int index, bool create = true, const AbstractMetaClass *cl = nullptr) const; - QPropertySpec *propertySpec() const { return m_propertySpec; } - void setPropertySpec(QPropertySpec *spec) { m_propertySpec = spec; } + int propertySpecIndex() const { return m_propertySpecIndex; } + void setPropertySpecIndex(int i) { m_propertySpecIndex = i; } FunctionTypeEntry* typeEntry() const { return m_typeEntry; } @@ -318,7 +317,7 @@ private: const AbstractMetaClass *m_class = nullptr; const AbstractMetaClass *m_implementingClass = nullptr; const AbstractMetaClass *m_declaringClass = nullptr; - QPropertySpec *m_propertySpec = nullptr; + int m_propertySpecIndex = -1; AbstractMetaArgumentList m_arguments; AddedFunctionPtr m_addedFunction; SourceLocation m_sourceLocation; diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp index a742910ec..2d3da6abe 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp @@ -68,7 +68,6 @@ public: ~AbstractMetaClassPrivate() { qDeleteAll(m_functions); - qDeleteAll(m_propertySpecs); } uint m_hasVirtuals : 1; @@ -97,7 +96,7 @@ public: AbstractMetaFunctionList m_functions; AbstractMetaFieldList m_fields; AbstractMetaEnumList m_enums; - QVector<QPropertySpec *> m_propertySpecs; + QList<QPropertySpec> m_propertySpecs; AbstractMetaClassList m_innerClasses; AbstractMetaFunctionList m_externalConversionOperators; @@ -349,12 +348,12 @@ void AbstractMetaClass::setHasCloneOperator(bool on) d->m_hasCloneOperator = on; } -const QVector<QPropertySpec *> &AbstractMetaClass::propertySpecs() const +const QList<QPropertySpec> &AbstractMetaClass::propertySpecs() const { return d->m_propertySpecs; } -void AbstractMetaClass::addPropertySpec(QPropertySpec *spec) +void AbstractMetaClass::addPropertySpec(const QPropertySpec &spec) { d->m_propertySpecs << spec; } @@ -574,40 +573,30 @@ bool AbstractMetaClass::hasHashFunction() const return d->m_hasHashFunction; } -QPropertySpec *AbstractMetaClass::propertySpecByName(const QString &name) const +// Search whether a functions is a property setter/getter/reset +AbstractMetaClass::PropertyFunctionSearchResult + AbstractMetaClass::searchPropertyFunction(const QString &name) const { - for (auto propertySpec : d->m_propertySpecs) { - if (name == propertySpec->name()) - return propertySpec; - } - return nullptr; -} - -QPropertySpec *AbstractMetaClass::propertySpecForRead(const QString &name) const -{ - for (const auto &propertySpec : d->m_propertySpecs) { - if (name == propertySpec->read()) - return propertySpec; - } - return nullptr; -} - -QPropertySpec *AbstractMetaClass::propertySpecForWrite(const QString &name) const -{ - for (const auto &propertySpec : d->m_propertySpecs) { - if (name == propertySpec->write()) - return propertySpec; + for (int i = 0, size = d->m_propertySpecs.size(); i < size; ++i) { + const auto &propertySpec = d->m_propertySpecs.at(i); + if (name == propertySpec.read()) + return PropertyFunctionSearchResult{i, PropertyFunction::Read}; + if (name == propertySpec.write()) + return PropertyFunctionSearchResult{i, PropertyFunction::Write}; + if (name == propertySpec.reset()) + return PropertyFunctionSearchResult{i, PropertyFunction::Reset}; } - return nullptr; + return PropertyFunctionSearchResult{-1, PropertyFunction::Read}; } -QPropertySpec *AbstractMetaClass::propertySpecForReset(const QString &name) const +std::optional<QPropertySpec> + AbstractMetaClass::propertySpecByName(const QString &name) const { for (const auto &propertySpec : d->m_propertySpecs) { - if (name == propertySpec->reset()) + if (name == propertySpec.name()) return propertySpec; } - return nullptr; + return {}; } AbstractMetaFunctionList AbstractMetaClass::externalConversionOperators() const @@ -1400,7 +1389,7 @@ void AbstractMetaClass::format(QDebug &debug) const for (int i = 0; i < count; ++i) { if (i) debug << ", "; - d->m_propertySpecs.at(i)->formatDebug(debug); + d->m_propertySpecs.at(i).formatDebug(debug); } debug << ']'; } diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.h b/sources/shiboken6/ApiExtractor/abstractmetalang.h index 2087180cd..f07fdb355 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken6/ApiExtractor/abstractmetalang.h @@ -271,13 +271,25 @@ public: bool hasCloneOperator() const; void setHasCloneOperator(bool on); - const QVector<QPropertySpec *> &propertySpecs() const; - void addPropertySpec(QPropertySpec *spec); + const QList<QPropertySpec> &propertySpecs() const; + void addPropertySpec(const QPropertySpec &spec); + + // Helpers to search whether a functions is a property setter/getter/reset + enum class PropertyFunction + { + Read, + Write, + Reset + }; + struct PropertyFunctionSearchResult + { + int index; + PropertyFunction function; + }; + + PropertyFunctionSearchResult searchPropertyFunction(const QString &name) const; - QPropertySpec *propertySpecByName(const QString &name) const; - QPropertySpec *propertySpecForRead(const QString &name) const; - QPropertySpec *propertySpecForWrite(const QString &name) const; - QPropertySpec *propertySpecForReset(const QString &name) const; + std::optional<QPropertySpec> propertySpecByName(const QString &name) const; /// Returns a list of conversion operators for this class. The conversion /// operators are defined in other classes of the same module. diff --git a/sources/shiboken6/ApiExtractor/doxygenparser.cpp b/sources/shiboken6/ApiExtractor/doxygenparser.cpp index 723a5f022..92040dfc5 100644 --- a/sources/shiboken6/ApiExtractor/doxygenparser.cpp +++ b/sources/shiboken6/ApiExtractor/doxygenparser.cpp @@ -126,8 +126,9 @@ void DoxygenParser::fillDocumentation(AbstractMetaClass* metaClass) // properties if (func->isPropertyReader() || func->isPropertyWriter() || func->isPropertyResetter()) { + const auto prop = metaClass->propertySpecs().at(func->propertySpecIndex()); query += QLatin1String("[@kind=\"property\"]/memberdef/name[text()=\"") - + func->propertySpec()->name() + QLatin1String("\"]"); + + prop.name() + QLatin1String("\"]"); isProperty = true; } else { // normal methods QString kind = getSectionKindAttr(func); diff --git a/sources/shiboken6/ApiExtractor/propertyspec.cpp b/sources/shiboken6/ApiExtractor/propertyspec.cpp index d15647fda..fb45830b1 100644 --- a/sources/shiboken6/ApiExtractor/propertyspec.cpp +++ b/sources/shiboken6/ApiExtractor/propertyspec.cpp @@ -29,6 +29,7 @@ #include "propertyspec.h" #include "abstractmetalang.h" #include "abstractmetabuilder_p.h" +#include "abstractmetatype.h" #include "codemodel.h" #include "messages.h" #include "typesystem.h" @@ -41,28 +42,140 @@ #include <algorithm> +class QPropertySpecData : public QSharedData +{ +public: + QPropertySpecData(const TypeSystemProperty &ts, + const AbstractMetaType &type) : + m_name(ts.name), + m_read(ts.read), + m_write(ts.write), + m_designable(ts.designable), + m_reset(ts.reset), + m_type(type), + m_generateGetSetDef(ts.generateGetSetDef) + { + } + + QString m_name; + QString m_read; + QString m_write; + QString m_designable; + QString m_reset; + AbstractMetaType m_type; + int m_index = -1; + // Indicates whether actual code is generated instead of relying on libpyside. + bool m_generateGetSetDef = false; +}; + QPropertySpec::QPropertySpec(const TypeSystemProperty &ts, const AbstractMetaType &type) : - m_name(ts.name), - m_read(ts.read), - m_write(ts.write), - m_designable(ts.designable), - m_reset(ts.reset), - m_type(type), - m_generateGetSetDef(ts.generateGetSetDef) + d(new QPropertySpecData(ts, type)) { } +QPropertySpec::QPropertySpec(const QPropertySpec &) = default; +QPropertySpec &QPropertySpec::operator=(const QPropertySpec &) = default; +QPropertySpec::QPropertySpec(QPropertySpec &&) = default; +QPropertySpec &QPropertySpec::operator=(QPropertySpec &&) = default; QPropertySpec::~QPropertySpec() = default; -bool QPropertySpec::isValid() const +const AbstractMetaType &QPropertySpec::type() const +{ + return d->m_type; +} + +void QPropertySpec::setType(const AbstractMetaType &t) { - return m_type.isValid() && !m_name.isEmpty() && !m_read.isEmpty(); + if (d->m_type != t) + d->m_type = t; } const TypeEntry *QPropertySpec::typeEntry() const { - return m_type.typeEntry(); + return d->m_type.typeEntry(); +} + +QString QPropertySpec::name() const +{ + return d->m_name; +} + +void QPropertySpec::setName(const QString &name) +{ + if (d->m_name != name) + d->m_name = name; +} + +QString QPropertySpec::read() const +{ + return d->m_read; +} + +void QPropertySpec::setRead(const QString &read) +{ + if (d->m_read != read) + d->m_read = read; +} + +QString QPropertySpec::write() const +{ + return d->m_write; +} + +void QPropertySpec::setWrite(const QString &write) +{ + if (d->m_write != write) + d->m_write = write; +} + +bool QPropertySpec::hasWrite() const +{ + return !d->m_write.isEmpty(); +} + +QString QPropertySpec::designable() const +{ + return d->m_designable; +} + +void QPropertySpec::setDesignable(const QString &designable) +{ + if (d->m_designable != designable) + d->m_designable = designable; +} + +QString QPropertySpec::reset() const +{ + return d->m_reset; +} + +void QPropertySpec::setReset(const QString &reset) +{ + if (d->m_reset != reset) + d->m_reset = reset; +} + +int QPropertySpec::index() const +{ + return d->m_index; +} + +void QPropertySpec::setIndex(int index) +{ + if (d->m_index != index) + d->m_index = index; +} + +bool QPropertySpec::generateGetSetDef() const +{ + return d->m_generateGetSetDef; +} + +void QPropertySpec::setGenerateGetSetDef(bool generateGetSetDef) +{ + if (d->m_generateGetSetDef != generateGetSetDef) + d->m_generateGetSetDef = generateGetSetDef; } // Parse a Q_PROPERTY macro @@ -144,18 +257,19 @@ TypeSystemProperty QPropertySpec::typeSystemPropertyFromQ_Property(const QString // Create a QPropertySpec from a TypeSystemProperty, determining // the AbstractMetaType from the type string. -QPropertySpec *QPropertySpec::fromTypeSystemProperty(AbstractMetaBuilderPrivate *b, - AbstractMetaClass *metaClass, - const TypeSystemProperty &ts, - const QStringList &scopes, - QString *errorMessage) +std::optional<QPropertySpec> + QPropertySpec::fromTypeSystemProperty(AbstractMetaBuilderPrivate *b, + AbstractMetaClass *metaClass, + const TypeSystemProperty &ts, + const QStringList &scopes, + QString *errorMessage) { Q_ASSERT(ts.isValid()); QString typeError; TypeInfo info = TypeParser::parse(ts.type, &typeError); if (info.qualifiedName().isEmpty()) { *errorMessage = msgPropertyTypeParsingFailed(ts.name, ts.type, typeError); - return nullptr; + return {}; } AbstractMetaType type = b->translateType(info, metaClass, {}, &typeError); @@ -169,37 +283,38 @@ QPropertySpec *QPropertySpec::fromTypeSystemProperty(AbstractMetaBuilderPrivate if (!type) { *errorMessage = msgPropertyTypeParsingFailed(ts.name, ts.type, typeError); - return nullptr; + return {}; } - return new QPropertySpec(ts, type); + return QPropertySpec(ts, type); } // Convenience to create a QPropertySpec from a Q_PROPERTY macro // via TypeSystemProperty. -QPropertySpec *QPropertySpec::parseQ_Property(AbstractMetaBuilderPrivate *b, - AbstractMetaClass *metaClass, - const QString &declarationIn, - const QStringList &scopes, - QString *errorMessage) +std::optional<QPropertySpec> + QPropertySpec::parseQ_Property(AbstractMetaBuilderPrivate *b, + AbstractMetaClass *metaClass, + const QString &declarationIn, + const QStringList &scopes, + QString *errorMessage) { const TypeSystemProperty ts = typeSystemPropertyFromQ_Property(declarationIn, errorMessage); - return ts.isValid() - ? fromTypeSystemProperty(b, metaClass, ts, scopes, errorMessage) - : nullptr; + if (!ts.isValid()) + return {}; + return fromTypeSystemProperty(b, metaClass, ts, scopes, errorMessage); } #ifndef QT_NO_DEBUG_STREAM -void QPropertySpec::formatDebug(QDebug &d) const -{ - d << '#' << m_index << " \"" << m_name << "\" (" << m_type.cppSignature(); - d << "), read=" << m_read; - if (!m_write.isEmpty()) - d << ", write=" << m_write; - if (!m_reset.isEmpty()) - d << ", reset=" << m_reset; - if (!m_designable.isEmpty()) - d << ", designable=" << m_designable; +void QPropertySpec::formatDebug(QDebug &debug) const +{ + debug << '#' << d->m_index << " \"" << d->m_name << "\" (" << d->m_type.cppSignature(); + debug << "), read=" << d->m_read; + if (!d->m_write.isEmpty()) + debug << ", write=" << d->m_write; + if (!d->m_reset.isEmpty()) + debug << ", reset=" << d->m_reset; + if (!d->m_designable.isEmpty()) + debug << ", designable=" << d->m_designable; } QDebug operator<<(QDebug d, const QPropertySpec &p) diff --git a/sources/shiboken6/ApiExtractor/propertyspec.h b/sources/shiboken6/ApiExtractor/propertyspec.h index d26f7e826..4121f72d2 100644 --- a/sources/shiboken6/ApiExtractor/propertyspec.h +++ b/sources/shiboken6/ApiExtractor/propertyspec.h @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ @@ -29,9 +29,12 @@ #ifndef PROPERTYSPEC_H #define PROPERTYSPEC_H -#include "abstractmetatype.h" +class AbstractMetaType; #include <QtCore/QStringList> +#include <QtCore/QSharedDataPointer> + +#include <optional> class AbstractMetaClass; class AbstractMetaBuilderPrivate; @@ -40,75 +43,73 @@ class TypeEntry; struct TypeSystemProperty; +class QPropertySpecData; + QT_FORWARD_DECLARE_CLASS(QDebug) class QPropertySpec { public: - Q_DISABLE_COPY_MOVE(QPropertySpec) - explicit QPropertySpec(const TypeSystemProperty &ts, const AbstractMetaType &type); + QPropertySpec(const QPropertySpec &); + QPropertySpec &operator=(const QPropertySpec &); + QPropertySpec(QPropertySpec &&); + QPropertySpec &operator=(QPropertySpec &&); ~QPropertySpec(); static TypeSystemProperty typeSystemPropertyFromQ_Property(const QString &declarationIn, QString *errorMessage); - static QPropertySpec *fromTypeSystemProperty(AbstractMetaBuilderPrivate *b, - AbstractMetaClass *metaClass, - const TypeSystemProperty &ts, - const QStringList &scopes, - QString *errorMessage); - static QPropertySpec *parseQ_Property(AbstractMetaBuilderPrivate *b, - AbstractMetaClass *metaClass, - const QString &declarationIn, - const QStringList &scopes, - QString *errorMessage); + static std::optional<QPropertySpec> + fromTypeSystemProperty(AbstractMetaBuilderPrivate *b, + AbstractMetaClass *metaClass, + const TypeSystemProperty &ts, + const QStringList &scopes, + QString *errorMessage); - bool isValid() const; + static std::optional<QPropertySpec> + parseQ_Property(AbstractMetaBuilderPrivate *b, + AbstractMetaClass *metaClass, + const QString &declarationIn, + const QStringList &scopes, + QString *errorMessage); - const AbstractMetaType &type() const { return m_type; } - void setType(const AbstractMetaType &t) { m_type = t; } + const AbstractMetaType &type() const; + void setType(const AbstractMetaType &t); const TypeEntry *typeEntry() const; - QString name() const { return m_name; } - void setName(const QString &name) { m_name = name; } + QString name() const; + void setName(const QString &name); - QString read() const { return m_read; } - void setRead(const QString &read) { m_read = read; } + QString read() const; + void setRead(const QString &read); - QString write() const { return m_write; } - void setWrite(const QString &write) { m_write = write; } - bool hasWrite() const { return !m_write.isEmpty(); } + QString write() const; + void setWrite(const QString &write); + bool hasWrite() const; - QString designable() const { return m_designable; } - void setDesignable(const QString &designable) { m_designable = designable; } + QString designable() const; + void setDesignable(const QString &designable); - QString reset() const { return m_reset; } - void setReset(const QString &reset) { m_reset = reset; } + QString reset() const; + void setReset(const QString &reset); - int index() const { return m_index; } - void setIndex(int index) {m_index = index; } + int index() const; + void setIndex(int index); - bool generateGetSetDef() const { return m_generateGetSetDef; } - void setGenerateGetSetDef(bool generateGetSetDef) { m_generateGetSetDef = generateGetSetDef; } + // Indicates whether actual code is generated instead of relying on libpyside. + bool generateGetSetDef() const; + void setGenerateGetSetDef(bool generateGetSetDef); #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &d) const; #endif private: - QString m_name; - QString m_read; - QString m_write; - QString m_designable; - QString m_reset; - AbstractMetaType m_type; - int m_index = -1; - // Indicates whether actual code is generated instead of relying on libpyside. - bool m_generateGetSetDef = false; + QSharedDataPointer<QPropertySpecData> d; }; #ifndef QT_NO_DEBUG_STREAM diff --git a/sources/shiboken6/ApiExtractor/qtdocparser.cpp b/sources/shiboken6/ApiExtractor/qtdocparser.cpp index 6ce3432d7..f71e84432 100644 --- a/sources/shiboken6/ApiExtractor/qtdocparser.cpp +++ b/sources/shiboken6/ApiExtractor/qtdocparser.cpp @@ -177,8 +177,9 @@ QString QtDocParser::queryFunctionDocumentation(const QString &sourceFileName, // Properties if (func->isPropertyReader() || func->isPropertyWriter() || func->isPropertyResetter()) { + const auto prop = metaClass->propertySpecs().at(func->propertySpecIndex()); const QString propertyQuery = classQuery + QLatin1String("/property[@name=\"") - + func->propertySpec()->name() + QLatin1String("\"]/description"); + + prop.name() + QLatin1String("\"]/description"); const QString properyDocumentation = getDocumentation(xquery, propertyQuery, funcModifs); if (properyDocumentation.isEmpty()) *errorMessage = msgCannotFindDocumentation(sourceFileName, metaClass, func, propertyQuery); diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 65417229d..f6c9bba29 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -310,20 +310,20 @@ static bool isStdSetterName(QString setterName, QString propertyName) && setterName.at(3) == propertyName.at(0).toUpper(); } -static QString buildPropertyString(QPropertySpec *spec) +static QString buildPropertyString(const QPropertySpec &spec) { QString text; text += QLatin1Char('"'); - text += spec->name(); + text += spec.name(); text += QLatin1Char(':'); - if (spec->read() != spec->name()) - text += spec->read(); + if (spec.read() != spec.name()) + text += spec.read(); - if (!spec->write().isEmpty()) { + if (!spec.write().isEmpty()) { text += QLatin1Char(':'); - if (!isStdSetterName(spec->write(), spec->name())) - text += spec->write(); + if (!isStdSetterName(spec.write(), spec.name())) + text += spec.write(); } text += QLatin1Char('"'); @@ -613,8 +613,8 @@ void CppGenerator::generateClass(QTextStream &s, const GeneratorContext &classCo // PYSIDE-1019: Write a compressed list of all properties `name:getter[:setter]`. // Default values are suppressed. QStringList sorter; - for (const auto spec : metaClass->propertySpecs()) { - if (!spec->generateGetSetDef()) + for (const auto &spec : metaClass->propertySpecs()) { + if (!spec.generateGetSetDef()) sorter.append(buildPropertyString(spec)); } sorter.sort(); @@ -714,10 +714,10 @@ void CppGenerator::generateClass(QTextStream &s, const GeneratorContext &classCo s << Qt::endl; } - for (const QPropertySpec *property : metaClass->propertySpecs()) { - if (property->generateGetSetDef() || !usePySideExtensions()) { + for (const QPropertySpec &property : metaClass->propertySpecs()) { + if (property.generateGetSetDef() || !usePySideExtensions()) { writeGetterFunction(s, property, classContext); - if (property->hasWrite()) + if (property.hasWrite()) writeSetterFunction(s, property, classContext); } } @@ -734,12 +734,12 @@ void CppGenerator::generateClass(QTextStream &s, const GeneratorContext &classCo } } - for (const QPropertySpec *property : metaClass->propertySpecs()) { - if (property->generateGetSetDef() || !usePySideExtensions()) { + for (const QPropertySpec &property : metaClass->propertySpecs()) { + if (property.generateGetSetDef() || !usePySideExtensions()) { s << INDENT; - const QString setter = property->hasWrite() + const QString setter = property.hasWrite() ? cpythonSetterFunctionName(property, metaClass) : QString(); - writePyGetSetDefEntry(s, property->name(), + writePyGetSetDefEntry(s, property.name(), cpythonGetterFunctionName(property, metaClass), setter); } } @@ -4082,7 +4082,7 @@ bool CppGenerator::shouldGenerateGetSetList(const AbstractMetaClass *metaClass) // in libpyside). return usePySideExtensions() ? std::any_of(metaClass->propertySpecs().cbegin(), metaClass->propertySpecs().cend(), - [] (const QPropertySpec *s) { return s->generateGetSetDef(); }) + [] (const QPropertySpec &s) { return s.generateGetSetDef(); }) : !metaClass->propertySpecs().isEmpty(); return false; } @@ -4605,16 +4605,16 @@ void CppGenerator::writeGetterFunction(QTextStream &s, } // Write a getter for QPropertySpec -void CppGenerator::writeGetterFunction(QTextStream &s, const QPropertySpec *property, +void CppGenerator::writeGetterFunction(QTextStream &s, const QPropertySpec &property, const GeneratorContext &context) { ErrorCode errorCode(0); writeGetterFunctionStart(s, cpythonGetterFunctionName(property, context.metaClass())); writeCppSelfDefinition(s, context); const QString value = QStringLiteral("value"); - s << INDENT << "auto " << value << " = " << CPP_SELF_VAR << "->" << property->read() << "();\n" + s << INDENT << "auto " << value << " = " << CPP_SELF_VAR << "->" << property.read() << "();\n" << INDENT << "auto pyResult = "; - writeToPythonConversion(s, property->type(), context.metaClass(), value); + writeToPythonConversion(s, property.type(), context.metaClass(), value); s << ";\n" << INDENT << "if (PyErr_Occurred() || !pyResult) {\n"; { @@ -4696,22 +4696,22 @@ void CppGenerator::writeSetterFunction(QTextStream &s, } // Write a setter for QPropertySpec -void CppGenerator::writeSetterFunction(QTextStream &s, const QPropertySpec *property, +void CppGenerator::writeSetterFunction(QTextStream &s, const QPropertySpec &property, const GeneratorContext &context) { ErrorCode errorCode(0); - writeSetterFunctionPreamble(s, property->name(), + writeSetterFunctionPreamble(s, property.name(), cpythonSetterFunctionName(property, context.metaClass()), - property->type(), context); + property.type(), context); - s << INDENT << "auto cppOut = " << CPP_SELF_VAR << "->" << property->read() << "();\n" + s << INDENT << "auto cppOut = " << CPP_SELF_VAR << "->" << property.read() << "();\n" << INDENT << PYTHON_TO_CPP_VAR << "(pyIn, &cppOut);\n" << INDENT << "if (PyErr_Occurred())\n"; { Indentation indent(INDENT); s << INDENT << "return -1;\n"; } - s << INDENT << CPP_SELF_VAR << "->" << property->write() << "(cppOut);\n" + s << INDENT << CPP_SELF_VAR << "->" << property.write() << "(cppOut);\n" << INDENT << "return 0;\n}\n\n"; } diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h index 5073f8524..e0b30117a 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.h +++ b/sources/shiboken6/generator/shiboken/cppgenerator.h @@ -293,7 +293,7 @@ private: const AbstractMetaField &metaField, const GeneratorContext &context); void writeGetterFunction(QTextStream &s, - const QPropertySpec *property, + const QPropertySpec &property, const GeneratorContext &context); void writeSetterFunctionPreamble(QTextStream &s, const QString &name, @@ -304,7 +304,7 @@ private: const AbstractMetaField &metaField, const GeneratorContext &context); void writeSetterFunction(QTextStream &s, - const QPropertySpec *property, + const QPropertySpec &property, const GeneratorContext &context); void writeRichCompareFunction(QTextStream &s, const GeneratorContext &context); diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index dd996d15a..5c46566ca 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -474,16 +474,16 @@ QString ShibokenGenerator::cpythonSetterFunctionName(const AbstractMetaField &me return cpythonSetterFunctionName(metaField.name(), metaField.enclosingClass()); } -QString ShibokenGenerator::cpythonGetterFunctionName(const QPropertySpec *property, +QString ShibokenGenerator::cpythonGetterFunctionName(const QPropertySpec &property, const AbstractMetaClass *metaClass) { - return cpythonGetterFunctionName(property->name(), metaClass); + return cpythonGetterFunctionName(property.name(), metaClass); } -QString ShibokenGenerator::cpythonSetterFunctionName(const QPropertySpec *property, +QString ShibokenGenerator::cpythonSetterFunctionName(const QPropertySpec &property, const AbstractMetaClass *metaClass) { - return cpythonSetterFunctionName(property->name(), metaClass); + return cpythonSetterFunctionName(property.name(), metaClass); } static QString cpythonEnumFlagsName(const QString &moduleName, diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h index 91ddf8886..55d8c00db 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.h +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h @@ -345,9 +345,9 @@ protected: static QString cpythonSetattroFunctionName(const AbstractMetaClass *metaClass); static QString cpythonGetterFunctionName(const AbstractMetaField &metaField); static QString cpythonSetterFunctionName(const AbstractMetaField &metaField); - static QString cpythonGetterFunctionName(const QPropertySpec *property, + static QString cpythonGetterFunctionName(const QPropertySpec &property, const AbstractMetaClass *metaClass); - static QString cpythonSetterFunctionName(const QPropertySpec *property, + static QString cpythonSetterFunctionName(const QPropertySpec &property, const AbstractMetaClass *metaClass); QString cpythonWrapperCPtr(const AbstractMetaClass *metaClass, const QString &argName = QLatin1String("self")) const; |
