From d4d197d06279f9257647628f7e1ccc9ec763a6bb Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 23 May 2019 14:57:09 +0200 Subject: Simplify errors and diagnostics We only need two classes to describe all possible diagnostics: * A low-level private POD DiagnosticMessage. This is easily copied and passed around internally. It doesn't need to adhere to a stable API and it doesn't carry any extra baggage. * The high-level public QQmlError with its stable interface. This can internally also use a DiagnosticMessage as storage. Change-Id: I52be88d9b5d9855a661b8032b01eedb43a0fb0b3 Reviewed-by: Simon Hausmann --- tools/qmlcachegen/qmlcachegen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/qmlcachegen') diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index 7b4135e1f8..ff6ba17612 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -82,9 +82,9 @@ Error Error::augment(const QString &contextErrorMessage) const 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(':'); + message = fileName + QLatin1Char(':') + QString::number(m.line) + QLatin1Char(':'); + if (m.column > 0) + message += QString::number(m.column) + QLatin1Char(':'); if (m.isError()) message += QLatin1String(" error: "); -- cgit v1.2.3 From e72637deed3aee3dd8ebc0b2d980bf18469ad270 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 14 Jun 2019 11:30:47 +0200 Subject: Move saveToDisk into SaveableUnitPointer This way we can keep the flag mutilation closely local to the place where we write the data. Also, SaveableUnitPointer doesn't need a full CompilationUnit this way. Change-Id: I01872e4c406cb2ccbaa1fa35325cc063b1e8a7df Reviewed-by: Simon Hausmann --- tools/qmlcachegen/qmlcachegen.cpp | 47 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'tools/qmlcachegen') diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index ff6ba17612..a91c181233 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -233,7 +233,7 @@ static bool compileQmlFile(const QString &inputFileName, SaveFunction saveFuncti const quint32 saveFlags = QV4::CompiledData::Unit::StaticData | QV4::CompiledData::Unit::PendingTypeCompilation; - QV4::CompiledData::SaveableUnitPointer saveable(&irDocument.javaScriptCompilationUnit, + QV4::CompiledData::SaveableUnitPointer saveable(irDocument.javaScriptCompilationUnit.data, saveFlags); if (!saveFunction(saveable, &error->message)) return false; @@ -327,7 +327,7 @@ static bool compileJSFile(const QString &inputFileName, const QString &inputFile } } - return saveFunction(QV4::CompiledData::SaveableUnitPointer(&unit), &error->message); + return saveFunction(QV4::CompiledData::SaveableUnitPointer(unit.data), &error->message); } static bool saveUnitAsCpp(const QString &inputFileName, const QString &outputFileName, @@ -366,27 +366,28 @@ static bool saveUnitAsCpp(const QString &inputFileName, const QString &outputFil if (!writeStr(QByteArrayLiteral(" {\nextern const unsigned char qmlData alignas(16) [] = {\n"))) return false; - QByteArray hexifiedData; - { - QTextStream stream(&hexifiedData); - const uchar *begin = unit.data(); - const uchar *end = begin + unit.size(); - stream << hex; - int col = 0; - for (const uchar *data = begin; data < end; ++data, ++col) { - if (data > begin) - stream << ','; - if (col % 8 == 0) { - stream << '\n'; - col = 0; + unit.saveToDisk([&writeStr](const uchar *begin, quint32 size) { + QByteArray hexifiedData; + { + QTextStream stream(&hexifiedData); + const uchar *end = begin + size; + stream << hex; + int col = 0; + for (const uchar *data = begin; data < end; ++data, ++col) { + if (data > begin) + stream << ','; + if (col % 8 == 0) { + stream << '\n'; + col = 0; + } + stream << "0x" << *data; } - stream << "0x" << *data; + stream << '\n'; } - stream << '\n'; - }; + return writeStr(hexifiedData); + }); + - if (!writeStr(hexifiedData)) - return false; if (!writeStr("};\n}\n}\n")) return false; @@ -527,7 +528,11 @@ int main(int argc, char **argv) } else { saveFunction = [outputFileName](const QV4::CompiledData::SaveableUnitPointer &unit, QString *errorString) { - return unit->saveToDisk(outputFileName, errorString); + return unit.saveToDisk( + [&outputFileName, errorString](const char *data, quint32 size) { + return QV4::CompiledData::SaveableUnitPointer::writeDataToFile( + outputFileName, data, size, errorString); + }); }; } -- cgit v1.2.3 From abfa03d7021aabe22f46a04d2b9d9f6adff2478a Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 4 Dec 2018 10:54:20 +0100 Subject: Unregister unit cache hook when destroying the plugin singleton At the point the plugin is actually unloaded the hook turns into a dangling pointer. Fixes: QTBUG-71387 Change-Id: Ib8ccee3f9a86d4700fbea7e87c666cd8f30f71e4 Reviewed-by: Simon Hausmann --- tools/qmlcachegen/generateloader.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tools/qmlcachegen') diff --git a/tools/qmlcachegen/generateloader.cpp b/tools/qmlcachegen/generateloader.cpp index 68aacf78ce..5638b311c2 100644 --- a/tools/qmlcachegen/generateloader.cpp +++ b/tools/qmlcachegen/generateloader.cpp @@ -357,6 +357,7 @@ bool generateLoader(const QStringList &compiledFiles, const QString &outputFileN stream << "struct Registry {\n"; stream << " Registry();\n"; + stream << " ~Registry();\n"; stream << " QHash resourcePathToCachedUnit;\n"; stream << " static const QQmlPrivate::CachedQmlUnit *lookupCachedUnit(const QUrl &url);\n"; stream << "};\n\n"; @@ -379,7 +380,11 @@ bool generateLoader(const QStringList &compiledFiles, const QString &outputFileN if (!resourceRegisterCall.isEmpty()) stream << resourceRegisterCall; - stream << "}\n"; + stream << "}\n\n"; + stream << "Registry::~Registry() {\n"; + stream << " QQmlPrivate::qmlunregister(QQmlPrivate::QmlUnitCacheHookRegistration, quintptr(&lookupCachedUnit));\n"; + stream << "}\n\n"; + stream << "const QQmlPrivate::CachedQmlUnit *Registry::lookupCachedUnit(const QUrl &url) {\n"; stream << " if (url.scheme() != QLatin1String(\"qrc\"))\n"; stream << " return nullptr;\n"; -- cgit v1.2.3 From 415bba6cfe2f4004dbf7a76c150e8c01a950ea54 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 1 Jul 2019 20:06:40 +0200 Subject: Port to somewhat stricter implicit conversions to QChar Currently, QChar can be implicitly converted from nearly any integral type. The goal for the future is to allow only actual character types ((u)char/char16_t) to implicitly convert to QChar. This patch prepares the code for such a change. Change-Id: I6db0a9214c48912e11ce6e90050223fa9dd8d3a2 Reviewed-by: Ulf Hermann --- tools/qmlcachegen/generateloader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/qmlcachegen') diff --git a/tools/qmlcachegen/generateloader.cpp b/tools/qmlcachegen/generateloader.cpp index 4fbbb27afb..74208a25e2 100644 --- a/tools/qmlcachegen/generateloader.cpp +++ b/tools/qmlcachegen/generateloader.cpp @@ -75,7 +75,7 @@ QString mangledIdentifier(const QString &str) || (c >= QLatin1Char('a') && c <= QLatin1Char('z')) || (c >= QLatin1Char('A') && c <= QLatin1Char('Z')) || c == QLatin1Char('_')) { - mangled += c; + mangled += QChar(c); } else { mangled += QLatin1String("_0x") + QString::number(c, 16) + QLatin1Char('_'); } -- cgit v1.2.3 From 1289bd6045818249915028fb345ec29c4ead52e5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 1 Jul 2019 20:07:26 +0200 Subject: Eradicate Java-style iterators and mark the module free of them Java-style iterators are scheduled to be deprecated, or at the very least banned from use in Qt's own implementation. Change-Id: I6a1aeceb22dfa13c4ed7443296455b60abed7d67 Reviewed-by: Lars Knoll --- tools/qmlcachegen/resourcefilemapper.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tools/qmlcachegen') diff --git a/tools/qmlcachegen/resourcefilemapper.cpp b/tools/qmlcachegen/resourcefilemapper.cpp index 6a00b39f2e..244874717f 100644 --- a/tools/qmlcachegen/resourcefilemapper.cpp +++ b/tools/qmlcachegen/resourcefilemapper.cpp @@ -50,10 +50,8 @@ bool ResourceFileMapper::isEmpty() const QStringList ResourceFileMapper::resourcePaths(const QString &fileName) { const QString absPath = QDir::cleanPath(QDir::current().absoluteFilePath(fileName)); - QHashIterator it(qrcPathToFileSystemPath); QStringList resourcePaths; - while (it.hasNext()) { - it.next(); + for (auto it = qrcPathToFileSystemPath.cbegin(), end = qrcPathToFileSystemPath.cend(); it != end; ++it) { if (QFileInfo(it.value()) == QFileInfo(absPath)) resourcePaths.append(it.key()); } -- cgit v1.2.3 From 40ded579bd977dc8fc41aaa1cdfca36822d14fc6 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 4 Jul 2019 13:18:55 +0200 Subject: Simplify codegen error handling There can only ever be one error, either a syntax error or a reference error. We record the error type as we want to get rid of the virtual throwError methods in favor of an explicit compilation result. Change-Id: Ie228490aad8efb7885083f6485f931299567f54c Reviewed-by: Fabian Kosmale Reviewed-by: Simon Hausmann --- tools/qmlcachegen/qmlcachegen.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'tools/qmlcachegen') diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index a91c181233..cbfc110089 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -65,6 +65,7 @@ struct Error void print(); Error augment(const QString &contextErrorMessage) const; void appendDiagnostics(const QString &inputFileName, const QList &diagnostics); + void appendDiagnostic(const QString &inputFileName, const DiagnosticMessage &diagnostic); }; void Error::print() @@ -94,13 +95,17 @@ QString diagnosticErrorMessage(const QString &fileName, const QQmlJS::Diagnostic return message; } +void Error::appendDiagnostic(const QString &inputFileName, const DiagnosticMessage &diagnostic) +{ + if (!message.isEmpty()) + message += QLatin1Char('\n'); + message += diagnosticErrorMessage(inputFileName, diagnostic); +} + void Error::appendDiagnostics(const QString &inputFileName, const QList &diagnostics) { - for (const QQmlJS::DiagnosticMessage &parseError: diagnostics) { - if (!message.isEmpty()) - message += QLatin1Char('\n'); - message += diagnosticErrorMessage(inputFileName, parseError); - } + for (const QQmlJS::DiagnosticMessage &diagnostic: diagnostics) + appendDiagnostic(inputFileName, diagnostic); } // Ensure that ListElement objects keep all property assignments in their string form @@ -211,9 +216,8 @@ static bool compileQmlFile(const QString &inputFileName, SaveFunction saveFuncti for (QmlIR::CompiledFunctionOrExpression *foe = object->functionsAndExpressions->first; foe; foe = foe->next) functionsToCompile << *foe; const QVector runtimeFunctionIndices = v4CodeGen.generateJSCodeForFunctionsAndBindings(functionsToCompile); - QList jsErrors = v4CodeGen.errors(); - if (!jsErrors.isEmpty()) { - error->appendDiagnostics(inputFileName, jsErrors); + if (v4CodeGen.hasError()) { + error->appendDiagnostic(inputFileName, v4CodeGen.error()); return false; } @@ -310,9 +314,8 @@ static bool compileJSFile(const QString &inputFileName, const QString &inputFile irDocument.program, &irDocument.jsGenerator.stringTable, illegalNames); v4CodeGen.generateFromProgram(inputFileName, inputFileUrl, sourceCode, program, &irDocument.jsModule, QV4::Compiler::ContextType::ScriptImportedByQML); - QList jsErrors = v4CodeGen.errors(); - if (!jsErrors.isEmpty()) { - error->appendDiagnostics(inputFileName, jsErrors); + if (v4CodeGen.hasError()) { + error->appendDiagnostic(inputFileName, v4CodeGen.error()); return false; } -- cgit v1.2.3 From 1c5c5f7aadc2dcc73a21eeb818e95c4e1b7de70f Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 26 Jun 2019 16:46:23 +0200 Subject: Fix Qt6 build in preparation of qt5 submodule update Fixes the QTextStream usages. Change-Id: I0c009a82fb644a9f3c3d42ec410d18b680977f23 Reviewed-by: Qt CI Bot Reviewed-by: Simon Hausmann --- tools/qmlcachegen/qmlcachegen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/qmlcachegen') diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index a91c181233..b5abe568aa 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -371,7 +371,7 @@ static bool saveUnitAsCpp(const QString &inputFileName, const QString &outputFil { QTextStream stream(&hexifiedData); const uchar *end = begin + size; - stream << hex; + stream << Qt::hex; int col = 0; for (const uchar *data = begin; data < end; ++data, ++col) { if (data > begin) -- cgit v1.2.3