From 48411444b45e1bc1d23e9b7dfceb631fe1380909 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 23 Jul 2021 18:40:32 +0000 Subject: [PATCH] writer/[hlsl,msl]: Default `name_printed` to false Addresses the review comment: https://dawn-review.googlesource.com/c/tint/+/59302/4/src/writer/msl/generator_impl.cc#1932 Change-Id: I4cd6e0e626748328ca2bacc74aa9127cb224cf4a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59448 Auto-Submit: Ben Clayton Commit-Queue: James Price Kokoro: Kokoro Reviewed-by: James Price --- src/writer/hlsl/generator_impl.cc | 9 ++++++--- src/writer/msl/generator_impl.cc | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 5ba656adc7..a85a555fcd 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -2912,6 +2912,9 @@ bool GeneratorImpl::EmitType(std::ostream& out, ast::Access access, const std::string& name, bool* name_printed /* = nullptr */) { + if (name_printed) { + *name_printed = false; + } switch (storage_class) { case ast::StorageClass::kStorage: if (access != ast::Access::kRead) { @@ -3091,11 +3094,11 @@ bool GeneratorImpl::EmitTypeAndName(std::ostream& out, ast::StorageClass storage_class, ast::Access access, const std::string& name) { - bool printed_name = false; - if (!EmitType(out, type, storage_class, access, name, &printed_name)) { + bool name_printed = false; + if (!EmitType(out, type, storage_class, access, name, &name_printed)) { return false; } - if (!name.empty() && !printed_name) { + if (!name.empty() && !name_printed) { out << " " << name; } return true; diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index f4efca46d7..f9cfe89924 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -1930,6 +1930,9 @@ bool GeneratorImpl::EmitType(std::ostream& out, const sem::Type* type, const std::string& name, bool* name_printed /* = nullptr */) { + if (name_printed) { + *name_printed = false; + } if (auto* atomic = type->As()) { if (atomic->Type()->Is()) { out << "atomic_int"; @@ -2000,12 +2003,12 @@ bool GeneratorImpl::EmitType(std::ostream& out, out << " "; if (ptr->StoreType()->Is()) { std::string inner = "(*" + name + ")"; - if (name_printed) { - *name_printed = true; - } if (!EmitType(out, ptr->StoreType(), inner)) { return false; } + if (name_printed) { + *name_printed = true; + } } else { if (!EmitType(out, ptr->StoreType(), "")) { return false;