From 9bcb31b1860909ce424128dfbaf13ba55a760267 Mon Sep 17 00:00:00 2001 From: Ali Kianian Date: Wed, 30 Aug 2023 11:22:29 +0300 Subject: [PATCH] QmlDesigner: Modify the failure for two tests - Multiple statements are not allowed - Matched statement should have the same type in the case that we have both Ok and Ko statements Change-Id: I2aedc1fe7f7f2096af0293c019d0caeb9771646f Reviewed-by: Thomas Hartmann --- .../connectioneditorevaluator.cpp | 53 ++++++++++++++----- .../connectioneditorevaluator.h | 4 +- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.cpp b/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.cpp index e77e270304f..fccb5b11941 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.cpp @@ -84,6 +84,15 @@ inline bool isAcceptedIfBinaryOperator(const int &operation) } } +inline bool areOfTheSameTypeMatch(const MatchedStatement &m1, const MatchedStatement &m2) +{ + return std::visit(Overload{[](auto m1, auto m2) -> bool { + return std::is_same(); + }}, + m1, + m2); +} + class NodeStatus { public: @@ -737,10 +746,7 @@ ConnectionEditorEvaluator::ConnectionEditorEvaluator() : d(std::make_unique()) {} -ConnectionEditorEvaluator::~ConnectionEditorEvaluator() -{ - delete d.release(); -} +ConnectionEditorEvaluator::~ConnectionEditorEvaluator() {} ConnectionEditorEvaluator::Status ConnectionEditorEvaluator::status() const { @@ -872,11 +878,6 @@ bool ConnectionEditorEvaluator::visit([[maybe_unused]] QmlJS::AST::Program *prog return true; } -bool ConnectionEditorEvaluator::visit([[maybe_unused]] QmlJS::AST::StatementList *statementList) -{ - return d->checkValidityAndReturn(true); -} - bool ConnectionEditorEvaluator::visit([[maybe_unused]] QmlJS::AST::IfStatement *ifStatement) { if (d->m_ifStatement++) @@ -903,11 +904,6 @@ bool ConnectionEditorEvaluator::visit(QmlJS::AST::IdentifierExpression *identifi return d->checkValidityAndReturn(true); } -bool ConnectionEditorEvaluator::visit([[maybe_unused]] QmlJS::AST::ExpressionStatement *expressionStatement) -{ - return d->checkValidityAndReturn(true); -} - bool ConnectionEditorEvaluator::visit(QmlJS::AST::BinaryExpression *binaryExpression) { if (d->isInIfCondition()) { @@ -1070,6 +1066,35 @@ void ConnectionEditorEvaluator::endVisit([[maybe_unused]] QmlJS::AST::CallExpres d->m_acceptLogArgument = false; } +void ConnectionEditorEvaluator::endVisit(QmlJS::AST::IfStatement *ifStatement) +{ + if (status() != UnFinished) + return; + + std::visit(Overload{[this](const ConnectionEditorStatements::ConditionalStatement &statement) { + if (!ConnectionEditorStatements::isEmptyStatement(statement.ok) + && !ConnectionEditorStatements::isEmptyStatement(statement.ko)) { + qDebug() << Q_FUNC_INFO + << areOfTheSameTypeMatch(statement.ok, statement.ko); + if (!areOfTheSameTypeMatch(statement.ok, statement.ko)) { + d->checkValidityAndReturn( + false, "Matched statements types are mismatched"); + } + } + }, + [](auto) {}}, + d->m_handler); +} + +void ConnectionEditorEvaluator::endVisit(QmlJS::AST::StatementList *statementList) +{ + if (status() != UnFinished) + return; + + if (d->nodeStatus().children() > 1) + d->checkValidityAndReturn(false, "More than one statements are available."); +} + void ConnectionEditorEvaluator::throwRecursionDepthError() { d->checkValidityAndReturn(false, "Recursion depth problem"); diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.h b/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.h index c4465fcc32f..2cc285ed6c5 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.h +++ b/src/plugins/qmldesigner/components/connectioneditor/connectioneditorevaluator.h @@ -32,10 +32,8 @@ protected: void postVisit(QmlJS::AST::Node *node) override; bool visit(QmlJS::AST::Program *program) override; - bool visit(QmlJS::AST::StatementList *statementList) override; bool visit(QmlJS::AST::IfStatement *ifStatement) override; bool visit(QmlJS::AST::IdentifierExpression *identifier) override; - bool visit(QmlJS::AST::ExpressionStatement *expressionStatement) override; bool visit(QmlJS::AST::BinaryExpression *binaryExpression) override; bool visit(QmlJS::AST::FieldMemberExpression *fieldExpression) override; bool visit(QmlJS::AST::CallExpression *callExpression) override; @@ -45,6 +43,8 @@ protected: void endVisit(QmlJS::AST::Program *program) override; void endVisit(QmlJS::AST::FieldMemberExpression *fieldExpression) override; void endVisit(QmlJS::AST::CallExpression *callExpression) override; + void endVisit(QmlJS::AST::IfStatement *ifStatement) override; + void endVisit(QmlJS::AST::StatementList *statementList) override; void throwRecursionDepthError() override;