diff options
| author | Olivier De Cannière <olivier.decanniere@qt.io> | 2024-08-02 10:13:44 +0200 |
|---|---|---|
| committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2024-08-21 19:57:58 +0200 |
| commit | d70abd83dc94d722cde6d4b19b9d35c5f4f19946 (patch) | |
| tree | 1119f20b6f64d71b4602e7d4e39f7dc0c2caeec4 /src/qmlcompiler/qqmljsfunctioninitializer.cpp | |
| parent | 06577c9e80eb150b6b9e76e7805bfed1abbae82d (diff) | |
Compiler: Create infrastructure to support multiple warnings
Currently only one DiagnosticMessage can be stored at a time when using
the compiler. However, we want to be able to show more than one to the
user.
Therefore, use a list that gets passed inside the compiler instead of a
pointer to the sole error.
This also means that the error is valid by its very existence. There is
no need to check validity explicitly anymore.
Task-number: QTBUG-127624
Change-Id: I356db917b86703b508dc1ad52de7825d82eafd71
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsfunctioninitializer.cpp')
| -rw-r--r-- | src/qmlcompiler/qqmljsfunctioninitializer.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/qmlcompiler/qqmljsfunctioninitializer.cpp b/src/qmlcompiler/qqmljsfunctioninitializer.cpp index 1c90167691..5d0b32a5af 100644 --- a/src/qmlcompiler/qqmljsfunctioninitializer.cpp +++ b/src/qmlcompiler/qqmljsfunctioninitializer.cpp @@ -55,12 +55,14 @@ static QString bindingTypeDescription(QmlIR::Binding::Type type) void QQmlJSFunctionInitializer::populateSignature( const QV4::Compiler::Context *context, QQmlJS::AST::FunctionExpression *ast, - QQmlJSCompilePass::Function *function, QQmlJS::DiagnosticMessage *error) + QQmlJSCompilePass::Function *function, QList<QQmlJS::DiagnosticMessage> *errors) { const auto signatureError = [&](const QString &message) { - error->type = QtWarningMsg; - error->loc = ast->firstSourceLocation(); - error->message = message; + QQmlJS::DiagnosticMessage error; + error.type = QtWarningMsg; + error.loc = ast->firstSourceLocation(); + error.message = message; + *errors << error; function->isFullyTyped = false; }; @@ -143,13 +145,9 @@ void QQmlJSFunctionInitializer::populateSignature( static void diagnose( const QString &message, QtMsgType type, const QQmlJS::SourceLocation &location, - QQmlJS::DiagnosticMessage *error) + QList<QQmlJS::DiagnosticMessage> *errors) { - *error = QQmlJS::DiagnosticMessage{ - message, - type, - location - }; + *errors << QQmlJS::DiagnosticMessage{ message, type, location }; } QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( @@ -157,7 +155,7 @@ QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( const QString &propertyName, QQmlJS::AST::Node *astNode, const QmlIR::Binding &irBinding, - QQmlJS::DiagnosticMessage *error) + QList<QQmlJS::DiagnosticMessage> *errors) { QQmlJS::SourceLocation bindingLocation; bindingLocation.startLine = irBinding.location.line(); @@ -169,7 +167,7 @@ QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( if (irBinding.type() != QmlIR::Binding::Type_Script) { diagnose(u"Binding is not a script binding, but %1."_s.arg( bindingTypeDescription(QmlIR::Binding::Type(quint32(irBinding.type())))), - QtDebugMsg, bindingLocation, error); + QtDebugMsg, bindingLocation, errors); } function.isProperty = m_objectType->hasProperty(propertyName); @@ -193,7 +191,7 @@ QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( if (type.isNull()) { diagnose(u"Cannot resolve the argument type %1."_s.arg( arguments[i].typeName()), - QtDebugMsg, bindingLocation, error); + QtDebugMsg, bindingLocation, errors); function.argumentTypes.append( m_typeResolver->tracked( m_typeResolver->globalType(m_typeResolver->varType()))); @@ -208,7 +206,7 @@ QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( if (!function.isSignalHandler) { diagnose(u"Could not compile signal handler for %1: The signal does not exist"_s.arg( *signalName), - QtWarningMsg, bindingLocation, error); + QtWarningMsg, bindingLocation, errors); } } } @@ -218,7 +216,7 @@ QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( if (!function.isProperty) { diagnose(u"Could not compile binding for %1: The property does not exist"_s.arg( propertyName), - QtWarningMsg, bindingLocation, error); + QtWarningMsg, bindingLocation, errors); } const auto property = m_objectType->property(propertyName); @@ -235,7 +233,7 @@ QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( // most commonly used to enable generalized grouped properties. message += u" You may want use ID-based grouped properties here."; } - diagnose(message, QtWarningMsg, bindingLocation, error); + diagnose(message, QtWarningMsg, bindingLocation, errors); } if (!property.bindable().isEmpty() && !property.isPrivate()) @@ -262,14 +260,14 @@ QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( ast->rbraceToken = astNode->lastSourceLocation(); } - populateSignature(context, ast, &function, error); + populateSignature(context, ast, &function, errors); return function; } QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( const QV4::Compiler::Context *context, const QString &functionName, QQmlJS::AST::Node *astNode, - QQmlJS::DiagnosticMessage *error) + QList<QQmlJS::DiagnosticMessage> *errors) { Q_UNUSED(functionName); @@ -279,7 +277,7 @@ QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( auto ast = astNode->asFunctionDefinition(); Q_ASSERT(ast); - populateSignature(context, ast, &function, error); + populateSignature(context, ast, &function, errors); return function; } |
