| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/tools/qmlcachegen/qmlcachegen.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | int filterResourceFile(const QString &input, const QString &output); | - | ||||||||||||||||||
| 5 | bool generateLoader(const QStringList &compiledFiles, const QString &output, const QStringList &resourceFileMappings, QString *errorString); | - | ||||||||||||||||||
| 6 | QString symbolNamespaceForPath(const QString &relativePath); | - | ||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | QSet<QString> illegalNames; | - | ||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | void setupIllegalNames() | - | ||||||||||||||||||
| 11 | { | - | ||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "Math")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Math" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 14 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "Array")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Array" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 15 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "String")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "String" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 16 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "Function")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Function" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 17 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "Boolean")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Boolean" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 18 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "Number")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Number" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 19 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "Date")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Date" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 20 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "RegExp")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "RegExp" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 21 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "Error")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Error" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 22 | illegalNames.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "Object")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Object" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 23 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 24 | - | |||||||||||||||||||
| 25 | struct Error | - | ||||||||||||||||||
| 26 | { | - | ||||||||||||||||||
| 27 | QString message; | - | ||||||||||||||||||
| 28 | void print(); | - | ||||||||||||||||||
| 29 | Error augment(const QString &contextErrorMessage) const; | - | ||||||||||||||||||
| 30 | }; | - | ||||||||||||||||||
| 31 | - | |||||||||||||||||||
| 32 | void Error::print() | - | ||||||||||||||||||
| 33 | { | - | ||||||||||||||||||
| 34 | fprintf( | - | ||||||||||||||||||
| 35 | stderr | - | ||||||||||||||||||
| 36 | , "%s\n", QtPrivate::asString(message).toLocal8Bit().constData()); | - | ||||||||||||||||||
| 37 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | Error Error::augment(const QString &contextErrorMessage) const | - | ||||||||||||||||||
| 40 | { | - | ||||||||||||||||||
| 41 | Error augmented; | - | ||||||||||||||||||
| 42 | augmented.message = contextErrorMessage + message; | - | ||||||||||||||||||
| 43 | return executed 4 times by 1 test: augmented;return augmented;Executed by:
executed 4 times by 1 test: return augmented;Executed by:
| 4 | ||||||||||||||||||
| 44 | } | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | QString diagnosticErrorMessage(const QString &fileName, const QQmlJS::DiagnosticMessage &m) | - | ||||||||||||||||||
| 47 | { | - | ||||||||||||||||||
| 48 | QString message; | - | ||||||||||||||||||
| 49 | message = fileName + QLatin1Char(':') + QString::number(m.loc.startLine) + QLatin1Char(':'); | - | ||||||||||||||||||
| 50 | if (m.loc.startColumn > 0
| 0 | ||||||||||||||||||
| 51 | message += QString::number(m.loc.startColumn) + QLatin1Char(':'); never executed: message += QString::number(m.loc.startColumn) + QLatin1Char(':'); | 0 | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | if (m.isError()
| 0 | ||||||||||||||||||
| 54 | message += QLatin1String(" error: "); never executed: message += QLatin1String(" error: "); | 0 | ||||||||||||||||||
| 55 | else | - | ||||||||||||||||||
| 56 | message += QLatin1String(" warning: "); never executed: message += QLatin1String(" warning: "); | 0 | ||||||||||||||||||
| 57 | message += m.message; | - | ||||||||||||||||||
| 58 | return never executed: message;return message;never executed: return message; | 0 | ||||||||||||||||||
| 59 | } | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | - | |||||||||||||||||||
| 62 | static void annotateListElements(QmlIR::Document *document) | - | ||||||||||||||||||
| 63 | { | - | ||||||||||||||||||
| 64 | QStringList listElementNames; | - | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | for (auto _container_ = QtPrivate::qMakeForeachContainer(document->imports); _container_.control
| 0-26 | ||||||||||||||||||
| 67 | const QString uri = document->stringAt(import->uriIndex); | - | ||||||||||||||||||
| 68 | if (uri != ([]() noexcept -> QString { enum { Size = sizeof(u"" "QtQml.Models")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "QtQml.Models" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()) && uri != ([]() noexcept -> QString { enum { Size = sizeof(u"" "QtQuick")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "QtQuick" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()))return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 69 | continue; executed 10 times by 1 test: continue;Executed by:
| 10 | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | QString listElementName = ([]() noexcept dead code: -> QString { enum { Size = sizeof(u"" "ListElement")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "ListElement" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());QString listElementName = ([]() noexcept | - | ||||||||||||||||||
| 72 | const QString qualifier = document->stringAt(import->qualifierIndex); | - | ||||||||||||||||||
| 73 | if (!qualifier.isEmpty()
| 0-4 | ||||||||||||||||||
| 74 | listElementName.prepend(QLatin1Char('.')); | - | ||||||||||||||||||
| 75 | listElementName.prepend(qualifier); | - | ||||||||||||||||||
| 76 | } never executed: end of block | 0 | ||||||||||||||||||
| 77 | listElementNames.append(listElementName); | - | ||||||||||||||||||
| 78 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | if (listElementNames.isEmpty()
| 4-8 | ||||||||||||||||||
| 81 | return; executed 8 times by 1 test: return;Executed by:
| 8 | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | for (auto _container_ = QtPrivate::qMakeForeachContainer(document->objects); _container_.control
| 0-16 | ||||||||||||||||||
| 84 | if (!listElementNames.contains(document->stringAt(object->inheritedTypeNameIndex))
| 4-8 | ||||||||||||||||||
| 85 | continue; executed 8 times by 1 test: continue;Executed by:
| 8 | ||||||||||||||||||
| 86 | for (QmlIR::Binding *binding = object->firstBinding(); binding
| 4 | ||||||||||||||||||
| 87 | if (binding->type != QV4::CompiledData::Binding::Type_Script
| 0-4 | ||||||||||||||||||
| 88 | continue; executed 4 times by 1 test: continue;Executed by:
| 4 | ||||||||||||||||||
| 89 | binding->stringIndex = document->registerString(object->bindingAsString(document, binding->value.compiledScriptIndex)); | - | ||||||||||||||||||
| 90 | } never executed: end of block | 0 | ||||||||||||||||||
| 91 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 92 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | static bool checkArgumentsObjectUseInSignalHandlers(const QmlIR::Document &doc, Error *error) | - | ||||||||||||||||||
| 95 | { | - | ||||||||||||||||||
| 96 | for (QmlIR::Object *object: qAsConst(doc.objects)) { | - | ||||||||||||||||||
| 97 | for (auto binding = object->bindingsBegin(); binding != object->bindingsEnd()
| 18-36 | ||||||||||||||||||
| 98 | if (binding->type != QV4::CompiledData::Binding::Type_Script
| 16-20 | ||||||||||||||||||
| 99 | continue; executed 20 times by 1 test: continue;Executed by:
| 20 | ||||||||||||||||||
| 100 | const QString propName = doc.stringAt(binding->propertyNameIndex); | - | ||||||||||||||||||
| 101 | if (!propName.startsWith(QLatin1String("on"))
| 8 | ||||||||||||||||||
| 102 | || propName.length() < 3
| 0-8 | ||||||||||||||||||
| 103 | || !propName.at(2).isUpper()
| 0-8 | ||||||||||||||||||
| 104 | continue; executed 8 times by 1 test: continue;Executed by:
| 8 | ||||||||||||||||||
| 105 | auto compiledFunction = doc.jsModule.functions.value(object->runtimeFunctionIndices.at(binding->value.compiledScriptIndex)); | - | ||||||||||||||||||
| 106 | if (!compiledFunction
| 0-8 | ||||||||||||||||||
| 107 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 108 | if (compiledFunction->usesArgumentsObject == QV4::Compiler::Context::ArgumentsObjectUsed
| 2-6 | ||||||||||||||||||
| 109 | error->message = QLatin1Char(':') + QString::number(compiledFunction->line) + QLatin1Char(':'); | - | ||||||||||||||||||
| 110 | if (compiledFunction->column > 0
| 0-2 | ||||||||||||||||||
| 111 | error->message += QString::number(compiledFunction->column) + QLatin1Char(':'); executed 2 times by 1 test: error->message += QString::number(compiledFunction->column) + QLatin1Char(':');Executed by:
| 2 | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | error->message += QLatin1String(" error: The use of eval() or the use of the arguments object in signal handlers is\n" | - | ||||||||||||||||||
| 114 | "not supported when compiling qml files ahead of time. That is because it's ambiguous if \n" | - | ||||||||||||||||||
| 115 | "any signal parameter is called \"arguments\". Similarly the string passed to eval might use\n" | - | ||||||||||||||||||
| 116 | "\"arguments\". Unfortunately we cannot distinguish between it being a parameter or the\n" | - | ||||||||||||||||||
| 117 | "JavaScript arguments object at this point.\n" | - | ||||||||||||||||||
| 118 | "Consider renaming the parameter of the signal if applicable or moving the code into a\n" | - | ||||||||||||||||||
| 119 | "helper function."); | - | ||||||||||||||||||
| 120 | return executed 2 times by 1 test: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 121 | } | - | ||||||||||||||||||
| 122 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 123 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 124 | return executed 10 times by 1 test: true;return true;Executed by:
executed 10 times by 1 test: return true;Executed by:
| 10 | ||||||||||||||||||
| 125 | } | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | using SaveFunction = std::function<bool (QV4::CompiledData::CompilationUnit *, QString *)>; | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | static bool compileQmlFile(const QString &inputFileName, SaveFunction saveFunction, Error *error) | - | ||||||||||||||||||
| 130 | { | - | ||||||||||||||||||
| 131 | QmlIR::Document irDocument( false); | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | QString sourceCode; | - | ||||||||||||||||||
| 134 | { | - | ||||||||||||||||||
| 135 | QFile f(inputFileName); | - | ||||||||||||||||||
| 136 | if (!f.open(QIODevice::ReadOnly)
| 0-12 | ||||||||||||||||||
| 137 | error->message = QLatin1String("Error opening ") + inputFileName + QLatin1Char(':') + f.errorString(); | - | ||||||||||||||||||
| 138 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 139 | } | - | ||||||||||||||||||
| 140 | sourceCode = QString::fromUtf8(f.readAll()); | - | ||||||||||||||||||
| 141 | if (f.error() != QFileDevice::NoError
| 0-12 | ||||||||||||||||||
| 142 | error->message = QLatin1String("Error reading from ") + inputFileName + QLatin1Char(':') + f.errorString(); | - | ||||||||||||||||||
| 143 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 144 | } | - | ||||||||||||||||||
| 145 | } | - | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | { | - | ||||||||||||||||||
| 148 | QmlIR::IRBuilder irBuilder(illegalNames); | - | ||||||||||||||||||
| 149 | if (!irBuilder.generateFromQml(sourceCode, inputFileName, &irDocument)
| 0-12 | ||||||||||||||||||
| 150 | for (const QQmlJS::DiagnosticMessage &parseError: qAsConst(irBuilder.errors)) { | - | ||||||||||||||||||
| 151 | if (!error->message.isEmpty()
| 0 | ||||||||||||||||||
| 152 | error->message += QLatin1Char('\n'); never executed: error->message += QLatin1Char('\n'); | 0 | ||||||||||||||||||
| 153 | error->message += diagnosticErrorMessage(inputFileName, parseError); | - | ||||||||||||||||||
| 154 | } never executed: end of block | 0 | ||||||||||||||||||
| 155 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 156 | } | - | ||||||||||||||||||
| 157 | } | - | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | annotateListElements(&irDocument); | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | { | - | ||||||||||||||||||
| 162 | QmlIR::JSCodeGen v4CodeGen(irDocument.code, | - | ||||||||||||||||||
| 163 | &irDocument.jsGenerator, &irDocument.jsModule, | - | ||||||||||||||||||
| 164 | &irDocument.jsParserEngine, irDocument.program, | - | ||||||||||||||||||
| 165 | nullptr, &irDocument.jsGenerator.stringTable, illegalNames); | - | ||||||||||||||||||
| 166 | v4CodeGen.setUseFastLookups(false); | - | ||||||||||||||||||
| 167 | for (QmlIR::Object *object: qAsConst(irDocument.objects)) { | - | ||||||||||||||||||
| 168 | if (object->functionsAndExpressions->count == 0
| 6-14 | ||||||||||||||||||
| 169 | continue; executed 6 times by 1 test: continue;Executed by:
| 6 | ||||||||||||||||||
| 170 | QList<QmlIR::CompiledFunctionOrExpression> functionsToCompile; | - | ||||||||||||||||||
| 171 | for (QmlIR::CompiledFunctionOrExpression *foe = object->functionsAndExpressions->first; foe
| 14-22 | ||||||||||||||||||
| 172 | foe->disableAcceleratedLookups = true; | - | ||||||||||||||||||
| 173 | functionsToCompile << *foe; | - | ||||||||||||||||||
| 174 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 175 | const QVector<int> runtimeFunctionIndices = v4CodeGen.generateJSCodeForFunctionsAndBindings(functionsToCompile); | - | ||||||||||||||||||
| 176 | QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors(); | - | ||||||||||||||||||
| 177 | if (!jsErrors.isEmpty()
| 0-14 | ||||||||||||||||||
| 178 | for (const QQmlJS::DiagnosticMessage &e: qAsConst(jsErrors)) { | - | ||||||||||||||||||
| 179 | if (!error->message.isEmpty()
| 0 | ||||||||||||||||||
| 180 | error->message += QLatin1Char('\n'); never executed: error->message += QLatin1Char('\n'); | 0 | ||||||||||||||||||
| 181 | error->message += diagnosticErrorMessage(inputFileName, e); | - | ||||||||||||||||||
| 182 | } never executed: end of block | 0 | ||||||||||||||||||
| 183 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 184 | } | - | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | QQmlJS::MemoryPool *pool = irDocument.jsParserEngine.pool(); | - | ||||||||||||||||||
| 187 | object->runtimeFunctionIndices.allocate(pool, runtimeFunctionIndices); | - | ||||||||||||||||||
| 188 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | if (!checkArgumentsObjectUseInSignalHandlers(irDocument, error)
| 2-10 | ||||||||||||||||||
| 191 | *error = error->augment(inputFileName); | - | ||||||||||||||||||
| 192 | return executed 2 times by 1 test: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 193 | } | - | ||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | QmlIR::QmlUnitGenerator generator; | - | ||||||||||||||||||
| 196 | irDocument.javaScriptCompilationUnit = v4CodeGen.generateCompilationUnit( false); | - | ||||||||||||||||||
| 197 | QV4::CompiledData::Unit *unit = generator.generate(irDocument); | - | ||||||||||||||||||
| 198 | unit->flags |= QV4::CompiledData::Unit::StaticData; | - | ||||||||||||||||||
| 199 | unit->flags |= QV4::CompiledData::Unit::PendingTypeCompilation; | - | ||||||||||||||||||
| 200 | irDocument.javaScriptCompilationUnit->data = unit; | - | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | if (!saveFunction(irDocument.javaScriptCompilationUnit.data(), &error->message)
| 0-10 | ||||||||||||||||||
| 203 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | free(unit); | - | ||||||||||||||||||
| 206 | } | - | ||||||||||||||||||
| 207 | return executed 10 times by 1 test: true;return true;Executed by:
executed 10 times by 1 test: return true;Executed by:
| 10 | ||||||||||||||||||
| 208 | } | - | ||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | static bool compileJSFile(const QString &inputFileName, const QString &inputFileUrl, SaveFunction saveFunction, Error *error) | - | ||||||||||||||||||
| 211 | { | - | ||||||||||||||||||
| 212 | QmlIR::Document irDocument( false); | - | ||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | QString sourceCode; | - | ||||||||||||||||||
| 215 | { | - | ||||||||||||||||||
| 216 | QFile f(inputFileName); | - | ||||||||||||||||||
| 217 | if (!f.open(QIODevice::ReadOnly)
| 0 | ||||||||||||||||||
| 218 | error->message = QLatin1String("Error opening ") + inputFileName + QLatin1Char(':') + f.errorString(); | - | ||||||||||||||||||
| 219 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 220 | } | - | ||||||||||||||||||
| 221 | sourceCode = QString::fromUtf8(f.readAll()); | - | ||||||||||||||||||
| 222 | if (f.error() != QFileDevice::NoError
| 0 | ||||||||||||||||||
| 223 | error->message = QLatin1String("Error reading from ") + inputFileName + QLatin1Char(':') + f.errorString(); | - | ||||||||||||||||||
| 224 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 225 | } | - | ||||||||||||||||||
| 226 | } | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | QQmlJS::Engine *engine = &irDocument.jsParserEngine; | - | ||||||||||||||||||
| 229 | QmlIR::ScriptDirectivesCollector directivesCollector(&irDocument); | - | ||||||||||||||||||
| 230 | QQmlJS::Directives *oldDirs = engine->directives(); | - | ||||||||||||||||||
| 231 | engine->setDirectives(&directivesCollector); | - | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | QQmlJS::AST::Program *program = nullptr; | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | { | - | ||||||||||||||||||
| 236 | QQmlJS::Lexer lexer(engine); | - | ||||||||||||||||||
| 237 | lexer.setCode(sourceCode, 1, false); | - | ||||||||||||||||||
| 238 | QQmlJS::Parser parser(engine); | - | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | bool parsed = parser.parseProgram(); | - | ||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 | for (const QQmlJS::DiagnosticMessage &parseError: parser.diagnosticMessages()) { | - | ||||||||||||||||||
| 243 | if (!error->message.isEmpty()
| 0 | ||||||||||||||||||
| 244 | error->message += QLatin1Char('\n'); never executed: error->message += QLatin1Char('\n'); | 0 | ||||||||||||||||||
| 245 | error->message += diagnosticErrorMessage(inputFileName, parseError); | - | ||||||||||||||||||
| 246 | } never executed: end of block | 0 | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | if (!parsed
| 0 | ||||||||||||||||||
| 249 | engine->setDirectives(oldDirs); | - | ||||||||||||||||||
| 250 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 251 | } | - | ||||||||||||||||||
| 252 | - | |||||||||||||||||||
| 253 | program = QQmlJS::AST::cast<QQmlJS::AST::Program*>(parser.rootNode()); | - | ||||||||||||||||||
| 254 | if (!program
| 0 | ||||||||||||||||||
| 255 | lexer.setCode(([]() noexcept -> QString { enum { Size = sizeof(u"" "undefined;")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "undefined;" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }()), 1, false);return qstring_literal_temp; | 0 | ||||||||||||||||||
| 256 | parsed = parser.parseProgram(); | - | ||||||||||||||||||
| 257 | ((parsed) ? static_cast<void>(0) : qt_assert("parsed", __FILE__, 295)); | - | ||||||||||||||||||
| 258 | program = QQmlJS::AST::cast<QQmlJS::AST::Program*>(parser.rootNode()); | - | ||||||||||||||||||
| 259 | ((program) ? static_cast<void>(0) : qt_assert("program", __FILE__, 297)); | - | ||||||||||||||||||
| 260 | } never executed: end of block | 0 | ||||||||||||||||||
| 261 | } | - | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | { | - | ||||||||||||||||||
| 264 | QmlIR::JSCodeGen v4CodeGen(irDocument.code, &irDocument.jsGenerator, | - | ||||||||||||||||||
| 265 | &irDocument.jsModule, &irDocument.jsParserEngine, | - | ||||||||||||||||||
| 266 | irDocument.program, nullptr, | - | ||||||||||||||||||
| 267 | &irDocument.jsGenerator.stringTable, illegalNames); | - | ||||||||||||||||||
| 268 | v4CodeGen.setUseFastLookups(false); | - | ||||||||||||||||||
| 269 | v4CodeGen.generateFromProgram(inputFileName, inputFileUrl, sourceCode, program, | - | ||||||||||||||||||
| 270 | &irDocument.jsModule, QV4::Compiler::ContextType::Global); | - | ||||||||||||||||||
| 271 | QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors(); | - | ||||||||||||||||||
| 272 | if (!jsErrors.isEmpty()
| 0 | ||||||||||||||||||
| 273 | for (const QQmlJS::DiagnosticMessage &e: qAsConst(jsErrors)) { | - | ||||||||||||||||||
| 274 | if (!error->message.isEmpty()
| 0 | ||||||||||||||||||
| 275 | error->message += QLatin1Char('\n'); never executed: error->message += QLatin1Char('\n'); | 0 | ||||||||||||||||||
| 276 | error->message += diagnosticErrorMessage(inputFileName, e); | - | ||||||||||||||||||
| 277 | } never executed: end of block | 0 | ||||||||||||||||||
| 278 | engine->setDirectives(oldDirs); | - | ||||||||||||||||||
| 279 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 280 | } | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | QmlIR::QmlUnitGenerator generator; | - | ||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | irDocument.javaScriptCompilationUnit = v4CodeGen.generateCompilationUnit( false); | - | ||||||||||||||||||
| 285 | QV4::CompiledData::Unit *unit = generator.generate(irDocument); | - | ||||||||||||||||||
| 286 | unit->flags |= QV4::CompiledData::Unit::StaticData; | - | ||||||||||||||||||
| 287 | irDocument.javaScriptCompilationUnit->data = unit; | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | if (!saveFunction(irDocument.javaScriptCompilationUnit.data(), &error->message)
| 0 | ||||||||||||||||||
| 290 | engine->setDirectives(oldDirs); | - | ||||||||||||||||||
| 291 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 292 | } | - | ||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | free(unit); | - | ||||||||||||||||||
| 295 | } | - | ||||||||||||||||||
| 296 | engine->setDirectives(oldDirs); | - | ||||||||||||||||||
| 297 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 298 | } | - | ||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | static bool saveUnitAsCpp(const QString &inputFileName, const QString &outputFileName, QV4::CompiledData::CompilationUnit *unit, QString *errorString) | - | ||||||||||||||||||
| 301 | { | - | ||||||||||||||||||
| 302 | QSaveFile f(outputFileName); | - | ||||||||||||||||||
| 303 | if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)
| 0 | ||||||||||||||||||
| 304 | *errorString = f.errorString(); | - | ||||||||||||||||||
| 305 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 306 | } | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | auto writeStr = [&f, errorString](const QByteArray &data) { | - | ||||||||||||||||||
| 309 | if (f.write(data) != data.size()
| 0 | ||||||||||||||||||
| 310 | *errorString = f.errorString(); | - | ||||||||||||||||||
| 311 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 312 | } | - | ||||||||||||||||||
| 313 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 314 | }; | - | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | if (!writeStr("// ")
| 0 | ||||||||||||||||||
| 317 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 318 | - | |||||||||||||||||||
| 319 | if (!writeStr(inputFileName.toUtf8())
| 0 | ||||||||||||||||||
| 320 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | if (!writeStr("\n")
| 0 | ||||||||||||||||||
| 323 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | if (!writeStr(([]() -> QByteArray { enum { Size = sizeof("namespace QmlCacheGeneratedCode {\nnamespace ") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "namespace QmlCacheGeneratedCode {\nnamespace " }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 326 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | if (!writeStr(symbolNamespaceForPath(inputFileName).toUtf8())
| 0 | ||||||||||||||||||
| 329 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | if (!writeStr(([]() -> QByteArray { enum { Size = sizeof(" {\nextern const unsigned char qmlData alignas(16) [] = {\n") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, " {\nextern const unsigned char qmlData alignas(16) [] = {\n" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 332 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | QByteArray hexifiedData; | - | ||||||||||||||||||
| 335 | { | - | ||||||||||||||||||
| 336 | QByteArray modifiedUnit; | - | ||||||||||||||||||
| 337 | modifiedUnit.resize(unit->data->unitSize); | - | ||||||||||||||||||
| 338 | memcpy(modifiedUnit.data(), unit->data, unit->data->unitSize); | - | ||||||||||||||||||
| 339 | const char *dataPtr = modifiedUnit.data(); | - | ||||||||||||||||||
| 340 | QV4::CompiledData::Unit *unitPtr; | - | ||||||||||||||||||
| 341 | memcpy(&unitPtr, &dataPtr, sizeof(unitPtr)); | - | ||||||||||||||||||
| 342 | unitPtr->flags |= QV4::CompiledData::Unit::StaticData; | - | ||||||||||||||||||
| 343 | - | |||||||||||||||||||
| 344 | QTextStream stream(&hexifiedData); | - | ||||||||||||||||||
| 345 | const uchar *begin = reinterpret_cast<const uchar *>(modifiedUnit.constData()); | - | ||||||||||||||||||
| 346 | const uchar *end = begin + unit->data->unitSize; | - | ||||||||||||||||||
| 347 | stream << hex; | - | ||||||||||||||||||
| 348 | int col = 0; | - | ||||||||||||||||||
| 349 | for (const uchar *data = begin; data < end
| 0 | ||||||||||||||||||
| 350 | if (data > begin
| 0 | ||||||||||||||||||
| 351 | stream << ','; never executed: stream << ','; | 0 | ||||||||||||||||||
| 352 | if (col % 8 == 0
| 0 | ||||||||||||||||||
| 353 | stream << '\n'; | - | ||||||||||||||||||
| 354 | col = 0; | - | ||||||||||||||||||
| 355 | } never executed: end of block | 0 | ||||||||||||||||||
| 356 | stream << "0x" << *data; | - | ||||||||||||||||||
| 357 | } never executed: end of block | 0 | ||||||||||||||||||
| 358 | stream << '\n'; | - | ||||||||||||||||||
| 359 | }; | - | ||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | if (!writeStr(hexifiedData)
| 0 | ||||||||||||||||||
| 362 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 363 | - | |||||||||||||||||||
| 364 | if (!writeStr("};\n}\n}\n")
| 0 | ||||||||||||||||||
| 365 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | if (!f.commit()
| 0 | ||||||||||||||||||
| 368 | *errorString = f.errorString(); | - | ||||||||||||||||||
| 369 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 370 | } | - | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 373 | } | - | ||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | int main(int argc, char **argv) | - | ||||||||||||||||||
| 376 | { | - | ||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | qSetGlobalQHashSeed(0); | - | ||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | QCoreApplication app(argc, argv); | - | ||||||||||||||||||
| 381 | QCoreApplication::setApplicationName(([]() noexcept -> QString { enum { Size = sizeof(u"" "qmlcachegen")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "qmlcachegen" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 382 | QCoreApplication::setApplicationVersion(QLatin1String("5.12.0")); | - | ||||||||||||||||||
| 383 | - | |||||||||||||||||||
| 384 | QCommandLineParser parser; | - | ||||||||||||||||||
| 385 | parser.addHelpOption(); | - | ||||||||||||||||||
| 386 | parser.addVersionOption(); | - | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | QCommandLineOption filterResourceFileOption(([]() noexcept -> QString { enum { Size = sizeof(u"" "filter-resource-file")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "filter-resource-file" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()), QCoreApplication::translate("main", "Filter out QML/JS files from a resource file that can be cached ahead of time instead"));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 389 | parser.addOption(filterResourceFileOption); | - | ||||||||||||||||||
| 390 | QCommandLineOption resourceFileMappingOption(([]() noexcept -> QString { enum { Size = sizeof(u"" "resource-file-mapping")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "resource-file-mapping" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()), QCoreApplication::translate("main", "Path from original resource file to new one"), QCoreApplication::translate("main", "old-name:new-name"));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 391 | parser.addOption(resourceFileMappingOption); | - | ||||||||||||||||||
| 392 | QCommandLineOption resourceOption(([]() noexcept -> QString { enum { Size = sizeof(u"" "resource")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "resource" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()), QCoreApplication::translate("main", "Qt resource file that might later contain one of the compiled files"), QCoreApplication::translate("main", "resource-file-name"));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 393 | parser.addOption(resourceOption); | - | ||||||||||||||||||
| 394 | QCommandLineOption resourcePathOption(([]() noexcept -> QString { enum { Size = sizeof(u"" "resource-path")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "resource-path" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()), QCoreApplication::translate("main", "Qt resource file path corresponding to the file being compiled"), QCoreApplication::translate("main", "resource-path"));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 395 | parser.addOption(resourcePathOption); | - | ||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | QCommandLineOption outputFileOption(([]() noexcept -> QString { enum { Size = sizeof(u"" "o")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "o" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()), QCoreApplication::translate("main", "Output file name"), QCoreApplication::translate("main", "file name"));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 398 | parser.addOption(outputFileOption); | - | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | parser.addPositionalArgument(([]() noexcept -> QString { enum { Size = sizeof(u"" "[qml file]")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "[qml file]" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()),return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 401 | ([]() noexcept -> QString { enum { Size = sizeof(u"" "QML source file to generate cache for.")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "QML source file to generate cache for." }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 12 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 12 times by 1 test: }()));return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||
| 402 | - | |||||||||||||||||||
| 403 | parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); | - | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | parser.process(app); | - | ||||||||||||||||||
| 406 | - | |||||||||||||||||||
| 407 | enum Output { | - | ||||||||||||||||||
| 408 | GenerateCpp, | - | ||||||||||||||||||
| 409 | GenerateCacheFile, | - | ||||||||||||||||||
| 410 | GenerateLoader | - | ||||||||||||||||||
| 411 | } target = GenerateCacheFile; | - | ||||||||||||||||||
| 412 | - | |||||||||||||||||||
| 413 | QString outputFileName; | - | ||||||||||||||||||
| 414 | if (parser.isSet(outputFileOption)
| 0-12 | ||||||||||||||||||
| 415 | outputFileName = parser.value(outputFileOption); never executed: outputFileName = parser.value(outputFileOption); | 0 | ||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | if (outputFileName.endsWith(QLatin1String(".cpp"))
| 0-12 | ||||||||||||||||||
| 418 | target = GenerateCpp; | - | ||||||||||||||||||
| 419 | if (outputFileName.endsWith(QLatin1String("qmlcache_loader.cpp"))
| 0 | ||||||||||||||||||
| 420 | target = GenerateLoader; never executed: target = GenerateLoader; | 0 | ||||||||||||||||||
| 421 | } never executed: end of block | 0 | ||||||||||||||||||
| 422 | - | |||||||||||||||||||
| 423 | const QStringList sources = parser.positionalArguments(); | - | ||||||||||||||||||
| 424 | if (sources.isEmpty()
| 0-12 | ||||||||||||||||||
| 425 | parser.showHelp(); | - | ||||||||||||||||||
| 426 | } never executed: else if (sources.count() > 1end of block
| 0-12 | ||||||||||||||||||
| 427 | fprintf( | - | ||||||||||||||||||
| 428 | stderr | - | ||||||||||||||||||
| 429 | , "%s\n", QtPrivate::asString(([]() noexcept -> QString { enum { Size = sizeof(u"" "Too many input files specified: '")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Too many input files specified: '" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }()) + sources.join(([]() noexcept -> QString { enum { Size = sizeof(u"" "' '")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "' '" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); returnreturn qstring_literal_temp;never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }())) + QLatin1Char('\'')).toLocal8Bit().constData());return qstring_literal_temp; | 0 | ||||||||||||||||||
| 430 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||
| 431 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||
| 432 | ; never executed: return 1 ; | 0 | ||||||||||||||||||
| 433 | } | - | ||||||||||||||||||
| 434 | - | |||||||||||||||||||
| 435 | const QString inputFile = sources.first(); | - | ||||||||||||||||||
| 436 | if (outputFileName.isEmpty()
| 0-12 | ||||||||||||||||||
| 437 | outputFileName = inputFile + QLatin1Char('c'); executed 12 times by 1 test: outputFileName = inputFile + QLatin1Char('c');Executed by:
| 12 | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | if (parser.isSet(filterResourceFileOption)
| 0-12 | ||||||||||||||||||
| 440 | return never executed: filterResourceFile(inputFile, outputFileName);return filterResourceFile(inputFile, outputFileName);never executed: return filterResourceFile(inputFile, outputFileName); | 0 | ||||||||||||||||||
| 441 | } | - | ||||||||||||||||||
| 442 | - | |||||||||||||||||||
| 443 | if (target == GenerateLoader
| 0-12 | ||||||||||||||||||
| 444 | ResourceFileMapper mapper(sources); | - | ||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | Error error; | - | ||||||||||||||||||
| 447 | if (!generateLoader(mapper.qmlCompilerFiles(), outputFileName, parser.values(resourceFileMappingOption), &error.message)
| 0 | ||||||||||||||||||
| 448 | error.augment(QLatin1String("Error generating loader stub: ")).print(); | - | ||||||||||||||||||
| 449 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||
| 450 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||
| 451 | ; never executed: return 1 ; | 0 | ||||||||||||||||||
| 452 | } | - | ||||||||||||||||||
| 453 | return never executed: return 0 ;never executed: return 0 ; | 0 | ||||||||||||||||||
| 454 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||
| 455 | ; never executed: return 0 ; | 0 | ||||||||||||||||||
| 456 | } | - | ||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | QString inputFileUrl = inputFile; | - | ||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | SaveFunction saveFunction; | - | ||||||||||||||||||
| 461 | if (target == GenerateCpp
| 0-12 | ||||||||||||||||||
| 462 | ResourceFileMapper fileMapper(parser.values(resourceOption)); | - | ||||||||||||||||||
| 463 | QString inputResourcePath = parser.value(resourcePathOption); | - | ||||||||||||||||||
| 464 | - | |||||||||||||||||||
| 465 | if (!inputResourcePath.isEmpty()
| 0 | ||||||||||||||||||
| 466 | fprintf( | - | ||||||||||||||||||
| 467 | stderr | - | ||||||||||||||||||
| 468 | , "--%s and --%s are mutually exclusive.\n", | - | ||||||||||||||||||
| 469 | QtPrivate::asString(resourcePathOption.names().first()).toLocal8Bit().constData(), | - | ||||||||||||||||||
| 470 | QtPrivate::asString(resourceOption.names().first()).toLocal8Bit().constData()); | - | ||||||||||||||||||
| 471 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||
| 472 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||
| 473 | ; never executed: return 1 ; | 0 | ||||||||||||||||||
| 474 | } | - | ||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | - | |||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | if (inputResourcePath.isEmpty()
| 0 | ||||||||||||||||||
| 479 | const QStringList resourcePaths = fileMapper.resourcePaths(inputFile); | - | ||||||||||||||||||
| 480 | if (resourcePaths.isEmpty()
| 0 | ||||||||||||||||||
| 481 | fprintf( | - | ||||||||||||||||||
| 482 | stderr | - | ||||||||||||||||||
| 483 | , "No resource path for file: %s\n", QtPrivate::asString(inputFile).toLocal8Bit().constData()); | - | ||||||||||||||||||
| 484 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||
| 485 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||
| 486 | ; never executed: return 1 ; | 0 | ||||||||||||||||||
| 487 | } | - | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | if (resourcePaths.size() != 1
| 0 | ||||||||||||||||||
| 490 | fprintf( | - | ||||||||||||||||||
| 491 | stderr | - | ||||||||||||||||||
| 492 | , "Multiple resource paths for file %s. " | - | ||||||||||||||||||
| 493 | "Use the --%s option to disambiguate:\n", | - | ||||||||||||||||||
| 494 | QtPrivate::asString(inputFile).toLocal8Bit().constData(), | - | ||||||||||||||||||
| 495 | QtPrivate::asString(resourcePathOption.names().first()).toLocal8Bit().constData()); | - | ||||||||||||||||||
| 496 | for (const QString &resourcePath: resourcePaths) | - | ||||||||||||||||||
| 497 | fprintf( never executed: fprintf( stderr , "\t%s\n", QtPrivate::asString(resourcePath).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
| 498 | stderr never executed: fprintf( stderr , "\t%s\n", QtPrivate::asString(resourcePath).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
| 499 | , "\t%s\n", QtPrivate::asString(resourcePath).toLocal8Bit().constData()); never executed: fprintf( stderr , "\t%s\n", QtPrivate::asString(resourcePath).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
| 500 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||
| 501 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||
| 502 | ; never executed: return 1 ; | 0 | ||||||||||||||||||
| 503 | } | - | ||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | inputResourcePath = resourcePaths.first(); | - | ||||||||||||||||||
| 506 | } never executed: end of block | 0 | ||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | inputFileUrl = ([]() noexcept -> QString { enum { Size = sizeof(u"" "qrc://")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "qrc://" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()) + inputResourcePath; | - | ||||||||||||||||||
| 509 | - | |||||||||||||||||||
| 510 | saveFunction = [inputResourcePath, outputFileName](QV4::CompiledData::CompilationUnit *unit, QString *errorString) { | - | ||||||||||||||||||
| 511 | return never executed: saveUnitAsCpp(inputResourcePath, outputFileName, unit, errorString);return saveUnitAsCpp(inputResourcePath, outputFileName, unit, errorString);never executed: return saveUnitAsCpp(inputResourcePath, outputFileName, unit, errorString); | 0 | ||||||||||||||||||
| 512 | }; | - | ||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 515 | saveFunction = [outputFileName](QV4::CompiledData::CompilationUnit *unit, QString *errorString) { | - | ||||||||||||||||||
| 516 | return executed 10 times by 1 test: unit->saveToDisk(outputFileName, errorString);return unit->saveToDisk(outputFileName, errorString);Executed by:
executed 10 times by 1 test: return unit->saveToDisk(outputFileName, errorString);Executed by:
| 10 | ||||||||||||||||||
| 517 | }; | - | ||||||||||||||||||
| 518 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 519 | - | |||||||||||||||||||
| 520 | setupIllegalNames(); | - | ||||||||||||||||||
| 521 | - | |||||||||||||||||||
| 522 | - | |||||||||||||||||||
| 523 | if (inputFile.endsWith(QLatin1String(".qml"))
| 0-12 | ||||||||||||||||||
| 524 | Error error; | - | ||||||||||||||||||
| 525 | if (!compileQmlFile(inputFile, saveFunction, &error)
| 2-10 | ||||||||||||||||||
| 526 | error.augment(QLatin1String("Error compiling qml file: ")).print(); | - | ||||||||||||||||||
| 527 | return executed 2 times by 1 test: return 1 ;Executed by:
executed 2 times by 1 test: return 1 ;Executed by:
| 2 | ||||||||||||||||||
| 528 | 1 executed 2 times by 1 test: return 1 ;Executed by:
| 2 | ||||||||||||||||||
| 529 | ; executed 2 times by 1 test: return 1 ;Executed by:
| 2 | ||||||||||||||||||
| 530 | } | - | ||||||||||||||||||
| 531 | } executed 10 times by 1 test: else if (inputFile.endsWith(QLatin1String(".js"))end of blockExecuted by:
| 0-10 | ||||||||||||||||||
| 532 | Error error; | - | ||||||||||||||||||
| 533 | if (!compileJSFile(inputFile, inputFileUrl, saveFunction, &error)
| 0 | ||||||||||||||||||
| 534 | error.augment(QLatin1String("Error compiling js file: ")).print(); | - | ||||||||||||||||||
| 535 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||
| 536 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||
| 537 | ; never executed: return 1 ; | 0 | ||||||||||||||||||
| 538 | } | - | ||||||||||||||||||
| 539 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 540 | fprintf( | - | ||||||||||||||||||
| 541 | stderr | - | ||||||||||||||||||
| 542 | , "Ignoring %s input file as it is not QML source code - maybe remove from QML_FILES?\n", QtPrivate::asString(inputFile).toLocal8Bit().constData()); | - | ||||||||||||||||||
| 543 | } never executed: end of block | 0 | ||||||||||||||||||
| 544 | - | |||||||||||||||||||
| 545 | return executed 10 times by 1 test: return 0 ;Executed by:
executed 10 times by 1 test: return 0 ;Executed by:
| 10 | ||||||||||||||||||
| 546 | 0 executed 10 times by 1 test: return 0 ;Executed by:
| 10 | ||||||||||||||||||
| 547 | ; executed 10 times by 1 test: return 0 ;Executed by:
| 10 | ||||||||||||||||||
| 548 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |