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 <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-07-23 18:40:32 +00:00 committed by Tint LUCI CQ
parent 294cb95f0e
commit 48411444b4
2 changed files with 12 additions and 6 deletions

View File

@ -2912,6 +2912,9 @@ bool GeneratorImpl::EmitType(std::ostream& out,
ast::Access access, ast::Access access,
const std::string& name, const std::string& name,
bool* name_printed /* = nullptr */) { bool* name_printed /* = nullptr */) {
if (name_printed) {
*name_printed = false;
}
switch (storage_class) { switch (storage_class) {
case ast::StorageClass::kStorage: case ast::StorageClass::kStorage:
if (access != ast::Access::kRead) { if (access != ast::Access::kRead) {
@ -3091,11 +3094,11 @@ bool GeneratorImpl::EmitTypeAndName(std::ostream& out,
ast::StorageClass storage_class, ast::StorageClass storage_class,
ast::Access access, ast::Access access,
const std::string& name) { const std::string& name) {
bool printed_name = false; bool name_printed = false;
if (!EmitType(out, type, storage_class, access, name, &printed_name)) { if (!EmitType(out, type, storage_class, access, name, &name_printed)) {
return false; return false;
} }
if (!name.empty() && !printed_name) { if (!name.empty() && !name_printed) {
out << " " << name; out << " " << name;
} }
return true; return true;

View File

@ -1930,6 +1930,9 @@ bool GeneratorImpl::EmitType(std::ostream& out,
const sem::Type* type, const sem::Type* type,
const std::string& name, const std::string& name,
bool* name_printed /* = nullptr */) { bool* name_printed /* = nullptr */) {
if (name_printed) {
*name_printed = false;
}
if (auto* atomic = type->As<sem::Atomic>()) { if (auto* atomic = type->As<sem::Atomic>()) {
if (atomic->Type()->Is<sem::I32>()) { if (atomic->Type()->Is<sem::I32>()) {
out << "atomic_int"; out << "atomic_int";
@ -2000,12 +2003,12 @@ bool GeneratorImpl::EmitType(std::ostream& out,
out << " "; out << " ";
if (ptr->StoreType()->Is<sem::Array>()) { if (ptr->StoreType()->Is<sem::Array>()) {
std::string inner = "(*" + name + ")"; std::string inner = "(*" + name + ")";
if (name_printed) {
*name_printed = true;
}
if (!EmitType(out, ptr->StoreType(), inner)) { if (!EmitType(out, ptr->StoreType(), inner)) {
return false; return false;
} }
if (name_printed) {
*name_printed = true;
}
} else { } else {
if (!EmitType(out, ptr->StoreType(), "")) { if (!EmitType(out, ptr->StoreType(), "")) {
return false; return false;