diff options
Diffstat (limited to 'src/tools/moc/moc.cpp')
-rw-r--r-- | src/tools/moc/moc.cpp | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 726d1972f1..0e689bd5c1 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 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:LGPL21$ +** $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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** 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$ ** @@ -543,7 +538,7 @@ bool Moc::parseMaybeFunction(const ClassDef *cdef, FunctionDef *def) void Moc::parse() { - QList<NamespaceDef> namespaceList; + QVector<NamespaceDef> namespaceList; bool templateClass = false; while (hasNext()) { Token t = next(); @@ -806,9 +801,30 @@ void Moc::parse() } } -static void findRequiredContainers(ClassDef *cdef, QSet<QByteArray> *requiredQtContainers) +static bool any_type_contains(const QVector<PropertyDef> &properties, const QByteArray &pattern) +{ + for (const auto &p : properties) { + if (p.type.contains(pattern)) + return true; + } + return false; +} + +static bool any_arg_contains(const QVector<FunctionDef> &functions, const QByteArray &pattern) { - static const QVector<QByteArray> candidates = QVector<QByteArray>() + for (const auto &f : functions) { + for (const auto &arg : f.arguments) { + if (arg.normalizedType.contains(pattern)) + return true; + } + } + return false; +} + +static QByteArrayList make_candidates() +{ + QByteArrayList result; + result #define STREAM_SMART_POINTER(SMART_POINTER) << #SMART_POINTER QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(STREAM_SMART_POINTER) #undef STREAM_SMART_POINTER @@ -816,26 +832,31 @@ static void findRequiredContainers(ClassDef *cdef, QSet<QByteArray> *requiredQtC QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE) #undef STREAM_1ARG_TEMPLATE ; + return result; +} - for (int i = 0; i < cdef->propertyList.count(); ++i) { - const PropertyDef &p = cdef->propertyList.at(i); - foreach (const QByteArray &candidate, candidates) { - if (p.type.contains(candidate + "<")) - requiredQtContainers->insert(candidate); - } - } +static QByteArrayList requiredQtContainers(const QVector<ClassDef> &classes) +{ + static const QByteArrayList candidates = make_candidates(); + + QByteArrayList required; + required.reserve(candidates.size()); - QList<FunctionDef> allFunctions = cdef->slotList + cdef->signalList + cdef->methodList; + for (const auto &candidate : candidates) { + const QByteArray pattern = candidate + '<'; - for (int i = 0; i < allFunctions.count(); ++i) { - const FunctionDef &f = allFunctions.at(i); - foreach (const ArgumentDef &arg, f.arguments) { - foreach (const QByteArray &candidate, candidates) { - if (arg.normalizedType.contains(candidate + "<")) - requiredQtContainers->insert(candidate); + for (const auto &c : classes) { + if (any_type_contains(c.propertyList, pattern) || + any_arg_contains(c.slotList, pattern) || + any_arg_contains(c.signalList, pattern) || + any_arg_contains(c.methodList, pattern)) { + required.push_back(candidate); + break; } } } + + return required; } void Moc::generate(FILE *out) @@ -874,19 +895,9 @@ void Moc::generate(FILE *out) if (mustIncludeQPluginH) fprintf(out, "#include <QtCore/qplugin.h>\n"); - QSet<QByteArray> requiredQtContainers; - for (i = 0; i < classList.size(); ++i) { - findRequiredContainers(&classList[i], &requiredQtContainers); - } - - // after finding the containers, we sort them into a list to avoid - // non-deterministic behavior which may cause rebuilds unnecessarily. - QList<QByteArray> requiredContainerList = requiredQtContainers.toList(); - std::sort(requiredContainerList.begin(), requiredContainerList.end()); - - foreach (const QByteArray &qtContainer, requiredContainerList) { + const auto qtContainers = requiredQtContainers(classList); + for (const QByteArray &qtContainer : qtContainers) fprintf(out, "#include <QtCore/%s>\n", qtContainer.constData()); - } fprintf(out, "#if !defined(Q_MOC_OUTPUT_REVISION)\n" @@ -1308,7 +1319,7 @@ void Moc::parseInterfaces(ClassDef *def) { next(LPAREN); while (test(IDENTIFIER)) { - QList<ClassDef::Interface> iface; + QVector<ClassDef::Interface> iface; iface += ClassDef::Interface(lexem()); while (test(SCOPE)) { iface.last().className += lexem(); @@ -1444,7 +1455,7 @@ bool Moc::until(Token target) { case LPAREN: ++parenCount; break; case RPAREN: --parenCount; break; case LANGLE: - if (parenCount == 0 && braceCount == 0 && parenCount == 0) + if (parenCount == 0 && braceCount == 0) ++angleCount; break; case RANGLE: |