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/qmlcachegen.cpp') 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