diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qml/main.cpp | 32 | ||||
-rw-r--r-- | tools/qmlcachegen/qmlcache.prf | 12 | ||||
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.cpp | 312 | ||||
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.pro | 24 | ||||
-rw-r--r-- | tools/qmleasing/mainwindow.cpp | 3 | ||||
-rw-r--r-- | tools/qmleasing/mainwindow.h | 6 | ||||
-rw-r--r-- | tools/qmleasing/splineeditor.cpp | 4 | ||||
-rw-r--r-- | tools/qmleasing/splineeditor.h | 10 | ||||
-rw-r--r-- | tools/qmlimportscanner/main.cpp | 14 | ||||
-rw-r--r-- | tools/qmljs/qmljs.cpp | 12 | ||||
-rw-r--r-- | tools/qmllint/main.cpp | 12 | ||||
-rw-r--r-- | tools/qmlplugindump/main.cpp | 53 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerclient.h | 26 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerdata.cpp | 10 | ||||
-rw-r--r-- | tools/qmltime/qmltime.cpp | 2 | ||||
-rw-r--r-- | tools/tools.pro | 5 |
16 files changed, 442 insertions, 95 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 31fd9b383f..e8a506264c 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -46,7 +46,6 @@ #include <QDir> #include <QFile> #include <QFileInfo> -#include <QRegularExpression> #include <QStringList> #include <QScopedPointer> #include <QDebug> @@ -464,7 +463,7 @@ int main(int argc, char *argv[]) QString dummyDir; //Handle main arguments - QStringList argList = app->arguments(); + const QStringList argList = app->arguments(); for (int i = 1; i < argList.count(); i++) { const QString &arg = argList[i]; if (arg == QLatin1String("-quiet")) @@ -568,29 +567,14 @@ int main(int argc, char *argv[]) loadDummyDataFiles(e, dummyDir); for (const QString &path : qAsConst(files)) { - //QUrl::fromUserInput doesn't treat no scheme as relative file paths -#if QT_CONFIG(regularexpression) - QRegularExpression urlRe("[[:word:]]+://.*"); - if (urlRe.match(path).hasMatch()) { //Treat as a URL - QUrl url = QUrl::fromUserInput(path); - if (verboseMode) - printf("qml: loading %s\n", - qPrintable(url.isLocalFile() - ? QDir::toNativeSeparators(url.toLocalFile()) - : url.toString())); + QUrl url = QUrl::fromUserInput(path, QDir::currentPath()); + if (verboseMode) + printf("qml: loading %s\n", qPrintable(url.toString())); + QByteArray strippedFile; + if (getFileSansBangLine(path, strippedFile)) + e.loadData(strippedFile, e.baseUrl().resolved(url)); //QQmlComponent won't resolve it for us, it doesn't know it's a valid file if we loadData + else //Errors or no bang line e.load(url); - } else -#endif - { //Local file path - if (verboseMode) - printf("qml: loading %s\n", qPrintable(QDir::toNativeSeparators(path))); - - QByteArray strippedFile; - if (getFileSansBangLine(path, strippedFile)) - e.loadData(strippedFile, e.baseUrl().resolved(QUrl::fromLocalFile(path))); //QQmlComponent won't resolve it for us, it doesn't know it's a valid file if we loadData - else //Errors or no bang line - e.load(path); - } } if (lw->earlyExit) diff --git a/tools/qmlcachegen/qmlcache.prf b/tools/qmlcachegen/qmlcache.prf new file mode 100644 index 0000000000..fed9f0d2f3 --- /dev/null +++ b/tools/qmlcachegen/qmlcache.prf @@ -0,0 +1,12 @@ +qtPrepareTool(QML_CACHEGEN, qmlcachegen) + +!isEmpty(QT_TARGET_ARCH):QML_CACHEGEN_ARCH=$$QT_TARGET_ARCH +else:QML_CACHEGEN_ARCH=$$QT_ARCH + +qmlcachegen.input = QML_FILES +qmlcachegen.output = ${QMAKE_FILE_IN}c +qmlcachegen.commands = $$QML_CACHEGEN --target-architecture=$$QML_CACHEGEN_ARCH ${QMAKE_FILE_IN} +qmlcachegen.name = Generate QML Cache ${QMAKE_FILE_IN} +qmlcachegen.variable_out = AUX_QML_FILES + +QMAKE_EXTRA_COMPILERS += qmlcachegen diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp new file mode 100644 index 0000000000..977c5b6ff1 --- /dev/null +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -0,0 +1,312 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQml module 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 <QCoreApplication> +#include <QStringList> +#include <QCommandLineParser> +#include <QFile> +#include <QFileInfo> +#include <QDateTime> + +#include <private/qqmlirbuilder_p.h> +#include <private/qv4isel_moth_p.h> +#include <private/qqmljsparser_p.h> + +QT_BEGIN_NAMESPACE +extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed; + +namespace QV4 { namespace JIT { +Q_QML_EXPORT QV4::EvalISelFactory *createISelForArchitecture(const QString &architecture); +} } + +QT_END_NAMESPACE + +struct Error +{ + QString message; + void print(); + Error augment(const QString &contextErrorMessage) const; +}; + +void Error::print() +{ + fprintf(stderr, "%s\n", qPrintable(message)); +} + +Error Error::augment(const QString &contextErrorMessage) const +{ + Error augmented; + augmented.message = contextErrorMessage + message; + return augmented; +} + +QString diagnosticErrorMessage(const QString &fileName, const QQmlJS::DiagnosticMessage &m) +{ + QString message; + message = fileName + QLatin1Char(':') + QString::number(m.loc.startLine) + QLatin1Char(':'); + if (m.loc.startColumn > 0) + message += QString::number(m.loc.startColumn) + QLatin1Char(':'); + + if (m.isError()) + message += QLatin1String(" error: "); + else + message += QLatin1String(" warning: "); + message += m.message; + return message; +} + +static bool compileQmlFile(const QString &inputFileName, QV4::EvalISelFactory *iselFactory, Error *error) +{ + QmlIR::Document irDocument(/*debugMode*/false); + + QString sourceCode; + { + QFile f(inputFileName); + if (!f.open(QIODevice::ReadOnly)) { + error->message = QLatin1String("Error opening ") + inputFileName + QLatin1Char(':') + f.errorString(); + return false; + } + sourceCode = QString::fromUtf8(f.readAll()); + if (f.error() != QFileDevice::NoError) { + error->message = QLatin1String("Error reading from ") + inputFileName + QLatin1Char(':') + f.errorString(); + return false; + } + irDocument.jsModule.sourceTimeStamp = QFileInfo(f).lastModified().toMSecsSinceEpoch(); + } + + { + QSet<QString> illegalNames; // #### + QmlIR::IRBuilder irBuilder(illegalNames); + if (!irBuilder.generateFromQml(sourceCode, inputFileName, &irDocument)) { + for (const QQmlJS::DiagnosticMessage &parseError: qAsConst(irBuilder.errors)) { + if (!error->message.isEmpty()) + error->message += QLatin1Char('\n'); + error->message += diagnosticErrorMessage(inputFileName, parseError); + } + return false; + } + } + + { + QmlIR::JSCodeGen v4CodeGen(inputFileName, irDocument.code, &irDocument.jsModule, &irDocument.jsParserEngine, irDocument.program, /*import cache*/0, &irDocument.jsGenerator.stringTable); + for (QmlIR::Object *object: qAsConst(irDocument.objects)) { + if (object->functionsAndExpressions->count == 0) + continue; + QList<QmlIR::CompiledFunctionOrExpression> functionsToCompile; + for (QmlIR::CompiledFunctionOrExpression *foe = object->functionsAndExpressions->first; foe; foe = foe->next) { + foe->disableAcceleratedLookups = true; + functionsToCompile << *foe; + } + const QVector<int> runtimeFunctionIndices = v4CodeGen.generateJSCodeForFunctionsAndBindings(functionsToCompile); + QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors(); + if (!jsErrors.isEmpty()) { + for (const QQmlJS::DiagnosticMessage &e: qAsConst(jsErrors)) { + if (!error->message.isEmpty()) + error->message += QLatin1Char('\n'); + error->message += diagnosticErrorMessage(inputFileName, e); + } + return false; + } + + QQmlJS::MemoryPool *pool = irDocument.jsParserEngine.pool(); + object->runtimeFunctionIndices.allocate(pool, runtimeFunctionIndices); + } + + QmlIR::QmlUnitGenerator generator; + + // ### translation binding simplification + + QV4::ExecutableAllocator allocator; + QScopedPointer<QV4::EvalInstructionSelection> isel(iselFactory->create(/*engine*/nullptr, &allocator, &irDocument.jsModule, &irDocument.jsGenerator)); + // Disable lookups in non-standalone (aka QML) mode + isel->setUseFastLookups(false); + irDocument.javaScriptCompilationUnit = isel->compile(/*generate unit*/false); + // ### + QV4::CompiledData::ResolvedTypeReferenceMap dummyDependencies; + QV4::CompiledData::Unit *unit = generator.generate(irDocument, /*engine*/nullptr, dummyDependencies); + unit->flags |= QV4::CompiledData::Unit::StaticData; + unit->flags |= QV4::CompiledData::Unit::PendingTypeCompilation; + irDocument.javaScriptCompilationUnit->data = unit; + + if (!irDocument.javaScriptCompilationUnit->saveToDisk(inputFileName, &error->message)) + return false; + + free(unit); + } + return true; +} + +static bool compileJSFile(const QString &inputFileName, QV4::EvalISelFactory *iselFactory, Error *error) +{ + QmlIR::Document irDocument(/*debugMode*/false); + + QString sourceCode; + { + QFile f(inputFileName); + if (!f.open(QIODevice::ReadOnly)) { + error->message = QLatin1String("Error opening ") + inputFileName + QLatin1Char(':') + f.errorString(); + return false; + } + sourceCode = QString::fromUtf8(f.readAll()); + if (f.error() != QFileDevice::NoError) { + error->message = QLatin1String("Error reading from ") + inputFileName + QLatin1Char(':') + f.errorString(); + return false; + } + irDocument.jsModule.sourceTimeStamp = QFileInfo(f).lastModified().toMSecsSinceEpoch(); + } + + QQmlJS::Engine *engine = &irDocument.jsParserEngine; + QmlIR::ScriptDirectivesCollector directivesCollector(engine, &irDocument.jsGenerator); + QQmlJS::Directives *oldDirs = engine->directives(); + engine->setDirectives(&directivesCollector); + + QQmlJS::AST::Program *program = nullptr; + + { + QQmlJS::Lexer lexer(engine); + lexer.setCode(sourceCode, /*line*/1, /*parseAsBinding*/false); + QQmlJS::Parser parser(engine); + + bool parsed = parser.parseProgram(); + + for (const QQmlJS::DiagnosticMessage &parseError: parser.diagnosticMessages()) { + if (!error->message.isEmpty()) + error->message += QLatin1Char('\n'); + error->message += diagnosticErrorMessage(inputFileName, parseError); + } + + if (!parsed) { + engine->setDirectives(oldDirs); + return false; + } + + program = QQmlJS::AST::cast<QQmlJS::AST::Program*>(parser.rootNode()); + if (!program) { + lexer.setCode(QStringLiteral("undefined;"), 1, false); + parsed = parser.parseProgram(); + Q_ASSERT(parsed); + program = QQmlJS::AST::cast<QQmlJS::AST::Program*>(parser.rootNode()); + Q_ASSERT(program); + } + } + + { + QmlIR::JSCodeGen v4CodeGen(inputFileName, irDocument.code, &irDocument.jsModule, &irDocument.jsParserEngine, irDocument.program, /*import cache*/0, &irDocument.jsGenerator.stringTable); + v4CodeGen.generateFromProgram(inputFileName, sourceCode, program, &irDocument.jsModule, QQmlJS::Codegen::GlobalCode); + QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors(); + if (!jsErrors.isEmpty()) { + for (const QQmlJS::DiagnosticMessage &e: qAsConst(jsErrors)) { + if (!error->message.isEmpty()) + error->message += QLatin1Char('\n'); + error->message += diagnosticErrorMessage(inputFileName, e); + } + engine->setDirectives(oldDirs); + return false; + } + + QmlIR::QmlUnitGenerator generator; + + // ### translation binding simplification + + QScopedPointer<QV4::EvalInstructionSelection> isel(iselFactory->create(/*engine*/nullptr, /*executable allocator*/nullptr, &irDocument.jsModule, &irDocument.jsGenerator)); + // Disable lookups in non-standalone (aka QML) mode + isel->setUseFastLookups(false); + irDocument.javaScriptCompilationUnit = isel->compile(/*generate unit*/false); + // ### + QV4::CompiledData::ResolvedTypeReferenceMap dummyDependencies; + QV4::CompiledData::Unit *unit = generator.generate(irDocument, /*engine*/nullptr, dummyDependencies); + unit->flags |= QV4::CompiledData::Unit::StaticData; + irDocument.javaScriptCompilationUnit->data = unit; + + if (!irDocument.javaScriptCompilationUnit->saveToDisk(inputFileName, &error->message)) { + engine->setDirectives(oldDirs); + return false; + } + + free(unit); + } + engine->setDirectives(oldDirs); + return true; +} + +int main(int argc, char **argv) +{ + // Produce reliably the same output for the same input by disabling QHash's random seeding. + qt_qhash_seed.testAndSetRelaxed(-1, 0); + + QCoreApplication app(argc, argv); + QCoreApplication::setApplicationName(QStringLiteral("qmlcachegen")); + QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); + + QCommandLineParser parser; + parser.addHelpOption(); + parser.addVersionOption(); + + QCommandLineOption targetArchitectureOption(QStringLiteral("target-architecture"), QCoreApplication::translate("main", "Target architecture"), QCoreApplication::translate("main", "architecture")); + parser.addOption(targetArchitectureOption); + + parser.addPositionalArgument(QStringLiteral("[qml file]"), + QStringLiteral("QML source file to generate cache for.")); + + parser.process(app); + + const QStringList sources = parser.positionalArguments(); + if (sources.isEmpty()){ + parser.showHelp(); + } else if (sources.count() > 1) { + fprintf(stderr, "%s\n", qPrintable(QStringLiteral("Too many input files specified: '") + sources.join(QStringLiteral("' '")) + QLatin1Char('\''))); + return EXIT_FAILURE; + } + const QString inputFile = sources.first(); + + QScopedPointer<QV4::EvalISelFactory> isel; + const QString targetArchitecture = parser.value(targetArchitectureOption); + + isel.reset(QV4::JIT::createISelForArchitecture(targetArchitecture)); + + if (!isel) + isel.reset(new QV4::Moth::ISelFactory); + + Error error; + + if (inputFile.endsWith(QLatin1String(".qml"))) { + if (!compileQmlFile(inputFile, isel.data(), &error)) { + error.augment(QLatin1String("Error compiling qml file: ")).print(); + return EXIT_FAILURE; + } + } else if (inputFile.endsWith(QLatin1String(".js"))) { + if (!compileJSFile(inputFile, isel.data(), &error)) { + error.augment(QLatin1String("Error compiling qml file: ")).print(); + return EXIT_FAILURE; + } + } else { + fprintf(stderr, "Ignoring %s input file as it is not QML source code - maybe remove from QML_FILES?\n", qPrintable(inputFile)); } + + + return EXIT_SUCCESS; +} diff --git a/tools/qmlcachegen/qmlcachegen.pro b/tools/qmlcachegen/qmlcachegen.pro new file mode 100644 index 0000000000..81783d0396 --- /dev/null +++ b/tools/qmlcachegen/qmlcachegen.pro @@ -0,0 +1,24 @@ +option(host_build) + +QT = qmldevtools-private +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +SOURCES = qmlcachegen.cpp +TARGET = qmlcachegen + +BUILD_INTEGRATION = qmlcache.prf +!force_independent { + qmake_integration.input = BUILD_INTEGRATION + qmake_integration.output = $$[QT_HOST_DATA]/mkspecs/features/${QMAKE_FILE_BASE}.prf + qmake_integration.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} + qmake_integration.name = COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} + qmake_integration.CONFIG = no_clean no_link + !contains(TEMPLATE, vc.*): qmake_integration.variable_out = GENERATED_FILES + QMAKE_EXTRA_COMPILERS += qmake_integration +} + +qmake_integration_installs.files = $$BUILD_INTEGRATION +qmake_integration_installs.path = $$[QT_HOST_DATA]/mkspecs/features +INSTALLS += qmake_integration_installs + +load(qt_tool) diff --git a/tools/qmleasing/mainwindow.cpp b/tools/qmleasing/mainwindow.cpp index 5a5f651396..d36ab5fd75 100644 --- a/tools/qmleasing/mainwindow.cpp +++ b/tools/qmleasing/mainwindow.cpp @@ -73,7 +73,8 @@ MainWindow::MainWindow(QWidget *parent) : quickView.rootContext()->setContextProperty(QLatin1String("spinBox"), ui_properties.spinBox); - foreach (const QString &name, splineEditor->presetNames()) + const auto presetNames = splineEditor->presetNames(); + for (const QString &name : presetNames) ui_properties.comboBox->addItem(name); connect(ui_properties.comboBox, SIGNAL(currentIndexChanged(QString)), splineEditor, SLOT(setPreset(QString))); diff --git a/tools/qmleasing/mainwindow.h b/tools/qmleasing/mainwindow.h index 9af5c8050c..7ca4dbfd5c 100644 --- a/tools/qmleasing/mainwindow.h +++ b/tools/qmleasing/mainwindow.h @@ -51,9 +51,9 @@ public slots: void importData(int result); protected: - virtual void moveEvent(QMoveEvent *event); - virtual void resizeEvent(QResizeEvent *event); - virtual void closeEvent(QCloseEvent *event); + void moveEvent(QMoveEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + void closeEvent(QCloseEvent *event) override; void initQml(); private: diff --git a/tools/qmleasing/splineeditor.cpp b/tools/qmleasing/splineeditor.cpp index 01a279afbf..cd0c0b3ae0 100644 --- a/tools/qmleasing/splineeditor.cpp +++ b/tools/qmleasing/splineeditor.cpp @@ -620,7 +620,7 @@ void SplineEditor::mouseMoveEvent(QMouseEvent *e) if (indexIsRealPoint(m_activeControlPoint)) { //move also the tangents QPointF targetPoint = p; - QPointF distance = targetPoint - m_controlPoints[m_activeControlPoint]; + QPointF distance = targetPoint - m_controlPoints.at(m_activeControlPoint); m_controlPoints[m_activeControlPoint] = targetPoint; m_controlPoints[m_activeControlPoint - 1] += distance; m_controlPoints[m_activeControlPoint + 1] += distance; @@ -629,7 +629,7 @@ void SplineEditor::mouseMoveEvent(QMouseEvent *e) m_controlPoints[m_activeControlPoint] = p; } else { QPointF targetPoint = p; - QPointF distance = targetPoint - m_controlPoints[m_activeControlPoint]; + QPointF distance = targetPoint - m_controlPoints.at(m_activeControlPoint); m_controlPoints[m_activeControlPoint] = p; if ((m_activeControlPoint > 1) && (m_activeControlPoint % 3) == 0) { //right control point diff --git a/tools/qmleasing/splineeditor.h b/tools/qmleasing/splineeditor.h index 414b787bc3..8dd47c3a89 100644 --- a/tools/qmleasing/splineeditor.h +++ b/tools/qmleasing/splineeditor.h @@ -75,12 +75,12 @@ public slots: void setEasingCurve(const QString &code); protected: - void paintEvent(QPaintEvent *); - void mousePressEvent(QMouseEvent *); - void mouseMoveEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *); + void paintEvent(QPaintEvent *) override; + void mousePressEvent(QMouseEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; + void mouseReleaseEvent(QMouseEvent *) override; #if QT_CONFIG(contextmenu) - void contextMenuEvent(QContextMenuEvent *); + void contextMenuEvent(QContextMenuEvent *) override; #endif // contextmenu void invalidate(); diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp index b2ff751231..bac7694e17 100644 --- a/tools/qmlimportscanner/main.cpp +++ b/tools/qmlimportscanner/main.cpp @@ -146,7 +146,7 @@ QVariantMap pluginsForModulePath(const QString &modulePath) { classnames += QString::fromUtf8(line.split(' ').at(1)); classnames += QLatin1Char(' '); } else if (line.startsWith("depends")) { - QList<QByteArray> dep = line.split(' '); + const QList<QByteArray> dep = line.split(' '); if (dep.length() != 3) std::cerr << "depends: expected 2 arguments: module identifier and version" << std::endl; else @@ -222,8 +222,8 @@ QVariantList findPathsForModuleImports(const QVariantList &imports) QVariantList importsCopy(imports); for (int i = 0; i < importsCopy.length(); ++i) { - QVariantMap import = qvariant_cast<QVariantMap>(importsCopy[i]); - if (import[typeLiteral()] == QLatin1String("module")) { + QVariantMap import = qvariant_cast<QVariantMap>(importsCopy.at(i)); + if (import.value(typeLiteral()) == QLatin1String("module")) { const QPair<QString, QString> paths = resolveImportPath(import.value(nameLiteral()).toString(), import.value(versionLiteral()).toString()); if (!paths.first.isEmpty()) { @@ -264,7 +264,8 @@ static QVariantList findQmlImportsInQmlCode(const QString &filePath, const QStri if (!parser.parse() || !parser.diagnosticMessages().isEmpty()) { // Extract errors from the parser - foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) { + const auto diagnosticMessages = parser.diagnosticMessages(); + for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { std::cerr << QDir::toNativeSeparators(filePath).toStdString() << ':' << m.loc.startLine << ':' << m.message.toStdString() << std::endl; } @@ -342,7 +343,8 @@ QVariantList findQmlImportsInJavascriptFile(const QString &filePath) QQmlJS::Parser parser(&ee); parser.parseProgram(); - foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) + const auto diagnosticMessages = parser.diagnosticMessages(); + for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) if (m.isError()) return QVariantList(); @@ -537,7 +539,7 @@ int main(int argc, char *argv[]) if (arg.startsWith(QLatin1Char('-')) && arg != QLatin1String("-")) break; ++i; - if (!QFile::exists(arg)) { + if (arg != QLatin1String("-") && !QFile::exists(arg)) { std::cerr << qPrintable(appName) << ": No such file or directory: \"" << qPrintable(arg) << "\"\n"; return 1; diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp index dd1898a88a..4d0f9d278f 100644 --- a/tools/qmljs/qmljs.cpp +++ b/tools/qmljs/qmljs.cpp @@ -103,29 +103,29 @@ int main(int argc, char *argv[]) bool cache = false; if (!args.isEmpty()) { - if (args.first() == QLatin1String("--jit")) { + if (args.constFirst() == QLatin1String("--jit")) { mode = use_masm; args.removeFirst(); } #if QT_CONFIG(qml_interpreter) - if (args.first() == QLatin1String("--interpret")) { + if (args.constFirst() == QLatin1String("--interpret")) { mode = use_moth; args.removeFirst(); } #endif - if (args.first() == QLatin1String("--qml")) { + if (args.constFirst() == QLatin1String("--qml")) { runAsQml = true; args.removeFirst(); } - if (args.first() == QLatin1String("--cache")) { + if (args.constFirst() == QLatin1String("--cache")) { cache = true; args.removeFirst(); } - if (args.first() == QLatin1String("--help")) { + if (args.constFirst() == QLatin1String("--help")) { std::cerr << "Usage: qmljs [|--jit|--interpret|--qml] file..." << std::endl; return EXIT_SUCCESS; } @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) #endif #ifdef V4_ENABLE_JIT } else { - iSelFactory = new QV4::JIT::ISelFactory; + iSelFactory = new QV4::JIT::ISelFactory<>; #endif // V4_ENABLE_JIT } diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index 45914353a8..791fb71685 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -61,7 +61,8 @@ static bool lint_file(const QString &filename, bool silent) bool success = isJavaScript ? parser.parseProgram() : parser.parse(); if (!success && !silent) { - foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) { + const auto diagnosticMessages = parser.diagnosticMessages(); + for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { qWarning("%s:%d : %s", qPrintable(filename), m.loc.startLine, qPrintable(m.message)); } } @@ -85,7 +86,8 @@ int main(int argv, char *argc[]) parser.process(app); - if (parser.positionalArguments().isEmpty()) { + const auto positionalArguments = parser.positionalArguments(); + if (positionalArguments.isEmpty()) { parser.showHelp(-1); } @@ -95,12 +97,12 @@ int main(int argv, char *argc[]) #endif bool success = true; #if QT_CONFIG(commandlineparser) - foreach (const QString &filename, parser.positionalArguments()) { + for (const QString &filename : positionalArguments) #else - foreach (const QString &filename, app.arguments()) { + const auto arguments = app.arguments(); + for (const QString &filename : arguments) #endif success &= lint_file(filename, silent); - } return success ? 0 : -1; } diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index e4482ba2a6..dd7ae36c5d 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -212,7 +212,8 @@ QByteArray convertToId(const QMetaObject *mo) // Collect all metaobjects for types registered with qmlRegisterType() without parameters void collectReachableMetaObjectsWithoutQmlName(QQmlEnginePrivate *engine, QSet<const QMetaObject *>& metas ) { - foreach (const QQmlType *ty, QQmlMetaType::qmlAllTypes()) { + const auto qmlAllTypes = QQmlMetaType::qmlAllTypes(); + for (const QQmlType *ty : qmlAllTypes) { if ( ! metas.contains(ty->metaObject()) ) { if (!ty->isComposite()) { collectReachableMetaObjects(engine, ty, &metas); @@ -232,7 +233,8 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, metas.insert(FriendlyQObject::qtMeta()); QHash<QByteArray, QSet<QByteArray> > extensions; - foreach (const QQmlType *ty, QQmlMetaType::qmlTypes()) { + const auto qmlTypes = QQmlMetaType::qmlTypes(); + for (const QQmlType *ty : qmlTypes) { if (!ty->isCreatable()) noncreatables.insert(ty->metaObject()); if (ty->isSingleton()) @@ -282,7 +284,7 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, if (creatable) { // find even more QMetaObjects by instantiating QML types and running // over the instances - foreach (QQmlType *ty, QQmlMetaType::qmlTypes()) { + for (QQmlType *ty : qmlTypes) { if (skip.contains(ty)) continue; if (ty->isExtendedType()) @@ -773,7 +775,8 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil const QStringList requiredKeys = QStringList() << QStringLiteral("name") << QStringLiteral("type") << QStringLiteral("version"); - foreach (const QJsonValue &dep, doc.array()) { + const auto deps = doc.array(); + for (const QJsonValue &dep : deps) { if (dep.isObject()) { QJsonObject obj = dep.toObject(); for (const QString &requiredKey : requiredKeys) @@ -840,7 +843,9 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor QStringList commandArgs = QStringList() << QLatin1String("-qmlFiles") << QLatin1String("-"); - foreach (const QString &path, engine.importPathList()) + QStringList importPathList = engine.importPathList(); + importPathList.removeOne(QStringLiteral("qrc:/qt-project.org/imports")); + for (const QString &path : importPathList) commandArgs << QLatin1String("-importPath") << path; QProcess importScanner; @@ -866,6 +871,8 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor if (!readDependenciesData(QLatin1String("<outputOfQmlimportscanner>"), depencenciesData, dependencies, QStringList(pluginImportUri), forceQtQuickDependency)) { std::cerr << "failed to process output of qmlimportscanner" << std::endl; + if (importScanner.exitCode() != 0) + std::cerr << importScanner.readAllStandardError().toStdString(); return false; } @@ -884,20 +891,20 @@ bool compactDependencies(QStringList *dependencies) if (dependencies->isEmpty()) return false; dependencies->sort(); - QStringList oldDep = dependencies->first().split(QLatin1Char(' ')); + QStringList oldDep = dependencies->constFirst().split(QLatin1Char(' ')); Q_ASSERT(oldDep.size() == 2); int oldPos = 0; for (int idep = 1; idep < dependencies->size(); ++idep) { QString depStr = dependencies->at(idep); const QStringList newDep = depStr.split(QLatin1Char(' ')); Q_ASSERT(newDep.size() == 2); - if (newDep.first() != oldDep.first()) { + if (newDep.constFirst() != oldDep.constFirst()) { if (++oldPos != idep) dependencies->replace(oldPos, depStr); oldDep = newDep; } else { - QStringList v1 = oldDep.last().split(QLatin1Char('.')); - QStringList v2 = newDep.last().split(QLatin1Char('.')); + const QStringList v1 = oldDep.constLast().split(QLatin1Char('.')); + const QStringList v2 = newDep.constLast().split(QLatin1Char('.')); Q_ASSERT(v1.size() == 2); Q_ASSERT(v2.size() == 2); bool ok; @@ -906,9 +913,9 @@ bool compactDependencies(QStringList *dependencies) int major2 = v2.first().toInt(&ok); Q_ASSERT(ok); if (major1 != major2) { - std::cerr << "Found a dependency on " << qPrintable(oldDep.first()) - << " with two major versions:" << qPrintable(oldDep.last()) - << " and " << qPrintable(newDep.last()) + std::cerr << "Found a dependency on " << qPrintable(oldDep.constFirst()) + << " with two major versions:" << qPrintable(oldDep.constLast()) + << " and " << qPrintable(newDep.constLast()) << " which is unsupported, discarding smaller version" << std::endl; if (major1 < major2) dependencies->replace(oldPos, depStr); @@ -1091,18 +1098,18 @@ int main(int argc, char *argv[]) std::cerr << "Incorrect number of positional arguments" << std::endl; return EXIT_INVALIDARGUMENTS; } - pluginImportUri = positionalArgs[1]; + pluginImportUri = positionalArgs.at(1); pluginImportVersion = positionalArgs[2]; if (positionalArgs.size() >= 4) - pluginImportPath = positionalArgs[3]; + pluginImportPath = positionalArgs.at(3); } else if (action == Path) { if (positionalArgs.size() != 2 && positionalArgs.size() != 3) { std::cerr << "Incorrect number of positional arguments" << std::endl; return EXIT_INVALIDARGUMENTS; } - pluginImportPath = QDir::fromNativeSeparators(positionalArgs[1]); + pluginImportPath = QDir::fromNativeSeparators(positionalArgs.at(1)); if (positionalArgs.size() == 3) - pluginImportVersion = positionalArgs[2]; + pluginImportVersion = positionalArgs.at(2); } else if (action == Builtins) { if (positionalArgs.size() != 1) { std::cerr << "Incorrect number of positional arguments" << std::endl; @@ -1124,7 +1131,7 @@ int main(int argc, char *argv[]) QStringList mergeDependencies; QString mergeComponents; if (!mergeFile.isEmpty()) { - QStringList merge = readQmlTypes(mergeFile); + const QStringList merge = readQmlTypes(mergeFile); if (!merge.isEmpty()) { QRegularExpression re("(\\w+\\.*\\w*\\s*\\d+\\.\\d+)"); QRegularExpressionMatchIterator i = re.globalMatch(merge[1]); @@ -1166,8 +1173,9 @@ int main(int argc, char *argv[]) QQmlComponent c(&engine); c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/loaddependencies.qml")); c.create(); - if (!c.errors().isEmpty()) { - foreach (const QQmlError &error, c.errors()) + const auto errors = c.errors(); + if (!errors.isEmpty()) { + for (const QQmlError &error : errors) std::cerr << qPrintable( error.toString() ) << std::endl; return EXIT_IMPORTERROR; } @@ -1196,7 +1204,7 @@ int main(int argc, char *argv[]) } } else if (pluginImportUri == QLatin1String("QtQml")) { bool ok = false; - const uint major = pluginImportVersion.split('.')[0].toUInt(&ok, 10); + const uint major = pluginImportVersion.splitRef('.').at(0).toUInt(&ok, 10); if (!ok) { std::cerr << "Malformed version string \""<< qPrintable(pluginImportVersion) << "\"." << std::endl; @@ -1252,8 +1260,9 @@ int main(int argc, char *argv[]) c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typelist.qml")); c.create(); - if (!c.errors().isEmpty()) { - foreach (const QQmlError &error, c.errors()) + const auto errors = c.errors(); + if (!errors.isEmpty()) { + for (const QQmlError &error : errors) std::cerr << qPrintable( error.toString() ) << std::endl; return EXIT_IMPORTERROR; } diff --git a/tools/qmlprofiler/qmlprofilerclient.h b/tools/qmlprofiler/qmlprofilerclient.h index 1da04db42a..a04a412bb0 100644 --- a/tools/qmlprofiler/qmlprofilerclient.h +++ b/tools/qmlprofiler/qmlprofilerclient.h @@ -50,24 +50,24 @@ signals: void error(const QString &error); private: - virtual void stateChanged(State state); + void stateChanged(State state) override; - void traceStarted(qint64 time, int engineId); - void traceFinished(qint64 time, int engineId); - void rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime); - void rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, const QString &data); + void traceStarted(qint64 time, int engineId) override; + void traceFinished(qint64 time, int engineId) override; + void rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime) override; + void rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, const QString &data) override; void rangeLocation(QQmlProfilerDefinitions::RangeType type, qint64 time, - const QQmlEventLocation &location); - void rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime); - void animationFrame(qint64 time, int frameRate, int animationCount, int threadId); + const QQmlEventLocation &location) override; + void rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime) override; + void animationFrame(qint64 time, int frameRate, int animationCount, int threadId) override; void sceneGraphEvent(QQmlProfilerDefinitions::SceneGraphFrameType type, qint64 time, qint64 numericData1, qint64 numericData2, qint64 numericData3, - qint64 numericData4, qint64 numericData5); + qint64 numericData4, qint64 numericData5) override; void pixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, qint64 time, - const QString &url, int numericData1, int numericData2); - void memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, qint64 amount); - void inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, int a, int b); - void complete(); + const QString &url, int numericData1, int numericData2) override; + void memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, qint64 amount) override; + void inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, int a, int b) override; + void complete() override; }; #endif // QMLPROFILERCLIENT_H diff --git a/tools/qmlprofiler/qmlprofilerdata.cpp b/tools/qmlprofiler/qmlprofilerdata.cpp index 048c92bb93..668cb3ce2d 100644 --- a/tools/qmlprofiler/qmlprofilerdata.cpp +++ b/tools/qmlprofiler/qmlprofilerdata.cpp @@ -403,23 +403,23 @@ void QmlProfilerData::computeQmlTime() int level = minimumLevel; for (int i = 0; i < d->startInstanceList.count(); i++) { - qint64 st = d->startInstanceList[i].startTime; + qint64 st = d->startInstanceList.at(i).startTime; - if (d->startInstanceList[i].data->rangeType == QQmlProfilerDefinitions::Painting) { + if (d->startInstanceList.at(i).data->rangeType == QQmlProfilerDefinitions::Painting) { continue; } // general level - if (endtimesPerLevel[level] > st) { + if (endtimesPerLevel.value(level) > st) { level++; } else { while (level > minimumLevel && endtimesPerLevel[level-1] <= st) level--; } - endtimesPerLevel[level] = st + d->startInstanceList[i].duration; + endtimesPerLevel[level] = st + d->startInstanceList.at(i).duration; if (level == minimumLevel) { - d->qmlMeasuredTime += d->startInstanceList[i].duration; + d->qmlMeasuredTime += d->startInstanceList.at(i).duration; } } } diff --git a/tools/qmltime/qmltime.cpp b/tools/qmltime/qmltime.cpp index 4c282dd8f4..b337ccac5c 100644 --- a/tools/qmltime/qmltime.cpp +++ b/tools/qmltime/qmltime.cpp @@ -222,7 +222,7 @@ int main(int argc, char ** argv) QByteArray its(argv[ii]); bool ok = false; iterations = its.toUInt(&ok); - if (!ok) + if (!ok || iterations == 0) usage(argv[0]); } else { usage(argv[0]); diff --git a/tools/tools.pro b/tools/tools.pro index d16888e539..bf39a649df 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -2,7 +2,8 @@ TEMPLATE = subdirs QT_FOR_CONFIG += qml-private SUBDIRS += \ qmlmin \ - qmlimportscanner + qmlimportscanner \ + qmlcachegen !android|android_app { SUBDIRS += \ @@ -31,7 +32,7 @@ SUBDIRS += \ qml.depends = qmlimportscanner qmleasing.depends = qmlimportscanner -# qmlmin, qmlimportscanner & qmlbundle are build tools. +# qmlmin, qmlimportscanner & qmlcachegen are build tools. # qmlscene is needed by the autotests. # qmltestrunner may be useful for manual testing. # qmlplugindump cannot be a build tool, because it loads target plugins. |