ast::type: Remove Array::set_decorations

Move to constructor

Bug: tint:390
Change-Id: If6c65b7305db7f9977c0cc9884a8f551e07de050
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35014
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2020-12-07 22:19:27 +00:00
committed by Commit Bot service account
parent dec971328d
commit 8b0ffe9185
32 changed files with 205 additions and 235 deletions

View File

@@ -710,11 +710,11 @@ ast::type::Type* ParserImpl::ConvertType(
if (ast_elem_ty == nullptr) {
return nullptr;
}
auto ast_type = std::make_unique<ast::type::Array>(ast_elem_ty);
if (!ApplyArrayDecorations(rtarr_ty, ast_type.get())) {
ast::ArrayDecorationList decorations;
if (!ParseArrayDecorations(rtarr_ty, &decorations)) {
return nullptr;
}
return ast_module_.unique_type(std::move(ast_type));
return create<ast::type::Array>(ast_elem_ty, 0, std::move(decorations));
}
ast::type::Type* ParserImpl::ConvertType(
@@ -751,20 +751,22 @@ ast::type::Type* ParserImpl::ConvertType(
<< num_elem;
return nullptr;
}
auto ast_type = std::make_unique<ast::type::Array>(
ast_elem_ty, static_cast<uint32_t>(num_elem));
if (!ApplyArrayDecorations(arr_ty, ast_type.get())) {
ast::ArrayDecorationList decorations;
if (!ParseArrayDecorations(arr_ty, &decorations)) {
return nullptr;
}
if (remap_buffer_block_type_.count(elem_type_id)) {
remap_buffer_block_type_.insert(type_mgr_->GetId(arr_ty));
}
return ast_module_.unique_type(std::move(ast_type));
return create<ast::type::Array>(ast_elem_ty, static_cast<uint32_t>(num_elem),
std::move(decorations));
}
bool ParserImpl::ApplyArrayDecorations(
bool ParserImpl::ParseArrayDecorations(
const spvtools::opt::analysis::Type* spv_type,
ast::type::Array* ast_type) {
ast::ArrayDecorationList* decorations) {
bool has_array_stride = false;
const auto type_id = type_mgr_->GetId(spv_type);
for (auto& decoration : this->GetDecorationsFor(type_id)) {
if (decoration.size() == 2 && decoration[0] == SpvDecorationArrayStride) {
@@ -773,13 +775,12 @@ bool ParserImpl::ApplyArrayDecorations(
return Fail() << "invalid array type ID " << type_id
<< ": ArrayStride can't be 0";
}
if (ast_type->has_array_stride()) {
if (has_array_stride) {
return Fail() << "invalid array type ID " << type_id
<< ": multiple ArrayStride decorations";
}
ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(stride, Source{}));
ast_type->set_decorations(std::move(decos));
has_array_stride = true;
decorations->push_back(create<ast::StrideDecoration>(stride, Source{}));
} else {
return Fail() << "invalid array type ID " << type_id
<< ": unknown decoration "

View File

@@ -492,12 +492,12 @@ class ParserImpl : Reader {
ast::type::Type* ConvertType(uint32_t type_id,
const spvtools::opt::analysis::Pointer* ptr_ty);
/// Applies SPIR-V decorations to the given array or runtime-array type.
/// @param spv_type the SPIR-V aray or runtime-array type.
/// @param ast_type non-null; the AST type to apply decorations to
/// Parses the array or runtime-array decorations.
/// @param spv_type the SPIR-V array or runtime-array type.
/// @param decorations the populated decoration list
/// @returns true on success.
bool ApplyArrayDecorations(const spvtools::opt::analysis::Type* spv_type,
ast::type::Array* ast_type);
bool ParseArrayDecorations(const spvtools::opt::analysis::Type* spv_type,
ast::ArrayDecorationList* decorations);
/// Creates a new `ast::Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed.

View File

@@ -1099,9 +1099,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_array(
size = val.value;
}
auto ty = std::make_unique<ast::type::Array>(subtype.value, size);
ty->set_decorations(std::move(decos));
return module_.unique_type(std::move(ty));
return create<ast::type::Array>(subtype.value, size, std::move(decos));
});
}