From b078890608344f0556a0ff50aab62ede83e0e180 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 30 Sep 2020 11:02:53 +0200 Subject: qmllint: Remove ComponentVersion QTypeRevision does all we need there. Change-Id: Ib27ae2d58167a7a45fac31262a45e387d047af89 Reviewed-by: Fabian Kosmale --- tools/qmllint/.prev_CMakeLists.txt | 1 - tools/qmllint/CMakeLists.txt | 1 - tools/shared/componentversion.cpp | 80 ---------------------------------- tools/shared/componentversion.h | 66 ---------------------------- tools/shared/qmljsimporter.cpp | 4 +- tools/shared/scopetree.cpp | 5 +-- tools/shared/scopetree.h | 8 ++-- tools/shared/shared.pri | 2 - tools/shared/typedescriptionreader.cpp | 25 ++++++++--- tools/shared/typedescriptionreader.h | 2 +- 10 files changed, 28 insertions(+), 166 deletions(-) delete mode 100644 tools/shared/componentversion.cpp delete mode 100644 tools/shared/componentversion.h (limited to 'tools') diff --git a/tools/qmllint/.prev_CMakeLists.txt b/tools/qmllint/.prev_CMakeLists.txt index cf5dc7e28e..3034d8699f 100644 --- a/tools/qmllint/.prev_CMakeLists.txt +++ b/tools/qmllint/.prev_CMakeLists.txt @@ -8,7 +8,6 @@ qt_get_tool_target_name(target_name qmllint) qt_add_tool(${target_name} TARGET_DESCRIPTION "QML Syntax Verifier" SOURCES - ../shared/componentversion.cpp ../shared/componentversion.h ../shared/importedmembersvisitor.cpp ../shared/importedmembersvisitor.h ../shared/metatypes.h ../shared/qmljsimporter.cpp ../shared/qmljsimporter.h diff --git a/tools/qmllint/CMakeLists.txt b/tools/qmllint/CMakeLists.txt index ba4cd62e65..e9d92cc134 100644 --- a/tools/qmllint/CMakeLists.txt +++ b/tools/qmllint/CMakeLists.txt @@ -9,7 +9,6 @@ qt_add_tool(${target_name} TARGET_DESCRIPTION "QML Syntax Verifier" TOOLS_TARGET Qml # special case SOURCES - ../shared/componentversion.cpp ../shared/componentversion.h ../shared/importedmembersvisitor.cpp ../shared/importedmembersvisitor.h ../shared/metatypes.h ../shared/qmljsimporter.cpp ../shared/qmljsimporter.h diff --git a/tools/shared/componentversion.cpp b/tools/shared/componentversion.cpp deleted file mode 100644 index 5019cdcc33..0000000000 --- a/tools/shared/componentversion.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $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 "componentversion.h" -#include - -ComponentVersion::ComponentVersion(const QString &versionString) -{ - const int dotIdx = versionString.indexOf(QLatin1Char('.')); - if (dotIdx == -1) - return; - bool ok = false; - const int maybeMajor = QStringView{versionString}.left(dotIdx).toInt(&ok); - if (!ok) - return; - const int maybeMinor = QStringView{versionString}.mid(dotIdx + 1).toInt(&ok); - if (!ok) - return; - m_version = QTypeRevision::fromVersion(maybeMajor, maybeMinor); -} - -bool operator<(const ComponentVersion &lhs, const ComponentVersion &rhs) -{ - return lhs.version().majorVersion() < rhs.version().majorVersion() - || (lhs.version().majorVersion() == rhs.version().majorVersion() - && lhs.version().minorVersion() < rhs.version().minorVersion()); -} - -bool operator<=(const ComponentVersion &lhs, const ComponentVersion &rhs) -{ - return lhs.version().majorVersion() < rhs.version().majorVersion() - || (lhs.version().majorVersion() == rhs.version().majorVersion() - && lhs.version().minorVersion() <= rhs.version().minorVersion()); -} - -bool operator>(const ComponentVersion &lhs, const ComponentVersion &rhs) -{ - return rhs < lhs; -} - -bool operator>=(const ComponentVersion &lhs, const ComponentVersion &rhs) -{ - return rhs <= lhs; -} - -bool operator==(const ComponentVersion &lhs, const ComponentVersion &rhs) -{ - return lhs.version().majorVersion() == rhs.version().majorVersion() - && lhs.version().minorVersion() == rhs.version().minorVersion(); -} - -bool operator!=(const ComponentVersion &lhs, const ComponentVersion &rhs) -{ - return !(lhs == rhs); -} diff --git a/tools/shared/componentversion.h b/tools/shared/componentversion.h deleted file mode 100644 index bbb039fc40..0000000000 --- a/tools/shared/componentversion.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $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 COMPONENTVERSION_H -#define COMPONENTVERSION_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#include -#include - -class ComponentVersion -{ -public: - ComponentVersion() = default; - ComponentVersion(QTypeRevision version) : m_version(version) {} - explicit ComponentVersion(const QString &versionString); - - QTypeRevision version() const { return m_version; } - bool isValid() const { return m_version.hasMajorVersion() && m_version.hasMinorVersion(); } - -private: - QTypeRevision m_version; -}; - -bool operator<(const ComponentVersion &lhs, const ComponentVersion &rhs); -bool operator<=(const ComponentVersion &lhs, const ComponentVersion &rhs); -bool operator>(const ComponentVersion &lhs, const ComponentVersion &rhs); -bool operator>=(const ComponentVersion &lhs, const ComponentVersion &rhs); -bool operator==(const ComponentVersion &lhs, const ComponentVersion &rhs); -bool operator!=(const ComponentVersion &lhs, const ComponentVersion &rhs); - -#endif // COMPONENTVERSION_H diff --git a/tools/shared/qmljsimporter.cpp b/tools/shared/qmljsimporter.cpp index b7de18e818..f2e8453c7c 100644 --- a/tools/shared/qmljsimporter.cpp +++ b/tools/shared/qmljsimporter.cpp @@ -98,9 +98,7 @@ QmlJSImporter::Import QmlJSImporter::readQmldir(const QString &path) if (mo == qmlComponents.end()) mo = qmlComponents.insert(it.key(), localFile2ScopeTree(filePath)); - (*mo)->addExport( - it.key(), reader.typeNamespace(), - ComponentVersion(it->version)); + (*mo)->addExport(it.key(), reader.typeNamespace(), it->version); } for (auto it = qmlComponents.begin(), end = qmlComponents.end(); it != end; ++it) result.objects.insert(it.key(), it.value()); diff --git a/tools/shared/scopetree.cpp b/tools/shared/scopetree.cpp index f55fd7d845..e7ce631b1d 100644 --- a/tools/shared/scopetree.cpp +++ b/tools/shared/scopetree.cpp @@ -168,8 +168,7 @@ ScopeTree::ConstPtr ScopeTree::findCurrentQMLScope(const ScopeTree::ConstPtr &sc return qmlScope; } -void ScopeTree::addExport(const QString &name, const QString &package, - const ComponentVersion &version) +void ScopeTree::addExport(const QString &name, const QString &package, const QTypeRevision &version) { m_exports.append(Export(package, name, version, 0)); } @@ -179,7 +178,7 @@ void ScopeTree::setExportMetaObjectRevision(int exportIndex, int metaObjectRevis m_exports[exportIndex].setMetaObjectRevision(metaObjectRevision); } -ScopeTree::Export::Export(QString package, QString type, const ComponentVersion &version, +ScopeTree::Export::Export(QString package, QString type, const QTypeRevision &version, int metaObjectRevision) : m_package(std::move(package)), m_type(std::move(type)), diff --git a/tools/shared/scopetree.h b/tools/shared/scopetree.h index d87422224c..37eee26d16 100644 --- a/tools/shared/scopetree.h +++ b/tools/shared/scopetree.h @@ -40,13 +40,13 @@ // We mean it. #include "metatypes.h" -#include "componentversion.h" #include #include #include #include +#include enum class ScopeType { @@ -88,7 +88,7 @@ public: class Export { public: Export() = default; - Export(QString package, QString type, const ComponentVersion &version, + Export(QString package, QString type, const QTypeRevision &version, int metaObjectRevision); bool isValid() const; @@ -105,7 +105,7 @@ public: private: QString m_package; QString m_type; - ComponentVersion m_version; + QTypeRevision m_version; int m_metaObjectRevision = 0; }; @@ -145,7 +145,7 @@ public: QString internalName() const { return m_internalName; } void setInternalName(const QString &internalName) { m_internalName = internalName; } - void addExport(const QString &name, const QString &package, const ComponentVersion &version); + void addExport(const QString &name, const QString &package, const QTypeRevision &version); void setExportMetaObjectRevision(int exportIndex, int metaObjectRevision); QList exports() const { return m_exports; } diff --git a/tools/shared/shared.pri b/tools/shared/shared.pri index b7eb2ec6c1..181cda3e8b 100644 --- a/tools/shared/shared.pri +++ b/tools/shared/shared.pri @@ -10,7 +10,6 @@ RESOURCEFILEMAPPER_HEADERS = \ $$PWD/resourcefilemapper.h METATYPEREADER_SOURCES = \ - $$PWD/componentversion.cpp \ $$PWD/importedmembersvisitor.cpp \ $$PWD/qmljsimporter.cpp \ $$PWD/qmljstypereader.cpp \ @@ -18,7 +17,6 @@ METATYPEREADER_SOURCES = \ $$PWD/typedescriptionreader.cpp METATYPEREADER_HEADERS = \ - $$PWD/componentversion.h \ $$PWD/importedmembersvisitor.h \ $$PWD/qmljsimporter.h \ $$PWD/qmljstypereader.h \ diff --git a/tools/shared/typedescriptionreader.cpp b/tools/shared/typedescriptionreader.cpp index 3691fa080c..f95e4453b3 100644 --- a/tools/shared/typedescriptionreader.cpp +++ b/tools/shared/typedescriptionreader.cpp @@ -492,9 +492,24 @@ double TypeDescriptionReader::readNumericBinding(UiScriptBinding *ast) return numericLit->value; } -ComponentVersion TypeDescriptionReader::readNumericVersionBinding(UiScriptBinding *ast) +static QTypeRevision parseVersion(const QString &versionString) { - ComponentVersion invalidVersion; + const int dotIdx = versionString.indexOf(QLatin1Char('.')); + if (dotIdx == -1) + return QTypeRevision(); + bool ok = false; + const int maybeMajor = QStringView{versionString}.left(dotIdx).toInt(&ok); + if (!ok) + return QTypeRevision(); + const int maybeMinor = QStringView{versionString}.mid(dotIdx + 1).toInt(&ok); + if (!ok) + return QTypeRevision(); + return QTypeRevision::fromVersion(maybeMajor, maybeMinor); +} + +QTypeRevision TypeDescriptionReader::readNumericVersionBinding(UiScriptBinding *ast) +{ + QTypeRevision invalidVersion; if (!ast || !ast->statement) { addError((ast ? ast->colonToken : SourceLocation()), @@ -515,8 +530,8 @@ ComponentVersion TypeDescriptionReader::readNumericVersionBinding(UiScriptBindin return invalidVersion; } - return ComponentVersion(m_source.mid(numericLit->literalToken.begin(), - numericLit->literalToken.length)); + return parseVersion(m_source.mid(numericLit->literalToken.begin(), + numericLit->literalToken.length)); } int TypeDescriptionReader::readIntBinding(UiScriptBinding *ast) @@ -564,7 +579,7 @@ void TypeDescriptionReader::readExports(UiScriptBinding *ast, const ScopeTree::P QString exp = stringLit->value.toString(); int slashIdx = exp.indexOf(QLatin1Char('/')); int spaceIdx = exp.indexOf(QLatin1Char(' ')); - ComponentVersion version(exp.mid(spaceIdx + 1)); + const QTypeRevision version = parseVersion(exp.mid(spaceIdx + 1)); if (spaceIdx == -1 || !version.isValid()) { addError(stringLit->firstSourceLocation(), diff --git a/tools/shared/typedescriptionreader.h b/tools/shared/typedescriptionreader.h index bf0fd43eae..8395f09bc4 100644 --- a/tools/shared/typedescriptionreader.h +++ b/tools/shared/typedescriptionreader.h @@ -75,7 +75,7 @@ private: QString readStringBinding(QQmlJS::AST::UiScriptBinding *ast); bool readBoolBinding(QQmlJS::AST::UiScriptBinding *ast); double readNumericBinding(QQmlJS::AST::UiScriptBinding *ast); - ComponentVersion readNumericVersionBinding(QQmlJS::AST::UiScriptBinding *ast); + QTypeRevision readNumericVersionBinding(QQmlJS::AST::UiScriptBinding *ast); int readIntBinding(QQmlJS::AST::UiScriptBinding *ast); void readExports(QQmlJS::AST::UiScriptBinding *ast, const ScopeTree::Ptr &scope); void readMetaObjectRevisions(QQmlJS::AST::UiScriptBinding *ast, const ScopeTree::Ptr &scope); -- cgit v1.2.3