aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlcachegen
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-07-11 14:51:40 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-07-11 17:24:39 +0200
commit13374ceb165c44658aa97890c37b206859c9a31c (patch)
tree562362b196a459ee3449a5a1e60e5216a9dd6984 /tools/qmlcachegen
parentae47deba4c943c496412530a8d2a5a688ae12038 (diff)
parentb5d18be5a03406d0aac83856dd41e1525fd14a28 (diff)
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Diffstat (limited to 'tools/qmlcachegen')
-rw-r--r--tools/qmlcachegen/generateloader.cpp9
-rw-r--r--tools/qmlcachegen/qmlcachegen.cpp78
-rw-r--r--tools/qmlcachegen/resourcefilemapper.cpp4
3 files changed, 51 insertions, 40 deletions
diff --git a/tools/qmlcachegen/generateloader.cpp b/tools/qmlcachegen/generateloader.cpp
index 5b8fc34455..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('_');
}
@@ -365,6 +365,7 @@ bool generateLoader(const QStringList &compiledFiles, const QStringList &sortedR
stream << "struct Registry {\n";
stream << " Registry();\n";
+ stream << " ~Registry();\n";
stream << " QHash<QString, const QQmlPrivate::CachedQmlUnit*> resourcePathToCachedUnit;\n";
stream << " static const QQmlPrivate::CachedQmlUnit *lookupCachedUnit(const QUrl &url);\n";
stream << "};\n\n";
@@ -387,7 +388,11 @@ bool generateLoader(const QStringList &compiledFiles, const QStringList &sortedR
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";
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp
index 7b4135e1f8..abad2435dc 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<QQmlJS::DiagnosticMessage> &diagnostics);
+ void appendDiagnostic(const QString &inputFileName, const DiagnosticMessage &diagnostic);
};
void Error::print()
@@ -82,9 +83,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: ");
@@ -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<DiagnosticMessage> &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<int> runtimeFunctionIndices = v4CodeGen.generateJSCodeForFunctionsAndBindings(functionsToCompile);
- QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors();
- if (!jsErrors.isEmpty()) {
- error->appendDiagnostics(inputFileName, jsErrors);
+ if (v4CodeGen.hasError()) {
+ error->appendDiagnostic(inputFileName, v4CodeGen.error());
return false;
}
@@ -233,7 +237,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;
@@ -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<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors();
- if (!jsErrors.isEmpty()) {
- error->appendDiagnostics(inputFileName, jsErrors);
+ if (v4CodeGen.hasError()) {
+ error->appendDiagnostic(inputFileName, v4CodeGen.error());
return false;
}
@@ -327,7 +330,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 +369,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<uchar>();
- 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<uchar>([&writeStr](const uchar *begin, quint32 size) {
+ QByteArray hexifiedData;
+ {
+ QTextStream stream(&hexifiedData);
+ const uchar *end = begin + size;
+ stream << Qt::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 +531,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<char>(
+ [&outputFileName, errorString](const char *data, quint32 size) {
+ return QV4::CompiledData::SaveableUnitPointer::writeDataToFile(
+ outputFileName, data, size, errorString);
+ });
};
}
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<QString, QString> 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());
}