mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-08 13:14:56 +00:00
writer/msl: Fix array type emission
Add a special-case for pointer-to-array types, where the * and the variable name need to be enclosed in parentheses in between the array element type and the size. Move the `const` qualifier to before the array size. Add E2E tests to cover all non-handle types used in various places. Fixed: tint:822 Change-Id: I93b7d6867f92397aa47838ab2c94530b6e634617 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51823 Auto-Submit: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
351ac4a009
commit
0c978e9bbb
@@ -1314,8 +1314,8 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
|
||||
if (!EmitType(type, program_->Symbols().NameFor(v->symbol()))) {
|
||||
return false;
|
||||
}
|
||||
// Array name is output as part of the type
|
||||
if (!type->Is<sem::Array>()) {
|
||||
// Parameter name is output as part of the type for arrays and pointers.
|
||||
if (!type->Is<sem::Array>() && !type->Is<sem::Pointer>()) {
|
||||
out_ << " " << program_->Symbols().NameFor(v->symbol());
|
||||
}
|
||||
}
|
||||
@@ -1926,10 +1926,17 @@ bool GeneratorImpl::EmitType(const sem::Type* type, const std::string& name) {
|
||||
default:
|
||||
TINT_ICE(diagnostics_) << "unhandled storage class for pointer";
|
||||
}
|
||||
if (!EmitType(ptr->StoreType(), "")) {
|
||||
return false;
|
||||
if (ptr->StoreType()->Is<sem::Array>()) {
|
||||
std::string inner = "(*" + name + ")";
|
||||
if (!EmitType(ptr->StoreType(), inner)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!EmitType(ptr->StoreType(), "")) {
|
||||
return false;
|
||||
}
|
||||
out_ << "* " << name;
|
||||
}
|
||||
out_ << "*";
|
||||
} else if (type->Is<sem::Sampler>()) {
|
||||
out_ << "sampler";
|
||||
} else if (auto* str = type->As<sem::Struct>()) {
|
||||
@@ -2201,14 +2208,17 @@ bool GeneratorImpl::EmitVariable(const sem::Variable* var,
|
||||
return false;
|
||||
}
|
||||
auto* type = var->Type()->UnwrapRef();
|
||||
if (!EmitType(type, program_->Symbols().NameFor(decl->symbol()))) {
|
||||
|
||||
std::string name = program_->Symbols().NameFor(decl->symbol());
|
||||
if (decl->is_const()) {
|
||||
name = "const " + name;
|
||||
}
|
||||
if (!EmitType(type, name)) {
|
||||
return false;
|
||||
}
|
||||
if (decl->is_const()) {
|
||||
out_ << " const";
|
||||
}
|
||||
if (!type->Is<sem::Array>()) {
|
||||
out_ << " " << program_->Symbols().NameFor(decl->symbol());
|
||||
// Variable name is output as part of the type for arrays and pointers.
|
||||
if (!type->Is<sem::Array>() && !type->Is<sem::Pointer>()) {
|
||||
out_ << " " << name;
|
||||
}
|
||||
|
||||
if (!skip_constructor) {
|
||||
|
||||
Reference in New Issue
Block a user