diff options
Diffstat (limited to 'sources/shiboken6/tests/dumpcodemodel/main.cpp')
-rw-r--r-- | sources/shiboken6/tests/dumpcodemodel/main.cpp | 104 |
1 files changed, 41 insertions, 63 deletions
diff --git a/sources/shiboken6/tests/dumpcodemodel/main.cpp b/sources/shiboken6/tests/dumpcodemodel/main.cpp index 527a81262..eb876634c 100644 --- a/sources/shiboken6/tests/dumpcodemodel/main.cpp +++ b/sources/shiboken6/tests/dumpcodemodel/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite 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$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include <abstractmetabuilder_p.h> #include <parser/codemodel.h> @@ -37,6 +12,7 @@ #include <QtCore/QDebug> #include <QtCore/QDir> #include <QtCore/QFile> +#include <QtCore/QLibraryInfo> #include <QtCore/QVersionNumber> #include <QtCore/QXmlStreamWriter> @@ -44,13 +20,15 @@ #include <algorithm> #include <iterator> +using namespace Qt::StringLiterals; + static bool optJoinNamespaces = false; static inline QString languageLevelDescription() { - return QLatin1String("C++ Language level (c++11..c++17, default=") - + QLatin1String(clang::languageLevelOption(clang::emulatedCompilerLanguageLevel())) - + QLatin1Char(')'); + return u"C++ Language level (c++11..c++20, default="_s + + QLatin1StringView(clang::languageLevelOption(clang::emulatedCompilerLanguageLevel())) + + u')'; } static void formatDebugOutput(const FileModelItem &dom, bool verbose) @@ -60,7 +38,7 @@ static void formatDebugOutput(const FileModelItem &dom, bool verbose) QDebug debug(&output); if (verbose) debug.setVerbosity(3); - debug << dom.data(); + debug << dom.get(); } std::cout << qPrintable(output) << '\n'; } @@ -70,14 +48,14 @@ static const char *primitiveTypes[] = { "float", "double" }; -static inline QString nameAttribute() { return QStringLiteral("name"); } +constexpr auto nameAttribute = "name"_L1; static void formatXmlClass(QXmlStreamWriter &writer, const ClassModelItem &klass); static void formatXmlEnum(QXmlStreamWriter &writer, const EnumModelItem &en) { - writer.writeStartElement(QStringLiteral("enum-type")); - writer.writeAttribute(nameAttribute(), en->name()); + writer.writeStartElement(u"enum-type"_s); + writer.writeAttribute(nameAttribute, en->name()); writer.writeEndElement(); } @@ -117,9 +95,9 @@ static void formatXmlClass(QXmlStreamWriter &writer, const ClassModelItem &klass const bool isValueType = std::any_of(functions.cbegin(), functions.cend(), isPublicCopyConstructor); formatXmlLocationComment(writer, klass); - writer.writeStartElement(isValueType ? QStringLiteral("value-type") - : QStringLiteral("object-type")); - writer.writeAttribute(nameAttribute(), klass->name()); + writer.writeStartElement(isValueType ? u"value-type"_s + : u"object-type"_s); + writer.writeAttribute(nameAttribute, klass->name()); formatXmlScopeMembers(writer, klass); writer.writeEndElement(); } @@ -139,14 +117,14 @@ static bool hasMembers(const NamespaceModelItem &nsp) static void startXmlNamespace(QXmlStreamWriter &writer, const NamespaceModelItem &nsp) { formatXmlLocationComment(writer, nsp); - writer.writeStartElement(QStringLiteral("namespace-type")); - writer.writeAttribute(nameAttribute(), nsp->name()); + writer.writeStartElement(u"namespace-type"_s); + writer.writeAttribute(nameAttribute, nsp->name()); } static void formatXmlNamespaceMembers(QXmlStreamWriter &writer, const NamespaceModelItem &nsp) { auto nestedNamespaces = nsp->namespaces(); - for (int i = nestedNamespaces.size() - 1; i >= 0; --i) { + for (auto i = nestedNamespaces.size() - 1; i >= 0; --i) { if (!hasMembers(nestedNamespaces.at(i))) nestedNamespaces.removeAt(i); } @@ -157,7 +135,7 @@ static void formatXmlNamespaceMembers(QXmlStreamWriter &writer, const NamespaceM if (optJoinNamespaces) { // Write out members of identical namespaces and remove const QString name = current->name(); - for (int i = 0; i < nestedNamespaces.size(); ) { + for (qsizetype i = 0; i < nestedNamespaces.size(); ) { if (nestedNamespaces.at(i)->name() == name) { formatXmlNamespaceMembers(writer, nestedNamespaces.at(i)); nestedNamespaces.removeAt(i); @@ -171,9 +149,9 @@ static void formatXmlNamespaceMembers(QXmlStreamWriter &writer, const NamespaceM for (const auto &func : nsp->functions()) { const QString signature = func->typeSystemSignature(); - if (!signature.contains(QLatin1String("operator"))) { // Skip free operators - writer.writeStartElement(QStringLiteral("function")); - writer.writeAttribute(QStringLiteral("signature"), signature); + if (!signature.contains(u"operator")) { // Skip free operators + writer.writeStartElement(u"function"_s); + writer.writeAttribute(u"signature"_s, signature); writer.writeEndElement(); } } @@ -186,13 +164,13 @@ static void formatXmlOutput(const FileModelItem &dom) QXmlStreamWriter writer(&output); writer.setAutoFormatting(true); writer.writeStartDocument(); - writer.writeStartElement(QStringLiteral("typesystem")); - writer.writeAttribute(QStringLiteral("package"), QStringLiteral("insert_name")); - writer.writeComment(QStringLiteral("Auto-generated ") + + writer.writeStartElement(u"typesystem"_s); + writer.writeAttribute(u"package"_s, u"insert_name"_s); + writer.writeComment(u"Auto-generated "_s + QDateTime::currentDateTime().toString(Qt::ISODate)); for (auto p : primitiveTypes) { - writer.writeStartElement(QStringLiteral("primitive-type")); - writer.writeAttribute(nameAttribute(), QLatin1String(p)); + writer.writeStartElement(u"primitive-type"_s); + writer.writeAttribute(nameAttribute, QLatin1StringView(p)); writer.writeEndElement(); } formatXmlNamespaceMembers(writer, dom); @@ -220,29 +198,29 @@ int main(int argc, char **argv) parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments); const QString description = - QString::fromLatin1(descriptionFormat).arg(QLatin1String(qVersion()), + QString::fromLatin1(descriptionFormat).arg(QLatin1StringView(qVersion()), clang::libClangVersion().toString()); parser.setApplicationDescription(description); parser.addHelpOption(); parser.addVersionOption(); - QCommandLineOption verboseOption(QStringLiteral("verbose"), - QStringLiteral("Display verbose output about types")); + QCommandLineOption verboseOption(u"verbose"_s, + u"Display verbose output about types"_s); parser.addOption(verboseOption); - QCommandLineOption debugOption(QStringLiteral("debug"), - QStringLiteral("Display debug output")); + QCommandLineOption debugOption(u"debug"_s, + u"Display debug output"_s); parser.addOption(debugOption); - QCommandLineOption joinNamespacesOption({QStringLiteral("j"), QStringLiteral("join-namespaces")}, - QStringLiteral("Join namespaces")); + QCommandLineOption joinNamespacesOption({u"j"_s, u"join-namespaces"_s}, + u"Join namespaces"_s); parser.addOption(joinNamespacesOption); - QCommandLineOption languageLevelOption(QStringLiteral("std"), + QCommandLineOption languageLevelOption(u"std"_s, languageLevelDescription(), - QStringLiteral("level")); + u"level"_s); parser.addOption(languageLevelOption); - parser.addPositionalArgument(QStringLiteral("argument"), - QStringLiteral("C++ compiler argument"), - QStringLiteral("argument(s)")); + parser.addPositionalArgument(u"argument"_s, + u"C++ compiler argument"_s, + u"argument(s)"_s); parser.process(app); const QStringList &positionalArguments = parser.positionalArguments(); @@ -267,8 +245,8 @@ int main(int argc, char **argv) optJoinNamespaces = parser.isSet(joinNamespacesOption); const FileModelItem dom = AbstractMetaBuilderPrivate::buildDom(arguments, true, level, 0); - if (dom.isNull()) { - QString message = QLatin1String("Unable to parse ") + positionalArguments.join(QLatin1Char(' ')); + if (!dom) { + QString message = u"Unable to parse "_s + positionalArguments.join(u' '); std::cerr << qPrintable(message) << '\n'; return -2; } |