diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-01-30 10:51:34 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-01-31 14:46:03 +0100 |
commit | 85f15e2af40be1e9500fe600daba31839b904ef4 (patch) | |
tree | d37e14b6940ef04cc04cc2c5e4fd37457ff9ae3e /src/qml/parser | |
parent | a87ad432a002614a5cca4d635ead5aedb97ba757 (diff) |
Required properties: Allow retroactive require specification
It is now possible to mark a property of a parent class as required in
the child by writing required <propertyName>
Change-Id: I9e9d58c7b5c00577b056e905b39744b2fa359ea0
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/parser')
-rw-r--r-- | src/qml/parser/qqmljs.g | 13 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast.cpp | 8 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast_p.h | 25 | ||||
-rw-r--r-- | src/qml/parser/qqmljsastfwd_p.h | 1 | ||||
-rw-r--r-- | src/qml/parser/qqmljsastvisitor_p.h | 3 |
5 files changed, 48 insertions, 2 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index b0f0f6a809..879de92e5f 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -1350,6 +1350,18 @@ OptionalSemicolon: | Semicolon; and then we would miss a semicolon (see tests/auto/quick/qquickvisualdatamodel/data/objectlist.qml)*/ ./ +UiRequired: T_REQUIRED QmlIdentifier Semicolon; +/. + case $rule_number: { + AST::UiRequired *node = new (pool) AST::UiRequired(stringRef(2)); + node->requiredToken = loc(1); + node->semicolonToken = loc(3); + sym(1).Node = node; + } break; +./ + +UiObjectMember: UiRequired; + UiObjectMember: T_REQUIRED UiObjectMemberPropertyNoInitialiser; /. case $rule_number: { @@ -1360,7 +1372,6 @@ UiObjectMember: T_REQUIRED UiObjectMemberPropertyNoInitialiser; } break; ./ - UiObjectMemberWithScriptStatement: T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScriptStatement OptionalSemicolon; /. case $rule_number: { diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp index aa3e8ab5e3..416916c547 100644 --- a/src/qml/parser/qqmljsast.cpp +++ b/src/qml/parser/qqmljsast.cpp @@ -1554,6 +1554,14 @@ void UiInlineComponent::accept0(Visitor *visitor) visitor->endVisit(this); } +void UiRequired::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + } + + visitor->endVisit(this); +} + } } // namespace QQmlJS::AST QT_END_NAMESPACE diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index 48a994cd33..f3369676e9 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -258,7 +258,8 @@ public: Kind_UiHeaderItemList, Kind_UiEnumDeclaration, Kind_UiEnumMemberList, - Kind_UiVersionSpecifier + Kind_UiVersionSpecifier, + Kind_UiRequired }; inline Node() {} @@ -3103,6 +3104,28 @@ public: SourceLocation semicolonToken; }; +class QML_PARSER_EXPORT UiRequired: public Node +{ +public: + QQMLJS_DECLARE_AST_NODE(UiRequired) + + UiRequired(QStringRef name) + :name(name) + { kind = K; } + + void accept0(Visitor *visitor) override; + + SourceLocation firstSourceLocation() const override + { return requiredToken; } + + SourceLocation lastSourceLocation() const override + { return semicolonToken; } + + QStringRef name; + SourceLocation requiredToken; + SourceLocation semicolonToken; +}; + class QML_PARSER_EXPORT UiHeaderItemList: public Node { public: diff --git a/src/qml/parser/qqmljsastfwd_p.h b/src/qml/parser/qqmljsastfwd_p.h index 8a8ee2dfae..fe260e2bb5 100644 --- a/src/qml/parser/qqmljsastfwd_p.h +++ b/src/qml/parser/qqmljsastfwd_p.h @@ -183,6 +183,7 @@ class UiHeaderItemList; class UiEnumDeclaration; class UiEnumMemberList; class UiVersionSpecifier; +class UiRequired; } // namespace AST } // namespace QQmlJS diff --git a/src/qml/parser/qqmljsastvisitor_p.h b/src/qml/parser/qqmljsastvisitor_p.h index d6b92990ad..fcc48da1d3 100644 --- a/src/qml/parser/qqmljsastvisitor_p.h +++ b/src/qml/parser/qqmljsastvisitor_p.h @@ -414,6 +414,9 @@ public: virtual bool visit(TypeAnnotation *) { return true; } virtual void endVisit(TypeAnnotation *) {} + virtual bool visit(UiRequired *) { return true; } + virtual void endVisit(UiRequired *) {} + virtual void throwRecursionDepthError() = 0; quint16 recursionDepth() const { return m_recursionDepth; } |