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 <thomas.hartmann@qt.io>
This commit is contained in:
Ali Kianian
2023-08-30 11:22:29 +03:00
parent 03cb651627
commit 9bcb31b186
2 changed files with 41 additions and 16 deletions

View File

@@ -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<decltype(m1), decltype(m2)>();
}},
m1,
m2);
}
class NodeStatus class NodeStatus
{ {
public: public:
@@ -737,10 +746,7 @@ ConnectionEditorEvaluator::ConnectionEditorEvaluator()
: d(std::make_unique<ConnectionEditorEvaluatorPrivate>()) : d(std::make_unique<ConnectionEditorEvaluatorPrivate>())
{} {}
ConnectionEditorEvaluator::~ConnectionEditorEvaluator() ConnectionEditorEvaluator::~ConnectionEditorEvaluator() {}
{
delete d.release();
}
ConnectionEditorEvaluator::Status ConnectionEditorEvaluator::status() const ConnectionEditorEvaluator::Status ConnectionEditorEvaluator::status() const
{ {
@@ -872,11 +878,6 @@ bool ConnectionEditorEvaluator::visit([[maybe_unused]] QmlJS::AST::Program *prog
return true; return true;
} }
bool ConnectionEditorEvaluator::visit([[maybe_unused]] QmlJS::AST::StatementList *statementList)
{
return d->checkValidityAndReturn(true);
}
bool ConnectionEditorEvaluator::visit([[maybe_unused]] QmlJS::AST::IfStatement *ifStatement) bool ConnectionEditorEvaluator::visit([[maybe_unused]] QmlJS::AST::IfStatement *ifStatement)
{ {
if (d->m_ifStatement++) if (d->m_ifStatement++)
@@ -903,11 +904,6 @@ bool ConnectionEditorEvaluator::visit(QmlJS::AST::IdentifierExpression *identifi
return d->checkValidityAndReturn(true); return d->checkValidityAndReturn(true);
} }
bool ConnectionEditorEvaluator::visit([[maybe_unused]] QmlJS::AST::ExpressionStatement *expressionStatement)
{
return d->checkValidityAndReturn(true);
}
bool ConnectionEditorEvaluator::visit(QmlJS::AST::BinaryExpression *binaryExpression) bool ConnectionEditorEvaluator::visit(QmlJS::AST::BinaryExpression *binaryExpression)
{ {
if (d->isInIfCondition()) { if (d->isInIfCondition()) {
@@ -1070,6 +1066,35 @@ void ConnectionEditorEvaluator::endVisit([[maybe_unused]] QmlJS::AST::CallExpres
d->m_acceptLogArgument = false; 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() void ConnectionEditorEvaluator::throwRecursionDepthError()
{ {
d->checkValidityAndReturn(false, "Recursion depth problem"); d->checkValidityAndReturn(false, "Recursion depth problem");

View File

@@ -32,10 +32,8 @@ protected:
void postVisit(QmlJS::AST::Node *node) override; void postVisit(QmlJS::AST::Node *node) override;
bool visit(QmlJS::AST::Program *program) 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::IfStatement *ifStatement) override;
bool visit(QmlJS::AST::IdentifierExpression *identifier) 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::BinaryExpression *binaryExpression) override;
bool visit(QmlJS::AST::FieldMemberExpression *fieldExpression) override; bool visit(QmlJS::AST::FieldMemberExpression *fieldExpression) override;
bool visit(QmlJS::AST::CallExpression *callExpression) override; bool visit(QmlJS::AST::CallExpression *callExpression) override;
@@ -45,6 +43,8 @@ protected:
void endVisit(QmlJS::AST::Program *program) override; void endVisit(QmlJS::AST::Program *program) override;
void endVisit(QmlJS::AST::FieldMemberExpression *fieldExpression) override; void endVisit(QmlJS::AST::FieldMemberExpression *fieldExpression) override;
void endVisit(QmlJS::AST::CallExpression *callExpression) 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; void throwRecursionDepthError() override;