diff options
Diffstat (limited to 'src/tools/moc/generator.cpp')
-rw-r--r-- | src/tools/moc/generator.cpp | 97 |
1 files changed, 50 insertions, 47 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 99629f0427..7de6fe632f 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1,32 +1,27 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com> -** Contact: http://www.qt.io/licensing/ +** 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$ ** @@ -84,7 +79,7 @@ Generator::Generator(ClassDef *classDef, const QList<QByteArray> &metaTypes, con , knownGadgets(knownGadgets) { if (cdef->superclassList.size()) - purestSuperClass = cdef->superclassList.first().first; + purestSuperClass = cdef->superclassList.constFirst().first; } static inline int lengthOfEscapeSequence(const QByteArray &s, int i) @@ -126,7 +121,7 @@ int Generator::stridx(const QByteArray &s) // Returns the sum of all parameters (including return type) for the given // \a list of methods. This is needed for calculating the size of the methods' // parameter type/name meta-data. -static int aggregateParameterCount(const QList<FunctionDef> &list) +static int aggregateParameterCount(const QVector<FunctionDef> &list) { int sum = 0; for (int i = 0; i < list.count(); ++i) @@ -155,16 +150,17 @@ bool Generator::registerableMetaType(const QByteArray &propertyType) #undef STREAM_SMART_POINTER ; - foreach (const QByteArray &smartPointer, smartPointers) + for (const QByteArray &smartPointer : smartPointers) { if (propertyType.startsWith(smartPointer + "<") && !propertyType.endsWith("&")) return knownQObjectClasses.contains(propertyType.mid(smartPointer.size() + 1, propertyType.size() - smartPointer.size() - 1 - 1)); + } static const QVector<QByteArray> oneArgTemplates = QVector<QByteArray>() #define STREAM_1ARG_TEMPLATE(TEMPLATENAME) << #TEMPLATENAME QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE) #undef STREAM_1ARG_TEMPLATE ; - foreach (const QByteArray &oneArgTemplateType, oneArgTemplates) + for (const QByteArray &oneArgTemplateType : oneArgTemplates) { if (propertyType.startsWith(oneArgTemplateType + "<") && propertyType.endsWith(">")) { const int argumentSize = propertyType.size() - oneArgTemplateType.size() - 1 // The closing '>' @@ -174,6 +170,7 @@ bool Generator::registerableMetaType(const QByteArray &propertyType) const QByteArray templateArg = propertyType.mid(oneArgTemplateType.size() + 1, argumentSize); return isBuiltinType(templateArg) || registerableMetaType(templateArg); } + } return false; } @@ -197,7 +194,7 @@ void Generator::generateCode() // filter out undeclared enumerators and sets { - QList<EnumDef> enumList; + QVector<EnumDef> enumList; for (int i = 0; i < cdef->enumList.count(); ++i) { EnumDef def = cdef->enumList.at(i); if (cdef->enumDeclarations.contains(def.name)) { @@ -502,9 +499,9 @@ void Generator::generateCode() // QTBUG-20639 - Accept non-local enums for QML signal/slot parameters. // Look for any scoped enum declarations, and add those to the list // of extra/related metaobjects for this object. - QList<QByteArray> enumKeys = cdef->enumDeclarations.keys(); - for (int i = 0; i < enumKeys.count(); ++i) { - const QByteArray &enumKey = enumKeys[i]; + for (auto it = cdef->enumDeclarations.keyBegin(), + end = cdef->enumDeclarations.keyEnd(); it != end; ++it) { + const QByteArray &enumKey = *it; int s = enumKey.lastIndexOf("::"); if (s > 0) { QByteArray scope = enumKey.left(s); @@ -574,7 +571,7 @@ void Generator::generateCode() cname, cname, cdef->classname.constData()); } for (int i = 0; i < cdef->interfaceList.size(); ++i) { - const QList<ClassDef::Interface> &iface = cdef->interfaceList.at(i); + const QVector<ClassDef::Interface> &iface = cdef->interfaceList.at(i); for (int j = 0; j < iface.size(); ++j) { fprintf(out, " if (!strcmp(_clname, %s))\n return ", iface.at(j).interfaceId.constData()); for (int k = j; k >= 0; --k) @@ -631,7 +628,7 @@ void Generator::generateClassInfos() } } -void Generator::registerFunctionStrings(const QList<FunctionDef>& list) +void Generator::registerFunctionStrings(const QVector<FunctionDef>& list) { for (int i = 0; i < list.count(); ++i) { const FunctionDef &f = list.at(i); @@ -651,7 +648,7 @@ void Generator::registerFunctionStrings(const QList<FunctionDef>& list) } } -void Generator::generateFunctions(const QList<FunctionDef>& list, const char *functype, int type, int ¶msIndex) +void Generator::generateFunctions(const QVector<FunctionDef>& list, const char *functype, int type, int ¶msIndex) { if (list.isEmpty()) return; @@ -697,7 +694,7 @@ void Generator::generateFunctions(const QList<FunctionDef>& list, const char *fu } } -void Generator::generateFunctionRevisions(const QList<FunctionDef>& list, const char *functype) +void Generator::generateFunctionRevisions(const QVector<FunctionDef>& list, const char *functype) { if (list.count()) fprintf(out, "\n // %ss: revision\n", functype); @@ -707,7 +704,7 @@ void Generator::generateFunctionRevisions(const QList<FunctionDef>& list, const } } -void Generator::generateFunctionParameters(const QList<FunctionDef>& list, const char *functype) +void Generator::generateFunctionParameters(const QVector<FunctionDef>& list, const char *functype) { if (list.isEmpty()) return; @@ -920,7 +917,7 @@ void Generator::generateMetacall() fprintf(out, " "); bool needElse = false; - QList<FunctionDef> methodList; + QVector<FunctionDef> methodList; methodList += cdef->signalList; methodList += cdef->slotList; methodList += cdef->methodList; @@ -1082,7 +1079,7 @@ QMultiMap<QByteArray, int> Generator::automaticPropertyMetaTypesHelper() return automaticPropertyMetaTypes; } -QMap<int, QMultiMap<QByteArray, int> > Generator::methodsWithAutomaticTypesHelper(const QList<FunctionDef> &methodList) +QMap<int, QMultiMap<QByteArray, int> > Generator::methodsWithAutomaticTypesHelper(const QVector<FunctionDef> &methodList) { QMap<int, QMultiMap<QByteArray, int> > methodsWithAutomaticTypes; for (int i = 0; i < methodList.size(); ++i) { @@ -1136,7 +1133,7 @@ void Generator::generateStaticMetacall() isUsed_a = true; } - QList<FunctionDef> methodList; + QVector<FunctionDef> methodList; methodList += cdef->signalList; methodList += cdef->slotList; methodList += cdef->methodList; @@ -1207,10 +1204,14 @@ void Generator::generateStaticMetacall() fprintf(out, " case %d:\n", it.key()); fprintf(out, " switch (*reinterpret_cast<int*>(_a[1])) {\n"); fprintf(out, " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n"); - foreach (const QByteArray &key, it->uniqueKeys()) { - foreach (int argumentID, it->values(key)) - fprintf(out, " case %d:\n", argumentID); - fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", key.constData()); + auto jt = it->begin(); + const auto jend = it->end(); + while (jt != jend) { + fprintf(out, " case %d:\n", jt.value()); + const QByteArray &lastKey = jt.key(); + ++jt; + if (jt == jend || jt.key() != lastKey) + fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", lastKey.constData()); } fprintf(out, " }\n"); fprintf(out, " break;\n"); @@ -1263,7 +1264,7 @@ void Generator::generateStaticMetacall() needElse = true; } - QMultiMap<QByteArray, int> automaticPropertyMetaTypes = automaticPropertyMetaTypesHelper(); + const QMultiMap<QByteArray, int> automaticPropertyMetaTypes = automaticPropertyMetaTypesHelper(); if (!automaticPropertyMetaTypes.isEmpty()) { if (needElse) @@ -1273,10 +1274,14 @@ void Generator::generateStaticMetacall() fprintf(out, "if (_c == QMetaObject::RegisterPropertyMetaType) {\n"); fprintf(out, " switch (_id) {\n"); fprintf(out, " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n"); - foreach (const QByteArray &key, automaticPropertyMetaTypes.uniqueKeys()) { - foreach (int propertyID, automaticPropertyMetaTypes.values(key)) - fprintf(out, " case %d:\n", propertyID); - fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", key.constData()); + auto it = automaticPropertyMetaTypes.begin(); + const auto end = automaticPropertyMetaTypes.end(); + while (it != end) { + fprintf(out, " case %d:\n", it.value()); + const QByteArray &lastKey = it.key(); + ++it; + if (it == end || it.key() != lastKey) + fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", lastKey.constData()); } fprintf(out, " }\n"); fprintf(out, " }\n"); @@ -1461,9 +1466,7 @@ void Generator::generateSignal(FunctionDef *def,int index) const char *constQualifier = ""; if (def->isConst) { - thisPtr = "const_cast< "; - thisPtr += cdef->qualified; - thisPtr += " *>(this)"; + thisPtr = "const_cast< " + cdef->qualified + " *>(this)"; constQualifier = "const"; } @@ -1567,8 +1570,8 @@ void Generator::generatePluginMetaData() data.insert(QStringLiteral("MetaData"), cdef->pluginData.metaData.object()); // Add -M args from the command line: - foreach (const QString &key, cdef->pluginData.metaArgs.keys()) - data.insert(key, cdef->pluginData.metaArgs.value(key)); + for (auto it = cdef->pluginData.metaArgs.cbegin(), end = cdef->pluginData.metaArgs.cend(); it != end; ++it) + data.insert(it.key(), it.value()); fputs("\nQT_PLUGIN_METADATA_SECTION const uint qt_section_alignment_dummy = 42;\n\n" "#ifdef QT_NO_DEBUG\n", out); |