From f6e90ba533b9b4b98cfcae3d31731c1cb794ee77 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 15 Nov 2019 15:49:23 +0100 Subject: Add (and ignore for now) type assertions to QML You can write "(something as Foo)" to give hints to any tools that you expect something to be a Foo at this place. This is not a conversion and ignored at runtime for now. Eventually the compiler will verify that the type assertions are plausible and error out if they aren't. Change-Id: I21c8705bb387f7ab2cbc153293dbf477663afe87 Reviewed-by: Fabian Kosmale --- src/qml/parser/qqmljs.g | 14 ++++++++++++++ src/qml/parser/qqmljsast_p.h | 1 + 2 files changed, 15 insertions(+) (limited to 'src/qml/parser') diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index f7b528ce13..ea105e7e22 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -2513,6 +2513,20 @@ RelationalExpression_In: RelationalExpression_In T_IN ShiftExpression; } break; ./ +TypeAssertExpression_In: RelationalExpression_In T_AS Type; +/. case $rule_number: Q_FALLTHROUGH(); ./ +TypeAssertExpression: RelationalExpression T_AS Type; +/. + case $rule_number: { + AST::BinaryExpression *node = new (pool) AST::BinaryExpression(sym(1).Expression, QSOperator::As, sym(3).Expression); + node->operatorToken = loc(2); + sym(1).Node = node; + } break; +./ + +RelationalExpression_In: TypeAssertExpression_In; +RelationalExpression: TypeAssertExpression; + EqualityExpression_In: RelationalExpression_In; EqualityExpression: RelationalExpression; diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index fcf9933e67..bc0a467f40 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -104,6 +104,7 @@ enum Op { URShift, InplaceURightShift, InplaceXor, + As, Invalid }; -- cgit v1.2.3