[msl-writer] Emit member accessors.

This CL adds emission of member accessor expressions to the MSL writer.

Bug: tint:8
Change-Id: I21d8564880c44d719c89dca2a10cd97ccb1e2cd7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24120
Reviewed-by: David Neto <dneto@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 0187d06..5c67ee8 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -895,6 +895,7 @@
     "src/writer/msl/generator_impl_identifier_test.cc",
     "src/writer/msl/generator_impl_if_test.cc",
     "src/writer/msl/generator_impl_kill_test.cc",
+    "src/writer/msl/generator_impl_member_accessor_test.cc",
     "src/writer/msl/generator_impl_return_test.cc",
     "src/writer/msl/generator_impl_test.cc",
     "src/writer/msl/generator_impl_type_test.cc",
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 25adf24..ab01566 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -503,6 +503,7 @@
     writer/msl/generator_impl_identifier_test.cc
     writer/msl/generator_impl_if_test.cc
     writer/msl/generator_impl_kill_test.cc
+    writer/msl/generator_impl_member_accessor_test.cc
     writer/msl/generator_impl_return_test.cc
     writer/msl/generator_impl_test.cc
     writer/msl/generator_impl_type_test.cc
diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc
index 9bb51c1..8d05206 100644
--- a/src/writer/msl/generator_impl.cc
+++ b/src/writer/msl/generator_impl.cc
@@ -25,6 +25,7 @@
 #include "src/ast/function.h"
 #include "src/ast/identifier_expression.h"
 #include "src/ast/if_statement.h"
+#include "src/ast/member_accessor_expression.h"
 #include "src/ast/return_statement.h"
 #include "src/ast/sint_literal.h"
 #include "src/ast/type/alias_type.h"
@@ -304,6 +305,9 @@
   if (expr->IsIdentifier()) {
     return EmitIdentifier(expr->AsIdentifier());
   }
+  if (expr->IsMemberAccessor()) {
+    return EmitMemberAccessor(expr->AsMemberAccessor());
+  }
   if (expr->IsUnaryOp()) {
     return EmitUnaryOp(expr->AsUnaryOp());
   }
@@ -433,6 +437,17 @@
 
   return true;
 }
+
+bool GeneratorImpl::EmitMemberAccessor(ast::MemberAccessorExpression* expr) {
+  if (!EmitExpression(expr->structure())) {
+    return false;
+  }
+
+  out_ << ".";
+
+  return EmitExpression(expr->member());
+}
+
 bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) {
   make_indent();
 
diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h
index 12517a3..e27a071 100644
--- a/src/writer/msl/generator_impl.h
+++ b/src/writer/msl/generator_impl.h
@@ -96,6 +96,10 @@
   /// @param lit the literal to emit
   /// @returns true if the literal was successfully emitted
   bool EmitLiteral(ast::Literal* lit);
+  /// Handles a member accessor expression
+  /// @param expr the member accessor expression
+  /// @returns true if the member accessor was emitted
+  bool EmitMemberAccessor(ast::MemberAccessorExpression* expr);
   /// Handles return statements
   /// @param stmt the statement to emit
   /// @returns true if the statement was successfully emitted
diff --git a/src/writer/msl/generator_impl_member_accessor_test.cc b/src/writer/msl/generator_impl_member_accessor_test.cc
new file mode 100644
index 0000000..a21e81b
--- /dev/null
+++ b/src/writer/msl/generator_impl_member_accessor_test.cc
@@ -0,0 +1,43 @@
+// Copyright 2020 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 <memory>
+
+#include "gtest/gtest.h"
+#include "src/ast/identifier_expression.h"
+#include "src/ast/member_accessor_expression.h"
+#include "src/writer/msl/generator_impl.h"
+
+namespace tint {
+namespace writer {
+namespace msl {
+namespace {
+
+using MslGeneratorImplTest = testing::Test;
+
+TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
+  auto str = std::make_unique<ast::IdentifierExpression>("str");
+  auto mem = std::make_unique<ast::IdentifierExpression>("mem");
+
+  ast::MemberAccessorExpression expr(std::move(str), std::move(mem));
+
+  GeneratorImpl g;
+  ASSERT_TRUE(g.EmitExpression(&expr)) << g.error();
+  EXPECT_EQ(g.result(), "str.mem");
+}
+
+}  // namespace
+}  // namespace msl
+}  // namespace writer
+}  // namespace tint