aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-07-04 13:18:55 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-07-04 16:03:36 +0200
commit40ded579bd977dc8fc41aaa1cdfca36822d14fc6 (patch)
tree04069b8c15c05b2625dd45c869b45c37a6c62b3a /tools
parentc1546f8b7005a7cc0ed25f9dc1c762a9c929a25b (diff)
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 throw<X>Error methods in favor of an explicit compilation result. Change-Id: Ie228490aad8efb7885083f6485f931299567f54c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlcachegen/qmlcachegen.cpp25
1 files changed, 14 insertions, 11 deletions
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<QQmlJS::DiagnosticMessage> &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<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;
}
@@ -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;
}