mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +00:00
Add support for >>= and <<=.
This CL adds `<<=` and `>>=` to the supported operators in WGSL. The ExpandCompoundAssignment transform is used to convert to the expanded form. Bug: tint:1594 Change-Id: I20519052c52d4b69bc90def1acc5c0a30c36fd8a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97980 Auto-Submit: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
6f0884983f
commit
73778d3b0b
@@ -1025,8 +1025,13 @@ Token Lexer::try_punctuation() {
|
||||
type = Token::Type::kGreaterThanEqual;
|
||||
advance(2);
|
||||
} else if (matches(pos() + 1, '>')) {
|
||||
type = Token::Type::kShiftRight;
|
||||
advance(2);
|
||||
if (matches(pos() + 2, '=')) {
|
||||
type = Token::Type::kShiftRightEqual;
|
||||
advance(3);
|
||||
} else {
|
||||
type = Token::Type::kShiftRight;
|
||||
advance(2);
|
||||
}
|
||||
} else {
|
||||
type = Token::Type::kGreaterThan;
|
||||
advance(1);
|
||||
@@ -1036,8 +1041,13 @@ Token Lexer::try_punctuation() {
|
||||
type = Token::Type::kLessThanEqual;
|
||||
advance(2);
|
||||
} else if (matches(pos() + 1, '<')) {
|
||||
type = Token::Type::kShiftLeft;
|
||||
advance(2);
|
||||
if (matches(pos() + 2, '=')) {
|
||||
type = Token::Type::kShiftLeftEqual;
|
||||
advance(3);
|
||||
} else {
|
||||
type = Token::Type::kShiftLeft;
|
||||
advance(2);
|
||||
}
|
||||
} else {
|
||||
type = Token::Type::kLessThan;
|
||||
advance(1);
|
||||
|
||||
@@ -1049,7 +1049,9 @@ INSTANTIATE_TEST_SUITE_P(LexerTest,
|
||||
TokenData{"%=", Token::Type::kModuloEqual},
|
||||
TokenData{"&=", Token::Type::kAndEqual},
|
||||
TokenData{"|=", Token::Type::kOrEqual},
|
||||
TokenData{"^=", Token::Type::kXorEqual}));
|
||||
TokenData{"^=", Token::Type::kXorEqual},
|
||||
TokenData{">>=", Token::Type::kShiftRightEqual},
|
||||
TokenData{"<<=", Token::Type::kShiftLeftEqual}));
|
||||
|
||||
using SplittablePunctuationTest = testing::TestWithParam<TokenData>;
|
||||
TEST_P(SplittablePunctuationTest, Parses) {
|
||||
|
||||
@@ -2924,6 +2924,8 @@ Maybe<const ast::Expression*> ParserImpl::logical_or_expression() {
|
||||
// | and_equal
|
||||
// | or_equal
|
||||
// | xor_equal
|
||||
// | shift_right_equal
|
||||
// | shift_left_equal
|
||||
Maybe<ast::BinaryOp> ParserImpl::compound_assignment_operator() {
|
||||
ast::BinaryOp compound_op = ast::BinaryOp::kNone;
|
||||
if (peek_is(Token::Type::kPlusEqual)) {
|
||||
@@ -2942,6 +2944,10 @@ Maybe<ast::BinaryOp> ParserImpl::compound_assignment_operator() {
|
||||
compound_op = ast::BinaryOp::kOr;
|
||||
} else if (peek_is(Token::Type::kXorEqual)) {
|
||||
compound_op = ast::BinaryOp::kXor;
|
||||
} else if (peek_is(Token::Type::kShiftLeftEqual)) {
|
||||
compound_op = ast::BinaryOp::kShiftLeft;
|
||||
} else if (peek_is(Token::Type::kShiftRightEqual)) {
|
||||
compound_op = ast::BinaryOp::kShiftRight;
|
||||
}
|
||||
if (compound_op != ast::BinaryOp::kNone) {
|
||||
next();
|
||||
|
||||
@@ -111,8 +111,14 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToPhony) {
|
||||
ASSERT_TRUE(a->lhs->Is<ast::PhonyExpression>());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, AssignmentStmt_Parses_CompoundOp) {
|
||||
auto p = parser("a += 123u");
|
||||
struct CompoundData {
|
||||
std::string str;
|
||||
ast::BinaryOp op;
|
||||
};
|
||||
using CompoundOpTest = ParserImplTestWithParam<CompoundData>;
|
||||
TEST_P(CompoundOpTest, CompoundOp) {
|
||||
auto params = GetParam();
|
||||
auto p = parser("a " + params.str + " 123u");
|
||||
auto e = p->assignment_stmt();
|
||||
EXPECT_TRUE(e.matched);
|
||||
EXPECT_FALSE(e.errored);
|
||||
@@ -123,7 +129,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_CompoundOp) {
|
||||
ASSERT_NE(a, nullptr);
|
||||
ASSERT_NE(a->lhs, nullptr);
|
||||
ASSERT_NE(a->rhs, nullptr);
|
||||
EXPECT_EQ(a->op, ast::BinaryOp::kAdd);
|
||||
EXPECT_EQ(a->op, params.op);
|
||||
|
||||
ASSERT_TRUE(a->lhs->Is<ast::IdentifierExpression>());
|
||||
auto* ident = a->lhs->As<ast::IdentifierExpression>();
|
||||
@@ -134,6 +140,18 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_CompoundOp) {
|
||||
EXPECT_EQ(a->rhs->As<ast::IntLiteralExpression>()->suffix,
|
||||
ast::IntLiteralExpression::Suffix::kU);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||
CompoundOpTest,
|
||||
testing::Values(CompoundData{"+=", ast::BinaryOp::kAdd},
|
||||
CompoundData{"-=", ast::BinaryOp::kSubtract},
|
||||
CompoundData{"*=", ast::BinaryOp::kMultiply},
|
||||
CompoundData{"/=", ast::BinaryOp::kDivide},
|
||||
CompoundData{"%=", ast::BinaryOp::kModulo},
|
||||
CompoundData{"&=", ast::BinaryOp::kAnd},
|
||||
CompoundData{"|=", ast::BinaryOp::kOr},
|
||||
CompoundData{"^=", ast::BinaryOp::kXor},
|
||||
CompoundData{">>=", ast::BinaryOp::kShiftRight},
|
||||
CompoundData{"<<=", ast::BinaryOp::kShiftLeft}));
|
||||
|
||||
TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) {
|
||||
auto p = parser("a.b.c[2].d 123");
|
||||
|
||||
@@ -130,6 +130,10 @@ std::string_view Token::TypeToName(Type type) {
|
||||
return "|=";
|
||||
case Token::Type::kXorEqual:
|
||||
return "^=";
|
||||
case Token::Type::kShiftLeftEqual:
|
||||
return "<<=";
|
||||
case Token::Type::kShiftRightEqual:
|
||||
return ">>=";
|
||||
|
||||
case Token::Type::kArray:
|
||||
return "array";
|
||||
|
||||
@@ -140,6 +140,10 @@ class Token {
|
||||
kOrEqual,
|
||||
/// A '^='
|
||||
kXorEqual,
|
||||
/// A '>>='
|
||||
kShiftRightEqual,
|
||||
/// A '<<='
|
||||
kShiftLeftEqual,
|
||||
|
||||
/// A 'array'
|
||||
kArray,
|
||||
|
||||
Reference in New Issue
Block a user