diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-22 10:26:06 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-22 16:08:37 +0200 |
commit | 2919d4b31aba3806f31884518396ac07f98ec552 (patch) | |
tree | 8036ac333b7d84d3aad880b9f20bdbbac6422a64 /sources/shiboken2/ApiExtractor | |
parent | 20b96311b5bca6978f72d0bf3a4ea774e98ebb76 (diff) |
shiboken2: Move class PropertySpec into its own source file
Move the class and the parser function into its own source file.
Task-number: PYSIDE-1019
Change-Id: If403f799f6b8da769fd8b47dd958a7430d061ad8
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor')
-rw-r--r-- | sources/shiboken2/ApiExtractor/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp | 72 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h | 2 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.cpp | 32 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.h | 94 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/doxygenparser.cpp | 1 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/propertyspec.cpp | 139 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/propertyspec.h | 97 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/qtdocparser.cpp | 1 |
9 files changed, 242 insertions, 197 deletions
diff --git a/sources/shiboken2/ApiExtractor/CMakeLists.txt b/sources/shiboken2/ApiExtractor/CMakeLists.txt index 28644fe49..b081beda9 100644 --- a/sources/shiboken2/ApiExtractor/CMakeLists.txt +++ b/sources/shiboken2/ApiExtractor/CMakeLists.txt @@ -12,6 +12,7 @@ abstractmetalang.cpp fileout.cpp graph.cpp messages.cpp +propertyspec.cpp reporthandler.cpp sourcelocation.cpp typeparser.cpp diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index 278c0b9c4..3c9ef21a7 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -28,6 +28,7 @@ #include "abstractmetabuilder_p.h" #include "messages.h" +#include "propertyspec.h" #include "reporthandler.h" #include "typedatabase.h" @@ -2789,7 +2790,7 @@ void AbstractMetaBuilderPrivate::parseQ_Properties(AbstractMetaClass *metaClass, const QStringList scopes = currentScope()->qualifiedName(); QString errorMessage; for (int i = 0; i < declarations.size(); ++i) { - if (auto spec = parseQ_Property(metaClass, declarations.at(i), scopes, &errorMessage)) { + if (auto spec = QPropertySpec::parseQ_Property(this, metaClass, declarations.at(i), scopes, &errorMessage)) { spec->setIndex(i); metaClass->addPropertySpec(spec); } else { @@ -2801,75 +2802,6 @@ void AbstractMetaBuilderPrivate::parseQ_Properties(AbstractMetaClass *metaClass, } } -QPropertySpec *AbstractMetaBuilderPrivate::parseQ_Property(AbstractMetaClass *metaClass, - const QString &declarationIn, - const QStringList &scopes, - QString *errorMessage) -{ - errorMessage->clear(); - - // Q_PROPERTY(QString objectName READ objectName WRITE setObjectName NOTIFY objectNameChanged) - - const QString declaration = declarationIn.simplified(); - auto propertyTokens = declaration.splitRef(QLatin1Char(' '), Qt::SkipEmptyParts); - if (propertyTokens.size() < 4) { - *errorMessage = QLatin1String("Insufficient number of tokens"); - return nullptr; - } - - QString fullTypeName = propertyTokens.takeFirst().toString(); - QString name = propertyTokens.takeFirst().toString(); - // Fix errors like "Q_PROPERTY(QXYSeries *series .." to be of type "QXYSeries*" - while (name.startsWith(QLatin1Char('*'))) { - fullTypeName += name.at(0); - name.remove(0, 1); - } - - int indirections = 0; - QString typeName = fullTypeName; - for (; typeName.endsWith(QLatin1Char('*')); ++indirections) - typeName.chop(1); - - QScopedPointer<AbstractMetaType> type; - QString typeError; - for (int j = scopes.size(); j >= 0 && type.isNull(); --j) { - QStringList qualifiedName = scopes.mid(0, j); - qualifiedName.append(typeName); - TypeInfo info; - info.setIndirections(indirections); - info.setQualifiedName(qualifiedName); - type.reset(translateType(info, metaClass, {}, &typeError)); - } - - if (!type) { - QTextStream str(errorMessage); - str << "Unable to decide type of property: \"" << name << "\" (" - << typeName << "): " << typeError; - return nullptr; - } - - QScopedPointer<QPropertySpec> spec(new QPropertySpec(type->typeEntry())); - spec->setName(name); - spec->setIndirections(indirections); - - for (int pos = 0; pos + 1 < propertyTokens.size(); pos += 2) { - if (propertyTokens.at(pos) == QLatin1String("READ")) - spec->setRead(propertyTokens.at(pos + 1).toString()); - else if (propertyTokens.at(pos) == QLatin1String("WRITE")) - spec->setWrite(propertyTokens.at(pos + 1).toString()); - else if (propertyTokens.at(pos) == QLatin1String("DESIGNABLE")) - spec->setDesignable(propertyTokens.at(pos + 1).toString()); - else if (propertyTokens.at(pos) == QLatin1String("RESET")) - spec->setReset(propertyTokens.at(pos + 1).toString()); - } - - if (!spec->isValid()) { - *errorMessage = QLatin1String("Incomplete specification"); - return nullptr; - } - return spec.take(); -} - static AbstractMetaFunction* findCopyCtor(AbstractMetaClass* cls) { diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h index 2867e5f74..671775130 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h @@ -126,8 +126,6 @@ public: void fixReturnTypeOfConversionOperator(AbstractMetaFunction *metaFunction); void parseQ_Properties(AbstractMetaClass *metaClass, const QStringList &declarations); - QPropertySpec *parseQ_Property(AbstractMetaClass *metaClass, const QString &declaration, - const QStringList &scopes, QString *errorMessage); void setupEquals(AbstractMetaClass *metaClass); void setupComparable(AbstractMetaClass *metaClass); void setupClonable(AbstractMetaClass *cls); diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index e93108be1..ff1bb53f2 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -28,6 +28,7 @@ #include "abstractmetalang.h" #include "messages.h" +#include "propertyspec.h" #include "reporthandler.h" #include "typedatabase.h" #include "typesystem.h" @@ -2794,34 +2795,3 @@ QString AbstractMetaEnum::package() const return m_typeEntry->targetLangPackage(); } -bool QPropertySpec::isValid() const -{ - return m_type != nullptr && !m_name.isEmpty() && !m_read.isEmpty(); -} - -#ifndef QT_NO_DEBUG_STREAM -void QPropertySpec::formatDebug(QDebug &d) const -{ - d << '#' << m_index << " \"" << m_name << "\" (" << m_type->qualifiedCppName(); - for (int i = 0; i < m_indirections; ++i) - d << '*'; - 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; -} - -QDebug operator<<(QDebug d, const QPropertySpec &p) -{ - QDebugStateSaver s(d); - d.noquote(); - d.nospace(); - d << "QPropertySpec("; - p.formatDebug(d); - d << ')'; - return d; -} -#endif // QT_NO_DEBUG_STREAM diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h index 2fe114de4..38ba316b7 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h @@ -1734,98 +1734,4 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaClass::FunctionQueryOptions) Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaClass::OperatorQueryOptions) -class QPropertySpec -{ -public: - explicit QPropertySpec(const TypeEntry *type) : m_type(type) {} - - bool isValid() const; - - const TypeEntry *type() const - { - return m_type; - } - - int indirections() const { return m_indirections; } - void setIndirections(int indirections) { m_indirections = indirections; } - - QString name() const - { - return m_name; - } - - void setName(const QString &name) - { - m_name = name; - } - - QString read() const - { - return m_read; - } - - void setRead(const QString &read) - { - m_read = read; - } - - QString write() const - { - return m_write; - } - - void setWrite(const QString &write) - { - m_write = write; - } - - QString designable() const - { - return m_designable; - } - - void setDesignable(const QString &designable) - { - m_designable = designable; - } - - QString reset() const - { - return m_reset; - } - - void setReset(const QString &reset) - { - m_reset = reset; - } - - int index() const - { - return m_index; - } - - void setIndex(int index) - { - m_index = index; - } - -#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; - const TypeEntry *m_type; - int m_indirections = 0; - int m_index = -1; -}; - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug d, const QPropertySpec &p); -#endif - #endif // ABSTRACTMETALANG_H diff --git a/sources/shiboken2/ApiExtractor/doxygenparser.cpp b/sources/shiboken2/ApiExtractor/doxygenparser.cpp index 9fceb4328..da6e32fba 100644 --- a/sources/shiboken2/ApiExtractor/doxygenparser.cpp +++ b/sources/shiboken2/ApiExtractor/doxygenparser.cpp @@ -29,6 +29,7 @@ #include "doxygenparser.h" #include "abstractmetalang.h" #include "messages.h" +#include "propertyspec.h" #include "reporthandler.h" #include "typesystem.h" #include "xmlutils.h" diff --git a/sources/shiboken2/ApiExtractor/propertyspec.cpp b/sources/shiboken2/ApiExtractor/propertyspec.cpp new file mode 100644 index 000000000..682a24473 --- /dev/null +++ b/sources/shiboken2/ApiExtractor/propertyspec.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "propertyspec.h" +#include "abstractmetalang.h" +#include "abstractmetabuilder_p.h" +#include "codemodel.h" +#include "typesystem.h" + +#ifndef QT_NO_DEBUG_STREAM +# include <QtCore/QDebug> +#endif + +bool QPropertySpec::isValid() const +{ + return m_type != nullptr && !m_name.isEmpty() && !m_read.isEmpty(); +} + +QPropertySpec *QPropertySpec::parseQ_Property(AbstractMetaBuilderPrivate *b, + AbstractMetaClass *metaClass, + const QString &declarationIn, + const QStringList &scopes, + QString *errorMessage) +{ + errorMessage->clear(); + + // Q_PROPERTY(QString objectName READ objectName WRITE setObjectName NOTIFY objectNameChanged) + + const QString declaration = declarationIn.simplified(); + auto propertyTokens = declaration.splitRef(QLatin1Char(' '), Qt::SkipEmptyParts); + if (propertyTokens.size() < 4) { + *errorMessage = QLatin1String("Insufficient number of tokens"); + return nullptr; + } + + QString fullTypeName = propertyTokens.takeFirst().toString(); + QString name = propertyTokens.takeFirst().toString(); + // Fix errors like "Q_PROPERTY(QXYSeries *series .." to be of type "QXYSeries*" + while (name.startsWith(QLatin1Char('*'))) { + fullTypeName += name.at(0); + name.remove(0, 1); + } + + int indirections = 0; + QString typeName = fullTypeName; + for (; typeName.endsWith(QLatin1Char('*')); ++indirections) + typeName.chop(1); + + QScopedPointer<AbstractMetaType> type; + QString typeError; + for (int j = scopes.size(); j >= 0 && type.isNull(); --j) { + QStringList qualifiedName = scopes.mid(0, j); + qualifiedName.append(typeName); + TypeInfo info; + info.setIndirections(indirections); + info.setQualifiedName(qualifiedName); + type.reset(b->translateType(info, metaClass, {}, &typeError)); + } + + if (!type) { + QTextStream str(errorMessage); + str << "Unable to decide type of property: \"" << name << "\" (" + << typeName << "): " << typeError; + return nullptr; + } + + QScopedPointer<QPropertySpec> spec(new QPropertySpec(type->typeEntry())); + spec->setName(name); + spec->setIndirections(indirections); + + for (int pos = 0; pos + 1 < propertyTokens.size(); pos += 2) { + if (propertyTokens.at(pos) == QLatin1String("READ")) + spec->setRead(propertyTokens.at(pos + 1).toString()); + else if (propertyTokens.at(pos) == QLatin1String("WRITE")) + spec->setWrite(propertyTokens.at(pos + 1).toString()); + else if (propertyTokens.at(pos) == QLatin1String("DESIGNABLE")) + spec->setDesignable(propertyTokens.at(pos + 1).toString()); + else if (propertyTokens.at(pos) == QLatin1String("RESET")) + spec->setReset(propertyTokens.at(pos + 1).toString()); + } + + if (!spec->isValid()) { + *errorMessage = QLatin1String("Incomplete specification"); + return nullptr; + } + return spec.take(); +} + +#ifndef QT_NO_DEBUG_STREAM +void QPropertySpec::formatDebug(QDebug &d) const +{ + d << '#' << m_index << " \"" << m_name << "\" (" << m_type->qualifiedCppName(); + for (int i = 0; i < m_indirections; ++i) + d << '*'; + 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; +} + +QDebug operator<<(QDebug d, const QPropertySpec &p) +{ + QDebugStateSaver s(d); + d.noquote(); + d.nospace(); + d << "QPropertySpec("; + p.formatDebug(d); + d << ')'; + return d; +} +#endif // QT_NO_DEBUG_STREAM diff --git a/sources/shiboken2/ApiExtractor/propertyspec.h b/sources/shiboken2/ApiExtractor/propertyspec.h new file mode 100644 index 000000000..9cf9310ec --- /dev/null +++ b/sources/shiboken2/ApiExtractor/propertyspec.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PROPERTYSPEC_H +#define PROPERTYSPEC_H + +#include <QtCore/QStringList> + +class AbstractMetaClass; +class AbstractMetaBuilderPrivate; +class TypeEntry; + +QT_FORWARD_DECLARE_CLASS(QDebug) + +class QPropertySpec +{ +public: + Q_DISABLE_COPY_MOVE(QPropertySpec) + + explicit QPropertySpec(const TypeEntry *type) : m_type(type) {} + + static QPropertySpec *parseQ_Property(AbstractMetaBuilderPrivate *b, + AbstractMetaClass *metaClass, + const QString &declarationIn, + const QStringList &scopes, + QString *errorMessage); + + bool isValid() const; + + const TypeEntry *type() const { return m_type; } + + int indirections() const { return m_indirections; } + void setIndirections(int indirections) { m_indirections = indirections; } + + QString name() const { return m_name; } + void setName(const QString &name) { m_name = name; } + + QString read() const { return m_read; } + void setRead(const QString &read) { m_read = read; } + + QString write() const { return m_write; } + void setWrite(const QString &write) { m_write = write; } + + QString designable() const { return m_designable; } + void setDesignable(const QString &designable) { m_designable = designable; } + + QString reset() const { return m_reset; } + void setReset(const QString &reset) { m_reset = reset; } + + int index() const { return m_index; } + void setIndex(int index) {m_index = index; } + +#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; + const TypeEntry *m_type; + int m_indirections = 0; + int m_index = -1; +}; + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug d, const QPropertySpec &p); +#endif + +#endif // PROPERTYSPEC_H diff --git a/sources/shiboken2/ApiExtractor/qtdocparser.cpp b/sources/shiboken2/ApiExtractor/qtdocparser.cpp index 512473131..40c04a403 100644 --- a/sources/shiboken2/ApiExtractor/qtdocparser.cpp +++ b/sources/shiboken2/ApiExtractor/qtdocparser.cpp @@ -29,6 +29,7 @@ #include "qtdocparser.h" #include "abstractmetalang.h" #include "messages.h" +#include "propertyspec.h" #include "reporthandler.h" #include "typesystem.h" #include "xmlutils.h" |