ast: Add PhonyExpression

Represents the `_` in a phony assignment `_ = <expr>`

Bug: tint:1213
Change-Id: Ifb070277b7872aa5ae405e467e28191e625c4c5a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67062
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/BUILD.gn b/src/BUILD.gn
index fa51b86..aa4a13d 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -274,6 +274,8 @@
     "ast/node.h",
     "ast/override_decoration.cc",
     "ast/override_decoration.h",
+    "ast/phony_expression.cc",
+    "ast/phony_expression.h",
     "ast/pipeline_stage.cc",
     "ast/pipeline_stage.h",
     "ast/pointer.cc",
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f188da1..53def54 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -138,6 +138,8 @@
   ast/node.h
   ast/override_decoration.cc
   ast/override_decoration.h
+  ast/phony_expression.cc
+  ast/phony_expression.h
   ast/pipeline_stage.cc
   ast/pipeline_stage.h
   ast/pointer.cc
@@ -619,6 +621,7 @@
     ast/module_test.cc
     ast/multisampled_texture_test.cc
     ast/override_decoration_test.cc
+    ast/phony_expression_test.cc
     ast/pointer_test.cc
     ast/return_statement_test.cc
     ast/sampled_texture_test.cc
diff --git a/src/ast/phony_expression.cc b/src/ast/phony_expression.cc
new file mode 100644
index 0000000..dc01f03
--- /dev/null
+++ b/src/ast/phony_expression.cc
@@ -0,0 +1,38 @@
+// Copyright 2021 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/ast/phony_expression.h"
+
+#include "src/program_builder.h"
+
+TINT_INSTANTIATE_TYPEINFO(tint::ast::PhonyExpression);
+
+namespace tint {
+namespace ast {
+
+PhonyExpression::PhonyExpression(ProgramID pid, const Source& src)
+    : Base(pid, src) {}
+
+PhonyExpression::PhonyExpression(PhonyExpression&&) = default;
+
+PhonyExpression::~PhonyExpression() = default;
+
+const PhonyExpression* PhonyExpression::Clone(CloneContext* ctx) const {
+  // Clone arguments outside of create() call to have deterministic ordering
+  auto src = ctx->Clone(source);
+  return ctx->dst->create<PhonyExpression>(src);
+}
+
+}  // namespace ast
+}  // namespace tint
diff --git a/src/ast/phony_expression.h b/src/ast/phony_expression.h
new file mode 100644
index 0000000..edfc7d0
--- /dev/null
+++ b/src/ast/phony_expression.h
@@ -0,0 +1,45 @@
+// Copyright 2021 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_AST_PHONY_EXPRESSION_H_
+#define SRC_AST_PHONY_EXPRESSION_H_
+
+#include "src/ast/expression.h"
+
+namespace tint {
+namespace ast {
+
+/// Represents the `_` of a phony assignment `_ = <expr>`
+/// @see https://www.w3.org/TR/WGSL/#phony-assignment-section
+class PhonyExpression : public Castable<PhonyExpression, Expression> {
+ public:
+  /// Constructor
+  /// @param pid the identifier of the program that owns this node
+  /// @param src the source of this node
+  PhonyExpression(ProgramID pid, const Source& src);
+  /// Move constructor
+  PhonyExpression(PhonyExpression&&);
+  ~PhonyExpression() override;
+
+  /// Clones this node and all transitive child nodes using the `CloneContext`
+  /// `ctx`.
+  /// @param ctx the clone context
+  /// @return the newly cloned node
+  const PhonyExpression* Clone(CloneContext* ctx) const override;
+};
+
+}  // namespace ast
+}  // namespace tint
+
+#endif  // SRC_AST_PHONY_EXPRESSION_H_
diff --git a/src/ast/phony_expression_test.cc b/src/ast/phony_expression_test.cc
new file mode 100644
index 0000000..15ec654
--- /dev/null
+++ b/src/ast/phony_expression_test.cc
@@ -0,0 +1,42 @@
+// Copyright 2021 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/ast/test_helper.h"
+
+namespace tint {
+namespace ast {
+namespace {
+
+using IdentifierExpressionTest = TestHelper;
+
+TEST_F(IdentifierExpressionTest, Creation) {
+  EXPECT_NE(Phony(), nullptr);
+}
+
+TEST_F(IdentifierExpressionTest, Creation_WithSource) {
+  auto* p = Phony(Source{{20, 2}});
+
+  auto src = p->source;
+  EXPECT_EQ(src.range.begin.line, 20u);
+  EXPECT_EQ(src.range.begin.column, 2u);
+}
+
+TEST_F(IdentifierExpressionTest, IsPhony) {
+  auto* p = Phony();
+  EXPECT_TRUE(p->Is<PhonyExpression>());
+}
+
+}  // namespace
+}  // namespace ast
+}  // namespace tint
diff --git a/src/program_builder.h b/src/program_builder.h
index 0928b8e..cf9103a 100644
--- a/src/program_builder.h
+++ b/src/program_builder.h
@@ -49,6 +49,7 @@
 #include "src/ast/module.h"
 #include "src/ast/multisampled_texture.h"
 #include "src/ast/override_decoration.h"
+#include "src/ast/phony_expression.h"
 #include "src/ast/pointer.h"
 #include "src/ast/return_statement.h"
 #include "src/ast/sampled_texture.h"
@@ -1618,6 +1619,15 @@
                                        ExprList(std::forward<ARGS>(args)...));
   }
 
+  /// @param source the source information
+  /// @returns a `ast::PhonyExpression`
+  const ast::PhonyExpression* Phony(const Source& source) {
+    return create<ast::PhonyExpression>(source);
+  }
+
+  /// @returns a `ast::PhonyExpression`
+  const ast::PhonyExpression* Phony() { return create<ast::PhonyExpression>(); }
+
   /// @param expr the expression to ignore
   /// @returns a `ast::CallStatement` that calls the `ignore` intrinsic which is
   /// passed the single `expr` argument
diff --git a/test/BUILD.gn b/test/BUILD.gn
index cefec25..53dc747 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -189,6 +189,7 @@
     "../src/ast/module_test.cc",
     "../src/ast/multisampled_texture_test.cc",
     "../src/ast/override_decoration_test.cc",
+    "../src/ast/phony_expression_test.cc",
     "../src/ast/pointer_test.cc",
     "../src/ast/return_statement_test.cc",
     "../src/ast/sampled_texture_test.cc",