diff options
author | Semih Yavuz <semih.yavuz@qt.io> | 2023-05-04 14:43:25 +0200 |
---|---|---|
committer | Semih Yavuz <semih.yavuz@qt.io> | 2023-05-05 19:56:42 +0200 |
commit | feca8417f610f8f64193292379eb9e0b9423936f (patch) | |
tree | bcbcd7c61bde4e88db6b931365135410a9df3251 /src | |
parent | d32ccc5f1b7ccb5e2ffe1fcf25417a3131126e1d (diff) | |
download | qtdeclarative-feca8417f610f8f64193292379eb9e0b9423936f.tar.gz |
qmldom: Add more literals
Dom construction fails before this commit if it encounters one of
null expression, true and false literals. Add dom representation for
them.
Change-Id: I2dbb2ebfce83b32426eb5e159fe9e4f0f68c56c3
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qmldom/qqmldomastcreator.cpp | 33 | ||||
-rw-r--r-- | src/qmldom/qqmldomastcreator_p.h | 3 | ||||
-rw-r--r-- | src/qmldom/qqmldomscriptelements_p.h | 2 |
3 files changed, 37 insertions, 1 deletions
diff --git a/src/qmldom/qqmldomastcreator.cpp b/src/qmldom/qqmldomastcreator.cpp index 0462c7c65c..ae6acbb366 100644 --- a/src/qmldom/qqmldomastcreator.cpp +++ b/src/qmldom/qqmldomastcreator.cpp @@ -1155,6 +1155,39 @@ bool QQmlDomAstCreator::visit(AST::StringLiteral *expression) return true; } +bool QQmlDomAstCreator::visit(AST::NullExpression *expression) +{ + if (!m_enableScriptExpressions) + return false; + + auto current = makeScriptElement<ScriptElements::Literal>(expression); + current->setLiteralValue(nullptr); + pushScriptElement(current); + return true; +} + +bool QQmlDomAstCreator::visit(AST::TrueLiteral *expression) +{ + if (!m_enableScriptExpressions) + return false; + + auto current = makeScriptElement<ScriptElements::Literal>(expression); + current->setLiteralValue(true); + pushScriptElement(current); + return true; +} + +bool QQmlDomAstCreator::visit(AST::FalseLiteral *expression) +{ + if (!m_enableScriptExpressions) + return false; + + auto current = makeScriptElement<ScriptElements::Literal>(expression); + current->setLiteralValue(false); + pushScriptElement(current); + return true; +} + bool QQmlDomAstCreator::visit(AST::VariableDeclarationList *) { if (!m_enableScriptExpressions) diff --git a/src/qmldom/qqmldomastcreator_p.h b/src/qmldom/qqmldomastcreator_p.h index a99294fd23..77fe2af823 100644 --- a/src/qmldom/qqmldomastcreator_p.h +++ b/src/qmldom/qqmldomastcreator_p.h @@ -321,6 +321,9 @@ public: bool visit(AST::IdentifierExpression *expression) override; bool visit(AST::NumericLiteral *expression) override; bool visit(AST::StringLiteral *expression) override; + bool visit(AST::NullExpression *expression) override; + bool visit(AST::TrueLiteral *expression) override; + bool visit(AST::FalseLiteral *expression) override; void throwRecursionDepthError() override; diff --git a/src/qmldom/qqmldomscriptelements_p.h b/src/qmldom/qqmldomscriptelements_p.h index 0ddcb54938..00cc25fe49 100644 --- a/src/qmldom/qqmldomscriptelements_p.h +++ b/src/qmldom/qqmldomscriptelements_p.h @@ -167,7 +167,7 @@ public: using BaseT::BaseT; ~Literal() override{}; - using VariantT = std::variant<QString, double>; + using VariantT = std::variant<QString, double, bool, std::nullptr_t>; void setLiteralValue(VariantT value) { m_value = value; } VariantT literalValue() const { return m_value; } |